exceljs.js 2.5 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885508865088750888508895089050891508925089350894508955089650897508985089950900509015090250903509045090550906509075090850909509105091150912509135091450915509165091750918509195092050921509225092350924509255092650927509285092950930509315093250933509345093550936509375093850939509405094150942509435094450945509465094750948509495095050951509525095350954509555095650957509585095950960509615096250963509645096550966509675096850969509705097150972509735097450975509765097750978509795098050981509825098350984509855098650987509885098950990509915099250993509945099550996509975099850999510005100151002510035100451005510065100751008510095101051011510125101351014510155101651017510185101951020510215102251023510245102551026510275102851029510305103151032510335103451035510365103751038510395104051041510425104351044510455104651047510485104951050510515105251053510545105551056510575105851059510605106151062510635106451065510665106751068510695107051071510725107351074510755107651077510785107951080510815108251083510845108551086510875108851089510905109151092510935109451095510965109751098510995110051101511025110351104511055110651107511085110951110511115111251113511145111551116511175111851119511205112151122511235112451125511265112751128511295113051131511325113351134511355113651137511385113951140511415114251143511445114551146511475114851149511505115151152511535115451155511565115751158511595116051161511625116351164511655116651167511685116951170511715117251173511745117551176511775117851179511805118151182511835118451185511865118751188511895119051191511925119351194511955119651197511985119951200512015120251203512045120551206512075120851209512105121151212512135121451215512165121751218512195122051221512225122351224512255122651227512285122951230512315123251233512345123551236512375123851239512405124151242512435124451245512465124751248512495125051251512525125351254512555125651257512585125951260512615126251263512645126551266512675126851269512705127151272512735127451275512765127751278512795128051281512825128351284512855128651287512885128951290512915129251293512945129551296512975129851299513005130151302513035130451305513065130751308513095131051311513125131351314513155131651317513185131951320513215132251323513245132551326513275132851329513305133151332513335133451335513365133751338513395134051341513425134351344513455134651347513485134951350513515135251353513545135551356513575135851359513605136151362513635136451365513665136751368513695137051371513725137351374513755137651377513785137951380513815138251383513845138551386513875138851389513905139151392513935139451395513965139751398513995140051401514025140351404514055140651407514085140951410514115141251413514145141551416514175141851419514205142151422514235142451425514265142751428514295143051431514325143351434514355143651437514385143951440514415144251443514445144551446514475144851449514505145151452514535145451455514565145751458514595146051461514625146351464514655146651467514685146951470514715147251473514745147551476514775147851479514805148151482514835148451485514865148751488514895149051491514925149351494514955149651497514985149951500515015150251503515045150551506515075150851509515105151151512515135151451515515165151751518515195152051521515225152351524515255152651527515285152951530515315153251533515345153551536515375153851539515405154151542515435154451545515465154751548515495155051551515525155351554515555155651557515585155951560515615156251563515645156551566515675156851569515705157151572515735157451575515765157751578515795158051581515825158351584515855158651587515885158951590515915159251593515945159551596515975159851599516005160151602516035160451605516065160751608516095161051611516125161351614516155161651617516185161951620516215162251623516245162551626516275162851629516305163151632516335163451635516365163751638516395164051641516425164351644516455164651647516485164951650516515165251653516545165551656516575165851659516605166151662516635166451665516665166751668516695167051671516725167351674516755167651677516785167951680516815168251683516845168551686516875168851689516905169151692516935169451695516965169751698516995170051701517025170351704517055170651707517085170951710517115171251713517145171551716517175171851719517205172151722517235172451725517265172751728517295173051731517325173351734517355173651737517385173951740517415174251743517445174551746517475174851749517505175151752517535175451755517565175751758517595176051761517625176351764517655176651767517685176951770517715177251773517745177551776517775177851779517805178151782517835178451785517865178751788517895179051791517925179351794517955179651797517985179951800518015180251803518045180551806518075180851809518105181151812518135181451815518165181751818518195182051821518225182351824518255182651827518285182951830518315183251833518345183551836518375183851839518405184151842518435184451845518465184751848518495185051851518525185351854518555185651857518585185951860518615186251863518645186551866518675186851869518705187151872518735187451875518765187751878518795188051881518825188351884518855188651887518885188951890518915189251893518945189551896518975189851899519005190151902519035190451905519065190751908519095191051911519125191351914519155191651917519185191951920519215192251923519245192551926519275192851929519305193151932519335193451935519365193751938519395194051941519425194351944519455194651947519485194951950519515195251953519545195551956519575195851959519605196151962519635196451965519665196751968519695197051971519725197351974519755197651977519785197951980519815198251983519845198551986519875198851989519905199151992519935199451995519965199751998519995200052001520025200352004520055200652007520085200952010520115201252013520145201552016520175201852019520205202152022520235202452025520265202752028520295203052031520325203352034520355203652037520385203952040520415204252043520445204552046520475204852049520505205152052520535205452055520565205752058520595206052061520625206352064520655206652067520685206952070520715207252073520745207552076520775207852079520805208152082520835208452085520865208752088520895209052091520925209352094520955209652097520985209952100521015210252103521045210552106521075210852109521105211152112521135211452115521165211752118521195212052121521225212352124521255212652127521285212952130521315213252133521345213552136521375213852139521405214152142521435214452145521465214752148521495215052151521525215352154521555215652157521585215952160521615216252163521645216552166521675216852169521705217152172521735217452175521765217752178521795218052181521825218352184521855218652187521885218952190521915219252193521945219552196521975219852199522005220152202522035220452205522065220752208522095221052211522125221352214522155221652217522185221952220522215222252223522245222552226522275222852229522305223152232522335223452235522365223752238522395224052241522425224352244522455224652247522485224952250522515225252253522545225552256522575225852259522605226152262522635226452265522665226752268522695227052271522725227352274522755227652277522785227952280522815228252283522845228552286522875228852289522905229152292522935229452295522965229752298522995230052301523025230352304523055230652307523085230952310523115231252313523145231552316523175231852319523205232152322523235232452325523265232752328523295233052331523325233352334523355233652337523385233952340523415234252343523445234552346523475234852349523505235152352523535235452355523565235752358523595236052361523625236352364523655236652367523685236952370523715237252373523745237552376523775237852379523805238152382523835238452385523865238752388523895239052391523925239352394523955239652397523985239952400524015240252403524045240552406524075240852409524105241152412524135241452415524165241752418524195242052421524225242352424524255242652427524285242952430524315243252433524345243552436524375243852439524405244152442524435244452445524465244752448524495245052451524525245352454524555245652457524585245952460524615246252463524645246552466524675246852469524705247152472524735247452475524765247752478524795248052481524825248352484524855248652487524885248952490524915249252493524945249552496524975249852499525005250152502525035250452505525065250752508525095251052511525125251352514525155251652517525185251952520525215252252523525245252552526525275252852529525305253152532525335253452535525365253752538525395254052541525425254352544525455254652547525485254952550525515255252553525545255552556525575255852559525605256152562525635256452565525665256752568525695257052571525725257352574525755257652577525785257952580525815258252583525845258552586525875258852589525905259152592525935259452595525965259752598525995260052601526025260352604526055260652607526085260952610526115261252613526145261552616526175261852619526205262152622526235262452625526265262752628526295263052631526325263352634526355263652637526385263952640526415264252643526445264552646526475264852649526505265152652526535265452655526565265752658526595266052661526625266352664526655266652667526685266952670526715267252673526745267552676526775267852679526805268152682526835268452685526865268752688526895269052691526925269352694526955269652697526985269952700527015270252703527045270552706527075270852709527105271152712527135271452715527165271752718527195272052721527225272352724527255272652727527285272952730527315273252733527345273552736527375273852739527405274152742527435274452745527465274752748527495275052751527525275352754527555275652757527585275952760527615276252763527645276552766527675276852769527705277152772527735277452775527765277752778527795278052781527825278352784527855278652787527885278952790527915279252793527945279552796527975279852799528005280152802528035280452805528065280752808528095281052811528125281352814528155281652817528185281952820528215282252823528245282552826528275282852829528305283152832528335283452835528365283752838528395284052841528425284352844528455284652847528485284952850528515285252853528545285552856528575285852859528605286152862528635286452865528665286752868528695287052871528725287352874528755287652877528785287952880528815288252883528845288552886528875288852889528905289152892528935289452895528965289752898528995290052901529025290352904529055290652907529085290952910529115291252913529145291552916529175291852919529205292152922529235292452925529265292752928529295293052931529325293352934529355293652937529385293952940529415294252943529445294552946529475294852949529505295152952529535295452955529565295752958529595296052961529625296352964529655296652967529685296952970529715297252973529745297552976529775297852979529805298152982529835298452985529865298752988529895299052991529925299352994529955299652997529985299953000530015300253003530045300553006530075300853009530105301153012530135301453015530165301753018530195302053021530225302353024530255302653027530285302953030530315303253033530345303553036530375303853039530405304153042530435304453045530465304753048530495305053051530525305353054530555305653057530585305953060530615306253063530645306553066530675306853069530705307153072530735307453075530765307753078530795308053081530825308353084530855308653087530885308953090530915309253093530945309553096530975309853099531005310153102531035310453105531065310753108531095311053111531125311353114531155311653117531185311953120531215312253123531245312553126531275312853129531305313153132531335313453135531365313753138531395314053141531425314353144531455314653147531485314953150531515315253153531545315553156531575315853159531605316153162531635316453165531665316753168531695317053171531725317353174531755317653177531785317953180531815318253183531845318553186531875318853189531905319153192531935319453195531965319753198531995320053201532025320353204532055320653207532085320953210532115321253213532145321553216532175321853219532205322153222532235322453225532265322753228532295323053231532325323353234532355323653237532385323953240532415324253243532445324553246532475324853249532505325153252532535325453255532565325753258532595326053261532625326353264532655326653267532685326953270532715327253273532745327553276532775327853279532805328153282532835328453285532865328753288532895329053291532925329353294532955329653297532985329953300533015330253303533045330553306533075330853309533105331153312533135331453315533165331753318533195332053321533225332353324533255332653327533285332953330533315333253333533345333553336533375333853339533405334153342533435334453345533465334753348533495335053351533525335353354533555335653357533585335953360533615336253363533645336553366533675336853369533705337153372533735337453375533765337753378533795338053381533825338353384533855338653387533885338953390533915339253393533945339553396533975339853399534005340153402534035340453405534065340753408534095341053411534125341353414534155341653417534185341953420534215342253423534245342553426534275342853429534305343153432534335343453435534365343753438534395344053441534425344353444534455344653447534485344953450534515345253453534545345553456534575345853459534605346153462534635346453465534665346753468534695347053471534725347353474534755347653477534785347953480534815348253483534845348553486534875348853489534905349153492534935349453495534965349753498534995350053501535025350353504535055350653507535085350953510535115351253513535145351553516535175351853519535205352153522535235352453525535265352753528535295353053531535325353353534535355353653537535385353953540535415354253543535445354553546535475354853549535505355153552535535355453555535565355753558535595356053561535625356353564535655356653567535685356953570535715357253573535745357553576535775357853579535805358153582535835358453585535865358753588535895359053591535925359353594535955359653597535985359953600536015360253603536045360553606536075360853609536105361153612536135361453615536165361753618536195362053621536225362353624536255362653627536285362953630536315363253633536345363553636536375363853639536405364153642536435364453645536465364753648536495365053651536525365353654536555365653657536585365953660536615366253663536645366553666536675366853669536705367153672536735367453675536765367753678536795368053681536825368353684536855368653687536885368953690536915369253693536945369553696536975369853699537005370153702537035370453705537065370753708537095371053711537125371353714537155371653717537185371953720537215372253723537245372553726537275372853729537305373153732537335373453735537365373753738537395374053741537425374353744537455374653747537485374953750537515375253753537545375553756537575375853759537605376153762537635376453765537665376753768537695377053771537725377353774537755377653777537785377953780537815378253783537845378553786537875378853789537905379153792537935379453795537965379753798537995380053801538025380353804538055380653807538085380953810538115381253813538145381553816538175381853819538205382153822538235382453825538265382753828538295383053831538325383353834538355383653837538385383953840538415384253843538445384553846538475384853849538505385153852538535385453855538565385753858538595386053861538625386353864538655386653867538685386953870538715387253873538745387553876538775387853879538805388153882538835388453885538865388753888538895389053891538925389353894538955389653897538985389953900539015390253903539045390553906539075390853909539105391153912539135391453915539165391753918539195392053921539225392353924539255392653927539285392953930539315393253933539345393553936539375393853939539405394153942539435394453945539465394753948539495395053951539525395353954539555395653957539585395953960539615396253963539645396553966539675396853969539705397153972539735397453975539765397753978539795398053981539825398353984539855398653987539885398953990539915399253993539945399553996539975399853999540005400154002540035400454005540065400754008540095401054011540125401354014540155401654017540185401954020540215402254023540245402554026540275402854029540305403154032540335403454035540365403754038540395404054041540425404354044540455404654047540485404954050540515405254053540545405554056540575405854059540605406154062540635406454065540665406754068540695407054071540725407354074540755407654077540785407954080540815408254083540845408554086540875408854089540905409154092540935409454095540965409754098540995410054101541025410354104541055410654107541085410954110541115411254113541145411554116541175411854119541205412154122541235412454125541265412754128541295413054131541325413354134541355413654137541385413954140541415414254143541445414554146541475414854149541505415154152541535415454155541565415754158541595416054161541625416354164541655416654167541685416954170541715417254173541745417554176541775417854179541805418154182541835418454185541865418754188541895419054191541925419354194541955419654197541985419954200542015420254203542045420554206542075420854209542105421154212542135421454215542165421754218542195422054221542225422354224542255422654227542285422954230542315423254233542345423554236542375423854239542405424154242542435424454245542465424754248542495425054251542525425354254542555425654257542585425954260542615426254263542645426554266542675426854269542705427154272542735427454275542765427754278542795428054281542825428354284542855428654287542885428954290542915429254293542945429554296542975429854299543005430154302543035430454305543065430754308543095431054311543125431354314543155431654317543185431954320543215432254323543245432554326543275432854329543305433154332543335433454335543365433754338543395434054341543425434354344543455434654347543485434954350543515435254353543545435554356543575435854359543605436154362543635436454365543665436754368543695437054371543725437354374543755437654377543785437954380543815438254383543845438554386543875438854389543905439154392543935439454395543965439754398543995440054401544025440354404544055440654407544085440954410544115441254413544145441554416544175441854419544205442154422544235442454425544265442754428544295443054431544325443354434544355443654437544385443954440544415444254443544445444554446544475444854449544505445154452544535445454455544565445754458544595446054461544625446354464544655446654467544685446954470544715447254473544745447554476544775447854479544805448154482544835448454485544865448754488544895449054491544925449354494544955449654497544985449954500545015450254503545045450554506545075450854509545105451154512545135451454515545165451754518545195452054521545225452354524545255452654527545285452954530545315453254533545345453554536545375453854539545405454154542545435454454545545465454754548545495455054551545525455354554545555455654557545585455954560545615456254563545645456554566545675456854569545705457154572545735457454575545765457754578545795458054581545825458354584545855458654587545885458954590545915459254593545945459554596545975459854599546005460154602546035460454605546065460754608546095461054611546125461354614546155461654617546185461954620546215462254623546245462554626546275462854629546305463154632546335463454635546365463754638546395464054641546425464354644546455464654647546485464954650546515465254653546545465554656546575465854659546605466154662546635466454665546665466754668546695467054671546725467354674546755467654677546785467954680546815468254683546845468554686546875468854689546905469154692546935469454695546965469754698546995470054701547025470354704547055470654707547085470954710547115471254713547145471554716547175471854719547205472154722547235472454725547265472754728547295473054731547325473354734547355473654737547385473954740547415474254743547445474554746547475474854749547505475154752547535475454755547565475754758547595476054761547625476354764547655476654767547685476954770547715477254773547745477554776547775477854779547805478154782547835478454785547865478754788547895479054791547925479354794547955479654797547985479954800548015480254803548045480554806548075480854809548105481154812548135481454815548165481754818548195482054821548225482354824548255482654827548285482954830548315483254833548345483554836548375483854839548405484154842548435484454845548465484754848548495485054851548525485354854548555485654857548585485954860548615486254863548645486554866548675486854869548705487154872548735487454875548765487754878548795488054881548825488354884548855488654887548885488954890548915489254893548945489554896548975489854899549005490154902549035490454905549065490754908549095491054911549125491354914549155491654917549185491954920549215492254923549245492554926549275492854929549305493154932549335493454935549365493754938549395494054941549425494354944549455494654947549485494954950549515495254953549545495554956549575495854959549605496154962549635496454965549665496754968549695497054971549725497354974549755497654977549785497954980549815498254983549845498554986549875498854989549905499154992549935499454995549965499754998549995500055001550025500355004550055500655007550085500955010550115501255013550145501555016550175501855019550205502155022550235502455025550265502755028550295503055031550325503355034550355503655037550385503955040550415504255043550445504555046550475504855049550505505155052550535505455055550565505755058550595506055061550625506355064550655506655067550685506955070550715507255073550745507555076550775507855079550805508155082550835508455085550865508755088550895509055091550925509355094550955509655097550985509955100551015510255103551045510555106551075510855109551105511155112551135511455115551165511755118551195512055121551225512355124551255512655127551285512955130551315513255133551345513555136551375513855139551405514155142551435514455145551465514755148551495515055151551525515355154551555515655157551585515955160551615516255163551645516555166551675516855169551705517155172551735517455175551765517755178551795518055181551825518355184551855518655187551885518955190551915519255193551945519555196551975519855199552005520155202552035520455205552065520755208552095521055211552125521355214552155521655217552185521955220552215522255223552245522555226552275522855229552305523155232552335523455235552365523755238552395524055241552425524355244552455524655247552485524955250552515525255253552545525555256552575525855259552605526155262552635526455265552665526755268552695527055271552725527355274552755527655277552785527955280552815528255283552845528555286552875528855289552905529155292552935529455295552965529755298552995530055301553025530355304553055530655307553085530955310553115531255313553145531555316553175531855319553205532155322553235532455325553265532755328553295533055331553325533355334553355533655337553385533955340553415534255343553445534555346553475534855349553505535155352553535535455355553565535755358553595536055361553625536355364553655536655367553685536955370553715537255373553745537555376553775537855379553805538155382553835538455385553865538755388553895539055391553925539355394553955539655397553985539955400554015540255403554045540555406554075540855409554105541155412554135541455415554165541755418554195542055421554225542355424554255542655427554285542955430554315543255433554345543555436554375543855439554405544155442554435544455445554465544755448554495545055451554525545355454554555545655457554585545955460554615546255463554645546555466554675546855469554705547155472554735547455475554765547755478554795548055481554825548355484554855548655487554885548955490554915549255493554945549555496554975549855499555005550155502555035550455505555065550755508555095551055511555125551355514555155551655517555185551955520555215552255523555245552555526555275552855529555305553155532555335553455535555365553755538555395554055541555425554355544555455554655547555485554955550555515555255553555545555555556555575555855559555605556155562555635556455565555665556755568555695557055571555725557355574555755557655577555785557955580555815558255583555845558555586555875558855589555905559155592555935559455595555965559755598555995560055601556025560355604556055560655607556085560955610556115561255613556145561555616556175561855619556205562155622556235562455625556265562755628556295563055631556325563355634556355563655637556385563955640556415564255643556445564555646556475564855649556505565155652556535565455655556565565755658556595566055661556625566355664556655566655667556685566955670556715567255673556745567555676556775567855679556805568155682556835568455685556865568755688556895569055691556925569355694556955569655697556985569955700557015570255703557045570555706557075570855709557105571155712557135571455715557165571755718557195572055721557225572355724557255572655727557285572955730557315573255733557345573555736557375573855739557405574155742557435574455745557465574755748557495575055751557525575355754557555575655757557585575955760557615576255763557645576555766557675576855769557705577155772557735577455775557765577755778557795578055781557825578355784557855578655787557885578955790557915579255793557945579555796557975579855799558005580155802558035580455805558065580755808558095581055811558125581355814558155581655817558185581955820558215582255823558245582555826558275582855829558305583155832558335583455835558365583755838558395584055841558425584355844558455584655847558485584955850558515585255853558545585555856558575585855859558605586155862558635586455865558665586755868558695587055871558725587355874558755587655877558785587955880558815588255883558845588555886558875588855889558905589155892558935589455895558965589755898558995590055901559025590355904559055590655907559085590955910559115591255913559145591555916559175591855919559205592155922559235592455925559265592755928559295593055931559325593355934559355593655937559385593955940559415594255943559445594555946559475594855949559505595155952559535595455955559565595755958559595596055961559625596355964559655596655967559685596955970559715597255973559745597555976559775597855979559805598155982559835598455985559865598755988559895599055991559925599355994559955599655997559985599956000560015600256003560045600556006560075600856009560105601156012560135601456015560165601756018560195602056021560225602356024560255602656027560285602956030560315603256033560345603556036560375603856039560405604156042560435604456045560465604756048560495605056051560525605356054560555605656057560585605956060560615606256063560645606556066560675606856069560705607156072560735607456075560765607756078560795608056081560825608356084560855608656087560885608956090560915609256093560945609556096560975609856099561005610156102561035610456105561065610756108561095611056111561125611356114561155611656117561185611956120561215612256123561245612556126561275612856129561305613156132561335613456135561365613756138561395614056141561425614356144561455614656147561485614956150561515615256153561545615556156561575615856159561605616156162561635616456165561665616756168561695617056171561725617356174561755617656177561785617956180561815618256183561845618556186561875618856189561905619156192561935619456195561965619756198561995620056201562025620356204562055620656207562085620956210562115621256213562145621556216562175621856219562205622156222562235622456225562265622756228562295623056231562325623356234562355623656237562385623956240562415624256243562445624556246562475624856249562505625156252562535625456255562565625756258562595626056261562625626356264562655626656267562685626956270562715627256273562745627556276562775627856279562805628156282562835628456285562865628756288562895629056291562925629356294562955629656297562985629956300563015630256303563045630556306563075630856309563105631156312563135631456315563165631756318563195632056321563225632356324563255632656327563285632956330563315633256333563345633556336563375633856339563405634156342563435634456345563465634756348563495635056351563525635356354563555635656357563585635956360563615636256363563645636556366563675636856369563705637156372563735637456375563765637756378563795638056381563825638356384563855638656387563885638956390563915639256393563945639556396563975639856399564005640156402564035640456405564065640756408564095641056411564125641356414564155641656417564185641956420564215642256423564245642556426564275642856429564305643156432564335643456435564365643756438564395644056441564425644356444564455644656447564485644956450564515645256453564545645556456564575645856459564605646156462564635646456465564665646756468564695647056471564725647356474564755647656477564785647956480564815648256483564845648556486564875648856489564905649156492564935649456495564965649756498564995650056501565025650356504565055650656507565085650956510565115651256513565145651556516565175651856519565205652156522565235652456525565265652756528565295653056531565325653356534565355653656537565385653956540565415654256543565445654556546565475654856549565505655156552565535655456555565565655756558565595656056561565625656356564565655656656567565685656956570565715657256573565745657556576565775657856579565805658156582565835658456585565865658756588565895659056591565925659356594565955659656597565985659956600566015660256603566045660556606566075660856609566105661156612566135661456615566165661756618566195662056621566225662356624566255662656627566285662956630566315663256633566345663556636566375663856639566405664156642566435664456645566465664756648566495665056651566525665356654566555665656657566585665956660566615666256663566645666556666566675666856669566705667156672566735667456675566765667756678566795668056681566825668356684566855668656687566885668956690566915669256693566945669556696566975669856699567005670156702567035670456705567065670756708567095671056711567125671356714567155671656717567185671956720567215672256723567245672556726567275672856729567305673156732567335673456735567365673756738567395674056741567425674356744567455674656747567485674956750567515675256753567545675556756567575675856759567605676156762567635676456765567665676756768567695677056771567725677356774567755677656777567785677956780567815678256783567845678556786567875678856789567905679156792567935679456795567965679756798567995680056801568025680356804568055680656807568085680956810568115681256813568145681556816568175681856819568205682156822568235682456825568265682756828568295683056831568325683356834568355683656837568385683956840568415684256843568445684556846568475684856849568505685156852568535685456855568565685756858568595686056861568625686356864568655686656867568685686956870568715687256873568745687556876568775687856879568805688156882568835688456885568865688756888568895689056891568925689356894568955689656897568985689956900569015690256903569045690556906569075690856909569105691156912569135691456915569165691756918569195692056921569225692356924569255692656927569285692956930569315693256933569345693556936569375693856939569405694156942569435694456945569465694756948569495695056951569525695356954569555695656957569585695956960569615696256963569645696556966569675696856969569705697156972569735697456975569765697756978569795698056981569825698356984569855698656987569885698956990569915699256993569945699556996569975699856999570005700157002570035700457005570065700757008570095701057011570125701357014570155701657017570185701957020570215702257023570245702557026570275702857029570305703157032570335703457035570365703757038570395704057041570425704357044570455704657047570485704957050570515705257053570545705557056570575705857059570605706157062570635706457065570665706757068570695707057071570725707357074570755707657077570785707957080570815708257083570845708557086570875708857089570905709157092570935709457095570965709757098570995710057101571025710357104571055710657107571085710957110571115711257113571145711557116571175711857119571205712157122571235712457125571265712757128571295713057131571325713357134571355713657137571385713957140571415714257143571445714557146571475714857149571505715157152571535715457155571565715757158571595716057161571625716357164571655716657167571685716957170571715717257173571745717557176571775717857179571805718157182571835718457185571865718757188571895719057191571925719357194571955719657197571985719957200572015720257203572045720557206572075720857209572105721157212572135721457215572165721757218572195722057221572225722357224572255722657227572285722957230572315723257233572345723557236572375723857239572405724157242572435724457245572465724757248572495725057251572525725357254572555725657257572585725957260572615726257263572645726557266572675726857269572705727157272572735727457275572765727757278572795728057281572825728357284572855728657287572885728957290572915729257293572945729557296572975729857299573005730157302573035730457305573065730757308573095731057311573125731357314573155731657317573185731957320573215732257323573245732557326573275732857329573305733157332573335733457335573365733757338573395734057341573425734357344573455734657347573485734957350573515735257353573545735557356573575735857359573605736157362573635736457365573665736757368573695737057371573725737357374573755737657377573785737957380573815738257383573845738557386573875738857389573905739157392573935739457395573965739757398573995740057401574025740357404574055740657407574085740957410574115741257413574145741557416574175741857419574205742157422574235742457425574265742757428574295743057431574325743357434574355743657437574385743957440574415744257443574445744557446574475744857449574505745157452574535745457455574565745757458574595746057461574625746357464574655746657467574685746957470574715747257473574745747557476574775747857479574805748157482574835748457485574865748757488574895749057491574925749357494574955749657497574985749957500575015750257503575045750557506575075750857509575105751157512575135751457515575165751757518575195752057521575225752357524575255752657527575285752957530575315753257533575345753557536575375753857539575405754157542575435754457545575465754757548575495755057551575525755357554575555755657557575585755957560575615756257563575645756557566575675756857569575705757157572575735757457575575765757757578575795758057581575825758357584575855758657587575885758957590575915759257593575945759557596575975759857599576005760157602576035760457605576065760757608576095761057611576125761357614576155761657617576185761957620576215762257623576245762557626576275762857629576305763157632576335763457635576365763757638576395764057641576425764357644576455764657647576485764957650576515765257653576545765557656576575765857659576605766157662576635766457665576665766757668576695767057671576725767357674576755767657677576785767957680576815768257683576845768557686576875768857689576905769157692576935769457695576965769757698576995770057701577025770357704577055770657707577085770957710577115771257713577145771557716577175771857719577205772157722577235772457725577265772757728577295773057731577325773357734577355773657737577385773957740577415774257743577445774557746577475774857749577505775157752577535775457755577565775757758577595776057761577625776357764577655776657767577685776957770577715777257773577745777557776577775777857779577805778157782577835778457785577865778757788577895779057791577925779357794577955779657797577985779957800578015780257803578045780557806578075780857809578105781157812578135781457815578165781757818578195782057821578225782357824578255782657827578285782957830578315783257833578345783557836578375783857839578405784157842578435784457845578465784757848578495785057851578525785357854578555785657857578585785957860578615786257863578645786557866578675786857869578705787157872578735787457875578765787757878578795788057881578825788357884578855788657887578885788957890578915789257893578945789557896578975789857899579005790157902579035790457905579065790757908579095791057911579125791357914579155791657917579185791957920579215792257923579245792557926579275792857929579305793157932579335793457935579365793757938579395794057941579425794357944579455794657947579485794957950579515795257953579545795557956579575795857959579605796157962579635796457965579665796757968579695797057971579725797357974579755797657977579785797957980579815798257983579845798557986579875798857989579905799157992579935799457995579965799757998579995800058001580025800358004580055800658007580085800958010580115801258013580145801558016580175801858019580205802158022580235802458025580265802758028580295803058031580325803358034580355803658037580385803958040580415804258043580445804558046580475804858049580505805158052580535805458055580565805758058580595806058061580625806358064580655806658067580685806958070580715807258073580745807558076580775807858079580805808158082580835808458085580865808758088580895809058091580925809358094580955809658097580985809958100581015810258103581045810558106581075810858109581105811158112581135811458115581165811758118581195812058121581225812358124581255812658127581285812958130581315813258133581345813558136581375813858139581405814158142581435814458145581465814758148581495815058151581525815358154581555815658157581585815958160581615816258163581645816558166581675816858169581705817158172581735817458175581765817758178581795818058181581825818358184581855818658187581885818958190581915819258193581945819558196581975819858199582005820158202582035820458205582065820758208582095821058211582125821358214582155821658217582185821958220582215822258223582245822558226582275822858229582305823158232582335823458235582365823758238582395824058241582425824358244582455824658247582485824958250582515825258253582545825558256582575825858259582605826158262582635826458265582665826758268582695827058271582725827358274582755827658277582785827958280582815828258283582845828558286582875828858289582905829158292582935829458295582965829758298582995830058301583025830358304583055830658307583085830958310583115831258313583145831558316583175831858319583205832158322583235832458325583265832758328583295833058331583325833358334583355833658337583385833958340583415834258343583445834558346583475834858349583505835158352583535835458355583565835758358583595836058361583625836358364583655836658367583685836958370583715837258373583745837558376583775837858379583805838158382583835838458385583865838758388583895839058391583925839358394583955839658397583985839958400584015840258403584045840558406584075840858409584105841158412584135841458415584165841758418584195842058421584225842358424584255842658427584285842958430584315843258433584345843558436584375843858439584405844158442584435844458445584465844758448584495845058451584525845358454584555845658457584585845958460584615846258463584645846558466584675846858469584705847158472584735847458475584765847758478584795848058481584825848358484584855848658487584885848958490584915849258493584945849558496584975849858499585005850158502585035850458505585065850758508585095851058511585125851358514585155851658517585185851958520585215852258523585245852558526585275852858529585305853158532585335853458535585365853758538585395854058541585425854358544585455854658547585485854958550585515855258553585545855558556585575855858559585605856158562585635856458565585665856758568585695857058571585725857358574585755857658577585785857958580585815858258583585845858558586585875858858589585905859158592585935859458595585965859758598585995860058601586025860358604586055860658607586085860958610586115861258613586145861558616586175861858619586205862158622586235862458625586265862758628586295863058631586325863358634586355863658637586385863958640586415864258643586445864558646586475864858649586505865158652586535865458655586565865758658586595866058661586625866358664586655866658667586685866958670586715867258673586745867558676586775867858679586805868158682586835868458685586865868758688586895869058691586925869358694586955869658697586985869958700587015870258703587045870558706587075870858709587105871158712587135871458715587165871758718587195872058721587225872358724587255872658727587285872958730587315873258733587345873558736587375873858739587405874158742587435874458745587465874758748587495875058751587525875358754587555875658757587585875958760587615876258763587645876558766587675876858769587705877158772587735877458775587765877758778587795878058781587825878358784587855878658787587885878958790587915879258793587945879558796587975879858799588005880158802588035880458805588065880758808588095881058811588125881358814588155881658817588185881958820588215882258823588245882558826588275882858829588305883158832588335883458835588365883758838588395884058841588425884358844588455884658847588485884958850588515885258853588545885558856588575885858859588605886158862588635886458865588665886758868588695887058871588725887358874588755887658877588785887958880588815888258883588845888558886588875888858889588905889158892588935889458895588965889758898588995890058901589025890358904589055890658907589085890958910589115891258913589145891558916589175891858919589205892158922589235892458925589265892758928589295893058931589325893358934589355893658937589385893958940589415894258943589445894558946589475894858949589505895158952589535895458955589565895758958589595896058961589625896358964589655896658967589685896958970589715897258973589745897558976589775897858979589805898158982589835898458985589865898758988589895899058991589925899358994589955899658997589985899959000590015900259003590045900559006590075900859009590105901159012590135901459015590165901759018590195902059021590225902359024590255902659027590285902959030590315903259033590345903559036590375903859039590405904159042590435904459045590465904759048590495905059051590525905359054590555905659057590585905959060590615906259063590645906559066590675906859069590705907159072590735907459075590765907759078590795908059081590825908359084590855908659087590885908959090590915909259093590945909559096590975909859099591005910159102591035910459105591065910759108591095911059111591125911359114591155911659117591185911959120591215912259123591245912559126591275912859129591305913159132591335913459135591365913759138591395914059141591425914359144591455914659147591485914959150591515915259153591545915559156591575915859159591605916159162591635916459165591665916759168591695917059171591725917359174591755917659177591785917959180591815918259183591845918559186591875918859189591905919159192591935919459195591965919759198591995920059201592025920359204592055920659207592085920959210592115921259213592145921559216592175921859219592205922159222592235922459225592265922759228592295923059231592325923359234592355923659237592385923959240592415924259243592445924559246592475924859249592505925159252592535925459255592565925759258592595926059261592625926359264592655926659267592685926959270592715927259273592745927559276592775927859279592805928159282592835928459285592865928759288592895929059291592925929359294592955929659297592985929959300593015930259303593045930559306593075930859309593105931159312593135931459315593165931759318593195932059321593225932359324593255932659327593285932959330593315933259333593345933559336593375933859339593405934159342593435934459345593465934759348593495935059351593525935359354593555935659357593585935959360593615936259363593645936559366593675936859369593705937159372593735937459375593765937759378593795938059381593825938359384593855938659387593885938959390593915939259393593945939559396593975939859399594005940159402594035940459405594065940759408594095941059411594125941359414594155941659417594185941959420594215942259423594245942559426594275942859429594305943159432594335943459435594365943759438594395944059441594425944359444594455944659447594485944959450594515945259453594545945559456594575945859459594605946159462594635946459465594665946759468594695947059471594725947359474594755947659477594785947959480594815948259483594845948559486594875948859489594905949159492594935949459495594965949759498594995950059501595025950359504595055950659507595085950959510595115951259513595145951559516595175951859519595205952159522595235952459525595265952759528595295953059531595325953359534595355953659537595385953959540595415954259543595445954559546595475954859549595505955159552595535955459555595565955759558595595956059561595625956359564595655956659567595685956959570595715957259573595745957559576595775957859579595805958159582595835958459585595865958759588595895959059591595925959359594595955959659597595985959959600596015960259603596045960559606596075960859609596105961159612596135961459615596165961759618596195962059621596225962359624596255962659627596285962959630596315963259633596345963559636596375963859639596405964159642596435964459645596465964759648596495965059651596525965359654596555965659657596585965959660596615966259663596645966559666596675966859669596705967159672596735967459675596765967759678596795968059681596825968359684596855968659687596885968959690596915969259693596945969559696596975969859699597005970159702597035970459705597065970759708597095971059711597125971359714597155971659717597185971959720597215972259723597245972559726597275972859729597305973159732597335973459735597365973759738597395974059741597425974359744597455974659747597485974959750597515975259753597545975559756597575975859759597605976159762597635976459765597665976759768597695977059771597725977359774597755977659777597785977959780597815978259783597845978559786597875978859789597905979159792597935979459795597965979759798597995980059801598025980359804598055980659807598085980959810598115981259813598145981559816598175981859819598205982159822598235982459825598265982759828598295983059831598325983359834598355983659837598385983959840598415984259843598445984559846598475984859849598505985159852598535985459855598565985759858598595986059861598625986359864598655986659867598685986959870598715987259873598745987559876598775987859879598805988159882598835988459885598865988759888598895989059891598925989359894598955989659897598985989959900599015990259903599045990559906599075990859909599105991159912599135991459915599165991759918599195992059921599225992359924599255992659927599285992959930599315993259933599345993559936599375993859939599405994159942599435994459945599465994759948599495995059951599525995359954599555995659957599585995959960599615996259963599645996559966599675996859969599705997159972599735997459975599765997759978599795998059981599825998359984599855998659987599885998959990599915999259993599945999559996599975999859999600006000160002600036000460005600066000760008600096001060011600126001360014600156001660017600186001960020600216002260023600246002560026600276002860029600306003160032600336003460035600366003760038600396004060041600426004360044600456004660047600486004960050600516005260053600546005560056600576005860059600606006160062600636006460065600666006760068600696007060071600726007360074600756007660077600786007960080600816008260083600846008560086600876008860089600906009160092600936009460095600966009760098600996010060101601026010360104601056010660107601086010960110601116011260113601146011560116601176011860119601206012160122601236012460125601266012760128601296013060131601326013360134601356013660137601386013960140601416014260143601446014560146601476014860149601506015160152601536015460155601566015760158601596016060161601626016360164601656016660167601686016960170601716017260173601746017560176601776017860179601806018160182601836018460185601866018760188601896019060191601926019360194601956019660197601986019960200602016020260203602046020560206602076020860209602106021160212602136021460215602166021760218602196022060221602226022360224602256022660227602286022960230602316023260233602346023560236602376023860239602406024160242602436024460245602466024760248602496025060251602526025360254602556025660257602586025960260602616026260263602646026560266602676026860269602706027160272602736027460275602766027760278602796028060281602826028360284602856028660287602886028960290602916029260293602946029560296602976029860299603006030160302603036030460305603066030760308603096031060311603126031360314603156031660317603186031960320603216032260323603246032560326603276032860329603306033160332603336033460335603366033760338603396034060341603426034360344603456034660347603486034960350603516035260353603546035560356603576035860359603606036160362603636036460365603666036760368603696037060371603726037360374603756037660377603786037960380603816038260383603846038560386603876038860389603906039160392603936039460395603966039760398603996040060401604026040360404604056040660407604086040960410604116041260413604146041560416604176041860419604206042160422604236042460425604266042760428604296043060431604326043360434604356043660437604386043960440604416044260443604446044560446604476044860449604506045160452604536045460455604566045760458604596046060461604626046360464604656046660467604686046960470604716047260473604746047560476604776047860479604806048160482604836048460485604866048760488604896049060491604926049360494604956049660497604986049960500605016050260503605046050560506605076050860509605106051160512605136051460515605166051760518605196052060521605226052360524605256052660527605286052960530605316053260533605346053560536605376053860539605406054160542605436054460545605466054760548605496055060551605526055360554605556055660557605586055960560605616056260563605646056560566605676056860569605706057160572605736057460575605766057760578605796058060581605826058360584605856058660587605886058960590605916059260593605946059560596605976059860599606006060160602606036060460605606066060760608606096061060611606126061360614606156061660617606186061960620606216062260623606246062560626606276062860629606306063160632606336063460635606366063760638606396064060641606426064360644606456064660647606486064960650606516065260653606546065560656606576065860659606606066160662606636066460665606666066760668606696067060671606726067360674606756067660677606786067960680606816068260683606846068560686606876068860689606906069160692606936069460695606966069760698606996070060701607026070360704607056070660707607086070960710607116071260713607146071560716607176071860719607206072160722607236072460725607266072760728607296073060731607326073360734607356073660737607386073960740607416074260743607446074560746607476074860749607506075160752607536075460755607566075760758607596076060761607626076360764607656076660767607686076960770607716077260773607746077560776607776077860779607806078160782607836078460785607866078760788607896079060791607926079360794607956079660797607986079960800608016080260803608046080560806608076080860809608106081160812608136081460815608166081760818608196082060821608226082360824608256082660827608286082960830608316083260833608346083560836608376083860839608406084160842608436084460845608466084760848608496085060851608526085360854608556085660857608586085960860608616086260863608646086560866608676086860869608706087160872608736087460875608766087760878608796088060881608826088360884608856088660887608886088960890608916089260893608946089560896608976089860899609006090160902609036090460905609066090760908609096091060911609126091360914609156091660917609186091960920609216092260923609246092560926609276092860929609306093160932609336093460935609366093760938609396094060941609426094360944609456094660947609486094960950609516095260953609546095560956609576095860959609606096160962609636096460965609666096760968609696097060971609726097360974609756097660977609786097960980609816098260983609846098560986609876098860989609906099160992609936099460995609966099760998609996100061001610026100361004610056100661007610086100961010610116101261013610146101561016610176101861019610206102161022610236102461025610266102761028610296103061031610326103361034610356103661037610386103961040610416104261043610446104561046610476104861049610506105161052610536105461055610566105761058610596106061061610626106361064610656106661067610686106961070610716107261073610746107561076610776107861079610806108161082610836108461085610866108761088610896109061091610926109361094610956109661097610986109961100611016110261103611046110561106611076110861109611106111161112611136111461115611166111761118611196112061121611226112361124611256112661127611286112961130611316113261133611346113561136611376113861139611406114161142611436114461145611466114761148611496115061151611526115361154611556115661157611586115961160611616116261163611646116561166611676116861169611706117161172611736117461175611766117761178611796118061181611826118361184611856118661187611886118961190611916119261193611946119561196611976119861199612006120161202612036120461205612066120761208612096121061211612126121361214612156121661217612186121961220612216122261223612246122561226612276122861229612306123161232612336123461235612366123761238612396124061241612426124361244612456124661247612486124961250612516125261253612546125561256612576125861259612606126161262612636126461265612666126761268612696127061271612726127361274612756127661277612786127961280612816128261283612846128561286612876128861289612906129161292612936129461295612966129761298612996130061301613026130361304613056130661307613086130961310613116131261313613146131561316613176131861319613206132161322613236132461325613266132761328613296133061331613326133361334613356133661337613386133961340613416134261343613446134561346613476134861349613506135161352613536135461355613566135761358613596136061361613626136361364613656136661367613686136961370613716137261373613746137561376613776137861379613806138161382613836138461385613866138761388613896139061391613926139361394613956139661397613986139961400614016140261403614046140561406614076140861409614106141161412614136141461415614166141761418614196142061421614226142361424614256142661427614286142961430614316143261433614346143561436614376143861439614406144161442614436144461445614466144761448614496145061451614526145361454614556145661457614586145961460614616146261463614646146561466614676146861469614706147161472614736147461475614766147761478614796148061481614826148361484614856148661487614886148961490614916149261493614946149561496614976149861499615006150161502615036150461505615066150761508615096151061511615126151361514615156151661517615186151961520615216152261523615246152561526615276152861529615306153161532615336153461535615366153761538615396154061541615426154361544615456154661547615486154961550615516155261553615546155561556615576155861559615606156161562615636156461565615666156761568615696157061571615726157361574615756157661577615786157961580615816158261583615846158561586615876158861589615906159161592615936159461595615966159761598615996160061601616026160361604616056160661607616086160961610616116161261613616146161561616616176161861619616206162161622616236162461625616266162761628616296163061631616326163361634616356163661637616386163961640616416164261643616446164561646616476164861649616506165161652616536165461655616566165761658616596166061661616626166361664616656166661667616686166961670616716167261673616746167561676616776167861679616806168161682616836168461685616866168761688616896169061691616926169361694616956169661697616986169961700617016170261703617046170561706617076170861709617106171161712617136171461715617166171761718617196172061721617226172361724617256172661727617286172961730617316173261733617346173561736617376173861739617406174161742617436174461745617466174761748617496175061751617526175361754617556175661757617586175961760617616176261763617646176561766617676176861769617706177161772617736177461775617766177761778617796178061781617826178361784617856178661787617886178961790617916179261793617946179561796617976179861799618006180161802618036180461805618066180761808618096181061811618126181361814618156181661817618186181961820618216182261823618246182561826618276182861829618306183161832618336183461835618366183761838618396184061841618426184361844618456184661847618486184961850618516185261853618546185561856618576185861859618606186161862618636186461865618666186761868618696187061871618726187361874618756187661877618786187961880618816188261883618846188561886618876188861889618906189161892618936189461895618966189761898618996190061901619026190361904619056190661907619086190961910619116191261913619146191561916619176191861919619206192161922619236192461925619266192761928619296193061931619326193361934619356193661937619386193961940619416194261943619446194561946619476194861949619506195161952619536195461955619566195761958619596196061961619626196361964619656196661967619686196961970619716197261973619746197561976619776197861979619806198161982619836198461985619866198761988619896199061991619926199361994619956199661997619986199962000620016200262003620046200562006620076200862009620106201162012620136201462015620166201762018620196202062021620226202362024620256202662027620286202962030620316203262033620346203562036620376203862039620406204162042620436204462045620466204762048620496205062051620526205362054620556205662057620586205962060620616206262063620646206562066620676206862069620706207162072620736207462075620766207762078620796208062081620826208362084620856208662087620886208962090620916209262093620946209562096620976209862099621006210162102621036210462105621066210762108621096211062111621126211362114621156211662117621186211962120621216212262123621246212562126621276212862129621306213162132621336213462135621366213762138621396214062141621426214362144621456214662147621486214962150621516215262153621546215562156621576215862159621606216162162621636216462165621666216762168621696217062171621726217362174621756217662177621786217962180621816218262183621846218562186621876218862189621906219162192621936219462195621966219762198621996220062201622026220362204622056220662207622086220962210622116221262213622146221562216622176221862219622206222162222622236222462225622266222762228622296223062231622326223362234622356223662237622386223962240622416224262243622446224562246622476224862249622506225162252622536225462255622566225762258622596226062261622626226362264622656226662267622686226962270622716227262273622746227562276622776227862279622806228162282622836228462285622866228762288622896229062291622926229362294622956229662297622986229962300623016230262303623046230562306623076230862309623106231162312623136231462315623166231762318623196232062321623226232362324623256232662327623286232962330623316233262333623346233562336623376233862339623406234162342623436234462345623466234762348623496235062351623526235362354623556235662357623586235962360623616236262363623646236562366623676236862369623706237162372623736237462375623766237762378623796238062381623826238362384623856238662387623886238962390623916239262393623946239562396623976239862399624006240162402624036240462405624066240762408624096241062411624126241362414624156241662417624186241962420624216242262423624246242562426624276242862429624306243162432624336243462435624366243762438624396244062441624426244362444624456244662447624486244962450624516245262453624546245562456624576245862459624606246162462624636246462465624666246762468624696247062471624726247362474624756247662477624786247962480624816248262483624846248562486624876248862489624906249162492624936249462495624966249762498624996250062501625026250362504625056250662507625086250962510625116251262513625146251562516625176251862519625206252162522625236252462525625266252762528625296253062531625326253362534625356253662537625386253962540625416254262543625446254562546625476254862549625506255162552625536255462555625566255762558625596256062561625626256362564625656256662567625686256962570625716257262573625746257562576625776257862579625806258162582625836258462585625866258762588625896259062591625926259362594625956259662597625986259962600626016260262603626046260562606626076260862609626106261162612626136261462615626166261762618626196262062621626226262362624626256262662627626286262962630626316263262633626346263562636626376263862639626406264162642626436264462645626466264762648626496265062651626526265362654626556265662657626586265962660626616266262663626646266562666626676266862669626706267162672626736267462675626766267762678626796268062681626826268362684626856268662687626886268962690626916269262693626946269562696626976269862699627006270162702627036270462705627066270762708627096271062711627126271362714627156271662717627186271962720627216272262723627246272562726627276272862729627306273162732627336273462735627366273762738627396274062741627426274362744627456274662747627486274962750627516275262753627546275562756627576275862759627606276162762627636276462765627666276762768627696277062771627726277362774627756277662777627786277962780627816278262783627846278562786627876278862789627906279162792627936279462795627966279762798627996280062801628026280362804628056280662807628086280962810628116281262813628146281562816628176281862819628206282162822628236282462825628266282762828628296283062831628326283362834628356283662837628386283962840628416284262843628446284562846628476284862849628506285162852628536285462855628566285762858628596286062861628626286362864628656286662867628686286962870628716287262873628746287562876628776287862879628806288162882628836288462885628866288762888628896289062891628926289362894628956289662897628986289962900629016290262903629046290562906629076290862909629106291162912629136291462915629166291762918629196292062921629226292362924629256292662927629286292962930629316293262933629346293562936629376293862939629406294162942629436294462945629466294762948629496295062951629526295362954629556295662957629586295962960629616296262963629646296562966629676296862969629706297162972629736297462975629766297762978629796298062981629826298362984629856298662987629886298962990629916299262993629946299562996629976299862999630006300163002630036300463005630066300763008630096301063011630126301363014630156301663017630186301963020630216302263023630246302563026630276302863029630306303163032630336303463035630366303763038630396304063041630426304363044630456304663047630486304963050630516305263053630546305563056630576305863059630606306163062630636306463065630666306763068630696307063071630726307363074630756307663077630786307963080630816308263083630846308563086630876308863089630906309163092630936309463095630966309763098630996310063101631026310363104631056310663107631086310963110631116311263113631146311563116631176311863119631206312163122631236312463125631266312763128631296313063131631326313363134631356313663137631386313963140631416314263143631446314563146631476314863149631506315163152631536315463155631566315763158631596316063161631626316363164631656316663167631686316963170631716317263173631746317563176631776317863179631806318163182631836318463185631866318763188631896319063191631926319363194631956319663197631986319963200632016320263203632046320563206632076320863209632106321163212632136321463215632166321763218632196322063221632226322363224632256322663227632286322963230632316323263233632346323563236632376323863239632406324163242632436324463245632466324763248632496325063251632526325363254632556325663257632586325963260632616326263263632646326563266632676326863269632706327163272632736327463275632766327763278632796328063281632826328363284632856328663287632886328963290632916329263293632946329563296632976329863299633006330163302633036330463305633066330763308633096331063311633126331363314633156331663317633186331963320633216332263323633246332563326633276332863329633306333163332633336333463335633366333763338633396334063341633426334363344633456334663347633486334963350633516335263353633546335563356633576335863359633606336163362633636336463365633666336763368633696337063371633726337363374633756337663377633786337963380633816338263383633846338563386633876338863389633906339163392633936339463395633966339763398633996340063401634026340363404634056340663407634086340963410634116341263413634146341563416634176341863419634206342163422634236342463425634266342763428634296343063431634326343363434634356343663437634386343963440634416344263443634446344563446634476344863449634506345163452634536345463455634566345763458634596346063461634626346363464634656346663467634686346963470634716347263473634746347563476634776347863479634806348163482634836348463485634866348763488634896349063491634926349363494634956349663497634986349963500635016350263503635046350563506635076350863509635106351163512635136351463515635166351763518635196352063521635226352363524635256352663527635286352963530635316353263533635346353563536635376353863539635406354163542635436354463545635466354763548635496355063551635526355363554635556355663557635586355963560635616356263563635646356563566635676356863569635706357163572635736357463575635766357763578635796358063581635826358363584635856358663587635886358963590635916359263593635946359563596635976359863599636006360163602636036360463605636066360763608636096361063611636126361363614636156361663617636186361963620636216362263623636246362563626636276362863629636306363163632636336363463635636366363763638636396364063641636426364363644636456364663647636486364963650636516365263653636546365563656636576365863659636606366163662636636366463665636666366763668636696367063671636726367363674636756367663677636786367963680636816368263683636846368563686636876368863689636906369163692636936369463695636966369763698636996370063701637026370363704637056370663707637086370963710637116371263713637146371563716637176371863719637206372163722637236372463725637266372763728637296373063731637326373363734637356373663737637386373963740637416374263743637446374563746637476374863749637506375163752637536375463755637566375763758637596376063761637626376363764637656376663767637686376963770637716377263773637746377563776637776377863779637806378163782637836378463785637866378763788637896379063791637926379363794637956379663797637986379963800638016380263803638046380563806638076380863809638106381163812638136381463815638166381763818638196382063821638226382363824638256382663827638286382963830638316383263833638346383563836638376383863839638406384163842638436384463845638466384763848638496385063851638526385363854638556385663857638586385963860638616386263863638646386563866638676386863869638706387163872638736387463875638766387763878638796388063881638826388363884638856388663887638886388963890638916389263893638946389563896638976389863899639006390163902639036390463905639066390763908639096391063911639126391363914639156391663917639186391963920639216392263923639246392563926639276392863929639306393163932639336393463935639366393763938639396394063941639426394363944639456394663947639486394963950639516395263953639546395563956639576395863959639606396163962639636396463965639666396763968639696397063971639726397363974639756397663977639786397963980639816398263983639846398563986639876398863989639906399163992639936399463995639966399763998639996400064001640026400364004640056400664007640086400964010640116401264013640146401564016640176401864019640206402164022640236402464025640266402764028640296403064031640326403364034640356403664037640386403964040640416404264043640446404564046640476404864049640506405164052640536405464055640566405764058640596406064061640626406364064640656406664067640686406964070640716407264073640746407564076640776407864079640806408164082640836408464085640866408764088640896409064091640926409364094640956409664097640986409964100641016410264103641046410564106641076410864109641106411164112641136411464115641166411764118641196412064121641226412364124641256412664127641286412964130641316413264133641346413564136641376413864139641406414164142641436414464145641466414764148641496415064151641526415364154641556415664157641586415964160641616416264163641646416564166641676416864169641706417164172641736417464175641766417764178641796418064181641826418364184641856418664187641886418964190641916419264193641946419564196641976419864199642006420164202642036420464205642066420764208642096421064211642126421364214642156421664217642186421964220642216422264223642246422564226642276422864229642306423164232642336423464235642366423764238642396424064241642426424364244642456424664247642486424964250642516425264253642546425564256642576425864259642606426164262642636426464265642666426764268642696427064271642726427364274642756427664277642786427964280642816428264283642846428564286642876428864289642906429164292642936429464295642966429764298642996430064301643026430364304643056430664307643086430964310643116431264313643146431564316643176431864319643206432164322643236432464325643266432764328643296433064331643326433364334643356433664337643386433964340643416434264343643446434564346643476434864349643506435164352643536435464355643566435764358643596436064361643626436364364643656436664367643686436964370643716437264373643746437564376643776437864379643806438164382643836438464385643866438764388643896439064391643926439364394643956439664397643986439964400644016440264403644046440564406644076440864409644106441164412644136441464415644166441764418644196442064421644226442364424644256442664427644286442964430644316443264433644346443564436644376443864439644406444164442644436444464445644466444764448644496445064451644526445364454644556445664457644586445964460644616446264463644646446564466644676446864469644706447164472644736447464475644766447764478644796448064481644826448364484644856448664487644886448964490644916449264493644946449564496644976449864499645006450164502645036450464505645066450764508645096451064511645126451364514645156451664517645186451964520645216452264523645246452564526645276452864529645306453164532645336453464535645366453764538645396454064541645426454364544645456454664547645486454964550645516455264553645546455564556645576455864559645606456164562645636456464565645666456764568645696457064571645726457364574645756457664577645786457964580645816458264583645846458564586645876458864589645906459164592645936459464595645966459764598645996460064601646026460364604646056460664607646086460964610646116461264613646146461564616646176461864619646206462164622646236462464625646266462764628646296463064631646326463364634646356463664637646386463964640646416464264643646446464564646646476464864649646506465164652646536465464655646566465764658646596466064661646626466364664646656466664667646686466964670646716467264673646746467564676646776467864679646806468164682646836468464685646866468764688646896469064691646926469364694646956469664697646986469964700647016470264703647046470564706647076470864709647106471164712647136471464715647166471764718647196472064721647226472364724647256472664727647286472964730647316473264733647346473564736647376473864739647406474164742647436474464745647466474764748647496475064751647526475364754647556475664757647586475964760647616476264763647646476564766647676476864769647706477164772647736477464775647766477764778647796478064781647826478364784647856478664787647886478964790647916479264793647946479564796647976479864799648006480164802648036480464805648066480764808648096481064811648126481364814648156481664817648186481964820648216482264823648246482564826648276482864829648306483164832648336483464835648366483764838648396484064841648426484364844648456484664847648486484964850648516485264853648546485564856648576485864859648606486164862648636486464865648666486764868648696487064871648726487364874648756487664877648786487964880648816488264883648846488564886648876488864889648906489164892648936489464895648966489764898648996490064901649026490364904649056490664907649086490964910649116491264913649146491564916649176491864919649206492164922649236492464925649266492764928649296493064931649326493364934649356493664937649386493964940649416494264943649446494564946649476494864949649506495164952649536495464955649566495764958649596496064961649626496364964649656496664967649686496964970649716497264973649746497564976649776497864979649806498164982649836498464985649866498764988649896499064991649926499364994649956499664997649986499965000650016500265003650046500565006650076500865009650106501165012650136501465015650166501765018650196502065021650226502365024650256502665027650286502965030650316503265033650346503565036650376503865039650406504165042650436504465045650466504765048650496505065051650526505365054650556505665057650586505965060650616506265063650646506565066650676506865069650706507165072650736507465075650766507765078650796508065081650826508365084650856508665087650886508965090650916509265093650946509565096650976509865099651006510165102651036510465105651066510765108651096511065111651126511365114651156511665117651186511965120651216512265123651246512565126651276512865129651306513165132651336513465135651366513765138651396514065141651426514365144651456514665147651486514965150651516515265153651546515565156651576515865159651606516165162651636516465165651666516765168651696517065171651726517365174651756517665177651786517965180651816518265183651846518565186651876518865189651906519165192651936519465195651966519765198651996520065201652026520365204652056520665207652086520965210652116521265213652146521565216652176521865219652206522165222652236522465225652266522765228652296523065231652326523365234652356523665237652386523965240652416524265243652446524565246652476524865249652506525165252652536525465255652566525765258652596526065261652626526365264652656526665267652686526965270652716527265273652746527565276652776527865279652806528165282652836528465285652866528765288652896529065291652926529365294652956529665297652986529965300653016530265303653046530565306653076530865309653106531165312653136531465315653166531765318653196532065321653226532365324653256532665327653286532965330653316533265333653346533565336653376533865339653406534165342653436534465345653466534765348653496535065351653526535365354653556535665357653586535965360653616536265363653646536565366653676536865369653706537165372653736537465375653766537765378653796538065381653826538365384653856538665387653886538965390653916539265393653946539565396653976539865399654006540165402654036540465405654066540765408654096541065411654126541365414654156541665417654186541965420654216542265423654246542565426654276542865429654306543165432654336543465435654366543765438654396544065441654426544365444654456544665447654486544965450654516545265453654546545565456654576545865459654606546165462654636546465465654666546765468654696547065471654726547365474654756547665477654786547965480654816548265483654846548565486654876548865489654906549165492654936549465495654966549765498654996550065501655026550365504655056550665507655086550965510655116551265513655146551565516655176551865519655206552165522655236552465525655266552765528655296553065531655326553365534655356553665537655386553965540655416554265543655446554565546655476554865549655506555165552655536555465555655566555765558655596556065561655626556365564655656556665567655686556965570655716557265573655746557565576655776557865579655806558165582655836558465585655866558765588655896559065591655926559365594655956559665597655986559965600656016560265603656046560565606656076560865609656106561165612656136561465615656166561765618656196562065621656226562365624656256562665627656286562965630656316563265633656346563565636656376563865639656406564165642656436564465645656466564765648656496565065651656526565365654656556565665657656586565965660656616566265663656646566565666656676566865669656706567165672656736567465675656766567765678656796568065681656826568365684656856568665687656886568965690656916569265693656946569565696656976569865699657006570165702657036570465705657066570765708657096571065711657126571365714657156571665717657186571965720657216572265723657246572565726657276572865729657306573165732657336573465735657366573765738657396574065741657426574365744657456574665747657486574965750657516575265753657546575565756657576575865759657606576165762657636576465765657666576765768657696577065771657726577365774657756577665777657786577965780657816578265783657846578565786657876578865789657906579165792657936579465795657966579765798657996580065801658026580365804658056580665807658086580965810658116581265813658146581565816658176581865819658206582165822658236582465825658266582765828658296583065831658326583365834658356583665837658386583965840658416584265843658446584565846658476584865849658506585165852658536585465855658566585765858658596586065861658626586365864658656586665867658686586965870658716587265873658746587565876658776587865879658806588165882658836588465885658866588765888658896589065891658926589365894658956589665897658986589965900659016590265903659046590565906659076590865909659106591165912659136591465915659166591765918659196592065921659226592365924659256592665927659286592965930659316593265933659346593565936659376593865939659406594165942659436594465945659466594765948659496595065951659526595365954659556595665957659586595965960659616596265963659646596565966659676596865969659706597165972659736597465975659766597765978659796598065981659826598365984659856598665987659886598965990659916599265993659946599565996659976599865999660006600166002660036600466005660066600766008660096601066011660126601366014660156601666017660186601966020660216602266023660246602566026660276602866029660306603166032660336603466035660366603766038660396604066041660426604366044660456604666047660486604966050660516605266053660546605566056660576605866059660606606166062660636606466065660666606766068660696607066071660726607366074660756607666077660786607966080660816608266083660846608566086660876608866089660906609166092660936609466095660966609766098660996610066101661026610366104661056610666107661086610966110661116611266113661146611566116661176611866119661206612166122661236612466125661266612766128661296613066131661326613366134661356613666137661386613966140661416614266143661446614566146661476614866149661506615166152661536615466155661566615766158661596616066161661626616366164661656616666167661686616966170661716617266173661746617566176661776617866179661806618166182661836618466185661866618766188661896619066191661926619366194661956619666197661986619966200662016620266203662046620566206662076620866209662106621166212662136621466215662166621766218662196622066221662226622366224662256622666227662286622966230662316623266233662346623566236662376623866239662406624166242662436624466245662466624766248662496625066251662526625366254662556625666257662586625966260662616626266263662646626566266662676626866269662706627166272662736627466275662766627766278662796628066281662826628366284662856628666287662886628966290662916629266293662946629566296662976629866299663006630166302663036630466305663066630766308663096631066311663126631366314663156631666317663186631966320663216632266323663246632566326663276632866329663306633166332663336633466335663366633766338663396634066341663426634366344663456634666347663486634966350663516635266353663546635566356663576635866359663606636166362663636636466365663666636766368663696637066371663726637366374663756637666377663786637966380663816638266383663846638566386663876638866389663906639166392663936639466395663966639766398663996640066401664026640366404664056640666407664086640966410664116641266413664146641566416664176641866419664206642166422664236642466425664266642766428664296643066431664326643366434664356643666437664386643966440664416644266443664446644566446664476644866449664506645166452664536645466455664566645766458664596646066461664626646366464664656646666467664686646966470664716647266473664746647566476664776647866479664806648166482664836648466485664866648766488664896649066491664926649366494664956649666497664986649966500665016650266503665046650566506665076650866509665106651166512665136651466515665166651766518665196652066521665226652366524665256652666527665286652966530665316653266533665346653566536665376653866539665406654166542665436654466545665466654766548665496655066551665526655366554665556655666557665586655966560665616656266563665646656566566665676656866569665706657166572665736657466575665766657766578665796658066581665826658366584665856658666587665886658966590665916659266593665946659566596665976659866599666006660166602666036660466605666066660766608666096661066611666126661366614666156661666617666186661966620666216662266623666246662566626666276662866629666306663166632666336663466635666366663766638666396664066641666426664366644666456664666647666486664966650666516665266653666546665566656666576665866659666606666166662666636666466665666666666766668666696667066671666726667366674666756667666677666786667966680666816668266683666846668566686666876668866689666906669166692666936669466695666966669766698666996670066701667026670366704667056670666707667086670966710667116671266713667146671566716667176671866719667206672166722667236672466725667266672766728667296673066731667326673366734667356673666737667386673966740667416674266743667446674566746667476674866749667506675166752667536675466755667566675766758667596676066761667626676366764667656676666767667686676966770667716677266773667746677566776667776677866779667806678166782667836678466785667866678766788667896679066791667926679366794667956679666797667986679966800668016680266803668046680566806668076680866809668106681166812668136681466815668166681766818668196682066821668226682366824668256682666827668286682966830668316683266833668346683566836668376683866839668406684166842668436684466845668466684766848668496685066851668526685366854668556685666857668586685966860668616686266863668646686566866668676686866869668706687166872668736687466875668766687766878668796688066881668826688366884668856688666887668886688966890668916689266893668946689566896668976689866899669006690166902669036690466905669066690766908669096691066911669126691366914669156691666917669186691966920669216692266923669246692566926669276692866929669306693166932669336693466935669366693766938669396694066941669426694366944669456694666947669486694966950669516695266953669546695566956669576695866959669606696166962669636696466965669666696766968669696697066971669726697366974669756697666977669786697966980669816698266983669846698566986669876698866989669906699166992669936699466995669966699766998669996700067001670026700367004670056700667007670086700967010670116701267013670146701567016670176701867019670206702167022670236702467025670266702767028670296703067031670326703367034670356703667037670386703967040670416704267043670446704567046670476704867049670506705167052670536705467055670566705767058670596706067061670626706367064670656706667067670686706967070670716707267073670746707567076670776707867079670806708167082670836708467085670866708767088670896709067091670926709367094670956709667097670986709967100671016710267103671046710567106671076710867109671106711167112671136711467115671166711767118671196712067121671226712367124671256712667127671286712967130671316713267133671346713567136671376713867139671406714167142671436714467145671466714767148671496715067151671526715367154671556715667157671586715967160671616716267163671646716567166671676716867169671706717167172671736717467175671766717767178671796718067181671826718367184671856718667187671886718967190671916719267193671946719567196671976719867199672006720167202672036720467205672066720767208672096721067211672126721367214672156721667217672186721967220672216722267223672246722567226672276722867229672306723167232672336723467235672366723767238672396724067241672426724367244672456724667247672486724967250672516725267253672546725567256672576725867259672606726167262672636726467265672666726767268672696727067271672726727367274672756727667277672786727967280672816728267283672846728567286672876728867289672906729167292672936729467295672966729767298672996730067301673026730367304673056730667307673086730967310673116731267313673146731567316673176731867319673206732167322673236732467325673266732767328673296733067331673326733367334673356733667337673386733967340673416734267343673446734567346673476734867349673506735167352673536735467355673566735767358673596736067361673626736367364673656736667367673686736967370673716737267373673746737567376673776737867379673806738167382673836738467385673866738767388673896739067391673926739367394673956739667397673986739967400674016740267403674046740567406674076740867409674106741167412674136741467415674166741767418674196742067421674226742367424674256742667427674286742967430674316743267433674346743567436674376743867439674406744167442674436744467445674466744767448674496745067451674526745367454674556745667457674586745967460674616746267463674646746567466674676746867469674706747167472674736747467475674766747767478674796748067481674826748367484674856748667487674886748967490674916749267493674946749567496674976749867499675006750167502675036750467505675066750767508675096751067511675126751367514675156751667517675186751967520675216752267523675246752567526675276752867529675306753167532675336753467535675366753767538675396754067541675426754367544675456754667547675486754967550675516755267553675546755567556675576755867559675606756167562675636756467565675666756767568675696757067571675726757367574675756757667577675786757967580675816758267583675846758567586675876758867589675906759167592675936759467595675966759767598675996760067601676026760367604676056760667607676086760967610676116761267613676146761567616676176761867619676206762167622676236762467625676266762767628676296763067631676326763367634676356763667637676386763967640676416764267643676446764567646676476764867649676506765167652676536765467655676566765767658676596766067661676626766367664676656766667667676686766967670676716767267673676746767567676676776767867679676806768167682676836768467685676866768767688676896769067691676926769367694676956769667697676986769967700677016770267703677046770567706677076770867709677106771167712677136771467715677166771767718677196772067721677226772367724677256772667727677286772967730677316773267733677346773567736677376773867739677406774167742677436774467745677466774767748677496775067751677526775367754677556775667757677586775967760677616776267763677646776567766677676776867769677706777167772677736777467775677766777767778677796778067781677826778367784677856778667787677886778967790677916779267793677946779567796677976779867799678006780167802678036780467805678066780767808678096781067811678126781367814678156781667817678186781967820678216782267823678246782567826678276782867829678306783167832678336783467835678366783767838678396784067841678426784367844678456784667847678486784967850678516785267853678546785567856678576785867859678606786167862678636786467865678666786767868678696787067871678726787367874678756787667877678786787967880678816788267883678846788567886678876788867889678906789167892678936789467895678966789767898678996790067901679026790367904679056790667907679086790967910679116791267913679146791567916679176791867919679206792167922679236792467925679266792767928679296793067931679326793367934679356793667937679386793967940679416794267943679446794567946679476794867949679506795167952679536795467955679566795767958679596796067961679626796367964679656796667967679686796967970679716797267973679746797567976679776797867979679806798167982679836798467985679866798767988679896799067991679926799367994679956799667997679986799968000680016800268003680046800568006680076800868009680106801168012680136801468015680166801768018680196802068021680226802368024680256802668027680286802968030680316803268033680346803568036680376803868039680406804168042680436804468045680466804768048680496805068051680526805368054680556805668057680586805968060680616806268063680646806568066680676806868069680706807168072680736807468075680766807768078680796808068081680826808368084680856808668087680886808968090680916809268093680946809568096680976809868099681006810168102681036810468105681066810768108681096811068111681126811368114681156811668117681186811968120681216812268123681246812568126681276812868129681306813168132681336813468135681366813768138681396814068141681426814368144681456814668147681486814968150681516815268153681546815568156681576815868159681606816168162681636816468165681666816768168681696817068171681726817368174681756817668177681786817968180681816818268183681846818568186681876818868189681906819168192681936819468195681966819768198681996820068201682026820368204682056820668207682086820968210682116821268213682146821568216682176821868219682206822168222682236822468225682266822768228682296823068231682326823368234682356823668237682386823968240682416824268243682446824568246682476824868249682506825168252682536825468255682566825768258682596826068261682626826368264682656826668267682686826968270682716827268273682746827568276682776827868279682806828168282682836828468285682866828768288682896829068291682926829368294682956829668297682986829968300683016830268303683046830568306683076830868309683106831168312683136831468315683166831768318683196832068321683226832368324683256832668327683286832968330683316833268333683346833568336683376833868339683406834168342683436834468345683466834768348683496835068351683526835368354683556835668357683586835968360683616836268363683646836568366683676836868369683706837168372683736837468375683766837768378683796838068381683826838368384683856838668387683886838968390683916839268393683946839568396683976839868399684006840168402684036840468405684066840768408684096841068411684126841368414684156841668417684186841968420684216842268423684246842568426684276842868429684306843168432684336843468435684366843768438684396844068441684426844368444684456844668447684486844968450684516845268453684546845568456684576845868459684606846168462684636846468465684666846768468684696847068471684726847368474684756847668477684786847968480684816848268483684846848568486684876848868489684906849168492684936849468495684966849768498684996850068501685026850368504685056850668507685086850968510685116851268513685146851568516685176851868519685206852168522685236852468525685266852768528685296853068531685326853368534685356853668537685386853968540685416854268543685446854568546685476854868549685506855168552685536855468555685566855768558685596856068561685626856368564685656856668567685686856968570685716857268573685746857568576685776857868579685806858168582685836858468585685866858768588685896859068591685926859368594685956859668597685986859968600686016860268603686046860568606686076860868609686106861168612686136861468615686166861768618686196862068621686226862368624686256862668627686286862968630686316863268633686346863568636686376863868639686406864168642686436864468645686466864768648686496865068651686526865368654686556865668657686586865968660686616866268663686646866568666686676866868669686706867168672686736867468675686766867768678686796868068681686826868368684686856868668687686886868968690686916869268693686946869568696686976869868699687006870168702687036870468705687066870768708687096871068711687126871368714687156871668717687186871968720687216872268723687246872568726687276872868729687306873168732687336873468735687366873768738687396874068741687426874368744687456874668747687486874968750687516875268753687546875568756687576875868759687606876168762687636876468765687666876768768687696877068771687726877368774687756877668777687786877968780687816878268783687846878568786687876878868789687906879168792687936879468795687966879768798687996880068801688026880368804688056880668807688086880968810688116881268813688146881568816688176881868819688206882168822688236882468825688266882768828688296883068831688326883368834688356883668837688386883968840688416884268843688446884568846688476884868849688506885168852688536885468855688566885768858688596886068861688626886368864688656886668867688686886968870688716887268873688746887568876688776887868879688806888168882688836888468885688866888768888688896889068891688926889368894688956889668897688986889968900689016890268903689046890568906689076890868909689106891168912689136891468915689166891768918689196892068921689226892368924689256892668927689286892968930689316893268933689346893568936689376893868939689406894168942689436894468945689466894768948689496895068951689526895368954689556895668957689586895968960689616896268963689646896568966689676896868969689706897168972689736897468975689766897768978689796898068981689826898368984689856898668987689886898968990689916899268993689946899568996689976899868999690006900169002690036900469005690066900769008690096901069011690126901369014690156901669017690186901969020690216902269023690246902569026690276902869029690306903169032690336903469035690366903769038690396904069041690426904369044690456904669047690486904969050690516905269053690546905569056690576905869059690606906169062690636906469065690666906769068690696907069071690726907369074690756907669077690786907969080690816908269083690846908569086690876908869089690906909169092690936909469095690966909769098690996910069101691026910369104691056910669107691086910969110691116911269113691146911569116691176911869119691206912169122691236912469125691266912769128691296913069131691326913369134691356913669137691386913969140691416914269143691446914569146691476914869149691506915169152691536915469155691566915769158691596916069161691626916369164691656916669167691686916969170691716917269173691746917569176691776917869179691806918169182691836918469185691866918769188691896919069191691926919369194691956919669197691986919969200692016920269203692046920569206692076920869209692106921169212692136921469215692166921769218692196922069221692226922369224692256922669227692286922969230692316923269233692346923569236692376923869239692406924169242692436924469245692466924769248692496925069251692526925369254692556925669257692586925969260692616926269263692646926569266692676926869269692706927169272692736927469275692766927769278692796928069281692826928369284692856928669287692886928969290692916929269293692946929569296692976929869299693006930169302693036930469305693066930769308693096931069311693126931369314693156931669317693186931969320693216932269323693246932569326693276932869329693306933169332693336933469335693366933769338693396934069341693426934369344693456934669347693486934969350693516935269353693546935569356693576935869359693606936169362693636936469365693666936769368693696937069371693726937369374693756937669377693786937969380693816938269383693846938569386693876938869389693906939169392693936939469395693966939769398693996940069401694026940369404694056940669407694086940969410694116941269413694146941569416694176941869419694206942169422694236942469425694266942769428694296943069431694326943369434694356943669437694386943969440694416944269443694446944569446694476944869449694506945169452694536945469455694566945769458694596946069461694626946369464694656946669467694686946969470694716947269473694746947569476694776947869479694806948169482694836948469485694866948769488694896949069491694926949369494694956949669497694986949969500695016950269503695046950569506695076950869509695106951169512695136951469515695166951769518695196952069521695226952369524695256952669527695286952969530695316953269533695346953569536695376953869539695406954169542695436954469545695466954769548695496955069551695526955369554695556955669557695586955969560695616956269563695646956569566695676956869569695706957169572695736957469575695766957769578695796958069581695826958369584695856958669587695886958969590695916959269593695946959569596695976959869599696006960169602696036960469605696066960769608696096961069611696126961369614696156961669617696186961969620696216962269623696246962569626696276962869629696306963169632696336963469635696366963769638696396964069641696426964369644696456964669647696486964969650696516965269653696546965569656696576965869659696606966169662696636966469665696666966769668696696967069671696726967369674696756967669677696786967969680696816968269683696846968569686696876968869689696906969169692696936969469695696966969769698696996970069701697026970369704697056970669707697086970969710697116971269713697146971569716697176971869719697206972169722697236972469725697266972769728697296973069731697326973369734697356973669737697386973969740697416974269743697446974569746697476974869749697506975169752697536975469755697566975769758697596976069761697626976369764697656976669767697686976969770697716977269773697746977569776697776977869779697806978169782697836978469785697866978769788697896979069791697926979369794697956979669797697986979969800698016980269803698046980569806698076980869809698106981169812698136981469815698166981769818698196982069821698226982369824698256982669827698286982969830698316983269833698346983569836698376983869839698406984169842698436984469845698466984769848698496985069851698526985369854698556985669857698586985969860698616986269863698646986569866698676986869869698706987169872698736987469875698766987769878698796988069881698826988369884698856988669887698886988969890698916989269893698946989569896698976989869899699006990169902699036990469905699066990769908699096991069911699126991369914699156991669917699186991969920699216992269923699246992569926699276992869929699306993169932699336993469935699366993769938699396994069941699426994369944699456994669947699486994969950699516995269953699546995569956699576995869959699606996169962699636996469965699666996769968699696997069971699726997369974699756997669977699786997969980699816998269983699846998569986699876998869989699906999169992699936999469995699966999769998699997000070001700027000370004700057000670007700087000970010700117001270013700147001570016700177001870019700207002170022700237002470025700267002770028700297003070031700327003370034700357003670037700387003970040700417004270043700447004570046700477004870049700507005170052700537005470055700567005770058700597006070061700627006370064700657006670067700687006970070700717007270073700747007570076700777007870079700807008170082700837008470085700867008770088700897009070091700927009370094700957009670097700987009970100701017010270103701047010570106701077010870109701107011170112701137011470115701167011770118701197012070121701227012370124701257012670127701287012970130701317013270133701347013570136701377013870139701407014170142701437014470145701467014770148701497015070151701527015370154701557015670157701587015970160701617016270163701647016570166701677016870169701707017170172701737017470175701767017770178701797018070181701827018370184701857018670187701887018970190701917019270193701947019570196701977019870199702007020170202702037020470205702067020770208702097021070211702127021370214702157021670217702187021970220702217022270223702247022570226702277022870229702307023170232702337023470235702367023770238702397024070241702427024370244702457024670247702487024970250702517025270253702547025570256702577025870259702607026170262702637026470265702667026770268702697027070271702727027370274702757027670277702787027970280702817028270283702847028570286702877028870289702907029170292702937029470295702967029770298702997030070301703027030370304703057030670307703087030970310703117031270313703147031570316703177031870319703207032170322703237032470325703267032770328703297033070331703327033370334703357033670337703387033970340703417034270343703447034570346703477034870349703507035170352703537035470355703567035770358703597036070361703627036370364703657036670367703687036970370703717037270373703747037570376703777037870379703807038170382703837038470385703867038770388703897039070391703927039370394703957039670397703987039970400704017040270403704047040570406704077040870409704107041170412704137041470415704167041770418704197042070421704227042370424704257042670427704287042970430704317043270433704347043570436704377043870439704407044170442704437044470445704467044770448704497045070451704527045370454704557045670457704587045970460704617046270463704647046570466704677046870469704707047170472704737047470475704767047770478704797048070481704827048370484704857048670487704887048970490704917049270493704947049570496704977049870499705007050170502705037050470505705067050770508705097051070511705127051370514705157051670517705187051970520705217052270523705247052570526705277052870529705307053170532705337053470535705367053770538705397054070541705427054370544705457054670547705487054970550705517055270553705547055570556705577055870559705607056170562705637056470565705667056770568705697057070571705727057370574705757057670577705787057970580705817058270583705847058570586705877058870589705907059170592705937059470595705967059770598705997060070601706027060370604706057060670607706087060970610706117061270613706147061570616706177061870619706207062170622706237062470625706267062770628706297063070631706327063370634706357063670637706387063970640706417064270643706447064570646706477064870649706507065170652706537065470655706567065770658706597066070661706627066370664706657066670667706687066970670706717067270673706747067570676706777067870679706807068170682706837068470685706867068770688706897069070691706927069370694706957069670697706987069970700707017070270703707047070570706707077070870709707107071170712707137071470715707167071770718707197072070721707227072370724707257072670727707287072970730707317073270733707347073570736707377073870739707407074170742707437074470745707467074770748707497075070751707527075370754707557075670757707587075970760707617076270763707647076570766707677076870769707707077170772707737077470775707767077770778707797078070781707827078370784707857078670787707887078970790707917079270793707947079570796707977079870799708007080170802708037080470805708067080770808708097081070811708127081370814708157081670817708187081970820708217082270823708247082570826708277082870829708307083170832708337083470835708367083770838708397084070841708427084370844708457084670847708487084970850708517085270853708547085570856708577085870859708607086170862708637086470865708667086770868708697087070871708727087370874708757087670877708787087970880708817088270883708847088570886708877088870889708907089170892708937089470895708967089770898708997090070901709027090370904709057090670907709087090970910709117091270913709147091570916709177091870919709207092170922709237092470925709267092770928709297093070931709327093370934709357093670937709387093970940709417094270943709447094570946709477094870949709507095170952709537095470955709567095770958709597096070961709627096370964709657096670967709687096970970709717097270973709747097570976709777097870979709807098170982709837098470985709867098770988709897099070991709927099370994709957099670997709987099971000710017100271003710047100571006710077100871009710107101171012710137101471015710167101771018710197102071021710227102371024710257102671027710287102971030710317103271033710347103571036710377103871039710407104171042710437104471045710467104771048710497105071051710527105371054710557105671057710587105971060710617106271063710647106571066710677106871069710707107171072710737107471075710767107771078710797108071081710827108371084710857108671087710887108971090710917109271093710947109571096710977109871099711007110171102711037110471105711067110771108711097111071111711127111371114711157111671117711187111971120711217112271123711247112571126711277112871129711307113171132711337113471135711367113771138711397114071141711427114371144711457114671147711487114971150711517115271153711547115571156711577115871159711607116171162711637116471165711667116771168711697117071171711727117371174711757117671177711787117971180711817118271183711847118571186711877118871189711907119171192711937119471195711967119771198711997120071201712027120371204712057120671207712087120971210712117121271213712147121571216712177121871219712207122171222712237122471225712267122771228712297123071231712327123371234712357123671237712387123971240712417124271243712447124571246712477124871249712507125171252712537125471255712567125771258712597126071261712627126371264712657126671267712687126971270712717127271273712747127571276712777127871279712807128171282712837128471285712867128771288712897129071291712927129371294712957129671297712987129971300713017130271303713047130571306713077130871309713107131171312713137131471315713167131771318713197132071321713227132371324713257132671327713287132971330713317133271333713347133571336713377133871339713407134171342713437134471345713467134771348713497135071351713527135371354713557135671357713587135971360713617136271363713647136571366713677136871369713707137171372713737137471375713767137771378713797138071381713827138371384713857138671387713887138971390713917139271393713947139571396713977139871399714007140171402714037140471405714067140771408714097141071411714127141371414714157141671417714187141971420714217142271423714247142571426714277142871429714307143171432714337143471435714367143771438714397144071441714427144371444714457144671447714487144971450714517145271453714547145571456714577145871459714607146171462714637146471465714667146771468714697147071471714727147371474714757147671477714787147971480714817148271483714847148571486714877148871489714907149171492714937149471495714967149771498714997150071501715027150371504715057150671507715087150971510715117151271513715147151571516715177151871519715207152171522715237152471525715267152771528715297153071531715327153371534715357153671537715387153971540715417154271543715447154571546715477154871549715507155171552715537155471555715567155771558715597156071561715627156371564715657156671567715687156971570715717157271573715747157571576715777157871579715807158171582715837158471585715867158771588715897159071591715927159371594715957159671597715987159971600716017160271603716047160571606716077160871609716107161171612716137161471615716167161771618716197162071621716227162371624716257162671627716287162971630716317163271633716347163571636716377163871639716407164171642716437164471645716467164771648716497165071651716527165371654716557165671657716587165971660716617166271663716647166571666716677166871669716707167171672716737167471675716767167771678716797168071681716827168371684716857168671687716887168971690716917169271693716947169571696716977169871699717007170171702717037170471705717067170771708717097171071711717127171371714717157171671717717187171971720717217172271723717247172571726717277172871729717307173171732717337173471735717367173771738717397174071741717427174371744717457174671747717487174971750717517175271753717547175571756717577175871759717607176171762717637176471765717667176771768717697177071771717727177371774717757177671777717787177971780717817178271783717847178571786717877178871789717907179171792717937179471795717967179771798717997180071801718027180371804718057180671807718087180971810718117181271813718147181571816718177181871819718207182171822718237182471825718267182771828718297183071831718327183371834718357183671837718387183971840718417184271843718447184571846718477184871849718507185171852718537185471855718567185771858718597186071861718627186371864718657186671867718687186971870718717187271873718747187571876718777187871879718807188171882718837188471885718867188771888718897189071891718927189371894718957189671897718987189971900719017190271903719047190571906719077190871909719107191171912719137191471915719167191771918719197192071921719227192371924719257192671927719287192971930719317193271933719347193571936719377193871939719407194171942719437194471945719467194771948719497195071951719527195371954719557195671957719587195971960719617196271963719647196571966719677196871969719707197171972719737197471975719767197771978719797198071981719827198371984719857198671987719887198971990719917199271993719947199571996719977199871999720007200172002720037200472005720067200772008720097201072011720127201372014720157201672017720187201972020720217202272023720247202572026720277202872029720307203172032720337203472035720367203772038720397204072041720427204372044720457204672047720487204972050720517205272053720547205572056720577205872059720607206172062720637206472065720667206772068720697207072071720727207372074720757207672077720787207972080720817208272083720847208572086720877208872089720907209172092720937209472095720967209772098720997210072101721027210372104721057210672107721087210972110721117211272113721147211572116721177211872119721207212172122721237212472125721267212772128721297213072131721327213372134721357213672137721387213972140721417214272143721447214572146721477214872149721507215172152721537215472155721567215772158721597216072161721627216372164721657216672167721687216972170721717217272173721747217572176721777217872179721807218172182721837218472185721867218772188721897219072191721927219372194721957219672197721987219972200722017220272203722047220572206722077220872209722107221172212722137221472215722167221772218722197222072221722227222372224722257222672227722287222972230722317223272233722347223572236722377223872239722407224172242722437224472245722467224772248722497225072251722527225372254722557225672257722587225972260722617226272263722647226572266722677226872269722707227172272722737227472275722767227772278722797228072281722827228372284722857228672287722887228972290722917229272293722947229572296722977229872299723007230172302723037230472305723067230772308723097231072311723127231372314723157231672317723187231972320723217232272323723247232572326723277232872329723307233172332723337233472335723367233772338723397234072341723427234372344723457234672347723487234972350723517235272353723547235572356723577235872359723607236172362723637236472365723667236772368723697237072371723727237372374723757237672377723787237972380723817238272383723847238572386723877238872389723907239172392723937239472395723967239772398723997240072401724027240372404724057240672407724087240972410724117241272413724147241572416724177241872419724207242172422724237242472425724267242772428724297243072431724327243372434724357243672437724387243972440724417244272443724447244572446724477244872449724507245172452724537245472455724567245772458724597246072461724627246372464724657246672467724687246972470724717247272473724747247572476724777247872479724807248172482724837248472485724867248772488724897249072491724927249372494724957249672497724987249972500725017250272503725047250572506725077250872509725107251172512725137251472515725167251772518725197252072521725227252372524725257252672527725287252972530725317253272533725347253572536725377253872539725407254172542725437254472545725467254772548725497255072551725527255372554725557255672557725587255972560725617256272563725647256572566725677256872569725707257172572725737257472575725767257772578725797258072581725827258372584725857258672587725887258972590725917259272593725947259572596725977259872599726007260172602726037260472605726067260772608726097261072611726127261372614726157261672617726187261972620726217262272623726247262572626726277262872629726307263172632726337263472635726367263772638726397264072641726427264372644726457264672647726487264972650726517265272653726547265572656726577265872659726607266172662726637266472665726667266772668726697267072671726727267372674726757267672677726787267972680726817268272683726847268572686726877268872689726907269172692726937269472695726967269772698726997270072701727027270372704727057270672707727087270972710727117271272713727147271572716727177271872719727207272172722727237272472725727267272772728727297273072731727327273372734727357273672737727387273972740727417274272743727447274572746727477274872749727507275172752727537275472755727567275772758727597276072761727627276372764727657276672767727687276972770727717277272773727747277572776727777277872779727807278172782727837278472785727867278772788727897279072791727927279372794727957279672797727987279972800728017280272803728047280572806728077280872809728107281172812728137281472815728167281772818728197282072821728227282372824728257282672827728287282972830728317283272833728347283572836728377283872839728407284172842728437284472845728467284772848728497285072851728527285372854728557285672857728587285972860728617286272863728647286572866728677286872869728707287172872728737287472875728767287772878728797288072881728827288372884728857288672887728887288972890728917289272893728947289572896728977289872899729007290172902729037290472905729067290772908729097291072911729127291372914729157291672917729187291972920729217292272923729247292572926729277292872929729307293172932729337293472935729367293772938729397294072941729427294372944729457294672947729487294972950729517295272953729547295572956729577295872959729607296172962729637296472965729667296772968729697297072971729727297372974729757297672977729787297972980729817298272983729847298572986729877298872989729907299172992729937299472995729967299772998729997300073001730027300373004730057300673007730087300973010730117301273013730147301573016730177301873019730207302173022730237302473025730267302773028730297303073031730327303373034730357303673037730387303973040730417304273043730447304573046730477304873049730507305173052730537305473055730567305773058730597306073061730627306373064730657306673067730687306973070730717307273073730747307573076730777307873079730807308173082730837308473085730867308773088730897309073091730927309373094730957309673097730987309973100731017310273103731047310573106731077310873109731107311173112731137311473115731167311773118731197312073121731227312373124731257312673127731287312973130731317313273133731347313573136731377313873139731407314173142731437314473145731467314773148731497315073151731527315373154731557315673157731587315973160731617316273163731647316573166731677316873169731707317173172731737317473175731767317773178731797318073181731827318373184731857318673187731887318973190731917319273193731947319573196731977319873199732007320173202732037320473205732067320773208732097321073211732127321373214732157321673217732187321973220732217322273223732247322573226732277322873229732307323173232732337323473235732367323773238732397324073241732427324373244732457324673247732487324973250732517325273253732547325573256732577325873259732607326173262732637326473265732667326773268732697327073271732727327373274732757327673277732787327973280732817328273283732847328573286732877328873289732907329173292732937329473295732967329773298732997330073301733027330373304733057330673307733087330973310733117331273313733147331573316733177331873319733207332173322733237332473325733267332773328733297333073331733327333373334733357333673337733387333973340733417334273343733447334573346733477334873349733507335173352733537335473355733567335773358733597336073361733627336373364733657336673367733687336973370733717337273373733747337573376733777337873379733807338173382733837338473385733867338773388733897339073391733927339373394733957339673397733987339973400734017340273403734047340573406734077340873409734107341173412734137341473415734167341773418734197342073421734227342373424734257342673427734287342973430734317343273433734347343573436734377343873439734407344173442734437344473445734467344773448734497345073451734527345373454734557345673457734587345973460734617346273463734647346573466734677346873469734707347173472734737347473475734767347773478734797348073481734827348373484734857348673487734887348973490734917349273493734947349573496734977349873499735007350173502735037350473505735067350773508735097351073511735127351373514735157351673517735187351973520735217352273523735247352573526735277352873529735307353173532735337353473535735367353773538735397354073541735427354373544735457354673547735487354973550735517355273553735547355573556735577355873559735607356173562735637356473565735667356773568735697357073571735727357373574735757357673577735787357973580735817358273583735847358573586735877358873589735907359173592735937359473595735967359773598735997360073601736027360373604736057360673607736087360973610736117361273613736147361573616736177361873619736207362173622736237362473625736267362773628736297363073631736327363373634736357363673637736387363973640736417364273643736447364573646736477364873649736507365173652736537365473655736567365773658736597366073661736627366373664736657366673667736687366973670736717367273673736747367573676736777367873679736807368173682736837368473685736867368773688736897369073691736927369373694736957369673697736987369973700737017370273703737047370573706737077370873709737107371173712737137371473715737167371773718737197372073721737227372373724737257372673727737287372973730737317373273733737347373573736737377373873739737407374173742737437374473745737467374773748737497375073751737527375373754737557375673757737587375973760737617376273763737647376573766737677376873769737707377173772737737377473775737767377773778737797378073781737827378373784737857378673787737887378973790737917379273793737947379573796737977379873799738007380173802738037380473805738067380773808738097381073811738127381373814738157381673817738187381973820738217382273823738247382573826738277382873829738307383173832738337383473835738367383773838738397384073841738427384373844738457384673847738487384973850738517385273853738547385573856738577385873859738607386173862738637386473865738667386773868738697387073871738727387373874738757387673877738787387973880738817388273883738847388573886738877388873889738907389173892738937389473895738967389773898738997390073901739027390373904739057390673907739087390973910739117391273913739147391573916739177391873919739207392173922739237392473925739267392773928739297393073931739327393373934739357393673937739387393973940739417394273943739447394573946739477394873949739507395173952739537395473955739567395773958739597396073961739627396373964739657396673967739687396973970739717397273973739747397573976739777397873979739807398173982739837398473985739867398773988739897399073991739927399373994739957399673997739987399974000740017400274003740047400574006740077400874009740107401174012740137401474015740167401774018740197402074021740227402374024740257402674027740287402974030740317403274033740347403574036740377403874039740407404174042740437404474045740467404774048740497405074051740527405374054740557405674057740587405974060740617406274063740647406574066740677406874069740707407174072740737407474075740767407774078740797408074081740827408374084740857408674087740887408974090740917409274093740947409574096740977409874099741007410174102741037410474105741067410774108741097411074111741127411374114741157411674117741187411974120741217412274123741247412574126741277412874129741307413174132741337413474135741367413774138741397414074141741427414374144741457414674147741487414974150741517415274153741547415574156741577415874159741607416174162741637416474165741667416774168741697417074171741727417374174741757417674177741787417974180741817418274183741847418574186741877418874189741907419174192741937419474195741967419774198741997420074201742027420374204742057420674207742087420974210742117421274213742147421574216742177421874219742207422174222742237422474225742267422774228742297423074231742327423374234742357423674237742387423974240742417424274243742447424574246742477424874249742507425174252742537425474255742567425774258742597426074261742627426374264742657426674267742687426974270742717427274273742747427574276742777427874279742807428174282742837428474285742867428774288742897429074291742927429374294742957429674297742987429974300743017430274303743047430574306743077430874309743107431174312743137431474315743167431774318743197432074321743227432374324743257432674327743287432974330743317433274333743347433574336743377433874339743407434174342743437434474345743467434774348743497435074351743527435374354743557435674357743587435974360743617436274363743647436574366743677436874369743707437174372743737437474375743767437774378743797438074381743827438374384743857438674387743887438974390743917439274393743947439574396743977439874399744007440174402744037440474405744067440774408744097441074411744127441374414744157441674417744187441974420744217442274423744247442574426744277442874429744307443174432744337443474435744367443774438744397444074441744427444374444744457444674447744487444974450744517445274453744547445574456744577445874459744607446174462744637446474465744667446774468744697447074471744727447374474744757447674477744787447974480744817448274483744847448574486744877448874489744907449174492744937449474495744967449774498744997450074501745027450374504745057450674507745087450974510745117451274513745147451574516745177451874519745207452174522745237452474525745267452774528745297453074531745327453374534745357453674537745387453974540745417454274543745447454574546745477454874549745507455174552745537455474555745567455774558745597456074561745627456374564745657456674567745687456974570745717457274573745747457574576745777457874579745807458174582745837458474585745867458774588745897459074591745927459374594745957459674597745987459974600746017460274603746047460574606746077460874609746107461174612746137461474615746167461774618746197462074621746227462374624746257462674627746287462974630746317463274633746347463574636746377463874639746407464174642746437464474645746467464774648746497465074651746527465374654746557465674657746587465974660746617466274663746647466574666746677466874669746707467174672746737467474675746767467774678746797468074681746827468374684746857468674687746887468974690746917469274693746947469574696746977469874699747007470174702747037470474705747067470774708747097471074711747127471374714747157471674717747187471974720747217472274723747247472574726747277472874729747307473174732747337473474735747367473774738747397474074741747427474374744747457474674747747487474974750747517475274753747547475574756747577475874759747607476174762747637476474765747667476774768747697477074771747727477374774747757477674777747787477974780747817478274783747847478574786747877478874789747907479174792747937479474795747967479774798747997480074801748027480374804748057480674807748087480974810748117481274813748147481574816748177481874819748207482174822748237482474825748267482774828748297483074831748327483374834748357483674837748387483974840748417484274843748447484574846748477484874849748507485174852748537485474855748567485774858748597486074861748627486374864748657486674867748687486974870748717487274873748747487574876748777487874879748807488174882748837488474885748867488774888748897489074891748927489374894748957489674897748987489974900749017490274903749047490574906749077490874909749107491174912749137491474915749167491774918749197492074921749227492374924749257492674927749287492974930749317493274933749347493574936749377493874939749407494174942749437494474945749467494774948749497495074951749527495374954749557495674957749587495974960749617496274963749647496574966749677496874969749707497174972749737497474975749767497774978749797498074981749827498374984749857498674987749887498974990749917499274993749947499574996749977499874999750007500175002750037500475005750067500775008750097501075011750127501375014750157501675017750187501975020750217502275023750247502575026750277502875029750307503175032750337503475035750367503775038750397504075041750427504375044750457504675047750487504975050750517505275053750547505575056750577505875059750607506175062750637506475065750667506775068750697507075071750727507375074750757507675077750787507975080750817508275083750847508575086750877508875089750907509175092750937509475095750967509775098750997510075101751027510375104751057510675107751087510975110751117511275113751147511575116751177511875119751207512175122751237512475125751267512775128751297513075131751327513375134751357513675137751387513975140751417514275143751447514575146751477514875149751507515175152751537515475155751567515775158751597516075161751627516375164751657516675167751687516975170751717517275173751747517575176751777517875179751807518175182751837518475185751867518775188751897519075191751927519375194751957519675197751987519975200752017520275203752047520575206752077520875209752107521175212752137521475215752167521775218752197522075221752227522375224752257522675227752287522975230752317523275233752347523575236752377523875239752407524175242752437524475245752467524775248752497525075251752527525375254752557525675257752587525975260752617526275263752647526575266752677526875269752707527175272752737527475275752767527775278752797528075281752827528375284752857528675287752887528975290752917529275293752947529575296752977529875299753007530175302753037530475305753067530775308753097531075311753127531375314753157531675317753187531975320753217532275323753247532575326753277532875329753307533175332753337533475335753367533775338753397534075341753427534375344753457534675347753487534975350753517535275353753547535575356753577535875359753607536175362753637536475365753667536775368753697537075371753727537375374753757537675377753787537975380753817538275383753847538575386753877538875389753907539175392753937539475395753967539775398753997540075401754027540375404754057540675407754087540975410754117541275413754147541575416754177541875419754207542175422754237542475425754267542775428754297543075431754327543375434754357543675437754387543975440754417544275443754447544575446754477544875449754507545175452754537545475455754567545775458754597546075461754627546375464754657546675467754687546975470754717547275473754747547575476754777547875479754807548175482754837548475485754867548775488754897549075491754927549375494754957549675497754987549975500755017550275503755047550575506755077550875509755107551175512755137551475515755167551775518755197552075521755227552375524755257552675527755287552975530755317553275533755347553575536755377553875539755407554175542755437554475545755467554775548755497555075551755527555375554755557555675557755587555975560755617556275563755647556575566755677556875569755707557175572755737557475575755767557775578755797558075581755827558375584755857558675587755887558975590755917559275593755947559575596755977559875599756007560175602756037560475605756067560775608756097561075611756127561375614756157561675617756187561975620756217562275623756247562575626756277562875629756307563175632756337563475635756367563775638756397564075641756427564375644756457564675647756487564975650756517565275653756547565575656756577565875659756607566175662756637566475665756667566775668756697567075671756727567375674756757567675677756787567975680756817568275683756847568575686756877568875689756907569175692756937569475695756967569775698756997570075701757027570375704757057570675707757087570975710757117571275713757147571575716757177571875719757207572175722757237572475725757267572775728757297573075731757327573375734757357573675737757387573975740757417574275743757447574575746757477574875749757507575175752757537575475755757567575775758757597576075761757627576375764757657576675767757687576975770757717577275773757747577575776757777577875779757807578175782757837578475785757867578775788757897579075791757927579375794757957579675797757987579975800758017580275803758047580575806758077580875809758107581175812758137581475815758167581775818758197582075821758227582375824758257582675827758287582975830758317583275833758347583575836758377583875839758407584175842758437584475845758467584775848758497585075851758527585375854758557585675857758587585975860758617586275863758647586575866758677586875869758707587175872758737587475875758767587775878758797588075881758827588375884758857588675887758887588975890758917589275893758947589575896758977589875899759007590175902759037590475905759067590775908759097591075911759127591375914759157591675917759187591975920759217592275923759247592575926759277592875929759307593175932759337593475935759367593775938759397594075941759427594375944759457594675947759487594975950759517595275953759547595575956759577595875959759607596175962759637596475965759667596775968759697597075971759727597375974759757597675977759787597975980759817598275983759847598575986759877598875989759907599175992759937599475995759967599775998759997600076001760027600376004760057600676007760087600976010760117601276013760147601576016760177601876019760207602176022760237602476025760267602776028760297603076031760327603376034760357603676037760387603976040760417604276043760447604576046760477604876049760507605176052760537605476055760567605776058760597606076061760627606376064760657606676067760687606976070760717607276073760747607576076760777607876079760807608176082760837608476085760867608776088760897609076091760927609376094760957609676097760987609976100761017610276103761047610576106761077610876109761107611176112761137611476115761167611776118761197612076121761227612376124761257612676127761287612976130761317613276133761347613576136761377613876139761407614176142761437614476145761467614776148761497615076151761527615376154761557615676157761587615976160761617616276163761647616576166761677616876169761707617176172761737617476175761767617776178761797618076181761827618376184761857618676187761887618976190761917619276193761947619576196761977619876199762007620176202762037620476205762067620776208762097621076211762127621376214762157621676217762187621976220762217622276223762247622576226762277622876229762307623176232762337623476235762367623776238762397624076241762427624376244762457624676247762487624976250762517625276253762547625576256762577625876259762607626176262762637626476265762667626776268762697627076271762727627376274762757627676277762787627976280762817628276283762847628576286762877628876289762907629176292762937629476295762967629776298762997630076301763027630376304763057630676307763087630976310763117631276313763147631576316763177631876319763207632176322763237632476325763267632776328763297633076331763327633376334763357633676337763387633976340763417634276343763447634576346763477634876349763507635176352763537635476355763567635776358763597636076361763627636376364763657636676367763687636976370763717637276373763747637576376763777637876379763807638176382763837638476385763867638776388763897639076391763927639376394763957639676397763987639976400764017640276403764047640576406764077640876409764107641176412764137641476415764167641776418764197642076421764227642376424764257642676427764287642976430764317643276433764347643576436764377643876439764407644176442764437644476445764467644776448764497645076451764527645376454764557645676457764587645976460764617646276463764647646576466764677646876469764707647176472764737647476475764767647776478764797648076481764827648376484764857648676487764887648976490764917649276493764947649576496764977649876499765007650176502765037650476505765067650776508765097651076511765127651376514765157651676517765187651976520765217652276523765247652576526765277652876529765307653176532765337653476535765367653776538765397654076541765427654376544765457654676547765487654976550765517655276553765547655576556765577655876559765607656176562765637656476565765667656776568765697657076571765727657376574765757657676577765787657976580765817658276583765847658576586765877658876589765907659176592765937659476595765967659776598765997660076601766027660376604766057660676607766087660976610766117661276613766147661576616766177661876619766207662176622766237662476625766267662776628766297663076631766327663376634766357663676637766387663976640766417664276643766447664576646766477664876649766507665176652766537665476655766567665776658766597666076661766627666376664766657666676667766687666976670766717667276673766747667576676766777667876679766807668176682766837668476685766867668776688766897669076691766927669376694766957669676697766987669976700767017670276703767047670576706767077670876709767107671176712767137671476715767167671776718767197672076721767227672376724767257672676727767287672976730767317673276733767347673576736767377673876739767407674176742767437674476745767467674776748767497675076751767527675376754767557675676757767587675976760767617676276763767647676576766767677676876769767707677176772767737677476775767767677776778767797678076781767827678376784767857678676787767887678976790767917679276793767947679576796767977679876799768007680176802768037680476805768067680776808768097681076811768127681376814768157681676817768187681976820768217682276823768247682576826768277682876829768307683176832768337683476835768367683776838768397684076841768427684376844768457684676847768487684976850768517685276853768547685576856768577685876859768607686176862768637686476865768667686776868768697687076871768727687376874768757687676877768787687976880768817688276883768847688576886768877688876889768907689176892768937689476895768967689776898768997690076901769027690376904769057690676907769087690976910769117691276913769147691576916769177691876919769207692176922769237692476925769267692776928769297693076931769327693376934769357693676937769387693976940769417694276943769447694576946769477694876949769507695176952769537695476955769567695776958769597696076961769627696376964769657696676967769687696976970769717697276973769747697576976769777697876979769807698176982769837698476985769867698776988769897699076991769927699376994769957699676997769987699977000770017700277003770047700577006770077700877009770107701177012770137701477015770167701777018770197702077021770227702377024770257702677027770287702977030770317703277033770347703577036770377703877039770407704177042770437704477045770467704777048770497705077051770527705377054770557705677057770587705977060770617706277063770647706577066770677706877069770707707177072770737707477075770767707777078770797708077081770827708377084770857708677087770887708977090770917709277093770947709577096770977709877099771007710177102771037710477105771067710777108771097711077111771127711377114771157711677117771187711977120771217712277123771247712577126771277712877129771307713177132771337713477135771367713777138771397714077141771427714377144771457714677147771487714977150771517715277153771547715577156771577715877159771607716177162771637716477165771667716777168771697717077171771727717377174771757717677177771787717977180771817718277183771847718577186771877718877189771907719177192771937719477195771967719777198771997720077201772027720377204772057720677207772087720977210772117721277213772147721577216772177721877219772207722177222772237722477225772267722777228772297723077231772327723377234772357723677237772387723977240772417724277243772447724577246772477724877249772507725177252772537725477255772567725777258772597726077261772627726377264772657726677267772687726977270772717727277273772747727577276772777727877279772807728177282772837728477285772867728777288772897729077291772927729377294772957729677297772987729977300773017730277303773047730577306773077730877309773107731177312773137731477315773167731777318773197732077321773227732377324773257732677327773287732977330773317733277333773347733577336773377733877339773407734177342773437734477345773467734777348773497735077351773527735377354773557735677357773587735977360773617736277363773647736577366773677736877369773707737177372773737737477375773767737777378773797738077381773827738377384773857738677387773887738977390773917739277393773947739577396773977739877399774007740177402774037740477405774067740777408774097741077411774127741377414774157741677417774187741977420774217742277423774247742577426774277742877429774307743177432774337743477435774367743777438774397744077441774427744377444774457744677447774487744977450774517745277453774547745577456774577745877459774607746177462774637746477465774667746777468774697747077471774727747377474774757747677477774787747977480774817748277483774847748577486774877748877489774907749177492774937749477495774967749777498774997750077501775027750377504775057750677507775087750977510775117751277513775147751577516775177751877519775207752177522775237752477525775267752777528775297753077531775327753377534775357753677537775387753977540775417754277543775447754577546775477754877549775507755177552775537755477555775567755777558775597756077561775627756377564775657756677567775687756977570775717757277573775747757577576775777757877579775807758177582775837758477585775867758777588775897759077591775927759377594775957759677597775987759977600776017760277603776047760577606776077760877609776107761177612776137761477615776167761777618776197762077621776227762377624776257762677627776287762977630776317763277633776347763577636776377763877639776407764177642776437764477645776467764777648776497765077651776527765377654776557765677657776587765977660776617766277663776647766577666776677766877669776707767177672776737767477675776767767777678776797768077681776827768377684776857768677687776887768977690776917769277693776947769577696776977769877699777007770177702777037770477705777067770777708777097771077711777127771377714777157771677717777187771977720777217772277723777247772577726777277772877729777307773177732777337773477735777367773777738777397774077741777427774377744777457774677747777487774977750777517775277753777547775577756777577775877759777607776177762777637776477765777667776777768777697777077771777727777377774777757777677777777787777977780777817778277783777847778577786777877778877789777907779177792777937779477795777967779777798777997780077801778027780377804778057780677807778087780977810778117781277813778147781577816778177781877819778207782177822778237782477825778267782777828778297783077831778327783377834778357783677837778387783977840778417784277843778447784577846778477784877849778507785177852778537785477855778567785777858778597786077861778627786377864778657786677867778687786977870778717787277873778747787577876778777787877879778807788177882778837788477885778867788777888778897789077891778927789377894778957789677897778987789977900779017790277903779047790577906779077790877909779107791177912779137791477915779167791777918779197792077921779227792377924779257792677927779287792977930779317793277933779347793577936779377793877939779407794177942779437794477945779467794777948779497795077951779527795377954779557795677957779587795977960779617796277963779647796577966779677796877969779707797177972779737797477975779767797777978779797798077981779827798377984779857798677987779887798977990779917799277993779947799577996779977799877999780007800178002780037800478005780067800778008780097801078011780127801378014780157801678017780187801978020780217802278023780247802578026780277802878029780307803178032780337803478035780367803778038780397804078041780427804378044780457804678047780487804978050780517805278053780547805578056780577805878059780607806178062780637806478065780667806778068780697807078071780727807378074780757807678077780787807978080780817808278083780847808578086780877808878089780907809178092780937809478095780967809778098780997810078101781027810378104781057810678107781087810978110781117811278113781147811578116781177811878119781207812178122781237812478125781267812778128781297813078131781327813378134781357813678137781387813978140781417814278143781447814578146781477814878149781507815178152781537815478155781567815778158781597816078161781627816378164781657816678167781687816978170781717817278173781747817578176781777817878179781807818178182781837818478185781867818778188781897819078191781927819378194781957819678197781987819978200782017820278203782047820578206782077820878209782107821178212782137821478215782167821778218782197822078221782227822378224782257822678227782287822978230782317823278233782347823578236782377823878239782407824178242782437824478245782467824778248782497825078251782527825378254782557825678257782587825978260782617826278263782647826578266782677826878269782707827178272782737827478275782767827778278782797828078281782827828378284782857828678287782887828978290782917829278293782947829578296782977829878299783007830178302783037830478305783067830778308783097831078311783127831378314783157831678317783187831978320783217832278323783247832578326783277832878329783307833178332783337833478335783367833778338783397834078341783427834378344783457834678347783487834978350783517835278353783547835578356783577835878359783607836178362783637836478365783667836778368783697837078371783727837378374783757837678377783787837978380783817838278383783847838578386783877838878389783907839178392783937839478395783967839778398783997840078401784027840378404784057840678407784087840978410784117841278413784147841578416784177841878419784207842178422784237842478425784267842778428784297843078431784327843378434784357843678437784387843978440784417844278443784447844578446784477844878449784507845178452784537845478455784567845778458784597846078461784627846378464784657846678467784687846978470784717847278473784747847578476784777847878479784807848178482784837848478485784867848778488784897849078491784927849378494784957849678497784987849978500785017850278503785047850578506785077850878509785107851178512785137851478515785167851778518785197852078521785227852378524785257852678527785287852978530785317853278533785347853578536785377853878539785407854178542785437854478545785467854778548785497855078551785527855378554785557855678557785587855978560785617856278563785647856578566785677856878569785707857178572785737857478575785767857778578785797858078581785827858378584785857858678587785887858978590785917859278593785947859578596785977859878599786007860178602786037860478605786067860778608786097861078611786127861378614786157861678617786187861978620786217862278623786247862578626786277862878629786307863178632786337863478635786367863778638786397864078641786427864378644786457864678647786487864978650786517865278653786547865578656786577865878659786607866178662786637866478665786667866778668786697867078671786727867378674786757867678677786787867978680786817868278683786847868578686786877868878689786907869178692786937869478695786967869778698786997870078701787027870378704787057870678707787087870978710787117871278713787147871578716787177871878719787207872178722787237872478725787267872778728787297873078731787327873378734787357873678737787387873978740787417874278743787447874578746787477874878749787507875178752787537875478755787567875778758787597876078761787627876378764787657876678767787687876978770787717877278773787747877578776787777877878779787807878178782787837878478785787867878778788787897879078791787927879378794787957879678797787987879978800788017880278803788047880578806788077880878809788107881178812788137881478815788167881778818788197882078821788227882378824788257882678827788287882978830788317883278833788347883578836788377883878839788407884178842788437884478845788467884778848788497885078851788527885378854788557885678857788587885978860788617886278863788647886578866788677886878869788707887178872788737887478875788767887778878788797888078881788827888378884788857888678887788887888978890788917889278893788947889578896788977889878899789007890178902789037890478905789067890778908789097891078911789127891378914789157891678917789187891978920789217892278923789247892578926789277892878929789307893178932789337893478935789367893778938789397894078941789427894378944789457894678947789487894978950789517895278953789547895578956789577895878959789607896178962789637896478965789667896778968789697897078971789727897378974789757897678977789787897978980789817898278983789847898578986789877898878989789907899178992789937899478995789967899778998789997900079001790027900379004790057900679007790087900979010790117901279013790147901579016790177901879019790207902179022790237902479025790267902779028790297903079031790327903379034790357903679037790387903979040790417904279043790447904579046790477904879049790507905179052790537905479055790567905779058790597906079061790627906379064790657906679067790687906979070790717907279073790747907579076790777907879079790807908179082790837908479085790867908779088790897909079091790927909379094790957909679097790987909979100791017910279103791047910579106791077910879109791107911179112791137911479115791167911779118791197912079121791227912379124791257912679127791287912979130791317913279133791347913579136791377913879139791407914179142791437914479145791467914779148791497915079151791527915379154791557915679157791587915979160791617916279163791647916579166791677916879169791707917179172791737917479175791767917779178791797918079181791827918379184791857918679187791887918979190791917919279193791947919579196791977919879199792007920179202792037920479205792067920779208792097921079211792127921379214792157921679217792187921979220792217922279223792247922579226792277922879229792307923179232792337923479235792367923779238792397924079241792427924379244792457924679247792487924979250792517925279253792547925579256792577925879259792607926179262792637926479265792667926779268792697927079271792727927379274792757927679277792787927979280792817928279283792847928579286792877928879289792907929179292792937929479295792967929779298792997930079301793027930379304793057930679307793087930979310793117931279313793147931579316793177931879319793207932179322793237932479325793267932779328793297933079331793327933379334793357933679337793387933979340793417934279343793447934579346793477934879349793507935179352793537935479355793567935779358793597936079361793627936379364793657936679367793687936979370793717937279373793747937579376793777937879379793807938179382793837938479385793867938779388793897939079391793927939379394793957939679397793987939979400794017940279403794047940579406794077940879409794107941179412794137941479415794167941779418794197942079421794227942379424794257942679427794287942979430794317943279433794347943579436794377943879439794407944179442794437944479445794467944779448794497945079451794527945379454794557945679457794587945979460794617946279463794647946579466794677946879469794707947179472794737947479475794767947779478794797948079481794827948379484794857948679487794887948979490794917949279493794947949579496794977949879499795007950179502795037950479505795067950779508795097951079511795127951379514795157951679517795187951979520795217952279523795247952579526795277952879529795307953179532795337953479535795367953779538795397954079541795427954379544795457954679547795487954979550795517955279553795547955579556795577955879559795607956179562795637956479565795667956779568795697957079571795727957379574795757957679577795787957979580795817958279583795847958579586795877958879589795907959179592795937959479595795967959779598795997960079601796027960379604796057960679607796087960979610796117961279613796147961579616796177961879619796207962179622796237962479625796267962779628796297963079631796327963379634796357963679637796387963979640796417964279643796447964579646796477964879649796507965179652796537965479655796567965779658796597966079661796627966379664796657966679667796687966979670796717967279673796747967579676796777967879679796807968179682796837968479685796867968779688796897969079691796927969379694796957969679697796987969979700797017970279703797047970579706797077970879709797107971179712797137971479715797167971779718797197972079721797227972379724797257972679727797287972979730797317973279733797347973579736797377973879739797407974179742797437974479745797467974779748797497975079751797527975379754797557975679757797587975979760797617976279763797647976579766797677976879769797707977179772797737977479775797767977779778797797978079781797827978379784797857978679787797887978979790797917979279793797947979579796797977979879799798007980179802798037980479805798067980779808798097981079811798127981379814798157981679817798187981979820798217982279823798247982579826798277982879829798307983179832798337983479835798367983779838798397984079841798427984379844798457984679847798487984979850798517985279853798547985579856798577985879859798607986179862798637986479865798667986779868798697987079871798727987379874798757987679877798787987979880798817988279883798847988579886798877988879889798907989179892798937989479895798967989779898798997990079901799027990379904799057990679907799087990979910799117991279913799147991579916799177991879919799207992179922799237992479925799267992779928799297993079931799327993379934799357993679937799387993979940799417994279943799447994579946799477994879949799507995179952799537995479955799567995779958799597996079961799627996379964799657996679967799687996979970799717997279973799747997579976799777997879979799807998179982799837998479985799867998779988799897999079991799927999379994799957999679997799987999980000800018000280003800048000580006800078000880009800108001180012800138001480015800168001780018800198002080021800228002380024800258002680027800288002980030800318003280033800348003580036800378003880039800408004180042800438004480045800468004780048800498005080051800528005380054800558005680057800588005980060800618006280063800648006580066800678006880069800708007180072800738007480075800768007780078800798008080081800828008380084800858008680087800888008980090800918009280093800948009580096800978009880099801008010180102801038010480105801068010780108801098011080111801128011380114801158011680117801188011980120801218012280123801248012580126801278012880129801308013180132801338013480135801368013780138801398014080141801428014380144801458014680147801488014980150801518015280153801548015580156801578015880159801608016180162801638016480165801668016780168801698017080171801728017380174801758017680177801788017980180801818018280183801848018580186801878018880189801908019180192801938019480195801968019780198801998020080201802028020380204802058020680207802088020980210802118021280213802148021580216802178021880219802208022180222802238022480225802268022780228802298023080231802328023380234802358023680237802388023980240802418024280243802448024580246802478024880249802508025180252802538025480255802568025780258802598026080261802628026380264802658026680267802688026980270802718027280273802748027580276802778027880279802808028180282802838028480285802868028780288802898029080291802928029380294802958029680297802988029980300803018030280303803048030580306803078030880309803108031180312803138031480315803168031780318803198032080321803228032380324803258032680327803288032980330803318033280333803348033580336803378033880339803408034180342803438034480345803468034780348803498035080351803528035380354803558035680357803588035980360803618036280363803648036580366803678036880369803708037180372803738037480375803768037780378803798038080381803828038380384803858038680387803888038980390803918039280393803948039580396803978039880399804008040180402804038040480405804068040780408804098041080411804128041380414804158041680417804188041980420804218042280423804248042580426804278042880429804308043180432804338043480435804368043780438804398044080441804428044380444804458044680447804488044980450804518045280453804548045580456804578045880459804608046180462804638046480465804668046780468804698047080471804728047380474804758047680477804788047980480804818048280483804848048580486804878048880489804908049180492804938049480495804968049780498804998050080501805028050380504805058050680507805088050980510805118051280513805148051580516805178051880519805208052180522805238052480525805268052780528805298053080531805328053380534805358053680537805388053980540805418054280543805448054580546805478054880549805508055180552805538055480555805568055780558805598056080561805628056380564805658056680567805688056980570805718057280573805748057580576805778057880579805808058180582805838058480585805868058780588805898059080591805928059380594805958059680597805988059980600806018060280603806048060580606806078060880609806108061180612806138061480615806168061780618806198062080621806228062380624806258062680627806288062980630806318063280633806348063580636806378063880639806408064180642806438064480645806468064780648806498065080651806528065380654806558065680657806588065980660806618066280663806648066580666806678066880669806708067180672806738067480675806768067780678806798068080681806828068380684806858068680687806888068980690806918069280693806948069580696806978069880699807008070180702807038070480705807068070780708807098071080711807128071380714807158071680717807188071980720807218072280723807248072580726807278072880729807308073180732807338073480735807368073780738807398074080741807428074380744807458074680747807488074980750807518075280753807548075580756807578075880759807608076180762807638076480765807668076780768807698077080771807728077380774807758077680777807788077980780807818078280783807848078580786807878078880789807908079180792807938079480795807968079780798807998080080801808028080380804808058080680807808088080980810808118081280813808148081580816808178081880819808208082180822808238082480825808268082780828808298083080831808328083380834808358083680837808388083980840808418084280843808448084580846808478084880849808508085180852808538085480855808568085780858808598086080861808628086380864808658086680867808688086980870808718087280873808748087580876808778087880879808808088180882808838088480885808868088780888808898089080891808928089380894808958089680897808988089980900809018090280903809048090580906809078090880909809108091180912809138091480915809168091780918809198092080921809228092380924809258092680927809288092980930809318093280933809348093580936809378093880939809408094180942809438094480945809468094780948809498095080951809528095380954809558095680957809588095980960809618096280963809648096580966809678096880969809708097180972809738097480975809768097780978809798098080981809828098380984809858098680987809888098980990809918099280993809948099580996809978099880999810008100181002810038100481005810068100781008810098101081011810128101381014810158101681017810188101981020810218102281023810248102581026810278102881029810308103181032810338103481035810368103781038810398104081041810428104381044810458104681047810488104981050810518105281053810548105581056810578105881059810608106181062810638106481065810668106781068810698107081071810728107381074810758107681077810788107981080810818108281083810848108581086810878108881089810908109181092810938109481095810968109781098810998110081101811028110381104811058110681107811088110981110811118111281113811148111581116811178111881119811208112181122811238112481125811268112781128811298113081131811328113381134811358113681137811388113981140811418114281143811448114581146811478114881149811508115181152811538115481155811568115781158811598116081161811628116381164811658116681167811688116981170811718117281173811748117581176811778117881179811808118181182811838118481185811868118781188811898119081191811928119381194811958119681197811988119981200812018120281203812048120581206812078120881209812108121181212812138121481215812168121781218812198122081221812228122381224812258122681227812288122981230812318123281233812348123581236812378123881239812408124181242812438124481245812468124781248812498125081251812528125381254812558125681257812588125981260812618126281263812648126581266812678126881269812708127181272812738127481275812768127781278812798128081281812828128381284812858128681287812888128981290812918129281293812948129581296812978129881299813008130181302813038130481305813068130781308813098131081311813128131381314813158131681317813188131981320813218132281323813248132581326813278132881329813308133181332813338133481335813368133781338813398134081341813428134381344813458134681347813488134981350813518135281353813548135581356813578135881359813608136181362813638136481365813668136781368813698137081371813728137381374813758137681377813788137981380813818138281383813848138581386813878138881389813908139181392813938139481395813968139781398813998140081401814028140381404814058140681407814088140981410814118141281413814148141581416814178141881419814208142181422814238142481425814268142781428814298143081431814328143381434814358143681437814388143981440814418144281443814448144581446814478144881449814508145181452814538145481455814568145781458814598146081461814628146381464814658146681467814688146981470814718147281473814748147581476814778147881479814808148181482814838148481485814868148781488814898149081491814928149381494814958149681497814988149981500815018150281503815048150581506815078150881509815108151181512815138151481515815168151781518815198152081521815228152381524815258152681527815288152981530815318153281533815348153581536815378153881539815408154181542815438154481545815468154781548815498155081551815528155381554815558155681557815588155981560815618156281563815648156581566815678156881569815708157181572815738157481575815768157781578815798158081581815828158381584815858158681587815888158981590815918159281593815948159581596815978159881599816008160181602816038160481605816068160781608816098161081611816128161381614816158161681617816188161981620816218162281623816248162581626816278162881629816308163181632816338163481635816368163781638816398164081641816428164381644816458164681647816488164981650816518165281653816548165581656816578165881659816608166181662816638166481665816668166781668816698167081671816728167381674816758167681677816788167981680816818168281683816848168581686816878168881689816908169181692816938169481695816968169781698816998170081701817028170381704817058170681707817088170981710817118171281713817148171581716817178171881719817208172181722817238172481725817268172781728817298173081731817328173381734817358173681737817388173981740817418174281743817448174581746817478174881749817508175181752817538175481755817568175781758817598176081761817628176381764817658176681767817688176981770817718177281773817748177581776817778177881779817808178181782817838178481785817868178781788817898179081791817928179381794817958179681797817988179981800818018180281803818048180581806818078180881809818108181181812818138181481815818168181781818818198182081821818228182381824818258182681827818288182981830818318183281833818348183581836818378183881839818408184181842818438184481845818468184781848818498185081851818528185381854818558185681857818588185981860818618186281863818648186581866818678186881869818708187181872818738187481875818768187781878818798188081881818828188381884818858188681887818888188981890818918189281893818948189581896818978189881899819008190181902819038190481905819068190781908819098191081911819128191381914819158191681917819188191981920819218192281923819248192581926819278192881929819308193181932819338193481935819368193781938819398194081941819428194381944819458194681947819488194981950819518195281953819548195581956819578195881959819608196181962819638196481965819668196781968819698197081971819728197381974819758197681977819788197981980819818198281983819848198581986819878198881989819908199181992819938199481995819968199781998819998200082001820028200382004820058200682007820088200982010820118201282013820148201582016820178201882019820208202182022820238202482025820268202782028820298203082031820328203382034820358203682037820388203982040820418204282043820448204582046820478204882049820508205182052820538205482055820568205782058820598206082061820628206382064820658206682067820688206982070820718207282073820748207582076820778207882079820808208182082820838208482085820868208782088820898209082091820928209382094820958209682097820988209982100821018210282103821048210582106821078210882109821108211182112821138211482115821168211782118821198212082121821228212382124821258212682127821288212982130821318213282133821348213582136821378213882139821408214182142821438214482145821468214782148821498215082151821528215382154821558215682157821588215982160821618216282163821648216582166821678216882169821708217182172821738217482175821768217782178821798218082181821828218382184821858218682187821888218982190821918219282193821948219582196821978219882199822008220182202822038220482205822068220782208822098221082211822128221382214822158221682217822188221982220822218222282223822248222582226822278222882229822308223182232822338223482235822368223782238822398224082241822428224382244822458224682247822488224982250822518225282253822548225582256822578225882259822608226182262822638226482265822668226782268822698227082271822728227382274822758227682277822788227982280822818228282283822848228582286822878228882289822908229182292822938229482295822968229782298822998230082301823028230382304823058230682307823088230982310823118231282313823148231582316823178231882319823208232182322823238232482325823268232782328823298233082331823328233382334823358233682337823388233982340823418234282343823448234582346823478234882349823508235182352823538235482355823568235782358823598236082361823628236382364823658236682367823688236982370823718237282373823748237582376823778237882379823808238182382823838238482385823868238782388823898239082391823928239382394823958239682397823988239982400824018240282403824048240582406824078240882409824108241182412824138241482415824168241782418824198242082421824228242382424824258242682427824288242982430824318243282433824348243582436824378243882439824408244182442824438244482445824468244782448824498245082451824528245382454824558245682457824588245982460824618246282463824648246582466824678246882469824708247182472824738247482475824768247782478824798248082481824828248382484824858248682487824888248982490824918249282493824948249582496824978249882499825008250182502825038250482505825068250782508825098251082511825128251382514825158251682517825188251982520825218252282523825248252582526825278252882529825308253182532825338253482535825368253782538825398254082541825428254382544825458254682547825488254982550825518255282553825548255582556825578255882559825608256182562825638256482565825668256782568825698257082571825728257382574825758257682577825788257982580825818258282583825848258582586825878258882589825908259182592825938259482595825968259782598825998260082601826028260382604826058260682607826088260982610826118261282613826148261582616826178261882619826208262182622826238262482625826268262782628826298263082631826328263382634826358263682637826388263982640826418264282643826448264582646826478264882649826508265182652826538265482655826568265782658826598266082661826628266382664826658266682667826688266982670826718267282673826748267582676826778267882679826808268182682826838268482685826868268782688826898269082691826928269382694826958269682697826988269982700827018270282703827048270582706827078270882709827108271182712827138271482715827168271782718827198272082721827228272382724827258272682727827288272982730827318273282733827348273582736827378273882739827408274182742827438274482745827468274782748827498275082751827528275382754827558275682757827588275982760827618276282763827648276582766827678276882769827708277182772827738277482775827768277782778827798278082781827828278382784827858278682787827888278982790827918279282793827948279582796827978279882799828008280182802828038280482805828068280782808828098281082811828128281382814828158281682817828188281982820828218282282823828248282582826828278282882829828308283182832828338283482835828368283782838828398284082841828428284382844828458284682847828488284982850828518285282853828548285582856828578285882859828608286182862828638286482865828668286782868828698287082871828728287382874828758287682877828788287982880828818288282883828848288582886828878288882889828908289182892828938289482895828968289782898828998290082901829028290382904829058290682907829088290982910829118291282913829148291582916829178291882919829208292182922829238292482925829268292782928829298293082931829328293382934829358293682937829388293982940829418294282943829448294582946829478294882949829508295182952829538295482955829568295782958829598296082961829628296382964829658296682967829688296982970829718297282973829748297582976829778297882979829808298182982829838298482985829868298782988829898299082991829928299382994829958299682997829988299983000830018300283003830048300583006830078300883009830108301183012830138301483015830168301783018830198302083021830228302383024830258302683027830288302983030830318303283033830348303583036830378303883039830408304183042830438304483045830468304783048830498305083051830528305383054830558305683057830588305983060830618306283063830648306583066830678306883069830708307183072830738307483075830768307783078830798308083081830828308383084830858308683087830888308983090830918309283093830948309583096830978309883099831008310183102831038310483105831068310783108831098311083111831128311383114831158311683117831188311983120831218312283123831248312583126831278312883129831308313183132831338313483135831368313783138831398314083141831428314383144831458314683147831488314983150831518315283153831548315583156831578315883159831608316183162831638316483165831668316783168831698317083171831728317383174831758317683177831788317983180831818318283183831848318583186831878318883189831908319183192831938319483195831968319783198831998320083201832028320383204832058320683207832088320983210832118321283213832148321583216832178321883219832208322183222832238322483225832268322783228832298323083231832328323383234832358323683237832388323983240832418324283243832448324583246832478324883249832508325183252832538325483255832568325783258832598326083261832628326383264832658326683267832688326983270832718327283273832748327583276832778327883279832808328183282832838328483285832868328783288832898329083291832928329383294832958329683297832988329983300833018330283303833048330583306833078330883309833108331183312833138331483315833168331783318833198332083321833228332383324833258332683327833288332983330833318333283333833348333583336833378333883339833408334183342833438334483345833468334783348833498335083351833528335383354833558335683357833588335983360833618336283363833648336583366833678336883369833708337183372833738337483375833768337783378833798338083381833828338383384833858338683387833888338983390833918339283393833948339583396833978339883399834008340183402834038340483405834068340783408834098341083411834128341383414834158341683417834188341983420834218342283423834248342583426834278342883429834308343183432834338343483435834368343783438834398344083441834428344383444834458344683447834488344983450834518345283453834548345583456834578345883459834608346183462834638346483465834668346783468834698347083471834728347383474834758347683477834788347983480834818348283483834848348583486834878348883489834908349183492834938349483495834968349783498834998350083501835028350383504835058350683507835088350983510835118351283513835148351583516835178351883519835208352183522835238352483525835268352783528835298353083531835328353383534835358353683537835388353983540835418354283543835448354583546835478354883549835508355183552835538355483555835568355783558835598356083561835628356383564835658356683567835688356983570835718357283573835748357583576835778357883579835808358183582835838358483585835868358783588835898359083591835928359383594835958359683597835988359983600836018360283603836048360583606
  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. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  4. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
  5. function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
  6. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  8. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9. var fs = require('fs');
  10. var fastCsv = require('fast-csv');
  11. var customParseFormat = require('dayjs/plugin/customParseFormat');
  12. var utc = require('dayjs/plugin/utc');
  13. var dayjs = require('dayjs').extend(customParseFormat).extend(utc);
  14. var StreamBuf = require('../utils/stream-buf');
  15. var _require = require('../utils/utils'),
  16. exists = _require.fs.exists;
  17. /* eslint-disable quote-props */
  18. var SpecialValues = {
  19. true: true,
  20. false: false,
  21. '#N/A': {
  22. error: '#N/A'
  23. },
  24. '#REF!': {
  25. error: '#REF!'
  26. },
  27. '#NAME?': {
  28. error: '#NAME?'
  29. },
  30. '#DIV/0!': {
  31. error: '#DIV/0!'
  32. },
  33. '#NULL!': {
  34. error: '#NULL!'
  35. },
  36. '#VALUE!': {
  37. error: '#VALUE!'
  38. },
  39. '#NUM!': {
  40. error: '#NUM!'
  41. }
  42. };
  43. /* eslint-ensable quote-props */
  44. var CSV = /*#__PURE__*/function () {
  45. function CSV(workbook) {
  46. _classCallCheck(this, CSV);
  47. this.workbook = workbook;
  48. this.worksheet = null;
  49. }
  50. _createClass(CSV, [{
  51. key: "readFile",
  52. value: function () {
  53. var _readFile = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(filename, options) {
  54. var stream, worksheet;
  55. return regeneratorRuntime.wrap(function _callee$(_context) {
  56. while (1) {
  57. switch (_context.prev = _context.next) {
  58. case 0:
  59. options = options || {};
  60. _context.next = 3;
  61. return exists(filename);
  62. case 3:
  63. if (_context.sent) {
  64. _context.next = 5;
  65. break;
  66. }
  67. throw new Error("File not found: ".concat(filename));
  68. case 5:
  69. stream = fs.createReadStream(filename);
  70. _context.next = 8;
  71. return this.read(stream, options);
  72. case 8:
  73. worksheet = _context.sent;
  74. stream.close();
  75. return _context.abrupt("return", worksheet);
  76. case 11:
  77. case "end":
  78. return _context.stop();
  79. }
  80. }
  81. }, _callee, this);
  82. }));
  83. function readFile(_x, _x2) {
  84. return _readFile.apply(this, arguments);
  85. }
  86. return readFile;
  87. }()
  88. }, {
  89. key: "read",
  90. value: function read(stream, options) {
  91. var _this = this;
  92. options = options || {};
  93. return new Promise(function (resolve, reject) {
  94. var worksheet = _this.workbook.addWorksheet(options.sheetName);
  95. var dateFormats = options.dateFormats || ['YYYY-MM-DD[T]HH:mm:ssZ', 'YYYY-MM-DD[T]HH:mm:ss', 'MM-DD-YYYY', 'YYYY-MM-DD'];
  96. var map = options.map || function (datum) {
  97. if (datum === '') {
  98. return null;
  99. }
  100. var datumNumber = Number(datum);
  101. if (!Number.isNaN(datumNumber) && datumNumber !== Infinity) {
  102. return datumNumber;
  103. }
  104. var dt = dateFormats.reduce(function (matchingDate, currentDateFormat) {
  105. if (matchingDate) {
  106. return matchingDate;
  107. }
  108. var dayjsObj = dayjs(datum, currentDateFormat, true);
  109. if (dayjsObj.isValid()) {
  110. return dayjsObj;
  111. }
  112. return null;
  113. }, null);
  114. if (dt) {
  115. return new Date(dt.valueOf());
  116. }
  117. var special = SpecialValues[datum];
  118. if (special !== undefined) {
  119. return special;
  120. }
  121. return datum;
  122. };
  123. var csvStream = fastCsv.parse(options.parserOptions).on('data', function (data) {
  124. worksheet.addRow(data.map(map));
  125. }).on('end', function () {
  126. csvStream.emit('worksheet', worksheet);
  127. });
  128. csvStream.on('worksheet', resolve).on('error', reject);
  129. stream.pipe(csvStream);
  130. });
  131. }
  132. /**
  133. * @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
  134. */
  135. }, {
  136. key: "createInputStream",
  137. value: function createInputStream() {
  138. 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');
  139. }
  140. }, {
  141. key: "write",
  142. value: function write(stream, options) {
  143. var _this2 = this;
  144. return new Promise(function (resolve, reject) {
  145. options = options || {}; // const encoding = options.encoding || 'utf8';
  146. // const separator = options.separator || ',';
  147. // const quoteChar = options.quoteChar || '\'';
  148. var worksheet = _this2.workbook.getWorksheet(options.sheetName || options.sheetId);
  149. var csvStream = fastCsv.format(options.formatterOptions);
  150. stream.on('finish', function () {
  151. resolve();
  152. });
  153. csvStream.on('error', reject);
  154. csvStream.pipe(stream);
  155. var _options = options,
  156. dateFormat = _options.dateFormat,
  157. dateUTC = _options.dateUTC;
  158. var map = options.map || function (value) {
  159. if (value) {
  160. if (value.text || value.hyperlink) {
  161. return value.hyperlink || value.text || '';
  162. }
  163. if (value.formula || value.result) {
  164. return value.result || '';
  165. }
  166. if (value instanceof Date) {
  167. if (dateFormat) {
  168. return dateUTC ? dayjs.utc(value).format(dateFormat) : dayjs(value).format(dateFormat);
  169. }
  170. return dateUTC ? dayjs.utc(value).format() : dayjs(value).format();
  171. }
  172. if (value.error) {
  173. return value.error;
  174. }
  175. if (_typeof(value) === 'object') {
  176. return JSON.stringify(value);
  177. }
  178. }
  179. return value;
  180. };
  181. var includeEmptyRows = options.includeEmptyRows === undefined || options.includeEmptyRows;
  182. var lastRow = 1;
  183. if (worksheet) {
  184. worksheet.eachRow(function (row, rowNumber) {
  185. if (includeEmptyRows) {
  186. while (lastRow++ < rowNumber - 1) {
  187. csvStream.write([]);
  188. }
  189. }
  190. var values = row.values;
  191. values.shift();
  192. csvStream.write(values.map(map));
  193. lastRow = rowNumber;
  194. });
  195. }
  196. csvStream.end();
  197. });
  198. }
  199. }, {
  200. key: "writeFile",
  201. value: function writeFile(filename, options) {
  202. options = options || {};
  203. var streamOptions = {
  204. encoding: options.encoding || 'utf8'
  205. };
  206. var stream = fs.createWriteStream(filename, streamOptions);
  207. return this.write(stream, options);
  208. }
  209. }, {
  210. key: "writeBuffer",
  211. value: function () {
  212. var _writeBuffer = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(options) {
  213. var stream;
  214. return regeneratorRuntime.wrap(function _callee2$(_context2) {
  215. while (1) {
  216. switch (_context2.prev = _context2.next) {
  217. case 0:
  218. stream = new StreamBuf();
  219. _context2.next = 3;
  220. return this.write(stream, options);
  221. case 3:
  222. return _context2.abrupt("return", stream.read());
  223. case 4:
  224. case "end":
  225. return _context2.stop();
  226. }
  227. }
  228. }, _callee2, this);
  229. }));
  230. function writeBuffer(_x3) {
  231. return _writeBuffer.apply(this, arguments);
  232. }
  233. return writeBuffer;
  234. }()
  235. }]);
  236. return CSV;
  237. }();
  238. module.exports = CSV;
  239. },{"../utils/stream-buf":23,"../utils/utils":26,"dayjs":336,"dayjs/plugin/customParseFormat":337,"dayjs/plugin/utc":338,"fast-csv":369,"fs":215}],2:[function(require,module,exports){
  240. 'use strict';
  241. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  242. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  243. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  244. var colCache = require('../utils/col-cache');
  245. var Anchor = /*#__PURE__*/function () {
  246. function Anchor(worksheet, address) {
  247. var offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  248. _classCallCheck(this, Anchor);
  249. if (!address) {
  250. this.nativeCol = 0;
  251. this.nativeColOff = 0;
  252. this.nativeRow = 0;
  253. this.nativeRowOff = 0;
  254. } else if (typeof address === 'string') {
  255. var decoded = colCache.decodeAddress(address);
  256. this.nativeCol = decoded.col + offset;
  257. this.nativeColOff = 0;
  258. this.nativeRow = decoded.row + offset;
  259. this.nativeRowOff = 0;
  260. } else if (address.nativeCol !== undefined) {
  261. this.nativeCol = address.nativeCol || 0;
  262. this.nativeColOff = address.nativeColOff || 0;
  263. this.nativeRow = address.nativeRow || 0;
  264. this.nativeRowOff = address.nativeRowOff || 0;
  265. } else if (address.col !== undefined) {
  266. this.col = address.col + offset;
  267. this.row = address.row + offset;
  268. } else {
  269. this.nativeCol = 0;
  270. this.nativeColOff = 0;
  271. this.nativeRow = 0;
  272. this.nativeRowOff = 0;
  273. }
  274. this.worksheet = worksheet;
  275. }
  276. _createClass(Anchor, [{
  277. key: "col",
  278. get: function get() {
  279. return this.nativeCol + Math.min(this.colWidth - 1, this.nativeColOff) / this.colWidth;
  280. },
  281. set: function set(v) {
  282. this.nativeCol = Math.floor(v);
  283. this.nativeColOff = Math.floor((v - this.nativeCol) * this.colWidth);
  284. }
  285. }, {
  286. key: "row",
  287. get: function get() {
  288. return this.nativeRow + Math.min(this.rowHeight - 1, this.nativeRowOff) / this.rowHeight;
  289. },
  290. set: function set(v) {
  291. this.nativeRow = Math.floor(v);
  292. this.nativeRowOff = Math.floor((v - this.nativeRow) * this.rowHeight);
  293. }
  294. }, {
  295. key: "colWidth",
  296. get: function get() {
  297. 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;
  298. }
  299. }, {
  300. key: "rowHeight",
  301. get: function get() {
  302. 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;
  303. }
  304. }, {
  305. key: "model",
  306. get: function get() {
  307. return {
  308. nativeCol: this.nativeCol,
  309. nativeColOff: this.nativeColOff,
  310. nativeRow: this.nativeRow,
  311. nativeRowOff: this.nativeRowOff
  312. };
  313. },
  314. set: function set(value) {
  315. this.nativeCol = value.nativeCol;
  316. this.nativeColOff = value.nativeColOff;
  317. this.nativeRow = value.nativeRow;
  318. this.nativeRowOff = value.nativeRowOff;
  319. }
  320. }], [{
  321. key: "asInstance",
  322. value: function asInstance(model) {
  323. return model instanceof Anchor || model == null ? model : new Anchor(model);
  324. }
  325. }]);
  326. return Anchor;
  327. }();
  328. module.exports = Anchor;
  329. },{"../utils/col-cache":19}],3:[function(require,module,exports){
  330. "use strict";
  331. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  332. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  333. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  334. /* eslint-disable max-classes-per-file */
  335. var colCache = require('../utils/col-cache');
  336. var _ = require('../utils/under-dash');
  337. var Enums = require('./enums');
  338. var _require = require('../utils/shared-formula'),
  339. slideFormula = _require.slideFormula;
  340. var Note = require('./note'); // Cell requirements
  341. // Operate inside a worksheet
  342. // Store and retrieve a value with a range of types: text, number, date, hyperlink, reference, formula, etc.
  343. // Manage/use and manipulate cell format either as local to cell or inherited from column or row.
  344. var Cell = /*#__PURE__*/function () {
  345. function Cell(row, column, address) {
  346. _classCallCheck(this, Cell);
  347. if (!row || !column) {
  348. throw new Error('A Cell needs a Row');
  349. }
  350. this._row = row;
  351. this._column = column;
  352. colCache.validateAddress(address);
  353. this._address = address; // TODO: lazy evaluation of this._value
  354. this._value = Value.create(Cell.Types.Null, this);
  355. this.style = this._mergeStyle(row.style, column.style, {});
  356. this._mergeCount = 0;
  357. }
  358. _createClass(Cell, [{
  359. key: "destroy",
  360. // help GC by removing cyclic (and other) references
  361. value: function destroy() {
  362. delete this.style;
  363. delete this._value;
  364. delete this._row;
  365. delete this._column;
  366. delete this._address;
  367. } // =========================================================================
  368. // Styles stuff
  369. }, {
  370. key: "_mergeStyle",
  371. value: function _mergeStyle(rowStyle, colStyle, style) {
  372. var numFmt = rowStyle && rowStyle.numFmt || colStyle && colStyle.numFmt;
  373. if (numFmt) style.numFmt = numFmt;
  374. var font = rowStyle && rowStyle.font || colStyle && colStyle.font;
  375. if (font) style.font = font;
  376. var alignment = rowStyle && rowStyle.alignment || colStyle && colStyle.alignment;
  377. if (alignment) style.alignment = alignment;
  378. var border = rowStyle && rowStyle.border || colStyle && colStyle.border;
  379. if (border) style.border = border;
  380. var fill = rowStyle && rowStyle.fill || colStyle && colStyle.fill;
  381. if (fill) style.fill = fill;
  382. var protection = rowStyle && rowStyle.protection || colStyle && colStyle.protection;
  383. if (protection) style.protection = protection;
  384. return style;
  385. } // =========================================================================
  386. // return the address for this cell
  387. }, {
  388. key: "toCsvString",
  389. value: function toCsvString() {
  390. return this._value.toCsvString();
  391. } // =========================================================================
  392. // Merge stuff
  393. }, {
  394. key: "addMergeRef",
  395. value: function addMergeRef() {
  396. this._mergeCount++;
  397. }
  398. }, {
  399. key: "releaseMergeRef",
  400. value: function releaseMergeRef() {
  401. this._mergeCount--;
  402. }
  403. }, {
  404. key: "merge",
  405. value: function merge(master, ignoreStyle) {
  406. this._value.release();
  407. this._value = Value.create(Cell.Types.Merge, this, master);
  408. if (!ignoreStyle) {
  409. this.style = master.style;
  410. }
  411. }
  412. }, {
  413. key: "unmerge",
  414. value: function unmerge() {
  415. if (this.type === Cell.Types.Merge) {
  416. this._value.release();
  417. this._value = Value.create(Cell.Types.Null, this);
  418. this.style = this._mergeStyle(this._row.style, this._column.style, {});
  419. }
  420. }
  421. }, {
  422. key: "isMergedTo",
  423. value: function isMergedTo(master) {
  424. if (this._value.type !== Cell.Types.Merge) return false;
  425. return this._value.isMergedTo(master);
  426. }
  427. }, {
  428. key: "toString",
  429. value: function toString() {
  430. return this.text;
  431. }
  432. }, {
  433. key: "_upgradeToHyperlink",
  434. value: function _upgradeToHyperlink(hyperlink) {
  435. // if this cell is a string, turn it into a Hyperlink
  436. if (this.type === Cell.Types.String) {
  437. this._value = Value.create(Cell.Types.Hyperlink, this, {
  438. text: this._value.value,
  439. hyperlink: hyperlink
  440. });
  441. }
  442. } // =========================================================================
  443. // Formula stuff
  444. }, {
  445. key: "addName",
  446. value: function addName(name) {
  447. this.workbook.definedNames.addEx(this.fullAddress, name);
  448. }
  449. }, {
  450. key: "removeName",
  451. value: function removeName(name) {
  452. this.workbook.definedNames.removeEx(this.fullAddress, name);
  453. }
  454. }, {
  455. key: "removeAllNames",
  456. value: function removeAllNames() {
  457. this.workbook.definedNames.removeAllNames(this.fullAddress);
  458. } // =========================================================================
  459. // Data Validation stuff
  460. }, {
  461. key: "worksheet",
  462. get: function get() {
  463. return this._row.worksheet;
  464. }
  465. }, {
  466. key: "workbook",
  467. get: function get() {
  468. return this._row.worksheet.workbook;
  469. }
  470. }, {
  471. key: "numFmt",
  472. get: function get() {
  473. return this.style.numFmt;
  474. },
  475. set: function set(value) {
  476. this.style.numFmt = value;
  477. }
  478. }, {
  479. key: "font",
  480. get: function get() {
  481. return this.style.font;
  482. },
  483. set: function set(value) {
  484. this.style.font = value;
  485. }
  486. }, {
  487. key: "alignment",
  488. get: function get() {
  489. return this.style.alignment;
  490. },
  491. set: function set(value) {
  492. this.style.alignment = value;
  493. }
  494. }, {
  495. key: "border",
  496. get: function get() {
  497. return this.style.border;
  498. },
  499. set: function set(value) {
  500. this.style.border = value;
  501. }
  502. }, {
  503. key: "fill",
  504. get: function get() {
  505. return this.style.fill;
  506. },
  507. set: function set(value) {
  508. this.style.fill = value;
  509. }
  510. }, {
  511. key: "protection",
  512. get: function get() {
  513. return this.style.protection;
  514. },
  515. set: function set(value) {
  516. this.style.protection = value;
  517. }
  518. }, {
  519. key: "address",
  520. get: function get() {
  521. return this._address;
  522. }
  523. }, {
  524. key: "row",
  525. get: function get() {
  526. return this._row.number;
  527. }
  528. }, {
  529. key: "col",
  530. get: function get() {
  531. return this._column.number;
  532. }
  533. }, {
  534. key: "$col$row",
  535. get: function get() {
  536. return "$".concat(this._column.letter, "$").concat(this.row);
  537. } // =========================================================================
  538. // Value stuff
  539. }, {
  540. key: "type",
  541. get: function get() {
  542. return this._value.type;
  543. }
  544. }, {
  545. key: "effectiveType",
  546. get: function get() {
  547. return this._value.effectiveType;
  548. }
  549. }, {
  550. key: "isMerged",
  551. get: function get() {
  552. return this._mergeCount > 0 || this.type === Cell.Types.Merge;
  553. }
  554. }, {
  555. key: "master",
  556. get: function get() {
  557. if (this.type === Cell.Types.Merge) {
  558. return this._value.master;
  559. }
  560. return this; // an unmerged cell is its own master
  561. }
  562. }, {
  563. key: "isHyperlink",
  564. get: function get() {
  565. return this._value.type === Cell.Types.Hyperlink;
  566. }
  567. }, {
  568. key: "hyperlink",
  569. get: function get() {
  570. return this._value.hyperlink;
  571. } // return the value
  572. }, {
  573. key: "value",
  574. get: function get() {
  575. return this._value.value;
  576. } // set the value - can be number, string or raw
  577. ,
  578. set: function set(v) {
  579. // special case - merge cells set their master's value
  580. if (this.type === Cell.Types.Merge) {
  581. this._value.master.value = v;
  582. return;
  583. }
  584. this._value.release(); // assign value
  585. this._value = Value.create(Value.getType(v), this, v);
  586. }
  587. }, {
  588. key: "note",
  589. get: function get() {
  590. return this._comment && this._comment.note;
  591. },
  592. set: function set(note) {
  593. this._comment = new Note(note);
  594. }
  595. }, {
  596. key: "text",
  597. get: function get() {
  598. return this._value.toString();
  599. }
  600. }, {
  601. key: "html",
  602. get: function get() {
  603. return _.escapeHtml(this.text);
  604. }
  605. }, {
  606. key: "formula",
  607. get: function get() {
  608. return this._value.formula;
  609. }
  610. }, {
  611. key: "result",
  612. get: function get() {
  613. return this._value.result;
  614. }
  615. }, {
  616. key: "formulaType",
  617. get: function get() {
  618. return this._value.formulaType;
  619. } // =========================================================================
  620. // Name stuff
  621. }, {
  622. key: "fullAddress",
  623. get: function get() {
  624. var worksheet = this._row.worksheet;
  625. return {
  626. sheetName: worksheet.name,
  627. address: this.address,
  628. row: this.row,
  629. col: this.col
  630. };
  631. }
  632. }, {
  633. key: "name",
  634. get: function get() {
  635. return this.names[0];
  636. },
  637. set: function set(value) {
  638. this.names = [value];
  639. }
  640. }, {
  641. key: "names",
  642. get: function get() {
  643. return this.workbook.definedNames.getNamesEx(this.fullAddress);
  644. },
  645. set: function set(value) {
  646. var _this = this;
  647. var definedNames = this.workbook.definedNames;
  648. definedNames.removeAllNames(this.fullAddress);
  649. value.forEach(function (name) {
  650. definedNames.addEx(_this.fullAddress, name);
  651. });
  652. }
  653. }, {
  654. key: "_dataValidations",
  655. get: function get() {
  656. return this.worksheet.dataValidations;
  657. }
  658. }, {
  659. key: "dataValidation",
  660. get: function get() {
  661. return this._dataValidations.find(this.address);
  662. },
  663. set: function set(value) {
  664. this._dataValidations.add(this.address, value);
  665. } // =========================================================================
  666. // Model stuff
  667. }, {
  668. key: "model",
  669. get: function get() {
  670. var model = this._value.model;
  671. model.style = this.style;
  672. if (this._comment) {
  673. model.comment = this._comment.model;
  674. }
  675. return model;
  676. },
  677. set: function set(value) {
  678. this._value.release();
  679. this._value = Value.create(value.type, this);
  680. this._value.model = value;
  681. if (value.comment) {
  682. switch (value.comment.type) {
  683. case 'note':
  684. this._comment = Note.fromModel(value.comment);
  685. break;
  686. }
  687. }
  688. if (value.style) {
  689. this.style = value.style;
  690. } else {
  691. this.style = {};
  692. }
  693. }
  694. }]);
  695. return Cell;
  696. }();
  697. Cell.Types = Enums.ValueType; // =============================================================================
  698. // Internal Value Types
  699. var NullValue = /*#__PURE__*/function () {
  700. function NullValue(cell) {
  701. _classCallCheck(this, NullValue);
  702. this.model = {
  703. address: cell.address,
  704. type: Cell.Types.Null
  705. };
  706. }
  707. _createClass(NullValue, [{
  708. key: "toCsvString",
  709. value: function toCsvString() {
  710. return '';
  711. }
  712. }, {
  713. key: "release",
  714. value: function release() {}
  715. }, {
  716. key: "toString",
  717. value: function toString() {
  718. return '';
  719. }
  720. }, {
  721. key: "value",
  722. get: function get() {
  723. return null;
  724. },
  725. set: function set(value) {// nothing to do
  726. }
  727. }, {
  728. key: "type",
  729. get: function get() {
  730. return Cell.Types.Null;
  731. }
  732. }, {
  733. key: "effectiveType",
  734. get: function get() {
  735. return Cell.Types.Null;
  736. }
  737. }, {
  738. key: "address",
  739. get: function get() {
  740. return this.model.address;
  741. },
  742. set: function set(value) {
  743. this.model.address = value;
  744. }
  745. }]);
  746. return NullValue;
  747. }();
  748. var NumberValue = /*#__PURE__*/function () {
  749. function NumberValue(cell, value) {
  750. _classCallCheck(this, NumberValue);
  751. this.model = {
  752. address: cell.address,
  753. type: Cell.Types.Number,
  754. value: value
  755. };
  756. }
  757. _createClass(NumberValue, [{
  758. key: "toCsvString",
  759. value: function toCsvString() {
  760. return this.model.value.toString();
  761. }
  762. }, {
  763. key: "release",
  764. value: function release() {}
  765. }, {
  766. key: "toString",
  767. value: function toString() {
  768. return this.model.value.toString();
  769. }
  770. }, {
  771. key: "value",
  772. get: function get() {
  773. return this.model.value;
  774. },
  775. set: function set(value) {
  776. this.model.value = value;
  777. }
  778. }, {
  779. key: "type",
  780. get: function get() {
  781. return Cell.Types.Number;
  782. }
  783. }, {
  784. key: "effectiveType",
  785. get: function get() {
  786. return Cell.Types.Number;
  787. }
  788. }, {
  789. key: "address",
  790. get: function get() {
  791. return this.model.address;
  792. },
  793. set: function set(value) {
  794. this.model.address = value;
  795. }
  796. }]);
  797. return NumberValue;
  798. }();
  799. var StringValue = /*#__PURE__*/function () {
  800. function StringValue(cell, value) {
  801. _classCallCheck(this, StringValue);
  802. this.model = {
  803. address: cell.address,
  804. type: Cell.Types.String,
  805. value: value
  806. };
  807. }
  808. _createClass(StringValue, [{
  809. key: "toCsvString",
  810. value: function toCsvString() {
  811. return "\"".concat(this.model.value.replace(/"/g, '""'), "\"");
  812. }
  813. }, {
  814. key: "release",
  815. value: function release() {}
  816. }, {
  817. key: "toString",
  818. value: function toString() {
  819. return this.model.value;
  820. }
  821. }, {
  822. key: "value",
  823. get: function get() {
  824. return this.model.value;
  825. },
  826. set: function set(value) {
  827. this.model.value = value;
  828. }
  829. }, {
  830. key: "type",
  831. get: function get() {
  832. return Cell.Types.String;
  833. }
  834. }, {
  835. key: "effectiveType",
  836. get: function get() {
  837. return Cell.Types.String;
  838. }
  839. }, {
  840. key: "address",
  841. get: function get() {
  842. return this.model.address;
  843. },
  844. set: function set(value) {
  845. this.model.address = value;
  846. }
  847. }]);
  848. return StringValue;
  849. }();
  850. var RichTextValue = /*#__PURE__*/function () {
  851. function RichTextValue(cell, value) {
  852. _classCallCheck(this, RichTextValue);
  853. this.model = {
  854. address: cell.address,
  855. type: Cell.Types.String,
  856. value: value
  857. };
  858. }
  859. _createClass(RichTextValue, [{
  860. key: "toString",
  861. value: function toString() {
  862. return this.model.value.richText.map(function (t) {
  863. return t.text;
  864. }).join('');
  865. }
  866. }, {
  867. key: "toCsvString",
  868. value: function toCsvString() {
  869. return "\"".concat(this.text.replace(/"/g, '""'), "\"");
  870. }
  871. }, {
  872. key: "release",
  873. value: function release() {}
  874. }, {
  875. key: "value",
  876. get: function get() {
  877. return this.model.value;
  878. },
  879. set: function set(value) {
  880. this.model.value = value;
  881. }
  882. }, {
  883. key: "type",
  884. get: function get() {
  885. return Cell.Types.RichText;
  886. }
  887. }, {
  888. key: "effectiveType",
  889. get: function get() {
  890. return Cell.Types.RichText;
  891. }
  892. }, {
  893. key: "address",
  894. get: function get() {
  895. return this.model.address;
  896. },
  897. set: function set(value) {
  898. this.model.address = value;
  899. }
  900. }]);
  901. return RichTextValue;
  902. }();
  903. var DateValue = /*#__PURE__*/function () {
  904. function DateValue(cell, value) {
  905. _classCallCheck(this, DateValue);
  906. this.model = {
  907. address: cell.address,
  908. type: Cell.Types.Date,
  909. value: value
  910. };
  911. }
  912. _createClass(DateValue, [{
  913. key: "toCsvString",
  914. value: function toCsvString() {
  915. return this.model.value.toISOString();
  916. }
  917. }, {
  918. key: "release",
  919. value: function release() {}
  920. }, {
  921. key: "toString",
  922. value: function toString() {
  923. return this.model.value.toString();
  924. }
  925. }, {
  926. key: "value",
  927. get: function get() {
  928. return this.model.value;
  929. },
  930. set: function set(value) {
  931. this.model.value = value;
  932. }
  933. }, {
  934. key: "type",
  935. get: function get() {
  936. return Cell.Types.Date;
  937. }
  938. }, {
  939. key: "effectiveType",
  940. get: function get() {
  941. return Cell.Types.Date;
  942. }
  943. }, {
  944. key: "address",
  945. get: function get() {
  946. return this.model.address;
  947. },
  948. set: function set(value) {
  949. this.model.address = value;
  950. }
  951. }]);
  952. return DateValue;
  953. }();
  954. var HyperlinkValue = /*#__PURE__*/function () {
  955. function HyperlinkValue(cell, value) {
  956. _classCallCheck(this, HyperlinkValue);
  957. this.model = {
  958. address: cell.address,
  959. type: Cell.Types.Hyperlink,
  960. text: value ? value.text : undefined,
  961. hyperlink: value ? value.hyperlink : undefined
  962. };
  963. if (value && value.tooltip) {
  964. this.model.tooltip = value.tooltip;
  965. }
  966. }
  967. _createClass(HyperlinkValue, [{
  968. key: "toCsvString",
  969. value: function toCsvString() {
  970. return this.model.hyperlink;
  971. }
  972. }, {
  973. key: "release",
  974. value: function release() {}
  975. }, {
  976. key: "toString",
  977. value: function toString() {
  978. return this.model.text;
  979. }
  980. }, {
  981. key: "value",
  982. get: function get() {
  983. var v = {
  984. text: this.model.text,
  985. hyperlink: this.model.hyperlink
  986. };
  987. if (this.model.tooltip) {
  988. v.tooltip = this.model.tooltip;
  989. }
  990. return v;
  991. },
  992. set: function set(value) {
  993. this.model = {
  994. text: value.text,
  995. hyperlink: value.hyperlink
  996. };
  997. if (value.tooltip) {
  998. this.model.tooltip = value.tooltip;
  999. }
  1000. }
  1001. }, {
  1002. key: "text",
  1003. get: function get() {
  1004. return this.model.text;
  1005. },
  1006. set: function set(value) {
  1007. this.model.text = value;
  1008. }
  1009. /*
  1010. get tooltip() {
  1011. return this.model.tooltip;
  1012. }
  1013. set tooltip(value) {
  1014. this.model.tooltip = value;
  1015. } */
  1016. }, {
  1017. key: "hyperlink",
  1018. get: function get() {
  1019. return this.model.hyperlink;
  1020. },
  1021. set: function set(value) {
  1022. this.model.hyperlink = value;
  1023. }
  1024. }, {
  1025. key: "type",
  1026. get: function get() {
  1027. return Cell.Types.Hyperlink;
  1028. }
  1029. }, {
  1030. key: "effectiveType",
  1031. get: function get() {
  1032. return Cell.Types.Hyperlink;
  1033. }
  1034. }, {
  1035. key: "address",
  1036. get: function get() {
  1037. return this.model.address;
  1038. },
  1039. set: function set(value) {
  1040. this.model.address = value;
  1041. }
  1042. }]);
  1043. return HyperlinkValue;
  1044. }();
  1045. var MergeValue = /*#__PURE__*/function () {
  1046. function MergeValue(cell, master) {
  1047. _classCallCheck(this, MergeValue);
  1048. this.model = {
  1049. address: cell.address,
  1050. type: Cell.Types.Merge,
  1051. master: master ? master.address : undefined
  1052. };
  1053. this._master = master;
  1054. if (master) {
  1055. master.addMergeRef();
  1056. }
  1057. }
  1058. _createClass(MergeValue, [{
  1059. key: "isMergedTo",
  1060. value: function isMergedTo(master) {
  1061. return master === this._master;
  1062. }
  1063. }, {
  1064. key: "toCsvString",
  1065. value: function toCsvString() {
  1066. return '';
  1067. }
  1068. }, {
  1069. key: "release",
  1070. value: function release() {
  1071. this._master.releaseMergeRef();
  1072. }
  1073. }, {
  1074. key: "toString",
  1075. value: function toString() {
  1076. return this.value.toString();
  1077. }
  1078. }, {
  1079. key: "value",
  1080. get: function get() {
  1081. return this._master.value;
  1082. },
  1083. set: function set(value) {
  1084. if (value instanceof Cell) {
  1085. if (this._master) {
  1086. this._master.releaseMergeRef();
  1087. }
  1088. value.addMergeRef();
  1089. this._master = value;
  1090. } else {
  1091. this._master.value = value;
  1092. }
  1093. }
  1094. }, {
  1095. key: "master",
  1096. get: function get() {
  1097. return this._master;
  1098. }
  1099. }, {
  1100. key: "type",
  1101. get: function get() {
  1102. return Cell.Types.Merge;
  1103. }
  1104. }, {
  1105. key: "effectiveType",
  1106. get: function get() {
  1107. return this._master.effectiveType;
  1108. }
  1109. }, {
  1110. key: "address",
  1111. get: function get() {
  1112. return this.model.address;
  1113. },
  1114. set: function set(value) {
  1115. this.model.address = value;
  1116. }
  1117. }]);
  1118. return MergeValue;
  1119. }();
  1120. var FormulaValue = /*#__PURE__*/function () {
  1121. function FormulaValue(cell, value) {
  1122. _classCallCheck(this, FormulaValue);
  1123. this.cell = cell;
  1124. this.model = {
  1125. address: cell.address,
  1126. type: Cell.Types.Formula,
  1127. shareType: value ? value.shareType : undefined,
  1128. ref: value ? value.ref : undefined,
  1129. formula: value ? value.formula : undefined,
  1130. sharedFormula: value ? value.sharedFormula : undefined,
  1131. result: value ? value.result : undefined
  1132. };
  1133. }
  1134. _createClass(FormulaValue, [{
  1135. key: "_copyModel",
  1136. value: function _copyModel(model) {
  1137. var copy = {};
  1138. var cp = function cp(name) {
  1139. var value = model[name];
  1140. if (value) {
  1141. copy[name] = value;
  1142. }
  1143. };
  1144. cp('formula');
  1145. cp('result');
  1146. cp('ref');
  1147. cp('shareType');
  1148. cp('sharedFormula');
  1149. return copy;
  1150. }
  1151. }, {
  1152. key: "validate",
  1153. value: function validate(value) {
  1154. switch (Value.getType(value)) {
  1155. case Cell.Types.Null:
  1156. case Cell.Types.String:
  1157. case Cell.Types.Number:
  1158. case Cell.Types.Date:
  1159. break;
  1160. case Cell.Types.Hyperlink:
  1161. case Cell.Types.Formula:
  1162. default:
  1163. throw new Error('Cannot process that type of result value');
  1164. }
  1165. }
  1166. }, {
  1167. key: "_getTranslatedFormula",
  1168. value: function _getTranslatedFormula() {
  1169. if (!this._translatedFormula && this.model.sharedFormula) {
  1170. var worksheet = this.cell.worksheet;
  1171. var master = worksheet.findCell(this.model.sharedFormula);
  1172. this._translatedFormula = master && slideFormula(master.formula, master.address, this.model.address);
  1173. }
  1174. return this._translatedFormula;
  1175. }
  1176. }, {
  1177. key: "toCsvString",
  1178. value: function toCsvString() {
  1179. return "".concat(this.model.result || '');
  1180. }
  1181. }, {
  1182. key: "release",
  1183. value: function release() {}
  1184. }, {
  1185. key: "toString",
  1186. value: function toString() {
  1187. return this.model.result ? this.model.result.toString() : '';
  1188. }
  1189. }, {
  1190. key: "value",
  1191. get: function get() {
  1192. return this._copyModel(this.model);
  1193. },
  1194. set: function set(value) {
  1195. this.model = this._copyModel(value);
  1196. }
  1197. }, {
  1198. key: "dependencies",
  1199. get: function get() {
  1200. // find all the ranges and cells mentioned in the formula
  1201. var ranges = this.formula.match(/([a-zA-Z0-9]+!)?[A-Z]{1,3}\d{1,4}:[A-Z]{1,3}\d{1,4}/g);
  1202. var 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);
  1203. return {
  1204. ranges: ranges,
  1205. cells: cells
  1206. };
  1207. }
  1208. }, {
  1209. key: "formula",
  1210. get: function get() {
  1211. return this.model.formula || this._getTranslatedFormula();
  1212. },
  1213. set: function set(value) {
  1214. this.model.formula = value;
  1215. }
  1216. }, {
  1217. key: "formulaType",
  1218. get: function get() {
  1219. if (this.model.formula) {
  1220. return Enums.FormulaType.Master;
  1221. }
  1222. if (this.model.sharedFormula) {
  1223. return Enums.FormulaType.Shared;
  1224. }
  1225. return Enums.FormulaType.None;
  1226. }
  1227. }, {
  1228. key: "result",
  1229. get: function get() {
  1230. return this.model.result;
  1231. },
  1232. set: function set(value) {
  1233. this.model.result = value;
  1234. }
  1235. }, {
  1236. key: "type",
  1237. get: function get() {
  1238. return Cell.Types.Formula;
  1239. }
  1240. }, {
  1241. key: "effectiveType",
  1242. get: function get() {
  1243. var v = this.model.result;
  1244. if (v === null || v === undefined) {
  1245. return Enums.ValueType.Null;
  1246. }
  1247. if (v instanceof String || typeof v === 'string') {
  1248. return Enums.ValueType.String;
  1249. }
  1250. if (typeof v === 'number') {
  1251. return Enums.ValueType.Number;
  1252. }
  1253. if (v instanceof Date) {
  1254. return Enums.ValueType.Date;
  1255. }
  1256. if (v.text && v.hyperlink) {
  1257. return Enums.ValueType.Hyperlink;
  1258. }
  1259. if (v.formula) {
  1260. return Enums.ValueType.Formula;
  1261. }
  1262. return Enums.ValueType.Null;
  1263. }
  1264. }, {
  1265. key: "address",
  1266. get: function get() {
  1267. return this.model.address;
  1268. },
  1269. set: function set(value) {
  1270. this.model.address = value;
  1271. }
  1272. }]);
  1273. return FormulaValue;
  1274. }();
  1275. var SharedStringValue = /*#__PURE__*/function () {
  1276. function SharedStringValue(cell, value) {
  1277. _classCallCheck(this, SharedStringValue);
  1278. this.model = {
  1279. address: cell.address,
  1280. type: Cell.Types.SharedString,
  1281. value: value
  1282. };
  1283. }
  1284. _createClass(SharedStringValue, [{
  1285. key: "toCsvString",
  1286. value: function toCsvString() {
  1287. return this.model.value.toString();
  1288. }
  1289. }, {
  1290. key: "release",
  1291. value: function release() {}
  1292. }, {
  1293. key: "toString",
  1294. value: function toString() {
  1295. return this.model.value.toString();
  1296. }
  1297. }, {
  1298. key: "value",
  1299. get: function get() {
  1300. return this.model.value;
  1301. },
  1302. set: function set(value) {
  1303. this.model.value = value;
  1304. }
  1305. }, {
  1306. key: "type",
  1307. get: function get() {
  1308. return Cell.Types.SharedString;
  1309. }
  1310. }, {
  1311. key: "effectiveType",
  1312. get: function get() {
  1313. return Cell.Types.SharedString;
  1314. }
  1315. }, {
  1316. key: "address",
  1317. get: function get() {
  1318. return this.model.address;
  1319. },
  1320. set: function set(value) {
  1321. this.model.address = value;
  1322. }
  1323. }]);
  1324. return SharedStringValue;
  1325. }();
  1326. var BooleanValue = /*#__PURE__*/function () {
  1327. function BooleanValue(cell, value) {
  1328. _classCallCheck(this, BooleanValue);
  1329. this.model = {
  1330. address: cell.address,
  1331. type: Cell.Types.Boolean,
  1332. value: value
  1333. };
  1334. }
  1335. _createClass(BooleanValue, [{
  1336. key: "toCsvString",
  1337. value: function toCsvString() {
  1338. return this.model.value ? 1 : 0;
  1339. }
  1340. }, {
  1341. key: "release",
  1342. value: function release() {}
  1343. }, {
  1344. key: "toString",
  1345. value: function toString() {
  1346. return this.model.value.toString();
  1347. }
  1348. }, {
  1349. key: "value",
  1350. get: function get() {
  1351. return this.model.value;
  1352. },
  1353. set: function set(value) {
  1354. this.model.value = value;
  1355. }
  1356. }, {
  1357. key: "type",
  1358. get: function get() {
  1359. return Cell.Types.Boolean;
  1360. }
  1361. }, {
  1362. key: "effectiveType",
  1363. get: function get() {
  1364. return Cell.Types.Boolean;
  1365. }
  1366. }, {
  1367. key: "address",
  1368. get: function get() {
  1369. return this.model.address;
  1370. },
  1371. set: function set(value) {
  1372. this.model.address = value;
  1373. }
  1374. }]);
  1375. return BooleanValue;
  1376. }();
  1377. var ErrorValue = /*#__PURE__*/function () {
  1378. function ErrorValue(cell, value) {
  1379. _classCallCheck(this, ErrorValue);
  1380. this.model = {
  1381. address: cell.address,
  1382. type: Cell.Types.Error,
  1383. value: value
  1384. };
  1385. }
  1386. _createClass(ErrorValue, [{
  1387. key: "toCsvString",
  1388. value: function toCsvString() {
  1389. return this.toString();
  1390. }
  1391. }, {
  1392. key: "release",
  1393. value: function release() {}
  1394. }, {
  1395. key: "toString",
  1396. value: function toString() {
  1397. return this.model.value.error.toString();
  1398. }
  1399. }, {
  1400. key: "value",
  1401. get: function get() {
  1402. return this.model.value;
  1403. },
  1404. set: function set(value) {
  1405. this.model.value = value;
  1406. }
  1407. }, {
  1408. key: "type",
  1409. get: function get() {
  1410. return Cell.Types.Error;
  1411. }
  1412. }, {
  1413. key: "effectiveType",
  1414. get: function get() {
  1415. return Cell.Types.Error;
  1416. }
  1417. }, {
  1418. key: "address",
  1419. get: function get() {
  1420. return this.model.address;
  1421. },
  1422. set: function set(value) {
  1423. this.model.address = value;
  1424. }
  1425. }]);
  1426. return ErrorValue;
  1427. }();
  1428. var JSONValue = /*#__PURE__*/function () {
  1429. function JSONValue(cell, value) {
  1430. _classCallCheck(this, JSONValue);
  1431. this.model = {
  1432. address: cell.address,
  1433. type: Cell.Types.String,
  1434. value: JSON.stringify(value),
  1435. rawValue: value
  1436. };
  1437. }
  1438. _createClass(JSONValue, [{
  1439. key: "toCsvString",
  1440. value: function toCsvString() {
  1441. return this.model.value;
  1442. }
  1443. }, {
  1444. key: "release",
  1445. value: function release() {}
  1446. }, {
  1447. key: "toString",
  1448. value: function toString() {
  1449. return this.model.value;
  1450. }
  1451. }, {
  1452. key: "value",
  1453. get: function get() {
  1454. return this.model.rawValue;
  1455. },
  1456. set: function set(value) {
  1457. this.model.rawValue = value;
  1458. this.model.value = JSON.stringify(value);
  1459. }
  1460. }, {
  1461. key: "type",
  1462. get: function get() {
  1463. return Cell.Types.String;
  1464. }
  1465. }, {
  1466. key: "effectiveType",
  1467. get: function get() {
  1468. return Cell.Types.String;
  1469. }
  1470. }, {
  1471. key: "address",
  1472. get: function get() {
  1473. return this.model.address;
  1474. },
  1475. set: function set(value) {
  1476. this.model.address = value;
  1477. }
  1478. }]);
  1479. return JSONValue;
  1480. }(); // Value is a place to hold common static Value type functions
  1481. var Value = {
  1482. getType: function getType(value) {
  1483. if (value === null || value === undefined) {
  1484. return Cell.Types.Null;
  1485. }
  1486. if (value instanceof String || typeof value === 'string') {
  1487. return Cell.Types.String;
  1488. }
  1489. if (typeof value === 'number') {
  1490. return Cell.Types.Number;
  1491. }
  1492. if (typeof value === 'boolean') {
  1493. return Cell.Types.Boolean;
  1494. }
  1495. if (value instanceof Date) {
  1496. return Cell.Types.Date;
  1497. }
  1498. if (value.text && value.hyperlink) {
  1499. return Cell.Types.Hyperlink;
  1500. }
  1501. if (value.formula || value.sharedFormula) {
  1502. return Cell.Types.Formula;
  1503. }
  1504. if (value.richText) {
  1505. return Cell.Types.RichText;
  1506. }
  1507. if (value.sharedString) {
  1508. return Cell.Types.SharedString;
  1509. }
  1510. if (value.error) {
  1511. return Cell.Types.Error;
  1512. }
  1513. return Cell.Types.JSON;
  1514. },
  1515. // map valueType to constructor
  1516. types: [{
  1517. t: Cell.Types.Null,
  1518. f: NullValue
  1519. }, {
  1520. t: Cell.Types.Number,
  1521. f: NumberValue
  1522. }, {
  1523. t: Cell.Types.String,
  1524. f: StringValue
  1525. }, {
  1526. t: Cell.Types.Date,
  1527. f: DateValue
  1528. }, {
  1529. t: Cell.Types.Hyperlink,
  1530. f: HyperlinkValue
  1531. }, {
  1532. t: Cell.Types.Formula,
  1533. f: FormulaValue
  1534. }, {
  1535. t: Cell.Types.Merge,
  1536. f: MergeValue
  1537. }, {
  1538. t: Cell.Types.JSON,
  1539. f: JSONValue
  1540. }, {
  1541. t: Cell.Types.SharedString,
  1542. f: SharedStringValue
  1543. }, {
  1544. t: Cell.Types.RichText,
  1545. f: RichTextValue
  1546. }, {
  1547. t: Cell.Types.Boolean,
  1548. f: BooleanValue
  1549. }, {
  1550. t: Cell.Types.Error,
  1551. f: ErrorValue
  1552. }].reduce(function (p, t) {
  1553. p[t.t] = t.f;
  1554. return p;
  1555. }, []),
  1556. create: function create(type, cell, value) {
  1557. var T = this.types[type];
  1558. if (!T) {
  1559. throw new Error("Could not create Value of type ".concat(type));
  1560. }
  1561. return new T(cell, value);
  1562. }
  1563. };
  1564. module.exports = Cell;
  1565. },{"../utils/col-cache":19,"../utils/shared-formula":22,"../utils/under-dash":25,"./enums":7,"./note":9}],4:[function(require,module,exports){
  1566. 'use strict';
  1567. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1568. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  1569. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  1570. var _ = require('../utils/under-dash');
  1571. var Enums = require('./enums');
  1572. var colCache = require('../utils/col-cache');
  1573. var DEFAULT_COLUMN_WIDTH = 9; // Column defines the column properties for 1 column.
  1574. // This includes header rows, widths, key, (style), etc.
  1575. // Worksheet will condense the columns as appropriate during serialization
  1576. var Column = /*#__PURE__*/function () {
  1577. function Column(worksheet, number, defn) {
  1578. _classCallCheck(this, Column);
  1579. this._worksheet = worksheet;
  1580. this._number = number;
  1581. if (defn !== false) {
  1582. // sometimes defn will follow
  1583. this.defn = defn;
  1584. }
  1585. }
  1586. _createClass(Column, [{
  1587. key: "toString",
  1588. value: function toString() {
  1589. return JSON.stringify({
  1590. key: this.key,
  1591. width: this.width,
  1592. headers: this.headers.length ? this.headers : undefined
  1593. });
  1594. }
  1595. }, {
  1596. key: "equivalentTo",
  1597. value: function equivalentTo(other) {
  1598. return this.width === other.width && this.hidden === other.hidden && this.outlineLevel === other.outlineLevel && _.isEqual(this.style, other.style);
  1599. }
  1600. }, {
  1601. key: "eachCell",
  1602. value: function eachCell(options, iteratee) {
  1603. var colNumber = this.number;
  1604. if (!iteratee) {
  1605. iteratee = options;
  1606. options = null;
  1607. }
  1608. this._worksheet.eachRow(options, function (row, rowNumber) {
  1609. iteratee(row.getCell(colNumber), rowNumber);
  1610. });
  1611. }
  1612. }, {
  1613. key: "_applyStyle",
  1614. // =========================================================================
  1615. // styles
  1616. value: function _applyStyle(name, value) {
  1617. this.style[name] = value;
  1618. this.eachCell(function (cell) {
  1619. cell[name] = value;
  1620. });
  1621. return value;
  1622. }
  1623. }, {
  1624. key: "number",
  1625. get: function get() {
  1626. return this._number;
  1627. }
  1628. }, {
  1629. key: "worksheet",
  1630. get: function get() {
  1631. return this._worksheet;
  1632. }
  1633. }, {
  1634. key: "letter",
  1635. get: function get() {
  1636. return colCache.n2l(this._number);
  1637. }
  1638. }, {
  1639. key: "isCustomWidth",
  1640. get: function get() {
  1641. return this.width !== undefined && this.width !== DEFAULT_COLUMN_WIDTH;
  1642. }
  1643. }, {
  1644. key: "defn",
  1645. get: function get() {
  1646. return {
  1647. header: this._header,
  1648. key: this.key,
  1649. width: this.width,
  1650. style: this.style,
  1651. hidden: this.hidden,
  1652. outlineLevel: this.outlineLevel
  1653. };
  1654. },
  1655. set: function set(value) {
  1656. if (value) {
  1657. this.key = value.key;
  1658. this.width = value.width !== undefined ? value.width : DEFAULT_COLUMN_WIDTH;
  1659. this.outlineLevel = value.outlineLevel;
  1660. if (value.style) {
  1661. this.style = value.style;
  1662. } else {
  1663. this.style = {};
  1664. } // headers must be set after style
  1665. this.header = value.header;
  1666. this._hidden = !!value.hidden;
  1667. } else {
  1668. delete this._header;
  1669. delete this._key;
  1670. delete this.width;
  1671. this.style = {};
  1672. this.outlineLevel = 0;
  1673. }
  1674. }
  1675. }, {
  1676. key: "headers",
  1677. get: function get() {
  1678. return this._header && this._header instanceof Array ? this._header : [this._header];
  1679. }
  1680. }, {
  1681. key: "header",
  1682. get: function get() {
  1683. return this._header;
  1684. },
  1685. set: function set(value) {
  1686. var _this = this;
  1687. if (value !== undefined) {
  1688. this._header = value;
  1689. this.headers.forEach(function (text, index) {
  1690. _this._worksheet.getCell(index + 1, _this.number).value = text;
  1691. });
  1692. } else {
  1693. this._header = undefined;
  1694. }
  1695. }
  1696. }, {
  1697. key: "key",
  1698. get: function get() {
  1699. return this._key;
  1700. },
  1701. set: function set(value) {
  1702. var column = this._key && this._worksheet.getColumnKey(this._key);
  1703. if (column === this) {
  1704. this._worksheet.deleteColumnKey(this._key);
  1705. }
  1706. this._key = value;
  1707. if (value) {
  1708. this._worksheet.setColumnKey(this._key, this);
  1709. }
  1710. }
  1711. }, {
  1712. key: "hidden",
  1713. get: function get() {
  1714. return !!this._hidden;
  1715. },
  1716. set: function set(value) {
  1717. this._hidden = value;
  1718. }
  1719. }, {
  1720. key: "outlineLevel",
  1721. get: function get() {
  1722. return this._outlineLevel || 0;
  1723. },
  1724. set: function set(value) {
  1725. this._outlineLevel = value;
  1726. }
  1727. }, {
  1728. key: "collapsed",
  1729. get: function get() {
  1730. return !!(this._outlineLevel && this._outlineLevel >= this._worksheet.properties.outlineLevelCol);
  1731. }
  1732. }, {
  1733. key: "isDefault",
  1734. get: function get() {
  1735. if (this.isCustomWidth) {
  1736. return false;
  1737. }
  1738. if (this.hidden) {
  1739. return false;
  1740. }
  1741. if (this.outlineLevel) {
  1742. return false;
  1743. }
  1744. var s = this.style;
  1745. if (s && (s.font || s.numFmt || s.alignment || s.border || s.fill || s.protection)) {
  1746. return false;
  1747. }
  1748. return true;
  1749. }
  1750. }, {
  1751. key: "headerCount",
  1752. get: function get() {
  1753. return this.headers.length;
  1754. }
  1755. }, {
  1756. key: "values",
  1757. get: function get() {
  1758. var v = [];
  1759. this.eachCell(function (cell, rowNumber) {
  1760. if (cell && cell.type !== Enums.ValueType.Null) {
  1761. v[rowNumber] = cell.value;
  1762. }
  1763. });
  1764. return v;
  1765. },
  1766. set: function set(v) {
  1767. var _this2 = this;
  1768. if (!v) {
  1769. return;
  1770. }
  1771. var colNumber = this.number;
  1772. var offset = 0;
  1773. if (v.hasOwnProperty('0')) {
  1774. // assume contiguous array, start at row 1
  1775. offset = 1;
  1776. }
  1777. v.forEach(function (value, index) {
  1778. _this2._worksheet.getCell(index + offset, colNumber).value = value;
  1779. });
  1780. }
  1781. }, {
  1782. key: "numFmt",
  1783. get: function get() {
  1784. return this.style.numFmt;
  1785. },
  1786. set: function set(value) {
  1787. this._applyStyle('numFmt', value);
  1788. }
  1789. }, {
  1790. key: "font",
  1791. get: function get() {
  1792. return this.style.font;
  1793. },
  1794. set: function set(value) {
  1795. this._applyStyle('font', value);
  1796. }
  1797. }, {
  1798. key: "alignment",
  1799. get: function get() {
  1800. return this.style.alignment;
  1801. },
  1802. set: function set(value) {
  1803. this._applyStyle('alignment', value);
  1804. }
  1805. }, {
  1806. key: "protection",
  1807. get: function get() {
  1808. return this.style.protection;
  1809. },
  1810. set: function set(value) {
  1811. this._applyStyle('protection', value);
  1812. }
  1813. }, {
  1814. key: "border",
  1815. get: function get() {
  1816. return this.style.border;
  1817. },
  1818. set: function set(value) {
  1819. this._applyStyle('border', value);
  1820. }
  1821. }, {
  1822. key: "fill",
  1823. get: function get() {
  1824. return this.style.fill;
  1825. },
  1826. set: function set(value) {
  1827. this._applyStyle('fill', value);
  1828. } // =============================================================================
  1829. // static functions
  1830. }], [{
  1831. key: "toModel",
  1832. value: function toModel(columns) {
  1833. // Convert array of Column into compressed list cols
  1834. var cols = [];
  1835. var col = null;
  1836. if (columns) {
  1837. columns.forEach(function (column, index) {
  1838. if (column.isDefault) {
  1839. if (col) {
  1840. col = null;
  1841. }
  1842. } else if (!col || !column.equivalentTo(col)) {
  1843. col = {
  1844. min: index + 1,
  1845. max: index + 1,
  1846. width: column.width !== undefined ? column.width : DEFAULT_COLUMN_WIDTH,
  1847. style: column.style,
  1848. isCustomWidth: column.isCustomWidth,
  1849. hidden: column.hidden,
  1850. outlineLevel: column.outlineLevel,
  1851. collapsed: column.collapsed
  1852. };
  1853. cols.push(col);
  1854. } else {
  1855. col.max = index + 1;
  1856. }
  1857. });
  1858. }
  1859. return cols.length ? cols : undefined;
  1860. }
  1861. }, {
  1862. key: "fromModel",
  1863. value: function fromModel(worksheet, cols) {
  1864. cols = cols || [];
  1865. var columns = [];
  1866. var count = 1;
  1867. var index = 0;
  1868. while (index < cols.length) {
  1869. var col = cols[index++];
  1870. while (count < col.min) {
  1871. columns.push(new Column(worksheet, count++));
  1872. }
  1873. while (count <= col.max) {
  1874. columns.push(new Column(worksheet, count++, col));
  1875. }
  1876. }
  1877. return columns.length ? columns : null;
  1878. }
  1879. }]);
  1880. return Column;
  1881. }();
  1882. module.exports = Column;
  1883. },{"../utils/col-cache":19,"../utils/under-dash":25,"./enums":7}],5:[function(require,module,exports){
  1884. "use strict";
  1885. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1886. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  1887. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  1888. var DataValidations = /*#__PURE__*/function () {
  1889. function DataValidations(model) {
  1890. _classCallCheck(this, DataValidations);
  1891. this.model = model || {};
  1892. }
  1893. _createClass(DataValidations, [{
  1894. key: "add",
  1895. value: function add(address, validation) {
  1896. return this.model[address] = validation;
  1897. }
  1898. }, {
  1899. key: "find",
  1900. value: function find(address) {
  1901. return this.model[address];
  1902. }
  1903. }, {
  1904. key: "remove",
  1905. value: function remove(address) {
  1906. this.model[address] = undefined;
  1907. }
  1908. }]);
  1909. return DataValidations;
  1910. }();
  1911. module.exports = DataValidations;
  1912. },{}],6:[function(require,module,exports){
  1913. 'use strict';
  1914. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1915. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  1916. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  1917. var _ = require('../utils/under-dash');
  1918. var colCache = require('../utils/col-cache');
  1919. var CellMatrix = require('../utils/cell-matrix');
  1920. var Range = require('./range');
  1921. var rangeRegexp = /[$](\w+)[$](\d+)(:[$](\w+)[$](\d+))?/;
  1922. var DefinedNames = /*#__PURE__*/function () {
  1923. function DefinedNames() {
  1924. _classCallCheck(this, DefinedNames);
  1925. this.matrixMap = {};
  1926. }
  1927. _createClass(DefinedNames, [{
  1928. key: "getMatrix",
  1929. value: function getMatrix(name) {
  1930. var matrix = this.matrixMap[name] || (this.matrixMap[name] = new CellMatrix());
  1931. return matrix;
  1932. } // add a name to a cell. locStr in the form SheetName!$col$row or SheetName!$c1$r1:$c2:$r2
  1933. }, {
  1934. key: "add",
  1935. value: function add(locStr, name) {
  1936. var location = colCache.decodeEx(locStr);
  1937. this.addEx(location, name);
  1938. }
  1939. }, {
  1940. key: "addEx",
  1941. value: function addEx(location, name) {
  1942. var matrix = this.getMatrix(name);
  1943. if (location.top) {
  1944. for (var col = location.left; col <= location.right; col++) {
  1945. for (var row = location.top; row <= location.bottom; row++) {
  1946. var address = {
  1947. sheetName: location.sheetName,
  1948. address: colCache.n2l(col) + row,
  1949. row: row,
  1950. col: col
  1951. };
  1952. matrix.addCellEx(address);
  1953. }
  1954. }
  1955. } else {
  1956. matrix.addCellEx(location);
  1957. }
  1958. }
  1959. }, {
  1960. key: "remove",
  1961. value: function remove(locStr, name) {
  1962. var location = colCache.decodeEx(locStr);
  1963. this.removeEx(location, name);
  1964. }
  1965. }, {
  1966. key: "removeEx",
  1967. value: function removeEx(location, name) {
  1968. var matrix = this.getMatrix(name);
  1969. matrix.removeCellEx(location);
  1970. }
  1971. }, {
  1972. key: "removeAllNames",
  1973. value: function removeAllNames(location) {
  1974. _.each(this.matrixMap, function (matrix) {
  1975. matrix.removeCellEx(location);
  1976. });
  1977. }
  1978. }, {
  1979. key: "forEach",
  1980. value: function forEach(callback) {
  1981. _.each(this.matrixMap, function (matrix, name) {
  1982. matrix.forEach(function (cell) {
  1983. callback(name, cell);
  1984. });
  1985. });
  1986. } // get all the names of a cell
  1987. }, {
  1988. key: "getNames",
  1989. value: function getNames(addressStr) {
  1990. return this.getNamesEx(colCache.decodeEx(addressStr));
  1991. }
  1992. }, {
  1993. key: "getNamesEx",
  1994. value: function getNamesEx(address) {
  1995. return _.map(this.matrixMap, function (matrix, name) {
  1996. return matrix.findCellEx(address) && name;
  1997. }).filter(Boolean);
  1998. }
  1999. }, {
  2000. key: "_explore",
  2001. value: function _explore(matrix, cell) {
  2002. cell.mark = false;
  2003. var sheetName = cell.sheetName;
  2004. var range = new Range(cell.row, cell.col, cell.row, cell.col, sheetName);
  2005. var x;
  2006. var y; // grow vertical - only one col to worry about
  2007. function vGrow(yy, edge) {
  2008. var c = matrix.findCellAt(sheetName, yy, cell.col);
  2009. if (!c || !c.mark) {
  2010. return false;
  2011. }
  2012. range[edge] = yy;
  2013. c.mark = false;
  2014. return true;
  2015. }
  2016. for (y = cell.row - 1; vGrow(y, 'top'); y--) {
  2017. ;
  2018. }
  2019. for (y = cell.row + 1; vGrow(y, 'bottom'); y++) {
  2020. ;
  2021. } // grow horizontal - ensure all rows can grow
  2022. function hGrow(xx, edge) {
  2023. var cells = [];
  2024. for (y = range.top; y <= range.bottom; y++) {
  2025. var c = matrix.findCellAt(sheetName, y, xx);
  2026. if (c && c.mark) {
  2027. cells.push(c);
  2028. } else {
  2029. return false;
  2030. }
  2031. }
  2032. range[edge] = xx;
  2033. for (var i = 0; i < cells.length; i++) {
  2034. cells[i].mark = false;
  2035. }
  2036. return true;
  2037. }
  2038. for (x = cell.col - 1; hGrow(x, 'left'); x--) {
  2039. ;
  2040. }
  2041. for (x = cell.col + 1; hGrow(x, 'right'); x++) {
  2042. ;
  2043. }
  2044. return range;
  2045. }
  2046. }, {
  2047. key: "getRanges",
  2048. value: function getRanges(name, matrix) {
  2049. var _this = this;
  2050. matrix = matrix || this.matrixMap[name];
  2051. if (!matrix) {
  2052. return {
  2053. name: name,
  2054. ranges: []
  2055. };
  2056. } // mark and sweep!
  2057. matrix.forEach(function (cell) {
  2058. cell.mark = true;
  2059. });
  2060. var ranges = matrix.map(function (cell) {
  2061. return cell.mark && _this._explore(matrix, cell);
  2062. }).filter(Boolean).map(function (range) {
  2063. return range.$shortRange;
  2064. });
  2065. return {
  2066. name: name,
  2067. ranges: ranges
  2068. };
  2069. }
  2070. }, {
  2071. key: "normaliseMatrix",
  2072. value: function normaliseMatrix(matrix, sheetName) {
  2073. // some of the cells might have shifted on specified sheet
  2074. // need to reassign rows, cols
  2075. matrix.forEachInSheet(sheetName, function (cell, row, col) {
  2076. if (cell) {
  2077. if (cell.row !== row || cell.col !== col) {
  2078. cell.row = row;
  2079. cell.col = col;
  2080. cell.address = colCache.n2l(col) + row;
  2081. }
  2082. }
  2083. });
  2084. }
  2085. }, {
  2086. key: "spliceRows",
  2087. value: function spliceRows(sheetName, start, numDelete, numInsert) {
  2088. var _this2 = this;
  2089. _.each(this.matrixMap, function (matrix) {
  2090. matrix.spliceRows(sheetName, start, numDelete, numInsert);
  2091. _this2.normaliseMatrix(matrix, sheetName);
  2092. });
  2093. }
  2094. }, {
  2095. key: "spliceColumns",
  2096. value: function spliceColumns(sheetName, start, numDelete, numInsert) {
  2097. var _this3 = this;
  2098. _.each(this.matrixMap, function (matrix) {
  2099. matrix.spliceColumns(sheetName, start, numDelete, numInsert);
  2100. _this3.normaliseMatrix(matrix, sheetName);
  2101. });
  2102. }
  2103. }, {
  2104. key: "model",
  2105. get: function get() {
  2106. var _this4 = this;
  2107. // To get names per cell - just iterate over all names finding cells if they exist
  2108. return _.map(this.matrixMap, function (matrix, name) {
  2109. return _this4.getRanges(name, matrix);
  2110. }).filter(function (definedName) {
  2111. return definedName.ranges.length;
  2112. });
  2113. },
  2114. set: function set(value) {
  2115. // value is [ { name, ranges }, ... ]
  2116. var matrixMap = this.matrixMap = {};
  2117. value.forEach(function (definedName) {
  2118. var matrix = matrixMap[definedName.name] = new CellMatrix();
  2119. definedName.ranges.forEach(function (rangeStr) {
  2120. if (rangeRegexp.test(rangeStr.split('!').pop() || '')) {
  2121. matrix.addCell(rangeStr);
  2122. }
  2123. });
  2124. });
  2125. }
  2126. }]);
  2127. return DefinedNames;
  2128. }();
  2129. module.exports = DefinedNames;
  2130. },{"../utils/cell-matrix":18,"../utils/col-cache":19,"../utils/under-dash":25,"./range":10}],7:[function(require,module,exports){
  2131. 'use strict';
  2132. module.exports = {
  2133. ValueType: {
  2134. Null: 0,
  2135. Merge: 1,
  2136. Number: 2,
  2137. String: 3,
  2138. Date: 4,
  2139. Hyperlink: 5,
  2140. Formula: 6,
  2141. SharedString: 7,
  2142. RichText: 8,
  2143. Boolean: 9,
  2144. Error: 10
  2145. },
  2146. FormulaType: {
  2147. None: 0,
  2148. Master: 1,
  2149. Shared: 2
  2150. },
  2151. RelationshipType: {
  2152. None: 0,
  2153. OfficeDocument: 1,
  2154. Worksheet: 2,
  2155. CalcChain: 3,
  2156. SharedStrings: 4,
  2157. Styles: 5,
  2158. Theme: 6,
  2159. Hyperlink: 7
  2160. },
  2161. DocumentType: {
  2162. Xlsx: 1
  2163. },
  2164. ReadingOrder: {
  2165. LeftToRight: 1,
  2166. RightToLeft: 2
  2167. },
  2168. ErrorValue: {
  2169. NotApplicable: '#N/A',
  2170. Ref: '#REF!',
  2171. Name: '#NAME?',
  2172. DivZero: '#DIV/0!',
  2173. Null: '#NULL!',
  2174. Value: '#VALUE!',
  2175. Num: '#NUM!'
  2176. }
  2177. };
  2178. },{}],8:[function(require,module,exports){
  2179. "use strict";
  2180. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2181. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  2182. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  2183. var colCache = require('../utils/col-cache');
  2184. var Anchor = require('./anchor');
  2185. var Image = /*#__PURE__*/function () {
  2186. function Image(worksheet, model) {
  2187. _classCallCheck(this, Image);
  2188. this.worksheet = worksheet;
  2189. this.model = model;
  2190. }
  2191. _createClass(Image, [{
  2192. key: "model",
  2193. get: function get() {
  2194. switch (this.type) {
  2195. case 'background':
  2196. return {
  2197. type: this.type,
  2198. imageId: this.imageId
  2199. };
  2200. case 'image':
  2201. return {
  2202. type: this.type,
  2203. imageId: this.imageId,
  2204. hyperlinks: this.range.hyperlinks,
  2205. range: {
  2206. tl: this.range.tl.model,
  2207. br: this.range.br && this.range.br.model,
  2208. ext: this.range.ext,
  2209. editAs: this.range.editAs
  2210. }
  2211. };
  2212. default:
  2213. throw new Error('Invalid Image Type');
  2214. }
  2215. },
  2216. set: function set(_ref) {
  2217. var type = _ref.type,
  2218. imageId = _ref.imageId,
  2219. range = _ref.range,
  2220. hyperlinks = _ref.hyperlinks;
  2221. this.type = type;
  2222. this.imageId = imageId;
  2223. if (type === 'image') {
  2224. if (typeof range === 'string') {
  2225. var decoded = colCache.decode(range);
  2226. this.range = {
  2227. tl: new Anchor(this.worksheet, {
  2228. col: decoded.left,
  2229. row: decoded.top
  2230. }, -1),
  2231. br: new Anchor(this.worksheet, {
  2232. col: decoded.right,
  2233. row: decoded.bottom
  2234. }, 0),
  2235. editAs: 'oneCell'
  2236. };
  2237. } else {
  2238. this.range = {
  2239. tl: new Anchor(this.worksheet, range.tl, 0),
  2240. br: range.br && new Anchor(this.worksheet, range.br, 0),
  2241. ext: range.ext,
  2242. editAs: range.editAs,
  2243. hyperlinks: hyperlinks || range.hyperlinks
  2244. };
  2245. }
  2246. }
  2247. }
  2248. }]);
  2249. return Image;
  2250. }();
  2251. module.exports = Image;
  2252. },{"../utils/col-cache":19,"./anchor":2}],9:[function(require,module,exports){
  2253. "use strict";
  2254. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  2255. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2256. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  2257. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  2258. var _ = require('../utils/under-dash');
  2259. var Note = /*#__PURE__*/function () {
  2260. function Note(note) {
  2261. _classCallCheck(this, Note);
  2262. this.note = note;
  2263. }
  2264. _createClass(Note, [{
  2265. key: "model",
  2266. get: function get() {
  2267. var value = null;
  2268. switch (_typeof(this.note)) {
  2269. case 'string':
  2270. value = {
  2271. type: 'note',
  2272. note: {
  2273. texts: [{
  2274. text: this.note
  2275. }]
  2276. }
  2277. };
  2278. break;
  2279. default:
  2280. value = {
  2281. type: 'note',
  2282. note: this.note
  2283. };
  2284. break;
  2285. } // Suitable for all cell comments
  2286. return _.deepMerge({}, Note.DEFAULT_CONFIGS, value);
  2287. },
  2288. set: function set(value) {
  2289. var note = value.note;
  2290. var texts = note.texts;
  2291. if (texts.length === 1 && Object.keys(texts[0]).length === 1) {
  2292. this.note = texts[0].text;
  2293. } else {
  2294. this.note = note;
  2295. }
  2296. }
  2297. }], [{
  2298. key: "fromModel",
  2299. value: function fromModel(model) {
  2300. var note = new Note();
  2301. note.model = model;
  2302. return note;
  2303. }
  2304. }]);
  2305. return Note;
  2306. }();
  2307. Note.DEFAULT_CONFIGS = {
  2308. note: {
  2309. margins: {
  2310. insetmode: 'auto',
  2311. inset: [0.13, 0.13, 0.25, 0.25]
  2312. },
  2313. protection: {
  2314. locked: 'True',
  2315. lockText: 'True'
  2316. },
  2317. editAs: 'absolute'
  2318. }
  2319. };
  2320. module.exports = Note;
  2321. },{"../utils/under-dash":25}],10:[function(require,module,exports){
  2322. "use strict";
  2323. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2324. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  2325. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  2326. var colCache = require('../utils/col-cache'); // used by worksheet to calculate sheet dimensions
  2327. var Range = /*#__PURE__*/function () {
  2328. function Range() {
  2329. _classCallCheck(this, Range);
  2330. this.decode(arguments);
  2331. }
  2332. _createClass(Range, [{
  2333. key: "setTLBR",
  2334. value: function setTLBR(t, l, b, r, s) {
  2335. if (arguments.length < 4) {
  2336. // setTLBR(tl, br, s)
  2337. var tl = colCache.decodeAddress(t);
  2338. var br = colCache.decodeAddress(l);
  2339. this.model = {
  2340. top: Math.min(tl.row, br.row),
  2341. left: Math.min(tl.col, br.col),
  2342. bottom: Math.max(tl.row, br.row),
  2343. right: Math.max(tl.col, br.col),
  2344. sheetName: b
  2345. };
  2346. this.setTLBR(tl.row, tl.col, br.row, br.col, s);
  2347. } else {
  2348. // setTLBR(t, l, b, r, s)
  2349. this.model = {
  2350. top: Math.min(t, b),
  2351. left: Math.min(l, r),
  2352. bottom: Math.max(t, b),
  2353. right: Math.max(l, r),
  2354. sheetName: s
  2355. };
  2356. }
  2357. }
  2358. }, {
  2359. key: "decode",
  2360. value: function decode(argv) {
  2361. switch (argv.length) {
  2362. case 5:
  2363. // [t,l,b,r,s]
  2364. this.setTLBR(argv[0], argv[1], argv[2], argv[3], argv[4]);
  2365. break;
  2366. case 4:
  2367. // [t,l,b,r]
  2368. this.setTLBR(argv[0], argv[1], argv[2], argv[3]);
  2369. break;
  2370. case 3:
  2371. // [tl,br,s]
  2372. this.setTLBR(argv[0], argv[1], argv[2]);
  2373. break;
  2374. case 2:
  2375. // [tl,br]
  2376. this.setTLBR(argv[0], argv[1]);
  2377. break;
  2378. case 1:
  2379. {
  2380. var value = argv[0];
  2381. if (value instanceof Range) {
  2382. // copy constructor
  2383. this.model = {
  2384. top: value.model.top,
  2385. left: value.model.left,
  2386. bottom: value.model.bottom,
  2387. right: value.model.right,
  2388. sheetName: value.sheetName
  2389. };
  2390. } else if (value instanceof Array) {
  2391. // an arguments array
  2392. this.decode(value);
  2393. } else if (value.top && value.left && value.bottom && value.right) {
  2394. // a model
  2395. this.model = {
  2396. top: value.top,
  2397. left: value.left,
  2398. bottom: value.bottom,
  2399. right: value.right,
  2400. sheetName: value.sheetName
  2401. };
  2402. } else {
  2403. // [sheetName!]tl:br
  2404. var tlbr = colCache.decodeEx(value);
  2405. if (tlbr.top) {
  2406. this.model = {
  2407. top: tlbr.top,
  2408. left: tlbr.left,
  2409. bottom: tlbr.bottom,
  2410. right: tlbr.right,
  2411. sheetName: tlbr.sheetName
  2412. };
  2413. } else {
  2414. this.model = {
  2415. top: tlbr.row,
  2416. left: tlbr.col,
  2417. bottom: tlbr.row,
  2418. right: tlbr.col,
  2419. sheetName: tlbr.sheetName
  2420. };
  2421. }
  2422. }
  2423. break;
  2424. }
  2425. case 0:
  2426. this.model = {
  2427. top: 0,
  2428. left: 0,
  2429. bottom: 0,
  2430. right: 0
  2431. };
  2432. break;
  2433. default:
  2434. throw new Error("Invalid number of arguments to _getDimensions() - ".concat(argv.length));
  2435. }
  2436. }
  2437. }, {
  2438. key: "expand",
  2439. value: function expand(top, left, bottom, right) {
  2440. if (!this.model.top || top < this.top) this.top = top;
  2441. if (!this.model.left || left < this.left) this.left = left;
  2442. if (!this.model.bottom || bottom > this.bottom) this.bottom = bottom;
  2443. if (!this.model.right || right > this.right) this.right = right;
  2444. }
  2445. }, {
  2446. key: "expandRow",
  2447. value: function expandRow(row) {
  2448. if (row) {
  2449. var dimensions = row.dimensions,
  2450. number = row.number;
  2451. if (dimensions) {
  2452. this.expand(number, dimensions.min, number, dimensions.max);
  2453. }
  2454. }
  2455. }
  2456. }, {
  2457. key: "expandToAddress",
  2458. value: function expandToAddress(addressStr) {
  2459. var address = colCache.decodeEx(addressStr);
  2460. this.expand(address.row, address.col, address.row, address.col);
  2461. }
  2462. }, {
  2463. key: "toString",
  2464. value: function toString() {
  2465. return this.range;
  2466. }
  2467. }, {
  2468. key: "intersects",
  2469. value: function intersects(other) {
  2470. if (other.sheetName && this.sheetName && other.sheetName !== this.sheetName) return false;
  2471. if (other.bottom < this.top) return false;
  2472. if (other.top > this.bottom) return false;
  2473. if (other.right < this.left) return false;
  2474. if (other.left > this.right) return false;
  2475. return true;
  2476. }
  2477. }, {
  2478. key: "contains",
  2479. value: function contains(addressStr) {
  2480. var address = colCache.decodeEx(addressStr);
  2481. return this.containsEx(address);
  2482. }
  2483. }, {
  2484. key: "containsEx",
  2485. value: function containsEx(address) {
  2486. if (address.sheetName && this.sheetName && address.sheetName !== this.sheetName) return false;
  2487. return address.row >= this.top && address.row <= this.bottom && address.col >= this.left && address.col <= this.right;
  2488. }
  2489. }, {
  2490. key: "forEachAddress",
  2491. value: function forEachAddress(cb) {
  2492. for (var col = this.left; col <= this.right; col++) {
  2493. for (var row = this.top; row <= this.bottom; row++) {
  2494. cb(colCache.encodeAddress(row, col), row, col);
  2495. }
  2496. }
  2497. }
  2498. }, {
  2499. key: "top",
  2500. get: function get() {
  2501. return this.model.top || 1;
  2502. },
  2503. set: function set(value) {
  2504. this.model.top = value;
  2505. }
  2506. }, {
  2507. key: "left",
  2508. get: function get() {
  2509. return this.model.left || 1;
  2510. },
  2511. set: function set(value) {
  2512. this.model.left = value;
  2513. }
  2514. }, {
  2515. key: "bottom",
  2516. get: function get() {
  2517. return this.model.bottom || 1;
  2518. },
  2519. set: function set(value) {
  2520. this.model.bottom = value;
  2521. }
  2522. }, {
  2523. key: "right",
  2524. get: function get() {
  2525. return this.model.right || 1;
  2526. },
  2527. set: function set(value) {
  2528. this.model.right = value;
  2529. }
  2530. }, {
  2531. key: "sheetName",
  2532. get: function get() {
  2533. return this.model.sheetName;
  2534. },
  2535. set: function set(value) {
  2536. this.model.sheetName = value;
  2537. }
  2538. }, {
  2539. key: "_serialisedSheetName",
  2540. get: function get() {
  2541. var sheetName = this.model.sheetName;
  2542. if (sheetName) {
  2543. if (/^[a-zA-Z0-9]*$/.test(sheetName)) {
  2544. return "".concat(sheetName, "!");
  2545. }
  2546. return "'".concat(sheetName, "'!");
  2547. }
  2548. return '';
  2549. }
  2550. }, {
  2551. key: "tl",
  2552. get: function get() {
  2553. return colCache.n2l(this.left) + this.top;
  2554. }
  2555. }, {
  2556. key: "$t$l",
  2557. get: function get() {
  2558. return "$".concat(colCache.n2l(this.left), "$").concat(this.top);
  2559. }
  2560. }, {
  2561. key: "br",
  2562. get: function get() {
  2563. return colCache.n2l(this.right) + this.bottom;
  2564. }
  2565. }, {
  2566. key: "$b$r",
  2567. get: function get() {
  2568. return "$".concat(colCache.n2l(this.right), "$").concat(this.bottom);
  2569. }
  2570. }, {
  2571. key: "range",
  2572. get: function get() {
  2573. return "".concat(this._serialisedSheetName + this.tl, ":").concat(this.br);
  2574. }
  2575. }, {
  2576. key: "$range",
  2577. get: function get() {
  2578. return "".concat(this._serialisedSheetName + this.$t$l, ":").concat(this.$b$r);
  2579. }
  2580. }, {
  2581. key: "shortRange",
  2582. get: function get() {
  2583. return this.count > 1 ? this.range : this._serialisedSheetName + this.tl;
  2584. }
  2585. }, {
  2586. key: "$shortRange",
  2587. get: function get() {
  2588. return this.count > 1 ? this.$range : this._serialisedSheetName + this.$t$l;
  2589. }
  2590. }, {
  2591. key: "count",
  2592. get: function get() {
  2593. return (1 + this.bottom - this.top) * (1 + this.right - this.left);
  2594. }
  2595. }]);
  2596. return Range;
  2597. }();
  2598. module.exports = Range;
  2599. },{"../utils/col-cache":19}],11:[function(require,module,exports){
  2600. 'use strict';
  2601. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2602. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  2603. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  2604. var _ = require('../utils/under-dash');
  2605. var Enums = require('./enums');
  2606. var colCache = require('../utils/col-cache');
  2607. var Cell = require('./cell');
  2608. var Row = /*#__PURE__*/function () {
  2609. function Row(worksheet, number) {
  2610. _classCallCheck(this, Row);
  2611. this._worksheet = worksheet;
  2612. this._number = number;
  2613. this._cells = [];
  2614. this.style = {};
  2615. this.outlineLevel = 0;
  2616. } // return the row number
  2617. _createClass(Row, [{
  2618. key: "commit",
  2619. // Inform Streaming Writer that this row (and all rows before it) are complete
  2620. // and ready to write. Has no effect on Worksheet document
  2621. value: function commit() {
  2622. this._worksheet._commitRow(this); // eslint-disable-line no-underscore-dangle
  2623. } // helps GC by breaking cyclic references
  2624. }, {
  2625. key: "destroy",
  2626. value: function destroy() {
  2627. delete this._worksheet;
  2628. delete this._cells;
  2629. delete this.style;
  2630. }
  2631. }, {
  2632. key: "findCell",
  2633. value: function findCell(colNumber) {
  2634. return this._cells[colNumber - 1];
  2635. } // given {address, row, col}, find or create new cell
  2636. }, {
  2637. key: "getCellEx",
  2638. value: function getCellEx(address) {
  2639. var cell = this._cells[address.col - 1];
  2640. if (!cell) {
  2641. var column = this._worksheet.getColumn(address.col);
  2642. cell = new Cell(this, column, address.address);
  2643. this._cells[address.col - 1] = cell;
  2644. }
  2645. return cell;
  2646. } // get cell by key, letter or column number
  2647. }, {
  2648. key: "getCell",
  2649. value: function getCell(col) {
  2650. if (typeof col === 'string') {
  2651. // is it a key?
  2652. var column = this._worksheet.getColumnKey(col);
  2653. if (column) {
  2654. col = column.number;
  2655. } else {
  2656. col = colCache.l2n(col);
  2657. }
  2658. }
  2659. return this._cells[col - 1] || this.getCellEx({
  2660. address: colCache.encodeAddress(this._number, col),
  2661. row: this._number,
  2662. col: col
  2663. });
  2664. } // remove cell(s) and shift all higher cells down by count
  2665. }, {
  2666. key: "splice",
  2667. value: function splice(start, count) {
  2668. var nKeep = start + count;
  2669. for (var _len = arguments.length, inserts = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
  2670. inserts[_key - 2] = arguments[_key];
  2671. }
  2672. var nExpand = inserts.length - count;
  2673. var nEnd = this._cells.length;
  2674. var i;
  2675. var cSrc;
  2676. var cDst;
  2677. if (nExpand < 0) {
  2678. // remove cells
  2679. for (i = start + inserts.length; i <= nEnd; i++) {
  2680. cDst = this._cells[i - 1];
  2681. cSrc = this._cells[i - nExpand - 1];
  2682. if (cSrc) {
  2683. cDst = this.getCell(i);
  2684. cDst.value = cSrc.value;
  2685. cDst.style = cSrc.style; // eslint-disable-next-line no-underscore-dangle
  2686. cDst._comment = cSrc._comment;
  2687. } else if (cDst) {
  2688. cDst.value = null;
  2689. cDst.style = {}; // eslint-disable-next-line no-underscore-dangle
  2690. cDst._comment = undefined;
  2691. }
  2692. }
  2693. } else if (nExpand > 0) {
  2694. // insert new cells
  2695. for (i = nEnd; i >= nKeep; i--) {
  2696. cSrc = this._cells[i - 1];
  2697. if (cSrc) {
  2698. cDst = this.getCell(i + nExpand);
  2699. cDst.value = cSrc.value;
  2700. cDst.style = cSrc.style; // eslint-disable-next-line no-underscore-dangle
  2701. cDst._comment = cSrc._comment;
  2702. } else {
  2703. this._cells[i + nExpand - 1] = undefined;
  2704. }
  2705. }
  2706. } // now add the new values
  2707. for (i = 0; i < inserts.length; i++) {
  2708. cDst = this.getCell(start + i);
  2709. cDst.value = inserts[i];
  2710. cDst.style = {}; // eslint-disable-next-line no-underscore-dangle
  2711. cDst._comment = undefined;
  2712. }
  2713. } // Iterate over all non-null cells in this row
  2714. }, {
  2715. key: "eachCell",
  2716. value: function eachCell(options, iteratee) {
  2717. if (!iteratee) {
  2718. iteratee = options;
  2719. options = null;
  2720. }
  2721. if (options && options.includeEmpty) {
  2722. var n = this._cells.length;
  2723. for (var i = 1; i <= n; i++) {
  2724. iteratee(this.getCell(i), i);
  2725. }
  2726. } else {
  2727. this._cells.forEach(function (cell, index) {
  2728. if (cell && cell.type !== Enums.ValueType.Null) {
  2729. iteratee(cell, index + 1);
  2730. }
  2731. });
  2732. }
  2733. } // ===========================================================================
  2734. // Page Breaks
  2735. }, {
  2736. key: "addPageBreak",
  2737. value: function addPageBreak(lft, rght) {
  2738. var ws = this._worksheet;
  2739. var left = Math.max(0, lft - 1) || 0;
  2740. var right = Math.max(0, rght - 1) || 16838;
  2741. var pb = {
  2742. id: this._number,
  2743. max: right,
  2744. man: 1
  2745. };
  2746. if (left) pb.min = left;
  2747. ws.rowBreaks.push(pb);
  2748. } // return a sparse array of cell values
  2749. }, {
  2750. key: "_applyStyle",
  2751. // =========================================================================
  2752. // styles
  2753. value: function _applyStyle(name, value) {
  2754. this.style[name] = value;
  2755. this._cells.forEach(function (cell) {
  2756. if (cell) {
  2757. cell[name] = value;
  2758. }
  2759. });
  2760. return value;
  2761. }
  2762. }, {
  2763. key: "number",
  2764. get: function get() {
  2765. return this._number;
  2766. }
  2767. }, {
  2768. key: "worksheet",
  2769. get: function get() {
  2770. return this._worksheet;
  2771. }
  2772. }, {
  2773. key: "values",
  2774. get: function get() {
  2775. var values = [];
  2776. this._cells.forEach(function (cell) {
  2777. if (cell && cell.type !== Enums.ValueType.Null) {
  2778. values[cell.col] = cell.value;
  2779. }
  2780. });
  2781. return values;
  2782. } // set the values by contiguous or sparse array, or by key'd object literal
  2783. ,
  2784. set: function set(value) {
  2785. var _this = this;
  2786. // this operation is not additive - any prior cells are removed
  2787. this._cells = [];
  2788. if (!value) {// empty row
  2789. } else if (value instanceof Array) {
  2790. var offset = 0;
  2791. if (value.hasOwnProperty('0')) {
  2792. // contiguous array - start at column 1
  2793. offset = 1;
  2794. }
  2795. value.forEach(function (item, index) {
  2796. if (item !== undefined) {
  2797. _this.getCellEx({
  2798. address: colCache.encodeAddress(_this._number, index + offset),
  2799. row: _this._number,
  2800. col: index + offset
  2801. }).value = item;
  2802. }
  2803. });
  2804. } else {
  2805. // assume object with column keys
  2806. this._worksheet.eachColumnKey(function (column, key) {
  2807. if (value[key] !== undefined) {
  2808. _this.getCellEx({
  2809. address: colCache.encodeAddress(_this._number, column.number),
  2810. row: _this._number,
  2811. col: column.number
  2812. }).value = value[key];
  2813. }
  2814. });
  2815. }
  2816. } // returns true if the row includes at least one cell with a value
  2817. }, {
  2818. key: "hasValues",
  2819. get: function get() {
  2820. return _.some(this._cells, function (cell) {
  2821. return cell && cell.type !== Enums.ValueType.Null;
  2822. });
  2823. }
  2824. }, {
  2825. key: "cellCount",
  2826. get: function get() {
  2827. return this._cells.length;
  2828. }
  2829. }, {
  2830. key: "actualCellCount",
  2831. get: function get() {
  2832. var count = 0;
  2833. this.eachCell(function () {
  2834. count++;
  2835. });
  2836. return count;
  2837. } // get the min and max column number for the non-null cells in this row or null
  2838. }, {
  2839. key: "dimensions",
  2840. get: function get() {
  2841. var min = 0;
  2842. var max = 0;
  2843. this._cells.forEach(function (cell) {
  2844. if (cell && cell.type !== Enums.ValueType.Null) {
  2845. if (!min || min > cell.col) {
  2846. min = cell.col;
  2847. }
  2848. if (max < cell.col) {
  2849. max = cell.col;
  2850. }
  2851. }
  2852. });
  2853. return min > 0 ? {
  2854. min: min,
  2855. max: max
  2856. } : null;
  2857. }
  2858. }, {
  2859. key: "numFmt",
  2860. get: function get() {
  2861. return this.style.numFmt;
  2862. },
  2863. set: function set(value) {
  2864. this._applyStyle('numFmt', value);
  2865. }
  2866. }, {
  2867. key: "font",
  2868. get: function get() {
  2869. return this.style.font;
  2870. },
  2871. set: function set(value) {
  2872. this._applyStyle('font', value);
  2873. }
  2874. }, {
  2875. key: "alignment",
  2876. get: function get() {
  2877. return this.style.alignment;
  2878. },
  2879. set: function set(value) {
  2880. this._applyStyle('alignment', value);
  2881. }
  2882. }, {
  2883. key: "protection",
  2884. get: function get() {
  2885. return this.style.protection;
  2886. },
  2887. set: function set(value) {
  2888. this._applyStyle('protection', value);
  2889. }
  2890. }, {
  2891. key: "border",
  2892. get: function get() {
  2893. return this.style.border;
  2894. },
  2895. set: function set(value) {
  2896. this._applyStyle('border', value);
  2897. }
  2898. }, {
  2899. key: "fill",
  2900. get: function get() {
  2901. return this.style.fill;
  2902. },
  2903. set: function set(value) {
  2904. this._applyStyle('fill', value);
  2905. }
  2906. }, {
  2907. key: "hidden",
  2908. get: function get() {
  2909. return !!this._hidden;
  2910. },
  2911. set: function set(value) {
  2912. this._hidden = value;
  2913. }
  2914. }, {
  2915. key: "outlineLevel",
  2916. get: function get() {
  2917. return this._outlineLevel || 0;
  2918. },
  2919. set: function set(value) {
  2920. this._outlineLevel = value;
  2921. }
  2922. }, {
  2923. key: "collapsed",
  2924. get: function get() {
  2925. return !!(this._outlineLevel && this._outlineLevel >= this._worksheet.properties.outlineLevelRow);
  2926. } // =========================================================================
  2927. }, {
  2928. key: "model",
  2929. get: function get() {
  2930. var cells = [];
  2931. var min = 0;
  2932. var max = 0;
  2933. this._cells.forEach(function (cell) {
  2934. if (cell) {
  2935. var cellModel = cell.model;
  2936. if (cellModel) {
  2937. if (!min || min > cell.col) {
  2938. min = cell.col;
  2939. }
  2940. if (max < cell.col) {
  2941. max = cell.col;
  2942. }
  2943. cells.push(cellModel);
  2944. }
  2945. }
  2946. });
  2947. return this.height || cells.length ? {
  2948. cells: cells,
  2949. number: this.number,
  2950. min: min,
  2951. max: max,
  2952. height: this.height,
  2953. style: this.style,
  2954. hidden: this.hidden,
  2955. outlineLevel: this.outlineLevel,
  2956. collapsed: this.collapsed
  2957. } : null;
  2958. },
  2959. set: function set(value) {
  2960. var _this2 = this;
  2961. if (value.number !== this._number) {
  2962. throw new Error('Invalid row number in model');
  2963. }
  2964. this._cells = [];
  2965. var previousAddress;
  2966. value.cells.forEach(function (cellModel) {
  2967. switch (cellModel.type) {
  2968. case Cell.Types.Merge:
  2969. // special case - don't add this types
  2970. break;
  2971. default:
  2972. {
  2973. var address;
  2974. if (cellModel.address) {
  2975. address = colCache.decodeAddress(cellModel.address);
  2976. } else if (previousAddress) {
  2977. // This is a <c> element without an r attribute
  2978. // Assume that it's the cell for the next column
  2979. var _previousAddress = previousAddress,
  2980. row = _previousAddress.row;
  2981. var col = previousAddress.col + 1;
  2982. address = {
  2983. row: row,
  2984. col: col,
  2985. address: colCache.encodeAddress(row, col),
  2986. $col$row: "$".concat(colCache.n2l(col), "$").concat(row)
  2987. };
  2988. }
  2989. previousAddress = address;
  2990. var cell = _this2.getCellEx(address);
  2991. cell.model = cellModel;
  2992. break;
  2993. }
  2994. }
  2995. });
  2996. if (value.height) {
  2997. this.height = value.height;
  2998. } else {
  2999. delete this.height;
  3000. }
  3001. this.hidden = value.hidden;
  3002. this.outlineLevel = value.outlineLevel || 0;
  3003. this.style = value.style && JSON.parse(JSON.stringify(value.style)) || {};
  3004. }
  3005. }]);
  3006. return Row;
  3007. }();
  3008. module.exports = Row;
  3009. },{"../utils/col-cache":19,"../utils/under-dash":25,"./cell":3,"./enums":7}],12:[function(require,module,exports){
  3010. "use strict";
  3011. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3012. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  3013. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  3014. /* eslint-disable max-classes-per-file */
  3015. var colCache = require('../utils/col-cache');
  3016. var Column = /*#__PURE__*/function () {
  3017. // wrapper around column model, allowing access and manipulation
  3018. function Column(table, column, index) {
  3019. _classCallCheck(this, Column);
  3020. this.table = table;
  3021. this.column = column;
  3022. this.index = index;
  3023. }
  3024. _createClass(Column, [{
  3025. key: "_set",
  3026. value: function _set(name, value) {
  3027. this.table.cacheState();
  3028. this.column[name] = value;
  3029. }
  3030. /* eslint-disable lines-between-class-members */
  3031. }, {
  3032. key: "name",
  3033. get: function get() {
  3034. return this.column.name;
  3035. },
  3036. set: function set(value) {
  3037. this._set('name', value);
  3038. }
  3039. }, {
  3040. key: "filterButton",
  3041. get: function get() {
  3042. return this.column.filterButton;
  3043. },
  3044. set: function set(value) {
  3045. this.column.filterButton = value;
  3046. }
  3047. }, {
  3048. key: "style",
  3049. get: function get() {
  3050. return this.column.style;
  3051. },
  3052. set: function set(value) {
  3053. this.column.style = value;
  3054. }
  3055. }, {
  3056. key: "totalsRowLabel",
  3057. get: function get() {
  3058. return this.column.totalsRowLabel;
  3059. },
  3060. set: function set(value) {
  3061. this._set('totalsRowLabel', value);
  3062. }
  3063. }, {
  3064. key: "totalsRowFunction",
  3065. get: function get() {
  3066. return this.column.totalsRowFunction;
  3067. },
  3068. set: function set(value) {
  3069. this._set('totalsRowFunction', value);
  3070. }
  3071. }, {
  3072. key: "totalsRowResult",
  3073. get: function get() {
  3074. return this.column.totalsRowResult;
  3075. },
  3076. set: function set(value) {
  3077. this._set('totalsRowResult', value);
  3078. }
  3079. }, {
  3080. key: "totalsRowFormula",
  3081. get: function get() {
  3082. return this.column.totalsRowFormula;
  3083. },
  3084. set: function set(value) {
  3085. this._set('totalsRowFormula', value);
  3086. }
  3087. /* eslint-enable lines-between-class-members */
  3088. }]);
  3089. return Column;
  3090. }();
  3091. var Table = /*#__PURE__*/function () {
  3092. function Table(worksheet, table) {
  3093. _classCallCheck(this, Table);
  3094. this.worksheet = worksheet;
  3095. if (table) {
  3096. this.table = table; // check things are ok first
  3097. this.validate();
  3098. this.store();
  3099. }
  3100. }
  3101. _createClass(Table, [{
  3102. key: "getFormula",
  3103. value: function getFormula(column) {
  3104. // get the correct formula to apply to the totals row
  3105. switch (column.totalsRowFunction) {
  3106. case 'none':
  3107. return null;
  3108. case 'average':
  3109. return "SUBTOTAL(101,".concat(this.table.name, "[").concat(column.name, "])");
  3110. case 'countNums':
  3111. return "SUBTOTAL(102,".concat(this.table.name, "[").concat(column.name, "])");
  3112. case 'count':
  3113. return "SUBTOTAL(103,".concat(this.table.name, "[").concat(column.name, "])");
  3114. case 'max':
  3115. return "SUBTOTAL(104,".concat(this.table.name, "[").concat(column.name, "])");
  3116. case 'min':
  3117. return "SUBTOTAL(105,".concat(this.table.name, "[").concat(column.name, "])");
  3118. case 'stdDev':
  3119. return "SUBTOTAL(106,".concat(this.table.name, "[").concat(column.name, "])");
  3120. case 'var':
  3121. return "SUBTOTAL(107,".concat(this.table.name, "[").concat(column.name, "])");
  3122. case 'sum':
  3123. return "SUBTOTAL(109,".concat(this.table.name, "[").concat(column.name, "])");
  3124. case 'custom':
  3125. return column.totalsRowFormula;
  3126. default:
  3127. throw new Error("Invalid Totals Row Function: ".concat(column.totalsRowFunction));
  3128. }
  3129. }
  3130. }, {
  3131. key: "validate",
  3132. value: function validate() {
  3133. var _this = this;
  3134. var table = this.table; // set defaults and check is valid
  3135. var assign = function assign(o, name, dflt) {
  3136. if (o[name] === undefined) {
  3137. o[name] = dflt;
  3138. }
  3139. };
  3140. assign(table, 'headerRow', true);
  3141. assign(table, 'totalsRow', false);
  3142. assign(table, 'style', {});
  3143. assign(table.style, 'theme', 'TableStyleMedium2');
  3144. assign(table.style, 'showFirstColumn', false);
  3145. assign(table.style, 'showLastColumn', false);
  3146. assign(table.style, 'showRowStripes', false);
  3147. assign(table.style, 'showColumnStripes', false);
  3148. var assert = function assert(test, message) {
  3149. if (!test) {
  3150. throw new Error(message);
  3151. }
  3152. };
  3153. assert(table.ref, 'Table must have ref');
  3154. assert(table.columns, 'Table must have column definitions');
  3155. assert(table.rows, 'Table must have row definitions');
  3156. table.tl = colCache.decodeAddress(table.ref);
  3157. var _table$tl = table.tl,
  3158. row = _table$tl.row,
  3159. col = _table$tl.col;
  3160. assert(row > 0, 'Table must be on valid row');
  3161. assert(col > 0, 'Table must be on valid col');
  3162. var width = this.width,
  3163. filterHeight = this.filterHeight,
  3164. tableHeight = this.tableHeight; // autoFilterRef is a range that includes optional headers only
  3165. table.autoFilterRef = colCache.encode(row, col, row + filterHeight - 1, col + width - 1); // tableRef is a range that includes optional headers and totals
  3166. table.tableRef = colCache.encode(row, col, row + tableHeight - 1, col + width - 1);
  3167. table.columns.forEach(function (column, i) {
  3168. assert(column.name, "Column ".concat(i, " must have a name"));
  3169. if (i === 0) {
  3170. assign(column, 'totalsRowLabel', 'Total');
  3171. } else {
  3172. assign(column, 'totalsRowFunction', 'none');
  3173. column.totalsRowFormula = _this.getFormula(column);
  3174. }
  3175. });
  3176. }
  3177. }, {
  3178. key: "store",
  3179. value: function store() {
  3180. var _this2 = this;
  3181. // where the table needs to store table data, headers, footers in
  3182. // the sheet...
  3183. var assignStyle = function assignStyle(cell, style) {
  3184. if (style) {
  3185. Object.keys(style).forEach(function (key) {
  3186. cell[key] = style[key];
  3187. });
  3188. }
  3189. };
  3190. var worksheet = this.worksheet,
  3191. table = this.table;
  3192. var _table$tl2 = table.tl,
  3193. row = _table$tl2.row,
  3194. col = _table$tl2.col;
  3195. var count = 0;
  3196. if (table.headerRow) {
  3197. var r = worksheet.getRow(row + count++);
  3198. table.columns.forEach(function (column, j) {
  3199. var style = column.style,
  3200. name = column.name;
  3201. var cell = r.getCell(col + j);
  3202. cell.value = name;
  3203. assignStyle(cell, style);
  3204. });
  3205. }
  3206. table.rows.forEach(function (data) {
  3207. var r = worksheet.getRow(row + count++);
  3208. data.forEach(function (value, j) {
  3209. var cell = r.getCell(col + j);
  3210. cell.value = value;
  3211. assignStyle(cell, table.columns[j].style);
  3212. });
  3213. });
  3214. if (table.totalsRow) {
  3215. var _r = worksheet.getRow(row + count++);
  3216. table.columns.forEach(function (column, j) {
  3217. var cell = _r.getCell(col + j);
  3218. if (j === 0) {
  3219. cell.value = column.totalsRowLabel;
  3220. } else {
  3221. var formula = _this2.getFormula(column);
  3222. if (formula) {
  3223. cell.value = {
  3224. formula: column.totalsRowFormula,
  3225. result: column.totalsRowResult
  3226. };
  3227. } else {
  3228. cell.value = null;
  3229. }
  3230. }
  3231. assignStyle(cell, column.style);
  3232. });
  3233. }
  3234. }
  3235. }, {
  3236. key: "load",
  3237. value: function load(worksheet) {
  3238. var _this3 = this;
  3239. // where the table will read necessary features from a loaded sheet
  3240. var table = this.table;
  3241. var _table$tl3 = table.tl,
  3242. row = _table$tl3.row,
  3243. col = _table$tl3.col;
  3244. var count = 0;
  3245. if (table.headerRow) {
  3246. var r = worksheet.getRow(row + count++);
  3247. table.columns.forEach(function (column, j) {
  3248. var cell = r.getCell(col + j);
  3249. cell.value = column.name;
  3250. });
  3251. }
  3252. table.rows.forEach(function (data) {
  3253. var r = worksheet.getRow(row + count++);
  3254. data.forEach(function (value, j) {
  3255. var cell = r.getCell(col + j);
  3256. cell.value = value;
  3257. });
  3258. });
  3259. if (table.totalsRow) {
  3260. var _r2 = worksheet.getRow(row + count++);
  3261. table.columns.forEach(function (column, j) {
  3262. var cell = _r2.getCell(col + j);
  3263. if (j === 0) {
  3264. cell.value = column.totalsRowLabel;
  3265. } else {
  3266. var formula = _this3.getFormula(column);
  3267. if (formula) {
  3268. cell.value = {
  3269. formula: column.totalsRowFormula,
  3270. result: column.totalsRowResult
  3271. };
  3272. }
  3273. }
  3274. });
  3275. }
  3276. }
  3277. }, {
  3278. key: "cacheState",
  3279. // ================================================================
  3280. // TODO: Mutating methods
  3281. value: function cacheState() {
  3282. if (!this._cache) {
  3283. this._cache = {
  3284. ref: this.ref,
  3285. width: this.width,
  3286. tableHeight: this.tableHeight
  3287. };
  3288. }
  3289. }
  3290. }, {
  3291. key: "commit",
  3292. value: function commit() {
  3293. // changes may have been made that might have on-sheet effects
  3294. if (!this._cache) {
  3295. return;
  3296. } // check things are ok first
  3297. this.validate();
  3298. var ref = colCache.decodeAddress(this._cache.ref);
  3299. if (this.ref !== this._cache.ref) {
  3300. // wipe out whole table footprint at previous location
  3301. for (var i = 0; i < this._cache.tableHeight; i++) {
  3302. var row = this.worksheet.getRow(ref.row + i);
  3303. for (var j = 0; j < this._cache.width; j++) {
  3304. var cell = row.getCell(ref.col + j);
  3305. cell.value = null;
  3306. }
  3307. }
  3308. } else {
  3309. // clear out below table if it has shrunk
  3310. for (var _i = this.tableHeight; _i < this._cache.tableHeight; _i++) {
  3311. var _row = this.worksheet.getRow(ref.row + _i);
  3312. for (var _j = 0; _j < this._cache.width; _j++) {
  3313. var _cell = _row.getCell(ref.col + _j);
  3314. _cell.value = null;
  3315. }
  3316. } // clear out to right of table if it has lost columns
  3317. for (var _i2 = 0; _i2 < this.tableHeight; _i2++) {
  3318. var _row2 = this.worksheet.getRow(ref.row + _i2);
  3319. for (var _j2 = this.width; _j2 < this._cache.width; _j2++) {
  3320. var _cell2 = _row2.getCell(ref.col + _j2);
  3321. _cell2.value = null;
  3322. }
  3323. }
  3324. }
  3325. this.store();
  3326. }
  3327. }, {
  3328. key: "addRow",
  3329. value: function addRow(values, rowNumber) {
  3330. // Add a row of data, either insert at rowNumber or append
  3331. this.cacheState();
  3332. if (rowNumber === undefined) {
  3333. this.table.rows.push(values);
  3334. } else {
  3335. this.table.rows.splice(rowNumber, 0, values);
  3336. }
  3337. }
  3338. }, {
  3339. key: "removeRows",
  3340. value: function removeRows(rowIndex) {
  3341. var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  3342. // Remove a rows of data
  3343. this.cacheState();
  3344. this.table.rows.splice(rowIndex, count);
  3345. }
  3346. }, {
  3347. key: "getColumn",
  3348. value: function getColumn(colIndex) {
  3349. var column = this.table.columns[colIndex];
  3350. return new Column(this, column, colIndex);
  3351. }
  3352. }, {
  3353. key: "addColumn",
  3354. value: function addColumn(column, values, colIndex) {
  3355. // Add a new column, including column defn and values
  3356. // Inserts at colNumber or adds to the right
  3357. this.cacheState();
  3358. if (colIndex === undefined) {
  3359. this.table.columns.push(column);
  3360. this.table.rows.forEach(function (row, i) {
  3361. row.push(values[i]);
  3362. });
  3363. } else {
  3364. this.table.columns.splice(colIndex, 0, column);
  3365. this.table.rows.forEach(function (row, i) {
  3366. row.splice(colIndex, 0, values[i]);
  3367. });
  3368. }
  3369. }
  3370. }, {
  3371. key: "removeColumns",
  3372. value: function removeColumns(colIndex) {
  3373. var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  3374. // Remove a column with data
  3375. this.cacheState();
  3376. this.table.columns.splice(colIndex, count);
  3377. this.table.rows.forEach(function (row) {
  3378. row.splice(colIndex, count);
  3379. });
  3380. }
  3381. }, {
  3382. key: "_assign",
  3383. value: function _assign(target, prop, value) {
  3384. this.cacheState();
  3385. target[prop] = value;
  3386. }
  3387. /* eslint-disable lines-between-class-members */
  3388. }, {
  3389. key: "width",
  3390. get: function get() {
  3391. // width of the table
  3392. return this.table.columns.length;
  3393. }
  3394. }, {
  3395. key: "height",
  3396. get: function get() {
  3397. // height of the table data
  3398. return this.table.rows.length;
  3399. }
  3400. }, {
  3401. key: "filterHeight",
  3402. get: function get() {
  3403. // height of the table data plus optional header row
  3404. return this.height + (this.table.headerRow ? 1 : 0);
  3405. }
  3406. }, {
  3407. key: "tableHeight",
  3408. get: function get() {
  3409. // full height of the table on the sheet
  3410. return this.filterHeight + (this.table.totalsRow ? 1 : 0);
  3411. }
  3412. }, {
  3413. key: "model",
  3414. get: function get() {
  3415. return this.table;
  3416. },
  3417. set: function set(value) {
  3418. this.table = value;
  3419. }
  3420. }, {
  3421. key: "ref",
  3422. get: function get() {
  3423. return this.table.ref;
  3424. },
  3425. set: function set(value) {
  3426. this._assign(this.table, 'ref', value);
  3427. }
  3428. }, {
  3429. key: "name",
  3430. get: function get() {
  3431. return this.table.name;
  3432. },
  3433. set: function set(value) {
  3434. this.table.name = value;
  3435. }
  3436. }, {
  3437. key: "displayName",
  3438. get: function get() {
  3439. return this.table.displyName || this.table.name;
  3440. }
  3441. }, {
  3442. key: "displayNamename",
  3443. set: function set(value) {
  3444. this.table.displayName = value;
  3445. }
  3446. }, {
  3447. key: "headerRow",
  3448. get: function get() {
  3449. return this.table.headerRow;
  3450. },
  3451. set: function set(value) {
  3452. this._assign(this.table, 'headerRow', value);
  3453. }
  3454. }, {
  3455. key: "totalsRow",
  3456. get: function get() {
  3457. return this.table.totalsRow;
  3458. },
  3459. set: function set(value) {
  3460. this._assign(this.table, 'totalsRow', value);
  3461. }
  3462. }, {
  3463. key: "theme",
  3464. get: function get() {
  3465. return this.table.style.name;
  3466. },
  3467. set: function set(value) {
  3468. this.table.style.name = value;
  3469. }
  3470. }, {
  3471. key: "showFirstColumn",
  3472. get: function get() {
  3473. return this.table.style.showFirstColumn;
  3474. },
  3475. set: function set(value) {
  3476. this.table.style.showFirstColumn = value;
  3477. }
  3478. }, {
  3479. key: "showLastColumn",
  3480. get: function get() {
  3481. return this.table.style.showLastColumn;
  3482. },
  3483. set: function set(value) {
  3484. this.table.style.showLastColumn = value;
  3485. }
  3486. }, {
  3487. key: "showRowStripes",
  3488. get: function get() {
  3489. return this.table.style.showRowStripes;
  3490. },
  3491. set: function set(value) {
  3492. this.table.style.showRowStripes = value;
  3493. }
  3494. }, {
  3495. key: "showColumnStripes",
  3496. get: function get() {
  3497. return this.table.style.showColumnStripes;
  3498. },
  3499. set: function set(value) {
  3500. this.table.style.showColumnStripes = value;
  3501. }
  3502. /* eslint-enable lines-between-class-members */
  3503. }]);
  3504. return Table;
  3505. }();
  3506. module.exports = Table;
  3507. },{"../utils/col-cache":19}],13:[function(require,module,exports){
  3508. 'use strict';
  3509. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3510. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  3511. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  3512. var Worksheet = require('./worksheet');
  3513. var DefinedNames = require('./defined-names');
  3514. var XLSX = require('../xlsx/xlsx');
  3515. var CSV = require('../csv/csv'); // Workbook requirements
  3516. // Load and Save from file and stream
  3517. // Access/Add/Delete individual worksheets
  3518. // Manage String table, Hyperlink table, etc.
  3519. // Manage scaffolding for contained objects to write to/read from
  3520. var Workbook = /*#__PURE__*/function () {
  3521. function Workbook() {
  3522. _classCallCheck(this, Workbook);
  3523. this.category = '';
  3524. this.company = '';
  3525. this.created = new Date();
  3526. this.description = '';
  3527. this.keywords = '';
  3528. this.manager = '';
  3529. this.modified = this.created;
  3530. this.properties = {};
  3531. this.calcProperties = {};
  3532. this._worksheets = [];
  3533. this.subject = '';
  3534. this.title = '';
  3535. this.views = [];
  3536. this.media = [];
  3537. this._definedNames = new DefinedNames();
  3538. }
  3539. _createClass(Workbook, [{
  3540. key: "addWorksheet",
  3541. value: function addWorksheet(name, options) {
  3542. var id = this.nextId;
  3543. if (name && name.length > 31) {
  3544. // eslint-disable-next-line no-console
  3545. console.warn("Worksheet name ".concat(name, " exceeds 31 chars. This will be truncated"));
  3546. } // Illegal character in worksheet name: asterisk (*), question mark (?),
  3547. // colon (:), forward slash (/ \), or bracket ([])
  3548. if (/[*?:/\\[\]]/.test(name)) {
  3549. throw new Error("Worksheet name ".concat(name, " cannot include any of the following characters: * ? : \\ / [ ]"));
  3550. }
  3551. if (/(^')|('$)/.test(name)) {
  3552. throw new Error("The first or last character of worksheet name cannot be a single quotation mark: ".concat(name));
  3553. }
  3554. name = (name || "sheet".concat(id)).substring(0, 31);
  3555. if (this._worksheets.find(function (ws) {
  3556. return ws && ws.name.toLowerCase() === name.toLowerCase();
  3557. })) {
  3558. throw new Error("Worksheet name already exists: ".concat(name));
  3559. } // if options is a color, call it tabColor (and signal deprecated message)
  3560. if (options) {
  3561. if (typeof options === 'string') {
  3562. // eslint-disable-next-line no-console
  3563. console.trace('tabColor argument is now deprecated. Please use workbook.addWorksheet(name, {properties: { tabColor: { argb: "rbg value" } }');
  3564. options = {
  3565. properties: {
  3566. tabColor: {
  3567. argb: options
  3568. }
  3569. }
  3570. };
  3571. } else if (options.argb || options.theme || options.indexed) {
  3572. // eslint-disable-next-line no-console
  3573. console.trace('tabColor argument is now deprecated. Please use workbook.addWorksheet(name, {properties: { tabColor: { ... } }');
  3574. options = {
  3575. properties: {
  3576. tabColor: options
  3577. }
  3578. };
  3579. }
  3580. }
  3581. var lastOrderNo = this._worksheets.reduce(function (acc, ws) {
  3582. return (ws && ws.orderNo) > acc ? ws.orderNo : acc;
  3583. }, 0);
  3584. var worksheetOptions = Object.assign({}, options, {
  3585. id: id,
  3586. name: name,
  3587. orderNo: lastOrderNo + 1,
  3588. workbook: this
  3589. });
  3590. var worksheet = new Worksheet(worksheetOptions);
  3591. this._worksheets[id] = worksheet;
  3592. return worksheet;
  3593. }
  3594. }, {
  3595. key: "removeWorksheetEx",
  3596. value: function removeWorksheetEx(worksheet) {
  3597. delete this._worksheets[worksheet.id];
  3598. }
  3599. }, {
  3600. key: "removeWorksheet",
  3601. value: function removeWorksheet(id) {
  3602. var worksheet = this.getWorksheet(id);
  3603. if (worksheet) {
  3604. worksheet.destroy();
  3605. }
  3606. }
  3607. }, {
  3608. key: "getWorksheet",
  3609. value: function getWorksheet(id) {
  3610. if (id === undefined) {
  3611. return this._worksheets.find(Boolean);
  3612. }
  3613. if (typeof id === 'number') {
  3614. return this._worksheets[id];
  3615. }
  3616. if (typeof id === 'string') {
  3617. return this._worksheets.find(function (worksheet) {
  3618. return worksheet && worksheet.name === id;
  3619. });
  3620. }
  3621. return undefined;
  3622. }
  3623. }, {
  3624. key: "eachSheet",
  3625. value: function eachSheet(iteratee) {
  3626. this.worksheets.forEach(function (sheet) {
  3627. iteratee(sheet, sheet.id);
  3628. });
  3629. }
  3630. }, {
  3631. key: "clearThemes",
  3632. value: function clearThemes() {
  3633. // Note: themes are not an exposed feature, meddle at your peril!
  3634. this._themes = undefined;
  3635. }
  3636. }, {
  3637. key: "addImage",
  3638. value: function addImage(image) {
  3639. // TODO: validation?
  3640. var id = this.media.length;
  3641. this.media.push(Object.assign({}, image, {
  3642. type: 'image'
  3643. }));
  3644. return id;
  3645. }
  3646. }, {
  3647. key: "getImage",
  3648. value: function getImage(id) {
  3649. return this.media[id];
  3650. }
  3651. }, {
  3652. key: "xlsx",
  3653. get: function get() {
  3654. if (!this._xlsx) this._xlsx = new XLSX(this);
  3655. return this._xlsx;
  3656. }
  3657. }, {
  3658. key: "csv",
  3659. get: function get() {
  3660. if (!this._csv) this._csv = new CSV(this);
  3661. return this._csv;
  3662. }
  3663. }, {
  3664. key: "nextId",
  3665. get: function get() {
  3666. // find the next unique spot to add worksheet
  3667. for (var i = 1; i < this._worksheets.length; i++) {
  3668. if (!this._worksheets[i]) {
  3669. return i;
  3670. }
  3671. }
  3672. return this._worksheets.length || 1;
  3673. }
  3674. }, {
  3675. key: "worksheets",
  3676. get: function get() {
  3677. // return a clone of _worksheets
  3678. return this._worksheets.slice(1).sort(function (a, b) {
  3679. return a.orderNo - b.orderNo;
  3680. }).filter(Boolean);
  3681. }
  3682. }, {
  3683. key: "definedNames",
  3684. get: function get() {
  3685. return this._definedNames;
  3686. }
  3687. }, {
  3688. key: "model",
  3689. get: function get() {
  3690. return {
  3691. creator: this.creator || 'Unknown',
  3692. lastModifiedBy: this.lastModifiedBy || 'Unknown',
  3693. lastPrinted: this.lastPrinted,
  3694. created: this.created,
  3695. modified: this.modified,
  3696. properties: this.properties,
  3697. worksheets: this.worksheets.map(function (worksheet) {
  3698. return worksheet.model;
  3699. }),
  3700. sheets: this.worksheets.map(function (ws) {
  3701. return ws.model;
  3702. }).filter(Boolean),
  3703. definedNames: this._definedNames.model,
  3704. views: this.views,
  3705. company: this.company,
  3706. manager: this.manager,
  3707. title: this.title,
  3708. subject: this.subject,
  3709. keywords: this.keywords,
  3710. category: this.category,
  3711. description: this.description,
  3712. language: this.language,
  3713. revision: this.revision,
  3714. contentStatus: this.contentStatus,
  3715. themes: this._themes,
  3716. media: this.media,
  3717. calcProperties: this.calcProperties
  3718. };
  3719. },
  3720. set: function set(value) {
  3721. var _this = this;
  3722. this.creator = value.creator;
  3723. this.lastModifiedBy = value.lastModifiedBy;
  3724. this.lastPrinted = value.lastPrinted;
  3725. this.created = value.created;
  3726. this.modified = value.modified;
  3727. this.company = value.company;
  3728. this.manager = value.manager;
  3729. this.title = value.title;
  3730. this.subject = value.subject;
  3731. this.keywords = value.keywords;
  3732. this.category = value.category;
  3733. this.description = value.description;
  3734. this.language = value.language;
  3735. this.revision = value.revision;
  3736. this.contentStatus = value.contentStatus;
  3737. this.properties = value.properties;
  3738. this.calcProperties = value.calcProperties;
  3739. this._worksheets = [];
  3740. value.worksheets.forEach(function (worksheetModel) {
  3741. var id = worksheetModel.id,
  3742. name = worksheetModel.name,
  3743. state = worksheetModel.state;
  3744. var orderNo = value.sheets && value.sheets.findIndex(function (ws) {
  3745. return ws.id === id;
  3746. });
  3747. var worksheet = _this._worksheets[id] = new Worksheet({
  3748. id: id,
  3749. name: name,
  3750. orderNo: orderNo,
  3751. state: state,
  3752. workbook: _this
  3753. });
  3754. worksheet.model = worksheetModel;
  3755. });
  3756. this._definedNames.model = value.definedNames;
  3757. this.views = value.views;
  3758. this._themes = value.themes;
  3759. this.media = value.media || [];
  3760. }
  3761. }]);
  3762. return Workbook;
  3763. }();
  3764. module.exports = Workbook;
  3765. },{"../csv/csv":1,"../xlsx/xlsx":141,"./defined-names":6,"./worksheet":14}],14:[function(require,module,exports){
  3766. "use strict";
  3767. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  3768. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  3769. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  3770. function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
  3771. function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  3772. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  3773. function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
  3774. function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
  3775. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  3776. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3777. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  3778. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  3779. var _ = require('../utils/under-dash');
  3780. var colCache = require('../utils/col-cache');
  3781. var Range = require('./range');
  3782. var Row = require('./row');
  3783. var Column = require('./column');
  3784. var Enums = require('./enums');
  3785. var Image = require('./image');
  3786. var Table = require('./table');
  3787. var DataValidations = require('./data-validations');
  3788. var Encryptor = require('../utils/encryptor'); // Worksheet requirements
  3789. // Operate as sheet inside workbook or standalone
  3790. // Load and Save from file and stream
  3791. // Access/Add/Delete individual cells
  3792. // Manage column widths and row heights
  3793. var Worksheet = /*#__PURE__*/function () {
  3794. function Worksheet(options) {
  3795. _classCallCheck(this, Worksheet);
  3796. options = options || {}; // in a workbook, each sheet will have a number
  3797. this.id = options.id;
  3798. this.orderNo = options.orderNo; // and a name
  3799. this.name = options.name || "Sheet".concat(this.id); // add a state
  3800. this.state = options.state || 'visible'; // rows allows access organised by row. Sparse array of arrays indexed by row-1, col
  3801. // Note: _rows is zero based. Must subtract 1 to go from cell.row to index
  3802. this._rows = []; // column definitions
  3803. this._columns = null; // column keys (addRow convenience): key ==> this._collumns index
  3804. this._keys = {}; // keep record of all merges
  3805. this._merges = {}; // record of all row and column pageBreaks
  3806. this.rowBreaks = [];
  3807. this._workbook = options.workbook; // for tabColor, default row height, outline levels, etc
  3808. this.properties = Object.assign({}, {
  3809. defaultRowHeight: 15,
  3810. dyDescent: 55,
  3811. outlineLevelCol: 0,
  3812. outlineLevelRow: 0
  3813. }, options.properties); // for all things printing
  3814. this.pageSetup = Object.assign({}, {
  3815. margins: {
  3816. left: 0.7,
  3817. right: 0.7,
  3818. top: 0.75,
  3819. bottom: 0.75,
  3820. header: 0.3,
  3821. footer: 0.3
  3822. },
  3823. orientation: 'portrait',
  3824. horizontalDpi: 4294967295,
  3825. verticalDpi: 4294967295,
  3826. fitToPage: !!(options.pageSetup && (options.pageSetup.fitToWidth || options.pageSetup.fitToHeight) && !options.pageSetup.scale),
  3827. pageOrder: 'downThenOver',
  3828. blackAndWhite: false,
  3829. draft: false,
  3830. cellComments: 'None',
  3831. errors: 'displayed',
  3832. scale: 100,
  3833. fitToWidth: 1,
  3834. fitToHeight: 1,
  3835. paperSize: undefined,
  3836. showRowColHeaders: false,
  3837. showGridLines: false,
  3838. firstPageNumber: undefined,
  3839. horizontalCentered: false,
  3840. verticalCentered: false,
  3841. rowBreaks: null,
  3842. colBreaks: null
  3843. }, options.pageSetup);
  3844. this.headerFooter = Object.assign({}, {
  3845. differentFirst: false,
  3846. differentOddEven: false,
  3847. oddHeader: null,
  3848. oddFooter: null,
  3849. evenHeader: null,
  3850. evenFooter: null,
  3851. firstHeader: null,
  3852. firstFooter: null
  3853. }, options.headerFooter);
  3854. this.dataValidations = new DataValidations(); // for freezepanes, split, zoom, gridlines, etc
  3855. this.views = options.views || [];
  3856. this.autoFilter = options.autoFilter || null; // for images, etc
  3857. this._media = []; // worksheet protection
  3858. this.sheetProtection = null; // for tables
  3859. this.tables = {};
  3860. this.conditionalFormattings = [];
  3861. }
  3862. _createClass(Worksheet, [{
  3863. key: "destroy",
  3864. // when you're done with this worksheet, call this to remove from workbook
  3865. value: function destroy() {
  3866. this._workbook.removeWorksheetEx(this);
  3867. } // Get the bounding range of the cells in this worksheet
  3868. }, {
  3869. key: "getColumnKey",
  3870. value: function getColumnKey(key) {
  3871. return this._keys[key];
  3872. }
  3873. }, {
  3874. key: "setColumnKey",
  3875. value: function setColumnKey(key, value) {
  3876. this._keys[key] = value;
  3877. }
  3878. }, {
  3879. key: "deleteColumnKey",
  3880. value: function deleteColumnKey(key) {
  3881. delete this._keys[key];
  3882. }
  3883. }, {
  3884. key: "eachColumnKey",
  3885. value: function eachColumnKey(f) {
  3886. _.each(this._keys, f);
  3887. } // get a single column by col number. If it doesn't exist, create it and any gaps before it
  3888. }, {
  3889. key: "getColumn",
  3890. value: function getColumn(c) {
  3891. if (typeof c === 'string') {
  3892. // if it matches a key'd column, return that
  3893. var col = this._keys[c];
  3894. if (col) return col; // otherwise, assume letter
  3895. c = colCache.l2n(c);
  3896. }
  3897. if (!this._columns) {
  3898. this._columns = [];
  3899. }
  3900. if (c > this._columns.length) {
  3901. var n = this._columns.length + 1;
  3902. while (n <= c) {
  3903. this._columns.push(new Column(this, n++));
  3904. }
  3905. }
  3906. return this._columns[c - 1];
  3907. }
  3908. }, {
  3909. key: "spliceColumns",
  3910. value: function spliceColumns(start, count) {
  3911. var _this = this;
  3912. var rows = this._rows;
  3913. var nRows = rows.length;
  3914. for (var _len = arguments.length, inserts = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
  3915. inserts[_key - 2] = arguments[_key];
  3916. }
  3917. if (inserts.length > 0) {
  3918. var _loop = function _loop(i) {
  3919. var rowArguments = [start, count]; // eslint-disable-next-line no-loop-func
  3920. inserts.forEach(function (insert) {
  3921. rowArguments.push(insert[i] || null);
  3922. });
  3923. var row = _this.getRow(i + 1); // eslint-disable-next-line prefer-spread
  3924. row.splice.apply(row, rowArguments);
  3925. };
  3926. // must iterate over all rows whether they exist yet or not
  3927. for (var i = 0; i < nRows; i++) {
  3928. _loop(i);
  3929. }
  3930. } else {
  3931. // nothing to insert, so just splice all rows
  3932. this._rows.forEach(function (r) {
  3933. if (r) {
  3934. r.splice(start, count);
  3935. }
  3936. });
  3937. } // splice column definitions
  3938. var nExpand = inserts.length - count;
  3939. var nKeep = start + count;
  3940. var nEnd = this._columns.length;
  3941. if (nExpand < 0) {
  3942. for (var _i = start + inserts.length; _i <= nEnd; _i++) {
  3943. this.getColumn(_i).defn = this.getColumn(_i - nExpand).defn;
  3944. }
  3945. } else if (nExpand > 0) {
  3946. for (var _i2 = nEnd; _i2 >= nKeep; _i2--) {
  3947. this.getColumn(_i2 + nExpand).defn = this.getColumn(_i2).defn;
  3948. }
  3949. }
  3950. for (var _i3 = start; _i3 < start + inserts.length; _i3++) {
  3951. this.getColumn(_i3).defn = null;
  3952. } // account for defined names
  3953. this.workbook.definedNames.spliceColumns(this.name, start, count, inserts.length);
  3954. }
  3955. }, {
  3956. key: "_commitRow",
  3957. // =========================================================================
  3958. // Rows
  3959. value: function _commitRow() {// nop - allows streaming reader to fill a document
  3960. }
  3961. }, {
  3962. key: "findRow",
  3963. // find a row (if exists) by row number
  3964. value: function findRow(r) {
  3965. return this._rows[r - 1];
  3966. } // find multiple rows (if exists) by row number
  3967. }, {
  3968. key: "findRows",
  3969. value: function findRows(start, length) {
  3970. return this._rows.slice(start - 1, start - 1 + length);
  3971. }
  3972. }, {
  3973. key: "getRow",
  3974. // get a row by row number.
  3975. value: function getRow(r) {
  3976. var row = this._rows[r - 1];
  3977. if (!row) {
  3978. row = this._rows[r - 1] = new Row(this, r);
  3979. }
  3980. return row;
  3981. } // get multiple rows by row number.
  3982. }, {
  3983. key: "getRows",
  3984. value: function getRows(start, length) {
  3985. if (length < 1) return undefined;
  3986. var rows = [];
  3987. for (var i = start; i < start + length; i++) {
  3988. rows.push(this.getRow(i));
  3989. }
  3990. return rows;
  3991. }
  3992. }, {
  3993. key: "addRow",
  3994. value: function addRow(value) {
  3995. var style = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'n';
  3996. var rowNo = this._nextRow;
  3997. var row = this.getRow(rowNo);
  3998. row.values = value;
  3999. this._setStyleOption(rowNo, style[0] === 'i' ? style : 'n');
  4000. return row;
  4001. }
  4002. }, {
  4003. key: "addRows",
  4004. value: function addRows(value) {
  4005. var _this2 = this;
  4006. var style = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'n';
  4007. var rows = [];
  4008. value.forEach(function (row) {
  4009. rows.push(_this2.addRow(row, style));
  4010. });
  4011. return rows;
  4012. }
  4013. }, {
  4014. key: "insertRow",
  4015. value: function insertRow(pos, value) {
  4016. var style = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'n';
  4017. this.spliceRows(pos, 0, value);
  4018. this._setStyleOption(pos, style);
  4019. return this.getRow(pos);
  4020. }
  4021. }, {
  4022. key: "insertRows",
  4023. value: function insertRows(pos, values) {
  4024. var style = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'n';
  4025. this.spliceRows.apply(this, [pos, 0].concat(_toConsumableArray(values)));
  4026. if (style !== 'n') {
  4027. // copy over the styles
  4028. for (var i = 0; i < values.length; i++) {
  4029. if (style[0] === 'o' && this.findRow(values.length + pos + i) !== undefined) {
  4030. this._copyStyle(values.length + pos + i, pos + i, style[1] === '+');
  4031. } else if (style[0] === 'i' && this.findRow(pos - 1) !== undefined) {
  4032. this._copyStyle(pos - 1, pos + i, style[1] === '+');
  4033. }
  4034. }
  4035. }
  4036. return this.getRows(pos, values.length);
  4037. } // set row at position to same style as of either pervious row (option 'i') or next row (option 'o')
  4038. }, {
  4039. key: "_setStyleOption",
  4040. value: function _setStyleOption(pos) {
  4041. var style = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'n';
  4042. if (style[0] === 'o' && this.findRow(pos + 1) !== undefined) {
  4043. this._copyStyle(pos + 1, pos, style[1] === '+');
  4044. } else if (style[0] === 'i' && this.findRow(pos - 1) !== undefined) {
  4045. this._copyStyle(pos - 1, pos, style[1] === '+');
  4046. }
  4047. }
  4048. }, {
  4049. key: "_copyStyle",
  4050. value: function _copyStyle(src, dest) {
  4051. var styleEmpty = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  4052. var rSrc = this.getRow(src);
  4053. var rDst = this.getRow(dest);
  4054. rDst.style = Object.freeze(_objectSpread({}, rSrc.style)); // eslint-disable-next-line no-loop-func
  4055. rSrc.eachCell({
  4056. includeEmpty: styleEmpty
  4057. }, function (cell, colNumber) {
  4058. rDst.getCell(colNumber).style = Object.freeze(_objectSpread({}, cell.style));
  4059. });
  4060. rDst.height = rSrc.height;
  4061. }
  4062. }, {
  4063. key: "duplicateRow",
  4064. value: function duplicateRow(rowNum, count) {
  4065. var _this3 = this;
  4066. var insert = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  4067. // create count duplicates of rowNum
  4068. // either inserting new or overwriting existing rows
  4069. var rSrc = this._rows[rowNum - 1];
  4070. var inserts = new Array(count).fill(rSrc.values);
  4071. this.spliceRows.apply(this, [rowNum + 1, insert ? 0 : count].concat(_toConsumableArray(inserts))); // now copy styles...
  4072. var _loop2 = function _loop2(i) {
  4073. var rDst = _this3._rows[rowNum + i];
  4074. rDst.style = rSrc.style;
  4075. rDst.height = rSrc.height; // eslint-disable-next-line no-loop-func
  4076. rSrc.eachCell({
  4077. includeEmpty: true
  4078. }, function (cell, colNumber) {
  4079. rDst.getCell(colNumber).style = cell.style;
  4080. });
  4081. };
  4082. for (var i = 0; i < count; i++) {
  4083. _loop2(i);
  4084. }
  4085. }
  4086. }, {
  4087. key: "spliceRows",
  4088. value: function spliceRows(start, count) {
  4089. var _this4 = this;
  4090. // same problem as row.splice, except worse.
  4091. var nKeep = start + count;
  4092. for (var _len2 = arguments.length, inserts = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
  4093. inserts[_key2 - 2] = arguments[_key2];
  4094. }
  4095. var nInserts = inserts.length;
  4096. var nExpand = nInserts - count;
  4097. var nEnd = this._rows.length;
  4098. var i;
  4099. var rSrc;
  4100. if (nExpand < 0) {
  4101. // remove rows
  4102. for (i = nKeep; i <= nEnd; i++) {
  4103. rSrc = this._rows[i - 1];
  4104. if (rSrc) {
  4105. (function () {
  4106. var rDst = _this4.getRow(i + nExpand);
  4107. rDst.values = rSrc.values;
  4108. rDst.style = rSrc.style;
  4109. rDst.height = rSrc.height; // eslint-disable-next-line no-loop-func
  4110. rSrc.eachCell({
  4111. includeEmpty: true
  4112. }, function (cell, colNumber) {
  4113. rDst.getCell(colNumber).style = cell.style;
  4114. });
  4115. _this4._rows[i - 1] = undefined;
  4116. })();
  4117. } else {
  4118. this._rows[i + nExpand - 1] = undefined;
  4119. }
  4120. }
  4121. } else if (nExpand > 0) {
  4122. // insert new cells
  4123. for (i = nEnd; i >= nKeep; i--) {
  4124. rSrc = this._rows[i - 1];
  4125. if (rSrc) {
  4126. (function () {
  4127. var rDst = _this4.getRow(i + nExpand);
  4128. rDst.values = rSrc.values;
  4129. rDst.style = rSrc.style;
  4130. rDst.height = rSrc.height; // eslint-disable-next-line no-loop-func
  4131. rSrc.eachCell({
  4132. includeEmpty: true
  4133. }, function (cell, colNumber) {
  4134. rDst.getCell(colNumber).style = cell.style; // remerge cells accounting for insert offset
  4135. if (cell._value.constructor.name === 'MergeValue') {
  4136. var cellToBeMerged = _this4.getRow(cell._row._number + nInserts).getCell(colNumber);
  4137. var prevMaster = cell._value._master;
  4138. var newMaster = _this4.getRow(prevMaster._row._number + nInserts).getCell(prevMaster._column._number);
  4139. cellToBeMerged.merge(newMaster);
  4140. }
  4141. });
  4142. })();
  4143. } else {
  4144. this._rows[i + nExpand - 1] = undefined;
  4145. }
  4146. }
  4147. } // now copy over the new values
  4148. for (i = 0; i < nInserts; i++) {
  4149. var rDst = this.getRow(start + i);
  4150. rDst.style = {};
  4151. rDst.values = inserts[i];
  4152. } // account for defined names
  4153. this.workbook.definedNames.spliceRows(this.name, start, count, nInserts);
  4154. } // iterate over every row in the worksheet, including maybe empty rows
  4155. }, {
  4156. key: "eachRow",
  4157. value: function eachRow(options, iteratee) {
  4158. if (!iteratee) {
  4159. iteratee = options;
  4160. options = undefined;
  4161. }
  4162. if (options && options.includeEmpty) {
  4163. var n = this._rows.length;
  4164. for (var i = 1; i <= n; i++) {
  4165. iteratee(this.getRow(i), i);
  4166. }
  4167. } else {
  4168. this._rows.forEach(function (row) {
  4169. if (row && row.hasValues) {
  4170. iteratee(row, row.number);
  4171. }
  4172. });
  4173. }
  4174. } // return all rows as sparse array
  4175. }, {
  4176. key: "getSheetValues",
  4177. value: function getSheetValues() {
  4178. var rows = [];
  4179. this._rows.forEach(function (row) {
  4180. if (row) {
  4181. rows[row.number] = row.values;
  4182. }
  4183. });
  4184. return rows;
  4185. } // =========================================================================
  4186. // Cells
  4187. // returns the cell at [r,c] or address given by r. If not found, return undefined
  4188. }, {
  4189. key: "findCell",
  4190. value: function findCell(r, c) {
  4191. var address = colCache.getAddress(r, c);
  4192. var row = this._rows[address.row - 1];
  4193. return row ? row.findCell(address.col) : undefined;
  4194. } // return the cell at [r,c] or address given by r. If not found, create a new one.
  4195. }, {
  4196. key: "getCell",
  4197. value: function getCell(r, c) {
  4198. var address = colCache.getAddress(r, c);
  4199. var row = this.getRow(address.row);
  4200. return row.getCellEx(address);
  4201. } // =========================================================================
  4202. // Merge
  4203. // convert the range defined by ['tl:br'], [tl,br] or [t,l,b,r] into a single 'merged' cell
  4204. }, {
  4205. key: "mergeCells",
  4206. value: function mergeCells() {
  4207. for (var _len3 = arguments.length, cells = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  4208. cells[_key3] = arguments[_key3];
  4209. }
  4210. var dimensions = new Range(cells);
  4211. this._mergeCellsInternal(dimensions);
  4212. }
  4213. }, {
  4214. key: "mergeCellsWithoutStyle",
  4215. value: function mergeCellsWithoutStyle() {
  4216. for (var _len4 = arguments.length, cells = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
  4217. cells[_key4] = arguments[_key4];
  4218. }
  4219. var dimensions = new Range(cells);
  4220. this._mergeCellsInternal(dimensions, true);
  4221. }
  4222. }, {
  4223. key: "_mergeCellsInternal",
  4224. value: function _mergeCellsInternal(dimensions, ignoreStyle) {
  4225. // check cells aren't already merged
  4226. _.each(this._merges, function (merge) {
  4227. if (merge.intersects(dimensions)) {
  4228. throw new Error('Cannot merge already merged cells');
  4229. }
  4230. }); // apply merge
  4231. var master = this.getCell(dimensions.top, dimensions.left);
  4232. for (var i = dimensions.top; i <= dimensions.bottom; i++) {
  4233. for (var j = dimensions.left; j <= dimensions.right; j++) {
  4234. // merge all but the master cell
  4235. if (i > dimensions.top || j > dimensions.left) {
  4236. this.getCell(i, j).merge(master, ignoreStyle);
  4237. }
  4238. }
  4239. } // index merge
  4240. this._merges[master.address] = dimensions;
  4241. }
  4242. }, {
  4243. key: "_unMergeMaster",
  4244. value: function _unMergeMaster(master) {
  4245. // master is always top left of a rectangle
  4246. var merge = this._merges[master.address];
  4247. if (merge) {
  4248. for (var i = merge.top; i <= merge.bottom; i++) {
  4249. for (var j = merge.left; j <= merge.right; j++) {
  4250. this.getCell(i, j).unmerge();
  4251. }
  4252. }
  4253. delete this._merges[master.address];
  4254. }
  4255. }
  4256. }, {
  4257. key: "unMergeCells",
  4258. // scan the range defined by ['tl:br'], [tl,br] or [t,l,b,r] and if any cell is part of a merge,
  4259. // un-merge the group. Note this function can affect multiple merges and merge-blocks are
  4260. // atomic - either they're all merged or all un-merged.
  4261. value: function unMergeCells() {
  4262. for (var _len5 = arguments.length, cells = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
  4263. cells[_key5] = arguments[_key5];
  4264. }
  4265. var dimensions = new Range(cells); // find any cells in that range and unmerge them
  4266. for (var i = dimensions.top; i <= dimensions.bottom; i++) {
  4267. for (var j = dimensions.left; j <= dimensions.right; j++) {
  4268. var cell = this.findCell(i, j);
  4269. if (cell) {
  4270. if (cell.type === Enums.ValueType.Merge) {
  4271. // this cell merges to another master
  4272. this._unMergeMaster(cell.master);
  4273. } else if (this._merges[cell.address]) {
  4274. // this cell is a master
  4275. this._unMergeMaster(cell);
  4276. }
  4277. }
  4278. }
  4279. }
  4280. } // ===========================================================================
  4281. // Shared/Array Formula
  4282. }, {
  4283. key: "fillFormula",
  4284. value: function fillFormula(range, formula, results) {
  4285. var shareType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'shared';
  4286. // Define formula for top-left cell and share to rest
  4287. var decoded = colCache.decode(range);
  4288. var top = decoded.top,
  4289. left = decoded.left,
  4290. bottom = decoded.bottom,
  4291. right = decoded.right;
  4292. var width = right - left + 1;
  4293. var masterAddress = colCache.encodeAddress(top, left);
  4294. var isShared = shareType === 'shared'; // work out result accessor
  4295. var getResult;
  4296. if (typeof results === 'function') {
  4297. getResult = results;
  4298. } else if (Array.isArray(results)) {
  4299. if (Array.isArray(results[0])) {
  4300. getResult = function getResult(row, col) {
  4301. return results[row - top][col - left];
  4302. };
  4303. } else {
  4304. // eslint-disable-next-line no-mixed-operators
  4305. getResult = function getResult(row, col) {
  4306. return results[(row - top) * width + (col - left)];
  4307. };
  4308. }
  4309. } else {
  4310. getResult = function getResult() {
  4311. return undefined;
  4312. };
  4313. }
  4314. var first = true;
  4315. for (var r = top; r <= bottom; r++) {
  4316. for (var c = left; c <= right; c++) {
  4317. if (first) {
  4318. this.getCell(r, c).value = {
  4319. shareType: shareType,
  4320. formula: formula,
  4321. ref: range,
  4322. result: getResult(r, c)
  4323. };
  4324. first = false;
  4325. } else {
  4326. this.getCell(r, c).value = isShared ? {
  4327. sharedFormula: masterAddress,
  4328. result: getResult(r, c)
  4329. } : getResult(r, c);
  4330. }
  4331. }
  4332. }
  4333. } // =========================================================================
  4334. // Images
  4335. }, {
  4336. key: "addImage",
  4337. value: function addImage(imageId, range) {
  4338. var model = {
  4339. type: 'image',
  4340. imageId: imageId,
  4341. range: range
  4342. };
  4343. this._media.push(new Image(this, model));
  4344. }
  4345. }, {
  4346. key: "getImages",
  4347. value: function getImages() {
  4348. return this._media.filter(function (m) {
  4349. return m.type === 'image';
  4350. });
  4351. }
  4352. }, {
  4353. key: "addBackgroundImage",
  4354. value: function addBackgroundImage(imageId) {
  4355. var model = {
  4356. type: 'background',
  4357. imageId: imageId
  4358. };
  4359. this._media.push(new Image(this, model));
  4360. }
  4361. }, {
  4362. key: "getBackgroundImageId",
  4363. value: function getBackgroundImageId() {
  4364. var image = this._media.find(function (m) {
  4365. return m.type === 'background';
  4366. });
  4367. return image && image.imageId;
  4368. } // =========================================================================
  4369. // Worksheet Protection
  4370. }, {
  4371. key: "protect",
  4372. value: function protect(password, options) {
  4373. var _this5 = this;
  4374. // TODO: make this function truly async
  4375. // perhaps marshal to worker thread or something
  4376. return new Promise(function (resolve) {
  4377. _this5.sheetProtection = {
  4378. sheet: true
  4379. };
  4380. if (options && 'spinCount' in options) {
  4381. // force spinCount to be integer >= 0
  4382. options.spinCount = Number.isFinite(options.spinCount) ? Math.round(Math.max(0, options.spinCount)) : 100000;
  4383. }
  4384. if (password) {
  4385. _this5.sheetProtection.algorithmName = 'SHA-512';
  4386. _this5.sheetProtection.saltValue = Encryptor.randomBytes(16).toString('base64');
  4387. _this5.sheetProtection.spinCount = options && 'spinCount' in options ? options.spinCount : 100000; // allow user specified spinCount
  4388. _this5.sheetProtection.hashValue = Encryptor.convertPasswordToHash(password, 'SHA512', _this5.sheetProtection.saltValue, _this5.sheetProtection.spinCount);
  4389. }
  4390. if (options) {
  4391. _this5.sheetProtection = Object.assign(_this5.sheetProtection, options);
  4392. if (!password && 'spinCount' in options) {
  4393. delete _this5.sheetProtection.spinCount;
  4394. }
  4395. }
  4396. resolve();
  4397. });
  4398. }
  4399. }, {
  4400. key: "unprotect",
  4401. value: function unprotect() {
  4402. this.sheetProtection = null;
  4403. } // =========================================================================
  4404. // Tables
  4405. }, {
  4406. key: "addTable",
  4407. value: function addTable(model) {
  4408. var table = new Table(this, model);
  4409. this.tables[model.name] = table;
  4410. return table;
  4411. }
  4412. }, {
  4413. key: "getTable",
  4414. value: function getTable(name) {
  4415. return this.tables[name];
  4416. }
  4417. }, {
  4418. key: "removeTable",
  4419. value: function removeTable(name) {
  4420. delete this.tables[name];
  4421. }
  4422. }, {
  4423. key: "getTables",
  4424. value: function getTables() {
  4425. return Object.values(this.tables);
  4426. } // ===========================================================================
  4427. // Conditional Formatting
  4428. }, {
  4429. key: "addConditionalFormatting",
  4430. value: function addConditionalFormatting(cf) {
  4431. this.conditionalFormattings.push(cf);
  4432. }
  4433. }, {
  4434. key: "removeConditionalFormatting",
  4435. value: function removeConditionalFormatting(filter) {
  4436. if (typeof filter === 'number') {
  4437. this.conditionalFormattings.splice(filter, 1);
  4438. } else if (filter instanceof Function) {
  4439. this.conditionalFormattings = this.conditionalFormattings.filter(filter);
  4440. } else {
  4441. this.conditionalFormattings = [];
  4442. }
  4443. } // ===========================================================================
  4444. // Deprecated
  4445. }, {
  4446. key: "_parseRows",
  4447. value: function _parseRows(model) {
  4448. var _this6 = this;
  4449. this._rows = [];
  4450. model.rows.forEach(function (rowModel) {
  4451. var row = new Row(_this6, rowModel.number);
  4452. _this6._rows[row.number - 1] = row;
  4453. row.model = rowModel;
  4454. });
  4455. }
  4456. }, {
  4457. key: "_parseMergeCells",
  4458. value: function _parseMergeCells(model) {
  4459. var _this7 = this;
  4460. _.each(model.mergeCells, function (merge) {
  4461. // Do not merge styles when importing an Excel file
  4462. // since each cell may have different styles intentionally.
  4463. _this7.mergeCellsWithoutStyle(merge);
  4464. });
  4465. }
  4466. }, {
  4467. key: "workbook",
  4468. get: function get() {
  4469. return this._workbook;
  4470. }
  4471. }, {
  4472. key: "dimensions",
  4473. get: function get() {
  4474. var dimensions = new Range();
  4475. this._rows.forEach(function (row) {
  4476. if (row) {
  4477. var rowDims = row.dimensions;
  4478. if (rowDims) {
  4479. dimensions.expand(row.number, rowDims.min, row.number, rowDims.max);
  4480. }
  4481. }
  4482. });
  4483. return dimensions;
  4484. } // =========================================================================
  4485. // Columns
  4486. // get the current columns array.
  4487. }, {
  4488. key: "columns",
  4489. get: function get() {
  4490. return this._columns;
  4491. } // set the columns from an array of column definitions.
  4492. // Note: any headers defined will overwrite existing values.
  4493. ,
  4494. set: function set(value) {
  4495. var _this8 = this;
  4496. // calculate max header row count
  4497. this._headerRowCount = value.reduce(function (pv, cv) {
  4498. var headerCount = cv.header && 1 || cv.headers && cv.headers.length || 0;
  4499. return Math.max(pv, headerCount);
  4500. }, 0); // construct Column objects
  4501. var count = 1;
  4502. var columns = this._columns = [];
  4503. value.forEach(function (defn) {
  4504. var column = new Column(_this8, count++, false);
  4505. columns.push(column);
  4506. column.defn = defn;
  4507. });
  4508. }
  4509. }, {
  4510. key: "lastColumn",
  4511. get: function get() {
  4512. return this.getColumn(this.columnCount);
  4513. }
  4514. }, {
  4515. key: "columnCount",
  4516. get: function get() {
  4517. var maxCount = 0;
  4518. this.eachRow(function (row) {
  4519. maxCount = Math.max(maxCount, row.cellCount);
  4520. });
  4521. return maxCount;
  4522. }
  4523. }, {
  4524. key: "actualColumnCount",
  4525. get: function get() {
  4526. // performance nightmare - for each row, counts all the columns used
  4527. var counts = [];
  4528. var count = 0;
  4529. this.eachRow(function (row) {
  4530. row.eachCell(function (_ref) {
  4531. var col = _ref.col;
  4532. if (!counts[col]) {
  4533. counts[col] = true;
  4534. count++;
  4535. }
  4536. });
  4537. });
  4538. return count;
  4539. }
  4540. }, {
  4541. key: "_lastRowNumber",
  4542. get: function get() {
  4543. // need to cope with results of splice
  4544. var rows = this._rows;
  4545. var n = rows.length;
  4546. while (n > 0 && rows[n - 1] === undefined) {
  4547. n--;
  4548. }
  4549. return n;
  4550. }
  4551. }, {
  4552. key: "_nextRow",
  4553. get: function get() {
  4554. return this._lastRowNumber + 1;
  4555. }
  4556. }, {
  4557. key: "lastRow",
  4558. get: function get() {
  4559. if (this._rows.length) {
  4560. return this._rows[this._rows.length - 1];
  4561. }
  4562. return undefined;
  4563. }
  4564. }, {
  4565. key: "rowCount",
  4566. get: function get() {
  4567. return this._lastRowNumber;
  4568. }
  4569. }, {
  4570. key: "actualRowCount",
  4571. get: function get() {
  4572. // counts actual rows that have actual data
  4573. var count = 0;
  4574. this.eachRow(function () {
  4575. count++;
  4576. });
  4577. return count;
  4578. }
  4579. }, {
  4580. key: "hasMerges",
  4581. get: function get() {
  4582. // return true if this._merges has a merge object
  4583. return _.some(this._merges, Boolean);
  4584. }
  4585. }, {
  4586. key: "tabColor",
  4587. get: function get() {
  4588. // eslint-disable-next-line no-console
  4589. console.trace('worksheet.tabColor property is now deprecated. Please use worksheet.properties.tabColor');
  4590. return this.properties.tabColor;
  4591. },
  4592. set: function set(value) {
  4593. // eslint-disable-next-line no-console
  4594. console.trace('worksheet.tabColor property is now deprecated. Please use worksheet.properties.tabColor');
  4595. this.properties.tabColor = value;
  4596. } // ===========================================================================
  4597. // Model
  4598. }, {
  4599. key: "model",
  4600. get: function get() {
  4601. var model = {
  4602. id: this.id,
  4603. name: this.name,
  4604. dataValidations: this.dataValidations.model,
  4605. properties: this.properties,
  4606. state: this.state,
  4607. pageSetup: this.pageSetup,
  4608. headerFooter: this.headerFooter,
  4609. rowBreaks: this.rowBreaks,
  4610. views: this.views,
  4611. autoFilter: this.autoFilter,
  4612. media: this._media.map(function (medium) {
  4613. return medium.model;
  4614. }),
  4615. sheetProtection: this.sheetProtection,
  4616. tables: Object.values(this.tables).map(function (table) {
  4617. return table.model;
  4618. }),
  4619. conditionalFormattings: this.conditionalFormattings
  4620. }; // =================================================
  4621. // columns
  4622. model.cols = Column.toModel(this.columns); // ==========================================================
  4623. // Rows
  4624. var rows = model.rows = [];
  4625. var dimensions = model.dimensions = new Range();
  4626. this._rows.forEach(function (row) {
  4627. var rowModel = row && row.model;
  4628. if (rowModel) {
  4629. dimensions.expand(rowModel.number, rowModel.min, rowModel.number, rowModel.max);
  4630. rows.push(rowModel);
  4631. }
  4632. }); // ==========================================================
  4633. // Merges
  4634. model.merges = [];
  4635. _.each(this._merges, function (merge) {
  4636. model.merges.push(merge.range);
  4637. });
  4638. return model;
  4639. },
  4640. set: function set(value) {
  4641. var _this9 = this;
  4642. this.name = value.name;
  4643. this._columns = Column.fromModel(this, value.cols);
  4644. this._parseRows(value);
  4645. this._parseMergeCells(value);
  4646. this.dataValidations = new DataValidations(value.dataValidations);
  4647. this.properties = value.properties;
  4648. this.pageSetup = value.pageSetup;
  4649. this.headerFooter = value.headerFooter;
  4650. this.views = value.views;
  4651. this.autoFilter = value.autoFilter;
  4652. this._media = value.media.map(function (medium) {
  4653. return new Image(_this9, medium);
  4654. });
  4655. this.sheetProtection = value.sheetProtection;
  4656. this.tables = value.tables.reduce(function (tables, table) {
  4657. var t = new Table();
  4658. t.model = table;
  4659. tables[table.name] = t;
  4660. return tables;
  4661. }, {});
  4662. this.conditionalFormattings = value.conditionalFormattings;
  4663. }
  4664. }]);
  4665. return Worksheet;
  4666. }();
  4667. module.exports = Worksheet;
  4668. },{"../utils/col-cache":19,"../utils/encryptor":20,"../utils/under-dash":25,"./column":4,"./data-validations":5,"./enums":7,"./image":8,"./range":10,"./row":11,"./table":12}],15:[function(require,module,exports){
  4669. "use strict";
  4670. /* eslint-disable import/no-extraneous-dependencies,node/no-unpublished-require */
  4671. require('core-js/modules/es.promise');
  4672. require('core-js/modules/es.object.assign');
  4673. require('core-js/modules/es.object.keys');
  4674. require('core-js/modules/es.object.values');
  4675. require('core-js/modules/es.symbol');
  4676. require('core-js/modules/es.symbol.async-iterator'); // required by core-js/modules/es.promise Promise.all
  4677. require('core-js/modules/es.array.iterator'); // required by node_modules/saxes/saxes.js SaxesParser.captureTo
  4678. require('core-js/modules/es.array.includes'); // required by lib/doc/workbook.js Workbook.model
  4679. require('core-js/modules/es.array.find-index'); // required by lib/doc/workbook.js Workbook.addWorksheet and Workbook.getWorksheet
  4680. require('core-js/modules/es.array.find'); // required by node_modules/saxes/saxes.js SaxesParser.getCode10
  4681. require('core-js/modules/es.string.from-code-point'); // required by lib/xlsx/xform/sheet/data-validations-xform.js DataValidationsXform.parseClose
  4682. require('core-js/modules/es.string.includes'); // required by lib/utils/utils.js utils.validInt and lib/csv/csv.js CSV.read
  4683. require('core-js/modules/es.number.is-nan');
  4684. require('regenerator-runtime/runtime');
  4685. var ExcelJS = {
  4686. Workbook: require('./doc/workbook')
  4687. }; // Object.assign mono-fill
  4688. var Enums = require('./doc/enums');
  4689. Object.keys(Enums).forEach(function (key) {
  4690. ExcelJS[key] = Enums[key];
  4691. });
  4692. module.exports = ExcelJS;
  4693. },{"./doc/enums":7,"./doc/workbook":13,"core-js/modules/es.array.find":316,"core-js/modules/es.array.find-index":315,"core-js/modules/es.array.includes":317,"core-js/modules/es.array.iterator":318,"core-js/modules/es.number.is-nan":319,"core-js/modules/es.object.assign":320,"core-js/modules/es.object.keys":321,"core-js/modules/es.object.values":322,"core-js/modules/es.promise":323,"core-js/modules/es.string.from-code-point":324,"core-js/modules/es.string.includes":325,"core-js/modules/es.symbol":327,"core-js/modules/es.symbol.async-iterator":326,"regenerator-runtime/runtime":492}],16:[function(require,module,exports){
  4694. "use strict";
  4695. // eslint-disable-next-line node/no-unsupported-features/node-builtins
  4696. var textDecoder = typeof TextDecoder === 'undefined' ? null : new TextDecoder('utf-8');
  4697. function bufferToString(chunk) {
  4698. if (typeof chunk === 'string') {
  4699. return chunk;
  4700. }
  4701. if (textDecoder) {
  4702. return textDecoder.decode(chunk);
  4703. }
  4704. return chunk.toString();
  4705. }
  4706. exports.bufferToString = bufferToString;
  4707. },{}],17:[function(require,module,exports){
  4708. "use strict";
  4709. // eslint-disable-next-line node/no-unsupported-features/node-builtins
  4710. var textEncoder = typeof TextEncoder === 'undefined' ? null : new TextEncoder('utf-8');
  4711. var _require = require('buffer'),
  4712. Buffer = _require.Buffer;
  4713. function stringToBuffer(str) {
  4714. if (typeof str !== 'string') {
  4715. return str;
  4716. }
  4717. if (textEncoder) {
  4718. return Buffer.from(textEncoder.encode(str).buffer);
  4719. }
  4720. return Buffer.from(str);
  4721. }
  4722. exports.stringToBuffer = stringToBuffer;
  4723. },{"buffer":216}],18:[function(require,module,exports){
  4724. "use strict";
  4725. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4726. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  4727. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  4728. var _ = require('./under-dash');
  4729. var colCache = require('./col-cache');
  4730. var CellMatrix = /*#__PURE__*/function () {
  4731. function CellMatrix(template) {
  4732. _classCallCheck(this, CellMatrix);
  4733. this.template = template;
  4734. this.sheets = {};
  4735. }
  4736. _createClass(CellMatrix, [{
  4737. key: "addCell",
  4738. value: function addCell(addressStr) {
  4739. this.addCellEx(colCache.decodeEx(addressStr));
  4740. }
  4741. }, {
  4742. key: "getCell",
  4743. value: function getCell(addressStr) {
  4744. return this.findCellEx(colCache.decodeEx(addressStr), true);
  4745. }
  4746. }, {
  4747. key: "findCell",
  4748. value: function findCell(addressStr) {
  4749. return this.findCellEx(colCache.decodeEx(addressStr), false);
  4750. }
  4751. }, {
  4752. key: "findCellAt",
  4753. value: function findCellAt(sheetName, rowNumber, colNumber) {
  4754. var sheet = this.sheets[sheetName];
  4755. var row = sheet && sheet[rowNumber];
  4756. return row && row[colNumber];
  4757. }
  4758. }, {
  4759. key: "addCellEx",
  4760. value: function addCellEx(address) {
  4761. if (address.top) {
  4762. for (var row = address.top; row <= address.bottom; row++) {
  4763. for (var col = address.left; col <= address.right; col++) {
  4764. this.getCellAt(address.sheetName, row, col);
  4765. }
  4766. }
  4767. } else {
  4768. this.findCellEx(address, true);
  4769. }
  4770. }
  4771. }, {
  4772. key: "getCellEx",
  4773. value: function getCellEx(address) {
  4774. return this.findCellEx(address, true);
  4775. }
  4776. }, {
  4777. key: "findCellEx",
  4778. value: function findCellEx(address, create) {
  4779. var sheet = this.findSheet(address, create);
  4780. var row = this.findSheetRow(sheet, address, create);
  4781. return this.findRowCell(row, address, create);
  4782. }
  4783. }, {
  4784. key: "getCellAt",
  4785. value: function getCellAt(sheetName, rowNumber, colNumber) {
  4786. var sheet = this.sheets[sheetName] || (this.sheets[sheetName] = []);
  4787. var row = sheet[rowNumber] || (sheet[rowNumber] = []);
  4788. var cell = row[colNumber] || (row[colNumber] = {
  4789. sheetName: sheetName,
  4790. address: colCache.n2l(colNumber) + rowNumber,
  4791. row: rowNumber,
  4792. col: colNumber
  4793. });
  4794. return cell;
  4795. }
  4796. }, {
  4797. key: "removeCellEx",
  4798. value: function removeCellEx(address) {
  4799. var sheet = this.findSheet(address);
  4800. if (!sheet) {
  4801. return;
  4802. }
  4803. var row = this.findSheetRow(sheet, address);
  4804. if (!row) {
  4805. return;
  4806. }
  4807. delete row[address.col];
  4808. }
  4809. }, {
  4810. key: "forEachInSheet",
  4811. value: function forEachInSheet(sheetName, callback) {
  4812. var sheet = this.sheets[sheetName];
  4813. if (sheet) {
  4814. sheet.forEach(function (row, rowNumber) {
  4815. if (row) {
  4816. row.forEach(function (cell, colNumber) {
  4817. if (cell) {
  4818. callback(cell, rowNumber, colNumber);
  4819. }
  4820. });
  4821. }
  4822. });
  4823. }
  4824. }
  4825. }, {
  4826. key: "forEach",
  4827. value: function forEach(callback) {
  4828. var _this = this;
  4829. _.each(this.sheets, function (sheet, sheetName) {
  4830. _this.forEachInSheet(sheetName, callback);
  4831. });
  4832. }
  4833. }, {
  4834. key: "map",
  4835. value: function map(callback) {
  4836. var results = [];
  4837. this.forEach(function (cell) {
  4838. results.push(callback(cell));
  4839. });
  4840. return results;
  4841. }
  4842. }, {
  4843. key: "findSheet",
  4844. value: function findSheet(address, create) {
  4845. var name = address.sheetName;
  4846. if (this.sheets[name]) {
  4847. return this.sheets[name];
  4848. }
  4849. if (create) {
  4850. return this.sheets[name] = [];
  4851. }
  4852. return undefined;
  4853. }
  4854. }, {
  4855. key: "findSheetRow",
  4856. value: function findSheetRow(sheet, address, create) {
  4857. var row = address.row;
  4858. if (sheet && sheet[row]) {
  4859. return sheet[row];
  4860. }
  4861. if (create) {
  4862. return sheet[row] = [];
  4863. }
  4864. return undefined;
  4865. }
  4866. }, {
  4867. key: "findRowCell",
  4868. value: function findRowCell(row, address, create) {
  4869. var col = address.col;
  4870. if (row && row[col]) {
  4871. return row[col];
  4872. }
  4873. if (create) {
  4874. return row[col] = this.template ? Object.assign(address, JSON.parse(JSON.stringify(this.template))) : address;
  4875. }
  4876. return undefined;
  4877. }
  4878. }, {
  4879. key: "spliceRows",
  4880. value: function spliceRows(sheetName, start, numDelete, numInsert) {
  4881. var sheet = this.sheets[sheetName];
  4882. if (sheet) {
  4883. var inserts = [];
  4884. for (var i = 0; i < numInsert; i++) {
  4885. inserts.push([]);
  4886. }
  4887. sheet.splice.apply(sheet, [start, numDelete].concat(inserts));
  4888. }
  4889. }
  4890. }, {
  4891. key: "spliceColumns",
  4892. value: function spliceColumns(sheetName, start, numDelete, numInsert) {
  4893. var sheet = this.sheets[sheetName];
  4894. if (sheet) {
  4895. var inserts = [];
  4896. for (var i = 0; i < numInsert; i++) {
  4897. inserts.push(null);
  4898. }
  4899. _.each(sheet, function (row) {
  4900. row.splice.apply(row, [start, numDelete].concat(inserts));
  4901. });
  4902. }
  4903. }
  4904. }]);
  4905. return CellMatrix;
  4906. }();
  4907. module.exports = CellMatrix;
  4908. },{"./col-cache":19,"./under-dash":25}],19:[function(require,module,exports){
  4909. "use strict";
  4910. function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
  4911. function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  4912. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  4913. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  4914. function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
  4915. function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  4916. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  4917. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  4918. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  4919. var addressRegex = /^[A-Z]+\d+$/; // =========================================================================
  4920. // Column Letter to Number conversion
  4921. var colCache = {
  4922. _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'],
  4923. _l2nFill: 0,
  4924. _l2n: {},
  4925. _n2l: [],
  4926. _level: function _level(n) {
  4927. if (n <= 26) {
  4928. return 1;
  4929. }
  4930. if (n <= 26 * 26) {
  4931. return 2;
  4932. }
  4933. return 3;
  4934. },
  4935. _fill: function _fill(level) {
  4936. var c;
  4937. var v;
  4938. var l1;
  4939. var l2;
  4940. var l3;
  4941. var n = 1;
  4942. if (level >= 4) {
  4943. throw new Error('Out of bounds. Excel supports columns from 1 to 16384');
  4944. }
  4945. if (this._l2nFill < 1 && level >= 1) {
  4946. while (n <= 26) {
  4947. c = this._dictionary[n - 1];
  4948. this._n2l[n] = c;
  4949. this._l2n[c] = n;
  4950. n++;
  4951. }
  4952. this._l2nFill = 1;
  4953. }
  4954. if (this._l2nFill < 2 && level >= 2) {
  4955. n = 27;
  4956. while (n <= 26 + 26 * 26) {
  4957. v = n - (26 + 1);
  4958. l1 = v % 26;
  4959. l2 = Math.floor(v / 26);
  4960. c = this._dictionary[l2] + this._dictionary[l1];
  4961. this._n2l[n] = c;
  4962. this._l2n[c] = n;
  4963. n++;
  4964. }
  4965. this._l2nFill = 2;
  4966. }
  4967. if (this._l2nFill < 3 && level >= 3) {
  4968. n = 26 + 26 * 26 + 1;
  4969. while (n <= 16384) {
  4970. v = n - (26 * 26 + 26 + 1);
  4971. l1 = v % 26;
  4972. l2 = Math.floor(v / 26) % 26;
  4973. l3 = Math.floor(v / (26 * 26));
  4974. c = this._dictionary[l3] + this._dictionary[l2] + this._dictionary[l1];
  4975. this._n2l[n] = c;
  4976. this._l2n[c] = n;
  4977. n++;
  4978. }
  4979. this._l2nFill = 3;
  4980. }
  4981. },
  4982. l2n: function l2n(l) {
  4983. if (!this._l2n[l]) {
  4984. this._fill(l.length);
  4985. }
  4986. if (!this._l2n[l]) {
  4987. throw new Error("Out of bounds. Invalid column letter: ".concat(l));
  4988. }
  4989. return this._l2n[l];
  4990. },
  4991. n2l: function n2l(n) {
  4992. if (n < 1 || n > 16384) {
  4993. throw new Error("".concat(n, " is out of bounds. Excel supports columns from 1 to 16384"));
  4994. }
  4995. if (!this._n2l[n]) {
  4996. this._fill(this._level(n));
  4997. }
  4998. return this._n2l[n];
  4999. },
  5000. // =========================================================================
  5001. // Address processing
  5002. _hash: {},
  5003. // check if value looks like an address
  5004. validateAddress: function validateAddress(value) {
  5005. if (!addressRegex.test(value)) {
  5006. throw new Error("Invalid Address: ".concat(value));
  5007. }
  5008. return true;
  5009. },
  5010. // convert address string into structure
  5011. decodeAddress: function decodeAddress(value) {
  5012. var addr = value.length < 5 && this._hash[value];
  5013. if (addr) {
  5014. return addr;
  5015. }
  5016. var hasCol = false;
  5017. var col = '';
  5018. var colNumber = 0;
  5019. var hasRow = false;
  5020. var row = '';
  5021. var rowNumber = 0;
  5022. for (var i = 0, char; i < value.length; i++) {
  5023. char = value.charCodeAt(i); // col should before row
  5024. if (!hasRow && char >= 65 && char <= 90) {
  5025. // 65 = 'A'.charCodeAt(0)
  5026. // 90 = 'Z'.charCodeAt(0)
  5027. hasCol = true;
  5028. col += value[i]; // colNumber starts from 1
  5029. colNumber = colNumber * 26 + char - 64;
  5030. } else if (char >= 48 && char <= 57) {
  5031. // 48 = '0'.charCodeAt(0)
  5032. // 57 = '9'.charCodeAt(0)
  5033. hasRow = true;
  5034. row += value[i]; // rowNumber starts from 0
  5035. rowNumber = rowNumber * 10 + char - 48;
  5036. } else if (hasRow && hasCol && char !== 36) {
  5037. // 36 = '$'.charCodeAt(0)
  5038. break;
  5039. }
  5040. }
  5041. if (!hasCol) {
  5042. colNumber = undefined;
  5043. } else if (colNumber > 16384) {
  5044. throw new Error("Out of bounds. Invalid column letter: ".concat(col));
  5045. }
  5046. if (!hasRow) {
  5047. rowNumber = undefined;
  5048. } // in case $row$col
  5049. value = col + row;
  5050. var address = {
  5051. address: value,
  5052. col: colNumber,
  5053. row: rowNumber,
  5054. $col$row: "$".concat(col, "$").concat(row)
  5055. }; // mem fix - cache only the tl 100x100 square
  5056. if (colNumber <= 100 && rowNumber <= 100) {
  5057. this._hash[value] = address;
  5058. this._hash[address.$col$row] = address;
  5059. }
  5060. return address;
  5061. },
  5062. // convert r,c into structure (if only 1 arg, assume r is address string)
  5063. getAddress: function getAddress(r, c) {
  5064. if (c) {
  5065. var address = this.n2l(c) + r;
  5066. return this.decodeAddress(address);
  5067. }
  5068. return this.decodeAddress(r);
  5069. },
  5070. // convert [address], [tl:br] into address structures
  5071. decode: function decode(value) {
  5072. var parts = value.split(':');
  5073. if (parts.length === 2) {
  5074. var tl = this.decodeAddress(parts[0]);
  5075. var br = this.decodeAddress(parts[1]);
  5076. var result = {
  5077. top: Math.min(tl.row, br.row),
  5078. left: Math.min(tl.col, br.col),
  5079. bottom: Math.max(tl.row, br.row),
  5080. right: Math.max(tl.col, br.col)
  5081. }; // reconstruct tl, br and dimensions
  5082. result.tl = this.n2l(result.left) + result.top;
  5083. result.br = this.n2l(result.right) + result.bottom;
  5084. result.dimensions = "".concat(result.tl, ":").concat(result.br);
  5085. return result;
  5086. }
  5087. return this.decodeAddress(value);
  5088. },
  5089. // convert [sheetName!][$]col[$]row[[$]col[$]row] into address or range structures
  5090. decodeEx: function decodeEx(value) {
  5091. var groups = value.match(/(?:(?:(?:'((?:[^']|'')*)')|([^'^ !]*))!)?(.*)/);
  5092. var sheetName = groups[1] || groups[2]; // Qouted and unqouted groups
  5093. var reference = groups[3]; // Remaining address
  5094. var parts = reference.split(':');
  5095. if (parts.length > 1) {
  5096. var tl = this.decodeAddress(parts[0]);
  5097. var br = this.decodeAddress(parts[1]);
  5098. var top = Math.min(tl.row, br.row);
  5099. var left = Math.min(tl.col, br.col);
  5100. var bottom = Math.max(tl.row, br.row);
  5101. var right = Math.max(tl.col, br.col);
  5102. tl = this.n2l(left) + top;
  5103. br = this.n2l(right) + bottom;
  5104. return {
  5105. top: top,
  5106. left: left,
  5107. bottom: bottom,
  5108. right: right,
  5109. sheetName: sheetName,
  5110. tl: {
  5111. address: tl,
  5112. col: left,
  5113. row: top,
  5114. $col$row: "$".concat(this.n2l(left), "$").concat(top),
  5115. sheetName: sheetName
  5116. },
  5117. br: {
  5118. address: br,
  5119. col: right,
  5120. row: bottom,
  5121. $col$row: "$".concat(this.n2l(right), "$").concat(bottom),
  5122. sheetName: sheetName
  5123. },
  5124. dimensions: "".concat(tl, ":").concat(br)
  5125. };
  5126. }
  5127. if (reference.startsWith('#')) {
  5128. return sheetName ? {
  5129. sheetName: sheetName,
  5130. error: reference
  5131. } : {
  5132. error: reference
  5133. };
  5134. }
  5135. var address = this.decodeAddress(reference);
  5136. return sheetName ? _objectSpread({
  5137. sheetName: sheetName
  5138. }, address) : address;
  5139. },
  5140. // convert row,col into address string
  5141. encodeAddress: function encodeAddress(row, col) {
  5142. return colCache.n2l(col) + row;
  5143. },
  5144. // convert row,col into string address or t,l,b,r into range
  5145. encode: function encode() {
  5146. switch (arguments.length) {
  5147. case 2:
  5148. return colCache.encodeAddress(arguments[0], arguments[1]);
  5149. case 4:
  5150. return "".concat(colCache.encodeAddress(arguments[0], arguments[1]), ":").concat(colCache.encodeAddress(arguments[2], arguments[3]));
  5151. default:
  5152. throw new Error('Can only encode with 2 or 4 arguments');
  5153. }
  5154. },
  5155. // return true if address is contained within range
  5156. inRange: function inRange(range, address) {
  5157. var _range = _slicedToArray(range, 5),
  5158. left = _range[0],
  5159. top = _range[1],
  5160. right = _range[3],
  5161. bottom = _range[4];
  5162. var _address = _slicedToArray(address, 2),
  5163. col = _address[0],
  5164. row = _address[1];
  5165. return col >= left && col <= right && row >= top && row <= bottom;
  5166. }
  5167. };
  5168. module.exports = colCache;
  5169. },{}],20:[function(require,module,exports){
  5170. (function (Buffer){
  5171. 'use strict';
  5172. var crypto = require('crypto');
  5173. var Encryptor = {
  5174. /**
  5175. * Calculate a hash of the concatenated buffers with the given algorithm.
  5176. * @param {string} algorithm - The hash algorithm.
  5177. * @returns {Buffer} The hash
  5178. */
  5179. hash: function hash(algorithm) {
  5180. var hash = crypto.createHash(algorithm);
  5181. for (var _len = arguments.length, buffers = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  5182. buffers[_key - 1] = arguments[_key];
  5183. }
  5184. hash.update(Buffer.concat(buffers));
  5185. return hash.digest();
  5186. },
  5187. /**
  5188. * Convert a password into an encryption key
  5189. * @param {string} password - The password
  5190. * @param {string} hashAlgorithm - The hash algoritm
  5191. * @param {string} saltValue - The salt value
  5192. * @param {number} spinCount - The spin count
  5193. * @param {number} keyBits - The length of the key in bits
  5194. * @param {Buffer} blockKey - The block key
  5195. * @returns {Buffer} The encryption key
  5196. */
  5197. convertPasswordToHash: function convertPasswordToHash(password, hashAlgorithm, saltValue, spinCount) {
  5198. hashAlgorithm = hashAlgorithm.toLowerCase();
  5199. var hashes = crypto.getHashes();
  5200. if (hashes.indexOf(hashAlgorithm) < 0) {
  5201. throw new Error("Hash algorithm '".concat(hashAlgorithm, "' not supported!"));
  5202. } // Password must be in unicode buffer
  5203. var passwordBuffer = Buffer.from(password, 'utf16le'); // Generate the initial hash
  5204. var key = this.hash(hashAlgorithm, Buffer.from(saltValue, 'base64'), passwordBuffer); // Now regenerate until spin count
  5205. for (var i = 0; i < spinCount; i++) {
  5206. var iterator = Buffer.alloc(4); // this is the 'special' element of Excel password hashing
  5207. // that stops us from using crypto.pbkdf2()
  5208. iterator.writeUInt32LE(i, 0);
  5209. key = this.hash(hashAlgorithm, key, iterator);
  5210. }
  5211. return key.toString('base64');
  5212. },
  5213. /**
  5214. * Generates cryptographically strong pseudo-random data.
  5215. * @param size The size argument is a number indicating the number of bytes to generate.
  5216. */
  5217. randomBytes: function randomBytes(size) {
  5218. return crypto.randomBytes(size);
  5219. }
  5220. };
  5221. module.exports = Encryptor;
  5222. }).call(this,require("buffer").Buffer)
  5223. },{"buffer":216,"crypto":335}],21:[function(require,module,exports){
  5224. "use strict";
  5225. function _awaitAsyncGenerator(value) { return new _AwaitValue(value); }
  5226. function _wrapAsyncGenerator(fn) { return function () { return new _AsyncGenerator(fn.apply(this, arguments)); }; }
  5227. function _AsyncGenerator(gen) { var front, back; function send(key, arg) { return new Promise(function (resolve, reject) { var request = { key: key, arg: arg, resolve: resolve, reject: reject, next: null }; if (back) { back = back.next = request; } else { front = back = request; resume(key, arg); } }); } function resume(key, arg) { try { var result = gen[key](arg); var value = result.value; var wrappedAwait = value instanceof _AwaitValue; Promise.resolve(wrappedAwait ? value.wrapped : value).then(function (arg) { if (wrappedAwait) { resume(key === "return" ? "return" : "next", arg); return; } settle(result.done ? "return" : "normal", arg); }, function (err) { resume("throw", err); }); } catch (err) { settle("throw", err); } } function settle(type, value) { switch (type) { case "return": front.resolve({ value: value, done: true }); break; case "throw": front.reject(value); break; default: front.resolve({ value: value, done: false }); break; } front = front.next; if (front) { resume(front.key, front.arg); } else { back = null; } } this._invoke = send; if (typeof gen.return !== "function") { this.return = undefined; } }
  5228. if (typeof Symbol === "function" && Symbol.asyncIterator) { _AsyncGenerator.prototype[Symbol.asyncIterator] = function () { return this; }; }
  5229. _AsyncGenerator.prototype.next = function (arg) { return this._invoke("next", arg); };
  5230. _AsyncGenerator.prototype.throw = function (arg) { return this._invoke("throw", arg); };
  5231. _AsyncGenerator.prototype.return = function (arg) { return this._invoke("return", arg); };
  5232. function _AwaitValue(value) { this.wrapped = value; }
  5233. function _asyncIterator(iterable) { var method; if (typeof Symbol !== "undefined") { if (Symbol.asyncIterator) { method = iterable[Symbol.asyncIterator]; if (method != null) return method.call(iterable); } if (Symbol.iterator) { method = iterable[Symbol.iterator]; if (method != null) return method.call(iterable); } } throw new TypeError("Object is not async iterable"); }
  5234. var _require = require('saxes'),
  5235. SaxesParser = _require.SaxesParser;
  5236. var _require2 = require('readable-stream'),
  5237. PassThrough = _require2.PassThrough;
  5238. var _require3 = require('./browser-buffer-decode'),
  5239. bufferToString = _require3.bufferToString;
  5240. module.exports = /*#__PURE__*/function () {
  5241. var _ref = _wrapAsyncGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(iterable) {
  5242. var saxesParser, error, events, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk;
  5243. return regeneratorRuntime.wrap(function _callee$(_context) {
  5244. while (1) {
  5245. switch (_context.prev = _context.next) {
  5246. case 0:
  5247. // TODO: Remove once node v8 is deprecated
  5248. // Detect and upgrade old streams
  5249. if (iterable.pipe && !iterable[Symbol.asyncIterator]) {
  5250. iterable = iterable.pipe(new PassThrough());
  5251. }
  5252. saxesParser = new SaxesParser();
  5253. saxesParser.on('error', function (err) {
  5254. error = err;
  5255. });
  5256. events = [];
  5257. saxesParser.on('opentag', function (value) {
  5258. return events.push({
  5259. eventType: 'opentag',
  5260. value: value
  5261. });
  5262. });
  5263. saxesParser.on('text', function (value) {
  5264. return events.push({
  5265. eventType: 'text',
  5266. value: value
  5267. });
  5268. });
  5269. saxesParser.on('closetag', function (value) {
  5270. return events.push({
  5271. eventType: 'closetag',
  5272. value: value
  5273. });
  5274. });
  5275. _iteratorNormalCompletion = true;
  5276. _didIteratorError = false;
  5277. _context.prev = 9;
  5278. _iterator = _asyncIterator(iterable);
  5279. case 11:
  5280. _context.next = 13;
  5281. return _awaitAsyncGenerator(_iterator.next());
  5282. case 13:
  5283. _step = _context.sent;
  5284. _iteratorNormalCompletion = _step.done;
  5285. _context.next = 17;
  5286. return _awaitAsyncGenerator(_step.value);
  5287. case 17:
  5288. _value = _context.sent;
  5289. if (_iteratorNormalCompletion) {
  5290. _context.next = 29;
  5291. break;
  5292. }
  5293. chunk = _value;
  5294. saxesParser.write(bufferToString(chunk)); // saxesParser.write and saxesParser.on() are synchronous,
  5295. // so we can only reach the below line once all events have been emitted
  5296. if (!error) {
  5297. _context.next = 23;
  5298. break;
  5299. }
  5300. throw error;
  5301. case 23:
  5302. _context.next = 25;
  5303. return events;
  5304. case 25:
  5305. events = [];
  5306. case 26:
  5307. _iteratorNormalCompletion = true;
  5308. _context.next = 11;
  5309. break;
  5310. case 29:
  5311. _context.next = 35;
  5312. break;
  5313. case 31:
  5314. _context.prev = 31;
  5315. _context.t0 = _context["catch"](9);
  5316. _didIteratorError = true;
  5317. _iteratorError = _context.t0;
  5318. case 35:
  5319. _context.prev = 35;
  5320. _context.prev = 36;
  5321. if (!(!_iteratorNormalCompletion && _iterator.return != null)) {
  5322. _context.next = 40;
  5323. break;
  5324. }
  5325. _context.next = 40;
  5326. return _awaitAsyncGenerator(_iterator.return());
  5327. case 40:
  5328. _context.prev = 40;
  5329. if (!_didIteratorError) {
  5330. _context.next = 43;
  5331. break;
  5332. }
  5333. throw _iteratorError;
  5334. case 43:
  5335. return _context.finish(40);
  5336. case 44:
  5337. return _context.finish(35);
  5338. case 45:
  5339. case "end":
  5340. return _context.stop();
  5341. }
  5342. }
  5343. }, _callee, null, [[9, 31, 35, 45], [36,, 40, 44]]);
  5344. }));
  5345. return function (_x) {
  5346. return _ref.apply(this, arguments);
  5347. };
  5348. }();
  5349. },{"./browser-buffer-decode":16,"readable-stream":491,"saxes":496}],22:[function(require,module,exports){
  5350. "use strict";
  5351. var colCache = require('./col-cache'); // const cellRefRegex = /(([a-z_\-0-9]*)!)?[$]?([a-z]+)[$]?([1-9][0-9]*)/i;
  5352. var replacementCandidateRx = /(([a-z_\-0-9]*)!)?([a-z0-9_$]{2,})([(])?/gi;
  5353. var CRrx = /^([$])?([a-z]+)([$])?([1-9][0-9]*)$/i;
  5354. function slideFormula(formula, fromCell, toCell) {
  5355. var offset = colCache.decode(fromCell);
  5356. var to = colCache.decode(toCell);
  5357. return formula.replace(replacementCandidateRx, function (refMatch, sheet, sheetMaybe, addrPart, trailingParen) {
  5358. if (trailingParen) {
  5359. return refMatch;
  5360. }
  5361. var match = CRrx.exec(addrPart);
  5362. if (match) {
  5363. var colDollar = match[1];
  5364. var colStr = match[2].toUpperCase();
  5365. var rowDollar = match[3];
  5366. var rowStr = match[4];
  5367. if (colStr.length > 3 || colStr.length === 3 && colStr > 'XFD') {
  5368. // > XFD is the highest col number in excel 2007 and beyond, so this is a named range
  5369. return refMatch;
  5370. }
  5371. var col = colCache.l2n(colStr);
  5372. var row = parseInt(rowStr, 10);
  5373. if (!colDollar) {
  5374. col += to.col - offset.col;
  5375. }
  5376. if (!rowDollar) {
  5377. row += to.row - offset.row;
  5378. }
  5379. var res = (sheet || '') + (colDollar || '') + colCache.n2l(col) + (rowDollar || '') + row;
  5380. return res;
  5381. }
  5382. return refMatch;
  5383. });
  5384. }
  5385. module.exports = {
  5386. slideFormula: slideFormula
  5387. };
  5388. },{"./col-cache":19}],23:[function(require,module,exports){
  5389. (function (process,Buffer){
  5390. "use strict";
  5391. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
  5392. function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
  5393. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5394. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  5395. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  5396. /* eslint-disable max-classes-per-file */
  5397. var Stream = require('readable-stream');
  5398. var utils = require('./utils');
  5399. var StringBuf = require('./string-buf'); // =============================================================================
  5400. // data chunks - encapsulating incoming data
  5401. var StringChunk = /*#__PURE__*/function () {
  5402. function StringChunk(data, encoding) {
  5403. _classCallCheck(this, StringChunk);
  5404. this._data = data;
  5405. this._encoding = encoding;
  5406. }
  5407. _createClass(StringChunk, [{
  5408. key: "copy",
  5409. // copy to target buffer
  5410. value: function copy(target, targetOffset, offset, length) {
  5411. return this.toBuffer().copy(target, targetOffset, offset, length);
  5412. }
  5413. }, {
  5414. key: "toBuffer",
  5415. value: function toBuffer() {
  5416. if (!this._buffer) {
  5417. this._buffer = Buffer.from(this._data, this._encoding);
  5418. }
  5419. return this._buffer;
  5420. }
  5421. }, {
  5422. key: "length",
  5423. get: function get() {
  5424. return this.toBuffer().length;
  5425. }
  5426. }]);
  5427. return StringChunk;
  5428. }();
  5429. var StringBufChunk = /*#__PURE__*/function () {
  5430. function StringBufChunk(data) {
  5431. _classCallCheck(this, StringBufChunk);
  5432. this._data = data;
  5433. }
  5434. _createClass(StringBufChunk, [{
  5435. key: "copy",
  5436. // copy to target buffer
  5437. value: function copy(target, targetOffset, offset, length) {
  5438. // eslint-disable-next-line no-underscore-dangle
  5439. return this._data._buf.copy(target, targetOffset, offset, length);
  5440. }
  5441. }, {
  5442. key: "toBuffer",
  5443. value: function toBuffer() {
  5444. return this._data.toBuffer();
  5445. }
  5446. }, {
  5447. key: "length",
  5448. get: function get() {
  5449. return this._data.length;
  5450. }
  5451. }]);
  5452. return StringBufChunk;
  5453. }();
  5454. var BufferChunk = /*#__PURE__*/function () {
  5455. function BufferChunk(data) {
  5456. _classCallCheck(this, BufferChunk);
  5457. this._data = data;
  5458. }
  5459. _createClass(BufferChunk, [{
  5460. key: "copy",
  5461. // copy to target buffer
  5462. value: function copy(target, targetOffset, offset, length) {
  5463. this._data.copy(target, targetOffset, offset, length);
  5464. }
  5465. }, {
  5466. key: "toBuffer",
  5467. value: function toBuffer() {
  5468. return this._data;
  5469. }
  5470. }, {
  5471. key: "length",
  5472. get: function get() {
  5473. return this._data.length;
  5474. }
  5475. }]);
  5476. return BufferChunk;
  5477. }(); // =============================================================================
  5478. // ReadWriteBuf - a single buffer supporting simple read-write
  5479. var ReadWriteBuf = /*#__PURE__*/function () {
  5480. function ReadWriteBuf(size) {
  5481. _classCallCheck(this, ReadWriteBuf);
  5482. this.size = size; // the buffer
  5483. this.buffer = Buffer.alloc(size); // read index
  5484. this.iRead = 0; // write index
  5485. this.iWrite = 0;
  5486. }
  5487. _createClass(ReadWriteBuf, [{
  5488. key: "toBuffer",
  5489. value: function toBuffer() {
  5490. if (this.iRead === 0 && this.iWrite === this.size) {
  5491. return this.buffer;
  5492. }
  5493. var buf = Buffer.alloc(this.iWrite - this.iRead);
  5494. this.buffer.copy(buf, 0, this.iRead, this.iWrite);
  5495. return buf;
  5496. }
  5497. }, {
  5498. key: "read",
  5499. value: function read(size) {
  5500. var buf; // read size bytes from buffer and return buffer
  5501. if (size === 0) {
  5502. // special case - return null if no data requested
  5503. return null;
  5504. }
  5505. if (size === undefined || size >= this.length) {
  5506. // if no size specified or size is at least what we have then return all of the bytes
  5507. buf = this.toBuffer();
  5508. this.iRead = this.iWrite;
  5509. return buf;
  5510. } // otherwise return a chunk
  5511. buf = Buffer.alloc(size);
  5512. this.buffer.copy(buf, 0, this.iRead, size);
  5513. this.iRead += size;
  5514. return buf;
  5515. }
  5516. }, {
  5517. key: "write",
  5518. value: function write(chunk, offset, length) {
  5519. // write as many bytes from data from optional source offset
  5520. // and return number of bytes written
  5521. var size = Math.min(length, this.size - this.iWrite);
  5522. chunk.copy(this.buffer, this.iWrite, offset, offset + size);
  5523. this.iWrite += size;
  5524. return size;
  5525. }
  5526. }, {
  5527. key: "length",
  5528. get: function get() {
  5529. return this.iWrite - this.iRead;
  5530. }
  5531. }, {
  5532. key: "eod",
  5533. get: function get() {
  5534. return this.iRead === this.iWrite;
  5535. }
  5536. }, {
  5537. key: "full",
  5538. get: function get() {
  5539. return this.iWrite === this.size;
  5540. }
  5541. }]);
  5542. return ReadWriteBuf;
  5543. }(); // =============================================================================
  5544. // StreamBuf - a multi-purpose read-write stream
  5545. // As MemBuf - write as much data as you like. Then call toBuffer() to consolidate
  5546. // As StreamHub - pipe to multiple writables
  5547. // As readable stream - feed data into the writable part and have some other code read from it.
  5548. // Note: Not sure why but StreamBuf does not like JS "class" sugar. It fails the
  5549. // integration tests
  5550. var StreamBuf = function StreamBuf(options) {
  5551. options = options || {};
  5552. this.bufSize = options.bufSize || 1024 * 1024;
  5553. this.buffers = []; // batch mode fills a buffer completely before passing the data on
  5554. // to pipes or 'readable' event listeners
  5555. this.batch = options.batch || false;
  5556. this.corked = false; // where in the current writable buffer we're up to
  5557. this.inPos = 0; // where in the current readable buffer we've read up to
  5558. this.outPos = 0; // consuming pipe streams go here
  5559. this.pipes = []; // controls emit('data')
  5560. this.paused = false;
  5561. this.encoding = null;
  5562. };
  5563. utils.inherits(StreamBuf, Stream.Duplex, {
  5564. toBuffer: function toBuffer() {
  5565. switch (this.buffers.length) {
  5566. case 0:
  5567. return null;
  5568. case 1:
  5569. return this.buffers[0].toBuffer();
  5570. default:
  5571. return Buffer.concat(this.buffers.map(function (rwBuf) {
  5572. return rwBuf.toBuffer();
  5573. }));
  5574. }
  5575. },
  5576. // writable
  5577. // event drain - if write returns false (which it won't), indicates when safe to write again.
  5578. // finish - end() has been called
  5579. // pipe(src) - pipe() has been called on readable
  5580. // unpipe(src) - unpipe() has been called on readable
  5581. // error - duh
  5582. _getWritableBuffer: function _getWritableBuffer() {
  5583. if (this.buffers.length) {
  5584. var last = this.buffers[this.buffers.length - 1];
  5585. if (!last.full) {
  5586. return last;
  5587. }
  5588. }
  5589. var buf = new ReadWriteBuf(this.bufSize);
  5590. this.buffers.push(buf);
  5591. return buf;
  5592. },
  5593. _pipe: function _pipe(chunk) {
  5594. var _this = this;
  5595. return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
  5596. var write;
  5597. return regeneratorRuntime.wrap(function _callee$(_context) {
  5598. while (1) {
  5599. switch (_context.prev = _context.next) {
  5600. case 0:
  5601. write = function write(pipe) {
  5602. return new Promise(function (resolve) {
  5603. pipe.write(chunk.toBuffer(), function () {
  5604. resolve();
  5605. });
  5606. });
  5607. };
  5608. _context.next = 3;
  5609. return Promise.all(_this.pipes.map(write));
  5610. case 3:
  5611. case "end":
  5612. return _context.stop();
  5613. }
  5614. }
  5615. }, _callee);
  5616. }))();
  5617. },
  5618. _writeToBuffers: function _writeToBuffers(chunk) {
  5619. var inPos = 0;
  5620. var inLen = chunk.length;
  5621. while (inPos < inLen) {
  5622. // find writable buffer
  5623. var buffer = this._getWritableBuffer(); // write some data
  5624. inPos += buffer.write(chunk, inPos, inLen - inPos);
  5625. }
  5626. },
  5627. write: function write(data, encoding, callback) {
  5628. var _this2 = this;
  5629. return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
  5630. var chunk;
  5631. return regeneratorRuntime.wrap(function _callee2$(_context2) {
  5632. while (1) {
  5633. switch (_context2.prev = _context2.next) {
  5634. case 0:
  5635. if (encoding instanceof Function) {
  5636. callback = encoding;
  5637. encoding = 'utf8';
  5638. }
  5639. callback = callback || utils.nop; // encapsulate data into a chunk
  5640. if (!(data instanceof StringBuf)) {
  5641. _context2.next = 6;
  5642. break;
  5643. }
  5644. chunk = new StringBufChunk(data);
  5645. _context2.next = 15;
  5646. break;
  5647. case 6:
  5648. if (!(data instanceof Buffer)) {
  5649. _context2.next = 10;
  5650. break;
  5651. }
  5652. chunk = new BufferChunk(data);
  5653. _context2.next = 15;
  5654. break;
  5655. case 10:
  5656. if (!(typeof data === 'string' || data instanceof String || data instanceof ArrayBuffer)) {
  5657. _context2.next = 14;
  5658. break;
  5659. }
  5660. chunk = new StringChunk(data, encoding);
  5661. _context2.next = 15;
  5662. break;
  5663. case 14:
  5664. throw new Error('Chunk must be one of type String, Buffer or StringBuf.');
  5665. case 15:
  5666. if (!_this2.pipes.length) {
  5667. _context2.next = 31;
  5668. break;
  5669. }
  5670. if (!_this2.batch) {
  5671. _context2.next = 21;
  5672. break;
  5673. }
  5674. _this2._writeToBuffers(chunk);
  5675. while (!_this2.corked && _this2.buffers.length > 1) {
  5676. _this2._pipe(_this2.buffers.shift());
  5677. }
  5678. _context2.next = 29;
  5679. break;
  5680. case 21:
  5681. if (_this2.corked) {
  5682. _context2.next = 27;
  5683. break;
  5684. }
  5685. _context2.next = 24;
  5686. return _this2._pipe(chunk);
  5687. case 24:
  5688. callback();
  5689. _context2.next = 29;
  5690. break;
  5691. case 27:
  5692. _this2._writeToBuffers(chunk);
  5693. process.nextTick(callback);
  5694. case 29:
  5695. _context2.next = 34;
  5696. break;
  5697. case 31:
  5698. if (!_this2.paused) {
  5699. _this2.emit('data', chunk.toBuffer());
  5700. }
  5701. _this2._writeToBuffers(chunk);
  5702. _this2.emit('readable');
  5703. case 34:
  5704. return _context2.abrupt("return", true);
  5705. case 35:
  5706. case "end":
  5707. return _context2.stop();
  5708. }
  5709. }
  5710. }, _callee2);
  5711. }))();
  5712. },
  5713. cork: function cork() {
  5714. this.corked = true;
  5715. },
  5716. _flush: function _flush()
  5717. /* destination */
  5718. {
  5719. // if we have comsumers...
  5720. if (this.pipes.length) {
  5721. // and there's stuff not written
  5722. while (this.buffers.length) {
  5723. this._pipe(this.buffers.shift());
  5724. }
  5725. }
  5726. },
  5727. uncork: function uncork() {
  5728. this.corked = false;
  5729. this._flush();
  5730. },
  5731. end: function end(chunk, encoding, callback) {
  5732. var _this3 = this;
  5733. var writeComplete = function writeComplete(error) {
  5734. if (error) {
  5735. callback(error);
  5736. } else {
  5737. _this3._flush();
  5738. _this3.pipes.forEach(function (pipe) {
  5739. pipe.end();
  5740. });
  5741. _this3.emit('finish');
  5742. }
  5743. };
  5744. if (chunk) {
  5745. this.write(chunk, encoding, writeComplete);
  5746. } else {
  5747. writeComplete();
  5748. }
  5749. },
  5750. // readable
  5751. // event readable - some data is now available
  5752. // event data - switch to flowing mode - feeds chunks to handler
  5753. // event end - no more data
  5754. // event close - optional, indicates upstream close
  5755. // event error - duh
  5756. read: function read(size) {
  5757. var buffers; // read min(buffer, size || infinity)
  5758. if (size) {
  5759. buffers = [];
  5760. while (size && this.buffers.length && !this.buffers[0].eod) {
  5761. var first = this.buffers[0];
  5762. var buffer = first.read(size);
  5763. size -= buffer.length;
  5764. buffers.push(buffer);
  5765. if (first.eod && first.full) {
  5766. this.buffers.shift();
  5767. }
  5768. }
  5769. return Buffer.concat(buffers);
  5770. }
  5771. buffers = this.buffers.map(function (buf) {
  5772. return buf.toBuffer();
  5773. }).filter(Boolean);
  5774. this.buffers = [];
  5775. return Buffer.concat(buffers);
  5776. },
  5777. setEncoding: function setEncoding(encoding) {
  5778. // causes stream.read or stream.on('data) to return strings of encoding instead of Buffer objects
  5779. this.encoding = encoding;
  5780. },
  5781. pause: function pause() {
  5782. this.paused = true;
  5783. },
  5784. resume: function resume() {
  5785. this.paused = false;
  5786. },
  5787. isPaused: function isPaused() {
  5788. return !!this.paused;
  5789. },
  5790. pipe: function pipe(destination) {
  5791. // add destination to pipe list & write current buffer
  5792. this.pipes.push(destination);
  5793. if (!this.paused && this.buffers.length) {
  5794. this.end();
  5795. }
  5796. },
  5797. unpipe: function unpipe(destination) {
  5798. // remove destination from pipe list
  5799. this.pipes = this.pipes.filter(function (pipe) {
  5800. return pipe !== destination;
  5801. });
  5802. },
  5803. unshift: function unshift()
  5804. /* chunk */
  5805. {
  5806. // some numpty has read some data that's not for them and they want to put it back!
  5807. // Might implement this some day
  5808. throw new Error('Not Implemented');
  5809. },
  5810. wrap: function wrap()
  5811. /* stream */
  5812. {
  5813. // not implemented
  5814. throw new Error('Not Implemented');
  5815. }
  5816. });
  5817. module.exports = StreamBuf;
  5818. }).call(this,require('_process'),require("buffer").Buffer)
  5819. },{"./string-buf":24,"./utils":26,"_process":467,"buffer":216,"readable-stream":491}],24:[function(require,module,exports){
  5820. (function (Buffer){
  5821. "use strict";
  5822. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5823. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  5824. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  5825. // StringBuf - a way to keep string memory operations to a minimum
  5826. // while building the strings for the xml files
  5827. var StringBuf = /*#__PURE__*/function () {
  5828. function StringBuf(options) {
  5829. _classCallCheck(this, StringBuf);
  5830. this._buf = Buffer.alloc(options && options.size || 16384);
  5831. this._encoding = options && options.encoding || 'utf8'; // where in the buffer we are at
  5832. this._inPos = 0; // for use by toBuffer()
  5833. this._buffer = undefined;
  5834. }
  5835. _createClass(StringBuf, [{
  5836. key: "toBuffer",
  5837. value: function toBuffer() {
  5838. // return the current data as a single enclosing buffer
  5839. if (!this._buffer) {
  5840. this._buffer = Buffer.alloc(this.length);
  5841. this._buf.copy(this._buffer, 0, 0, this.length);
  5842. }
  5843. return this._buffer;
  5844. }
  5845. }, {
  5846. key: "reset",
  5847. value: function reset(position) {
  5848. position = position || 0;
  5849. this._buffer = undefined;
  5850. this._inPos = position;
  5851. }
  5852. }, {
  5853. key: "_grow",
  5854. value: function _grow(min) {
  5855. var size = this._buf.length * 2;
  5856. while (size < min) {
  5857. size *= 2;
  5858. }
  5859. var buf = Buffer.alloc(size);
  5860. this._buf.copy(buf, 0);
  5861. this._buf = buf;
  5862. }
  5863. }, {
  5864. key: "addText",
  5865. value: function addText(text) {
  5866. this._buffer = undefined;
  5867. var inPos = this._inPos + this._buf.write(text, this._inPos, this._encoding); // if we've hit (or nearing capacity), grow the buf
  5868. while (inPos >= this._buf.length - 4) {
  5869. this._grow(this._inPos + text.length); // keep trying to write until we've completely written the text
  5870. inPos = this._inPos + this._buf.write(text, this._inPos, this._encoding);
  5871. }
  5872. this._inPos = inPos;
  5873. }
  5874. }, {
  5875. key: "addStringBuf",
  5876. value: function addStringBuf(inBuf) {
  5877. if (inBuf.length) {
  5878. this._buffer = undefined;
  5879. if (this.length + inBuf.length > this.capacity) {
  5880. this._grow(this.length + inBuf.length);
  5881. } // eslint-disable-next-line no-underscore-dangle
  5882. inBuf._buf.copy(this._buf, this._inPos, 0, inBuf.length);
  5883. this._inPos += inBuf.length;
  5884. }
  5885. }
  5886. }, {
  5887. key: "length",
  5888. get: function get() {
  5889. return this._inPos;
  5890. }
  5891. }, {
  5892. key: "capacity",
  5893. get: function get() {
  5894. return this._buf.length;
  5895. }
  5896. }, {
  5897. key: "buffer",
  5898. get: function get() {
  5899. return this._buf;
  5900. }
  5901. }]);
  5902. return StringBuf;
  5903. }();
  5904. module.exports = StringBuf;
  5905. }).call(this,require("buffer").Buffer)
  5906. },{"buffer":216}],25:[function(require,module,exports){
  5907. "use strict";
  5908. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  5909. var toString = Object.prototype.toString;
  5910. var escapeHtmlRegex = /["&<>]/;
  5911. var _ = {
  5912. each: function each(obj, cb) {
  5913. if (obj) {
  5914. if (Array.isArray(obj)) {
  5915. obj.forEach(cb);
  5916. } else {
  5917. Object.keys(obj).forEach(function (key) {
  5918. cb(obj[key], key);
  5919. });
  5920. }
  5921. }
  5922. },
  5923. some: function some(obj, cb) {
  5924. if (obj) {
  5925. if (Array.isArray(obj)) {
  5926. return obj.some(cb);
  5927. }
  5928. return Object.keys(obj).some(function (key) {
  5929. return cb(obj[key], key);
  5930. });
  5931. }
  5932. return false;
  5933. },
  5934. every: function every(obj, cb) {
  5935. if (obj) {
  5936. if (Array.isArray(obj)) {
  5937. return obj.every(cb);
  5938. }
  5939. return Object.keys(obj).every(function (key) {
  5940. return cb(obj[key], key);
  5941. });
  5942. }
  5943. return true;
  5944. },
  5945. map: function map(obj, cb) {
  5946. if (obj) {
  5947. if (Array.isArray(obj)) {
  5948. return obj.map(cb);
  5949. }
  5950. return Object.keys(obj).map(function (key) {
  5951. return cb(obj[key], key);
  5952. });
  5953. }
  5954. return [];
  5955. },
  5956. keyBy: function keyBy(a, p) {
  5957. return a.reduce(function (o, v) {
  5958. o[v[p]] = v;
  5959. return o;
  5960. }, {});
  5961. },
  5962. isEqual: function isEqual(a, b) {
  5963. var aType = _typeof(a);
  5964. var bType = _typeof(b);
  5965. var aArray = Array.isArray(a);
  5966. var bArray = Array.isArray(b);
  5967. if (aType !== bType) {
  5968. return false;
  5969. }
  5970. switch (_typeof(a)) {
  5971. case 'object':
  5972. if (aArray || bArray) {
  5973. if (aArray && bArray) {
  5974. return a.length === b.length && a.every(function (aValue, index) {
  5975. var bValue = b[index];
  5976. return _.isEqual(aValue, bValue);
  5977. });
  5978. }
  5979. return false;
  5980. }
  5981. return _.every(a, function (aValue, key) {
  5982. var bValue = b[key];
  5983. return _.isEqual(aValue, bValue);
  5984. });
  5985. default:
  5986. return a === b;
  5987. }
  5988. },
  5989. escapeHtml: function escapeHtml(html) {
  5990. var regexResult = escapeHtmlRegex.exec(html);
  5991. if (!regexResult) return html;
  5992. var result = '';
  5993. var escape = '';
  5994. var lastIndex = 0;
  5995. var i = regexResult.index;
  5996. for (; i < html.length; i++) {
  5997. switch (html.charAt(i)) {
  5998. case '"':
  5999. escape = '&quot;';
  6000. break;
  6001. case '&':
  6002. escape = '&amp;';
  6003. break;
  6004. case '\'':
  6005. escape = '&apos;';
  6006. break;
  6007. case '<':
  6008. escape = '&lt;';
  6009. break;
  6010. case '>':
  6011. escape = '&gt;';
  6012. break;
  6013. default:
  6014. continue;
  6015. }
  6016. if (lastIndex !== i) result += html.substring(lastIndex, i);
  6017. lastIndex = i + 1;
  6018. result += escape;
  6019. }
  6020. if (lastIndex !== i) return result + html.substring(lastIndex, i);
  6021. return result;
  6022. },
  6023. strcmp: function strcmp(a, b) {
  6024. if (a < b) return -1;
  6025. if (a > b) return 1;
  6026. return 0;
  6027. },
  6028. isUndefined: function isUndefined(val) {
  6029. return toString.call(val) === '[object Undefined]';
  6030. },
  6031. isObject: function isObject(val) {
  6032. return toString.call(val) === '[object Object]';
  6033. },
  6034. deepMerge: function deepMerge() {
  6035. var target = arguments[0] || {};
  6036. var length = arguments.length; // eslint-disable-next-line one-var
  6037. var src, clone, copyIsArray;
  6038. function assignValue(val, key) {
  6039. src = target[key];
  6040. copyIsArray = Array.isArray(val);
  6041. if (_.isObject(val) || copyIsArray) {
  6042. if (copyIsArray) {
  6043. copyIsArray = false;
  6044. clone = src && Array.isArray(src) ? src : [];
  6045. } else {
  6046. clone = src && _.isObject(src) ? src : {};
  6047. }
  6048. target[key] = _.deepMerge(clone, val);
  6049. } else if (!_.isUndefined(val)) {
  6050. target[key] = val;
  6051. }
  6052. }
  6053. for (var i = 0; i < length; i++) {
  6054. _.each(arguments[i], assignValue);
  6055. }
  6056. return target;
  6057. }
  6058. };
  6059. module.exports = _;
  6060. },{}],26:[function(require,module,exports){
  6061. (function (global,setImmediate){
  6062. "use strict";
  6063. var fs = require('fs'); // useful stuff
  6064. var inherits = function inherits(cls, superCtor, statics, prototype) {
  6065. // eslint-disable-next-line no-underscore-dangle
  6066. cls.super_ = superCtor;
  6067. if (!prototype) {
  6068. prototype = statics;
  6069. statics = null;
  6070. }
  6071. if (statics) {
  6072. Object.keys(statics).forEach(function (i) {
  6073. Object.defineProperty(cls, i, Object.getOwnPropertyDescriptor(statics, i));
  6074. });
  6075. }
  6076. var properties = {
  6077. constructor: {
  6078. value: cls,
  6079. enumerable: false,
  6080. writable: false,
  6081. configurable: true
  6082. }
  6083. };
  6084. if (prototype) {
  6085. Object.keys(prototype).forEach(function (i) {
  6086. properties[i] = Object.getOwnPropertyDescriptor(prototype, i);
  6087. });
  6088. }
  6089. cls.prototype = Object.create(superCtor.prototype, properties);
  6090. }; // eslint-disable-next-line no-control-regex
  6091. var xmlDecodeRegex = /[<>&'"\x7F\x00-\x08\x0B-\x0C\x0E-\x1F]/;
  6092. var utils = {
  6093. nop: function nop() {},
  6094. promiseImmediate: function promiseImmediate(value) {
  6095. return new Promise(function (resolve) {
  6096. if (global.setImmediate) {
  6097. setImmediate(function () {
  6098. resolve(value);
  6099. });
  6100. } else {
  6101. // poorman's setImmediate - must wait at least 1ms
  6102. setTimeout(function () {
  6103. resolve(value);
  6104. }, 1);
  6105. }
  6106. });
  6107. },
  6108. inherits: inherits,
  6109. dateToExcel: function dateToExcel(d, date1904) {
  6110. return 25569 + d.getTime() / (24 * 3600 * 1000) - (date1904 ? 1462 : 0);
  6111. },
  6112. excelToDate: function excelToDate(v, date1904) {
  6113. var millisecondSinceEpoch = Math.round((v - 25569 + (date1904 ? 1462 : 0)) * 24 * 3600 * 1000);
  6114. return new Date(millisecondSinceEpoch);
  6115. },
  6116. parsePath: function parsePath(filepath) {
  6117. var last = filepath.lastIndexOf('/');
  6118. return {
  6119. path: filepath.substring(0, last),
  6120. name: filepath.substring(last + 1)
  6121. };
  6122. },
  6123. getRelsPath: function getRelsPath(filepath) {
  6124. var path = utils.parsePath(filepath);
  6125. return "".concat(path.path, "/_rels/").concat(path.name, ".rels");
  6126. },
  6127. xmlEncode: function xmlEncode(text) {
  6128. var regexResult = xmlDecodeRegex.exec(text);
  6129. if (!regexResult) return text;
  6130. var result = '';
  6131. var escape = '';
  6132. var lastIndex = 0;
  6133. var i = regexResult.index;
  6134. for (; i < text.length; i++) {
  6135. var charCode = text.charCodeAt(i);
  6136. switch (charCode) {
  6137. case 34:
  6138. // "
  6139. escape = '&quot;';
  6140. break;
  6141. case 38:
  6142. // &
  6143. escape = '&amp;';
  6144. break;
  6145. case 39:
  6146. // '
  6147. escape = '&apos;';
  6148. break;
  6149. case 60:
  6150. // <
  6151. escape = '&lt;';
  6152. break;
  6153. case 62:
  6154. // >
  6155. escape = '&gt;';
  6156. break;
  6157. case 127:
  6158. escape = '';
  6159. break;
  6160. default:
  6161. {
  6162. if (charCode <= 31 && (charCode <= 8 || charCode >= 11 && charCode !== 13)) {
  6163. escape = '';
  6164. break;
  6165. }
  6166. continue;
  6167. }
  6168. }
  6169. if (lastIndex !== i) result += text.substring(lastIndex, i);
  6170. lastIndex = i + 1;
  6171. if (escape) result += escape;
  6172. }
  6173. if (lastIndex !== i) return result + text.substring(lastIndex, i);
  6174. return result;
  6175. },
  6176. xmlDecode: function xmlDecode(text) {
  6177. return text.replace(/&([a-z]*);/g, function (c) {
  6178. switch (c) {
  6179. case '&lt;':
  6180. return '<';
  6181. case '&gt;':
  6182. return '>';
  6183. case '&amp;':
  6184. return '&';
  6185. case '&apos;':
  6186. return '\'';
  6187. case '&quot;':
  6188. return '"';
  6189. default:
  6190. return c;
  6191. }
  6192. });
  6193. },
  6194. validInt: function validInt(value) {
  6195. var i = parseInt(value, 10);
  6196. return !Number.isNaN(i) ? i : 0;
  6197. },
  6198. isDateFmt: function isDateFmt(fmt) {
  6199. if (!fmt) {
  6200. return false;
  6201. } // must remove all chars inside quotes and []
  6202. fmt = fmt.replace(/\[[^\]]*]/g, '');
  6203. fmt = fmt.replace(/"[^"]*"/g, ''); // then check for date formatting chars
  6204. var result = fmt.match(/[ymdhMsb]+/) !== null;
  6205. return result;
  6206. },
  6207. fs: {
  6208. exists: function exists(path) {
  6209. return new Promise(function (resolve) {
  6210. fs.access(path, fs.constants.F_OK, function (err) {
  6211. resolve(!err);
  6212. });
  6213. });
  6214. }
  6215. },
  6216. toIsoDateString: function toIsoDateString(dt) {
  6217. return dt.toIsoString().subsstr(0, 10);
  6218. }
  6219. };
  6220. module.exports = utils;
  6221. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("timers").setImmediate)
  6222. },{"fs":215,"timers":521}],27:[function(require,module,exports){
  6223. "use strict";
  6224. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6225. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  6226. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  6227. var _ = require('./under-dash');
  6228. var utils = require('./utils'); // constants
  6229. var OPEN_ANGLE = '<';
  6230. var CLOSE_ANGLE = '>';
  6231. var OPEN_ANGLE_SLASH = '</';
  6232. var CLOSE_SLASH_ANGLE = '/>';
  6233. var EQUALS_QUOTE = '="';
  6234. var QUOTE = '"';
  6235. var SPACE = ' ';
  6236. function pushAttribute(xml, name, value) {
  6237. xml.push(SPACE);
  6238. xml.push(name);
  6239. xml.push(EQUALS_QUOTE);
  6240. xml.push(utils.xmlEncode(value.toString()));
  6241. xml.push(QUOTE);
  6242. }
  6243. function pushAttributes(xml, attributes) {
  6244. if (attributes) {
  6245. _.each(attributes, function (value, name) {
  6246. if (value !== undefined) {
  6247. pushAttribute(xml, name, value);
  6248. }
  6249. });
  6250. }
  6251. }
  6252. var XmlStream = /*#__PURE__*/function () {
  6253. function XmlStream() {
  6254. _classCallCheck(this, XmlStream);
  6255. this._xml = [];
  6256. this._stack = [];
  6257. this._rollbacks = [];
  6258. }
  6259. _createClass(XmlStream, [{
  6260. key: "openXml",
  6261. value: function openXml(docAttributes) {
  6262. var xml = this._xml; // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  6263. xml.push('<?xml');
  6264. pushAttributes(xml, docAttributes);
  6265. xml.push('?>\n');
  6266. }
  6267. }, {
  6268. key: "openNode",
  6269. value: function openNode(name, attributes) {
  6270. var parent = this.tos;
  6271. var xml = this._xml;
  6272. if (parent && this.open) {
  6273. xml.push(CLOSE_ANGLE);
  6274. }
  6275. this._stack.push(name); // start streaming node
  6276. xml.push(OPEN_ANGLE);
  6277. xml.push(name);
  6278. pushAttributes(xml, attributes);
  6279. this.leaf = true;
  6280. this.open = true;
  6281. }
  6282. }, {
  6283. key: "addAttribute",
  6284. value: function addAttribute(name, value) {
  6285. if (!this.open) {
  6286. throw new Error('Cannot write attributes to node if it is not open');
  6287. }
  6288. if (value !== undefined) {
  6289. pushAttribute(this._xml, name, value);
  6290. }
  6291. }
  6292. }, {
  6293. key: "addAttributes",
  6294. value: function addAttributes(attrs) {
  6295. if (!this.open) {
  6296. throw new Error('Cannot write attributes to node if it is not open');
  6297. }
  6298. pushAttributes(this._xml, attrs);
  6299. }
  6300. }, {
  6301. key: "writeText",
  6302. value: function writeText(text) {
  6303. var xml = this._xml;
  6304. if (this.open) {
  6305. xml.push(CLOSE_ANGLE);
  6306. this.open = false;
  6307. }
  6308. this.leaf = false;
  6309. xml.push(utils.xmlEncode(text.toString()));
  6310. }
  6311. }, {
  6312. key: "writeXml",
  6313. value: function writeXml(xml) {
  6314. if (this.open) {
  6315. this._xml.push(CLOSE_ANGLE);
  6316. this.open = false;
  6317. }
  6318. this.leaf = false;
  6319. this._xml.push(xml);
  6320. }
  6321. }, {
  6322. key: "closeNode",
  6323. value: function closeNode() {
  6324. var node = this._stack.pop();
  6325. var xml = this._xml;
  6326. if (this.leaf) {
  6327. xml.push(CLOSE_SLASH_ANGLE);
  6328. } else {
  6329. xml.push(OPEN_ANGLE_SLASH);
  6330. xml.push(node);
  6331. xml.push(CLOSE_ANGLE);
  6332. }
  6333. this.open = false;
  6334. this.leaf = false;
  6335. }
  6336. }, {
  6337. key: "leafNode",
  6338. value: function leafNode(name, attributes, text) {
  6339. this.openNode(name, attributes);
  6340. if (text !== undefined) {
  6341. // zeros need to be written
  6342. this.writeText(text);
  6343. }
  6344. this.closeNode();
  6345. }
  6346. }, {
  6347. key: "closeAll",
  6348. value: function closeAll() {
  6349. while (this._stack.length) {
  6350. this.closeNode();
  6351. }
  6352. }
  6353. }, {
  6354. key: "addRollback",
  6355. value: function addRollback() {
  6356. this._rollbacks.push({
  6357. xml: this._xml.length,
  6358. stack: this._stack.length,
  6359. leaf: this.leaf,
  6360. open: this.open
  6361. });
  6362. return this.cursor;
  6363. }
  6364. }, {
  6365. key: "commit",
  6366. value: function commit() {
  6367. this._rollbacks.pop();
  6368. }
  6369. }, {
  6370. key: "rollback",
  6371. value: function rollback() {
  6372. var r = this._rollbacks.pop();
  6373. if (this._xml.length > r.xml) {
  6374. this._xml.splice(r.xml, this._xml.length - r.xml);
  6375. }
  6376. if (this._stack.length > r.stack) {
  6377. this._stack.splice(r.stack, this._stack.length - r.stack);
  6378. }
  6379. this.leaf = r.leaf;
  6380. this.open = r.open;
  6381. }
  6382. }, {
  6383. key: "tos",
  6384. get: function get() {
  6385. return this._stack.length ? this._stack[this._stack.length - 1] : undefined;
  6386. }
  6387. }, {
  6388. key: "cursor",
  6389. get: function get() {
  6390. // handy way to track whether anything has been added
  6391. return this._xml.length;
  6392. }
  6393. }, {
  6394. key: "xml",
  6395. get: function get() {
  6396. this.closeAll();
  6397. return this._xml.join('');
  6398. }
  6399. }]);
  6400. return XmlStream;
  6401. }();
  6402. XmlStream.StdDocAttributes = {
  6403. version: '1.0',
  6404. encoding: 'UTF-8',
  6405. standalone: 'yes'
  6406. };
  6407. module.exports = XmlStream;
  6408. },{"./under-dash":25,"./utils":26}],28:[function(require,module,exports){
  6409. (function (process){
  6410. "use strict";
  6411. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  6412. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
  6413. function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
  6414. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6415. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  6416. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  6417. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  6418. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  6419. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  6420. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  6421. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  6422. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  6423. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  6424. var events = require('events');
  6425. var JSZip = require('jszip');
  6426. var StreamBuf = require('./stream-buf');
  6427. var _require = require('./browser-buffer-encode'),
  6428. stringToBuffer = _require.stringToBuffer; // =============================================================================
  6429. // The ZipWriter class
  6430. // Packs streamed data into an output zip stream
  6431. var ZipWriter = /*#__PURE__*/function (_events$EventEmitter) {
  6432. _inherits(ZipWriter, _events$EventEmitter);
  6433. var _super = _createSuper(ZipWriter);
  6434. function ZipWriter(options) {
  6435. var _this;
  6436. _classCallCheck(this, ZipWriter);
  6437. _this = _super.call(this);
  6438. _this.options = Object.assign({
  6439. type: 'nodebuffer',
  6440. compression: 'DEFLATE'
  6441. }, options);
  6442. _this.zip = new JSZip();
  6443. _this.stream = new StreamBuf();
  6444. return _this;
  6445. }
  6446. _createClass(ZipWriter, [{
  6447. key: "append",
  6448. value: function append(data, options) {
  6449. if (options.hasOwnProperty('base64') && options.base64) {
  6450. this.zip.file(options.name, data, {
  6451. base64: true
  6452. });
  6453. } else {
  6454. // https://www.npmjs.com/package/process
  6455. if (process.browser && typeof data === 'string') {
  6456. // use TextEncoder in browser
  6457. data = stringToBuffer(data);
  6458. }
  6459. this.zip.file(options.name, data);
  6460. }
  6461. }
  6462. }, {
  6463. key: "finalize",
  6464. value: function () {
  6465. var _finalize = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
  6466. var content;
  6467. return regeneratorRuntime.wrap(function _callee$(_context) {
  6468. while (1) {
  6469. switch (_context.prev = _context.next) {
  6470. case 0:
  6471. _context.next = 2;
  6472. return this.zip.generateAsync(this.options);
  6473. case 2:
  6474. content = _context.sent;
  6475. this.stream.end(content);
  6476. this.emit('finish');
  6477. case 5:
  6478. case "end":
  6479. return _context.stop();
  6480. }
  6481. }
  6482. }, _callee, this);
  6483. }));
  6484. function finalize() {
  6485. return _finalize.apply(this, arguments);
  6486. }
  6487. return finalize;
  6488. }() // ==========================================================================
  6489. // Stream.Readable interface
  6490. }, {
  6491. key: "read",
  6492. value: function read(size) {
  6493. return this.stream.read(size);
  6494. }
  6495. }, {
  6496. key: "setEncoding",
  6497. value: function setEncoding(encoding) {
  6498. return this.stream.setEncoding(encoding);
  6499. }
  6500. }, {
  6501. key: "pause",
  6502. value: function pause() {
  6503. return this.stream.pause();
  6504. }
  6505. }, {
  6506. key: "resume",
  6507. value: function resume() {
  6508. return this.stream.resume();
  6509. }
  6510. }, {
  6511. key: "isPaused",
  6512. value: function isPaused() {
  6513. return this.stream.isPaused();
  6514. }
  6515. }, {
  6516. key: "pipe",
  6517. value: function pipe(destination, options) {
  6518. return this.stream.pipe(destination, options);
  6519. }
  6520. }, {
  6521. key: "unpipe",
  6522. value: function unpipe(destination) {
  6523. return this.stream.unpipe(destination);
  6524. }
  6525. }, {
  6526. key: "unshift",
  6527. value: function unshift(chunk) {
  6528. return this.stream.unshift(chunk);
  6529. }
  6530. }, {
  6531. key: "wrap",
  6532. value: function wrap(stream) {
  6533. return this.stream.wrap(stream);
  6534. }
  6535. }]);
  6536. return ZipWriter;
  6537. }(events.EventEmitter); // =============================================================================
  6538. module.exports = {
  6539. ZipWriter: ZipWriter
  6540. };
  6541. }).call(this,require('_process'))
  6542. },{"./browser-buffer-encode":17,"./stream-buf":23,"_process":467,"events":367,"jszip":399}],29:[function(require,module,exports){
  6543. "use strict";
  6544. module.exports = {
  6545. 0: {
  6546. f: 'General'
  6547. },
  6548. 1: {
  6549. f: '0'
  6550. },
  6551. 2: {
  6552. f: '0.00'
  6553. },
  6554. 3: {
  6555. f: '#,##0'
  6556. },
  6557. 4: {
  6558. f: '#,##0.00'
  6559. },
  6560. 9: {
  6561. f: '0%'
  6562. },
  6563. 10: {
  6564. f: '0.00%'
  6565. },
  6566. 11: {
  6567. f: '0.00E+00'
  6568. },
  6569. 12: {
  6570. f: '# ?/?'
  6571. },
  6572. 13: {
  6573. f: '# ??/??'
  6574. },
  6575. 14: {
  6576. f: 'mm-dd-yy'
  6577. },
  6578. 15: {
  6579. f: 'd-mmm-yy'
  6580. },
  6581. 16: {
  6582. f: 'd-mmm'
  6583. },
  6584. 17: {
  6585. f: 'mmm-yy'
  6586. },
  6587. 18: {
  6588. f: 'h:mm AM/PM'
  6589. },
  6590. 19: {
  6591. f: 'h:mm:ss AM/PM'
  6592. },
  6593. 20: {
  6594. f: 'h:mm'
  6595. },
  6596. 21: {
  6597. f: 'h:mm:ss'
  6598. },
  6599. 22: {
  6600. f: 'm/d/yy "h":mm'
  6601. },
  6602. 27: {
  6603. 'zh-tw': '[$-404]e/m/d',
  6604. 'zh-cn': 'yyyy"年"m"月"',
  6605. 'ja-jp': '[$-411]ge.m.d',
  6606. 'ko-kr': 'yyyy"年" mm"月" dd"日"'
  6607. },
  6608. 28: {
  6609. 'zh-tw': '[$-404]e"年"m"月"d"日"',
  6610. 'zh-cn': 'm"月"d"日"',
  6611. 'ja-jp': '[$-411]ggge"年"m"月"d"日"',
  6612. 'ko-kr': 'mm-dd'
  6613. },
  6614. 29: {
  6615. 'zh-tw': '[$-404]e"年"m"月"d"日"',
  6616. 'zh-cn': 'm"月"d"日"',
  6617. 'ja-jp': '[$-411]ggge"年"m"月"d"日"',
  6618. 'ko-kr': 'mm-dd'
  6619. },
  6620. 30: {
  6621. 'zh-tw': 'm/d/yy ',
  6622. 'zh-cn': 'm-d-yy',
  6623. 'ja-jp': 'm/d/yy',
  6624. 'ko-kr': 'mm-dd-yy'
  6625. },
  6626. 31: {
  6627. 'zh-tw': 'yyyy"年"m"月"d"日"',
  6628. 'zh-cn': 'yyyy"年"m"月"d"日"',
  6629. 'ja-jp': 'yyyy"年"m"月"d"日"',
  6630. 'ko-kr': 'yyyy"년" mm"월" dd"일"'
  6631. },
  6632. 32: {
  6633. 'zh-tw': 'hh"時"mm"分"',
  6634. 'zh-cn': 'h"时"mm"分"',
  6635. 'ja-jp': 'h"時"mm"分"',
  6636. 'ko-kr': 'h"시" mm"분"'
  6637. },
  6638. 33: {
  6639. 'zh-tw': 'hh"時"mm"分"ss"秒"',
  6640. 'zh-cn': 'h"时"mm"分"ss"秒"',
  6641. 'ja-jp': 'h"時"mm"分"ss"秒"',
  6642. 'ko-kr': 'h"시" mm"분" ss"초"'
  6643. },
  6644. 34: {
  6645. 'zh-tw': '上午/下午 hh"時"mm"分"',
  6646. 'zh-cn': '上午/下午 h"时"mm"分"',
  6647. 'ja-jp': 'yyyy"年"m"月"',
  6648. 'ko-kr': 'yyyy-mm-dd'
  6649. },
  6650. 35: {
  6651. 'zh-tw': '上午/下午 hh"時"mm"分"ss"秒"',
  6652. 'zh-cn': '上午/下午 h"时"mm"分"ss"秒"',
  6653. 'ja-jp': 'm"月"d"日"',
  6654. 'ko-kr': 'yyyy-mm-dd'
  6655. },
  6656. 36: {
  6657. 'zh-tw': '[$-404]e/m/d',
  6658. 'zh-cn': 'yyyy"年"m"月"',
  6659. 'ja-jp': '[$-411]ge.m.d',
  6660. 'ko-kr': 'yyyy"年" mm"月" dd"日"'
  6661. },
  6662. 37: {
  6663. f: '#,##0 ;(#,##0)'
  6664. },
  6665. 38: {
  6666. f: '#,##0 ;[Red](#,##0)'
  6667. },
  6668. 39: {
  6669. f: '#,##0.00 ;(#,##0.00)'
  6670. },
  6671. 40: {
  6672. f: '#,##0.00 ;[Red](#,##0.00)'
  6673. },
  6674. 45: {
  6675. f: 'mm:ss'
  6676. },
  6677. 46: {
  6678. f: '[h]:mm:ss'
  6679. },
  6680. 47: {
  6681. f: 'mmss.0'
  6682. },
  6683. 48: {
  6684. f: '##0.0E+0'
  6685. },
  6686. 49: {
  6687. f: '@'
  6688. },
  6689. 50: {
  6690. 'zh-tw': '[$-404]e/m/d',
  6691. 'zh-cn': 'yyyy"年"m"月"',
  6692. 'ja-jp': '[$-411]ge.m.d',
  6693. 'ko-kr': 'yyyy"年" mm"月" dd"日"'
  6694. },
  6695. 51: {
  6696. 'zh-tw': '[$-404]e"年"m"月"d"日"',
  6697. 'zh-cn': 'm"月"d"日"',
  6698. 'ja-jp': '[$-411]ggge"年"m"月"d"日"',
  6699. 'ko-kr': 'mm-dd'
  6700. },
  6701. 52: {
  6702. 'zh-tw': '上午/下午 hh"時"mm"分"',
  6703. 'zh-cn': 'yyyy"年"m"月"',
  6704. 'ja-jp': 'yyyy"年"m"月"',
  6705. 'ko-kr': 'yyyy-mm-dd'
  6706. },
  6707. 53: {
  6708. 'zh-tw': '上午/下午 hh"時"mm"分"ss"秒"',
  6709. 'zh-cn': 'm"月"d"日"',
  6710. 'ja-jp': 'm"月"d"日"',
  6711. 'ko-kr': 'yyyy-mm-dd'
  6712. },
  6713. 54: {
  6714. 'zh-tw': '[$-404]e"年"m"月"d"日"',
  6715. 'zh-cn': 'm"月"d"日"',
  6716. 'ja-jp': '[$-411]ggge"年"m"月"d"日"',
  6717. 'ko-kr': 'mm-dd'
  6718. },
  6719. 55: {
  6720. 'zh-tw': '上午/下午 hh"時"mm"分"',
  6721. 'zh-cn': '上午/下午 h"时"mm"分"',
  6722. 'ja-jp': 'yyyy"年"m"月"',
  6723. 'ko-kr': 'yyyy-mm-dd'
  6724. },
  6725. 56: {
  6726. 'zh-tw': '上午/下午 hh"時"mm"分"ss"秒"',
  6727. 'zh-cn': '上午/下午 h"时"mm"分"ss"秒"',
  6728. 'ja-jp': 'm"月"d"日"',
  6729. 'ko-kr': 'yyyy-mm-dd'
  6730. },
  6731. 57: {
  6732. 'zh-tw': '[$-404]e/m/d',
  6733. 'zh-cn': 'yyyy"年"m"月"',
  6734. 'ja-jp': '[$-411]ge.m.d',
  6735. 'ko-kr': 'yyyy"年" mm"月" dd"日"'
  6736. },
  6737. 58: {
  6738. 'zh-tw': '[$-404]e"年"m"月"d"日"',
  6739. 'zh-cn': 'm"月"d"日"',
  6740. 'ja-jp': '[$-411]ggge"年"m"月"d"日"',
  6741. 'ko-kr': 'mm-dd'
  6742. },
  6743. 59: {
  6744. 'th-th': 't0'
  6745. },
  6746. 60: {
  6747. 'th-th': 't0.00'
  6748. },
  6749. 61: {
  6750. 'th-th': 't#,##0'
  6751. },
  6752. 62: {
  6753. 'th-th': 't#,##0.00'
  6754. },
  6755. 67: {
  6756. 'th-th': 't0%'
  6757. },
  6758. 68: {
  6759. 'th-th': 't0.00%'
  6760. },
  6761. 69: {
  6762. 'th-th': 't# ?/?'
  6763. },
  6764. 70: {
  6765. 'th-th': 't# ??/??'
  6766. },
  6767. 81: {
  6768. 'th-th': 'd/m/bb'
  6769. }
  6770. };
  6771. },{}],30:[function(require,module,exports){
  6772. 'use strict';
  6773. module.exports = {
  6774. OfficeDocument: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument',
  6775. Worksheet: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet',
  6776. CalcChain: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/calcChain',
  6777. SharedStrings: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings',
  6778. Styles: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles',
  6779. Theme: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme',
  6780. Hyperlink: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink',
  6781. Image: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image',
  6782. CoreProperties: 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties',
  6783. ExtenderProperties: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties',
  6784. Comments: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments',
  6785. VmlDrawing: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing',
  6786. Table: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/table'
  6787. };
  6788. },{}],31:[function(require,module,exports){
  6789. "use strict";
  6790. function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
  6791. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  6792. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  6793. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
  6794. function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
  6795. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6796. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  6797. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  6798. function _asyncIterator(iterable) { var method; if (typeof Symbol !== "undefined") { if (Symbol.asyncIterator) { method = iterable[Symbol.asyncIterator]; if (method != null) return method.call(iterable); } if (Symbol.iterator) { method = iterable[Symbol.iterator]; if (method != null) return method.call(iterable); } } throw new TypeError("Object is not async iterable"); }
  6799. var parseSax = require('../../utils/parse-sax');
  6800. var XmlStream = require('../../utils/xml-stream');
  6801. /* 'virtual' methods used as a form of documentation */
  6802. /* eslint-disable class-methods-use-this */
  6803. // Base class for Xforms
  6804. var BaseXform = /*#__PURE__*/function () {
  6805. function BaseXform() {
  6806. _classCallCheck(this, BaseXform);
  6807. }
  6808. _createClass(BaseXform, [{
  6809. key: "prepare",
  6810. // constructor(/* model, name */) {}
  6811. // ============================================================
  6812. // Virtual Interface
  6813. value: function prepare()
  6814. /* model, options */
  6815. {// optional preparation (mutation) of model so it is ready for write
  6816. }
  6817. }, {
  6818. key: "render",
  6819. value: function render()
  6820. /* xmlStream, model */
  6821. {// convert model to xml
  6822. }
  6823. }, {
  6824. key: "parseOpen",
  6825. value: function parseOpen(node) {// XML node opened
  6826. }
  6827. }, {
  6828. key: "parseText",
  6829. value: function parseText(text) {// chunk of text encountered for current node
  6830. }
  6831. }, {
  6832. key: "parseClose",
  6833. value: function parseClose(name) {// XML node closed
  6834. }
  6835. }, {
  6836. key: "reconcile",
  6837. value: function reconcile(model, options) {// optional post-parse step (opposite to prepare)
  6838. } // ============================================================
  6839. }, {
  6840. key: "reset",
  6841. value: function reset() {
  6842. // to make sure parses don't bleed to next iteration
  6843. this.model = null; // if we have a map - reset them too
  6844. if (this.map) {
  6845. Object.values(this.map).forEach(function (xform) {
  6846. if (xform instanceof BaseXform) {
  6847. xform.reset();
  6848. } else if (xform.xform) {
  6849. xform.xform.reset();
  6850. }
  6851. });
  6852. }
  6853. }
  6854. }, {
  6855. key: "mergeModel",
  6856. value: function mergeModel(obj) {
  6857. // set obj's props to this.model
  6858. this.model = Object.assign(this.model || {}, obj);
  6859. }
  6860. }, {
  6861. key: "parse",
  6862. value: function () {
  6863. var _parse = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(saxParser) {
  6864. var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, events, _iterator2, _step2, _step2$value, eventType, value;
  6865. return regeneratorRuntime.wrap(function _callee$(_context) {
  6866. while (1) {
  6867. switch (_context.prev = _context.next) {
  6868. case 0:
  6869. _iteratorNormalCompletion = true;
  6870. _didIteratorError = false;
  6871. _context.prev = 2;
  6872. _iterator = _asyncIterator(saxParser);
  6873. case 4:
  6874. _context.next = 6;
  6875. return _iterator.next();
  6876. case 6:
  6877. _step = _context.sent;
  6878. _iteratorNormalCompletion = _step.done;
  6879. _context.next = 10;
  6880. return _step.value;
  6881. case 10:
  6882. _value = _context.sent;
  6883. if (_iteratorNormalCompletion) {
  6884. _context.next = 42;
  6885. break;
  6886. }
  6887. events = _value;
  6888. _iterator2 = _createForOfIteratorHelper(events);
  6889. _context.prev = 14;
  6890. _iterator2.s();
  6891. case 16:
  6892. if ((_step2 = _iterator2.n()).done) {
  6893. _context.next = 31;
  6894. break;
  6895. }
  6896. _step2$value = _step2.value, eventType = _step2$value.eventType, value = _step2$value.value;
  6897. if (!(eventType === 'opentag')) {
  6898. _context.next = 22;
  6899. break;
  6900. }
  6901. this.parseOpen(value);
  6902. _context.next = 29;
  6903. break;
  6904. case 22:
  6905. if (!(eventType === 'text')) {
  6906. _context.next = 26;
  6907. break;
  6908. }
  6909. this.parseText(value);
  6910. _context.next = 29;
  6911. break;
  6912. case 26:
  6913. if (!(eventType === 'closetag')) {
  6914. _context.next = 29;
  6915. break;
  6916. }
  6917. if (this.parseClose(value.name)) {
  6918. _context.next = 29;
  6919. break;
  6920. }
  6921. return _context.abrupt("return", this.model);
  6922. case 29:
  6923. _context.next = 16;
  6924. break;
  6925. case 31:
  6926. _context.next = 36;
  6927. break;
  6928. case 33:
  6929. _context.prev = 33;
  6930. _context.t0 = _context["catch"](14);
  6931. _iterator2.e(_context.t0);
  6932. case 36:
  6933. _context.prev = 36;
  6934. _iterator2.f();
  6935. return _context.finish(36);
  6936. case 39:
  6937. _iteratorNormalCompletion = true;
  6938. _context.next = 4;
  6939. break;
  6940. case 42:
  6941. _context.next = 48;
  6942. break;
  6943. case 44:
  6944. _context.prev = 44;
  6945. _context.t1 = _context["catch"](2);
  6946. _didIteratorError = true;
  6947. _iteratorError = _context.t1;
  6948. case 48:
  6949. _context.prev = 48;
  6950. _context.prev = 49;
  6951. if (!(!_iteratorNormalCompletion && _iterator.return != null)) {
  6952. _context.next = 53;
  6953. break;
  6954. }
  6955. _context.next = 53;
  6956. return _iterator.return();
  6957. case 53:
  6958. _context.prev = 53;
  6959. if (!_didIteratorError) {
  6960. _context.next = 56;
  6961. break;
  6962. }
  6963. throw _iteratorError;
  6964. case 56:
  6965. return _context.finish(53);
  6966. case 57:
  6967. return _context.finish(48);
  6968. case 58:
  6969. return _context.abrupt("return", this.model);
  6970. case 59:
  6971. case "end":
  6972. return _context.stop();
  6973. }
  6974. }
  6975. }, _callee, this, [[2, 44, 48, 58], [14, 33, 36, 39], [49,, 53, 57]]);
  6976. }));
  6977. function parse(_x) {
  6978. return _parse.apply(this, arguments);
  6979. }
  6980. return parse;
  6981. }()
  6982. }, {
  6983. key: "parseStream",
  6984. value: function () {
  6985. var _parseStream = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(stream) {
  6986. return regeneratorRuntime.wrap(function _callee2$(_context2) {
  6987. while (1) {
  6988. switch (_context2.prev = _context2.next) {
  6989. case 0:
  6990. return _context2.abrupt("return", this.parse(parseSax(stream)));
  6991. case 1:
  6992. case "end":
  6993. return _context2.stop();
  6994. }
  6995. }
  6996. }, _callee2, this);
  6997. }));
  6998. function parseStream(_x2) {
  6999. return _parseStream.apply(this, arguments);
  7000. }
  7001. return parseStream;
  7002. }()
  7003. }, {
  7004. key: "toXml",
  7005. value: function toXml(model) {
  7006. var xmlStream = new XmlStream();
  7007. this.render(xmlStream, model);
  7008. return xmlStream.xml;
  7009. } // ============================================================
  7010. // Useful Utilities
  7011. }, {
  7012. key: "xml",
  7013. get: function get() {
  7014. // convenience function to get the xml of this.model
  7015. // useful for manager types that are built during the prepare phase
  7016. return this.toXml(this.model);
  7017. }
  7018. }], [{
  7019. key: "toAttribute",
  7020. value: function toAttribute(value, dflt) {
  7021. var always = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  7022. if (value === undefined) {
  7023. if (always) {
  7024. return dflt;
  7025. }
  7026. } else if (always || value !== dflt) {
  7027. return value.toString();
  7028. }
  7029. return undefined;
  7030. }
  7031. }, {
  7032. key: "toStringAttribute",
  7033. value: function toStringAttribute(value, dflt) {
  7034. var always = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  7035. return BaseXform.toAttribute(value, dflt, always);
  7036. }
  7037. }, {
  7038. key: "toStringValue",
  7039. value: function toStringValue(attr, dflt) {
  7040. return attr === undefined ? dflt : attr;
  7041. }
  7042. }, {
  7043. key: "toBoolAttribute",
  7044. value: function toBoolAttribute(value, dflt) {
  7045. var always = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  7046. if (value === undefined) {
  7047. if (always) {
  7048. return dflt;
  7049. }
  7050. } else if (always || value !== dflt) {
  7051. return value ? '1' : '0';
  7052. }
  7053. return undefined;
  7054. }
  7055. }, {
  7056. key: "toBoolValue",
  7057. value: function toBoolValue(attr, dflt) {
  7058. return attr === undefined ? dflt : attr === '1';
  7059. }
  7060. }, {
  7061. key: "toIntAttribute",
  7062. value: function toIntAttribute(value, dflt) {
  7063. var always = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  7064. return BaseXform.toAttribute(value, dflt, always);
  7065. }
  7066. }, {
  7067. key: "toIntValue",
  7068. value: function toIntValue(attr, dflt) {
  7069. return attr === undefined ? dflt : parseInt(attr, 10);
  7070. }
  7071. }, {
  7072. key: "toFloatAttribute",
  7073. value: function toFloatAttribute(value, dflt) {
  7074. var always = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  7075. return BaseXform.toAttribute(value, dflt, always);
  7076. }
  7077. }, {
  7078. key: "toFloatValue",
  7079. value: function toFloatValue(attr, dflt) {
  7080. return attr === undefined ? dflt : parseFloat(attr);
  7081. }
  7082. }]);
  7083. return BaseXform;
  7084. }();
  7085. module.exports = BaseXform;
  7086. },{"../../utils/parse-sax":21,"../../utils/xml-stream":27}],32:[function(require,module,exports){
  7087. "use strict";
  7088. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  7089. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7090. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  7091. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7092. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  7093. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  7094. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  7095. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  7096. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  7097. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  7098. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  7099. var BaseXform = require('../base-xform');
  7100. var colCache = require('../../../utils/col-cache');
  7101. var DefinedNamesXform = /*#__PURE__*/function (_BaseXform) {
  7102. _inherits(DefinedNamesXform, _BaseXform);
  7103. var _super = _createSuper(DefinedNamesXform);
  7104. function DefinedNamesXform() {
  7105. _classCallCheck(this, DefinedNamesXform);
  7106. return _super.apply(this, arguments);
  7107. }
  7108. _createClass(DefinedNamesXform, [{
  7109. key: "render",
  7110. value: function render(xmlStream, model) {
  7111. // <definedNames>
  7112. // <definedName name="name">name.ranges.join(',')</definedName>
  7113. // <definedName name="_xlnm.Print_Area" localSheetId="0">name.ranges.join(',')</definedName>
  7114. // </definedNames>
  7115. xmlStream.openNode('definedName', {
  7116. name: model.name,
  7117. localSheetId: model.localSheetId
  7118. });
  7119. xmlStream.writeText(model.ranges.join(','));
  7120. xmlStream.closeNode();
  7121. }
  7122. }, {
  7123. key: "parseOpen",
  7124. value: function parseOpen(node) {
  7125. switch (node.name) {
  7126. case 'definedName':
  7127. this._parsedName = node.attributes.name;
  7128. this._parsedLocalSheetId = node.attributes.localSheetId;
  7129. this._parsedText = [];
  7130. return true;
  7131. default:
  7132. return false;
  7133. }
  7134. }
  7135. }, {
  7136. key: "parseText",
  7137. value: function parseText(text) {
  7138. this._parsedText.push(text);
  7139. }
  7140. }, {
  7141. key: "parseClose",
  7142. value: function parseClose() {
  7143. this.model = {
  7144. name: this._parsedName,
  7145. ranges: extractRanges(this._parsedText.join(''))
  7146. };
  7147. if (this._parsedLocalSheetId !== undefined) {
  7148. this.model.localSheetId = parseInt(this._parsedLocalSheetId, 10);
  7149. }
  7150. return false;
  7151. }
  7152. }]);
  7153. return DefinedNamesXform;
  7154. }(BaseXform);
  7155. function isValidRange(range) {
  7156. try {
  7157. colCache.decodeEx(range);
  7158. return true;
  7159. } catch (err) {
  7160. return false;
  7161. }
  7162. }
  7163. function extractRanges(parsedText) {
  7164. var ranges = [];
  7165. var quotesOpened = false;
  7166. var last = '';
  7167. parsedText.split(',').forEach(function (item) {
  7168. if (!item) {
  7169. return;
  7170. }
  7171. var quotes = (item.match(/'/g) || []).length;
  7172. if (!quotes) {
  7173. if (quotesOpened) {
  7174. last += "".concat(item, ",");
  7175. } else if (isValidRange(item)) {
  7176. ranges.push(item);
  7177. }
  7178. return;
  7179. }
  7180. var quotesEven = quotes % 2 === 0;
  7181. if (!quotesOpened && quotesEven && isValidRange(item)) {
  7182. ranges.push(item);
  7183. } else if (quotesOpened && !quotesEven) {
  7184. quotesOpened = false;
  7185. if (isValidRange(last + item)) {
  7186. ranges.push(last + item);
  7187. }
  7188. last = '';
  7189. } else {
  7190. quotesOpened = true;
  7191. last += "".concat(item, ",");
  7192. }
  7193. });
  7194. return ranges;
  7195. }
  7196. module.exports = DefinedNamesXform;
  7197. },{"../../../utils/col-cache":19,"../base-xform":31}],33:[function(require,module,exports){
  7198. "use strict";
  7199. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  7200. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7201. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  7202. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7203. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  7204. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  7205. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  7206. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  7207. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  7208. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  7209. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  7210. var utils = require('../../../utils/utils');
  7211. var BaseXform = require('../base-xform');
  7212. var WorksheetXform = /*#__PURE__*/function (_BaseXform) {
  7213. _inherits(WorksheetXform, _BaseXform);
  7214. var _super = _createSuper(WorksheetXform);
  7215. function WorksheetXform() {
  7216. _classCallCheck(this, WorksheetXform);
  7217. return _super.apply(this, arguments);
  7218. }
  7219. _createClass(WorksheetXform, [{
  7220. key: "render",
  7221. value: function render(xmlStream, model) {
  7222. xmlStream.leafNode('sheet', {
  7223. sheetId: model.id,
  7224. name: model.name,
  7225. state: model.state,
  7226. 'r:id': model.rId
  7227. });
  7228. }
  7229. }, {
  7230. key: "parseOpen",
  7231. value: function parseOpen(node) {
  7232. if (node.name === 'sheet') {
  7233. this.model = {
  7234. name: utils.xmlDecode(node.attributes.name),
  7235. id: parseInt(node.attributes.sheetId, 10),
  7236. state: node.attributes.state,
  7237. rId: node.attributes['r:id']
  7238. };
  7239. return true;
  7240. }
  7241. return false;
  7242. }
  7243. }, {
  7244. key: "parseText",
  7245. value: function parseText() {}
  7246. }, {
  7247. key: "parseClose",
  7248. value: function parseClose() {
  7249. return false;
  7250. }
  7251. }]);
  7252. return WorksheetXform;
  7253. }(BaseXform);
  7254. module.exports = WorksheetXform;
  7255. },{"../../../utils/utils":26,"../base-xform":31}],34:[function(require,module,exports){
  7256. "use strict";
  7257. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  7258. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7259. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  7260. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7261. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  7262. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  7263. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  7264. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  7265. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  7266. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  7267. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  7268. var BaseXform = require('../base-xform');
  7269. var WorkbookCalcPropertiesXform = /*#__PURE__*/function (_BaseXform) {
  7270. _inherits(WorkbookCalcPropertiesXform, _BaseXform);
  7271. var _super = _createSuper(WorkbookCalcPropertiesXform);
  7272. function WorkbookCalcPropertiesXform() {
  7273. _classCallCheck(this, WorkbookCalcPropertiesXform);
  7274. return _super.apply(this, arguments);
  7275. }
  7276. _createClass(WorkbookCalcPropertiesXform, [{
  7277. key: "render",
  7278. value: function render(xmlStream, model) {
  7279. xmlStream.leafNode('calcPr', {
  7280. calcId: 171027,
  7281. fullCalcOnLoad: model.fullCalcOnLoad ? 1 : undefined
  7282. });
  7283. }
  7284. }, {
  7285. key: "parseOpen",
  7286. value: function parseOpen(node) {
  7287. if (node.name === 'calcPr') {
  7288. this.model = {};
  7289. return true;
  7290. }
  7291. return false;
  7292. }
  7293. }, {
  7294. key: "parseText",
  7295. value: function parseText() {}
  7296. }, {
  7297. key: "parseClose",
  7298. value: function parseClose() {
  7299. return false;
  7300. }
  7301. }]);
  7302. return WorkbookCalcPropertiesXform;
  7303. }(BaseXform);
  7304. module.exports = WorkbookCalcPropertiesXform;
  7305. },{"../base-xform":31}],35:[function(require,module,exports){
  7306. "use strict";
  7307. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  7308. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7309. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  7310. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7311. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  7312. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  7313. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  7314. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  7315. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  7316. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  7317. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  7318. var BaseXform = require('../base-xform');
  7319. var WorksheetPropertiesXform = /*#__PURE__*/function (_BaseXform) {
  7320. _inherits(WorksheetPropertiesXform, _BaseXform);
  7321. var _super = _createSuper(WorksheetPropertiesXform);
  7322. function WorksheetPropertiesXform() {
  7323. _classCallCheck(this, WorksheetPropertiesXform);
  7324. return _super.apply(this, arguments);
  7325. }
  7326. _createClass(WorksheetPropertiesXform, [{
  7327. key: "render",
  7328. value: function render(xmlStream, model) {
  7329. xmlStream.leafNode('workbookPr', {
  7330. date1904: model.date1904 ? 1 : undefined,
  7331. defaultThemeVersion: 164011,
  7332. filterPrivacy: 1
  7333. });
  7334. }
  7335. }, {
  7336. key: "parseOpen",
  7337. value: function parseOpen(node) {
  7338. if (node.name === 'workbookPr') {
  7339. this.model = {
  7340. date1904: node.attributes.date1904 === '1'
  7341. };
  7342. return true;
  7343. }
  7344. return false;
  7345. }
  7346. }, {
  7347. key: "parseText",
  7348. value: function parseText() {}
  7349. }, {
  7350. key: "parseClose",
  7351. value: function parseClose() {
  7352. return false;
  7353. }
  7354. }]);
  7355. return WorksheetPropertiesXform;
  7356. }(BaseXform);
  7357. module.exports = WorksheetPropertiesXform;
  7358. },{"../base-xform":31}],36:[function(require,module,exports){
  7359. "use strict";
  7360. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  7361. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7362. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  7363. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7364. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  7365. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  7366. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  7367. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  7368. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  7369. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  7370. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  7371. var BaseXform = require('../base-xform');
  7372. var WorkbookViewXform = /*#__PURE__*/function (_BaseXform) {
  7373. _inherits(WorkbookViewXform, _BaseXform);
  7374. var _super = _createSuper(WorkbookViewXform);
  7375. function WorkbookViewXform() {
  7376. _classCallCheck(this, WorkbookViewXform);
  7377. return _super.apply(this, arguments);
  7378. }
  7379. _createClass(WorkbookViewXform, [{
  7380. key: "render",
  7381. value: function render(xmlStream, model) {
  7382. var attributes = {
  7383. xWindow: model.x || 0,
  7384. yWindow: model.y || 0,
  7385. windowWidth: model.width || 12000,
  7386. windowHeight: model.height || 24000,
  7387. firstSheet: model.firstSheet,
  7388. activeTab: model.activeTab
  7389. };
  7390. if (model.visibility && model.visibility !== 'visible') {
  7391. attributes.visibility = model.visibility;
  7392. }
  7393. xmlStream.leafNode('workbookView', attributes);
  7394. }
  7395. }, {
  7396. key: "parseOpen",
  7397. value: function parseOpen(node) {
  7398. if (node.name === 'workbookView') {
  7399. var model = this.model = {};
  7400. var addS = function addS(name, value, dflt) {
  7401. var s = value !== undefined ? model[name] = value : dflt;
  7402. if (s !== undefined) {
  7403. model[name] = s;
  7404. }
  7405. };
  7406. var addN = function addN(name, value, dflt) {
  7407. var n = value !== undefined ? model[name] = parseInt(value, 10) : dflt;
  7408. if (n !== undefined) {
  7409. model[name] = n;
  7410. }
  7411. };
  7412. addN('x', node.attributes.xWindow, 0);
  7413. addN('y', node.attributes.yWindow, 0);
  7414. addN('width', node.attributes.windowWidth, 25000);
  7415. addN('height', node.attributes.windowHeight, 10000);
  7416. addS('visibility', node.attributes.visibility, 'visible');
  7417. addN('activeTab', node.attributes.activeTab, undefined);
  7418. addN('firstSheet', node.attributes.firstSheet, undefined);
  7419. return true;
  7420. }
  7421. return false;
  7422. }
  7423. }, {
  7424. key: "parseText",
  7425. value: function parseText() {}
  7426. }, {
  7427. key: "parseClose",
  7428. value: function parseClose() {
  7429. return false;
  7430. }
  7431. }]);
  7432. return WorkbookViewXform;
  7433. }(BaseXform);
  7434. module.exports = WorkbookViewXform;
  7435. },{"../base-xform":31}],37:[function(require,module,exports){
  7436. "use strict";
  7437. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  7438. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7439. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  7440. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7441. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  7442. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  7443. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  7444. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  7445. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  7446. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  7447. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  7448. var _ = require('../../../utils/under-dash');
  7449. var colCache = require('../../../utils/col-cache');
  7450. var XmlStream = require('../../../utils/xml-stream');
  7451. var BaseXform = require('../base-xform');
  7452. var StaticXform = require('../static-xform');
  7453. var ListXform = require('../list-xform');
  7454. var DefinedNameXform = require('./defined-name-xform');
  7455. var SheetXform = require('./sheet-xform');
  7456. var WorkbookViewXform = require('./workbook-view-xform');
  7457. var WorkbookPropertiesXform = require('./workbook-properties-xform');
  7458. var WorkbookCalcPropertiesXform = require('./workbook-calc-properties-xform');
  7459. var WorkbookXform = /*#__PURE__*/function (_BaseXform) {
  7460. _inherits(WorkbookXform, _BaseXform);
  7461. var _super = _createSuper(WorkbookXform);
  7462. function WorkbookXform() {
  7463. var _this;
  7464. _classCallCheck(this, WorkbookXform);
  7465. _this = _super.call(this);
  7466. _this.map = {
  7467. fileVersion: WorkbookXform.STATIC_XFORMS.fileVersion,
  7468. workbookPr: new WorkbookPropertiesXform(),
  7469. bookViews: new ListXform({
  7470. tag: 'bookViews',
  7471. count: false,
  7472. childXform: new WorkbookViewXform()
  7473. }),
  7474. sheets: new ListXform({
  7475. tag: 'sheets',
  7476. count: false,
  7477. childXform: new SheetXform()
  7478. }),
  7479. definedNames: new ListXform({
  7480. tag: 'definedNames',
  7481. count: false,
  7482. childXform: new DefinedNameXform()
  7483. }),
  7484. calcPr: new WorkbookCalcPropertiesXform()
  7485. };
  7486. return _this;
  7487. }
  7488. _createClass(WorkbookXform, [{
  7489. key: "prepare",
  7490. value: function prepare(model) {
  7491. model.sheets = model.worksheets; // collate all the print areas from all of the sheets and add them to the defined names
  7492. var printAreas = [];
  7493. var index = 0; // sheets is sparse array - calc index manually
  7494. model.sheets.forEach(function (sheet) {
  7495. if (sheet.pageSetup && sheet.pageSetup.printArea) {
  7496. sheet.pageSetup.printArea.split('&&').forEach(function (printArea) {
  7497. var printAreaComponents = printArea.split(':');
  7498. var definedName = {
  7499. name: '_xlnm.Print_Area',
  7500. ranges: ["'".concat(sheet.name, "'!$").concat(printAreaComponents[0], ":$").concat(printAreaComponents[1])],
  7501. localSheetId: index
  7502. };
  7503. printAreas.push(definedName);
  7504. });
  7505. }
  7506. if (sheet.pageSetup && (sheet.pageSetup.printTitlesRow || sheet.pageSetup.printTitlesColumn)) {
  7507. var ranges = [];
  7508. if (sheet.pageSetup.printTitlesColumn) {
  7509. var titlesColumns = sheet.pageSetup.printTitlesColumn.split(':');
  7510. ranges.push("'".concat(sheet.name, "'!$").concat(titlesColumns[0], ":$").concat(titlesColumns[1]));
  7511. }
  7512. if (sheet.pageSetup.printTitlesRow) {
  7513. var titlesRows = sheet.pageSetup.printTitlesRow.split(':');
  7514. ranges.push("'".concat(sheet.name, "'!$").concat(titlesRows[0], ":$").concat(titlesRows[1]));
  7515. }
  7516. var definedName = {
  7517. name: '_xlnm.Print_Titles',
  7518. ranges: ranges,
  7519. localSheetId: index
  7520. };
  7521. printAreas.push(definedName);
  7522. }
  7523. index++;
  7524. });
  7525. if (printAreas.length) {
  7526. model.definedNames = model.definedNames.concat(printAreas);
  7527. }
  7528. (model.media || []).forEach(function (medium, i) {
  7529. // assign name
  7530. medium.name = medium.type + (i + 1);
  7531. });
  7532. }
  7533. }, {
  7534. key: "render",
  7535. value: function render(xmlStream, model) {
  7536. xmlStream.openXml(XmlStream.StdDocAttributes);
  7537. xmlStream.openNode('workbook', WorkbookXform.WORKBOOK_ATTRIBUTES);
  7538. this.map.fileVersion.render(xmlStream);
  7539. this.map.workbookPr.render(xmlStream, model.properties);
  7540. this.map.bookViews.render(xmlStream, model.views);
  7541. this.map.sheets.render(xmlStream, model.sheets);
  7542. this.map.definedNames.render(xmlStream, model.definedNames);
  7543. this.map.calcPr.render(xmlStream, model.calcProperties);
  7544. xmlStream.closeNode();
  7545. }
  7546. }, {
  7547. key: "parseOpen",
  7548. value: function parseOpen(node) {
  7549. if (this.parser) {
  7550. this.parser.parseOpen(node);
  7551. return true;
  7552. }
  7553. switch (node.name) {
  7554. case 'workbook':
  7555. return true;
  7556. default:
  7557. this.parser = this.map[node.name];
  7558. if (this.parser) {
  7559. this.parser.parseOpen(node);
  7560. }
  7561. return true;
  7562. }
  7563. }
  7564. }, {
  7565. key: "parseText",
  7566. value: function parseText(text) {
  7567. if (this.parser) {
  7568. this.parser.parseText(text);
  7569. }
  7570. }
  7571. }, {
  7572. key: "parseClose",
  7573. value: function parseClose(name) {
  7574. if (this.parser) {
  7575. if (!this.parser.parseClose(name)) {
  7576. this.parser = undefined;
  7577. }
  7578. return true;
  7579. }
  7580. switch (name) {
  7581. case 'workbook':
  7582. this.model = {
  7583. sheets: this.map.sheets.model,
  7584. properties: this.map.workbookPr.model || {},
  7585. views: this.map.bookViews.model,
  7586. calcProperties: {}
  7587. };
  7588. if (this.map.definedNames.model) {
  7589. this.model.definedNames = this.map.definedNames.model;
  7590. }
  7591. return false;
  7592. default:
  7593. // not quite sure how we get here!
  7594. return true;
  7595. }
  7596. }
  7597. }, {
  7598. key: "reconcile",
  7599. value: function reconcile(model) {
  7600. var rels = (model.workbookRels || []).reduce(function (map, rel) {
  7601. map[rel.Id] = rel;
  7602. return map;
  7603. }, {}); // reconcile sheet ids, rIds and names
  7604. var worksheets = [];
  7605. var worksheet;
  7606. var index = 0;
  7607. (model.sheets || []).forEach(function (sheet) {
  7608. var rel = rels[sheet.rId];
  7609. if (!rel) {
  7610. return;
  7611. } // if rel.Target start with `[space]/xl/` or `/xl/` , then it will be replaced with `''` and spliced behind `xl/`,
  7612. // otherwise it will be spliced directly behind `xl/`. i.g.
  7613. worksheet = model.worksheetHash["xl/".concat(rel.Target.replace(/^(\s|\/xl\/)+/, ''))]; // If there are "chartsheets" in the file, rel.Target will
  7614. // come out as chartsheets/sheet1.xml or similar here, and
  7615. // that won't be in model.worksheetHash.
  7616. // As we don't have the infrastructure to support chartsheets,
  7617. // we will ignore them for now:
  7618. if (worksheet) {
  7619. worksheet.name = sheet.name;
  7620. worksheet.id = sheet.id;
  7621. worksheet.state = sheet.state;
  7622. worksheets[index++] = worksheet;
  7623. }
  7624. }); // reconcile print areas
  7625. var definedNames = [];
  7626. _.each(model.definedNames, function (definedName) {
  7627. if (definedName.name === '_xlnm.Print_Area') {
  7628. worksheet = worksheets[definedName.localSheetId];
  7629. if (worksheet) {
  7630. if (!worksheet.pageSetup) {
  7631. worksheet.pageSetup = {};
  7632. }
  7633. var range = colCache.decodeEx(definedName.ranges[0]);
  7634. worksheet.pageSetup.printArea = worksheet.pageSetup.printArea ? "".concat(worksheet.pageSetup.printArea, "&&").concat(range.dimensions) : range.dimensions;
  7635. }
  7636. } else if (definedName.name === '_xlnm.Print_Titles') {
  7637. worksheet = worksheets[definedName.localSheetId];
  7638. if (worksheet) {
  7639. if (!worksheet.pageSetup) {
  7640. worksheet.pageSetup = {};
  7641. }
  7642. var rangeString = definedName.ranges.join(',');
  7643. var dollarRegex = /\$/g;
  7644. var rowRangeRegex = /\$\d+:\$\d+/;
  7645. var rowRangeMatches = rangeString.match(rowRangeRegex);
  7646. if (rowRangeMatches && rowRangeMatches.length) {
  7647. var _range = rowRangeMatches[0];
  7648. worksheet.pageSetup.printTitlesRow = _range.replace(dollarRegex, '');
  7649. }
  7650. var columnRangeRegex = /\$[A-Z]+:\$[A-Z]+/;
  7651. var columnRangeMatches = rangeString.match(columnRangeRegex);
  7652. if (columnRangeMatches && columnRangeMatches.length) {
  7653. var _range2 = columnRangeMatches[0];
  7654. worksheet.pageSetup.printTitlesColumn = _range2.replace(dollarRegex, '');
  7655. }
  7656. }
  7657. } else {
  7658. definedNames.push(definedName);
  7659. }
  7660. });
  7661. model.definedNames = definedNames; // used by sheets to build their image models
  7662. model.media.forEach(function (media, i) {
  7663. media.index = i;
  7664. });
  7665. }
  7666. }]);
  7667. return WorkbookXform;
  7668. }(BaseXform);
  7669. WorkbookXform.WORKBOOK_ATTRIBUTES = {
  7670. xmlns: 'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
  7671. 'xmlns:r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
  7672. 'xmlns:mc': 'http://schemas.openxmlformats.org/markup-compatibility/2006',
  7673. 'mc:Ignorable': 'x15',
  7674. 'xmlns:x15': 'http://schemas.microsoft.com/office/spreadsheetml/2010/11/main'
  7675. };
  7676. WorkbookXform.STATIC_XFORMS = {
  7677. fileVersion: new StaticXform({
  7678. tag: 'fileVersion',
  7679. $: {
  7680. appName: 'xl',
  7681. lastEdited: 5,
  7682. lowestEdited: 5,
  7683. rupBuild: 9303
  7684. }
  7685. })
  7686. };
  7687. module.exports = WorkbookXform;
  7688. },{"../../../utils/col-cache":19,"../../../utils/under-dash":25,"../../../utils/xml-stream":27,"../base-xform":31,"../list-xform":70,"../static-xform":119,"./defined-name-xform":32,"./sheet-xform":33,"./workbook-calc-properties-xform":34,"./workbook-properties-xform":35,"./workbook-view-xform":36}],38:[function(require,module,exports){
  7689. "use strict";
  7690. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  7691. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  7692. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  7693. var RichTextXform = require('../strings/rich-text-xform');
  7694. var utils = require('../../../utils/utils');
  7695. var BaseXform = require('../base-xform');
  7696. /**
  7697. <comment ref="B1" authorId="0">
  7698. <text>
  7699. <r>
  7700. <rPr>
  7701. <b/>
  7702. <sz val="9"/>
  7703. <rFont val="宋体"/>
  7704. <charset val="134"/>
  7705. </rPr>
  7706. <t>51422:</t>
  7707. </r>
  7708. <r>
  7709. <rPr>
  7710. <sz val="9"/>
  7711. <rFont val="宋体"/>
  7712. <charset val="134"/>
  7713. </rPr>
  7714. <t xml:space="preserve">&#10;test</t>
  7715. </r>
  7716. </text>
  7717. </comment>
  7718. */
  7719. var CommentXform = module.exports = function (model) {
  7720. this.model = model;
  7721. };
  7722. utils.inherits(CommentXform, BaseXform, {
  7723. get tag() {
  7724. return 'r';
  7725. },
  7726. get richTextXform() {
  7727. if (!this._richTextXform) {
  7728. this._richTextXform = new RichTextXform();
  7729. }
  7730. return this._richTextXform;
  7731. },
  7732. render: function render(xmlStream, model) {
  7733. var _this = this;
  7734. model = model || this.model;
  7735. xmlStream.openNode('comment', {
  7736. ref: model.ref,
  7737. authorId: 0
  7738. });
  7739. xmlStream.openNode('text');
  7740. if (model && model.note && model.note.texts) {
  7741. model.note.texts.forEach(function (text) {
  7742. _this.richTextXform.render(xmlStream, text);
  7743. });
  7744. }
  7745. xmlStream.closeNode();
  7746. xmlStream.closeNode();
  7747. },
  7748. parseOpen: function parseOpen(node) {
  7749. if (this.parser) {
  7750. this.parser.parseOpen(node);
  7751. return true;
  7752. }
  7753. switch (node.name) {
  7754. case 'comment':
  7755. this.model = _objectSpread({
  7756. type: 'note',
  7757. note: {
  7758. texts: []
  7759. }
  7760. }, node.attributes);
  7761. return true;
  7762. case 'r':
  7763. this.parser = this.richTextXform;
  7764. this.parser.parseOpen(node);
  7765. return true;
  7766. default:
  7767. return false;
  7768. }
  7769. },
  7770. parseText: function parseText(text) {
  7771. if (this.parser) {
  7772. this.parser.parseText(text);
  7773. }
  7774. },
  7775. parseClose: function parseClose(name) {
  7776. switch (name) {
  7777. case 'comment':
  7778. return false;
  7779. case 'r':
  7780. this.model.note.texts.push(this.parser.model);
  7781. this.parser = undefined;
  7782. return true;
  7783. default:
  7784. if (this.parser) {
  7785. this.parser.parseClose(name);
  7786. }
  7787. return true;
  7788. }
  7789. }
  7790. });
  7791. },{"../../../utils/utils":26,"../base-xform":31,"../strings/rich-text-xform":121}],39:[function(require,module,exports){
  7792. "use strict";
  7793. var XmlStream = require('../../../utils/xml-stream');
  7794. var utils = require('../../../utils/utils');
  7795. var BaseXform = require('../base-xform');
  7796. var CommentXform = require('./comment-xform');
  7797. var CommentsXform = module.exports = function () {
  7798. this.map = {
  7799. comment: new CommentXform()
  7800. };
  7801. };
  7802. utils.inherits(CommentsXform, BaseXform, {
  7803. COMMENTS_ATTRIBUTES: {
  7804. xmlns: 'http://schemas.openxmlformats.org/spreadsheetml/2006/main'
  7805. }
  7806. }, {
  7807. render: function render(xmlStream, model) {
  7808. var _this = this;
  7809. model = model || this.model;
  7810. xmlStream.openXml(XmlStream.StdDocAttributes);
  7811. xmlStream.openNode('comments', CommentsXform.COMMENTS_ATTRIBUTES); // authors
  7812. // TODO: support authors properly
  7813. xmlStream.openNode('authors');
  7814. xmlStream.leafNode('author', null, 'Author');
  7815. xmlStream.closeNode(); // comments
  7816. xmlStream.openNode('commentList');
  7817. model.comments.forEach(function (comment) {
  7818. _this.map.comment.render(xmlStream, comment);
  7819. });
  7820. xmlStream.closeNode();
  7821. xmlStream.closeNode();
  7822. },
  7823. parseOpen: function parseOpen(node) {
  7824. if (this.parser) {
  7825. this.parser.parseOpen(node);
  7826. return true;
  7827. }
  7828. switch (node.name) {
  7829. case 'commentList':
  7830. this.model = {
  7831. comments: []
  7832. };
  7833. return true;
  7834. case 'comment':
  7835. this.parser = this.map.comment;
  7836. this.parser.parseOpen(node);
  7837. return true;
  7838. default:
  7839. return false;
  7840. }
  7841. },
  7842. parseText: function parseText(text) {
  7843. if (this.parser) {
  7844. this.parser.parseText(text);
  7845. }
  7846. },
  7847. parseClose: function parseClose(name) {
  7848. switch (name) {
  7849. case 'commentList':
  7850. return false;
  7851. case 'comment':
  7852. this.model.comments.push(this.parser.model);
  7853. this.parser = undefined;
  7854. return true;
  7855. default:
  7856. if (this.parser) {
  7857. this.parser.parseClose(name);
  7858. }
  7859. return true;
  7860. }
  7861. }
  7862. });
  7863. },{"../../../utils/utils":26,"../../../utils/xml-stream":27,"../base-xform":31,"./comment-xform":38}],40:[function(require,module,exports){
  7864. "use strict";
  7865. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  7866. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7867. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  7868. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7869. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  7870. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  7871. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  7872. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  7873. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  7874. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  7875. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  7876. var BaseXform = require('../../base-xform');
  7877. var VmlPositionXform = /*#__PURE__*/function (_BaseXform) {
  7878. _inherits(VmlPositionXform, _BaseXform);
  7879. var _super = _createSuper(VmlPositionXform);
  7880. function VmlPositionXform(model) {
  7881. var _this;
  7882. _classCallCheck(this, VmlPositionXform);
  7883. _this = _super.call(this);
  7884. _this._model = model;
  7885. return _this;
  7886. }
  7887. _createClass(VmlPositionXform, [{
  7888. key: "render",
  7889. value: function render(xmlStream, model, type) {
  7890. if (model === type[2]) {
  7891. xmlStream.leafNode(this.tag);
  7892. } else if (this.tag === 'x:SizeWithCells' && model === type[1]) {
  7893. xmlStream.leafNode(this.tag);
  7894. }
  7895. }
  7896. }, {
  7897. key: "parseOpen",
  7898. value: function parseOpen(node) {
  7899. switch (node.name) {
  7900. case this.tag:
  7901. this.model = {};
  7902. this.model[this.tag] = true;
  7903. return true;
  7904. default:
  7905. return false;
  7906. }
  7907. }
  7908. }, {
  7909. key: "parseText",
  7910. value: function parseText() {}
  7911. }, {
  7912. key: "parseClose",
  7913. value: function parseClose() {
  7914. return false;
  7915. }
  7916. }, {
  7917. key: "tag",
  7918. get: function get() {
  7919. return this._model && this._model.tag;
  7920. }
  7921. }]);
  7922. return VmlPositionXform;
  7923. }(BaseXform);
  7924. module.exports = VmlPositionXform;
  7925. },{"../../base-xform":31}],41:[function(require,module,exports){
  7926. "use strict";
  7927. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  7928. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7929. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  7930. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7931. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  7932. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  7933. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  7934. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  7935. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  7936. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  7937. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  7938. var BaseXform = require('../../base-xform');
  7939. var VmlProtectionXform = /*#__PURE__*/function (_BaseXform) {
  7940. _inherits(VmlProtectionXform, _BaseXform);
  7941. var _super = _createSuper(VmlProtectionXform);
  7942. function VmlProtectionXform(model) {
  7943. var _this;
  7944. _classCallCheck(this, VmlProtectionXform);
  7945. _this = _super.call(this);
  7946. _this._model = model;
  7947. return _this;
  7948. }
  7949. _createClass(VmlProtectionXform, [{
  7950. key: "render",
  7951. value: function render(xmlStream, model) {
  7952. xmlStream.leafNode(this.tag, null, model);
  7953. }
  7954. }, {
  7955. key: "parseOpen",
  7956. value: function parseOpen(node) {
  7957. switch (node.name) {
  7958. case this.tag:
  7959. this.text = '';
  7960. return true;
  7961. default:
  7962. return false;
  7963. }
  7964. }
  7965. }, {
  7966. key: "parseText",
  7967. value: function parseText(text) {
  7968. this.text = text;
  7969. }
  7970. }, {
  7971. key: "parseClose",
  7972. value: function parseClose() {
  7973. return false;
  7974. }
  7975. }, {
  7976. key: "tag",
  7977. get: function get() {
  7978. return this._model && this._model.tag;
  7979. }
  7980. }]);
  7981. return VmlProtectionXform;
  7982. }(BaseXform);
  7983. module.exports = VmlProtectionXform;
  7984. },{"../../base-xform":31}],42:[function(require,module,exports){
  7985. "use strict";
  7986. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  7987. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7988. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  7989. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7990. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  7991. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  7992. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  7993. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  7994. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  7995. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  7996. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  7997. var BaseXform = require('../base-xform'); // render the triangle in the cell for the comment
  7998. var VmlAnchorXform = /*#__PURE__*/function (_BaseXform) {
  7999. _inherits(VmlAnchorXform, _BaseXform);
  8000. var _super = _createSuper(VmlAnchorXform);
  8001. function VmlAnchorXform() {
  8002. _classCallCheck(this, VmlAnchorXform);
  8003. return _super.apply(this, arguments);
  8004. }
  8005. _createClass(VmlAnchorXform, [{
  8006. key: "getAnchorRect",
  8007. value: function getAnchorRect(anchor) {
  8008. var l = Math.floor(anchor.left);
  8009. var lf = Math.floor((anchor.left - l) * 68);
  8010. var t = Math.floor(anchor.top);
  8011. var tf = Math.floor((anchor.top - t) * 18);
  8012. var r = Math.floor(anchor.right);
  8013. var rf = Math.floor((anchor.right - r) * 68);
  8014. var b = Math.floor(anchor.bottom);
  8015. var bf = Math.floor((anchor.bottom - b) * 18);
  8016. return [l, lf, t, tf, r, rf, b, bf];
  8017. }
  8018. }, {
  8019. key: "getDefaultRect",
  8020. value: function getDefaultRect(ref) {
  8021. var l = ref.col;
  8022. var lf = 6;
  8023. var t = Math.max(ref.row - 2, 0);
  8024. var tf = 14;
  8025. var r = l + 2;
  8026. var rf = 2;
  8027. var b = t + 4;
  8028. var bf = 16;
  8029. return [l, lf, t, tf, r, rf, b, bf];
  8030. }
  8031. }, {
  8032. key: "render",
  8033. value: function render(xmlStream, model) {
  8034. var rect = model.anchor ? this.getAnchorRect(model.anchor) : this.getDefaultRect(model.refAddress);
  8035. xmlStream.leafNode('x:Anchor', null, rect.join(', '));
  8036. }
  8037. }, {
  8038. key: "parseOpen",
  8039. value: function parseOpen(node) {
  8040. switch (node.name) {
  8041. case this.tag:
  8042. this.text = '';
  8043. return true;
  8044. default:
  8045. return false;
  8046. }
  8047. }
  8048. }, {
  8049. key: "parseText",
  8050. value: function parseText(text) {
  8051. this.text = text;
  8052. }
  8053. }, {
  8054. key: "parseClose",
  8055. value: function parseClose() {
  8056. return false;
  8057. }
  8058. }, {
  8059. key: "tag",
  8060. get: function get() {
  8061. return 'x:Anchor';
  8062. }
  8063. }]);
  8064. return VmlAnchorXform;
  8065. }(BaseXform);
  8066. module.exports = VmlAnchorXform;
  8067. },{"../base-xform":31}],43:[function(require,module,exports){
  8068. "use strict";
  8069. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  8070. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8071. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  8072. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8073. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  8074. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8075. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  8076. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  8077. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8078. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  8079. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8080. var BaseXform = require('../base-xform');
  8081. var VmlAnchorXform = require('./vml-anchor-xform');
  8082. var VmlProtectionXform = require('./style/vml-protection-xform');
  8083. var VmlPositionXform = require('./style/vml-position-xform');
  8084. var POSITION_TYPE = ['twoCells', 'oneCells', 'absolute'];
  8085. var VmlClientDataXform = /*#__PURE__*/function (_BaseXform) {
  8086. _inherits(VmlClientDataXform, _BaseXform);
  8087. var _super = _createSuper(VmlClientDataXform);
  8088. function VmlClientDataXform() {
  8089. var _this;
  8090. _classCallCheck(this, VmlClientDataXform);
  8091. _this = _super.call(this);
  8092. _this.map = {
  8093. 'x:Anchor': new VmlAnchorXform(),
  8094. 'x:Locked': new VmlProtectionXform({
  8095. tag: 'x:Locked'
  8096. }),
  8097. 'x:LockText': new VmlProtectionXform({
  8098. tag: 'x:LockText'
  8099. }),
  8100. 'x:SizeWithCells': new VmlPositionXform({
  8101. tag: 'x:SizeWithCells'
  8102. }),
  8103. 'x:MoveWithCells': new VmlPositionXform({
  8104. tag: 'x:MoveWithCells'
  8105. })
  8106. };
  8107. return _this;
  8108. }
  8109. _createClass(VmlClientDataXform, [{
  8110. key: "render",
  8111. value: function render(xmlStream, model) {
  8112. var _model$note = model.note,
  8113. protection = _model$note.protection,
  8114. editAs = _model$note.editAs;
  8115. xmlStream.openNode(this.tag, {
  8116. ObjectType: 'Note'
  8117. });
  8118. this.map['x:MoveWithCells'].render(xmlStream, editAs, POSITION_TYPE);
  8119. this.map['x:SizeWithCells'].render(xmlStream, editAs, POSITION_TYPE);
  8120. this.map['x:Anchor'].render(xmlStream, model);
  8121. this.map['x:Locked'].render(xmlStream, protection.locked);
  8122. xmlStream.leafNode('x:AutoFill', null, 'False');
  8123. this.map['x:LockText'].render(xmlStream, protection.lockText);
  8124. xmlStream.leafNode('x:Row', null, model.refAddress.row - 1);
  8125. xmlStream.leafNode('x:Column', null, model.refAddress.col - 1);
  8126. xmlStream.closeNode();
  8127. }
  8128. }, {
  8129. key: "parseOpen",
  8130. value: function parseOpen(node) {
  8131. switch (node.name) {
  8132. case this.tag:
  8133. this.reset();
  8134. this.model = {
  8135. anchor: [],
  8136. protection: {},
  8137. editAs: ''
  8138. };
  8139. break;
  8140. default:
  8141. this.parser = this.map[node.name];
  8142. if (this.parser) {
  8143. this.parser.parseOpen(node);
  8144. }
  8145. break;
  8146. }
  8147. return true;
  8148. }
  8149. }, {
  8150. key: "parseText",
  8151. value: function parseText(text) {
  8152. if (this.parser) {
  8153. this.parser.parseText(text);
  8154. }
  8155. }
  8156. }, {
  8157. key: "parseClose",
  8158. value: function parseClose(name) {
  8159. if (this.parser) {
  8160. if (!this.parser.parseClose(name)) {
  8161. this.parser = undefined;
  8162. }
  8163. return true;
  8164. }
  8165. switch (name) {
  8166. case this.tag:
  8167. this.normalizeModel();
  8168. return false;
  8169. default:
  8170. return true;
  8171. }
  8172. }
  8173. }, {
  8174. key: "normalizeModel",
  8175. value: function normalizeModel() {
  8176. var position = Object.assign({}, this.map['x:MoveWithCells'].model, this.map['x:SizeWithCells'].model);
  8177. var len = Object.keys(position).length;
  8178. this.model.editAs = POSITION_TYPE[len];
  8179. this.model.anchor = this.map['x:Anchor'].text;
  8180. this.model.protection.locked = this.map['x:Locked'].text;
  8181. this.model.protection.lockText = this.map['x:LockText'].text;
  8182. }
  8183. }, {
  8184. key: "tag",
  8185. get: function get() {
  8186. return 'x:ClientData';
  8187. }
  8188. }]);
  8189. return VmlClientDataXform;
  8190. }(BaseXform);
  8191. module.exports = VmlClientDataXform;
  8192. },{"../base-xform":31,"./style/vml-position-xform":40,"./style/vml-protection-xform":41,"./vml-anchor-xform":42}],44:[function(require,module,exports){
  8193. "use strict";
  8194. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  8195. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8196. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  8197. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8198. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  8199. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8200. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  8201. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  8202. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8203. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  8204. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8205. var XmlStream = require('../../../utils/xml-stream');
  8206. var BaseXform = require('../base-xform');
  8207. var VmlShapeXform = require('./vml-shape-xform'); // This class is (currently) single purposed to insert the triangle
  8208. // drawing icons on commented cells
  8209. var VmlNotesXform = /*#__PURE__*/function (_BaseXform) {
  8210. _inherits(VmlNotesXform, _BaseXform);
  8211. var _super = _createSuper(VmlNotesXform);
  8212. function VmlNotesXform() {
  8213. var _this;
  8214. _classCallCheck(this, VmlNotesXform);
  8215. _this = _super.call(this);
  8216. _this.map = {
  8217. 'v:shape': new VmlShapeXform()
  8218. };
  8219. return _this;
  8220. }
  8221. _createClass(VmlNotesXform, [{
  8222. key: "render",
  8223. value: function render(xmlStream, model) {
  8224. var _this2 = this;
  8225. xmlStream.openXml(XmlStream.StdDocAttributes);
  8226. xmlStream.openNode(this.tag, VmlNotesXform.DRAWING_ATTRIBUTES);
  8227. xmlStream.openNode('o:shapelayout', {
  8228. 'v:ext': 'edit'
  8229. });
  8230. xmlStream.leafNode('o:idmap', {
  8231. 'v:ext': 'edit',
  8232. data: 1
  8233. });
  8234. xmlStream.closeNode();
  8235. xmlStream.openNode('v:shapetype', {
  8236. id: '_x0000_t202',
  8237. coordsize: '21600,21600',
  8238. 'o:spt': 202,
  8239. path: 'm,l,21600r21600,l21600,xe'
  8240. });
  8241. xmlStream.leafNode('v:stroke', {
  8242. joinstyle: 'miter'
  8243. });
  8244. xmlStream.leafNode('v:path', {
  8245. gradientshapeok: 't',
  8246. 'o:connecttype': 'rect'
  8247. });
  8248. xmlStream.closeNode();
  8249. model.comments.forEach(function (item, index) {
  8250. _this2.map['v:shape'].render(xmlStream, item, index);
  8251. });
  8252. xmlStream.closeNode();
  8253. }
  8254. }, {
  8255. key: "parseOpen",
  8256. value: function parseOpen(node) {
  8257. if (this.parser) {
  8258. this.parser.parseOpen(node);
  8259. return true;
  8260. }
  8261. switch (node.name) {
  8262. case this.tag:
  8263. this.reset();
  8264. this.model = {
  8265. comments: []
  8266. };
  8267. break;
  8268. default:
  8269. this.parser = this.map[node.name];
  8270. if (this.parser) {
  8271. this.parser.parseOpen(node);
  8272. }
  8273. break;
  8274. }
  8275. return true;
  8276. }
  8277. }, {
  8278. key: "parseText",
  8279. value: function parseText(text) {
  8280. if (this.parser) {
  8281. this.parser.parseText(text);
  8282. }
  8283. }
  8284. }, {
  8285. key: "parseClose",
  8286. value: function parseClose(name) {
  8287. if (this.parser) {
  8288. if (!this.parser.parseClose(name)) {
  8289. this.model.comments.push(this.parser.model);
  8290. this.parser = undefined;
  8291. }
  8292. return true;
  8293. }
  8294. switch (name) {
  8295. case this.tag:
  8296. return false;
  8297. default:
  8298. // could be some unrecognised tags
  8299. return true;
  8300. }
  8301. }
  8302. }, {
  8303. key: "reconcile",
  8304. value: function reconcile(model, options) {
  8305. var _this3 = this;
  8306. model.anchors.forEach(function (anchor) {
  8307. if (anchor.br) {
  8308. _this3.map['xdr:twoCellAnchor'].reconcile(anchor, options);
  8309. } else {
  8310. _this3.map['xdr:oneCellAnchor'].reconcile(anchor, options);
  8311. }
  8312. });
  8313. }
  8314. }, {
  8315. key: "tag",
  8316. get: function get() {
  8317. return 'xml';
  8318. }
  8319. }]);
  8320. return VmlNotesXform;
  8321. }(BaseXform);
  8322. VmlNotesXform.DRAWING_ATTRIBUTES = {
  8323. 'xmlns:v': 'urn:schemas-microsoft-com:vml',
  8324. 'xmlns:o': 'urn:schemas-microsoft-com:office:office',
  8325. 'xmlns:x': 'urn:schemas-microsoft-com:office:excel'
  8326. };
  8327. module.exports = VmlNotesXform;
  8328. },{"../../../utils/xml-stream":27,"../base-xform":31,"./vml-shape-xform":45}],45:[function(require,module,exports){
  8329. "use strict";
  8330. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  8331. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8332. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  8333. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8334. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  8335. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8336. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  8337. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  8338. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8339. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  8340. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8341. var BaseXform = require('../base-xform');
  8342. var VmlTextboxXform = require('./vml-textbox-xform');
  8343. var VmlClientDataXform = require('./vml-client-data-xform');
  8344. var VmlShapeXform = /*#__PURE__*/function (_BaseXform) {
  8345. _inherits(VmlShapeXform, _BaseXform);
  8346. var _super = _createSuper(VmlShapeXform);
  8347. function VmlShapeXform() {
  8348. var _this;
  8349. _classCallCheck(this, VmlShapeXform);
  8350. _this = _super.call(this);
  8351. _this.map = {
  8352. 'v:textbox': new VmlTextboxXform(),
  8353. 'x:ClientData': new VmlClientDataXform()
  8354. };
  8355. return _this;
  8356. }
  8357. _createClass(VmlShapeXform, [{
  8358. key: "render",
  8359. value: function render(xmlStream, model, index) {
  8360. xmlStream.openNode('v:shape', VmlShapeXform.V_SHAPE_ATTRIBUTES(model, index));
  8361. xmlStream.leafNode('v:fill', {
  8362. color2: 'infoBackground [80]'
  8363. });
  8364. xmlStream.leafNode('v:shadow', {
  8365. color: 'none [81]',
  8366. obscured: 't'
  8367. });
  8368. xmlStream.leafNode('v:path', {
  8369. 'o:connecttype': 'none'
  8370. });
  8371. this.map['v:textbox'].render(xmlStream, model);
  8372. this.map['x:ClientData'].render(xmlStream, model);
  8373. xmlStream.closeNode();
  8374. }
  8375. }, {
  8376. key: "parseOpen",
  8377. value: function parseOpen(node) {
  8378. if (this.parser) {
  8379. this.parser.parseOpen(node);
  8380. return true;
  8381. }
  8382. switch (node.name) {
  8383. case this.tag:
  8384. this.reset();
  8385. this.model = {
  8386. margins: {
  8387. insetmode: node.attributes['o:insetmode']
  8388. },
  8389. anchor: '',
  8390. editAs: '',
  8391. protection: {}
  8392. };
  8393. break;
  8394. default:
  8395. this.parser = this.map[node.name];
  8396. if (this.parser) {
  8397. this.parser.parseOpen(node);
  8398. }
  8399. break;
  8400. }
  8401. return true;
  8402. }
  8403. }, {
  8404. key: "parseText",
  8405. value: function parseText(text) {
  8406. if (this.parser) {
  8407. this.parser.parseText(text);
  8408. }
  8409. }
  8410. }, {
  8411. key: "parseClose",
  8412. value: function parseClose(name) {
  8413. if (this.parser) {
  8414. if (!this.parser.parseClose(name)) {
  8415. this.parser = undefined;
  8416. }
  8417. return true;
  8418. }
  8419. switch (name) {
  8420. case this.tag:
  8421. this.model.margins.inset = this.map['v:textbox'].model && this.map['v:textbox'].model.inset;
  8422. this.model.protection = this.map['x:ClientData'].model && this.map['x:ClientData'].model.protection;
  8423. this.model.anchor = this.map['x:ClientData'].model && this.map['x:ClientData'].model.anchor;
  8424. this.model.editAs = this.map['x:ClientData'].model && this.map['x:ClientData'].model.editAs;
  8425. return false;
  8426. default:
  8427. return true;
  8428. }
  8429. }
  8430. }, {
  8431. key: "tag",
  8432. get: function get() {
  8433. return 'v:shape';
  8434. }
  8435. }]);
  8436. return VmlShapeXform;
  8437. }(BaseXform);
  8438. VmlShapeXform.V_SHAPE_ATTRIBUTES = function (model, index) {
  8439. return {
  8440. id: "_x0000_s".concat(1025 + index),
  8441. type: '#_x0000_t202',
  8442. style: 'position:absolute; margin-left:105.3pt;margin-top:10.5pt;width:97.8pt;height:59.1pt;z-index:1;visibility:hidden',
  8443. fillcolor: 'infoBackground [80]',
  8444. strokecolor: 'none [81]',
  8445. 'o:insetmode': model.note.margins && model.note.margins.insetmode
  8446. };
  8447. };
  8448. module.exports = VmlShapeXform;
  8449. },{"../base-xform":31,"./vml-client-data-xform":43,"./vml-textbox-xform":46}],46:[function(require,module,exports){
  8450. "use strict";
  8451. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  8452. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8453. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  8454. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8455. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  8456. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8457. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  8458. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  8459. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8460. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  8461. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8462. var BaseXform = require('../base-xform');
  8463. var VmlTextboxXform = /*#__PURE__*/function (_BaseXform) {
  8464. _inherits(VmlTextboxXform, _BaseXform);
  8465. var _super = _createSuper(VmlTextboxXform);
  8466. function VmlTextboxXform() {
  8467. _classCallCheck(this, VmlTextboxXform);
  8468. return _super.apply(this, arguments);
  8469. }
  8470. _createClass(VmlTextboxXform, [{
  8471. key: "conversionUnit",
  8472. value: function conversionUnit(value, multiple, unit) {
  8473. return "".concat(parseFloat(value) * multiple.toFixed(2)).concat(unit);
  8474. }
  8475. }, {
  8476. key: "reverseConversionUnit",
  8477. value: function reverseConversionUnit(inset) {
  8478. var _this = this;
  8479. return (inset || '').split(',').map(function (margin) {
  8480. return Number(parseFloat(_this.conversionUnit(parseFloat(margin), 0.1, '')).toFixed(2));
  8481. });
  8482. }
  8483. }, {
  8484. key: "render",
  8485. value: function render(xmlStream, model) {
  8486. var _this2 = this;
  8487. var attributes = {
  8488. style: 'mso-direction-alt:auto'
  8489. };
  8490. if (model && model.note) {
  8491. var _ref = model.note && model.note.margins,
  8492. inset = _ref.inset;
  8493. if (Array.isArray(inset)) {
  8494. inset = inset.map(function (margin) {
  8495. return _this2.conversionUnit(margin, 10, 'mm');
  8496. }).join(',');
  8497. }
  8498. if (inset) {
  8499. attributes.inset = inset;
  8500. }
  8501. }
  8502. xmlStream.openNode('v:textbox', attributes);
  8503. xmlStream.leafNode('div', {
  8504. style: 'text-align:left'
  8505. });
  8506. xmlStream.closeNode();
  8507. }
  8508. }, {
  8509. key: "parseOpen",
  8510. value: function parseOpen(node) {
  8511. switch (node.name) {
  8512. case this.tag:
  8513. this.model = {
  8514. inset: this.reverseConversionUnit(node.attributes.inset)
  8515. };
  8516. return true;
  8517. default:
  8518. return true;
  8519. }
  8520. }
  8521. }, {
  8522. key: "parseText",
  8523. value: function parseText() {}
  8524. }, {
  8525. key: "parseClose",
  8526. value: function parseClose(name) {
  8527. switch (name) {
  8528. case this.tag:
  8529. return false;
  8530. default:
  8531. return true;
  8532. }
  8533. }
  8534. }, {
  8535. key: "tag",
  8536. get: function get() {
  8537. return 'v:textbox';
  8538. }
  8539. }]);
  8540. return VmlTextboxXform;
  8541. }(BaseXform);
  8542. module.exports = VmlTextboxXform;
  8543. },{"../base-xform":31}],47:[function(require,module,exports){
  8544. "use strict";
  8545. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  8546. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8547. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  8548. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8549. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  8550. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8551. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  8552. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  8553. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8554. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  8555. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8556. var BaseXform = require('./base-xform');
  8557. /* 'virtual' methods used as a form of documentation */
  8558. /* eslint-disable class-methods-use-this */
  8559. // base class for xforms that are composed of other xforms
  8560. // offers some default implementations
  8561. var CompositeXform = /*#__PURE__*/function (_BaseXform) {
  8562. _inherits(CompositeXform, _BaseXform);
  8563. var _super = _createSuper(CompositeXform);
  8564. function CompositeXform() {
  8565. _classCallCheck(this, CompositeXform);
  8566. return _super.apply(this, arguments);
  8567. }
  8568. _createClass(CompositeXform, [{
  8569. key: "createNewModel",
  8570. value: function createNewModel(node) {
  8571. return {};
  8572. }
  8573. }, {
  8574. key: "parseOpen",
  8575. value: function parseOpen(node) {
  8576. // Typical pattern for composite xform
  8577. this.parser = this.parser || this.map[node.name];
  8578. if (this.parser) {
  8579. this.parser.parseOpen(node);
  8580. return true;
  8581. }
  8582. if (node.name === this.tag) {
  8583. this.model = this.createNewModel(node);
  8584. return true;
  8585. }
  8586. return false;
  8587. }
  8588. }, {
  8589. key: "parseText",
  8590. value: function parseText(text) {
  8591. // Default implementation. Send text to child parser
  8592. if (this.parser) {
  8593. this.parser.parseText(text);
  8594. }
  8595. }
  8596. }, {
  8597. key: "onParserClose",
  8598. value: function onParserClose(name, parser) {
  8599. // parseClose has seen a child parser close
  8600. // now need to incorporate into this.model somehow
  8601. this.model[name] = parser.model;
  8602. }
  8603. }, {
  8604. key: "parseClose",
  8605. value: function parseClose(name) {
  8606. // Default implementation
  8607. if (this.parser) {
  8608. if (!this.parser.parseClose(name)) {
  8609. this.onParserClose(name, this.parser);
  8610. this.parser = undefined;
  8611. }
  8612. return true;
  8613. }
  8614. return name !== this.tag;
  8615. }
  8616. }]);
  8617. return CompositeXform;
  8618. }(BaseXform);
  8619. module.exports = CompositeXform;
  8620. },{"./base-xform":31}],48:[function(require,module,exports){
  8621. "use strict";
  8622. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  8623. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8624. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  8625. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8626. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  8627. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8628. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  8629. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  8630. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8631. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  8632. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8633. var BaseXform = require('../base-xform');
  8634. var AppHeadingPairsXform = /*#__PURE__*/function (_BaseXform) {
  8635. _inherits(AppHeadingPairsXform, _BaseXform);
  8636. var _super = _createSuper(AppHeadingPairsXform);
  8637. function AppHeadingPairsXform() {
  8638. _classCallCheck(this, AppHeadingPairsXform);
  8639. return _super.apply(this, arguments);
  8640. }
  8641. _createClass(AppHeadingPairsXform, [{
  8642. key: "render",
  8643. value: function render(xmlStream, model) {
  8644. xmlStream.openNode('HeadingPairs');
  8645. xmlStream.openNode('vt:vector', {
  8646. size: 2,
  8647. baseType: 'variant'
  8648. });
  8649. xmlStream.openNode('vt:variant');
  8650. xmlStream.leafNode('vt:lpstr', undefined, 'Worksheets');
  8651. xmlStream.closeNode();
  8652. xmlStream.openNode('vt:variant');
  8653. xmlStream.leafNode('vt:i4', undefined, model.length);
  8654. xmlStream.closeNode();
  8655. xmlStream.closeNode();
  8656. xmlStream.closeNode();
  8657. }
  8658. }, {
  8659. key: "parseOpen",
  8660. value: function parseOpen(node) {
  8661. // no parsing
  8662. return node.name === 'HeadingPairs';
  8663. }
  8664. }, {
  8665. key: "parseText",
  8666. value: function parseText() {}
  8667. }, {
  8668. key: "parseClose",
  8669. value: function parseClose(name) {
  8670. return name !== 'HeadingPairs';
  8671. }
  8672. }]);
  8673. return AppHeadingPairsXform;
  8674. }(BaseXform);
  8675. module.exports = AppHeadingPairsXform;
  8676. },{"../base-xform":31}],49:[function(require,module,exports){
  8677. "use strict";
  8678. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  8679. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8680. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  8681. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8682. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  8683. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8684. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  8685. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  8686. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8687. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  8688. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8689. var BaseXform = require('../base-xform');
  8690. var AppTitlesOfPartsXform = /*#__PURE__*/function (_BaseXform) {
  8691. _inherits(AppTitlesOfPartsXform, _BaseXform);
  8692. var _super = _createSuper(AppTitlesOfPartsXform);
  8693. function AppTitlesOfPartsXform() {
  8694. _classCallCheck(this, AppTitlesOfPartsXform);
  8695. return _super.apply(this, arguments);
  8696. }
  8697. _createClass(AppTitlesOfPartsXform, [{
  8698. key: "render",
  8699. value: function render(xmlStream, model) {
  8700. xmlStream.openNode('TitlesOfParts');
  8701. xmlStream.openNode('vt:vector', {
  8702. size: model.length,
  8703. baseType: 'lpstr'
  8704. });
  8705. model.forEach(function (sheet) {
  8706. xmlStream.leafNode('vt:lpstr', undefined, sheet.name);
  8707. });
  8708. xmlStream.closeNode();
  8709. xmlStream.closeNode();
  8710. }
  8711. }, {
  8712. key: "parseOpen",
  8713. value: function parseOpen(node) {
  8714. // no parsing
  8715. return node.name === 'TitlesOfParts';
  8716. }
  8717. }, {
  8718. key: "parseText",
  8719. value: function parseText() {}
  8720. }, {
  8721. key: "parseClose",
  8722. value: function parseClose(name) {
  8723. return name !== 'TitlesOfParts';
  8724. }
  8725. }]);
  8726. return AppTitlesOfPartsXform;
  8727. }(BaseXform);
  8728. module.exports = AppTitlesOfPartsXform;
  8729. },{"../base-xform":31}],50:[function(require,module,exports){
  8730. "use strict";
  8731. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  8732. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8733. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  8734. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8735. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  8736. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8737. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  8738. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  8739. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8740. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  8741. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8742. var XmlStream = require('../../../utils/xml-stream');
  8743. var BaseXform = require('../base-xform');
  8744. var StringXform = require('../simple/string-xform');
  8745. var AppHeadingPairsXform = require('./app-heading-pairs-xform');
  8746. var AppTitleOfPartsXform = require('./app-titles-of-parts-xform');
  8747. var AppXform = /*#__PURE__*/function (_BaseXform) {
  8748. _inherits(AppXform, _BaseXform);
  8749. var _super = _createSuper(AppXform);
  8750. function AppXform() {
  8751. var _this;
  8752. _classCallCheck(this, AppXform);
  8753. _this = _super.call(this);
  8754. _this.map = {
  8755. Company: new StringXform({
  8756. tag: 'Company'
  8757. }),
  8758. Manager: new StringXform({
  8759. tag: 'Manager'
  8760. }),
  8761. HeadingPairs: new AppHeadingPairsXform(),
  8762. TitleOfParts: new AppTitleOfPartsXform()
  8763. };
  8764. return _this;
  8765. }
  8766. _createClass(AppXform, [{
  8767. key: "render",
  8768. value: function render(xmlStream, model) {
  8769. xmlStream.openXml(XmlStream.StdDocAttributes);
  8770. xmlStream.openNode('Properties', AppXform.PROPERTY_ATTRIBUTES);
  8771. xmlStream.leafNode('Application', undefined, 'Microsoft Excel');
  8772. xmlStream.leafNode('DocSecurity', undefined, '0');
  8773. xmlStream.leafNode('ScaleCrop', undefined, 'false');
  8774. this.map.HeadingPairs.render(xmlStream, model.worksheets);
  8775. this.map.TitleOfParts.render(xmlStream, model.worksheets);
  8776. this.map.Company.render(xmlStream, model.company || '');
  8777. this.map.Manager.render(xmlStream, model.manager);
  8778. xmlStream.leafNode('LinksUpToDate', undefined, 'false');
  8779. xmlStream.leafNode('SharedDoc', undefined, 'false');
  8780. xmlStream.leafNode('HyperlinksChanged', undefined, 'false');
  8781. xmlStream.leafNode('AppVersion', undefined, '16.0300');
  8782. xmlStream.closeNode();
  8783. }
  8784. }, {
  8785. key: "parseOpen",
  8786. value: function parseOpen(node) {
  8787. if (this.parser) {
  8788. this.parser.parseOpen(node);
  8789. return true;
  8790. }
  8791. switch (node.name) {
  8792. case 'Properties':
  8793. return true;
  8794. default:
  8795. this.parser = this.map[node.name];
  8796. if (this.parser) {
  8797. this.parser.parseOpen(node);
  8798. return true;
  8799. } // there's a lot we don't bother to parse
  8800. return false;
  8801. }
  8802. }
  8803. }, {
  8804. key: "parseText",
  8805. value: function parseText(text) {
  8806. if (this.parser) {
  8807. this.parser.parseText(text);
  8808. }
  8809. }
  8810. }, {
  8811. key: "parseClose",
  8812. value: function parseClose(name) {
  8813. if (this.parser) {
  8814. if (!this.parser.parseClose(name)) {
  8815. this.parser = undefined;
  8816. }
  8817. return true;
  8818. }
  8819. switch (name) {
  8820. case 'Properties':
  8821. this.model = {
  8822. worksheets: this.map.TitleOfParts.model,
  8823. company: this.map.Company.model,
  8824. manager: this.map.Manager.model
  8825. };
  8826. return false;
  8827. default:
  8828. return true;
  8829. }
  8830. }
  8831. }]);
  8832. return AppXform;
  8833. }(BaseXform);
  8834. AppXform.DateFormat = function (dt) {
  8835. return dt.toISOString().replace(/[.]\d{3,6}/, '');
  8836. };
  8837. AppXform.DateAttrs = {
  8838. 'xsi:type': 'dcterms:W3CDTF'
  8839. };
  8840. AppXform.PROPERTY_ATTRIBUTES = {
  8841. xmlns: 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties',
  8842. 'xmlns:vt': 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes'
  8843. };
  8844. module.exports = AppXform;
  8845. },{"../../../utils/xml-stream":27,"../base-xform":31,"../simple/string-xform":118,"./app-heading-pairs-xform":48,"./app-titles-of-parts-xform":49}],51:[function(require,module,exports){
  8846. "use strict";
  8847. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  8848. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8849. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  8850. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8851. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  8852. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8853. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  8854. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  8855. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8856. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  8857. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8858. var XmlStream = require('../../../utils/xml-stream');
  8859. var BaseXform = require('../base-xform'); // used for rendering the [Content_Types].xml file
  8860. // not used for parsing
  8861. var ContentTypesXform = /*#__PURE__*/function (_BaseXform) {
  8862. _inherits(ContentTypesXform, _BaseXform);
  8863. var _super = _createSuper(ContentTypesXform);
  8864. function ContentTypesXform() {
  8865. _classCallCheck(this, ContentTypesXform);
  8866. return _super.apply(this, arguments);
  8867. }
  8868. _createClass(ContentTypesXform, [{
  8869. key: "render",
  8870. value: function render(xmlStream, model) {
  8871. xmlStream.openXml(XmlStream.StdDocAttributes);
  8872. xmlStream.openNode('Types', ContentTypesXform.PROPERTY_ATTRIBUTES);
  8873. var mediaHash = {};
  8874. (model.media || []).forEach(function (medium) {
  8875. if (medium.type === 'image') {
  8876. var imageType = medium.extension;
  8877. if (!mediaHash[imageType]) {
  8878. mediaHash[imageType] = true;
  8879. xmlStream.leafNode('Default', {
  8880. Extension: imageType,
  8881. ContentType: "image/".concat(imageType)
  8882. });
  8883. }
  8884. }
  8885. });
  8886. xmlStream.leafNode('Default', {
  8887. Extension: 'rels',
  8888. ContentType: 'application/vnd.openxmlformats-package.relationships+xml'
  8889. });
  8890. xmlStream.leafNode('Default', {
  8891. Extension: 'xml',
  8892. ContentType: 'application/xml'
  8893. });
  8894. xmlStream.leafNode('Override', {
  8895. PartName: '/xl/workbook.xml',
  8896. ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml'
  8897. });
  8898. model.worksheets.forEach(function (worksheet) {
  8899. var name = "/xl/worksheets/sheet".concat(worksheet.id, ".xml");
  8900. xmlStream.leafNode('Override', {
  8901. PartName: name,
  8902. ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml'
  8903. });
  8904. });
  8905. xmlStream.leafNode('Override', {
  8906. PartName: '/xl/theme/theme1.xml',
  8907. ContentType: 'application/vnd.openxmlformats-officedocument.theme+xml'
  8908. });
  8909. xmlStream.leafNode('Override', {
  8910. PartName: '/xl/styles.xml',
  8911. ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml'
  8912. });
  8913. var hasSharedStrings = model.sharedStrings && model.sharedStrings.count;
  8914. if (hasSharedStrings) {
  8915. xmlStream.leafNode('Override', {
  8916. PartName: '/xl/sharedStrings.xml',
  8917. ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml'
  8918. });
  8919. }
  8920. if (model.tables) {
  8921. model.tables.forEach(function (table) {
  8922. xmlStream.leafNode('Override', {
  8923. PartName: "/xl/tables/".concat(table.target),
  8924. ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml'
  8925. });
  8926. });
  8927. }
  8928. if (model.drawings) {
  8929. model.drawings.forEach(function (drawing) {
  8930. xmlStream.leafNode('Override', {
  8931. PartName: "/xl/drawings/".concat(drawing.name, ".xml"),
  8932. ContentType: 'application/vnd.openxmlformats-officedocument.drawing+xml'
  8933. });
  8934. });
  8935. }
  8936. if (model.commentRefs) {
  8937. xmlStream.leafNode('Default', {
  8938. Extension: 'vml',
  8939. ContentType: 'application/vnd.openxmlformats-officedocument.vmlDrawing'
  8940. });
  8941. model.commentRefs.forEach(function (_ref) {
  8942. var commentName = _ref.commentName;
  8943. xmlStream.leafNode('Override', {
  8944. PartName: "/xl/".concat(commentName, ".xml"),
  8945. ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml'
  8946. });
  8947. });
  8948. }
  8949. xmlStream.leafNode('Override', {
  8950. PartName: '/docProps/core.xml',
  8951. ContentType: 'application/vnd.openxmlformats-package.core-properties+xml'
  8952. });
  8953. xmlStream.leafNode('Override', {
  8954. PartName: '/docProps/app.xml',
  8955. ContentType: 'application/vnd.openxmlformats-officedocument.extended-properties+xml'
  8956. });
  8957. xmlStream.closeNode();
  8958. }
  8959. }, {
  8960. key: "parseOpen",
  8961. value: function parseOpen() {
  8962. return false;
  8963. }
  8964. }, {
  8965. key: "parseText",
  8966. value: function parseText() {}
  8967. }, {
  8968. key: "parseClose",
  8969. value: function parseClose() {
  8970. return false;
  8971. }
  8972. }]);
  8973. return ContentTypesXform;
  8974. }(BaseXform);
  8975. ContentTypesXform.PROPERTY_ATTRIBUTES = {
  8976. xmlns: 'http://schemas.openxmlformats.org/package/2006/content-types'
  8977. };
  8978. module.exports = ContentTypesXform;
  8979. },{"../../../utils/xml-stream":27,"../base-xform":31}],52:[function(require,module,exports){
  8980. "use strict";
  8981. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  8982. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8983. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  8984. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8985. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  8986. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8987. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  8988. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  8989. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8990. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  8991. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8992. var XmlStream = require('../../../utils/xml-stream');
  8993. var BaseXform = require('../base-xform');
  8994. var DateXform = require('../simple/date-xform');
  8995. var StringXform = require('../simple/string-xform');
  8996. var IntegerXform = require('../simple/integer-xform');
  8997. var CoreXform = /*#__PURE__*/function (_BaseXform) {
  8998. _inherits(CoreXform, _BaseXform);
  8999. var _super = _createSuper(CoreXform);
  9000. function CoreXform() {
  9001. var _this;
  9002. _classCallCheck(this, CoreXform);
  9003. _this = _super.call(this);
  9004. _this.map = {
  9005. 'dc:creator': new StringXform({
  9006. tag: 'dc:creator'
  9007. }),
  9008. 'dc:title': new StringXform({
  9009. tag: 'dc:title'
  9010. }),
  9011. 'dc:subject': new StringXform({
  9012. tag: 'dc:subject'
  9013. }),
  9014. 'dc:description': new StringXform({
  9015. tag: 'dc:description'
  9016. }),
  9017. 'dc:identifier': new StringXform({
  9018. tag: 'dc:identifier'
  9019. }),
  9020. 'dc:language': new StringXform({
  9021. tag: 'dc:language'
  9022. }),
  9023. 'cp:keywords': new StringXform({
  9024. tag: 'cp:keywords'
  9025. }),
  9026. 'cp:category': new StringXform({
  9027. tag: 'cp:category'
  9028. }),
  9029. 'cp:lastModifiedBy': new StringXform({
  9030. tag: 'cp:lastModifiedBy'
  9031. }),
  9032. 'cp:lastPrinted': new DateXform({
  9033. tag: 'cp:lastPrinted',
  9034. format: CoreXform.DateFormat
  9035. }),
  9036. 'cp:revision': new IntegerXform({
  9037. tag: 'cp:revision'
  9038. }),
  9039. 'cp:version': new StringXform({
  9040. tag: 'cp:version'
  9041. }),
  9042. 'cp:contentStatus': new StringXform({
  9043. tag: 'cp:contentStatus'
  9044. }),
  9045. 'cp:contentType': new StringXform({
  9046. tag: 'cp:contentType'
  9047. }),
  9048. 'dcterms:created': new DateXform({
  9049. tag: 'dcterms:created',
  9050. attrs: CoreXform.DateAttrs,
  9051. format: CoreXform.DateFormat
  9052. }),
  9053. 'dcterms:modified': new DateXform({
  9054. tag: 'dcterms:modified',
  9055. attrs: CoreXform.DateAttrs,
  9056. format: CoreXform.DateFormat
  9057. })
  9058. };
  9059. return _this;
  9060. }
  9061. _createClass(CoreXform, [{
  9062. key: "render",
  9063. value: function render(xmlStream, model) {
  9064. xmlStream.openXml(XmlStream.StdDocAttributes);
  9065. xmlStream.openNode('cp:coreProperties', CoreXform.CORE_PROPERTY_ATTRIBUTES);
  9066. this.map['dc:creator'].render(xmlStream, model.creator);
  9067. this.map['dc:title'].render(xmlStream, model.title);
  9068. this.map['dc:subject'].render(xmlStream, model.subject);
  9069. this.map['dc:description'].render(xmlStream, model.description);
  9070. this.map['dc:identifier'].render(xmlStream, model.identifier);
  9071. this.map['dc:language'].render(xmlStream, model.language);
  9072. this.map['cp:keywords'].render(xmlStream, model.keywords);
  9073. this.map['cp:category'].render(xmlStream, model.category);
  9074. this.map['cp:lastModifiedBy'].render(xmlStream, model.lastModifiedBy);
  9075. this.map['cp:lastPrinted'].render(xmlStream, model.lastPrinted);
  9076. this.map['cp:revision'].render(xmlStream, model.revision);
  9077. this.map['cp:version'].render(xmlStream, model.version);
  9078. this.map['cp:contentStatus'].render(xmlStream, model.contentStatus);
  9079. this.map['cp:contentType'].render(xmlStream, model.contentType);
  9080. this.map['dcterms:created'].render(xmlStream, model.created);
  9081. this.map['dcterms:modified'].render(xmlStream, model.modified);
  9082. xmlStream.closeNode();
  9083. }
  9084. }, {
  9085. key: "parseOpen",
  9086. value: function parseOpen(node) {
  9087. if (this.parser) {
  9088. this.parser.parseOpen(node);
  9089. return true;
  9090. }
  9091. switch (node.name) {
  9092. case 'cp:coreProperties':
  9093. case 'coreProperties':
  9094. return true;
  9095. default:
  9096. this.parser = this.map[node.name];
  9097. if (this.parser) {
  9098. this.parser.parseOpen(node);
  9099. return true;
  9100. }
  9101. throw new Error("Unexpected xml node in parseOpen: ".concat(JSON.stringify(node)));
  9102. }
  9103. }
  9104. }, {
  9105. key: "parseText",
  9106. value: function parseText(text) {
  9107. if (this.parser) {
  9108. this.parser.parseText(text);
  9109. }
  9110. }
  9111. }, {
  9112. key: "parseClose",
  9113. value: function parseClose(name) {
  9114. if (this.parser) {
  9115. if (!this.parser.parseClose(name)) {
  9116. this.parser = undefined;
  9117. }
  9118. return true;
  9119. }
  9120. switch (name) {
  9121. case 'cp:coreProperties':
  9122. case 'coreProperties':
  9123. this.model = {
  9124. creator: this.map['dc:creator'].model,
  9125. title: this.map['dc:title'].model,
  9126. subject: this.map['dc:subject'].model,
  9127. description: this.map['dc:description'].model,
  9128. identifier: this.map['dc:identifier'].model,
  9129. language: this.map['dc:language'].model,
  9130. keywords: this.map['cp:keywords'].model,
  9131. category: this.map['cp:category'].model,
  9132. lastModifiedBy: this.map['cp:lastModifiedBy'].model,
  9133. lastPrinted: this.map['cp:lastPrinted'].model,
  9134. revision: this.map['cp:revision'].model,
  9135. contentStatus: this.map['cp:contentStatus'].model,
  9136. contentType: this.map['cp:contentType'].model,
  9137. created: this.map['dcterms:created'].model,
  9138. modified: this.map['dcterms:modified'].model
  9139. };
  9140. return false;
  9141. default:
  9142. throw new Error("Unexpected xml node in parseClose: ".concat(name));
  9143. }
  9144. }
  9145. }]);
  9146. return CoreXform;
  9147. }(BaseXform);
  9148. CoreXform.DateFormat = function (dt) {
  9149. return dt.toISOString().replace(/[.]\d{3}/, '');
  9150. };
  9151. CoreXform.DateAttrs = {
  9152. 'xsi:type': 'dcterms:W3CDTF'
  9153. };
  9154. CoreXform.CORE_PROPERTY_ATTRIBUTES = {
  9155. 'xmlns:cp': 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties',
  9156. 'xmlns:dc': 'http://purl.org/dc/elements/1.1/',
  9157. 'xmlns:dcterms': 'http://purl.org/dc/terms/',
  9158. 'xmlns:dcmitype': 'http://purl.org/dc/dcmitype/',
  9159. 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance'
  9160. };
  9161. module.exports = CoreXform;
  9162. },{"../../../utils/xml-stream":27,"../base-xform":31,"../simple/date-xform":116,"../simple/integer-xform":117,"../simple/string-xform":118}],53:[function(require,module,exports){
  9163. "use strict";
  9164. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  9165. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9166. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9167. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9168. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  9169. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9170. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  9171. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  9172. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9173. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  9174. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9175. var BaseXform = require('../base-xform');
  9176. var RelationshipXform = /*#__PURE__*/function (_BaseXform) {
  9177. _inherits(RelationshipXform, _BaseXform);
  9178. var _super = _createSuper(RelationshipXform);
  9179. function RelationshipXform() {
  9180. _classCallCheck(this, RelationshipXform);
  9181. return _super.apply(this, arguments);
  9182. }
  9183. _createClass(RelationshipXform, [{
  9184. key: "render",
  9185. value: function render(xmlStream, model) {
  9186. xmlStream.leafNode('Relationship', model);
  9187. }
  9188. }, {
  9189. key: "parseOpen",
  9190. value: function parseOpen(node) {
  9191. switch (node.name) {
  9192. case 'Relationship':
  9193. this.model = node.attributes;
  9194. return true;
  9195. default:
  9196. return false;
  9197. }
  9198. }
  9199. }, {
  9200. key: "parseText",
  9201. value: function parseText() {}
  9202. }, {
  9203. key: "parseClose",
  9204. value: function parseClose() {
  9205. return false;
  9206. }
  9207. }]);
  9208. return RelationshipXform;
  9209. }(BaseXform);
  9210. module.exports = RelationshipXform;
  9211. },{"../base-xform":31}],54:[function(require,module,exports){
  9212. "use strict";
  9213. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  9214. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9215. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9216. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9217. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  9218. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9219. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  9220. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  9221. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9222. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  9223. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9224. var XmlStream = require('../../../utils/xml-stream');
  9225. var BaseXform = require('../base-xform');
  9226. var RelationshipXform = require('./relationship-xform');
  9227. var RelationshipsXform = /*#__PURE__*/function (_BaseXform) {
  9228. _inherits(RelationshipsXform, _BaseXform);
  9229. var _super = _createSuper(RelationshipsXform);
  9230. function RelationshipsXform() {
  9231. var _this;
  9232. _classCallCheck(this, RelationshipsXform);
  9233. _this = _super.call(this);
  9234. _this.map = {
  9235. Relationship: new RelationshipXform()
  9236. };
  9237. return _this;
  9238. }
  9239. _createClass(RelationshipsXform, [{
  9240. key: "render",
  9241. value: function render(xmlStream, model) {
  9242. var _this2 = this;
  9243. model = model || this._values;
  9244. xmlStream.openXml(XmlStream.StdDocAttributes);
  9245. xmlStream.openNode('Relationships', RelationshipsXform.RELATIONSHIPS_ATTRIBUTES);
  9246. model.forEach(function (relationship) {
  9247. _this2.map.Relationship.render(xmlStream, relationship);
  9248. });
  9249. xmlStream.closeNode();
  9250. }
  9251. }, {
  9252. key: "parseOpen",
  9253. value: function parseOpen(node) {
  9254. if (this.parser) {
  9255. this.parser.parseOpen(node);
  9256. return true;
  9257. }
  9258. switch (node.name) {
  9259. case 'Relationships':
  9260. this.model = [];
  9261. return true;
  9262. default:
  9263. this.parser = this.map[node.name];
  9264. if (this.parser) {
  9265. this.parser.parseOpen(node);
  9266. return true;
  9267. }
  9268. throw new Error("Unexpected xml node in parseOpen: ".concat(JSON.stringify(node)));
  9269. }
  9270. }
  9271. }, {
  9272. key: "parseText",
  9273. value: function parseText(text) {
  9274. if (this.parser) {
  9275. this.parser.parseText(text);
  9276. }
  9277. }
  9278. }, {
  9279. key: "parseClose",
  9280. value: function parseClose(name) {
  9281. if (this.parser) {
  9282. if (!this.parser.parseClose(name)) {
  9283. this.model.push(this.parser.model);
  9284. this.parser = undefined;
  9285. }
  9286. return true;
  9287. }
  9288. switch (name) {
  9289. case 'Relationships':
  9290. return false;
  9291. default:
  9292. throw new Error("Unexpected xml node in parseClose: ".concat(name));
  9293. }
  9294. }
  9295. }]);
  9296. return RelationshipsXform;
  9297. }(BaseXform);
  9298. RelationshipsXform.RELATIONSHIPS_ATTRIBUTES = {
  9299. xmlns: 'http://schemas.openxmlformats.org/package/2006/relationships'
  9300. };
  9301. module.exports = RelationshipsXform;
  9302. },{"../../../utils/xml-stream":27,"../base-xform":31,"./relationship-xform":53}],55:[function(require,module,exports){
  9303. "use strict";
  9304. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  9305. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9306. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9307. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9308. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  9309. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9310. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  9311. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  9312. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9313. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  9314. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9315. var BaseXform = require('../base-xform');
  9316. var BaseCellAnchorXform = /*#__PURE__*/function (_BaseXform) {
  9317. _inherits(BaseCellAnchorXform, _BaseXform);
  9318. var _super = _createSuper(BaseCellAnchorXform);
  9319. function BaseCellAnchorXform() {
  9320. _classCallCheck(this, BaseCellAnchorXform);
  9321. return _super.apply(this, arguments);
  9322. }
  9323. _createClass(BaseCellAnchorXform, [{
  9324. key: "parseOpen",
  9325. value: function parseOpen(node) {
  9326. if (this.parser) {
  9327. this.parser.parseOpen(node);
  9328. return true;
  9329. }
  9330. switch (node.name) {
  9331. case this.tag:
  9332. this.reset();
  9333. this.model = {
  9334. range: {
  9335. editAs: node.attributes.editAs || 'oneCell'
  9336. }
  9337. };
  9338. break;
  9339. default:
  9340. this.parser = this.map[node.name];
  9341. if (this.parser) {
  9342. this.parser.parseOpen(node);
  9343. }
  9344. break;
  9345. }
  9346. return true;
  9347. }
  9348. }, {
  9349. key: "parseText",
  9350. value: function parseText(text) {
  9351. if (this.parser) {
  9352. this.parser.parseText(text);
  9353. }
  9354. }
  9355. }, {
  9356. key: "reconcilePicture",
  9357. value: function reconcilePicture(model, options) {
  9358. if (model && model.rId) {
  9359. var rel = options.rels[model.rId];
  9360. var match = rel.Target.match(/.*\/media\/(.+[.][a-zA-Z]{3,4})/);
  9361. if (match) {
  9362. var name = match[1];
  9363. var mediaId = options.mediaIndex[name];
  9364. return options.media[mediaId];
  9365. }
  9366. }
  9367. return undefined;
  9368. }
  9369. }]);
  9370. return BaseCellAnchorXform;
  9371. }(BaseXform);
  9372. module.exports = BaseCellAnchorXform;
  9373. },{"../base-xform":31}],56:[function(require,module,exports){
  9374. "use strict";
  9375. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  9376. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9377. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9378. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9379. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  9380. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9381. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  9382. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  9383. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9384. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  9385. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9386. var BaseXform = require('../base-xform');
  9387. var BlipXform = require('./blip-xform');
  9388. var BlipFillXform = /*#__PURE__*/function (_BaseXform) {
  9389. _inherits(BlipFillXform, _BaseXform);
  9390. var _super = _createSuper(BlipFillXform);
  9391. function BlipFillXform() {
  9392. var _this;
  9393. _classCallCheck(this, BlipFillXform);
  9394. _this = _super.call(this);
  9395. _this.map = {
  9396. 'a:blip': new BlipXform()
  9397. };
  9398. return _this;
  9399. }
  9400. _createClass(BlipFillXform, [{
  9401. key: "render",
  9402. value: function render(xmlStream, model) {
  9403. xmlStream.openNode(this.tag);
  9404. this.map['a:blip'].render(xmlStream, model); // TODO: options for this + parsing
  9405. xmlStream.openNode('a:stretch');
  9406. xmlStream.leafNode('a:fillRect');
  9407. xmlStream.closeNode();
  9408. xmlStream.closeNode();
  9409. }
  9410. }, {
  9411. key: "parseOpen",
  9412. value: function parseOpen(node) {
  9413. if (this.parser) {
  9414. this.parser.parseOpen(node);
  9415. return true;
  9416. }
  9417. switch (node.name) {
  9418. case this.tag:
  9419. this.reset();
  9420. break;
  9421. default:
  9422. this.parser = this.map[node.name];
  9423. if (this.parser) {
  9424. this.parser.parseOpen(node);
  9425. }
  9426. break;
  9427. }
  9428. return true;
  9429. }
  9430. }, {
  9431. key: "parseText",
  9432. value: function parseText() {}
  9433. }, {
  9434. key: "parseClose",
  9435. value: function parseClose(name) {
  9436. if (this.parser) {
  9437. if (!this.parser.parseClose(name)) {
  9438. this.parser = undefined;
  9439. }
  9440. return true;
  9441. }
  9442. switch (name) {
  9443. case this.tag:
  9444. this.model = this.map['a:blip'].model;
  9445. return false;
  9446. default:
  9447. return true;
  9448. }
  9449. }
  9450. }, {
  9451. key: "tag",
  9452. get: function get() {
  9453. return 'xdr:blipFill';
  9454. }
  9455. }]);
  9456. return BlipFillXform;
  9457. }(BaseXform);
  9458. module.exports = BlipFillXform;
  9459. },{"../base-xform":31,"./blip-xform":57}],57:[function(require,module,exports){
  9460. "use strict";
  9461. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  9462. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9463. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9464. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9465. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  9466. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9467. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  9468. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  9469. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9470. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  9471. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9472. var BaseXform = require('../base-xform');
  9473. var BlipXform = /*#__PURE__*/function (_BaseXform) {
  9474. _inherits(BlipXform, _BaseXform);
  9475. var _super = _createSuper(BlipXform);
  9476. function BlipXform() {
  9477. _classCallCheck(this, BlipXform);
  9478. return _super.apply(this, arguments);
  9479. }
  9480. _createClass(BlipXform, [{
  9481. key: "render",
  9482. value: function render(xmlStream, model) {
  9483. xmlStream.leafNode(this.tag, {
  9484. 'xmlns:r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
  9485. 'r:embed': model.rId,
  9486. cstate: 'print'
  9487. }); // TODO: handle children (e.g. a:extLst=>a:ext=>a14:useLocalDpi
  9488. }
  9489. }, {
  9490. key: "parseOpen",
  9491. value: function parseOpen(node) {
  9492. switch (node.name) {
  9493. case this.tag:
  9494. this.model = {
  9495. rId: node.attributes['r:embed']
  9496. };
  9497. return true;
  9498. default:
  9499. return true;
  9500. }
  9501. }
  9502. }, {
  9503. key: "parseText",
  9504. value: function parseText() {}
  9505. }, {
  9506. key: "parseClose",
  9507. value: function parseClose(name) {
  9508. switch (name) {
  9509. case this.tag:
  9510. return false;
  9511. default:
  9512. // unprocessed internal nodes
  9513. return true;
  9514. }
  9515. }
  9516. }, {
  9517. key: "tag",
  9518. get: function get() {
  9519. return 'a:blip';
  9520. }
  9521. }]);
  9522. return BlipXform;
  9523. }(BaseXform);
  9524. module.exports = BlipXform;
  9525. },{"../base-xform":31}],58:[function(require,module,exports){
  9526. "use strict";
  9527. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  9528. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9529. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9530. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9531. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  9532. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9533. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  9534. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  9535. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9536. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  9537. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9538. var BaseXform = require('../base-xform');
  9539. var CNvPicPrXform = /*#__PURE__*/function (_BaseXform) {
  9540. _inherits(CNvPicPrXform, _BaseXform);
  9541. var _super = _createSuper(CNvPicPrXform);
  9542. function CNvPicPrXform() {
  9543. _classCallCheck(this, CNvPicPrXform);
  9544. return _super.apply(this, arguments);
  9545. }
  9546. _createClass(CNvPicPrXform, [{
  9547. key: "render",
  9548. value: function render(xmlStream) {
  9549. xmlStream.openNode(this.tag);
  9550. xmlStream.leafNode('a:picLocks', {
  9551. noChangeAspect: '1'
  9552. });
  9553. xmlStream.closeNode();
  9554. }
  9555. }, {
  9556. key: "parseOpen",
  9557. value: function parseOpen(node) {
  9558. switch (node.name) {
  9559. case this.tag:
  9560. return true;
  9561. default:
  9562. return true;
  9563. }
  9564. }
  9565. }, {
  9566. key: "parseText",
  9567. value: function parseText() {}
  9568. }, {
  9569. key: "parseClose",
  9570. value: function parseClose(name) {
  9571. switch (name) {
  9572. case this.tag:
  9573. return false;
  9574. default:
  9575. // unprocessed internal nodes
  9576. return true;
  9577. }
  9578. }
  9579. }, {
  9580. key: "tag",
  9581. get: function get() {
  9582. return 'xdr:cNvPicPr';
  9583. }
  9584. }]);
  9585. return CNvPicPrXform;
  9586. }(BaseXform);
  9587. module.exports = CNvPicPrXform;
  9588. },{"../base-xform":31}],59:[function(require,module,exports){
  9589. "use strict";
  9590. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  9591. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9592. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9593. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9594. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  9595. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9596. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  9597. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  9598. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9599. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  9600. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9601. var BaseXform = require('../base-xform');
  9602. var HlickClickXform = require('./hlink-click-xform');
  9603. var ExtLstXform = require('./ext-lst-xform');
  9604. var CNvPrXform = /*#__PURE__*/function (_BaseXform) {
  9605. _inherits(CNvPrXform, _BaseXform);
  9606. var _super = _createSuper(CNvPrXform);
  9607. function CNvPrXform() {
  9608. var _this;
  9609. _classCallCheck(this, CNvPrXform);
  9610. _this = _super.call(this);
  9611. _this.map = {
  9612. 'a:hlinkClick': new HlickClickXform(),
  9613. 'a:extLst': new ExtLstXform()
  9614. };
  9615. return _this;
  9616. }
  9617. _createClass(CNvPrXform, [{
  9618. key: "render",
  9619. value: function render(xmlStream, model) {
  9620. xmlStream.openNode(this.tag, {
  9621. id: model.index,
  9622. name: "Picture ".concat(model.index)
  9623. });
  9624. this.map['a:hlinkClick'].render(xmlStream, model);
  9625. this.map['a:extLst'].render(xmlStream, model);
  9626. xmlStream.closeNode();
  9627. }
  9628. }, {
  9629. key: "parseOpen",
  9630. value: function parseOpen(node) {
  9631. if (this.parser) {
  9632. this.parser.parseOpen(node);
  9633. return true;
  9634. }
  9635. switch (node.name) {
  9636. case this.tag:
  9637. this.reset();
  9638. break;
  9639. default:
  9640. this.parser = this.map[node.name];
  9641. if (this.parser) {
  9642. this.parser.parseOpen(node);
  9643. }
  9644. break;
  9645. }
  9646. return true;
  9647. }
  9648. }, {
  9649. key: "parseText",
  9650. value: function parseText() {}
  9651. }, {
  9652. key: "parseClose",
  9653. value: function parseClose(name) {
  9654. if (this.parser) {
  9655. if (!this.parser.parseClose(name)) {
  9656. this.parser = undefined;
  9657. }
  9658. return true;
  9659. }
  9660. switch (name) {
  9661. case this.tag:
  9662. this.model = this.map['a:hlinkClick'].model;
  9663. return false;
  9664. default:
  9665. return true;
  9666. }
  9667. }
  9668. }, {
  9669. key: "tag",
  9670. get: function get() {
  9671. return 'xdr:cNvPr';
  9672. }
  9673. }]);
  9674. return CNvPrXform;
  9675. }(BaseXform);
  9676. module.exports = CNvPrXform;
  9677. },{"../base-xform":31,"./ext-lst-xform":62,"./hlink-click-xform":64}],60:[function(require,module,exports){
  9678. "use strict";
  9679. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  9680. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9681. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9682. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9683. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  9684. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9685. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  9686. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  9687. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9688. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  9689. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9690. var BaseXform = require('../base-xform');
  9691. var IntegerXform = require('../simple/integer-xform');
  9692. var CellPositionXform = /*#__PURE__*/function (_BaseXform) {
  9693. _inherits(CellPositionXform, _BaseXform);
  9694. var _super = _createSuper(CellPositionXform);
  9695. function CellPositionXform(options) {
  9696. var _this;
  9697. _classCallCheck(this, CellPositionXform);
  9698. _this = _super.call(this);
  9699. _this.tag = options.tag;
  9700. _this.map = {
  9701. 'xdr:col': new IntegerXform({
  9702. tag: 'xdr:col',
  9703. zero: true
  9704. }),
  9705. 'xdr:colOff': new IntegerXform({
  9706. tag: 'xdr:colOff',
  9707. zero: true
  9708. }),
  9709. 'xdr:row': new IntegerXform({
  9710. tag: 'xdr:row',
  9711. zero: true
  9712. }),
  9713. 'xdr:rowOff': new IntegerXform({
  9714. tag: 'xdr:rowOff',
  9715. zero: true
  9716. })
  9717. };
  9718. return _this;
  9719. }
  9720. _createClass(CellPositionXform, [{
  9721. key: "render",
  9722. value: function render(xmlStream, model) {
  9723. xmlStream.openNode(this.tag);
  9724. this.map['xdr:col'].render(xmlStream, model.nativeCol);
  9725. this.map['xdr:colOff'].render(xmlStream, model.nativeColOff);
  9726. this.map['xdr:row'].render(xmlStream, model.nativeRow);
  9727. this.map['xdr:rowOff'].render(xmlStream, model.nativeRowOff);
  9728. xmlStream.closeNode();
  9729. }
  9730. }, {
  9731. key: "parseOpen",
  9732. value: function parseOpen(node) {
  9733. if (this.parser) {
  9734. this.parser.parseOpen(node);
  9735. return true;
  9736. }
  9737. switch (node.name) {
  9738. case this.tag:
  9739. this.reset();
  9740. break;
  9741. default:
  9742. this.parser = this.map[node.name];
  9743. if (this.parser) {
  9744. this.parser.parseOpen(node);
  9745. }
  9746. break;
  9747. }
  9748. return true;
  9749. }
  9750. }, {
  9751. key: "parseText",
  9752. value: function parseText(text) {
  9753. if (this.parser) {
  9754. this.parser.parseText(text);
  9755. }
  9756. }
  9757. }, {
  9758. key: "parseClose",
  9759. value: function parseClose(name) {
  9760. if (this.parser) {
  9761. if (!this.parser.parseClose(name)) {
  9762. this.parser = undefined;
  9763. }
  9764. return true;
  9765. }
  9766. switch (name) {
  9767. case this.tag:
  9768. this.model = {
  9769. nativeCol: this.map['xdr:col'].model,
  9770. nativeColOff: this.map['xdr:colOff'].model,
  9771. nativeRow: this.map['xdr:row'].model,
  9772. nativeRowOff: this.map['xdr:rowOff'].model
  9773. };
  9774. return false;
  9775. default:
  9776. // not quite sure how we get here!
  9777. return true;
  9778. }
  9779. }
  9780. }]);
  9781. return CellPositionXform;
  9782. }(BaseXform);
  9783. module.exports = CellPositionXform;
  9784. },{"../base-xform":31,"../simple/integer-xform":117}],61:[function(require,module,exports){
  9785. "use strict";
  9786. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  9787. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9788. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9789. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9790. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  9791. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9792. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  9793. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  9794. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9795. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  9796. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9797. var colCache = require('../../../utils/col-cache');
  9798. var XmlStream = require('../../../utils/xml-stream');
  9799. var BaseXform = require('../base-xform');
  9800. var TwoCellAnchorXform = require('./two-cell-anchor-xform');
  9801. var OneCellAnchorXform = require('./one-cell-anchor-xform');
  9802. function getAnchorType(model) {
  9803. var range = typeof model.range === 'string' ? colCache.decode(model.range) : model.range;
  9804. return range.br ? 'xdr:twoCellAnchor' : 'xdr:oneCellAnchor';
  9805. }
  9806. var DrawingXform = /*#__PURE__*/function (_BaseXform) {
  9807. _inherits(DrawingXform, _BaseXform);
  9808. var _super = _createSuper(DrawingXform);
  9809. function DrawingXform() {
  9810. var _this;
  9811. _classCallCheck(this, DrawingXform);
  9812. _this = _super.call(this);
  9813. _this.map = {
  9814. 'xdr:twoCellAnchor': new TwoCellAnchorXform(),
  9815. 'xdr:oneCellAnchor': new OneCellAnchorXform()
  9816. };
  9817. return _this;
  9818. }
  9819. _createClass(DrawingXform, [{
  9820. key: "prepare",
  9821. value: function prepare(model) {
  9822. var _this2 = this;
  9823. model.anchors.forEach(function (item, index) {
  9824. item.anchorType = getAnchorType(item);
  9825. var anchor = _this2.map[item.anchorType];
  9826. anchor.prepare(item, {
  9827. index: index
  9828. });
  9829. });
  9830. }
  9831. }, {
  9832. key: "render",
  9833. value: function render(xmlStream, model) {
  9834. var _this3 = this;
  9835. xmlStream.openXml(XmlStream.StdDocAttributes);
  9836. xmlStream.openNode(this.tag, DrawingXform.DRAWING_ATTRIBUTES);
  9837. model.anchors.forEach(function (item) {
  9838. var anchor = _this3.map[item.anchorType];
  9839. anchor.render(xmlStream, item);
  9840. });
  9841. xmlStream.closeNode();
  9842. }
  9843. }, {
  9844. key: "parseOpen",
  9845. value: function parseOpen(node) {
  9846. if (this.parser) {
  9847. this.parser.parseOpen(node);
  9848. return true;
  9849. }
  9850. switch (node.name) {
  9851. case this.tag:
  9852. this.reset();
  9853. this.model = {
  9854. anchors: []
  9855. };
  9856. break;
  9857. default:
  9858. this.parser = this.map[node.name];
  9859. if (this.parser) {
  9860. this.parser.parseOpen(node);
  9861. }
  9862. break;
  9863. }
  9864. return true;
  9865. }
  9866. }, {
  9867. key: "parseText",
  9868. value: function parseText(text) {
  9869. if (this.parser) {
  9870. this.parser.parseText(text);
  9871. }
  9872. }
  9873. }, {
  9874. key: "parseClose",
  9875. value: function parseClose(name) {
  9876. if (this.parser) {
  9877. if (!this.parser.parseClose(name)) {
  9878. this.model.anchors.push(this.parser.model);
  9879. this.parser = undefined;
  9880. }
  9881. return true;
  9882. }
  9883. switch (name) {
  9884. case this.tag:
  9885. return false;
  9886. default:
  9887. // could be some unrecognised tags
  9888. return true;
  9889. }
  9890. }
  9891. }, {
  9892. key: "reconcile",
  9893. value: function reconcile(model, options) {
  9894. var _this4 = this;
  9895. model.anchors.forEach(function (anchor) {
  9896. if (anchor.br) {
  9897. _this4.map['xdr:twoCellAnchor'].reconcile(anchor, options);
  9898. } else {
  9899. _this4.map['xdr:oneCellAnchor'].reconcile(anchor, options);
  9900. }
  9901. });
  9902. }
  9903. }, {
  9904. key: "tag",
  9905. get: function get() {
  9906. return 'xdr:wsDr';
  9907. }
  9908. }]);
  9909. return DrawingXform;
  9910. }(BaseXform);
  9911. DrawingXform.DRAWING_ATTRIBUTES = {
  9912. 'xmlns:xdr': 'http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing',
  9913. 'xmlns:a': 'http://schemas.openxmlformats.org/drawingml/2006/main'
  9914. };
  9915. module.exports = DrawingXform;
  9916. },{"../../../utils/col-cache":19,"../../../utils/xml-stream":27,"../base-xform":31,"./one-cell-anchor-xform":66,"./two-cell-anchor-xform":69}],62:[function(require,module,exports){
  9917. "use strict";
  9918. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  9919. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9920. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9921. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9922. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  9923. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9924. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  9925. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  9926. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9927. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  9928. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9929. var BaseXform = require('../base-xform');
  9930. var ExtLstXform = /*#__PURE__*/function (_BaseXform) {
  9931. _inherits(ExtLstXform, _BaseXform);
  9932. var _super = _createSuper(ExtLstXform);
  9933. function ExtLstXform() {
  9934. _classCallCheck(this, ExtLstXform);
  9935. return _super.apply(this, arguments);
  9936. }
  9937. _createClass(ExtLstXform, [{
  9938. key: "render",
  9939. value: function render(xmlStream) {
  9940. xmlStream.openNode(this.tag);
  9941. xmlStream.openNode('a:ext', {
  9942. uri: '{FF2B5EF4-FFF2-40B4-BE49-F238E27FC236}'
  9943. });
  9944. xmlStream.leafNode('a16:creationId', {
  9945. 'xmlns:a16': 'http://schemas.microsoft.com/office/drawing/2014/main',
  9946. id: '{00000000-0008-0000-0000-000002000000}'
  9947. });
  9948. xmlStream.closeNode();
  9949. xmlStream.closeNode();
  9950. }
  9951. }, {
  9952. key: "parseOpen",
  9953. value: function parseOpen(node) {
  9954. switch (node.name) {
  9955. case this.tag:
  9956. return true;
  9957. default:
  9958. return true;
  9959. }
  9960. }
  9961. }, {
  9962. key: "parseText",
  9963. value: function parseText() {}
  9964. }, {
  9965. key: "parseClose",
  9966. value: function parseClose(name) {
  9967. switch (name) {
  9968. case this.tag:
  9969. return false;
  9970. default:
  9971. // unprocessed internal nodes
  9972. return true;
  9973. }
  9974. }
  9975. }, {
  9976. key: "tag",
  9977. get: function get() {
  9978. return 'a:extLst';
  9979. }
  9980. }]);
  9981. return ExtLstXform;
  9982. }(BaseXform);
  9983. module.exports = ExtLstXform;
  9984. },{"../base-xform":31}],63:[function(require,module,exports){
  9985. "use strict";
  9986. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  9987. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9988. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9989. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9990. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  9991. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9992. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  9993. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  9994. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9995. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  9996. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9997. var BaseXform = require('../base-xform');
  9998. /** https://en.wikipedia.org/wiki/Office_Open_XML_file_formats#DrawingML */
  9999. var EMU_PER_PIXEL_AT_96_DPI = 9525;
  10000. var ExtXform = /*#__PURE__*/function (_BaseXform) {
  10001. _inherits(ExtXform, _BaseXform);
  10002. var _super = _createSuper(ExtXform);
  10003. function ExtXform(options) {
  10004. var _this;
  10005. _classCallCheck(this, ExtXform);
  10006. _this = _super.call(this);
  10007. _this.tag = options.tag;
  10008. _this.map = {};
  10009. return _this;
  10010. }
  10011. _createClass(ExtXform, [{
  10012. key: "render",
  10013. value: function render(xmlStream, model) {
  10014. xmlStream.openNode(this.tag);
  10015. var width = Math.floor(model.width * EMU_PER_PIXEL_AT_96_DPI);
  10016. var height = Math.floor(model.height * EMU_PER_PIXEL_AT_96_DPI);
  10017. xmlStream.addAttribute('cx', width);
  10018. xmlStream.addAttribute('cy', height);
  10019. xmlStream.closeNode();
  10020. }
  10021. }, {
  10022. key: "parseOpen",
  10023. value: function parseOpen(node) {
  10024. if (node.name === this.tag) {
  10025. this.model = {
  10026. width: parseInt(node.attributes.cx || '0', 10) / EMU_PER_PIXEL_AT_96_DPI,
  10027. height: parseInt(node.attributes.cy || '0', 10) / EMU_PER_PIXEL_AT_96_DPI
  10028. };
  10029. return true;
  10030. }
  10031. return false;
  10032. }
  10033. }, {
  10034. key: "parseText",
  10035. value: function parseText()
  10036. /* text */
  10037. {}
  10038. }, {
  10039. key: "parseClose",
  10040. value: function parseClose()
  10041. /* name */
  10042. {
  10043. return false;
  10044. }
  10045. }]);
  10046. return ExtXform;
  10047. }(BaseXform);
  10048. module.exports = ExtXform;
  10049. },{"../base-xform":31}],64:[function(require,module,exports){
  10050. "use strict";
  10051. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  10052. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10053. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  10054. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  10055. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  10056. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  10057. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  10058. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  10059. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  10060. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  10061. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  10062. var BaseXform = require('../base-xform');
  10063. var HLinkClickXform = /*#__PURE__*/function (_BaseXform) {
  10064. _inherits(HLinkClickXform, _BaseXform);
  10065. var _super = _createSuper(HLinkClickXform);
  10066. function HLinkClickXform() {
  10067. _classCallCheck(this, HLinkClickXform);
  10068. return _super.apply(this, arguments);
  10069. }
  10070. _createClass(HLinkClickXform, [{
  10071. key: "render",
  10072. value: function render(xmlStream, model) {
  10073. if (!(model.hyperlinks && model.hyperlinks.rId)) {
  10074. return;
  10075. }
  10076. xmlStream.leafNode(this.tag, {
  10077. 'xmlns:r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
  10078. 'r:id': model.hyperlinks.rId,
  10079. tooltip: model.hyperlinks.tooltip
  10080. });
  10081. }
  10082. }, {
  10083. key: "parseOpen",
  10084. value: function parseOpen(node) {
  10085. switch (node.name) {
  10086. case this.tag:
  10087. this.model = {
  10088. hyperlinks: {
  10089. rId: node.attributes['r:id'],
  10090. tooltip: node.attributes.tooltip
  10091. }
  10092. };
  10093. return true;
  10094. default:
  10095. return true;
  10096. }
  10097. }
  10098. }, {
  10099. key: "parseText",
  10100. value: function parseText() {}
  10101. }, {
  10102. key: "parseClose",
  10103. value: function parseClose() {
  10104. return false;
  10105. }
  10106. }, {
  10107. key: "tag",
  10108. get: function get() {
  10109. return 'a:hlinkClick';
  10110. }
  10111. }]);
  10112. return HLinkClickXform;
  10113. }(BaseXform);
  10114. module.exports = HLinkClickXform;
  10115. },{"../base-xform":31}],65:[function(require,module,exports){
  10116. "use strict";
  10117. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  10118. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10119. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  10120. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  10121. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  10122. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  10123. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  10124. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  10125. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  10126. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  10127. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  10128. var BaseXform = require('../base-xform');
  10129. var CNvPrXform = require('./c-nv-pr-xform');
  10130. var CNvPicPrXform = require('./c-nv-pic-pr-xform');
  10131. var NvPicPrXform = /*#__PURE__*/function (_BaseXform) {
  10132. _inherits(NvPicPrXform, _BaseXform);
  10133. var _super = _createSuper(NvPicPrXform);
  10134. function NvPicPrXform() {
  10135. var _this;
  10136. _classCallCheck(this, NvPicPrXform);
  10137. _this = _super.call(this);
  10138. _this.map = {
  10139. 'xdr:cNvPr': new CNvPrXform(),
  10140. 'xdr:cNvPicPr': new CNvPicPrXform()
  10141. };
  10142. return _this;
  10143. }
  10144. _createClass(NvPicPrXform, [{
  10145. key: "render",
  10146. value: function render(xmlStream, model) {
  10147. xmlStream.openNode(this.tag);
  10148. this.map['xdr:cNvPr'].render(xmlStream, model);
  10149. this.map['xdr:cNvPicPr'].render(xmlStream, model);
  10150. xmlStream.closeNode();
  10151. }
  10152. }, {
  10153. key: "parseOpen",
  10154. value: function parseOpen(node) {
  10155. if (this.parser) {
  10156. this.parser.parseOpen(node);
  10157. return true;
  10158. }
  10159. switch (node.name) {
  10160. case this.tag:
  10161. this.reset();
  10162. break;
  10163. default:
  10164. this.parser = this.map[node.name];
  10165. if (this.parser) {
  10166. this.parser.parseOpen(node);
  10167. }
  10168. break;
  10169. }
  10170. return true;
  10171. }
  10172. }, {
  10173. key: "parseText",
  10174. value: function parseText() {}
  10175. }, {
  10176. key: "parseClose",
  10177. value: function parseClose(name) {
  10178. if (this.parser) {
  10179. if (!this.parser.parseClose(name)) {
  10180. this.parser = undefined;
  10181. }
  10182. return true;
  10183. }
  10184. switch (name) {
  10185. case this.tag:
  10186. this.model = this.map['xdr:cNvPr'].model;
  10187. return false;
  10188. default:
  10189. return true;
  10190. }
  10191. }
  10192. }, {
  10193. key: "tag",
  10194. get: function get() {
  10195. return 'xdr:nvPicPr';
  10196. }
  10197. }]);
  10198. return NvPicPrXform;
  10199. }(BaseXform);
  10200. module.exports = NvPicPrXform;
  10201. },{"../base-xform":31,"./c-nv-pic-pr-xform":58,"./c-nv-pr-xform":59}],66:[function(require,module,exports){
  10202. "use strict";
  10203. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  10204. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10205. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  10206. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  10207. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  10208. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  10209. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  10210. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  10211. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  10212. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  10213. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  10214. var BaseCellAnchorXform = require('./base-cell-anchor-xform');
  10215. var StaticXform = require('../static-xform');
  10216. var CellPositionXform = require('./cell-position-xform');
  10217. var ExtXform = require('./ext-xform');
  10218. var PicXform = require('./pic-xform');
  10219. var OneCellAnchorXform = /*#__PURE__*/function (_BaseCellAnchorXform) {
  10220. _inherits(OneCellAnchorXform, _BaseCellAnchorXform);
  10221. var _super = _createSuper(OneCellAnchorXform);
  10222. function OneCellAnchorXform() {
  10223. var _this;
  10224. _classCallCheck(this, OneCellAnchorXform);
  10225. _this = _super.call(this);
  10226. _this.map = {
  10227. 'xdr:from': new CellPositionXform({
  10228. tag: 'xdr:from'
  10229. }),
  10230. 'xdr:ext': new ExtXform({
  10231. tag: 'xdr:ext'
  10232. }),
  10233. 'xdr:pic': new PicXform(),
  10234. 'xdr:clientData': new StaticXform({
  10235. tag: 'xdr:clientData'
  10236. })
  10237. };
  10238. return _this;
  10239. }
  10240. _createClass(OneCellAnchorXform, [{
  10241. key: "prepare",
  10242. value: function prepare(model, options) {
  10243. this.map['xdr:pic'].prepare(model.picture, options);
  10244. }
  10245. }, {
  10246. key: "render",
  10247. value: function render(xmlStream, model) {
  10248. xmlStream.openNode(this.tag, {
  10249. editAs: model.range.editAs || 'oneCell'
  10250. });
  10251. this.map['xdr:from'].render(xmlStream, model.range.tl);
  10252. this.map['xdr:ext'].render(xmlStream, model.range.ext);
  10253. this.map['xdr:pic'].render(xmlStream, model.picture);
  10254. this.map['xdr:clientData'].render(xmlStream, {});
  10255. xmlStream.closeNode();
  10256. }
  10257. }, {
  10258. key: "parseClose",
  10259. value: function parseClose(name) {
  10260. if (this.parser) {
  10261. if (!this.parser.parseClose(name)) {
  10262. this.parser = undefined;
  10263. }
  10264. return true;
  10265. }
  10266. switch (name) {
  10267. case this.tag:
  10268. this.model.range.tl = this.map['xdr:from'].model;
  10269. this.model.range.ext = this.map['xdr:ext'].model;
  10270. this.model.picture = this.map['xdr:pic'].model;
  10271. return false;
  10272. default:
  10273. // could be some unrecognised tags
  10274. return true;
  10275. }
  10276. }
  10277. }, {
  10278. key: "reconcile",
  10279. value: function reconcile(model, options) {
  10280. model.medium = this.reconcilePicture(model.picture, options);
  10281. }
  10282. }, {
  10283. key: "tag",
  10284. get: function get() {
  10285. return 'xdr:oneCellAnchor';
  10286. }
  10287. }]);
  10288. return OneCellAnchorXform;
  10289. }(BaseCellAnchorXform);
  10290. module.exports = OneCellAnchorXform;
  10291. },{"../static-xform":119,"./base-cell-anchor-xform":55,"./cell-position-xform":60,"./ext-xform":63,"./pic-xform":67}],67:[function(require,module,exports){
  10292. "use strict";
  10293. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  10294. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10295. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  10296. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  10297. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  10298. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  10299. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  10300. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  10301. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  10302. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  10303. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  10304. var BaseXform = require('../base-xform');
  10305. var StaticXform = require('../static-xform');
  10306. var BlipFillXform = require('./blip-fill-xform');
  10307. var NvPicPrXform = require('./nv-pic-pr-xform');
  10308. var spPrJSON = require('./sp-pr');
  10309. var PicXform = /*#__PURE__*/function (_BaseXform) {
  10310. _inherits(PicXform, _BaseXform);
  10311. var _super = _createSuper(PicXform);
  10312. function PicXform() {
  10313. var _this;
  10314. _classCallCheck(this, PicXform);
  10315. _this = _super.call(this);
  10316. _this.map = {
  10317. 'xdr:nvPicPr': new NvPicPrXform(),
  10318. 'xdr:blipFill': new BlipFillXform(),
  10319. 'xdr:spPr': new StaticXform(spPrJSON)
  10320. };
  10321. return _this;
  10322. }
  10323. _createClass(PicXform, [{
  10324. key: "prepare",
  10325. value: function prepare(model, options) {
  10326. model.index = options.index + 1;
  10327. }
  10328. }, {
  10329. key: "render",
  10330. value: function render(xmlStream, model) {
  10331. xmlStream.openNode(this.tag);
  10332. this.map['xdr:nvPicPr'].render(xmlStream, model);
  10333. this.map['xdr:blipFill'].render(xmlStream, model);
  10334. this.map['xdr:spPr'].render(xmlStream, model);
  10335. xmlStream.closeNode();
  10336. }
  10337. }, {
  10338. key: "parseOpen",
  10339. value: function parseOpen(node) {
  10340. if (this.parser) {
  10341. this.parser.parseOpen(node);
  10342. return true;
  10343. }
  10344. switch (node.name) {
  10345. case this.tag:
  10346. this.reset();
  10347. break;
  10348. default:
  10349. this.parser = this.map[node.name];
  10350. if (this.parser) {
  10351. this.parser.parseOpen(node);
  10352. }
  10353. break;
  10354. }
  10355. return true;
  10356. }
  10357. }, {
  10358. key: "parseText",
  10359. value: function parseText() {}
  10360. }, {
  10361. key: "parseClose",
  10362. value: function parseClose(name) {
  10363. if (this.parser) {
  10364. if (!this.parser.parseClose(name)) {
  10365. this.mergeModel(this.parser.model);
  10366. this.parser = undefined;
  10367. }
  10368. return true;
  10369. }
  10370. switch (name) {
  10371. case this.tag:
  10372. return false;
  10373. default:
  10374. // not quite sure how we get here!
  10375. return true;
  10376. }
  10377. }
  10378. }, {
  10379. key: "tag",
  10380. get: function get() {
  10381. return 'xdr:pic';
  10382. }
  10383. }]);
  10384. return PicXform;
  10385. }(BaseXform);
  10386. module.exports = PicXform;
  10387. },{"../base-xform":31,"../static-xform":119,"./blip-fill-xform":56,"./nv-pic-pr-xform":65,"./sp-pr":68}],68:[function(require,module,exports){
  10388. "use strict";
  10389. module.exports = {
  10390. tag: 'xdr:spPr',
  10391. c: [{
  10392. tag: 'a:xfrm',
  10393. c: [{
  10394. tag: 'a:off',
  10395. $: {
  10396. x: '0',
  10397. y: '0'
  10398. }
  10399. }, {
  10400. tag: 'a:ext',
  10401. $: {
  10402. cx: '0',
  10403. cy: '0'
  10404. }
  10405. }]
  10406. }, {
  10407. tag: 'a:prstGeom',
  10408. $: {
  10409. prst: 'rect'
  10410. },
  10411. c: [{
  10412. tag: 'a:avLst'
  10413. }]
  10414. }]
  10415. };
  10416. },{}],69:[function(require,module,exports){
  10417. "use strict";
  10418. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  10419. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10420. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  10421. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  10422. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  10423. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  10424. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  10425. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  10426. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  10427. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  10428. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  10429. var BaseCellAnchorXform = require('./base-cell-anchor-xform');
  10430. var StaticXform = require('../static-xform');
  10431. var CellPositionXform = require('./cell-position-xform');
  10432. var PicXform = require('./pic-xform');
  10433. var TwoCellAnchorXform = /*#__PURE__*/function (_BaseCellAnchorXform) {
  10434. _inherits(TwoCellAnchorXform, _BaseCellAnchorXform);
  10435. var _super = _createSuper(TwoCellAnchorXform);
  10436. function TwoCellAnchorXform() {
  10437. var _this;
  10438. _classCallCheck(this, TwoCellAnchorXform);
  10439. _this = _super.call(this);
  10440. _this.map = {
  10441. 'xdr:from': new CellPositionXform({
  10442. tag: 'xdr:from'
  10443. }),
  10444. 'xdr:to': new CellPositionXform({
  10445. tag: 'xdr:to'
  10446. }),
  10447. 'xdr:pic': new PicXform(),
  10448. 'xdr:clientData': new StaticXform({
  10449. tag: 'xdr:clientData'
  10450. })
  10451. };
  10452. return _this;
  10453. }
  10454. _createClass(TwoCellAnchorXform, [{
  10455. key: "prepare",
  10456. value: function prepare(model, options) {
  10457. this.map['xdr:pic'].prepare(model.picture, options);
  10458. }
  10459. }, {
  10460. key: "render",
  10461. value: function render(xmlStream, model) {
  10462. xmlStream.openNode(this.tag, {
  10463. editAs: model.range.editAs || 'oneCell'
  10464. });
  10465. this.map['xdr:from'].render(xmlStream, model.range.tl);
  10466. this.map['xdr:to'].render(xmlStream, model.range.br);
  10467. this.map['xdr:pic'].render(xmlStream, model.picture);
  10468. this.map['xdr:clientData'].render(xmlStream, {});
  10469. xmlStream.closeNode();
  10470. }
  10471. }, {
  10472. key: "parseClose",
  10473. value: function parseClose(name) {
  10474. if (this.parser) {
  10475. if (!this.parser.parseClose(name)) {
  10476. this.parser = undefined;
  10477. }
  10478. return true;
  10479. }
  10480. switch (name) {
  10481. case this.tag:
  10482. this.model.range.tl = this.map['xdr:from'].model;
  10483. this.model.range.br = this.map['xdr:to'].model;
  10484. this.model.picture = this.map['xdr:pic'].model;
  10485. return false;
  10486. default:
  10487. // could be some unrecognised tags
  10488. return true;
  10489. }
  10490. }
  10491. }, {
  10492. key: "reconcile",
  10493. value: function reconcile(model, options) {
  10494. model.medium = this.reconcilePicture(model.picture, options);
  10495. }
  10496. }, {
  10497. key: "tag",
  10498. get: function get() {
  10499. return 'xdr:twoCellAnchor';
  10500. }
  10501. }]);
  10502. return TwoCellAnchorXform;
  10503. }(BaseCellAnchorXform);
  10504. module.exports = TwoCellAnchorXform;
  10505. },{"../static-xform":119,"./base-cell-anchor-xform":55,"./cell-position-xform":60,"./pic-xform":67}],70:[function(require,module,exports){
  10506. "use strict";
  10507. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  10508. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10509. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  10510. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  10511. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  10512. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  10513. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  10514. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  10515. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  10516. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  10517. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  10518. var BaseXform = require('./base-xform');
  10519. var ListXform = /*#__PURE__*/function (_BaseXform) {
  10520. _inherits(ListXform, _BaseXform);
  10521. var _super = _createSuper(ListXform);
  10522. function ListXform(options) {
  10523. var _this;
  10524. _classCallCheck(this, ListXform);
  10525. _this = _super.call(this);
  10526. _this.tag = options.tag;
  10527. _this.always = !!options.always;
  10528. _this.count = options.count;
  10529. _this.empty = options.empty;
  10530. _this.$count = options.$count || 'count';
  10531. _this.$ = options.$;
  10532. _this.childXform = options.childXform;
  10533. _this.maxItems = options.maxItems;
  10534. return _this;
  10535. }
  10536. _createClass(ListXform, [{
  10537. key: "prepare",
  10538. value: function prepare(model, options) {
  10539. var childXform = this.childXform;
  10540. if (model) {
  10541. model.forEach(function (childModel, index) {
  10542. options.index = index;
  10543. childXform.prepare(childModel, options);
  10544. });
  10545. }
  10546. }
  10547. }, {
  10548. key: "render",
  10549. value: function render(xmlStream, model) {
  10550. if (this.always || model && model.length) {
  10551. xmlStream.openNode(this.tag, this.$);
  10552. if (this.count) {
  10553. xmlStream.addAttribute(this.$count, model && model.length || 0);
  10554. }
  10555. var childXform = this.childXform;
  10556. (model || []).forEach(function (childModel, index) {
  10557. childXform.render(xmlStream, childModel, index);
  10558. });
  10559. xmlStream.closeNode();
  10560. } else if (this.empty) {
  10561. xmlStream.leafNode(this.tag);
  10562. }
  10563. }
  10564. }, {
  10565. key: "parseOpen",
  10566. value: function parseOpen(node) {
  10567. if (this.parser) {
  10568. this.parser.parseOpen(node);
  10569. return true;
  10570. }
  10571. switch (node.name) {
  10572. case this.tag:
  10573. this.model = [];
  10574. return true;
  10575. default:
  10576. if (this.childXform.parseOpen(node)) {
  10577. this.parser = this.childXform;
  10578. return true;
  10579. }
  10580. return false;
  10581. }
  10582. }
  10583. }, {
  10584. key: "parseText",
  10585. value: function parseText(text) {
  10586. if (this.parser) {
  10587. this.parser.parseText(text);
  10588. }
  10589. }
  10590. }, {
  10591. key: "parseClose",
  10592. value: function parseClose(name) {
  10593. if (this.parser) {
  10594. if (!this.parser.parseClose(name)) {
  10595. this.model.push(this.parser.model);
  10596. this.parser = undefined;
  10597. if (this.maxItems && this.model.length > this.maxItems) {
  10598. throw new Error("Max ".concat(this.childXform.tag, " count (").concat(this.maxItems, ") exceeded"));
  10599. }
  10600. }
  10601. return true;
  10602. }
  10603. return false;
  10604. }
  10605. }, {
  10606. key: "reconcile",
  10607. value: function reconcile(model, options) {
  10608. if (model) {
  10609. var childXform = this.childXform;
  10610. model.forEach(function (childModel) {
  10611. childXform.reconcile(childModel, options);
  10612. });
  10613. }
  10614. }
  10615. }]);
  10616. return ListXform;
  10617. }(BaseXform);
  10618. module.exports = ListXform;
  10619. },{"./base-xform":31}],71:[function(require,module,exports){
  10620. "use strict";
  10621. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  10622. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10623. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  10624. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  10625. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  10626. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  10627. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  10628. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  10629. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  10630. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  10631. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  10632. var colCache = require('../../../utils/col-cache');
  10633. var BaseXform = require('../base-xform');
  10634. var AutoFilterXform = /*#__PURE__*/function (_BaseXform) {
  10635. _inherits(AutoFilterXform, _BaseXform);
  10636. var _super = _createSuper(AutoFilterXform);
  10637. function AutoFilterXform() {
  10638. _classCallCheck(this, AutoFilterXform);
  10639. return _super.apply(this, arguments);
  10640. }
  10641. _createClass(AutoFilterXform, [{
  10642. key: "render",
  10643. value: function render(xmlStream, model) {
  10644. if (model) {
  10645. if (typeof model === 'string') {
  10646. // assume range
  10647. xmlStream.leafNode('autoFilter', {
  10648. ref: model
  10649. });
  10650. } else {
  10651. var getAddress = function getAddress(addr) {
  10652. if (typeof addr === 'string') {
  10653. return addr;
  10654. }
  10655. return colCache.getAddress(addr.row, addr.column).address;
  10656. };
  10657. var firstAddress = getAddress(model.from);
  10658. var secondAddress = getAddress(model.to);
  10659. if (firstAddress && secondAddress) {
  10660. xmlStream.leafNode('autoFilter', {
  10661. ref: "".concat(firstAddress, ":").concat(secondAddress)
  10662. });
  10663. }
  10664. }
  10665. }
  10666. }
  10667. }, {
  10668. key: "parseOpen",
  10669. value: function parseOpen(node) {
  10670. if (node.name === 'autoFilter') {
  10671. this.model = node.attributes.ref;
  10672. }
  10673. }
  10674. }, {
  10675. key: "tag",
  10676. get: function get() {
  10677. return 'autoFilter';
  10678. }
  10679. }]);
  10680. return AutoFilterXform;
  10681. }(BaseXform);
  10682. module.exports = AutoFilterXform;
  10683. },{"../../../utils/col-cache":19,"../base-xform":31}],72:[function(require,module,exports){
  10684. "use strict";
  10685. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  10686. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  10687. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  10688. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  10689. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10690. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  10691. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  10692. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  10693. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  10694. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  10695. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  10696. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  10697. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  10698. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  10699. var utils = require('../../../utils/utils');
  10700. var BaseXform = require('../base-xform');
  10701. var Range = require('../../../doc/range');
  10702. var Enums = require('../../../doc/enums');
  10703. var RichTextXform = require('../strings/rich-text-xform');
  10704. function getValueType(v) {
  10705. if (v === null || v === undefined) {
  10706. return Enums.ValueType.Null;
  10707. }
  10708. if (v instanceof String || typeof v === 'string') {
  10709. return Enums.ValueType.String;
  10710. }
  10711. if (typeof v === 'number') {
  10712. return Enums.ValueType.Number;
  10713. }
  10714. if (typeof v === 'boolean') {
  10715. return Enums.ValueType.Boolean;
  10716. }
  10717. if (v instanceof Date) {
  10718. return Enums.ValueType.Date;
  10719. }
  10720. if (v.text && v.hyperlink) {
  10721. return Enums.ValueType.Hyperlink;
  10722. }
  10723. if (v.formula) {
  10724. return Enums.ValueType.Formula;
  10725. }
  10726. if (v.error) {
  10727. return Enums.ValueType.Error;
  10728. }
  10729. throw new Error('I could not understand type of value');
  10730. }
  10731. function getEffectiveCellType(cell) {
  10732. switch (cell.type) {
  10733. case Enums.ValueType.Formula:
  10734. return getValueType(cell.result);
  10735. default:
  10736. return cell.type;
  10737. }
  10738. }
  10739. var CellXform = /*#__PURE__*/function (_BaseXform) {
  10740. _inherits(CellXform, _BaseXform);
  10741. var _super = _createSuper(CellXform);
  10742. function CellXform() {
  10743. var _this;
  10744. _classCallCheck(this, CellXform);
  10745. _this = _super.call(this);
  10746. _this.richTextXForm = new RichTextXform();
  10747. return _this;
  10748. }
  10749. _createClass(CellXform, [{
  10750. key: "prepare",
  10751. value: function prepare(model, options) {
  10752. var styleId = options.styles.addStyleModel(model.style || {}, getEffectiveCellType(model));
  10753. if (styleId) {
  10754. model.styleId = styleId;
  10755. }
  10756. if (model.comment) {
  10757. options.comments.push(_objectSpread(_objectSpread({}, model.comment), {}, {
  10758. ref: model.address
  10759. }));
  10760. }
  10761. switch (model.type) {
  10762. case Enums.ValueType.String:
  10763. case Enums.ValueType.RichText:
  10764. if (options.sharedStrings) {
  10765. model.ssId = options.sharedStrings.add(model.value);
  10766. }
  10767. break;
  10768. case Enums.ValueType.Date:
  10769. if (options.date1904) {
  10770. model.date1904 = true;
  10771. }
  10772. break;
  10773. case Enums.ValueType.Hyperlink:
  10774. if (options.sharedStrings && model.text !== undefined && model.text !== null) {
  10775. model.ssId = options.sharedStrings.add(model.text);
  10776. }
  10777. options.hyperlinks.push({
  10778. address: model.address,
  10779. target: model.hyperlink,
  10780. tooltip: model.tooltip
  10781. });
  10782. break;
  10783. case Enums.ValueType.Merge:
  10784. options.merges.add(model);
  10785. break;
  10786. case Enums.ValueType.Formula:
  10787. if (options.date1904) {
  10788. // in case valueType is date
  10789. model.date1904 = true;
  10790. }
  10791. if (model.shareType === 'shared') {
  10792. model.si = options.siFormulae++;
  10793. }
  10794. if (model.formula) {
  10795. options.formulae[model.address] = model;
  10796. } else if (model.sharedFormula) {
  10797. var master = options.formulae[model.sharedFormula];
  10798. if (!master) {
  10799. throw new Error("Shared Formula master must exist above and or left of clone for cell ".concat(model.address));
  10800. }
  10801. if (master.si === undefined) {
  10802. master.shareType = 'shared';
  10803. master.si = options.siFormulae++;
  10804. master.range = new Range(master.address, model.address);
  10805. } else if (master.range) {
  10806. master.range.expandToAddress(model.address);
  10807. }
  10808. model.si = master.si;
  10809. }
  10810. break;
  10811. default:
  10812. break;
  10813. }
  10814. }
  10815. }, {
  10816. key: "renderFormula",
  10817. value: function renderFormula(xmlStream, model) {
  10818. var attrs = null;
  10819. switch (model.shareType) {
  10820. case 'shared':
  10821. attrs = {
  10822. t: 'shared',
  10823. ref: model.ref || model.range.range,
  10824. si: model.si
  10825. };
  10826. break;
  10827. case 'array':
  10828. attrs = {
  10829. t: 'array',
  10830. ref: model.ref
  10831. };
  10832. break;
  10833. default:
  10834. if (model.si !== undefined) {
  10835. attrs = {
  10836. t: 'shared',
  10837. si: model.si
  10838. };
  10839. }
  10840. break;
  10841. }
  10842. switch (getValueType(model.result)) {
  10843. case Enums.ValueType.Null:
  10844. // ?
  10845. xmlStream.leafNode('f', attrs, model.formula);
  10846. break;
  10847. case Enums.ValueType.String:
  10848. // oddly, formula results don't ever use shared strings
  10849. xmlStream.addAttribute('t', 'str');
  10850. xmlStream.leafNode('f', attrs, model.formula);
  10851. xmlStream.leafNode('v', null, model.result);
  10852. break;
  10853. case Enums.ValueType.Number:
  10854. xmlStream.leafNode('f', attrs, model.formula);
  10855. xmlStream.leafNode('v', null, model.result);
  10856. break;
  10857. case Enums.ValueType.Boolean:
  10858. xmlStream.addAttribute('t', 'b');
  10859. xmlStream.leafNode('f', attrs, model.formula);
  10860. xmlStream.leafNode('v', null, model.result ? 1 : 0);
  10861. break;
  10862. case Enums.ValueType.Error:
  10863. xmlStream.addAttribute('t', 'e');
  10864. xmlStream.leafNode('f', attrs, model.formula);
  10865. xmlStream.leafNode('v', null, model.result.error);
  10866. break;
  10867. case Enums.ValueType.Date:
  10868. xmlStream.leafNode('f', attrs, model.formula);
  10869. xmlStream.leafNode('v', null, utils.dateToExcel(model.result, model.date1904));
  10870. break;
  10871. // case Enums.ValueType.Hyperlink: // ??
  10872. // case Enums.ValueType.Formula:
  10873. default:
  10874. throw new Error('I could not understand type of value');
  10875. }
  10876. }
  10877. }, {
  10878. key: "render",
  10879. value: function render(xmlStream, model) {
  10880. var _this2 = this;
  10881. if (model.type === Enums.ValueType.Null && !model.styleId) {
  10882. // if null and no style, exit
  10883. return;
  10884. }
  10885. xmlStream.openNode('c');
  10886. xmlStream.addAttribute('r', model.address);
  10887. if (model.styleId) {
  10888. xmlStream.addAttribute('s', model.styleId);
  10889. }
  10890. switch (model.type) {
  10891. case Enums.ValueType.Null:
  10892. break;
  10893. case Enums.ValueType.Number:
  10894. xmlStream.leafNode('v', null, model.value);
  10895. break;
  10896. case Enums.ValueType.Boolean:
  10897. xmlStream.addAttribute('t', 'b');
  10898. xmlStream.leafNode('v', null, model.value ? '1' : '0');
  10899. break;
  10900. case Enums.ValueType.Error:
  10901. xmlStream.addAttribute('t', 'e');
  10902. xmlStream.leafNode('v', null, model.value.error);
  10903. break;
  10904. case Enums.ValueType.String:
  10905. case Enums.ValueType.RichText:
  10906. if (model.ssId !== undefined) {
  10907. xmlStream.addAttribute('t', 's');
  10908. xmlStream.leafNode('v', null, model.ssId);
  10909. } else if (model.value && model.value.richText) {
  10910. xmlStream.addAttribute('t', 'inlineStr');
  10911. xmlStream.openNode('is');
  10912. model.value.richText.forEach(function (text) {
  10913. _this2.richTextXForm.render(xmlStream, text);
  10914. });
  10915. xmlStream.closeNode('is');
  10916. } else {
  10917. xmlStream.addAttribute('t', 'str');
  10918. xmlStream.leafNode('v', null, model.value);
  10919. }
  10920. break;
  10921. case Enums.ValueType.Date:
  10922. xmlStream.leafNode('v', null, utils.dateToExcel(model.value, model.date1904));
  10923. break;
  10924. case Enums.ValueType.Hyperlink:
  10925. if (model.ssId !== undefined) {
  10926. xmlStream.addAttribute('t', 's');
  10927. xmlStream.leafNode('v', null, model.ssId);
  10928. } else {
  10929. xmlStream.addAttribute('t', 'str');
  10930. xmlStream.leafNode('v', null, model.text);
  10931. }
  10932. break;
  10933. case Enums.ValueType.Formula:
  10934. this.renderFormula(xmlStream, model);
  10935. break;
  10936. case Enums.ValueType.Merge:
  10937. // nothing to add
  10938. break;
  10939. default:
  10940. break;
  10941. }
  10942. xmlStream.closeNode(); // </c>
  10943. }
  10944. }, {
  10945. key: "parseOpen",
  10946. value: function parseOpen(node) {
  10947. if (this.parser) {
  10948. this.parser.parseOpen(node);
  10949. return true;
  10950. }
  10951. switch (node.name) {
  10952. case 'c':
  10953. // const address = colCache.decodeAddress(node.attributes.r);
  10954. this.model = {
  10955. address: node.attributes.r
  10956. };
  10957. this.t = node.attributes.t;
  10958. if (node.attributes.s) {
  10959. this.model.styleId = parseInt(node.attributes.s, 10);
  10960. }
  10961. return true;
  10962. case 'f':
  10963. this.currentNode = 'f';
  10964. this.model.si = node.attributes.si;
  10965. this.model.shareType = node.attributes.t;
  10966. this.model.ref = node.attributes.ref;
  10967. return true;
  10968. case 'v':
  10969. this.currentNode = 'v';
  10970. return true;
  10971. case 't':
  10972. this.currentNode = 't';
  10973. return true;
  10974. case 'r':
  10975. this.parser = this.richTextXForm;
  10976. this.parser.parseOpen(node);
  10977. return true;
  10978. default:
  10979. return false;
  10980. }
  10981. }
  10982. }, {
  10983. key: "parseText",
  10984. value: function parseText(text) {
  10985. if (this.parser) {
  10986. this.parser.parseText(text);
  10987. return;
  10988. }
  10989. switch (this.currentNode) {
  10990. case 'f':
  10991. this.model.formula = this.model.formula ? this.model.formula + text : text;
  10992. break;
  10993. case 'v':
  10994. case 't':
  10995. if (this.model.value && this.model.value.richText) {
  10996. this.model.value.richText.text = this.model.value.richText.text ? this.model.value.richText.text + text : text;
  10997. } else {
  10998. this.model.value = this.model.value ? this.model.value + text : text;
  10999. }
  11000. break;
  11001. default:
  11002. break;
  11003. }
  11004. }
  11005. }, {
  11006. key: "parseClose",
  11007. value: function parseClose(name) {
  11008. switch (name) {
  11009. case 'c':
  11010. {
  11011. var model = this.model; // first guess on cell type
  11012. if (model.formula || model.shareType) {
  11013. model.type = Enums.ValueType.Formula;
  11014. if (model.value) {
  11015. if (this.t === 'str') {
  11016. model.result = utils.xmlDecode(model.value);
  11017. } else if (this.t === 'b') {
  11018. model.result = parseInt(model.value, 10) !== 0;
  11019. } else if (this.t === 'e') {
  11020. model.result = {
  11021. error: model.value
  11022. };
  11023. } else {
  11024. model.result = parseFloat(model.value);
  11025. }
  11026. model.value = undefined;
  11027. }
  11028. } else if (model.value !== undefined) {
  11029. switch (this.t) {
  11030. case 's':
  11031. model.type = Enums.ValueType.String;
  11032. model.value = parseInt(model.value, 10);
  11033. break;
  11034. case 'str':
  11035. model.type = Enums.ValueType.String;
  11036. model.value = utils.xmlDecode(model.value);
  11037. break;
  11038. case 'inlineStr':
  11039. model.type = Enums.ValueType.String;
  11040. break;
  11041. case 'b':
  11042. model.type = Enums.ValueType.Boolean;
  11043. model.value = parseInt(model.value, 10) !== 0;
  11044. break;
  11045. case 'e':
  11046. model.type = Enums.ValueType.Error;
  11047. model.value = {
  11048. error: model.value
  11049. };
  11050. break;
  11051. default:
  11052. model.type = Enums.ValueType.Number;
  11053. model.value = parseFloat(model.value);
  11054. break;
  11055. }
  11056. } else if (model.styleId) {
  11057. model.type = Enums.ValueType.Null;
  11058. } else {
  11059. model.type = Enums.ValueType.Merge;
  11060. }
  11061. return false;
  11062. }
  11063. case 'f':
  11064. case 'v':
  11065. case 'is':
  11066. this.currentNode = undefined;
  11067. return true;
  11068. case 't':
  11069. if (this.parser) {
  11070. this.parser.parseClose(name);
  11071. return true;
  11072. }
  11073. this.currentNode = undefined;
  11074. return true;
  11075. case 'r':
  11076. this.model.value = this.model.value || {};
  11077. this.model.value.richText = this.model.value.richText || [];
  11078. this.model.value.richText.push(this.parser.model);
  11079. this.parser = undefined;
  11080. this.currentNode = undefined;
  11081. return true;
  11082. default:
  11083. if (this.parser) {
  11084. this.parser.parseClose(name);
  11085. return true;
  11086. }
  11087. return false;
  11088. }
  11089. }
  11090. }, {
  11091. key: "reconcile",
  11092. value: function reconcile(model, options) {
  11093. var style = model.styleId && options.styles && options.styles.getStyleModel(model.styleId);
  11094. if (style) {
  11095. model.style = style;
  11096. }
  11097. if (model.styleId !== undefined) {
  11098. model.styleId = undefined;
  11099. }
  11100. switch (model.type) {
  11101. case Enums.ValueType.String:
  11102. if (typeof model.value === 'number') {
  11103. if (options.sharedStrings) {
  11104. model.value = options.sharedStrings.getString(model.value);
  11105. }
  11106. }
  11107. if (model.value.richText) {
  11108. model.type = Enums.ValueType.RichText;
  11109. }
  11110. break;
  11111. case Enums.ValueType.Number:
  11112. if (style && utils.isDateFmt(style.numFmt)) {
  11113. model.type = Enums.ValueType.Date;
  11114. model.value = utils.excelToDate(model.value, options.date1904);
  11115. }
  11116. break;
  11117. case Enums.ValueType.Formula:
  11118. if (model.result !== undefined && style && utils.isDateFmt(style.numFmt)) {
  11119. model.result = utils.excelToDate(model.result, options.date1904);
  11120. }
  11121. if (model.shareType === 'shared') {
  11122. if (model.ref) {
  11123. // master
  11124. options.formulae[model.si] = model.address;
  11125. } else {
  11126. // slave
  11127. model.sharedFormula = options.formulae[model.si];
  11128. delete model.shareType;
  11129. }
  11130. delete model.si;
  11131. }
  11132. break;
  11133. default:
  11134. break;
  11135. } // look for hyperlink
  11136. var hyperlink = options.hyperlinkMap[model.address];
  11137. if (hyperlink) {
  11138. if (model.type === Enums.ValueType.Formula) {
  11139. model.text = model.result;
  11140. model.result = undefined;
  11141. } else {
  11142. model.text = model.value;
  11143. model.value = undefined;
  11144. }
  11145. model.type = Enums.ValueType.Hyperlink;
  11146. model.hyperlink = hyperlink;
  11147. }
  11148. var comment = options.commentsMap && options.commentsMap[model.address];
  11149. if (comment) {
  11150. model.comment = comment;
  11151. }
  11152. }
  11153. }, {
  11154. key: "tag",
  11155. get: function get() {
  11156. return 'c';
  11157. }
  11158. }]);
  11159. return CellXform;
  11160. }(BaseXform);
  11161. module.exports = CellXform;
  11162. },{"../../../doc/enums":7,"../../../doc/range":10,"../../../utils/utils":26,"../base-xform":31,"../strings/rich-text-xform":121}],73:[function(require,module,exports){
  11163. "use strict";
  11164. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  11165. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11166. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  11167. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11168. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  11169. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11170. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  11171. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  11172. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11173. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  11174. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  11175. var BaseXform = require('../../base-xform');
  11176. var CfIconExtXform = /*#__PURE__*/function (_BaseXform) {
  11177. _inherits(CfIconExtXform, _BaseXform);
  11178. var _super = _createSuper(CfIconExtXform);
  11179. function CfIconExtXform() {
  11180. _classCallCheck(this, CfIconExtXform);
  11181. return _super.apply(this, arguments);
  11182. }
  11183. _createClass(CfIconExtXform, [{
  11184. key: "render",
  11185. value: function render(xmlStream, model) {
  11186. xmlStream.leafNode(this.tag, {
  11187. iconSet: model.iconSet,
  11188. iconId: model.iconId
  11189. });
  11190. }
  11191. }, {
  11192. key: "parseOpen",
  11193. value: function parseOpen(_ref) {
  11194. var attributes = _ref.attributes;
  11195. this.model = {
  11196. iconSet: attributes.iconSet,
  11197. iconId: BaseXform.toIntValue(attributes.iconId)
  11198. };
  11199. }
  11200. }, {
  11201. key: "parseClose",
  11202. value: function parseClose(name) {
  11203. return name !== this.tag;
  11204. }
  11205. }, {
  11206. key: "tag",
  11207. get: function get() {
  11208. return 'x14:cfIcon';
  11209. }
  11210. }]);
  11211. return CfIconExtXform;
  11212. }(BaseXform);
  11213. module.exports = CfIconExtXform;
  11214. },{"../../base-xform":31}],74:[function(require,module,exports){
  11215. "use strict";
  11216. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  11217. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11218. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  11219. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11220. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  11221. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11222. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  11223. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  11224. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11225. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  11226. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  11227. var _require = require('uuid'),
  11228. uuidv4 = _require.v4;
  11229. var BaseXform = require('../../base-xform');
  11230. var CompositeXform = require('../../composite-xform');
  11231. var DatabarExtXform = require('./databar-ext-xform');
  11232. var IconSetExtXform = require('./icon-set-ext-xform');
  11233. var extIcons = {
  11234. '3Triangles': true,
  11235. '3Stars': true,
  11236. '5Boxes': true
  11237. };
  11238. var CfRuleExtXform = /*#__PURE__*/function (_CompositeXform) {
  11239. _inherits(CfRuleExtXform, _CompositeXform);
  11240. var _super = _createSuper(CfRuleExtXform);
  11241. function CfRuleExtXform() {
  11242. var _this;
  11243. _classCallCheck(this, CfRuleExtXform);
  11244. _this = _super.call(this);
  11245. _this.map = {
  11246. 'x14:dataBar': _this.databarXform = new DatabarExtXform(),
  11247. 'x14:iconSet': _this.iconSetXform = new IconSetExtXform()
  11248. };
  11249. return _this;
  11250. }
  11251. _createClass(CfRuleExtXform, [{
  11252. key: "prepare",
  11253. value: function prepare(model) {
  11254. if (CfRuleExtXform.isExt(model)) {
  11255. model.x14Id = "{".concat(uuidv4(), "}").toUpperCase();
  11256. }
  11257. }
  11258. }, {
  11259. key: "render",
  11260. value: function render(xmlStream, model) {
  11261. if (!CfRuleExtXform.isExt(model)) {
  11262. return;
  11263. }
  11264. switch (model.type) {
  11265. case 'dataBar':
  11266. this.renderDataBar(xmlStream, model);
  11267. break;
  11268. case 'iconSet':
  11269. this.renderIconSet(xmlStream, model);
  11270. break;
  11271. }
  11272. }
  11273. }, {
  11274. key: "renderDataBar",
  11275. value: function renderDataBar(xmlStream, model) {
  11276. xmlStream.openNode(this.tag, {
  11277. type: 'dataBar',
  11278. id: model.x14Id
  11279. });
  11280. this.databarXform.render(xmlStream, model);
  11281. xmlStream.closeNode();
  11282. }
  11283. }, {
  11284. key: "renderIconSet",
  11285. value: function renderIconSet(xmlStream, model) {
  11286. xmlStream.openNode(this.tag, {
  11287. type: 'iconSet',
  11288. priority: model.priority,
  11289. id: model.x14Id || "{".concat(uuidv4(), "}")
  11290. });
  11291. this.iconSetXform.render(xmlStream, model);
  11292. xmlStream.closeNode();
  11293. }
  11294. }, {
  11295. key: "createNewModel",
  11296. value: function createNewModel(_ref) {
  11297. var attributes = _ref.attributes;
  11298. return {
  11299. type: attributes.type,
  11300. x14Id: attributes.id,
  11301. priority: BaseXform.toIntValue(attributes.priority)
  11302. };
  11303. }
  11304. }, {
  11305. key: "onParserClose",
  11306. value: function onParserClose(name, parser) {
  11307. Object.assign(this.model, parser.model);
  11308. }
  11309. }, {
  11310. key: "tag",
  11311. get: function get() {
  11312. return 'x14:cfRule';
  11313. }
  11314. }], [{
  11315. key: "isExt",
  11316. value: function isExt(rule) {
  11317. // is this rule primitive?
  11318. if (rule.type === 'dataBar') {
  11319. return DatabarExtXform.isExt(rule);
  11320. }
  11321. if (rule.type === 'iconSet') {
  11322. if (rule.custom || extIcons[rule.iconSet]) {
  11323. return true;
  11324. }
  11325. }
  11326. return false;
  11327. }
  11328. }]);
  11329. return CfRuleExtXform;
  11330. }(CompositeXform);
  11331. module.exports = CfRuleExtXform;
  11332. },{"../../base-xform":31,"../../composite-xform":47,"./databar-ext-xform":78,"./icon-set-ext-xform":80,"uuid":526}],75:[function(require,module,exports){
  11333. "use strict";
  11334. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  11335. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11336. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  11337. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11338. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  11339. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11340. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  11341. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  11342. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11343. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  11344. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  11345. var CompositeXform = require('../../composite-xform');
  11346. var FExtXform = require('./f-ext-xform');
  11347. var CfvoExtXform = /*#__PURE__*/function (_CompositeXform) {
  11348. _inherits(CfvoExtXform, _CompositeXform);
  11349. var _super = _createSuper(CfvoExtXform);
  11350. function CfvoExtXform() {
  11351. var _this;
  11352. _classCallCheck(this, CfvoExtXform);
  11353. _this = _super.call(this);
  11354. _this.map = {
  11355. 'xm:f': _this.fExtXform = new FExtXform()
  11356. };
  11357. return _this;
  11358. }
  11359. _createClass(CfvoExtXform, [{
  11360. key: "render",
  11361. value: function render(xmlStream, model) {
  11362. xmlStream.openNode(this.tag, {
  11363. type: model.type
  11364. });
  11365. if (model.value !== undefined) {
  11366. this.fExtXform.render(xmlStream, model.value);
  11367. }
  11368. xmlStream.closeNode();
  11369. }
  11370. }, {
  11371. key: "createNewModel",
  11372. value: function createNewModel(node) {
  11373. return {
  11374. type: node.attributes.type
  11375. };
  11376. }
  11377. }, {
  11378. key: "onParserClose",
  11379. value: function onParserClose(name, parser) {
  11380. switch (name) {
  11381. case 'xm:f':
  11382. this.model.value = parser.model ? parseFloat(parser.model) : 0;
  11383. break;
  11384. }
  11385. }
  11386. }, {
  11387. key: "tag",
  11388. get: function get() {
  11389. return 'x14:cfvo';
  11390. }
  11391. }]);
  11392. return CfvoExtXform;
  11393. }(CompositeXform);
  11394. module.exports = CfvoExtXform;
  11395. },{"../../composite-xform":47,"./f-ext-xform":79}],76:[function(require,module,exports){
  11396. "use strict";
  11397. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  11398. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11399. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  11400. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11401. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  11402. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11403. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  11404. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  11405. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11406. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  11407. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  11408. var CompositeXform = require('../../composite-xform');
  11409. var SqRefExtXform = require('./sqref-ext-xform');
  11410. var CfRuleExtXform = require('./cf-rule-ext-xform');
  11411. var ConditionalFormattingExtXform = /*#__PURE__*/function (_CompositeXform) {
  11412. _inherits(ConditionalFormattingExtXform, _CompositeXform);
  11413. var _super = _createSuper(ConditionalFormattingExtXform);
  11414. function ConditionalFormattingExtXform() {
  11415. var _this;
  11416. _classCallCheck(this, ConditionalFormattingExtXform);
  11417. _this = _super.call(this);
  11418. _this.map = {
  11419. 'xm:sqref': _this.sqRef = new SqRefExtXform(),
  11420. 'x14:cfRule': _this.cfRule = new CfRuleExtXform()
  11421. };
  11422. return _this;
  11423. }
  11424. _createClass(ConditionalFormattingExtXform, [{
  11425. key: "prepare",
  11426. value: function prepare(model, options) {
  11427. var _this2 = this;
  11428. model.rules.forEach(function (rule) {
  11429. _this2.cfRule.prepare(rule, options);
  11430. });
  11431. }
  11432. }, {
  11433. key: "render",
  11434. value: function render(xmlStream, model) {
  11435. var _this3 = this;
  11436. if (!model.rules.some(CfRuleExtXform.isExt)) {
  11437. return;
  11438. }
  11439. xmlStream.openNode(this.tag, {
  11440. 'xmlns:xm': 'http://schemas.microsoft.com/office/excel/2006/main'
  11441. });
  11442. model.rules.filter(CfRuleExtXform.isExt).forEach(function (rule) {
  11443. return _this3.cfRule.render(xmlStream, rule);
  11444. }); // for some odd reason, Excel needs the <xm:sqref> node to be after the rules
  11445. this.sqRef.render(xmlStream, model.ref);
  11446. xmlStream.closeNode();
  11447. }
  11448. }, {
  11449. key: "createNewModel",
  11450. value: function createNewModel() {
  11451. return {
  11452. rules: []
  11453. };
  11454. }
  11455. }, {
  11456. key: "onParserClose",
  11457. value: function onParserClose(name, parser) {
  11458. switch (name) {
  11459. case 'xm:sqref':
  11460. this.model.ref = parser.model;
  11461. break;
  11462. case 'x14:cfRule':
  11463. this.model.rules.push(parser.model);
  11464. break;
  11465. }
  11466. }
  11467. }, {
  11468. key: "tag",
  11469. get: function get() {
  11470. return 'x14:conditionalFormatting';
  11471. }
  11472. }]);
  11473. return ConditionalFormattingExtXform;
  11474. }(CompositeXform);
  11475. module.exports = ConditionalFormattingExtXform;
  11476. },{"../../composite-xform":47,"./cf-rule-ext-xform":74,"./sqref-ext-xform":81}],77:[function(require,module,exports){
  11477. "use strict";
  11478. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  11479. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11480. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  11481. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11482. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  11483. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11484. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  11485. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  11486. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11487. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  11488. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  11489. var CompositeXform = require('../../composite-xform');
  11490. var CfRuleExtXform = require('./cf-rule-ext-xform');
  11491. var ConditionalFormattingExtXform = require('./conditional-formatting-ext-xform');
  11492. var ConditionalFormattingsExtXform = /*#__PURE__*/function (_CompositeXform) {
  11493. _inherits(ConditionalFormattingsExtXform, _CompositeXform);
  11494. var _super = _createSuper(ConditionalFormattingsExtXform);
  11495. function ConditionalFormattingsExtXform() {
  11496. var _this;
  11497. _classCallCheck(this, ConditionalFormattingsExtXform);
  11498. _this = _super.call(this);
  11499. _this.map = {
  11500. 'x14:conditionalFormatting': _this.cfXform = new ConditionalFormattingExtXform()
  11501. };
  11502. return _this;
  11503. }
  11504. _createClass(ConditionalFormattingsExtXform, [{
  11505. key: "hasContent",
  11506. value: function hasContent(model) {
  11507. if (model.hasExtContent === undefined) {
  11508. model.hasExtContent = model.some(function (cf) {
  11509. return cf.rules.some(CfRuleExtXform.isExt);
  11510. });
  11511. }
  11512. return model.hasExtContent;
  11513. }
  11514. }, {
  11515. key: "prepare",
  11516. value: function prepare(model, options) {
  11517. var _this2 = this;
  11518. model.forEach(function (cf) {
  11519. _this2.cfXform.prepare(cf, options);
  11520. });
  11521. }
  11522. }, {
  11523. key: "render",
  11524. value: function render(xmlStream, model) {
  11525. var _this3 = this;
  11526. if (this.hasContent(model)) {
  11527. xmlStream.openNode(this.tag);
  11528. model.forEach(function (cf) {
  11529. return _this3.cfXform.render(xmlStream, cf);
  11530. });
  11531. xmlStream.closeNode();
  11532. }
  11533. }
  11534. }, {
  11535. key: "createNewModel",
  11536. value: function createNewModel() {
  11537. return [];
  11538. }
  11539. }, {
  11540. key: "onParserClose",
  11541. value: function onParserClose(name, parser) {
  11542. // model is array of conditional formatting objects
  11543. this.model.push(parser.model);
  11544. }
  11545. }, {
  11546. key: "tag",
  11547. get: function get() {
  11548. return 'x14:conditionalFormattings';
  11549. }
  11550. }]);
  11551. return ConditionalFormattingsExtXform;
  11552. }(CompositeXform);
  11553. module.exports = ConditionalFormattingsExtXform;
  11554. },{"../../composite-xform":47,"./cf-rule-ext-xform":74,"./conditional-formatting-ext-xform":76}],78:[function(require,module,exports){
  11555. "use strict";
  11556. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  11557. function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
  11558. function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  11559. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  11560. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  11561. function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
  11562. function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  11563. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11564. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  11565. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11566. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  11567. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11568. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  11569. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  11570. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11571. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  11572. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  11573. var BaseXform = require('../../base-xform');
  11574. var CompositeXform = require('../../composite-xform');
  11575. var ColorXform = require('../../style/color-xform');
  11576. var CfvoExtXform = require('./cfvo-ext-xform');
  11577. var DatabarExtXform = /*#__PURE__*/function (_CompositeXform) {
  11578. _inherits(DatabarExtXform, _CompositeXform);
  11579. var _super = _createSuper(DatabarExtXform);
  11580. function DatabarExtXform() {
  11581. var _this;
  11582. _classCallCheck(this, DatabarExtXform);
  11583. _this = _super.call(this);
  11584. _this.map = {
  11585. 'x14:cfvo': _this.cfvoXform = new CfvoExtXform(),
  11586. 'x14:borderColor': _this.borderColorXform = new ColorXform('x14:borderColor'),
  11587. 'x14:negativeBorderColor': _this.negativeBorderColorXform = new ColorXform('x14:negativeBorderColor'),
  11588. 'x14:negativeFillColor': _this.negativeFillColorXform = new ColorXform('x14:negativeFillColor'),
  11589. 'x14:axisColor': _this.axisColorXform = new ColorXform('x14:axisColor')
  11590. };
  11591. return _this;
  11592. }
  11593. _createClass(DatabarExtXform, [{
  11594. key: "render",
  11595. value: function render(xmlStream, model) {
  11596. var _this2 = this;
  11597. xmlStream.openNode(this.tag, {
  11598. minLength: BaseXform.toIntAttribute(model.minLength, 0, true),
  11599. maxLength: BaseXform.toIntAttribute(model.maxLength, 100, true),
  11600. border: BaseXform.toBoolAttribute(model.border, false),
  11601. gradient: BaseXform.toBoolAttribute(model.gradient, true),
  11602. negativeBarColorSameAsPositive: BaseXform.toBoolAttribute(model.negativeBarColorSameAsPositive, true),
  11603. negativeBarBorderColorSameAsPositive: BaseXform.toBoolAttribute(model.negativeBarBorderColorSameAsPositive, true),
  11604. axisPosition: BaseXform.toAttribute(model.axisPosition, 'auto'),
  11605. direction: BaseXform.toAttribute(model.direction, 'leftToRight')
  11606. });
  11607. model.cfvo.forEach(function (cfvo) {
  11608. _this2.cfvoXform.render(xmlStream, cfvo);
  11609. });
  11610. this.borderColorXform.render(xmlStream, model.borderColor);
  11611. this.negativeBorderColorXform.render(xmlStream, model.negativeBorderColor);
  11612. this.negativeFillColorXform.render(xmlStream, model.negativeFillColor);
  11613. this.axisColorXform.render(xmlStream, model.axisColor);
  11614. xmlStream.closeNode();
  11615. }
  11616. }, {
  11617. key: "createNewModel",
  11618. value: function createNewModel(_ref) {
  11619. var attributes = _ref.attributes;
  11620. return {
  11621. cfvo: [],
  11622. minLength: BaseXform.toIntValue(attributes.minLength, 0),
  11623. maxLength: BaseXform.toIntValue(attributes.maxLength, 100),
  11624. border: BaseXform.toBoolValue(attributes.border, false),
  11625. gradient: BaseXform.toBoolValue(attributes.gradient, true),
  11626. negativeBarColorSameAsPositive: BaseXform.toBoolValue(attributes.negativeBarColorSameAsPositive, true),
  11627. negativeBarBorderColorSameAsPositive: BaseXform.toBoolValue(attributes.negativeBarBorderColorSameAsPositive, true),
  11628. axisPosition: BaseXform.toStringValue(attributes.axisPosition, 'auto'),
  11629. direction: BaseXform.toStringValue(attributes.direction, 'leftToRight')
  11630. };
  11631. }
  11632. }, {
  11633. key: "onParserClose",
  11634. value: function onParserClose(name, parser) {
  11635. var _name$split = name.split(':'),
  11636. _name$split2 = _slicedToArray(_name$split, 2),
  11637. prop = _name$split2[1];
  11638. switch (prop) {
  11639. case 'cfvo':
  11640. this.model.cfvo.push(parser.model);
  11641. break;
  11642. default:
  11643. this.model[prop] = parser.model;
  11644. break;
  11645. }
  11646. }
  11647. }, {
  11648. key: "tag",
  11649. get: function get() {
  11650. return 'x14:dataBar';
  11651. }
  11652. }], [{
  11653. key: "isExt",
  11654. value: function isExt(rule) {
  11655. // not all databars need ext
  11656. // TODO: refine this
  11657. return !rule.gradient;
  11658. }
  11659. }]);
  11660. return DatabarExtXform;
  11661. }(CompositeXform);
  11662. module.exports = DatabarExtXform;
  11663. },{"../../base-xform":31,"../../composite-xform":47,"../../style/color-xform":127,"./cfvo-ext-xform":75}],79:[function(require,module,exports){
  11664. "use strict";
  11665. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  11666. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11667. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  11668. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11669. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  11670. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11671. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  11672. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  11673. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11674. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  11675. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  11676. var BaseXform = require('../../base-xform');
  11677. var FExtXform = /*#__PURE__*/function (_BaseXform) {
  11678. _inherits(FExtXform, _BaseXform);
  11679. var _super = _createSuper(FExtXform);
  11680. function FExtXform() {
  11681. _classCallCheck(this, FExtXform);
  11682. return _super.apply(this, arguments);
  11683. }
  11684. _createClass(FExtXform, [{
  11685. key: "render",
  11686. value: function render(xmlStream, model) {
  11687. xmlStream.leafNode(this.tag, null, model);
  11688. }
  11689. }, {
  11690. key: "parseOpen",
  11691. value: function parseOpen() {
  11692. this.model = '';
  11693. }
  11694. }, {
  11695. key: "parseText",
  11696. value: function parseText(text) {
  11697. this.model += text;
  11698. }
  11699. }, {
  11700. key: "parseClose",
  11701. value: function parseClose(name) {
  11702. return name !== this.tag;
  11703. }
  11704. }, {
  11705. key: "tag",
  11706. get: function get() {
  11707. return 'xm:f';
  11708. }
  11709. }]);
  11710. return FExtXform;
  11711. }(BaseXform);
  11712. module.exports = FExtXform;
  11713. },{"../../base-xform":31}],80:[function(require,module,exports){
  11714. "use strict";
  11715. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  11716. function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
  11717. function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  11718. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  11719. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  11720. function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
  11721. function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  11722. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11723. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  11724. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11725. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  11726. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11727. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  11728. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  11729. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11730. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  11731. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  11732. var BaseXform = require('../../base-xform');
  11733. var CompositeXform = require('../../composite-xform');
  11734. var CfvoExtXform = require('./cfvo-ext-xform');
  11735. var CfIconExtXform = require('./cf-icon-ext-xform');
  11736. var IconSetExtXform = /*#__PURE__*/function (_CompositeXform) {
  11737. _inherits(IconSetExtXform, _CompositeXform);
  11738. var _super = _createSuper(IconSetExtXform);
  11739. function IconSetExtXform() {
  11740. var _this;
  11741. _classCallCheck(this, IconSetExtXform);
  11742. _this = _super.call(this);
  11743. _this.map = {
  11744. 'x14:cfvo': _this.cfvoXform = new CfvoExtXform(),
  11745. 'x14:cfIcon': _this.cfIconXform = new CfIconExtXform()
  11746. };
  11747. return _this;
  11748. }
  11749. _createClass(IconSetExtXform, [{
  11750. key: "render",
  11751. value: function render(xmlStream, model) {
  11752. var _this2 = this;
  11753. xmlStream.openNode(this.tag, {
  11754. iconSet: BaseXform.toStringAttribute(model.iconSet),
  11755. reverse: BaseXform.toBoolAttribute(model.reverse, false),
  11756. showValue: BaseXform.toBoolAttribute(model.showValue, true),
  11757. custom: BaseXform.toBoolAttribute(model.icons, false)
  11758. });
  11759. model.cfvo.forEach(function (cfvo) {
  11760. _this2.cfvoXform.render(xmlStream, cfvo);
  11761. });
  11762. if (model.icons) {
  11763. model.icons.forEach(function (icon, i) {
  11764. icon.iconId = i;
  11765. _this2.cfIconXform.render(xmlStream, icon);
  11766. });
  11767. }
  11768. xmlStream.closeNode();
  11769. }
  11770. }, {
  11771. key: "createNewModel",
  11772. value: function createNewModel(_ref) {
  11773. var attributes = _ref.attributes;
  11774. return {
  11775. cfvo: [],
  11776. iconSet: BaseXform.toStringValue(attributes.iconSet, '3TrafficLights'),
  11777. reverse: BaseXform.toBoolValue(attributes.reverse, false),
  11778. showValue: BaseXform.toBoolValue(attributes.showValue, true)
  11779. };
  11780. }
  11781. }, {
  11782. key: "onParserClose",
  11783. value: function onParserClose(name, parser) {
  11784. var _name$split = name.split(':'),
  11785. _name$split2 = _slicedToArray(_name$split, 2),
  11786. prop = _name$split2[1];
  11787. switch (prop) {
  11788. case 'cfvo':
  11789. this.model.cfvo.push(parser.model);
  11790. break;
  11791. case 'cfIcon':
  11792. if (!this.model.icons) {
  11793. this.model.icons = [];
  11794. }
  11795. this.model.icons.push(parser.model);
  11796. break;
  11797. default:
  11798. this.model[prop] = parser.model;
  11799. break;
  11800. }
  11801. }
  11802. }, {
  11803. key: "tag",
  11804. get: function get() {
  11805. return 'x14:iconSet';
  11806. }
  11807. }]);
  11808. return IconSetExtXform;
  11809. }(CompositeXform);
  11810. module.exports = IconSetExtXform;
  11811. },{"../../base-xform":31,"../../composite-xform":47,"./cf-icon-ext-xform":73,"./cfvo-ext-xform":75}],81:[function(require,module,exports){
  11812. "use strict";
  11813. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  11814. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11815. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  11816. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11817. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  11818. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11819. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  11820. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  11821. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11822. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  11823. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  11824. var BaseXform = require('../../base-xform');
  11825. var SqrefExtXform = /*#__PURE__*/function (_BaseXform) {
  11826. _inherits(SqrefExtXform, _BaseXform);
  11827. var _super = _createSuper(SqrefExtXform);
  11828. function SqrefExtXform() {
  11829. _classCallCheck(this, SqrefExtXform);
  11830. return _super.apply(this, arguments);
  11831. }
  11832. _createClass(SqrefExtXform, [{
  11833. key: "render",
  11834. value: function render(xmlStream, model) {
  11835. xmlStream.leafNode(this.tag, null, model);
  11836. }
  11837. }, {
  11838. key: "parseOpen",
  11839. value: function parseOpen() {
  11840. this.model = '';
  11841. }
  11842. }, {
  11843. key: "parseText",
  11844. value: function parseText(text) {
  11845. this.model += text;
  11846. }
  11847. }, {
  11848. key: "parseClose",
  11849. value: function parseClose(name) {
  11850. return name !== this.tag;
  11851. }
  11852. }, {
  11853. key: "tag",
  11854. get: function get() {
  11855. return 'xm:sqref';
  11856. }
  11857. }]);
  11858. return SqrefExtXform;
  11859. }(BaseXform);
  11860. module.exports = SqrefExtXform;
  11861. },{"../../base-xform":31}],82:[function(require,module,exports){
  11862. "use strict";
  11863. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  11864. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  11865. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  11866. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  11867. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11868. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  11869. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11870. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  11871. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11872. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  11873. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  11874. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11875. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  11876. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  11877. var BaseXform = require('../../base-xform');
  11878. var CompositeXform = require('../../composite-xform');
  11879. var Range = require('../../../../doc/range');
  11880. var DatabarXform = require('./databar-xform');
  11881. var ExtLstRefXform = require('./ext-lst-ref-xform');
  11882. var FormulaXform = require('./formula-xform');
  11883. var ColorScaleXform = require('./color-scale-xform');
  11884. var IconSetXform = require('./icon-set-xform');
  11885. var extIcons = {
  11886. '3Triangles': true,
  11887. '3Stars': true,
  11888. '5Boxes': true
  11889. };
  11890. var getTextFormula = function getTextFormula(model) {
  11891. if (model.formulae && model.formulae[0]) {
  11892. return model.formulae[0];
  11893. }
  11894. var range = new Range(model.ref);
  11895. var tl = range.tl;
  11896. switch (model.operator) {
  11897. case 'containsText':
  11898. return "NOT(ISERROR(SEARCH(\"".concat(model.text, "\",").concat(tl, ")))");
  11899. case 'containsBlanks':
  11900. return "LEN(TRIM(".concat(tl, "))=0");
  11901. case 'notContainsBlanks':
  11902. return "LEN(TRIM(".concat(tl, "))>0");
  11903. case 'containsErrors':
  11904. return "ISERROR(".concat(tl, ")");
  11905. case 'notContainsErrors':
  11906. return "NOT(ISERROR(".concat(tl, "))");
  11907. default:
  11908. return undefined;
  11909. }
  11910. };
  11911. var getTimePeriodFormula = function getTimePeriodFormula(model) {
  11912. if (model.formulae && model.formulae[0]) {
  11913. return model.formulae[0];
  11914. }
  11915. var range = new Range(model.ref);
  11916. var tl = range.tl;
  11917. switch (model.timePeriod) {
  11918. case 'thisWeek':
  11919. return "AND(TODAY()-ROUNDDOWN(".concat(tl, ",0)<=WEEKDAY(TODAY())-1,ROUNDDOWN(").concat(tl, ",0)-TODAY()<=7-WEEKDAY(TODAY()))");
  11920. case 'lastWeek':
  11921. return "AND(TODAY()-ROUNDDOWN(".concat(tl, ",0)>=(WEEKDAY(TODAY())),TODAY()-ROUNDDOWN(").concat(tl, ",0)<(WEEKDAY(TODAY())+7))");
  11922. case 'nextWeek':
  11923. return "AND(ROUNDDOWN(".concat(tl, ",0)-TODAY()>(7-WEEKDAY(TODAY())),ROUNDDOWN(").concat(tl, ",0)-TODAY()<(15-WEEKDAY(TODAY())))");
  11924. case 'yesterday':
  11925. return "FLOOR(".concat(tl, ",1)=TODAY()-1");
  11926. case 'today':
  11927. return "FLOOR(".concat(tl, ",1)=TODAY()");
  11928. case 'tomorrow':
  11929. return "FLOOR(".concat(tl, ",1)=TODAY()+1");
  11930. case 'last7Days':
  11931. return "AND(TODAY()-FLOOR(".concat(tl, ",1)<=6,FLOOR(").concat(tl, ",1)<=TODAY())");
  11932. case 'lastMonth':
  11933. return "AND(MONTH(".concat(tl, ")=MONTH(EDATE(TODAY(),0-1)),YEAR(").concat(tl, ")=YEAR(EDATE(TODAY(),0-1)))");
  11934. case 'thisMonth':
  11935. return "AND(MONTH(".concat(tl, ")=MONTH(TODAY()),YEAR(").concat(tl, ")=YEAR(TODAY()))");
  11936. case 'nextMonth':
  11937. return "AND(MONTH(".concat(tl, ")=MONTH(EDATE(TODAY(),0+1)),YEAR(").concat(tl, ")=YEAR(EDATE(TODAY(),0+1)))");
  11938. default:
  11939. return undefined;
  11940. }
  11941. };
  11942. var opType = function opType(attributes) {
  11943. var type = attributes.type,
  11944. operator = attributes.operator;
  11945. switch (type) {
  11946. case 'containsText':
  11947. case 'containsBlanks':
  11948. case 'notContainsBlanks':
  11949. case 'containsErrors':
  11950. case 'notContainsErrors':
  11951. return {
  11952. type: 'containsText',
  11953. operator: type
  11954. };
  11955. default:
  11956. return {
  11957. type: type,
  11958. operator: operator
  11959. };
  11960. }
  11961. };
  11962. var CfRuleXform = /*#__PURE__*/function (_CompositeXform) {
  11963. _inherits(CfRuleXform, _CompositeXform);
  11964. var _super = _createSuper(CfRuleXform);
  11965. function CfRuleXform() {
  11966. var _this;
  11967. _classCallCheck(this, CfRuleXform);
  11968. _this = _super.call(this);
  11969. _this.map = {
  11970. dataBar: _this.databarXform = new DatabarXform(),
  11971. extLst: _this.extLstRefXform = new ExtLstRefXform(),
  11972. formula: _this.formulaXform = new FormulaXform(),
  11973. colorScale: _this.colorScaleXform = new ColorScaleXform(),
  11974. iconSet: _this.iconSetXform = new IconSetXform()
  11975. };
  11976. return _this;
  11977. }
  11978. _createClass(CfRuleXform, [{
  11979. key: "render",
  11980. value: function render(xmlStream, model) {
  11981. switch (model.type) {
  11982. case 'expression':
  11983. this.renderExpression(xmlStream, model);
  11984. break;
  11985. case 'cellIs':
  11986. this.renderCellIs(xmlStream, model);
  11987. break;
  11988. case 'top10':
  11989. this.renderTop10(xmlStream, model);
  11990. break;
  11991. case 'aboveAverage':
  11992. this.renderAboveAverage(xmlStream, model);
  11993. break;
  11994. case 'dataBar':
  11995. this.renderDataBar(xmlStream, model);
  11996. break;
  11997. case 'colorScale':
  11998. this.renderColorScale(xmlStream, model);
  11999. break;
  12000. case 'iconSet':
  12001. this.renderIconSet(xmlStream, model);
  12002. break;
  12003. case 'containsText':
  12004. this.renderText(xmlStream, model);
  12005. break;
  12006. case 'timePeriod':
  12007. this.renderTimePeriod(xmlStream, model);
  12008. break;
  12009. }
  12010. }
  12011. }, {
  12012. key: "renderExpression",
  12013. value: function renderExpression(xmlStream, model) {
  12014. xmlStream.openNode(this.tag, {
  12015. type: 'expression',
  12016. dxfId: model.dxfId,
  12017. priority: model.priority
  12018. });
  12019. this.formulaXform.render(xmlStream, model.formulae[0]);
  12020. xmlStream.closeNode();
  12021. }
  12022. }, {
  12023. key: "renderCellIs",
  12024. value: function renderCellIs(xmlStream, model) {
  12025. var _this2 = this;
  12026. xmlStream.openNode(this.tag, {
  12027. type: 'cellIs',
  12028. dxfId: model.dxfId,
  12029. priority: model.priority,
  12030. operator: model.operator
  12031. });
  12032. model.formulae.forEach(function (formula) {
  12033. _this2.formulaXform.render(xmlStream, formula);
  12034. });
  12035. xmlStream.closeNode();
  12036. }
  12037. }, {
  12038. key: "renderTop10",
  12039. value: function renderTop10(xmlStream, model) {
  12040. xmlStream.leafNode(this.tag, {
  12041. type: 'top10',
  12042. dxfId: model.dxfId,
  12043. priority: model.priority,
  12044. percent: BaseXform.toBoolAttribute(model.percent, false),
  12045. bottom: BaseXform.toBoolAttribute(model.bottom, false),
  12046. rank: BaseXform.toIntValue(model.rank, 10, true)
  12047. });
  12048. }
  12049. }, {
  12050. key: "renderAboveAverage",
  12051. value: function renderAboveAverage(xmlStream, model) {
  12052. xmlStream.leafNode(this.tag, {
  12053. type: 'aboveAverage',
  12054. dxfId: model.dxfId,
  12055. priority: model.priority,
  12056. aboveAverage: BaseXform.toBoolAttribute(model.aboveAverage, true)
  12057. });
  12058. }
  12059. }, {
  12060. key: "renderDataBar",
  12061. value: function renderDataBar(xmlStream, model) {
  12062. xmlStream.openNode(this.tag, {
  12063. type: 'dataBar',
  12064. priority: model.priority
  12065. });
  12066. this.databarXform.render(xmlStream, model);
  12067. this.extLstRefXform.render(xmlStream, model);
  12068. xmlStream.closeNode();
  12069. }
  12070. }, {
  12071. key: "renderColorScale",
  12072. value: function renderColorScale(xmlStream, model) {
  12073. xmlStream.openNode(this.tag, {
  12074. type: 'colorScale',
  12075. priority: model.priority
  12076. });
  12077. this.colorScaleXform.render(xmlStream, model);
  12078. xmlStream.closeNode();
  12079. }
  12080. }, {
  12081. key: "renderIconSet",
  12082. value: function renderIconSet(xmlStream, model) {
  12083. // iconset is all primitive or all extLst
  12084. if (!CfRuleXform.isPrimitive(model)) {
  12085. return;
  12086. }
  12087. xmlStream.openNode(this.tag, {
  12088. type: 'iconSet',
  12089. priority: model.priority
  12090. });
  12091. this.iconSetXform.render(xmlStream, model);
  12092. xmlStream.closeNode();
  12093. }
  12094. }, {
  12095. key: "renderText",
  12096. value: function renderText(xmlStream, model) {
  12097. xmlStream.openNode(this.tag, {
  12098. type: model.operator,
  12099. dxfId: model.dxfId,
  12100. priority: model.priority,
  12101. operator: BaseXform.toStringAttribute(model.operator, 'containsText')
  12102. });
  12103. var formula = getTextFormula(model);
  12104. if (formula) {
  12105. this.formulaXform.render(xmlStream, formula);
  12106. }
  12107. xmlStream.closeNode();
  12108. }
  12109. }, {
  12110. key: "renderTimePeriod",
  12111. value: function renderTimePeriod(xmlStream, model) {
  12112. xmlStream.openNode(this.tag, {
  12113. type: 'timePeriod',
  12114. dxfId: model.dxfId,
  12115. priority: model.priority,
  12116. timePeriod: model.timePeriod
  12117. });
  12118. var formula = getTimePeriodFormula(model);
  12119. if (formula) {
  12120. this.formulaXform.render(xmlStream, formula);
  12121. }
  12122. xmlStream.closeNode();
  12123. }
  12124. }, {
  12125. key: "createNewModel",
  12126. value: function createNewModel(_ref) {
  12127. var attributes = _ref.attributes;
  12128. return _objectSpread(_objectSpread({}, opType(attributes)), {}, {
  12129. dxfId: BaseXform.toIntValue(attributes.dxfId),
  12130. priority: BaseXform.toIntValue(attributes.priority),
  12131. timePeriod: attributes.timePeriod,
  12132. percent: BaseXform.toBoolValue(attributes.percent),
  12133. bottom: BaseXform.toBoolValue(attributes.bottom),
  12134. rank: BaseXform.toIntValue(attributes.rank),
  12135. aboveAverage: BaseXform.toBoolValue(attributes.aboveAverage)
  12136. });
  12137. }
  12138. }, {
  12139. key: "onParserClose",
  12140. value: function onParserClose(name, parser) {
  12141. switch (name) {
  12142. case 'dataBar':
  12143. case 'extLst':
  12144. case 'colorScale':
  12145. case 'iconSet':
  12146. // merge parser model with ours
  12147. Object.assign(this.model, parser.model);
  12148. break;
  12149. case 'formula':
  12150. // except - formula is a string and appends to formulae
  12151. this.model.formulae = this.model.formulae || [];
  12152. this.model.formulae.push(parser.model);
  12153. break;
  12154. }
  12155. }
  12156. }, {
  12157. key: "tag",
  12158. get: function get() {
  12159. return 'cfRule';
  12160. }
  12161. }], [{
  12162. key: "isPrimitive",
  12163. value: function isPrimitive(rule) {
  12164. // is this rule primitive?
  12165. if (rule.type === 'iconSet') {
  12166. if (rule.custom || extIcons[rule.iconSet]) {
  12167. return false;
  12168. }
  12169. }
  12170. return true;
  12171. }
  12172. }]);
  12173. return CfRuleXform;
  12174. }(CompositeXform);
  12175. module.exports = CfRuleXform;
  12176. },{"../../../../doc/range":10,"../../base-xform":31,"../../composite-xform":47,"./color-scale-xform":84,"./databar-xform":87,"./ext-lst-ref-xform":88,"./formula-xform":89,"./icon-set-xform":90}],83:[function(require,module,exports){
  12177. "use strict";
  12178. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  12179. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12180. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  12181. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  12182. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  12183. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  12184. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  12185. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  12186. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  12187. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  12188. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  12189. var BaseXform = require('../../base-xform');
  12190. var CfvoXform = /*#__PURE__*/function (_BaseXform) {
  12191. _inherits(CfvoXform, _BaseXform);
  12192. var _super = _createSuper(CfvoXform);
  12193. function CfvoXform() {
  12194. _classCallCheck(this, CfvoXform);
  12195. return _super.apply(this, arguments);
  12196. }
  12197. _createClass(CfvoXform, [{
  12198. key: "render",
  12199. value: function render(xmlStream, model) {
  12200. xmlStream.leafNode(this.tag, {
  12201. type: model.type,
  12202. val: model.value
  12203. });
  12204. }
  12205. }, {
  12206. key: "parseOpen",
  12207. value: function parseOpen(node) {
  12208. this.model = {
  12209. type: node.attributes.type,
  12210. value: BaseXform.toFloatValue(node.attributes.val)
  12211. };
  12212. }
  12213. }, {
  12214. key: "parseClose",
  12215. value: function parseClose(name) {
  12216. return name !== this.tag;
  12217. }
  12218. }, {
  12219. key: "tag",
  12220. get: function get() {
  12221. return 'cfvo';
  12222. }
  12223. }]);
  12224. return CfvoXform;
  12225. }(BaseXform);
  12226. module.exports = CfvoXform;
  12227. },{"../../base-xform":31}],84:[function(require,module,exports){
  12228. "use strict";
  12229. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  12230. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12231. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  12232. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  12233. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  12234. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  12235. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  12236. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  12237. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  12238. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  12239. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  12240. var CompositeXform = require('../../composite-xform');
  12241. var ColorXform = require('../../style/color-xform');
  12242. var CfvoXform = require('./cfvo-xform');
  12243. var ColorScaleXform = /*#__PURE__*/function (_CompositeXform) {
  12244. _inherits(ColorScaleXform, _CompositeXform);
  12245. var _super = _createSuper(ColorScaleXform);
  12246. function ColorScaleXform() {
  12247. var _this;
  12248. _classCallCheck(this, ColorScaleXform);
  12249. _this = _super.call(this);
  12250. _this.map = {
  12251. cfvo: _this.cfvoXform = new CfvoXform(),
  12252. color: _this.colorXform = new ColorXform()
  12253. };
  12254. return _this;
  12255. }
  12256. _createClass(ColorScaleXform, [{
  12257. key: "render",
  12258. value: function render(xmlStream, model) {
  12259. var _this2 = this;
  12260. xmlStream.openNode(this.tag);
  12261. model.cfvo.forEach(function (cfvo) {
  12262. _this2.cfvoXform.render(xmlStream, cfvo);
  12263. });
  12264. model.color.forEach(function (color) {
  12265. _this2.colorXform.render(xmlStream, color);
  12266. });
  12267. xmlStream.closeNode();
  12268. }
  12269. }, {
  12270. key: "createNewModel",
  12271. value: function createNewModel(node) {
  12272. return {
  12273. cfvo: [],
  12274. color: []
  12275. };
  12276. }
  12277. }, {
  12278. key: "onParserClose",
  12279. value: function onParserClose(name, parser) {
  12280. this.model[name].push(parser.model);
  12281. }
  12282. }, {
  12283. key: "tag",
  12284. get: function get() {
  12285. return 'colorScale';
  12286. }
  12287. }]);
  12288. return ColorScaleXform;
  12289. }(CompositeXform);
  12290. module.exports = ColorScaleXform;
  12291. },{"../../composite-xform":47,"../../style/color-xform":127,"./cfvo-xform":83}],85:[function(require,module,exports){
  12292. "use strict";
  12293. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  12294. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12295. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  12296. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  12297. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  12298. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  12299. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  12300. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  12301. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  12302. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  12303. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  12304. var CompositeXform = require('../../composite-xform');
  12305. var CfRuleXform = require('./cf-rule-xform');
  12306. var ConditionalFormattingXform = /*#__PURE__*/function (_CompositeXform) {
  12307. _inherits(ConditionalFormattingXform, _CompositeXform);
  12308. var _super = _createSuper(ConditionalFormattingXform);
  12309. function ConditionalFormattingXform() {
  12310. var _this;
  12311. _classCallCheck(this, ConditionalFormattingXform);
  12312. _this = _super.call(this);
  12313. _this.map = {
  12314. cfRule: new CfRuleXform()
  12315. };
  12316. return _this;
  12317. }
  12318. _createClass(ConditionalFormattingXform, [{
  12319. key: "render",
  12320. value: function render(xmlStream, model) {
  12321. var _this2 = this;
  12322. // if there are no primitive rules, exit now
  12323. if (!model.rules.some(CfRuleXform.isPrimitive)) {
  12324. return;
  12325. }
  12326. xmlStream.openNode(this.tag, {
  12327. sqref: model.ref
  12328. });
  12329. model.rules.forEach(function (rule) {
  12330. if (CfRuleXform.isPrimitive(rule)) {
  12331. rule.ref = model.ref;
  12332. _this2.map.cfRule.render(xmlStream, rule);
  12333. }
  12334. });
  12335. xmlStream.closeNode();
  12336. }
  12337. }, {
  12338. key: "createNewModel",
  12339. value: function createNewModel(_ref) {
  12340. var attributes = _ref.attributes;
  12341. return {
  12342. ref: attributes.sqref,
  12343. rules: []
  12344. };
  12345. }
  12346. }, {
  12347. key: "onParserClose",
  12348. value: function onParserClose(name, parser) {
  12349. this.model.rules.push(parser.model);
  12350. }
  12351. }, {
  12352. key: "tag",
  12353. get: function get() {
  12354. return 'conditionalFormatting';
  12355. }
  12356. }]);
  12357. return ConditionalFormattingXform;
  12358. }(CompositeXform);
  12359. module.exports = ConditionalFormattingXform;
  12360. },{"../../composite-xform":47,"./cf-rule-xform":82}],86:[function(require,module,exports){
  12361. "use strict";
  12362. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  12363. function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
  12364. function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  12365. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  12366. function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
  12367. function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
  12368. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  12369. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12370. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  12371. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  12372. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  12373. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  12374. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  12375. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  12376. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  12377. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  12378. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  12379. var BaseXform = require('../../base-xform');
  12380. var ConditionalFormattingXform = require('./conditional-formatting-xform');
  12381. var ConditionalFormattingsXform = /*#__PURE__*/function (_BaseXform) {
  12382. _inherits(ConditionalFormattingsXform, _BaseXform);
  12383. var _super = _createSuper(ConditionalFormattingsXform);
  12384. function ConditionalFormattingsXform() {
  12385. var _this;
  12386. _classCallCheck(this, ConditionalFormattingsXform);
  12387. _this = _super.call(this);
  12388. _this.cfXform = new ConditionalFormattingXform();
  12389. return _this;
  12390. }
  12391. _createClass(ConditionalFormattingsXform, [{
  12392. key: "reset",
  12393. value: function reset() {
  12394. this.model = [];
  12395. }
  12396. }, {
  12397. key: "prepare",
  12398. value: function prepare(model, options) {
  12399. // ensure each rule has a priority value
  12400. var nextPriority = model.reduce(function (p, cf) {
  12401. return Math.max.apply(Math, [p].concat(_toConsumableArray(cf.rules.map(function (rule) {
  12402. return rule.priority || 0;
  12403. }))));
  12404. }, 1);
  12405. model.forEach(function (cf) {
  12406. cf.rules.forEach(function (rule) {
  12407. if (!rule.priority) {
  12408. rule.priority = nextPriority++;
  12409. }
  12410. if (rule.style) {
  12411. rule.dxfId = options.styles.addDxfStyle(rule.style);
  12412. }
  12413. });
  12414. });
  12415. }
  12416. }, {
  12417. key: "render",
  12418. value: function render(xmlStream, model) {
  12419. var _this2 = this;
  12420. model.forEach(function (cf) {
  12421. _this2.cfXform.render(xmlStream, cf);
  12422. });
  12423. }
  12424. }, {
  12425. key: "parseOpen",
  12426. value: function parseOpen(node) {
  12427. if (this.parser) {
  12428. this.parser.parseOpen(node);
  12429. return true;
  12430. }
  12431. switch (node.name) {
  12432. case 'conditionalFormatting':
  12433. this.parser = this.cfXform;
  12434. this.parser.parseOpen(node);
  12435. return true;
  12436. default:
  12437. return false;
  12438. }
  12439. }
  12440. }, {
  12441. key: "parseText",
  12442. value: function parseText(text) {
  12443. if (this.parser) {
  12444. this.parser.parseText(text);
  12445. }
  12446. }
  12447. }, {
  12448. key: "parseClose",
  12449. value: function parseClose(name) {
  12450. if (this.parser) {
  12451. if (!this.parser.parseClose(name)) {
  12452. this.model.push(this.parser.model);
  12453. this.parser = undefined;
  12454. return false;
  12455. }
  12456. return true;
  12457. }
  12458. return false;
  12459. }
  12460. }, {
  12461. key: "reconcile",
  12462. value: function reconcile(model, options) {
  12463. model.forEach(function (cf) {
  12464. cf.rules.forEach(function (rule) {
  12465. if (rule.dxfId !== undefined) {
  12466. rule.style = options.styles.getDxfStyle(rule.dxfId);
  12467. delete rule.dxfId;
  12468. }
  12469. });
  12470. });
  12471. }
  12472. }, {
  12473. key: "tag",
  12474. get: function get() {
  12475. return 'conditionalFormatting';
  12476. }
  12477. }]);
  12478. return ConditionalFormattingsXform;
  12479. }(BaseXform);
  12480. module.exports = ConditionalFormattingsXform;
  12481. },{"../../base-xform":31,"./conditional-formatting-xform":85}],87:[function(require,module,exports){
  12482. "use strict";
  12483. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  12484. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12485. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  12486. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  12487. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  12488. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  12489. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  12490. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  12491. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  12492. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  12493. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  12494. var CompositeXform = require('../../composite-xform');
  12495. var ColorXform = require('../../style/color-xform');
  12496. var CfvoXform = require('./cfvo-xform');
  12497. var DatabarXform = /*#__PURE__*/function (_CompositeXform) {
  12498. _inherits(DatabarXform, _CompositeXform);
  12499. var _super = _createSuper(DatabarXform);
  12500. function DatabarXform() {
  12501. var _this;
  12502. _classCallCheck(this, DatabarXform);
  12503. _this = _super.call(this);
  12504. _this.map = {
  12505. cfvo: _this.cfvoXform = new CfvoXform(),
  12506. color: _this.colorXform = new ColorXform()
  12507. };
  12508. return _this;
  12509. }
  12510. _createClass(DatabarXform, [{
  12511. key: "render",
  12512. value: function render(xmlStream, model) {
  12513. var _this2 = this;
  12514. xmlStream.openNode(this.tag);
  12515. model.cfvo.forEach(function (cfvo) {
  12516. _this2.cfvoXform.render(xmlStream, cfvo);
  12517. });
  12518. this.colorXform.render(xmlStream, model.color);
  12519. xmlStream.closeNode();
  12520. }
  12521. }, {
  12522. key: "createNewModel",
  12523. value: function createNewModel() {
  12524. return {
  12525. cfvo: []
  12526. };
  12527. }
  12528. }, {
  12529. key: "onParserClose",
  12530. value: function onParserClose(name, parser) {
  12531. switch (name) {
  12532. case 'cfvo':
  12533. this.model.cfvo.push(parser.model);
  12534. break;
  12535. case 'color':
  12536. this.model.color = parser.model;
  12537. break;
  12538. }
  12539. }
  12540. }, {
  12541. key: "tag",
  12542. get: function get() {
  12543. return 'dataBar';
  12544. }
  12545. }]);
  12546. return DatabarXform;
  12547. }(CompositeXform);
  12548. module.exports = DatabarXform;
  12549. },{"../../composite-xform":47,"../../style/color-xform":127,"./cfvo-xform":83}],88:[function(require,module,exports){
  12550. "use strict";
  12551. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  12552. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12553. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  12554. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  12555. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  12556. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  12557. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  12558. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  12559. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  12560. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  12561. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  12562. /* eslint-disable max-classes-per-file */
  12563. var BaseXform = require('../../base-xform');
  12564. var CompositeXform = require('../../composite-xform');
  12565. var X14IdXform = /*#__PURE__*/function (_BaseXform) {
  12566. _inherits(X14IdXform, _BaseXform);
  12567. var _super = _createSuper(X14IdXform);
  12568. function X14IdXform() {
  12569. _classCallCheck(this, X14IdXform);
  12570. return _super.apply(this, arguments);
  12571. }
  12572. _createClass(X14IdXform, [{
  12573. key: "render",
  12574. value: function render(xmlStream, model) {
  12575. xmlStream.leafNode(this.tag, null, model);
  12576. }
  12577. }, {
  12578. key: "parseOpen",
  12579. value: function parseOpen() {
  12580. this.model = '';
  12581. }
  12582. }, {
  12583. key: "parseText",
  12584. value: function parseText(text) {
  12585. this.model += text;
  12586. }
  12587. }, {
  12588. key: "parseClose",
  12589. value: function parseClose(name) {
  12590. return name !== this.tag;
  12591. }
  12592. }, {
  12593. key: "tag",
  12594. get: function get() {
  12595. return 'x14:id';
  12596. }
  12597. }]);
  12598. return X14IdXform;
  12599. }(BaseXform);
  12600. var ExtXform = /*#__PURE__*/function (_CompositeXform) {
  12601. _inherits(ExtXform, _CompositeXform);
  12602. var _super2 = _createSuper(ExtXform);
  12603. function ExtXform() {
  12604. var _this;
  12605. _classCallCheck(this, ExtXform);
  12606. _this = _super2.call(this);
  12607. _this.map = {
  12608. 'x14:id': _this.idXform = new X14IdXform()
  12609. };
  12610. return _this;
  12611. }
  12612. _createClass(ExtXform, [{
  12613. key: "render",
  12614. value: function render(xmlStream, model) {
  12615. xmlStream.openNode(this.tag, {
  12616. uri: '{B025F937-C7B1-47D3-B67F-A62EFF666E3E}',
  12617. 'xmlns:x14': 'http://schemas.microsoft.com/office/spreadsheetml/2009/9/main'
  12618. });
  12619. this.idXform.render(xmlStream, model.x14Id);
  12620. xmlStream.closeNode();
  12621. }
  12622. }, {
  12623. key: "createNewModel",
  12624. value: function createNewModel() {
  12625. return {};
  12626. }
  12627. }, {
  12628. key: "onParserClose",
  12629. value: function onParserClose(name, parser) {
  12630. this.model.x14Id = parser.model;
  12631. }
  12632. }, {
  12633. key: "tag",
  12634. get: function get() {
  12635. return 'ext';
  12636. }
  12637. }]);
  12638. return ExtXform;
  12639. }(CompositeXform);
  12640. var ExtLstRefXform = /*#__PURE__*/function (_CompositeXform2) {
  12641. _inherits(ExtLstRefXform, _CompositeXform2);
  12642. var _super3 = _createSuper(ExtLstRefXform);
  12643. function ExtLstRefXform() {
  12644. var _this2;
  12645. _classCallCheck(this, ExtLstRefXform);
  12646. _this2 = _super3.call(this);
  12647. _this2.map = {
  12648. ext: new ExtXform()
  12649. };
  12650. return _this2;
  12651. }
  12652. _createClass(ExtLstRefXform, [{
  12653. key: "render",
  12654. value: function render(xmlStream, model) {
  12655. xmlStream.openNode(this.tag);
  12656. this.map.ext.render(xmlStream, model);
  12657. xmlStream.closeNode();
  12658. }
  12659. }, {
  12660. key: "createNewModel",
  12661. value: function createNewModel() {
  12662. return {};
  12663. }
  12664. }, {
  12665. key: "onParserClose",
  12666. value: function onParserClose(name, parser) {
  12667. Object.assign(this.model, parser.model);
  12668. }
  12669. }, {
  12670. key: "tag",
  12671. get: function get() {
  12672. return 'extLst';
  12673. }
  12674. }]);
  12675. return ExtLstRefXform;
  12676. }(CompositeXform);
  12677. module.exports = ExtLstRefXform;
  12678. },{"../../base-xform":31,"../../composite-xform":47}],89:[function(require,module,exports){
  12679. "use strict";
  12680. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  12681. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12682. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  12683. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  12684. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  12685. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  12686. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  12687. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  12688. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  12689. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  12690. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  12691. var BaseXform = require('../../base-xform');
  12692. var FormulaXform = /*#__PURE__*/function (_BaseXform) {
  12693. _inherits(FormulaXform, _BaseXform);
  12694. var _super = _createSuper(FormulaXform);
  12695. function FormulaXform() {
  12696. _classCallCheck(this, FormulaXform);
  12697. return _super.apply(this, arguments);
  12698. }
  12699. _createClass(FormulaXform, [{
  12700. key: "render",
  12701. value: function render(xmlStream, model) {
  12702. xmlStream.leafNode(this.tag, null, model);
  12703. }
  12704. }, {
  12705. key: "parseOpen",
  12706. value: function parseOpen() {
  12707. this.model = '';
  12708. }
  12709. }, {
  12710. key: "parseText",
  12711. value: function parseText(text) {
  12712. this.model += text;
  12713. }
  12714. }, {
  12715. key: "parseClose",
  12716. value: function parseClose(name) {
  12717. return name !== this.tag;
  12718. }
  12719. }, {
  12720. key: "tag",
  12721. get: function get() {
  12722. return 'formula';
  12723. }
  12724. }]);
  12725. return FormulaXform;
  12726. }(BaseXform);
  12727. module.exports = FormulaXform;
  12728. },{"../../base-xform":31}],90:[function(require,module,exports){
  12729. "use strict";
  12730. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  12731. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12732. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  12733. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  12734. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  12735. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  12736. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  12737. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  12738. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  12739. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  12740. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  12741. var BaseXform = require('../../base-xform');
  12742. var CompositeXform = require('../../composite-xform');
  12743. var CfvoXform = require('./cfvo-xform');
  12744. var IconSetXform = /*#__PURE__*/function (_CompositeXform) {
  12745. _inherits(IconSetXform, _CompositeXform);
  12746. var _super = _createSuper(IconSetXform);
  12747. function IconSetXform() {
  12748. var _this;
  12749. _classCallCheck(this, IconSetXform);
  12750. _this = _super.call(this);
  12751. _this.map = {
  12752. cfvo: _this.cfvoXform = new CfvoXform()
  12753. };
  12754. return _this;
  12755. }
  12756. _createClass(IconSetXform, [{
  12757. key: "render",
  12758. value: function render(xmlStream, model) {
  12759. var _this2 = this;
  12760. xmlStream.openNode(this.tag, {
  12761. iconSet: BaseXform.toStringAttribute(model.iconSet, '3TrafficLights'),
  12762. reverse: BaseXform.toBoolAttribute(model.reverse, false),
  12763. showValue: BaseXform.toBoolAttribute(model.showValue, true)
  12764. });
  12765. model.cfvo.forEach(function (cfvo) {
  12766. _this2.cfvoXform.render(xmlStream, cfvo);
  12767. });
  12768. xmlStream.closeNode();
  12769. }
  12770. }, {
  12771. key: "createNewModel",
  12772. value: function createNewModel(_ref) {
  12773. var attributes = _ref.attributes;
  12774. return {
  12775. iconSet: BaseXform.toStringValue(attributes.iconSet, '3TrafficLights'),
  12776. reverse: BaseXform.toBoolValue(attributes.reverse),
  12777. showValue: BaseXform.toBoolValue(attributes.showValue),
  12778. cfvo: []
  12779. };
  12780. }
  12781. }, {
  12782. key: "onParserClose",
  12783. value: function onParserClose(name, parser) {
  12784. this.model[name].push(parser.model);
  12785. }
  12786. }, {
  12787. key: "tag",
  12788. get: function get() {
  12789. return 'iconSet';
  12790. }
  12791. }]);
  12792. return IconSetXform;
  12793. }(CompositeXform);
  12794. module.exports = IconSetXform;
  12795. },{"../../base-xform":31,"../../composite-xform":47,"./cfvo-xform":83}],91:[function(require,module,exports){
  12796. "use strict";
  12797. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  12798. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12799. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  12800. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  12801. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  12802. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  12803. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  12804. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  12805. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  12806. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  12807. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  12808. var BaseXform = require('../base-xform');
  12809. var ColXform = /*#__PURE__*/function (_BaseXform) {
  12810. _inherits(ColXform, _BaseXform);
  12811. var _super = _createSuper(ColXform);
  12812. function ColXform() {
  12813. _classCallCheck(this, ColXform);
  12814. return _super.apply(this, arguments);
  12815. }
  12816. _createClass(ColXform, [{
  12817. key: "prepare",
  12818. value: function prepare(model, options) {
  12819. var styleId = options.styles.addStyleModel(model.style || {});
  12820. if (styleId) {
  12821. model.styleId = styleId;
  12822. }
  12823. }
  12824. }, {
  12825. key: "render",
  12826. value: function render(xmlStream, model) {
  12827. xmlStream.openNode('col');
  12828. xmlStream.addAttribute('min', model.min);
  12829. xmlStream.addAttribute('max', model.max);
  12830. if (model.width) {
  12831. xmlStream.addAttribute('width', model.width);
  12832. }
  12833. if (model.styleId) {
  12834. xmlStream.addAttribute('style', model.styleId);
  12835. }
  12836. if (model.hidden) {
  12837. xmlStream.addAttribute('hidden', '1');
  12838. }
  12839. if (model.bestFit) {
  12840. xmlStream.addAttribute('bestFit', '1');
  12841. }
  12842. if (model.outlineLevel) {
  12843. xmlStream.addAttribute('outlineLevel', model.outlineLevel);
  12844. }
  12845. if (model.collapsed) {
  12846. xmlStream.addAttribute('collapsed', '1');
  12847. }
  12848. xmlStream.addAttribute('customWidth', '1');
  12849. xmlStream.closeNode();
  12850. }
  12851. }, {
  12852. key: "parseOpen",
  12853. value: function parseOpen(node) {
  12854. if (node.name === 'col') {
  12855. var model = this.model = {
  12856. min: parseInt(node.attributes.min || '0', 10),
  12857. max: parseInt(node.attributes.max || '0', 10),
  12858. width: node.attributes.width === undefined ? undefined : parseFloat(node.attributes.width || '0')
  12859. };
  12860. if (node.attributes.style) {
  12861. model.styleId = parseInt(node.attributes.style, 10);
  12862. }
  12863. if (node.attributes.hidden === true || node.attributes.hidden === 'true' || node.attributes.hidden === 1 || node.attributes.hidden === '1') {
  12864. model.hidden = true;
  12865. }
  12866. if (node.attributes.bestFit) {
  12867. model.bestFit = true;
  12868. }
  12869. if (node.attributes.outlineLevel) {
  12870. model.outlineLevel = parseInt(node.attributes.outlineLevel, 10);
  12871. }
  12872. if (node.attributes.collapsed) {
  12873. model.collapsed = true;
  12874. }
  12875. return true;
  12876. }
  12877. return false;
  12878. }
  12879. }, {
  12880. key: "parseText",
  12881. value: function parseText() {}
  12882. }, {
  12883. key: "parseClose",
  12884. value: function parseClose() {
  12885. return false;
  12886. }
  12887. }, {
  12888. key: "reconcile",
  12889. value: function reconcile(model, options) {
  12890. // reconcile column styles
  12891. if (model.styleId) {
  12892. model.style = options.styles.getStyleModel(model.styleId);
  12893. }
  12894. }
  12895. }, {
  12896. key: "tag",
  12897. get: function get() {
  12898. return 'col';
  12899. }
  12900. }]);
  12901. return ColXform;
  12902. }(BaseXform);
  12903. module.exports = ColXform;
  12904. },{"../base-xform":31}],92:[function(require,module,exports){
  12905. "use strict";
  12906. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  12907. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12908. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  12909. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  12910. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  12911. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  12912. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  12913. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  12914. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  12915. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  12916. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  12917. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  12918. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  12919. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  12920. var _ = require('../../../utils/under-dash');
  12921. var utils = require('../../../utils/utils');
  12922. var colCache = require('../../../utils/col-cache');
  12923. var BaseXform = require('../base-xform');
  12924. var Range = require('../../../doc/range');
  12925. function assign(definedName, attributes, name, defaultValue) {
  12926. var value = attributes[name];
  12927. if (value !== undefined) {
  12928. definedName[name] = value;
  12929. } else if (defaultValue !== undefined) {
  12930. definedName[name] = defaultValue;
  12931. }
  12932. }
  12933. function parseBool(value) {
  12934. switch (value) {
  12935. case '1':
  12936. case 'true':
  12937. return true;
  12938. default:
  12939. return false;
  12940. }
  12941. }
  12942. function assignBool(definedName, attributes, name, defaultValue) {
  12943. var value = attributes[name];
  12944. if (value !== undefined) {
  12945. definedName[name] = parseBool(value);
  12946. } else if (defaultValue !== undefined) {
  12947. definedName[name] = defaultValue;
  12948. }
  12949. }
  12950. function optimiseDataValidations(model) {
  12951. // Squeeze alike data validations together into rectangular ranges
  12952. // to reduce file size and speed up Excel load time
  12953. var dvList = _.map(model, function (dataValidation, address) {
  12954. return {
  12955. address: address,
  12956. dataValidation: dataValidation,
  12957. marked: false
  12958. };
  12959. }).sort(function (a, b) {
  12960. return _.strcmp(a.address, b.address);
  12961. });
  12962. var dvMap = _.keyBy(dvList, 'address');
  12963. var matchCol = function matchCol(addr, height, col) {
  12964. for (var i = 0; i < height; i++) {
  12965. var otherAddress = colCache.encodeAddress(addr.row + i, col);
  12966. if (!model[otherAddress] || !_.isEqual(model[addr.address], model[otherAddress])) {
  12967. return false;
  12968. }
  12969. }
  12970. return true;
  12971. };
  12972. return dvList.map(function (dv) {
  12973. if (!dv.marked) {
  12974. var addr = colCache.decodeEx(dv.address);
  12975. if (addr.dimensions) {
  12976. dvMap[addr.dimensions].marked = true;
  12977. return _objectSpread(_objectSpread({}, dv.dataValidation), {}, {
  12978. sqref: dv.address
  12979. });
  12980. } // iterate downwards - finding matching cells
  12981. var height = 1;
  12982. var otherAddress = colCache.encodeAddress(addr.row + height, addr.col);
  12983. while (model[otherAddress] && _.isEqual(dv.dataValidation, model[otherAddress])) {
  12984. height++;
  12985. otherAddress = colCache.encodeAddress(addr.row + height, addr.col);
  12986. } // iterate rightwards...
  12987. var width = 1;
  12988. while (matchCol(addr, height, addr.col + width)) {
  12989. width++;
  12990. } // mark all included addresses
  12991. for (var i = 0; i < height; i++) {
  12992. for (var j = 0; j < width; j++) {
  12993. otherAddress = colCache.encodeAddress(addr.row + i, addr.col + j);
  12994. dvMap[otherAddress].marked = true;
  12995. }
  12996. }
  12997. if (height > 1 || width > 1) {
  12998. var bottom = addr.row + (height - 1);
  12999. var right = addr.col + (width - 1);
  13000. return _objectSpread(_objectSpread({}, dv.dataValidation), {}, {
  13001. sqref: "".concat(dv.address, ":").concat(colCache.encodeAddress(bottom, right))
  13002. });
  13003. }
  13004. return _objectSpread(_objectSpread({}, dv.dataValidation), {}, {
  13005. sqref: dv.address
  13006. });
  13007. }
  13008. return null;
  13009. }).filter(Boolean);
  13010. }
  13011. var DataValidationsXform = /*#__PURE__*/function (_BaseXform) {
  13012. _inherits(DataValidationsXform, _BaseXform);
  13013. var _super = _createSuper(DataValidationsXform);
  13014. function DataValidationsXform() {
  13015. _classCallCheck(this, DataValidationsXform);
  13016. return _super.apply(this, arguments);
  13017. }
  13018. _createClass(DataValidationsXform, [{
  13019. key: "render",
  13020. value: function render(xmlStream, model) {
  13021. var optimizedModel = optimiseDataValidations(model);
  13022. if (optimizedModel.length) {
  13023. xmlStream.openNode('dataValidations', {
  13024. count: optimizedModel.length
  13025. });
  13026. optimizedModel.forEach(function (value) {
  13027. xmlStream.openNode('dataValidation');
  13028. if (value.type !== 'any') {
  13029. xmlStream.addAttribute('type', value.type);
  13030. if (value.operator && value.type !== 'list' && value.operator !== 'between') {
  13031. xmlStream.addAttribute('operator', value.operator);
  13032. }
  13033. if (value.allowBlank) {
  13034. xmlStream.addAttribute('allowBlank', '1');
  13035. }
  13036. }
  13037. if (value.showInputMessage) {
  13038. xmlStream.addAttribute('showInputMessage', '1');
  13039. }
  13040. if (value.promptTitle) {
  13041. xmlStream.addAttribute('promptTitle', value.promptTitle);
  13042. }
  13043. if (value.prompt) {
  13044. xmlStream.addAttribute('prompt', value.prompt);
  13045. }
  13046. if (value.showErrorMessage) {
  13047. xmlStream.addAttribute('showErrorMessage', '1');
  13048. }
  13049. if (value.errorStyle) {
  13050. xmlStream.addAttribute('errorStyle', value.errorStyle);
  13051. }
  13052. if (value.errorTitle) {
  13053. xmlStream.addAttribute('errorTitle', value.errorTitle);
  13054. }
  13055. if (value.error) {
  13056. xmlStream.addAttribute('error', value.error);
  13057. }
  13058. xmlStream.addAttribute('sqref', value.sqref);
  13059. (value.formulae || []).forEach(function (formula, index) {
  13060. xmlStream.openNode("formula".concat(index + 1));
  13061. if (value.type === 'date') {
  13062. xmlStream.writeText(utils.dateToExcel(new Date(formula)));
  13063. } else {
  13064. xmlStream.writeText(formula);
  13065. }
  13066. xmlStream.closeNode();
  13067. });
  13068. xmlStream.closeNode();
  13069. });
  13070. xmlStream.closeNode();
  13071. }
  13072. }
  13073. }, {
  13074. key: "parseOpen",
  13075. value: function parseOpen(node) {
  13076. switch (node.name) {
  13077. case 'dataValidations':
  13078. this.model = {};
  13079. return true;
  13080. case 'dataValidation':
  13081. {
  13082. this._address = node.attributes.sqref;
  13083. var dataValidation = {
  13084. type: node.attributes.type || 'any',
  13085. formulae: []
  13086. };
  13087. if (node.attributes.type) {
  13088. assignBool(dataValidation, node.attributes, 'allowBlank');
  13089. }
  13090. assignBool(dataValidation, node.attributes, 'showInputMessage');
  13091. assignBool(dataValidation, node.attributes, 'showErrorMessage');
  13092. switch (dataValidation.type) {
  13093. case 'any':
  13094. case 'list':
  13095. case 'custom':
  13096. break;
  13097. default:
  13098. assign(dataValidation, node.attributes, 'operator', 'between');
  13099. break;
  13100. }
  13101. assign(dataValidation, node.attributes, 'promptTitle');
  13102. assign(dataValidation, node.attributes, 'prompt');
  13103. assign(dataValidation, node.attributes, 'errorStyle');
  13104. assign(dataValidation, node.attributes, 'errorTitle');
  13105. assign(dataValidation, node.attributes, 'error');
  13106. this._dataValidation = dataValidation;
  13107. return true;
  13108. }
  13109. case 'formula1':
  13110. case 'formula2':
  13111. this._formula = [];
  13112. return true;
  13113. default:
  13114. return false;
  13115. }
  13116. }
  13117. }, {
  13118. key: "parseText",
  13119. value: function parseText(text) {
  13120. if (this._formula) {
  13121. this._formula.push(text);
  13122. }
  13123. }
  13124. }, {
  13125. key: "parseClose",
  13126. value: function parseClose(name) {
  13127. var _this = this;
  13128. switch (name) {
  13129. case 'dataValidations':
  13130. return false;
  13131. case 'dataValidation':
  13132. {
  13133. if (!this._dataValidation.formulae || !this._dataValidation.formulae.length) {
  13134. delete this._dataValidation.formulae;
  13135. delete this._dataValidation.operator;
  13136. } // The four known cases: 1. E4:L9 N4:U9 2.E4 L9 3. N4:U9 4. E4
  13137. var list = this._address.split(/\s+/g) || [];
  13138. list.forEach(function (addr) {
  13139. if (addr.includes(':')) {
  13140. var range = new Range(addr);
  13141. range.forEachAddress(function (address) {
  13142. _this.model[address] = _this._dataValidation;
  13143. });
  13144. } else {
  13145. _this.model[addr] = _this._dataValidation;
  13146. }
  13147. });
  13148. return true;
  13149. }
  13150. case 'formula1':
  13151. case 'formula2':
  13152. {
  13153. var formula = this._formula.join('');
  13154. switch (this._dataValidation.type) {
  13155. case 'whole':
  13156. case 'textLength':
  13157. formula = parseInt(formula, 10);
  13158. break;
  13159. case 'decimal':
  13160. formula = parseFloat(formula);
  13161. break;
  13162. case 'date':
  13163. formula = utils.excelToDate(parseFloat(formula));
  13164. break;
  13165. default:
  13166. break;
  13167. }
  13168. this._dataValidation.formulae.push(formula);
  13169. this._formula = undefined;
  13170. return true;
  13171. }
  13172. default:
  13173. return true;
  13174. }
  13175. }
  13176. }, {
  13177. key: "tag",
  13178. get: function get() {
  13179. return 'dataValidations';
  13180. }
  13181. }]);
  13182. return DataValidationsXform;
  13183. }(BaseXform);
  13184. module.exports = DataValidationsXform;
  13185. },{"../../../doc/range":10,"../../../utils/col-cache":19,"../../../utils/under-dash":25,"../../../utils/utils":26,"../base-xform":31}],93:[function(require,module,exports){
  13186. "use strict";
  13187. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  13188. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13189. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  13190. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13191. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  13192. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13193. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  13194. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13195. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13196. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  13197. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13198. var BaseXform = require('../base-xform');
  13199. var DimensionXform = /*#__PURE__*/function (_BaseXform) {
  13200. _inherits(DimensionXform, _BaseXform);
  13201. var _super = _createSuper(DimensionXform);
  13202. function DimensionXform() {
  13203. _classCallCheck(this, DimensionXform);
  13204. return _super.apply(this, arguments);
  13205. }
  13206. _createClass(DimensionXform, [{
  13207. key: "render",
  13208. value: function render(xmlStream, model) {
  13209. if (model) {
  13210. xmlStream.leafNode('dimension', {
  13211. ref: model
  13212. });
  13213. }
  13214. }
  13215. }, {
  13216. key: "parseOpen",
  13217. value: function parseOpen(node) {
  13218. if (node.name === 'dimension') {
  13219. this.model = node.attributes.ref;
  13220. return true;
  13221. }
  13222. return false;
  13223. }
  13224. }, {
  13225. key: "parseText",
  13226. value: function parseText() {}
  13227. }, {
  13228. key: "parseClose",
  13229. value: function parseClose() {
  13230. return false;
  13231. }
  13232. }, {
  13233. key: "tag",
  13234. get: function get() {
  13235. return 'dimension';
  13236. }
  13237. }]);
  13238. return DimensionXform;
  13239. }(BaseXform);
  13240. module.exports = DimensionXform;
  13241. },{"../base-xform":31}],94:[function(require,module,exports){
  13242. "use strict";
  13243. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  13244. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13245. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  13246. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13247. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  13248. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13249. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  13250. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13251. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13252. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  13253. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13254. var BaseXform = require('../base-xform');
  13255. var DrawingXform = /*#__PURE__*/function (_BaseXform) {
  13256. _inherits(DrawingXform, _BaseXform);
  13257. var _super = _createSuper(DrawingXform);
  13258. function DrawingXform() {
  13259. _classCallCheck(this, DrawingXform);
  13260. return _super.apply(this, arguments);
  13261. }
  13262. _createClass(DrawingXform, [{
  13263. key: "render",
  13264. value: function render(xmlStream, model) {
  13265. if (model) {
  13266. xmlStream.leafNode(this.tag, {
  13267. 'r:id': model.rId
  13268. });
  13269. }
  13270. }
  13271. }, {
  13272. key: "parseOpen",
  13273. value: function parseOpen(node) {
  13274. switch (node.name) {
  13275. case this.tag:
  13276. this.model = {
  13277. rId: node.attributes['r:id']
  13278. };
  13279. return true;
  13280. default:
  13281. return false;
  13282. }
  13283. }
  13284. }, {
  13285. key: "parseText",
  13286. value: function parseText() {}
  13287. }, {
  13288. key: "parseClose",
  13289. value: function parseClose() {
  13290. return false;
  13291. }
  13292. }, {
  13293. key: "tag",
  13294. get: function get() {
  13295. return 'drawing';
  13296. }
  13297. }]);
  13298. return DrawingXform;
  13299. }(BaseXform);
  13300. module.exports = DrawingXform;
  13301. },{"../base-xform":31}],95:[function(require,module,exports){
  13302. "use strict";
  13303. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  13304. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13305. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  13306. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13307. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  13308. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13309. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  13310. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13311. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13312. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  13313. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13314. /* eslint-disable max-classes-per-file */
  13315. var CompositeXform = require('../composite-xform');
  13316. var ConditionalFormattingsExt = require('./cf-ext/conditional-formattings-ext-xform');
  13317. var ExtXform = /*#__PURE__*/function (_CompositeXform) {
  13318. _inherits(ExtXform, _CompositeXform);
  13319. var _super = _createSuper(ExtXform);
  13320. function ExtXform() {
  13321. var _this;
  13322. _classCallCheck(this, ExtXform);
  13323. _this = _super.call(this);
  13324. _this.map = {
  13325. 'x14:conditionalFormattings': _this.conditionalFormattings = new ConditionalFormattingsExt()
  13326. };
  13327. return _this;
  13328. }
  13329. _createClass(ExtXform, [{
  13330. key: "hasContent",
  13331. value: function hasContent(model) {
  13332. return this.conditionalFormattings.hasContent(model.conditionalFormattings);
  13333. }
  13334. }, {
  13335. key: "prepare",
  13336. value: function prepare(model, options) {
  13337. this.conditionalFormattings.prepare(model.conditionalFormattings, options);
  13338. }
  13339. }, {
  13340. key: "render",
  13341. value: function render(xmlStream, model) {
  13342. xmlStream.openNode('ext', {
  13343. uri: '{78C0D931-6437-407d-A8EE-F0AAD7539E65}',
  13344. 'xmlns:x14': 'http://schemas.microsoft.com/office/spreadsheetml/2009/9/main'
  13345. });
  13346. this.conditionalFormattings.render(xmlStream, model.conditionalFormattings);
  13347. xmlStream.closeNode();
  13348. }
  13349. }, {
  13350. key: "createNewModel",
  13351. value: function createNewModel() {
  13352. return {};
  13353. }
  13354. }, {
  13355. key: "onParserClose",
  13356. value: function onParserClose(name, parser) {
  13357. this.model[name] = parser.model;
  13358. }
  13359. }, {
  13360. key: "tag",
  13361. get: function get() {
  13362. return 'ext';
  13363. }
  13364. }]);
  13365. return ExtXform;
  13366. }(CompositeXform);
  13367. var ExtLstXform = /*#__PURE__*/function (_CompositeXform2) {
  13368. _inherits(ExtLstXform, _CompositeXform2);
  13369. var _super2 = _createSuper(ExtLstXform);
  13370. function ExtLstXform() {
  13371. var _this2;
  13372. _classCallCheck(this, ExtLstXform);
  13373. _this2 = _super2.call(this);
  13374. _this2.map = {
  13375. ext: _this2.ext = new ExtXform()
  13376. };
  13377. return _this2;
  13378. }
  13379. _createClass(ExtLstXform, [{
  13380. key: "prepare",
  13381. value: function prepare(model, options) {
  13382. this.ext.prepare(model, options);
  13383. }
  13384. }, {
  13385. key: "hasContent",
  13386. value: function hasContent(model) {
  13387. return this.ext.hasContent(model);
  13388. }
  13389. }, {
  13390. key: "render",
  13391. value: function render(xmlStream, model) {
  13392. if (!this.hasContent(model)) {
  13393. return;
  13394. }
  13395. xmlStream.openNode('extLst');
  13396. this.ext.render(xmlStream, model);
  13397. xmlStream.closeNode();
  13398. }
  13399. }, {
  13400. key: "createNewModel",
  13401. value: function createNewModel() {
  13402. return {};
  13403. }
  13404. }, {
  13405. key: "onParserClose",
  13406. value: function onParserClose(name, parser) {
  13407. Object.assign(this.model, parser.model);
  13408. }
  13409. }, {
  13410. key: "tag",
  13411. get: function get() {
  13412. return 'extLst';
  13413. }
  13414. }]);
  13415. return ExtLstXform;
  13416. }(CompositeXform);
  13417. module.exports = ExtLstXform;
  13418. },{"../composite-xform":47,"./cf-ext/conditional-formattings-ext-xform":77}],96:[function(require,module,exports){
  13419. "use strict";
  13420. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  13421. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13422. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  13423. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13424. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  13425. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13426. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  13427. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13428. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13429. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  13430. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13431. var BaseXform = require('../base-xform');
  13432. var HeaderFooterXform = /*#__PURE__*/function (_BaseXform) {
  13433. _inherits(HeaderFooterXform, _BaseXform);
  13434. var _super = _createSuper(HeaderFooterXform);
  13435. function HeaderFooterXform() {
  13436. _classCallCheck(this, HeaderFooterXform);
  13437. return _super.apply(this, arguments);
  13438. }
  13439. _createClass(HeaderFooterXform, [{
  13440. key: "render",
  13441. value: function render(xmlStream, model) {
  13442. if (model) {
  13443. xmlStream.addRollback();
  13444. var createTag = false;
  13445. xmlStream.openNode('headerFooter');
  13446. if (model.differentFirst) {
  13447. xmlStream.addAttribute('differentFirst', '1');
  13448. createTag = true;
  13449. }
  13450. if (model.differentOddEven) {
  13451. xmlStream.addAttribute('differentOddEven', '1');
  13452. createTag = true;
  13453. }
  13454. if (model.oddHeader && typeof model.oddHeader === 'string') {
  13455. xmlStream.leafNode('oddHeader', null, model.oddHeader);
  13456. createTag = true;
  13457. }
  13458. if (model.oddFooter && typeof model.oddFooter === 'string') {
  13459. xmlStream.leafNode('oddFooter', null, model.oddFooter);
  13460. createTag = true;
  13461. }
  13462. if (model.evenHeader && typeof model.evenHeader === 'string') {
  13463. xmlStream.leafNode('evenHeader', null, model.evenHeader);
  13464. createTag = true;
  13465. }
  13466. if (model.evenFooter && typeof model.evenFooter === 'string') {
  13467. xmlStream.leafNode('evenFooter', null, model.evenFooter);
  13468. createTag = true;
  13469. }
  13470. if (model.firstHeader && typeof model.firstHeader === 'string') {
  13471. xmlStream.leafNode('firstHeader', null, model.firstHeader);
  13472. createTag = true;
  13473. }
  13474. if (model.firstFooter && typeof model.firstFooter === 'string') {
  13475. xmlStream.leafNode('firstFooter', null, model.firstFooter);
  13476. createTag = true;
  13477. }
  13478. if (createTag) {
  13479. xmlStream.closeNode();
  13480. xmlStream.commit();
  13481. } else {
  13482. xmlStream.rollback();
  13483. }
  13484. }
  13485. }
  13486. }, {
  13487. key: "parseOpen",
  13488. value: function parseOpen(node) {
  13489. switch (node.name) {
  13490. case 'headerFooter':
  13491. this.model = {};
  13492. if (node.attributes.differentFirst) {
  13493. this.model.differentFirst = parseInt(node.attributes.differentFirst, 0) === 1;
  13494. }
  13495. if (node.attributes.differentOddEven) {
  13496. this.model.differentOddEven = parseInt(node.attributes.differentOddEven, 0) === 1;
  13497. }
  13498. return true;
  13499. case 'oddHeader':
  13500. this.currentNode = 'oddHeader';
  13501. return true;
  13502. case 'oddFooter':
  13503. this.currentNode = 'oddFooter';
  13504. return true;
  13505. case 'evenHeader':
  13506. this.currentNode = 'evenHeader';
  13507. return true;
  13508. case 'evenFooter':
  13509. this.currentNode = 'evenFooter';
  13510. return true;
  13511. case 'firstHeader':
  13512. this.currentNode = 'firstHeader';
  13513. return true;
  13514. case 'firstFooter':
  13515. this.currentNode = 'firstFooter';
  13516. return true;
  13517. default:
  13518. return false;
  13519. }
  13520. }
  13521. }, {
  13522. key: "parseText",
  13523. value: function parseText(text) {
  13524. switch (this.currentNode) {
  13525. case 'oddHeader':
  13526. this.model.oddHeader = text;
  13527. break;
  13528. case 'oddFooter':
  13529. this.model.oddFooter = text;
  13530. break;
  13531. case 'evenHeader':
  13532. this.model.evenHeader = text;
  13533. break;
  13534. case 'evenFooter':
  13535. this.model.evenFooter = text;
  13536. break;
  13537. case 'firstHeader':
  13538. this.model.firstHeader = text;
  13539. break;
  13540. case 'firstFooter':
  13541. this.model.firstFooter = text;
  13542. break;
  13543. default:
  13544. break;
  13545. }
  13546. }
  13547. }, {
  13548. key: "parseClose",
  13549. value: function parseClose() {
  13550. switch (this.currentNode) {
  13551. case 'oddHeader':
  13552. case 'oddFooter':
  13553. case 'evenHeader':
  13554. case 'evenFooter':
  13555. case 'firstHeader':
  13556. case 'firstFooter':
  13557. this.currentNode = undefined;
  13558. return true;
  13559. default:
  13560. return false;
  13561. }
  13562. }
  13563. }, {
  13564. key: "tag",
  13565. get: function get() {
  13566. return 'headerFooter';
  13567. }
  13568. }]);
  13569. return HeaderFooterXform;
  13570. }(BaseXform);
  13571. module.exports = HeaderFooterXform;
  13572. },{"../base-xform":31}],97:[function(require,module,exports){
  13573. "use strict";
  13574. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  13575. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13576. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  13577. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13578. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  13579. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13580. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  13581. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13582. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13583. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  13584. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13585. var BaseXform = require('../base-xform');
  13586. var HyperlinkXform = /*#__PURE__*/function (_BaseXform) {
  13587. _inherits(HyperlinkXform, _BaseXform);
  13588. var _super = _createSuper(HyperlinkXform);
  13589. function HyperlinkXform() {
  13590. _classCallCheck(this, HyperlinkXform);
  13591. return _super.apply(this, arguments);
  13592. }
  13593. _createClass(HyperlinkXform, [{
  13594. key: "render",
  13595. value: function render(xmlStream, model) {
  13596. xmlStream.leafNode('hyperlink', {
  13597. ref: model.address,
  13598. 'r:id': model.rId,
  13599. tooltip: model.tooltip
  13600. });
  13601. }
  13602. }, {
  13603. key: "parseOpen",
  13604. value: function parseOpen(node) {
  13605. if (node.name === 'hyperlink') {
  13606. this.model = {
  13607. address: node.attributes.ref,
  13608. rId: node.attributes['r:id'],
  13609. tooltip: node.attributes.tooltip
  13610. };
  13611. return true;
  13612. }
  13613. return false;
  13614. }
  13615. }, {
  13616. key: "parseText",
  13617. value: function parseText() {}
  13618. }, {
  13619. key: "parseClose",
  13620. value: function parseClose() {
  13621. return false;
  13622. }
  13623. }, {
  13624. key: "tag",
  13625. get: function get() {
  13626. return 'hyperlink';
  13627. }
  13628. }]);
  13629. return HyperlinkXform;
  13630. }(BaseXform);
  13631. module.exports = HyperlinkXform;
  13632. },{"../base-xform":31}],98:[function(require,module,exports){
  13633. "use strict";
  13634. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  13635. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13636. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  13637. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13638. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  13639. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13640. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  13641. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13642. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13643. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  13644. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13645. var BaseXform = require('../base-xform');
  13646. var MergeCellXform = /*#__PURE__*/function (_BaseXform) {
  13647. _inherits(MergeCellXform, _BaseXform);
  13648. var _super = _createSuper(MergeCellXform);
  13649. function MergeCellXform() {
  13650. _classCallCheck(this, MergeCellXform);
  13651. return _super.apply(this, arguments);
  13652. }
  13653. _createClass(MergeCellXform, [{
  13654. key: "render",
  13655. value: function render(xmlStream, model) {
  13656. xmlStream.leafNode('mergeCell', {
  13657. ref: model
  13658. });
  13659. }
  13660. }, {
  13661. key: "parseOpen",
  13662. value: function parseOpen(node) {
  13663. if (node.name === 'mergeCell') {
  13664. this.model = node.attributes.ref;
  13665. return true;
  13666. }
  13667. return false;
  13668. }
  13669. }, {
  13670. key: "parseText",
  13671. value: function parseText() {}
  13672. }, {
  13673. key: "parseClose",
  13674. value: function parseClose() {
  13675. return false;
  13676. }
  13677. }, {
  13678. key: "tag",
  13679. get: function get() {
  13680. return 'mergeCell';
  13681. }
  13682. }]);
  13683. return MergeCellXform;
  13684. }(BaseXform);
  13685. module.exports = MergeCellXform;
  13686. },{"../base-xform":31}],99:[function(require,module,exports){
  13687. "use strict";
  13688. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13689. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  13690. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13691. var _ = require('../../../utils/under-dash');
  13692. var Range = require('../../../doc/range');
  13693. var colCache = require('../../../utils/col-cache');
  13694. var Enums = require('../../../doc/enums');
  13695. var Merges = /*#__PURE__*/function () {
  13696. function Merges() {
  13697. _classCallCheck(this, Merges);
  13698. // optional mergeCells is array of ranges (like the xml)
  13699. this.merges = {};
  13700. }
  13701. _createClass(Merges, [{
  13702. key: "add",
  13703. value: function add(merge) {
  13704. // merge is {address, master}
  13705. if (this.merges[merge.master]) {
  13706. this.merges[merge.master].expandToAddress(merge.address);
  13707. } else {
  13708. var range = "".concat(merge.master, ":").concat(merge.address);
  13709. this.merges[merge.master] = new Range(range);
  13710. }
  13711. }
  13712. }, {
  13713. key: "reconcile",
  13714. value: function reconcile(mergeCells, rows) {
  13715. // reconcile merge list with merge cells
  13716. _.each(mergeCells, function (merge) {
  13717. var dimensions = colCache.decode(merge);
  13718. for (var i = dimensions.top; i <= dimensions.bottom; i++) {
  13719. var row = rows[i - 1];
  13720. for (var j = dimensions.left; j <= dimensions.right; j++) {
  13721. var cell = row.cells[j - 1];
  13722. if (!cell) {
  13723. // nulls are not included in document - so if master cell has no value - add a null one here
  13724. row.cells[j] = {
  13725. type: Enums.ValueType.Null,
  13726. address: colCache.encodeAddress(i, j)
  13727. };
  13728. } else if (cell.type === Enums.ValueType.Merge) {
  13729. cell.master = dimensions.tl;
  13730. }
  13731. }
  13732. }
  13733. });
  13734. }
  13735. }, {
  13736. key: "getMasterAddress",
  13737. value: function getMasterAddress(address) {
  13738. // if address has been merged, return its master's address. Assumes reconcile has been called
  13739. var range = this.hash[address];
  13740. return range && range.tl;
  13741. }
  13742. }, {
  13743. key: "mergeCells",
  13744. get: function get() {
  13745. return _.map(this.merges, function (merge) {
  13746. return merge.range;
  13747. });
  13748. }
  13749. }]);
  13750. return Merges;
  13751. }();
  13752. module.exports = Merges;
  13753. },{"../../../doc/enums":7,"../../../doc/range":10,"../../../utils/col-cache":19,"../../../utils/under-dash":25}],100:[function(require,module,exports){
  13754. "use strict";
  13755. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  13756. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13757. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  13758. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13759. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  13760. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13761. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  13762. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13763. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13764. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  13765. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13766. var BaseXform = require('../base-xform');
  13767. var isDefined = function isDefined(attr) {
  13768. return typeof attr !== 'undefined';
  13769. };
  13770. var OutlinePropertiesXform = /*#__PURE__*/function (_BaseXform) {
  13771. _inherits(OutlinePropertiesXform, _BaseXform);
  13772. var _super = _createSuper(OutlinePropertiesXform);
  13773. function OutlinePropertiesXform() {
  13774. _classCallCheck(this, OutlinePropertiesXform);
  13775. return _super.apply(this, arguments);
  13776. }
  13777. _createClass(OutlinePropertiesXform, [{
  13778. key: "render",
  13779. value: function render(xmlStream, model) {
  13780. if (model && (isDefined(model.summaryBelow) || isDefined(model.summaryRight))) {
  13781. xmlStream.leafNode(this.tag, {
  13782. summaryBelow: isDefined(model.summaryBelow) ? Number(model.summaryBelow) : undefined,
  13783. summaryRight: isDefined(model.summaryRight) ? Number(model.summaryRight) : undefined
  13784. });
  13785. return true;
  13786. }
  13787. return false;
  13788. }
  13789. }, {
  13790. key: "parseOpen",
  13791. value: function parseOpen(node) {
  13792. if (node.name === this.tag) {
  13793. this.model = {
  13794. summaryBelow: isDefined(node.attributes.summaryBelow) ? Boolean(Number(node.attributes.summaryBelow)) : undefined,
  13795. summaryRight: isDefined(node.attributes.summaryRight) ? Boolean(Number(node.attributes.summaryRight)) : undefined
  13796. };
  13797. return true;
  13798. }
  13799. return false;
  13800. }
  13801. }, {
  13802. key: "parseText",
  13803. value: function parseText() {}
  13804. }, {
  13805. key: "parseClose",
  13806. value: function parseClose() {
  13807. return false;
  13808. }
  13809. }, {
  13810. key: "tag",
  13811. get: function get() {
  13812. return 'outlinePr';
  13813. }
  13814. }]);
  13815. return OutlinePropertiesXform;
  13816. }(BaseXform);
  13817. module.exports = OutlinePropertiesXform;
  13818. },{"../base-xform":31}],101:[function(require,module,exports){
  13819. "use strict";
  13820. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  13821. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13822. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  13823. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13824. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  13825. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13826. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  13827. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13828. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13829. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  13830. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13831. var BaseXform = require('../base-xform');
  13832. var PageBreaksXform = /*#__PURE__*/function (_BaseXform) {
  13833. _inherits(PageBreaksXform, _BaseXform);
  13834. var _super = _createSuper(PageBreaksXform);
  13835. function PageBreaksXform() {
  13836. _classCallCheck(this, PageBreaksXform);
  13837. return _super.apply(this, arguments);
  13838. }
  13839. _createClass(PageBreaksXform, [{
  13840. key: "render",
  13841. value: function render(xmlStream, model) {
  13842. xmlStream.leafNode('brk', model);
  13843. }
  13844. }, {
  13845. key: "parseOpen",
  13846. value: function parseOpen(node) {
  13847. if (node.name === 'brk') {
  13848. this.model = node.attributes.ref;
  13849. return true;
  13850. }
  13851. return false;
  13852. }
  13853. }, {
  13854. key: "parseText",
  13855. value: function parseText() {}
  13856. }, {
  13857. key: "parseClose",
  13858. value: function parseClose() {
  13859. return false;
  13860. }
  13861. }, {
  13862. key: "tag",
  13863. get: function get() {
  13864. return 'brk';
  13865. }
  13866. }]);
  13867. return PageBreaksXform;
  13868. }(BaseXform);
  13869. module.exports = PageBreaksXform;
  13870. },{"../base-xform":31}],102:[function(require,module,exports){
  13871. "use strict";
  13872. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  13873. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13874. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  13875. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13876. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  13877. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13878. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  13879. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13880. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13881. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  13882. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13883. var _ = require('../../../utils/under-dash');
  13884. var BaseXform = require('../base-xform');
  13885. var PageMarginsXform = /*#__PURE__*/function (_BaseXform) {
  13886. _inherits(PageMarginsXform, _BaseXform);
  13887. var _super = _createSuper(PageMarginsXform);
  13888. function PageMarginsXform() {
  13889. _classCallCheck(this, PageMarginsXform);
  13890. return _super.apply(this, arguments);
  13891. }
  13892. _createClass(PageMarginsXform, [{
  13893. key: "render",
  13894. value: function render(xmlStream, model) {
  13895. if (model) {
  13896. var attributes = {
  13897. left: model.left,
  13898. right: model.right,
  13899. top: model.top,
  13900. bottom: model.bottom,
  13901. header: model.header,
  13902. footer: model.footer
  13903. };
  13904. if (_.some(attributes, function (value) {
  13905. return value !== undefined;
  13906. })) {
  13907. xmlStream.leafNode(this.tag, attributes);
  13908. }
  13909. }
  13910. }
  13911. }, {
  13912. key: "parseOpen",
  13913. value: function parseOpen(node) {
  13914. switch (node.name) {
  13915. case this.tag:
  13916. this.model = {
  13917. left: parseFloat(node.attributes.left || 0.7),
  13918. right: parseFloat(node.attributes.right || 0.7),
  13919. top: parseFloat(node.attributes.top || 0.75),
  13920. bottom: parseFloat(node.attributes.bottom || 0.75),
  13921. header: parseFloat(node.attributes.header || 0.3),
  13922. footer: parseFloat(node.attributes.footer || 0.3)
  13923. };
  13924. return true;
  13925. default:
  13926. return false;
  13927. }
  13928. }
  13929. }, {
  13930. key: "parseText",
  13931. value: function parseText() {}
  13932. }, {
  13933. key: "parseClose",
  13934. value: function parseClose() {
  13935. return false;
  13936. }
  13937. }, {
  13938. key: "tag",
  13939. get: function get() {
  13940. return 'pageMargins';
  13941. }
  13942. }]);
  13943. return PageMarginsXform;
  13944. }(BaseXform);
  13945. module.exports = PageMarginsXform;
  13946. },{"../../../utils/under-dash":25,"../base-xform":31}],103:[function(require,module,exports){
  13947. "use strict";
  13948. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  13949. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13950. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  13951. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13952. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  13953. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13954. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  13955. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13956. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13957. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  13958. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13959. var BaseXform = require('../base-xform');
  13960. var PageSetupPropertiesXform = /*#__PURE__*/function (_BaseXform) {
  13961. _inherits(PageSetupPropertiesXform, _BaseXform);
  13962. var _super = _createSuper(PageSetupPropertiesXform);
  13963. function PageSetupPropertiesXform() {
  13964. _classCallCheck(this, PageSetupPropertiesXform);
  13965. return _super.apply(this, arguments);
  13966. }
  13967. _createClass(PageSetupPropertiesXform, [{
  13968. key: "render",
  13969. value: function render(xmlStream, model) {
  13970. if (model && model.fitToPage) {
  13971. xmlStream.leafNode(this.tag, {
  13972. fitToPage: model.fitToPage ? '1' : undefined
  13973. });
  13974. return true;
  13975. }
  13976. return false;
  13977. }
  13978. }, {
  13979. key: "parseOpen",
  13980. value: function parseOpen(node) {
  13981. if (node.name === this.tag) {
  13982. this.model = {
  13983. fitToPage: node.attributes.fitToPage === '1'
  13984. };
  13985. return true;
  13986. }
  13987. return false;
  13988. }
  13989. }, {
  13990. key: "parseText",
  13991. value: function parseText() {}
  13992. }, {
  13993. key: "parseClose",
  13994. value: function parseClose() {
  13995. return false;
  13996. }
  13997. }, {
  13998. key: "tag",
  13999. get: function get() {
  14000. return 'pageSetUpPr';
  14001. }
  14002. }]);
  14003. return PageSetupPropertiesXform;
  14004. }(BaseXform);
  14005. module.exports = PageSetupPropertiesXform;
  14006. },{"../base-xform":31}],104:[function(require,module,exports){
  14007. "use strict";
  14008. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  14009. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14010. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  14011. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  14012. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  14013. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  14014. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  14015. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  14016. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  14017. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  14018. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  14019. var _ = require('../../../utils/under-dash');
  14020. var BaseXform = require('../base-xform');
  14021. function booleanToXml(model) {
  14022. return model ? '1' : undefined;
  14023. }
  14024. function pageOrderToXml(model) {
  14025. switch (model) {
  14026. case 'overThenDown':
  14027. return model;
  14028. default:
  14029. return undefined;
  14030. }
  14031. }
  14032. function cellCommentsToXml(model) {
  14033. switch (model) {
  14034. case 'atEnd':
  14035. case 'asDisplyed':
  14036. return model;
  14037. default:
  14038. return undefined;
  14039. }
  14040. }
  14041. function errorsToXml(model) {
  14042. switch (model) {
  14043. case 'dash':
  14044. case 'blank':
  14045. case 'NA':
  14046. return model;
  14047. default:
  14048. return undefined;
  14049. }
  14050. }
  14051. function pageSizeToModel(value) {
  14052. return value !== undefined ? parseInt(value, 10) : undefined;
  14053. }
  14054. var PageSetupXform = /*#__PURE__*/function (_BaseXform) {
  14055. _inherits(PageSetupXform, _BaseXform);
  14056. var _super = _createSuper(PageSetupXform);
  14057. function PageSetupXform() {
  14058. _classCallCheck(this, PageSetupXform);
  14059. return _super.apply(this, arguments);
  14060. }
  14061. _createClass(PageSetupXform, [{
  14062. key: "render",
  14063. value: function render(xmlStream, model) {
  14064. if (model) {
  14065. var attributes = {
  14066. paperSize: model.paperSize,
  14067. orientation: model.orientation,
  14068. horizontalDpi: model.horizontalDpi,
  14069. verticalDpi: model.verticalDpi,
  14070. pageOrder: pageOrderToXml(model.pageOrder),
  14071. blackAndWhite: booleanToXml(model.blackAndWhite),
  14072. draft: booleanToXml(model.draft),
  14073. cellComments: cellCommentsToXml(model.cellComments),
  14074. errors: errorsToXml(model.errors),
  14075. scale: model.scale,
  14076. fitToWidth: model.fitToWidth,
  14077. fitToHeight: model.fitToHeight,
  14078. firstPageNumber: model.firstPageNumber,
  14079. useFirstPageNumber: booleanToXml(model.firstPageNumber),
  14080. usePrinterDefaults: booleanToXml(model.usePrinterDefaults),
  14081. copies: model.copies
  14082. };
  14083. if (_.some(attributes, function (value) {
  14084. return value !== undefined;
  14085. })) {
  14086. xmlStream.leafNode(this.tag, attributes);
  14087. }
  14088. }
  14089. }
  14090. }, {
  14091. key: "parseOpen",
  14092. value: function parseOpen(node) {
  14093. switch (node.name) {
  14094. case this.tag:
  14095. this.model = {
  14096. paperSize: pageSizeToModel(node.attributes.paperSize),
  14097. orientation: node.attributes.orientation || 'portrait',
  14098. horizontalDpi: parseInt(node.attributes.horizontalDpi || '4294967295', 10),
  14099. verticalDpi: parseInt(node.attributes.verticalDpi || '4294967295', 10),
  14100. pageOrder: node.attributes.pageOrder || 'downThenOver',
  14101. blackAndWhite: node.attributes.blackAndWhite === '1',
  14102. draft: node.attributes.draft === '1',
  14103. cellComments: node.attributes.cellComments || 'None',
  14104. errors: node.attributes.errors || 'displayed',
  14105. scale: parseInt(node.attributes.scale || '100', 10),
  14106. fitToWidth: parseInt(node.attributes.fitToWidth || '1', 10),
  14107. fitToHeight: parseInt(node.attributes.fitToHeight || '1', 10),
  14108. firstPageNumber: parseInt(node.attributes.firstPageNumber || '1', 10),
  14109. useFirstPageNumber: node.attributes.useFirstPageNumber === '1',
  14110. usePrinterDefaults: node.attributes.usePrinterDefaults === '1',
  14111. copies: parseInt(node.attributes.copies || '1', 10)
  14112. };
  14113. return true;
  14114. default:
  14115. return false;
  14116. }
  14117. }
  14118. }, {
  14119. key: "parseText",
  14120. value: function parseText() {}
  14121. }, {
  14122. key: "parseClose",
  14123. value: function parseClose() {
  14124. return false;
  14125. }
  14126. }, {
  14127. key: "tag",
  14128. get: function get() {
  14129. return 'pageSetup';
  14130. }
  14131. }]);
  14132. return PageSetupXform;
  14133. }(BaseXform);
  14134. module.exports = PageSetupXform;
  14135. },{"../../../utils/under-dash":25,"../base-xform":31}],105:[function(require,module,exports){
  14136. "use strict";
  14137. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  14138. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14139. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  14140. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  14141. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  14142. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  14143. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  14144. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  14145. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  14146. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  14147. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  14148. var BaseXform = require('../base-xform');
  14149. var PictureXform = /*#__PURE__*/function (_BaseXform) {
  14150. _inherits(PictureXform, _BaseXform);
  14151. var _super = _createSuper(PictureXform);
  14152. function PictureXform() {
  14153. _classCallCheck(this, PictureXform);
  14154. return _super.apply(this, arguments);
  14155. }
  14156. _createClass(PictureXform, [{
  14157. key: "render",
  14158. value: function render(xmlStream, model) {
  14159. if (model) {
  14160. xmlStream.leafNode(this.tag, {
  14161. 'r:id': model.rId
  14162. });
  14163. }
  14164. }
  14165. }, {
  14166. key: "parseOpen",
  14167. value: function parseOpen(node) {
  14168. switch (node.name) {
  14169. case this.tag:
  14170. this.model = {
  14171. rId: node.attributes['r:id']
  14172. };
  14173. return true;
  14174. default:
  14175. return false;
  14176. }
  14177. }
  14178. }, {
  14179. key: "parseText",
  14180. value: function parseText() {}
  14181. }, {
  14182. key: "parseClose",
  14183. value: function parseClose() {
  14184. return false;
  14185. }
  14186. }, {
  14187. key: "tag",
  14188. get: function get() {
  14189. return 'picture';
  14190. }
  14191. }]);
  14192. return PictureXform;
  14193. }(BaseXform);
  14194. module.exports = PictureXform;
  14195. },{"../base-xform":31}],106:[function(require,module,exports){
  14196. "use strict";
  14197. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  14198. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14199. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  14200. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  14201. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  14202. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  14203. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  14204. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  14205. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  14206. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  14207. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  14208. var _ = require('../../../utils/under-dash');
  14209. var BaseXform = require('../base-xform');
  14210. function booleanToXml(model) {
  14211. return model ? '1' : undefined;
  14212. }
  14213. var PrintOptionsXform = /*#__PURE__*/function (_BaseXform) {
  14214. _inherits(PrintOptionsXform, _BaseXform);
  14215. var _super = _createSuper(PrintOptionsXform);
  14216. function PrintOptionsXform() {
  14217. _classCallCheck(this, PrintOptionsXform);
  14218. return _super.apply(this, arguments);
  14219. }
  14220. _createClass(PrintOptionsXform, [{
  14221. key: "render",
  14222. value: function render(xmlStream, model) {
  14223. if (model) {
  14224. var attributes = {
  14225. headings: booleanToXml(model.showRowColHeaders),
  14226. gridLines: booleanToXml(model.showGridLines),
  14227. horizontalCentered: booleanToXml(model.horizontalCentered),
  14228. verticalCentered: booleanToXml(model.verticalCentered)
  14229. };
  14230. if (_.some(attributes, function (value) {
  14231. return value !== undefined;
  14232. })) {
  14233. xmlStream.leafNode(this.tag, attributes);
  14234. }
  14235. }
  14236. }
  14237. }, {
  14238. key: "parseOpen",
  14239. value: function parseOpen(node) {
  14240. switch (node.name) {
  14241. case this.tag:
  14242. this.model = {
  14243. showRowColHeaders: node.attributes.headings === '1',
  14244. showGridLines: node.attributes.gridLines === '1',
  14245. horizontalCentered: node.attributes.horizontalCentered === '1',
  14246. verticalCentered: node.attributes.verticalCentered === '1'
  14247. };
  14248. return true;
  14249. default:
  14250. return false;
  14251. }
  14252. }
  14253. }, {
  14254. key: "parseText",
  14255. value: function parseText() {}
  14256. }, {
  14257. key: "parseClose",
  14258. value: function parseClose() {
  14259. return false;
  14260. }
  14261. }, {
  14262. key: "tag",
  14263. get: function get() {
  14264. return 'printOptions';
  14265. }
  14266. }]);
  14267. return PrintOptionsXform;
  14268. }(BaseXform);
  14269. module.exports = PrintOptionsXform;
  14270. },{"../../../utils/under-dash":25,"../base-xform":31}],107:[function(require,module,exports){
  14271. 'use strict';
  14272. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  14273. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14274. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  14275. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  14276. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  14277. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  14278. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  14279. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  14280. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  14281. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  14282. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  14283. var PageBreaksXform = require('./page-breaks-xform');
  14284. var ListXform = require('../list-xform');
  14285. var RowBreaksXform = /*#__PURE__*/function (_ListXform) {
  14286. _inherits(RowBreaksXform, _ListXform);
  14287. var _super = _createSuper(RowBreaksXform);
  14288. function RowBreaksXform() {
  14289. _classCallCheck(this, RowBreaksXform);
  14290. var options = {
  14291. tag: 'rowBreaks',
  14292. count: true,
  14293. childXform: new PageBreaksXform()
  14294. };
  14295. return _super.call(this, options);
  14296. } // get tag() { return 'rowBreaks'; }
  14297. _createClass(RowBreaksXform, [{
  14298. key: "render",
  14299. value: function render(xmlStream, model) {
  14300. if (model && model.length) {
  14301. xmlStream.openNode(this.tag, this.$);
  14302. if (this.count) {
  14303. xmlStream.addAttribute(this.$count, model.length);
  14304. xmlStream.addAttribute('manualBreakCount', model.length);
  14305. }
  14306. var childXform = this.childXform;
  14307. model.forEach(function (childModel) {
  14308. childXform.render(xmlStream, childModel);
  14309. });
  14310. xmlStream.closeNode();
  14311. } else if (this.empty) {
  14312. xmlStream.leafNode(this.tag);
  14313. }
  14314. }
  14315. }]);
  14316. return RowBreaksXform;
  14317. }(ListXform);
  14318. module.exports = RowBreaksXform;
  14319. },{"../list-xform":70,"./page-breaks-xform":101}],108:[function(require,module,exports){
  14320. "use strict";
  14321. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  14322. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14323. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  14324. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  14325. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  14326. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  14327. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  14328. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  14329. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  14330. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  14331. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  14332. var BaseXform = require('../base-xform');
  14333. var CellXform = require('./cell-xform');
  14334. var RowXform = /*#__PURE__*/function (_BaseXform) {
  14335. _inherits(RowXform, _BaseXform);
  14336. var _super = _createSuper(RowXform);
  14337. function RowXform(options) {
  14338. var _this;
  14339. _classCallCheck(this, RowXform);
  14340. _this = _super.call(this);
  14341. _this.maxItems = options && options.maxItems;
  14342. _this.map = {
  14343. c: new CellXform()
  14344. };
  14345. return _this;
  14346. }
  14347. _createClass(RowXform, [{
  14348. key: "prepare",
  14349. value: function prepare(model, options) {
  14350. var styleId = options.styles.addStyleModel(model.style);
  14351. if (styleId) {
  14352. model.styleId = styleId;
  14353. }
  14354. var cellXform = this.map.c;
  14355. model.cells.forEach(function (cellModel) {
  14356. cellXform.prepare(cellModel, options);
  14357. });
  14358. }
  14359. }, {
  14360. key: "render",
  14361. value: function render(xmlStream, model, options) {
  14362. xmlStream.openNode('row');
  14363. xmlStream.addAttribute('r', model.number);
  14364. if (model.height) {
  14365. xmlStream.addAttribute('ht', model.height);
  14366. xmlStream.addAttribute('customHeight', '1');
  14367. }
  14368. if (model.hidden) {
  14369. xmlStream.addAttribute('hidden', '1');
  14370. }
  14371. if (model.min > 0 && model.max > 0 && model.min <= model.max) {
  14372. xmlStream.addAttribute('spans', "".concat(model.min, ":").concat(model.max));
  14373. }
  14374. if (model.styleId) {
  14375. xmlStream.addAttribute('s', model.styleId);
  14376. xmlStream.addAttribute('customFormat', '1');
  14377. }
  14378. xmlStream.addAttribute('x14ac:dyDescent', '0.25');
  14379. if (model.outlineLevel) {
  14380. xmlStream.addAttribute('outlineLevel', model.outlineLevel);
  14381. }
  14382. if (model.collapsed) {
  14383. xmlStream.addAttribute('collapsed', '1');
  14384. }
  14385. var cellXform = this.map.c;
  14386. model.cells.forEach(function (cellModel) {
  14387. cellXform.render(xmlStream, cellModel, options);
  14388. });
  14389. xmlStream.closeNode();
  14390. }
  14391. }, {
  14392. key: "parseOpen",
  14393. value: function parseOpen(node) {
  14394. if (this.parser) {
  14395. this.parser.parseOpen(node);
  14396. return true;
  14397. }
  14398. if (node.name === 'row') {
  14399. this.numRowsSeen += 1;
  14400. var spans = node.attributes.spans ? node.attributes.spans.split(':').map(function (span) {
  14401. return parseInt(span, 10);
  14402. }) : [undefined, undefined];
  14403. var model = this.model = {
  14404. number: parseInt(node.attributes.r, 10),
  14405. min: spans[0],
  14406. max: spans[1],
  14407. cells: []
  14408. };
  14409. if (node.attributes.s) {
  14410. model.styleId = parseInt(node.attributes.s, 10);
  14411. }
  14412. if (node.attributes.hidden === true || node.attributes.hidden === 'true' || node.attributes.hidden === 1 || node.attributes.hidden === '1') {
  14413. model.hidden = true;
  14414. }
  14415. if (node.attributes.bestFit) {
  14416. model.bestFit = true;
  14417. }
  14418. if (node.attributes.ht) {
  14419. model.height = parseFloat(node.attributes.ht);
  14420. }
  14421. if (node.attributes.outlineLevel) {
  14422. model.outlineLevel = parseInt(node.attributes.outlineLevel, 10);
  14423. }
  14424. if (node.attributes.collapsed) {
  14425. model.collapsed = true;
  14426. }
  14427. return true;
  14428. }
  14429. this.parser = this.map[node.name];
  14430. if (this.parser) {
  14431. this.parser.parseOpen(node);
  14432. return true;
  14433. }
  14434. return false;
  14435. }
  14436. }, {
  14437. key: "parseText",
  14438. value: function parseText(text) {
  14439. if (this.parser) {
  14440. this.parser.parseText(text);
  14441. }
  14442. }
  14443. }, {
  14444. key: "parseClose",
  14445. value: function parseClose(name) {
  14446. if (this.parser) {
  14447. if (!this.parser.parseClose(name)) {
  14448. this.model.cells.push(this.parser.model);
  14449. if (this.maxItems && this.model.cells.length > this.maxItems) {
  14450. throw new Error("Max column count (".concat(this.maxItems, ") exceeded"));
  14451. }
  14452. this.parser = undefined;
  14453. }
  14454. return true;
  14455. }
  14456. return false;
  14457. }
  14458. }, {
  14459. key: "reconcile",
  14460. value: function reconcile(model, options) {
  14461. model.style = model.styleId ? options.styles.getStyleModel(model.styleId) : {};
  14462. if (model.styleId !== undefined) {
  14463. model.styleId = undefined;
  14464. }
  14465. var cellXform = this.map.c;
  14466. model.cells.forEach(function (cellModel) {
  14467. cellXform.reconcile(cellModel, options);
  14468. });
  14469. }
  14470. }, {
  14471. key: "tag",
  14472. get: function get() {
  14473. return 'row';
  14474. }
  14475. }]);
  14476. return RowXform;
  14477. }(BaseXform);
  14478. module.exports = RowXform;
  14479. },{"../base-xform":31,"./cell-xform":72}],109:[function(require,module,exports){
  14480. "use strict";
  14481. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  14482. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14483. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  14484. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  14485. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  14486. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  14487. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  14488. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  14489. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  14490. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  14491. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  14492. var _ = require('../../../utils/under-dash');
  14493. var BaseXform = require('../base-xform');
  14494. var SheetFormatPropertiesXform = /*#__PURE__*/function (_BaseXform) {
  14495. _inherits(SheetFormatPropertiesXform, _BaseXform);
  14496. var _super = _createSuper(SheetFormatPropertiesXform);
  14497. function SheetFormatPropertiesXform() {
  14498. _classCallCheck(this, SheetFormatPropertiesXform);
  14499. return _super.apply(this, arguments);
  14500. }
  14501. _createClass(SheetFormatPropertiesXform, [{
  14502. key: "render",
  14503. value: function render(xmlStream, model) {
  14504. if (model) {
  14505. var attributes = {
  14506. defaultRowHeight: model.defaultRowHeight,
  14507. outlineLevelRow: model.outlineLevelRow,
  14508. outlineLevelCol: model.outlineLevelCol,
  14509. 'x14ac:dyDescent': model.dyDescent
  14510. };
  14511. if (model.defaultColWidth) {
  14512. attributes.defaultColWidth = model.defaultColWidth;
  14513. } // default value for 'defaultRowHeight' is 15, this should not be 'custom'
  14514. if (!model.defaultRowHeight || model.defaultRowHeight !== 15) {
  14515. attributes.customHeight = '1';
  14516. }
  14517. if (_.some(attributes, function (value) {
  14518. return value !== undefined;
  14519. })) {
  14520. xmlStream.leafNode('sheetFormatPr', attributes);
  14521. }
  14522. }
  14523. }
  14524. }, {
  14525. key: "parseOpen",
  14526. value: function parseOpen(node) {
  14527. if (node.name === 'sheetFormatPr') {
  14528. this.model = {
  14529. defaultRowHeight: parseFloat(node.attributes.defaultRowHeight || '0'),
  14530. dyDescent: parseFloat(node.attributes['x14ac:dyDescent'] || '0'),
  14531. outlineLevelRow: parseInt(node.attributes.outlineLevelRow || '0', 10),
  14532. outlineLevelCol: parseInt(node.attributes.outlineLevelCol || '0', 10)
  14533. };
  14534. if (node.attributes.defaultColWidth) {
  14535. this.model.defaultColWidth = parseFloat(node.attributes.defaultColWidth);
  14536. }
  14537. return true;
  14538. }
  14539. return false;
  14540. }
  14541. }, {
  14542. key: "parseText",
  14543. value: function parseText() {}
  14544. }, {
  14545. key: "parseClose",
  14546. value: function parseClose() {
  14547. return false;
  14548. }
  14549. }, {
  14550. key: "tag",
  14551. get: function get() {
  14552. return 'sheetFormatPr';
  14553. }
  14554. }]);
  14555. return SheetFormatPropertiesXform;
  14556. }(BaseXform);
  14557. module.exports = SheetFormatPropertiesXform;
  14558. },{"../../../utils/under-dash":25,"../base-xform":31}],110:[function(require,module,exports){
  14559. "use strict";
  14560. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  14561. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14562. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  14563. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  14564. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  14565. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  14566. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  14567. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  14568. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  14569. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  14570. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  14571. var BaseXform = require('../base-xform');
  14572. var ColorXform = require('../style/color-xform');
  14573. var PageSetupPropertiesXform = require('./page-setup-properties-xform');
  14574. var OutlinePropertiesXform = require('./outline-properties-xform');
  14575. var SheetPropertiesXform = /*#__PURE__*/function (_BaseXform) {
  14576. _inherits(SheetPropertiesXform, _BaseXform);
  14577. var _super = _createSuper(SheetPropertiesXform);
  14578. function SheetPropertiesXform() {
  14579. var _this;
  14580. _classCallCheck(this, SheetPropertiesXform);
  14581. _this = _super.call(this);
  14582. _this.map = {
  14583. tabColor: new ColorXform('tabColor'),
  14584. pageSetUpPr: new PageSetupPropertiesXform(),
  14585. outlinePr: new OutlinePropertiesXform()
  14586. };
  14587. return _this;
  14588. }
  14589. _createClass(SheetPropertiesXform, [{
  14590. key: "render",
  14591. value: function render(xmlStream, model) {
  14592. if (model) {
  14593. xmlStream.addRollback();
  14594. xmlStream.openNode('sheetPr');
  14595. var inner = false;
  14596. inner = this.map.tabColor.render(xmlStream, model.tabColor) || inner;
  14597. inner = this.map.pageSetUpPr.render(xmlStream, model.pageSetup) || inner;
  14598. inner = this.map.outlinePr.render(xmlStream, model.outlineProperties) || inner;
  14599. if (inner) {
  14600. xmlStream.closeNode();
  14601. xmlStream.commit();
  14602. } else {
  14603. xmlStream.rollback();
  14604. }
  14605. }
  14606. }
  14607. }, {
  14608. key: "parseOpen",
  14609. value: function parseOpen(node) {
  14610. if (this.parser) {
  14611. this.parser.parseOpen(node);
  14612. return true;
  14613. }
  14614. if (node.name === this.tag) {
  14615. this.reset();
  14616. return true;
  14617. }
  14618. if (this.map[node.name]) {
  14619. this.parser = this.map[node.name];
  14620. this.parser.parseOpen(node);
  14621. return true;
  14622. }
  14623. return false;
  14624. }
  14625. }, {
  14626. key: "parseText",
  14627. value: function parseText(text) {
  14628. if (this.parser) {
  14629. this.parser.parseText(text);
  14630. return true;
  14631. }
  14632. return false;
  14633. }
  14634. }, {
  14635. key: "parseClose",
  14636. value: function parseClose(name) {
  14637. if (this.parser) {
  14638. if (!this.parser.parseClose(name)) {
  14639. this.parser = undefined;
  14640. }
  14641. return true;
  14642. }
  14643. if (this.map.tabColor.model || this.map.pageSetUpPr.model || this.map.outlinePr.model) {
  14644. this.model = {};
  14645. if (this.map.tabColor.model) {
  14646. this.model.tabColor = this.map.tabColor.model;
  14647. }
  14648. if (this.map.pageSetUpPr.model) {
  14649. this.model.pageSetup = this.map.pageSetUpPr.model;
  14650. }
  14651. if (this.map.outlinePr.model) {
  14652. this.model.outlineProperties = this.map.outlinePr.model;
  14653. }
  14654. } else {
  14655. this.model = null;
  14656. }
  14657. return false;
  14658. }
  14659. }, {
  14660. key: "tag",
  14661. get: function get() {
  14662. return 'sheetPr';
  14663. }
  14664. }]);
  14665. return SheetPropertiesXform;
  14666. }(BaseXform);
  14667. module.exports = SheetPropertiesXform;
  14668. },{"../base-xform":31,"../style/color-xform":127,"./outline-properties-xform":100,"./page-setup-properties-xform":103}],111:[function(require,module,exports){
  14669. "use strict";
  14670. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  14671. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14672. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  14673. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  14674. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  14675. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  14676. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  14677. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  14678. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  14679. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  14680. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  14681. var _ = require('../../../utils/under-dash');
  14682. var BaseXform = require('../base-xform');
  14683. function booleanToXml(model, value) {
  14684. return model ? value : undefined;
  14685. }
  14686. function xmlToBoolean(value, equals) {
  14687. return value === equals ? true : undefined;
  14688. }
  14689. var SheetProtectionXform = /*#__PURE__*/function (_BaseXform) {
  14690. _inherits(SheetProtectionXform, _BaseXform);
  14691. var _super = _createSuper(SheetProtectionXform);
  14692. function SheetProtectionXform() {
  14693. _classCallCheck(this, SheetProtectionXform);
  14694. return _super.apply(this, arguments);
  14695. }
  14696. _createClass(SheetProtectionXform, [{
  14697. key: "render",
  14698. value: function render(xmlStream, model) {
  14699. if (model) {
  14700. var attributes = {
  14701. sheet: booleanToXml(model.sheet, '1'),
  14702. selectLockedCells: model.selectLockedCells === false ? '1' : undefined,
  14703. selectUnlockedCells: model.selectUnlockedCells === false ? '1' : undefined,
  14704. formatCells: booleanToXml(model.formatCells, '0'),
  14705. formatColumns: booleanToXml(model.formatColumns, '0'),
  14706. formatRows: booleanToXml(model.formatRows, '0'),
  14707. insertColumns: booleanToXml(model.insertColumns, '0'),
  14708. insertRows: booleanToXml(model.insertRows, '0'),
  14709. insertHyperlinks: booleanToXml(model.insertHyperlinks, '0'),
  14710. deleteColumns: booleanToXml(model.deleteColumns, '0'),
  14711. deleteRows: booleanToXml(model.deleteRows, '0'),
  14712. sort: booleanToXml(model.sort, '0'),
  14713. autoFilter: booleanToXml(model.autoFilter, '0'),
  14714. pivotTables: booleanToXml(model.pivotTables, '0')
  14715. };
  14716. if (model.sheet) {
  14717. attributes.algorithmName = model.algorithmName;
  14718. attributes.hashValue = model.hashValue;
  14719. attributes.saltValue = model.saltValue;
  14720. attributes.spinCount = model.spinCount;
  14721. attributes.objects = booleanToXml(model.objects === false, '1');
  14722. attributes.scenarios = booleanToXml(model.scenarios === false, '1');
  14723. }
  14724. if (_.some(attributes, function (value) {
  14725. return value !== undefined;
  14726. })) {
  14727. xmlStream.leafNode(this.tag, attributes);
  14728. }
  14729. }
  14730. }
  14731. }, {
  14732. key: "parseOpen",
  14733. value: function parseOpen(node) {
  14734. switch (node.name) {
  14735. case this.tag:
  14736. this.model = {
  14737. sheet: xmlToBoolean(node.attributes.sheet, '1'),
  14738. objects: node.attributes.objects === '1' ? false : undefined,
  14739. scenarios: node.attributes.scenarios === '1' ? false : undefined,
  14740. selectLockedCells: node.attributes.selectLockedCells === '1' ? false : undefined,
  14741. selectUnlockedCells: node.attributes.selectUnlockedCells === '1' ? false : undefined,
  14742. formatCells: xmlToBoolean(node.attributes.formatCells, '0'),
  14743. formatColumns: xmlToBoolean(node.attributes.formatColumns, '0'),
  14744. formatRows: xmlToBoolean(node.attributes.formatRows, '0'),
  14745. insertColumns: xmlToBoolean(node.attributes.insertColumns, '0'),
  14746. insertRows: xmlToBoolean(node.attributes.insertRows, '0'),
  14747. insertHyperlinks: xmlToBoolean(node.attributes.insertHyperlinks, '0'),
  14748. deleteColumns: xmlToBoolean(node.attributes.deleteColumns, '0'),
  14749. deleteRows: xmlToBoolean(node.attributes.deleteRows, '0'),
  14750. sort: xmlToBoolean(node.attributes.sort, '0'),
  14751. autoFilter: xmlToBoolean(node.attributes.autoFilter, '0'),
  14752. pivotTables: xmlToBoolean(node.attributes.pivotTables, '0')
  14753. };
  14754. if (node.attributes.algorithmName) {
  14755. this.model.algorithmName = node.attributes.algorithmName;
  14756. this.model.hashValue = node.attributes.hashValue;
  14757. this.model.saltValue = node.attributes.saltValue;
  14758. this.model.spinCount = parseInt(node.attributes.spinCount, 10);
  14759. }
  14760. return true;
  14761. default:
  14762. return false;
  14763. }
  14764. }
  14765. }, {
  14766. key: "parseText",
  14767. value: function parseText() {}
  14768. }, {
  14769. key: "parseClose",
  14770. value: function parseClose() {
  14771. return false;
  14772. }
  14773. }, {
  14774. key: "tag",
  14775. get: function get() {
  14776. return 'sheetProtection';
  14777. }
  14778. }]);
  14779. return SheetProtectionXform;
  14780. }(BaseXform);
  14781. module.exports = SheetProtectionXform;
  14782. },{"../../../utils/under-dash":25,"../base-xform":31}],112:[function(require,module,exports){
  14783. "use strict";
  14784. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  14785. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14786. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  14787. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  14788. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  14789. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  14790. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  14791. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  14792. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  14793. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  14794. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  14795. var colCache = require('../../../utils/col-cache');
  14796. var BaseXform = require('../base-xform');
  14797. var VIEW_STATES = {
  14798. frozen: 'frozen',
  14799. frozenSplit: 'frozen',
  14800. split: 'split'
  14801. };
  14802. var SheetViewXform = /*#__PURE__*/function (_BaseXform) {
  14803. _inherits(SheetViewXform, _BaseXform);
  14804. var _super = _createSuper(SheetViewXform);
  14805. function SheetViewXform() {
  14806. _classCallCheck(this, SheetViewXform);
  14807. return _super.apply(this, arguments);
  14808. }
  14809. _createClass(SheetViewXform, [{
  14810. key: "prepare",
  14811. value: function prepare(model) {
  14812. switch (model.state) {
  14813. case 'frozen':
  14814. case 'split':
  14815. break;
  14816. default:
  14817. model.state = 'normal';
  14818. break;
  14819. }
  14820. }
  14821. }, {
  14822. key: "render",
  14823. value: function render(xmlStream, model) {
  14824. xmlStream.openNode('sheetView', {
  14825. workbookViewId: model.workbookViewId || 0
  14826. });
  14827. var add = function add(name, value, included) {
  14828. if (included) {
  14829. xmlStream.addAttribute(name, value);
  14830. }
  14831. };
  14832. add('rightToLeft', '1', model.rightToLeft === true);
  14833. add('tabSelected', '1', model.tabSelected);
  14834. add('showRuler', '0', model.showRuler === false);
  14835. add('showRowColHeaders', '0', model.showRowColHeaders === false);
  14836. add('showGridLines', '0', model.showGridLines === false);
  14837. add('zoomScale', model.zoomScale, model.zoomScale);
  14838. add('zoomScaleNormal', model.zoomScaleNormal, model.zoomScaleNormal);
  14839. add('view', model.style, model.style);
  14840. var topLeftCell;
  14841. var xSplit;
  14842. var ySplit;
  14843. var activePane;
  14844. switch (model.state) {
  14845. case 'frozen':
  14846. xSplit = model.xSplit || 0;
  14847. ySplit = model.ySplit || 0;
  14848. topLeftCell = model.topLeftCell || colCache.getAddress(ySplit + 1, xSplit + 1).address;
  14849. activePane = model.xSplit && model.ySplit && 'bottomRight' || model.xSplit && 'topRight' || 'bottomLeft';
  14850. xmlStream.leafNode('pane', {
  14851. xSplit: model.xSplit || undefined,
  14852. ySplit: model.ySplit || undefined,
  14853. topLeftCell: topLeftCell,
  14854. activePane: activePane,
  14855. state: 'frozen'
  14856. });
  14857. xmlStream.leafNode('selection', {
  14858. pane: activePane,
  14859. activeCell: model.activeCell,
  14860. sqref: model.activeCell
  14861. });
  14862. break;
  14863. case 'split':
  14864. if (model.activePane === 'topLeft') {
  14865. model.activePane = undefined;
  14866. }
  14867. xmlStream.leafNode('pane', {
  14868. xSplit: model.xSplit || undefined,
  14869. ySplit: model.ySplit || undefined,
  14870. topLeftCell: model.topLeftCell,
  14871. activePane: model.activePane
  14872. });
  14873. xmlStream.leafNode('selection', {
  14874. pane: model.activePane,
  14875. activeCell: model.activeCell,
  14876. sqref: model.activeCell
  14877. });
  14878. break;
  14879. case 'normal':
  14880. if (model.activeCell) {
  14881. xmlStream.leafNode('selection', {
  14882. activeCell: model.activeCell,
  14883. sqref: model.activeCell
  14884. });
  14885. }
  14886. break;
  14887. default:
  14888. break;
  14889. }
  14890. xmlStream.closeNode();
  14891. }
  14892. }, {
  14893. key: "parseOpen",
  14894. value: function parseOpen(node) {
  14895. switch (node.name) {
  14896. case 'sheetView':
  14897. this.sheetView = {
  14898. workbookViewId: parseInt(node.attributes.workbookViewId, 10),
  14899. rightToLeft: node.attributes.rightToLeft === '1',
  14900. tabSelected: node.attributes.tabSelected === '1',
  14901. showRuler: !(node.attributes.showRuler === '0'),
  14902. showRowColHeaders: !(node.attributes.showRowColHeaders === '0'),
  14903. showGridLines: !(node.attributes.showGridLines === '0'),
  14904. zoomScale: parseInt(node.attributes.zoomScale || '100', 10),
  14905. zoomScaleNormal: parseInt(node.attributes.zoomScaleNormal || '100', 10),
  14906. style: node.attributes.view
  14907. };
  14908. this.pane = undefined;
  14909. this.selections = {};
  14910. return true;
  14911. case 'pane':
  14912. this.pane = {
  14913. xSplit: parseInt(node.attributes.xSplit || '0', 10),
  14914. ySplit: parseInt(node.attributes.ySplit || '0', 10),
  14915. topLeftCell: node.attributes.topLeftCell,
  14916. activePane: node.attributes.activePane || 'topLeft',
  14917. state: node.attributes.state
  14918. };
  14919. return true;
  14920. case 'selection':
  14921. {
  14922. var name = node.attributes.pane || 'topLeft';
  14923. this.selections[name] = {
  14924. pane: name,
  14925. activeCell: node.attributes.activeCell
  14926. };
  14927. return true;
  14928. }
  14929. default:
  14930. return false;
  14931. }
  14932. }
  14933. }, {
  14934. key: "parseText",
  14935. value: function parseText() {}
  14936. }, {
  14937. key: "parseClose",
  14938. value: function parseClose(name) {
  14939. var model;
  14940. var selection;
  14941. switch (name) {
  14942. case 'sheetView':
  14943. if (this.sheetView && this.pane) {
  14944. model = this.model = {
  14945. workbookViewId: this.sheetView.workbookViewId,
  14946. rightToLeft: this.sheetView.rightToLeft,
  14947. state: VIEW_STATES[this.pane.state] || 'split',
  14948. // split is default
  14949. xSplit: this.pane.xSplit,
  14950. ySplit: this.pane.ySplit,
  14951. topLeftCell: this.pane.topLeftCell,
  14952. showRuler: this.sheetView.showRuler,
  14953. showRowColHeaders: this.sheetView.showRowColHeaders,
  14954. showGridLines: this.sheetView.showGridLines,
  14955. zoomScale: this.sheetView.zoomScale,
  14956. zoomScaleNormal: this.sheetView.zoomScaleNormal
  14957. };
  14958. if (this.model.state === 'split') {
  14959. model.activePane = this.pane.activePane;
  14960. }
  14961. selection = this.selections[this.pane.activePane];
  14962. if (selection && selection.activeCell) {
  14963. model.activeCell = selection.activeCell;
  14964. }
  14965. if (this.sheetView.style) {
  14966. model.style = this.sheetView.style;
  14967. }
  14968. } else {
  14969. model = this.model = {
  14970. workbookViewId: this.sheetView.workbookViewId,
  14971. rightToLeft: this.sheetView.rightToLeft,
  14972. state: 'normal',
  14973. showRuler: this.sheetView.showRuler,
  14974. showRowColHeaders: this.sheetView.showRowColHeaders,
  14975. showGridLines: this.sheetView.showGridLines,
  14976. zoomScale: this.sheetView.zoomScale,
  14977. zoomScaleNormal: this.sheetView.zoomScaleNormal
  14978. };
  14979. selection = this.selections.topLeft;
  14980. if (selection && selection.activeCell) {
  14981. model.activeCell = selection.activeCell;
  14982. }
  14983. if (this.sheetView.style) {
  14984. model.style = this.sheetView.style;
  14985. }
  14986. }
  14987. return false;
  14988. default:
  14989. return true;
  14990. }
  14991. }
  14992. }, {
  14993. key: "reconcile",
  14994. value: function reconcile() {}
  14995. }, {
  14996. key: "tag",
  14997. get: function get() {
  14998. return 'sheetView';
  14999. }
  15000. }]);
  15001. return SheetViewXform;
  15002. }(BaseXform);
  15003. module.exports = SheetViewXform;
  15004. },{"../../../utils/col-cache":19,"../base-xform":31}],113:[function(require,module,exports){
  15005. "use strict";
  15006. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  15007. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  15008. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  15009. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  15010. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  15011. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  15012. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  15013. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  15014. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  15015. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  15016. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  15017. var BaseXform = require('../base-xform');
  15018. var TablePartXform = /*#__PURE__*/function (_BaseXform) {
  15019. _inherits(TablePartXform, _BaseXform);
  15020. var _super = _createSuper(TablePartXform);
  15021. function TablePartXform() {
  15022. _classCallCheck(this, TablePartXform);
  15023. return _super.apply(this, arguments);
  15024. }
  15025. _createClass(TablePartXform, [{
  15026. key: "render",
  15027. value: function render(xmlStream, model) {
  15028. if (model) {
  15029. xmlStream.leafNode(this.tag, {
  15030. 'r:id': model.rId
  15031. });
  15032. }
  15033. }
  15034. }, {
  15035. key: "parseOpen",
  15036. value: function parseOpen(node) {
  15037. switch (node.name) {
  15038. case this.tag:
  15039. this.model = {
  15040. rId: node.attributes['r:id']
  15041. };
  15042. return true;
  15043. default:
  15044. return false;
  15045. }
  15046. }
  15047. }, {
  15048. key: "parseText",
  15049. value: function parseText() {}
  15050. }, {
  15051. key: "parseClose",
  15052. value: function parseClose() {
  15053. return false;
  15054. }
  15055. }, {
  15056. key: "tag",
  15057. get: function get() {
  15058. return 'tablePart';
  15059. }
  15060. }]);
  15061. return TablePartXform;
  15062. }(BaseXform);
  15063. module.exports = TablePartXform;
  15064. },{"../base-xform":31}],114:[function(require,module,exports){
  15065. "use strict";
  15066. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  15067. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  15068. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  15069. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  15070. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  15071. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  15072. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  15073. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  15074. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  15075. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  15076. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  15077. var _ = require('../../../utils/under-dash');
  15078. var colCache = require('../../../utils/col-cache');
  15079. var XmlStream = require('../../../utils/xml-stream');
  15080. var RelType = require('../../rel-type');
  15081. var Merges = require('./merges');
  15082. var BaseXform = require('../base-xform');
  15083. var ListXform = require('../list-xform');
  15084. var RowXform = require('./row-xform');
  15085. var ColXform = require('./col-xform');
  15086. var DimensionXform = require('./dimension-xform');
  15087. var HyperlinkXform = require('./hyperlink-xform');
  15088. var MergeCellXform = require('./merge-cell-xform');
  15089. var DataValidationsXform = require('./data-validations-xform');
  15090. var SheetPropertiesXform = require('./sheet-properties-xform');
  15091. var SheetFormatPropertiesXform = require('./sheet-format-properties-xform');
  15092. var SheetViewXform = require('./sheet-view-xform');
  15093. var SheetProtectionXform = require('./sheet-protection-xform');
  15094. var PageMarginsXform = require('./page-margins-xform');
  15095. var PageSetupXform = require('./page-setup-xform');
  15096. var PrintOptionsXform = require('./print-options-xform');
  15097. var AutoFilterXform = require('./auto-filter-xform');
  15098. var PictureXform = require('./picture-xform');
  15099. var DrawingXform = require('./drawing-xform');
  15100. var TablePartXform = require('./table-part-xform');
  15101. var RowBreaksXform = require('./row-breaks-xform');
  15102. var HeaderFooterXform = require('./header-footer-xform');
  15103. var ConditionalFormattingsXform = require('./cf/conditional-formattings-xform');
  15104. var ExtListXform = require('./ext-lst-xform');
  15105. var mergeRule = function mergeRule(rule, extRule) {
  15106. Object.keys(extRule).forEach(function (key) {
  15107. var value = rule[key];
  15108. var extValue = extRule[key];
  15109. if (value === undefined && extValue !== undefined) {
  15110. rule[key] = extValue;
  15111. }
  15112. });
  15113. };
  15114. var mergeConditionalFormattings = function mergeConditionalFormattings(model, extModel) {
  15115. // conditional formattings are rendered in worksheet.conditionalFormatting and also in
  15116. // worksheet.extLst.ext.x14:conditionalFormattings
  15117. // some (e.g. dataBar) are even spread across both!
  15118. if (!extModel || !extModel.length) {
  15119. return model;
  15120. }
  15121. if (!model || !model.length) {
  15122. return extModel;
  15123. } // index model rules by x14Id
  15124. var cfMap = {};
  15125. var ruleMap = {};
  15126. model.forEach(function (cf) {
  15127. cfMap[cf.ref] = cf;
  15128. cf.rules.forEach(function (rule) {
  15129. var x14Id = rule.x14Id;
  15130. if (x14Id) {
  15131. ruleMap[x14Id] = rule;
  15132. }
  15133. });
  15134. });
  15135. extModel.forEach(function (extCf) {
  15136. extCf.rules.forEach(function (extRule) {
  15137. var rule = ruleMap[extRule.x14Id];
  15138. if (rule) {
  15139. // merge with matching rule
  15140. mergeRule(rule, extRule);
  15141. } else if (cfMap[extCf.ref]) {
  15142. // reuse existing cf ref
  15143. cfMap[extCf.ref].rules.push(extRule);
  15144. } else {
  15145. // create new cf
  15146. model.push({
  15147. ref: extCf.ref,
  15148. rules: [extRule]
  15149. });
  15150. }
  15151. });
  15152. }); // need to cope with rules in extModel that don't exist in model
  15153. return model;
  15154. };
  15155. var WorkSheetXform = /*#__PURE__*/function (_BaseXform) {
  15156. _inherits(WorkSheetXform, _BaseXform);
  15157. var _super = _createSuper(WorkSheetXform);
  15158. function WorkSheetXform(options) {
  15159. var _this;
  15160. _classCallCheck(this, WorkSheetXform);
  15161. _this = _super.call(this);
  15162. var _ref = options || {},
  15163. maxRows = _ref.maxRows,
  15164. maxCols = _ref.maxCols;
  15165. _this.map = {
  15166. sheetPr: new SheetPropertiesXform(),
  15167. dimension: new DimensionXform(),
  15168. sheetViews: new ListXform({
  15169. tag: 'sheetViews',
  15170. count: false,
  15171. childXform: new SheetViewXform()
  15172. }),
  15173. sheetFormatPr: new SheetFormatPropertiesXform(),
  15174. cols: new ListXform({
  15175. tag: 'cols',
  15176. count: false,
  15177. childXform: new ColXform()
  15178. }),
  15179. sheetData: new ListXform({
  15180. tag: 'sheetData',
  15181. count: false,
  15182. empty: true,
  15183. childXform: new RowXform({
  15184. maxItems: maxCols
  15185. }),
  15186. maxItems: maxRows
  15187. }),
  15188. autoFilter: new AutoFilterXform(),
  15189. mergeCells: new ListXform({
  15190. tag: 'mergeCells',
  15191. count: true,
  15192. childXform: new MergeCellXform()
  15193. }),
  15194. rowBreaks: new RowBreaksXform(),
  15195. hyperlinks: new ListXform({
  15196. tag: 'hyperlinks',
  15197. count: false,
  15198. childXform: new HyperlinkXform()
  15199. }),
  15200. pageMargins: new PageMarginsXform(),
  15201. dataValidations: new DataValidationsXform(),
  15202. pageSetup: new PageSetupXform(),
  15203. headerFooter: new HeaderFooterXform(),
  15204. printOptions: new PrintOptionsXform(),
  15205. picture: new PictureXform(),
  15206. drawing: new DrawingXform(),
  15207. sheetProtection: new SheetProtectionXform(),
  15208. tableParts: new ListXform({
  15209. tag: 'tableParts',
  15210. count: true,
  15211. childXform: new TablePartXform()
  15212. }),
  15213. conditionalFormatting: new ConditionalFormattingsXform(),
  15214. extLst: new ExtListXform()
  15215. };
  15216. return _this;
  15217. }
  15218. _createClass(WorkSheetXform, [{
  15219. key: "prepare",
  15220. value: function prepare(model, options) {
  15221. var _this2 = this;
  15222. options.merges = new Merges();
  15223. model.hyperlinks = options.hyperlinks = [];
  15224. model.comments = options.comments = [];
  15225. options.formulae = {};
  15226. options.siFormulae = 0;
  15227. this.map.cols.prepare(model.cols, options);
  15228. this.map.sheetData.prepare(model.rows, options);
  15229. this.map.conditionalFormatting.prepare(model.conditionalFormattings, options);
  15230. model.mergeCells = options.merges.mergeCells; // prepare relationships
  15231. var rels = model.rels = [];
  15232. function nextRid(r) {
  15233. return "rId".concat(r.length + 1);
  15234. }
  15235. model.hyperlinks.forEach(function (hyperlink) {
  15236. var rId = nextRid(rels);
  15237. hyperlink.rId = rId;
  15238. rels.push({
  15239. Id: rId,
  15240. Type: RelType.Hyperlink,
  15241. Target: hyperlink.target,
  15242. TargetMode: 'External'
  15243. });
  15244. }); // prepare comment relationships
  15245. if (model.comments.length > 0) {
  15246. var comment = {
  15247. Id: nextRid(rels),
  15248. Type: RelType.Comments,
  15249. Target: "../comments".concat(model.id, ".xml")
  15250. };
  15251. rels.push(comment);
  15252. var vmlDrawing = {
  15253. Id: nextRid(rels),
  15254. Type: RelType.VmlDrawing,
  15255. Target: "../drawings/vmlDrawing".concat(model.id, ".vml")
  15256. };
  15257. rels.push(vmlDrawing);
  15258. model.comments.forEach(function (item) {
  15259. item.refAddress = colCache.decodeAddress(item.ref);
  15260. });
  15261. options.commentRefs.push({
  15262. commentName: "comments".concat(model.id),
  15263. vmlDrawing: "vmlDrawing".concat(model.id)
  15264. });
  15265. }
  15266. var drawingRelsHash = [];
  15267. var bookImage;
  15268. model.media.forEach(function (medium) {
  15269. if (medium.type === 'background') {
  15270. var rId = nextRid(rels);
  15271. bookImage = options.media[medium.imageId];
  15272. rels.push({
  15273. Id: rId,
  15274. Type: RelType.Image,
  15275. Target: "../media/".concat(bookImage.name, ".").concat(bookImage.extension)
  15276. });
  15277. model.background = {
  15278. rId: rId
  15279. };
  15280. model.image = options.media[medium.imageId];
  15281. } else if (medium.type === 'image') {
  15282. var drawing = model.drawing;
  15283. bookImage = options.media[medium.imageId];
  15284. if (!drawing) {
  15285. drawing = model.drawing = {
  15286. rId: nextRid(rels),
  15287. name: "drawing".concat(++options.drawingsCount),
  15288. anchors: [],
  15289. rels: []
  15290. };
  15291. options.drawings.push(drawing);
  15292. rels.push({
  15293. Id: drawing.rId,
  15294. Type: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing',
  15295. Target: "../drawings/".concat(drawing.name, ".xml")
  15296. });
  15297. }
  15298. var rIdImage = _this2.preImageId === medium.imageId ? drawingRelsHash[medium.imageId] : drawingRelsHash[drawing.rels.length];
  15299. if (!rIdImage) {
  15300. rIdImage = nextRid(drawing.rels);
  15301. drawingRelsHash[drawing.rels.length] = rIdImage;
  15302. drawing.rels.push({
  15303. Id: rIdImage,
  15304. Type: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image',
  15305. Target: "../media/".concat(bookImage.name, ".").concat(bookImage.extension)
  15306. });
  15307. }
  15308. var anchor = {
  15309. picture: {
  15310. rId: rIdImage
  15311. },
  15312. range: medium.range
  15313. };
  15314. if (medium.hyperlinks && medium.hyperlinks.hyperlink) {
  15315. var rIdHyperLink = nextRid(drawing.rels);
  15316. drawingRelsHash[drawing.rels.length] = rIdHyperLink;
  15317. anchor.picture.hyperlinks = {
  15318. tooltip: medium.hyperlinks.tooltip,
  15319. rId: rIdHyperLink
  15320. };
  15321. drawing.rels.push({
  15322. Id: rIdHyperLink,
  15323. Type: RelType.Hyperlink,
  15324. Target: medium.hyperlinks.hyperlink,
  15325. TargetMode: 'External'
  15326. });
  15327. }
  15328. _this2.preImageId = medium.imageId;
  15329. drawing.anchors.push(anchor);
  15330. }
  15331. }); // prepare tables
  15332. model.tables.forEach(function (table) {
  15333. // relationships
  15334. var rId = nextRid(rels);
  15335. table.rId = rId;
  15336. rels.push({
  15337. Id: rId,
  15338. Type: RelType.Table,
  15339. Target: "../tables/".concat(table.target)
  15340. }); // dynamic styles
  15341. table.columns.forEach(function (column) {
  15342. var style = column.style;
  15343. if (style) {
  15344. column.dxfId = options.styles.addDxfStyle(style);
  15345. }
  15346. });
  15347. }); // prepare ext items
  15348. this.map.extLst.prepare(model, options);
  15349. }
  15350. }, {
  15351. key: "render",
  15352. value: function render(xmlStream, model) {
  15353. xmlStream.openXml(XmlStream.StdDocAttributes);
  15354. xmlStream.openNode('worksheet', WorkSheetXform.WORKSHEET_ATTRIBUTES);
  15355. var sheetFormatPropertiesModel = model.properties ? {
  15356. defaultRowHeight: model.properties.defaultRowHeight,
  15357. dyDescent: model.properties.dyDescent,
  15358. outlineLevelCol: model.properties.outlineLevelCol,
  15359. outlineLevelRow: model.properties.outlineLevelRow
  15360. } : undefined;
  15361. if (model.properties && model.properties.defaultColWidth) {
  15362. sheetFormatPropertiesModel.defaultColWidth = model.properties.defaultColWidth;
  15363. }
  15364. var sheetPropertiesModel = {
  15365. outlineProperties: model.properties && model.properties.outlineProperties,
  15366. tabColor: model.properties && model.properties.tabColor,
  15367. pageSetup: model.pageSetup && model.pageSetup.fitToPage ? {
  15368. fitToPage: model.pageSetup.fitToPage
  15369. } : undefined
  15370. };
  15371. var pageMarginsModel = model.pageSetup && model.pageSetup.margins;
  15372. var printOptionsModel = {
  15373. showRowColHeaders: model.pageSetup && model.pageSetup.showRowColHeaders,
  15374. showGridLines: model.pageSetup && model.pageSetup.showGridLines,
  15375. horizontalCentered: model.pageSetup && model.pageSetup.horizontalCentered,
  15376. verticalCentered: model.pageSetup && model.pageSetup.verticalCentered
  15377. };
  15378. var sheetProtectionModel = model.sheetProtection;
  15379. this.map.sheetPr.render(xmlStream, sheetPropertiesModel);
  15380. this.map.dimension.render(xmlStream, model.dimensions);
  15381. this.map.sheetViews.render(xmlStream, model.views);
  15382. this.map.sheetFormatPr.render(xmlStream, sheetFormatPropertiesModel);
  15383. this.map.cols.render(xmlStream, model.cols);
  15384. this.map.sheetData.render(xmlStream, model.rows);
  15385. this.map.sheetProtection.render(xmlStream, sheetProtectionModel); // Note: must be after sheetData and before autoFilter
  15386. this.map.autoFilter.render(xmlStream, model.autoFilter);
  15387. this.map.mergeCells.render(xmlStream, model.mergeCells);
  15388. this.map.conditionalFormatting.render(xmlStream, model.conditionalFormattings); // Note: must be before dataValidations
  15389. this.map.dataValidations.render(xmlStream, model.dataValidations); // For some reason hyperlinks have to be after the data validations
  15390. this.map.hyperlinks.render(xmlStream, model.hyperlinks);
  15391. this.map.printOptions.render(xmlStream, printOptionsModel); // Note: must be before pageMargins
  15392. this.map.pageMargins.render(xmlStream, pageMarginsModel);
  15393. this.map.pageSetup.render(xmlStream, model.pageSetup);
  15394. this.map.headerFooter.render(xmlStream, model.headerFooter);
  15395. this.map.rowBreaks.render(xmlStream, model.rowBreaks);
  15396. this.map.drawing.render(xmlStream, model.drawing); // Note: must be after rowBreaks
  15397. this.map.picture.render(xmlStream, model.background); // Note: must be after drawing
  15398. this.map.tableParts.render(xmlStream, model.tables);
  15399. this.map.extLst.render(xmlStream, model);
  15400. if (model.rels) {
  15401. // add a <legacyDrawing /> node for each comment
  15402. model.rels.forEach(function (rel) {
  15403. if (rel.Type === RelType.VmlDrawing) {
  15404. xmlStream.leafNode('legacyDrawing', {
  15405. 'r:id': rel.Id
  15406. });
  15407. }
  15408. });
  15409. }
  15410. xmlStream.closeNode();
  15411. }
  15412. }, {
  15413. key: "parseOpen",
  15414. value: function parseOpen(node) {
  15415. if (this.parser) {
  15416. this.parser.parseOpen(node);
  15417. return true;
  15418. }
  15419. if (node.name === 'worksheet') {
  15420. _.each(this.map, function (xform) {
  15421. xform.reset();
  15422. });
  15423. return true;
  15424. }
  15425. this.parser = this.map[node.name];
  15426. if (this.parser) {
  15427. this.parser.parseOpen(node);
  15428. }
  15429. return true;
  15430. }
  15431. }, {
  15432. key: "parseText",
  15433. value: function parseText(text) {
  15434. if (this.parser) {
  15435. this.parser.parseText(text);
  15436. }
  15437. }
  15438. }, {
  15439. key: "parseClose",
  15440. value: function parseClose(name) {
  15441. if (this.parser) {
  15442. if (!this.parser.parseClose(name)) {
  15443. this.parser = undefined;
  15444. }
  15445. return true;
  15446. }
  15447. switch (name) {
  15448. case 'worksheet':
  15449. {
  15450. var properties = this.map.sheetFormatPr.model || {};
  15451. if (this.map.sheetPr.model && this.map.sheetPr.model.tabColor) {
  15452. properties.tabColor = this.map.sheetPr.model.tabColor;
  15453. }
  15454. if (this.map.sheetPr.model && this.map.sheetPr.model.outlineProperties) {
  15455. properties.outlineProperties = this.map.sheetPr.model.outlineProperties;
  15456. }
  15457. var sheetProperties = {
  15458. fitToPage: this.map.sheetPr.model && this.map.sheetPr.model.pageSetup && this.map.sheetPr.model.pageSetup.fitToPage || false,
  15459. margins: this.map.pageMargins.model
  15460. };
  15461. var pageSetup = Object.assign(sheetProperties, this.map.pageSetup.model, this.map.printOptions.model);
  15462. var conditionalFormattings = mergeConditionalFormattings(this.map.conditionalFormatting.model, this.map.extLst.model && this.map.extLst.model['x14:conditionalFormattings']);
  15463. this.model = {
  15464. dimensions: this.map.dimension.model,
  15465. cols: this.map.cols.model,
  15466. rows: this.map.sheetData.model,
  15467. mergeCells: this.map.mergeCells.model,
  15468. hyperlinks: this.map.hyperlinks.model,
  15469. dataValidations: this.map.dataValidations.model,
  15470. properties: properties,
  15471. views: this.map.sheetViews.model,
  15472. pageSetup: pageSetup,
  15473. headerFooter: this.map.headerFooter.model,
  15474. background: this.map.picture.model,
  15475. drawing: this.map.drawing.model,
  15476. tables: this.map.tableParts.model,
  15477. conditionalFormattings: conditionalFormattings
  15478. };
  15479. if (this.map.autoFilter.model) {
  15480. this.model.autoFilter = this.map.autoFilter.model;
  15481. }
  15482. if (this.map.sheetProtection.model) {
  15483. this.model.sheetProtection = this.map.sheetProtection.model;
  15484. }
  15485. return false;
  15486. }
  15487. default:
  15488. // not quite sure how we get here!
  15489. return true;
  15490. }
  15491. }
  15492. }, {
  15493. key: "reconcile",
  15494. value: function reconcile(model, options) {
  15495. // options.merges = new Merges();
  15496. // options.merges.reconcile(model.mergeCells, model.rows);
  15497. var rels = (model.relationships || []).reduce(function (h, rel) {
  15498. h[rel.Id] = rel;
  15499. if (rel.Type === RelType.Comments) {
  15500. model.comments = options.comments[rel.Target].comments;
  15501. }
  15502. if (rel.Type === RelType.VmlDrawing && model.comments && model.comments.length) {
  15503. var vmlComment = options.vmlDrawings[rel.Target].comments;
  15504. model.comments.forEach(function (comment, index) {
  15505. comment.note = Object.assign({}, comment.note, vmlComment[index]);
  15506. });
  15507. }
  15508. return h;
  15509. }, {});
  15510. options.commentsMap = (model.comments || []).reduce(function (h, comment) {
  15511. if (comment.ref) {
  15512. h[comment.ref] = comment;
  15513. }
  15514. return h;
  15515. }, {});
  15516. options.hyperlinkMap = (model.hyperlinks || []).reduce(function (h, hyperlink) {
  15517. if (hyperlink.rId) {
  15518. h[hyperlink.address] = rels[hyperlink.rId].Target;
  15519. }
  15520. return h;
  15521. }, {});
  15522. options.formulae = {}; // compact the rows and cells
  15523. model.rows = model.rows && model.rows.filter(Boolean) || [];
  15524. model.rows.forEach(function (row) {
  15525. row.cells = row.cells && row.cells.filter(Boolean) || [];
  15526. });
  15527. this.map.cols.reconcile(model.cols, options);
  15528. this.map.sheetData.reconcile(model.rows, options);
  15529. this.map.conditionalFormatting.reconcile(model.conditionalFormattings, options);
  15530. model.media = [];
  15531. if (model.drawing) {
  15532. var drawingRel = rels[model.drawing.rId];
  15533. var match = drawingRel.Target.match(/\/drawings\/([a-zA-Z0-9]+)[.][a-zA-Z]{3,4}$/);
  15534. if (match) {
  15535. var drawingName = match[1];
  15536. var drawing = options.drawings[drawingName];
  15537. drawing.anchors.forEach(function (anchor) {
  15538. if (anchor.medium) {
  15539. var image = {
  15540. type: 'image',
  15541. imageId: anchor.medium.index,
  15542. range: anchor.range,
  15543. hyperlinks: anchor.picture.hyperlinks
  15544. };
  15545. model.media.push(image);
  15546. }
  15547. });
  15548. }
  15549. }
  15550. var backgroundRel = model.background && rels[model.background.rId];
  15551. if (backgroundRel) {
  15552. var target = backgroundRel.Target.split('/media/')[1];
  15553. var imageId = options.mediaIndex && options.mediaIndex[target];
  15554. if (imageId !== undefined) {
  15555. model.media.push({
  15556. type: 'background',
  15557. imageId: imageId
  15558. });
  15559. }
  15560. }
  15561. model.tables = (model.tables || []).map(function (tablePart) {
  15562. var rel = rels[tablePart.rId];
  15563. return options.tables[rel.Target];
  15564. });
  15565. delete model.relationships;
  15566. delete model.hyperlinks;
  15567. delete model.comments;
  15568. }
  15569. }]);
  15570. return WorkSheetXform;
  15571. }(BaseXform);
  15572. WorkSheetXform.WORKSHEET_ATTRIBUTES = {
  15573. xmlns: 'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
  15574. 'xmlns:r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
  15575. 'xmlns:mc': 'http://schemas.openxmlformats.org/markup-compatibility/2006',
  15576. 'mc:Ignorable': 'x14ac',
  15577. 'xmlns:x14ac': 'http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac'
  15578. };
  15579. module.exports = WorkSheetXform;
  15580. },{"../../../utils/col-cache":19,"../../../utils/under-dash":25,"../../../utils/xml-stream":27,"../../rel-type":30,"../base-xform":31,"../list-xform":70,"./auto-filter-xform":71,"./cf/conditional-formattings-xform":86,"./col-xform":91,"./data-validations-xform":92,"./dimension-xform":93,"./drawing-xform":94,"./ext-lst-xform":95,"./header-footer-xform":96,"./hyperlink-xform":97,"./merge-cell-xform":98,"./merges":99,"./page-margins-xform":102,"./page-setup-xform":104,"./picture-xform":105,"./print-options-xform":106,"./row-breaks-xform":107,"./row-xform":108,"./sheet-format-properties-xform":109,"./sheet-properties-xform":110,"./sheet-protection-xform":111,"./sheet-view-xform":112,"./table-part-xform":113}],115:[function(require,module,exports){
  15581. "use strict";
  15582. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  15583. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  15584. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  15585. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  15586. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  15587. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  15588. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  15589. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  15590. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  15591. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  15592. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  15593. var BaseXform = require('../base-xform');
  15594. var BooleanXform = /*#__PURE__*/function (_BaseXform) {
  15595. _inherits(BooleanXform, _BaseXform);
  15596. var _super = _createSuper(BooleanXform);
  15597. function BooleanXform(options) {
  15598. var _this;
  15599. _classCallCheck(this, BooleanXform);
  15600. _this = _super.call(this);
  15601. _this.tag = options.tag;
  15602. _this.attr = options.attr;
  15603. return _this;
  15604. }
  15605. _createClass(BooleanXform, [{
  15606. key: "render",
  15607. value: function render(xmlStream, model) {
  15608. if (model) {
  15609. xmlStream.openNode(this.tag);
  15610. xmlStream.closeNode();
  15611. }
  15612. }
  15613. }, {
  15614. key: "parseOpen",
  15615. value: function parseOpen(node) {
  15616. if (node.name === this.tag) {
  15617. this.model = true;
  15618. }
  15619. }
  15620. }, {
  15621. key: "parseText",
  15622. value: function parseText() {}
  15623. }, {
  15624. key: "parseClose",
  15625. value: function parseClose() {
  15626. return false;
  15627. }
  15628. }]);
  15629. return BooleanXform;
  15630. }(BaseXform);
  15631. module.exports = BooleanXform;
  15632. },{"../base-xform":31}],116:[function(require,module,exports){
  15633. "use strict";
  15634. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  15635. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  15636. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  15637. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  15638. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  15639. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  15640. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  15641. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  15642. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  15643. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  15644. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  15645. var BaseXform = require('../base-xform');
  15646. var DateXform = /*#__PURE__*/function (_BaseXform) {
  15647. _inherits(DateXform, _BaseXform);
  15648. var _super = _createSuper(DateXform);
  15649. function DateXform(options) {
  15650. var _this;
  15651. _classCallCheck(this, DateXform);
  15652. _this = _super.call(this);
  15653. _this.tag = options.tag;
  15654. _this.attr = options.attr;
  15655. _this.attrs = options.attrs;
  15656. _this._format = options.format || function (dt) {
  15657. try {
  15658. if (Number.isNaN(dt.getTime())) return '';
  15659. return dt.toISOString();
  15660. } catch (e) {
  15661. return '';
  15662. }
  15663. };
  15664. _this._parse = options.parse || function (str) {
  15665. return new Date(str);
  15666. };
  15667. return _this;
  15668. }
  15669. _createClass(DateXform, [{
  15670. key: "render",
  15671. value: function render(xmlStream, model) {
  15672. if (model) {
  15673. xmlStream.openNode(this.tag);
  15674. if (this.attrs) {
  15675. xmlStream.addAttributes(this.attrs);
  15676. }
  15677. if (this.attr) {
  15678. xmlStream.addAttribute(this.attr, this._format(model));
  15679. } else {
  15680. xmlStream.writeText(this._format(model));
  15681. }
  15682. xmlStream.closeNode();
  15683. }
  15684. }
  15685. }, {
  15686. key: "parseOpen",
  15687. value: function parseOpen(node) {
  15688. if (node.name === this.tag) {
  15689. if (this.attr) {
  15690. this.model = this._parse(node.attributes[this.attr]);
  15691. } else {
  15692. this.text = [];
  15693. }
  15694. }
  15695. }
  15696. }, {
  15697. key: "parseText",
  15698. value: function parseText(text) {
  15699. if (!this.attr) {
  15700. this.text.push(text);
  15701. }
  15702. }
  15703. }, {
  15704. key: "parseClose",
  15705. value: function parseClose() {
  15706. if (!this.attr) {
  15707. this.model = this._parse(this.text.join(''));
  15708. }
  15709. return false;
  15710. }
  15711. }]);
  15712. return DateXform;
  15713. }(BaseXform);
  15714. module.exports = DateXform;
  15715. },{"../base-xform":31}],117:[function(require,module,exports){
  15716. "use strict";
  15717. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  15718. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  15719. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  15720. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  15721. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  15722. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  15723. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  15724. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  15725. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  15726. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  15727. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  15728. var BaseXform = require('../base-xform');
  15729. var IntegerXform = /*#__PURE__*/function (_BaseXform) {
  15730. _inherits(IntegerXform, _BaseXform);
  15731. var _super = _createSuper(IntegerXform);
  15732. function IntegerXform(options) {
  15733. var _this;
  15734. _classCallCheck(this, IntegerXform);
  15735. _this = _super.call(this);
  15736. _this.tag = options.tag;
  15737. _this.attr = options.attr;
  15738. _this.attrs = options.attrs; // option to render zero
  15739. _this.zero = options.zero;
  15740. return _this;
  15741. }
  15742. _createClass(IntegerXform, [{
  15743. key: "render",
  15744. value: function render(xmlStream, model) {
  15745. // int is different to float in that zero is not rendered
  15746. if (model || this.zero) {
  15747. xmlStream.openNode(this.tag);
  15748. if (this.attrs) {
  15749. xmlStream.addAttributes(this.attrs);
  15750. }
  15751. if (this.attr) {
  15752. xmlStream.addAttribute(this.attr, model);
  15753. } else {
  15754. xmlStream.writeText(model);
  15755. }
  15756. xmlStream.closeNode();
  15757. }
  15758. }
  15759. }, {
  15760. key: "parseOpen",
  15761. value: function parseOpen(node) {
  15762. if (node.name === this.tag) {
  15763. if (this.attr) {
  15764. this.model = parseInt(node.attributes[this.attr], 10);
  15765. } else {
  15766. this.text = [];
  15767. }
  15768. return true;
  15769. }
  15770. return false;
  15771. }
  15772. }, {
  15773. key: "parseText",
  15774. value: function parseText(text) {
  15775. if (!this.attr) {
  15776. this.text.push(text);
  15777. }
  15778. }
  15779. }, {
  15780. key: "parseClose",
  15781. value: function parseClose() {
  15782. if (!this.attr) {
  15783. this.model = parseInt(this.text.join('') || 0, 10);
  15784. }
  15785. return false;
  15786. }
  15787. }]);
  15788. return IntegerXform;
  15789. }(BaseXform);
  15790. module.exports = IntegerXform;
  15791. },{"../base-xform":31}],118:[function(require,module,exports){
  15792. "use strict";
  15793. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  15794. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  15795. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  15796. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  15797. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  15798. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  15799. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  15800. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  15801. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  15802. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  15803. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  15804. var BaseXform = require('../base-xform');
  15805. var StringXform = /*#__PURE__*/function (_BaseXform) {
  15806. _inherits(StringXform, _BaseXform);
  15807. var _super = _createSuper(StringXform);
  15808. function StringXform(options) {
  15809. var _this;
  15810. _classCallCheck(this, StringXform);
  15811. _this = _super.call(this);
  15812. _this.tag = options.tag;
  15813. _this.attr = options.attr;
  15814. _this.attrs = options.attrs;
  15815. return _this;
  15816. }
  15817. _createClass(StringXform, [{
  15818. key: "render",
  15819. value: function render(xmlStream, model) {
  15820. if (model !== undefined) {
  15821. xmlStream.openNode(this.tag);
  15822. if (this.attrs) {
  15823. xmlStream.addAttributes(this.attrs);
  15824. }
  15825. if (this.attr) {
  15826. xmlStream.addAttribute(this.attr, model);
  15827. } else {
  15828. xmlStream.writeText(model);
  15829. }
  15830. xmlStream.closeNode();
  15831. }
  15832. }
  15833. }, {
  15834. key: "parseOpen",
  15835. value: function parseOpen(node) {
  15836. if (node.name === this.tag) {
  15837. if (this.attr) {
  15838. this.model = node.attributes[this.attr];
  15839. } else {
  15840. this.text = [];
  15841. }
  15842. }
  15843. }
  15844. }, {
  15845. key: "parseText",
  15846. value: function parseText(text) {
  15847. if (!this.attr) {
  15848. this.text.push(text);
  15849. }
  15850. }
  15851. }, {
  15852. key: "parseClose",
  15853. value: function parseClose() {
  15854. if (!this.attr) {
  15855. this.model = this.text.join('');
  15856. }
  15857. return false;
  15858. }
  15859. }]);
  15860. return StringXform;
  15861. }(BaseXform);
  15862. module.exports = StringXform;
  15863. },{"../base-xform":31}],119:[function(require,module,exports){
  15864. "use strict";
  15865. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  15866. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  15867. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  15868. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  15869. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  15870. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  15871. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  15872. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  15873. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  15874. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  15875. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  15876. var BaseXform = require('./base-xform');
  15877. var XmlStream = require('../../utils/xml-stream'); // const model = {
  15878. // tag: 'name',
  15879. // $: {attr: 'value'},
  15880. // c: [
  15881. // { tag: 'child' }
  15882. // ],
  15883. // t: 'some text'
  15884. // };
  15885. function build(xmlStream, model) {
  15886. xmlStream.openNode(model.tag, model.$);
  15887. if (model.c) {
  15888. model.c.forEach(function (child) {
  15889. build(xmlStream, child);
  15890. });
  15891. }
  15892. if (model.t) {
  15893. xmlStream.writeText(model.t);
  15894. }
  15895. xmlStream.closeNode();
  15896. }
  15897. var StaticXform = /*#__PURE__*/function (_BaseXform) {
  15898. _inherits(StaticXform, _BaseXform);
  15899. var _super = _createSuper(StaticXform);
  15900. function StaticXform(model) {
  15901. var _this;
  15902. _classCallCheck(this, StaticXform);
  15903. _this = _super.call(this); // This class is an optimisation for static (unimportant and unchanging) xml
  15904. // It is stateless - apart from its static model and so can be used as a singleton
  15905. // Being stateless - it will only track entry to and exit from it's root xml tag during parsing and nothing else
  15906. // Known issues:
  15907. // since stateless - parseOpen always returns true. Parent xform must know when to start using this xform
  15908. // if the root tag is recursive, the parsing will behave unpredictably
  15909. _this._model = model;
  15910. return _this;
  15911. }
  15912. _createClass(StaticXform, [{
  15913. key: "render",
  15914. value: function render(xmlStream) {
  15915. if (!this._xml) {
  15916. var stream = new XmlStream();
  15917. build(stream, this._model);
  15918. this._xml = stream.xml;
  15919. }
  15920. xmlStream.writeXml(this._xml);
  15921. }
  15922. }, {
  15923. key: "parseOpen",
  15924. value: function parseOpen() {
  15925. return true;
  15926. }
  15927. }, {
  15928. key: "parseText",
  15929. value: function parseText() {}
  15930. }, {
  15931. key: "parseClose",
  15932. value: function parseClose(name) {
  15933. switch (name) {
  15934. case this._model.tag:
  15935. return false;
  15936. default:
  15937. return true;
  15938. }
  15939. }
  15940. }]);
  15941. return StaticXform;
  15942. }(BaseXform);
  15943. module.exports = StaticXform;
  15944. },{"../../utils/xml-stream":27,"./base-xform":31}],120:[function(require,module,exports){
  15945. "use strict";
  15946. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  15947. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  15948. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  15949. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  15950. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  15951. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  15952. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  15953. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  15954. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  15955. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  15956. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  15957. var TextXform = require('./text-xform');
  15958. var RichTextXform = require('./rich-text-xform');
  15959. var BaseXform = require('../base-xform'); // <rPh sb="0" eb="1">
  15960. // <t>(its pronounciation in KATAKANA)</t>
  15961. // </rPh>
  15962. var PhoneticTextXform = /*#__PURE__*/function (_BaseXform) {
  15963. _inherits(PhoneticTextXform, _BaseXform);
  15964. var _super = _createSuper(PhoneticTextXform);
  15965. function PhoneticTextXform() {
  15966. var _this;
  15967. _classCallCheck(this, PhoneticTextXform);
  15968. _this = _super.call(this);
  15969. _this.map = {
  15970. r: new RichTextXform(),
  15971. t: new TextXform()
  15972. };
  15973. return _this;
  15974. }
  15975. _createClass(PhoneticTextXform, [{
  15976. key: "render",
  15977. value: function render(xmlStream, model) {
  15978. xmlStream.openNode(this.tag, {
  15979. sb: model.sb || 0,
  15980. eb: model.eb || 0
  15981. });
  15982. if (model && model.hasOwnProperty('richText') && model.richText) {
  15983. var r = this.map.r;
  15984. model.richText.forEach(function (text) {
  15985. r.render(xmlStream, text);
  15986. });
  15987. } else if (model) {
  15988. this.map.t.render(xmlStream, model.text);
  15989. }
  15990. xmlStream.closeNode();
  15991. }
  15992. }, {
  15993. key: "parseOpen",
  15994. value: function parseOpen(node) {
  15995. var name = node.name;
  15996. if (this.parser) {
  15997. this.parser.parseOpen(node);
  15998. return true;
  15999. }
  16000. if (name === this.tag) {
  16001. this.model = {
  16002. sb: parseInt(node.attributes.sb, 10),
  16003. eb: parseInt(node.attributes.eb, 10)
  16004. };
  16005. return true;
  16006. }
  16007. this.parser = this.map[name];
  16008. if (this.parser) {
  16009. this.parser.parseOpen(node);
  16010. return true;
  16011. }
  16012. return false;
  16013. }
  16014. }, {
  16015. key: "parseText",
  16016. value: function parseText(text) {
  16017. if (this.parser) {
  16018. this.parser.parseText(text);
  16019. }
  16020. }
  16021. }, {
  16022. key: "parseClose",
  16023. value: function parseClose(name) {
  16024. if (this.parser) {
  16025. if (!this.parser.parseClose(name)) {
  16026. switch (name) {
  16027. case 'r':
  16028. {
  16029. var rt = this.model.richText;
  16030. if (!rt) {
  16031. rt = this.model.richText = [];
  16032. }
  16033. rt.push(this.parser.model);
  16034. break;
  16035. }
  16036. case 't':
  16037. this.model.text = this.parser.model;
  16038. break;
  16039. default:
  16040. break;
  16041. }
  16042. this.parser = undefined;
  16043. }
  16044. return true;
  16045. }
  16046. switch (name) {
  16047. case this.tag:
  16048. return false;
  16049. default:
  16050. return true;
  16051. }
  16052. }
  16053. }, {
  16054. key: "tag",
  16055. get: function get() {
  16056. return 'rPh';
  16057. }
  16058. }]);
  16059. return PhoneticTextXform;
  16060. }(BaseXform);
  16061. module.exports = PhoneticTextXform;
  16062. },{"../base-xform":31,"./rich-text-xform":121,"./text-xform":124}],121:[function(require,module,exports){
  16063. "use strict";
  16064. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  16065. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16066. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  16067. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  16068. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  16069. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  16070. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  16071. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  16072. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  16073. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  16074. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  16075. var TextXform = require('./text-xform');
  16076. var FontXform = require('../style/font-xform');
  16077. var BaseXform = require('../base-xform'); // <r>
  16078. // <rPr>
  16079. // <sz val="11"/>
  16080. // <color theme="1" tint="5"/>
  16081. // <rFont val="Calibri"/>
  16082. // <family val="2"/>
  16083. // <scheme val="minor"/>
  16084. // </rPr>
  16085. // <t xml:space="preserve"> is </t>
  16086. // </r>
  16087. var RichTextXform = /*#__PURE__*/function (_BaseXform) {
  16088. _inherits(RichTextXform, _BaseXform);
  16089. var _super = _createSuper(RichTextXform);
  16090. function RichTextXform(model) {
  16091. var _this;
  16092. _classCallCheck(this, RichTextXform);
  16093. _this = _super.call(this);
  16094. _this.model = model;
  16095. return _this;
  16096. }
  16097. _createClass(RichTextXform, [{
  16098. key: "render",
  16099. value: function render(xmlStream, model) {
  16100. model = model || this.model;
  16101. xmlStream.openNode('r');
  16102. if (model.font) {
  16103. this.fontXform.render(xmlStream, model.font);
  16104. }
  16105. this.textXform.render(xmlStream, model.text);
  16106. xmlStream.closeNode();
  16107. }
  16108. }, {
  16109. key: "parseOpen",
  16110. value: function parseOpen(node) {
  16111. if (this.parser) {
  16112. this.parser.parseOpen(node);
  16113. return true;
  16114. }
  16115. switch (node.name) {
  16116. case 'r':
  16117. this.model = {};
  16118. return true;
  16119. case 't':
  16120. this.parser = this.textXform;
  16121. this.parser.parseOpen(node);
  16122. return true;
  16123. case 'rPr':
  16124. this.parser = this.fontXform;
  16125. this.parser.parseOpen(node);
  16126. return true;
  16127. default:
  16128. return false;
  16129. }
  16130. }
  16131. }, {
  16132. key: "parseText",
  16133. value: function parseText(text) {
  16134. if (this.parser) {
  16135. this.parser.parseText(text);
  16136. }
  16137. }
  16138. }, {
  16139. key: "parseClose",
  16140. value: function parseClose(name) {
  16141. switch (name) {
  16142. case 'r':
  16143. return false;
  16144. case 't':
  16145. this.model.text = this.parser.model;
  16146. this.parser = undefined;
  16147. return true;
  16148. case 'rPr':
  16149. this.model.font = this.parser.model;
  16150. this.parser = undefined;
  16151. return true;
  16152. default:
  16153. if (this.parser) {
  16154. this.parser.parseClose(name);
  16155. }
  16156. return true;
  16157. }
  16158. }
  16159. }, {
  16160. key: "tag",
  16161. get: function get() {
  16162. return 'r';
  16163. }
  16164. }, {
  16165. key: "textXform",
  16166. get: function get() {
  16167. return this._textXform || (this._textXform = new TextXform());
  16168. }
  16169. }, {
  16170. key: "fontXform",
  16171. get: function get() {
  16172. return this._fontXform || (this._fontXform = new FontXform(RichTextXform.FONT_OPTIONS));
  16173. }
  16174. }]);
  16175. return RichTextXform;
  16176. }(BaseXform);
  16177. RichTextXform.FONT_OPTIONS = {
  16178. tagName: 'rPr',
  16179. fontNameTag: 'rFont'
  16180. };
  16181. module.exports = RichTextXform;
  16182. },{"../base-xform":31,"../style/font-xform":130,"./text-xform":124}],122:[function(require,module,exports){
  16183. "use strict";
  16184. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  16185. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16186. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  16187. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  16188. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  16189. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  16190. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  16191. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  16192. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  16193. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  16194. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  16195. var TextXform = require('./text-xform');
  16196. var RichTextXform = require('./rich-text-xform');
  16197. var PhoneticTextXform = require('./phonetic-text-xform');
  16198. var BaseXform = require('../base-xform'); // <si>
  16199. // <r></r><r></r>...
  16200. // </si>
  16201. // <si>
  16202. // <t></t>
  16203. // </si>
  16204. var SharedStringXform = /*#__PURE__*/function (_BaseXform) {
  16205. _inherits(SharedStringXform, _BaseXform);
  16206. var _super = _createSuper(SharedStringXform);
  16207. function SharedStringXform(model) {
  16208. var _this;
  16209. _classCallCheck(this, SharedStringXform);
  16210. _this = _super.call(this);
  16211. _this.model = model;
  16212. _this.map = {
  16213. r: new RichTextXform(),
  16214. t: new TextXform(),
  16215. rPh: new PhoneticTextXform()
  16216. };
  16217. return _this;
  16218. }
  16219. _createClass(SharedStringXform, [{
  16220. key: "render",
  16221. value: function render(xmlStream, model) {
  16222. var _this2 = this;
  16223. xmlStream.openNode(this.tag);
  16224. if (model && model.hasOwnProperty('richText') && model.richText) {
  16225. if (model.richText.length) {
  16226. model.richText.forEach(function (text) {
  16227. _this2.map.r.render(xmlStream, text);
  16228. });
  16229. } else {
  16230. this.map.t.render(xmlStream, '');
  16231. }
  16232. } else if (model !== undefined && model !== null) {
  16233. this.map.t.render(xmlStream, model);
  16234. }
  16235. xmlStream.closeNode();
  16236. }
  16237. }, {
  16238. key: "parseOpen",
  16239. value: function parseOpen(node) {
  16240. var name = node.name;
  16241. if (this.parser) {
  16242. this.parser.parseOpen(node);
  16243. return true;
  16244. }
  16245. if (name === this.tag) {
  16246. this.model = {};
  16247. return true;
  16248. }
  16249. this.parser = this.map[name];
  16250. if (this.parser) {
  16251. this.parser.parseOpen(node);
  16252. return true;
  16253. }
  16254. return false;
  16255. }
  16256. }, {
  16257. key: "parseText",
  16258. value: function parseText(text) {
  16259. if (this.parser) {
  16260. this.parser.parseText(text);
  16261. }
  16262. }
  16263. }, {
  16264. key: "parseClose",
  16265. value: function parseClose(name) {
  16266. if (this.parser) {
  16267. if (!this.parser.parseClose(name)) {
  16268. switch (name) {
  16269. case 'r':
  16270. {
  16271. var rt = this.model.richText;
  16272. if (!rt) {
  16273. rt = this.model.richText = [];
  16274. }
  16275. rt.push(this.parser.model);
  16276. break;
  16277. }
  16278. case 't':
  16279. this.model = this.parser.model;
  16280. break;
  16281. default:
  16282. break;
  16283. }
  16284. this.parser = undefined;
  16285. }
  16286. return true;
  16287. }
  16288. switch (name) {
  16289. case this.tag:
  16290. return false;
  16291. default:
  16292. return true;
  16293. }
  16294. }
  16295. }, {
  16296. key: "tag",
  16297. get: function get() {
  16298. return 'si';
  16299. }
  16300. }]);
  16301. return SharedStringXform;
  16302. }(BaseXform);
  16303. module.exports = SharedStringXform;
  16304. },{"../base-xform":31,"./phonetic-text-xform":120,"./rich-text-xform":121,"./text-xform":124}],123:[function(require,module,exports){
  16305. "use strict";
  16306. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  16307. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16308. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  16309. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  16310. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  16311. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  16312. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  16313. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  16314. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  16315. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  16316. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  16317. var XmlStream = require('../../../utils/xml-stream');
  16318. var BaseXform = require('../base-xform');
  16319. var SharedStringXform = require('./shared-string-xform');
  16320. var SharedStringsXform = /*#__PURE__*/function (_BaseXform) {
  16321. _inherits(SharedStringsXform, _BaseXform);
  16322. var _super = _createSuper(SharedStringsXform);
  16323. function SharedStringsXform(model) {
  16324. var _this;
  16325. _classCallCheck(this, SharedStringsXform);
  16326. _this = _super.call(this);
  16327. _this.model = model || {
  16328. values: [],
  16329. count: 0
  16330. };
  16331. _this.hash = Object.create(null);
  16332. _this.rich = Object.create(null);
  16333. return _this;
  16334. }
  16335. _createClass(SharedStringsXform, [{
  16336. key: "getString",
  16337. value: function getString(index) {
  16338. return this.model.values[index];
  16339. }
  16340. }, {
  16341. key: "add",
  16342. value: function add(value) {
  16343. return value.richText ? this.addRichText(value) : this.addText(value);
  16344. }
  16345. }, {
  16346. key: "addText",
  16347. value: function addText(value) {
  16348. var index = this.hash[value];
  16349. if (index === undefined) {
  16350. index = this.hash[value] = this.model.values.length;
  16351. this.model.values.push(value);
  16352. }
  16353. this.model.count++;
  16354. return index;
  16355. }
  16356. }, {
  16357. key: "addRichText",
  16358. value: function addRichText(value) {
  16359. // TODO: add WeakMap here
  16360. var xml = this.sharedStringXform.toXml(value);
  16361. var index = this.rich[xml];
  16362. if (index === undefined) {
  16363. index = this.rich[xml] = this.model.values.length;
  16364. this.model.values.push(value);
  16365. }
  16366. this.model.count++;
  16367. return index;
  16368. } // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  16369. // <sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="<%=totalRefs%>" uniqueCount="<%=count%>">
  16370. // <si><t><%=text%></t></si>
  16371. // <si><r><rPr></rPr><t></t></r></si>
  16372. // </sst>
  16373. }, {
  16374. key: "render",
  16375. value: function render(xmlStream, model) {
  16376. model = model || this._values;
  16377. xmlStream.openXml(XmlStream.StdDocAttributes);
  16378. xmlStream.openNode('sst', {
  16379. xmlns: 'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
  16380. count: model.count,
  16381. uniqueCount: model.values.length
  16382. });
  16383. var sx = this.sharedStringXform;
  16384. model.values.forEach(function (sharedString) {
  16385. sx.render(xmlStream, sharedString);
  16386. });
  16387. xmlStream.closeNode();
  16388. }
  16389. }, {
  16390. key: "parseOpen",
  16391. value: function parseOpen(node) {
  16392. if (this.parser) {
  16393. this.parser.parseOpen(node);
  16394. return true;
  16395. }
  16396. switch (node.name) {
  16397. case 'sst':
  16398. return true;
  16399. case 'si':
  16400. this.parser = this.sharedStringXform;
  16401. this.parser.parseOpen(node);
  16402. return true;
  16403. default:
  16404. throw new Error("Unexpected xml node in parseOpen: ".concat(JSON.stringify(node)));
  16405. }
  16406. }
  16407. }, {
  16408. key: "parseText",
  16409. value: function parseText(text) {
  16410. if (this.parser) {
  16411. this.parser.parseText(text);
  16412. }
  16413. }
  16414. }, {
  16415. key: "parseClose",
  16416. value: function parseClose(name) {
  16417. if (this.parser) {
  16418. if (!this.parser.parseClose(name)) {
  16419. this.model.values.push(this.parser.model);
  16420. this.model.count++;
  16421. this.parser = undefined;
  16422. }
  16423. return true;
  16424. }
  16425. switch (name) {
  16426. case 'sst':
  16427. return false;
  16428. default:
  16429. throw new Error("Unexpected xml node in parseClose: ".concat(name));
  16430. }
  16431. }
  16432. }, {
  16433. key: "sharedStringXform",
  16434. get: function get() {
  16435. return this._sharedStringXform || (this._sharedStringXform = new SharedStringXform());
  16436. }
  16437. }, {
  16438. key: "values",
  16439. get: function get() {
  16440. return this.model.values;
  16441. }
  16442. }, {
  16443. key: "uniqueCount",
  16444. get: function get() {
  16445. return this.model.values.length;
  16446. }
  16447. }, {
  16448. key: "count",
  16449. get: function get() {
  16450. return this.model.count;
  16451. }
  16452. }]);
  16453. return SharedStringsXform;
  16454. }(BaseXform);
  16455. module.exports = SharedStringsXform;
  16456. },{"../../../utils/xml-stream":27,"../base-xform":31,"./shared-string-xform":122}],124:[function(require,module,exports){
  16457. "use strict";
  16458. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  16459. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16460. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  16461. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  16462. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  16463. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  16464. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  16465. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  16466. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  16467. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  16468. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  16469. var BaseXform = require('../base-xform'); // <t xml:space="preserve"> is </t>
  16470. var TextXform = /*#__PURE__*/function (_BaseXform) {
  16471. _inherits(TextXform, _BaseXform);
  16472. var _super = _createSuper(TextXform);
  16473. function TextXform() {
  16474. _classCallCheck(this, TextXform);
  16475. return _super.apply(this, arguments);
  16476. }
  16477. _createClass(TextXform, [{
  16478. key: "render",
  16479. value: function render(xmlStream, model) {
  16480. xmlStream.openNode('t');
  16481. if (/^\s|\n|\s$/.test(model)) {
  16482. xmlStream.addAttribute('xml:space', 'preserve');
  16483. }
  16484. xmlStream.writeText(model);
  16485. xmlStream.closeNode();
  16486. }
  16487. }, {
  16488. key: "parseOpen",
  16489. value: function parseOpen(node) {
  16490. switch (node.name) {
  16491. case 't':
  16492. this._text = [];
  16493. return true;
  16494. default:
  16495. return false;
  16496. }
  16497. }
  16498. }, {
  16499. key: "parseText",
  16500. value: function parseText(text) {
  16501. this._text.push(text);
  16502. }
  16503. }, {
  16504. key: "parseClose",
  16505. value: function parseClose() {
  16506. return false;
  16507. }
  16508. }, {
  16509. key: "tag",
  16510. get: function get() {
  16511. return 't';
  16512. }
  16513. }, {
  16514. key: "model",
  16515. get: function get() {
  16516. return this._text.join('').replace(/_x([0-9A-F]{4})_/g, function ($0, $1) {
  16517. return String.fromCharCode(parseInt($1, 16));
  16518. });
  16519. }
  16520. }]);
  16521. return TextXform;
  16522. }(BaseXform);
  16523. module.exports = TextXform;
  16524. },{"../base-xform":31}],125:[function(require,module,exports){
  16525. "use strict";
  16526. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  16527. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16528. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  16529. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  16530. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  16531. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  16532. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  16533. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  16534. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  16535. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  16536. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  16537. var Enums = require('../../../doc/enums');
  16538. var utils = require('../../../utils/utils');
  16539. var BaseXform = require('../base-xform');
  16540. var validation = {
  16541. horizontalValues: ['left', 'center', 'right', 'fill', 'centerContinuous', 'distributed', 'justify'].reduce(function (p, v) {
  16542. p[v] = true;
  16543. return p;
  16544. }, {}),
  16545. horizontal: function horizontal(value) {
  16546. return this.horizontalValues[value] ? value : undefined;
  16547. },
  16548. verticalValues: ['top', 'middle', 'bottom', 'distributed', 'justify'].reduce(function (p, v) {
  16549. p[v] = true;
  16550. return p;
  16551. }, {}),
  16552. vertical: function vertical(value) {
  16553. if (value === 'middle') return 'center';
  16554. return this.verticalValues[value] ? value : undefined;
  16555. },
  16556. wrapText: function wrapText(value) {
  16557. return value ? true : undefined;
  16558. },
  16559. shrinkToFit: function shrinkToFit(value) {
  16560. return value ? true : undefined;
  16561. },
  16562. textRotation: function textRotation(value) {
  16563. switch (value) {
  16564. case 'vertical':
  16565. return value;
  16566. default:
  16567. value = utils.validInt(value);
  16568. return value >= -90 && value <= 90 ? value : undefined;
  16569. }
  16570. },
  16571. indent: function indent(value) {
  16572. value = utils.validInt(value);
  16573. return Math.max(0, value);
  16574. },
  16575. readingOrder: function readingOrder(value) {
  16576. switch (value) {
  16577. case 'ltr':
  16578. return Enums.ReadingOrder.LeftToRight;
  16579. case 'rtl':
  16580. return Enums.ReadingOrder.RightToLeft;
  16581. default:
  16582. return undefined;
  16583. }
  16584. }
  16585. };
  16586. var textRotationXform = {
  16587. toXml: function toXml(textRotation) {
  16588. textRotation = validation.textRotation(textRotation);
  16589. if (textRotation) {
  16590. if (textRotation === 'vertical') {
  16591. return 255;
  16592. }
  16593. var tr = Math.round(textRotation);
  16594. if (tr >= 0 && tr <= 90) {
  16595. return tr;
  16596. }
  16597. if (tr < 0 && tr >= -90) {
  16598. return 90 - tr;
  16599. }
  16600. }
  16601. return undefined;
  16602. },
  16603. toModel: function toModel(textRotation) {
  16604. var tr = utils.validInt(textRotation);
  16605. if (tr !== undefined) {
  16606. if (tr === 255) {
  16607. return 'vertical';
  16608. }
  16609. if (tr >= 0 && tr <= 90) {
  16610. return tr;
  16611. }
  16612. if (tr > 90 && tr <= 180) {
  16613. return 90 - tr;
  16614. }
  16615. }
  16616. return undefined;
  16617. }
  16618. }; // Alignment encapsulates translation from style.alignment model to/from xlsx
  16619. var AlignmentXform = /*#__PURE__*/function (_BaseXform) {
  16620. _inherits(AlignmentXform, _BaseXform);
  16621. var _super = _createSuper(AlignmentXform);
  16622. function AlignmentXform() {
  16623. _classCallCheck(this, AlignmentXform);
  16624. return _super.apply(this, arguments);
  16625. }
  16626. _createClass(AlignmentXform, [{
  16627. key: "render",
  16628. value: function render(xmlStream, model) {
  16629. xmlStream.addRollback();
  16630. xmlStream.openNode('alignment');
  16631. var isValid = false;
  16632. function add(name, value) {
  16633. if (value) {
  16634. xmlStream.addAttribute(name, value);
  16635. isValid = true;
  16636. }
  16637. }
  16638. add('horizontal', validation.horizontal(model.horizontal));
  16639. add('vertical', validation.vertical(model.vertical));
  16640. add('wrapText', validation.wrapText(model.wrapText) ? '1' : false);
  16641. add('shrinkToFit', validation.shrinkToFit(model.shrinkToFit) ? '1' : false);
  16642. add('indent', validation.indent(model.indent));
  16643. add('textRotation', textRotationXform.toXml(model.textRotation));
  16644. add('readingOrder', validation.readingOrder(model.readingOrder));
  16645. xmlStream.closeNode();
  16646. if (isValid) {
  16647. xmlStream.commit();
  16648. } else {
  16649. xmlStream.rollback();
  16650. }
  16651. }
  16652. }, {
  16653. key: "parseOpen",
  16654. value: function parseOpen(node) {
  16655. var model = {};
  16656. var valid = false;
  16657. function add(truthy, name, value) {
  16658. if (truthy) {
  16659. model[name] = value;
  16660. valid = true;
  16661. }
  16662. }
  16663. add(node.attributes.horizontal, 'horizontal', node.attributes.horizontal);
  16664. add(node.attributes.vertical, 'vertical', node.attributes.vertical === 'center' ? 'middle' : node.attributes.vertical);
  16665. add(node.attributes.wrapText, 'wrapText', !!node.attributes.wrapText);
  16666. add(node.attributes.shrinkToFit, 'shrinkToFit', !!node.attributes.shrinkToFit);
  16667. add(node.attributes.indent, 'indent', parseInt(node.attributes.indent, 10));
  16668. add(node.attributes.textRotation, 'textRotation', textRotationXform.toModel(node.attributes.textRotation));
  16669. add(node.attributes.readingOrder, 'readingOrder', node.attributes.readingOrder === '2' ? 'rtl' : 'ltr');
  16670. this.model = valid ? model : null;
  16671. }
  16672. }, {
  16673. key: "parseText",
  16674. value: function parseText() {}
  16675. }, {
  16676. key: "parseClose",
  16677. value: function parseClose() {
  16678. return false;
  16679. }
  16680. }, {
  16681. key: "tag",
  16682. get: function get() {
  16683. return 'alignment';
  16684. }
  16685. }]);
  16686. return AlignmentXform;
  16687. }(BaseXform);
  16688. module.exports = AlignmentXform;
  16689. },{"../../../doc/enums":7,"../../../utils/utils":26,"../base-xform":31}],126:[function(require,module,exports){
  16690. "use strict";
  16691. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  16692. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  16693. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  16694. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  16695. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16696. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  16697. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  16698. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  16699. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  16700. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  16701. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  16702. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  16703. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  16704. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  16705. /* eslint-disable max-classes-per-file */
  16706. var BaseXform = require('../base-xform');
  16707. var ColorXform = require('./color-xform');
  16708. var EdgeXform = /*#__PURE__*/function (_BaseXform) {
  16709. _inherits(EdgeXform, _BaseXform);
  16710. var _super = _createSuper(EdgeXform);
  16711. function EdgeXform(name) {
  16712. var _this;
  16713. _classCallCheck(this, EdgeXform);
  16714. _this = _super.call(this);
  16715. _this.name = name;
  16716. _this.map = {
  16717. color: new ColorXform()
  16718. };
  16719. return _this;
  16720. }
  16721. _createClass(EdgeXform, [{
  16722. key: "render",
  16723. value: function render(xmlStream, model, defaultColor) {
  16724. var color = model && model.color || defaultColor || this.defaultColor;
  16725. xmlStream.openNode(this.name);
  16726. if (model && model.style) {
  16727. xmlStream.addAttribute('style', model.style);
  16728. if (color) {
  16729. this.map.color.render(xmlStream, color);
  16730. }
  16731. }
  16732. xmlStream.closeNode();
  16733. }
  16734. }, {
  16735. key: "parseOpen",
  16736. value: function parseOpen(node) {
  16737. if (this.parser) {
  16738. this.parser.parseOpen(node);
  16739. return true;
  16740. }
  16741. switch (node.name) {
  16742. case this.name:
  16743. {
  16744. var style = node.attributes.style;
  16745. if (style) {
  16746. this.model = {
  16747. style: style
  16748. };
  16749. } else {
  16750. this.model = undefined;
  16751. }
  16752. return true;
  16753. }
  16754. case 'color':
  16755. this.parser = this.map.color;
  16756. this.parser.parseOpen(node);
  16757. return true;
  16758. default:
  16759. return false;
  16760. }
  16761. }
  16762. }, {
  16763. key: "parseText",
  16764. value: function parseText(text) {
  16765. if (this.parser) {
  16766. this.parser.parseText(text);
  16767. }
  16768. }
  16769. }, {
  16770. key: "parseClose",
  16771. value: function parseClose(name) {
  16772. if (this.parser) {
  16773. if (!this.parser.parseClose(name)) {
  16774. this.parser = undefined;
  16775. }
  16776. return true;
  16777. }
  16778. if (name === this.name) {
  16779. if (this.map.color.model) {
  16780. if (!this.model) {
  16781. this.model = {};
  16782. }
  16783. this.model.color = this.map.color.model;
  16784. }
  16785. }
  16786. return false;
  16787. }
  16788. }, {
  16789. key: "validStyle",
  16790. value: function validStyle(value) {
  16791. return EdgeXform.validStyleValues[value];
  16792. }
  16793. }, {
  16794. key: "tag",
  16795. get: function get() {
  16796. return this.name;
  16797. }
  16798. }]);
  16799. return EdgeXform;
  16800. }(BaseXform);
  16801. EdgeXform.validStyleValues = ['thin', 'dotted', 'dashDot', 'hair', 'dashDotDot', 'slantDashDot', 'mediumDashed', 'mediumDashDotDot', 'mediumDashDot', 'medium', 'double', 'thick'].reduce(function (p, v) {
  16802. p[v] = true;
  16803. return p;
  16804. }, {}); // Border encapsulates translation from border model to/from xlsx
  16805. var BorderXform = /*#__PURE__*/function (_BaseXform2) {
  16806. _inherits(BorderXform, _BaseXform2);
  16807. var _super2 = _createSuper(BorderXform);
  16808. function BorderXform() {
  16809. var _this2;
  16810. _classCallCheck(this, BorderXform);
  16811. _this2 = _super2.call(this);
  16812. _this2.map = {
  16813. top: new EdgeXform('top'),
  16814. left: new EdgeXform('left'),
  16815. bottom: new EdgeXform('bottom'),
  16816. right: new EdgeXform('right'),
  16817. diagonal: new EdgeXform('diagonal')
  16818. };
  16819. return _this2;
  16820. }
  16821. _createClass(BorderXform, [{
  16822. key: "render",
  16823. value: function render(xmlStream, model) {
  16824. var color = model.color;
  16825. xmlStream.openNode('border');
  16826. if (model.diagonal && model.diagonal.style) {
  16827. if (model.diagonal.up) {
  16828. xmlStream.addAttribute('diagonalUp', '1');
  16829. }
  16830. if (model.diagonal.down) {
  16831. xmlStream.addAttribute('diagonalDown', '1');
  16832. }
  16833. }
  16834. function add(edgeModel, edgeXform) {
  16835. if (edgeModel && !edgeModel.color && model.color) {
  16836. // don't mess with incoming models
  16837. edgeModel = _objectSpread(_objectSpread({}, edgeModel), {}, {
  16838. color: model.color
  16839. });
  16840. }
  16841. edgeXform.render(xmlStream, edgeModel, color);
  16842. }
  16843. add(model.left, this.map.left);
  16844. add(model.right, this.map.right);
  16845. add(model.top, this.map.top);
  16846. add(model.bottom, this.map.bottom);
  16847. add(model.diagonal, this.map.diagonal);
  16848. xmlStream.closeNode();
  16849. }
  16850. }, {
  16851. key: "parseOpen",
  16852. value: function parseOpen(node) {
  16853. if (this.parser) {
  16854. this.parser.parseOpen(node);
  16855. return true;
  16856. }
  16857. switch (node.name) {
  16858. case 'border':
  16859. this.reset();
  16860. this.diagonalUp = !!node.attributes.diagonalUp;
  16861. this.diagonalDown = !!node.attributes.diagonalDown;
  16862. return true;
  16863. default:
  16864. this.parser = this.map[node.name];
  16865. if (this.parser) {
  16866. this.parser.parseOpen(node);
  16867. return true;
  16868. }
  16869. return false;
  16870. }
  16871. }
  16872. }, {
  16873. key: "parseText",
  16874. value: function parseText(text) {
  16875. if (this.parser) {
  16876. this.parser.parseText(text);
  16877. }
  16878. }
  16879. }, {
  16880. key: "parseClose",
  16881. value: function parseClose(name) {
  16882. if (this.parser) {
  16883. if (!this.parser.parseClose(name)) {
  16884. this.parser = undefined;
  16885. }
  16886. return true;
  16887. }
  16888. if (name === 'border') {
  16889. var model = this.model = {};
  16890. var add = function add(key, edgeModel, extensions) {
  16891. if (edgeModel) {
  16892. if (extensions) {
  16893. Object.assign(edgeModel, extensions);
  16894. }
  16895. model[key] = edgeModel;
  16896. }
  16897. };
  16898. add('left', this.map.left.model);
  16899. add('right', this.map.right.model);
  16900. add('top', this.map.top.model);
  16901. add('bottom', this.map.bottom.model);
  16902. add('diagonal', this.map.diagonal.model, {
  16903. up: this.diagonalUp,
  16904. down: this.diagonalDown
  16905. });
  16906. }
  16907. return false;
  16908. }
  16909. }]);
  16910. return BorderXform;
  16911. }(BaseXform);
  16912. module.exports = BorderXform;
  16913. },{"../base-xform":31,"./color-xform":127}],127:[function(require,module,exports){
  16914. "use strict";
  16915. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  16916. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16917. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  16918. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  16919. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  16920. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  16921. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  16922. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  16923. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  16924. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  16925. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  16926. var BaseXform = require('../base-xform'); // Color encapsulates translation from color model to/from xlsx
  16927. var ColorXform = /*#__PURE__*/function (_BaseXform) {
  16928. _inherits(ColorXform, _BaseXform);
  16929. var _super = _createSuper(ColorXform);
  16930. function ColorXform(name) {
  16931. var _this;
  16932. _classCallCheck(this, ColorXform);
  16933. _this = _super.call(this); // this.name controls the xm node name
  16934. _this.name = name || 'color';
  16935. return _this;
  16936. }
  16937. _createClass(ColorXform, [{
  16938. key: "render",
  16939. value: function render(xmlStream, model) {
  16940. if (model) {
  16941. xmlStream.openNode(this.name);
  16942. if (model.argb) {
  16943. xmlStream.addAttribute('rgb', model.argb);
  16944. } else if (model.theme !== undefined) {
  16945. xmlStream.addAttribute('theme', model.theme);
  16946. if (model.tint !== undefined) {
  16947. xmlStream.addAttribute('tint', model.tint);
  16948. }
  16949. } else if (model.indexed !== undefined) {
  16950. xmlStream.addAttribute('indexed', model.indexed);
  16951. } else {
  16952. xmlStream.addAttribute('auto', '1');
  16953. }
  16954. xmlStream.closeNode();
  16955. return true;
  16956. }
  16957. return false;
  16958. }
  16959. }, {
  16960. key: "parseOpen",
  16961. value: function parseOpen(node) {
  16962. if (node.name === this.name) {
  16963. if (node.attributes.rgb) {
  16964. this.model = {
  16965. argb: node.attributes.rgb
  16966. };
  16967. } else if (node.attributes.theme) {
  16968. this.model = {
  16969. theme: parseInt(node.attributes.theme, 10)
  16970. };
  16971. if (node.attributes.tint) {
  16972. this.model.tint = parseFloat(node.attributes.tint);
  16973. }
  16974. } else if (node.attributes.indexed) {
  16975. this.model = {
  16976. indexed: parseInt(node.attributes.indexed, 10)
  16977. };
  16978. } else {
  16979. this.model = undefined;
  16980. }
  16981. return true;
  16982. }
  16983. return false;
  16984. }
  16985. }, {
  16986. key: "parseText",
  16987. value: function parseText() {}
  16988. }, {
  16989. key: "parseClose",
  16990. value: function parseClose() {
  16991. return false;
  16992. }
  16993. }, {
  16994. key: "tag",
  16995. get: function get() {
  16996. return this.name;
  16997. }
  16998. }]);
  16999. return ColorXform;
  17000. }(BaseXform);
  17001. module.exports = ColorXform;
  17002. },{"../base-xform":31}],128:[function(require,module,exports){
  17003. "use strict";
  17004. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  17005. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17006. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  17007. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  17008. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  17009. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  17010. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  17011. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  17012. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  17013. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  17014. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  17015. var BaseXform = require('../base-xform');
  17016. var AlignmentXform = require('./alignment-xform');
  17017. var BorderXform = require('./border-xform');
  17018. var FillXform = require('./fill-xform');
  17019. var FontXform = require('./font-xform');
  17020. var NumFmtXform = require('./numfmt-xform');
  17021. var ProtectionXform = require('./protection-xform'); // <xf numFmtId="[numFmtId]" fontId="[fontId]" fillId="[fillId]" borderId="[xf.borderId]" xfId="[xfId]">
  17022. // Optional <alignment>
  17023. // Optional <protection>
  17024. // </xf>
  17025. // Style assists translation from style model to/from xlsx
  17026. var DxfXform = /*#__PURE__*/function (_BaseXform) {
  17027. _inherits(DxfXform, _BaseXform);
  17028. var _super = _createSuper(DxfXform);
  17029. function DxfXform() {
  17030. var _this;
  17031. _classCallCheck(this, DxfXform);
  17032. _this = _super.call(this);
  17033. _this.map = {
  17034. alignment: new AlignmentXform(),
  17035. border: new BorderXform(),
  17036. fill: new FillXform(),
  17037. font: new FontXform(),
  17038. numFmt: new NumFmtXform(),
  17039. protection: new ProtectionXform()
  17040. };
  17041. return _this;
  17042. }
  17043. _createClass(DxfXform, [{
  17044. key: "render",
  17045. // how do we generate dxfid?
  17046. value: function render(xmlStream, model) {
  17047. xmlStream.openNode(this.tag);
  17048. if (model.font) {
  17049. this.map.font.render(xmlStream, model.font);
  17050. }
  17051. if (model.numFmt) {
  17052. this.map.numFmt.render(xmlStream, model.numFmt);
  17053. }
  17054. if (model.fill) {
  17055. this.map.fill.render(xmlStream, model.fill);
  17056. }
  17057. if (model.alignment) {
  17058. this.map.alignment.render(xmlStream, model.alignment);
  17059. }
  17060. if (model.border) {
  17061. this.map.border.render(xmlStream, model.border);
  17062. }
  17063. if (model.protection) {
  17064. this.map.protection.render(xmlStream, model.protection);
  17065. }
  17066. xmlStream.closeNode();
  17067. }
  17068. }, {
  17069. key: "parseOpen",
  17070. value: function parseOpen(node) {
  17071. if (this.parser) {
  17072. this.parser.parseOpen(node);
  17073. return true;
  17074. }
  17075. switch (node.name) {
  17076. case this.tag:
  17077. // this node is often repeated. Need to reset children
  17078. this.reset();
  17079. return true;
  17080. default:
  17081. this.parser = this.map[node.name];
  17082. if (this.parser) {
  17083. this.parser.parseOpen(node);
  17084. }
  17085. return true;
  17086. }
  17087. }
  17088. }, {
  17089. key: "parseText",
  17090. value: function parseText(text) {
  17091. if (this.parser) {
  17092. this.parser.parseText(text);
  17093. }
  17094. }
  17095. }, {
  17096. key: "parseClose",
  17097. value: function parseClose(name) {
  17098. if (this.parser) {
  17099. if (!this.parser.parseClose(name)) {
  17100. this.parser = undefined;
  17101. }
  17102. return true;
  17103. }
  17104. if (name === this.tag) {
  17105. this.model = {
  17106. alignment: this.map.alignment.model,
  17107. border: this.map.border.model,
  17108. fill: this.map.fill.model,
  17109. font: this.map.font.model,
  17110. numFmt: this.map.numFmt.model,
  17111. protection: this.map.protection.model
  17112. };
  17113. return false;
  17114. }
  17115. return true;
  17116. }
  17117. }, {
  17118. key: "tag",
  17119. get: function get() {
  17120. return 'dxf';
  17121. }
  17122. }]);
  17123. return DxfXform;
  17124. }(BaseXform);
  17125. module.exports = DxfXform;
  17126. },{"../base-xform":31,"./alignment-xform":125,"./border-xform":126,"./fill-xform":129,"./font-xform":130,"./numfmt-xform":131,"./protection-xform":132}],129:[function(require,module,exports){
  17127. "use strict";
  17128. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  17129. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17130. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  17131. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  17132. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  17133. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  17134. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  17135. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  17136. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  17137. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  17138. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  17139. /* eslint-disable max-classes-per-file */
  17140. var BaseXform = require('../base-xform');
  17141. var ColorXform = require('./color-xform');
  17142. var StopXform = /*#__PURE__*/function (_BaseXform) {
  17143. _inherits(StopXform, _BaseXform);
  17144. var _super = _createSuper(StopXform);
  17145. function StopXform() {
  17146. var _this;
  17147. _classCallCheck(this, StopXform);
  17148. _this = _super.call(this);
  17149. _this.map = {
  17150. color: new ColorXform()
  17151. };
  17152. return _this;
  17153. }
  17154. _createClass(StopXform, [{
  17155. key: "render",
  17156. value: function render(xmlStream, model) {
  17157. xmlStream.openNode('stop');
  17158. xmlStream.addAttribute('position', model.position);
  17159. this.map.color.render(xmlStream, model.color);
  17160. xmlStream.closeNode();
  17161. }
  17162. }, {
  17163. key: "parseOpen",
  17164. value: function parseOpen(node) {
  17165. if (this.parser) {
  17166. this.parser.parseOpen(node);
  17167. return true;
  17168. }
  17169. switch (node.name) {
  17170. case 'stop':
  17171. this.model = {
  17172. position: parseFloat(node.attributes.position)
  17173. };
  17174. return true;
  17175. case 'color':
  17176. this.parser = this.map.color;
  17177. this.parser.parseOpen(node);
  17178. return true;
  17179. default:
  17180. return false;
  17181. }
  17182. }
  17183. }, {
  17184. key: "parseText",
  17185. value: function parseText() {}
  17186. }, {
  17187. key: "parseClose",
  17188. value: function parseClose(name) {
  17189. if (this.parser) {
  17190. if (!this.parser.parseClose(name)) {
  17191. this.model.color = this.parser.model;
  17192. this.parser = undefined;
  17193. }
  17194. return true;
  17195. }
  17196. return false;
  17197. }
  17198. }, {
  17199. key: "tag",
  17200. get: function get() {
  17201. return 'stop';
  17202. }
  17203. }]);
  17204. return StopXform;
  17205. }(BaseXform);
  17206. var PatternFillXform = /*#__PURE__*/function (_BaseXform2) {
  17207. _inherits(PatternFillXform, _BaseXform2);
  17208. var _super2 = _createSuper(PatternFillXform);
  17209. function PatternFillXform() {
  17210. var _this2;
  17211. _classCallCheck(this, PatternFillXform);
  17212. _this2 = _super2.call(this);
  17213. _this2.map = {
  17214. fgColor: new ColorXform('fgColor'),
  17215. bgColor: new ColorXform('bgColor')
  17216. };
  17217. return _this2;
  17218. }
  17219. _createClass(PatternFillXform, [{
  17220. key: "render",
  17221. value: function render(xmlStream, model) {
  17222. xmlStream.openNode('patternFill');
  17223. xmlStream.addAttribute('patternType', model.pattern);
  17224. if (model.fgColor) {
  17225. this.map.fgColor.render(xmlStream, model.fgColor);
  17226. }
  17227. if (model.bgColor) {
  17228. this.map.bgColor.render(xmlStream, model.bgColor);
  17229. }
  17230. xmlStream.closeNode();
  17231. }
  17232. }, {
  17233. key: "parseOpen",
  17234. value: function parseOpen(node) {
  17235. if (this.parser) {
  17236. this.parser.parseOpen(node);
  17237. return true;
  17238. }
  17239. switch (node.name) {
  17240. case 'patternFill':
  17241. this.model = {
  17242. type: 'pattern',
  17243. pattern: node.attributes.patternType
  17244. };
  17245. return true;
  17246. default:
  17247. this.parser = this.map[node.name];
  17248. if (this.parser) {
  17249. this.parser.parseOpen(node);
  17250. return true;
  17251. }
  17252. return false;
  17253. }
  17254. }
  17255. }, {
  17256. key: "parseText",
  17257. value: function parseText(text) {
  17258. if (this.parser) {
  17259. this.parser.parseText(text);
  17260. }
  17261. }
  17262. }, {
  17263. key: "parseClose",
  17264. value: function parseClose(name) {
  17265. if (this.parser) {
  17266. if (!this.parser.parseClose(name)) {
  17267. if (this.parser.model) {
  17268. this.model[name] = this.parser.model;
  17269. }
  17270. this.parser = undefined;
  17271. }
  17272. return true;
  17273. }
  17274. return false;
  17275. }
  17276. }, {
  17277. key: "name",
  17278. get: function get() {
  17279. return 'pattern';
  17280. }
  17281. }, {
  17282. key: "tag",
  17283. get: function get() {
  17284. return 'patternFill';
  17285. }
  17286. }]);
  17287. return PatternFillXform;
  17288. }(BaseXform);
  17289. var GradientFillXform = /*#__PURE__*/function (_BaseXform3) {
  17290. _inherits(GradientFillXform, _BaseXform3);
  17291. var _super3 = _createSuper(GradientFillXform);
  17292. function GradientFillXform() {
  17293. var _this3;
  17294. _classCallCheck(this, GradientFillXform);
  17295. _this3 = _super3.call(this);
  17296. _this3.map = {
  17297. stop: new StopXform()
  17298. }; // if (model) {
  17299. // this.gradient = model.gradient;
  17300. // if (model.center) {
  17301. // this.center = model.center;
  17302. // }
  17303. // if (model.degree !== undefined) {
  17304. // this.degree = model.degree;
  17305. // }
  17306. // this.stops = model.stops.map(function(stop) { return new StopXform(stop); });
  17307. // } else {
  17308. // this.stops = [];
  17309. // }
  17310. return _this3;
  17311. }
  17312. _createClass(GradientFillXform, [{
  17313. key: "render",
  17314. value: function render(xmlStream, model) {
  17315. xmlStream.openNode('gradientFill');
  17316. switch (model.gradient) {
  17317. case 'angle':
  17318. xmlStream.addAttribute('degree', model.degree);
  17319. break;
  17320. case 'path':
  17321. xmlStream.addAttribute('type', 'path');
  17322. if (model.center.left) {
  17323. xmlStream.addAttribute('left', model.center.left);
  17324. if (model.center.right === undefined) {
  17325. xmlStream.addAttribute('right', model.center.left);
  17326. }
  17327. }
  17328. if (model.center.right) {
  17329. xmlStream.addAttribute('right', model.center.right);
  17330. }
  17331. if (model.center.top) {
  17332. xmlStream.addAttribute('top', model.center.top);
  17333. if (model.center.bottom === undefined) {
  17334. xmlStream.addAttribute('bottom', model.center.top);
  17335. }
  17336. }
  17337. if (model.center.bottom) {
  17338. xmlStream.addAttribute('bottom', model.center.bottom);
  17339. }
  17340. break;
  17341. default:
  17342. break;
  17343. }
  17344. var stopXform = this.map.stop;
  17345. model.stops.forEach(function (stopModel) {
  17346. stopXform.render(xmlStream, stopModel);
  17347. });
  17348. xmlStream.closeNode();
  17349. }
  17350. }, {
  17351. key: "parseOpen",
  17352. value: function parseOpen(node) {
  17353. if (this.parser) {
  17354. this.parser.parseOpen(node);
  17355. return true;
  17356. }
  17357. switch (node.name) {
  17358. case 'gradientFill':
  17359. {
  17360. var model = this.model = {
  17361. stops: []
  17362. };
  17363. if (node.attributes.degree) {
  17364. model.gradient = 'angle';
  17365. model.degree = parseInt(node.attributes.degree, 10);
  17366. } else if (node.attributes.type === 'path') {
  17367. model.gradient = 'path';
  17368. model.center = {
  17369. left: node.attributes.left ? parseFloat(node.attributes.left) : 0,
  17370. top: node.attributes.top ? parseFloat(node.attributes.top) : 0
  17371. };
  17372. if (node.attributes.right !== node.attributes.left) {
  17373. model.center.right = node.attributes.right ? parseFloat(node.attributes.right) : 0;
  17374. }
  17375. if (node.attributes.bottom !== node.attributes.top) {
  17376. model.center.bottom = node.attributes.bottom ? parseFloat(node.attributes.bottom) : 0;
  17377. }
  17378. }
  17379. return true;
  17380. }
  17381. case 'stop':
  17382. this.parser = this.map.stop;
  17383. this.parser.parseOpen(node);
  17384. return true;
  17385. default:
  17386. return false;
  17387. }
  17388. }
  17389. }, {
  17390. key: "parseText",
  17391. value: function parseText(text) {
  17392. if (this.parser) {
  17393. this.parser.parseText(text);
  17394. }
  17395. }
  17396. }, {
  17397. key: "parseClose",
  17398. value: function parseClose(name) {
  17399. if (this.parser) {
  17400. if (!this.parser.parseClose(name)) {
  17401. this.model.stops.push(this.parser.model);
  17402. this.parser = undefined;
  17403. }
  17404. return true;
  17405. }
  17406. return false;
  17407. }
  17408. }, {
  17409. key: "name",
  17410. get: function get() {
  17411. return 'gradient';
  17412. }
  17413. }, {
  17414. key: "tag",
  17415. get: function get() {
  17416. return 'gradientFill';
  17417. }
  17418. }]);
  17419. return GradientFillXform;
  17420. }(BaseXform); // Fill encapsulates translation from fill model to/from xlsx
  17421. var FillXform = /*#__PURE__*/function (_BaseXform4) {
  17422. _inherits(FillXform, _BaseXform4);
  17423. var _super4 = _createSuper(FillXform);
  17424. function FillXform() {
  17425. var _this4;
  17426. _classCallCheck(this, FillXform);
  17427. _this4 = _super4.call(this);
  17428. _this4.map = {
  17429. patternFill: new PatternFillXform(),
  17430. gradientFill: new GradientFillXform()
  17431. };
  17432. return _this4;
  17433. }
  17434. _createClass(FillXform, [{
  17435. key: "render",
  17436. value: function render(xmlStream, model) {
  17437. xmlStream.addRollback();
  17438. xmlStream.openNode('fill');
  17439. switch (model.type) {
  17440. case 'pattern':
  17441. this.map.patternFill.render(xmlStream, model);
  17442. break;
  17443. case 'gradient':
  17444. this.map.gradientFill.render(xmlStream, model);
  17445. break;
  17446. default:
  17447. xmlStream.rollback();
  17448. return;
  17449. }
  17450. xmlStream.closeNode();
  17451. xmlStream.commit();
  17452. }
  17453. }, {
  17454. key: "parseOpen",
  17455. value: function parseOpen(node) {
  17456. if (this.parser) {
  17457. this.parser.parseOpen(node);
  17458. return true;
  17459. }
  17460. switch (node.name) {
  17461. case 'fill':
  17462. this.model = {};
  17463. return true;
  17464. default:
  17465. this.parser = this.map[node.name];
  17466. if (this.parser) {
  17467. this.parser.parseOpen(node);
  17468. return true;
  17469. }
  17470. return false;
  17471. }
  17472. }
  17473. }, {
  17474. key: "parseText",
  17475. value: function parseText(text) {
  17476. if (this.parser) {
  17477. this.parser.parseText(text);
  17478. }
  17479. }
  17480. }, {
  17481. key: "parseClose",
  17482. value: function parseClose(name) {
  17483. if (this.parser) {
  17484. if (!this.parser.parseClose(name)) {
  17485. this.model = this.parser.model;
  17486. this.model.type = this.parser.name;
  17487. this.parser = undefined;
  17488. }
  17489. return true;
  17490. }
  17491. return false;
  17492. }
  17493. }, {
  17494. key: "validStyle",
  17495. value: function validStyle(value) {
  17496. return FillXform.validPatternValues[value];
  17497. }
  17498. }, {
  17499. key: "tag",
  17500. get: function get() {
  17501. return 'fill';
  17502. }
  17503. }]);
  17504. return FillXform;
  17505. }(BaseXform);
  17506. FillXform.validPatternValues = ['none', 'solid', 'darkVertical', 'darkGray', 'mediumGray', 'lightGray', 'gray125', 'gray0625', 'darkHorizontal', 'darkVertical', 'darkDown', 'darkUp', 'darkGrid', 'darkTrellis', 'lightHorizontal', 'lightVertical', 'lightDown', 'lightUp', 'lightGrid', 'lightTrellis', 'lightGrid'].reduce(function (p, v) {
  17507. p[v] = true;
  17508. return p;
  17509. }, {});
  17510. FillXform.StopXform = StopXform;
  17511. FillXform.PatternFillXform = PatternFillXform;
  17512. FillXform.GradientFillXform = GradientFillXform;
  17513. module.exports = FillXform;
  17514. },{"../base-xform":31,"./color-xform":127}],130:[function(require,module,exports){
  17515. 'use strict';
  17516. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  17517. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17518. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  17519. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  17520. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  17521. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  17522. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  17523. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  17524. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  17525. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  17526. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  17527. var ColorXform = require('./color-xform');
  17528. var BooleanXform = require('../simple/boolean-xform');
  17529. var IntegerXform = require('../simple/integer-xform');
  17530. var StringXform = require('../simple/string-xform');
  17531. var UnderlineXform = require('./underline-xform');
  17532. var _ = require('../../../utils/under-dash');
  17533. var BaseXform = require('../base-xform'); // Font encapsulates translation from font model to xlsx
  17534. var FontXform = /*#__PURE__*/function (_BaseXform) {
  17535. _inherits(FontXform, _BaseXform);
  17536. var _super = _createSuper(FontXform);
  17537. function FontXform(options) {
  17538. var _this;
  17539. _classCallCheck(this, FontXform);
  17540. _this = _super.call(this);
  17541. _this.options = options || FontXform.OPTIONS;
  17542. _this.map = {
  17543. b: {
  17544. prop: 'bold',
  17545. xform: new BooleanXform({
  17546. tag: 'b',
  17547. attr: 'val'
  17548. })
  17549. },
  17550. i: {
  17551. prop: 'italic',
  17552. xform: new BooleanXform({
  17553. tag: 'i',
  17554. attr: 'val'
  17555. })
  17556. },
  17557. u: {
  17558. prop: 'underline',
  17559. xform: new UnderlineXform()
  17560. },
  17561. charset: {
  17562. prop: 'charset',
  17563. xform: new IntegerXform({
  17564. tag: 'charset',
  17565. attr: 'val'
  17566. })
  17567. },
  17568. color: {
  17569. prop: 'color',
  17570. xform: new ColorXform()
  17571. },
  17572. condense: {
  17573. prop: 'condense',
  17574. xform: new BooleanXform({
  17575. tag: 'condense',
  17576. attr: 'val'
  17577. })
  17578. },
  17579. extend: {
  17580. prop: 'extend',
  17581. xform: new BooleanXform({
  17582. tag: 'extend',
  17583. attr: 'val'
  17584. })
  17585. },
  17586. family: {
  17587. prop: 'family',
  17588. xform: new IntegerXform({
  17589. tag: 'family',
  17590. attr: 'val'
  17591. })
  17592. },
  17593. outline: {
  17594. prop: 'outline',
  17595. xform: new BooleanXform({
  17596. tag: 'outline',
  17597. attr: 'val'
  17598. })
  17599. },
  17600. vertAlign: {
  17601. prop: 'vertAlign',
  17602. xform: new StringXform({
  17603. tag: 'vertAlign',
  17604. attr: 'val'
  17605. })
  17606. },
  17607. scheme: {
  17608. prop: 'scheme',
  17609. xform: new StringXform({
  17610. tag: 'scheme',
  17611. attr: 'val'
  17612. })
  17613. },
  17614. shadow: {
  17615. prop: 'shadow',
  17616. xform: new BooleanXform({
  17617. tag: 'shadow',
  17618. attr: 'val'
  17619. })
  17620. },
  17621. strike: {
  17622. prop: 'strike',
  17623. xform: new BooleanXform({
  17624. tag: 'strike',
  17625. attr: 'val'
  17626. })
  17627. },
  17628. sz: {
  17629. prop: 'size',
  17630. xform: new IntegerXform({
  17631. tag: 'sz',
  17632. attr: 'val'
  17633. })
  17634. }
  17635. };
  17636. _this.map[_this.options.fontNameTag] = {
  17637. prop: 'name',
  17638. xform: new StringXform({
  17639. tag: _this.options.fontNameTag,
  17640. attr: 'val'
  17641. })
  17642. };
  17643. return _this;
  17644. }
  17645. _createClass(FontXform, [{
  17646. key: "render",
  17647. value: function render(xmlStream, model) {
  17648. var map = this.map;
  17649. xmlStream.openNode(this.options.tagName);
  17650. _.each(this.map, function (defn, tag) {
  17651. map[tag].xform.render(xmlStream, model[defn.prop]);
  17652. });
  17653. xmlStream.closeNode();
  17654. }
  17655. }, {
  17656. key: "parseOpen",
  17657. value: function parseOpen(node) {
  17658. if (this.parser) {
  17659. this.parser.parseOpen(node);
  17660. return true;
  17661. }
  17662. if (this.map[node.name]) {
  17663. this.parser = this.map[node.name].xform;
  17664. return this.parser.parseOpen(node);
  17665. }
  17666. switch (node.name) {
  17667. case this.options.tagName:
  17668. this.model = {};
  17669. return true;
  17670. default:
  17671. return false;
  17672. }
  17673. }
  17674. }, {
  17675. key: "parseText",
  17676. value: function parseText(text) {
  17677. if (this.parser) {
  17678. this.parser.parseText(text);
  17679. }
  17680. }
  17681. }, {
  17682. key: "parseClose",
  17683. value: function parseClose(name) {
  17684. if (this.parser && !this.parser.parseClose(name)) {
  17685. var item = this.map[name];
  17686. if (this.parser.model) {
  17687. this.model[item.prop] = this.parser.model;
  17688. }
  17689. this.parser = undefined;
  17690. return true;
  17691. }
  17692. switch (name) {
  17693. case this.options.tagName:
  17694. return false;
  17695. default:
  17696. return true;
  17697. }
  17698. }
  17699. }, {
  17700. key: "tag",
  17701. get: function get() {
  17702. return this.options.tagName;
  17703. }
  17704. }]);
  17705. return FontXform;
  17706. }(BaseXform);
  17707. FontXform.OPTIONS = {
  17708. tagName: 'font',
  17709. fontNameTag: 'name'
  17710. };
  17711. module.exports = FontXform;
  17712. },{"../../../utils/under-dash":25,"../base-xform":31,"../simple/boolean-xform":115,"../simple/integer-xform":117,"../simple/string-xform":118,"./color-xform":127,"./underline-xform":135}],131:[function(require,module,exports){
  17713. "use strict";
  17714. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  17715. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17716. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  17717. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  17718. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  17719. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  17720. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  17721. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  17722. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  17723. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  17724. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  17725. var _ = require('../../../utils/under-dash');
  17726. var defaultNumFormats = require('../../defaultnumformats');
  17727. var BaseXform = require('../base-xform');
  17728. function hashDefaultFormats() {
  17729. var hash = {};
  17730. _.each(defaultNumFormats, function (dnf, id) {
  17731. if (dnf.f) {
  17732. hash[dnf.f] = parseInt(id, 10);
  17733. } // at some point, add the other cultures here...
  17734. });
  17735. return hash;
  17736. }
  17737. var defaultFmtHash = hashDefaultFormats(); // NumFmt encapsulates translation between number format and xlsx
  17738. var NumFmtXform = /*#__PURE__*/function (_BaseXform) {
  17739. _inherits(NumFmtXform, _BaseXform);
  17740. var _super = _createSuper(NumFmtXform);
  17741. function NumFmtXform(id, formatCode) {
  17742. var _this;
  17743. _classCallCheck(this, NumFmtXform);
  17744. _this = _super.call(this);
  17745. _this.id = id;
  17746. _this.formatCode = formatCode;
  17747. return _this;
  17748. }
  17749. _createClass(NumFmtXform, [{
  17750. key: "render",
  17751. value: function render(xmlStream, model) {
  17752. xmlStream.leafNode('numFmt', {
  17753. numFmtId: model.id,
  17754. formatCode: model.formatCode
  17755. });
  17756. }
  17757. }, {
  17758. key: "parseOpen",
  17759. value: function parseOpen(node) {
  17760. switch (node.name) {
  17761. case 'numFmt':
  17762. this.model = {
  17763. id: parseInt(node.attributes.numFmtId, 10),
  17764. formatCode: node.attributes.formatCode.replace(/[\\](.)/g, '$1')
  17765. };
  17766. return true;
  17767. default:
  17768. return false;
  17769. }
  17770. }
  17771. }, {
  17772. key: "parseText",
  17773. value: function parseText() {}
  17774. }, {
  17775. key: "parseClose",
  17776. value: function parseClose() {
  17777. return false;
  17778. }
  17779. }, {
  17780. key: "tag",
  17781. get: function get() {
  17782. return 'numFmt';
  17783. }
  17784. }]);
  17785. return NumFmtXform;
  17786. }(BaseXform);
  17787. NumFmtXform.getDefaultFmtId = function getDefaultFmtId(formatCode) {
  17788. return defaultFmtHash[formatCode];
  17789. };
  17790. NumFmtXform.getDefaultFmtCode = function getDefaultFmtCode(numFmtId) {
  17791. return defaultNumFormats[numFmtId] && defaultNumFormats[numFmtId].f;
  17792. };
  17793. module.exports = NumFmtXform;
  17794. },{"../../../utils/under-dash":25,"../../defaultnumformats":29,"../base-xform":31}],132:[function(require,module,exports){
  17795. "use strict";
  17796. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  17797. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17798. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  17799. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  17800. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  17801. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  17802. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  17803. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  17804. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  17805. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  17806. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  17807. var BaseXform = require('../base-xform');
  17808. var validation = {
  17809. boolean: function boolean(value, dflt) {
  17810. if (value === undefined) {
  17811. return dflt;
  17812. }
  17813. return value;
  17814. }
  17815. }; // Protection encapsulates translation from style.protection model to/from xlsx
  17816. var ProtectionXform = /*#__PURE__*/function (_BaseXform) {
  17817. _inherits(ProtectionXform, _BaseXform);
  17818. var _super = _createSuper(ProtectionXform);
  17819. function ProtectionXform() {
  17820. _classCallCheck(this, ProtectionXform);
  17821. return _super.apply(this, arguments);
  17822. }
  17823. _createClass(ProtectionXform, [{
  17824. key: "render",
  17825. value: function render(xmlStream, model) {
  17826. xmlStream.addRollback();
  17827. xmlStream.openNode('protection');
  17828. var isValid = false;
  17829. function add(name, value) {
  17830. if (value !== undefined) {
  17831. xmlStream.addAttribute(name, value);
  17832. isValid = true;
  17833. }
  17834. }
  17835. add('locked', validation.boolean(model.locked, true) ? undefined : '0');
  17836. add('hidden', validation.boolean(model.hidden, false) ? '1' : undefined);
  17837. xmlStream.closeNode();
  17838. if (isValid) {
  17839. xmlStream.commit();
  17840. } else {
  17841. xmlStream.rollback();
  17842. }
  17843. }
  17844. }, {
  17845. key: "parseOpen",
  17846. value: function parseOpen(node) {
  17847. var model = {
  17848. locked: !(node.attributes.locked === '0'),
  17849. hidden: node.attributes.hidden === '1'
  17850. }; // only want to record models that differ from defaults
  17851. var isSignificant = !model.locked || model.hidden;
  17852. this.model = isSignificant ? model : null;
  17853. }
  17854. }, {
  17855. key: "parseText",
  17856. value: function parseText() {}
  17857. }, {
  17858. key: "parseClose",
  17859. value: function parseClose() {
  17860. return false;
  17861. }
  17862. }, {
  17863. key: "tag",
  17864. get: function get() {
  17865. return 'protection';
  17866. }
  17867. }]);
  17868. return ProtectionXform;
  17869. }(BaseXform);
  17870. module.exports = ProtectionXform;
  17871. },{"../base-xform":31}],133:[function(require,module,exports){
  17872. "use strict";
  17873. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  17874. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17875. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  17876. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  17877. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  17878. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  17879. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  17880. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  17881. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  17882. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  17883. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  17884. var BaseXform = require('../base-xform');
  17885. var AlignmentXform = require('./alignment-xform');
  17886. var ProtectionXform = require('./protection-xform'); // <xf numFmtId="[numFmtId]" fontId="[fontId]" fillId="[fillId]" borderId="[xf.borderId]" xfId="[xfId]">
  17887. // Optional <alignment>
  17888. // Optional <protection>
  17889. // </xf>
  17890. // Style assists translation from style model to/from xlsx
  17891. var StyleXform = /*#__PURE__*/function (_BaseXform) {
  17892. _inherits(StyleXform, _BaseXform);
  17893. var _super = _createSuper(StyleXform);
  17894. function StyleXform(options) {
  17895. var _this;
  17896. _classCallCheck(this, StyleXform);
  17897. _this = _super.call(this);
  17898. _this.xfId = !!(options && options.xfId);
  17899. _this.map = {
  17900. alignment: new AlignmentXform(),
  17901. protection: new ProtectionXform()
  17902. };
  17903. return _this;
  17904. }
  17905. _createClass(StyleXform, [{
  17906. key: "render",
  17907. value: function render(xmlStream, model) {
  17908. xmlStream.openNode('xf', {
  17909. numFmtId: model.numFmtId || 0,
  17910. fontId: model.fontId || 0,
  17911. fillId: model.fillId || 0,
  17912. borderId: model.borderId || 0
  17913. });
  17914. if (this.xfId) {
  17915. xmlStream.addAttribute('xfId', model.xfId || 0);
  17916. }
  17917. if (model.numFmtId) {
  17918. xmlStream.addAttribute('applyNumberFormat', '1');
  17919. }
  17920. if (model.fontId) {
  17921. xmlStream.addAttribute('applyFont', '1');
  17922. }
  17923. if (model.fillId) {
  17924. xmlStream.addAttribute('applyFill', '1');
  17925. }
  17926. if (model.borderId) {
  17927. xmlStream.addAttribute('applyBorder', '1');
  17928. }
  17929. if (model.alignment) {
  17930. xmlStream.addAttribute('applyAlignment', '1');
  17931. }
  17932. if (model.protection) {
  17933. xmlStream.addAttribute('applyProtection', '1');
  17934. }
  17935. /**
  17936. * Rendering tags causes close of XML stream.
  17937. * Therefore adding attributes must be done before rendering tags.
  17938. */
  17939. if (model.alignment) {
  17940. this.map.alignment.render(xmlStream, model.alignment);
  17941. }
  17942. if (model.protection) {
  17943. this.map.protection.render(xmlStream, model.protection);
  17944. }
  17945. xmlStream.closeNode();
  17946. }
  17947. }, {
  17948. key: "parseOpen",
  17949. value: function parseOpen(node) {
  17950. if (this.parser) {
  17951. this.parser.parseOpen(node);
  17952. return true;
  17953. } // used during sax parsing of xml to build font object
  17954. switch (node.name) {
  17955. case 'xf':
  17956. this.model = {
  17957. numFmtId: parseInt(node.attributes.numFmtId, 10),
  17958. fontId: parseInt(node.attributes.fontId, 10),
  17959. fillId: parseInt(node.attributes.fillId, 10),
  17960. borderId: parseInt(node.attributes.borderId, 10)
  17961. };
  17962. if (this.xfId) {
  17963. this.model.xfId = parseInt(node.attributes.xfId, 10);
  17964. }
  17965. return true;
  17966. case 'alignment':
  17967. this.parser = this.map.alignment;
  17968. this.parser.parseOpen(node);
  17969. return true;
  17970. case 'protection':
  17971. this.parser = this.map.protection;
  17972. this.parser.parseOpen(node);
  17973. return true;
  17974. default:
  17975. return false;
  17976. }
  17977. }
  17978. }, {
  17979. key: "parseText",
  17980. value: function parseText(text) {
  17981. if (this.parser) {
  17982. this.parser.parseText(text);
  17983. }
  17984. }
  17985. }, {
  17986. key: "parseClose",
  17987. value: function parseClose(name) {
  17988. if (this.parser) {
  17989. if (!this.parser.parseClose(name)) {
  17990. if (this.map.protection === this.parser) {
  17991. this.model.protection = this.parser.model;
  17992. } else {
  17993. this.model.alignment = this.parser.model;
  17994. }
  17995. this.parser = undefined;
  17996. }
  17997. return true;
  17998. }
  17999. return name !== 'xf';
  18000. }
  18001. }, {
  18002. key: "tag",
  18003. get: function get() {
  18004. return 'xf';
  18005. }
  18006. }]);
  18007. return StyleXform;
  18008. }(BaseXform);
  18009. module.exports = StyleXform;
  18010. },{"../base-xform":31,"./alignment-xform":125,"./protection-xform":132}],134:[function(require,module,exports){
  18011. "use strict";
  18012. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  18013. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  18014. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  18015. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  18016. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  18017. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  18018. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  18019. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  18020. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  18021. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  18022. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  18023. /* eslint-disable max-classes-per-file */
  18024. var Enums = require('../../../doc/enums');
  18025. var XmlStream = require('../../../utils/xml-stream');
  18026. var BaseXform = require('../base-xform');
  18027. var StaticXform = require('../static-xform');
  18028. var ListXform = require('../list-xform');
  18029. var FontXform = require('./font-xform');
  18030. var FillXform = require('./fill-xform');
  18031. var BorderXform = require('./border-xform');
  18032. var NumFmtXform = require('./numfmt-xform');
  18033. var StyleXform = require('./style-xform');
  18034. var DxfXform = require('./dxf-xform'); // custom numfmt ids start here
  18035. var NUMFMT_BASE = 164; // =============================================================================
  18036. // StylesXform is used to generate and parse the styles.xml file
  18037. // it manages the collections of fonts, number formats, alignments, etc
  18038. var StylesXform = /*#__PURE__*/function (_BaseXform) {
  18039. _inherits(StylesXform, _BaseXform);
  18040. var _super = _createSuper(StylesXform);
  18041. function StylesXform(initialise) {
  18042. var _this;
  18043. _classCallCheck(this, StylesXform);
  18044. _this = _super.call(this);
  18045. _this.map = {
  18046. numFmts: new ListXform({
  18047. tag: 'numFmts',
  18048. count: true,
  18049. childXform: new NumFmtXform()
  18050. }),
  18051. fonts: new ListXform({
  18052. tag: 'fonts',
  18053. count: true,
  18054. childXform: new FontXform(),
  18055. $: {
  18056. 'x14ac:knownFonts': 1
  18057. }
  18058. }),
  18059. fills: new ListXform({
  18060. tag: 'fills',
  18061. count: true,
  18062. childXform: new FillXform()
  18063. }),
  18064. borders: new ListXform({
  18065. tag: 'borders',
  18066. count: true,
  18067. childXform: new BorderXform()
  18068. }),
  18069. cellStyleXfs: new ListXform({
  18070. tag: 'cellStyleXfs',
  18071. count: true,
  18072. childXform: new StyleXform()
  18073. }),
  18074. cellXfs: new ListXform({
  18075. tag: 'cellXfs',
  18076. count: true,
  18077. childXform: new StyleXform({
  18078. xfId: true
  18079. })
  18080. }),
  18081. dxfs: new ListXform({
  18082. tag: 'dxfs',
  18083. always: true,
  18084. count: true,
  18085. childXform: new DxfXform()
  18086. }),
  18087. // for style manager
  18088. numFmt: new NumFmtXform(),
  18089. font: new FontXform(),
  18090. fill: new FillXform(),
  18091. border: new BorderXform(),
  18092. style: new StyleXform({
  18093. xfId: true
  18094. }),
  18095. cellStyles: StylesXform.STATIC_XFORMS.cellStyles,
  18096. tableStyles: StylesXform.STATIC_XFORMS.tableStyles,
  18097. extLst: StylesXform.STATIC_XFORMS.extLst
  18098. };
  18099. if (initialise) {
  18100. // StylesXform also acts as style manager and is used to build up styles-model during worksheet processing
  18101. _this.init();
  18102. }
  18103. return _this;
  18104. }
  18105. _createClass(StylesXform, [{
  18106. key: "initIndex",
  18107. value: function initIndex() {
  18108. this.index = {
  18109. style: {},
  18110. numFmt: {},
  18111. numFmtNextId: 164,
  18112. // start custom format ids here
  18113. font: {},
  18114. border: {},
  18115. fill: {}
  18116. };
  18117. }
  18118. }, {
  18119. key: "init",
  18120. value: function init() {
  18121. // Prepare for Style Manager role
  18122. this.model = {
  18123. styles: [],
  18124. numFmts: [],
  18125. fonts: [],
  18126. borders: [],
  18127. fills: [],
  18128. dxfs: []
  18129. };
  18130. this.initIndex(); // default (zero) border
  18131. this._addBorder({}); // add default (all zero) style
  18132. this._addStyle({
  18133. numFmtId: 0,
  18134. fontId: 0,
  18135. fillId: 0,
  18136. borderId: 0,
  18137. xfId: 0
  18138. }); // add default fills
  18139. this._addFill({
  18140. type: 'pattern',
  18141. pattern: 'none'
  18142. });
  18143. this._addFill({
  18144. type: 'pattern',
  18145. pattern: 'gray125'
  18146. });
  18147. this.weakMap = new WeakMap();
  18148. }
  18149. }, {
  18150. key: "render",
  18151. value: function render(xmlStream, model) {
  18152. model = model || this.model; //
  18153. // <fonts count="2" x14ac:knownFonts="1">
  18154. xmlStream.openXml(XmlStream.StdDocAttributes);
  18155. xmlStream.openNode('styleSheet', StylesXform.STYLESHEET_ATTRIBUTES);
  18156. if (this.index) {
  18157. // model has been built by style manager role (contains xml)
  18158. if (model.numFmts && model.numFmts.length) {
  18159. xmlStream.openNode('numFmts', {
  18160. count: model.numFmts.length
  18161. });
  18162. model.numFmts.forEach(function (numFmtXml) {
  18163. xmlStream.writeXml(numFmtXml);
  18164. });
  18165. xmlStream.closeNode();
  18166. }
  18167. if (!model.fonts.length) {
  18168. // default (zero) font
  18169. this._addFont({
  18170. size: 11,
  18171. color: {
  18172. theme: 1
  18173. },
  18174. name: 'Calibri',
  18175. family: 2,
  18176. scheme: 'minor'
  18177. });
  18178. }
  18179. xmlStream.openNode('fonts', {
  18180. count: model.fonts.length,
  18181. 'x14ac:knownFonts': 1
  18182. });
  18183. model.fonts.forEach(function (fontXml) {
  18184. xmlStream.writeXml(fontXml);
  18185. });
  18186. xmlStream.closeNode();
  18187. xmlStream.openNode('fills', {
  18188. count: model.fills.length
  18189. });
  18190. model.fills.forEach(function (fillXml) {
  18191. xmlStream.writeXml(fillXml);
  18192. });
  18193. xmlStream.closeNode();
  18194. xmlStream.openNode('borders', {
  18195. count: model.borders.length
  18196. });
  18197. model.borders.forEach(function (borderXml) {
  18198. xmlStream.writeXml(borderXml);
  18199. });
  18200. xmlStream.closeNode();
  18201. this.map.cellStyleXfs.render(xmlStream, [{
  18202. numFmtId: 0,
  18203. fontId: 0,
  18204. fillId: 0,
  18205. borderId: 0,
  18206. xfId: 0
  18207. }]);
  18208. xmlStream.openNode('cellXfs', {
  18209. count: model.styles.length
  18210. });
  18211. model.styles.forEach(function (styleXml) {
  18212. xmlStream.writeXml(styleXml);
  18213. });
  18214. xmlStream.closeNode();
  18215. } else {
  18216. // model is plain JSON and needs to be xformed
  18217. this.map.numFmts.render(xmlStream, model.numFmts);
  18218. this.map.fonts.render(xmlStream, model.fonts);
  18219. this.map.fills.render(xmlStream, model.fills);
  18220. this.map.borders.render(xmlStream, model.borders);
  18221. this.map.cellStyleXfs.render(xmlStream, [{
  18222. numFmtId: 0,
  18223. fontId: 0,
  18224. fillId: 0,
  18225. borderId: 0,
  18226. xfId: 0
  18227. }]);
  18228. this.map.cellXfs.render(xmlStream, model.styles);
  18229. }
  18230. StylesXform.STATIC_XFORMS.cellStyles.render(xmlStream);
  18231. this.map.dxfs.render(xmlStream, model.dxfs);
  18232. StylesXform.STATIC_XFORMS.tableStyles.render(xmlStream);
  18233. StylesXform.STATIC_XFORMS.extLst.render(xmlStream);
  18234. xmlStream.closeNode();
  18235. }
  18236. }, {
  18237. key: "parseOpen",
  18238. value: function parseOpen(node) {
  18239. if (this.parser) {
  18240. this.parser.parseOpen(node);
  18241. return true;
  18242. }
  18243. switch (node.name) {
  18244. case 'styleSheet':
  18245. this.initIndex();
  18246. return true;
  18247. default:
  18248. this.parser = this.map[node.name];
  18249. if (this.parser) {
  18250. this.parser.parseOpen(node);
  18251. }
  18252. return true;
  18253. }
  18254. }
  18255. }, {
  18256. key: "parseText",
  18257. value: function parseText(text) {
  18258. if (this.parser) {
  18259. this.parser.parseText(text);
  18260. }
  18261. }
  18262. }, {
  18263. key: "parseClose",
  18264. value: function parseClose(name) {
  18265. var _this2 = this;
  18266. if (this.parser) {
  18267. if (!this.parser.parseClose(name)) {
  18268. this.parser = undefined;
  18269. }
  18270. return true;
  18271. }
  18272. switch (name) {
  18273. case 'styleSheet':
  18274. {
  18275. this.model = {};
  18276. var add = function add(propName, xform) {
  18277. if (xform.model && xform.model.length) {
  18278. _this2.model[propName] = xform.model;
  18279. }
  18280. };
  18281. add('numFmts', this.map.numFmts);
  18282. add('fonts', this.map.fonts);
  18283. add('fills', this.map.fills);
  18284. add('borders', this.map.borders);
  18285. add('styles', this.map.cellXfs);
  18286. add('dxfs', this.map.dxfs); // index numFmts
  18287. this.index = {
  18288. model: [],
  18289. numFmt: []
  18290. };
  18291. if (this.model.numFmts) {
  18292. var numFmtIndex = this.index.numFmt;
  18293. this.model.numFmts.forEach(function (numFmt) {
  18294. numFmtIndex[numFmt.id] = numFmt.formatCode;
  18295. });
  18296. }
  18297. return false;
  18298. }
  18299. default:
  18300. // not quite sure how we get here!
  18301. return true;
  18302. }
  18303. } // add a cell's style model to the collection
  18304. // each style property is processed and cross-referenced, etc.
  18305. // the styleId is returned. Note: cellType is used when numFmt not defined
  18306. }, {
  18307. key: "addStyleModel",
  18308. value: function addStyleModel(model, cellType) {
  18309. if (!model) {
  18310. return 0;
  18311. } // if we have no default font, add it here now
  18312. if (!this.model.fonts.length) {
  18313. // default (zero) font
  18314. this._addFont({
  18315. size: 11,
  18316. color: {
  18317. theme: 1
  18318. },
  18319. name: 'Calibri',
  18320. family: 2,
  18321. scheme: 'minor'
  18322. });
  18323. } // if we have seen this style object before, assume it has the same styleId
  18324. if (this.weakMap && this.weakMap.has(model)) {
  18325. return this.weakMap.get(model);
  18326. }
  18327. var style = {};
  18328. cellType = cellType || Enums.ValueType.Number;
  18329. if (model.numFmt) {
  18330. style.numFmtId = this._addNumFmtStr(model.numFmt);
  18331. } else {
  18332. switch (cellType) {
  18333. case Enums.ValueType.Number:
  18334. style.numFmtId = this._addNumFmtStr('General');
  18335. break;
  18336. case Enums.ValueType.Date:
  18337. style.numFmtId = this._addNumFmtStr('mm-dd-yy');
  18338. break;
  18339. default:
  18340. break;
  18341. }
  18342. }
  18343. if (model.font) {
  18344. style.fontId = this._addFont(model.font);
  18345. }
  18346. if (model.border) {
  18347. style.borderId = this._addBorder(model.border);
  18348. }
  18349. if (model.fill) {
  18350. style.fillId = this._addFill(model.fill);
  18351. }
  18352. if (model.alignment) {
  18353. style.alignment = model.alignment;
  18354. }
  18355. if (model.protection) {
  18356. style.protection = model.protection;
  18357. }
  18358. var styleId = this._addStyle(style);
  18359. if (this.weakMap) {
  18360. this.weakMap.set(model, styleId);
  18361. }
  18362. return styleId;
  18363. } // given a styleId (i.e. s="n"), get the cell's style model
  18364. // objects are shared where possible.
  18365. }, {
  18366. key: "getStyleModel",
  18367. value: function getStyleModel(id) {
  18368. // if the style doesn't exist return null
  18369. var style = this.model.styles[id];
  18370. if (!style) return null; // have we built this model before?
  18371. var model = this.index.model[id];
  18372. if (model) return model; // build a new model
  18373. model = this.index.model[id] = {}; // -------------------------------------------------------
  18374. // number format
  18375. if (style.numFmtId) {
  18376. var numFmt = this.index.numFmt[style.numFmtId] || NumFmtXform.getDefaultFmtCode(style.numFmtId);
  18377. if (numFmt) {
  18378. model.numFmt = numFmt;
  18379. }
  18380. }
  18381. function addStyle(name, group, styleId) {
  18382. if (styleId || styleId === 0) {
  18383. var part = group[styleId];
  18384. if (part) {
  18385. model[name] = part;
  18386. }
  18387. }
  18388. }
  18389. addStyle('font', this.model.fonts, style.fontId);
  18390. addStyle('border', this.model.borders, style.borderId);
  18391. addStyle('fill', this.model.fills, style.fillId); // -------------------------------------------------------
  18392. // alignment
  18393. if (style.alignment) {
  18394. model.alignment = style.alignment;
  18395. } // -------------------------------------------------------
  18396. // protection
  18397. if (style.protection) {
  18398. model.protection = style.protection;
  18399. }
  18400. return model;
  18401. }
  18402. }, {
  18403. key: "addDxfStyle",
  18404. value: function addDxfStyle(style) {
  18405. this.model.dxfs.push(style);
  18406. return this.model.dxfs.length - 1;
  18407. }
  18408. }, {
  18409. key: "getDxfStyle",
  18410. value: function getDxfStyle(id) {
  18411. return this.model.dxfs[id];
  18412. } // =========================================================================
  18413. // Private Interface
  18414. }, {
  18415. key: "_addStyle",
  18416. value: function _addStyle(style) {
  18417. var xml = this.map.style.toXml(style);
  18418. var index = this.index.style[xml];
  18419. if (index === undefined) {
  18420. index = this.index.style[xml] = this.model.styles.length;
  18421. this.model.styles.push(xml);
  18422. }
  18423. return index;
  18424. } // =========================================================================
  18425. // Number Formats
  18426. }, {
  18427. key: "_addNumFmtStr",
  18428. value: function _addNumFmtStr(formatCode) {
  18429. // check if default format
  18430. var index = NumFmtXform.getDefaultFmtId(formatCode);
  18431. if (index !== undefined) return index; // check if already in
  18432. index = this.index.numFmt[formatCode];
  18433. if (index !== undefined) return index;
  18434. index = this.index.numFmt[formatCode] = NUMFMT_BASE + this.model.numFmts.length;
  18435. var xml = this.map.numFmt.toXml({
  18436. id: index,
  18437. formatCode: formatCode
  18438. });
  18439. this.model.numFmts.push(xml);
  18440. return index;
  18441. } // =========================================================================
  18442. // Fonts
  18443. }, {
  18444. key: "_addFont",
  18445. value: function _addFont(font) {
  18446. var xml = this.map.font.toXml(font);
  18447. var index = this.index.font[xml];
  18448. if (index === undefined) {
  18449. index = this.index.font[xml] = this.model.fonts.length;
  18450. this.model.fonts.push(xml);
  18451. }
  18452. return index;
  18453. } // =========================================================================
  18454. // Borders
  18455. }, {
  18456. key: "_addBorder",
  18457. value: function _addBorder(border) {
  18458. var xml = this.map.border.toXml(border);
  18459. var index = this.index.border[xml];
  18460. if (index === undefined) {
  18461. index = this.index.border[xml] = this.model.borders.length;
  18462. this.model.borders.push(xml);
  18463. }
  18464. return index;
  18465. } // =========================================================================
  18466. // Fills
  18467. }, {
  18468. key: "_addFill",
  18469. value: function _addFill(fill) {
  18470. var xml = this.map.fill.toXml(fill);
  18471. var index = this.index.fill[xml];
  18472. if (index === undefined) {
  18473. index = this.index.fill[xml] = this.model.fills.length;
  18474. this.model.fills.push(xml);
  18475. }
  18476. return index;
  18477. } // =========================================================================
  18478. }]);
  18479. return StylesXform;
  18480. }(BaseXform);
  18481. StylesXform.STYLESHEET_ATTRIBUTES = {
  18482. xmlns: 'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
  18483. 'xmlns:mc': 'http://schemas.openxmlformats.org/markup-compatibility/2006',
  18484. 'mc:Ignorable': 'x14ac x16r2',
  18485. 'xmlns:x14ac': 'http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac',
  18486. 'xmlns:x16r2': 'http://schemas.microsoft.com/office/spreadsheetml/2015/02/main'
  18487. };
  18488. StylesXform.STATIC_XFORMS = {
  18489. cellStyles: new StaticXform({
  18490. tag: 'cellStyles',
  18491. $: {
  18492. count: 1
  18493. },
  18494. c: [{
  18495. tag: 'cellStyle',
  18496. $: {
  18497. name: 'Normal',
  18498. xfId: 0,
  18499. builtinId: 0
  18500. }
  18501. }]
  18502. }),
  18503. dxfs: new StaticXform({
  18504. tag: 'dxfs',
  18505. $: {
  18506. count: 0
  18507. }
  18508. }),
  18509. tableStyles: new StaticXform({
  18510. tag: 'tableStyles',
  18511. $: {
  18512. count: 0,
  18513. defaultTableStyle: 'TableStyleMedium2',
  18514. defaultPivotStyle: 'PivotStyleLight16'
  18515. }
  18516. }),
  18517. extLst: new StaticXform({
  18518. tag: 'extLst',
  18519. c: [{
  18520. tag: 'ext',
  18521. $: {
  18522. uri: '{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}',
  18523. 'xmlns:x14': 'http://schemas.microsoft.com/office/spreadsheetml/2009/9/main'
  18524. },
  18525. c: [{
  18526. tag: 'x14:slicerStyles',
  18527. $: {
  18528. defaultSlicerStyle: 'SlicerStyleLight1'
  18529. }
  18530. }]
  18531. }, {
  18532. tag: 'ext',
  18533. $: {
  18534. uri: '{9260A510-F301-46a8-8635-F512D64BE5F5}',
  18535. 'xmlns:x15': 'http://schemas.microsoft.com/office/spreadsheetml/2010/11/main'
  18536. },
  18537. c: [{
  18538. tag: 'x15:timelineStyles',
  18539. $: {
  18540. defaultTimelineStyle: 'TimeSlicerStyleLight1'
  18541. }
  18542. }]
  18543. }]
  18544. })
  18545. }; // the stylemanager mock acts like StyleManager except that it always returns 0 or {}
  18546. var StylesXformMock = /*#__PURE__*/function (_StylesXform) {
  18547. _inherits(StylesXformMock, _StylesXform);
  18548. var _super2 = _createSuper(StylesXformMock);
  18549. function StylesXformMock() {
  18550. var _this3;
  18551. _classCallCheck(this, StylesXformMock);
  18552. _this3 = _super2.call(this);
  18553. _this3.model = {
  18554. styles: [{
  18555. numFmtId: 0,
  18556. fontId: 0,
  18557. fillId: 0,
  18558. borderId: 0,
  18559. xfId: 0
  18560. }],
  18561. numFmts: [],
  18562. fonts: [{
  18563. size: 11,
  18564. color: {
  18565. theme: 1
  18566. },
  18567. name: 'Calibri',
  18568. family: 2,
  18569. scheme: 'minor'
  18570. }],
  18571. borders: [{}],
  18572. fills: [{
  18573. type: 'pattern',
  18574. pattern: 'none'
  18575. }, {
  18576. type: 'pattern',
  18577. pattern: 'gray125'
  18578. }]
  18579. };
  18580. return _this3;
  18581. } // =========================================================================
  18582. // Style Manager Interface
  18583. // override normal behaviour - consume and dispose
  18584. _createClass(StylesXformMock, [{
  18585. key: "parseStream",
  18586. value: function parseStream(stream) {
  18587. stream.autodrain();
  18588. return Promise.resolve();
  18589. } // add a cell's style model to the collection
  18590. // each style property is processed and cross-referenced, etc.
  18591. // the styleId is returned. Note: cellType is used when numFmt not defined
  18592. }, {
  18593. key: "addStyleModel",
  18594. value: function addStyleModel(model, cellType) {
  18595. switch (cellType) {
  18596. case Enums.ValueType.Date:
  18597. return this.dateStyleId;
  18598. default:
  18599. return 0;
  18600. }
  18601. }
  18602. }, {
  18603. key: "getStyleModel",
  18604. // given a styleId (i.e. s="n"), get the cell's style model
  18605. // objects are shared where possible.
  18606. value: function getStyleModel()
  18607. /* id */
  18608. {
  18609. return {};
  18610. }
  18611. }, {
  18612. key: "dateStyleId",
  18613. get: function get() {
  18614. if (!this._dateStyleId) {
  18615. var dateStyle = {
  18616. numFmtId: NumFmtXform.getDefaultFmtId('mm-dd-yy')
  18617. };
  18618. this._dateStyleId = this.model.styles.length;
  18619. this.model.styles.push(dateStyle);
  18620. }
  18621. return this._dateStyleId;
  18622. }
  18623. }]);
  18624. return StylesXformMock;
  18625. }(StylesXform);
  18626. StylesXform.Mock = StylesXformMock;
  18627. module.exports = StylesXform;
  18628. },{"../../../doc/enums":7,"../../../utils/xml-stream":27,"../base-xform":31,"../list-xform":70,"../static-xform":119,"./border-xform":126,"./dxf-xform":128,"./fill-xform":129,"./font-xform":130,"./numfmt-xform":131,"./style-xform":133}],135:[function(require,module,exports){
  18629. "use strict";
  18630. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  18631. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  18632. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  18633. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  18634. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  18635. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  18636. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  18637. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  18638. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  18639. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  18640. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  18641. var BaseXform = require('../base-xform');
  18642. var UnderlineXform = /*#__PURE__*/function (_BaseXform) {
  18643. _inherits(UnderlineXform, _BaseXform);
  18644. var _super = _createSuper(UnderlineXform);
  18645. function UnderlineXform(model) {
  18646. var _this;
  18647. _classCallCheck(this, UnderlineXform);
  18648. _this = _super.call(this);
  18649. _this.model = model;
  18650. return _this;
  18651. }
  18652. _createClass(UnderlineXform, [{
  18653. key: "render",
  18654. value: function render(xmlStream, model) {
  18655. model = model || this.model;
  18656. if (model === true) {
  18657. xmlStream.leafNode('u');
  18658. } else {
  18659. var attr = UnderlineXform.Attributes[model];
  18660. if (attr) {
  18661. xmlStream.leafNode('u', attr);
  18662. }
  18663. }
  18664. }
  18665. }, {
  18666. key: "parseOpen",
  18667. value: function parseOpen(node) {
  18668. if (node.name === 'u') {
  18669. this.model = node.attributes.val || true;
  18670. }
  18671. }
  18672. }, {
  18673. key: "parseText",
  18674. value: function parseText() {}
  18675. }, {
  18676. key: "parseClose",
  18677. value: function parseClose() {
  18678. return false;
  18679. }
  18680. }, {
  18681. key: "tag",
  18682. get: function get() {
  18683. return 'u';
  18684. }
  18685. }]);
  18686. return UnderlineXform;
  18687. }(BaseXform);
  18688. UnderlineXform.Attributes = {
  18689. single: {},
  18690. double: {
  18691. val: 'double'
  18692. },
  18693. singleAccounting: {
  18694. val: 'singleAccounting'
  18695. },
  18696. doubleAccounting: {
  18697. val: 'doubleAccounting'
  18698. }
  18699. };
  18700. module.exports = UnderlineXform;
  18701. },{"../base-xform":31}],136:[function(require,module,exports){
  18702. "use strict";
  18703. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  18704. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  18705. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  18706. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  18707. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  18708. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  18709. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  18710. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  18711. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  18712. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  18713. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  18714. var BaseXform = require('../base-xform');
  18715. var FilterColumnXform = require('./filter-column-xform');
  18716. var AutoFilterXform = /*#__PURE__*/function (_BaseXform) {
  18717. _inherits(AutoFilterXform, _BaseXform);
  18718. var _super = _createSuper(AutoFilterXform);
  18719. function AutoFilterXform() {
  18720. var _this;
  18721. _classCallCheck(this, AutoFilterXform);
  18722. _this = _super.call(this);
  18723. _this.map = {
  18724. filterColumn: new FilterColumnXform()
  18725. };
  18726. return _this;
  18727. }
  18728. _createClass(AutoFilterXform, [{
  18729. key: "prepare",
  18730. value: function prepare(model) {
  18731. var _this2 = this;
  18732. model.columns.forEach(function (column, index) {
  18733. _this2.map.filterColumn.prepare(column, {
  18734. index: index
  18735. });
  18736. });
  18737. }
  18738. }, {
  18739. key: "render",
  18740. value: function render(xmlStream, model) {
  18741. var _this3 = this;
  18742. xmlStream.openNode(this.tag, {
  18743. ref: model.autoFilterRef
  18744. });
  18745. model.columns.forEach(function (column) {
  18746. _this3.map.filterColumn.render(xmlStream, column);
  18747. });
  18748. xmlStream.closeNode();
  18749. return true;
  18750. }
  18751. }, {
  18752. key: "parseOpen",
  18753. value: function parseOpen(node) {
  18754. if (this.parser) {
  18755. this.parser.parseOpen(node);
  18756. return true;
  18757. }
  18758. switch (node.name) {
  18759. case this.tag:
  18760. this.model = {
  18761. autoFilterRef: node.attributes.ref,
  18762. columns: []
  18763. };
  18764. return true;
  18765. default:
  18766. this.parser = this.map[node.name];
  18767. if (this.parser) {
  18768. this.parseOpen(node);
  18769. return true;
  18770. }
  18771. throw new Error("Unexpected xml node in parseOpen: ".concat(JSON.stringify(node)));
  18772. }
  18773. }
  18774. }, {
  18775. key: "parseText",
  18776. value: function parseText(text) {
  18777. if (this.parser) {
  18778. this.parser.parseText(text);
  18779. }
  18780. }
  18781. }, {
  18782. key: "parseClose",
  18783. value: function parseClose(name) {
  18784. if (this.parser) {
  18785. if (!this.parser.parseClose(name)) {
  18786. this.model.columns.push(this.parser.model);
  18787. this.parser = undefined;
  18788. }
  18789. return true;
  18790. }
  18791. switch (name) {
  18792. case this.tag:
  18793. return false;
  18794. default:
  18795. throw new Error("Unexpected xml node in parseClose: ".concat(name));
  18796. }
  18797. }
  18798. }, {
  18799. key: "tag",
  18800. get: function get() {
  18801. return 'autoFilter';
  18802. }
  18803. }]);
  18804. return AutoFilterXform;
  18805. }(BaseXform);
  18806. module.exports = AutoFilterXform;
  18807. },{"../base-xform":31,"./filter-column-xform":137}],137:[function(require,module,exports){
  18808. "use strict";
  18809. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  18810. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  18811. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  18812. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  18813. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  18814. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  18815. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  18816. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  18817. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  18818. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  18819. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  18820. var BaseXform = require('../base-xform');
  18821. var FilterColumnXform = /*#__PURE__*/function (_BaseXform) {
  18822. _inherits(FilterColumnXform, _BaseXform);
  18823. var _super = _createSuper(FilterColumnXform);
  18824. function FilterColumnXform() {
  18825. _classCallCheck(this, FilterColumnXform);
  18826. return _super.apply(this, arguments);
  18827. }
  18828. _createClass(FilterColumnXform, [{
  18829. key: "prepare",
  18830. value: function prepare(model, options) {
  18831. model.colId = options.index.toString();
  18832. }
  18833. }, {
  18834. key: "render",
  18835. value: function render(xmlStream, model) {
  18836. xmlStream.leafNode(this.tag, {
  18837. colId: model.colId,
  18838. hiddenButton: model.filterButton ? '0' : '1'
  18839. });
  18840. return true;
  18841. }
  18842. }, {
  18843. key: "parseOpen",
  18844. value: function parseOpen(node) {
  18845. if (node.name === this.tag) {
  18846. var attributes = node.attributes;
  18847. this.model = {
  18848. filterButton: attributes.hiddenButton === '0'
  18849. };
  18850. return true;
  18851. }
  18852. return false;
  18853. }
  18854. }, {
  18855. key: "parseText",
  18856. value: function parseText() {}
  18857. }, {
  18858. key: "parseClose",
  18859. value: function parseClose() {
  18860. return false;
  18861. }
  18862. }, {
  18863. key: "tag",
  18864. get: function get() {
  18865. return 'filterColumn';
  18866. }
  18867. }]);
  18868. return FilterColumnXform;
  18869. }(BaseXform);
  18870. module.exports = FilterColumnXform;
  18871. },{"../base-xform":31}],138:[function(require,module,exports){
  18872. "use strict";
  18873. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  18874. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  18875. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  18876. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  18877. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  18878. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  18879. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  18880. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  18881. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  18882. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  18883. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  18884. var BaseXform = require('../base-xform');
  18885. var TableColumnXform = /*#__PURE__*/function (_BaseXform) {
  18886. _inherits(TableColumnXform, _BaseXform);
  18887. var _super = _createSuper(TableColumnXform);
  18888. function TableColumnXform() {
  18889. _classCallCheck(this, TableColumnXform);
  18890. return _super.apply(this, arguments);
  18891. }
  18892. _createClass(TableColumnXform, [{
  18893. key: "prepare",
  18894. value: function prepare(model, options) {
  18895. model.id = options.index + 1;
  18896. }
  18897. }, {
  18898. key: "render",
  18899. value: function render(xmlStream, model) {
  18900. xmlStream.leafNode(this.tag, {
  18901. id: model.id.toString(),
  18902. name: model.name,
  18903. totalsRowLabel: model.totalsRowLabel,
  18904. totalsRowFunction: model.totalsRowFunction,
  18905. dxfId: model.dxfId
  18906. });
  18907. return true;
  18908. }
  18909. }, {
  18910. key: "parseOpen",
  18911. value: function parseOpen(node) {
  18912. if (node.name === this.tag) {
  18913. var attributes = node.attributes;
  18914. this.model = {
  18915. name: attributes.name,
  18916. totalsRowLabel: attributes.totalsRowLabel,
  18917. totalsRowFunction: attributes.totalsRowFunction,
  18918. dxfId: attributes.dxfId
  18919. };
  18920. return true;
  18921. }
  18922. return false;
  18923. }
  18924. }, {
  18925. key: "parseText",
  18926. value: function parseText() {}
  18927. }, {
  18928. key: "parseClose",
  18929. value: function parseClose() {
  18930. return false;
  18931. }
  18932. }, {
  18933. key: "tag",
  18934. get: function get() {
  18935. return 'tableColumn';
  18936. }
  18937. }]);
  18938. return TableColumnXform;
  18939. }(BaseXform);
  18940. module.exports = TableColumnXform;
  18941. },{"../base-xform":31}],139:[function(require,module,exports){
  18942. "use strict";
  18943. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  18944. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  18945. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  18946. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  18947. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  18948. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  18949. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  18950. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  18951. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  18952. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  18953. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  18954. var BaseXform = require('../base-xform');
  18955. var TableStyleInfoXform = /*#__PURE__*/function (_BaseXform) {
  18956. _inherits(TableStyleInfoXform, _BaseXform);
  18957. var _super = _createSuper(TableStyleInfoXform);
  18958. function TableStyleInfoXform() {
  18959. _classCallCheck(this, TableStyleInfoXform);
  18960. return _super.apply(this, arguments);
  18961. }
  18962. _createClass(TableStyleInfoXform, [{
  18963. key: "render",
  18964. value: function render(xmlStream, model) {
  18965. xmlStream.leafNode(this.tag, {
  18966. name: model.theme ? model.theme : undefined,
  18967. showFirstColumn: model.showFirstColumn ? '1' : '0',
  18968. showLastColumn: model.showLastColumn ? '1' : '0',
  18969. showRowStripes: model.showRowStripes ? '1' : '0',
  18970. showColumnStripes: model.showColumnStripes ? '1' : '0'
  18971. });
  18972. return true;
  18973. }
  18974. }, {
  18975. key: "parseOpen",
  18976. value: function parseOpen(node) {
  18977. if (node.name === this.tag) {
  18978. var attributes = node.attributes;
  18979. this.model = {
  18980. theme: attributes.name ? attributes.name : null,
  18981. showFirstColumn: attributes.showFirstColumn === '1',
  18982. showLastColumn: attributes.showLastColumn === '1',
  18983. showRowStripes: attributes.showRowStripes === '1',
  18984. showColumnStripes: attributes.showColumnStripes === '1'
  18985. };
  18986. return true;
  18987. }
  18988. return false;
  18989. }
  18990. }, {
  18991. key: "parseText",
  18992. value: function parseText() {}
  18993. }, {
  18994. key: "parseClose",
  18995. value: function parseClose() {
  18996. return false;
  18997. }
  18998. }, {
  18999. key: "tag",
  19000. get: function get() {
  19001. return 'tableStyleInfo';
  19002. }
  19003. }]);
  19004. return TableStyleInfoXform;
  19005. }(BaseXform);
  19006. module.exports = TableStyleInfoXform;
  19007. },{"../base-xform":31}],140:[function(require,module,exports){
  19008. "use strict";
  19009. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  19010. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  19011. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  19012. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  19013. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  19014. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  19015. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  19016. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  19017. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  19018. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  19019. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  19020. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  19021. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  19022. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  19023. var XmlStream = require('../../../utils/xml-stream');
  19024. var BaseXform = require('../base-xform');
  19025. var ListXform = require('../list-xform');
  19026. var AutoFilterXform = require('./auto-filter-xform');
  19027. var TableColumnXform = require('./table-column-xform');
  19028. var TableStyleInfoXform = require('./table-style-info-xform');
  19029. var TableXform = /*#__PURE__*/function (_BaseXform) {
  19030. _inherits(TableXform, _BaseXform);
  19031. var _super = _createSuper(TableXform);
  19032. function TableXform() {
  19033. var _this;
  19034. _classCallCheck(this, TableXform);
  19035. _this = _super.call(this);
  19036. _this.map = {
  19037. autoFilter: new AutoFilterXform(),
  19038. tableColumns: new ListXform({
  19039. tag: 'tableColumns',
  19040. count: true,
  19041. empty: true,
  19042. childXform: new TableColumnXform()
  19043. }),
  19044. tableStyleInfo: new TableStyleInfoXform()
  19045. };
  19046. return _this;
  19047. }
  19048. _createClass(TableXform, [{
  19049. key: "prepare",
  19050. value: function prepare(model, options) {
  19051. this.map.autoFilter.prepare(model);
  19052. this.map.tableColumns.prepare(model.columns, options);
  19053. }
  19054. }, {
  19055. key: "render",
  19056. value: function render(xmlStream, model) {
  19057. xmlStream.openXml(XmlStream.StdDocAttributes);
  19058. xmlStream.openNode(this.tag, _objectSpread(_objectSpread({}, TableXform.TABLE_ATTRIBUTES), {}, {
  19059. id: model.id,
  19060. name: model.name,
  19061. displayName: model.displayName || model.name,
  19062. ref: model.tableRef,
  19063. totalsRowCount: model.totalsRow ? '1' : undefined,
  19064. totalsRowShown: model.totalsRow ? undefined : '1',
  19065. headerRowCount: model.headerRow ? '1' : '0'
  19066. }));
  19067. this.map.autoFilter.render(xmlStream, model);
  19068. this.map.tableColumns.render(xmlStream, model.columns);
  19069. this.map.tableStyleInfo.render(xmlStream, model.style);
  19070. xmlStream.closeNode();
  19071. }
  19072. }, {
  19073. key: "parseOpen",
  19074. value: function parseOpen(node) {
  19075. if (this.parser) {
  19076. this.parser.parseOpen(node);
  19077. return true;
  19078. }
  19079. var name = node.name,
  19080. attributes = node.attributes;
  19081. switch (name) {
  19082. case this.tag:
  19083. this.reset();
  19084. this.model = {
  19085. name: attributes.name,
  19086. displayName: attributes.displayName || attributes.name,
  19087. tableRef: attributes.ref,
  19088. totalsRow: attributes.totalsRowCount === '1',
  19089. headerRow: attributes.headerRowCount === '1'
  19090. };
  19091. break;
  19092. default:
  19093. this.parser = this.map[node.name];
  19094. if (this.parser) {
  19095. this.parser.parseOpen(node);
  19096. }
  19097. break;
  19098. }
  19099. return true;
  19100. }
  19101. }, {
  19102. key: "parseText",
  19103. value: function parseText(text) {
  19104. if (this.parser) {
  19105. this.parser.parseText(text);
  19106. }
  19107. }
  19108. }, {
  19109. key: "parseClose",
  19110. value: function parseClose(name) {
  19111. var _this2 = this;
  19112. if (this.parser) {
  19113. if (!this.parser.parseClose(name)) {
  19114. this.parser = undefined;
  19115. }
  19116. return true;
  19117. }
  19118. switch (name) {
  19119. case this.tag:
  19120. this.model.columns = this.map.tableColumns.model;
  19121. if (this.map.autoFilter.model) {
  19122. this.model.autoFilterRef = this.map.autoFilter.model.autoFilterRef;
  19123. this.map.autoFilter.model.columns.forEach(function (column, index) {
  19124. _this2.model.columns[index].filterButton = column.filterButton;
  19125. });
  19126. }
  19127. this.model.style = this.map.tableStyleInfo.model;
  19128. return false;
  19129. default:
  19130. // could be some unrecognised tags
  19131. return true;
  19132. }
  19133. }
  19134. }, {
  19135. key: "reconcile",
  19136. value: function reconcile(model, options) {
  19137. // fetch the dfxs from styles
  19138. model.columns.forEach(function (column) {
  19139. if (column.dxfId !== undefined) {
  19140. column.style = options.styles.getDxfStyle(column.dxfId);
  19141. }
  19142. });
  19143. }
  19144. }, {
  19145. key: "tag",
  19146. get: function get() {
  19147. return 'table';
  19148. }
  19149. }]);
  19150. return TableXform;
  19151. }(BaseXform);
  19152. TableXform.TABLE_ATTRIBUTES = {
  19153. xmlns: 'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
  19154. 'xmlns:mc': 'http://schemas.openxmlformats.org/markup-compatibility/2006',
  19155. 'mc:Ignorable': 'xr xr3',
  19156. 'xmlns:xr': 'http://schemas.microsoft.com/office/spreadsheetml/2014/revision',
  19157. 'xmlns:xr3': 'http://schemas.microsoft.com/office/spreadsheetml/2016/revision3' // 'xr:uid': '{00000000-000C-0000-FFFF-FFFF00000000}',
  19158. };
  19159. module.exports = TableXform;
  19160. },{"../../../utils/xml-stream":27,"../base-xform":31,"../list-xform":70,"./auto-filter-xform":136,"./table-column-xform":138,"./table-style-info-xform":139}],141:[function(require,module,exports){
  19161. (function (process,Buffer){
  19162. "use strict";
  19163. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
  19164. function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
  19165. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  19166. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  19167. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  19168. function _asyncIterator(iterable) { var method; if (typeof Symbol !== "undefined") { if (Symbol.asyncIterator) { method = iterable[Symbol.asyncIterator]; if (method != null) return method.call(iterable); } if (Symbol.iterator) { method = iterable[Symbol.iterator]; if (method != null) return method.call(iterable); } } throw new TypeError("Object is not async iterable"); }
  19169. var fs = require('fs');
  19170. var JSZip = require('jszip');
  19171. var _require = require('readable-stream'),
  19172. PassThrough = _require.PassThrough;
  19173. var ZipStream = require('../utils/zip-stream');
  19174. var StreamBuf = require('../utils/stream-buf');
  19175. var utils = require('../utils/utils');
  19176. var XmlStream = require('../utils/xml-stream');
  19177. var _require2 = require('../utils/browser-buffer-decode'),
  19178. bufferToString = _require2.bufferToString;
  19179. var StylesXform = require('./xform/style/styles-xform');
  19180. var CoreXform = require('./xform/core/core-xform');
  19181. var SharedStringsXform = require('./xform/strings/shared-strings-xform');
  19182. var RelationshipsXform = require('./xform/core/relationships-xform');
  19183. var ContentTypesXform = require('./xform/core/content-types-xform');
  19184. var AppXform = require('./xform/core/app-xform');
  19185. var WorkbookXform = require('./xform/book/workbook-xform');
  19186. var WorksheetXform = require('./xform/sheet/worksheet-xform');
  19187. var DrawingXform = require('./xform/drawing/drawing-xform');
  19188. var TableXform = require('./xform/table/table-xform');
  19189. var CommentsXform = require('./xform/comment/comments-xform');
  19190. var VmlNotesXform = require('./xform/comment/vml-notes-xform');
  19191. var theme1Xml = require('./xml/theme1.js');
  19192. function fsReadFileAsync(filename, options) {
  19193. return new Promise(function (resolve, reject) {
  19194. fs.readFile(filename, options, function (error, data) {
  19195. if (error) {
  19196. reject(error);
  19197. } else {
  19198. resolve(data);
  19199. }
  19200. });
  19201. });
  19202. }
  19203. var XLSX = /*#__PURE__*/function () {
  19204. function XLSX(workbook) {
  19205. _classCallCheck(this, XLSX);
  19206. this.workbook = workbook;
  19207. } // ===============================================================================
  19208. // Workbook
  19209. // =========================================================================
  19210. // Read
  19211. _createClass(XLSX, [{
  19212. key: "readFile",
  19213. value: function () {
  19214. var _readFile = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(filename, options) {
  19215. var stream, workbook;
  19216. return regeneratorRuntime.wrap(function _callee$(_context) {
  19217. while (1) {
  19218. switch (_context.prev = _context.next) {
  19219. case 0:
  19220. _context.next = 2;
  19221. return utils.fs.exists(filename);
  19222. case 2:
  19223. if (_context.sent) {
  19224. _context.next = 4;
  19225. break;
  19226. }
  19227. throw new Error("File not found: ".concat(filename));
  19228. case 4:
  19229. stream = fs.createReadStream(filename);
  19230. _context.prev = 5;
  19231. _context.next = 8;
  19232. return this.read(stream, options);
  19233. case 8:
  19234. workbook = _context.sent;
  19235. stream.close();
  19236. return _context.abrupt("return", workbook);
  19237. case 13:
  19238. _context.prev = 13;
  19239. _context.t0 = _context["catch"](5);
  19240. stream.close();
  19241. throw _context.t0;
  19242. case 17:
  19243. case "end":
  19244. return _context.stop();
  19245. }
  19246. }
  19247. }, _callee, this, [[5, 13]]);
  19248. }));
  19249. function readFile(_x, _x2) {
  19250. return _readFile.apply(this, arguments);
  19251. }
  19252. return readFile;
  19253. }()
  19254. }, {
  19255. key: "parseRels",
  19256. value: function parseRels(stream) {
  19257. var xform = new RelationshipsXform();
  19258. return xform.parseStream(stream);
  19259. }
  19260. }, {
  19261. key: "parseWorkbook",
  19262. value: function parseWorkbook(stream) {
  19263. var xform = new WorkbookXform();
  19264. return xform.parseStream(stream);
  19265. }
  19266. }, {
  19267. key: "parseSharedStrings",
  19268. value: function parseSharedStrings(stream) {
  19269. var xform = new SharedStringsXform();
  19270. return xform.parseStream(stream);
  19271. }
  19272. }, {
  19273. key: "reconcile",
  19274. value: function reconcile(model, options) {
  19275. var workbookXform = new WorkbookXform();
  19276. var worksheetXform = new WorksheetXform(options);
  19277. var drawingXform = new DrawingXform();
  19278. var tableXform = new TableXform();
  19279. workbookXform.reconcile(model); // reconcile drawings with their rels
  19280. var drawingOptions = {
  19281. media: model.media,
  19282. mediaIndex: model.mediaIndex
  19283. };
  19284. Object.keys(model.drawings).forEach(function (name) {
  19285. var drawing = model.drawings[name];
  19286. var drawingRel = model.drawingRels[name];
  19287. if (drawingRel) {
  19288. drawingOptions.rels = drawingRel.reduce(function (o, rel) {
  19289. o[rel.Id] = rel;
  19290. return o;
  19291. }, {});
  19292. (drawing.anchors || []).forEach(function (anchor) {
  19293. var hyperlinks = anchor.picture && anchor.picture.hyperlinks;
  19294. if (hyperlinks && drawingOptions.rels[hyperlinks.rId]) {
  19295. hyperlinks.hyperlink = drawingOptions.rels[hyperlinks.rId].Target;
  19296. delete hyperlinks.rId;
  19297. }
  19298. });
  19299. drawingXform.reconcile(drawing, drawingOptions);
  19300. }
  19301. }); // reconcile tables with the default styles
  19302. var tableOptions = {
  19303. styles: model.styles
  19304. };
  19305. Object.values(model.tables).forEach(function (table) {
  19306. tableXform.reconcile(table, tableOptions);
  19307. });
  19308. var sheetOptions = {
  19309. styles: model.styles,
  19310. sharedStrings: model.sharedStrings,
  19311. media: model.media,
  19312. mediaIndex: model.mediaIndex,
  19313. date1904: model.properties && model.properties.date1904,
  19314. drawings: model.drawings,
  19315. comments: model.comments,
  19316. tables: model.tables,
  19317. vmlDrawings: model.vmlDrawings
  19318. };
  19319. model.worksheets.forEach(function (worksheet) {
  19320. worksheet.relationships = model.worksheetRels[worksheet.sheetNo];
  19321. worksheetXform.reconcile(worksheet, sheetOptions);
  19322. }); // delete unnecessary parts
  19323. delete model.worksheetHash;
  19324. delete model.worksheetRels;
  19325. delete model.globalRels;
  19326. delete model.sharedStrings;
  19327. delete model.workbookRels;
  19328. delete model.sheetDefs;
  19329. delete model.styles;
  19330. delete model.mediaIndex;
  19331. delete model.drawings;
  19332. delete model.drawingRels;
  19333. delete model.vmlDrawings;
  19334. }
  19335. }, {
  19336. key: "_processWorksheetEntry",
  19337. value: function () {
  19338. var _processWorksheetEntry2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(stream, model, sheetNo, options, path) {
  19339. var xform, worksheet;
  19340. return regeneratorRuntime.wrap(function _callee2$(_context2) {
  19341. while (1) {
  19342. switch (_context2.prev = _context2.next) {
  19343. case 0:
  19344. xform = new WorksheetXform(options);
  19345. _context2.next = 3;
  19346. return xform.parseStream(stream);
  19347. case 3:
  19348. worksheet = _context2.sent;
  19349. worksheet.sheetNo = sheetNo;
  19350. model.worksheetHash[path] = worksheet;
  19351. model.worksheets.push(worksheet);
  19352. case 7:
  19353. case "end":
  19354. return _context2.stop();
  19355. }
  19356. }
  19357. }, _callee2);
  19358. }));
  19359. function _processWorksheetEntry(_x3, _x4, _x5, _x6, _x7) {
  19360. return _processWorksheetEntry2.apply(this, arguments);
  19361. }
  19362. return _processWorksheetEntry;
  19363. }()
  19364. }, {
  19365. key: "_processCommentEntry",
  19366. value: function () {
  19367. var _processCommentEntry2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(stream, model, name) {
  19368. var xform, comments;
  19369. return regeneratorRuntime.wrap(function _callee3$(_context3) {
  19370. while (1) {
  19371. switch (_context3.prev = _context3.next) {
  19372. case 0:
  19373. xform = new CommentsXform();
  19374. _context3.next = 3;
  19375. return xform.parseStream(stream);
  19376. case 3:
  19377. comments = _context3.sent;
  19378. model.comments["../".concat(name, ".xml")] = comments;
  19379. case 5:
  19380. case "end":
  19381. return _context3.stop();
  19382. }
  19383. }
  19384. }, _callee3);
  19385. }));
  19386. function _processCommentEntry(_x8, _x9, _x10) {
  19387. return _processCommentEntry2.apply(this, arguments);
  19388. }
  19389. return _processCommentEntry;
  19390. }()
  19391. }, {
  19392. key: "_processTableEntry",
  19393. value: function () {
  19394. var _processTableEntry2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(stream, model, name) {
  19395. var xform, table;
  19396. return regeneratorRuntime.wrap(function _callee4$(_context4) {
  19397. while (1) {
  19398. switch (_context4.prev = _context4.next) {
  19399. case 0:
  19400. xform = new TableXform();
  19401. _context4.next = 3;
  19402. return xform.parseStream(stream);
  19403. case 3:
  19404. table = _context4.sent;
  19405. model.tables["../tables/".concat(name, ".xml")] = table;
  19406. case 5:
  19407. case "end":
  19408. return _context4.stop();
  19409. }
  19410. }
  19411. }, _callee4);
  19412. }));
  19413. function _processTableEntry(_x11, _x12, _x13) {
  19414. return _processTableEntry2.apply(this, arguments);
  19415. }
  19416. return _processTableEntry;
  19417. }()
  19418. }, {
  19419. key: "_processWorksheetRelsEntry",
  19420. value: function () {
  19421. var _processWorksheetRelsEntry2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(stream, model, sheetNo) {
  19422. var xform, relationships;
  19423. return regeneratorRuntime.wrap(function _callee5$(_context5) {
  19424. while (1) {
  19425. switch (_context5.prev = _context5.next) {
  19426. case 0:
  19427. xform = new RelationshipsXform();
  19428. _context5.next = 3;
  19429. return xform.parseStream(stream);
  19430. case 3:
  19431. relationships = _context5.sent;
  19432. model.worksheetRels[sheetNo] = relationships;
  19433. case 5:
  19434. case "end":
  19435. return _context5.stop();
  19436. }
  19437. }
  19438. }, _callee5);
  19439. }));
  19440. function _processWorksheetRelsEntry(_x14, _x15, _x16) {
  19441. return _processWorksheetRelsEntry2.apply(this, arguments);
  19442. }
  19443. return _processWorksheetRelsEntry;
  19444. }()
  19445. }, {
  19446. key: "_processMediaEntry",
  19447. value: function () {
  19448. var _processMediaEntry2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(entry, model, filename) {
  19449. var lastDot, extension, name;
  19450. return regeneratorRuntime.wrap(function _callee6$(_context6) {
  19451. while (1) {
  19452. switch (_context6.prev = _context6.next) {
  19453. case 0:
  19454. lastDot = filename.lastIndexOf('.'); // if we can't determine extension, ignore it
  19455. if (!(lastDot >= 1)) {
  19456. _context6.next = 6;
  19457. break;
  19458. }
  19459. extension = filename.substr(lastDot + 1);
  19460. name = filename.substr(0, lastDot);
  19461. _context6.next = 6;
  19462. return new Promise(function (resolve, reject) {
  19463. var streamBuf = new StreamBuf();
  19464. streamBuf.on('finish', function () {
  19465. model.mediaIndex[filename] = model.media.length;
  19466. model.mediaIndex[name] = model.media.length;
  19467. var medium = {
  19468. type: 'image',
  19469. name: name,
  19470. extension: extension,
  19471. buffer: streamBuf.toBuffer()
  19472. };
  19473. model.media.push(medium);
  19474. resolve();
  19475. });
  19476. entry.on('error', function (error) {
  19477. reject(error);
  19478. });
  19479. entry.pipe(streamBuf);
  19480. });
  19481. case 6:
  19482. case "end":
  19483. return _context6.stop();
  19484. }
  19485. }
  19486. }, _callee6);
  19487. }));
  19488. function _processMediaEntry(_x17, _x18, _x19) {
  19489. return _processMediaEntry2.apply(this, arguments);
  19490. }
  19491. return _processMediaEntry;
  19492. }()
  19493. }, {
  19494. key: "_processDrawingEntry",
  19495. value: function () {
  19496. var _processDrawingEntry2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7(entry, model, name) {
  19497. var xform, drawing;
  19498. return regeneratorRuntime.wrap(function _callee7$(_context7) {
  19499. while (1) {
  19500. switch (_context7.prev = _context7.next) {
  19501. case 0:
  19502. xform = new DrawingXform();
  19503. _context7.next = 3;
  19504. return xform.parseStream(entry);
  19505. case 3:
  19506. drawing = _context7.sent;
  19507. model.drawings[name] = drawing;
  19508. case 5:
  19509. case "end":
  19510. return _context7.stop();
  19511. }
  19512. }
  19513. }, _callee7);
  19514. }));
  19515. function _processDrawingEntry(_x20, _x21, _x22) {
  19516. return _processDrawingEntry2.apply(this, arguments);
  19517. }
  19518. return _processDrawingEntry;
  19519. }()
  19520. }, {
  19521. key: "_processDrawingRelsEntry",
  19522. value: function () {
  19523. var _processDrawingRelsEntry2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8(entry, model, name) {
  19524. var xform, relationships;
  19525. return regeneratorRuntime.wrap(function _callee8$(_context8) {
  19526. while (1) {
  19527. switch (_context8.prev = _context8.next) {
  19528. case 0:
  19529. xform = new RelationshipsXform();
  19530. _context8.next = 3;
  19531. return xform.parseStream(entry);
  19532. case 3:
  19533. relationships = _context8.sent;
  19534. model.drawingRels[name] = relationships;
  19535. case 5:
  19536. case "end":
  19537. return _context8.stop();
  19538. }
  19539. }
  19540. }, _callee8);
  19541. }));
  19542. function _processDrawingRelsEntry(_x23, _x24, _x25) {
  19543. return _processDrawingRelsEntry2.apply(this, arguments);
  19544. }
  19545. return _processDrawingRelsEntry;
  19546. }()
  19547. }, {
  19548. key: "_processVmlDrawingEntry",
  19549. value: function () {
  19550. var _processVmlDrawingEntry2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9(entry, model, name) {
  19551. var xform, vmlDrawing;
  19552. return regeneratorRuntime.wrap(function _callee9$(_context9) {
  19553. while (1) {
  19554. switch (_context9.prev = _context9.next) {
  19555. case 0:
  19556. xform = new VmlNotesXform();
  19557. _context9.next = 3;
  19558. return xform.parseStream(entry);
  19559. case 3:
  19560. vmlDrawing = _context9.sent;
  19561. model.vmlDrawings["../drawings/".concat(name, ".vml")] = vmlDrawing;
  19562. case 5:
  19563. case "end":
  19564. return _context9.stop();
  19565. }
  19566. }
  19567. }, _callee9);
  19568. }));
  19569. function _processVmlDrawingEntry(_x26, _x27, _x28) {
  19570. return _processVmlDrawingEntry2.apply(this, arguments);
  19571. }
  19572. return _processVmlDrawingEntry;
  19573. }()
  19574. }, {
  19575. key: "_processThemeEntry",
  19576. value: function () {
  19577. var _processThemeEntry2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10(entry, model, name) {
  19578. return regeneratorRuntime.wrap(function _callee10$(_context10) {
  19579. while (1) {
  19580. switch (_context10.prev = _context10.next) {
  19581. case 0:
  19582. _context10.next = 2;
  19583. return new Promise(function (resolve, reject) {
  19584. // TODO: stream entry into buffer and store the xml in the model.themes[]
  19585. var stream = new StreamBuf();
  19586. entry.on('error', reject);
  19587. stream.on('error', reject);
  19588. stream.on('finish', function () {
  19589. model.themes[name] = stream.read().toString();
  19590. resolve();
  19591. });
  19592. entry.pipe(stream);
  19593. });
  19594. case 2:
  19595. case "end":
  19596. return _context10.stop();
  19597. }
  19598. }
  19599. }, _callee10);
  19600. }));
  19601. function _processThemeEntry(_x29, _x30, _x31) {
  19602. return _processThemeEntry2.apply(this, arguments);
  19603. }
  19604. return _processThemeEntry;
  19605. }()
  19606. /**
  19607. * @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
  19608. */
  19609. }, {
  19610. key: "createInputStream",
  19611. value: function createInputStream() {
  19612. 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');
  19613. }
  19614. }, {
  19615. key: "read",
  19616. value: function () {
  19617. var _read = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11(stream, options) {
  19618. var chunks, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk;
  19619. return regeneratorRuntime.wrap(function _callee11$(_context11) {
  19620. while (1) {
  19621. switch (_context11.prev = _context11.next) {
  19622. case 0:
  19623. // TODO: Remove once node v8 is deprecated
  19624. // Detect and upgrade old streams
  19625. if (!stream[Symbol.asyncIterator] && stream.pipe) {
  19626. stream = stream.pipe(new PassThrough());
  19627. }
  19628. chunks = [];
  19629. _iteratorNormalCompletion = true;
  19630. _didIteratorError = false;
  19631. _context11.prev = 4;
  19632. _iterator = _asyncIterator(stream);
  19633. case 6:
  19634. _context11.next = 8;
  19635. return _iterator.next();
  19636. case 8:
  19637. _step = _context11.sent;
  19638. _iteratorNormalCompletion = _step.done;
  19639. _context11.next = 12;
  19640. return _step.value;
  19641. case 12:
  19642. _value = _context11.sent;
  19643. if (_iteratorNormalCompletion) {
  19644. _context11.next = 19;
  19645. break;
  19646. }
  19647. chunk = _value;
  19648. chunks.push(chunk);
  19649. case 16:
  19650. _iteratorNormalCompletion = true;
  19651. _context11.next = 6;
  19652. break;
  19653. case 19:
  19654. _context11.next = 25;
  19655. break;
  19656. case 21:
  19657. _context11.prev = 21;
  19658. _context11.t0 = _context11["catch"](4);
  19659. _didIteratorError = true;
  19660. _iteratorError = _context11.t0;
  19661. case 25:
  19662. _context11.prev = 25;
  19663. _context11.prev = 26;
  19664. if (!(!_iteratorNormalCompletion && _iterator.return != null)) {
  19665. _context11.next = 30;
  19666. break;
  19667. }
  19668. _context11.next = 30;
  19669. return _iterator.return();
  19670. case 30:
  19671. _context11.prev = 30;
  19672. if (!_didIteratorError) {
  19673. _context11.next = 33;
  19674. break;
  19675. }
  19676. throw _iteratorError;
  19677. case 33:
  19678. return _context11.finish(30);
  19679. case 34:
  19680. return _context11.finish(25);
  19681. case 35:
  19682. return _context11.abrupt("return", this.load(Buffer.concat(chunks), options));
  19683. case 36:
  19684. case "end":
  19685. return _context11.stop();
  19686. }
  19687. }
  19688. }, _callee11, this, [[4, 21, 25, 35], [26,, 30, 34]]);
  19689. }));
  19690. function read(_x32, _x33) {
  19691. return _read.apply(this, arguments);
  19692. }
  19693. return read;
  19694. }()
  19695. }, {
  19696. key: "load",
  19697. value: function () {
  19698. var _load = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee12(data, options) {
  19699. var buffer, model, zip, _i, _Object$values, entry, entryName, stream, content, chunkSize, i, workbook, appXform, appProperties, coreXform, coreProperties, match;
  19700. return regeneratorRuntime.wrap(function _callee12$(_context12) {
  19701. while (1) {
  19702. switch (_context12.prev = _context12.next) {
  19703. case 0:
  19704. if (options && options.base64) {
  19705. buffer = Buffer.from(data.toString(), 'base64');
  19706. } else {
  19707. buffer = data;
  19708. }
  19709. model = {
  19710. worksheets: [],
  19711. worksheetHash: {},
  19712. worksheetRels: [],
  19713. themes: {},
  19714. media: [],
  19715. mediaIndex: {},
  19716. drawings: {},
  19717. drawingRels: {},
  19718. comments: {},
  19719. tables: {},
  19720. vmlDrawings: {}
  19721. };
  19722. _context12.next = 4;
  19723. return JSZip.loadAsync(buffer);
  19724. case 4:
  19725. zip = _context12.sent;
  19726. _i = 0, _Object$values = Object.values(zip.files);
  19727. case 6:
  19728. if (!(_i < _Object$values.length)) {
  19729. _context12.next = 126;
  19730. break;
  19731. }
  19732. entry = _Object$values[_i];
  19733. if (entry.dir) {
  19734. _context12.next = 123;
  19735. break;
  19736. }
  19737. entryName = entry.name;
  19738. if (entryName[0] === '/') {
  19739. entryName = entryName.substr(1);
  19740. }
  19741. stream = void 0;
  19742. if (!(entryName.match(/xl\/media\//) || // themes are not parsed as stream
  19743. entryName.match(/xl\/theme\/([a-zA-Z0-9]+)[.]xml/))) {
  19744. _context12.next = 21;
  19745. break;
  19746. }
  19747. stream = new PassThrough();
  19748. _context12.t0 = stream;
  19749. _context12.next = 17;
  19750. return entry.async('nodebuffer');
  19751. case 17:
  19752. _context12.t1 = _context12.sent;
  19753. _context12.t0.write.call(_context12.t0, _context12.t1);
  19754. _context12.next = 36;
  19755. break;
  19756. case 21:
  19757. // use object mode to avoid buffer-string convention
  19758. stream = new PassThrough({
  19759. writableObjectMode: true,
  19760. readableObjectMode: true
  19761. });
  19762. content = void 0; // https://www.npmjs.com/package/process
  19763. if (!process.browser) {
  19764. _context12.next = 31;
  19765. break;
  19766. }
  19767. _context12.t2 = bufferToString;
  19768. _context12.next = 27;
  19769. return entry.async('nodebuffer');
  19770. case 27:
  19771. _context12.t3 = _context12.sent;
  19772. content = (0, _context12.t2)(_context12.t3);
  19773. _context12.next = 34;
  19774. break;
  19775. case 31:
  19776. _context12.next = 33;
  19777. return entry.async('string');
  19778. case 33:
  19779. content = _context12.sent;
  19780. case 34:
  19781. chunkSize = 16 * 1024;
  19782. for (i = 0; i < content.length; i += chunkSize) {
  19783. stream.write(content.substring(i, i + chunkSize));
  19784. }
  19785. case 36:
  19786. stream.end();
  19787. _context12.t4 = entryName;
  19788. _context12.next = _context12.t4 === '_rels/.rels' ? 40 : _context12.t4 === 'xl/workbook.xml' ? 44 : _context12.t4 === 'xl/_rels/workbook.xml.rels' ? 53 : _context12.t4 === 'xl/sharedStrings.xml' ? 57 : _context12.t4 === 'xl/styles.xml' ? 61 : _context12.t4 === 'docProps/app.xml' ? 65 : _context12.t4 === 'docProps/core.xml' ? 72 : 78;
  19789. break;
  19790. case 40:
  19791. _context12.next = 42;
  19792. return this.parseRels(stream);
  19793. case 42:
  19794. model.globalRels = _context12.sent;
  19795. return _context12.abrupt("break", 123);
  19796. case 44:
  19797. _context12.next = 46;
  19798. return this.parseWorkbook(stream);
  19799. case 46:
  19800. workbook = _context12.sent;
  19801. model.sheets = workbook.sheets;
  19802. model.definedNames = workbook.definedNames;
  19803. model.views = workbook.views;
  19804. model.properties = workbook.properties;
  19805. model.calcProperties = workbook.calcProperties;
  19806. return _context12.abrupt("break", 123);
  19807. case 53:
  19808. _context12.next = 55;
  19809. return this.parseRels(stream);
  19810. case 55:
  19811. model.workbookRels = _context12.sent;
  19812. return _context12.abrupt("break", 123);
  19813. case 57:
  19814. model.sharedStrings = new SharedStringsXform();
  19815. _context12.next = 60;
  19816. return model.sharedStrings.parseStream(stream);
  19817. case 60:
  19818. return _context12.abrupt("break", 123);
  19819. case 61:
  19820. model.styles = new StylesXform();
  19821. _context12.next = 64;
  19822. return model.styles.parseStream(stream);
  19823. case 64:
  19824. return _context12.abrupt("break", 123);
  19825. case 65:
  19826. appXform = new AppXform();
  19827. _context12.next = 68;
  19828. return appXform.parseStream(stream);
  19829. case 68:
  19830. appProperties = _context12.sent;
  19831. model.company = appProperties.company;
  19832. model.manager = appProperties.manager;
  19833. return _context12.abrupt("break", 123);
  19834. case 72:
  19835. coreXform = new CoreXform();
  19836. _context12.next = 75;
  19837. return coreXform.parseStream(stream);
  19838. case 75:
  19839. coreProperties = _context12.sent;
  19840. Object.assign(model, coreProperties);
  19841. return _context12.abrupt("break", 123);
  19842. case 78:
  19843. match = entryName.match(/xl\/worksheets\/sheet(\d+)[.]xml/);
  19844. if (!match) {
  19845. _context12.next = 83;
  19846. break;
  19847. }
  19848. _context12.next = 82;
  19849. return this._processWorksheetEntry(stream, model, match[1], options, entryName);
  19850. case 82:
  19851. return _context12.abrupt("break", 123);
  19852. case 83:
  19853. match = entryName.match(/xl\/worksheets\/_rels\/sheet(\d+)[.]xml.rels/);
  19854. if (!match) {
  19855. _context12.next = 88;
  19856. break;
  19857. }
  19858. _context12.next = 87;
  19859. return this._processWorksheetRelsEntry(stream, model, match[1]);
  19860. case 87:
  19861. return _context12.abrupt("break", 123);
  19862. case 88:
  19863. match = entryName.match(/xl\/theme\/([a-zA-Z0-9]+)[.]xml/);
  19864. if (!match) {
  19865. _context12.next = 93;
  19866. break;
  19867. }
  19868. _context12.next = 92;
  19869. return this._processThemeEntry(stream, model, match[1]);
  19870. case 92:
  19871. return _context12.abrupt("break", 123);
  19872. case 93:
  19873. match = entryName.match(/xl\/media\/([a-zA-Z0-9]+[.][a-zA-Z0-9]{3,4})$/);
  19874. if (!match) {
  19875. _context12.next = 98;
  19876. break;
  19877. }
  19878. _context12.next = 97;
  19879. return this._processMediaEntry(stream, model, match[1]);
  19880. case 97:
  19881. return _context12.abrupt("break", 123);
  19882. case 98:
  19883. match = entryName.match(/xl\/drawings\/([a-zA-Z0-9]+)[.]xml/);
  19884. if (!match) {
  19885. _context12.next = 103;
  19886. break;
  19887. }
  19888. _context12.next = 102;
  19889. return this._processDrawingEntry(stream, model, match[1]);
  19890. case 102:
  19891. return _context12.abrupt("break", 123);
  19892. case 103:
  19893. match = entryName.match(/xl\/(comments\d+)[.]xml/);
  19894. if (!match) {
  19895. _context12.next = 108;
  19896. break;
  19897. }
  19898. _context12.next = 107;
  19899. return this._processCommentEntry(stream, model, match[1]);
  19900. case 107:
  19901. return _context12.abrupt("break", 123);
  19902. case 108:
  19903. match = entryName.match(/xl\/tables\/(table\d+)[.]xml/);
  19904. if (!match) {
  19905. _context12.next = 113;
  19906. break;
  19907. }
  19908. _context12.next = 112;
  19909. return this._processTableEntry(stream, model, match[1]);
  19910. case 112:
  19911. return _context12.abrupt("break", 123);
  19912. case 113:
  19913. match = entryName.match(/xl\/drawings\/_rels\/([a-zA-Z0-9]+)[.]xml[.]rels/);
  19914. if (!match) {
  19915. _context12.next = 118;
  19916. break;
  19917. }
  19918. _context12.next = 117;
  19919. return this._processDrawingRelsEntry(stream, model, match[1]);
  19920. case 117:
  19921. return _context12.abrupt("break", 123);
  19922. case 118:
  19923. match = entryName.match(/xl\/drawings\/(vmlDrawing\d+)[.]vml/);
  19924. if (!match) {
  19925. _context12.next = 123;
  19926. break;
  19927. }
  19928. _context12.next = 122;
  19929. return this._processVmlDrawingEntry(stream, model, match[1]);
  19930. case 122:
  19931. return _context12.abrupt("break", 123);
  19932. case 123:
  19933. _i++;
  19934. _context12.next = 6;
  19935. break;
  19936. case 126:
  19937. this.reconcile(model, options); // apply model
  19938. this.workbook.model = model;
  19939. return _context12.abrupt("return", this.workbook);
  19940. case 129:
  19941. case "end":
  19942. return _context12.stop();
  19943. }
  19944. }
  19945. }, _callee12, this);
  19946. }));
  19947. function load(_x34, _x35) {
  19948. return _load.apply(this, arguments);
  19949. }
  19950. return load;
  19951. }() // =========================================================================
  19952. // Write
  19953. }, {
  19954. key: "addMedia",
  19955. value: function () {
  19956. var _addMedia = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee14(zip, model) {
  19957. return regeneratorRuntime.wrap(function _callee14$(_context14) {
  19958. while (1) {
  19959. switch (_context14.prev = _context14.next) {
  19960. case 0:
  19961. _context14.next = 2;
  19962. return Promise.all(model.media.map( /*#__PURE__*/function () {
  19963. var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee13(medium) {
  19964. var filename, data, dataimg64, content;
  19965. return regeneratorRuntime.wrap(function _callee13$(_context13) {
  19966. while (1) {
  19967. switch (_context13.prev = _context13.next) {
  19968. case 0:
  19969. if (!(medium.type === 'image')) {
  19970. _context13.next = 13;
  19971. break;
  19972. }
  19973. filename = "xl/media/".concat(medium.name, ".").concat(medium.extension);
  19974. if (!medium.filename) {
  19975. _context13.next = 7;
  19976. break;
  19977. }
  19978. _context13.next = 5;
  19979. return fsReadFileAsync(medium.filename);
  19980. case 5:
  19981. data = _context13.sent;
  19982. return _context13.abrupt("return", zip.append(data, {
  19983. name: filename
  19984. }));
  19985. case 7:
  19986. if (!medium.buffer) {
  19987. _context13.next = 9;
  19988. break;
  19989. }
  19990. return _context13.abrupt("return", zip.append(medium.buffer, {
  19991. name: filename
  19992. }));
  19993. case 9:
  19994. if (!medium.base64) {
  19995. _context13.next = 13;
  19996. break;
  19997. }
  19998. dataimg64 = medium.base64;
  19999. content = dataimg64.substring(dataimg64.indexOf(',') + 1);
  20000. return _context13.abrupt("return", zip.append(content, {
  20001. name: filename,
  20002. base64: true
  20003. }));
  20004. case 13:
  20005. throw new Error('Unsupported media');
  20006. case 14:
  20007. case "end":
  20008. return _context13.stop();
  20009. }
  20010. }
  20011. }, _callee13);
  20012. }));
  20013. return function (_x38) {
  20014. return _ref.apply(this, arguments);
  20015. };
  20016. }()));
  20017. case 2:
  20018. case "end":
  20019. return _context14.stop();
  20020. }
  20021. }
  20022. }, _callee14);
  20023. }));
  20024. function addMedia(_x36, _x37) {
  20025. return _addMedia.apply(this, arguments);
  20026. }
  20027. return addMedia;
  20028. }()
  20029. }, {
  20030. key: "addDrawings",
  20031. value: function addDrawings(zip, model) {
  20032. var drawingXform = new DrawingXform();
  20033. var relsXform = new RelationshipsXform();
  20034. model.worksheets.forEach(function (worksheet) {
  20035. var drawing = worksheet.drawing;
  20036. if (drawing) {
  20037. drawingXform.prepare(drawing, {});
  20038. var xml = drawingXform.toXml(drawing);
  20039. zip.append(xml, {
  20040. name: "xl/drawings/".concat(drawing.name, ".xml")
  20041. });
  20042. xml = relsXform.toXml(drawing.rels);
  20043. zip.append(xml, {
  20044. name: "xl/drawings/_rels/".concat(drawing.name, ".xml.rels")
  20045. });
  20046. }
  20047. });
  20048. }
  20049. }, {
  20050. key: "addTables",
  20051. value: function addTables(zip, model) {
  20052. var tableXform = new TableXform();
  20053. model.worksheets.forEach(function (worksheet) {
  20054. var tables = worksheet.tables;
  20055. tables.forEach(function (table) {
  20056. tableXform.prepare(table, {});
  20057. var tableXml = tableXform.toXml(table);
  20058. zip.append(tableXml, {
  20059. name: "xl/tables/".concat(table.target)
  20060. });
  20061. });
  20062. });
  20063. }
  20064. }, {
  20065. key: "addContentTypes",
  20066. value: function () {
  20067. var _addContentTypes = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee15(zip, model) {
  20068. var xform, xml;
  20069. return regeneratorRuntime.wrap(function _callee15$(_context15) {
  20070. while (1) {
  20071. switch (_context15.prev = _context15.next) {
  20072. case 0:
  20073. xform = new ContentTypesXform();
  20074. xml = xform.toXml(model);
  20075. zip.append(xml, {
  20076. name: '[Content_Types].xml'
  20077. });
  20078. case 3:
  20079. case "end":
  20080. return _context15.stop();
  20081. }
  20082. }
  20083. }, _callee15);
  20084. }));
  20085. function addContentTypes(_x39, _x40) {
  20086. return _addContentTypes.apply(this, arguments);
  20087. }
  20088. return addContentTypes;
  20089. }()
  20090. }, {
  20091. key: "addApp",
  20092. value: function () {
  20093. var _addApp = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee16(zip, model) {
  20094. var xform, xml;
  20095. return regeneratorRuntime.wrap(function _callee16$(_context16) {
  20096. while (1) {
  20097. switch (_context16.prev = _context16.next) {
  20098. case 0:
  20099. xform = new AppXform();
  20100. xml = xform.toXml(model);
  20101. zip.append(xml, {
  20102. name: 'docProps/app.xml'
  20103. });
  20104. case 3:
  20105. case "end":
  20106. return _context16.stop();
  20107. }
  20108. }
  20109. }, _callee16);
  20110. }));
  20111. function addApp(_x41, _x42) {
  20112. return _addApp.apply(this, arguments);
  20113. }
  20114. return addApp;
  20115. }()
  20116. }, {
  20117. key: "addCore",
  20118. value: function () {
  20119. var _addCore = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee17(zip, model) {
  20120. var coreXform;
  20121. return regeneratorRuntime.wrap(function _callee17$(_context17) {
  20122. while (1) {
  20123. switch (_context17.prev = _context17.next) {
  20124. case 0:
  20125. coreXform = new CoreXform();
  20126. zip.append(coreXform.toXml(model), {
  20127. name: 'docProps/core.xml'
  20128. });
  20129. case 2:
  20130. case "end":
  20131. return _context17.stop();
  20132. }
  20133. }
  20134. }, _callee17);
  20135. }));
  20136. function addCore(_x43, _x44) {
  20137. return _addCore.apply(this, arguments);
  20138. }
  20139. return addCore;
  20140. }()
  20141. }, {
  20142. key: "addThemes",
  20143. value: function () {
  20144. var _addThemes = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee18(zip, model) {
  20145. var themes;
  20146. return regeneratorRuntime.wrap(function _callee18$(_context18) {
  20147. while (1) {
  20148. switch (_context18.prev = _context18.next) {
  20149. case 0:
  20150. themes = model.themes || {
  20151. theme1: theme1Xml
  20152. };
  20153. Object.keys(themes).forEach(function (name) {
  20154. var xml = themes[name];
  20155. var path = "xl/theme/".concat(name, ".xml");
  20156. zip.append(xml, {
  20157. name: path
  20158. });
  20159. });
  20160. case 2:
  20161. case "end":
  20162. return _context18.stop();
  20163. }
  20164. }
  20165. }, _callee18);
  20166. }));
  20167. function addThemes(_x45, _x46) {
  20168. return _addThemes.apply(this, arguments);
  20169. }
  20170. return addThemes;
  20171. }()
  20172. }, {
  20173. key: "addOfficeRels",
  20174. value: function () {
  20175. var _addOfficeRels = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee19(zip) {
  20176. var xform, xml;
  20177. return regeneratorRuntime.wrap(function _callee19$(_context19) {
  20178. while (1) {
  20179. switch (_context19.prev = _context19.next) {
  20180. case 0:
  20181. xform = new RelationshipsXform();
  20182. xml = xform.toXml([{
  20183. Id: 'rId1',
  20184. Type: XLSX.RelType.OfficeDocument,
  20185. Target: 'xl/workbook.xml'
  20186. }, {
  20187. Id: 'rId2',
  20188. Type: XLSX.RelType.CoreProperties,
  20189. Target: 'docProps/core.xml'
  20190. }, {
  20191. Id: 'rId3',
  20192. Type: XLSX.RelType.ExtenderProperties,
  20193. Target: 'docProps/app.xml'
  20194. }]);
  20195. zip.append(xml, {
  20196. name: '_rels/.rels'
  20197. });
  20198. case 3:
  20199. case "end":
  20200. return _context19.stop();
  20201. }
  20202. }
  20203. }, _callee19);
  20204. }));
  20205. function addOfficeRels(_x47) {
  20206. return _addOfficeRels.apply(this, arguments);
  20207. }
  20208. return addOfficeRels;
  20209. }()
  20210. }, {
  20211. key: "addWorkbookRels",
  20212. value: function () {
  20213. var _addWorkbookRels = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee20(zip, model) {
  20214. var count, relationships, xform, xml;
  20215. return regeneratorRuntime.wrap(function _callee20$(_context20) {
  20216. while (1) {
  20217. switch (_context20.prev = _context20.next) {
  20218. case 0:
  20219. count = 1;
  20220. relationships = [{
  20221. Id: "rId".concat(count++),
  20222. Type: XLSX.RelType.Styles,
  20223. Target: 'styles.xml'
  20224. }, {
  20225. Id: "rId".concat(count++),
  20226. Type: XLSX.RelType.Theme,
  20227. Target: 'theme/theme1.xml'
  20228. }];
  20229. if (model.sharedStrings.count) {
  20230. relationships.push({
  20231. Id: "rId".concat(count++),
  20232. Type: XLSX.RelType.SharedStrings,
  20233. Target: 'sharedStrings.xml'
  20234. });
  20235. }
  20236. model.worksheets.forEach(function (worksheet) {
  20237. worksheet.rId = "rId".concat(count++);
  20238. relationships.push({
  20239. Id: worksheet.rId,
  20240. Type: XLSX.RelType.Worksheet,
  20241. Target: "worksheets/sheet".concat(worksheet.id, ".xml")
  20242. });
  20243. });
  20244. xform = new RelationshipsXform();
  20245. xml = xform.toXml(relationships);
  20246. zip.append(xml, {
  20247. name: 'xl/_rels/workbook.xml.rels'
  20248. });
  20249. case 7:
  20250. case "end":
  20251. return _context20.stop();
  20252. }
  20253. }
  20254. }, _callee20);
  20255. }));
  20256. function addWorkbookRels(_x48, _x49) {
  20257. return _addWorkbookRels.apply(this, arguments);
  20258. }
  20259. return addWorkbookRels;
  20260. }()
  20261. }, {
  20262. key: "addSharedStrings",
  20263. value: function () {
  20264. var _addSharedStrings = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee21(zip, model) {
  20265. return regeneratorRuntime.wrap(function _callee21$(_context21) {
  20266. while (1) {
  20267. switch (_context21.prev = _context21.next) {
  20268. case 0:
  20269. if (model.sharedStrings && model.sharedStrings.count) {
  20270. zip.append(model.sharedStrings.xml, {
  20271. name: 'xl/sharedStrings.xml'
  20272. });
  20273. }
  20274. case 1:
  20275. case "end":
  20276. return _context21.stop();
  20277. }
  20278. }
  20279. }, _callee21);
  20280. }));
  20281. function addSharedStrings(_x50, _x51) {
  20282. return _addSharedStrings.apply(this, arguments);
  20283. }
  20284. return addSharedStrings;
  20285. }()
  20286. }, {
  20287. key: "addStyles",
  20288. value: function () {
  20289. var _addStyles = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee22(zip, model) {
  20290. var xml;
  20291. return regeneratorRuntime.wrap(function _callee22$(_context22) {
  20292. while (1) {
  20293. switch (_context22.prev = _context22.next) {
  20294. case 0:
  20295. xml = model.styles.xml;
  20296. if (xml) {
  20297. zip.append(xml, {
  20298. name: 'xl/styles.xml'
  20299. });
  20300. }
  20301. case 2:
  20302. case "end":
  20303. return _context22.stop();
  20304. }
  20305. }
  20306. }, _callee22);
  20307. }));
  20308. function addStyles(_x52, _x53) {
  20309. return _addStyles.apply(this, arguments);
  20310. }
  20311. return addStyles;
  20312. }()
  20313. }, {
  20314. key: "addWorkbook",
  20315. value: function () {
  20316. var _addWorkbook = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee23(zip, model) {
  20317. var xform;
  20318. return regeneratorRuntime.wrap(function _callee23$(_context23) {
  20319. while (1) {
  20320. switch (_context23.prev = _context23.next) {
  20321. case 0:
  20322. xform = new WorkbookXform();
  20323. zip.append(xform.toXml(model), {
  20324. name: 'xl/workbook.xml'
  20325. });
  20326. case 2:
  20327. case "end":
  20328. return _context23.stop();
  20329. }
  20330. }
  20331. }, _callee23);
  20332. }));
  20333. function addWorkbook(_x54, _x55) {
  20334. return _addWorkbook.apply(this, arguments);
  20335. }
  20336. return addWorkbook;
  20337. }()
  20338. }, {
  20339. key: "addWorksheets",
  20340. value: function () {
  20341. var _addWorksheets = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee24(zip, model) {
  20342. var worksheetXform, relationshipsXform, commentsXform, vmlNotesXform;
  20343. return regeneratorRuntime.wrap(function _callee24$(_context24) {
  20344. while (1) {
  20345. switch (_context24.prev = _context24.next) {
  20346. case 0:
  20347. // preparation phase
  20348. worksheetXform = new WorksheetXform();
  20349. relationshipsXform = new RelationshipsXform();
  20350. commentsXform = new CommentsXform();
  20351. vmlNotesXform = new VmlNotesXform(); // write sheets
  20352. model.worksheets.forEach(function (worksheet) {
  20353. var xmlStream = new XmlStream();
  20354. worksheetXform.render(xmlStream, worksheet);
  20355. zip.append(xmlStream.xml, {
  20356. name: "xl/worksheets/sheet".concat(worksheet.id, ".xml")
  20357. });
  20358. if (worksheet.rels && worksheet.rels.length) {
  20359. xmlStream = new XmlStream();
  20360. relationshipsXform.render(xmlStream, worksheet.rels);
  20361. zip.append(xmlStream.xml, {
  20362. name: "xl/worksheets/_rels/sheet".concat(worksheet.id, ".xml.rels")
  20363. });
  20364. }
  20365. if (worksheet.comments.length > 0) {
  20366. xmlStream = new XmlStream();
  20367. commentsXform.render(xmlStream, worksheet);
  20368. zip.append(xmlStream.xml, {
  20369. name: "xl/comments".concat(worksheet.id, ".xml")
  20370. });
  20371. xmlStream = new XmlStream();
  20372. vmlNotesXform.render(xmlStream, worksheet);
  20373. zip.append(xmlStream.xml, {
  20374. name: "xl/drawings/vmlDrawing".concat(worksheet.id, ".vml")
  20375. });
  20376. }
  20377. });
  20378. case 5:
  20379. case "end":
  20380. return _context24.stop();
  20381. }
  20382. }
  20383. }, _callee24);
  20384. }));
  20385. function addWorksheets(_x56, _x57) {
  20386. return _addWorksheets.apply(this, arguments);
  20387. }
  20388. return addWorksheets;
  20389. }()
  20390. }, {
  20391. key: "_finalize",
  20392. value: function _finalize(zip) {
  20393. var _this = this;
  20394. return new Promise(function (resolve, reject) {
  20395. zip.on('finish', function () {
  20396. resolve(_this);
  20397. });
  20398. zip.on('error', reject);
  20399. zip.finalize();
  20400. });
  20401. }
  20402. }, {
  20403. key: "prepareModel",
  20404. value: function prepareModel(model, options) {
  20405. // ensure following properties have sane values
  20406. model.creator = model.creator || 'ExcelJS';
  20407. model.lastModifiedBy = model.lastModifiedBy || 'ExcelJS';
  20408. model.created = model.created || new Date();
  20409. model.modified = model.modified || new Date();
  20410. model.useSharedStrings = options.useSharedStrings !== undefined ? options.useSharedStrings : true;
  20411. model.useStyles = options.useStyles !== undefined ? options.useStyles : true; // Manage the shared strings
  20412. model.sharedStrings = new SharedStringsXform(); // add a style manager to handle cell formats, fonts, etc.
  20413. model.styles = model.useStyles ? new StylesXform(true) : new StylesXform.Mock(); // prepare all of the things before the render
  20414. var workbookXform = new WorkbookXform();
  20415. var worksheetXform = new WorksheetXform();
  20416. workbookXform.prepare(model);
  20417. var worksheetOptions = {
  20418. sharedStrings: model.sharedStrings,
  20419. styles: model.styles,
  20420. date1904: model.properties.date1904,
  20421. drawingsCount: 0,
  20422. media: model.media
  20423. };
  20424. worksheetOptions.drawings = model.drawings = [];
  20425. worksheetOptions.commentRefs = model.commentRefs = [];
  20426. var tableCount = 0;
  20427. model.tables = [];
  20428. model.worksheets.forEach(function (worksheet) {
  20429. // assign unique filenames to tables
  20430. worksheet.tables.forEach(function (table) {
  20431. tableCount++;
  20432. table.target = "table".concat(tableCount, ".xml");
  20433. table.id = tableCount;
  20434. model.tables.push(table);
  20435. });
  20436. worksheetXform.prepare(worksheet, worksheetOptions);
  20437. }); // TODO: workbook drawing list
  20438. }
  20439. }, {
  20440. key: "write",
  20441. value: function () {
  20442. var _write = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee25(stream, options) {
  20443. var model, zip;
  20444. return regeneratorRuntime.wrap(function _callee25$(_context25) {
  20445. while (1) {
  20446. switch (_context25.prev = _context25.next) {
  20447. case 0:
  20448. options = options || {};
  20449. model = this.workbook.model;
  20450. zip = new ZipStream.ZipWriter(options.zip);
  20451. zip.pipe(stream);
  20452. this.prepareModel(model, options); // render
  20453. _context25.next = 7;
  20454. return this.addContentTypes(zip, model);
  20455. case 7:
  20456. _context25.next = 9;
  20457. return this.addOfficeRels(zip, model);
  20458. case 9:
  20459. _context25.next = 11;
  20460. return this.addWorkbookRels(zip, model);
  20461. case 11:
  20462. _context25.next = 13;
  20463. return this.addWorksheets(zip, model);
  20464. case 13:
  20465. _context25.next = 15;
  20466. return this.addSharedStrings(zip, model);
  20467. case 15:
  20468. _context25.next = 17;
  20469. return this.addDrawings(zip, model);
  20470. case 17:
  20471. _context25.next = 19;
  20472. return this.addTables(zip, model);
  20473. case 19:
  20474. _context25.next = 21;
  20475. return Promise.all([this.addThemes(zip, model), this.addStyles(zip, model)]);
  20476. case 21:
  20477. _context25.next = 23;
  20478. return this.addMedia(zip, model);
  20479. case 23:
  20480. _context25.next = 25;
  20481. return Promise.all([this.addApp(zip, model), this.addCore(zip, model)]);
  20482. case 25:
  20483. _context25.next = 27;
  20484. return this.addWorkbook(zip, model);
  20485. case 27:
  20486. return _context25.abrupt("return", this._finalize(zip));
  20487. case 28:
  20488. case "end":
  20489. return _context25.stop();
  20490. }
  20491. }
  20492. }, _callee25, this);
  20493. }));
  20494. function write(_x58, _x59) {
  20495. return _write.apply(this, arguments);
  20496. }
  20497. return write;
  20498. }()
  20499. }, {
  20500. key: "writeFile",
  20501. value: function writeFile(filename, options) {
  20502. var _this2 = this;
  20503. var stream = fs.createWriteStream(filename);
  20504. return new Promise(function (resolve, reject) {
  20505. stream.on('finish', function () {
  20506. resolve();
  20507. });
  20508. stream.on('error', function (error) {
  20509. reject(error);
  20510. });
  20511. _this2.write(stream, options).then(function () {
  20512. stream.end();
  20513. });
  20514. });
  20515. }
  20516. }, {
  20517. key: "writeBuffer",
  20518. value: function () {
  20519. var _writeBuffer = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee26(options) {
  20520. var stream;
  20521. return regeneratorRuntime.wrap(function _callee26$(_context26) {
  20522. while (1) {
  20523. switch (_context26.prev = _context26.next) {
  20524. case 0:
  20525. stream = new StreamBuf();
  20526. _context26.next = 3;
  20527. return this.write(stream, options);
  20528. case 3:
  20529. return _context26.abrupt("return", stream.read());
  20530. case 4:
  20531. case "end":
  20532. return _context26.stop();
  20533. }
  20534. }
  20535. }, _callee26, this);
  20536. }));
  20537. function writeBuffer(_x60) {
  20538. return _writeBuffer.apply(this, arguments);
  20539. }
  20540. return writeBuffer;
  20541. }()
  20542. }]);
  20543. return XLSX;
  20544. }();
  20545. XLSX.RelType = require('./rel-type');
  20546. module.exports = XLSX;
  20547. }).call(this,require('_process'),require("buffer").Buffer)
  20548. },{"../utils/browser-buffer-decode":16,"../utils/stream-buf":23,"../utils/utils":26,"../utils/xml-stream":27,"../utils/zip-stream":28,"./rel-type":30,"./xform/book/workbook-xform":37,"./xform/comment/comments-xform":39,"./xform/comment/vml-notes-xform":44,"./xform/core/app-xform":50,"./xform/core/content-types-xform":51,"./xform/core/core-xform":52,"./xform/core/relationships-xform":54,"./xform/drawing/drawing-xform":61,"./xform/sheet/worksheet-xform":114,"./xform/strings/shared-strings-xform":123,"./xform/style/styles-xform":134,"./xform/table/table-xform":140,"./xml/theme1.js":142,"_process":467,"buffer":216,"fs":215,"jszip":399,"readable-stream":491}],142:[function(require,module,exports){
  20549. "use strict";
  20550. /* eslint-disable */
  20551. 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>';
  20552. },{}],143:[function(require,module,exports){
  20553. (function (Buffer){
  20554. "use strict";
  20555. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  20556. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  20557. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  20558. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  20559. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  20560. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  20561. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  20562. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  20563. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  20564. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  20565. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  20566. Object.defineProperty(exports, "__esModule", {
  20567. value: true
  20568. });
  20569. exports.CsvFormatterStream = void 0;
  20570. var stream_1 = require("stream");
  20571. var formatter_1 = require("./formatter");
  20572. var CsvFormatterStream = /*#__PURE__*/function (_stream_1$Transform) {
  20573. _inherits(CsvFormatterStream, _stream_1$Transform);
  20574. var _super = _createSuper(CsvFormatterStream);
  20575. function CsvFormatterStream(formatterOptions) {
  20576. var _this;
  20577. _classCallCheck(this, CsvFormatterStream);
  20578. _this = _super.call(this, {
  20579. writableObjectMode: formatterOptions.objectMode
  20580. });
  20581. _this.hasWrittenBOM = false;
  20582. _this.formatterOptions = formatterOptions;
  20583. _this.rowFormatter = new formatter_1.RowFormatter(formatterOptions); // if writeBOM is false then set to true
  20584. // if writeBOM is true then set to false by default so it is written out
  20585. _this.hasWrittenBOM = !formatterOptions.writeBOM;
  20586. return _this;
  20587. }
  20588. _createClass(CsvFormatterStream, [{
  20589. key: "transform",
  20590. value: function transform(transformFunction) {
  20591. this.rowFormatter.rowTransform = transformFunction;
  20592. return this;
  20593. }
  20594. }, {
  20595. key: "_transform",
  20596. value: function _transform(row, encoding, cb) {
  20597. var _this2 = this;
  20598. var cbCalled = false;
  20599. try {
  20600. if (!this.hasWrittenBOM) {
  20601. this.push(this.formatterOptions.BOM);
  20602. this.hasWrittenBOM = true;
  20603. }
  20604. this.rowFormatter.format(row, function (err, rows) {
  20605. if (err) {
  20606. cbCalled = true;
  20607. return cb(err);
  20608. }
  20609. if (rows) {
  20610. rows.forEach(function (r) {
  20611. _this2.push(Buffer.from(r, 'utf8'));
  20612. });
  20613. }
  20614. cbCalled = true;
  20615. return cb();
  20616. });
  20617. } catch (e) {
  20618. if (cbCalled) {
  20619. throw e;
  20620. }
  20621. cb(e);
  20622. }
  20623. }
  20624. }, {
  20625. key: "_flush",
  20626. value: function _flush(cb) {
  20627. var _this3 = this;
  20628. this.rowFormatter.finish(function (err, rows) {
  20629. if (err) {
  20630. return cb(err);
  20631. }
  20632. if (rows) {
  20633. rows.forEach(function (r) {
  20634. _this3.push(Buffer.from(r, 'utf8'));
  20635. });
  20636. }
  20637. return cb();
  20638. });
  20639. }
  20640. }]);
  20641. return CsvFormatterStream;
  20642. }(stream_1.Transform);
  20643. exports.CsvFormatterStream = CsvFormatterStream;
  20644. }).call(this,require("buffer").Buffer)
  20645. },{"./formatter":147,"buffer":216,"stream":506}],144:[function(require,module,exports){
  20646. "use strict";
  20647. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  20648. Object.defineProperty(exports, "__esModule", {
  20649. value: true
  20650. });
  20651. exports.FormatterOptions = void 0;
  20652. var FormatterOptions = function FormatterOptions() {
  20653. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  20654. _classCallCheck(this, FormatterOptions);
  20655. var _a;
  20656. this.objectMode = true;
  20657. this.delimiter = ',';
  20658. this.rowDelimiter = '\n';
  20659. this.quote = '"';
  20660. this.escape = this.quote;
  20661. this.quoteColumns = false;
  20662. this.quoteHeaders = this.quoteColumns;
  20663. this.headers = null;
  20664. this.includeEndRowDelimiter = false;
  20665. this.writeBOM = false;
  20666. this.BOM = "\uFEFF";
  20667. this.alwaysWriteHeaders = false;
  20668. Object.assign(this, opts || {});
  20669. if (typeof (opts === null || opts === void 0 ? void 0 : opts.quoteHeaders) === 'undefined') {
  20670. this.quoteHeaders = this.quoteColumns;
  20671. }
  20672. if ((opts === null || opts === void 0 ? void 0 : opts.quote) === true) {
  20673. this.quote = '"';
  20674. } else if ((opts === null || opts === void 0 ? void 0 : opts.quote) === false) {
  20675. this.quote = '';
  20676. }
  20677. if (typeof (opts === null || opts === void 0 ? void 0 : opts.escape) !== 'string') {
  20678. this.escape = this.quote;
  20679. }
  20680. this.shouldWriteHeaders = !!this.headers && ((_a = opts.writeHeaders) !== null && _a !== void 0 ? _a : true);
  20681. this.headers = Array.isArray(this.headers) ? this.headers : null;
  20682. this.escapedQuote = "".concat(this.escape).concat(this.quote);
  20683. };
  20684. exports.FormatterOptions = FormatterOptions;
  20685. },{}],145:[function(require,module,exports){
  20686. "use strict";
  20687. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  20688. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  20689. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  20690. var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
  20691. return mod && mod.__esModule ? mod : {
  20692. "default": mod
  20693. };
  20694. };
  20695. Object.defineProperty(exports, "__esModule", {
  20696. value: true
  20697. });
  20698. exports.FieldFormatter = void 0;
  20699. var lodash_isboolean_1 = __importDefault(require("lodash.isboolean"));
  20700. var lodash_isnil_1 = __importDefault(require("lodash.isnil"));
  20701. var lodash_escaperegexp_1 = __importDefault(require("lodash.escaperegexp"));
  20702. var FieldFormatter = /*#__PURE__*/function () {
  20703. function FieldFormatter(formatterOptions) {
  20704. _classCallCheck(this, FieldFormatter);
  20705. this._headers = null;
  20706. this.formatterOptions = formatterOptions;
  20707. if (formatterOptions.headers !== null) {
  20708. this.headers = formatterOptions.headers;
  20709. }
  20710. this.REPLACE_REGEXP = new RegExp(formatterOptions.quote, 'g');
  20711. var escapePattern = "[".concat(formatterOptions.delimiter).concat(lodash_escaperegexp_1.default(formatterOptions.rowDelimiter), "|\r|\n']");
  20712. this.ESCAPE_REGEXP = new RegExp(escapePattern);
  20713. }
  20714. _createClass(FieldFormatter, [{
  20715. key: "shouldQuote",
  20716. value: function shouldQuote(fieldIndex, isHeader) {
  20717. var quoteConfig = isHeader ? this.formatterOptions.quoteHeaders : this.formatterOptions.quoteColumns;
  20718. if (lodash_isboolean_1.default(quoteConfig)) {
  20719. return quoteConfig;
  20720. }
  20721. if (Array.isArray(quoteConfig)) {
  20722. return quoteConfig[fieldIndex];
  20723. }
  20724. if (this._headers !== null) {
  20725. return quoteConfig[this._headers[fieldIndex]];
  20726. }
  20727. return false;
  20728. }
  20729. }, {
  20730. key: "format",
  20731. value: function format(field, fieldIndex, isHeader) {
  20732. var preparedField = "".concat(lodash_isnil_1.default(field) ? '' : field).replace(/\0/g, '');
  20733. var formatterOptions = this.formatterOptions;
  20734. if (formatterOptions.quote !== '') {
  20735. var shouldEscape = preparedField.indexOf(formatterOptions.quote) !== -1;
  20736. if (shouldEscape) {
  20737. return this.quoteField(preparedField.replace(this.REPLACE_REGEXP, formatterOptions.escapedQuote));
  20738. }
  20739. }
  20740. var hasEscapeCharacters = preparedField.search(this.ESCAPE_REGEXP) !== -1;
  20741. if (hasEscapeCharacters || this.shouldQuote(fieldIndex, isHeader)) {
  20742. return this.quoteField(preparedField);
  20743. }
  20744. return preparedField;
  20745. }
  20746. }, {
  20747. key: "quoteField",
  20748. value: function quoteField(field) {
  20749. var quote = this.formatterOptions.quote;
  20750. return "".concat(quote).concat(field).concat(quote);
  20751. }
  20752. }, {
  20753. key: "headers",
  20754. set: function set(headers) {
  20755. this._headers = headers;
  20756. }
  20757. }]);
  20758. return FieldFormatter;
  20759. }();
  20760. exports.FieldFormatter = FieldFormatter;
  20761. },{"lodash.escaperegexp":426,"lodash.isboolean":428,"lodash.isnil":431}],146:[function(require,module,exports){
  20762. "use strict";
  20763. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  20764. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  20765. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  20766. var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
  20767. return mod && mod.__esModule ? mod : {
  20768. "default": mod
  20769. };
  20770. };
  20771. Object.defineProperty(exports, "__esModule", {
  20772. value: true
  20773. });
  20774. exports.RowFormatter = void 0;
  20775. var lodash_isfunction_1 = __importDefault(require("lodash.isfunction"));
  20776. var lodash_isequal_1 = __importDefault(require("lodash.isequal"));
  20777. var FieldFormatter_1 = require("./FieldFormatter");
  20778. var types_1 = require("../types");
  20779. var RowFormatter = /*#__PURE__*/function () {
  20780. function RowFormatter(formatterOptions) {
  20781. _classCallCheck(this, RowFormatter);
  20782. this.rowCount = 0;
  20783. this.formatterOptions = formatterOptions;
  20784. this.fieldFormatter = new FieldFormatter_1.FieldFormatter(formatterOptions);
  20785. this.headers = formatterOptions.headers;
  20786. this.shouldWriteHeaders = formatterOptions.shouldWriteHeaders;
  20787. this.hasWrittenHeaders = false;
  20788. if (this.headers !== null) {
  20789. this.fieldFormatter.headers = this.headers;
  20790. }
  20791. if (formatterOptions.transform) {
  20792. this.rowTransform = formatterOptions.transform;
  20793. }
  20794. }
  20795. _createClass(RowFormatter, [{
  20796. key: "format",
  20797. value: function format(row, cb) {
  20798. var _this = this;
  20799. this.callTransformer(row, function (err, transformedRow) {
  20800. if (err) {
  20801. return cb(err);
  20802. }
  20803. if (!row) {
  20804. return cb(null);
  20805. }
  20806. var rows = [];
  20807. if (transformedRow) {
  20808. var _this$checkHeaders = _this.checkHeaders(transformedRow),
  20809. shouldFormatColumns = _this$checkHeaders.shouldFormatColumns,
  20810. headers = _this$checkHeaders.headers;
  20811. if (_this.shouldWriteHeaders && headers && !_this.hasWrittenHeaders) {
  20812. rows.push(_this.formatColumns(headers, true));
  20813. _this.hasWrittenHeaders = true;
  20814. }
  20815. if (shouldFormatColumns) {
  20816. var columns = _this.gatherColumns(transformedRow);
  20817. rows.push(_this.formatColumns(columns, false));
  20818. }
  20819. }
  20820. return cb(null, rows);
  20821. });
  20822. }
  20823. }, {
  20824. key: "finish",
  20825. value: function finish(cb) {
  20826. var rows = []; // check if we should write headers and we didnt get any rows
  20827. if (this.formatterOptions.alwaysWriteHeaders && this.rowCount === 0) {
  20828. if (!this.headers) {
  20829. return cb(new Error('`alwaysWriteHeaders` option is set to true but `headers` option not provided.'));
  20830. }
  20831. rows.push(this.formatColumns(this.headers, true));
  20832. }
  20833. if (this.formatterOptions.includeEndRowDelimiter) {
  20834. rows.push(this.formatterOptions.rowDelimiter);
  20835. }
  20836. return cb(null, rows);
  20837. } // check if we need to write header return true if we should also write a row
  20838. // could be false if headers is true and the header row(first item) is passed in
  20839. }, {
  20840. key: "checkHeaders",
  20841. value: function checkHeaders(row) {
  20842. if (this.headers) {
  20843. // either the headers were provided by the user or we have already gathered them.
  20844. return {
  20845. shouldFormatColumns: true,
  20846. headers: this.headers
  20847. };
  20848. }
  20849. var headers = RowFormatter.gatherHeaders(row);
  20850. this.headers = headers;
  20851. this.fieldFormatter.headers = headers;
  20852. if (!this.shouldWriteHeaders) {
  20853. // if we are not supposed to write the headers then
  20854. // always format the columns
  20855. return {
  20856. shouldFormatColumns: true,
  20857. headers: null
  20858. };
  20859. } // if the row is equal to headers dont format
  20860. return {
  20861. shouldFormatColumns: !lodash_isequal_1.default(headers, row),
  20862. headers: headers
  20863. };
  20864. } // todo change this method to unknown[]
  20865. }, {
  20866. key: "gatherColumns",
  20867. value: function gatherColumns(row) {
  20868. if (this.headers === null) {
  20869. throw new Error('Headers is currently null');
  20870. }
  20871. if (!Array.isArray(row)) {
  20872. return this.headers.map(function (header) {
  20873. return row[header];
  20874. });
  20875. }
  20876. if (RowFormatter.isHashArray(row)) {
  20877. return this.headers.map(function (header, i) {
  20878. var col = row[i];
  20879. if (col) {
  20880. return col[1];
  20881. }
  20882. return '';
  20883. });
  20884. }
  20885. return this.headers.map(function (header, i) {
  20886. return row[i];
  20887. });
  20888. }
  20889. }, {
  20890. key: "callTransformer",
  20891. value: function callTransformer(row, cb) {
  20892. if (!this._rowTransform) {
  20893. return cb(null, row);
  20894. }
  20895. return this._rowTransform(row, cb);
  20896. }
  20897. }, {
  20898. key: "formatColumns",
  20899. value: function formatColumns(columns, isHeadersRow) {
  20900. var _this2 = this;
  20901. var formattedCols = columns.map(function (field, i) {
  20902. return _this2.fieldFormatter.format(field, i, isHeadersRow);
  20903. }).join(this.formatterOptions.delimiter);
  20904. var rowCount = this.rowCount;
  20905. this.rowCount += 1;
  20906. if (rowCount) {
  20907. return [this.formatterOptions.rowDelimiter, formattedCols].join('');
  20908. }
  20909. return formattedCols;
  20910. }
  20911. }, {
  20912. key: "rowTransform",
  20913. set: function set(transformFunction) {
  20914. if (!lodash_isfunction_1.default(transformFunction)) {
  20915. throw new TypeError('The transform should be a function');
  20916. }
  20917. this._rowTransform = RowFormatter.createTransform(transformFunction);
  20918. }
  20919. }], [{
  20920. key: "isHashArray",
  20921. value: function isHashArray(row) {
  20922. if (Array.isArray(row)) {
  20923. return Array.isArray(row[0]) && row[0].length === 2;
  20924. }
  20925. return false;
  20926. } // get headers from a row item
  20927. }, {
  20928. key: "gatherHeaders",
  20929. value: function gatherHeaders(row) {
  20930. if (RowFormatter.isHashArray(row)) {
  20931. // lets assume a multi-dimesional array with item 0 being the header
  20932. return row.map(function (it) {
  20933. return it[0];
  20934. });
  20935. }
  20936. if (Array.isArray(row)) {
  20937. return row;
  20938. }
  20939. return Object.keys(row);
  20940. }
  20941. }, {
  20942. key: "createTransform",
  20943. value: function createTransform(transformFunction) {
  20944. if (types_1.isSyncTransform(transformFunction)) {
  20945. return function (row, cb) {
  20946. var transformedRow = null;
  20947. try {
  20948. transformedRow = transformFunction(row);
  20949. } catch (e) {
  20950. return cb(e);
  20951. }
  20952. return cb(null, transformedRow);
  20953. };
  20954. }
  20955. return function (row, cb) {
  20956. transformFunction(row, cb);
  20957. };
  20958. }
  20959. }]);
  20960. return RowFormatter;
  20961. }();
  20962. exports.RowFormatter = RowFormatter;
  20963. },{"../types":149,"./FieldFormatter":145,"lodash.isequal":429,"lodash.isfunction":430}],147:[function(require,module,exports){
  20964. "use strict";
  20965. Object.defineProperty(exports, "__esModule", {
  20966. value: true
  20967. });
  20968. var RowFormatter_1 = require("./RowFormatter");
  20969. Object.defineProperty(exports, "RowFormatter", {
  20970. enumerable: true,
  20971. get: function get() {
  20972. return RowFormatter_1.RowFormatter;
  20973. }
  20974. });
  20975. var FieldFormatter_1 = require("./FieldFormatter");
  20976. Object.defineProperty(exports, "FieldFormatter", {
  20977. enumerable: true,
  20978. get: function get() {
  20979. return FieldFormatter_1.FieldFormatter;
  20980. }
  20981. });
  20982. },{"./FieldFormatter":145,"./RowFormatter":146}],148:[function(require,module,exports){
  20983. (function (Buffer){
  20984. "use strict";
  20985. var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
  20986. if (k2 === undefined) k2 = k;
  20987. Object.defineProperty(o, k2, {
  20988. enumerable: true,
  20989. get: function get() {
  20990. return m[k];
  20991. }
  20992. });
  20993. } : function (o, m, k, k2) {
  20994. if (k2 === undefined) k2 = k;
  20995. o[k2] = m[k];
  20996. });
  20997. var __setModuleDefault = void 0 && (void 0).__setModuleDefault || (Object.create ? function (o, v) {
  20998. Object.defineProperty(o, "default", {
  20999. enumerable: true,
  21000. value: v
  21001. });
  21002. } : function (o, v) {
  21003. o["default"] = v;
  21004. });
  21005. var __importStar = void 0 && (void 0).__importStar || function (mod) {
  21006. if (mod && mod.__esModule) return mod;
  21007. var result = {};
  21008. if (mod != null) for (var k in mod) {
  21009. if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  21010. }
  21011. __setModuleDefault(result, mod);
  21012. return result;
  21013. };
  21014. var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
  21015. for (var p in m) {
  21016. if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
  21017. }
  21018. };
  21019. Object.defineProperty(exports, "__esModule", {
  21020. value: true
  21021. });
  21022. exports.writeToPath = exports.writeToString = exports.writeToBuffer = exports.writeToStream = exports.write = exports.format = void 0;
  21023. var util_1 = require("util");
  21024. var stream_1 = require("stream");
  21025. var fs = __importStar(require("fs"));
  21026. var FormatterOptions_1 = require("./FormatterOptions");
  21027. var CsvFormatterStream_1 = require("./CsvFormatterStream");
  21028. __exportStar(require("./types"), exports);
  21029. var CsvFormatterStream_2 = require("./CsvFormatterStream");
  21030. Object.defineProperty(exports, "CsvFormatterStream", {
  21031. enumerable: true,
  21032. get: function get() {
  21033. return CsvFormatterStream_2.CsvFormatterStream;
  21034. }
  21035. });
  21036. var FormatterOptions_2 = require("./FormatterOptions");
  21037. Object.defineProperty(exports, "FormatterOptions", {
  21038. enumerable: true,
  21039. get: function get() {
  21040. return FormatterOptions_2.FormatterOptions;
  21041. }
  21042. });
  21043. exports.format = function (options) {
  21044. return new CsvFormatterStream_1.CsvFormatterStream(new FormatterOptions_1.FormatterOptions(options));
  21045. };
  21046. exports.write = function (rows, options) {
  21047. var csvStream = exports.format(options);
  21048. var promiseWrite = util_1.promisify(function (row, cb) {
  21049. csvStream.write(row, undefined, cb);
  21050. });
  21051. rows.reduce(function (prev, row) {
  21052. return prev.then(function () {
  21053. return promiseWrite(row);
  21054. });
  21055. }, Promise.resolve()).then(function () {
  21056. return csvStream.end();
  21057. }).catch(function (err) {
  21058. csvStream.emit('error', err);
  21059. });
  21060. return csvStream;
  21061. };
  21062. exports.writeToStream = function (ws, rows, options) {
  21063. return exports.write(rows, options).pipe(ws);
  21064. };
  21065. exports.writeToBuffer = function (rows) {
  21066. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  21067. var buffers = [];
  21068. var ws = new stream_1.Writable({
  21069. write: function write(data, enc, writeCb) {
  21070. buffers.push(data);
  21071. writeCb();
  21072. }
  21073. });
  21074. return new Promise(function (res, rej) {
  21075. ws.on('error', rej).on('finish', function () {
  21076. return res(Buffer.concat(buffers));
  21077. });
  21078. exports.write(rows, opts).pipe(ws);
  21079. });
  21080. };
  21081. exports.writeToString = function (rows, options) {
  21082. return exports.writeToBuffer(rows, options).then(function (buffer) {
  21083. return buffer.toString();
  21084. });
  21085. };
  21086. exports.writeToPath = function (path, rows, options) {
  21087. var stream = fs.createWriteStream(path, {
  21088. encoding: 'utf8'
  21089. });
  21090. return exports.write(rows, options).pipe(stream);
  21091. };
  21092. }).call(this,require("buffer").Buffer)
  21093. },{"./CsvFormatterStream":143,"./FormatterOptions":144,"./types":149,"buffer":216,"fs":215,"stream":506,"util":525}],149:[function(require,module,exports){
  21094. "use strict";
  21095. /* eslint-disable @typescript-eslint/no-explicit-any */
  21096. Object.defineProperty(exports, "__esModule", {
  21097. value: true
  21098. });
  21099. exports.isSyncTransform = void 0;
  21100. exports.isSyncTransform = function (transform) {
  21101. return transform.length === 1;
  21102. };
  21103. },{}],150:[function(require,module,exports){
  21104. (function (setImmediate){
  21105. "use strict";
  21106. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  21107. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21108. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  21109. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  21110. function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
  21111. function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
  21112. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  21113. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  21114. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  21115. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  21116. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  21117. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  21118. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  21119. Object.defineProperty(exports, "__esModule", {
  21120. value: true
  21121. });
  21122. exports.CsvParserStream = void 0;
  21123. var string_decoder_1 = require("string_decoder");
  21124. var stream_1 = require("stream");
  21125. var transforms_1 = require("./transforms");
  21126. var parser_1 = require("./parser");
  21127. var CsvParserStream = /*#__PURE__*/function (_stream_1$Transform) {
  21128. _inherits(CsvParserStream, _stream_1$Transform);
  21129. var _super = _createSuper(CsvParserStream);
  21130. function CsvParserStream(parserOptions) {
  21131. var _this;
  21132. _classCallCheck(this, CsvParserStream);
  21133. _this = _super.call(this, {
  21134. objectMode: parserOptions.objectMode
  21135. });
  21136. _this.lines = '';
  21137. _this.rowCount = 0;
  21138. _this.parsedRowCount = 0;
  21139. _this.parsedLineCount = 0;
  21140. _this.endEmitted = false;
  21141. _this.headersEmitted = false;
  21142. _this.parserOptions = parserOptions;
  21143. _this.parser = new parser_1.Parser(parserOptions);
  21144. _this.headerTransformer = new transforms_1.HeaderTransformer(parserOptions);
  21145. _this.decoder = new string_decoder_1.StringDecoder(parserOptions.encoding);
  21146. _this.rowTransformerValidator = new transforms_1.RowTransformerValidator();
  21147. return _this;
  21148. }
  21149. _createClass(CsvParserStream, [{
  21150. key: "transform",
  21151. value: function transform(transformFunction) {
  21152. this.rowTransformerValidator.rowTransform = transformFunction;
  21153. return this;
  21154. }
  21155. }, {
  21156. key: "validate",
  21157. value: function validate(validateFunction) {
  21158. this.rowTransformerValidator.rowValidator = validateFunction;
  21159. return this;
  21160. } // eslint-disable-next-line @typescript-eslint/no-explicit-any
  21161. }, {
  21162. key: "emit",
  21163. value: function emit(event) {
  21164. var _get2;
  21165. if (event === 'end') {
  21166. if (!this.endEmitted) {
  21167. this.endEmitted = true;
  21168. _get(_getPrototypeOf(CsvParserStream.prototype), "emit", this).call(this, 'end', this.rowCount);
  21169. }
  21170. return false;
  21171. }
  21172. for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  21173. rest[_key - 1] = arguments[_key];
  21174. }
  21175. return (_get2 = _get(_getPrototypeOf(CsvParserStream.prototype), "emit", this)).call.apply(_get2, [this, event].concat(rest));
  21176. }
  21177. }, {
  21178. key: "_transform",
  21179. value: function _transform(data, encoding, done) {
  21180. // if we have hit our maxRows parsing limit then skip parsing
  21181. if (this.hasHitRowLimit) {
  21182. return done();
  21183. }
  21184. try {
  21185. var lines = this.lines;
  21186. var newLine = lines + this.decoder.write(data);
  21187. var rows = this.parse(newLine, true);
  21188. return this.processRows(rows, done);
  21189. } catch (e) {
  21190. return done(e);
  21191. }
  21192. }
  21193. }, {
  21194. key: "_flush",
  21195. value: function _flush(done) {
  21196. // if we have hit our maxRows parsing limit then skip parsing
  21197. if (this.hasHitRowLimit) {
  21198. return done();
  21199. }
  21200. try {
  21201. var newLine = this.lines + this.decoder.end();
  21202. var rows = this.parse(newLine, false);
  21203. return this.processRows(rows, done);
  21204. } catch (e) {
  21205. return done(e);
  21206. }
  21207. }
  21208. }, {
  21209. key: "parse",
  21210. value: function parse(data, hasMoreData) {
  21211. if (!data) {
  21212. return [];
  21213. }
  21214. var _this$parser$parse = this.parser.parse(data, hasMoreData),
  21215. line = _this$parser$parse.line,
  21216. rows = _this$parser$parse.rows;
  21217. this.lines = line;
  21218. return rows;
  21219. }
  21220. }, {
  21221. key: "processRows",
  21222. value: function processRows(rows, cb) {
  21223. var _this2 = this;
  21224. var rowsLength = rows.length;
  21225. var iterate = function iterate(i) {
  21226. var callNext = function callNext(err) {
  21227. if (err) {
  21228. return cb(err);
  21229. }
  21230. if (i % 100 === 0) {
  21231. // incase the transform are sync insert a next tick to prevent stack overflow
  21232. setImmediate(function () {
  21233. return iterate(i + 1);
  21234. });
  21235. return undefined;
  21236. }
  21237. return iterate(i + 1);
  21238. };
  21239. _this2.checkAndEmitHeaders(); // if we have emitted all rows or we have hit the maxRows limit option
  21240. // then end
  21241. if (i >= rowsLength || _this2.hasHitRowLimit) {
  21242. return cb();
  21243. }
  21244. _this2.parsedLineCount += 1;
  21245. if (_this2.shouldSkipLine) {
  21246. return callNext();
  21247. }
  21248. var row = rows[i];
  21249. _this2.rowCount += 1;
  21250. _this2.parsedRowCount += 1;
  21251. var nextRowCount = _this2.rowCount;
  21252. return _this2.transformRow(row, function (err, transformResult) {
  21253. if (err) {
  21254. _this2.rowCount -= 1;
  21255. return callNext(err);
  21256. }
  21257. if (!transformResult) {
  21258. return callNext(new Error('expected transform result'));
  21259. }
  21260. if (!transformResult.isValid) {
  21261. _this2.emit('data-invalid', transformResult.row, nextRowCount, transformResult.reason);
  21262. } else if (transformResult.row) {
  21263. return _this2.pushRow(transformResult.row, callNext);
  21264. }
  21265. return callNext();
  21266. });
  21267. };
  21268. iterate(0);
  21269. }
  21270. }, {
  21271. key: "transformRow",
  21272. value: function transformRow(parsedRow, cb) {
  21273. var _this3 = this;
  21274. try {
  21275. this.headerTransformer.transform(parsedRow, function (err, withHeaders) {
  21276. if (err) {
  21277. return cb(err);
  21278. }
  21279. if (!withHeaders) {
  21280. return cb(new Error('Expected result from header transform'));
  21281. }
  21282. if (!withHeaders.isValid) {
  21283. if (_this3.shouldEmitRows) {
  21284. return cb(null, {
  21285. isValid: false,
  21286. row: parsedRow
  21287. });
  21288. } // skipped because of skipRows option remove from total row count
  21289. return _this3.skipRow(cb);
  21290. }
  21291. if (withHeaders.row) {
  21292. if (_this3.shouldEmitRows) {
  21293. return _this3.rowTransformerValidator.transformAndValidate(withHeaders.row, cb);
  21294. } // skipped because of skipRows option remove from total row count
  21295. return _this3.skipRow(cb);
  21296. } // this is a header row dont include in the rowCount or parsedRowCount
  21297. _this3.rowCount -= 1;
  21298. _this3.parsedRowCount -= 1;
  21299. return cb(null, {
  21300. row: null,
  21301. isValid: true
  21302. });
  21303. });
  21304. } catch (e) {
  21305. cb(e);
  21306. }
  21307. }
  21308. }, {
  21309. key: "checkAndEmitHeaders",
  21310. value: function checkAndEmitHeaders() {
  21311. if (!this.headersEmitted && this.headerTransformer.headers) {
  21312. this.headersEmitted = true;
  21313. this.emit('headers', this.headerTransformer.headers);
  21314. }
  21315. }
  21316. }, {
  21317. key: "skipRow",
  21318. value: function skipRow(cb) {
  21319. // skipped because of skipRows option remove from total row count
  21320. this.rowCount -= 1;
  21321. return cb(null, {
  21322. row: null,
  21323. isValid: true
  21324. });
  21325. }
  21326. }, {
  21327. key: "pushRow",
  21328. value: function pushRow(row, cb) {
  21329. try {
  21330. if (!this.parserOptions.objectMode) {
  21331. this.push(JSON.stringify(row));
  21332. } else {
  21333. this.push(row);
  21334. }
  21335. cb();
  21336. } catch (e) {
  21337. cb(e);
  21338. }
  21339. }
  21340. }, {
  21341. key: "hasHitRowLimit",
  21342. get: function get() {
  21343. return this.parserOptions.limitRows && this.rowCount >= this.parserOptions.maxRows;
  21344. }
  21345. }, {
  21346. key: "shouldEmitRows",
  21347. get: function get() {
  21348. return this.parsedRowCount > this.parserOptions.skipRows;
  21349. }
  21350. }, {
  21351. key: "shouldSkipLine",
  21352. get: function get() {
  21353. return this.parsedLineCount <= this.parserOptions.skipLines;
  21354. }
  21355. }]);
  21356. return CsvParserStream;
  21357. }(stream_1.Transform);
  21358. exports.CsvParserStream = CsvParserStream;
  21359. }).call(this,require("timers").setImmediate)
  21360. },{"./parser":162,"./transforms":165,"stream":506,"string_decoder":520,"timers":521}],151:[function(require,module,exports){
  21361. "use strict";
  21362. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21363. var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
  21364. return mod && mod.__esModule ? mod : {
  21365. "default": mod
  21366. };
  21367. };
  21368. Object.defineProperty(exports, "__esModule", {
  21369. value: true
  21370. });
  21371. exports.ParserOptions = void 0;
  21372. var lodash_escaperegexp_1 = __importDefault(require("lodash.escaperegexp"));
  21373. var lodash_isnil_1 = __importDefault(require("lodash.isnil"));
  21374. var ParserOptions = function ParserOptions(opts) {
  21375. _classCallCheck(this, ParserOptions);
  21376. var _a;
  21377. this.objectMode = true;
  21378. this.delimiter = ',';
  21379. this.ignoreEmpty = false;
  21380. this.quote = '"';
  21381. this.escape = null;
  21382. this.escapeChar = this.quote;
  21383. this.comment = null;
  21384. this.supportsComments = false;
  21385. this.ltrim = false;
  21386. this.rtrim = false;
  21387. this.trim = false;
  21388. this.headers = null;
  21389. this.renameHeaders = false;
  21390. this.strictColumnHandling = false;
  21391. this.discardUnmappedColumns = false;
  21392. this.carriageReturn = '\r';
  21393. this.encoding = 'utf8';
  21394. this.limitRows = false;
  21395. this.maxRows = 0;
  21396. this.skipLines = 0;
  21397. this.skipRows = 0;
  21398. Object.assign(this, opts || {});
  21399. if (this.delimiter.length > 1) {
  21400. throw new Error('delimiter option must be one character long');
  21401. }
  21402. this.escapedDelimiter = lodash_escaperegexp_1.default(this.delimiter);
  21403. this.escapeChar = (_a = this.escape) !== null && _a !== void 0 ? _a : this.quote;
  21404. this.supportsComments = !lodash_isnil_1.default(this.comment);
  21405. this.NEXT_TOKEN_REGEXP = new RegExp("([^\\s]|\\r\\n|\\n|\\r|".concat(this.escapedDelimiter, ")"));
  21406. if (this.maxRows > 0) {
  21407. this.limitRows = true;
  21408. }
  21409. };
  21410. exports.ParserOptions = ParserOptions;
  21411. },{"lodash.escaperegexp":426,"lodash.isnil":431}],152:[function(require,module,exports){
  21412. "use strict";
  21413. var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
  21414. if (k2 === undefined) k2 = k;
  21415. Object.defineProperty(o, k2, {
  21416. enumerable: true,
  21417. get: function get() {
  21418. return m[k];
  21419. }
  21420. });
  21421. } : function (o, m, k, k2) {
  21422. if (k2 === undefined) k2 = k;
  21423. o[k2] = m[k];
  21424. });
  21425. var __setModuleDefault = void 0 && (void 0).__setModuleDefault || (Object.create ? function (o, v) {
  21426. Object.defineProperty(o, "default", {
  21427. enumerable: true,
  21428. value: v
  21429. });
  21430. } : function (o, v) {
  21431. o["default"] = v;
  21432. });
  21433. var __importStar = void 0 && (void 0).__importStar || function (mod) {
  21434. if (mod && mod.__esModule) return mod;
  21435. var result = {};
  21436. if (mod != null) for (var k in mod) {
  21437. if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  21438. }
  21439. __setModuleDefault(result, mod);
  21440. return result;
  21441. };
  21442. var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
  21443. for (var p in m) {
  21444. if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
  21445. }
  21446. };
  21447. Object.defineProperty(exports, "__esModule", {
  21448. value: true
  21449. });
  21450. exports.parseString = exports.parseFile = exports.parseStream = exports.parse = void 0;
  21451. var fs = __importStar(require("fs"));
  21452. var stream_1 = require("stream");
  21453. var ParserOptions_1 = require("./ParserOptions");
  21454. var CsvParserStream_1 = require("./CsvParserStream");
  21455. __exportStar(require("./types"), exports);
  21456. var CsvParserStream_2 = require("./CsvParserStream");
  21457. Object.defineProperty(exports, "CsvParserStream", {
  21458. enumerable: true,
  21459. get: function get() {
  21460. return CsvParserStream_2.CsvParserStream;
  21461. }
  21462. });
  21463. var ParserOptions_2 = require("./ParserOptions");
  21464. Object.defineProperty(exports, "ParserOptions", {
  21465. enumerable: true,
  21466. get: function get() {
  21467. return ParserOptions_2.ParserOptions;
  21468. }
  21469. });
  21470. exports.parse = function (args) {
  21471. return new CsvParserStream_1.CsvParserStream(new ParserOptions_1.ParserOptions(args));
  21472. };
  21473. exports.parseStream = function (stream, options) {
  21474. return stream.pipe(new CsvParserStream_1.CsvParserStream(new ParserOptions_1.ParserOptions(options)));
  21475. };
  21476. exports.parseFile = function (location) {
  21477. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  21478. return fs.createReadStream(location).pipe(new CsvParserStream_1.CsvParserStream(new ParserOptions_1.ParserOptions(options)));
  21479. };
  21480. exports.parseString = function (string, options) {
  21481. var rs = new stream_1.Readable();
  21482. rs.push(string);
  21483. rs.push(null);
  21484. return rs.pipe(new CsvParserStream_1.CsvParserStream(new ParserOptions_1.ParserOptions(options)));
  21485. };
  21486. },{"./CsvParserStream":150,"./ParserOptions":151,"./types":166,"fs":215,"stream":506}],153:[function(require,module,exports){
  21487. "use strict";
  21488. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21489. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  21490. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  21491. Object.defineProperty(exports, "__esModule", {
  21492. value: true
  21493. });
  21494. exports.Parser = void 0;
  21495. var Scanner_1 = require("./Scanner");
  21496. var RowParser_1 = require("./RowParser");
  21497. var Token_1 = require("./Token");
  21498. var EMPTY_ROW_REGEXP = /^\s*(?:''|"")?\s*(?:,\s*(?:''|"")?\s*)*$/;
  21499. var Parser = /*#__PURE__*/function () {
  21500. function Parser(parserOptions) {
  21501. _classCallCheck(this, Parser);
  21502. this.parserOptions = parserOptions;
  21503. this.rowParser = new RowParser_1.RowParser(this.parserOptions);
  21504. }
  21505. _createClass(Parser, [{
  21506. key: "parse",
  21507. value: function parse(line, hasMoreData) {
  21508. var scanner = new Scanner_1.Scanner({
  21509. line: Parser.removeBOM(line),
  21510. parserOptions: this.parserOptions,
  21511. hasMoreData: hasMoreData
  21512. });
  21513. if (this.parserOptions.supportsComments) {
  21514. return this.parseWithComments(scanner);
  21515. }
  21516. return this.parseWithoutComments(scanner);
  21517. }
  21518. }, {
  21519. key: "parseWithoutComments",
  21520. value: function parseWithoutComments(scanner) {
  21521. var rows = [];
  21522. var shouldContinue = true;
  21523. while (shouldContinue) {
  21524. shouldContinue = this.parseRow(scanner, rows);
  21525. }
  21526. return {
  21527. line: scanner.line,
  21528. rows: rows
  21529. };
  21530. }
  21531. }, {
  21532. key: "parseWithComments",
  21533. value: function parseWithComments(scanner) {
  21534. var parserOptions = this.parserOptions;
  21535. var rows = [];
  21536. for (var nextToken = scanner.nextCharacterToken; nextToken !== null; nextToken = scanner.nextCharacterToken) {
  21537. if (Token_1.Token.isTokenComment(nextToken, parserOptions)) {
  21538. var cursor = scanner.advancePastLine();
  21539. if (cursor === null) {
  21540. return {
  21541. line: scanner.lineFromCursor,
  21542. rows: rows
  21543. };
  21544. }
  21545. if (!scanner.hasMoreCharacters) {
  21546. return {
  21547. line: scanner.lineFromCursor,
  21548. rows: rows
  21549. };
  21550. }
  21551. scanner.truncateToCursor();
  21552. } else if (!this.parseRow(scanner, rows)) {
  21553. break;
  21554. }
  21555. }
  21556. return {
  21557. line: scanner.line,
  21558. rows: rows
  21559. };
  21560. }
  21561. }, {
  21562. key: "parseRow",
  21563. value: function parseRow(scanner, rows) {
  21564. var nextToken = scanner.nextNonSpaceToken;
  21565. if (!nextToken) {
  21566. return false;
  21567. }
  21568. var row = this.rowParser.parse(scanner);
  21569. if (row === null) {
  21570. return false;
  21571. }
  21572. if (this.parserOptions.ignoreEmpty && EMPTY_ROW_REGEXP.test(row.join(''))) {
  21573. return true;
  21574. }
  21575. rows.push(row);
  21576. return true;
  21577. }
  21578. }], [{
  21579. key: "removeBOM",
  21580. value: function removeBOM(line) {
  21581. // Catches EFBBBF (UTF-8 BOM) because the buffer-to-string
  21582. // conversion translates it to FEFF (UTF-16 BOM)
  21583. if (line && line.charCodeAt(0) === 0xfeff) {
  21584. return line.slice(1);
  21585. }
  21586. return line;
  21587. }
  21588. }]);
  21589. return Parser;
  21590. }();
  21591. exports.Parser = Parser;
  21592. },{"./RowParser":154,"./Scanner":155,"./Token":156}],154:[function(require,module,exports){
  21593. "use strict";
  21594. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21595. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  21596. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  21597. Object.defineProperty(exports, "__esModule", {
  21598. value: true
  21599. });
  21600. exports.RowParser = void 0;
  21601. var column_1 = require("./column");
  21602. var Token_1 = require("./Token");
  21603. var _Token_1$Token = Token_1.Token,
  21604. isTokenRowDelimiter = _Token_1$Token.isTokenRowDelimiter,
  21605. isTokenCarriageReturn = _Token_1$Token.isTokenCarriageReturn,
  21606. isTokenDelimiter = _Token_1$Token.isTokenDelimiter;
  21607. var RowParser = /*#__PURE__*/function () {
  21608. function RowParser(parserOptions) {
  21609. _classCallCheck(this, RowParser);
  21610. this.parserOptions = parserOptions;
  21611. this.columnParser = new column_1.ColumnParser(parserOptions);
  21612. }
  21613. _createClass(RowParser, [{
  21614. key: "parse",
  21615. value: function parse(scanner) {
  21616. var parserOptions = this.parserOptions;
  21617. var hasMoreData = scanner.hasMoreData;
  21618. var currentScanner = scanner;
  21619. var columns = [];
  21620. var currentToken = this.getStartToken(currentScanner, columns);
  21621. while (currentToken) {
  21622. if (isTokenRowDelimiter(currentToken)) {
  21623. currentScanner.advancePastToken(currentToken); // if ends with CR and there is more data, keep unparsed due to possible
  21624. // coming LF in CRLF
  21625. if (!currentScanner.hasMoreCharacters && isTokenCarriageReturn(currentToken, parserOptions) && hasMoreData) {
  21626. return null;
  21627. }
  21628. currentScanner.truncateToCursor();
  21629. return columns;
  21630. }
  21631. if (!this.shouldSkipColumnParse(currentScanner, currentToken, columns)) {
  21632. var item = this.columnParser.parse(currentScanner);
  21633. if (item === null) {
  21634. return null;
  21635. }
  21636. columns.push(item);
  21637. }
  21638. currentToken = currentScanner.nextNonSpaceToken;
  21639. }
  21640. if (!hasMoreData) {
  21641. currentScanner.truncateToCursor();
  21642. return columns;
  21643. }
  21644. return null;
  21645. }
  21646. }, {
  21647. key: "getStartToken",
  21648. value: function getStartToken(scanner, columns) {
  21649. var currentToken = scanner.nextNonSpaceToken;
  21650. if (currentToken !== null && isTokenDelimiter(currentToken, this.parserOptions)) {
  21651. columns.push('');
  21652. return scanner.nextNonSpaceToken;
  21653. }
  21654. return currentToken;
  21655. }
  21656. }, {
  21657. key: "shouldSkipColumnParse",
  21658. value: function shouldSkipColumnParse(scanner, currentToken, columns) {
  21659. var parserOptions = this.parserOptions;
  21660. if (isTokenDelimiter(currentToken, parserOptions)) {
  21661. scanner.advancePastToken(currentToken); // if the delimiter is at the end of a line
  21662. var nextToken = scanner.nextCharacterToken;
  21663. if (!scanner.hasMoreCharacters || nextToken !== null && isTokenRowDelimiter(nextToken)) {
  21664. columns.push('');
  21665. return true;
  21666. }
  21667. if (nextToken !== null && isTokenDelimiter(nextToken, parserOptions)) {
  21668. columns.push('');
  21669. return true;
  21670. }
  21671. }
  21672. return false;
  21673. }
  21674. }]);
  21675. return RowParser;
  21676. }();
  21677. exports.RowParser = RowParser;
  21678. },{"./Token":156,"./column":161}],155:[function(require,module,exports){
  21679. "use strict";
  21680. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21681. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  21682. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  21683. Object.defineProperty(exports, "__esModule", {
  21684. value: true
  21685. });
  21686. exports.Scanner = void 0;
  21687. var Token_1 = require("./Token");
  21688. var ROW_DELIMITER = /((?:\r\n)|\n|\r)/;
  21689. var Scanner = /*#__PURE__*/function () {
  21690. function Scanner(args) {
  21691. _classCallCheck(this, Scanner);
  21692. this.cursor = 0;
  21693. this.line = args.line;
  21694. this.lineLength = this.line.length;
  21695. this.parserOptions = args.parserOptions;
  21696. this.hasMoreData = args.hasMoreData;
  21697. this.cursor = args.cursor || 0;
  21698. }
  21699. _createClass(Scanner, [{
  21700. key: "advancePastLine",
  21701. value: function advancePastLine() {
  21702. var match = ROW_DELIMITER.exec(this.lineFromCursor);
  21703. if (!match) {
  21704. if (this.hasMoreData) {
  21705. return null;
  21706. }
  21707. this.cursor = this.lineLength;
  21708. return this;
  21709. }
  21710. this.cursor += (match.index || 0) + match[0].length;
  21711. return this;
  21712. }
  21713. }, {
  21714. key: "advanceTo",
  21715. value: function advanceTo(cursor) {
  21716. this.cursor = cursor;
  21717. return this;
  21718. }
  21719. }, {
  21720. key: "advanceToToken",
  21721. value: function advanceToToken(token) {
  21722. this.cursor = token.startCursor;
  21723. return this;
  21724. }
  21725. }, {
  21726. key: "advancePastToken",
  21727. value: function advancePastToken(token) {
  21728. this.cursor = token.endCursor + 1;
  21729. return this;
  21730. }
  21731. }, {
  21732. key: "truncateToCursor",
  21733. value: function truncateToCursor() {
  21734. this.line = this.lineFromCursor;
  21735. this.lineLength = this.line.length;
  21736. this.cursor = 0;
  21737. return this;
  21738. }
  21739. }, {
  21740. key: "hasMoreCharacters",
  21741. get: function get() {
  21742. return this.lineLength > this.cursor;
  21743. }
  21744. }, {
  21745. key: "nextNonSpaceToken",
  21746. get: function get() {
  21747. var lineFromCursor = this.lineFromCursor;
  21748. var regex = this.parserOptions.NEXT_TOKEN_REGEXP;
  21749. if (lineFromCursor.search(regex) === -1) {
  21750. return null;
  21751. }
  21752. var match = regex.exec(lineFromCursor);
  21753. if (match == null) {
  21754. return null;
  21755. }
  21756. var token = match[1];
  21757. var startCursor = this.cursor + (match.index || 0);
  21758. return new Token_1.Token({
  21759. token: token,
  21760. startCursor: startCursor,
  21761. endCursor: startCursor + token.length - 1
  21762. });
  21763. }
  21764. }, {
  21765. key: "nextCharacterToken",
  21766. get: function get() {
  21767. var cursor = this.cursor,
  21768. lineLength = this.lineLength;
  21769. if (lineLength <= cursor) {
  21770. return null;
  21771. }
  21772. return new Token_1.Token({
  21773. token: this.line[cursor],
  21774. startCursor: cursor,
  21775. endCursor: cursor
  21776. });
  21777. }
  21778. }, {
  21779. key: "lineFromCursor",
  21780. get: function get() {
  21781. return this.line.substr(this.cursor);
  21782. }
  21783. }]);
  21784. return Scanner;
  21785. }();
  21786. exports.Scanner = Scanner;
  21787. },{"./Token":156}],156:[function(require,module,exports){
  21788. "use strict";
  21789. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21790. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  21791. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  21792. Object.defineProperty(exports, "__esModule", {
  21793. value: true
  21794. });
  21795. exports.Token = void 0;
  21796. var Token = /*#__PURE__*/function () {
  21797. function Token(tokenArgs) {
  21798. _classCallCheck(this, Token);
  21799. this.token = tokenArgs.token;
  21800. this.startCursor = tokenArgs.startCursor;
  21801. this.endCursor = tokenArgs.endCursor;
  21802. }
  21803. _createClass(Token, null, [{
  21804. key: "isTokenRowDelimiter",
  21805. value: function isTokenRowDelimiter(token) {
  21806. var content = token.token;
  21807. return content === '\r' || content === '\n' || content === '\r\n';
  21808. }
  21809. }, {
  21810. key: "isTokenCarriageReturn",
  21811. value: function isTokenCarriageReturn(token, parserOptions) {
  21812. return token.token === parserOptions.carriageReturn;
  21813. }
  21814. }, {
  21815. key: "isTokenComment",
  21816. value: function isTokenComment(token, parserOptions) {
  21817. return parserOptions.supportsComments && !!token && token.token === parserOptions.comment;
  21818. }
  21819. }, {
  21820. key: "isTokenEscapeCharacter",
  21821. value: function isTokenEscapeCharacter(token, parserOptions) {
  21822. return token.token === parserOptions.escapeChar;
  21823. }
  21824. }, {
  21825. key: "isTokenQuote",
  21826. value: function isTokenQuote(token, parserOptions) {
  21827. return token.token === parserOptions.quote;
  21828. }
  21829. }, {
  21830. key: "isTokenDelimiter",
  21831. value: function isTokenDelimiter(token, parserOptions) {
  21832. return token.token === parserOptions.delimiter;
  21833. }
  21834. }]);
  21835. return Token;
  21836. }();
  21837. exports.Token = Token;
  21838. },{}],157:[function(require,module,exports){
  21839. "use strict";
  21840. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21841. Object.defineProperty(exports, "__esModule", {
  21842. value: true
  21843. });
  21844. exports.ColumnFormatter = void 0;
  21845. var ColumnFormatter = function ColumnFormatter(parserOptions) {
  21846. _classCallCheck(this, ColumnFormatter);
  21847. if (parserOptions.trim) {
  21848. this.format = function (col) {
  21849. return col.trim();
  21850. };
  21851. } else if (parserOptions.ltrim) {
  21852. this.format = function (col) {
  21853. return col.trimLeft();
  21854. };
  21855. } else if (parserOptions.rtrim) {
  21856. this.format = function (col) {
  21857. return col.trimRight();
  21858. };
  21859. } else {
  21860. this.format = function (col) {
  21861. return col;
  21862. };
  21863. }
  21864. };
  21865. exports.ColumnFormatter = ColumnFormatter;
  21866. },{}],158:[function(require,module,exports){
  21867. "use strict";
  21868. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21869. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  21870. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  21871. Object.defineProperty(exports, "__esModule", {
  21872. value: true
  21873. });
  21874. exports.ColumnParser = void 0;
  21875. var NonQuotedColumnParser_1 = require("./NonQuotedColumnParser");
  21876. var QuotedColumnParser_1 = require("./QuotedColumnParser");
  21877. var Token_1 = require("../Token");
  21878. var ColumnParser = /*#__PURE__*/function () {
  21879. function ColumnParser(parserOptions) {
  21880. _classCallCheck(this, ColumnParser);
  21881. this.parserOptions = parserOptions;
  21882. this.quotedColumnParser = new QuotedColumnParser_1.QuotedColumnParser(parserOptions);
  21883. this.nonQuotedColumnParser = new NonQuotedColumnParser_1.NonQuotedColumnParser(parserOptions);
  21884. }
  21885. _createClass(ColumnParser, [{
  21886. key: "parse",
  21887. value: function parse(scanner) {
  21888. var nextNonSpaceToken = scanner.nextNonSpaceToken;
  21889. if (nextNonSpaceToken !== null && Token_1.Token.isTokenQuote(nextNonSpaceToken, this.parserOptions)) {
  21890. scanner.advanceToToken(nextNonSpaceToken);
  21891. return this.quotedColumnParser.parse(scanner);
  21892. }
  21893. return this.nonQuotedColumnParser.parse(scanner);
  21894. }
  21895. }]);
  21896. return ColumnParser;
  21897. }();
  21898. exports.ColumnParser = ColumnParser;
  21899. },{"../Token":156,"./NonQuotedColumnParser":159,"./QuotedColumnParser":160}],159:[function(require,module,exports){
  21900. "use strict";
  21901. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21902. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  21903. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  21904. Object.defineProperty(exports, "__esModule", {
  21905. value: true
  21906. });
  21907. exports.NonQuotedColumnParser = void 0;
  21908. var ColumnFormatter_1 = require("./ColumnFormatter");
  21909. var Token_1 = require("../Token");
  21910. var _Token_1$Token = Token_1.Token,
  21911. isTokenDelimiter = _Token_1$Token.isTokenDelimiter,
  21912. isTokenRowDelimiter = _Token_1$Token.isTokenRowDelimiter;
  21913. var NonQuotedColumnParser = /*#__PURE__*/function () {
  21914. function NonQuotedColumnParser(parserOptions) {
  21915. _classCallCheck(this, NonQuotedColumnParser);
  21916. this.parserOptions = parserOptions;
  21917. this.columnFormatter = new ColumnFormatter_1.ColumnFormatter(parserOptions);
  21918. }
  21919. _createClass(NonQuotedColumnParser, [{
  21920. key: "parse",
  21921. value: function parse(scanner) {
  21922. if (!scanner.hasMoreCharacters) {
  21923. return null;
  21924. }
  21925. var parserOptions = this.parserOptions;
  21926. var characters = [];
  21927. var nextToken = scanner.nextCharacterToken;
  21928. for (; nextToken; nextToken = scanner.nextCharacterToken) {
  21929. if (isTokenDelimiter(nextToken, parserOptions) || isTokenRowDelimiter(nextToken)) {
  21930. break;
  21931. }
  21932. characters.push(nextToken.token);
  21933. scanner.advancePastToken(nextToken);
  21934. }
  21935. return this.columnFormatter.format(characters.join(''));
  21936. }
  21937. }]);
  21938. return NonQuotedColumnParser;
  21939. }();
  21940. exports.NonQuotedColumnParser = NonQuotedColumnParser;
  21941. },{"../Token":156,"./ColumnFormatter":157}],160:[function(require,module,exports){
  21942. "use strict";
  21943. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21944. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  21945. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  21946. Object.defineProperty(exports, "__esModule", {
  21947. value: true
  21948. });
  21949. exports.QuotedColumnParser = void 0;
  21950. var ColumnFormatter_1 = require("./ColumnFormatter");
  21951. var Token_1 = require("../Token");
  21952. var _Token_1$Token = Token_1.Token,
  21953. isTokenDelimiter = _Token_1$Token.isTokenDelimiter,
  21954. isTokenRowDelimiter = _Token_1$Token.isTokenRowDelimiter,
  21955. isTokenEscapeCharacter = _Token_1$Token.isTokenEscapeCharacter,
  21956. isTokenQuote = _Token_1$Token.isTokenQuote;
  21957. var QuotedColumnParser = /*#__PURE__*/function () {
  21958. function QuotedColumnParser(parserOptions) {
  21959. _classCallCheck(this, QuotedColumnParser);
  21960. this.parserOptions = parserOptions;
  21961. this.columnFormatter = new ColumnFormatter_1.ColumnFormatter(parserOptions);
  21962. }
  21963. _createClass(QuotedColumnParser, [{
  21964. key: "parse",
  21965. value: function parse(scanner) {
  21966. if (!scanner.hasMoreCharacters) {
  21967. return null;
  21968. }
  21969. var originalCursor = scanner.cursor;
  21970. var _this$gatherDataBetwe = this.gatherDataBetweenQuotes(scanner),
  21971. foundClosingQuote = _this$gatherDataBetwe.foundClosingQuote,
  21972. col = _this$gatherDataBetwe.col;
  21973. if (!foundClosingQuote) {
  21974. // reset the cursor to the original
  21975. scanner.advanceTo(originalCursor); // if we didnt find a closing quote but we potentially have more data then skip the parsing
  21976. // and return the original scanner.
  21977. if (!scanner.hasMoreData) {
  21978. throw new Error("Parse Error: missing closing: '".concat(this.parserOptions.quote || '', "' in line: at '").concat(scanner.lineFromCursor.replace(/[\r\n]/g, "\\n'"), "'"));
  21979. }
  21980. return null;
  21981. }
  21982. this.checkForMalformedColumn(scanner);
  21983. return col;
  21984. }
  21985. }, {
  21986. key: "gatherDataBetweenQuotes",
  21987. value: function gatherDataBetweenQuotes(scanner) {
  21988. var parserOptions = this.parserOptions;
  21989. var foundStartingQuote = false;
  21990. var foundClosingQuote = false;
  21991. var characters = [];
  21992. var nextToken = scanner.nextCharacterToken;
  21993. for (; !foundClosingQuote && nextToken !== null; nextToken = scanner.nextCharacterToken) {
  21994. var isQuote = isTokenQuote(nextToken, parserOptions); // ignore first quote
  21995. if (!foundStartingQuote && isQuote) {
  21996. foundStartingQuote = true;
  21997. } else if (foundStartingQuote) {
  21998. if (isTokenEscapeCharacter(nextToken, parserOptions)) {
  21999. // advance past the escape character so we can get the next one in line
  22000. scanner.advancePastToken(nextToken);
  22001. var tokenFollowingEscape = scanner.nextCharacterToken; // if the character following the escape is a quote character then just add
  22002. // the quote and advance to that character
  22003. if (tokenFollowingEscape !== null && (isTokenQuote(tokenFollowingEscape, parserOptions) || isTokenEscapeCharacter(tokenFollowingEscape, parserOptions))) {
  22004. characters.push(tokenFollowingEscape.token);
  22005. nextToken = tokenFollowingEscape;
  22006. } else if (isQuote) {
  22007. // if the escape is also a quote then we found our closing quote and finish early
  22008. foundClosingQuote = true;
  22009. } else {
  22010. // other wise add the escape token to the characters since it wast escaping anything
  22011. characters.push(nextToken.token);
  22012. }
  22013. } else if (isQuote) {
  22014. // we found our closing quote!
  22015. foundClosingQuote = true;
  22016. } else {
  22017. // add the token to the characters
  22018. characters.push(nextToken.token);
  22019. }
  22020. }
  22021. scanner.advancePastToken(nextToken);
  22022. }
  22023. return {
  22024. col: this.columnFormatter.format(characters.join('')),
  22025. foundClosingQuote: foundClosingQuote
  22026. };
  22027. }
  22028. }, {
  22029. key: "checkForMalformedColumn",
  22030. value: function checkForMalformedColumn(scanner) {
  22031. var parserOptions = this.parserOptions;
  22032. var nextNonSpaceToken = scanner.nextNonSpaceToken;
  22033. if (nextNonSpaceToken) {
  22034. var isNextTokenADelimiter = isTokenDelimiter(nextNonSpaceToken, parserOptions);
  22035. var isNextTokenARowDelimiter = isTokenRowDelimiter(nextNonSpaceToken);
  22036. if (!(isNextTokenADelimiter || isNextTokenARowDelimiter)) {
  22037. // if the final quote was NOT followed by a column (,) or row(\n) delimiter then its a bad column
  22038. // tldr: only part of the column was quoted
  22039. var linePreview = scanner.lineFromCursor.substr(0, 10).replace(/[\r\n]/g, "\\n'");
  22040. throw new Error("Parse Error: expected: '".concat(parserOptions.escapedDelimiter, "' OR new line got: '").concat(nextNonSpaceToken.token, "'. at '").concat(linePreview));
  22041. }
  22042. scanner.advanceToToken(nextNonSpaceToken);
  22043. } else if (!scanner.hasMoreData) {
  22044. scanner.advancePastLine();
  22045. }
  22046. }
  22047. }]);
  22048. return QuotedColumnParser;
  22049. }();
  22050. exports.QuotedColumnParser = QuotedColumnParser;
  22051. },{"../Token":156,"./ColumnFormatter":157}],161:[function(require,module,exports){
  22052. "use strict";
  22053. Object.defineProperty(exports, "__esModule", {
  22054. value: true
  22055. });
  22056. var ColumnParser_1 = require("./ColumnParser");
  22057. Object.defineProperty(exports, "ColumnParser", {
  22058. enumerable: true,
  22059. get: function get() {
  22060. return ColumnParser_1.ColumnParser;
  22061. }
  22062. });
  22063. var NonQuotedColumnParser_1 = require("./NonQuotedColumnParser");
  22064. Object.defineProperty(exports, "NonQuotedColumnParser", {
  22065. enumerable: true,
  22066. get: function get() {
  22067. return NonQuotedColumnParser_1.NonQuotedColumnParser;
  22068. }
  22069. });
  22070. var QuotedColumnParser_1 = require("./QuotedColumnParser");
  22071. Object.defineProperty(exports, "QuotedColumnParser", {
  22072. enumerable: true,
  22073. get: function get() {
  22074. return QuotedColumnParser_1.QuotedColumnParser;
  22075. }
  22076. });
  22077. var ColumnFormatter_1 = require("./ColumnFormatter");
  22078. Object.defineProperty(exports, "ColumnFormatter", {
  22079. enumerable: true,
  22080. get: function get() {
  22081. return ColumnFormatter_1.ColumnFormatter;
  22082. }
  22083. });
  22084. },{"./ColumnFormatter":157,"./ColumnParser":158,"./NonQuotedColumnParser":159,"./QuotedColumnParser":160}],162:[function(require,module,exports){
  22085. "use strict";
  22086. Object.defineProperty(exports, "__esModule", {
  22087. value: true
  22088. });
  22089. var Parser_1 = require("./Parser");
  22090. Object.defineProperty(exports, "Parser", {
  22091. enumerable: true,
  22092. get: function get() {
  22093. return Parser_1.Parser;
  22094. }
  22095. });
  22096. var RowParser_1 = require("./RowParser");
  22097. Object.defineProperty(exports, "RowParser", {
  22098. enumerable: true,
  22099. get: function get() {
  22100. return RowParser_1.RowParser;
  22101. }
  22102. });
  22103. var Scanner_1 = require("./Scanner");
  22104. Object.defineProperty(exports, "Scanner", {
  22105. enumerable: true,
  22106. get: function get() {
  22107. return Scanner_1.Scanner;
  22108. }
  22109. });
  22110. var Token_1 = require("./Token");
  22111. Object.defineProperty(exports, "Token", {
  22112. enumerable: true,
  22113. get: function get() {
  22114. return Token_1.Token;
  22115. }
  22116. });
  22117. var column_1 = require("./column");
  22118. Object.defineProperty(exports, "ColumnParser", {
  22119. enumerable: true,
  22120. get: function get() {
  22121. return column_1.ColumnParser;
  22122. }
  22123. });
  22124. Object.defineProperty(exports, "NonQuotedColumnParser", {
  22125. enumerable: true,
  22126. get: function get() {
  22127. return column_1.NonQuotedColumnParser;
  22128. }
  22129. });
  22130. Object.defineProperty(exports, "QuotedColumnParser", {
  22131. enumerable: true,
  22132. get: function get() {
  22133. return column_1.QuotedColumnParser;
  22134. }
  22135. });
  22136. },{"./Parser":153,"./RowParser":154,"./Scanner":155,"./Token":156,"./column":161}],163:[function(require,module,exports){
  22137. "use strict";
  22138. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  22139. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  22140. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  22141. var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
  22142. return mod && mod.__esModule ? mod : {
  22143. "default": mod
  22144. };
  22145. };
  22146. Object.defineProperty(exports, "__esModule", {
  22147. value: true
  22148. });
  22149. exports.HeaderTransformer = void 0;
  22150. var lodash_isundefined_1 = __importDefault(require("lodash.isundefined"));
  22151. var lodash_isfunction_1 = __importDefault(require("lodash.isfunction"));
  22152. var lodash_uniq_1 = __importDefault(require("lodash.uniq"));
  22153. var lodash_groupby_1 = __importDefault(require("lodash.groupby"));
  22154. var HeaderTransformer = /*#__PURE__*/function () {
  22155. function HeaderTransformer(parserOptions) {
  22156. _classCallCheck(this, HeaderTransformer);
  22157. this.headers = null;
  22158. this.receivedHeaders = false;
  22159. this.shouldUseFirstRow = false;
  22160. this.processedFirstRow = false;
  22161. this.headersLength = 0;
  22162. this.parserOptions = parserOptions;
  22163. if (parserOptions.headers === true) {
  22164. this.shouldUseFirstRow = true;
  22165. } else if (Array.isArray(parserOptions.headers)) {
  22166. this.setHeaders(parserOptions.headers);
  22167. } else if (lodash_isfunction_1.default(parserOptions.headers)) {
  22168. this.headersTransform = parserOptions.headers;
  22169. }
  22170. }
  22171. _createClass(HeaderTransformer, [{
  22172. key: "transform",
  22173. value: function transform(row, cb) {
  22174. if (!this.shouldMapRow(row)) {
  22175. return cb(null, {
  22176. row: null,
  22177. isValid: true
  22178. });
  22179. }
  22180. return cb(null, this.processRow(row));
  22181. }
  22182. }, {
  22183. key: "shouldMapRow",
  22184. value: function shouldMapRow(row) {
  22185. var parserOptions = this.parserOptions;
  22186. if (!this.headersTransform && parserOptions.renameHeaders && !this.processedFirstRow) {
  22187. if (!this.receivedHeaders) {
  22188. throw new Error('Error renaming headers: new headers must be provided in an array');
  22189. }
  22190. this.processedFirstRow = true;
  22191. return false;
  22192. }
  22193. if (!this.receivedHeaders && Array.isArray(row)) {
  22194. if (this.headersTransform) {
  22195. this.setHeaders(this.headersTransform(row));
  22196. } else if (this.shouldUseFirstRow) {
  22197. this.setHeaders(row);
  22198. } else {
  22199. // dont do anything with the headers if we didnt receive a transform or shouldnt use the first row.
  22200. return true;
  22201. }
  22202. return false;
  22203. }
  22204. return true;
  22205. }
  22206. }, {
  22207. key: "processRow",
  22208. value: function processRow(row) {
  22209. if (!this.headers) {
  22210. return {
  22211. row: row,
  22212. isValid: true
  22213. };
  22214. }
  22215. var parserOptions = this.parserOptions;
  22216. if (!parserOptions.discardUnmappedColumns && row.length > this.headersLength) {
  22217. if (!parserOptions.strictColumnHandling) {
  22218. throw new Error("Unexpected Error: column header mismatch expected: ".concat(this.headersLength, " columns got: ").concat(row.length));
  22219. }
  22220. return {
  22221. row: row,
  22222. isValid: false,
  22223. reason: "Column header mismatch expected: ".concat(this.headersLength, " columns got: ").concat(row.length)
  22224. };
  22225. }
  22226. if (parserOptions.strictColumnHandling && row.length < this.headersLength) {
  22227. return {
  22228. row: row,
  22229. isValid: false,
  22230. reason: "Column header mismatch expected: ".concat(this.headersLength, " columns got: ").concat(row.length)
  22231. };
  22232. }
  22233. return {
  22234. row: this.mapHeaders(row),
  22235. isValid: true
  22236. };
  22237. }
  22238. }, {
  22239. key: "mapHeaders",
  22240. value: function mapHeaders(row) {
  22241. var rowMap = {};
  22242. var headers = this.headers,
  22243. headersLength = this.headersLength;
  22244. for (var i = 0; i < headersLength; i += 1) {
  22245. var header = headers[i];
  22246. if (!lodash_isundefined_1.default(header)) {
  22247. var val = row[i]; // eslint-disable-next-line no-param-reassign
  22248. if (lodash_isundefined_1.default(val)) {
  22249. rowMap[header] = '';
  22250. } else {
  22251. rowMap[header] = val;
  22252. }
  22253. }
  22254. }
  22255. return rowMap;
  22256. }
  22257. }, {
  22258. key: "setHeaders",
  22259. value: function setHeaders(headers) {
  22260. var _a;
  22261. var filteredHeaders = headers.filter(function (h) {
  22262. return !!h;
  22263. });
  22264. if (lodash_uniq_1.default(filteredHeaders).length !== filteredHeaders.length) {
  22265. var grouped = lodash_groupby_1.default(filteredHeaders);
  22266. var duplicates = Object.keys(grouped).filter(function (dup) {
  22267. return grouped[dup].length > 1;
  22268. });
  22269. throw new Error("Duplicate headers found ".concat(JSON.stringify(duplicates)));
  22270. }
  22271. this.headers = headers;
  22272. this.receivedHeaders = true;
  22273. this.headersLength = ((_a = this.headers) === null || _a === void 0 ? void 0 : _a.length) || 0;
  22274. }
  22275. }]);
  22276. return HeaderTransformer;
  22277. }();
  22278. exports.HeaderTransformer = HeaderTransformer;
  22279. },{"lodash.groupby":427,"lodash.isfunction":430,"lodash.isundefined":432,"lodash.uniq":433}],164:[function(require,module,exports){
  22280. "use strict";
  22281. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  22282. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  22283. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  22284. var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
  22285. return mod && mod.__esModule ? mod : {
  22286. "default": mod
  22287. };
  22288. };
  22289. Object.defineProperty(exports, "__esModule", {
  22290. value: true
  22291. });
  22292. exports.RowTransformerValidator = void 0;
  22293. var lodash_isfunction_1 = __importDefault(require("lodash.isfunction"));
  22294. var types_1 = require("../types");
  22295. var RowTransformerValidator = /*#__PURE__*/function () {
  22296. function RowTransformerValidator() {
  22297. _classCallCheck(this, RowTransformerValidator);
  22298. this._rowTransform = null;
  22299. this._rowValidator = null;
  22300. }
  22301. _createClass(RowTransformerValidator, [{
  22302. key: "transformAndValidate",
  22303. value: function transformAndValidate(row, cb) {
  22304. var _this = this;
  22305. return this.callTransformer(row, function (transformErr, transformedRow) {
  22306. if (transformErr) {
  22307. return cb(transformErr);
  22308. }
  22309. if (!transformedRow) {
  22310. return cb(null, {
  22311. row: null,
  22312. isValid: true
  22313. });
  22314. }
  22315. return _this.callValidator(transformedRow, function (validateErr, validationResult) {
  22316. if (validateErr) {
  22317. return cb(validateErr);
  22318. }
  22319. if (validationResult && !validationResult.isValid) {
  22320. return cb(null, {
  22321. row: transformedRow,
  22322. isValid: false,
  22323. reason: validationResult.reason
  22324. });
  22325. }
  22326. return cb(null, {
  22327. row: transformedRow,
  22328. isValid: true
  22329. });
  22330. });
  22331. });
  22332. }
  22333. }, {
  22334. key: "callTransformer",
  22335. value: function callTransformer(row, cb) {
  22336. if (!this._rowTransform) {
  22337. return cb(null, row);
  22338. }
  22339. return this._rowTransform(row, cb);
  22340. }
  22341. }, {
  22342. key: "callValidator",
  22343. value: function callValidator(row, cb) {
  22344. if (!this._rowValidator) {
  22345. return cb(null, {
  22346. row: row,
  22347. isValid: true
  22348. });
  22349. }
  22350. return this._rowValidator(row, cb);
  22351. }
  22352. }, {
  22353. key: "rowTransform",
  22354. set: function set(transformFunction) {
  22355. if (!lodash_isfunction_1.default(transformFunction)) {
  22356. throw new TypeError('The transform should be a function');
  22357. }
  22358. this._rowTransform = RowTransformerValidator.createTransform(transformFunction);
  22359. }
  22360. }, {
  22361. key: "rowValidator",
  22362. set: function set(validateFunction) {
  22363. if (!lodash_isfunction_1.default(validateFunction)) {
  22364. throw new TypeError('The validate should be a function');
  22365. }
  22366. this._rowValidator = RowTransformerValidator.createValidator(validateFunction);
  22367. }
  22368. }], [{
  22369. key: "createTransform",
  22370. value: function createTransform(transformFunction) {
  22371. if (types_1.isSyncTransform(transformFunction)) {
  22372. return function (row, cb) {
  22373. var transformed = null;
  22374. try {
  22375. transformed = transformFunction(row);
  22376. } catch (e) {
  22377. return cb(e);
  22378. }
  22379. return cb(null, transformed);
  22380. };
  22381. }
  22382. return transformFunction;
  22383. }
  22384. }, {
  22385. key: "createValidator",
  22386. value: function createValidator(validateFunction) {
  22387. if (types_1.isSyncValidate(validateFunction)) {
  22388. return function (row, cb) {
  22389. cb(null, {
  22390. row: row,
  22391. isValid: validateFunction(row)
  22392. });
  22393. };
  22394. }
  22395. return function (row, cb) {
  22396. validateFunction(row, function (err, isValid, reason) {
  22397. if (err) {
  22398. return cb(err);
  22399. }
  22400. if (isValid) {
  22401. return cb(null, {
  22402. row: row,
  22403. isValid: isValid,
  22404. reason: reason
  22405. });
  22406. }
  22407. return cb(null, {
  22408. row: row,
  22409. isValid: false,
  22410. reason: reason
  22411. });
  22412. });
  22413. };
  22414. }
  22415. }]);
  22416. return RowTransformerValidator;
  22417. }();
  22418. exports.RowTransformerValidator = RowTransformerValidator;
  22419. },{"../types":166,"lodash.isfunction":430}],165:[function(require,module,exports){
  22420. "use strict";
  22421. Object.defineProperty(exports, "__esModule", {
  22422. value: true
  22423. });
  22424. var RowTransformerValidator_1 = require("./RowTransformerValidator");
  22425. Object.defineProperty(exports, "RowTransformerValidator", {
  22426. enumerable: true,
  22427. get: function get() {
  22428. return RowTransformerValidator_1.RowTransformerValidator;
  22429. }
  22430. });
  22431. var HeaderTransformer_1 = require("./HeaderTransformer");
  22432. Object.defineProperty(exports, "HeaderTransformer", {
  22433. enumerable: true,
  22434. get: function get() {
  22435. return HeaderTransformer_1.HeaderTransformer;
  22436. }
  22437. });
  22438. },{"./HeaderTransformer":163,"./RowTransformerValidator":164}],166:[function(require,module,exports){
  22439. "use strict";
  22440. Object.defineProperty(exports, "__esModule", {
  22441. value: true
  22442. });
  22443. exports.isSyncValidate = exports.isSyncTransform = void 0;
  22444. exports.isSyncTransform = function (transform) {
  22445. return transform.length === 1;
  22446. };
  22447. exports.isSyncValidate = function (validate) {
  22448. return validate.length === 1;
  22449. };
  22450. },{}],167:[function(require,module,exports){
  22451. 'use strict';
  22452. var asn1 = exports;
  22453. asn1.bignum = require('bn.js');
  22454. asn1.define = require('./asn1/api').define;
  22455. asn1.base = require('./asn1/base');
  22456. asn1.constants = require('./asn1/constants');
  22457. asn1.decoders = require('./asn1/decoders');
  22458. asn1.encoders = require('./asn1/encoders');
  22459. },{"./asn1/api":168,"./asn1/base":170,"./asn1/constants":174,"./asn1/decoders":176,"./asn1/encoders":179,"bn.js":181}],168:[function(require,module,exports){
  22460. 'use strict';
  22461. var encoders = require('./encoders');
  22462. var decoders = require('./decoders');
  22463. var inherits = require('inherits');
  22464. var api = exports;
  22465. api.define = function define(name, body) {
  22466. return new Entity(name, body);
  22467. };
  22468. function Entity(name, body) {
  22469. this.name = name;
  22470. this.body = body;
  22471. this.decoders = {};
  22472. this.encoders = {};
  22473. }
  22474. Entity.prototype._createNamed = function createNamed(Base) {
  22475. var name = this.name;
  22476. function Generated(entity) {
  22477. this._initNamed(entity, name);
  22478. }
  22479. inherits(Generated, Base);
  22480. Generated.prototype._initNamed = function _initNamed(entity, name) {
  22481. Base.call(this, entity, name);
  22482. };
  22483. return new Generated(this);
  22484. };
  22485. Entity.prototype._getDecoder = function _getDecoder(enc) {
  22486. enc = enc || 'der'; // Lazily create decoder
  22487. if (!this.decoders.hasOwnProperty(enc)) this.decoders[enc] = this._createNamed(decoders[enc]);
  22488. return this.decoders[enc];
  22489. };
  22490. Entity.prototype.decode = function decode(data, enc, options) {
  22491. return this._getDecoder(enc).decode(data, options);
  22492. };
  22493. Entity.prototype._getEncoder = function _getEncoder(enc) {
  22494. enc = enc || 'der'; // Lazily create encoder
  22495. if (!this.encoders.hasOwnProperty(enc)) this.encoders[enc] = this._createNamed(encoders[enc]);
  22496. return this.encoders[enc];
  22497. };
  22498. Entity.prototype.encode = function encode(data, enc,
  22499. /* internal */
  22500. reporter) {
  22501. return this._getEncoder(enc).encode(data, reporter);
  22502. };
  22503. },{"./decoders":176,"./encoders":179,"inherits":387}],169:[function(require,module,exports){
  22504. 'use strict';
  22505. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  22506. var inherits = require('inherits');
  22507. var Reporter = require('../base/reporter').Reporter;
  22508. var Buffer = require('safer-buffer').Buffer;
  22509. function DecoderBuffer(base, options) {
  22510. Reporter.call(this, options);
  22511. if (!Buffer.isBuffer(base)) {
  22512. this.error('Input not Buffer');
  22513. return;
  22514. }
  22515. this.base = base;
  22516. this.offset = 0;
  22517. this.length = base.length;
  22518. }
  22519. inherits(DecoderBuffer, Reporter);
  22520. exports.DecoderBuffer = DecoderBuffer;
  22521. DecoderBuffer.isDecoderBuffer = function isDecoderBuffer(data) {
  22522. if (data instanceof DecoderBuffer) {
  22523. return true;
  22524. } // Or accept compatible API
  22525. var 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';
  22526. return isCompatible;
  22527. };
  22528. DecoderBuffer.prototype.save = function save() {
  22529. return {
  22530. offset: this.offset,
  22531. reporter: Reporter.prototype.save.call(this)
  22532. };
  22533. };
  22534. DecoderBuffer.prototype.restore = function restore(save) {
  22535. // Return skipped data
  22536. var res = new DecoderBuffer(this.base);
  22537. res.offset = save.offset;
  22538. res.length = this.offset;
  22539. this.offset = save.offset;
  22540. Reporter.prototype.restore.call(this, save.reporter);
  22541. return res;
  22542. };
  22543. DecoderBuffer.prototype.isEmpty = function isEmpty() {
  22544. return this.offset === this.length;
  22545. };
  22546. DecoderBuffer.prototype.readUInt8 = function readUInt8(fail) {
  22547. if (this.offset + 1 <= this.length) return this.base.readUInt8(this.offset++, true);else return this.error(fail || 'DecoderBuffer overrun');
  22548. };
  22549. DecoderBuffer.prototype.skip = function skip(bytes, fail) {
  22550. if (!(this.offset + bytes <= this.length)) return this.error(fail || 'DecoderBuffer overrun');
  22551. var res = new DecoderBuffer(this.base); // Share reporter state
  22552. res._reporterState = this._reporterState;
  22553. res.offset = this.offset;
  22554. res.length = this.offset + bytes;
  22555. this.offset += bytes;
  22556. return res;
  22557. };
  22558. DecoderBuffer.prototype.raw = function raw(save) {
  22559. return this.base.slice(save ? save.offset : this.offset, this.length);
  22560. };
  22561. function EncoderBuffer(value, reporter) {
  22562. if (Array.isArray(value)) {
  22563. this.length = 0;
  22564. this.value = value.map(function (item) {
  22565. if (!EncoderBuffer.isEncoderBuffer(item)) item = new EncoderBuffer(item, reporter);
  22566. this.length += item.length;
  22567. return item;
  22568. }, this);
  22569. } else if (typeof value === 'number') {
  22570. if (!(0 <= value && value <= 0xff)) return reporter.error('non-byte EncoderBuffer value');
  22571. this.value = value;
  22572. this.length = 1;
  22573. } else if (typeof value === 'string') {
  22574. this.value = value;
  22575. this.length = Buffer.byteLength(value);
  22576. } else if (Buffer.isBuffer(value)) {
  22577. this.value = value;
  22578. this.length = value.length;
  22579. } else {
  22580. return reporter.error('Unsupported type: ' + _typeof(value));
  22581. }
  22582. }
  22583. exports.EncoderBuffer = EncoderBuffer;
  22584. EncoderBuffer.isEncoderBuffer = function isEncoderBuffer(data) {
  22585. if (data instanceof EncoderBuffer) {
  22586. return true;
  22587. } // Or accept compatible API
  22588. var isCompatible = _typeof(data) === 'object' && data.constructor.name === 'EncoderBuffer' && typeof data.length === 'number' && typeof data.join === 'function';
  22589. return isCompatible;
  22590. };
  22591. EncoderBuffer.prototype.join = function join(out, offset) {
  22592. if (!out) out = Buffer.alloc(this.length);
  22593. if (!offset) offset = 0;
  22594. if (this.length === 0) return out;
  22595. if (Array.isArray(this.value)) {
  22596. this.value.forEach(function (item) {
  22597. item.join(out, offset);
  22598. offset += item.length;
  22599. });
  22600. } else {
  22601. 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);
  22602. offset += this.length;
  22603. }
  22604. return out;
  22605. };
  22606. },{"../base/reporter":172,"inherits":387,"safer-buffer":495}],170:[function(require,module,exports){
  22607. 'use strict';
  22608. var base = exports;
  22609. base.Reporter = require('./reporter').Reporter;
  22610. base.DecoderBuffer = require('./buffer').DecoderBuffer;
  22611. base.EncoderBuffer = require('./buffer').EncoderBuffer;
  22612. base.Node = require('./node');
  22613. },{"./buffer":169,"./node":171,"./reporter":172}],171:[function(require,module,exports){
  22614. 'use strict';
  22615. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  22616. var Reporter = require('../base/reporter').Reporter;
  22617. var EncoderBuffer = require('../base/buffer').EncoderBuffer;
  22618. var DecoderBuffer = require('../base/buffer').DecoderBuffer;
  22619. var assert = require('minimalistic-assert'); // Supported tags
  22620. var 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']; // Public methods list
  22621. var methods = ['key', 'obj', 'use', 'optional', 'explicit', 'implicit', 'def', 'choice', 'any', 'contains'].concat(tags); // Overrided methods list
  22622. var overrided = ['_peekTag', '_decodeTag', '_use', '_decodeStr', '_decodeObjid', '_decodeTime', '_decodeNull', '_decodeInt', '_decodeBool', '_decodeList', '_encodeComposite', '_encodeStr', '_encodeObjid', '_encodeTime', '_encodeNull', '_encodeInt', '_encodeBool'];
  22623. function Node(enc, parent, name) {
  22624. var state = {};
  22625. this._baseState = state;
  22626. state.name = name;
  22627. state.enc = enc;
  22628. state.parent = parent || null;
  22629. state.children = null; // State
  22630. state.tag = null;
  22631. state.args = null;
  22632. state.reverseArgs = null;
  22633. state.choice = null;
  22634. state.optional = false;
  22635. state.any = false;
  22636. state.obj = false;
  22637. state.use = null;
  22638. state.useDecoder = null;
  22639. state.key = null;
  22640. state['default'] = null;
  22641. state.explicit = null;
  22642. state.implicit = null;
  22643. state.contains = null; // Should create new instance on each method
  22644. if (!state.parent) {
  22645. state.children = [];
  22646. this._wrap();
  22647. }
  22648. }
  22649. module.exports = Node;
  22650. var stateProps = ['enc', 'parent', 'children', 'tag', 'args', 'reverseArgs', 'choice', 'optional', 'any', 'obj', 'use', 'alteredUse', 'key', 'default', 'explicit', 'implicit', 'contains'];
  22651. Node.prototype.clone = function clone() {
  22652. var state = this._baseState;
  22653. var cstate = {};
  22654. stateProps.forEach(function (prop) {
  22655. cstate[prop] = state[prop];
  22656. });
  22657. var res = new this.constructor(cstate.parent);
  22658. res._baseState = cstate;
  22659. return res;
  22660. };
  22661. Node.prototype._wrap = function wrap() {
  22662. var state = this._baseState;
  22663. methods.forEach(function (method) {
  22664. this[method] = function _wrappedMethod() {
  22665. var clone = new this.constructor(this);
  22666. state.children.push(clone);
  22667. return clone[method].apply(clone, arguments);
  22668. };
  22669. }, this);
  22670. };
  22671. Node.prototype._init = function init(body) {
  22672. var state = this._baseState;
  22673. assert(state.parent === null);
  22674. body.call(this); // Filter children
  22675. state.children = state.children.filter(function (child) {
  22676. return child._baseState.parent === this;
  22677. }, this);
  22678. assert.equal(state.children.length, 1, 'Root node can have only one child');
  22679. };
  22680. Node.prototype._useArgs = function useArgs(args) {
  22681. var state = this._baseState; // Filter children and args
  22682. var children = args.filter(function (arg) {
  22683. return arg instanceof this.constructor;
  22684. }, this);
  22685. args = args.filter(function (arg) {
  22686. return !(arg instanceof this.constructor);
  22687. }, this);
  22688. if (children.length !== 0) {
  22689. assert(state.children === null);
  22690. state.children = children; // Replace parent to maintain backward link
  22691. children.forEach(function (child) {
  22692. child._baseState.parent = this;
  22693. }, this);
  22694. }
  22695. if (args.length !== 0) {
  22696. assert(state.args === null);
  22697. state.args = args;
  22698. state.reverseArgs = args.map(function (arg) {
  22699. if (_typeof(arg) !== 'object' || arg.constructor !== Object) return arg;
  22700. var res = {};
  22701. Object.keys(arg).forEach(function (key) {
  22702. if (key == (key | 0)) key |= 0;
  22703. var value = arg[key];
  22704. res[value] = key;
  22705. });
  22706. return res;
  22707. });
  22708. }
  22709. }; //
  22710. // Overrided methods
  22711. //
  22712. overrided.forEach(function (method) {
  22713. Node.prototype[method] = function _overrided() {
  22714. var state = this._baseState;
  22715. throw new Error(method + ' not implemented for encoding: ' + state.enc);
  22716. };
  22717. }); //
  22718. // Public methods
  22719. //
  22720. tags.forEach(function (tag) {
  22721. Node.prototype[tag] = function _tagMethod() {
  22722. var state = this._baseState;
  22723. var args = Array.prototype.slice.call(arguments);
  22724. assert(state.tag === null);
  22725. state.tag = tag;
  22726. this._useArgs(args);
  22727. return this;
  22728. };
  22729. });
  22730. Node.prototype.use = function use(item) {
  22731. assert(item);
  22732. var state = this._baseState;
  22733. assert(state.use === null);
  22734. state.use = item;
  22735. return this;
  22736. };
  22737. Node.prototype.optional = function optional() {
  22738. var state = this._baseState;
  22739. state.optional = true;
  22740. return this;
  22741. };
  22742. Node.prototype.def = function def(val) {
  22743. var state = this._baseState;
  22744. assert(state['default'] === null);
  22745. state['default'] = val;
  22746. state.optional = true;
  22747. return this;
  22748. };
  22749. Node.prototype.explicit = function explicit(num) {
  22750. var state = this._baseState;
  22751. assert(state.explicit === null && state.implicit === null);
  22752. state.explicit = num;
  22753. return this;
  22754. };
  22755. Node.prototype.implicit = function implicit(num) {
  22756. var state = this._baseState;
  22757. assert(state.explicit === null && state.implicit === null);
  22758. state.implicit = num;
  22759. return this;
  22760. };
  22761. Node.prototype.obj = function obj() {
  22762. var state = this._baseState;
  22763. var args = Array.prototype.slice.call(arguments);
  22764. state.obj = true;
  22765. if (args.length !== 0) this._useArgs(args);
  22766. return this;
  22767. };
  22768. Node.prototype.key = function key(newKey) {
  22769. var state = this._baseState;
  22770. assert(state.key === null);
  22771. state.key = newKey;
  22772. return this;
  22773. };
  22774. Node.prototype.any = function any() {
  22775. var state = this._baseState;
  22776. state.any = true;
  22777. return this;
  22778. };
  22779. Node.prototype.choice = function choice(obj) {
  22780. var state = this._baseState;
  22781. assert(state.choice === null);
  22782. state.choice = obj;
  22783. this._useArgs(Object.keys(obj).map(function (key) {
  22784. return obj[key];
  22785. }));
  22786. return this;
  22787. };
  22788. Node.prototype.contains = function contains(item) {
  22789. var state = this._baseState;
  22790. assert(state.use === null);
  22791. state.contains = item;
  22792. return this;
  22793. }; //
  22794. // Decoding
  22795. //
  22796. Node.prototype._decode = function decode(input, options) {
  22797. var state = this._baseState; // Decode root node
  22798. if (state.parent === null) return input.wrapResult(state.children[0]._decode(input, options));
  22799. var result = state['default'];
  22800. var present = true;
  22801. var prevKey = null;
  22802. if (state.key !== null) prevKey = input.enterKey(state.key); // Check if tag is there
  22803. if (state.optional) {
  22804. var tag = null;
  22805. if (state.explicit !== null) tag = state.explicit;else if (state.implicit !== null) tag = state.implicit;else if (state.tag !== null) tag = state.tag;
  22806. if (tag === null && !state.any) {
  22807. // Trial and Error
  22808. var save = input.save();
  22809. try {
  22810. if (state.choice === null) this._decodeGeneric(state.tag, input, options);else this._decodeChoice(input, options);
  22811. present = true;
  22812. } catch (e) {
  22813. present = false;
  22814. }
  22815. input.restore(save);
  22816. } else {
  22817. present = this._peekTag(input, tag, state.any);
  22818. if (input.isError(present)) return present;
  22819. }
  22820. } // Push object on stack
  22821. var prevObj;
  22822. if (state.obj && present) prevObj = input.enterObject();
  22823. if (present) {
  22824. // Unwrap explicit values
  22825. if (state.explicit !== null) {
  22826. var explicit = this._decodeTag(input, state.explicit);
  22827. if (input.isError(explicit)) return explicit;
  22828. input = explicit;
  22829. }
  22830. var start = input.offset; // Unwrap implicit and normal values
  22831. if (state.use === null && state.choice === null) {
  22832. var _save;
  22833. if (state.any) _save = input.save();
  22834. var body = this._decodeTag(input, state.implicit !== null ? state.implicit : state.tag, state.any);
  22835. if (input.isError(body)) return body;
  22836. if (state.any) result = input.raw(_save);else input = body;
  22837. }
  22838. if (options && options.track && state.tag !== null) options.track(input.path(), start, input.length, 'tagged');
  22839. if (options && options.track && state.tag !== null) options.track(input.path(), input.offset, input.length, 'content'); // Select proper method for tag
  22840. if (state.any) {// no-op
  22841. } else if (state.choice === null) {
  22842. result = this._decodeGeneric(state.tag, input, options);
  22843. } else {
  22844. result = this._decodeChoice(input, options);
  22845. }
  22846. if (input.isError(result)) return result; // Decode children
  22847. if (!state.any && state.choice === null && state.children !== null) {
  22848. state.children.forEach(function decodeChildren(child) {
  22849. // NOTE: We are ignoring errors here, to let parser continue with other
  22850. // parts of encoded data
  22851. child._decode(input, options);
  22852. });
  22853. } // Decode contained/encoded by schema, only in bit or octet strings
  22854. if (state.contains && (state.tag === 'octstr' || state.tag === 'bitstr')) {
  22855. var data = new DecoderBuffer(result);
  22856. result = this._getUse(state.contains, input._reporterState.obj)._decode(data, options);
  22857. }
  22858. } // Pop object
  22859. if (state.obj && present) result = input.leaveObject(prevObj); // Set key
  22860. if (state.key !== null && (result !== null || present === true)) input.leaveKey(prevKey, state.key, result);else if (prevKey !== null) input.exitKey(prevKey);
  22861. return result;
  22862. };
  22863. Node.prototype._decodeGeneric = function decodeGeneric(tag, input, options) {
  22864. var state = this._baseState;
  22865. if (tag === 'seq' || tag === 'set') return null;
  22866. 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);
  22867. if (state.use !== null) {
  22868. return this._getUse(state.use, input._reporterState.obj)._decode(input, options);
  22869. } else {
  22870. return input.error('unknown tag: ' + tag);
  22871. }
  22872. };
  22873. Node.prototype._getUse = function _getUse(entity, obj) {
  22874. var state = this._baseState; // Create altered use decoder if implicit is set
  22875. state.useDecoder = this._use(entity, obj);
  22876. assert(state.useDecoder._baseState.parent === null);
  22877. state.useDecoder = state.useDecoder._baseState.children[0];
  22878. if (state.implicit !== state.useDecoder._baseState.implicit) {
  22879. state.useDecoder = state.useDecoder.clone();
  22880. state.useDecoder._baseState.implicit = state.implicit;
  22881. }
  22882. return state.useDecoder;
  22883. };
  22884. Node.prototype._decodeChoice = function decodeChoice(input, options) {
  22885. var state = this._baseState;
  22886. var result = null;
  22887. var match = false;
  22888. Object.keys(state.choice).some(function (key) {
  22889. var save = input.save();
  22890. var node = state.choice[key];
  22891. try {
  22892. var value = node._decode(input, options);
  22893. if (input.isError(value)) return false;
  22894. result = {
  22895. type: key,
  22896. value: value
  22897. };
  22898. match = true;
  22899. } catch (e) {
  22900. input.restore(save);
  22901. return false;
  22902. }
  22903. return true;
  22904. }, this);
  22905. if (!match) return input.error('Choice not matched');
  22906. return result;
  22907. }; //
  22908. // Encoding
  22909. //
  22910. Node.prototype._createEncoderBuffer = function createEncoderBuffer(data) {
  22911. return new EncoderBuffer(data, this.reporter);
  22912. };
  22913. Node.prototype._encode = function encode(data, reporter, parent) {
  22914. var state = this._baseState;
  22915. if (state['default'] !== null && state['default'] === data) return;
  22916. var result = this._encodeValue(data, reporter, parent);
  22917. if (result === undefined) return;
  22918. if (this._skipDefault(result, reporter, parent)) return;
  22919. return result;
  22920. };
  22921. Node.prototype._encodeValue = function encode(data, reporter, parent) {
  22922. var state = this._baseState; // Decode root node
  22923. if (state.parent === null) return state.children[0]._encode(data, reporter || new Reporter());
  22924. var result = null; // Set reporter to share it with a child class
  22925. this.reporter = reporter; // Check if data is there
  22926. if (state.optional && data === undefined) {
  22927. if (state['default'] !== null) data = state['default'];else return;
  22928. } // Encode children first
  22929. var content = null;
  22930. var primitive = false;
  22931. if (state.any) {
  22932. // Anything that was given is translated to buffer
  22933. result = this._createEncoderBuffer(data);
  22934. } else if (state.choice) {
  22935. result = this._encodeChoice(data, reporter);
  22936. } else if (state.contains) {
  22937. content = this._getUse(state.contains, parent)._encode(data, reporter);
  22938. primitive = true;
  22939. } else if (state.children) {
  22940. content = state.children.map(function (child) {
  22941. if (child._baseState.tag === 'null_') return child._encode(null, reporter, data);
  22942. if (child._baseState.key === null) return reporter.error('Child should have a key');
  22943. var prevKey = reporter.enterKey(child._baseState.key);
  22944. if (_typeof(data) !== 'object') return reporter.error('Child expected, but input is not object');
  22945. var res = child._encode(data[child._baseState.key], reporter, data);
  22946. reporter.leaveKey(prevKey);
  22947. return res;
  22948. }, this).filter(function (child) {
  22949. return child;
  22950. });
  22951. content = this._createEncoderBuffer(content);
  22952. } else {
  22953. if (state.tag === 'seqof' || state.tag === 'setof') {
  22954. // TODO(indutny): this should be thrown on DSL level
  22955. if (!(state.args && state.args.length === 1)) return reporter.error('Too many args for : ' + state.tag);
  22956. if (!Array.isArray(data)) return reporter.error('seqof/setof, but data is not Array');
  22957. var child = this.clone();
  22958. child._baseState.implicit = null;
  22959. content = this._createEncoderBuffer(data.map(function (item) {
  22960. var state = this._baseState;
  22961. return this._getUse(state.args[0], data)._encode(item, reporter);
  22962. }, child));
  22963. } else if (state.use !== null) {
  22964. result = this._getUse(state.use, parent)._encode(data, reporter);
  22965. } else {
  22966. content = this._encodePrimitive(state.tag, data);
  22967. primitive = true;
  22968. }
  22969. } // Encode data itself
  22970. if (!state.any && state.choice === null) {
  22971. var tag = state.implicit !== null ? state.implicit : state.tag;
  22972. var cls = state.implicit === null ? 'universal' : 'context';
  22973. if (tag === null) {
  22974. if (state.use === null) reporter.error('Tag could be omitted only for .use()');
  22975. } else {
  22976. if (state.use === null) result = this._encodeComposite(tag, primitive, cls, content);
  22977. }
  22978. } // Wrap in explicit
  22979. if (state.explicit !== null) result = this._encodeComposite(state.explicit, false, 'context', result);
  22980. return result;
  22981. };
  22982. Node.prototype._encodeChoice = function encodeChoice(data, reporter) {
  22983. var state = this._baseState;
  22984. var node = state.choice[data.type];
  22985. if (!node) {
  22986. assert(false, data.type + ' not found in ' + JSON.stringify(Object.keys(state.choice)));
  22987. }
  22988. return node._encode(data.value, reporter);
  22989. };
  22990. Node.prototype._encodePrimitive = function encodePrimitive(tag, data) {
  22991. var state = this._baseState;
  22992. 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);
  22993. };
  22994. Node.prototype._isNumstr = function isNumstr(str) {
  22995. return /^[0-9 ]*$/.test(str);
  22996. };
  22997. Node.prototype._isPrintstr = function isPrintstr(str) {
  22998. return /^[A-Za-z0-9 '()+,-./:=?]*$/.test(str);
  22999. };
  23000. },{"../base/buffer":169,"../base/reporter":172,"minimalistic-assert":437}],172:[function(require,module,exports){
  23001. 'use strict';
  23002. var inherits = require('inherits');
  23003. function Reporter(options) {
  23004. this._reporterState = {
  23005. obj: null,
  23006. path: [],
  23007. options: options || {},
  23008. errors: []
  23009. };
  23010. }
  23011. exports.Reporter = Reporter;
  23012. Reporter.prototype.isError = function isError(obj) {
  23013. return obj instanceof ReporterError;
  23014. };
  23015. Reporter.prototype.save = function save() {
  23016. var state = this._reporterState;
  23017. return {
  23018. obj: state.obj,
  23019. pathLen: state.path.length
  23020. };
  23021. };
  23022. Reporter.prototype.restore = function restore(data) {
  23023. var state = this._reporterState;
  23024. state.obj = data.obj;
  23025. state.path = state.path.slice(0, data.pathLen);
  23026. };
  23027. Reporter.prototype.enterKey = function enterKey(key) {
  23028. return this._reporterState.path.push(key);
  23029. };
  23030. Reporter.prototype.exitKey = function exitKey(index) {
  23031. var state = this._reporterState;
  23032. state.path = state.path.slice(0, index - 1);
  23033. };
  23034. Reporter.prototype.leaveKey = function leaveKey(index, key, value) {
  23035. var state = this._reporterState;
  23036. this.exitKey(index);
  23037. if (state.obj !== null) state.obj[key] = value;
  23038. };
  23039. Reporter.prototype.path = function path() {
  23040. return this._reporterState.path.join('/');
  23041. };
  23042. Reporter.prototype.enterObject = function enterObject() {
  23043. var state = this._reporterState;
  23044. var prev = state.obj;
  23045. state.obj = {};
  23046. return prev;
  23047. };
  23048. Reporter.prototype.leaveObject = function leaveObject(prev) {
  23049. var state = this._reporterState;
  23050. var now = state.obj;
  23051. state.obj = prev;
  23052. return now;
  23053. };
  23054. Reporter.prototype.error = function error(msg) {
  23055. var err;
  23056. var state = this._reporterState;
  23057. var inherited = msg instanceof ReporterError;
  23058. if (inherited) {
  23059. err = msg;
  23060. } else {
  23061. err = new ReporterError(state.path.map(function (elem) {
  23062. return '[' + JSON.stringify(elem) + ']';
  23063. }).join(''), msg.message || msg, msg.stack);
  23064. }
  23065. if (!state.options.partial) throw err;
  23066. if (!inherited) state.errors.push(err);
  23067. return err;
  23068. };
  23069. Reporter.prototype.wrapResult = function wrapResult(result) {
  23070. var state = this._reporterState;
  23071. if (!state.options.partial) return result;
  23072. return {
  23073. result: this.isError(result) ? null : result,
  23074. errors: state.errors
  23075. };
  23076. };
  23077. function ReporterError(path, msg) {
  23078. this.path = path;
  23079. this.rethrow(msg);
  23080. }
  23081. inherits(ReporterError, Error);
  23082. ReporterError.prototype.rethrow = function rethrow(msg) {
  23083. this.message = msg + ' at: ' + (this.path || '(shallow)');
  23084. if (Error.captureStackTrace) Error.captureStackTrace(this, ReporterError);
  23085. if (!this.stack) {
  23086. try {
  23087. // IE only adds stack when thrown
  23088. throw new Error(this.message);
  23089. } catch (e) {
  23090. this.stack = e.stack;
  23091. }
  23092. }
  23093. return this;
  23094. };
  23095. },{"inherits":387}],173:[function(require,module,exports){
  23096. 'use strict'; // Helper
  23097. function reverse(map) {
  23098. var res = {};
  23099. Object.keys(map).forEach(function (key) {
  23100. // Convert key to integer if it is stringified
  23101. if ((key | 0) == key) key = key | 0;
  23102. var value = map[key];
  23103. res[value] = key;
  23104. });
  23105. return res;
  23106. }
  23107. exports.tagClass = {
  23108. 0: 'universal',
  23109. 1: 'application',
  23110. 2: 'context',
  23111. 3: 'private'
  23112. };
  23113. exports.tagClassByName = reverse(exports.tagClass);
  23114. exports.tag = {
  23115. 0x00: 'end',
  23116. 0x01: 'bool',
  23117. 0x02: 'int',
  23118. 0x03: 'bitstr',
  23119. 0x04: 'octstr',
  23120. 0x05: 'null_',
  23121. 0x06: 'objid',
  23122. 0x07: 'objDesc',
  23123. 0x08: 'external',
  23124. 0x09: 'real',
  23125. 0x0a: 'enum',
  23126. 0x0b: 'embed',
  23127. 0x0c: 'utf8str',
  23128. 0x0d: 'relativeOid',
  23129. 0x10: 'seq',
  23130. 0x11: 'set',
  23131. 0x12: 'numstr',
  23132. 0x13: 'printstr',
  23133. 0x14: 't61str',
  23134. 0x15: 'videostr',
  23135. 0x16: 'ia5str',
  23136. 0x17: 'utctime',
  23137. 0x18: 'gentime',
  23138. 0x19: 'graphstr',
  23139. 0x1a: 'iso646str',
  23140. 0x1b: 'genstr',
  23141. 0x1c: 'unistr',
  23142. 0x1d: 'charstr',
  23143. 0x1e: 'bmpstr'
  23144. };
  23145. exports.tagByName = reverse(exports.tag);
  23146. },{}],174:[function(require,module,exports){
  23147. 'use strict';
  23148. var constants = exports; // Helper
  23149. constants._reverse = function reverse(map) {
  23150. var res = {};
  23151. Object.keys(map).forEach(function (key) {
  23152. // Convert key to integer if it is stringified
  23153. if ((key | 0) == key) key = key | 0;
  23154. var value = map[key];
  23155. res[value] = key;
  23156. });
  23157. return res;
  23158. };
  23159. constants.der = require('./der');
  23160. },{"./der":173}],175:[function(require,module,exports){
  23161. 'use strict';
  23162. var inherits = require('inherits');
  23163. var bignum = require('bn.js');
  23164. var DecoderBuffer = require('../base/buffer').DecoderBuffer;
  23165. var Node = require('../base/node'); // Import DER constants
  23166. var der = require('../constants/der');
  23167. function DERDecoder(entity) {
  23168. this.enc = 'der';
  23169. this.name = entity.name;
  23170. this.entity = entity; // Construct base tree
  23171. this.tree = new DERNode();
  23172. this.tree._init(entity.body);
  23173. }
  23174. module.exports = DERDecoder;
  23175. DERDecoder.prototype.decode = function decode(data, options) {
  23176. if (!DecoderBuffer.isDecoderBuffer(data)) {
  23177. data = new DecoderBuffer(data, options);
  23178. }
  23179. return this.tree._decode(data, options);
  23180. }; // Tree methods
  23181. function DERNode(parent) {
  23182. Node.call(this, 'der', parent);
  23183. }
  23184. inherits(DERNode, Node);
  23185. DERNode.prototype._peekTag = function peekTag(buffer, tag, any) {
  23186. if (buffer.isEmpty()) return false;
  23187. var state = buffer.save();
  23188. var decodedTag = derDecodeTag(buffer, 'Failed to peek tag: "' + tag + '"');
  23189. if (buffer.isError(decodedTag)) return decodedTag;
  23190. buffer.restore(state);
  23191. return decodedTag.tag === tag || decodedTag.tagStr === tag || decodedTag.tagStr + 'of' === tag || any;
  23192. };
  23193. DERNode.prototype._decodeTag = function decodeTag(buffer, tag, any) {
  23194. var decodedTag = derDecodeTag(buffer, 'Failed to decode tag of "' + tag + '"');
  23195. if (buffer.isError(decodedTag)) return decodedTag;
  23196. var len = derDecodeLen(buffer, decodedTag.primitive, 'Failed to get length of "' + tag + '"'); // Failure
  23197. if (buffer.isError(len)) return len;
  23198. if (!any && decodedTag.tag !== tag && decodedTag.tagStr !== tag && decodedTag.tagStr + 'of' !== tag) {
  23199. return buffer.error('Failed to match tag: "' + tag + '"');
  23200. }
  23201. if (decodedTag.primitive || len !== null) return buffer.skip(len, 'Failed to match body of: "' + tag + '"'); // Indefinite length... find END tag
  23202. var state = buffer.save();
  23203. var res = this._skipUntilEnd(buffer, 'Failed to skip indefinite length body: "' + this.tag + '"');
  23204. if (buffer.isError(res)) return res;
  23205. len = buffer.offset - state.offset;
  23206. buffer.restore(state);
  23207. return buffer.skip(len, 'Failed to match body of: "' + tag + '"');
  23208. };
  23209. DERNode.prototype._skipUntilEnd = function skipUntilEnd(buffer, fail) {
  23210. for (;;) {
  23211. var tag = derDecodeTag(buffer, fail);
  23212. if (buffer.isError(tag)) return tag;
  23213. var len = derDecodeLen(buffer, tag.primitive, fail);
  23214. if (buffer.isError(len)) return len;
  23215. var res = void 0;
  23216. if (tag.primitive || len !== null) res = buffer.skip(len);else res = this._skipUntilEnd(buffer, fail); // Failure
  23217. if (buffer.isError(res)) return res;
  23218. if (tag.tagStr === 'end') break;
  23219. }
  23220. };
  23221. DERNode.prototype._decodeList = function decodeList(buffer, tag, decoder, options) {
  23222. var result = [];
  23223. while (!buffer.isEmpty()) {
  23224. var possibleEnd = this._peekTag(buffer, 'end');
  23225. if (buffer.isError(possibleEnd)) return possibleEnd;
  23226. var res = decoder.decode(buffer, 'der', options);
  23227. if (buffer.isError(res) && possibleEnd) break;
  23228. result.push(res);
  23229. }
  23230. return result;
  23231. };
  23232. DERNode.prototype._decodeStr = function decodeStr(buffer, tag) {
  23233. if (tag === 'bitstr') {
  23234. var unused = buffer.readUInt8();
  23235. if (buffer.isError(unused)) return unused;
  23236. return {
  23237. unused: unused,
  23238. data: buffer.raw()
  23239. };
  23240. } else if (tag === 'bmpstr') {
  23241. var raw = buffer.raw();
  23242. if (raw.length % 2 === 1) return buffer.error('Decoding of string type: bmpstr length mismatch');
  23243. var str = '';
  23244. for (var i = 0; i < raw.length / 2; i++) {
  23245. str += String.fromCharCode(raw.readUInt16BE(i * 2));
  23246. }
  23247. return str;
  23248. } else if (tag === 'numstr') {
  23249. var numstr = buffer.raw().toString('ascii');
  23250. if (!this._isNumstr(numstr)) {
  23251. return buffer.error('Decoding of string type: ' + 'numstr unsupported characters');
  23252. }
  23253. return numstr;
  23254. } else if (tag === 'octstr') {
  23255. return buffer.raw();
  23256. } else if (tag === 'objDesc') {
  23257. return buffer.raw();
  23258. } else if (tag === 'printstr') {
  23259. var printstr = buffer.raw().toString('ascii');
  23260. if (!this._isPrintstr(printstr)) {
  23261. return buffer.error('Decoding of string type: ' + 'printstr unsupported characters');
  23262. }
  23263. return printstr;
  23264. } else if (/str$/.test(tag)) {
  23265. return buffer.raw().toString();
  23266. } else {
  23267. return buffer.error('Decoding of string type: ' + tag + ' unsupported');
  23268. }
  23269. };
  23270. DERNode.prototype._decodeObjid = function decodeObjid(buffer, values, relative) {
  23271. var result;
  23272. var identifiers = [];
  23273. var ident = 0;
  23274. var subident = 0;
  23275. while (!buffer.isEmpty()) {
  23276. subident = buffer.readUInt8();
  23277. ident <<= 7;
  23278. ident |= subident & 0x7f;
  23279. if ((subident & 0x80) === 0) {
  23280. identifiers.push(ident);
  23281. ident = 0;
  23282. }
  23283. }
  23284. if (subident & 0x80) identifiers.push(ident);
  23285. var first = identifiers[0] / 40 | 0;
  23286. var second = identifiers[0] % 40;
  23287. if (relative) result = identifiers;else result = [first, second].concat(identifiers.slice(1));
  23288. if (values) {
  23289. var tmp = values[result.join(' ')];
  23290. if (tmp === undefined) tmp = values[result.join('.')];
  23291. if (tmp !== undefined) result = tmp;
  23292. }
  23293. return result;
  23294. };
  23295. DERNode.prototype._decodeTime = function decodeTime(buffer, tag) {
  23296. var str = buffer.raw().toString();
  23297. var year;
  23298. var mon;
  23299. var day;
  23300. var hour;
  23301. var min;
  23302. var sec;
  23303. if (tag === 'gentime') {
  23304. year = str.slice(0, 4) | 0;
  23305. mon = str.slice(4, 6) | 0;
  23306. day = str.slice(6, 8) | 0;
  23307. hour = str.slice(8, 10) | 0;
  23308. min = str.slice(10, 12) | 0;
  23309. sec = str.slice(12, 14) | 0;
  23310. } else if (tag === 'utctime') {
  23311. year = str.slice(0, 2) | 0;
  23312. mon = str.slice(2, 4) | 0;
  23313. day = str.slice(4, 6) | 0;
  23314. hour = str.slice(6, 8) | 0;
  23315. min = str.slice(8, 10) | 0;
  23316. sec = str.slice(10, 12) | 0;
  23317. if (year < 70) year = 2000 + year;else year = 1900 + year;
  23318. } else {
  23319. return buffer.error('Decoding ' + tag + ' time is not supported yet');
  23320. }
  23321. return Date.UTC(year, mon - 1, day, hour, min, sec, 0);
  23322. };
  23323. DERNode.prototype._decodeNull = function decodeNull() {
  23324. return null;
  23325. };
  23326. DERNode.prototype._decodeBool = function decodeBool(buffer) {
  23327. var res = buffer.readUInt8();
  23328. if (buffer.isError(res)) return res;else return res !== 0;
  23329. };
  23330. DERNode.prototype._decodeInt = function decodeInt(buffer, values) {
  23331. // Bigint, return as it is (assume big endian)
  23332. var raw = buffer.raw();
  23333. var res = new bignum(raw);
  23334. if (values) res = values[res.toString(10)] || res;
  23335. return res;
  23336. };
  23337. DERNode.prototype._use = function use(entity, obj) {
  23338. if (typeof entity === 'function') entity = entity(obj);
  23339. return entity._getDecoder('der').tree;
  23340. }; // Utility methods
  23341. function derDecodeTag(buf, fail) {
  23342. var tag = buf.readUInt8(fail);
  23343. if (buf.isError(tag)) return tag;
  23344. var cls = der.tagClass[tag >> 6];
  23345. var primitive = (tag & 0x20) === 0; // Multi-octet tag - load
  23346. if ((tag & 0x1f) === 0x1f) {
  23347. var oct = tag;
  23348. tag = 0;
  23349. while ((oct & 0x80) === 0x80) {
  23350. oct = buf.readUInt8(fail);
  23351. if (buf.isError(oct)) return oct;
  23352. tag <<= 7;
  23353. tag |= oct & 0x7f;
  23354. }
  23355. } else {
  23356. tag &= 0x1f;
  23357. }
  23358. var tagStr = der.tag[tag];
  23359. return {
  23360. cls: cls,
  23361. primitive: primitive,
  23362. tag: tag,
  23363. tagStr: tagStr
  23364. };
  23365. }
  23366. function derDecodeLen(buf, primitive, fail) {
  23367. var len = buf.readUInt8(fail);
  23368. if (buf.isError(len)) return len; // Indefinite form
  23369. if (!primitive && len === 0x80) return null; // Definite form
  23370. if ((len & 0x80) === 0) {
  23371. // Short form
  23372. return len;
  23373. } // Long form
  23374. var num = len & 0x7f;
  23375. if (num > 4) return buf.error('length octect is too long');
  23376. len = 0;
  23377. for (var i = 0; i < num; i++) {
  23378. len <<= 8;
  23379. var j = buf.readUInt8(fail);
  23380. if (buf.isError(j)) return j;
  23381. len |= j;
  23382. }
  23383. return len;
  23384. }
  23385. },{"../base/buffer":169,"../base/node":171,"../constants/der":173,"bn.js":181,"inherits":387}],176:[function(require,module,exports){
  23386. 'use strict';
  23387. var decoders = exports;
  23388. decoders.der = require('./der');
  23389. decoders.pem = require('./pem');
  23390. },{"./der":175,"./pem":177}],177:[function(require,module,exports){
  23391. 'use strict';
  23392. var inherits = require('inherits');
  23393. var Buffer = require('safer-buffer').Buffer;
  23394. var DERDecoder = require('./der');
  23395. function PEMDecoder(entity) {
  23396. DERDecoder.call(this, entity);
  23397. this.enc = 'pem';
  23398. }
  23399. inherits(PEMDecoder, DERDecoder);
  23400. module.exports = PEMDecoder;
  23401. PEMDecoder.prototype.decode = function decode(data, options) {
  23402. var lines = data.toString().split(/[\r\n]+/g);
  23403. var label = options.label.toUpperCase();
  23404. var re = /^-----(BEGIN|END) ([^-]+)-----$/;
  23405. var start = -1;
  23406. var end = -1;
  23407. for (var i = 0; i < lines.length; i++) {
  23408. var match = lines[i].match(re);
  23409. if (match === null) continue;
  23410. if (match[2] !== label) continue;
  23411. if (start === -1) {
  23412. if (match[1] !== 'BEGIN') break;
  23413. start = i;
  23414. } else {
  23415. if (match[1] !== 'END') break;
  23416. end = i;
  23417. break;
  23418. }
  23419. }
  23420. if (start === -1 || end === -1) throw new Error('PEM section not found for: ' + label);
  23421. var base64 = lines.slice(start + 1, end).join(''); // Remove excessive symbols
  23422. base64.replace(/[^a-z0-9+/=]+/gi, '');
  23423. var input = Buffer.from(base64, 'base64');
  23424. return DERDecoder.prototype.decode.call(this, input, options);
  23425. };
  23426. },{"./der":175,"inherits":387,"safer-buffer":495}],178:[function(require,module,exports){
  23427. 'use strict';
  23428. var inherits = require('inherits');
  23429. var Buffer = require('safer-buffer').Buffer;
  23430. var Node = require('../base/node'); // Import DER constants
  23431. var der = require('../constants/der');
  23432. function DEREncoder(entity) {
  23433. this.enc = 'der';
  23434. this.name = entity.name;
  23435. this.entity = entity; // Construct base tree
  23436. this.tree = new DERNode();
  23437. this.tree._init(entity.body);
  23438. }
  23439. module.exports = DEREncoder;
  23440. DEREncoder.prototype.encode = function encode(data, reporter) {
  23441. return this.tree._encode(data, reporter).join();
  23442. }; // Tree methods
  23443. function DERNode(parent) {
  23444. Node.call(this, 'der', parent);
  23445. }
  23446. inherits(DERNode, Node);
  23447. DERNode.prototype._encodeComposite = function encodeComposite(tag, primitive, cls, content) {
  23448. var encodedTag = encodeTag(tag, primitive, cls, this.reporter); // Short form
  23449. if (content.length < 0x80) {
  23450. var _header = Buffer.alloc(2);
  23451. _header[0] = encodedTag;
  23452. _header[1] = content.length;
  23453. return this._createEncoderBuffer([_header, content]);
  23454. } // Long form
  23455. // Count octets required to store length
  23456. var lenOctets = 1;
  23457. for (var i = content.length; i >= 0x100; i >>= 8) {
  23458. lenOctets++;
  23459. }
  23460. var header = Buffer.alloc(1 + 1 + lenOctets);
  23461. header[0] = encodedTag;
  23462. header[1] = 0x80 | lenOctets;
  23463. for (var _i = 1 + lenOctets, j = content.length; j > 0; _i--, j >>= 8) {
  23464. header[_i] = j & 0xff;
  23465. }
  23466. return this._createEncoderBuffer([header, content]);
  23467. };
  23468. DERNode.prototype._encodeStr = function encodeStr(str, tag) {
  23469. if (tag === 'bitstr') {
  23470. return this._createEncoderBuffer([str.unused | 0, str.data]);
  23471. } else if (tag === 'bmpstr') {
  23472. var buf = Buffer.alloc(str.length * 2);
  23473. for (var i = 0; i < str.length; i++) {
  23474. buf.writeUInt16BE(str.charCodeAt(i), i * 2);
  23475. }
  23476. return this._createEncoderBuffer(buf);
  23477. } else if (tag === 'numstr') {
  23478. if (!this._isNumstr(str)) {
  23479. return this.reporter.error('Encoding of string type: numstr supports ' + 'only digits and space');
  23480. }
  23481. return this._createEncoderBuffer(str);
  23482. } else if (tag === 'printstr') {
  23483. if (!this._isPrintstr(str)) {
  23484. 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');
  23485. }
  23486. return this._createEncoderBuffer(str);
  23487. } else if (/str$/.test(tag)) {
  23488. return this._createEncoderBuffer(str);
  23489. } else if (tag === 'objDesc') {
  23490. return this._createEncoderBuffer(str);
  23491. } else {
  23492. return this.reporter.error('Encoding of string type: ' + tag + ' unsupported');
  23493. }
  23494. };
  23495. DERNode.prototype._encodeObjid = function encodeObjid(id, values, relative) {
  23496. if (typeof id === 'string') {
  23497. if (!values) return this.reporter.error('string objid given, but no values map found');
  23498. if (!values.hasOwnProperty(id)) return this.reporter.error('objid not found in values map');
  23499. id = values[id].split(/[\s.]+/g);
  23500. for (var i = 0; i < id.length; i++) {
  23501. id[i] |= 0;
  23502. }
  23503. } else if (Array.isArray(id)) {
  23504. id = id.slice();
  23505. for (var _i2 = 0; _i2 < id.length; _i2++) {
  23506. id[_i2] |= 0;
  23507. }
  23508. }
  23509. if (!Array.isArray(id)) {
  23510. return this.reporter.error('objid() should be either array or string, ' + 'got: ' + JSON.stringify(id));
  23511. }
  23512. if (!relative) {
  23513. if (id[1] >= 40) return this.reporter.error('Second objid identifier OOB');
  23514. id.splice(0, 2, id[0] * 40 + id[1]);
  23515. } // Count number of octets
  23516. var size = 0;
  23517. for (var _i3 = 0; _i3 < id.length; _i3++) {
  23518. var ident = id[_i3];
  23519. for (size++; ident >= 0x80; ident >>= 7) {
  23520. size++;
  23521. }
  23522. }
  23523. var objid = Buffer.alloc(size);
  23524. var offset = objid.length - 1;
  23525. for (var _i4 = id.length - 1; _i4 >= 0; _i4--) {
  23526. var _ident = id[_i4];
  23527. objid[offset--] = _ident & 0x7f;
  23528. while ((_ident >>= 7) > 0) {
  23529. objid[offset--] = 0x80 | _ident & 0x7f;
  23530. }
  23531. }
  23532. return this._createEncoderBuffer(objid);
  23533. };
  23534. function two(num) {
  23535. if (num < 10) return '0' + num;else return num;
  23536. }
  23537. DERNode.prototype._encodeTime = function encodeTime(time, tag) {
  23538. var str;
  23539. var date = new Date(time);
  23540. if (tag === 'gentime') {
  23541. str = [two(date.getUTCFullYear()), two(date.getUTCMonth() + 1), two(date.getUTCDate()), two(date.getUTCHours()), two(date.getUTCMinutes()), two(date.getUTCSeconds()), 'Z'].join('');
  23542. } else if (tag === 'utctime') {
  23543. str = [two(date.getUTCFullYear() % 100), two(date.getUTCMonth() + 1), two(date.getUTCDate()), two(date.getUTCHours()), two(date.getUTCMinutes()), two(date.getUTCSeconds()), 'Z'].join('');
  23544. } else {
  23545. this.reporter.error('Encoding ' + tag + ' time is not supported yet');
  23546. }
  23547. return this._encodeStr(str, 'octstr');
  23548. };
  23549. DERNode.prototype._encodeNull = function encodeNull() {
  23550. return this._createEncoderBuffer('');
  23551. };
  23552. DERNode.prototype._encodeInt = function encodeInt(num, values) {
  23553. if (typeof num === 'string') {
  23554. if (!values) return this.reporter.error('String int or enum given, but no values map');
  23555. if (!values.hasOwnProperty(num)) {
  23556. return this.reporter.error('Values map doesn\'t contain: ' + JSON.stringify(num));
  23557. }
  23558. num = values[num];
  23559. } // Bignum, assume big endian
  23560. if (typeof num !== 'number' && !Buffer.isBuffer(num)) {
  23561. var numArray = num.toArray();
  23562. if (!num.sign && numArray[0] & 0x80) {
  23563. numArray.unshift(0);
  23564. }
  23565. num = Buffer.from(numArray);
  23566. }
  23567. if (Buffer.isBuffer(num)) {
  23568. var _size = num.length;
  23569. if (num.length === 0) _size++;
  23570. var _out = Buffer.alloc(_size);
  23571. num.copy(_out);
  23572. if (num.length === 0) _out[0] = 0;
  23573. return this._createEncoderBuffer(_out);
  23574. }
  23575. if (num < 0x80) return this._createEncoderBuffer(num);
  23576. if (num < 0x100) return this._createEncoderBuffer([0, num]);
  23577. var size = 1;
  23578. for (var i = num; i >= 0x100; i >>= 8) {
  23579. size++;
  23580. }
  23581. var out = new Array(size);
  23582. for (var _i5 = out.length - 1; _i5 >= 0; _i5--) {
  23583. out[_i5] = num & 0xff;
  23584. num >>= 8;
  23585. }
  23586. if (out[0] & 0x80) {
  23587. out.unshift(0);
  23588. }
  23589. return this._createEncoderBuffer(Buffer.from(out));
  23590. };
  23591. DERNode.prototype._encodeBool = function encodeBool(value) {
  23592. return this._createEncoderBuffer(value ? 0xff : 0);
  23593. };
  23594. DERNode.prototype._use = function use(entity, obj) {
  23595. if (typeof entity === 'function') entity = entity(obj);
  23596. return entity._getEncoder('der').tree;
  23597. };
  23598. DERNode.prototype._skipDefault = function skipDefault(dataBuffer, reporter, parent) {
  23599. var state = this._baseState;
  23600. var i;
  23601. if (state['default'] === null) return false;
  23602. var data = dataBuffer.join();
  23603. if (state.defaultBuffer === undefined) state.defaultBuffer = this._encodeValue(state['default'], reporter, parent).join();
  23604. if (data.length !== state.defaultBuffer.length) return false;
  23605. for (i = 0; i < data.length; i++) {
  23606. if (data[i] !== state.defaultBuffer[i]) return false;
  23607. }
  23608. return true;
  23609. }; // Utility methods
  23610. function encodeTag(tag, primitive, cls, reporter) {
  23611. var res;
  23612. if (tag === 'seqof') tag = 'seq';else if (tag === 'setof') tag = 'set';
  23613. 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);
  23614. if (res >= 0x1f) return reporter.error('Multi-octet tag encoding unsupported');
  23615. if (!primitive) res |= 0x20;
  23616. res |= der.tagClassByName[cls || 'universal'] << 6;
  23617. return res;
  23618. }
  23619. },{"../base/node":171,"../constants/der":173,"inherits":387,"safer-buffer":495}],179:[function(require,module,exports){
  23620. 'use strict';
  23621. var encoders = exports;
  23622. encoders.der = require('./der');
  23623. encoders.pem = require('./pem');
  23624. },{"./der":178,"./pem":180}],180:[function(require,module,exports){
  23625. 'use strict';
  23626. var inherits = require('inherits');
  23627. var DEREncoder = require('./der');
  23628. function PEMEncoder(entity) {
  23629. DEREncoder.call(this, entity);
  23630. this.enc = 'pem';
  23631. }
  23632. inherits(PEMEncoder, DEREncoder);
  23633. module.exports = PEMEncoder;
  23634. PEMEncoder.prototype.encode = function encode(data, options) {
  23635. var buf = DEREncoder.prototype.encode.call(this, data);
  23636. var p = buf.toString('base64');
  23637. var out = ['-----BEGIN ' + options.label + '-----'];
  23638. for (var i = 0; i < p.length; i += 64) {
  23639. out.push(p.slice(i, i + 64));
  23640. }
  23641. out.push('-----END ' + options.label + '-----');
  23642. return out.join('\n');
  23643. };
  23644. },{"./der":178,"inherits":387}],181:[function(require,module,exports){
  23645. "use strict";
  23646. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  23647. (function (module, exports) {
  23648. 'use strict'; // Utils
  23649. function assert(val, msg) {
  23650. if (!val) throw new Error(msg || 'Assertion failed');
  23651. } // Could use `inherits` module, but don't want to move from single file
  23652. // architecture yet.
  23653. function inherits(ctor, superCtor) {
  23654. ctor.super_ = superCtor;
  23655. var TempCtor = function TempCtor() {};
  23656. TempCtor.prototype = superCtor.prototype;
  23657. ctor.prototype = new TempCtor();
  23658. ctor.prototype.constructor = ctor;
  23659. } // BN
  23660. function BN(number, base, endian) {
  23661. if (BN.isBN(number)) {
  23662. return number;
  23663. }
  23664. this.negative = 0;
  23665. this.words = null;
  23666. this.length = 0; // Reduction context
  23667. this.red = null;
  23668. if (number !== null) {
  23669. if (base === 'le' || base === 'be') {
  23670. endian = base;
  23671. base = 10;
  23672. }
  23673. this._init(number || 0, base || 10, endian || 'be');
  23674. }
  23675. }
  23676. if (_typeof(module) === 'object') {
  23677. module.exports = BN;
  23678. } else {
  23679. exports.BN = BN;
  23680. }
  23681. BN.BN = BN;
  23682. BN.wordSize = 26;
  23683. var Buffer;
  23684. try {
  23685. Buffer = require('buffer').Buffer;
  23686. } catch (e) {}
  23687. BN.isBN = function isBN(num) {
  23688. if (num instanceof BN) {
  23689. return true;
  23690. }
  23691. return num !== null && _typeof(num) === 'object' && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
  23692. };
  23693. BN.max = function max(left, right) {
  23694. if (left.cmp(right) > 0) return left;
  23695. return right;
  23696. };
  23697. BN.min = function min(left, right) {
  23698. if (left.cmp(right) < 0) return left;
  23699. return right;
  23700. };
  23701. BN.prototype._init = function init(number, base, endian) {
  23702. if (typeof number === 'number') {
  23703. return this._initNumber(number, base, endian);
  23704. }
  23705. if (_typeof(number) === 'object') {
  23706. return this._initArray(number, base, endian);
  23707. }
  23708. if (base === 'hex') {
  23709. base = 16;
  23710. }
  23711. assert(base === (base | 0) && base >= 2 && base <= 36);
  23712. number = number.toString().replace(/\s+/g, '');
  23713. var start = 0;
  23714. if (number[0] === '-') {
  23715. start++;
  23716. }
  23717. if (base === 16) {
  23718. this._parseHex(number, start);
  23719. } else {
  23720. this._parseBase(number, base, start);
  23721. }
  23722. if (number[0] === '-') {
  23723. this.negative = 1;
  23724. }
  23725. this.strip();
  23726. if (endian !== 'le') return;
  23727. this._initArray(this.toArray(), base, endian);
  23728. };
  23729. BN.prototype._initNumber = function _initNumber(number, base, endian) {
  23730. if (number < 0) {
  23731. this.negative = 1;
  23732. number = -number;
  23733. }
  23734. if (number < 0x4000000) {
  23735. this.words = [number & 0x3ffffff];
  23736. this.length = 1;
  23737. } else if (number < 0x10000000000000) {
  23738. this.words = [number & 0x3ffffff, number / 0x4000000 & 0x3ffffff];
  23739. this.length = 2;
  23740. } else {
  23741. assert(number < 0x20000000000000); // 2 ^ 53 (unsafe)
  23742. this.words = [number & 0x3ffffff, number / 0x4000000 & 0x3ffffff, 1];
  23743. this.length = 3;
  23744. }
  23745. if (endian !== 'le') return; // Reverse the bytes
  23746. this._initArray(this.toArray(), base, endian);
  23747. };
  23748. BN.prototype._initArray = function _initArray(number, base, endian) {
  23749. // Perhaps a Uint8Array
  23750. assert(typeof number.length === 'number');
  23751. if (number.length <= 0) {
  23752. this.words = [0];
  23753. this.length = 1;
  23754. return this;
  23755. }
  23756. this.length = Math.ceil(number.length / 3);
  23757. this.words = new Array(this.length);
  23758. for (var i = 0; i < this.length; i++) {
  23759. this.words[i] = 0;
  23760. }
  23761. var j, w;
  23762. var off = 0;
  23763. if (endian === 'be') {
  23764. for (i = number.length - 1, j = 0; i >= 0; i -= 3) {
  23765. w = number[i] | number[i - 1] << 8 | number[i - 2] << 16;
  23766. this.words[j] |= w << off & 0x3ffffff;
  23767. this.words[j + 1] = w >>> 26 - off & 0x3ffffff;
  23768. off += 24;
  23769. if (off >= 26) {
  23770. off -= 26;
  23771. j++;
  23772. }
  23773. }
  23774. } else if (endian === 'le') {
  23775. for (i = 0, j = 0; i < number.length; i += 3) {
  23776. w = number[i] | number[i + 1] << 8 | number[i + 2] << 16;
  23777. this.words[j] |= w << off & 0x3ffffff;
  23778. this.words[j + 1] = w >>> 26 - off & 0x3ffffff;
  23779. off += 24;
  23780. if (off >= 26) {
  23781. off -= 26;
  23782. j++;
  23783. }
  23784. }
  23785. }
  23786. return this.strip();
  23787. };
  23788. function parseHex(str, start, end) {
  23789. var r = 0;
  23790. var len = Math.min(str.length, end);
  23791. for (var i = start; i < len; i++) {
  23792. var c = str.charCodeAt(i) - 48;
  23793. r <<= 4; // 'a' - 'f'
  23794. if (c >= 49 && c <= 54) {
  23795. r |= c - 49 + 0xa; // 'A' - 'F'
  23796. } else if (c >= 17 && c <= 22) {
  23797. r |= c - 17 + 0xa; // '0' - '9'
  23798. } else {
  23799. r |= c & 0xf;
  23800. }
  23801. }
  23802. return r;
  23803. }
  23804. BN.prototype._parseHex = function _parseHex(number, start) {
  23805. // Create possibly bigger array to ensure that it fits the number
  23806. this.length = Math.ceil((number.length - start) / 6);
  23807. this.words = new Array(this.length);
  23808. for (var i = 0; i < this.length; i++) {
  23809. this.words[i] = 0;
  23810. }
  23811. var j, w; // Scan 24-bit chunks and add them to the number
  23812. var off = 0;
  23813. for (i = number.length - 6, j = 0; i >= start; i -= 6) {
  23814. w = parseHex(number, i, i + 6);
  23815. this.words[j] |= w << off & 0x3ffffff; // NOTE: `0x3fffff` is intentional here, 26bits max shift + 24bit hex limb
  23816. this.words[j + 1] |= w >>> 26 - off & 0x3fffff;
  23817. off += 24;
  23818. if (off >= 26) {
  23819. off -= 26;
  23820. j++;
  23821. }
  23822. }
  23823. if (i + 6 !== start) {
  23824. w = parseHex(number, start, i + 6);
  23825. this.words[j] |= w << off & 0x3ffffff;
  23826. this.words[j + 1] |= w >>> 26 - off & 0x3fffff;
  23827. }
  23828. this.strip();
  23829. };
  23830. function parseBase(str, start, end, mul) {
  23831. var r = 0;
  23832. var len = Math.min(str.length, end);
  23833. for (var i = start; i < len; i++) {
  23834. var c = str.charCodeAt(i) - 48;
  23835. r *= mul; // 'a'
  23836. if (c >= 49) {
  23837. r += c - 49 + 0xa; // 'A'
  23838. } else if (c >= 17) {
  23839. r += c - 17 + 0xa; // '0' - '9'
  23840. } else {
  23841. r += c;
  23842. }
  23843. }
  23844. return r;
  23845. }
  23846. BN.prototype._parseBase = function _parseBase(number, base, start) {
  23847. // Initialize as zero
  23848. this.words = [0];
  23849. this.length = 1; // Find length of limb in base
  23850. for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) {
  23851. limbLen++;
  23852. }
  23853. limbLen--;
  23854. limbPow = limbPow / base | 0;
  23855. var total = number.length - start;
  23856. var mod = total % limbLen;
  23857. var end = Math.min(total, total - mod) + start;
  23858. var word = 0;
  23859. for (var i = start; i < end; i += limbLen) {
  23860. word = parseBase(number, i, i + limbLen, base);
  23861. this.imuln(limbPow);
  23862. if (this.words[0] + word < 0x4000000) {
  23863. this.words[0] += word;
  23864. } else {
  23865. this._iaddn(word);
  23866. }
  23867. }
  23868. if (mod !== 0) {
  23869. var pow = 1;
  23870. word = parseBase(number, i, number.length, base);
  23871. for (i = 0; i < mod; i++) {
  23872. pow *= base;
  23873. }
  23874. this.imuln(pow);
  23875. if (this.words[0] + word < 0x4000000) {
  23876. this.words[0] += word;
  23877. } else {
  23878. this._iaddn(word);
  23879. }
  23880. }
  23881. };
  23882. BN.prototype.copy = function copy(dest) {
  23883. dest.words = new Array(this.length);
  23884. for (var i = 0; i < this.length; i++) {
  23885. dest.words[i] = this.words[i];
  23886. }
  23887. dest.length = this.length;
  23888. dest.negative = this.negative;
  23889. dest.red = this.red;
  23890. };
  23891. BN.prototype.clone = function clone() {
  23892. var r = new BN(null);
  23893. this.copy(r);
  23894. return r;
  23895. };
  23896. BN.prototype._expand = function _expand(size) {
  23897. while (this.length < size) {
  23898. this.words[this.length++] = 0;
  23899. }
  23900. return this;
  23901. }; // Remove leading `0` from `this`
  23902. BN.prototype.strip = function strip() {
  23903. while (this.length > 1 && this.words[this.length - 1] === 0) {
  23904. this.length--;
  23905. }
  23906. return this._normSign();
  23907. };
  23908. BN.prototype._normSign = function _normSign() {
  23909. // -0 = 0
  23910. if (this.length === 1 && this.words[0] === 0) {
  23911. this.negative = 0;
  23912. }
  23913. return this;
  23914. };
  23915. BN.prototype.inspect = function inspect() {
  23916. return (this.red ? '<BN-R: ' : '<BN: ') + this.toString(16) + '>';
  23917. };
  23918. /*
  23919. var zeros = [];
  23920. var groupSizes = [];
  23921. var groupBases = [];
  23922. var s = '';
  23923. var i = -1;
  23924. while (++i < BN.wordSize) {
  23925. zeros[i] = s;
  23926. s += '0';
  23927. }
  23928. groupSizes[0] = 0;
  23929. groupSizes[1] = 0;
  23930. groupBases[0] = 0;
  23931. groupBases[1] = 0;
  23932. var base = 2 - 1;
  23933. while (++base < 36 + 1) {
  23934. var groupSize = 0;
  23935. var groupBase = 1;
  23936. while (groupBase < (1 << BN.wordSize) / base) {
  23937. groupBase *= base;
  23938. groupSize += 1;
  23939. }
  23940. groupSizes[base] = groupSize;
  23941. groupBases[base] = groupBase;
  23942. }
  23943. */
  23944. 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'];
  23945. 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];
  23946. 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];
  23947. BN.prototype.toString = function toString(base, padding) {
  23948. base = base || 10;
  23949. padding = padding | 0 || 1;
  23950. var out;
  23951. if (base === 16 || base === 'hex') {
  23952. out = '';
  23953. var off = 0;
  23954. var carry = 0;
  23955. for (var i = 0; i < this.length; i++) {
  23956. var w = this.words[i];
  23957. var word = ((w << off | carry) & 0xffffff).toString(16);
  23958. carry = w >>> 24 - off & 0xffffff;
  23959. if (carry !== 0 || i !== this.length - 1) {
  23960. out = zeros[6 - word.length] + word + out;
  23961. } else {
  23962. out = word + out;
  23963. }
  23964. off += 2;
  23965. if (off >= 26) {
  23966. off -= 26;
  23967. i--;
  23968. }
  23969. }
  23970. if (carry !== 0) {
  23971. out = carry.toString(16) + out;
  23972. }
  23973. while (out.length % padding !== 0) {
  23974. out = '0' + out;
  23975. }
  23976. if (this.negative !== 0) {
  23977. out = '-' + out;
  23978. }
  23979. return out;
  23980. }
  23981. if (base === (base | 0) && base >= 2 && base <= 36) {
  23982. // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base));
  23983. var groupSize = groupSizes[base]; // var groupBase = Math.pow(base, groupSize);
  23984. var groupBase = groupBases[base];
  23985. out = '';
  23986. var c = this.clone();
  23987. c.negative = 0;
  23988. while (!c.isZero()) {
  23989. var r = c.modn(groupBase).toString(base);
  23990. c = c.idivn(groupBase);
  23991. if (!c.isZero()) {
  23992. out = zeros[groupSize - r.length] + r + out;
  23993. } else {
  23994. out = r + out;
  23995. }
  23996. }
  23997. if (this.isZero()) {
  23998. out = '0' + out;
  23999. }
  24000. while (out.length % padding !== 0) {
  24001. out = '0' + out;
  24002. }
  24003. if (this.negative !== 0) {
  24004. out = '-' + out;
  24005. }
  24006. return out;
  24007. }
  24008. assert(false, 'Base should be between 2 and 36');
  24009. };
  24010. BN.prototype.toNumber = function toNumber() {
  24011. var ret = this.words[0];
  24012. if (this.length === 2) {
  24013. ret += this.words[1] * 0x4000000;
  24014. } else if (this.length === 3 && this.words[2] === 0x01) {
  24015. // NOTE: at this stage it is known that the top bit is set
  24016. ret += 0x10000000000000 + this.words[1] * 0x4000000;
  24017. } else if (this.length > 2) {
  24018. assert(false, 'Number can only safely store up to 53 bits');
  24019. }
  24020. return this.negative !== 0 ? -ret : ret;
  24021. };
  24022. BN.prototype.toJSON = function toJSON() {
  24023. return this.toString(16);
  24024. };
  24025. BN.prototype.toBuffer = function toBuffer(endian, length) {
  24026. assert(typeof Buffer !== 'undefined');
  24027. return this.toArrayLike(Buffer, endian, length);
  24028. };
  24029. BN.prototype.toArray = function toArray(endian, length) {
  24030. return this.toArrayLike(Array, endian, length);
  24031. };
  24032. BN.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) {
  24033. var byteLength = this.byteLength();
  24034. var reqLength = length || Math.max(1, byteLength);
  24035. assert(byteLength <= reqLength, 'byte array longer than desired length');
  24036. assert(reqLength > 0, 'Requested array length <= 0');
  24037. this.strip();
  24038. var littleEndian = endian === 'le';
  24039. var res = new ArrayType(reqLength);
  24040. var b, i;
  24041. var q = this.clone();
  24042. if (!littleEndian) {
  24043. // Assume big-endian
  24044. for (i = 0; i < reqLength - byteLength; i++) {
  24045. res[i] = 0;
  24046. }
  24047. for (i = 0; !q.isZero(); i++) {
  24048. b = q.andln(0xff);
  24049. q.iushrn(8);
  24050. res[reqLength - i - 1] = b;
  24051. }
  24052. } else {
  24053. for (i = 0; !q.isZero(); i++) {
  24054. b = q.andln(0xff);
  24055. q.iushrn(8);
  24056. res[i] = b;
  24057. }
  24058. for (; i < reqLength; i++) {
  24059. res[i] = 0;
  24060. }
  24061. }
  24062. return res;
  24063. };
  24064. if (Math.clz32) {
  24065. BN.prototype._countBits = function _countBits(w) {
  24066. return 32 - Math.clz32(w);
  24067. };
  24068. } else {
  24069. BN.prototype._countBits = function _countBits(w) {
  24070. var t = w;
  24071. var r = 0;
  24072. if (t >= 0x1000) {
  24073. r += 13;
  24074. t >>>= 13;
  24075. }
  24076. if (t >= 0x40) {
  24077. r += 7;
  24078. t >>>= 7;
  24079. }
  24080. if (t >= 0x8) {
  24081. r += 4;
  24082. t >>>= 4;
  24083. }
  24084. if (t >= 0x02) {
  24085. r += 2;
  24086. t >>>= 2;
  24087. }
  24088. return r + t;
  24089. };
  24090. }
  24091. BN.prototype._zeroBits = function _zeroBits(w) {
  24092. // Short-cut
  24093. if (w === 0) return 26;
  24094. var t = w;
  24095. var r = 0;
  24096. if ((t & 0x1fff) === 0) {
  24097. r += 13;
  24098. t >>>= 13;
  24099. }
  24100. if ((t & 0x7f) === 0) {
  24101. r += 7;
  24102. t >>>= 7;
  24103. }
  24104. if ((t & 0xf) === 0) {
  24105. r += 4;
  24106. t >>>= 4;
  24107. }
  24108. if ((t & 0x3) === 0) {
  24109. r += 2;
  24110. t >>>= 2;
  24111. }
  24112. if ((t & 0x1) === 0) {
  24113. r++;
  24114. }
  24115. return r;
  24116. }; // Return number of used bits in a BN
  24117. BN.prototype.bitLength = function bitLength() {
  24118. var w = this.words[this.length - 1];
  24119. var hi = this._countBits(w);
  24120. return (this.length - 1) * 26 + hi;
  24121. };
  24122. function toBitArray(num) {
  24123. var w = new Array(num.bitLength());
  24124. for (var bit = 0; bit < w.length; bit++) {
  24125. var off = bit / 26 | 0;
  24126. var wbit = bit % 26;
  24127. w[bit] = (num.words[off] & 1 << wbit) >>> wbit;
  24128. }
  24129. return w;
  24130. } // Number of trailing zero bits
  24131. BN.prototype.zeroBits = function zeroBits() {
  24132. if (this.isZero()) return 0;
  24133. var r = 0;
  24134. for (var i = 0; i < this.length; i++) {
  24135. var b = this._zeroBits(this.words[i]);
  24136. r += b;
  24137. if (b !== 26) break;
  24138. }
  24139. return r;
  24140. };
  24141. BN.prototype.byteLength = function byteLength() {
  24142. return Math.ceil(this.bitLength() / 8);
  24143. };
  24144. BN.prototype.toTwos = function toTwos(width) {
  24145. if (this.negative !== 0) {
  24146. return this.abs().inotn(width).iaddn(1);
  24147. }
  24148. return this.clone();
  24149. };
  24150. BN.prototype.fromTwos = function fromTwos(width) {
  24151. if (this.testn(width - 1)) {
  24152. return this.notn(width).iaddn(1).ineg();
  24153. }
  24154. return this.clone();
  24155. };
  24156. BN.prototype.isNeg = function isNeg() {
  24157. return this.negative !== 0;
  24158. }; // Return negative clone of `this`
  24159. BN.prototype.neg = function neg() {
  24160. return this.clone().ineg();
  24161. };
  24162. BN.prototype.ineg = function ineg() {
  24163. if (!this.isZero()) {
  24164. this.negative ^= 1;
  24165. }
  24166. return this;
  24167. }; // Or `num` with `this` in-place
  24168. BN.prototype.iuor = function iuor(num) {
  24169. while (this.length < num.length) {
  24170. this.words[this.length++] = 0;
  24171. }
  24172. for (var i = 0; i < num.length; i++) {
  24173. this.words[i] = this.words[i] | num.words[i];
  24174. }
  24175. return this.strip();
  24176. };
  24177. BN.prototype.ior = function ior(num) {
  24178. assert((this.negative | num.negative) === 0);
  24179. return this.iuor(num);
  24180. }; // Or `num` with `this`
  24181. BN.prototype.or = function or(num) {
  24182. if (this.length > num.length) return this.clone().ior(num);
  24183. return num.clone().ior(this);
  24184. };
  24185. BN.prototype.uor = function uor(num) {
  24186. if (this.length > num.length) return this.clone().iuor(num);
  24187. return num.clone().iuor(this);
  24188. }; // And `num` with `this` in-place
  24189. BN.prototype.iuand = function iuand(num) {
  24190. // b = min-length(num, this)
  24191. var b;
  24192. if (this.length > num.length) {
  24193. b = num;
  24194. } else {
  24195. b = this;
  24196. }
  24197. for (var i = 0; i < b.length; i++) {
  24198. this.words[i] = this.words[i] & num.words[i];
  24199. }
  24200. this.length = b.length;
  24201. return this.strip();
  24202. };
  24203. BN.prototype.iand = function iand(num) {
  24204. assert((this.negative | num.negative) === 0);
  24205. return this.iuand(num);
  24206. }; // And `num` with `this`
  24207. BN.prototype.and = function and(num) {
  24208. if (this.length > num.length) return this.clone().iand(num);
  24209. return num.clone().iand(this);
  24210. };
  24211. BN.prototype.uand = function uand(num) {
  24212. if (this.length > num.length) return this.clone().iuand(num);
  24213. return num.clone().iuand(this);
  24214. }; // Xor `num` with `this` in-place
  24215. BN.prototype.iuxor = function iuxor(num) {
  24216. // a.length > b.length
  24217. var a;
  24218. var b;
  24219. if (this.length > num.length) {
  24220. a = this;
  24221. b = num;
  24222. } else {
  24223. a = num;
  24224. b = this;
  24225. }
  24226. for (var i = 0; i < b.length; i++) {
  24227. this.words[i] = a.words[i] ^ b.words[i];
  24228. }
  24229. if (this !== a) {
  24230. for (; i < a.length; i++) {
  24231. this.words[i] = a.words[i];
  24232. }
  24233. }
  24234. this.length = a.length;
  24235. return this.strip();
  24236. };
  24237. BN.prototype.ixor = function ixor(num) {
  24238. assert((this.negative | num.negative) === 0);
  24239. return this.iuxor(num);
  24240. }; // Xor `num` with `this`
  24241. BN.prototype.xor = function xor(num) {
  24242. if (this.length > num.length) return this.clone().ixor(num);
  24243. return num.clone().ixor(this);
  24244. };
  24245. BN.prototype.uxor = function uxor(num) {
  24246. if (this.length > num.length) return this.clone().iuxor(num);
  24247. return num.clone().iuxor(this);
  24248. }; // Not ``this`` with ``width`` bitwidth
  24249. BN.prototype.inotn = function inotn(width) {
  24250. assert(typeof width === 'number' && width >= 0);
  24251. var bytesNeeded = Math.ceil(width / 26) | 0;
  24252. var bitsLeft = width % 26; // Extend the buffer with leading zeroes
  24253. this._expand(bytesNeeded);
  24254. if (bitsLeft > 0) {
  24255. bytesNeeded--;
  24256. } // Handle complete words
  24257. for (var i = 0; i < bytesNeeded; i++) {
  24258. this.words[i] = ~this.words[i] & 0x3ffffff;
  24259. } // Handle the residue
  24260. if (bitsLeft > 0) {
  24261. this.words[i] = ~this.words[i] & 0x3ffffff >> 26 - bitsLeft;
  24262. } // And remove leading zeroes
  24263. return this.strip();
  24264. };
  24265. BN.prototype.notn = function notn(width) {
  24266. return this.clone().inotn(width);
  24267. }; // Set `bit` of `this`
  24268. BN.prototype.setn = function setn(bit, val) {
  24269. assert(typeof bit === 'number' && bit >= 0);
  24270. var off = bit / 26 | 0;
  24271. var wbit = bit % 26;
  24272. this._expand(off + 1);
  24273. if (val) {
  24274. this.words[off] = this.words[off] | 1 << wbit;
  24275. } else {
  24276. this.words[off] = this.words[off] & ~(1 << wbit);
  24277. }
  24278. return this.strip();
  24279. }; // Add `num` to `this` in-place
  24280. BN.prototype.iadd = function iadd(num) {
  24281. var r; // negative + positive
  24282. if (this.negative !== 0 && num.negative === 0) {
  24283. this.negative = 0;
  24284. r = this.isub(num);
  24285. this.negative ^= 1;
  24286. return this._normSign(); // positive + negative
  24287. } else if (this.negative === 0 && num.negative !== 0) {
  24288. num.negative = 0;
  24289. r = this.isub(num);
  24290. num.negative = 1;
  24291. return r._normSign();
  24292. } // a.length > b.length
  24293. var a, b;
  24294. if (this.length > num.length) {
  24295. a = this;
  24296. b = num;
  24297. } else {
  24298. a = num;
  24299. b = this;
  24300. }
  24301. var carry = 0;
  24302. for (var i = 0; i < b.length; i++) {
  24303. r = (a.words[i] | 0) + (b.words[i] | 0) + carry;
  24304. this.words[i] = r & 0x3ffffff;
  24305. carry = r >>> 26;
  24306. }
  24307. for (; carry !== 0 && i < a.length; i++) {
  24308. r = (a.words[i] | 0) + carry;
  24309. this.words[i] = r & 0x3ffffff;
  24310. carry = r >>> 26;
  24311. }
  24312. this.length = a.length;
  24313. if (carry !== 0) {
  24314. this.words[this.length] = carry;
  24315. this.length++; // Copy the rest of the words
  24316. } else if (a !== this) {
  24317. for (; i < a.length; i++) {
  24318. this.words[i] = a.words[i];
  24319. }
  24320. }
  24321. return this;
  24322. }; // Add `num` to `this`
  24323. BN.prototype.add = function add(num) {
  24324. var res;
  24325. if (num.negative !== 0 && this.negative === 0) {
  24326. num.negative = 0;
  24327. res = this.sub(num);
  24328. num.negative ^= 1;
  24329. return res;
  24330. } else if (num.negative === 0 && this.negative !== 0) {
  24331. this.negative = 0;
  24332. res = num.sub(this);
  24333. this.negative = 1;
  24334. return res;
  24335. }
  24336. if (this.length > num.length) return this.clone().iadd(num);
  24337. return num.clone().iadd(this);
  24338. }; // Subtract `num` from `this` in-place
  24339. BN.prototype.isub = function isub(num) {
  24340. // this - (-num) = this + num
  24341. if (num.negative !== 0) {
  24342. num.negative = 0;
  24343. var r = this.iadd(num);
  24344. num.negative = 1;
  24345. return r._normSign(); // -this - num = -(this + num)
  24346. } else if (this.negative !== 0) {
  24347. this.negative = 0;
  24348. this.iadd(num);
  24349. this.negative = 1;
  24350. return this._normSign();
  24351. } // At this point both numbers are positive
  24352. var cmp = this.cmp(num); // Optimization - zeroify
  24353. if (cmp === 0) {
  24354. this.negative = 0;
  24355. this.length = 1;
  24356. this.words[0] = 0;
  24357. return this;
  24358. } // a > b
  24359. var a, b;
  24360. if (cmp > 0) {
  24361. a = this;
  24362. b = num;
  24363. } else {
  24364. a = num;
  24365. b = this;
  24366. }
  24367. var carry = 0;
  24368. for (var i = 0; i < b.length; i++) {
  24369. r = (a.words[i] | 0) - (b.words[i] | 0) + carry;
  24370. carry = r >> 26;
  24371. this.words[i] = r & 0x3ffffff;
  24372. }
  24373. for (; carry !== 0 && i < a.length; i++) {
  24374. r = (a.words[i] | 0) + carry;
  24375. carry = r >> 26;
  24376. this.words[i] = r & 0x3ffffff;
  24377. } // Copy rest of the words
  24378. if (carry === 0 && i < a.length && a !== this) {
  24379. for (; i < a.length; i++) {
  24380. this.words[i] = a.words[i];
  24381. }
  24382. }
  24383. this.length = Math.max(this.length, i);
  24384. if (a !== this) {
  24385. this.negative = 1;
  24386. }
  24387. return this.strip();
  24388. }; // Subtract `num` from `this`
  24389. BN.prototype.sub = function sub(num) {
  24390. return this.clone().isub(num);
  24391. };
  24392. function smallMulTo(self, num, out) {
  24393. out.negative = num.negative ^ self.negative;
  24394. var len = self.length + num.length | 0;
  24395. out.length = len;
  24396. len = len - 1 | 0; // Peel one iteration (compiler can't do it, because of code complexity)
  24397. var a = self.words[0] | 0;
  24398. var b = num.words[0] | 0;
  24399. var r = a * b;
  24400. var lo = r & 0x3ffffff;
  24401. var carry = r / 0x4000000 | 0;
  24402. out.words[0] = lo;
  24403. for (var k = 1; k < len; k++) {
  24404. // Sum all words with the same `i + j = k` and accumulate `ncarry`,
  24405. // note that ncarry could be >= 0x3ffffff
  24406. var ncarry = carry >>> 26;
  24407. var rword = carry & 0x3ffffff;
  24408. var maxJ = Math.min(k, num.length - 1);
  24409. for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
  24410. var i = k - j | 0;
  24411. a = self.words[i] | 0;
  24412. b = num.words[j] | 0;
  24413. r = a * b + rword;
  24414. ncarry += r / 0x4000000 | 0;
  24415. rword = r & 0x3ffffff;
  24416. }
  24417. out.words[k] = rword | 0;
  24418. carry = ncarry | 0;
  24419. }
  24420. if (carry !== 0) {
  24421. out.words[k] = carry | 0;
  24422. } else {
  24423. out.length--;
  24424. }
  24425. return out.strip();
  24426. } // TODO(indutny): it may be reasonable to omit it for users who don't need
  24427. // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit
  24428. // multiplication (like elliptic secp256k1).
  24429. var comb10MulTo = function comb10MulTo(self, num, out) {
  24430. var a = self.words;
  24431. var b = num.words;
  24432. var o = out.words;
  24433. var c = 0;
  24434. var lo;
  24435. var mid;
  24436. var hi;
  24437. var a0 = a[0] | 0;
  24438. var al0 = a0 & 0x1fff;
  24439. var ah0 = a0 >>> 13;
  24440. var a1 = a[1] | 0;
  24441. var al1 = a1 & 0x1fff;
  24442. var ah1 = a1 >>> 13;
  24443. var a2 = a[2] | 0;
  24444. var al2 = a2 & 0x1fff;
  24445. var ah2 = a2 >>> 13;
  24446. var a3 = a[3] | 0;
  24447. var al3 = a3 & 0x1fff;
  24448. var ah3 = a3 >>> 13;
  24449. var a4 = a[4] | 0;
  24450. var al4 = a4 & 0x1fff;
  24451. var ah4 = a4 >>> 13;
  24452. var a5 = a[5] | 0;
  24453. var al5 = a5 & 0x1fff;
  24454. var ah5 = a5 >>> 13;
  24455. var a6 = a[6] | 0;
  24456. var al6 = a6 & 0x1fff;
  24457. var ah6 = a6 >>> 13;
  24458. var a7 = a[7] | 0;
  24459. var al7 = a7 & 0x1fff;
  24460. var ah7 = a7 >>> 13;
  24461. var a8 = a[8] | 0;
  24462. var al8 = a8 & 0x1fff;
  24463. var ah8 = a8 >>> 13;
  24464. var a9 = a[9] | 0;
  24465. var al9 = a9 & 0x1fff;
  24466. var ah9 = a9 >>> 13;
  24467. var b0 = b[0] | 0;
  24468. var bl0 = b0 & 0x1fff;
  24469. var bh0 = b0 >>> 13;
  24470. var b1 = b[1] | 0;
  24471. var bl1 = b1 & 0x1fff;
  24472. var bh1 = b1 >>> 13;
  24473. var b2 = b[2] | 0;
  24474. var bl2 = b2 & 0x1fff;
  24475. var bh2 = b2 >>> 13;
  24476. var b3 = b[3] | 0;
  24477. var bl3 = b3 & 0x1fff;
  24478. var bh3 = b3 >>> 13;
  24479. var b4 = b[4] | 0;
  24480. var bl4 = b4 & 0x1fff;
  24481. var bh4 = b4 >>> 13;
  24482. var b5 = b[5] | 0;
  24483. var bl5 = b5 & 0x1fff;
  24484. var bh5 = b5 >>> 13;
  24485. var b6 = b[6] | 0;
  24486. var bl6 = b6 & 0x1fff;
  24487. var bh6 = b6 >>> 13;
  24488. var b7 = b[7] | 0;
  24489. var bl7 = b7 & 0x1fff;
  24490. var bh7 = b7 >>> 13;
  24491. var b8 = b[8] | 0;
  24492. var bl8 = b8 & 0x1fff;
  24493. var bh8 = b8 >>> 13;
  24494. var b9 = b[9] | 0;
  24495. var bl9 = b9 & 0x1fff;
  24496. var bh9 = b9 >>> 13;
  24497. out.negative = self.negative ^ num.negative;
  24498. out.length = 19;
  24499. /* k = 0 */
  24500. lo = Math.imul(al0, bl0);
  24501. mid = Math.imul(al0, bh0);
  24502. mid = mid + Math.imul(ah0, bl0) | 0;
  24503. hi = Math.imul(ah0, bh0);
  24504. var w0 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24505. c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0;
  24506. w0 &= 0x3ffffff;
  24507. /* k = 1 */
  24508. lo = Math.imul(al1, bl0);
  24509. mid = Math.imul(al1, bh0);
  24510. mid = mid + Math.imul(ah1, bl0) | 0;
  24511. hi = Math.imul(ah1, bh0);
  24512. lo = lo + Math.imul(al0, bl1) | 0;
  24513. mid = mid + Math.imul(al0, bh1) | 0;
  24514. mid = mid + Math.imul(ah0, bl1) | 0;
  24515. hi = hi + Math.imul(ah0, bh1) | 0;
  24516. var w1 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24517. c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0;
  24518. w1 &= 0x3ffffff;
  24519. /* k = 2 */
  24520. lo = Math.imul(al2, bl0);
  24521. mid = Math.imul(al2, bh0);
  24522. mid = mid + Math.imul(ah2, bl0) | 0;
  24523. hi = Math.imul(ah2, bh0);
  24524. lo = lo + Math.imul(al1, bl1) | 0;
  24525. mid = mid + Math.imul(al1, bh1) | 0;
  24526. mid = mid + Math.imul(ah1, bl1) | 0;
  24527. hi = hi + Math.imul(ah1, bh1) | 0;
  24528. lo = lo + Math.imul(al0, bl2) | 0;
  24529. mid = mid + Math.imul(al0, bh2) | 0;
  24530. mid = mid + Math.imul(ah0, bl2) | 0;
  24531. hi = hi + Math.imul(ah0, bh2) | 0;
  24532. var w2 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24533. c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0;
  24534. w2 &= 0x3ffffff;
  24535. /* k = 3 */
  24536. lo = Math.imul(al3, bl0);
  24537. mid = Math.imul(al3, bh0);
  24538. mid = mid + Math.imul(ah3, bl0) | 0;
  24539. hi = Math.imul(ah3, bh0);
  24540. lo = lo + Math.imul(al2, bl1) | 0;
  24541. mid = mid + Math.imul(al2, bh1) | 0;
  24542. mid = mid + Math.imul(ah2, bl1) | 0;
  24543. hi = hi + Math.imul(ah2, bh1) | 0;
  24544. lo = lo + Math.imul(al1, bl2) | 0;
  24545. mid = mid + Math.imul(al1, bh2) | 0;
  24546. mid = mid + Math.imul(ah1, bl2) | 0;
  24547. hi = hi + Math.imul(ah1, bh2) | 0;
  24548. lo = lo + Math.imul(al0, bl3) | 0;
  24549. mid = mid + Math.imul(al0, bh3) | 0;
  24550. mid = mid + Math.imul(ah0, bl3) | 0;
  24551. hi = hi + Math.imul(ah0, bh3) | 0;
  24552. var w3 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24553. c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0;
  24554. w3 &= 0x3ffffff;
  24555. /* k = 4 */
  24556. lo = Math.imul(al4, bl0);
  24557. mid = Math.imul(al4, bh0);
  24558. mid = mid + Math.imul(ah4, bl0) | 0;
  24559. hi = Math.imul(ah4, bh0);
  24560. lo = lo + Math.imul(al3, bl1) | 0;
  24561. mid = mid + Math.imul(al3, bh1) | 0;
  24562. mid = mid + Math.imul(ah3, bl1) | 0;
  24563. hi = hi + Math.imul(ah3, bh1) | 0;
  24564. lo = lo + Math.imul(al2, bl2) | 0;
  24565. mid = mid + Math.imul(al2, bh2) | 0;
  24566. mid = mid + Math.imul(ah2, bl2) | 0;
  24567. hi = hi + Math.imul(ah2, bh2) | 0;
  24568. lo = lo + Math.imul(al1, bl3) | 0;
  24569. mid = mid + Math.imul(al1, bh3) | 0;
  24570. mid = mid + Math.imul(ah1, bl3) | 0;
  24571. hi = hi + Math.imul(ah1, bh3) | 0;
  24572. lo = lo + Math.imul(al0, bl4) | 0;
  24573. mid = mid + Math.imul(al0, bh4) | 0;
  24574. mid = mid + Math.imul(ah0, bl4) | 0;
  24575. hi = hi + Math.imul(ah0, bh4) | 0;
  24576. var w4 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24577. c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0;
  24578. w4 &= 0x3ffffff;
  24579. /* k = 5 */
  24580. lo = Math.imul(al5, bl0);
  24581. mid = Math.imul(al5, bh0);
  24582. mid = mid + Math.imul(ah5, bl0) | 0;
  24583. hi = Math.imul(ah5, bh0);
  24584. lo = lo + Math.imul(al4, bl1) | 0;
  24585. mid = mid + Math.imul(al4, bh1) | 0;
  24586. mid = mid + Math.imul(ah4, bl1) | 0;
  24587. hi = hi + Math.imul(ah4, bh1) | 0;
  24588. lo = lo + Math.imul(al3, bl2) | 0;
  24589. mid = mid + Math.imul(al3, bh2) | 0;
  24590. mid = mid + Math.imul(ah3, bl2) | 0;
  24591. hi = hi + Math.imul(ah3, bh2) | 0;
  24592. lo = lo + Math.imul(al2, bl3) | 0;
  24593. mid = mid + Math.imul(al2, bh3) | 0;
  24594. mid = mid + Math.imul(ah2, bl3) | 0;
  24595. hi = hi + Math.imul(ah2, bh3) | 0;
  24596. lo = lo + Math.imul(al1, bl4) | 0;
  24597. mid = mid + Math.imul(al1, bh4) | 0;
  24598. mid = mid + Math.imul(ah1, bl4) | 0;
  24599. hi = hi + Math.imul(ah1, bh4) | 0;
  24600. lo = lo + Math.imul(al0, bl5) | 0;
  24601. mid = mid + Math.imul(al0, bh5) | 0;
  24602. mid = mid + Math.imul(ah0, bl5) | 0;
  24603. hi = hi + Math.imul(ah0, bh5) | 0;
  24604. var w5 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24605. c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0;
  24606. w5 &= 0x3ffffff;
  24607. /* k = 6 */
  24608. lo = Math.imul(al6, bl0);
  24609. mid = Math.imul(al6, bh0);
  24610. mid = mid + Math.imul(ah6, bl0) | 0;
  24611. hi = Math.imul(ah6, bh0);
  24612. lo = lo + Math.imul(al5, bl1) | 0;
  24613. mid = mid + Math.imul(al5, bh1) | 0;
  24614. mid = mid + Math.imul(ah5, bl1) | 0;
  24615. hi = hi + Math.imul(ah5, bh1) | 0;
  24616. lo = lo + Math.imul(al4, bl2) | 0;
  24617. mid = mid + Math.imul(al4, bh2) | 0;
  24618. mid = mid + Math.imul(ah4, bl2) | 0;
  24619. hi = hi + Math.imul(ah4, bh2) | 0;
  24620. lo = lo + Math.imul(al3, bl3) | 0;
  24621. mid = mid + Math.imul(al3, bh3) | 0;
  24622. mid = mid + Math.imul(ah3, bl3) | 0;
  24623. hi = hi + Math.imul(ah3, bh3) | 0;
  24624. lo = lo + Math.imul(al2, bl4) | 0;
  24625. mid = mid + Math.imul(al2, bh4) | 0;
  24626. mid = mid + Math.imul(ah2, bl4) | 0;
  24627. hi = hi + Math.imul(ah2, bh4) | 0;
  24628. lo = lo + Math.imul(al1, bl5) | 0;
  24629. mid = mid + Math.imul(al1, bh5) | 0;
  24630. mid = mid + Math.imul(ah1, bl5) | 0;
  24631. hi = hi + Math.imul(ah1, bh5) | 0;
  24632. lo = lo + Math.imul(al0, bl6) | 0;
  24633. mid = mid + Math.imul(al0, bh6) | 0;
  24634. mid = mid + Math.imul(ah0, bl6) | 0;
  24635. hi = hi + Math.imul(ah0, bh6) | 0;
  24636. var w6 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24637. c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0;
  24638. w6 &= 0x3ffffff;
  24639. /* k = 7 */
  24640. lo = Math.imul(al7, bl0);
  24641. mid = Math.imul(al7, bh0);
  24642. mid = mid + Math.imul(ah7, bl0) | 0;
  24643. hi = Math.imul(ah7, bh0);
  24644. lo = lo + Math.imul(al6, bl1) | 0;
  24645. mid = mid + Math.imul(al6, bh1) | 0;
  24646. mid = mid + Math.imul(ah6, bl1) | 0;
  24647. hi = hi + Math.imul(ah6, bh1) | 0;
  24648. lo = lo + Math.imul(al5, bl2) | 0;
  24649. mid = mid + Math.imul(al5, bh2) | 0;
  24650. mid = mid + Math.imul(ah5, bl2) | 0;
  24651. hi = hi + Math.imul(ah5, bh2) | 0;
  24652. lo = lo + Math.imul(al4, bl3) | 0;
  24653. mid = mid + Math.imul(al4, bh3) | 0;
  24654. mid = mid + Math.imul(ah4, bl3) | 0;
  24655. hi = hi + Math.imul(ah4, bh3) | 0;
  24656. lo = lo + Math.imul(al3, bl4) | 0;
  24657. mid = mid + Math.imul(al3, bh4) | 0;
  24658. mid = mid + Math.imul(ah3, bl4) | 0;
  24659. hi = hi + Math.imul(ah3, bh4) | 0;
  24660. lo = lo + Math.imul(al2, bl5) | 0;
  24661. mid = mid + Math.imul(al2, bh5) | 0;
  24662. mid = mid + Math.imul(ah2, bl5) | 0;
  24663. hi = hi + Math.imul(ah2, bh5) | 0;
  24664. lo = lo + Math.imul(al1, bl6) | 0;
  24665. mid = mid + Math.imul(al1, bh6) | 0;
  24666. mid = mid + Math.imul(ah1, bl6) | 0;
  24667. hi = hi + Math.imul(ah1, bh6) | 0;
  24668. lo = lo + Math.imul(al0, bl7) | 0;
  24669. mid = mid + Math.imul(al0, bh7) | 0;
  24670. mid = mid + Math.imul(ah0, bl7) | 0;
  24671. hi = hi + Math.imul(ah0, bh7) | 0;
  24672. var w7 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24673. c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0;
  24674. w7 &= 0x3ffffff;
  24675. /* k = 8 */
  24676. lo = Math.imul(al8, bl0);
  24677. mid = Math.imul(al8, bh0);
  24678. mid = mid + Math.imul(ah8, bl0) | 0;
  24679. hi = Math.imul(ah8, bh0);
  24680. lo = lo + Math.imul(al7, bl1) | 0;
  24681. mid = mid + Math.imul(al7, bh1) | 0;
  24682. mid = mid + Math.imul(ah7, bl1) | 0;
  24683. hi = hi + Math.imul(ah7, bh1) | 0;
  24684. lo = lo + Math.imul(al6, bl2) | 0;
  24685. mid = mid + Math.imul(al6, bh2) | 0;
  24686. mid = mid + Math.imul(ah6, bl2) | 0;
  24687. hi = hi + Math.imul(ah6, bh2) | 0;
  24688. lo = lo + Math.imul(al5, bl3) | 0;
  24689. mid = mid + Math.imul(al5, bh3) | 0;
  24690. mid = mid + Math.imul(ah5, bl3) | 0;
  24691. hi = hi + Math.imul(ah5, bh3) | 0;
  24692. lo = lo + Math.imul(al4, bl4) | 0;
  24693. mid = mid + Math.imul(al4, bh4) | 0;
  24694. mid = mid + Math.imul(ah4, bl4) | 0;
  24695. hi = hi + Math.imul(ah4, bh4) | 0;
  24696. lo = lo + Math.imul(al3, bl5) | 0;
  24697. mid = mid + Math.imul(al3, bh5) | 0;
  24698. mid = mid + Math.imul(ah3, bl5) | 0;
  24699. hi = hi + Math.imul(ah3, bh5) | 0;
  24700. lo = lo + Math.imul(al2, bl6) | 0;
  24701. mid = mid + Math.imul(al2, bh6) | 0;
  24702. mid = mid + Math.imul(ah2, bl6) | 0;
  24703. hi = hi + Math.imul(ah2, bh6) | 0;
  24704. lo = lo + Math.imul(al1, bl7) | 0;
  24705. mid = mid + Math.imul(al1, bh7) | 0;
  24706. mid = mid + Math.imul(ah1, bl7) | 0;
  24707. hi = hi + Math.imul(ah1, bh7) | 0;
  24708. lo = lo + Math.imul(al0, bl8) | 0;
  24709. mid = mid + Math.imul(al0, bh8) | 0;
  24710. mid = mid + Math.imul(ah0, bl8) | 0;
  24711. hi = hi + Math.imul(ah0, bh8) | 0;
  24712. var w8 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24713. c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0;
  24714. w8 &= 0x3ffffff;
  24715. /* k = 9 */
  24716. lo = Math.imul(al9, bl0);
  24717. mid = Math.imul(al9, bh0);
  24718. mid = mid + Math.imul(ah9, bl0) | 0;
  24719. hi = Math.imul(ah9, bh0);
  24720. lo = lo + Math.imul(al8, bl1) | 0;
  24721. mid = mid + Math.imul(al8, bh1) | 0;
  24722. mid = mid + Math.imul(ah8, bl1) | 0;
  24723. hi = hi + Math.imul(ah8, bh1) | 0;
  24724. lo = lo + Math.imul(al7, bl2) | 0;
  24725. mid = mid + Math.imul(al7, bh2) | 0;
  24726. mid = mid + Math.imul(ah7, bl2) | 0;
  24727. hi = hi + Math.imul(ah7, bh2) | 0;
  24728. lo = lo + Math.imul(al6, bl3) | 0;
  24729. mid = mid + Math.imul(al6, bh3) | 0;
  24730. mid = mid + Math.imul(ah6, bl3) | 0;
  24731. hi = hi + Math.imul(ah6, bh3) | 0;
  24732. lo = lo + Math.imul(al5, bl4) | 0;
  24733. mid = mid + Math.imul(al5, bh4) | 0;
  24734. mid = mid + Math.imul(ah5, bl4) | 0;
  24735. hi = hi + Math.imul(ah5, bh4) | 0;
  24736. lo = lo + Math.imul(al4, bl5) | 0;
  24737. mid = mid + Math.imul(al4, bh5) | 0;
  24738. mid = mid + Math.imul(ah4, bl5) | 0;
  24739. hi = hi + Math.imul(ah4, bh5) | 0;
  24740. lo = lo + Math.imul(al3, bl6) | 0;
  24741. mid = mid + Math.imul(al3, bh6) | 0;
  24742. mid = mid + Math.imul(ah3, bl6) | 0;
  24743. hi = hi + Math.imul(ah3, bh6) | 0;
  24744. lo = lo + Math.imul(al2, bl7) | 0;
  24745. mid = mid + Math.imul(al2, bh7) | 0;
  24746. mid = mid + Math.imul(ah2, bl7) | 0;
  24747. hi = hi + Math.imul(ah2, bh7) | 0;
  24748. lo = lo + Math.imul(al1, bl8) | 0;
  24749. mid = mid + Math.imul(al1, bh8) | 0;
  24750. mid = mid + Math.imul(ah1, bl8) | 0;
  24751. hi = hi + Math.imul(ah1, bh8) | 0;
  24752. lo = lo + Math.imul(al0, bl9) | 0;
  24753. mid = mid + Math.imul(al0, bh9) | 0;
  24754. mid = mid + Math.imul(ah0, bl9) | 0;
  24755. hi = hi + Math.imul(ah0, bh9) | 0;
  24756. var w9 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24757. c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0;
  24758. w9 &= 0x3ffffff;
  24759. /* k = 10 */
  24760. lo = Math.imul(al9, bl1);
  24761. mid = Math.imul(al9, bh1);
  24762. mid = mid + Math.imul(ah9, bl1) | 0;
  24763. hi = Math.imul(ah9, bh1);
  24764. lo = lo + Math.imul(al8, bl2) | 0;
  24765. mid = mid + Math.imul(al8, bh2) | 0;
  24766. mid = mid + Math.imul(ah8, bl2) | 0;
  24767. hi = hi + Math.imul(ah8, bh2) | 0;
  24768. lo = lo + Math.imul(al7, bl3) | 0;
  24769. mid = mid + Math.imul(al7, bh3) | 0;
  24770. mid = mid + Math.imul(ah7, bl3) | 0;
  24771. hi = hi + Math.imul(ah7, bh3) | 0;
  24772. lo = lo + Math.imul(al6, bl4) | 0;
  24773. mid = mid + Math.imul(al6, bh4) | 0;
  24774. mid = mid + Math.imul(ah6, bl4) | 0;
  24775. hi = hi + Math.imul(ah6, bh4) | 0;
  24776. lo = lo + Math.imul(al5, bl5) | 0;
  24777. mid = mid + Math.imul(al5, bh5) | 0;
  24778. mid = mid + Math.imul(ah5, bl5) | 0;
  24779. hi = hi + Math.imul(ah5, bh5) | 0;
  24780. lo = lo + Math.imul(al4, bl6) | 0;
  24781. mid = mid + Math.imul(al4, bh6) | 0;
  24782. mid = mid + Math.imul(ah4, bl6) | 0;
  24783. hi = hi + Math.imul(ah4, bh6) | 0;
  24784. lo = lo + Math.imul(al3, bl7) | 0;
  24785. mid = mid + Math.imul(al3, bh7) | 0;
  24786. mid = mid + Math.imul(ah3, bl7) | 0;
  24787. hi = hi + Math.imul(ah3, bh7) | 0;
  24788. lo = lo + Math.imul(al2, bl8) | 0;
  24789. mid = mid + Math.imul(al2, bh8) | 0;
  24790. mid = mid + Math.imul(ah2, bl8) | 0;
  24791. hi = hi + Math.imul(ah2, bh8) | 0;
  24792. lo = lo + Math.imul(al1, bl9) | 0;
  24793. mid = mid + Math.imul(al1, bh9) | 0;
  24794. mid = mid + Math.imul(ah1, bl9) | 0;
  24795. hi = hi + Math.imul(ah1, bh9) | 0;
  24796. var w10 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24797. c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0;
  24798. w10 &= 0x3ffffff;
  24799. /* k = 11 */
  24800. lo = Math.imul(al9, bl2);
  24801. mid = Math.imul(al9, bh2);
  24802. mid = mid + Math.imul(ah9, bl2) | 0;
  24803. hi = Math.imul(ah9, bh2);
  24804. lo = lo + Math.imul(al8, bl3) | 0;
  24805. mid = mid + Math.imul(al8, bh3) | 0;
  24806. mid = mid + Math.imul(ah8, bl3) | 0;
  24807. hi = hi + Math.imul(ah8, bh3) | 0;
  24808. lo = lo + Math.imul(al7, bl4) | 0;
  24809. mid = mid + Math.imul(al7, bh4) | 0;
  24810. mid = mid + Math.imul(ah7, bl4) | 0;
  24811. hi = hi + Math.imul(ah7, bh4) | 0;
  24812. lo = lo + Math.imul(al6, bl5) | 0;
  24813. mid = mid + Math.imul(al6, bh5) | 0;
  24814. mid = mid + Math.imul(ah6, bl5) | 0;
  24815. hi = hi + Math.imul(ah6, bh5) | 0;
  24816. lo = lo + Math.imul(al5, bl6) | 0;
  24817. mid = mid + Math.imul(al5, bh6) | 0;
  24818. mid = mid + Math.imul(ah5, bl6) | 0;
  24819. hi = hi + Math.imul(ah5, bh6) | 0;
  24820. lo = lo + Math.imul(al4, bl7) | 0;
  24821. mid = mid + Math.imul(al4, bh7) | 0;
  24822. mid = mid + Math.imul(ah4, bl7) | 0;
  24823. hi = hi + Math.imul(ah4, bh7) | 0;
  24824. lo = lo + Math.imul(al3, bl8) | 0;
  24825. mid = mid + Math.imul(al3, bh8) | 0;
  24826. mid = mid + Math.imul(ah3, bl8) | 0;
  24827. hi = hi + Math.imul(ah3, bh8) | 0;
  24828. lo = lo + Math.imul(al2, bl9) | 0;
  24829. mid = mid + Math.imul(al2, bh9) | 0;
  24830. mid = mid + Math.imul(ah2, bl9) | 0;
  24831. hi = hi + Math.imul(ah2, bh9) | 0;
  24832. var w11 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24833. c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0;
  24834. w11 &= 0x3ffffff;
  24835. /* k = 12 */
  24836. lo = Math.imul(al9, bl3);
  24837. mid = Math.imul(al9, bh3);
  24838. mid = mid + Math.imul(ah9, bl3) | 0;
  24839. hi = Math.imul(ah9, bh3);
  24840. lo = lo + Math.imul(al8, bl4) | 0;
  24841. mid = mid + Math.imul(al8, bh4) | 0;
  24842. mid = mid + Math.imul(ah8, bl4) | 0;
  24843. hi = hi + Math.imul(ah8, bh4) | 0;
  24844. lo = lo + Math.imul(al7, bl5) | 0;
  24845. mid = mid + Math.imul(al7, bh5) | 0;
  24846. mid = mid + Math.imul(ah7, bl5) | 0;
  24847. hi = hi + Math.imul(ah7, bh5) | 0;
  24848. lo = lo + Math.imul(al6, bl6) | 0;
  24849. mid = mid + Math.imul(al6, bh6) | 0;
  24850. mid = mid + Math.imul(ah6, bl6) | 0;
  24851. hi = hi + Math.imul(ah6, bh6) | 0;
  24852. lo = lo + Math.imul(al5, bl7) | 0;
  24853. mid = mid + Math.imul(al5, bh7) | 0;
  24854. mid = mid + Math.imul(ah5, bl7) | 0;
  24855. hi = hi + Math.imul(ah5, bh7) | 0;
  24856. lo = lo + Math.imul(al4, bl8) | 0;
  24857. mid = mid + Math.imul(al4, bh8) | 0;
  24858. mid = mid + Math.imul(ah4, bl8) | 0;
  24859. hi = hi + Math.imul(ah4, bh8) | 0;
  24860. lo = lo + Math.imul(al3, bl9) | 0;
  24861. mid = mid + Math.imul(al3, bh9) | 0;
  24862. mid = mid + Math.imul(ah3, bl9) | 0;
  24863. hi = hi + Math.imul(ah3, bh9) | 0;
  24864. var w12 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24865. c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0;
  24866. w12 &= 0x3ffffff;
  24867. /* k = 13 */
  24868. lo = Math.imul(al9, bl4);
  24869. mid = Math.imul(al9, bh4);
  24870. mid = mid + Math.imul(ah9, bl4) | 0;
  24871. hi = Math.imul(ah9, bh4);
  24872. lo = lo + Math.imul(al8, bl5) | 0;
  24873. mid = mid + Math.imul(al8, bh5) | 0;
  24874. mid = mid + Math.imul(ah8, bl5) | 0;
  24875. hi = hi + Math.imul(ah8, bh5) | 0;
  24876. lo = lo + Math.imul(al7, bl6) | 0;
  24877. mid = mid + Math.imul(al7, bh6) | 0;
  24878. mid = mid + Math.imul(ah7, bl6) | 0;
  24879. hi = hi + Math.imul(ah7, bh6) | 0;
  24880. lo = lo + Math.imul(al6, bl7) | 0;
  24881. mid = mid + Math.imul(al6, bh7) | 0;
  24882. mid = mid + Math.imul(ah6, bl7) | 0;
  24883. hi = hi + Math.imul(ah6, bh7) | 0;
  24884. lo = lo + Math.imul(al5, bl8) | 0;
  24885. mid = mid + Math.imul(al5, bh8) | 0;
  24886. mid = mid + Math.imul(ah5, bl8) | 0;
  24887. hi = hi + Math.imul(ah5, bh8) | 0;
  24888. lo = lo + Math.imul(al4, bl9) | 0;
  24889. mid = mid + Math.imul(al4, bh9) | 0;
  24890. mid = mid + Math.imul(ah4, bl9) | 0;
  24891. hi = hi + Math.imul(ah4, bh9) | 0;
  24892. var w13 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24893. c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0;
  24894. w13 &= 0x3ffffff;
  24895. /* k = 14 */
  24896. lo = Math.imul(al9, bl5);
  24897. mid = Math.imul(al9, bh5);
  24898. mid = mid + Math.imul(ah9, bl5) | 0;
  24899. hi = Math.imul(ah9, bh5);
  24900. lo = lo + Math.imul(al8, bl6) | 0;
  24901. mid = mid + Math.imul(al8, bh6) | 0;
  24902. mid = mid + Math.imul(ah8, bl6) | 0;
  24903. hi = hi + Math.imul(ah8, bh6) | 0;
  24904. lo = lo + Math.imul(al7, bl7) | 0;
  24905. mid = mid + Math.imul(al7, bh7) | 0;
  24906. mid = mid + Math.imul(ah7, bl7) | 0;
  24907. hi = hi + Math.imul(ah7, bh7) | 0;
  24908. lo = lo + Math.imul(al6, bl8) | 0;
  24909. mid = mid + Math.imul(al6, bh8) | 0;
  24910. mid = mid + Math.imul(ah6, bl8) | 0;
  24911. hi = hi + Math.imul(ah6, bh8) | 0;
  24912. lo = lo + Math.imul(al5, bl9) | 0;
  24913. mid = mid + Math.imul(al5, bh9) | 0;
  24914. mid = mid + Math.imul(ah5, bl9) | 0;
  24915. hi = hi + Math.imul(ah5, bh9) | 0;
  24916. var w14 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24917. c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0;
  24918. w14 &= 0x3ffffff;
  24919. /* k = 15 */
  24920. lo = Math.imul(al9, bl6);
  24921. mid = Math.imul(al9, bh6);
  24922. mid = mid + Math.imul(ah9, bl6) | 0;
  24923. hi = Math.imul(ah9, bh6);
  24924. lo = lo + Math.imul(al8, bl7) | 0;
  24925. mid = mid + Math.imul(al8, bh7) | 0;
  24926. mid = mid + Math.imul(ah8, bl7) | 0;
  24927. hi = hi + Math.imul(ah8, bh7) | 0;
  24928. lo = lo + Math.imul(al7, bl8) | 0;
  24929. mid = mid + Math.imul(al7, bh8) | 0;
  24930. mid = mid + Math.imul(ah7, bl8) | 0;
  24931. hi = hi + Math.imul(ah7, bh8) | 0;
  24932. lo = lo + Math.imul(al6, bl9) | 0;
  24933. mid = mid + Math.imul(al6, bh9) | 0;
  24934. mid = mid + Math.imul(ah6, bl9) | 0;
  24935. hi = hi + Math.imul(ah6, bh9) | 0;
  24936. var w15 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24937. c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0;
  24938. w15 &= 0x3ffffff;
  24939. /* k = 16 */
  24940. lo = Math.imul(al9, bl7);
  24941. mid = Math.imul(al9, bh7);
  24942. mid = mid + Math.imul(ah9, bl7) | 0;
  24943. hi = Math.imul(ah9, bh7);
  24944. lo = lo + Math.imul(al8, bl8) | 0;
  24945. mid = mid + Math.imul(al8, bh8) | 0;
  24946. mid = mid + Math.imul(ah8, bl8) | 0;
  24947. hi = hi + Math.imul(ah8, bh8) | 0;
  24948. lo = lo + Math.imul(al7, bl9) | 0;
  24949. mid = mid + Math.imul(al7, bh9) | 0;
  24950. mid = mid + Math.imul(ah7, bl9) | 0;
  24951. hi = hi + Math.imul(ah7, bh9) | 0;
  24952. var w16 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24953. c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0;
  24954. w16 &= 0x3ffffff;
  24955. /* k = 17 */
  24956. lo = Math.imul(al9, bl8);
  24957. mid = Math.imul(al9, bh8);
  24958. mid = mid + Math.imul(ah9, bl8) | 0;
  24959. hi = Math.imul(ah9, bh8);
  24960. lo = lo + Math.imul(al8, bl9) | 0;
  24961. mid = mid + Math.imul(al8, bh9) | 0;
  24962. mid = mid + Math.imul(ah8, bl9) | 0;
  24963. hi = hi + Math.imul(ah8, bh9) | 0;
  24964. var w17 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24965. c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0;
  24966. w17 &= 0x3ffffff;
  24967. /* k = 18 */
  24968. lo = Math.imul(al9, bl9);
  24969. mid = Math.imul(al9, bh9);
  24970. mid = mid + Math.imul(ah9, bl9) | 0;
  24971. hi = Math.imul(ah9, bh9);
  24972. var w18 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24973. c = (hi + (mid >>> 13) | 0) + (w18 >>> 26) | 0;
  24974. w18 &= 0x3ffffff;
  24975. o[0] = w0;
  24976. o[1] = w1;
  24977. o[2] = w2;
  24978. o[3] = w3;
  24979. o[4] = w4;
  24980. o[5] = w5;
  24981. o[6] = w6;
  24982. o[7] = w7;
  24983. o[8] = w8;
  24984. o[9] = w9;
  24985. o[10] = w10;
  24986. o[11] = w11;
  24987. o[12] = w12;
  24988. o[13] = w13;
  24989. o[14] = w14;
  24990. o[15] = w15;
  24991. o[16] = w16;
  24992. o[17] = w17;
  24993. o[18] = w18;
  24994. if (c !== 0) {
  24995. o[19] = c;
  24996. out.length++;
  24997. }
  24998. return out;
  24999. }; // Polyfill comb
  25000. if (!Math.imul) {
  25001. comb10MulTo = smallMulTo;
  25002. }
  25003. function bigMulTo(self, num, out) {
  25004. out.negative = num.negative ^ self.negative;
  25005. out.length = self.length + num.length;
  25006. var carry = 0;
  25007. var hncarry = 0;
  25008. for (var k = 0; k < out.length - 1; k++) {
  25009. // Sum all words with the same `i + j = k` and accumulate `ncarry`,
  25010. // note that ncarry could be >= 0x3ffffff
  25011. var ncarry = hncarry;
  25012. hncarry = 0;
  25013. var rword = carry & 0x3ffffff;
  25014. var maxJ = Math.min(k, num.length - 1);
  25015. for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
  25016. var i = k - j;
  25017. var a = self.words[i] | 0;
  25018. var b = num.words[j] | 0;
  25019. var r = a * b;
  25020. var lo = r & 0x3ffffff;
  25021. ncarry = ncarry + (r / 0x4000000 | 0) | 0;
  25022. lo = lo + rword | 0;
  25023. rword = lo & 0x3ffffff;
  25024. ncarry = ncarry + (lo >>> 26) | 0;
  25025. hncarry += ncarry >>> 26;
  25026. ncarry &= 0x3ffffff;
  25027. }
  25028. out.words[k] = rword;
  25029. carry = ncarry;
  25030. ncarry = hncarry;
  25031. }
  25032. if (carry !== 0) {
  25033. out.words[k] = carry;
  25034. } else {
  25035. out.length--;
  25036. }
  25037. return out.strip();
  25038. }
  25039. function jumboMulTo(self, num, out) {
  25040. var fftm = new FFTM();
  25041. return fftm.mulp(self, num, out);
  25042. }
  25043. BN.prototype.mulTo = function mulTo(num, out) {
  25044. var res;
  25045. var len = this.length + num.length;
  25046. if (this.length === 10 && num.length === 10) {
  25047. res = comb10MulTo(this, num, out);
  25048. } else if (len < 63) {
  25049. res = smallMulTo(this, num, out);
  25050. } else if (len < 1024) {
  25051. res = bigMulTo(this, num, out);
  25052. } else {
  25053. res = jumboMulTo(this, num, out);
  25054. }
  25055. return res;
  25056. }; // Cooley-Tukey algorithm for FFT
  25057. // slightly revisited to rely on looping instead of recursion
  25058. function FFTM(x, y) {
  25059. this.x = x;
  25060. this.y = y;
  25061. }
  25062. FFTM.prototype.makeRBT = function makeRBT(N) {
  25063. var t = new Array(N);
  25064. var l = BN.prototype._countBits(N) - 1;
  25065. for (var i = 0; i < N; i++) {
  25066. t[i] = this.revBin(i, l, N);
  25067. }
  25068. return t;
  25069. }; // Returns binary-reversed representation of `x`
  25070. FFTM.prototype.revBin = function revBin(x, l, N) {
  25071. if (x === 0 || x === N - 1) return x;
  25072. var rb = 0;
  25073. for (var i = 0; i < l; i++) {
  25074. rb |= (x & 1) << l - i - 1;
  25075. x >>= 1;
  25076. }
  25077. return rb;
  25078. }; // Performs "tweedling" phase, therefore 'emulating'
  25079. // behaviour of the recursive algorithm
  25080. FFTM.prototype.permute = function permute(rbt, rws, iws, rtws, itws, N) {
  25081. for (var i = 0; i < N; i++) {
  25082. rtws[i] = rws[rbt[i]];
  25083. itws[i] = iws[rbt[i]];
  25084. }
  25085. };
  25086. FFTM.prototype.transform = function transform(rws, iws, rtws, itws, N, rbt) {
  25087. this.permute(rbt, rws, iws, rtws, itws, N);
  25088. for (var s = 1; s < N; s <<= 1) {
  25089. var l = s << 1;
  25090. var rtwdf = Math.cos(2 * Math.PI / l);
  25091. var itwdf = Math.sin(2 * Math.PI / l);
  25092. for (var p = 0; p < N; p += l) {
  25093. var rtwdf_ = rtwdf;
  25094. var itwdf_ = itwdf;
  25095. for (var j = 0; j < s; j++) {
  25096. var re = rtws[p + j];
  25097. var ie = itws[p + j];
  25098. var ro = rtws[p + j + s];
  25099. var io = itws[p + j + s];
  25100. var rx = rtwdf_ * ro - itwdf_ * io;
  25101. io = rtwdf_ * io + itwdf_ * ro;
  25102. ro = rx;
  25103. rtws[p + j] = re + ro;
  25104. itws[p + j] = ie + io;
  25105. rtws[p + j + s] = re - ro;
  25106. itws[p + j + s] = ie - io;
  25107. /* jshint maxdepth : false */
  25108. if (j !== l) {
  25109. rx = rtwdf * rtwdf_ - itwdf * itwdf_;
  25110. itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_;
  25111. rtwdf_ = rx;
  25112. }
  25113. }
  25114. }
  25115. }
  25116. };
  25117. FFTM.prototype.guessLen13b = function guessLen13b(n, m) {
  25118. var N = Math.max(m, n) | 1;
  25119. var odd = N & 1;
  25120. var i = 0;
  25121. for (N = N / 2 | 0; N; N = N >>> 1) {
  25122. i++;
  25123. }
  25124. return 1 << i + 1 + odd;
  25125. };
  25126. FFTM.prototype.conjugate = function conjugate(rws, iws, N) {
  25127. if (N <= 1) return;
  25128. for (var i = 0; i < N / 2; i++) {
  25129. var t = rws[i];
  25130. rws[i] = rws[N - i - 1];
  25131. rws[N - i - 1] = t;
  25132. t = iws[i];
  25133. iws[i] = -iws[N - i - 1];
  25134. iws[N - i - 1] = -t;
  25135. }
  25136. };
  25137. FFTM.prototype.normalize13b = function normalize13b(ws, N) {
  25138. var carry = 0;
  25139. for (var i = 0; i < N / 2; i++) {
  25140. var w = Math.round(ws[2 * i + 1] / N) * 0x2000 + Math.round(ws[2 * i] / N) + carry;
  25141. ws[i] = w & 0x3ffffff;
  25142. if (w < 0x4000000) {
  25143. carry = 0;
  25144. } else {
  25145. carry = w / 0x4000000 | 0;
  25146. }
  25147. }
  25148. return ws;
  25149. };
  25150. FFTM.prototype.convert13b = function convert13b(ws, len, rws, N) {
  25151. var carry = 0;
  25152. for (var i = 0; i < len; i++) {
  25153. carry = carry + (ws[i] | 0);
  25154. rws[2 * i] = carry & 0x1fff;
  25155. carry = carry >>> 13;
  25156. rws[2 * i + 1] = carry & 0x1fff;
  25157. carry = carry >>> 13;
  25158. } // Pad with zeroes
  25159. for (i = 2 * len; i < N; ++i) {
  25160. rws[i] = 0;
  25161. }
  25162. assert(carry === 0);
  25163. assert((carry & ~0x1fff) === 0);
  25164. };
  25165. FFTM.prototype.stub = function stub(N) {
  25166. var ph = new Array(N);
  25167. for (var i = 0; i < N; i++) {
  25168. ph[i] = 0;
  25169. }
  25170. return ph;
  25171. };
  25172. FFTM.prototype.mulp = function mulp(x, y, out) {
  25173. var N = 2 * this.guessLen13b(x.length, y.length);
  25174. var rbt = this.makeRBT(N);
  25175. var _ = this.stub(N);
  25176. var rws = new Array(N);
  25177. var rwst = new Array(N);
  25178. var iwst = new Array(N);
  25179. var nrws = new Array(N);
  25180. var nrwst = new Array(N);
  25181. var niwst = new Array(N);
  25182. var rmws = out.words;
  25183. rmws.length = N;
  25184. this.convert13b(x.words, x.length, rws, N);
  25185. this.convert13b(y.words, y.length, nrws, N);
  25186. this.transform(rws, _, rwst, iwst, N, rbt);
  25187. this.transform(nrws, _, nrwst, niwst, N, rbt);
  25188. for (var i = 0; i < N; i++) {
  25189. var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
  25190. iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i];
  25191. rwst[i] = rx;
  25192. }
  25193. this.conjugate(rwst, iwst, N);
  25194. this.transform(rwst, iwst, rmws, _, N, rbt);
  25195. this.conjugate(rmws, _, N);
  25196. this.normalize13b(rmws, N);
  25197. out.negative = x.negative ^ y.negative;
  25198. out.length = x.length + y.length;
  25199. return out.strip();
  25200. }; // Multiply `this` by `num`
  25201. BN.prototype.mul = function mul(num) {
  25202. var out = new BN(null);
  25203. out.words = new Array(this.length + num.length);
  25204. return this.mulTo(num, out);
  25205. }; // Multiply employing FFT
  25206. BN.prototype.mulf = function mulf(num) {
  25207. var out = new BN(null);
  25208. out.words = new Array(this.length + num.length);
  25209. return jumboMulTo(this, num, out);
  25210. }; // In-place Multiplication
  25211. BN.prototype.imul = function imul(num) {
  25212. return this.clone().mulTo(num, this);
  25213. };
  25214. BN.prototype.imuln = function imuln(num) {
  25215. assert(typeof num === 'number');
  25216. assert(num < 0x4000000); // Carry
  25217. var carry = 0;
  25218. for (var i = 0; i < this.length; i++) {
  25219. var w = (this.words[i] | 0) * num;
  25220. var lo = (w & 0x3ffffff) + (carry & 0x3ffffff);
  25221. carry >>= 26;
  25222. carry += w / 0x4000000 | 0; // NOTE: lo is 27bit maximum
  25223. carry += lo >>> 26;
  25224. this.words[i] = lo & 0x3ffffff;
  25225. }
  25226. if (carry !== 0) {
  25227. this.words[i] = carry;
  25228. this.length++;
  25229. }
  25230. return this;
  25231. };
  25232. BN.prototype.muln = function muln(num) {
  25233. return this.clone().imuln(num);
  25234. }; // `this` * `this`
  25235. BN.prototype.sqr = function sqr() {
  25236. return this.mul(this);
  25237. }; // `this` * `this` in-place
  25238. BN.prototype.isqr = function isqr() {
  25239. return this.imul(this.clone());
  25240. }; // Math.pow(`this`, `num`)
  25241. BN.prototype.pow = function pow(num) {
  25242. var w = toBitArray(num);
  25243. if (w.length === 0) return new BN(1); // Skip leading zeroes
  25244. var res = this;
  25245. for (var i = 0; i < w.length; i++, res = res.sqr()) {
  25246. if (w[i] !== 0) break;
  25247. }
  25248. if (++i < w.length) {
  25249. for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) {
  25250. if (w[i] === 0) continue;
  25251. res = res.mul(q);
  25252. }
  25253. }
  25254. return res;
  25255. }; // Shift-left in-place
  25256. BN.prototype.iushln = function iushln(bits) {
  25257. assert(typeof bits === 'number' && bits >= 0);
  25258. var r = bits % 26;
  25259. var s = (bits - r) / 26;
  25260. var carryMask = 0x3ffffff >>> 26 - r << 26 - r;
  25261. var i;
  25262. if (r !== 0) {
  25263. var carry = 0;
  25264. for (i = 0; i < this.length; i++) {
  25265. var newCarry = this.words[i] & carryMask;
  25266. var c = (this.words[i] | 0) - newCarry << r;
  25267. this.words[i] = c | carry;
  25268. carry = newCarry >>> 26 - r;
  25269. }
  25270. if (carry) {
  25271. this.words[i] = carry;
  25272. this.length++;
  25273. }
  25274. }
  25275. if (s !== 0) {
  25276. for (i = this.length - 1; i >= 0; i--) {
  25277. this.words[i + s] = this.words[i];
  25278. }
  25279. for (i = 0; i < s; i++) {
  25280. this.words[i] = 0;
  25281. }
  25282. this.length += s;
  25283. }
  25284. return this.strip();
  25285. };
  25286. BN.prototype.ishln = function ishln(bits) {
  25287. // TODO(indutny): implement me
  25288. assert(this.negative === 0);
  25289. return this.iushln(bits);
  25290. }; // Shift-right in-place
  25291. // NOTE: `hint` is a lowest bit before trailing zeroes
  25292. // NOTE: if `extended` is present - it will be filled with destroyed bits
  25293. BN.prototype.iushrn = function iushrn(bits, hint, extended) {
  25294. assert(typeof bits === 'number' && bits >= 0);
  25295. var h;
  25296. if (hint) {
  25297. h = (hint - hint % 26) / 26;
  25298. } else {
  25299. h = 0;
  25300. }
  25301. var r = bits % 26;
  25302. var s = Math.min((bits - r) / 26, this.length);
  25303. var mask = 0x3ffffff ^ 0x3ffffff >>> r << r;
  25304. var maskedWords = extended;
  25305. h -= s;
  25306. h = Math.max(0, h); // Extended mode, copy masked part
  25307. if (maskedWords) {
  25308. for (var i = 0; i < s; i++) {
  25309. maskedWords.words[i] = this.words[i];
  25310. }
  25311. maskedWords.length = s;
  25312. }
  25313. if (s === 0) {// No-op, we should not move anything at all
  25314. } else if (this.length > s) {
  25315. this.length -= s;
  25316. for (i = 0; i < this.length; i++) {
  25317. this.words[i] = this.words[i + s];
  25318. }
  25319. } else {
  25320. this.words[0] = 0;
  25321. this.length = 1;
  25322. }
  25323. var carry = 0;
  25324. for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
  25325. var word = this.words[i] | 0;
  25326. this.words[i] = carry << 26 - r | word >>> r;
  25327. carry = word & mask;
  25328. } // Push carried bits as a mask
  25329. if (maskedWords && carry !== 0) {
  25330. maskedWords.words[maskedWords.length++] = carry;
  25331. }
  25332. if (this.length === 0) {
  25333. this.words[0] = 0;
  25334. this.length = 1;
  25335. }
  25336. return this.strip();
  25337. };
  25338. BN.prototype.ishrn = function ishrn(bits, hint, extended) {
  25339. // TODO(indutny): implement me
  25340. assert(this.negative === 0);
  25341. return this.iushrn(bits, hint, extended);
  25342. }; // Shift-left
  25343. BN.prototype.shln = function shln(bits) {
  25344. return this.clone().ishln(bits);
  25345. };
  25346. BN.prototype.ushln = function ushln(bits) {
  25347. return this.clone().iushln(bits);
  25348. }; // Shift-right
  25349. BN.prototype.shrn = function shrn(bits) {
  25350. return this.clone().ishrn(bits);
  25351. };
  25352. BN.prototype.ushrn = function ushrn(bits) {
  25353. return this.clone().iushrn(bits);
  25354. }; // Test if n bit is set
  25355. BN.prototype.testn = function testn(bit) {
  25356. assert(typeof bit === 'number' && bit >= 0);
  25357. var r = bit % 26;
  25358. var s = (bit - r) / 26;
  25359. var q = 1 << r; // Fast case: bit is much higher than all existing words
  25360. if (this.length <= s) return false; // Check bit and return
  25361. var w = this.words[s];
  25362. return !!(w & q);
  25363. }; // Return only lowers bits of number (in-place)
  25364. BN.prototype.imaskn = function imaskn(bits) {
  25365. assert(typeof bits === 'number' && bits >= 0);
  25366. var r = bits % 26;
  25367. var s = (bits - r) / 26;
  25368. assert(this.negative === 0, 'imaskn works only with positive numbers');
  25369. if (this.length <= s) {
  25370. return this;
  25371. }
  25372. if (r !== 0) {
  25373. s++;
  25374. }
  25375. this.length = Math.min(s, this.length);
  25376. if (r !== 0) {
  25377. var mask = 0x3ffffff ^ 0x3ffffff >>> r << r;
  25378. this.words[this.length - 1] &= mask;
  25379. }
  25380. return this.strip();
  25381. }; // Return only lowers bits of number
  25382. BN.prototype.maskn = function maskn(bits) {
  25383. return this.clone().imaskn(bits);
  25384. }; // Add plain number `num` to `this`
  25385. BN.prototype.iaddn = function iaddn(num) {
  25386. assert(typeof num === 'number');
  25387. assert(num < 0x4000000);
  25388. if (num < 0) return this.isubn(-num); // Possible sign change
  25389. if (this.negative !== 0) {
  25390. if (this.length === 1 && (this.words[0] | 0) < num) {
  25391. this.words[0] = num - (this.words[0] | 0);
  25392. this.negative = 0;
  25393. return this;
  25394. }
  25395. this.negative = 0;
  25396. this.isubn(num);
  25397. this.negative = 1;
  25398. return this;
  25399. } // Add without checks
  25400. return this._iaddn(num);
  25401. };
  25402. BN.prototype._iaddn = function _iaddn(num) {
  25403. this.words[0] += num; // Carry
  25404. for (var i = 0; i < this.length && this.words[i] >= 0x4000000; i++) {
  25405. this.words[i] -= 0x4000000;
  25406. if (i === this.length - 1) {
  25407. this.words[i + 1] = 1;
  25408. } else {
  25409. this.words[i + 1]++;
  25410. }
  25411. }
  25412. this.length = Math.max(this.length, i + 1);
  25413. return this;
  25414. }; // Subtract plain number `num` from `this`
  25415. BN.prototype.isubn = function isubn(num) {
  25416. assert(typeof num === 'number');
  25417. assert(num < 0x4000000);
  25418. if (num < 0) return this.iaddn(-num);
  25419. if (this.negative !== 0) {
  25420. this.negative = 0;
  25421. this.iaddn(num);
  25422. this.negative = 1;
  25423. return this;
  25424. }
  25425. this.words[0] -= num;
  25426. if (this.length === 1 && this.words[0] < 0) {
  25427. this.words[0] = -this.words[0];
  25428. this.negative = 1;
  25429. } else {
  25430. // Carry
  25431. for (var i = 0; i < this.length && this.words[i] < 0; i++) {
  25432. this.words[i] += 0x4000000;
  25433. this.words[i + 1] -= 1;
  25434. }
  25435. }
  25436. return this.strip();
  25437. };
  25438. BN.prototype.addn = function addn(num) {
  25439. return this.clone().iaddn(num);
  25440. };
  25441. BN.prototype.subn = function subn(num) {
  25442. return this.clone().isubn(num);
  25443. };
  25444. BN.prototype.iabs = function iabs() {
  25445. this.negative = 0;
  25446. return this;
  25447. };
  25448. BN.prototype.abs = function abs() {
  25449. return this.clone().iabs();
  25450. };
  25451. BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) {
  25452. var len = num.length + shift;
  25453. var i;
  25454. this._expand(len);
  25455. var w;
  25456. var carry = 0;
  25457. for (i = 0; i < num.length; i++) {
  25458. w = (this.words[i + shift] | 0) + carry;
  25459. var right = (num.words[i] | 0) * mul;
  25460. w -= right & 0x3ffffff;
  25461. carry = (w >> 26) - (right / 0x4000000 | 0);
  25462. this.words[i + shift] = w & 0x3ffffff;
  25463. }
  25464. for (; i < this.length - shift; i++) {
  25465. w = (this.words[i + shift] | 0) + carry;
  25466. carry = w >> 26;
  25467. this.words[i + shift] = w & 0x3ffffff;
  25468. }
  25469. if (carry === 0) return this.strip(); // Subtraction overflow
  25470. assert(carry === -1);
  25471. carry = 0;
  25472. for (i = 0; i < this.length; i++) {
  25473. w = -(this.words[i] | 0) + carry;
  25474. carry = w >> 26;
  25475. this.words[i] = w & 0x3ffffff;
  25476. }
  25477. this.negative = 1;
  25478. return this.strip();
  25479. };
  25480. BN.prototype._wordDiv = function _wordDiv(num, mode) {
  25481. var shift = this.length - num.length;
  25482. var a = this.clone();
  25483. var b = num; // Normalize
  25484. var bhi = b.words[b.length - 1] | 0;
  25485. var bhiBits = this._countBits(bhi);
  25486. shift = 26 - bhiBits;
  25487. if (shift !== 0) {
  25488. b = b.ushln(shift);
  25489. a.iushln(shift);
  25490. bhi = b.words[b.length - 1] | 0;
  25491. } // Initialize quotient
  25492. var m = a.length - b.length;
  25493. var q;
  25494. if (mode !== 'mod') {
  25495. q = new BN(null);
  25496. q.length = m + 1;
  25497. q.words = new Array(q.length);
  25498. for (var i = 0; i < q.length; i++) {
  25499. q.words[i] = 0;
  25500. }
  25501. }
  25502. var diff = a.clone()._ishlnsubmul(b, 1, m);
  25503. if (diff.negative === 0) {
  25504. a = diff;
  25505. if (q) {
  25506. q.words[m] = 1;
  25507. }
  25508. }
  25509. for (var j = m - 1; j >= 0; j--) {
  25510. var qj = (a.words[b.length + j] | 0) * 0x4000000 + (a.words[b.length + j - 1] | 0); // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max
  25511. // (0x7ffffff)
  25512. qj = Math.min(qj / bhi | 0, 0x3ffffff);
  25513. a._ishlnsubmul(b, qj, j);
  25514. while (a.negative !== 0) {
  25515. qj--;
  25516. a.negative = 0;
  25517. a._ishlnsubmul(b, 1, j);
  25518. if (!a.isZero()) {
  25519. a.negative ^= 1;
  25520. }
  25521. }
  25522. if (q) {
  25523. q.words[j] = qj;
  25524. }
  25525. }
  25526. if (q) {
  25527. q.strip();
  25528. }
  25529. a.strip(); // Denormalize
  25530. if (mode !== 'div' && shift !== 0) {
  25531. a.iushrn(shift);
  25532. }
  25533. return {
  25534. div: q || null,
  25535. mod: a
  25536. };
  25537. }; // NOTE: 1) `mode` can be set to `mod` to request mod only,
  25538. // to `div` to request div only, or be absent to
  25539. // request both div & mod
  25540. // 2) `positive` is true if unsigned mod is requested
  25541. BN.prototype.divmod = function divmod(num, mode, positive) {
  25542. assert(!num.isZero());
  25543. if (this.isZero()) {
  25544. return {
  25545. div: new BN(0),
  25546. mod: new BN(0)
  25547. };
  25548. }
  25549. var div, mod, res;
  25550. if (this.negative !== 0 && num.negative === 0) {
  25551. res = this.neg().divmod(num, mode);
  25552. if (mode !== 'mod') {
  25553. div = res.div.neg();
  25554. }
  25555. if (mode !== 'div') {
  25556. mod = res.mod.neg();
  25557. if (positive && mod.negative !== 0) {
  25558. mod.iadd(num);
  25559. }
  25560. }
  25561. return {
  25562. div: div,
  25563. mod: mod
  25564. };
  25565. }
  25566. if (this.negative === 0 && num.negative !== 0) {
  25567. res = this.divmod(num.neg(), mode);
  25568. if (mode !== 'mod') {
  25569. div = res.div.neg();
  25570. }
  25571. return {
  25572. div: div,
  25573. mod: res.mod
  25574. };
  25575. }
  25576. if ((this.negative & num.negative) !== 0) {
  25577. res = this.neg().divmod(num.neg(), mode);
  25578. if (mode !== 'div') {
  25579. mod = res.mod.neg();
  25580. if (positive && mod.negative !== 0) {
  25581. mod.isub(num);
  25582. }
  25583. }
  25584. return {
  25585. div: res.div,
  25586. mod: mod
  25587. };
  25588. } // Both numbers are positive at this point
  25589. // Strip both numbers to approximate shift value
  25590. if (num.length > this.length || this.cmp(num) < 0) {
  25591. return {
  25592. div: new BN(0),
  25593. mod: this
  25594. };
  25595. } // Very short reduction
  25596. if (num.length === 1) {
  25597. if (mode === 'div') {
  25598. return {
  25599. div: this.divn(num.words[0]),
  25600. mod: null
  25601. };
  25602. }
  25603. if (mode === 'mod') {
  25604. return {
  25605. div: null,
  25606. mod: new BN(this.modn(num.words[0]))
  25607. };
  25608. }
  25609. return {
  25610. div: this.divn(num.words[0]),
  25611. mod: new BN(this.modn(num.words[0]))
  25612. };
  25613. }
  25614. return this._wordDiv(num, mode);
  25615. }; // Find `this` / `num`
  25616. BN.prototype.div = function div(num) {
  25617. return this.divmod(num, 'div', false).div;
  25618. }; // Find `this` % `num`
  25619. BN.prototype.mod = function mod(num) {
  25620. return this.divmod(num, 'mod', false).mod;
  25621. };
  25622. BN.prototype.umod = function umod(num) {
  25623. return this.divmod(num, 'mod', true).mod;
  25624. }; // Find Round(`this` / `num`)
  25625. BN.prototype.divRound = function divRound(num) {
  25626. var dm = this.divmod(num); // Fast case - exact division
  25627. if (dm.mod.isZero()) return dm.div;
  25628. var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
  25629. var half = num.ushrn(1);
  25630. var r2 = num.andln(1);
  25631. var cmp = mod.cmp(half); // Round down
  25632. if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; // Round up
  25633. return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
  25634. };
  25635. BN.prototype.modn = function modn(num) {
  25636. assert(num <= 0x3ffffff);
  25637. var p = (1 << 26) % num;
  25638. var acc = 0;
  25639. for (var i = this.length - 1; i >= 0; i--) {
  25640. acc = (p * acc + (this.words[i] | 0)) % num;
  25641. }
  25642. return acc;
  25643. }; // In-place division by number
  25644. BN.prototype.idivn = function idivn(num) {
  25645. assert(num <= 0x3ffffff);
  25646. var carry = 0;
  25647. for (var i = this.length - 1; i >= 0; i--) {
  25648. var w = (this.words[i] | 0) + carry * 0x4000000;
  25649. this.words[i] = w / num | 0;
  25650. carry = w % num;
  25651. }
  25652. return this.strip();
  25653. };
  25654. BN.prototype.divn = function divn(num) {
  25655. return this.clone().idivn(num);
  25656. };
  25657. BN.prototype.egcd = function egcd(p) {
  25658. assert(p.negative === 0);
  25659. assert(!p.isZero());
  25660. var x = this;
  25661. var y = p.clone();
  25662. if (x.negative !== 0) {
  25663. x = x.umod(p);
  25664. } else {
  25665. x = x.clone();
  25666. } // A * x + B * y = x
  25667. var A = new BN(1);
  25668. var B = new BN(0); // C * x + D * y = y
  25669. var C = new BN(0);
  25670. var D = new BN(1);
  25671. var g = 0;
  25672. while (x.isEven() && y.isEven()) {
  25673. x.iushrn(1);
  25674. y.iushrn(1);
  25675. ++g;
  25676. }
  25677. var yp = y.clone();
  25678. var xp = x.clone();
  25679. while (!x.isZero()) {
  25680. for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1) {
  25681. ;
  25682. }
  25683. if (i > 0) {
  25684. x.iushrn(i);
  25685. while (i-- > 0) {
  25686. if (A.isOdd() || B.isOdd()) {
  25687. A.iadd(yp);
  25688. B.isub(xp);
  25689. }
  25690. A.iushrn(1);
  25691. B.iushrn(1);
  25692. }
  25693. }
  25694. for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1) {
  25695. ;
  25696. }
  25697. if (j > 0) {
  25698. y.iushrn(j);
  25699. while (j-- > 0) {
  25700. if (C.isOdd() || D.isOdd()) {
  25701. C.iadd(yp);
  25702. D.isub(xp);
  25703. }
  25704. C.iushrn(1);
  25705. D.iushrn(1);
  25706. }
  25707. }
  25708. if (x.cmp(y) >= 0) {
  25709. x.isub(y);
  25710. A.isub(C);
  25711. B.isub(D);
  25712. } else {
  25713. y.isub(x);
  25714. C.isub(A);
  25715. D.isub(B);
  25716. }
  25717. }
  25718. return {
  25719. a: C,
  25720. b: D,
  25721. gcd: y.iushln(g)
  25722. };
  25723. }; // This is reduced incarnation of the binary EEA
  25724. // above, designated to invert members of the
  25725. // _prime_ fields F(p) at a maximal speed
  25726. BN.prototype._invmp = function _invmp(p) {
  25727. assert(p.negative === 0);
  25728. assert(!p.isZero());
  25729. var a = this;
  25730. var b = p.clone();
  25731. if (a.negative !== 0) {
  25732. a = a.umod(p);
  25733. } else {
  25734. a = a.clone();
  25735. }
  25736. var x1 = new BN(1);
  25737. var x2 = new BN(0);
  25738. var delta = b.clone();
  25739. while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
  25740. for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1) {
  25741. ;
  25742. }
  25743. if (i > 0) {
  25744. a.iushrn(i);
  25745. while (i-- > 0) {
  25746. if (x1.isOdd()) {
  25747. x1.iadd(delta);
  25748. }
  25749. x1.iushrn(1);
  25750. }
  25751. }
  25752. for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1) {
  25753. ;
  25754. }
  25755. if (j > 0) {
  25756. b.iushrn(j);
  25757. while (j-- > 0) {
  25758. if (x2.isOdd()) {
  25759. x2.iadd(delta);
  25760. }
  25761. x2.iushrn(1);
  25762. }
  25763. }
  25764. if (a.cmp(b) >= 0) {
  25765. a.isub(b);
  25766. x1.isub(x2);
  25767. } else {
  25768. b.isub(a);
  25769. x2.isub(x1);
  25770. }
  25771. }
  25772. var res;
  25773. if (a.cmpn(1) === 0) {
  25774. res = x1;
  25775. } else {
  25776. res = x2;
  25777. }
  25778. if (res.cmpn(0) < 0) {
  25779. res.iadd(p);
  25780. }
  25781. return res;
  25782. };
  25783. BN.prototype.gcd = function gcd(num) {
  25784. if (this.isZero()) return num.abs();
  25785. if (num.isZero()) return this.abs();
  25786. var a = this.clone();
  25787. var b = num.clone();
  25788. a.negative = 0;
  25789. b.negative = 0; // Remove common factor of two
  25790. for (var shift = 0; a.isEven() && b.isEven(); shift++) {
  25791. a.iushrn(1);
  25792. b.iushrn(1);
  25793. }
  25794. do {
  25795. while (a.isEven()) {
  25796. a.iushrn(1);
  25797. }
  25798. while (b.isEven()) {
  25799. b.iushrn(1);
  25800. }
  25801. var r = a.cmp(b);
  25802. if (r < 0) {
  25803. // Swap `a` and `b` to make `a` always bigger than `b`
  25804. var t = a;
  25805. a = b;
  25806. b = t;
  25807. } else if (r === 0 || b.cmpn(1) === 0) {
  25808. break;
  25809. }
  25810. a.isub(b);
  25811. } while (true);
  25812. return b.iushln(shift);
  25813. }; // Invert number in the field F(num)
  25814. BN.prototype.invm = function invm(num) {
  25815. return this.egcd(num).a.umod(num);
  25816. };
  25817. BN.prototype.isEven = function isEven() {
  25818. return (this.words[0] & 1) === 0;
  25819. };
  25820. BN.prototype.isOdd = function isOdd() {
  25821. return (this.words[0] & 1) === 1;
  25822. }; // And first word and num
  25823. BN.prototype.andln = function andln(num) {
  25824. return this.words[0] & num;
  25825. }; // Increment at the bit position in-line
  25826. BN.prototype.bincn = function bincn(bit) {
  25827. assert(typeof bit === 'number');
  25828. var r = bit % 26;
  25829. var s = (bit - r) / 26;
  25830. var q = 1 << r; // Fast case: bit is much higher than all existing words
  25831. if (this.length <= s) {
  25832. this._expand(s + 1);
  25833. this.words[s] |= q;
  25834. return this;
  25835. } // Add bit and propagate, if needed
  25836. var carry = q;
  25837. for (var i = s; carry !== 0 && i < this.length; i++) {
  25838. var w = this.words[i] | 0;
  25839. w += carry;
  25840. carry = w >>> 26;
  25841. w &= 0x3ffffff;
  25842. this.words[i] = w;
  25843. }
  25844. if (carry !== 0) {
  25845. this.words[i] = carry;
  25846. this.length++;
  25847. }
  25848. return this;
  25849. };
  25850. BN.prototype.isZero = function isZero() {
  25851. return this.length === 1 && this.words[0] === 0;
  25852. };
  25853. BN.prototype.cmpn = function cmpn(num) {
  25854. var negative = num < 0;
  25855. if (this.negative !== 0 && !negative) return -1;
  25856. if (this.negative === 0 && negative) return 1;
  25857. this.strip();
  25858. var res;
  25859. if (this.length > 1) {
  25860. res = 1;
  25861. } else {
  25862. if (negative) {
  25863. num = -num;
  25864. }
  25865. assert(num <= 0x3ffffff, 'Number is too big');
  25866. var w = this.words[0] | 0;
  25867. res = w === num ? 0 : w < num ? -1 : 1;
  25868. }
  25869. if (this.negative !== 0) return -res | 0;
  25870. return res;
  25871. }; // Compare two numbers and return:
  25872. // 1 - if `this` > `num`
  25873. // 0 - if `this` == `num`
  25874. // -1 - if `this` < `num`
  25875. BN.prototype.cmp = function cmp(num) {
  25876. if (this.negative !== 0 && num.negative === 0) return -1;
  25877. if (this.negative === 0 && num.negative !== 0) return 1;
  25878. var res = this.ucmp(num);
  25879. if (this.negative !== 0) return -res | 0;
  25880. return res;
  25881. }; // Unsigned comparison
  25882. BN.prototype.ucmp = function ucmp(num) {
  25883. // At this point both numbers have the same sign
  25884. if (this.length > num.length) return 1;
  25885. if (this.length < num.length) return -1;
  25886. var res = 0;
  25887. for (var i = this.length - 1; i >= 0; i--) {
  25888. var a = this.words[i] | 0;
  25889. var b = num.words[i] | 0;
  25890. if (a === b) continue;
  25891. if (a < b) {
  25892. res = -1;
  25893. } else if (a > b) {
  25894. res = 1;
  25895. }
  25896. break;
  25897. }
  25898. return res;
  25899. };
  25900. BN.prototype.gtn = function gtn(num) {
  25901. return this.cmpn(num) === 1;
  25902. };
  25903. BN.prototype.gt = function gt(num) {
  25904. return this.cmp(num) === 1;
  25905. };
  25906. BN.prototype.gten = function gten(num) {
  25907. return this.cmpn(num) >= 0;
  25908. };
  25909. BN.prototype.gte = function gte(num) {
  25910. return this.cmp(num) >= 0;
  25911. };
  25912. BN.prototype.ltn = function ltn(num) {
  25913. return this.cmpn(num) === -1;
  25914. };
  25915. BN.prototype.lt = function lt(num) {
  25916. return this.cmp(num) === -1;
  25917. };
  25918. BN.prototype.lten = function lten(num) {
  25919. return this.cmpn(num) <= 0;
  25920. };
  25921. BN.prototype.lte = function lte(num) {
  25922. return this.cmp(num) <= 0;
  25923. };
  25924. BN.prototype.eqn = function eqn(num) {
  25925. return this.cmpn(num) === 0;
  25926. };
  25927. BN.prototype.eq = function eq(num) {
  25928. return this.cmp(num) === 0;
  25929. }; //
  25930. // A reduce context, could be using montgomery or something better, depending
  25931. // on the `m` itself.
  25932. //
  25933. BN.red = function red(num) {
  25934. return new Red(num);
  25935. };
  25936. BN.prototype.toRed = function toRed(ctx) {
  25937. assert(!this.red, 'Already a number in reduction context');
  25938. assert(this.negative === 0, 'red works only with positives');
  25939. return ctx.convertTo(this)._forceRed(ctx);
  25940. };
  25941. BN.prototype.fromRed = function fromRed() {
  25942. assert(this.red, 'fromRed works only with numbers in reduction context');
  25943. return this.red.convertFrom(this);
  25944. };
  25945. BN.prototype._forceRed = function _forceRed(ctx) {
  25946. this.red = ctx;
  25947. return this;
  25948. };
  25949. BN.prototype.forceRed = function forceRed(ctx) {
  25950. assert(!this.red, 'Already a number in reduction context');
  25951. return this._forceRed(ctx);
  25952. };
  25953. BN.prototype.redAdd = function redAdd(num) {
  25954. assert(this.red, 'redAdd works only with red numbers');
  25955. return this.red.add(this, num);
  25956. };
  25957. BN.prototype.redIAdd = function redIAdd(num) {
  25958. assert(this.red, 'redIAdd works only with red numbers');
  25959. return this.red.iadd(this, num);
  25960. };
  25961. BN.prototype.redSub = function redSub(num) {
  25962. assert(this.red, 'redSub works only with red numbers');
  25963. return this.red.sub(this, num);
  25964. };
  25965. BN.prototype.redISub = function redISub(num) {
  25966. assert(this.red, 'redISub works only with red numbers');
  25967. return this.red.isub(this, num);
  25968. };
  25969. BN.prototype.redShl = function redShl(num) {
  25970. assert(this.red, 'redShl works only with red numbers');
  25971. return this.red.shl(this, num);
  25972. };
  25973. BN.prototype.redMul = function redMul(num) {
  25974. assert(this.red, 'redMul works only with red numbers');
  25975. this.red._verify2(this, num);
  25976. return this.red.mul(this, num);
  25977. };
  25978. BN.prototype.redIMul = function redIMul(num) {
  25979. assert(this.red, 'redMul works only with red numbers');
  25980. this.red._verify2(this, num);
  25981. return this.red.imul(this, num);
  25982. };
  25983. BN.prototype.redSqr = function redSqr() {
  25984. assert(this.red, 'redSqr works only with red numbers');
  25985. this.red._verify1(this);
  25986. return this.red.sqr(this);
  25987. };
  25988. BN.prototype.redISqr = function redISqr() {
  25989. assert(this.red, 'redISqr works only with red numbers');
  25990. this.red._verify1(this);
  25991. return this.red.isqr(this);
  25992. }; // Square root over p
  25993. BN.prototype.redSqrt = function redSqrt() {
  25994. assert(this.red, 'redSqrt works only with red numbers');
  25995. this.red._verify1(this);
  25996. return this.red.sqrt(this);
  25997. };
  25998. BN.prototype.redInvm = function redInvm() {
  25999. assert(this.red, 'redInvm works only with red numbers');
  26000. this.red._verify1(this);
  26001. return this.red.invm(this);
  26002. }; // Return negative clone of `this` % `red modulo`
  26003. BN.prototype.redNeg = function redNeg() {
  26004. assert(this.red, 'redNeg works only with red numbers');
  26005. this.red._verify1(this);
  26006. return this.red.neg(this);
  26007. };
  26008. BN.prototype.redPow = function redPow(num) {
  26009. assert(this.red && !num.red, 'redPow(normalNum)');
  26010. this.red._verify1(this);
  26011. return this.red.pow(this, num);
  26012. }; // Prime numbers with efficient reduction
  26013. var primes = {
  26014. k256: null,
  26015. p224: null,
  26016. p192: null,
  26017. p25519: null
  26018. }; // Pseudo-Mersenne prime
  26019. function MPrime(name, p) {
  26020. // P = 2 ^ N - K
  26021. this.name = name;
  26022. this.p = new BN(p, 16);
  26023. this.n = this.p.bitLength();
  26024. this.k = new BN(1).iushln(this.n).isub(this.p);
  26025. this.tmp = this._tmp();
  26026. }
  26027. MPrime.prototype._tmp = function _tmp() {
  26028. var tmp = new BN(null);
  26029. tmp.words = new Array(Math.ceil(this.n / 13));
  26030. return tmp;
  26031. };
  26032. MPrime.prototype.ireduce = function ireduce(num) {
  26033. // Assumes that `num` is less than `P^2`
  26034. // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P)
  26035. var r = num;
  26036. var rlen;
  26037. do {
  26038. this.split(r, this.tmp);
  26039. r = this.imulK(r);
  26040. r = r.iadd(this.tmp);
  26041. rlen = r.bitLength();
  26042. } while (rlen > this.n);
  26043. var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
  26044. if (cmp === 0) {
  26045. r.words[0] = 0;
  26046. r.length = 1;
  26047. } else if (cmp > 0) {
  26048. r.isub(this.p);
  26049. } else {
  26050. if (r.strip !== undefined) {
  26051. // r is BN v4 instance
  26052. r.strip();
  26053. } else {
  26054. // r is BN v5 instance
  26055. r._strip();
  26056. }
  26057. }
  26058. return r;
  26059. };
  26060. MPrime.prototype.split = function split(input, out) {
  26061. input.iushrn(this.n, 0, out);
  26062. };
  26063. MPrime.prototype.imulK = function imulK(num) {
  26064. return num.imul(this.k);
  26065. };
  26066. function K256() {
  26067. MPrime.call(this, 'k256', 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f');
  26068. }
  26069. inherits(K256, MPrime);
  26070. K256.prototype.split = function split(input, output) {
  26071. // 256 = 9 * 26 + 22
  26072. var mask = 0x3fffff;
  26073. var outLen = Math.min(input.length, 9);
  26074. for (var i = 0; i < outLen; i++) {
  26075. output.words[i] = input.words[i];
  26076. }
  26077. output.length = outLen;
  26078. if (input.length <= 9) {
  26079. input.words[0] = 0;
  26080. input.length = 1;
  26081. return;
  26082. } // Shift by 9 limbs
  26083. var prev = input.words[9];
  26084. output.words[output.length++] = prev & mask;
  26085. for (i = 10; i < input.length; i++) {
  26086. var next = input.words[i] | 0;
  26087. input.words[i - 10] = (next & mask) << 4 | prev >>> 22;
  26088. prev = next;
  26089. }
  26090. prev >>>= 22;
  26091. input.words[i - 10] = prev;
  26092. if (prev === 0 && input.length > 10) {
  26093. input.length -= 10;
  26094. } else {
  26095. input.length -= 9;
  26096. }
  26097. };
  26098. K256.prototype.imulK = function imulK(num) {
  26099. // K = 0x1000003d1 = [ 0x40, 0x3d1 ]
  26100. num.words[num.length] = 0;
  26101. num.words[num.length + 1] = 0;
  26102. num.length += 2; // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390
  26103. var lo = 0;
  26104. for (var i = 0; i < num.length; i++) {
  26105. var w = num.words[i] | 0;
  26106. lo += w * 0x3d1;
  26107. num.words[i] = lo & 0x3ffffff;
  26108. lo = w * 0x40 + (lo / 0x4000000 | 0);
  26109. } // Fast length reduction
  26110. if (num.words[num.length - 1] === 0) {
  26111. num.length--;
  26112. if (num.words[num.length - 1] === 0) {
  26113. num.length--;
  26114. }
  26115. }
  26116. return num;
  26117. };
  26118. function P224() {
  26119. MPrime.call(this, 'p224', 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001');
  26120. }
  26121. inherits(P224, MPrime);
  26122. function P192() {
  26123. MPrime.call(this, 'p192', 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff');
  26124. }
  26125. inherits(P192, MPrime);
  26126. function P25519() {
  26127. // 2 ^ 255 - 19
  26128. MPrime.call(this, '25519', '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed');
  26129. }
  26130. inherits(P25519, MPrime);
  26131. P25519.prototype.imulK = function imulK(num) {
  26132. // K = 0x13
  26133. var carry = 0;
  26134. for (var i = 0; i < num.length; i++) {
  26135. var hi = (num.words[i] | 0) * 0x13 + carry;
  26136. var lo = hi & 0x3ffffff;
  26137. hi >>>= 26;
  26138. num.words[i] = lo;
  26139. carry = hi;
  26140. }
  26141. if (carry !== 0) {
  26142. num.words[num.length++] = carry;
  26143. }
  26144. return num;
  26145. }; // Exported mostly for testing purposes, use plain name instead
  26146. BN._prime = function prime(name) {
  26147. // Cached version of prime
  26148. if (primes[name]) return primes[name];
  26149. var prime;
  26150. if (name === 'k256') {
  26151. prime = new K256();
  26152. } else if (name === 'p224') {
  26153. prime = new P224();
  26154. } else if (name === 'p192') {
  26155. prime = new P192();
  26156. } else if (name === 'p25519') {
  26157. prime = new P25519();
  26158. } else {
  26159. throw new Error('Unknown prime ' + name);
  26160. }
  26161. primes[name] = prime;
  26162. return prime;
  26163. }; //
  26164. // Base reduction engine
  26165. //
  26166. function Red(m) {
  26167. if (typeof m === 'string') {
  26168. var prime = BN._prime(m);
  26169. this.m = prime.p;
  26170. this.prime = prime;
  26171. } else {
  26172. assert(m.gtn(1), 'modulus must be greater than 1');
  26173. this.m = m;
  26174. this.prime = null;
  26175. }
  26176. }
  26177. Red.prototype._verify1 = function _verify1(a) {
  26178. assert(a.negative === 0, 'red works only with positives');
  26179. assert(a.red, 'red works only with red numbers');
  26180. };
  26181. Red.prototype._verify2 = function _verify2(a, b) {
  26182. assert((a.negative | b.negative) === 0, 'red works only with positives');
  26183. assert(a.red && a.red === b.red, 'red works only with red numbers');
  26184. };
  26185. Red.prototype.imod = function imod(a) {
  26186. if (this.prime) return this.prime.ireduce(a)._forceRed(this);
  26187. return a.umod(this.m)._forceRed(this);
  26188. };
  26189. Red.prototype.neg = function neg(a) {
  26190. if (a.isZero()) {
  26191. return a.clone();
  26192. }
  26193. return this.m.sub(a)._forceRed(this);
  26194. };
  26195. Red.prototype.add = function add(a, b) {
  26196. this._verify2(a, b);
  26197. var res = a.add(b);
  26198. if (res.cmp(this.m) >= 0) {
  26199. res.isub(this.m);
  26200. }
  26201. return res._forceRed(this);
  26202. };
  26203. Red.prototype.iadd = function iadd(a, b) {
  26204. this._verify2(a, b);
  26205. var res = a.iadd(b);
  26206. if (res.cmp(this.m) >= 0) {
  26207. res.isub(this.m);
  26208. }
  26209. return res;
  26210. };
  26211. Red.prototype.sub = function sub(a, b) {
  26212. this._verify2(a, b);
  26213. var res = a.sub(b);
  26214. if (res.cmpn(0) < 0) {
  26215. res.iadd(this.m);
  26216. }
  26217. return res._forceRed(this);
  26218. };
  26219. Red.prototype.isub = function isub(a, b) {
  26220. this._verify2(a, b);
  26221. var res = a.isub(b);
  26222. if (res.cmpn(0) < 0) {
  26223. res.iadd(this.m);
  26224. }
  26225. return res;
  26226. };
  26227. Red.prototype.shl = function shl(a, num) {
  26228. this._verify1(a);
  26229. return this.imod(a.ushln(num));
  26230. };
  26231. Red.prototype.imul = function imul(a, b) {
  26232. this._verify2(a, b);
  26233. return this.imod(a.imul(b));
  26234. };
  26235. Red.prototype.mul = function mul(a, b) {
  26236. this._verify2(a, b);
  26237. return this.imod(a.mul(b));
  26238. };
  26239. Red.prototype.isqr = function isqr(a) {
  26240. return this.imul(a, a.clone());
  26241. };
  26242. Red.prototype.sqr = function sqr(a) {
  26243. return this.mul(a, a);
  26244. };
  26245. Red.prototype.sqrt = function sqrt(a) {
  26246. if (a.isZero()) return a.clone();
  26247. var mod3 = this.m.andln(3);
  26248. assert(mod3 % 2 === 1); // Fast case
  26249. if (mod3 === 3) {
  26250. var pow = this.m.add(new BN(1)).iushrn(2);
  26251. return this.pow(a, pow);
  26252. } // Tonelli-Shanks algorithm (Totally unoptimized and slow)
  26253. //
  26254. // Find Q and S, that Q * 2 ^ S = (P - 1)
  26255. var q = this.m.subn(1);
  26256. var s = 0;
  26257. while (!q.isZero() && q.andln(1) === 0) {
  26258. s++;
  26259. q.iushrn(1);
  26260. }
  26261. assert(!q.isZero());
  26262. var one = new BN(1).toRed(this);
  26263. var nOne = one.redNeg(); // Find quadratic non-residue
  26264. // NOTE: Max is such because of generalized Riemann hypothesis.
  26265. var lpow = this.m.subn(1).iushrn(1);
  26266. var z = this.m.bitLength();
  26267. z = new BN(2 * z * z).toRed(this);
  26268. while (this.pow(z, lpow).cmp(nOne) !== 0) {
  26269. z.redIAdd(nOne);
  26270. }
  26271. var c = this.pow(z, q);
  26272. var r = this.pow(a, q.addn(1).iushrn(1));
  26273. var t = this.pow(a, q);
  26274. var m = s;
  26275. while (t.cmp(one) !== 0) {
  26276. var tmp = t;
  26277. for (var i = 0; tmp.cmp(one) !== 0; i++) {
  26278. tmp = tmp.redSqr();
  26279. }
  26280. assert(i < m);
  26281. var b = this.pow(c, new BN(1).iushln(m - i - 1));
  26282. r = r.redMul(b);
  26283. c = b.redSqr();
  26284. t = t.redMul(c);
  26285. m = i;
  26286. }
  26287. return r;
  26288. };
  26289. Red.prototype.invm = function invm(a) {
  26290. var inv = a._invmp(this.m);
  26291. if (inv.negative !== 0) {
  26292. inv.negative = 0;
  26293. return this.imod(inv).redNeg();
  26294. } else {
  26295. return this.imod(inv);
  26296. }
  26297. };
  26298. Red.prototype.pow = function pow(a, num) {
  26299. if (num.isZero()) return new BN(1).toRed(this);
  26300. if (num.cmpn(1) === 0) return a.clone();
  26301. var windowSize = 4;
  26302. var wnd = new Array(1 << windowSize);
  26303. wnd[0] = new BN(1).toRed(this);
  26304. wnd[1] = a;
  26305. for (var i = 2; i < wnd.length; i++) {
  26306. wnd[i] = this.mul(wnd[i - 1], a);
  26307. }
  26308. var res = wnd[0];
  26309. var current = 0;
  26310. var currentLen = 0;
  26311. var start = num.bitLength() % 26;
  26312. if (start === 0) {
  26313. start = 26;
  26314. }
  26315. for (i = num.length - 1; i >= 0; i--) {
  26316. var word = num.words[i];
  26317. for (var j = start - 1; j >= 0; j--) {
  26318. var bit = word >> j & 1;
  26319. if (res !== wnd[0]) {
  26320. res = this.sqr(res);
  26321. }
  26322. if (bit === 0 && current === 0) {
  26323. currentLen = 0;
  26324. continue;
  26325. }
  26326. current <<= 1;
  26327. current |= bit;
  26328. currentLen++;
  26329. if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue;
  26330. res = this.mul(res, wnd[current]);
  26331. currentLen = 0;
  26332. current = 0;
  26333. }
  26334. start = 26;
  26335. }
  26336. return res;
  26337. };
  26338. Red.prototype.convertTo = function convertTo(num) {
  26339. var r = num.umod(this.m);
  26340. return r === num ? r.clone() : r;
  26341. };
  26342. Red.prototype.convertFrom = function convertFrom(num) {
  26343. var res = num.clone();
  26344. res.red = null;
  26345. return res;
  26346. }; //
  26347. // Montgomery method engine
  26348. //
  26349. BN.mont = function mont(num) {
  26350. return new Mont(num);
  26351. };
  26352. function Mont(m) {
  26353. Red.call(this, m);
  26354. this.shift = this.m.bitLength();
  26355. if (this.shift % 26 !== 0) {
  26356. this.shift += 26 - this.shift % 26;
  26357. }
  26358. this.r = new BN(1).iushln(this.shift);
  26359. this.r2 = this.imod(this.r.sqr());
  26360. this.rinv = this.r._invmp(this.m);
  26361. this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
  26362. this.minv = this.minv.umod(this.r);
  26363. this.minv = this.r.sub(this.minv);
  26364. }
  26365. inherits(Mont, Red);
  26366. Mont.prototype.convertTo = function convertTo(num) {
  26367. return this.imod(num.ushln(this.shift));
  26368. };
  26369. Mont.prototype.convertFrom = function convertFrom(num) {
  26370. var r = this.imod(num.mul(this.rinv));
  26371. r.red = null;
  26372. return r;
  26373. };
  26374. Mont.prototype.imul = function imul(a, b) {
  26375. if (a.isZero() || b.isZero()) {
  26376. a.words[0] = 0;
  26377. a.length = 1;
  26378. return a;
  26379. }
  26380. var t = a.imul(b);
  26381. var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
  26382. var u = t.isub(c).iushrn(this.shift);
  26383. var res = u;
  26384. if (u.cmp(this.m) >= 0) {
  26385. res = u.isub(this.m);
  26386. } else if (u.cmpn(0) < 0) {
  26387. res = u.iadd(this.m);
  26388. }
  26389. return res._forceRed(this);
  26390. };
  26391. Mont.prototype.mul = function mul(a, b) {
  26392. if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
  26393. var t = a.mul(b);
  26394. var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
  26395. var u = t.isub(c).iushrn(this.shift);
  26396. var res = u;
  26397. if (u.cmp(this.m) >= 0) {
  26398. res = u.isub(this.m);
  26399. } else if (u.cmpn(0) < 0) {
  26400. res = u.iadd(this.m);
  26401. }
  26402. return res._forceRed(this);
  26403. };
  26404. Mont.prototype.invm = function invm(a) {
  26405. // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R
  26406. var res = this.imod(a._invmp(this.m).mul(this.r2));
  26407. return res._forceRed(this);
  26408. };
  26409. })(typeof module === 'undefined' || module, void 0);
  26410. },{"buffer":185}],182:[function(require,module,exports){
  26411. 'use strict';
  26412. exports.byteLength = byteLength;
  26413. exports.toByteArray = toByteArray;
  26414. exports.fromByteArray = fromByteArray;
  26415. var lookup = [];
  26416. var revLookup = [];
  26417. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
  26418. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  26419. for (var i = 0, len = code.length; i < len; ++i) {
  26420. lookup[i] = code[i];
  26421. revLookup[code.charCodeAt(i)] = i;
  26422. } // Support decoding URL-safe base64 strings, as Node.js does.
  26423. // See: https://en.wikipedia.org/wiki/Base64#URL_applications
  26424. revLookup['-'.charCodeAt(0)] = 62;
  26425. revLookup['_'.charCodeAt(0)] = 63;
  26426. function getLens(b64) {
  26427. var len = b64.length;
  26428. if (len % 4 > 0) {
  26429. throw new Error('Invalid string. Length must be a multiple of 4');
  26430. } // Trim off extra bytes after placeholder bytes are found
  26431. // See: https://github.com/beatgammit/base64-js/issues/42
  26432. var validLen = b64.indexOf('=');
  26433. if (validLen === -1) validLen = len;
  26434. var placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4;
  26435. return [validLen, placeHoldersLen];
  26436. } // base64 is 4/3 + up to two characters of the original data
  26437. function byteLength(b64) {
  26438. var lens = getLens(b64);
  26439. var validLen = lens[0];
  26440. var placeHoldersLen = lens[1];
  26441. return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
  26442. }
  26443. function _byteLength(b64, validLen, placeHoldersLen) {
  26444. return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
  26445. }
  26446. function toByteArray(b64) {
  26447. var tmp;
  26448. var lens = getLens(b64);
  26449. var validLen = lens[0];
  26450. var placeHoldersLen = lens[1];
  26451. var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
  26452. var curByte = 0; // if there are placeholders, only get up to the last complete 4 chars
  26453. var len = placeHoldersLen > 0 ? validLen - 4 : validLen;
  26454. var i;
  26455. for (i = 0; i < len; i += 4) {
  26456. tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)];
  26457. arr[curByte++] = tmp >> 16 & 0xFF;
  26458. arr[curByte++] = tmp >> 8 & 0xFF;
  26459. arr[curByte++] = tmp & 0xFF;
  26460. }
  26461. if (placeHoldersLen === 2) {
  26462. tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4;
  26463. arr[curByte++] = tmp & 0xFF;
  26464. }
  26465. if (placeHoldersLen === 1) {
  26466. tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2;
  26467. arr[curByte++] = tmp >> 8 & 0xFF;
  26468. arr[curByte++] = tmp & 0xFF;
  26469. }
  26470. return arr;
  26471. }
  26472. function tripletToBase64(num) {
  26473. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F];
  26474. }
  26475. function encodeChunk(uint8, start, end) {
  26476. var tmp;
  26477. var output = [];
  26478. for (var i = start; i < end; i += 3) {
  26479. tmp = (uint8[i] << 16 & 0xFF0000) + (uint8[i + 1] << 8 & 0xFF00) + (uint8[i + 2] & 0xFF);
  26480. output.push(tripletToBase64(tmp));
  26481. }
  26482. return output.join('');
  26483. }
  26484. function fromByteArray(uint8) {
  26485. var tmp;
  26486. var len = uint8.length;
  26487. var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
  26488. var parts = [];
  26489. var maxChunkLength = 16383; // must be multiple of 3
  26490. // go through the array every three bytes, we'll deal with trailing stuff later
  26491. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  26492. parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength));
  26493. } // pad the end with zeros, but make sure to not forget the extra bytes
  26494. if (extraBytes === 1) {
  26495. tmp = uint8[len - 1];
  26496. parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 0x3F] + '==');
  26497. } else if (extraBytes === 2) {
  26498. tmp = (uint8[len - 2] << 8) + uint8[len - 1];
  26499. parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 0x3F] + lookup[tmp << 2 & 0x3F] + '=');
  26500. }
  26501. return parts.join('');
  26502. }
  26503. },{}],183:[function(require,module,exports){
  26504. "use strict";
  26505. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  26506. (function (module, exports) {
  26507. 'use strict'; // Utils
  26508. function assert(val, msg) {
  26509. if (!val) throw new Error(msg || 'Assertion failed');
  26510. } // Could use `inherits` module, but don't want to move from single file
  26511. // architecture yet.
  26512. function inherits(ctor, superCtor) {
  26513. ctor.super_ = superCtor;
  26514. var TempCtor = function TempCtor() {};
  26515. TempCtor.prototype = superCtor.prototype;
  26516. ctor.prototype = new TempCtor();
  26517. ctor.prototype.constructor = ctor;
  26518. } // BN
  26519. function BN(number, base, endian) {
  26520. if (BN.isBN(number)) {
  26521. return number;
  26522. }
  26523. this.negative = 0;
  26524. this.words = null;
  26525. this.length = 0; // Reduction context
  26526. this.red = null;
  26527. if (number !== null) {
  26528. if (base === 'le' || base === 'be') {
  26529. endian = base;
  26530. base = 10;
  26531. }
  26532. this._init(number || 0, base || 10, endian || 'be');
  26533. }
  26534. }
  26535. if (_typeof(module) === 'object') {
  26536. module.exports = BN;
  26537. } else {
  26538. exports.BN = BN;
  26539. }
  26540. BN.BN = BN;
  26541. BN.wordSize = 26;
  26542. var Buffer;
  26543. try {
  26544. Buffer = require('buffer').Buffer;
  26545. } catch (e) {}
  26546. BN.isBN = function isBN(num) {
  26547. if (num instanceof BN) {
  26548. return true;
  26549. }
  26550. return num !== null && _typeof(num) === 'object' && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
  26551. };
  26552. BN.max = function max(left, right) {
  26553. if (left.cmp(right) > 0) return left;
  26554. return right;
  26555. };
  26556. BN.min = function min(left, right) {
  26557. if (left.cmp(right) < 0) return left;
  26558. return right;
  26559. };
  26560. BN.prototype._init = function init(number, base, endian) {
  26561. if (typeof number === 'number') {
  26562. return this._initNumber(number, base, endian);
  26563. }
  26564. if (_typeof(number) === 'object') {
  26565. return this._initArray(number, base, endian);
  26566. }
  26567. if (base === 'hex') {
  26568. base = 16;
  26569. }
  26570. assert(base === (base | 0) && base >= 2 && base <= 36);
  26571. number = number.toString().replace(/\s+/g, '');
  26572. var start = 0;
  26573. if (number[0] === '-') {
  26574. start++;
  26575. }
  26576. if (base === 16) {
  26577. this._parseHex(number, start);
  26578. } else {
  26579. this._parseBase(number, base, start);
  26580. }
  26581. if (number[0] === '-') {
  26582. this.negative = 1;
  26583. }
  26584. this._strip();
  26585. if (endian !== 'le') return;
  26586. this._initArray(this.toArray(), base, endian);
  26587. };
  26588. BN.prototype._initNumber = function _initNumber(number, base, endian) {
  26589. if (number < 0) {
  26590. this.negative = 1;
  26591. number = -number;
  26592. }
  26593. if (number < 0x4000000) {
  26594. this.words = [number & 0x3ffffff];
  26595. this.length = 1;
  26596. } else if (number < 0x10000000000000) {
  26597. this.words = [number & 0x3ffffff, number / 0x4000000 & 0x3ffffff];
  26598. this.length = 2;
  26599. } else {
  26600. assert(number < 0x20000000000000); // 2 ^ 53 (unsafe)
  26601. this.words = [number & 0x3ffffff, number / 0x4000000 & 0x3ffffff, 1];
  26602. this.length = 3;
  26603. }
  26604. if (endian !== 'le') return; // Reverse the bytes
  26605. this._initArray(this.toArray(), base, endian);
  26606. };
  26607. BN.prototype._initArray = function _initArray(number, base, endian) {
  26608. // Perhaps a Uint8Array
  26609. assert(typeof number.length === 'number');
  26610. if (number.length <= 0) {
  26611. this.words = [0];
  26612. this.length = 1;
  26613. return this;
  26614. }
  26615. this.length = Math.ceil(number.length / 3);
  26616. this.words = new Array(this.length);
  26617. for (var i = 0; i < this.length; i++) {
  26618. this.words[i] = 0;
  26619. }
  26620. var j, w;
  26621. var off = 0;
  26622. if (endian === 'be') {
  26623. for (i = number.length - 1, j = 0; i >= 0; i -= 3) {
  26624. w = number[i] | number[i - 1] << 8 | number[i - 2] << 16;
  26625. this.words[j] |= w << off & 0x3ffffff;
  26626. this.words[j + 1] = w >>> 26 - off & 0x3ffffff;
  26627. off += 24;
  26628. if (off >= 26) {
  26629. off -= 26;
  26630. j++;
  26631. }
  26632. }
  26633. } else if (endian === 'le') {
  26634. for (i = 0, j = 0; i < number.length; i += 3) {
  26635. w = number[i] | number[i + 1] << 8 | number[i + 2] << 16;
  26636. this.words[j] |= w << off & 0x3ffffff;
  26637. this.words[j + 1] = w >>> 26 - off & 0x3ffffff;
  26638. off += 24;
  26639. if (off >= 26) {
  26640. off -= 26;
  26641. j++;
  26642. }
  26643. }
  26644. }
  26645. return this._strip();
  26646. };
  26647. function parseHex(str, start, end) {
  26648. var r = 0;
  26649. var len = Math.min(str.length, end);
  26650. var z = 0;
  26651. for (var i = start; i < len; i++) {
  26652. var c = str.charCodeAt(i) - 48;
  26653. r <<= 4;
  26654. var b; // 'a' - 'f'
  26655. if (c >= 49 && c <= 54) {
  26656. b = c - 49 + 0xa; // 'A' - 'F'
  26657. } else if (c >= 17 && c <= 22) {
  26658. b = c - 17 + 0xa; // '0' - '9'
  26659. } else {
  26660. b = c;
  26661. }
  26662. r |= b;
  26663. z |= b;
  26664. }
  26665. assert(!(z & 0xf0), 'Invalid character in ' + str);
  26666. return r;
  26667. }
  26668. BN.prototype._parseHex = function _parseHex(number, start) {
  26669. // Create possibly bigger array to ensure that it fits the number
  26670. this.length = Math.ceil((number.length - start) / 6);
  26671. this.words = new Array(this.length);
  26672. for (var i = 0; i < this.length; i++) {
  26673. this.words[i] = 0;
  26674. }
  26675. var j, w; // Scan 24-bit chunks and add them to the number
  26676. var off = 0;
  26677. for (i = number.length - 6, j = 0; i >= start; i -= 6) {
  26678. w = parseHex(number, i, i + 6);
  26679. this.words[j] |= w << off & 0x3ffffff; // NOTE: `0x3fffff` is intentional here, 26bits max shift + 24bit hex limb
  26680. this.words[j + 1] |= w >>> 26 - off & 0x3fffff;
  26681. off += 24;
  26682. if (off >= 26) {
  26683. off -= 26;
  26684. j++;
  26685. }
  26686. }
  26687. if (i + 6 !== start) {
  26688. w = parseHex(number, start, i + 6);
  26689. this.words[j] |= w << off & 0x3ffffff;
  26690. this.words[j + 1] |= w >>> 26 - off & 0x3fffff;
  26691. }
  26692. this._strip();
  26693. };
  26694. function parseBase(str, start, end, mul) {
  26695. var r = 0;
  26696. var b = 0;
  26697. var len = Math.min(str.length, end);
  26698. for (var i = start; i < len; i++) {
  26699. var c = str.charCodeAt(i) - 48;
  26700. r *= mul; // 'a'
  26701. if (c >= 49) {
  26702. b = c - 49 + 0xa; // 'A'
  26703. } else if (c >= 17) {
  26704. b = c - 17 + 0xa; // '0' - '9'
  26705. } else {
  26706. b = c;
  26707. }
  26708. assert(c >= 0 && b < mul, 'Invalid character');
  26709. r += b;
  26710. }
  26711. return r;
  26712. }
  26713. BN.prototype._parseBase = function _parseBase(number, base, start) {
  26714. // Initialize as zero
  26715. this.words = [0];
  26716. this.length = 1; // Find length of limb in base
  26717. for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) {
  26718. limbLen++;
  26719. }
  26720. limbLen--;
  26721. limbPow = limbPow / base | 0;
  26722. var total = number.length - start;
  26723. var mod = total % limbLen;
  26724. var end = Math.min(total, total - mod) + start;
  26725. var word = 0;
  26726. for (var i = start; i < end; i += limbLen) {
  26727. word = parseBase(number, i, i + limbLen, base);
  26728. this.imuln(limbPow);
  26729. if (this.words[0] + word < 0x4000000) {
  26730. this.words[0] += word;
  26731. } else {
  26732. this._iaddn(word);
  26733. }
  26734. }
  26735. if (mod !== 0) {
  26736. var pow = 1;
  26737. word = parseBase(number, i, number.length, base);
  26738. for (i = 0; i < mod; i++) {
  26739. pow *= base;
  26740. }
  26741. this.imuln(pow);
  26742. if (this.words[0] + word < 0x4000000) {
  26743. this.words[0] += word;
  26744. } else {
  26745. this._iaddn(word);
  26746. }
  26747. }
  26748. };
  26749. BN.prototype.copy = function copy(dest) {
  26750. dest.words = new Array(this.length);
  26751. for (var i = 0; i < this.length; i++) {
  26752. dest.words[i] = this.words[i];
  26753. }
  26754. dest.length = this.length;
  26755. dest.negative = this.negative;
  26756. dest.red = this.red;
  26757. };
  26758. function move(dest, src) {
  26759. dest.words = src.words;
  26760. dest.length = src.length;
  26761. dest.negative = src.negative;
  26762. dest.red = src.red;
  26763. }
  26764. BN.prototype._move = function _move(dest) {
  26765. move(dest, this);
  26766. };
  26767. BN.prototype.clone = function clone() {
  26768. var r = new BN(null);
  26769. this.copy(r);
  26770. return r;
  26771. };
  26772. BN.prototype._expand = function _expand(size) {
  26773. while (this.length < size) {
  26774. this.words[this.length++] = 0;
  26775. }
  26776. return this;
  26777. }; // Remove leading `0` from `this`
  26778. BN.prototype._strip = function strip() {
  26779. while (this.length > 1 && this.words[this.length - 1] === 0) {
  26780. this.length--;
  26781. }
  26782. return this._normSign();
  26783. };
  26784. BN.prototype._normSign = function _normSign() {
  26785. // -0 = 0
  26786. if (this.length === 1 && this.words[0] === 0) {
  26787. this.negative = 0;
  26788. }
  26789. return this;
  26790. }; // Check Symbol.for because not everywhere where Symbol defined
  26791. // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol#Browser_compatibility
  26792. if (typeof Symbol !== 'undefined' && typeof Symbol.for === 'function') {
  26793. try {
  26794. BN.prototype[Symbol.for('nodejs.util.inspect.custom')] = inspect;
  26795. } catch (e) {
  26796. BN.prototype.inspect = inspect;
  26797. }
  26798. } else {
  26799. BN.prototype.inspect = inspect;
  26800. }
  26801. function inspect() {
  26802. return (this.red ? '<BN-R: ' : '<BN: ') + this.toString(16) + '>';
  26803. }
  26804. /*
  26805. var zeros = [];
  26806. var groupSizes = [];
  26807. var groupBases = [];
  26808. var s = '';
  26809. var i = -1;
  26810. while (++i < BN.wordSize) {
  26811. zeros[i] = s;
  26812. s += '0';
  26813. }
  26814. groupSizes[0] = 0;
  26815. groupSizes[1] = 0;
  26816. groupBases[0] = 0;
  26817. groupBases[1] = 0;
  26818. var base = 2 - 1;
  26819. while (++base < 36 + 1) {
  26820. var groupSize = 0;
  26821. var groupBase = 1;
  26822. while (groupBase < (1 << BN.wordSize) / base) {
  26823. groupBase *= base;
  26824. groupSize += 1;
  26825. }
  26826. groupSizes[base] = groupSize;
  26827. groupBases[base] = groupBase;
  26828. }
  26829. */
  26830. 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'];
  26831. 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];
  26832. 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];
  26833. BN.prototype.toString = function toString(base, padding) {
  26834. base = base || 10;
  26835. padding = padding | 0 || 1;
  26836. var out;
  26837. if (base === 16 || base === 'hex') {
  26838. out = '';
  26839. var off = 0;
  26840. var carry = 0;
  26841. for (var i = 0; i < this.length; i++) {
  26842. var w = this.words[i];
  26843. var word = ((w << off | carry) & 0xffffff).toString(16);
  26844. carry = w >>> 24 - off & 0xffffff;
  26845. if (carry !== 0 || i !== this.length - 1) {
  26846. out = zeros[6 - word.length] + word + out;
  26847. } else {
  26848. out = word + out;
  26849. }
  26850. off += 2;
  26851. if (off >= 26) {
  26852. off -= 26;
  26853. i--;
  26854. }
  26855. }
  26856. if (carry !== 0) {
  26857. out = carry.toString(16) + out;
  26858. }
  26859. while (out.length % padding !== 0) {
  26860. out = '0' + out;
  26861. }
  26862. if (this.negative !== 0) {
  26863. out = '-' + out;
  26864. }
  26865. return out;
  26866. }
  26867. if (base === (base | 0) && base >= 2 && base <= 36) {
  26868. // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base));
  26869. var groupSize = groupSizes[base]; // var groupBase = Math.pow(base, groupSize);
  26870. var groupBase = groupBases[base];
  26871. out = '';
  26872. var c = this.clone();
  26873. c.negative = 0;
  26874. while (!c.isZero()) {
  26875. var r = c.modrn(groupBase).toString(base);
  26876. c = c.idivn(groupBase);
  26877. if (!c.isZero()) {
  26878. out = zeros[groupSize - r.length] + r + out;
  26879. } else {
  26880. out = r + out;
  26881. }
  26882. }
  26883. if (this.isZero()) {
  26884. out = '0' + out;
  26885. }
  26886. while (out.length % padding !== 0) {
  26887. out = '0' + out;
  26888. }
  26889. if (this.negative !== 0) {
  26890. out = '-' + out;
  26891. }
  26892. return out;
  26893. }
  26894. assert(false, 'Base should be between 2 and 36');
  26895. };
  26896. BN.prototype.toNumber = function toNumber() {
  26897. var ret = this.words[0];
  26898. if (this.length === 2) {
  26899. ret += this.words[1] * 0x4000000;
  26900. } else if (this.length === 3 && this.words[2] === 0x01) {
  26901. // NOTE: at this stage it is known that the top bit is set
  26902. ret += 0x10000000000000 + this.words[1] * 0x4000000;
  26903. } else if (this.length > 2) {
  26904. assert(false, 'Number can only safely store up to 53 bits');
  26905. }
  26906. return this.negative !== 0 ? -ret : ret;
  26907. };
  26908. BN.prototype.toJSON = function toJSON() {
  26909. return this.toString(16, 2);
  26910. };
  26911. if (Buffer) {
  26912. BN.prototype.toBuffer = function toBuffer(endian, length) {
  26913. return this.toArrayLike(Buffer, endian, length);
  26914. };
  26915. }
  26916. BN.prototype.toArray = function toArray(endian, length) {
  26917. return this.toArrayLike(Array, endian, length);
  26918. };
  26919. var allocate = function allocate(ArrayType, size) {
  26920. if (ArrayType.allocUnsafe) {
  26921. return ArrayType.allocUnsafe(size);
  26922. }
  26923. return new ArrayType(size);
  26924. };
  26925. BN.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) {
  26926. this._strip();
  26927. var byteLength = this.byteLength();
  26928. var reqLength = length || Math.max(1, byteLength);
  26929. assert(byteLength <= reqLength, 'byte array longer than desired length');
  26930. assert(reqLength > 0, 'Requested array length <= 0');
  26931. var res = allocate(ArrayType, reqLength);
  26932. var postfix = endian === 'le' ? 'LE' : 'BE';
  26933. this['_toArrayLike' + postfix](res, byteLength);
  26934. return res;
  26935. };
  26936. BN.prototype._toArrayLikeLE = function _toArrayLikeLE(res, byteLength) {
  26937. var position = 0;
  26938. var carry = 0;
  26939. for (var i = 0, shift = 0; i < this.length; i++) {
  26940. var word = this.words[i] << shift | carry;
  26941. res[position++] = word & 0xff;
  26942. if (position < res.length) {
  26943. res[position++] = word >> 8 & 0xff;
  26944. }
  26945. if (position < res.length) {
  26946. res[position++] = word >> 16 & 0xff;
  26947. }
  26948. if (shift === 6) {
  26949. if (position < res.length) {
  26950. res[position++] = word >> 24 & 0xff;
  26951. }
  26952. carry = 0;
  26953. shift = 0;
  26954. } else {
  26955. carry = word >>> 24;
  26956. shift += 2;
  26957. }
  26958. }
  26959. if (position < res.length) {
  26960. res[position++] = carry;
  26961. while (position < res.length) {
  26962. res[position++] = 0;
  26963. }
  26964. }
  26965. };
  26966. BN.prototype._toArrayLikeBE = function _toArrayLikeBE(res, byteLength) {
  26967. var position = res.length - 1;
  26968. var carry = 0;
  26969. for (var i = 0, shift = 0; i < this.length; i++) {
  26970. var word = this.words[i] << shift | carry;
  26971. res[position--] = word & 0xff;
  26972. if (position >= 0) {
  26973. res[position--] = word >> 8 & 0xff;
  26974. }
  26975. if (position >= 0) {
  26976. res[position--] = word >> 16 & 0xff;
  26977. }
  26978. if (shift === 6) {
  26979. if (position >= 0) {
  26980. res[position--] = word >> 24 & 0xff;
  26981. }
  26982. carry = 0;
  26983. shift = 0;
  26984. } else {
  26985. carry = word >>> 24;
  26986. shift += 2;
  26987. }
  26988. }
  26989. if (position >= 0) {
  26990. res[position--] = carry;
  26991. while (position >= 0) {
  26992. res[position--] = 0;
  26993. }
  26994. }
  26995. };
  26996. if (Math.clz32) {
  26997. BN.prototype._countBits = function _countBits(w) {
  26998. return 32 - Math.clz32(w);
  26999. };
  27000. } else {
  27001. BN.prototype._countBits = function _countBits(w) {
  27002. var t = w;
  27003. var r = 0;
  27004. if (t >= 0x1000) {
  27005. r += 13;
  27006. t >>>= 13;
  27007. }
  27008. if (t >= 0x40) {
  27009. r += 7;
  27010. t >>>= 7;
  27011. }
  27012. if (t >= 0x8) {
  27013. r += 4;
  27014. t >>>= 4;
  27015. }
  27016. if (t >= 0x02) {
  27017. r += 2;
  27018. t >>>= 2;
  27019. }
  27020. return r + t;
  27021. };
  27022. }
  27023. BN.prototype._zeroBits = function _zeroBits(w) {
  27024. // Short-cut
  27025. if (w === 0) return 26;
  27026. var t = w;
  27027. var r = 0;
  27028. if ((t & 0x1fff) === 0) {
  27029. r += 13;
  27030. t >>>= 13;
  27031. }
  27032. if ((t & 0x7f) === 0) {
  27033. r += 7;
  27034. t >>>= 7;
  27035. }
  27036. if ((t & 0xf) === 0) {
  27037. r += 4;
  27038. t >>>= 4;
  27039. }
  27040. if ((t & 0x3) === 0) {
  27041. r += 2;
  27042. t >>>= 2;
  27043. }
  27044. if ((t & 0x1) === 0) {
  27045. r++;
  27046. }
  27047. return r;
  27048. }; // Return number of used bits in a BN
  27049. BN.prototype.bitLength = function bitLength() {
  27050. var w = this.words[this.length - 1];
  27051. var hi = this._countBits(w);
  27052. return (this.length - 1) * 26 + hi;
  27053. };
  27054. function toBitArray(num) {
  27055. var w = new Array(num.bitLength());
  27056. for (var bit = 0; bit < w.length; bit++) {
  27057. var off = bit / 26 | 0;
  27058. var wbit = bit % 26;
  27059. w[bit] = num.words[off] >>> wbit & 0x01;
  27060. }
  27061. return w;
  27062. } // Number of trailing zero bits
  27063. BN.prototype.zeroBits = function zeroBits() {
  27064. if (this.isZero()) return 0;
  27065. var r = 0;
  27066. for (var i = 0; i < this.length; i++) {
  27067. var b = this._zeroBits(this.words[i]);
  27068. r += b;
  27069. if (b !== 26) break;
  27070. }
  27071. return r;
  27072. };
  27073. BN.prototype.byteLength = function byteLength() {
  27074. return Math.ceil(this.bitLength() / 8);
  27075. };
  27076. BN.prototype.toTwos = function toTwos(width) {
  27077. if (this.negative !== 0) {
  27078. return this.abs().inotn(width).iaddn(1);
  27079. }
  27080. return this.clone();
  27081. };
  27082. BN.prototype.fromTwos = function fromTwos(width) {
  27083. if (this.testn(width - 1)) {
  27084. return this.notn(width).iaddn(1).ineg();
  27085. }
  27086. return this.clone();
  27087. };
  27088. BN.prototype.isNeg = function isNeg() {
  27089. return this.negative !== 0;
  27090. }; // Return negative clone of `this`
  27091. BN.prototype.neg = function neg() {
  27092. return this.clone().ineg();
  27093. };
  27094. BN.prototype.ineg = function ineg() {
  27095. if (!this.isZero()) {
  27096. this.negative ^= 1;
  27097. }
  27098. return this;
  27099. }; // Or `num` with `this` in-place
  27100. BN.prototype.iuor = function iuor(num) {
  27101. while (this.length < num.length) {
  27102. this.words[this.length++] = 0;
  27103. }
  27104. for (var i = 0; i < num.length; i++) {
  27105. this.words[i] = this.words[i] | num.words[i];
  27106. }
  27107. return this._strip();
  27108. };
  27109. BN.prototype.ior = function ior(num) {
  27110. assert((this.negative | num.negative) === 0);
  27111. return this.iuor(num);
  27112. }; // Or `num` with `this`
  27113. BN.prototype.or = function or(num) {
  27114. if (this.length > num.length) return this.clone().ior(num);
  27115. return num.clone().ior(this);
  27116. };
  27117. BN.prototype.uor = function uor(num) {
  27118. if (this.length > num.length) return this.clone().iuor(num);
  27119. return num.clone().iuor(this);
  27120. }; // And `num` with `this` in-place
  27121. BN.prototype.iuand = function iuand(num) {
  27122. // b = min-length(num, this)
  27123. var b;
  27124. if (this.length > num.length) {
  27125. b = num;
  27126. } else {
  27127. b = this;
  27128. }
  27129. for (var i = 0; i < b.length; i++) {
  27130. this.words[i] = this.words[i] & num.words[i];
  27131. }
  27132. this.length = b.length;
  27133. return this._strip();
  27134. };
  27135. BN.prototype.iand = function iand(num) {
  27136. assert((this.negative | num.negative) === 0);
  27137. return this.iuand(num);
  27138. }; // And `num` with `this`
  27139. BN.prototype.and = function and(num) {
  27140. if (this.length > num.length) return this.clone().iand(num);
  27141. return num.clone().iand(this);
  27142. };
  27143. BN.prototype.uand = function uand(num) {
  27144. if (this.length > num.length) return this.clone().iuand(num);
  27145. return num.clone().iuand(this);
  27146. }; // Xor `num` with `this` in-place
  27147. BN.prototype.iuxor = function iuxor(num) {
  27148. // a.length > b.length
  27149. var a;
  27150. var b;
  27151. if (this.length > num.length) {
  27152. a = this;
  27153. b = num;
  27154. } else {
  27155. a = num;
  27156. b = this;
  27157. }
  27158. for (var i = 0; i < b.length; i++) {
  27159. this.words[i] = a.words[i] ^ b.words[i];
  27160. }
  27161. if (this !== a) {
  27162. for (; i < a.length; i++) {
  27163. this.words[i] = a.words[i];
  27164. }
  27165. }
  27166. this.length = a.length;
  27167. return this._strip();
  27168. };
  27169. BN.prototype.ixor = function ixor(num) {
  27170. assert((this.negative | num.negative) === 0);
  27171. return this.iuxor(num);
  27172. }; // Xor `num` with `this`
  27173. BN.prototype.xor = function xor(num) {
  27174. if (this.length > num.length) return this.clone().ixor(num);
  27175. return num.clone().ixor(this);
  27176. };
  27177. BN.prototype.uxor = function uxor(num) {
  27178. if (this.length > num.length) return this.clone().iuxor(num);
  27179. return num.clone().iuxor(this);
  27180. }; // Not ``this`` with ``width`` bitwidth
  27181. BN.prototype.inotn = function inotn(width) {
  27182. assert(typeof width === 'number' && width >= 0);
  27183. var bytesNeeded = Math.ceil(width / 26) | 0;
  27184. var bitsLeft = width % 26; // Extend the buffer with leading zeroes
  27185. this._expand(bytesNeeded);
  27186. if (bitsLeft > 0) {
  27187. bytesNeeded--;
  27188. } // Handle complete words
  27189. for (var i = 0; i < bytesNeeded; i++) {
  27190. this.words[i] = ~this.words[i] & 0x3ffffff;
  27191. } // Handle the residue
  27192. if (bitsLeft > 0) {
  27193. this.words[i] = ~this.words[i] & 0x3ffffff >> 26 - bitsLeft;
  27194. } // And remove leading zeroes
  27195. return this._strip();
  27196. };
  27197. BN.prototype.notn = function notn(width) {
  27198. return this.clone().inotn(width);
  27199. }; // Set `bit` of `this`
  27200. BN.prototype.setn = function setn(bit, val) {
  27201. assert(typeof bit === 'number' && bit >= 0);
  27202. var off = bit / 26 | 0;
  27203. var wbit = bit % 26;
  27204. this._expand(off + 1);
  27205. if (val) {
  27206. this.words[off] = this.words[off] | 1 << wbit;
  27207. } else {
  27208. this.words[off] = this.words[off] & ~(1 << wbit);
  27209. }
  27210. return this._strip();
  27211. }; // Add `num` to `this` in-place
  27212. BN.prototype.iadd = function iadd(num) {
  27213. var r; // negative + positive
  27214. if (this.negative !== 0 && num.negative === 0) {
  27215. this.negative = 0;
  27216. r = this.isub(num);
  27217. this.negative ^= 1;
  27218. return this._normSign(); // positive + negative
  27219. } else if (this.negative === 0 && num.negative !== 0) {
  27220. num.negative = 0;
  27221. r = this.isub(num);
  27222. num.negative = 1;
  27223. return r._normSign();
  27224. } // a.length > b.length
  27225. var a, b;
  27226. if (this.length > num.length) {
  27227. a = this;
  27228. b = num;
  27229. } else {
  27230. a = num;
  27231. b = this;
  27232. }
  27233. var carry = 0;
  27234. for (var i = 0; i < b.length; i++) {
  27235. r = (a.words[i] | 0) + (b.words[i] | 0) + carry;
  27236. this.words[i] = r & 0x3ffffff;
  27237. carry = r >>> 26;
  27238. }
  27239. for (; carry !== 0 && i < a.length; i++) {
  27240. r = (a.words[i] | 0) + carry;
  27241. this.words[i] = r & 0x3ffffff;
  27242. carry = r >>> 26;
  27243. }
  27244. this.length = a.length;
  27245. if (carry !== 0) {
  27246. this.words[this.length] = carry;
  27247. this.length++; // Copy the rest of the words
  27248. } else if (a !== this) {
  27249. for (; i < a.length; i++) {
  27250. this.words[i] = a.words[i];
  27251. }
  27252. }
  27253. return this;
  27254. }; // Add `num` to `this`
  27255. BN.prototype.add = function add(num) {
  27256. var res;
  27257. if (num.negative !== 0 && this.negative === 0) {
  27258. num.negative = 0;
  27259. res = this.sub(num);
  27260. num.negative ^= 1;
  27261. return res;
  27262. } else if (num.negative === 0 && this.negative !== 0) {
  27263. this.negative = 0;
  27264. res = num.sub(this);
  27265. this.negative = 1;
  27266. return res;
  27267. }
  27268. if (this.length > num.length) return this.clone().iadd(num);
  27269. return num.clone().iadd(this);
  27270. }; // Subtract `num` from `this` in-place
  27271. BN.prototype.isub = function isub(num) {
  27272. // this - (-num) = this + num
  27273. if (num.negative !== 0) {
  27274. num.negative = 0;
  27275. var r = this.iadd(num);
  27276. num.negative = 1;
  27277. return r._normSign(); // -this - num = -(this + num)
  27278. } else if (this.negative !== 0) {
  27279. this.negative = 0;
  27280. this.iadd(num);
  27281. this.negative = 1;
  27282. return this._normSign();
  27283. } // At this point both numbers are positive
  27284. var cmp = this.cmp(num); // Optimization - zeroify
  27285. if (cmp === 0) {
  27286. this.negative = 0;
  27287. this.length = 1;
  27288. this.words[0] = 0;
  27289. return this;
  27290. } // a > b
  27291. var a, b;
  27292. if (cmp > 0) {
  27293. a = this;
  27294. b = num;
  27295. } else {
  27296. a = num;
  27297. b = this;
  27298. }
  27299. var carry = 0;
  27300. for (var i = 0; i < b.length; i++) {
  27301. r = (a.words[i] | 0) - (b.words[i] | 0) + carry;
  27302. carry = r >> 26;
  27303. this.words[i] = r & 0x3ffffff;
  27304. }
  27305. for (; carry !== 0 && i < a.length; i++) {
  27306. r = (a.words[i] | 0) + carry;
  27307. carry = r >> 26;
  27308. this.words[i] = r & 0x3ffffff;
  27309. } // Copy rest of the words
  27310. if (carry === 0 && i < a.length && a !== this) {
  27311. for (; i < a.length; i++) {
  27312. this.words[i] = a.words[i];
  27313. }
  27314. }
  27315. this.length = Math.max(this.length, i);
  27316. if (a !== this) {
  27317. this.negative = 1;
  27318. }
  27319. return this._strip();
  27320. }; // Subtract `num` from `this`
  27321. BN.prototype.sub = function sub(num) {
  27322. return this.clone().isub(num);
  27323. };
  27324. function smallMulTo(self, num, out) {
  27325. out.negative = num.negative ^ self.negative;
  27326. var len = self.length + num.length | 0;
  27327. out.length = len;
  27328. len = len - 1 | 0; // Peel one iteration (compiler can't do it, because of code complexity)
  27329. var a = self.words[0] | 0;
  27330. var b = num.words[0] | 0;
  27331. var r = a * b;
  27332. var lo = r & 0x3ffffff;
  27333. var carry = r / 0x4000000 | 0;
  27334. out.words[0] = lo;
  27335. for (var k = 1; k < len; k++) {
  27336. // Sum all words with the same `i + j = k` and accumulate `ncarry`,
  27337. // note that ncarry could be >= 0x3ffffff
  27338. var ncarry = carry >>> 26;
  27339. var rword = carry & 0x3ffffff;
  27340. var maxJ = Math.min(k, num.length - 1);
  27341. for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
  27342. var i = k - j | 0;
  27343. a = self.words[i] | 0;
  27344. b = num.words[j] | 0;
  27345. r = a * b + rword;
  27346. ncarry += r / 0x4000000 | 0;
  27347. rword = r & 0x3ffffff;
  27348. }
  27349. out.words[k] = rword | 0;
  27350. carry = ncarry | 0;
  27351. }
  27352. if (carry !== 0) {
  27353. out.words[k] = carry | 0;
  27354. } else {
  27355. out.length--;
  27356. }
  27357. return out._strip();
  27358. } // TODO(indutny): it may be reasonable to omit it for users who don't need
  27359. // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit
  27360. // multiplication (like elliptic secp256k1).
  27361. var comb10MulTo = function comb10MulTo(self, num, out) {
  27362. var a = self.words;
  27363. var b = num.words;
  27364. var o = out.words;
  27365. var c = 0;
  27366. var lo;
  27367. var mid;
  27368. var hi;
  27369. var a0 = a[0] | 0;
  27370. var al0 = a0 & 0x1fff;
  27371. var ah0 = a0 >>> 13;
  27372. var a1 = a[1] | 0;
  27373. var al1 = a1 & 0x1fff;
  27374. var ah1 = a1 >>> 13;
  27375. var a2 = a[2] | 0;
  27376. var al2 = a2 & 0x1fff;
  27377. var ah2 = a2 >>> 13;
  27378. var a3 = a[3] | 0;
  27379. var al3 = a3 & 0x1fff;
  27380. var ah3 = a3 >>> 13;
  27381. var a4 = a[4] | 0;
  27382. var al4 = a4 & 0x1fff;
  27383. var ah4 = a4 >>> 13;
  27384. var a5 = a[5] | 0;
  27385. var al5 = a5 & 0x1fff;
  27386. var ah5 = a5 >>> 13;
  27387. var a6 = a[6] | 0;
  27388. var al6 = a6 & 0x1fff;
  27389. var ah6 = a6 >>> 13;
  27390. var a7 = a[7] | 0;
  27391. var al7 = a7 & 0x1fff;
  27392. var ah7 = a7 >>> 13;
  27393. var a8 = a[8] | 0;
  27394. var al8 = a8 & 0x1fff;
  27395. var ah8 = a8 >>> 13;
  27396. var a9 = a[9] | 0;
  27397. var al9 = a9 & 0x1fff;
  27398. var ah9 = a9 >>> 13;
  27399. var b0 = b[0] | 0;
  27400. var bl0 = b0 & 0x1fff;
  27401. var bh0 = b0 >>> 13;
  27402. var b1 = b[1] | 0;
  27403. var bl1 = b1 & 0x1fff;
  27404. var bh1 = b1 >>> 13;
  27405. var b2 = b[2] | 0;
  27406. var bl2 = b2 & 0x1fff;
  27407. var bh2 = b2 >>> 13;
  27408. var b3 = b[3] | 0;
  27409. var bl3 = b3 & 0x1fff;
  27410. var bh3 = b3 >>> 13;
  27411. var b4 = b[4] | 0;
  27412. var bl4 = b4 & 0x1fff;
  27413. var bh4 = b4 >>> 13;
  27414. var b5 = b[5] | 0;
  27415. var bl5 = b5 & 0x1fff;
  27416. var bh5 = b5 >>> 13;
  27417. var b6 = b[6] | 0;
  27418. var bl6 = b6 & 0x1fff;
  27419. var bh6 = b6 >>> 13;
  27420. var b7 = b[7] | 0;
  27421. var bl7 = b7 & 0x1fff;
  27422. var bh7 = b7 >>> 13;
  27423. var b8 = b[8] | 0;
  27424. var bl8 = b8 & 0x1fff;
  27425. var bh8 = b8 >>> 13;
  27426. var b9 = b[9] | 0;
  27427. var bl9 = b9 & 0x1fff;
  27428. var bh9 = b9 >>> 13;
  27429. out.negative = self.negative ^ num.negative;
  27430. out.length = 19;
  27431. /* k = 0 */
  27432. lo = Math.imul(al0, bl0);
  27433. mid = Math.imul(al0, bh0);
  27434. mid = mid + Math.imul(ah0, bl0) | 0;
  27435. hi = Math.imul(ah0, bh0);
  27436. var w0 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27437. c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0;
  27438. w0 &= 0x3ffffff;
  27439. /* k = 1 */
  27440. lo = Math.imul(al1, bl0);
  27441. mid = Math.imul(al1, bh0);
  27442. mid = mid + Math.imul(ah1, bl0) | 0;
  27443. hi = Math.imul(ah1, bh0);
  27444. lo = lo + Math.imul(al0, bl1) | 0;
  27445. mid = mid + Math.imul(al0, bh1) | 0;
  27446. mid = mid + Math.imul(ah0, bl1) | 0;
  27447. hi = hi + Math.imul(ah0, bh1) | 0;
  27448. var w1 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27449. c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0;
  27450. w1 &= 0x3ffffff;
  27451. /* k = 2 */
  27452. lo = Math.imul(al2, bl0);
  27453. mid = Math.imul(al2, bh0);
  27454. mid = mid + Math.imul(ah2, bl0) | 0;
  27455. hi = Math.imul(ah2, bh0);
  27456. lo = lo + Math.imul(al1, bl1) | 0;
  27457. mid = mid + Math.imul(al1, bh1) | 0;
  27458. mid = mid + Math.imul(ah1, bl1) | 0;
  27459. hi = hi + Math.imul(ah1, bh1) | 0;
  27460. lo = lo + Math.imul(al0, bl2) | 0;
  27461. mid = mid + Math.imul(al0, bh2) | 0;
  27462. mid = mid + Math.imul(ah0, bl2) | 0;
  27463. hi = hi + Math.imul(ah0, bh2) | 0;
  27464. var w2 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27465. c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0;
  27466. w2 &= 0x3ffffff;
  27467. /* k = 3 */
  27468. lo = Math.imul(al3, bl0);
  27469. mid = Math.imul(al3, bh0);
  27470. mid = mid + Math.imul(ah3, bl0) | 0;
  27471. hi = Math.imul(ah3, bh0);
  27472. lo = lo + Math.imul(al2, bl1) | 0;
  27473. mid = mid + Math.imul(al2, bh1) | 0;
  27474. mid = mid + Math.imul(ah2, bl1) | 0;
  27475. hi = hi + Math.imul(ah2, bh1) | 0;
  27476. lo = lo + Math.imul(al1, bl2) | 0;
  27477. mid = mid + Math.imul(al1, bh2) | 0;
  27478. mid = mid + Math.imul(ah1, bl2) | 0;
  27479. hi = hi + Math.imul(ah1, bh2) | 0;
  27480. lo = lo + Math.imul(al0, bl3) | 0;
  27481. mid = mid + Math.imul(al0, bh3) | 0;
  27482. mid = mid + Math.imul(ah0, bl3) | 0;
  27483. hi = hi + Math.imul(ah0, bh3) | 0;
  27484. var w3 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27485. c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0;
  27486. w3 &= 0x3ffffff;
  27487. /* k = 4 */
  27488. lo = Math.imul(al4, bl0);
  27489. mid = Math.imul(al4, bh0);
  27490. mid = mid + Math.imul(ah4, bl0) | 0;
  27491. hi = Math.imul(ah4, bh0);
  27492. lo = lo + Math.imul(al3, bl1) | 0;
  27493. mid = mid + Math.imul(al3, bh1) | 0;
  27494. mid = mid + Math.imul(ah3, bl1) | 0;
  27495. hi = hi + Math.imul(ah3, bh1) | 0;
  27496. lo = lo + Math.imul(al2, bl2) | 0;
  27497. mid = mid + Math.imul(al2, bh2) | 0;
  27498. mid = mid + Math.imul(ah2, bl2) | 0;
  27499. hi = hi + Math.imul(ah2, bh2) | 0;
  27500. lo = lo + Math.imul(al1, bl3) | 0;
  27501. mid = mid + Math.imul(al1, bh3) | 0;
  27502. mid = mid + Math.imul(ah1, bl3) | 0;
  27503. hi = hi + Math.imul(ah1, bh3) | 0;
  27504. lo = lo + Math.imul(al0, bl4) | 0;
  27505. mid = mid + Math.imul(al0, bh4) | 0;
  27506. mid = mid + Math.imul(ah0, bl4) | 0;
  27507. hi = hi + Math.imul(ah0, bh4) | 0;
  27508. var w4 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27509. c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0;
  27510. w4 &= 0x3ffffff;
  27511. /* k = 5 */
  27512. lo = Math.imul(al5, bl0);
  27513. mid = Math.imul(al5, bh0);
  27514. mid = mid + Math.imul(ah5, bl0) | 0;
  27515. hi = Math.imul(ah5, bh0);
  27516. lo = lo + Math.imul(al4, bl1) | 0;
  27517. mid = mid + Math.imul(al4, bh1) | 0;
  27518. mid = mid + Math.imul(ah4, bl1) | 0;
  27519. hi = hi + Math.imul(ah4, bh1) | 0;
  27520. lo = lo + Math.imul(al3, bl2) | 0;
  27521. mid = mid + Math.imul(al3, bh2) | 0;
  27522. mid = mid + Math.imul(ah3, bl2) | 0;
  27523. hi = hi + Math.imul(ah3, bh2) | 0;
  27524. lo = lo + Math.imul(al2, bl3) | 0;
  27525. mid = mid + Math.imul(al2, bh3) | 0;
  27526. mid = mid + Math.imul(ah2, bl3) | 0;
  27527. hi = hi + Math.imul(ah2, bh3) | 0;
  27528. lo = lo + Math.imul(al1, bl4) | 0;
  27529. mid = mid + Math.imul(al1, bh4) | 0;
  27530. mid = mid + Math.imul(ah1, bl4) | 0;
  27531. hi = hi + Math.imul(ah1, bh4) | 0;
  27532. lo = lo + Math.imul(al0, bl5) | 0;
  27533. mid = mid + Math.imul(al0, bh5) | 0;
  27534. mid = mid + Math.imul(ah0, bl5) | 0;
  27535. hi = hi + Math.imul(ah0, bh5) | 0;
  27536. var w5 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27537. c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0;
  27538. w5 &= 0x3ffffff;
  27539. /* k = 6 */
  27540. lo = Math.imul(al6, bl0);
  27541. mid = Math.imul(al6, bh0);
  27542. mid = mid + Math.imul(ah6, bl0) | 0;
  27543. hi = Math.imul(ah6, bh0);
  27544. lo = lo + Math.imul(al5, bl1) | 0;
  27545. mid = mid + Math.imul(al5, bh1) | 0;
  27546. mid = mid + Math.imul(ah5, bl1) | 0;
  27547. hi = hi + Math.imul(ah5, bh1) | 0;
  27548. lo = lo + Math.imul(al4, bl2) | 0;
  27549. mid = mid + Math.imul(al4, bh2) | 0;
  27550. mid = mid + Math.imul(ah4, bl2) | 0;
  27551. hi = hi + Math.imul(ah4, bh2) | 0;
  27552. lo = lo + Math.imul(al3, bl3) | 0;
  27553. mid = mid + Math.imul(al3, bh3) | 0;
  27554. mid = mid + Math.imul(ah3, bl3) | 0;
  27555. hi = hi + Math.imul(ah3, bh3) | 0;
  27556. lo = lo + Math.imul(al2, bl4) | 0;
  27557. mid = mid + Math.imul(al2, bh4) | 0;
  27558. mid = mid + Math.imul(ah2, bl4) | 0;
  27559. hi = hi + Math.imul(ah2, bh4) | 0;
  27560. lo = lo + Math.imul(al1, bl5) | 0;
  27561. mid = mid + Math.imul(al1, bh5) | 0;
  27562. mid = mid + Math.imul(ah1, bl5) | 0;
  27563. hi = hi + Math.imul(ah1, bh5) | 0;
  27564. lo = lo + Math.imul(al0, bl6) | 0;
  27565. mid = mid + Math.imul(al0, bh6) | 0;
  27566. mid = mid + Math.imul(ah0, bl6) | 0;
  27567. hi = hi + Math.imul(ah0, bh6) | 0;
  27568. var w6 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27569. c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0;
  27570. w6 &= 0x3ffffff;
  27571. /* k = 7 */
  27572. lo = Math.imul(al7, bl0);
  27573. mid = Math.imul(al7, bh0);
  27574. mid = mid + Math.imul(ah7, bl0) | 0;
  27575. hi = Math.imul(ah7, bh0);
  27576. lo = lo + Math.imul(al6, bl1) | 0;
  27577. mid = mid + Math.imul(al6, bh1) | 0;
  27578. mid = mid + Math.imul(ah6, bl1) | 0;
  27579. hi = hi + Math.imul(ah6, bh1) | 0;
  27580. lo = lo + Math.imul(al5, bl2) | 0;
  27581. mid = mid + Math.imul(al5, bh2) | 0;
  27582. mid = mid + Math.imul(ah5, bl2) | 0;
  27583. hi = hi + Math.imul(ah5, bh2) | 0;
  27584. lo = lo + Math.imul(al4, bl3) | 0;
  27585. mid = mid + Math.imul(al4, bh3) | 0;
  27586. mid = mid + Math.imul(ah4, bl3) | 0;
  27587. hi = hi + Math.imul(ah4, bh3) | 0;
  27588. lo = lo + Math.imul(al3, bl4) | 0;
  27589. mid = mid + Math.imul(al3, bh4) | 0;
  27590. mid = mid + Math.imul(ah3, bl4) | 0;
  27591. hi = hi + Math.imul(ah3, bh4) | 0;
  27592. lo = lo + Math.imul(al2, bl5) | 0;
  27593. mid = mid + Math.imul(al2, bh5) | 0;
  27594. mid = mid + Math.imul(ah2, bl5) | 0;
  27595. hi = hi + Math.imul(ah2, bh5) | 0;
  27596. lo = lo + Math.imul(al1, bl6) | 0;
  27597. mid = mid + Math.imul(al1, bh6) | 0;
  27598. mid = mid + Math.imul(ah1, bl6) | 0;
  27599. hi = hi + Math.imul(ah1, bh6) | 0;
  27600. lo = lo + Math.imul(al0, bl7) | 0;
  27601. mid = mid + Math.imul(al0, bh7) | 0;
  27602. mid = mid + Math.imul(ah0, bl7) | 0;
  27603. hi = hi + Math.imul(ah0, bh7) | 0;
  27604. var w7 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27605. c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0;
  27606. w7 &= 0x3ffffff;
  27607. /* k = 8 */
  27608. lo = Math.imul(al8, bl0);
  27609. mid = Math.imul(al8, bh0);
  27610. mid = mid + Math.imul(ah8, bl0) | 0;
  27611. hi = Math.imul(ah8, bh0);
  27612. lo = lo + Math.imul(al7, bl1) | 0;
  27613. mid = mid + Math.imul(al7, bh1) | 0;
  27614. mid = mid + Math.imul(ah7, bl1) | 0;
  27615. hi = hi + Math.imul(ah7, bh1) | 0;
  27616. lo = lo + Math.imul(al6, bl2) | 0;
  27617. mid = mid + Math.imul(al6, bh2) | 0;
  27618. mid = mid + Math.imul(ah6, bl2) | 0;
  27619. hi = hi + Math.imul(ah6, bh2) | 0;
  27620. lo = lo + Math.imul(al5, bl3) | 0;
  27621. mid = mid + Math.imul(al5, bh3) | 0;
  27622. mid = mid + Math.imul(ah5, bl3) | 0;
  27623. hi = hi + Math.imul(ah5, bh3) | 0;
  27624. lo = lo + Math.imul(al4, bl4) | 0;
  27625. mid = mid + Math.imul(al4, bh4) | 0;
  27626. mid = mid + Math.imul(ah4, bl4) | 0;
  27627. hi = hi + Math.imul(ah4, bh4) | 0;
  27628. lo = lo + Math.imul(al3, bl5) | 0;
  27629. mid = mid + Math.imul(al3, bh5) | 0;
  27630. mid = mid + Math.imul(ah3, bl5) | 0;
  27631. hi = hi + Math.imul(ah3, bh5) | 0;
  27632. lo = lo + Math.imul(al2, bl6) | 0;
  27633. mid = mid + Math.imul(al2, bh6) | 0;
  27634. mid = mid + Math.imul(ah2, bl6) | 0;
  27635. hi = hi + Math.imul(ah2, bh6) | 0;
  27636. lo = lo + Math.imul(al1, bl7) | 0;
  27637. mid = mid + Math.imul(al1, bh7) | 0;
  27638. mid = mid + Math.imul(ah1, bl7) | 0;
  27639. hi = hi + Math.imul(ah1, bh7) | 0;
  27640. lo = lo + Math.imul(al0, bl8) | 0;
  27641. mid = mid + Math.imul(al0, bh8) | 0;
  27642. mid = mid + Math.imul(ah0, bl8) | 0;
  27643. hi = hi + Math.imul(ah0, bh8) | 0;
  27644. var w8 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27645. c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0;
  27646. w8 &= 0x3ffffff;
  27647. /* k = 9 */
  27648. lo = Math.imul(al9, bl0);
  27649. mid = Math.imul(al9, bh0);
  27650. mid = mid + Math.imul(ah9, bl0) | 0;
  27651. hi = Math.imul(ah9, bh0);
  27652. lo = lo + Math.imul(al8, bl1) | 0;
  27653. mid = mid + Math.imul(al8, bh1) | 0;
  27654. mid = mid + Math.imul(ah8, bl1) | 0;
  27655. hi = hi + Math.imul(ah8, bh1) | 0;
  27656. lo = lo + Math.imul(al7, bl2) | 0;
  27657. mid = mid + Math.imul(al7, bh2) | 0;
  27658. mid = mid + Math.imul(ah7, bl2) | 0;
  27659. hi = hi + Math.imul(ah7, bh2) | 0;
  27660. lo = lo + Math.imul(al6, bl3) | 0;
  27661. mid = mid + Math.imul(al6, bh3) | 0;
  27662. mid = mid + Math.imul(ah6, bl3) | 0;
  27663. hi = hi + Math.imul(ah6, bh3) | 0;
  27664. lo = lo + Math.imul(al5, bl4) | 0;
  27665. mid = mid + Math.imul(al5, bh4) | 0;
  27666. mid = mid + Math.imul(ah5, bl4) | 0;
  27667. hi = hi + Math.imul(ah5, bh4) | 0;
  27668. lo = lo + Math.imul(al4, bl5) | 0;
  27669. mid = mid + Math.imul(al4, bh5) | 0;
  27670. mid = mid + Math.imul(ah4, bl5) | 0;
  27671. hi = hi + Math.imul(ah4, bh5) | 0;
  27672. lo = lo + Math.imul(al3, bl6) | 0;
  27673. mid = mid + Math.imul(al3, bh6) | 0;
  27674. mid = mid + Math.imul(ah3, bl6) | 0;
  27675. hi = hi + Math.imul(ah3, bh6) | 0;
  27676. lo = lo + Math.imul(al2, bl7) | 0;
  27677. mid = mid + Math.imul(al2, bh7) | 0;
  27678. mid = mid + Math.imul(ah2, bl7) | 0;
  27679. hi = hi + Math.imul(ah2, bh7) | 0;
  27680. lo = lo + Math.imul(al1, bl8) | 0;
  27681. mid = mid + Math.imul(al1, bh8) | 0;
  27682. mid = mid + Math.imul(ah1, bl8) | 0;
  27683. hi = hi + Math.imul(ah1, bh8) | 0;
  27684. lo = lo + Math.imul(al0, bl9) | 0;
  27685. mid = mid + Math.imul(al0, bh9) | 0;
  27686. mid = mid + Math.imul(ah0, bl9) | 0;
  27687. hi = hi + Math.imul(ah0, bh9) | 0;
  27688. var w9 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27689. c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0;
  27690. w9 &= 0x3ffffff;
  27691. /* k = 10 */
  27692. lo = Math.imul(al9, bl1);
  27693. mid = Math.imul(al9, bh1);
  27694. mid = mid + Math.imul(ah9, bl1) | 0;
  27695. hi = Math.imul(ah9, bh1);
  27696. lo = lo + Math.imul(al8, bl2) | 0;
  27697. mid = mid + Math.imul(al8, bh2) | 0;
  27698. mid = mid + Math.imul(ah8, bl2) | 0;
  27699. hi = hi + Math.imul(ah8, bh2) | 0;
  27700. lo = lo + Math.imul(al7, bl3) | 0;
  27701. mid = mid + Math.imul(al7, bh3) | 0;
  27702. mid = mid + Math.imul(ah7, bl3) | 0;
  27703. hi = hi + Math.imul(ah7, bh3) | 0;
  27704. lo = lo + Math.imul(al6, bl4) | 0;
  27705. mid = mid + Math.imul(al6, bh4) | 0;
  27706. mid = mid + Math.imul(ah6, bl4) | 0;
  27707. hi = hi + Math.imul(ah6, bh4) | 0;
  27708. lo = lo + Math.imul(al5, bl5) | 0;
  27709. mid = mid + Math.imul(al5, bh5) | 0;
  27710. mid = mid + Math.imul(ah5, bl5) | 0;
  27711. hi = hi + Math.imul(ah5, bh5) | 0;
  27712. lo = lo + Math.imul(al4, bl6) | 0;
  27713. mid = mid + Math.imul(al4, bh6) | 0;
  27714. mid = mid + Math.imul(ah4, bl6) | 0;
  27715. hi = hi + Math.imul(ah4, bh6) | 0;
  27716. lo = lo + Math.imul(al3, bl7) | 0;
  27717. mid = mid + Math.imul(al3, bh7) | 0;
  27718. mid = mid + Math.imul(ah3, bl7) | 0;
  27719. hi = hi + Math.imul(ah3, bh7) | 0;
  27720. lo = lo + Math.imul(al2, bl8) | 0;
  27721. mid = mid + Math.imul(al2, bh8) | 0;
  27722. mid = mid + Math.imul(ah2, bl8) | 0;
  27723. hi = hi + Math.imul(ah2, bh8) | 0;
  27724. lo = lo + Math.imul(al1, bl9) | 0;
  27725. mid = mid + Math.imul(al1, bh9) | 0;
  27726. mid = mid + Math.imul(ah1, bl9) | 0;
  27727. hi = hi + Math.imul(ah1, bh9) | 0;
  27728. var w10 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27729. c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0;
  27730. w10 &= 0x3ffffff;
  27731. /* k = 11 */
  27732. lo = Math.imul(al9, bl2);
  27733. mid = Math.imul(al9, bh2);
  27734. mid = mid + Math.imul(ah9, bl2) | 0;
  27735. hi = Math.imul(ah9, bh2);
  27736. lo = lo + Math.imul(al8, bl3) | 0;
  27737. mid = mid + Math.imul(al8, bh3) | 0;
  27738. mid = mid + Math.imul(ah8, bl3) | 0;
  27739. hi = hi + Math.imul(ah8, bh3) | 0;
  27740. lo = lo + Math.imul(al7, bl4) | 0;
  27741. mid = mid + Math.imul(al7, bh4) | 0;
  27742. mid = mid + Math.imul(ah7, bl4) | 0;
  27743. hi = hi + Math.imul(ah7, bh4) | 0;
  27744. lo = lo + Math.imul(al6, bl5) | 0;
  27745. mid = mid + Math.imul(al6, bh5) | 0;
  27746. mid = mid + Math.imul(ah6, bl5) | 0;
  27747. hi = hi + Math.imul(ah6, bh5) | 0;
  27748. lo = lo + Math.imul(al5, bl6) | 0;
  27749. mid = mid + Math.imul(al5, bh6) | 0;
  27750. mid = mid + Math.imul(ah5, bl6) | 0;
  27751. hi = hi + Math.imul(ah5, bh6) | 0;
  27752. lo = lo + Math.imul(al4, bl7) | 0;
  27753. mid = mid + Math.imul(al4, bh7) | 0;
  27754. mid = mid + Math.imul(ah4, bl7) | 0;
  27755. hi = hi + Math.imul(ah4, bh7) | 0;
  27756. lo = lo + Math.imul(al3, bl8) | 0;
  27757. mid = mid + Math.imul(al3, bh8) | 0;
  27758. mid = mid + Math.imul(ah3, bl8) | 0;
  27759. hi = hi + Math.imul(ah3, bh8) | 0;
  27760. lo = lo + Math.imul(al2, bl9) | 0;
  27761. mid = mid + Math.imul(al2, bh9) | 0;
  27762. mid = mid + Math.imul(ah2, bl9) | 0;
  27763. hi = hi + Math.imul(ah2, bh9) | 0;
  27764. var w11 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27765. c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0;
  27766. w11 &= 0x3ffffff;
  27767. /* k = 12 */
  27768. lo = Math.imul(al9, bl3);
  27769. mid = Math.imul(al9, bh3);
  27770. mid = mid + Math.imul(ah9, bl3) | 0;
  27771. hi = Math.imul(ah9, bh3);
  27772. lo = lo + Math.imul(al8, bl4) | 0;
  27773. mid = mid + Math.imul(al8, bh4) | 0;
  27774. mid = mid + Math.imul(ah8, bl4) | 0;
  27775. hi = hi + Math.imul(ah8, bh4) | 0;
  27776. lo = lo + Math.imul(al7, bl5) | 0;
  27777. mid = mid + Math.imul(al7, bh5) | 0;
  27778. mid = mid + Math.imul(ah7, bl5) | 0;
  27779. hi = hi + Math.imul(ah7, bh5) | 0;
  27780. lo = lo + Math.imul(al6, bl6) | 0;
  27781. mid = mid + Math.imul(al6, bh6) | 0;
  27782. mid = mid + Math.imul(ah6, bl6) | 0;
  27783. hi = hi + Math.imul(ah6, bh6) | 0;
  27784. lo = lo + Math.imul(al5, bl7) | 0;
  27785. mid = mid + Math.imul(al5, bh7) | 0;
  27786. mid = mid + Math.imul(ah5, bl7) | 0;
  27787. hi = hi + Math.imul(ah5, bh7) | 0;
  27788. lo = lo + Math.imul(al4, bl8) | 0;
  27789. mid = mid + Math.imul(al4, bh8) | 0;
  27790. mid = mid + Math.imul(ah4, bl8) | 0;
  27791. hi = hi + Math.imul(ah4, bh8) | 0;
  27792. lo = lo + Math.imul(al3, bl9) | 0;
  27793. mid = mid + Math.imul(al3, bh9) | 0;
  27794. mid = mid + Math.imul(ah3, bl9) | 0;
  27795. hi = hi + Math.imul(ah3, bh9) | 0;
  27796. var w12 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27797. c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0;
  27798. w12 &= 0x3ffffff;
  27799. /* k = 13 */
  27800. lo = Math.imul(al9, bl4);
  27801. mid = Math.imul(al9, bh4);
  27802. mid = mid + Math.imul(ah9, bl4) | 0;
  27803. hi = Math.imul(ah9, bh4);
  27804. lo = lo + Math.imul(al8, bl5) | 0;
  27805. mid = mid + Math.imul(al8, bh5) | 0;
  27806. mid = mid + Math.imul(ah8, bl5) | 0;
  27807. hi = hi + Math.imul(ah8, bh5) | 0;
  27808. lo = lo + Math.imul(al7, bl6) | 0;
  27809. mid = mid + Math.imul(al7, bh6) | 0;
  27810. mid = mid + Math.imul(ah7, bl6) | 0;
  27811. hi = hi + Math.imul(ah7, bh6) | 0;
  27812. lo = lo + Math.imul(al6, bl7) | 0;
  27813. mid = mid + Math.imul(al6, bh7) | 0;
  27814. mid = mid + Math.imul(ah6, bl7) | 0;
  27815. hi = hi + Math.imul(ah6, bh7) | 0;
  27816. lo = lo + Math.imul(al5, bl8) | 0;
  27817. mid = mid + Math.imul(al5, bh8) | 0;
  27818. mid = mid + Math.imul(ah5, bl8) | 0;
  27819. hi = hi + Math.imul(ah5, bh8) | 0;
  27820. lo = lo + Math.imul(al4, bl9) | 0;
  27821. mid = mid + Math.imul(al4, bh9) | 0;
  27822. mid = mid + Math.imul(ah4, bl9) | 0;
  27823. hi = hi + Math.imul(ah4, bh9) | 0;
  27824. var w13 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27825. c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0;
  27826. w13 &= 0x3ffffff;
  27827. /* k = 14 */
  27828. lo = Math.imul(al9, bl5);
  27829. mid = Math.imul(al9, bh5);
  27830. mid = mid + Math.imul(ah9, bl5) | 0;
  27831. hi = Math.imul(ah9, bh5);
  27832. lo = lo + Math.imul(al8, bl6) | 0;
  27833. mid = mid + Math.imul(al8, bh6) | 0;
  27834. mid = mid + Math.imul(ah8, bl6) | 0;
  27835. hi = hi + Math.imul(ah8, bh6) | 0;
  27836. lo = lo + Math.imul(al7, bl7) | 0;
  27837. mid = mid + Math.imul(al7, bh7) | 0;
  27838. mid = mid + Math.imul(ah7, bl7) | 0;
  27839. hi = hi + Math.imul(ah7, bh7) | 0;
  27840. lo = lo + Math.imul(al6, bl8) | 0;
  27841. mid = mid + Math.imul(al6, bh8) | 0;
  27842. mid = mid + Math.imul(ah6, bl8) | 0;
  27843. hi = hi + Math.imul(ah6, bh8) | 0;
  27844. lo = lo + Math.imul(al5, bl9) | 0;
  27845. mid = mid + Math.imul(al5, bh9) | 0;
  27846. mid = mid + Math.imul(ah5, bl9) | 0;
  27847. hi = hi + Math.imul(ah5, bh9) | 0;
  27848. var w14 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27849. c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0;
  27850. w14 &= 0x3ffffff;
  27851. /* k = 15 */
  27852. lo = Math.imul(al9, bl6);
  27853. mid = Math.imul(al9, bh6);
  27854. mid = mid + Math.imul(ah9, bl6) | 0;
  27855. hi = Math.imul(ah9, bh6);
  27856. lo = lo + Math.imul(al8, bl7) | 0;
  27857. mid = mid + Math.imul(al8, bh7) | 0;
  27858. mid = mid + Math.imul(ah8, bl7) | 0;
  27859. hi = hi + Math.imul(ah8, bh7) | 0;
  27860. lo = lo + Math.imul(al7, bl8) | 0;
  27861. mid = mid + Math.imul(al7, bh8) | 0;
  27862. mid = mid + Math.imul(ah7, bl8) | 0;
  27863. hi = hi + Math.imul(ah7, bh8) | 0;
  27864. lo = lo + Math.imul(al6, bl9) | 0;
  27865. mid = mid + Math.imul(al6, bh9) | 0;
  27866. mid = mid + Math.imul(ah6, bl9) | 0;
  27867. hi = hi + Math.imul(ah6, bh9) | 0;
  27868. var w15 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27869. c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0;
  27870. w15 &= 0x3ffffff;
  27871. /* k = 16 */
  27872. lo = Math.imul(al9, bl7);
  27873. mid = Math.imul(al9, bh7);
  27874. mid = mid + Math.imul(ah9, bl7) | 0;
  27875. hi = Math.imul(ah9, bh7);
  27876. lo = lo + Math.imul(al8, bl8) | 0;
  27877. mid = mid + Math.imul(al8, bh8) | 0;
  27878. mid = mid + Math.imul(ah8, bl8) | 0;
  27879. hi = hi + Math.imul(ah8, bh8) | 0;
  27880. lo = lo + Math.imul(al7, bl9) | 0;
  27881. mid = mid + Math.imul(al7, bh9) | 0;
  27882. mid = mid + Math.imul(ah7, bl9) | 0;
  27883. hi = hi + Math.imul(ah7, bh9) | 0;
  27884. var w16 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27885. c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0;
  27886. w16 &= 0x3ffffff;
  27887. /* k = 17 */
  27888. lo = Math.imul(al9, bl8);
  27889. mid = Math.imul(al9, bh8);
  27890. mid = mid + Math.imul(ah9, bl8) | 0;
  27891. hi = Math.imul(ah9, bh8);
  27892. lo = lo + Math.imul(al8, bl9) | 0;
  27893. mid = mid + Math.imul(al8, bh9) | 0;
  27894. mid = mid + Math.imul(ah8, bl9) | 0;
  27895. hi = hi + Math.imul(ah8, bh9) | 0;
  27896. var w17 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27897. c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0;
  27898. w17 &= 0x3ffffff;
  27899. /* k = 18 */
  27900. lo = Math.imul(al9, bl9);
  27901. mid = Math.imul(al9, bh9);
  27902. mid = mid + Math.imul(ah9, bl9) | 0;
  27903. hi = Math.imul(ah9, bh9);
  27904. var w18 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27905. c = (hi + (mid >>> 13) | 0) + (w18 >>> 26) | 0;
  27906. w18 &= 0x3ffffff;
  27907. o[0] = w0;
  27908. o[1] = w1;
  27909. o[2] = w2;
  27910. o[3] = w3;
  27911. o[4] = w4;
  27912. o[5] = w5;
  27913. o[6] = w6;
  27914. o[7] = w7;
  27915. o[8] = w8;
  27916. o[9] = w9;
  27917. o[10] = w10;
  27918. o[11] = w11;
  27919. o[12] = w12;
  27920. o[13] = w13;
  27921. o[14] = w14;
  27922. o[15] = w15;
  27923. o[16] = w16;
  27924. o[17] = w17;
  27925. o[18] = w18;
  27926. if (c !== 0) {
  27927. o[19] = c;
  27928. out.length++;
  27929. }
  27930. return out;
  27931. }; // Polyfill comb
  27932. if (!Math.imul) {
  27933. comb10MulTo = smallMulTo;
  27934. }
  27935. function bigMulTo(self, num, out) {
  27936. out.negative = num.negative ^ self.negative;
  27937. out.length = self.length + num.length;
  27938. var carry = 0;
  27939. var hncarry = 0;
  27940. for (var k = 0; k < out.length - 1; k++) {
  27941. // Sum all words with the same `i + j = k` and accumulate `ncarry`,
  27942. // note that ncarry could be >= 0x3ffffff
  27943. var ncarry = hncarry;
  27944. hncarry = 0;
  27945. var rword = carry & 0x3ffffff;
  27946. var maxJ = Math.min(k, num.length - 1);
  27947. for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
  27948. var i = k - j;
  27949. var a = self.words[i] | 0;
  27950. var b = num.words[j] | 0;
  27951. var r = a * b;
  27952. var lo = r & 0x3ffffff;
  27953. ncarry = ncarry + (r / 0x4000000 | 0) | 0;
  27954. lo = lo + rword | 0;
  27955. rword = lo & 0x3ffffff;
  27956. ncarry = ncarry + (lo >>> 26) | 0;
  27957. hncarry += ncarry >>> 26;
  27958. ncarry &= 0x3ffffff;
  27959. }
  27960. out.words[k] = rword;
  27961. carry = ncarry;
  27962. ncarry = hncarry;
  27963. }
  27964. if (carry !== 0) {
  27965. out.words[k] = carry;
  27966. } else {
  27967. out.length--;
  27968. }
  27969. return out._strip();
  27970. }
  27971. function jumboMulTo(self, num, out) {
  27972. // Temporary disable, see https://github.com/indutny/bn.js/issues/211
  27973. // var fftm = new FFTM();
  27974. // return fftm.mulp(self, num, out);
  27975. return bigMulTo(self, num, out);
  27976. }
  27977. BN.prototype.mulTo = function mulTo(num, out) {
  27978. var res;
  27979. var len = this.length + num.length;
  27980. if (this.length === 10 && num.length === 10) {
  27981. res = comb10MulTo(this, num, out);
  27982. } else if (len < 63) {
  27983. res = smallMulTo(this, num, out);
  27984. } else if (len < 1024) {
  27985. res = bigMulTo(this, num, out);
  27986. } else {
  27987. res = jumboMulTo(this, num, out);
  27988. }
  27989. return res;
  27990. }; // Cooley-Tukey algorithm for FFT
  27991. // slightly revisited to rely on looping instead of recursion
  27992. function FFTM(x, y) {
  27993. this.x = x;
  27994. this.y = y;
  27995. }
  27996. FFTM.prototype.makeRBT = function makeRBT(N) {
  27997. var t = new Array(N);
  27998. var l = BN.prototype._countBits(N) - 1;
  27999. for (var i = 0; i < N; i++) {
  28000. t[i] = this.revBin(i, l, N);
  28001. }
  28002. return t;
  28003. }; // Returns binary-reversed representation of `x`
  28004. FFTM.prototype.revBin = function revBin(x, l, N) {
  28005. if (x === 0 || x === N - 1) return x;
  28006. var rb = 0;
  28007. for (var i = 0; i < l; i++) {
  28008. rb |= (x & 1) << l - i - 1;
  28009. x >>= 1;
  28010. }
  28011. return rb;
  28012. }; // Performs "tweedling" phase, therefore 'emulating'
  28013. // behaviour of the recursive algorithm
  28014. FFTM.prototype.permute = function permute(rbt, rws, iws, rtws, itws, N) {
  28015. for (var i = 0; i < N; i++) {
  28016. rtws[i] = rws[rbt[i]];
  28017. itws[i] = iws[rbt[i]];
  28018. }
  28019. };
  28020. FFTM.prototype.transform = function transform(rws, iws, rtws, itws, N, rbt) {
  28021. this.permute(rbt, rws, iws, rtws, itws, N);
  28022. for (var s = 1; s < N; s <<= 1) {
  28023. var l = s << 1;
  28024. var rtwdf = Math.cos(2 * Math.PI / l);
  28025. var itwdf = Math.sin(2 * Math.PI / l);
  28026. for (var p = 0; p < N; p += l) {
  28027. var rtwdf_ = rtwdf;
  28028. var itwdf_ = itwdf;
  28029. for (var j = 0; j < s; j++) {
  28030. var re = rtws[p + j];
  28031. var ie = itws[p + j];
  28032. var ro = rtws[p + j + s];
  28033. var io = itws[p + j + s];
  28034. var rx = rtwdf_ * ro - itwdf_ * io;
  28035. io = rtwdf_ * io + itwdf_ * ro;
  28036. ro = rx;
  28037. rtws[p + j] = re + ro;
  28038. itws[p + j] = ie + io;
  28039. rtws[p + j + s] = re - ro;
  28040. itws[p + j + s] = ie - io;
  28041. /* jshint maxdepth : false */
  28042. if (j !== l) {
  28043. rx = rtwdf * rtwdf_ - itwdf * itwdf_;
  28044. itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_;
  28045. rtwdf_ = rx;
  28046. }
  28047. }
  28048. }
  28049. }
  28050. };
  28051. FFTM.prototype.guessLen13b = function guessLen13b(n, m) {
  28052. var N = Math.max(m, n) | 1;
  28053. var odd = N & 1;
  28054. var i = 0;
  28055. for (N = N / 2 | 0; N; N = N >>> 1) {
  28056. i++;
  28057. }
  28058. return 1 << i + 1 + odd;
  28059. };
  28060. FFTM.prototype.conjugate = function conjugate(rws, iws, N) {
  28061. if (N <= 1) return;
  28062. for (var i = 0; i < N / 2; i++) {
  28063. var t = rws[i];
  28064. rws[i] = rws[N - i - 1];
  28065. rws[N - i - 1] = t;
  28066. t = iws[i];
  28067. iws[i] = -iws[N - i - 1];
  28068. iws[N - i - 1] = -t;
  28069. }
  28070. };
  28071. FFTM.prototype.normalize13b = function normalize13b(ws, N) {
  28072. var carry = 0;
  28073. for (var i = 0; i < N / 2; i++) {
  28074. var w = Math.round(ws[2 * i + 1] / N) * 0x2000 + Math.round(ws[2 * i] / N) + carry;
  28075. ws[i] = w & 0x3ffffff;
  28076. if (w < 0x4000000) {
  28077. carry = 0;
  28078. } else {
  28079. carry = w / 0x4000000 | 0;
  28080. }
  28081. }
  28082. return ws;
  28083. };
  28084. FFTM.prototype.convert13b = function convert13b(ws, len, rws, N) {
  28085. var carry = 0;
  28086. for (var i = 0; i < len; i++) {
  28087. carry = carry + (ws[i] | 0);
  28088. rws[2 * i] = carry & 0x1fff;
  28089. carry = carry >>> 13;
  28090. rws[2 * i + 1] = carry & 0x1fff;
  28091. carry = carry >>> 13;
  28092. } // Pad with zeroes
  28093. for (i = 2 * len; i < N; ++i) {
  28094. rws[i] = 0;
  28095. }
  28096. assert(carry === 0);
  28097. assert((carry & ~0x1fff) === 0);
  28098. };
  28099. FFTM.prototype.stub = function stub(N) {
  28100. var ph = new Array(N);
  28101. for (var i = 0; i < N; i++) {
  28102. ph[i] = 0;
  28103. }
  28104. return ph;
  28105. };
  28106. FFTM.prototype.mulp = function mulp(x, y, out) {
  28107. var N = 2 * this.guessLen13b(x.length, y.length);
  28108. var rbt = this.makeRBT(N);
  28109. var _ = this.stub(N);
  28110. var rws = new Array(N);
  28111. var rwst = new Array(N);
  28112. var iwst = new Array(N);
  28113. var nrws = new Array(N);
  28114. var nrwst = new Array(N);
  28115. var niwst = new Array(N);
  28116. var rmws = out.words;
  28117. rmws.length = N;
  28118. this.convert13b(x.words, x.length, rws, N);
  28119. this.convert13b(y.words, y.length, nrws, N);
  28120. this.transform(rws, _, rwst, iwst, N, rbt);
  28121. this.transform(nrws, _, nrwst, niwst, N, rbt);
  28122. for (var i = 0; i < N; i++) {
  28123. var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
  28124. iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i];
  28125. rwst[i] = rx;
  28126. }
  28127. this.conjugate(rwst, iwst, N);
  28128. this.transform(rwst, iwst, rmws, _, N, rbt);
  28129. this.conjugate(rmws, _, N);
  28130. this.normalize13b(rmws, N);
  28131. out.negative = x.negative ^ y.negative;
  28132. out.length = x.length + y.length;
  28133. return out._strip();
  28134. }; // Multiply `this` by `num`
  28135. BN.prototype.mul = function mul(num) {
  28136. var out = new BN(null);
  28137. out.words = new Array(this.length + num.length);
  28138. return this.mulTo(num, out);
  28139. }; // Multiply employing FFT
  28140. BN.prototype.mulf = function mulf(num) {
  28141. var out = new BN(null);
  28142. out.words = new Array(this.length + num.length);
  28143. return jumboMulTo(this, num, out);
  28144. }; // In-place Multiplication
  28145. BN.prototype.imul = function imul(num) {
  28146. return this.clone().mulTo(num, this);
  28147. };
  28148. BN.prototype.imuln = function imuln(num) {
  28149. var isNegNum = num < 0;
  28150. if (isNegNum) num = -num;
  28151. assert(typeof num === 'number');
  28152. assert(num < 0x4000000); // Carry
  28153. var carry = 0;
  28154. for (var i = 0; i < this.length; i++) {
  28155. var w = (this.words[i] | 0) * num;
  28156. var lo = (w & 0x3ffffff) + (carry & 0x3ffffff);
  28157. carry >>= 26;
  28158. carry += w / 0x4000000 | 0; // NOTE: lo is 27bit maximum
  28159. carry += lo >>> 26;
  28160. this.words[i] = lo & 0x3ffffff;
  28161. }
  28162. if (carry !== 0) {
  28163. this.words[i] = carry;
  28164. this.length++;
  28165. }
  28166. return isNegNum ? this.ineg() : this;
  28167. };
  28168. BN.prototype.muln = function muln(num) {
  28169. return this.clone().imuln(num);
  28170. }; // `this` * `this`
  28171. BN.prototype.sqr = function sqr() {
  28172. return this.mul(this);
  28173. }; // `this` * `this` in-place
  28174. BN.prototype.isqr = function isqr() {
  28175. return this.imul(this.clone());
  28176. }; // Math.pow(`this`, `num`)
  28177. BN.prototype.pow = function pow(num) {
  28178. var w = toBitArray(num);
  28179. if (w.length === 0) return new BN(1); // Skip leading zeroes
  28180. var res = this;
  28181. for (var i = 0; i < w.length; i++, res = res.sqr()) {
  28182. if (w[i] !== 0) break;
  28183. }
  28184. if (++i < w.length) {
  28185. for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) {
  28186. if (w[i] === 0) continue;
  28187. res = res.mul(q);
  28188. }
  28189. }
  28190. return res;
  28191. }; // Shift-left in-place
  28192. BN.prototype.iushln = function iushln(bits) {
  28193. assert(typeof bits === 'number' && bits >= 0);
  28194. var r = bits % 26;
  28195. var s = (bits - r) / 26;
  28196. var carryMask = 0x3ffffff >>> 26 - r << 26 - r;
  28197. var i;
  28198. if (r !== 0) {
  28199. var carry = 0;
  28200. for (i = 0; i < this.length; i++) {
  28201. var newCarry = this.words[i] & carryMask;
  28202. var c = (this.words[i] | 0) - newCarry << r;
  28203. this.words[i] = c | carry;
  28204. carry = newCarry >>> 26 - r;
  28205. }
  28206. if (carry) {
  28207. this.words[i] = carry;
  28208. this.length++;
  28209. }
  28210. }
  28211. if (s !== 0) {
  28212. for (i = this.length - 1; i >= 0; i--) {
  28213. this.words[i + s] = this.words[i];
  28214. }
  28215. for (i = 0; i < s; i++) {
  28216. this.words[i] = 0;
  28217. }
  28218. this.length += s;
  28219. }
  28220. return this._strip();
  28221. };
  28222. BN.prototype.ishln = function ishln(bits) {
  28223. // TODO(indutny): implement me
  28224. assert(this.negative === 0);
  28225. return this.iushln(bits);
  28226. }; // Shift-right in-place
  28227. // NOTE: `hint` is a lowest bit before trailing zeroes
  28228. // NOTE: if `extended` is present - it will be filled with destroyed bits
  28229. BN.prototype.iushrn = function iushrn(bits, hint, extended) {
  28230. assert(typeof bits === 'number' && bits >= 0);
  28231. var h;
  28232. if (hint) {
  28233. h = (hint - hint % 26) / 26;
  28234. } else {
  28235. h = 0;
  28236. }
  28237. var r = bits % 26;
  28238. var s = Math.min((bits - r) / 26, this.length);
  28239. var mask = 0x3ffffff ^ 0x3ffffff >>> r << r;
  28240. var maskedWords = extended;
  28241. h -= s;
  28242. h = Math.max(0, h); // Extended mode, copy masked part
  28243. if (maskedWords) {
  28244. for (var i = 0; i < s; i++) {
  28245. maskedWords.words[i] = this.words[i];
  28246. }
  28247. maskedWords.length = s;
  28248. }
  28249. if (s === 0) {// No-op, we should not move anything at all
  28250. } else if (this.length > s) {
  28251. this.length -= s;
  28252. for (i = 0; i < this.length; i++) {
  28253. this.words[i] = this.words[i + s];
  28254. }
  28255. } else {
  28256. this.words[0] = 0;
  28257. this.length = 1;
  28258. }
  28259. var carry = 0;
  28260. for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
  28261. var word = this.words[i] | 0;
  28262. this.words[i] = carry << 26 - r | word >>> r;
  28263. carry = word & mask;
  28264. } // Push carried bits as a mask
  28265. if (maskedWords && carry !== 0) {
  28266. maskedWords.words[maskedWords.length++] = carry;
  28267. }
  28268. if (this.length === 0) {
  28269. this.words[0] = 0;
  28270. this.length = 1;
  28271. }
  28272. return this._strip();
  28273. };
  28274. BN.prototype.ishrn = function ishrn(bits, hint, extended) {
  28275. // TODO(indutny): implement me
  28276. assert(this.negative === 0);
  28277. return this.iushrn(bits, hint, extended);
  28278. }; // Shift-left
  28279. BN.prototype.shln = function shln(bits) {
  28280. return this.clone().ishln(bits);
  28281. };
  28282. BN.prototype.ushln = function ushln(bits) {
  28283. return this.clone().iushln(bits);
  28284. }; // Shift-right
  28285. BN.prototype.shrn = function shrn(bits) {
  28286. return this.clone().ishrn(bits);
  28287. };
  28288. BN.prototype.ushrn = function ushrn(bits) {
  28289. return this.clone().iushrn(bits);
  28290. }; // Test if n bit is set
  28291. BN.prototype.testn = function testn(bit) {
  28292. assert(typeof bit === 'number' && bit >= 0);
  28293. var r = bit % 26;
  28294. var s = (bit - r) / 26;
  28295. var q = 1 << r; // Fast case: bit is much higher than all existing words
  28296. if (this.length <= s) return false; // Check bit and return
  28297. var w = this.words[s];
  28298. return !!(w & q);
  28299. }; // Return only lowers bits of number (in-place)
  28300. BN.prototype.imaskn = function imaskn(bits) {
  28301. assert(typeof bits === 'number' && bits >= 0);
  28302. var r = bits % 26;
  28303. var s = (bits - r) / 26;
  28304. assert(this.negative === 0, 'imaskn works only with positive numbers');
  28305. if (this.length <= s) {
  28306. return this;
  28307. }
  28308. if (r !== 0) {
  28309. s++;
  28310. }
  28311. this.length = Math.min(s, this.length);
  28312. if (r !== 0) {
  28313. var mask = 0x3ffffff ^ 0x3ffffff >>> r << r;
  28314. this.words[this.length - 1] &= mask;
  28315. }
  28316. return this._strip();
  28317. }; // Return only lowers bits of number
  28318. BN.prototype.maskn = function maskn(bits) {
  28319. return this.clone().imaskn(bits);
  28320. }; // Add plain number `num` to `this`
  28321. BN.prototype.iaddn = function iaddn(num) {
  28322. assert(typeof num === 'number');
  28323. assert(num < 0x4000000);
  28324. if (num < 0) return this.isubn(-num); // Possible sign change
  28325. if (this.negative !== 0) {
  28326. if (this.length === 1 && (this.words[0] | 0) <= num) {
  28327. this.words[0] = num - (this.words[0] | 0);
  28328. this.negative = 0;
  28329. return this;
  28330. }
  28331. this.negative = 0;
  28332. this.isubn(num);
  28333. this.negative = 1;
  28334. return this;
  28335. } // Add without checks
  28336. return this._iaddn(num);
  28337. };
  28338. BN.prototype._iaddn = function _iaddn(num) {
  28339. this.words[0] += num; // Carry
  28340. for (var i = 0; i < this.length && this.words[i] >= 0x4000000; i++) {
  28341. this.words[i] -= 0x4000000;
  28342. if (i === this.length - 1) {
  28343. this.words[i + 1] = 1;
  28344. } else {
  28345. this.words[i + 1]++;
  28346. }
  28347. }
  28348. this.length = Math.max(this.length, i + 1);
  28349. return this;
  28350. }; // Subtract plain number `num` from `this`
  28351. BN.prototype.isubn = function isubn(num) {
  28352. assert(typeof num === 'number');
  28353. assert(num < 0x4000000);
  28354. if (num < 0) return this.iaddn(-num);
  28355. if (this.negative !== 0) {
  28356. this.negative = 0;
  28357. this.iaddn(num);
  28358. this.negative = 1;
  28359. return this;
  28360. }
  28361. this.words[0] -= num;
  28362. if (this.length === 1 && this.words[0] < 0) {
  28363. this.words[0] = -this.words[0];
  28364. this.negative = 1;
  28365. } else {
  28366. // Carry
  28367. for (var i = 0; i < this.length && this.words[i] < 0; i++) {
  28368. this.words[i] += 0x4000000;
  28369. this.words[i + 1] -= 1;
  28370. }
  28371. }
  28372. return this._strip();
  28373. };
  28374. BN.prototype.addn = function addn(num) {
  28375. return this.clone().iaddn(num);
  28376. };
  28377. BN.prototype.subn = function subn(num) {
  28378. return this.clone().isubn(num);
  28379. };
  28380. BN.prototype.iabs = function iabs() {
  28381. this.negative = 0;
  28382. return this;
  28383. };
  28384. BN.prototype.abs = function abs() {
  28385. return this.clone().iabs();
  28386. };
  28387. BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) {
  28388. var len = num.length + shift;
  28389. var i;
  28390. this._expand(len);
  28391. var w;
  28392. var carry = 0;
  28393. for (i = 0; i < num.length; i++) {
  28394. w = (this.words[i + shift] | 0) + carry;
  28395. var right = (num.words[i] | 0) * mul;
  28396. w -= right & 0x3ffffff;
  28397. carry = (w >> 26) - (right / 0x4000000 | 0);
  28398. this.words[i + shift] = w & 0x3ffffff;
  28399. }
  28400. for (; i < this.length - shift; i++) {
  28401. w = (this.words[i + shift] | 0) + carry;
  28402. carry = w >> 26;
  28403. this.words[i + shift] = w & 0x3ffffff;
  28404. }
  28405. if (carry === 0) return this._strip(); // Subtraction overflow
  28406. assert(carry === -1);
  28407. carry = 0;
  28408. for (i = 0; i < this.length; i++) {
  28409. w = -(this.words[i] | 0) + carry;
  28410. carry = w >> 26;
  28411. this.words[i] = w & 0x3ffffff;
  28412. }
  28413. this.negative = 1;
  28414. return this._strip();
  28415. };
  28416. BN.prototype._wordDiv = function _wordDiv(num, mode) {
  28417. var shift = this.length - num.length;
  28418. var a = this.clone();
  28419. var b = num; // Normalize
  28420. var bhi = b.words[b.length - 1] | 0;
  28421. var bhiBits = this._countBits(bhi);
  28422. shift = 26 - bhiBits;
  28423. if (shift !== 0) {
  28424. b = b.ushln(shift);
  28425. a.iushln(shift);
  28426. bhi = b.words[b.length - 1] | 0;
  28427. } // Initialize quotient
  28428. var m = a.length - b.length;
  28429. var q;
  28430. if (mode !== 'mod') {
  28431. q = new BN(null);
  28432. q.length = m + 1;
  28433. q.words = new Array(q.length);
  28434. for (var i = 0; i < q.length; i++) {
  28435. q.words[i] = 0;
  28436. }
  28437. }
  28438. var diff = a.clone()._ishlnsubmul(b, 1, m);
  28439. if (diff.negative === 0) {
  28440. a = diff;
  28441. if (q) {
  28442. q.words[m] = 1;
  28443. }
  28444. }
  28445. for (var j = m - 1; j >= 0; j--) {
  28446. var qj = (a.words[b.length + j] | 0) * 0x4000000 + (a.words[b.length + j - 1] | 0); // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max
  28447. // (0x7ffffff)
  28448. qj = Math.min(qj / bhi | 0, 0x3ffffff);
  28449. a._ishlnsubmul(b, qj, j);
  28450. while (a.negative !== 0) {
  28451. qj--;
  28452. a.negative = 0;
  28453. a._ishlnsubmul(b, 1, j);
  28454. if (!a.isZero()) {
  28455. a.negative ^= 1;
  28456. }
  28457. }
  28458. if (q) {
  28459. q.words[j] = qj;
  28460. }
  28461. }
  28462. if (q) {
  28463. q._strip();
  28464. }
  28465. a._strip(); // Denormalize
  28466. if (mode !== 'div' && shift !== 0) {
  28467. a.iushrn(shift);
  28468. }
  28469. return {
  28470. div: q || null,
  28471. mod: a
  28472. };
  28473. }; // NOTE: 1) `mode` can be set to `mod` to request mod only,
  28474. // to `div` to request div only, or be absent to
  28475. // request both div & mod
  28476. // 2) `positive` is true if unsigned mod is requested
  28477. BN.prototype.divmod = function divmod(num, mode, positive) {
  28478. assert(!num.isZero());
  28479. if (this.isZero()) {
  28480. return {
  28481. div: new BN(0),
  28482. mod: new BN(0)
  28483. };
  28484. }
  28485. var div, mod, res;
  28486. if (this.negative !== 0 && num.negative === 0) {
  28487. res = this.neg().divmod(num, mode);
  28488. if (mode !== 'mod') {
  28489. div = res.div.neg();
  28490. }
  28491. if (mode !== 'div') {
  28492. mod = res.mod.neg();
  28493. if (positive && mod.negative !== 0) {
  28494. mod.iadd(num);
  28495. }
  28496. }
  28497. return {
  28498. div: div,
  28499. mod: mod
  28500. };
  28501. }
  28502. if (this.negative === 0 && num.negative !== 0) {
  28503. res = this.divmod(num.neg(), mode);
  28504. if (mode !== 'mod') {
  28505. div = res.div.neg();
  28506. }
  28507. return {
  28508. div: div,
  28509. mod: res.mod
  28510. };
  28511. }
  28512. if ((this.negative & num.negative) !== 0) {
  28513. res = this.neg().divmod(num.neg(), mode);
  28514. if (mode !== 'div') {
  28515. mod = res.mod.neg();
  28516. if (positive && mod.negative !== 0) {
  28517. mod.isub(num);
  28518. }
  28519. }
  28520. return {
  28521. div: res.div,
  28522. mod: mod
  28523. };
  28524. } // Both numbers are positive at this point
  28525. // Strip both numbers to approximate shift value
  28526. if (num.length > this.length || this.cmp(num) < 0) {
  28527. return {
  28528. div: new BN(0),
  28529. mod: this
  28530. };
  28531. } // Very short reduction
  28532. if (num.length === 1) {
  28533. if (mode === 'div') {
  28534. return {
  28535. div: this.divn(num.words[0]),
  28536. mod: null
  28537. };
  28538. }
  28539. if (mode === 'mod') {
  28540. return {
  28541. div: null,
  28542. mod: new BN(this.modrn(num.words[0]))
  28543. };
  28544. }
  28545. return {
  28546. div: this.divn(num.words[0]),
  28547. mod: new BN(this.modrn(num.words[0]))
  28548. };
  28549. }
  28550. return this._wordDiv(num, mode);
  28551. }; // Find `this` / `num`
  28552. BN.prototype.div = function div(num) {
  28553. return this.divmod(num, 'div', false).div;
  28554. }; // Find `this` % `num`
  28555. BN.prototype.mod = function mod(num) {
  28556. return this.divmod(num, 'mod', false).mod;
  28557. };
  28558. BN.prototype.umod = function umod(num) {
  28559. return this.divmod(num, 'mod', true).mod;
  28560. }; // Find Round(`this` / `num`)
  28561. BN.prototype.divRound = function divRound(num) {
  28562. var dm = this.divmod(num); // Fast case - exact division
  28563. if (dm.mod.isZero()) return dm.div;
  28564. var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
  28565. var half = num.ushrn(1);
  28566. var r2 = num.andln(1);
  28567. var cmp = mod.cmp(half); // Round down
  28568. if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; // Round up
  28569. return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
  28570. };
  28571. BN.prototype.modrn = function modrn(num) {
  28572. var isNegNum = num < 0;
  28573. if (isNegNum) num = -num;
  28574. assert(num <= 0x3ffffff);
  28575. var p = (1 << 26) % num;
  28576. var acc = 0;
  28577. for (var i = this.length - 1; i >= 0; i--) {
  28578. acc = (p * acc + (this.words[i] | 0)) % num;
  28579. }
  28580. return isNegNum ? -acc : acc;
  28581. }; // WARNING: DEPRECATED
  28582. BN.prototype.modn = function modn(num) {
  28583. return this.modrn(num);
  28584. }; // In-place division by number
  28585. BN.prototype.idivn = function idivn(num) {
  28586. var isNegNum = num < 0;
  28587. if (isNegNum) num = -num;
  28588. assert(num <= 0x3ffffff);
  28589. var carry = 0;
  28590. for (var i = this.length - 1; i >= 0; i--) {
  28591. var w = (this.words[i] | 0) + carry * 0x4000000;
  28592. this.words[i] = w / num | 0;
  28593. carry = w % num;
  28594. }
  28595. this._strip();
  28596. return isNegNum ? this.ineg() : this;
  28597. };
  28598. BN.prototype.divn = function divn(num) {
  28599. return this.clone().idivn(num);
  28600. };
  28601. BN.prototype.egcd = function egcd(p) {
  28602. assert(p.negative === 0);
  28603. assert(!p.isZero());
  28604. var x = this;
  28605. var y = p.clone();
  28606. if (x.negative !== 0) {
  28607. x = x.umod(p);
  28608. } else {
  28609. x = x.clone();
  28610. } // A * x + B * y = x
  28611. var A = new BN(1);
  28612. var B = new BN(0); // C * x + D * y = y
  28613. var C = new BN(0);
  28614. var D = new BN(1);
  28615. var g = 0;
  28616. while (x.isEven() && y.isEven()) {
  28617. x.iushrn(1);
  28618. y.iushrn(1);
  28619. ++g;
  28620. }
  28621. var yp = y.clone();
  28622. var xp = x.clone();
  28623. while (!x.isZero()) {
  28624. for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1) {
  28625. ;
  28626. }
  28627. if (i > 0) {
  28628. x.iushrn(i);
  28629. while (i-- > 0) {
  28630. if (A.isOdd() || B.isOdd()) {
  28631. A.iadd(yp);
  28632. B.isub(xp);
  28633. }
  28634. A.iushrn(1);
  28635. B.iushrn(1);
  28636. }
  28637. }
  28638. for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1) {
  28639. ;
  28640. }
  28641. if (j > 0) {
  28642. y.iushrn(j);
  28643. while (j-- > 0) {
  28644. if (C.isOdd() || D.isOdd()) {
  28645. C.iadd(yp);
  28646. D.isub(xp);
  28647. }
  28648. C.iushrn(1);
  28649. D.iushrn(1);
  28650. }
  28651. }
  28652. if (x.cmp(y) >= 0) {
  28653. x.isub(y);
  28654. A.isub(C);
  28655. B.isub(D);
  28656. } else {
  28657. y.isub(x);
  28658. C.isub(A);
  28659. D.isub(B);
  28660. }
  28661. }
  28662. return {
  28663. a: C,
  28664. b: D,
  28665. gcd: y.iushln(g)
  28666. };
  28667. }; // This is reduced incarnation of the binary EEA
  28668. // above, designated to invert members of the
  28669. // _prime_ fields F(p) at a maximal speed
  28670. BN.prototype._invmp = function _invmp(p) {
  28671. assert(p.negative === 0);
  28672. assert(!p.isZero());
  28673. var a = this;
  28674. var b = p.clone();
  28675. if (a.negative !== 0) {
  28676. a = a.umod(p);
  28677. } else {
  28678. a = a.clone();
  28679. }
  28680. var x1 = new BN(1);
  28681. var x2 = new BN(0);
  28682. var delta = b.clone();
  28683. while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
  28684. for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1) {
  28685. ;
  28686. }
  28687. if (i > 0) {
  28688. a.iushrn(i);
  28689. while (i-- > 0) {
  28690. if (x1.isOdd()) {
  28691. x1.iadd(delta);
  28692. }
  28693. x1.iushrn(1);
  28694. }
  28695. }
  28696. for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1) {
  28697. ;
  28698. }
  28699. if (j > 0) {
  28700. b.iushrn(j);
  28701. while (j-- > 0) {
  28702. if (x2.isOdd()) {
  28703. x2.iadd(delta);
  28704. }
  28705. x2.iushrn(1);
  28706. }
  28707. }
  28708. if (a.cmp(b) >= 0) {
  28709. a.isub(b);
  28710. x1.isub(x2);
  28711. } else {
  28712. b.isub(a);
  28713. x2.isub(x1);
  28714. }
  28715. }
  28716. var res;
  28717. if (a.cmpn(1) === 0) {
  28718. res = x1;
  28719. } else {
  28720. res = x2;
  28721. }
  28722. if (res.cmpn(0) < 0) {
  28723. res.iadd(p);
  28724. }
  28725. return res;
  28726. };
  28727. BN.prototype.gcd = function gcd(num) {
  28728. if (this.isZero()) return num.abs();
  28729. if (num.isZero()) return this.abs();
  28730. var a = this.clone();
  28731. var b = num.clone();
  28732. a.negative = 0;
  28733. b.negative = 0; // Remove common factor of two
  28734. for (var shift = 0; a.isEven() && b.isEven(); shift++) {
  28735. a.iushrn(1);
  28736. b.iushrn(1);
  28737. }
  28738. do {
  28739. while (a.isEven()) {
  28740. a.iushrn(1);
  28741. }
  28742. while (b.isEven()) {
  28743. b.iushrn(1);
  28744. }
  28745. var r = a.cmp(b);
  28746. if (r < 0) {
  28747. // Swap `a` and `b` to make `a` always bigger than `b`
  28748. var t = a;
  28749. a = b;
  28750. b = t;
  28751. } else if (r === 0 || b.cmpn(1) === 0) {
  28752. break;
  28753. }
  28754. a.isub(b);
  28755. } while (true);
  28756. return b.iushln(shift);
  28757. }; // Invert number in the field F(num)
  28758. BN.prototype.invm = function invm(num) {
  28759. return this.egcd(num).a.umod(num);
  28760. };
  28761. BN.prototype.isEven = function isEven() {
  28762. return (this.words[0] & 1) === 0;
  28763. };
  28764. BN.prototype.isOdd = function isOdd() {
  28765. return (this.words[0] & 1) === 1;
  28766. }; // And first word and num
  28767. BN.prototype.andln = function andln(num) {
  28768. return this.words[0] & num;
  28769. }; // Increment at the bit position in-line
  28770. BN.prototype.bincn = function bincn(bit) {
  28771. assert(typeof bit === 'number');
  28772. var r = bit % 26;
  28773. var s = (bit - r) / 26;
  28774. var q = 1 << r; // Fast case: bit is much higher than all existing words
  28775. if (this.length <= s) {
  28776. this._expand(s + 1);
  28777. this.words[s] |= q;
  28778. return this;
  28779. } // Add bit and propagate, if needed
  28780. var carry = q;
  28781. for (var i = s; carry !== 0 && i < this.length; i++) {
  28782. var w = this.words[i] | 0;
  28783. w += carry;
  28784. carry = w >>> 26;
  28785. w &= 0x3ffffff;
  28786. this.words[i] = w;
  28787. }
  28788. if (carry !== 0) {
  28789. this.words[i] = carry;
  28790. this.length++;
  28791. }
  28792. return this;
  28793. };
  28794. BN.prototype.isZero = function isZero() {
  28795. return this.length === 1 && this.words[0] === 0;
  28796. };
  28797. BN.prototype.cmpn = function cmpn(num) {
  28798. var negative = num < 0;
  28799. if (this.negative !== 0 && !negative) return -1;
  28800. if (this.negative === 0 && negative) return 1;
  28801. this._strip();
  28802. var res;
  28803. if (this.length > 1) {
  28804. res = 1;
  28805. } else {
  28806. if (negative) {
  28807. num = -num;
  28808. }
  28809. assert(num <= 0x3ffffff, 'Number is too big');
  28810. var w = this.words[0] | 0;
  28811. res = w === num ? 0 : w < num ? -1 : 1;
  28812. }
  28813. if (this.negative !== 0) return -res | 0;
  28814. return res;
  28815. }; // Compare two numbers and return:
  28816. // 1 - if `this` > `num`
  28817. // 0 - if `this` == `num`
  28818. // -1 - if `this` < `num`
  28819. BN.prototype.cmp = function cmp(num) {
  28820. if (this.negative !== 0 && num.negative === 0) return -1;
  28821. if (this.negative === 0 && num.negative !== 0) return 1;
  28822. var res = this.ucmp(num);
  28823. if (this.negative !== 0) return -res | 0;
  28824. return res;
  28825. }; // Unsigned comparison
  28826. BN.prototype.ucmp = function ucmp(num) {
  28827. // At this point both numbers have the same sign
  28828. if (this.length > num.length) return 1;
  28829. if (this.length < num.length) return -1;
  28830. var res = 0;
  28831. for (var i = this.length - 1; i >= 0; i--) {
  28832. var a = this.words[i] | 0;
  28833. var b = num.words[i] | 0;
  28834. if (a === b) continue;
  28835. if (a < b) {
  28836. res = -1;
  28837. } else if (a > b) {
  28838. res = 1;
  28839. }
  28840. break;
  28841. }
  28842. return res;
  28843. };
  28844. BN.prototype.gtn = function gtn(num) {
  28845. return this.cmpn(num) === 1;
  28846. };
  28847. BN.prototype.gt = function gt(num) {
  28848. return this.cmp(num) === 1;
  28849. };
  28850. BN.prototype.gten = function gten(num) {
  28851. return this.cmpn(num) >= 0;
  28852. };
  28853. BN.prototype.gte = function gte(num) {
  28854. return this.cmp(num) >= 0;
  28855. };
  28856. BN.prototype.ltn = function ltn(num) {
  28857. return this.cmpn(num) === -1;
  28858. };
  28859. BN.prototype.lt = function lt(num) {
  28860. return this.cmp(num) === -1;
  28861. };
  28862. BN.prototype.lten = function lten(num) {
  28863. return this.cmpn(num) <= 0;
  28864. };
  28865. BN.prototype.lte = function lte(num) {
  28866. return this.cmp(num) <= 0;
  28867. };
  28868. BN.prototype.eqn = function eqn(num) {
  28869. return this.cmpn(num) === 0;
  28870. };
  28871. BN.prototype.eq = function eq(num) {
  28872. return this.cmp(num) === 0;
  28873. }; //
  28874. // A reduce context, could be using montgomery or something better, depending
  28875. // on the `m` itself.
  28876. //
  28877. BN.red = function red(num) {
  28878. return new Red(num);
  28879. };
  28880. BN.prototype.toRed = function toRed(ctx) {
  28881. assert(!this.red, 'Already a number in reduction context');
  28882. assert(this.negative === 0, 'red works only with positives');
  28883. return ctx.convertTo(this)._forceRed(ctx);
  28884. };
  28885. BN.prototype.fromRed = function fromRed() {
  28886. assert(this.red, 'fromRed works only with numbers in reduction context');
  28887. return this.red.convertFrom(this);
  28888. };
  28889. BN.prototype._forceRed = function _forceRed(ctx) {
  28890. this.red = ctx;
  28891. return this;
  28892. };
  28893. BN.prototype.forceRed = function forceRed(ctx) {
  28894. assert(!this.red, 'Already a number in reduction context');
  28895. return this._forceRed(ctx);
  28896. };
  28897. BN.prototype.redAdd = function redAdd(num) {
  28898. assert(this.red, 'redAdd works only with red numbers');
  28899. return this.red.add(this, num);
  28900. };
  28901. BN.prototype.redIAdd = function redIAdd(num) {
  28902. assert(this.red, 'redIAdd works only with red numbers');
  28903. return this.red.iadd(this, num);
  28904. };
  28905. BN.prototype.redSub = function redSub(num) {
  28906. assert(this.red, 'redSub works only with red numbers');
  28907. return this.red.sub(this, num);
  28908. };
  28909. BN.prototype.redISub = function redISub(num) {
  28910. assert(this.red, 'redISub works only with red numbers');
  28911. return this.red.isub(this, num);
  28912. };
  28913. BN.prototype.redShl = function redShl(num) {
  28914. assert(this.red, 'redShl works only with red numbers');
  28915. return this.red.shl(this, num);
  28916. };
  28917. BN.prototype.redMul = function redMul(num) {
  28918. assert(this.red, 'redMul works only with red numbers');
  28919. this.red._verify2(this, num);
  28920. return this.red.mul(this, num);
  28921. };
  28922. BN.prototype.redIMul = function redIMul(num) {
  28923. assert(this.red, 'redMul works only with red numbers');
  28924. this.red._verify2(this, num);
  28925. return this.red.imul(this, num);
  28926. };
  28927. BN.prototype.redSqr = function redSqr() {
  28928. assert(this.red, 'redSqr works only with red numbers');
  28929. this.red._verify1(this);
  28930. return this.red.sqr(this);
  28931. };
  28932. BN.prototype.redISqr = function redISqr() {
  28933. assert(this.red, 'redISqr works only with red numbers');
  28934. this.red._verify1(this);
  28935. return this.red.isqr(this);
  28936. }; // Square root over p
  28937. BN.prototype.redSqrt = function redSqrt() {
  28938. assert(this.red, 'redSqrt works only with red numbers');
  28939. this.red._verify1(this);
  28940. return this.red.sqrt(this);
  28941. };
  28942. BN.prototype.redInvm = function redInvm() {
  28943. assert(this.red, 'redInvm works only with red numbers');
  28944. this.red._verify1(this);
  28945. return this.red.invm(this);
  28946. }; // Return negative clone of `this` % `red modulo`
  28947. BN.prototype.redNeg = function redNeg() {
  28948. assert(this.red, 'redNeg works only with red numbers');
  28949. this.red._verify1(this);
  28950. return this.red.neg(this);
  28951. };
  28952. BN.prototype.redPow = function redPow(num) {
  28953. assert(this.red && !num.red, 'redPow(normalNum)');
  28954. this.red._verify1(this);
  28955. return this.red.pow(this, num);
  28956. }; // Prime numbers with efficient reduction
  28957. var primes = {
  28958. k256: null,
  28959. p224: null,
  28960. p192: null,
  28961. p25519: null
  28962. }; // Pseudo-Mersenne prime
  28963. function MPrime(name, p) {
  28964. // P = 2 ^ N - K
  28965. this.name = name;
  28966. this.p = new BN(p, 16);
  28967. this.n = this.p.bitLength();
  28968. this.k = new BN(1).iushln(this.n).isub(this.p);
  28969. this.tmp = this._tmp();
  28970. }
  28971. MPrime.prototype._tmp = function _tmp() {
  28972. var tmp = new BN(null);
  28973. tmp.words = new Array(Math.ceil(this.n / 13));
  28974. return tmp;
  28975. };
  28976. MPrime.prototype.ireduce = function ireduce(num) {
  28977. // Assumes that `num` is less than `P^2`
  28978. // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P)
  28979. var r = num;
  28980. var rlen;
  28981. do {
  28982. this.split(r, this.tmp);
  28983. r = this.imulK(r);
  28984. r = r.iadd(this.tmp);
  28985. rlen = r.bitLength();
  28986. } while (rlen > this.n);
  28987. var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
  28988. if (cmp === 0) {
  28989. r.words[0] = 0;
  28990. r.length = 1;
  28991. } else if (cmp > 0) {
  28992. r.isub(this.p);
  28993. } else {
  28994. if (r.strip !== undefined) {
  28995. // r is a BN v4 instance
  28996. r.strip();
  28997. } else {
  28998. // r is a BN v5 instance
  28999. r._strip();
  29000. }
  29001. }
  29002. return r;
  29003. };
  29004. MPrime.prototype.split = function split(input, out) {
  29005. input.iushrn(this.n, 0, out);
  29006. };
  29007. MPrime.prototype.imulK = function imulK(num) {
  29008. return num.imul(this.k);
  29009. };
  29010. function K256() {
  29011. MPrime.call(this, 'k256', 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f');
  29012. }
  29013. inherits(K256, MPrime);
  29014. K256.prototype.split = function split(input, output) {
  29015. // 256 = 9 * 26 + 22
  29016. var mask = 0x3fffff;
  29017. var outLen = Math.min(input.length, 9);
  29018. for (var i = 0; i < outLen; i++) {
  29019. output.words[i] = input.words[i];
  29020. }
  29021. output.length = outLen;
  29022. if (input.length <= 9) {
  29023. input.words[0] = 0;
  29024. input.length = 1;
  29025. return;
  29026. } // Shift by 9 limbs
  29027. var prev = input.words[9];
  29028. output.words[output.length++] = prev & mask;
  29029. for (i = 10; i < input.length; i++) {
  29030. var next = input.words[i] | 0;
  29031. input.words[i - 10] = (next & mask) << 4 | prev >>> 22;
  29032. prev = next;
  29033. }
  29034. prev >>>= 22;
  29035. input.words[i - 10] = prev;
  29036. if (prev === 0 && input.length > 10) {
  29037. input.length -= 10;
  29038. } else {
  29039. input.length -= 9;
  29040. }
  29041. };
  29042. K256.prototype.imulK = function imulK(num) {
  29043. // K = 0x1000003d1 = [ 0x40, 0x3d1 ]
  29044. num.words[num.length] = 0;
  29045. num.words[num.length + 1] = 0;
  29046. num.length += 2; // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390
  29047. var lo = 0;
  29048. for (var i = 0; i < num.length; i++) {
  29049. var w = num.words[i] | 0;
  29050. lo += w * 0x3d1;
  29051. num.words[i] = lo & 0x3ffffff;
  29052. lo = w * 0x40 + (lo / 0x4000000 | 0);
  29053. } // Fast length reduction
  29054. if (num.words[num.length - 1] === 0) {
  29055. num.length--;
  29056. if (num.words[num.length - 1] === 0) {
  29057. num.length--;
  29058. }
  29059. }
  29060. return num;
  29061. };
  29062. function P224() {
  29063. MPrime.call(this, 'p224', 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001');
  29064. }
  29065. inherits(P224, MPrime);
  29066. function P192() {
  29067. MPrime.call(this, 'p192', 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff');
  29068. }
  29069. inherits(P192, MPrime);
  29070. function P25519() {
  29071. // 2 ^ 255 - 19
  29072. MPrime.call(this, '25519', '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed');
  29073. }
  29074. inherits(P25519, MPrime);
  29075. P25519.prototype.imulK = function imulK(num) {
  29076. // K = 0x13
  29077. var carry = 0;
  29078. for (var i = 0; i < num.length; i++) {
  29079. var hi = (num.words[i] | 0) * 0x13 + carry;
  29080. var lo = hi & 0x3ffffff;
  29081. hi >>>= 26;
  29082. num.words[i] = lo;
  29083. carry = hi;
  29084. }
  29085. if (carry !== 0) {
  29086. num.words[num.length++] = carry;
  29087. }
  29088. return num;
  29089. }; // Exported mostly for testing purposes, use plain name instead
  29090. BN._prime = function prime(name) {
  29091. // Cached version of prime
  29092. if (primes[name]) return primes[name];
  29093. var prime;
  29094. if (name === 'k256') {
  29095. prime = new K256();
  29096. } else if (name === 'p224') {
  29097. prime = new P224();
  29098. } else if (name === 'p192') {
  29099. prime = new P192();
  29100. } else if (name === 'p25519') {
  29101. prime = new P25519();
  29102. } else {
  29103. throw new Error('Unknown prime ' + name);
  29104. }
  29105. primes[name] = prime;
  29106. return prime;
  29107. }; //
  29108. // Base reduction engine
  29109. //
  29110. function Red(m) {
  29111. if (typeof m === 'string') {
  29112. var prime = BN._prime(m);
  29113. this.m = prime.p;
  29114. this.prime = prime;
  29115. } else {
  29116. assert(m.gtn(1), 'modulus must be greater than 1');
  29117. this.m = m;
  29118. this.prime = null;
  29119. }
  29120. }
  29121. Red.prototype._verify1 = function _verify1(a) {
  29122. assert(a.negative === 0, 'red works only with positives');
  29123. assert(a.red, 'red works only with red numbers');
  29124. };
  29125. Red.prototype._verify2 = function _verify2(a, b) {
  29126. assert((a.negative | b.negative) === 0, 'red works only with positives');
  29127. assert(a.red && a.red === b.red, 'red works only with red numbers');
  29128. };
  29129. Red.prototype.imod = function imod(a) {
  29130. if (this.prime) return this.prime.ireduce(a)._forceRed(this);
  29131. move(a, a.umod(this.m)._forceRed(this));
  29132. return a;
  29133. };
  29134. Red.prototype.neg = function neg(a) {
  29135. if (a.isZero()) {
  29136. return a.clone();
  29137. }
  29138. return this.m.sub(a)._forceRed(this);
  29139. };
  29140. Red.prototype.add = function add(a, b) {
  29141. this._verify2(a, b);
  29142. var res = a.add(b);
  29143. if (res.cmp(this.m) >= 0) {
  29144. res.isub(this.m);
  29145. }
  29146. return res._forceRed(this);
  29147. };
  29148. Red.prototype.iadd = function iadd(a, b) {
  29149. this._verify2(a, b);
  29150. var res = a.iadd(b);
  29151. if (res.cmp(this.m) >= 0) {
  29152. res.isub(this.m);
  29153. }
  29154. return res;
  29155. };
  29156. Red.prototype.sub = function sub(a, b) {
  29157. this._verify2(a, b);
  29158. var res = a.sub(b);
  29159. if (res.cmpn(0) < 0) {
  29160. res.iadd(this.m);
  29161. }
  29162. return res._forceRed(this);
  29163. };
  29164. Red.prototype.isub = function isub(a, b) {
  29165. this._verify2(a, b);
  29166. var res = a.isub(b);
  29167. if (res.cmpn(0) < 0) {
  29168. res.iadd(this.m);
  29169. }
  29170. return res;
  29171. };
  29172. Red.prototype.shl = function shl(a, num) {
  29173. this._verify1(a);
  29174. return this.imod(a.ushln(num));
  29175. };
  29176. Red.prototype.imul = function imul(a, b) {
  29177. this._verify2(a, b);
  29178. return this.imod(a.imul(b));
  29179. };
  29180. Red.prototype.mul = function mul(a, b) {
  29181. this._verify2(a, b);
  29182. return this.imod(a.mul(b));
  29183. };
  29184. Red.prototype.isqr = function isqr(a) {
  29185. return this.imul(a, a.clone());
  29186. };
  29187. Red.prototype.sqr = function sqr(a) {
  29188. return this.mul(a, a);
  29189. };
  29190. Red.prototype.sqrt = function sqrt(a) {
  29191. if (a.isZero()) return a.clone();
  29192. var mod3 = this.m.andln(3);
  29193. assert(mod3 % 2 === 1); // Fast case
  29194. if (mod3 === 3) {
  29195. var pow = this.m.add(new BN(1)).iushrn(2);
  29196. return this.pow(a, pow);
  29197. } // Tonelli-Shanks algorithm (Totally unoptimized and slow)
  29198. //
  29199. // Find Q and S, that Q * 2 ^ S = (P - 1)
  29200. var q = this.m.subn(1);
  29201. var s = 0;
  29202. while (!q.isZero() && q.andln(1) === 0) {
  29203. s++;
  29204. q.iushrn(1);
  29205. }
  29206. assert(!q.isZero());
  29207. var one = new BN(1).toRed(this);
  29208. var nOne = one.redNeg(); // Find quadratic non-residue
  29209. // NOTE: Max is such because of generalized Riemann hypothesis.
  29210. var lpow = this.m.subn(1).iushrn(1);
  29211. var z = this.m.bitLength();
  29212. z = new BN(2 * z * z).toRed(this);
  29213. while (this.pow(z, lpow).cmp(nOne) !== 0) {
  29214. z.redIAdd(nOne);
  29215. }
  29216. var c = this.pow(z, q);
  29217. var r = this.pow(a, q.addn(1).iushrn(1));
  29218. var t = this.pow(a, q);
  29219. var m = s;
  29220. while (t.cmp(one) !== 0) {
  29221. var tmp = t;
  29222. for (var i = 0; tmp.cmp(one) !== 0; i++) {
  29223. tmp = tmp.redSqr();
  29224. }
  29225. assert(i < m);
  29226. var b = this.pow(c, new BN(1).iushln(m - i - 1));
  29227. r = r.redMul(b);
  29228. c = b.redSqr();
  29229. t = t.redMul(c);
  29230. m = i;
  29231. }
  29232. return r;
  29233. };
  29234. Red.prototype.invm = function invm(a) {
  29235. var inv = a._invmp(this.m);
  29236. if (inv.negative !== 0) {
  29237. inv.negative = 0;
  29238. return this.imod(inv).redNeg();
  29239. } else {
  29240. return this.imod(inv);
  29241. }
  29242. };
  29243. Red.prototype.pow = function pow(a, num) {
  29244. if (num.isZero()) return new BN(1).toRed(this);
  29245. if (num.cmpn(1) === 0) return a.clone();
  29246. var windowSize = 4;
  29247. var wnd = new Array(1 << windowSize);
  29248. wnd[0] = new BN(1).toRed(this);
  29249. wnd[1] = a;
  29250. for (var i = 2; i < wnd.length; i++) {
  29251. wnd[i] = this.mul(wnd[i - 1], a);
  29252. }
  29253. var res = wnd[0];
  29254. var current = 0;
  29255. var currentLen = 0;
  29256. var start = num.bitLength() % 26;
  29257. if (start === 0) {
  29258. start = 26;
  29259. }
  29260. for (i = num.length - 1; i >= 0; i--) {
  29261. var word = num.words[i];
  29262. for (var j = start - 1; j >= 0; j--) {
  29263. var bit = word >> j & 1;
  29264. if (res !== wnd[0]) {
  29265. res = this.sqr(res);
  29266. }
  29267. if (bit === 0 && current === 0) {
  29268. currentLen = 0;
  29269. continue;
  29270. }
  29271. current <<= 1;
  29272. current |= bit;
  29273. currentLen++;
  29274. if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue;
  29275. res = this.mul(res, wnd[current]);
  29276. currentLen = 0;
  29277. current = 0;
  29278. }
  29279. start = 26;
  29280. }
  29281. return res;
  29282. };
  29283. Red.prototype.convertTo = function convertTo(num) {
  29284. var r = num.umod(this.m);
  29285. return r === num ? r.clone() : r;
  29286. };
  29287. Red.prototype.convertFrom = function convertFrom(num) {
  29288. var res = num.clone();
  29289. res.red = null;
  29290. return res;
  29291. }; //
  29292. // Montgomery method engine
  29293. //
  29294. BN.mont = function mont(num) {
  29295. return new Mont(num);
  29296. };
  29297. function Mont(m) {
  29298. Red.call(this, m);
  29299. this.shift = this.m.bitLength();
  29300. if (this.shift % 26 !== 0) {
  29301. this.shift += 26 - this.shift % 26;
  29302. }
  29303. this.r = new BN(1).iushln(this.shift);
  29304. this.r2 = this.imod(this.r.sqr());
  29305. this.rinv = this.r._invmp(this.m);
  29306. this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
  29307. this.minv = this.minv.umod(this.r);
  29308. this.minv = this.r.sub(this.minv);
  29309. }
  29310. inherits(Mont, Red);
  29311. Mont.prototype.convertTo = function convertTo(num) {
  29312. return this.imod(num.ushln(this.shift));
  29313. };
  29314. Mont.prototype.convertFrom = function convertFrom(num) {
  29315. var r = this.imod(num.mul(this.rinv));
  29316. r.red = null;
  29317. return r;
  29318. };
  29319. Mont.prototype.imul = function imul(a, b) {
  29320. if (a.isZero() || b.isZero()) {
  29321. a.words[0] = 0;
  29322. a.length = 1;
  29323. return a;
  29324. }
  29325. var t = a.imul(b);
  29326. var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
  29327. var u = t.isub(c).iushrn(this.shift);
  29328. var res = u;
  29329. if (u.cmp(this.m) >= 0) {
  29330. res = u.isub(this.m);
  29331. } else if (u.cmpn(0) < 0) {
  29332. res = u.iadd(this.m);
  29333. }
  29334. return res._forceRed(this);
  29335. };
  29336. Mont.prototype.mul = function mul(a, b) {
  29337. if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
  29338. var t = a.mul(b);
  29339. var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
  29340. var u = t.isub(c).iushrn(this.shift);
  29341. var res = u;
  29342. if (u.cmp(this.m) >= 0) {
  29343. res = u.isub(this.m);
  29344. } else if (u.cmpn(0) < 0) {
  29345. res = u.iadd(this.m);
  29346. }
  29347. return res._forceRed(this);
  29348. };
  29349. Mont.prototype.invm = function invm(a) {
  29350. // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R
  29351. var res = this.imod(a._invmp(this.m).mul(this.r2));
  29352. return res._forceRed(this);
  29353. };
  29354. })(typeof module === 'undefined' || module, void 0);
  29355. },{"buffer":185}],184:[function(require,module,exports){
  29356. "use strict";
  29357. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  29358. var r;
  29359. module.exports = function rand(len) {
  29360. if (!r) r = new Rand(null);
  29361. return r.generate(len);
  29362. };
  29363. function Rand(rand) {
  29364. this.rand = rand;
  29365. }
  29366. module.exports.Rand = Rand;
  29367. Rand.prototype.generate = function generate(len) {
  29368. return this._rand(len);
  29369. }; // Emulate crypto API using randy
  29370. Rand.prototype._rand = function _rand(n) {
  29371. if (this.rand.getBytes) return this.rand.getBytes(n);
  29372. var res = new Uint8Array(n);
  29373. for (var i = 0; i < res.length; i++) {
  29374. res[i] = this.rand.getByte();
  29375. }
  29376. return res;
  29377. };
  29378. if ((typeof self === "undefined" ? "undefined" : _typeof(self)) === 'object') {
  29379. if (self.crypto && self.crypto.getRandomValues) {
  29380. // Modern browsers
  29381. Rand.prototype._rand = function _rand(n) {
  29382. var arr = new Uint8Array(n);
  29383. self.crypto.getRandomValues(arr);
  29384. return arr;
  29385. };
  29386. } else if (self.msCrypto && self.msCrypto.getRandomValues) {
  29387. // IE
  29388. Rand.prototype._rand = function _rand(n) {
  29389. var arr = new Uint8Array(n);
  29390. self.msCrypto.getRandomValues(arr);
  29391. return arr;
  29392. }; // Safari's WebWorkers do not have `crypto`
  29393. } else if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object') {
  29394. // Old junk
  29395. Rand.prototype._rand = function () {
  29396. throw new Error('Not implemented yet');
  29397. };
  29398. }
  29399. } else {
  29400. // Node.js or Web worker with no crypto support
  29401. try {
  29402. var crypto = require('crypto');
  29403. if (typeof crypto.randomBytes !== 'function') throw new Error('Not supported');
  29404. Rand.prototype._rand = function _rand(n) {
  29405. return crypto.randomBytes(n);
  29406. };
  29407. } catch (e) {}
  29408. }
  29409. },{"crypto":185}],185:[function(require,module,exports){
  29410. "use strict";
  29411. },{}],186:[function(require,module,exports){
  29412. "use strict";
  29413. // based on the aes implimentation in triple sec
  29414. // https://github.com/keybase/triplesec
  29415. // which is in turn based on the one from crypto-js
  29416. // https://code.google.com/p/crypto-js/
  29417. var Buffer = require('safe-buffer').Buffer;
  29418. function asUInt32Array(buf) {
  29419. if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf);
  29420. var len = buf.length / 4 | 0;
  29421. var out = new Array(len);
  29422. for (var i = 0; i < len; i++) {
  29423. out[i] = buf.readUInt32BE(i * 4);
  29424. }
  29425. return out;
  29426. }
  29427. function scrubVec(v) {
  29428. for (var i = 0; i < v.length; v++) {
  29429. v[i] = 0;
  29430. }
  29431. }
  29432. function cryptBlock(M, keySchedule, SUB_MIX, SBOX, nRounds) {
  29433. var SUB_MIX0 = SUB_MIX[0];
  29434. var SUB_MIX1 = SUB_MIX[1];
  29435. var SUB_MIX2 = SUB_MIX[2];
  29436. var SUB_MIX3 = SUB_MIX[3];
  29437. var s0 = M[0] ^ keySchedule[0];
  29438. var s1 = M[1] ^ keySchedule[1];
  29439. var s2 = M[2] ^ keySchedule[2];
  29440. var s3 = M[3] ^ keySchedule[3];
  29441. var t0, t1, t2, t3;
  29442. var ksRow = 4;
  29443. for (var round = 1; round < nRounds; round++) {
  29444. t0 = SUB_MIX0[s0 >>> 24] ^ SUB_MIX1[s1 >>> 16 & 0xff] ^ SUB_MIX2[s2 >>> 8 & 0xff] ^ SUB_MIX3[s3 & 0xff] ^ keySchedule[ksRow++];
  29445. t1 = SUB_MIX0[s1 >>> 24] ^ SUB_MIX1[s2 >>> 16 & 0xff] ^ SUB_MIX2[s3 >>> 8 & 0xff] ^ SUB_MIX3[s0 & 0xff] ^ keySchedule[ksRow++];
  29446. t2 = SUB_MIX0[s2 >>> 24] ^ SUB_MIX1[s3 >>> 16 & 0xff] ^ SUB_MIX2[s0 >>> 8 & 0xff] ^ SUB_MIX3[s1 & 0xff] ^ keySchedule[ksRow++];
  29447. t3 = SUB_MIX0[s3 >>> 24] ^ SUB_MIX1[s0 >>> 16 & 0xff] ^ SUB_MIX2[s1 >>> 8 & 0xff] ^ SUB_MIX3[s2 & 0xff] ^ keySchedule[ksRow++];
  29448. s0 = t0;
  29449. s1 = t1;
  29450. s2 = t2;
  29451. s3 = t3;
  29452. }
  29453. t0 = (SBOX[s0 >>> 24] << 24 | SBOX[s1 >>> 16 & 0xff] << 16 | SBOX[s2 >>> 8 & 0xff] << 8 | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++];
  29454. t1 = (SBOX[s1 >>> 24] << 24 | SBOX[s2 >>> 16 & 0xff] << 16 | SBOX[s3 >>> 8 & 0xff] << 8 | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++];
  29455. t2 = (SBOX[s2 >>> 24] << 24 | SBOX[s3 >>> 16 & 0xff] << 16 | SBOX[s0 >>> 8 & 0xff] << 8 | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++];
  29456. t3 = (SBOX[s3 >>> 24] << 24 | SBOX[s0 >>> 16 & 0xff] << 16 | SBOX[s1 >>> 8 & 0xff] << 8 | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++];
  29457. t0 = t0 >>> 0;
  29458. t1 = t1 >>> 0;
  29459. t2 = t2 >>> 0;
  29460. t3 = t3 >>> 0;
  29461. return [t0, t1, t2, t3];
  29462. } // AES constants
  29463. var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
  29464. var G = function () {
  29465. // Compute double table
  29466. var d = new Array(256);
  29467. for (var j = 0; j < 256; j++) {
  29468. if (j < 128) {
  29469. d[j] = j << 1;
  29470. } else {
  29471. d[j] = j << 1 ^ 0x11b;
  29472. }
  29473. }
  29474. var SBOX = [];
  29475. var INV_SBOX = [];
  29476. var SUB_MIX = [[], [], [], []];
  29477. var INV_SUB_MIX = [[], [], [], []]; // Walk GF(2^8)
  29478. var x = 0;
  29479. var xi = 0;
  29480. for (var i = 0; i < 256; ++i) {
  29481. // Compute sbox
  29482. var sx = xi ^ xi << 1 ^ xi << 2 ^ xi << 3 ^ xi << 4;
  29483. sx = sx >>> 8 ^ sx & 0xff ^ 0x63;
  29484. SBOX[x] = sx;
  29485. INV_SBOX[sx] = x; // Compute multiplication
  29486. var x2 = d[x];
  29487. var x4 = d[x2];
  29488. var x8 = d[x4]; // Compute sub bytes, mix columns tables
  29489. var t = d[sx] * 0x101 ^ sx * 0x1010100;
  29490. SUB_MIX[0][x] = t << 24 | t >>> 8;
  29491. SUB_MIX[1][x] = t << 16 | t >>> 16;
  29492. SUB_MIX[2][x] = t << 8 | t >>> 24;
  29493. SUB_MIX[3][x] = t; // Compute inv sub bytes, inv mix columns tables
  29494. t = x8 * 0x1010101 ^ x4 * 0x10001 ^ x2 * 0x101 ^ x * 0x1010100;
  29495. INV_SUB_MIX[0][sx] = t << 24 | t >>> 8;
  29496. INV_SUB_MIX[1][sx] = t << 16 | t >>> 16;
  29497. INV_SUB_MIX[2][sx] = t << 8 | t >>> 24;
  29498. INV_SUB_MIX[3][sx] = t;
  29499. if (x === 0) {
  29500. x = xi = 1;
  29501. } else {
  29502. x = x2 ^ d[d[d[x8 ^ x2]]];
  29503. xi ^= d[d[xi]];
  29504. }
  29505. }
  29506. return {
  29507. SBOX: SBOX,
  29508. INV_SBOX: INV_SBOX,
  29509. SUB_MIX: SUB_MIX,
  29510. INV_SUB_MIX: INV_SUB_MIX
  29511. };
  29512. }();
  29513. function AES(key) {
  29514. this._key = asUInt32Array(key);
  29515. this._reset();
  29516. }
  29517. AES.blockSize = 4 * 4;
  29518. AES.keySize = 256 / 8;
  29519. AES.prototype.blockSize = AES.blockSize;
  29520. AES.prototype.keySize = AES.keySize;
  29521. AES.prototype._reset = function () {
  29522. var keyWords = this._key;
  29523. var keySize = keyWords.length;
  29524. var nRounds = keySize + 6;
  29525. var ksRows = (nRounds + 1) * 4;
  29526. var keySchedule = [];
  29527. for (var k = 0; k < keySize; k++) {
  29528. keySchedule[k] = keyWords[k];
  29529. }
  29530. for (k = keySize; k < ksRows; k++) {
  29531. var t = keySchedule[k - 1];
  29532. if (k % keySize === 0) {
  29533. t = t << 8 | t >>> 24;
  29534. t = G.SBOX[t >>> 24] << 24 | G.SBOX[t >>> 16 & 0xff] << 16 | G.SBOX[t >>> 8 & 0xff] << 8 | G.SBOX[t & 0xff];
  29535. t ^= RCON[k / keySize | 0] << 24;
  29536. } else if (keySize > 6 && k % keySize === 4) {
  29537. t = G.SBOX[t >>> 24] << 24 | G.SBOX[t >>> 16 & 0xff] << 16 | G.SBOX[t >>> 8 & 0xff] << 8 | G.SBOX[t & 0xff];
  29538. }
  29539. keySchedule[k] = keySchedule[k - keySize] ^ t;
  29540. }
  29541. var invKeySchedule = [];
  29542. for (var ik = 0; ik < ksRows; ik++) {
  29543. var ksR = ksRows - ik;
  29544. var tt = keySchedule[ksR - (ik % 4 ? 0 : 4)];
  29545. if (ik < 4 || ksR <= 4) {
  29546. invKeySchedule[ik] = tt;
  29547. } else {
  29548. 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]];
  29549. }
  29550. }
  29551. this._nRounds = nRounds;
  29552. this._keySchedule = keySchedule;
  29553. this._invKeySchedule = invKeySchedule;
  29554. };
  29555. AES.prototype.encryptBlockRaw = function (M) {
  29556. M = asUInt32Array(M);
  29557. return cryptBlock(M, this._keySchedule, G.SUB_MIX, G.SBOX, this._nRounds);
  29558. };
  29559. AES.prototype.encryptBlock = function (M) {
  29560. var out = this.encryptBlockRaw(M);
  29561. var buf = Buffer.allocUnsafe(16);
  29562. buf.writeUInt32BE(out[0], 0);
  29563. buf.writeUInt32BE(out[1], 4);
  29564. buf.writeUInt32BE(out[2], 8);
  29565. buf.writeUInt32BE(out[3], 12);
  29566. return buf;
  29567. };
  29568. AES.prototype.decryptBlock = function (M) {
  29569. M = asUInt32Array(M); // swap
  29570. var m1 = M[1];
  29571. M[1] = M[3];
  29572. M[3] = m1;
  29573. var out = cryptBlock(M, this._invKeySchedule, G.INV_SUB_MIX, G.INV_SBOX, this._nRounds);
  29574. var buf = Buffer.allocUnsafe(16);
  29575. buf.writeUInt32BE(out[0], 0);
  29576. buf.writeUInt32BE(out[3], 4);
  29577. buf.writeUInt32BE(out[2], 8);
  29578. buf.writeUInt32BE(out[1], 12);
  29579. return buf;
  29580. };
  29581. AES.prototype.scrub = function () {
  29582. scrubVec(this._keySchedule);
  29583. scrubVec(this._invKeySchedule);
  29584. scrubVec(this._key);
  29585. };
  29586. module.exports.AES = AES;
  29587. },{"safe-buffer":494}],187:[function(require,module,exports){
  29588. "use strict";
  29589. var aes = require('./aes');
  29590. var Buffer = require('safe-buffer').Buffer;
  29591. var Transform = require('cipher-base');
  29592. var inherits = require('inherits');
  29593. var GHASH = require('./ghash');
  29594. var xor = require('buffer-xor');
  29595. var incr32 = require('./incr32');
  29596. function xorTest(a, b) {
  29597. var out = 0;
  29598. if (a.length !== b.length) out++;
  29599. var len = Math.min(a.length, b.length);
  29600. for (var i = 0; i < len; ++i) {
  29601. out += a[i] ^ b[i];
  29602. }
  29603. return out;
  29604. }
  29605. function calcIv(self, iv, ck) {
  29606. if (iv.length === 12) {
  29607. self._finID = Buffer.concat([iv, Buffer.from([0, 0, 0, 1])]);
  29608. return Buffer.concat([iv, Buffer.from([0, 0, 0, 2])]);
  29609. }
  29610. var ghash = new GHASH(ck);
  29611. var len = iv.length;
  29612. var toPad = len % 16;
  29613. ghash.update(iv);
  29614. if (toPad) {
  29615. toPad = 16 - toPad;
  29616. ghash.update(Buffer.alloc(toPad, 0));
  29617. }
  29618. ghash.update(Buffer.alloc(8, 0));
  29619. var ivBits = len * 8;
  29620. var tail = Buffer.alloc(8);
  29621. tail.writeUIntBE(ivBits, 0, 8);
  29622. ghash.update(tail);
  29623. self._finID = ghash.state;
  29624. var out = Buffer.from(self._finID);
  29625. incr32(out);
  29626. return out;
  29627. }
  29628. function StreamCipher(mode, key, iv, decrypt) {
  29629. Transform.call(this);
  29630. var h = Buffer.alloc(4, 0);
  29631. this._cipher = new aes.AES(key);
  29632. var ck = this._cipher.encryptBlock(h);
  29633. this._ghash = new GHASH(ck);
  29634. iv = calcIv(this, iv, ck);
  29635. this._prev = Buffer.from(iv);
  29636. this._cache = Buffer.allocUnsafe(0);
  29637. this._secCache = Buffer.allocUnsafe(0);
  29638. this._decrypt = decrypt;
  29639. this._alen = 0;
  29640. this._len = 0;
  29641. this._mode = mode;
  29642. this._authTag = null;
  29643. this._called = false;
  29644. }
  29645. inherits(StreamCipher, Transform);
  29646. StreamCipher.prototype._update = function (chunk) {
  29647. if (!this._called && this._alen) {
  29648. var rump = 16 - this._alen % 16;
  29649. if (rump < 16) {
  29650. rump = Buffer.alloc(rump, 0);
  29651. this._ghash.update(rump);
  29652. }
  29653. }
  29654. this._called = true;
  29655. var out = this._mode.encrypt(this, chunk);
  29656. if (this._decrypt) {
  29657. this._ghash.update(chunk);
  29658. } else {
  29659. this._ghash.update(out);
  29660. }
  29661. this._len += chunk.length;
  29662. return out;
  29663. };
  29664. StreamCipher.prototype._final = function () {
  29665. if (this._decrypt && !this._authTag) throw new Error('Unsupported state or unable to authenticate data');
  29666. var tag = xor(this._ghash.final(this._alen * 8, this._len * 8), this._cipher.encryptBlock(this._finID));
  29667. if (this._decrypt && xorTest(tag, this._authTag)) throw new Error('Unsupported state or unable to authenticate data');
  29668. this._authTag = tag;
  29669. this._cipher.scrub();
  29670. };
  29671. StreamCipher.prototype.getAuthTag = function getAuthTag() {
  29672. if (this._decrypt || !Buffer.isBuffer(this._authTag)) throw new Error('Attempting to get auth tag in unsupported state');
  29673. return this._authTag;
  29674. };
  29675. StreamCipher.prototype.setAuthTag = function setAuthTag(tag) {
  29676. if (!this._decrypt) throw new Error('Attempting to set auth tag in unsupported state');
  29677. this._authTag = tag;
  29678. };
  29679. StreamCipher.prototype.setAAD = function setAAD(buf) {
  29680. if (this._called) throw new Error('Attempting to set AAD in unsupported state');
  29681. this._ghash.update(buf);
  29682. this._alen += buf.length;
  29683. };
  29684. module.exports = StreamCipher;
  29685. },{"./aes":186,"./ghash":191,"./incr32":192,"buffer-xor":217,"cipher-base":218,"inherits":387,"safe-buffer":494}],188:[function(require,module,exports){
  29686. "use strict";
  29687. var ciphers = require('./encrypter');
  29688. var deciphers = require('./decrypter');
  29689. var modes = require('./modes/list.json');
  29690. function getCiphers() {
  29691. return Object.keys(modes);
  29692. }
  29693. exports.createCipher = exports.Cipher = ciphers.createCipher;
  29694. exports.createCipheriv = exports.Cipheriv = ciphers.createCipheriv;
  29695. exports.createDecipher = exports.Decipher = deciphers.createDecipher;
  29696. exports.createDecipheriv = exports.Decipheriv = deciphers.createDecipheriv;
  29697. exports.listCiphers = exports.getCiphers = getCiphers;
  29698. },{"./decrypter":189,"./encrypter":190,"./modes/list.json":200}],189:[function(require,module,exports){
  29699. "use strict";
  29700. var AuthCipher = require('./authCipher');
  29701. var Buffer = require('safe-buffer').Buffer;
  29702. var MODES = require('./modes');
  29703. var StreamCipher = require('./streamCipher');
  29704. var Transform = require('cipher-base');
  29705. var aes = require('./aes');
  29706. var ebtk = require('evp_bytestokey');
  29707. var inherits = require('inherits');
  29708. function Decipher(mode, key, iv) {
  29709. Transform.call(this);
  29710. this._cache = new Splitter();
  29711. this._last = void 0;
  29712. this._cipher = new aes.AES(key);
  29713. this._prev = Buffer.from(iv);
  29714. this._mode = mode;
  29715. this._autopadding = true;
  29716. }
  29717. inherits(Decipher, Transform);
  29718. Decipher.prototype._update = function (data) {
  29719. this._cache.add(data);
  29720. var chunk;
  29721. var thing;
  29722. var out = [];
  29723. while (chunk = this._cache.get(this._autopadding)) {
  29724. thing = this._mode.decrypt(this, chunk);
  29725. out.push(thing);
  29726. }
  29727. return Buffer.concat(out);
  29728. };
  29729. Decipher.prototype._final = function () {
  29730. var chunk = this._cache.flush();
  29731. if (this._autopadding) {
  29732. return unpad(this._mode.decrypt(this, chunk));
  29733. } else if (chunk) {
  29734. throw new Error('data not multiple of block length');
  29735. }
  29736. };
  29737. Decipher.prototype.setAutoPadding = function (setTo) {
  29738. this._autopadding = !!setTo;
  29739. return this;
  29740. };
  29741. function Splitter() {
  29742. this.cache = Buffer.allocUnsafe(0);
  29743. }
  29744. Splitter.prototype.add = function (data) {
  29745. this.cache = Buffer.concat([this.cache, data]);
  29746. };
  29747. Splitter.prototype.get = function (autoPadding) {
  29748. var out;
  29749. if (autoPadding) {
  29750. if (this.cache.length > 16) {
  29751. out = this.cache.slice(0, 16);
  29752. this.cache = this.cache.slice(16);
  29753. return out;
  29754. }
  29755. } else {
  29756. if (this.cache.length >= 16) {
  29757. out = this.cache.slice(0, 16);
  29758. this.cache = this.cache.slice(16);
  29759. return out;
  29760. }
  29761. }
  29762. return null;
  29763. };
  29764. Splitter.prototype.flush = function () {
  29765. if (this.cache.length) return this.cache;
  29766. };
  29767. function unpad(last) {
  29768. var padded = last[15];
  29769. if (padded < 1 || padded > 16) {
  29770. throw new Error('unable to decrypt data');
  29771. }
  29772. var i = -1;
  29773. while (++i < padded) {
  29774. if (last[i + (16 - padded)] !== padded) {
  29775. throw new Error('unable to decrypt data');
  29776. }
  29777. }
  29778. if (padded === 16) return;
  29779. return last.slice(0, 16 - padded);
  29780. }
  29781. function createDecipheriv(suite, password, iv) {
  29782. var config = MODES[suite.toLowerCase()];
  29783. if (!config) throw new TypeError('invalid suite type');
  29784. if (typeof iv === 'string') iv = Buffer.from(iv);
  29785. if (config.mode !== 'GCM' && iv.length !== config.iv) throw new TypeError('invalid iv length ' + iv.length);
  29786. if (typeof password === 'string') password = Buffer.from(password);
  29787. if (password.length !== config.key / 8) throw new TypeError('invalid key length ' + password.length);
  29788. if (config.type === 'stream') {
  29789. return new StreamCipher(config.module, password, iv, true);
  29790. } else if (config.type === 'auth') {
  29791. return new AuthCipher(config.module, password, iv, true);
  29792. }
  29793. return new Decipher(config.module, password, iv);
  29794. }
  29795. function createDecipher(suite, password) {
  29796. var config = MODES[suite.toLowerCase()];
  29797. if (!config) throw new TypeError('invalid suite type');
  29798. var keys = ebtk(password, false, config.key, config.iv);
  29799. return createDecipheriv(suite, keys.key, keys.iv);
  29800. }
  29801. exports.createDecipher = createDecipher;
  29802. exports.createDecipheriv = createDecipheriv;
  29803. },{"./aes":186,"./authCipher":187,"./modes":199,"./streamCipher":202,"cipher-base":218,"evp_bytestokey":368,"inherits":387,"safe-buffer":494}],190:[function(require,module,exports){
  29804. "use strict";
  29805. var MODES = require('./modes');
  29806. var AuthCipher = require('./authCipher');
  29807. var Buffer = require('safe-buffer').Buffer;
  29808. var StreamCipher = require('./streamCipher');
  29809. var Transform = require('cipher-base');
  29810. var aes = require('./aes');
  29811. var ebtk = require('evp_bytestokey');
  29812. var inherits = require('inherits');
  29813. function Cipher(mode, key, iv) {
  29814. Transform.call(this);
  29815. this._cache = new Splitter();
  29816. this._cipher = new aes.AES(key);
  29817. this._prev = Buffer.from(iv);
  29818. this._mode = mode;
  29819. this._autopadding = true;
  29820. }
  29821. inherits(Cipher, Transform);
  29822. Cipher.prototype._update = function (data) {
  29823. this._cache.add(data);
  29824. var chunk;
  29825. var thing;
  29826. var out = [];
  29827. while (chunk = this._cache.get()) {
  29828. thing = this._mode.encrypt(this, chunk);
  29829. out.push(thing);
  29830. }
  29831. return Buffer.concat(out);
  29832. };
  29833. var PADDING = Buffer.alloc(16, 0x10);
  29834. Cipher.prototype._final = function () {
  29835. var chunk = this._cache.flush();
  29836. if (this._autopadding) {
  29837. chunk = this._mode.encrypt(this, chunk);
  29838. this._cipher.scrub();
  29839. return chunk;
  29840. }
  29841. if (!chunk.equals(PADDING)) {
  29842. this._cipher.scrub();
  29843. throw new Error('data not multiple of block length');
  29844. }
  29845. };
  29846. Cipher.prototype.setAutoPadding = function (setTo) {
  29847. this._autopadding = !!setTo;
  29848. return this;
  29849. };
  29850. function Splitter() {
  29851. this.cache = Buffer.allocUnsafe(0);
  29852. }
  29853. Splitter.prototype.add = function (data) {
  29854. this.cache = Buffer.concat([this.cache, data]);
  29855. };
  29856. Splitter.prototype.get = function () {
  29857. if (this.cache.length > 15) {
  29858. var out = this.cache.slice(0, 16);
  29859. this.cache = this.cache.slice(16);
  29860. return out;
  29861. }
  29862. return null;
  29863. };
  29864. Splitter.prototype.flush = function () {
  29865. var len = 16 - this.cache.length;
  29866. var padBuff = Buffer.allocUnsafe(len);
  29867. var i = -1;
  29868. while (++i < len) {
  29869. padBuff.writeUInt8(len, i);
  29870. }
  29871. return Buffer.concat([this.cache, padBuff]);
  29872. };
  29873. function createCipheriv(suite, password, iv) {
  29874. var config = MODES[suite.toLowerCase()];
  29875. if (!config) throw new TypeError('invalid suite type');
  29876. if (typeof password === 'string') password = Buffer.from(password);
  29877. if (password.length !== config.key / 8) throw new TypeError('invalid key length ' + password.length);
  29878. if (typeof iv === 'string') iv = Buffer.from(iv);
  29879. if (config.mode !== 'GCM' && iv.length !== config.iv) throw new TypeError('invalid iv length ' + iv.length);
  29880. if (config.type === 'stream') {
  29881. return new StreamCipher(config.module, password, iv);
  29882. } else if (config.type === 'auth') {
  29883. return new AuthCipher(config.module, password, iv);
  29884. }
  29885. return new Cipher(config.module, password, iv);
  29886. }
  29887. function createCipher(suite, password) {
  29888. var config = MODES[suite.toLowerCase()];
  29889. if (!config) throw new TypeError('invalid suite type');
  29890. var keys = ebtk(password, false, config.key, config.iv);
  29891. return createCipheriv(suite, keys.key, keys.iv);
  29892. }
  29893. exports.createCipheriv = createCipheriv;
  29894. exports.createCipher = createCipher;
  29895. },{"./aes":186,"./authCipher":187,"./modes":199,"./streamCipher":202,"cipher-base":218,"evp_bytestokey":368,"inherits":387,"safe-buffer":494}],191:[function(require,module,exports){
  29896. "use strict";
  29897. var Buffer = require('safe-buffer').Buffer;
  29898. var ZEROES = Buffer.alloc(16, 0);
  29899. function toArray(buf) {
  29900. return [buf.readUInt32BE(0), buf.readUInt32BE(4), buf.readUInt32BE(8), buf.readUInt32BE(12)];
  29901. }
  29902. function fromArray(out) {
  29903. var buf = Buffer.allocUnsafe(16);
  29904. buf.writeUInt32BE(out[0] >>> 0, 0);
  29905. buf.writeUInt32BE(out[1] >>> 0, 4);
  29906. buf.writeUInt32BE(out[2] >>> 0, 8);
  29907. buf.writeUInt32BE(out[3] >>> 0, 12);
  29908. return buf;
  29909. }
  29910. function GHASH(key) {
  29911. this.h = key;
  29912. this.state = Buffer.alloc(16, 0);
  29913. this.cache = Buffer.allocUnsafe(0);
  29914. } // from http://bitwiseshiftleft.github.io/sjcl/doc/symbols/src/core_gcm.js.html
  29915. // by Juho Vähä-Herttua
  29916. GHASH.prototype.ghash = function (block) {
  29917. var i = -1;
  29918. while (++i < block.length) {
  29919. this.state[i] ^= block[i];
  29920. }
  29921. this._multiply();
  29922. };
  29923. GHASH.prototype._multiply = function () {
  29924. var Vi = toArray(this.h);
  29925. var Zi = [0, 0, 0, 0];
  29926. var j, xi, lsbVi;
  29927. var i = -1;
  29928. while (++i < 128) {
  29929. xi = (this.state[~~(i / 8)] & 1 << 7 - i % 8) !== 0;
  29930. if (xi) {
  29931. // Z_i+1 = Z_i ^ V_i
  29932. Zi[0] ^= Vi[0];
  29933. Zi[1] ^= Vi[1];
  29934. Zi[2] ^= Vi[2];
  29935. Zi[3] ^= Vi[3];
  29936. } // Store the value of LSB(V_i)
  29937. lsbVi = (Vi[3] & 1) !== 0; // V_i+1 = V_i >> 1
  29938. for (j = 3; j > 0; j--) {
  29939. Vi[j] = Vi[j] >>> 1 | (Vi[j - 1] & 1) << 31;
  29940. }
  29941. Vi[0] = Vi[0] >>> 1; // If LSB(V_i) is 1, V_i+1 = (V_i >> 1) ^ R
  29942. if (lsbVi) {
  29943. Vi[0] = Vi[0] ^ 0xe1 << 24;
  29944. }
  29945. }
  29946. this.state = fromArray(Zi);
  29947. };
  29948. GHASH.prototype.update = function (buf) {
  29949. this.cache = Buffer.concat([this.cache, buf]);
  29950. var chunk;
  29951. while (this.cache.length >= 16) {
  29952. chunk = this.cache.slice(0, 16);
  29953. this.cache = this.cache.slice(16);
  29954. this.ghash(chunk);
  29955. }
  29956. };
  29957. GHASH.prototype.final = function (abl, bl) {
  29958. if (this.cache.length) {
  29959. this.ghash(Buffer.concat([this.cache, ZEROES], 16));
  29960. }
  29961. this.ghash(fromArray([0, abl, 0, bl]));
  29962. return this.state;
  29963. };
  29964. module.exports = GHASH;
  29965. },{"safe-buffer":494}],192:[function(require,module,exports){
  29966. "use strict";
  29967. function incr32(iv) {
  29968. var len = iv.length;
  29969. var item;
  29970. while (len--) {
  29971. item = iv.readUInt8(len);
  29972. if (item === 255) {
  29973. iv.writeUInt8(0, len);
  29974. } else {
  29975. item++;
  29976. iv.writeUInt8(item, len);
  29977. break;
  29978. }
  29979. }
  29980. }
  29981. module.exports = incr32;
  29982. },{}],193:[function(require,module,exports){
  29983. "use strict";
  29984. var xor = require('buffer-xor');
  29985. exports.encrypt = function (self, block) {
  29986. var data = xor(block, self._prev);
  29987. self._prev = self._cipher.encryptBlock(data);
  29988. return self._prev;
  29989. };
  29990. exports.decrypt = function (self, block) {
  29991. var pad = self._prev;
  29992. self._prev = block;
  29993. var out = self._cipher.decryptBlock(block);
  29994. return xor(out, pad);
  29995. };
  29996. },{"buffer-xor":217}],194:[function(require,module,exports){
  29997. "use strict";
  29998. var Buffer = require('safe-buffer').Buffer;
  29999. var xor = require('buffer-xor');
  30000. function encryptStart(self, data, decrypt) {
  30001. var len = data.length;
  30002. var out = xor(data, self._cache);
  30003. self._cache = self._cache.slice(len);
  30004. self._prev = Buffer.concat([self._prev, decrypt ? data : out]);
  30005. return out;
  30006. }
  30007. exports.encrypt = function (self, data, decrypt) {
  30008. var out = Buffer.allocUnsafe(0);
  30009. var len;
  30010. while (data.length) {
  30011. if (self._cache.length === 0) {
  30012. self._cache = self._cipher.encryptBlock(self._prev);
  30013. self._prev = Buffer.allocUnsafe(0);
  30014. }
  30015. if (self._cache.length <= data.length) {
  30016. len = self._cache.length;
  30017. out = Buffer.concat([out, encryptStart(self, data.slice(0, len), decrypt)]);
  30018. data = data.slice(len);
  30019. } else {
  30020. out = Buffer.concat([out, encryptStart(self, data, decrypt)]);
  30021. break;
  30022. }
  30023. }
  30024. return out;
  30025. };
  30026. },{"buffer-xor":217,"safe-buffer":494}],195:[function(require,module,exports){
  30027. "use strict";
  30028. var Buffer = require('safe-buffer').Buffer;
  30029. function encryptByte(self, byteParam, decrypt) {
  30030. var pad;
  30031. var i = -1;
  30032. var len = 8;
  30033. var out = 0;
  30034. var bit, value;
  30035. while (++i < len) {
  30036. pad = self._cipher.encryptBlock(self._prev);
  30037. bit = byteParam & 1 << 7 - i ? 0x80 : 0;
  30038. value = pad[0] ^ bit;
  30039. out += (value & 0x80) >> i % 8;
  30040. self._prev = shiftIn(self._prev, decrypt ? bit : value);
  30041. }
  30042. return out;
  30043. }
  30044. function shiftIn(buffer, value) {
  30045. var len = buffer.length;
  30046. var i = -1;
  30047. var out = Buffer.allocUnsafe(buffer.length);
  30048. buffer = Buffer.concat([buffer, Buffer.from([value])]);
  30049. while (++i < len) {
  30050. out[i] = buffer[i] << 1 | buffer[i + 1] >> 7;
  30051. }
  30052. return out;
  30053. }
  30054. exports.encrypt = function (self, chunk, decrypt) {
  30055. var len = chunk.length;
  30056. var out = Buffer.allocUnsafe(len);
  30057. var i = -1;
  30058. while (++i < len) {
  30059. out[i] = encryptByte(self, chunk[i], decrypt);
  30060. }
  30061. return out;
  30062. };
  30063. },{"safe-buffer":494}],196:[function(require,module,exports){
  30064. "use strict";
  30065. var Buffer = require('safe-buffer').Buffer;
  30066. function encryptByte(self, byteParam, decrypt) {
  30067. var pad = self._cipher.encryptBlock(self._prev);
  30068. var out = pad[0] ^ byteParam;
  30069. self._prev = Buffer.concat([self._prev.slice(1), Buffer.from([decrypt ? byteParam : out])]);
  30070. return out;
  30071. }
  30072. exports.encrypt = function (self, chunk, decrypt) {
  30073. var len = chunk.length;
  30074. var out = Buffer.allocUnsafe(len);
  30075. var i = -1;
  30076. while (++i < len) {
  30077. out[i] = encryptByte(self, chunk[i], decrypt);
  30078. }
  30079. return out;
  30080. };
  30081. },{"safe-buffer":494}],197:[function(require,module,exports){
  30082. "use strict";
  30083. var xor = require('buffer-xor');
  30084. var Buffer = require('safe-buffer').Buffer;
  30085. var incr32 = require('../incr32');
  30086. function getBlock(self) {
  30087. var out = self._cipher.encryptBlockRaw(self._prev);
  30088. incr32(self._prev);
  30089. return out;
  30090. }
  30091. var blockSize = 16;
  30092. exports.encrypt = function (self, chunk) {
  30093. var chunkNum = Math.ceil(chunk.length / blockSize);
  30094. var start = self._cache.length;
  30095. self._cache = Buffer.concat([self._cache, Buffer.allocUnsafe(chunkNum * blockSize)]);
  30096. for (var i = 0; i < chunkNum; i++) {
  30097. var out = getBlock(self);
  30098. var offset = start + i * blockSize;
  30099. self._cache.writeUInt32BE(out[0], offset + 0);
  30100. self._cache.writeUInt32BE(out[1], offset + 4);
  30101. self._cache.writeUInt32BE(out[2], offset + 8);
  30102. self._cache.writeUInt32BE(out[3], offset + 12);
  30103. }
  30104. var pad = self._cache.slice(0, chunk.length);
  30105. self._cache = self._cache.slice(chunk.length);
  30106. return xor(chunk, pad);
  30107. };
  30108. },{"../incr32":192,"buffer-xor":217,"safe-buffer":494}],198:[function(require,module,exports){
  30109. "use strict";
  30110. exports.encrypt = function (self, block) {
  30111. return self._cipher.encryptBlock(block);
  30112. };
  30113. exports.decrypt = function (self, block) {
  30114. return self._cipher.decryptBlock(block);
  30115. };
  30116. },{}],199:[function(require,module,exports){
  30117. "use strict";
  30118. var modeModules = {
  30119. ECB: require('./ecb'),
  30120. CBC: require('./cbc'),
  30121. CFB: require('./cfb'),
  30122. CFB8: require('./cfb8'),
  30123. CFB1: require('./cfb1'),
  30124. OFB: require('./ofb'),
  30125. CTR: require('./ctr'),
  30126. GCM: require('./ctr')
  30127. };
  30128. var modes = require('./list.json');
  30129. for (var key in modes) {
  30130. modes[key].module = modeModules[modes[key].mode];
  30131. }
  30132. module.exports = modes;
  30133. },{"./cbc":193,"./cfb":194,"./cfb1":195,"./cfb8":196,"./ctr":197,"./ecb":198,"./list.json":200,"./ofb":201}],200:[function(require,module,exports){
  30134. module.exports={
  30135. "aes-128-ecb": {
  30136. "cipher": "AES",
  30137. "key": 128,
  30138. "iv": 0,
  30139. "mode": "ECB",
  30140. "type": "block"
  30141. },
  30142. "aes-192-ecb": {
  30143. "cipher": "AES",
  30144. "key": 192,
  30145. "iv": 0,
  30146. "mode": "ECB",
  30147. "type": "block"
  30148. },
  30149. "aes-256-ecb": {
  30150. "cipher": "AES",
  30151. "key": 256,
  30152. "iv": 0,
  30153. "mode": "ECB",
  30154. "type": "block"
  30155. },
  30156. "aes-128-cbc": {
  30157. "cipher": "AES",
  30158. "key": 128,
  30159. "iv": 16,
  30160. "mode": "CBC",
  30161. "type": "block"
  30162. },
  30163. "aes-192-cbc": {
  30164. "cipher": "AES",
  30165. "key": 192,
  30166. "iv": 16,
  30167. "mode": "CBC",
  30168. "type": "block"
  30169. },
  30170. "aes-256-cbc": {
  30171. "cipher": "AES",
  30172. "key": 256,
  30173. "iv": 16,
  30174. "mode": "CBC",
  30175. "type": "block"
  30176. },
  30177. "aes128": {
  30178. "cipher": "AES",
  30179. "key": 128,
  30180. "iv": 16,
  30181. "mode": "CBC",
  30182. "type": "block"
  30183. },
  30184. "aes192": {
  30185. "cipher": "AES",
  30186. "key": 192,
  30187. "iv": 16,
  30188. "mode": "CBC",
  30189. "type": "block"
  30190. },
  30191. "aes256": {
  30192. "cipher": "AES",
  30193. "key": 256,
  30194. "iv": 16,
  30195. "mode": "CBC",
  30196. "type": "block"
  30197. },
  30198. "aes-128-cfb": {
  30199. "cipher": "AES",
  30200. "key": 128,
  30201. "iv": 16,
  30202. "mode": "CFB",
  30203. "type": "stream"
  30204. },
  30205. "aes-192-cfb": {
  30206. "cipher": "AES",
  30207. "key": 192,
  30208. "iv": 16,
  30209. "mode": "CFB",
  30210. "type": "stream"
  30211. },
  30212. "aes-256-cfb": {
  30213. "cipher": "AES",
  30214. "key": 256,
  30215. "iv": 16,
  30216. "mode": "CFB",
  30217. "type": "stream"
  30218. },
  30219. "aes-128-cfb8": {
  30220. "cipher": "AES",
  30221. "key": 128,
  30222. "iv": 16,
  30223. "mode": "CFB8",
  30224. "type": "stream"
  30225. },
  30226. "aes-192-cfb8": {
  30227. "cipher": "AES",
  30228. "key": 192,
  30229. "iv": 16,
  30230. "mode": "CFB8",
  30231. "type": "stream"
  30232. },
  30233. "aes-256-cfb8": {
  30234. "cipher": "AES",
  30235. "key": 256,
  30236. "iv": 16,
  30237. "mode": "CFB8",
  30238. "type": "stream"
  30239. },
  30240. "aes-128-cfb1": {
  30241. "cipher": "AES",
  30242. "key": 128,
  30243. "iv": 16,
  30244. "mode": "CFB1",
  30245. "type": "stream"
  30246. },
  30247. "aes-192-cfb1": {
  30248. "cipher": "AES",
  30249. "key": 192,
  30250. "iv": 16,
  30251. "mode": "CFB1",
  30252. "type": "stream"
  30253. },
  30254. "aes-256-cfb1": {
  30255. "cipher": "AES",
  30256. "key": 256,
  30257. "iv": 16,
  30258. "mode": "CFB1",
  30259. "type": "stream"
  30260. },
  30261. "aes-128-ofb": {
  30262. "cipher": "AES",
  30263. "key": 128,
  30264. "iv": 16,
  30265. "mode": "OFB",
  30266. "type": "stream"
  30267. },
  30268. "aes-192-ofb": {
  30269. "cipher": "AES",
  30270. "key": 192,
  30271. "iv": 16,
  30272. "mode": "OFB",
  30273. "type": "stream"
  30274. },
  30275. "aes-256-ofb": {
  30276. "cipher": "AES",
  30277. "key": 256,
  30278. "iv": 16,
  30279. "mode": "OFB",
  30280. "type": "stream"
  30281. },
  30282. "aes-128-ctr": {
  30283. "cipher": "AES",
  30284. "key": 128,
  30285. "iv": 16,
  30286. "mode": "CTR",
  30287. "type": "stream"
  30288. },
  30289. "aes-192-ctr": {
  30290. "cipher": "AES",
  30291. "key": 192,
  30292. "iv": 16,
  30293. "mode": "CTR",
  30294. "type": "stream"
  30295. },
  30296. "aes-256-ctr": {
  30297. "cipher": "AES",
  30298. "key": 256,
  30299. "iv": 16,
  30300. "mode": "CTR",
  30301. "type": "stream"
  30302. },
  30303. "aes-128-gcm": {
  30304. "cipher": "AES",
  30305. "key": 128,
  30306. "iv": 12,
  30307. "mode": "GCM",
  30308. "type": "auth"
  30309. },
  30310. "aes-192-gcm": {
  30311. "cipher": "AES",
  30312. "key": 192,
  30313. "iv": 12,
  30314. "mode": "GCM",
  30315. "type": "auth"
  30316. },
  30317. "aes-256-gcm": {
  30318. "cipher": "AES",
  30319. "key": 256,
  30320. "iv": 12,
  30321. "mode": "GCM",
  30322. "type": "auth"
  30323. }
  30324. }
  30325. },{}],201:[function(require,module,exports){
  30326. (function (Buffer){
  30327. "use strict";
  30328. var xor = require('buffer-xor');
  30329. function getBlock(self) {
  30330. self._prev = self._cipher.encryptBlock(self._prev);
  30331. return self._prev;
  30332. }
  30333. exports.encrypt = function (self, chunk) {
  30334. while (self._cache.length < chunk.length) {
  30335. self._cache = Buffer.concat([self._cache, getBlock(self)]);
  30336. }
  30337. var pad = self._cache.slice(0, chunk.length);
  30338. self._cache = self._cache.slice(chunk.length);
  30339. return xor(chunk, pad);
  30340. };
  30341. }).call(this,require("buffer").Buffer)
  30342. },{"buffer":216,"buffer-xor":217}],202:[function(require,module,exports){
  30343. "use strict";
  30344. var aes = require('./aes');
  30345. var Buffer = require('safe-buffer').Buffer;
  30346. var Transform = require('cipher-base');
  30347. var inherits = require('inherits');
  30348. function StreamCipher(mode, key, iv, decrypt) {
  30349. Transform.call(this);
  30350. this._cipher = new aes.AES(key);
  30351. this._prev = Buffer.from(iv);
  30352. this._cache = Buffer.allocUnsafe(0);
  30353. this._secCache = Buffer.allocUnsafe(0);
  30354. this._decrypt = decrypt;
  30355. this._mode = mode;
  30356. }
  30357. inherits(StreamCipher, Transform);
  30358. StreamCipher.prototype._update = function (chunk) {
  30359. return this._mode.encrypt(this, chunk, this._decrypt);
  30360. };
  30361. StreamCipher.prototype._final = function () {
  30362. this._cipher.scrub();
  30363. };
  30364. module.exports = StreamCipher;
  30365. },{"./aes":186,"cipher-base":218,"inherits":387,"safe-buffer":494}],203:[function(require,module,exports){
  30366. "use strict";
  30367. var DES = require('browserify-des');
  30368. var aes = require('browserify-aes/browser');
  30369. var aesModes = require('browserify-aes/modes');
  30370. var desModes = require('browserify-des/modes');
  30371. var ebtk = require('evp_bytestokey');
  30372. function createCipher(suite, password) {
  30373. suite = suite.toLowerCase();
  30374. var keyLen, ivLen;
  30375. if (aesModes[suite]) {
  30376. keyLen = aesModes[suite].key;
  30377. ivLen = aesModes[suite].iv;
  30378. } else if (desModes[suite]) {
  30379. keyLen = desModes[suite].key * 8;
  30380. ivLen = desModes[suite].iv;
  30381. } else {
  30382. throw new TypeError('invalid suite type');
  30383. }
  30384. var keys = ebtk(password, false, keyLen, ivLen);
  30385. return createCipheriv(suite, keys.key, keys.iv);
  30386. }
  30387. function createDecipher(suite, password) {
  30388. suite = suite.toLowerCase();
  30389. var keyLen, ivLen;
  30390. if (aesModes[suite]) {
  30391. keyLen = aesModes[suite].key;
  30392. ivLen = aesModes[suite].iv;
  30393. } else if (desModes[suite]) {
  30394. keyLen = desModes[suite].key * 8;
  30395. ivLen = desModes[suite].iv;
  30396. } else {
  30397. throw new TypeError('invalid suite type');
  30398. }
  30399. var keys = ebtk(password, false, keyLen, ivLen);
  30400. return createDecipheriv(suite, keys.key, keys.iv);
  30401. }
  30402. function createCipheriv(suite, key, iv) {
  30403. suite = suite.toLowerCase();
  30404. if (aesModes[suite]) return aes.createCipheriv(suite, key, iv);
  30405. if (desModes[suite]) return new DES({
  30406. key: key,
  30407. iv: iv,
  30408. mode: suite
  30409. });
  30410. throw new TypeError('invalid suite type');
  30411. }
  30412. function createDecipheriv(suite, key, iv) {
  30413. suite = suite.toLowerCase();
  30414. if (aesModes[suite]) return aes.createDecipheriv(suite, key, iv);
  30415. if (desModes[suite]) return new DES({
  30416. key: key,
  30417. iv: iv,
  30418. mode: suite,
  30419. decrypt: true
  30420. });
  30421. throw new TypeError('invalid suite type');
  30422. }
  30423. function getCiphers() {
  30424. return Object.keys(desModes).concat(aes.getCiphers());
  30425. }
  30426. exports.createCipher = exports.Cipher = createCipher;
  30427. exports.createCipheriv = exports.Cipheriv = createCipheriv;
  30428. exports.createDecipher = exports.Decipher = createDecipher;
  30429. exports.createDecipheriv = exports.Decipheriv = createDecipheriv;
  30430. exports.listCiphers = exports.getCiphers = getCiphers;
  30431. },{"browserify-aes/browser":188,"browserify-aes/modes":199,"browserify-des":204,"browserify-des/modes":205,"evp_bytestokey":368}],204:[function(require,module,exports){
  30432. "use strict";
  30433. var CipherBase = require('cipher-base');
  30434. var des = require('des.js');
  30435. var inherits = require('inherits');
  30436. var Buffer = require('safe-buffer').Buffer;
  30437. var modes = {
  30438. 'des-ede3-cbc': des.CBC.instantiate(des.EDE),
  30439. 'des-ede3': des.EDE,
  30440. 'des-ede-cbc': des.CBC.instantiate(des.EDE),
  30441. 'des-ede': des.EDE,
  30442. 'des-cbc': des.CBC.instantiate(des.DES),
  30443. 'des-ecb': des.DES
  30444. };
  30445. modes.des = modes['des-cbc'];
  30446. modes.des3 = modes['des-ede3-cbc'];
  30447. module.exports = DES;
  30448. inherits(DES, CipherBase);
  30449. function DES(opts) {
  30450. CipherBase.call(this);
  30451. var modeName = opts.mode.toLowerCase();
  30452. var mode = modes[modeName];
  30453. var type;
  30454. if (opts.decrypt) {
  30455. type = 'decrypt';
  30456. } else {
  30457. type = 'encrypt';
  30458. }
  30459. var key = opts.key;
  30460. if (!Buffer.isBuffer(key)) {
  30461. key = Buffer.from(key);
  30462. }
  30463. if (modeName === 'des-ede' || modeName === 'des-ede-cbc') {
  30464. key = Buffer.concat([key, key.slice(0, 8)]);
  30465. }
  30466. var iv = opts.iv;
  30467. if (!Buffer.isBuffer(iv)) {
  30468. iv = Buffer.from(iv);
  30469. }
  30470. this._des = mode.create({
  30471. key: key,
  30472. iv: iv,
  30473. type: type
  30474. });
  30475. }
  30476. DES.prototype._update = function (data) {
  30477. return Buffer.from(this._des.update(data));
  30478. };
  30479. DES.prototype._final = function () {
  30480. return Buffer.from(this._des.final());
  30481. };
  30482. },{"cipher-base":218,"des.js":339,"inherits":387,"safe-buffer":494}],205:[function(require,module,exports){
  30483. "use strict";
  30484. exports['des-ecb'] = {
  30485. key: 8,
  30486. iv: 0
  30487. };
  30488. exports['des-cbc'] = exports.des = {
  30489. key: 8,
  30490. iv: 8
  30491. };
  30492. exports['des-ede3-cbc'] = exports.des3 = {
  30493. key: 24,
  30494. iv: 8
  30495. };
  30496. exports['des-ede3'] = {
  30497. key: 24,
  30498. iv: 0
  30499. };
  30500. exports['des-ede-cbc'] = {
  30501. key: 16,
  30502. iv: 8
  30503. };
  30504. exports['des-ede'] = {
  30505. key: 16,
  30506. iv: 0
  30507. };
  30508. },{}],206:[function(require,module,exports){
  30509. (function (Buffer){
  30510. "use strict";
  30511. var bn = require('bn.js');
  30512. var randomBytes = require('randombytes');
  30513. module.exports = crt;
  30514. function blind(priv) {
  30515. var r = getr(priv);
  30516. var blinder = r.toRed(bn.mont(priv.modulus)).redPow(new bn(priv.publicExponent)).fromRed();
  30517. return {
  30518. blinder: blinder,
  30519. unblinder: r.invm(priv.modulus)
  30520. };
  30521. }
  30522. function crt(msg, priv) {
  30523. var blinds = blind(priv);
  30524. var len = priv.modulus.byteLength();
  30525. var mod = bn.mont(priv.modulus);
  30526. var blinded = new bn(msg).mul(blinds.blinder).umod(priv.modulus);
  30527. var c1 = blinded.toRed(bn.mont(priv.prime1));
  30528. var c2 = blinded.toRed(bn.mont(priv.prime2));
  30529. var qinv = priv.coefficient;
  30530. var p = priv.prime1;
  30531. var q = priv.prime2;
  30532. var m1 = c1.redPow(priv.exponent1);
  30533. var m2 = c2.redPow(priv.exponent2);
  30534. m1 = m1.fromRed();
  30535. m2 = m2.fromRed();
  30536. var h = m1.isub(m2).imul(qinv).umod(p);
  30537. h.imul(q);
  30538. m2.iadd(h);
  30539. return new Buffer(m2.imul(blinds.unblinder).umod(priv.modulus).toArray(false, len));
  30540. }
  30541. crt.getr = getr;
  30542. function getr(priv) {
  30543. var len = priv.modulus.byteLength();
  30544. var r = new bn(randomBytes(len));
  30545. while (r.cmp(priv.modulus) >= 0 || !r.umod(priv.prime1) || !r.umod(priv.prime2)) {
  30546. r = new bn(randomBytes(len));
  30547. }
  30548. return r;
  30549. }
  30550. }).call(this,require("buffer").Buffer)
  30551. },{"bn.js":207,"buffer":216,"randombytes":475}],207:[function(require,module,exports){
  30552. arguments[4][181][0].apply(exports,arguments)
  30553. },{"buffer":185,"dup":181}],208:[function(require,module,exports){
  30554. "use strict";
  30555. module.exports = require('./browser/algorithms.json');
  30556. },{"./browser/algorithms.json":209}],209:[function(require,module,exports){
  30557. module.exports={
  30558. "sha224WithRSAEncryption": {
  30559. "sign": "rsa",
  30560. "hash": "sha224",
  30561. "id": "302d300d06096086480165030402040500041c"
  30562. },
  30563. "RSA-SHA224": {
  30564. "sign": "ecdsa/rsa",
  30565. "hash": "sha224",
  30566. "id": "302d300d06096086480165030402040500041c"
  30567. },
  30568. "sha256WithRSAEncryption": {
  30569. "sign": "rsa",
  30570. "hash": "sha256",
  30571. "id": "3031300d060960864801650304020105000420"
  30572. },
  30573. "RSA-SHA256": {
  30574. "sign": "ecdsa/rsa",
  30575. "hash": "sha256",
  30576. "id": "3031300d060960864801650304020105000420"
  30577. },
  30578. "sha384WithRSAEncryption": {
  30579. "sign": "rsa",
  30580. "hash": "sha384",
  30581. "id": "3041300d060960864801650304020205000430"
  30582. },
  30583. "RSA-SHA384": {
  30584. "sign": "ecdsa/rsa",
  30585. "hash": "sha384",
  30586. "id": "3041300d060960864801650304020205000430"
  30587. },
  30588. "sha512WithRSAEncryption": {
  30589. "sign": "rsa",
  30590. "hash": "sha512",
  30591. "id": "3051300d060960864801650304020305000440"
  30592. },
  30593. "RSA-SHA512": {
  30594. "sign": "ecdsa/rsa",
  30595. "hash": "sha512",
  30596. "id": "3051300d060960864801650304020305000440"
  30597. },
  30598. "RSA-SHA1": {
  30599. "sign": "rsa",
  30600. "hash": "sha1",
  30601. "id": "3021300906052b0e03021a05000414"
  30602. },
  30603. "ecdsa-with-SHA1": {
  30604. "sign": "ecdsa",
  30605. "hash": "sha1",
  30606. "id": ""
  30607. },
  30608. "sha256": {
  30609. "sign": "ecdsa",
  30610. "hash": "sha256",
  30611. "id": ""
  30612. },
  30613. "sha224": {
  30614. "sign": "ecdsa",
  30615. "hash": "sha224",
  30616. "id": ""
  30617. },
  30618. "sha384": {
  30619. "sign": "ecdsa",
  30620. "hash": "sha384",
  30621. "id": ""
  30622. },
  30623. "sha512": {
  30624. "sign": "ecdsa",
  30625. "hash": "sha512",
  30626. "id": ""
  30627. },
  30628. "DSA-SHA": {
  30629. "sign": "dsa",
  30630. "hash": "sha1",
  30631. "id": ""
  30632. },
  30633. "DSA-SHA1": {
  30634. "sign": "dsa",
  30635. "hash": "sha1",
  30636. "id": ""
  30637. },
  30638. "DSA": {
  30639. "sign": "dsa",
  30640. "hash": "sha1",
  30641. "id": ""
  30642. },
  30643. "DSA-WITH-SHA224": {
  30644. "sign": "dsa",
  30645. "hash": "sha224",
  30646. "id": ""
  30647. },
  30648. "DSA-SHA224": {
  30649. "sign": "dsa",
  30650. "hash": "sha224",
  30651. "id": ""
  30652. },
  30653. "DSA-WITH-SHA256": {
  30654. "sign": "dsa",
  30655. "hash": "sha256",
  30656. "id": ""
  30657. },
  30658. "DSA-SHA256": {
  30659. "sign": "dsa",
  30660. "hash": "sha256",
  30661. "id": ""
  30662. },
  30663. "DSA-WITH-SHA384": {
  30664. "sign": "dsa",
  30665. "hash": "sha384",
  30666. "id": ""
  30667. },
  30668. "DSA-SHA384": {
  30669. "sign": "dsa",
  30670. "hash": "sha384",
  30671. "id": ""
  30672. },
  30673. "DSA-WITH-SHA512": {
  30674. "sign": "dsa",
  30675. "hash": "sha512",
  30676. "id": ""
  30677. },
  30678. "DSA-SHA512": {
  30679. "sign": "dsa",
  30680. "hash": "sha512",
  30681. "id": ""
  30682. },
  30683. "DSA-RIPEMD160": {
  30684. "sign": "dsa",
  30685. "hash": "rmd160",
  30686. "id": ""
  30687. },
  30688. "ripemd160WithRSA": {
  30689. "sign": "rsa",
  30690. "hash": "rmd160",
  30691. "id": "3021300906052b2403020105000414"
  30692. },
  30693. "RSA-RIPEMD160": {
  30694. "sign": "rsa",
  30695. "hash": "rmd160",
  30696. "id": "3021300906052b2403020105000414"
  30697. },
  30698. "md5WithRSAEncryption": {
  30699. "sign": "rsa",
  30700. "hash": "md5",
  30701. "id": "3020300c06082a864886f70d020505000410"
  30702. },
  30703. "RSA-MD5": {
  30704. "sign": "rsa",
  30705. "hash": "md5",
  30706. "id": "3020300c06082a864886f70d020505000410"
  30707. }
  30708. }
  30709. },{}],210:[function(require,module,exports){
  30710. module.exports={
  30711. "1.3.132.0.10": "secp256k1",
  30712. "1.3.132.0.33": "p224",
  30713. "1.2.840.10045.3.1.1": "p192",
  30714. "1.2.840.10045.3.1.7": "p256",
  30715. "1.3.132.0.34": "p384",
  30716. "1.3.132.0.35": "p521"
  30717. }
  30718. },{}],211:[function(require,module,exports){
  30719. "use strict";
  30720. var Buffer = require('safe-buffer').Buffer;
  30721. var createHash = require('create-hash');
  30722. var stream = require('readable-stream');
  30723. var inherits = require('inherits');
  30724. var sign = require('./sign');
  30725. var verify = require('./verify');
  30726. var algorithms = require('./algorithms.json');
  30727. Object.keys(algorithms).forEach(function (key) {
  30728. algorithms[key].id = Buffer.from(algorithms[key].id, 'hex');
  30729. algorithms[key.toLowerCase()] = algorithms[key];
  30730. });
  30731. function Sign(algorithm) {
  30732. stream.Writable.call(this);
  30733. var data = algorithms[algorithm];
  30734. if (!data) throw new Error('Unknown message digest');
  30735. this._hashType = data.hash;
  30736. this._hash = createHash(data.hash);
  30737. this._tag = data.id;
  30738. this._signType = data.sign;
  30739. }
  30740. inherits(Sign, stream.Writable);
  30741. Sign.prototype._write = function _write(data, _, done) {
  30742. this._hash.update(data);
  30743. done();
  30744. };
  30745. Sign.prototype.update = function update(data, enc) {
  30746. if (typeof data === 'string') data = Buffer.from(data, enc);
  30747. this._hash.update(data);
  30748. return this;
  30749. };
  30750. Sign.prototype.sign = function signMethod(key, enc) {
  30751. this.end();
  30752. var hash = this._hash.digest();
  30753. var sig = sign(hash, key, this._hashType, this._signType, this._tag);
  30754. return enc ? sig.toString(enc) : sig;
  30755. };
  30756. function Verify(algorithm) {
  30757. stream.Writable.call(this);
  30758. var data = algorithms[algorithm];
  30759. if (!data) throw new Error('Unknown message digest');
  30760. this._hash = createHash(data.hash);
  30761. this._tag = data.id;
  30762. this._signType = data.sign;
  30763. }
  30764. inherits(Verify, stream.Writable);
  30765. Verify.prototype._write = function _write(data, _, done) {
  30766. this._hash.update(data);
  30767. done();
  30768. };
  30769. Verify.prototype.update = function update(data, enc) {
  30770. if (typeof data === 'string') data = Buffer.from(data, enc);
  30771. this._hash.update(data);
  30772. return this;
  30773. };
  30774. Verify.prototype.verify = function verifyMethod(key, sig, enc) {
  30775. if (typeof sig === 'string') sig = Buffer.from(sig, enc);
  30776. this.end();
  30777. var hash = this._hash.digest();
  30778. return verify(sig, hash, key, this._signType, this._tag);
  30779. };
  30780. function createSign(algorithm) {
  30781. return new Sign(algorithm);
  30782. }
  30783. function createVerify(algorithm) {
  30784. return new Verify(algorithm);
  30785. }
  30786. module.exports = {
  30787. Sign: createSign,
  30788. Verify: createVerify,
  30789. createSign: createSign,
  30790. createVerify: createVerify
  30791. };
  30792. },{"./algorithms.json":209,"./sign":212,"./verify":213,"create-hash":331,"inherits":387,"readable-stream":491,"safe-buffer":214}],212:[function(require,module,exports){
  30793. "use strict";
  30794. // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js
  30795. var Buffer = require('safe-buffer').Buffer;
  30796. var createHmac = require('create-hmac');
  30797. var crt = require('browserify-rsa');
  30798. var EC = require('elliptic').ec;
  30799. var BN = require('bn.js');
  30800. var parseKeys = require('parse-asn1');
  30801. var curves = require('./curves.json');
  30802. function sign(hash, key, hashType, signType, tag) {
  30803. var priv = parseKeys(key);
  30804. if (priv.curve) {
  30805. // rsa keys can be interpreted as ecdsa ones in openssl
  30806. if (signType !== 'ecdsa' && signType !== 'ecdsa/rsa') throw new Error('wrong private key type');
  30807. return ecSign(hash, priv);
  30808. } else if (priv.type === 'dsa') {
  30809. if (signType !== 'dsa') throw new Error('wrong private key type');
  30810. return dsaSign(hash, priv, hashType);
  30811. } else {
  30812. if (signType !== 'rsa' && signType !== 'ecdsa/rsa') throw new Error('wrong private key type');
  30813. }
  30814. hash = Buffer.concat([tag, hash]);
  30815. var len = priv.modulus.byteLength();
  30816. var pad = [0, 1];
  30817. while (hash.length + pad.length + 1 < len) {
  30818. pad.push(0xff);
  30819. }
  30820. pad.push(0x00);
  30821. var i = -1;
  30822. while (++i < hash.length) {
  30823. pad.push(hash[i]);
  30824. }
  30825. var out = crt(pad, priv);
  30826. return out;
  30827. }
  30828. function ecSign(hash, priv) {
  30829. var curveId = curves[priv.curve.join('.')];
  30830. if (!curveId) throw new Error('unknown curve ' + priv.curve.join('.'));
  30831. var curve = new EC(curveId);
  30832. var key = curve.keyFromPrivate(priv.privateKey);
  30833. var out = key.sign(hash);
  30834. return Buffer.from(out.toDER());
  30835. }
  30836. function dsaSign(hash, priv, algo) {
  30837. var x = priv.params.priv_key;
  30838. var p = priv.params.p;
  30839. var q = priv.params.q;
  30840. var g = priv.params.g;
  30841. var r = new BN(0);
  30842. var k;
  30843. var H = bits2int(hash, q).mod(q);
  30844. var s = false;
  30845. var kv = getKey(x, q, hash, algo);
  30846. while (s === false) {
  30847. k = makeKey(q, kv, algo);
  30848. r = makeR(g, k, p, q);
  30849. s = k.invm(q).imul(H.add(x.mul(r))).mod(q);
  30850. if (s.cmpn(0) === 0) {
  30851. s = false;
  30852. r = new BN(0);
  30853. }
  30854. }
  30855. return toDER(r, s);
  30856. }
  30857. function toDER(r, s) {
  30858. r = r.toArray();
  30859. s = s.toArray(); // Pad values
  30860. if (r[0] & 0x80) r = [0].concat(r);
  30861. if (s[0] & 0x80) s = [0].concat(s);
  30862. var total = r.length + s.length + 4;
  30863. var res = [0x30, total, 0x02, r.length];
  30864. res = res.concat(r, [0x02, s.length], s);
  30865. return Buffer.from(res);
  30866. }
  30867. function getKey(x, q, hash, algo) {
  30868. x = Buffer.from(x.toArray());
  30869. if (x.length < q.byteLength()) {
  30870. var zeros = Buffer.alloc(q.byteLength() - x.length);
  30871. x = Buffer.concat([zeros, x]);
  30872. }
  30873. var hlen = hash.length;
  30874. var hbits = bits2octets(hash, q);
  30875. var v = Buffer.alloc(hlen);
  30876. v.fill(1);
  30877. var k = Buffer.alloc(hlen);
  30878. k = createHmac(algo, k).update(v).update(Buffer.from([0])).update(x).update(hbits).digest();
  30879. v = createHmac(algo, k).update(v).digest();
  30880. k = createHmac(algo, k).update(v).update(Buffer.from([1])).update(x).update(hbits).digest();
  30881. v = createHmac(algo, k).update(v).digest();
  30882. return {
  30883. k: k,
  30884. v: v
  30885. };
  30886. }
  30887. function bits2int(obits, q) {
  30888. var bits = new BN(obits);
  30889. var shift = (obits.length << 3) - q.bitLength();
  30890. if (shift > 0) bits.ishrn(shift);
  30891. return bits;
  30892. }
  30893. function bits2octets(bits, q) {
  30894. bits = bits2int(bits, q);
  30895. bits = bits.mod(q);
  30896. var out = Buffer.from(bits.toArray());
  30897. if (out.length < q.byteLength()) {
  30898. var zeros = Buffer.alloc(q.byteLength() - out.length);
  30899. out = Buffer.concat([zeros, out]);
  30900. }
  30901. return out;
  30902. }
  30903. function makeKey(q, kv, algo) {
  30904. var t;
  30905. var k;
  30906. do {
  30907. t = Buffer.alloc(0);
  30908. while (t.length * 8 < q.bitLength()) {
  30909. kv.v = createHmac(algo, kv.k).update(kv.v).digest();
  30910. t = Buffer.concat([t, kv.v]);
  30911. }
  30912. k = bits2int(t, q);
  30913. kv.k = createHmac(algo, kv.k).update(kv.v).update(Buffer.from([0])).digest();
  30914. kv.v = createHmac(algo, kv.k).update(kv.v).digest();
  30915. } while (k.cmp(q) !== -1);
  30916. return k;
  30917. }
  30918. function makeR(g, k, p, q) {
  30919. return g.toRed(BN.mont(p)).redPow(k).fromRed().mod(q);
  30920. }
  30921. module.exports = sign;
  30922. module.exports.getKey = getKey;
  30923. module.exports.makeKey = makeKey;
  30924. },{"./curves.json":210,"bn.js":183,"browserify-rsa":206,"create-hmac":333,"elliptic":350,"parse-asn1":459,"safe-buffer":214}],213:[function(require,module,exports){
  30925. "use strict";
  30926. // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js
  30927. var Buffer = require('safe-buffer').Buffer;
  30928. var BN = require('bn.js');
  30929. var EC = require('elliptic').ec;
  30930. var parseKeys = require('parse-asn1');
  30931. var curves = require('./curves.json');
  30932. function verify(sig, hash, key, signType, tag) {
  30933. var pub = parseKeys(key);
  30934. if (pub.type === 'ec') {
  30935. // rsa keys can be interpreted as ecdsa ones in openssl
  30936. if (signType !== 'ecdsa' && signType !== 'ecdsa/rsa') throw new Error('wrong public key type');
  30937. return ecVerify(sig, hash, pub);
  30938. } else if (pub.type === 'dsa') {
  30939. if (signType !== 'dsa') throw new Error('wrong public key type');
  30940. return dsaVerify(sig, hash, pub);
  30941. } else {
  30942. if (signType !== 'rsa' && signType !== 'ecdsa/rsa') throw new Error('wrong public key type');
  30943. }
  30944. hash = Buffer.concat([tag, hash]);
  30945. var len = pub.modulus.byteLength();
  30946. var pad = [1];
  30947. var padNum = 0;
  30948. while (hash.length + pad.length + 2 < len) {
  30949. pad.push(0xff);
  30950. padNum++;
  30951. }
  30952. pad.push(0x00);
  30953. var i = -1;
  30954. while (++i < hash.length) {
  30955. pad.push(hash[i]);
  30956. }
  30957. pad = Buffer.from(pad);
  30958. var red = BN.mont(pub.modulus);
  30959. sig = new BN(sig).toRed(red);
  30960. sig = sig.redPow(new BN(pub.publicExponent));
  30961. sig = Buffer.from(sig.fromRed().toArray());
  30962. var out = padNum < 8 ? 1 : 0;
  30963. len = Math.min(sig.length, pad.length);
  30964. if (sig.length !== pad.length) out = 1;
  30965. i = -1;
  30966. while (++i < len) {
  30967. out |= sig[i] ^ pad[i];
  30968. }
  30969. return out === 0;
  30970. }
  30971. function ecVerify(sig, hash, pub) {
  30972. var curveId = curves[pub.data.algorithm.curve.join('.')];
  30973. if (!curveId) throw new Error('unknown curve ' + pub.data.algorithm.curve.join('.'));
  30974. var curve = new EC(curveId);
  30975. var pubkey = pub.data.subjectPrivateKey.data;
  30976. return curve.verify(hash, sig, pubkey);
  30977. }
  30978. function dsaVerify(sig, hash, pub) {
  30979. var p = pub.data.p;
  30980. var q = pub.data.q;
  30981. var g = pub.data.g;
  30982. var y = pub.data.pub_key;
  30983. var unpacked = parseKeys.signature.decode(sig, 'der');
  30984. var s = unpacked.s;
  30985. var r = unpacked.r;
  30986. checkValue(s, q);
  30987. checkValue(r, q);
  30988. var montp = BN.mont(p);
  30989. var w = s.invm(q);
  30990. 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);
  30991. return v.cmp(r) === 0;
  30992. }
  30993. function checkValue(b, q) {
  30994. if (b.cmpn(0) <= 0) throw new Error('invalid sig');
  30995. if (b.cmp(q) >= q) throw new Error('invalid sig');
  30996. }
  30997. module.exports = verify;
  30998. },{"./curves.json":210,"bn.js":183,"elliptic":350,"parse-asn1":459,"safe-buffer":214}],214:[function(require,module,exports){
  30999. "use strict";
  31000. /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
  31001. /* eslint-disable node/no-deprecated-api */
  31002. var buffer = require('buffer');
  31003. var Buffer = buffer.Buffer; // alternative to using Object.keys for old browsers
  31004. function copyProps(src, dst) {
  31005. for (var key in src) {
  31006. dst[key] = src[key];
  31007. }
  31008. }
  31009. if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
  31010. module.exports = buffer;
  31011. } else {
  31012. // Copy properties from require('buffer')
  31013. copyProps(buffer, exports);
  31014. exports.Buffer = SafeBuffer;
  31015. }
  31016. function SafeBuffer(arg, encodingOrOffset, length) {
  31017. return Buffer(arg, encodingOrOffset, length);
  31018. }
  31019. SafeBuffer.prototype = Object.create(Buffer.prototype); // Copy static methods from Buffer
  31020. copyProps(Buffer, SafeBuffer);
  31021. SafeBuffer.from = function (arg, encodingOrOffset, length) {
  31022. if (typeof arg === 'number') {
  31023. throw new TypeError('Argument must not be a number');
  31024. }
  31025. return Buffer(arg, encodingOrOffset, length);
  31026. };
  31027. SafeBuffer.alloc = function (size, fill, encoding) {
  31028. if (typeof size !== 'number') {
  31029. throw new TypeError('Argument must be a number');
  31030. }
  31031. var buf = Buffer(size);
  31032. if (fill !== undefined) {
  31033. if (typeof encoding === 'string') {
  31034. buf.fill(fill, encoding);
  31035. } else {
  31036. buf.fill(fill);
  31037. }
  31038. } else {
  31039. buf.fill(0);
  31040. }
  31041. return buf;
  31042. };
  31043. SafeBuffer.allocUnsafe = function (size) {
  31044. if (typeof size !== 'number') {
  31045. throw new TypeError('Argument must be a number');
  31046. }
  31047. return Buffer(size);
  31048. };
  31049. SafeBuffer.allocUnsafeSlow = function (size) {
  31050. if (typeof size !== 'number') {
  31051. throw new TypeError('Argument must be a number');
  31052. }
  31053. return buffer.SlowBuffer(size);
  31054. };
  31055. },{"buffer":216}],215:[function(require,module,exports){
  31056. arguments[4][185][0].apply(exports,arguments)
  31057. },{"dup":185}],216:[function(require,module,exports){
  31058. (function (Buffer){
  31059. /*!
  31060. * The buffer module from node.js, for the browser.
  31061. *
  31062. * @author Feross Aboukhadijeh <https://feross.org>
  31063. * @license MIT
  31064. */
  31065. /* eslint-disable no-proto */
  31066. 'use strict';
  31067. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  31068. var base64 = require('base64-js');
  31069. var ieee754 = require('ieee754');
  31070. exports.Buffer = Buffer;
  31071. exports.SlowBuffer = SlowBuffer;
  31072. exports.INSPECT_MAX_BYTES = 50;
  31073. var K_MAX_LENGTH = 0x7fffffff;
  31074. exports.kMaxLength = K_MAX_LENGTH;
  31075. /**
  31076. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  31077. * === true Use Uint8Array implementation (fastest)
  31078. * === false Print warning and recommend using `buffer` v4.x which has an Object
  31079. * implementation (most compatible, even IE6)
  31080. *
  31081. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  31082. * Opera 11.6+, iOS 4.2+.
  31083. *
  31084. * We report that the browser does not support typed arrays if the are not subclassable
  31085. * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
  31086. * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
  31087. * for __proto__ and has a buggy typed array implementation.
  31088. */
  31089. Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
  31090. if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && typeof console.error === 'function') {
  31091. 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.');
  31092. }
  31093. function typedArraySupport() {
  31094. // Can typed array instances can be augmented?
  31095. try {
  31096. var arr = new Uint8Array(1);
  31097. arr.__proto__ = {
  31098. __proto__: Uint8Array.prototype,
  31099. foo: function foo() {
  31100. return 42;
  31101. }
  31102. };
  31103. return arr.foo() === 42;
  31104. } catch (e) {
  31105. return false;
  31106. }
  31107. }
  31108. Object.defineProperty(Buffer.prototype, 'parent', {
  31109. enumerable: true,
  31110. get: function get() {
  31111. if (!Buffer.isBuffer(this)) return undefined;
  31112. return this.buffer;
  31113. }
  31114. });
  31115. Object.defineProperty(Buffer.prototype, 'offset', {
  31116. enumerable: true,
  31117. get: function get() {
  31118. if (!Buffer.isBuffer(this)) return undefined;
  31119. return this.byteOffset;
  31120. }
  31121. });
  31122. function createBuffer(length) {
  31123. if (length > K_MAX_LENGTH) {
  31124. throw new RangeError('The value "' + length + '" is invalid for option "size"');
  31125. } // Return an augmented `Uint8Array` instance
  31126. var buf = new Uint8Array(length);
  31127. buf.__proto__ = Buffer.prototype;
  31128. return buf;
  31129. }
  31130. /**
  31131. * The Buffer constructor returns instances of `Uint8Array` that have their
  31132. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  31133. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  31134. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  31135. * returns a single octet.
  31136. *
  31137. * The `Uint8Array` prototype remains unmodified.
  31138. */
  31139. function Buffer(arg, encodingOrOffset, length) {
  31140. // Common case.
  31141. if (typeof arg === 'number') {
  31142. if (typeof encodingOrOffset === 'string') {
  31143. throw new TypeError('The "string" argument must be of type string. Received type number');
  31144. }
  31145. return allocUnsafe(arg);
  31146. }
  31147. return from(arg, encodingOrOffset, length);
  31148. } // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  31149. if (typeof Symbol !== 'undefined' && Symbol.species != null && Buffer[Symbol.species] === Buffer) {
  31150. Object.defineProperty(Buffer, Symbol.species, {
  31151. value: null,
  31152. configurable: true,
  31153. enumerable: false,
  31154. writable: false
  31155. });
  31156. }
  31157. Buffer.poolSize = 8192; // not used by this implementation
  31158. function from(value, encodingOrOffset, length) {
  31159. if (typeof value === 'string') {
  31160. return fromString(value, encodingOrOffset);
  31161. }
  31162. if (ArrayBuffer.isView(value)) {
  31163. return fromArrayLike(value);
  31164. }
  31165. if (value == null) {
  31166. throw TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + 'or Array-like Object. Received type ' + _typeof(value));
  31167. }
  31168. if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) {
  31169. return fromArrayBuffer(value, encodingOrOffset, length);
  31170. }
  31171. if (typeof value === 'number') {
  31172. throw new TypeError('The "value" argument must not be of type number. Received type number');
  31173. }
  31174. var valueOf = value.valueOf && value.valueOf();
  31175. if (valueOf != null && valueOf !== value) {
  31176. return Buffer.from(valueOf, encodingOrOffset, length);
  31177. }
  31178. var b = fromObject(value);
  31179. if (b) return b;
  31180. if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === 'function') {
  31181. return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length);
  31182. }
  31183. throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + 'or Array-like Object. Received type ' + _typeof(value));
  31184. }
  31185. /**
  31186. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  31187. * if value is a number.
  31188. * Buffer.from(str[, encoding])
  31189. * Buffer.from(array)
  31190. * Buffer.from(buffer)
  31191. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  31192. **/
  31193. Buffer.from = function (value, encodingOrOffset, length) {
  31194. return from(value, encodingOrOffset, length);
  31195. }; // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
  31196. // https://github.com/feross/buffer/pull/148
  31197. Buffer.prototype.__proto__ = Uint8Array.prototype;
  31198. Buffer.__proto__ = Uint8Array;
  31199. function assertSize(size) {
  31200. if (typeof size !== 'number') {
  31201. throw new TypeError('"size" argument must be of type number');
  31202. } else if (size < 0) {
  31203. throw new RangeError('The value "' + size + '" is invalid for option "size"');
  31204. }
  31205. }
  31206. function alloc(size, fill, encoding) {
  31207. assertSize(size);
  31208. if (size <= 0) {
  31209. return createBuffer(size);
  31210. }
  31211. if (fill !== undefined) {
  31212. // Only pay attention to encoding if it's a string. This
  31213. // prevents accidentally sending in a number that would
  31214. // be interpretted as a start offset.
  31215. return typeof encoding === 'string' ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill);
  31216. }
  31217. return createBuffer(size);
  31218. }
  31219. /**
  31220. * Creates a new filled Buffer instance.
  31221. * alloc(size[, fill[, encoding]])
  31222. **/
  31223. Buffer.alloc = function (size, fill, encoding) {
  31224. return alloc(size, fill, encoding);
  31225. };
  31226. function allocUnsafe(size) {
  31227. assertSize(size);
  31228. return createBuffer(size < 0 ? 0 : checked(size) | 0);
  31229. }
  31230. /**
  31231. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  31232. * */
  31233. Buffer.allocUnsafe = function (size) {
  31234. return allocUnsafe(size);
  31235. };
  31236. /**
  31237. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  31238. */
  31239. Buffer.allocUnsafeSlow = function (size) {
  31240. return allocUnsafe(size);
  31241. };
  31242. function fromString(string, encoding) {
  31243. if (typeof encoding !== 'string' || encoding === '') {
  31244. encoding = 'utf8';
  31245. }
  31246. if (!Buffer.isEncoding(encoding)) {
  31247. throw new TypeError('Unknown encoding: ' + encoding);
  31248. }
  31249. var length = byteLength(string, encoding) | 0;
  31250. var buf = createBuffer(length);
  31251. var actual = buf.write(string, encoding);
  31252. if (actual !== length) {
  31253. // Writing a hex string, for example, that contains invalid characters will
  31254. // cause everything after the first invalid character to be ignored. (e.g.
  31255. // 'abxxcd' will be treated as 'ab')
  31256. buf = buf.slice(0, actual);
  31257. }
  31258. return buf;
  31259. }
  31260. function fromArrayLike(array) {
  31261. var length = array.length < 0 ? 0 : checked(array.length) | 0;
  31262. var buf = createBuffer(length);
  31263. for (var i = 0; i < length; i += 1) {
  31264. buf[i] = array[i] & 255;
  31265. }
  31266. return buf;
  31267. }
  31268. function fromArrayBuffer(array, byteOffset, length) {
  31269. if (byteOffset < 0 || array.byteLength < byteOffset) {
  31270. throw new RangeError('"offset" is outside of buffer bounds');
  31271. }
  31272. if (array.byteLength < byteOffset + (length || 0)) {
  31273. throw new RangeError('"length" is outside of buffer bounds');
  31274. }
  31275. var buf;
  31276. if (byteOffset === undefined && length === undefined) {
  31277. buf = new Uint8Array(array);
  31278. } else if (length === undefined) {
  31279. buf = new Uint8Array(array, byteOffset);
  31280. } else {
  31281. buf = new Uint8Array(array, byteOffset, length);
  31282. } // Return an augmented `Uint8Array` instance
  31283. buf.__proto__ = Buffer.prototype;
  31284. return buf;
  31285. }
  31286. function fromObject(obj) {
  31287. if (Buffer.isBuffer(obj)) {
  31288. var len = checked(obj.length) | 0;
  31289. var buf = createBuffer(len);
  31290. if (buf.length === 0) {
  31291. return buf;
  31292. }
  31293. obj.copy(buf, 0, 0, len);
  31294. return buf;
  31295. }
  31296. if (obj.length !== undefined) {
  31297. if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
  31298. return createBuffer(0);
  31299. }
  31300. return fromArrayLike(obj);
  31301. }
  31302. if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
  31303. return fromArrayLike(obj.data);
  31304. }
  31305. }
  31306. function checked(length) {
  31307. // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
  31308. // length is NaN (which is otherwise coerced to zero.)
  31309. if (length >= K_MAX_LENGTH) {
  31310. throw new RangeError('Attempt to allocate Buffer larger than maximum ' + 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes');
  31311. }
  31312. return length | 0;
  31313. }
  31314. function SlowBuffer(length) {
  31315. if (+length != length) {
  31316. // eslint-disable-line eqeqeq
  31317. length = 0;
  31318. }
  31319. return Buffer.alloc(+length);
  31320. }
  31321. Buffer.isBuffer = function isBuffer(b) {
  31322. return b != null && b._isBuffer === true && b !== Buffer.prototype; // so Buffer.isBuffer(Buffer.prototype) will be false
  31323. };
  31324. Buffer.compare = function compare(a, b) {
  31325. if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength);
  31326. if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength);
  31327. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  31328. throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');
  31329. }
  31330. if (a === b) return 0;
  31331. var x = a.length;
  31332. var y = b.length;
  31333. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  31334. if (a[i] !== b[i]) {
  31335. x = a[i];
  31336. y = b[i];
  31337. break;
  31338. }
  31339. }
  31340. if (x < y) return -1;
  31341. if (y < x) return 1;
  31342. return 0;
  31343. };
  31344. Buffer.isEncoding = function isEncoding(encoding) {
  31345. switch (String(encoding).toLowerCase()) {
  31346. case 'hex':
  31347. case 'utf8':
  31348. case 'utf-8':
  31349. case 'ascii':
  31350. case 'latin1':
  31351. case 'binary':
  31352. case 'base64':
  31353. case 'ucs2':
  31354. case 'ucs-2':
  31355. case 'utf16le':
  31356. case 'utf-16le':
  31357. return true;
  31358. default:
  31359. return false;
  31360. }
  31361. };
  31362. Buffer.concat = function concat(list, length) {
  31363. if (!Array.isArray(list)) {
  31364. throw new TypeError('"list" argument must be an Array of Buffers');
  31365. }
  31366. if (list.length === 0) {
  31367. return Buffer.alloc(0);
  31368. }
  31369. var i;
  31370. if (length === undefined) {
  31371. length = 0;
  31372. for (i = 0; i < list.length; ++i) {
  31373. length += list[i].length;
  31374. }
  31375. }
  31376. var buffer = Buffer.allocUnsafe(length);
  31377. var pos = 0;
  31378. for (i = 0; i < list.length; ++i) {
  31379. var buf = list[i];
  31380. if (isInstance(buf, Uint8Array)) {
  31381. buf = Buffer.from(buf);
  31382. }
  31383. if (!Buffer.isBuffer(buf)) {
  31384. throw new TypeError('"list" argument must be an Array of Buffers');
  31385. }
  31386. buf.copy(buffer, pos);
  31387. pos += buf.length;
  31388. }
  31389. return buffer;
  31390. };
  31391. function byteLength(string, encoding) {
  31392. if (Buffer.isBuffer(string)) {
  31393. return string.length;
  31394. }
  31395. if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
  31396. return string.byteLength;
  31397. }
  31398. if (typeof string !== 'string') {
  31399. throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' + 'Received type ' + _typeof(string));
  31400. }
  31401. var len = string.length;
  31402. var mustMatch = arguments.length > 2 && arguments[2] === true;
  31403. if (!mustMatch && len === 0) return 0; // Use a for loop to avoid recursion
  31404. var loweredCase = false;
  31405. for (;;) {
  31406. switch (encoding) {
  31407. case 'ascii':
  31408. case 'latin1':
  31409. case 'binary':
  31410. return len;
  31411. case 'utf8':
  31412. case 'utf-8':
  31413. return utf8ToBytes(string).length;
  31414. case 'ucs2':
  31415. case 'ucs-2':
  31416. case 'utf16le':
  31417. case 'utf-16le':
  31418. return len * 2;
  31419. case 'hex':
  31420. return len >>> 1;
  31421. case 'base64':
  31422. return base64ToBytes(string).length;
  31423. default:
  31424. if (loweredCase) {
  31425. return mustMatch ? -1 : utf8ToBytes(string).length; // assume utf8
  31426. }
  31427. encoding = ('' + encoding).toLowerCase();
  31428. loweredCase = true;
  31429. }
  31430. }
  31431. }
  31432. Buffer.byteLength = byteLength;
  31433. function slowToString(encoding, start, end) {
  31434. var loweredCase = false; // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  31435. // property of a typed array.
  31436. // This behaves neither like String nor Uint8Array in that we set start/end
  31437. // to their upper/lower bounds if the value passed is out of range.
  31438. // undefined is handled specially as per ECMA-262 6th Edition,
  31439. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  31440. if (start === undefined || start < 0) {
  31441. start = 0;
  31442. } // Return early if start > this.length. Done here to prevent potential uint32
  31443. // coercion fail below.
  31444. if (start > this.length) {
  31445. return '';
  31446. }
  31447. if (end === undefined || end > this.length) {
  31448. end = this.length;
  31449. }
  31450. if (end <= 0) {
  31451. return '';
  31452. } // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  31453. end >>>= 0;
  31454. start >>>= 0;
  31455. if (end <= start) {
  31456. return '';
  31457. }
  31458. if (!encoding) encoding = 'utf8';
  31459. while (true) {
  31460. switch (encoding) {
  31461. case 'hex':
  31462. return hexSlice(this, start, end);
  31463. case 'utf8':
  31464. case 'utf-8':
  31465. return utf8Slice(this, start, end);
  31466. case 'ascii':
  31467. return asciiSlice(this, start, end);
  31468. case 'latin1':
  31469. case 'binary':
  31470. return latin1Slice(this, start, end);
  31471. case 'base64':
  31472. return base64Slice(this, start, end);
  31473. case 'ucs2':
  31474. case 'ucs-2':
  31475. case 'utf16le':
  31476. case 'utf-16le':
  31477. return utf16leSlice(this, start, end);
  31478. default:
  31479. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding);
  31480. encoding = (encoding + '').toLowerCase();
  31481. loweredCase = true;
  31482. }
  31483. }
  31484. } // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
  31485. // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
  31486. // reliably in a browserify context because there could be multiple different
  31487. // copies of the 'buffer' package in use. This method works even for Buffer
  31488. // instances that were created from another copy of the `buffer` package.
  31489. // See: https://github.com/feross/buffer/issues/154
  31490. Buffer.prototype._isBuffer = true;
  31491. function swap(b, n, m) {
  31492. var i = b[n];
  31493. b[n] = b[m];
  31494. b[m] = i;
  31495. }
  31496. Buffer.prototype.swap16 = function swap16() {
  31497. var len = this.length;
  31498. if (len % 2 !== 0) {
  31499. throw new RangeError('Buffer size must be a multiple of 16-bits');
  31500. }
  31501. for (var i = 0; i < len; i += 2) {
  31502. swap(this, i, i + 1);
  31503. }
  31504. return this;
  31505. };
  31506. Buffer.prototype.swap32 = function swap32() {
  31507. var len = this.length;
  31508. if (len % 4 !== 0) {
  31509. throw new RangeError('Buffer size must be a multiple of 32-bits');
  31510. }
  31511. for (var i = 0; i < len; i += 4) {
  31512. swap(this, i, i + 3);
  31513. swap(this, i + 1, i + 2);
  31514. }
  31515. return this;
  31516. };
  31517. Buffer.prototype.swap64 = function swap64() {
  31518. var len = this.length;
  31519. if (len % 8 !== 0) {
  31520. throw new RangeError('Buffer size must be a multiple of 64-bits');
  31521. }
  31522. for (var i = 0; i < len; i += 8) {
  31523. swap(this, i, i + 7);
  31524. swap(this, i + 1, i + 6);
  31525. swap(this, i + 2, i + 5);
  31526. swap(this, i + 3, i + 4);
  31527. }
  31528. return this;
  31529. };
  31530. Buffer.prototype.toString = function toString() {
  31531. var length = this.length;
  31532. if (length === 0) return '';
  31533. if (arguments.length === 0) return utf8Slice(this, 0, length);
  31534. return slowToString.apply(this, arguments);
  31535. };
  31536. Buffer.prototype.toLocaleString = Buffer.prototype.toString;
  31537. Buffer.prototype.equals = function equals(b) {
  31538. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer');
  31539. if (this === b) return true;
  31540. return Buffer.compare(this, b) === 0;
  31541. };
  31542. Buffer.prototype.inspect = function inspect() {
  31543. var str = '';
  31544. var max = exports.INSPECT_MAX_BYTES;
  31545. str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
  31546. if (this.length > max) str += ' ... ';
  31547. return '<Buffer ' + str + '>';
  31548. };
  31549. Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
  31550. if (isInstance(target, Uint8Array)) {
  31551. target = Buffer.from(target, target.offset, target.byteLength);
  31552. }
  31553. if (!Buffer.isBuffer(target)) {
  31554. throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. ' + 'Received type ' + _typeof(target));
  31555. }
  31556. if (start === undefined) {
  31557. start = 0;
  31558. }
  31559. if (end === undefined) {
  31560. end = target ? target.length : 0;
  31561. }
  31562. if (thisStart === undefined) {
  31563. thisStart = 0;
  31564. }
  31565. if (thisEnd === undefined) {
  31566. thisEnd = this.length;
  31567. }
  31568. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  31569. throw new RangeError('out of range index');
  31570. }
  31571. if (thisStart >= thisEnd && start >= end) {
  31572. return 0;
  31573. }
  31574. if (thisStart >= thisEnd) {
  31575. return -1;
  31576. }
  31577. if (start >= end) {
  31578. return 1;
  31579. }
  31580. start >>>= 0;
  31581. end >>>= 0;
  31582. thisStart >>>= 0;
  31583. thisEnd >>>= 0;
  31584. if (this === target) return 0;
  31585. var x = thisEnd - thisStart;
  31586. var y = end - start;
  31587. var len = Math.min(x, y);
  31588. var thisCopy = this.slice(thisStart, thisEnd);
  31589. var targetCopy = target.slice(start, end);
  31590. for (var i = 0; i < len; ++i) {
  31591. if (thisCopy[i] !== targetCopy[i]) {
  31592. x = thisCopy[i];
  31593. y = targetCopy[i];
  31594. break;
  31595. }
  31596. }
  31597. if (x < y) return -1;
  31598. if (y < x) return 1;
  31599. return 0;
  31600. }; // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  31601. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  31602. //
  31603. // Arguments:
  31604. // - buffer - a Buffer to search
  31605. // - val - a string, Buffer, or number
  31606. // - byteOffset - an index into `buffer`; will be clamped to an int32
  31607. // - encoding - an optional encoding, relevant is val is a string
  31608. // - dir - true for indexOf, false for lastIndexOf
  31609. function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
  31610. // Empty buffer means no match
  31611. if (buffer.length === 0) return -1; // Normalize byteOffset
  31612. if (typeof byteOffset === 'string') {
  31613. encoding = byteOffset;
  31614. byteOffset = 0;
  31615. } else if (byteOffset > 0x7fffffff) {
  31616. byteOffset = 0x7fffffff;
  31617. } else if (byteOffset < -0x80000000) {
  31618. byteOffset = -0x80000000;
  31619. }
  31620. byteOffset = +byteOffset; // Coerce to Number.
  31621. if (numberIsNaN(byteOffset)) {
  31622. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  31623. byteOffset = dir ? 0 : buffer.length - 1;
  31624. } // Normalize byteOffset: negative offsets start from the end of the buffer
  31625. if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
  31626. if (byteOffset >= buffer.length) {
  31627. if (dir) return -1;else byteOffset = buffer.length - 1;
  31628. } else if (byteOffset < 0) {
  31629. if (dir) byteOffset = 0;else return -1;
  31630. } // Normalize val
  31631. if (typeof val === 'string') {
  31632. val = Buffer.from(val, encoding);
  31633. } // Finally, search either indexOf (if dir is true) or lastIndexOf
  31634. if (Buffer.isBuffer(val)) {
  31635. // Special case: looking for empty string/buffer always fails
  31636. if (val.length === 0) {
  31637. return -1;
  31638. }
  31639. return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
  31640. } else if (typeof val === 'number') {
  31641. val = val & 0xFF; // Search for a byte value [0-255]
  31642. if (typeof Uint8Array.prototype.indexOf === 'function') {
  31643. if (dir) {
  31644. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
  31645. } else {
  31646. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
  31647. }
  31648. }
  31649. return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
  31650. }
  31651. throw new TypeError('val must be string, number or Buffer');
  31652. }
  31653. function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
  31654. var indexSize = 1;
  31655. var arrLength = arr.length;
  31656. var valLength = val.length;
  31657. if (encoding !== undefined) {
  31658. encoding = String(encoding).toLowerCase();
  31659. if (encoding === 'ucs2' || encoding === 'ucs-2' || encoding === 'utf16le' || encoding === 'utf-16le') {
  31660. if (arr.length < 2 || val.length < 2) {
  31661. return -1;
  31662. }
  31663. indexSize = 2;
  31664. arrLength /= 2;
  31665. valLength /= 2;
  31666. byteOffset /= 2;
  31667. }
  31668. }
  31669. function read(buf, i) {
  31670. if (indexSize === 1) {
  31671. return buf[i];
  31672. } else {
  31673. return buf.readUInt16BE(i * indexSize);
  31674. }
  31675. }
  31676. var i;
  31677. if (dir) {
  31678. var foundIndex = -1;
  31679. for (i = byteOffset; i < arrLength; i++) {
  31680. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  31681. if (foundIndex === -1) foundIndex = i;
  31682. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;
  31683. } else {
  31684. if (foundIndex !== -1) i -= i - foundIndex;
  31685. foundIndex = -1;
  31686. }
  31687. }
  31688. } else {
  31689. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
  31690. for (i = byteOffset; i >= 0; i--) {
  31691. var found = true;
  31692. for (var j = 0; j < valLength; j++) {
  31693. if (read(arr, i + j) !== read(val, j)) {
  31694. found = false;
  31695. break;
  31696. }
  31697. }
  31698. if (found) return i;
  31699. }
  31700. }
  31701. return -1;
  31702. }
  31703. Buffer.prototype.includes = function includes(val, byteOffset, encoding) {
  31704. return this.indexOf(val, byteOffset, encoding) !== -1;
  31705. };
  31706. Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
  31707. return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
  31708. };
  31709. Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
  31710. return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
  31711. };
  31712. function hexWrite(buf, string, offset, length) {
  31713. offset = Number(offset) || 0;
  31714. var remaining = buf.length - offset;
  31715. if (!length) {
  31716. length = remaining;
  31717. } else {
  31718. length = Number(length);
  31719. if (length > remaining) {
  31720. length = remaining;
  31721. }
  31722. }
  31723. var strLen = string.length;
  31724. if (length > strLen / 2) {
  31725. length = strLen / 2;
  31726. }
  31727. for (var i = 0; i < length; ++i) {
  31728. var parsed = parseInt(string.substr(i * 2, 2), 16);
  31729. if (numberIsNaN(parsed)) return i;
  31730. buf[offset + i] = parsed;
  31731. }
  31732. return i;
  31733. }
  31734. function utf8Write(buf, string, offset, length) {
  31735. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
  31736. }
  31737. function asciiWrite(buf, string, offset, length) {
  31738. return blitBuffer(asciiToBytes(string), buf, offset, length);
  31739. }
  31740. function latin1Write(buf, string, offset, length) {
  31741. return asciiWrite(buf, string, offset, length);
  31742. }
  31743. function base64Write(buf, string, offset, length) {
  31744. return blitBuffer(base64ToBytes(string), buf, offset, length);
  31745. }
  31746. function ucs2Write(buf, string, offset, length) {
  31747. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
  31748. }
  31749. Buffer.prototype.write = function write(string, offset, length, encoding) {
  31750. // Buffer#write(string)
  31751. if (offset === undefined) {
  31752. encoding = 'utf8';
  31753. length = this.length;
  31754. offset = 0; // Buffer#write(string, encoding)
  31755. } else if (length === undefined && typeof offset === 'string') {
  31756. encoding = offset;
  31757. length = this.length;
  31758. offset = 0; // Buffer#write(string, offset[, length][, encoding])
  31759. } else if (isFinite(offset)) {
  31760. offset = offset >>> 0;
  31761. if (isFinite(length)) {
  31762. length = length >>> 0;
  31763. if (encoding === undefined) encoding = 'utf8';
  31764. } else {
  31765. encoding = length;
  31766. length = undefined;
  31767. }
  31768. } else {
  31769. throw new Error('Buffer.write(string, encoding, offset[, length]) is no longer supported');
  31770. }
  31771. var remaining = this.length - offset;
  31772. if (length === undefined || length > remaining) length = remaining;
  31773. if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {
  31774. throw new RangeError('Attempt to write outside buffer bounds');
  31775. }
  31776. if (!encoding) encoding = 'utf8';
  31777. var loweredCase = false;
  31778. for (;;) {
  31779. switch (encoding) {
  31780. case 'hex':
  31781. return hexWrite(this, string, offset, length);
  31782. case 'utf8':
  31783. case 'utf-8':
  31784. return utf8Write(this, string, offset, length);
  31785. case 'ascii':
  31786. return asciiWrite(this, string, offset, length);
  31787. case 'latin1':
  31788. case 'binary':
  31789. return latin1Write(this, string, offset, length);
  31790. case 'base64':
  31791. // Warning: maxLength not taken into account in base64Write
  31792. return base64Write(this, string, offset, length);
  31793. case 'ucs2':
  31794. case 'ucs-2':
  31795. case 'utf16le':
  31796. case 'utf-16le':
  31797. return ucs2Write(this, string, offset, length);
  31798. default:
  31799. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding);
  31800. encoding = ('' + encoding).toLowerCase();
  31801. loweredCase = true;
  31802. }
  31803. }
  31804. };
  31805. Buffer.prototype.toJSON = function toJSON() {
  31806. return {
  31807. type: 'Buffer',
  31808. data: Array.prototype.slice.call(this._arr || this, 0)
  31809. };
  31810. };
  31811. function base64Slice(buf, start, end) {
  31812. if (start === 0 && end === buf.length) {
  31813. return base64.fromByteArray(buf);
  31814. } else {
  31815. return base64.fromByteArray(buf.slice(start, end));
  31816. }
  31817. }
  31818. function utf8Slice(buf, start, end) {
  31819. end = Math.min(buf.length, end);
  31820. var res = [];
  31821. var i = start;
  31822. while (i < end) {
  31823. var firstByte = buf[i];
  31824. var codePoint = null;
  31825. var bytesPerSequence = firstByte > 0xEF ? 4 : firstByte > 0xDF ? 3 : firstByte > 0xBF ? 2 : 1;
  31826. if (i + bytesPerSequence <= end) {
  31827. var secondByte, thirdByte, fourthByte, tempCodePoint;
  31828. switch (bytesPerSequence) {
  31829. case 1:
  31830. if (firstByte < 0x80) {
  31831. codePoint = firstByte;
  31832. }
  31833. break;
  31834. case 2:
  31835. secondByte = buf[i + 1];
  31836. if ((secondByte & 0xC0) === 0x80) {
  31837. tempCodePoint = (firstByte & 0x1F) << 0x6 | secondByte & 0x3F;
  31838. if (tempCodePoint > 0x7F) {
  31839. codePoint = tempCodePoint;
  31840. }
  31841. }
  31842. break;
  31843. case 3:
  31844. secondByte = buf[i + 1];
  31845. thirdByte = buf[i + 2];
  31846. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  31847. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | thirdByte & 0x3F;
  31848. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  31849. codePoint = tempCodePoint;
  31850. }
  31851. }
  31852. break;
  31853. case 4:
  31854. secondByte = buf[i + 1];
  31855. thirdByte = buf[i + 2];
  31856. fourthByte = buf[i + 3];
  31857. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  31858. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | fourthByte & 0x3F;
  31859. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  31860. codePoint = tempCodePoint;
  31861. }
  31862. }
  31863. }
  31864. }
  31865. if (codePoint === null) {
  31866. // we did not generate a valid codePoint so insert a
  31867. // replacement char (U+FFFD) and advance only 1 byte
  31868. codePoint = 0xFFFD;
  31869. bytesPerSequence = 1;
  31870. } else if (codePoint > 0xFFFF) {
  31871. // encode to utf16 (surrogate pair dance)
  31872. codePoint -= 0x10000;
  31873. res.push(codePoint >>> 10 & 0x3FF | 0xD800);
  31874. codePoint = 0xDC00 | codePoint & 0x3FF;
  31875. }
  31876. res.push(codePoint);
  31877. i += bytesPerSequence;
  31878. }
  31879. return decodeCodePointsArray(res);
  31880. } // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  31881. // the lowest limit is Chrome, with 0x10000 args.
  31882. // We go 1 magnitude less, for safety
  31883. var MAX_ARGUMENTS_LENGTH = 0x1000;
  31884. function decodeCodePointsArray(codePoints) {
  31885. var len = codePoints.length;
  31886. if (len <= MAX_ARGUMENTS_LENGTH) {
  31887. return String.fromCharCode.apply(String, codePoints); // avoid extra slice()
  31888. } // Decode in chunks to avoid "call stack size exceeded".
  31889. var res = '';
  31890. var i = 0;
  31891. while (i < len) {
  31892. res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH));
  31893. }
  31894. return res;
  31895. }
  31896. function asciiSlice(buf, start, end) {
  31897. var ret = '';
  31898. end = Math.min(buf.length, end);
  31899. for (var i = start; i < end; ++i) {
  31900. ret += String.fromCharCode(buf[i] & 0x7F);
  31901. }
  31902. return ret;
  31903. }
  31904. function latin1Slice(buf, start, end) {
  31905. var ret = '';
  31906. end = Math.min(buf.length, end);
  31907. for (var i = start; i < end; ++i) {
  31908. ret += String.fromCharCode(buf[i]);
  31909. }
  31910. return ret;
  31911. }
  31912. function hexSlice(buf, start, end) {
  31913. var len = buf.length;
  31914. if (!start || start < 0) start = 0;
  31915. if (!end || end < 0 || end > len) end = len;
  31916. var out = '';
  31917. for (var i = start; i < end; ++i) {
  31918. out += toHex(buf[i]);
  31919. }
  31920. return out;
  31921. }
  31922. function utf16leSlice(buf, start, end) {
  31923. var bytes = buf.slice(start, end);
  31924. var res = '';
  31925. for (var i = 0; i < bytes.length; i += 2) {
  31926. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
  31927. }
  31928. return res;
  31929. }
  31930. Buffer.prototype.slice = function slice(start, end) {
  31931. var len = this.length;
  31932. start = ~~start;
  31933. end = end === undefined ? len : ~~end;
  31934. if (start < 0) {
  31935. start += len;
  31936. if (start < 0) start = 0;
  31937. } else if (start > len) {
  31938. start = len;
  31939. }
  31940. if (end < 0) {
  31941. end += len;
  31942. if (end < 0) end = 0;
  31943. } else if (end > len) {
  31944. end = len;
  31945. }
  31946. if (end < start) end = start;
  31947. var newBuf = this.subarray(start, end); // Return an augmented `Uint8Array` instance
  31948. newBuf.__proto__ = Buffer.prototype;
  31949. return newBuf;
  31950. };
  31951. /*
  31952. * Need to make sure that buffer isn't trying to write out of bounds.
  31953. */
  31954. function checkOffset(offset, ext, length) {
  31955. if (offset % 1 !== 0 || offset < 0) throw new RangeError('offset is not uint');
  31956. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length');
  31957. }
  31958. Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) {
  31959. offset = offset >>> 0;
  31960. byteLength = byteLength >>> 0;
  31961. if (!noAssert) checkOffset(offset, byteLength, this.length);
  31962. var val = this[offset];
  31963. var mul = 1;
  31964. var i = 0;
  31965. while (++i < byteLength && (mul *= 0x100)) {
  31966. val += this[offset + i] * mul;
  31967. }
  31968. return val;
  31969. };
  31970. Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) {
  31971. offset = offset >>> 0;
  31972. byteLength = byteLength >>> 0;
  31973. if (!noAssert) {
  31974. checkOffset(offset, byteLength, this.length);
  31975. }
  31976. var val = this[offset + --byteLength];
  31977. var mul = 1;
  31978. while (byteLength > 0 && (mul *= 0x100)) {
  31979. val += this[offset + --byteLength] * mul;
  31980. }
  31981. return val;
  31982. };
  31983. Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) {
  31984. offset = offset >>> 0;
  31985. if (!noAssert) checkOffset(offset, 1, this.length);
  31986. return this[offset];
  31987. };
  31988. Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
  31989. offset = offset >>> 0;
  31990. if (!noAssert) checkOffset(offset, 2, this.length);
  31991. return this[offset] | this[offset + 1] << 8;
  31992. };
  31993. Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
  31994. offset = offset >>> 0;
  31995. if (!noAssert) checkOffset(offset, 2, this.length);
  31996. return this[offset] << 8 | this[offset + 1];
  31997. };
  31998. Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
  31999. offset = offset >>> 0;
  32000. if (!noAssert) checkOffset(offset, 4, this.length);
  32001. return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 0x1000000;
  32002. };
  32003. Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
  32004. offset = offset >>> 0;
  32005. if (!noAssert) checkOffset(offset, 4, this.length);
  32006. return this[offset] * 0x1000000 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
  32007. };
  32008. Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) {
  32009. offset = offset >>> 0;
  32010. byteLength = byteLength >>> 0;
  32011. if (!noAssert) checkOffset(offset, byteLength, this.length);
  32012. var val = this[offset];
  32013. var mul = 1;
  32014. var i = 0;
  32015. while (++i < byteLength && (mul *= 0x100)) {
  32016. val += this[offset + i] * mul;
  32017. }
  32018. mul *= 0x80;
  32019. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  32020. return val;
  32021. };
  32022. Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) {
  32023. offset = offset >>> 0;
  32024. byteLength = byteLength >>> 0;
  32025. if (!noAssert) checkOffset(offset, byteLength, this.length);
  32026. var i = byteLength;
  32027. var mul = 1;
  32028. var val = this[offset + --i];
  32029. while (i > 0 && (mul *= 0x100)) {
  32030. val += this[offset + --i] * mul;
  32031. }
  32032. mul *= 0x80;
  32033. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  32034. return val;
  32035. };
  32036. Buffer.prototype.readInt8 = function readInt8(offset, noAssert) {
  32037. offset = offset >>> 0;
  32038. if (!noAssert) checkOffset(offset, 1, this.length);
  32039. if (!(this[offset] & 0x80)) return this[offset];
  32040. return (0xff - this[offset] + 1) * -1;
  32041. };
  32042. Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
  32043. offset = offset >>> 0;
  32044. if (!noAssert) checkOffset(offset, 2, this.length);
  32045. var val = this[offset] | this[offset + 1] << 8;
  32046. return val & 0x8000 ? val | 0xFFFF0000 : val;
  32047. };
  32048. Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
  32049. offset = offset >>> 0;
  32050. if (!noAssert) checkOffset(offset, 2, this.length);
  32051. var val = this[offset + 1] | this[offset] << 8;
  32052. return val & 0x8000 ? val | 0xFFFF0000 : val;
  32053. };
  32054. Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
  32055. offset = offset >>> 0;
  32056. if (!noAssert) checkOffset(offset, 4, this.length);
  32057. return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
  32058. };
  32059. Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
  32060. offset = offset >>> 0;
  32061. if (!noAssert) checkOffset(offset, 4, this.length);
  32062. return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
  32063. };
  32064. Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
  32065. offset = offset >>> 0;
  32066. if (!noAssert) checkOffset(offset, 4, this.length);
  32067. return ieee754.read(this, offset, true, 23, 4);
  32068. };
  32069. Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
  32070. offset = offset >>> 0;
  32071. if (!noAssert) checkOffset(offset, 4, this.length);
  32072. return ieee754.read(this, offset, false, 23, 4);
  32073. };
  32074. Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
  32075. offset = offset >>> 0;
  32076. if (!noAssert) checkOffset(offset, 8, this.length);
  32077. return ieee754.read(this, offset, true, 52, 8);
  32078. };
  32079. Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
  32080. offset = offset >>> 0;
  32081. if (!noAssert) checkOffset(offset, 8, this.length);
  32082. return ieee754.read(this, offset, false, 52, 8);
  32083. };
  32084. function checkInt(buf, value, offset, ext, max, min) {
  32085. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance');
  32086. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds');
  32087. if (offset + ext > buf.length) throw new RangeError('Index out of range');
  32088. }
  32089. Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) {
  32090. value = +value;
  32091. offset = offset >>> 0;
  32092. byteLength = byteLength >>> 0;
  32093. if (!noAssert) {
  32094. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  32095. checkInt(this, value, offset, byteLength, maxBytes, 0);
  32096. }
  32097. var mul = 1;
  32098. var i = 0;
  32099. this[offset] = value & 0xFF;
  32100. while (++i < byteLength && (mul *= 0x100)) {
  32101. this[offset + i] = value / mul & 0xFF;
  32102. }
  32103. return offset + byteLength;
  32104. };
  32105. Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) {
  32106. value = +value;
  32107. offset = offset >>> 0;
  32108. byteLength = byteLength >>> 0;
  32109. if (!noAssert) {
  32110. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  32111. checkInt(this, value, offset, byteLength, maxBytes, 0);
  32112. }
  32113. var i = byteLength - 1;
  32114. var mul = 1;
  32115. this[offset + i] = value & 0xFF;
  32116. while (--i >= 0 && (mul *= 0x100)) {
  32117. this[offset + i] = value / mul & 0xFF;
  32118. }
  32119. return offset + byteLength;
  32120. };
  32121. Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
  32122. value = +value;
  32123. offset = offset >>> 0;
  32124. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
  32125. this[offset] = value & 0xff;
  32126. return offset + 1;
  32127. };
  32128. Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
  32129. value = +value;
  32130. offset = offset >>> 0;
  32131. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  32132. this[offset] = value & 0xff;
  32133. this[offset + 1] = value >>> 8;
  32134. return offset + 2;
  32135. };
  32136. Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
  32137. value = +value;
  32138. offset = offset >>> 0;
  32139. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  32140. this[offset] = value >>> 8;
  32141. this[offset + 1] = value & 0xff;
  32142. return offset + 2;
  32143. };
  32144. Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
  32145. value = +value;
  32146. offset = offset >>> 0;
  32147. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  32148. this[offset + 3] = value >>> 24;
  32149. this[offset + 2] = value >>> 16;
  32150. this[offset + 1] = value >>> 8;
  32151. this[offset] = value & 0xff;
  32152. return offset + 4;
  32153. };
  32154. Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
  32155. value = +value;
  32156. offset = offset >>> 0;
  32157. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  32158. this[offset] = value >>> 24;
  32159. this[offset + 1] = value >>> 16;
  32160. this[offset + 2] = value >>> 8;
  32161. this[offset + 3] = value & 0xff;
  32162. return offset + 4;
  32163. };
  32164. Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) {
  32165. value = +value;
  32166. offset = offset >>> 0;
  32167. if (!noAssert) {
  32168. var limit = Math.pow(2, 8 * byteLength - 1);
  32169. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  32170. }
  32171. var i = 0;
  32172. var mul = 1;
  32173. var sub = 0;
  32174. this[offset] = value & 0xFF;
  32175. while (++i < byteLength && (mul *= 0x100)) {
  32176. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  32177. sub = 1;
  32178. }
  32179. this[offset + i] = (value / mul >> 0) - sub & 0xFF;
  32180. }
  32181. return offset + byteLength;
  32182. };
  32183. Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) {
  32184. value = +value;
  32185. offset = offset >>> 0;
  32186. if (!noAssert) {
  32187. var limit = Math.pow(2, 8 * byteLength - 1);
  32188. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  32189. }
  32190. var i = byteLength - 1;
  32191. var mul = 1;
  32192. var sub = 0;
  32193. this[offset + i] = value & 0xFF;
  32194. while (--i >= 0 && (mul *= 0x100)) {
  32195. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  32196. sub = 1;
  32197. }
  32198. this[offset + i] = (value / mul >> 0) - sub & 0xFF;
  32199. }
  32200. return offset + byteLength;
  32201. };
  32202. Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
  32203. value = +value;
  32204. offset = offset >>> 0;
  32205. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
  32206. if (value < 0) value = 0xff + value + 1;
  32207. this[offset] = value & 0xff;
  32208. return offset + 1;
  32209. };
  32210. Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
  32211. value = +value;
  32212. offset = offset >>> 0;
  32213. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  32214. this[offset] = value & 0xff;
  32215. this[offset + 1] = value >>> 8;
  32216. return offset + 2;
  32217. };
  32218. Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
  32219. value = +value;
  32220. offset = offset >>> 0;
  32221. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  32222. this[offset] = value >>> 8;
  32223. this[offset + 1] = value & 0xff;
  32224. return offset + 2;
  32225. };
  32226. Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
  32227. value = +value;
  32228. offset = offset >>> 0;
  32229. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  32230. this[offset] = value & 0xff;
  32231. this[offset + 1] = value >>> 8;
  32232. this[offset + 2] = value >>> 16;
  32233. this[offset + 3] = value >>> 24;
  32234. return offset + 4;
  32235. };
  32236. Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
  32237. value = +value;
  32238. offset = offset >>> 0;
  32239. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  32240. if (value < 0) value = 0xffffffff + value + 1;
  32241. this[offset] = value >>> 24;
  32242. this[offset + 1] = value >>> 16;
  32243. this[offset + 2] = value >>> 8;
  32244. this[offset + 3] = value & 0xff;
  32245. return offset + 4;
  32246. };
  32247. function checkIEEE754(buf, value, offset, ext, max, min) {
  32248. if (offset + ext > buf.length) throw new RangeError('Index out of range');
  32249. if (offset < 0) throw new RangeError('Index out of range');
  32250. }
  32251. function writeFloat(buf, value, offset, littleEndian, noAssert) {
  32252. value = +value;
  32253. offset = offset >>> 0;
  32254. if (!noAssert) {
  32255. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38);
  32256. }
  32257. ieee754.write(buf, value, offset, littleEndian, 23, 4);
  32258. return offset + 4;
  32259. }
  32260. Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
  32261. return writeFloat(this, value, offset, true, noAssert);
  32262. };
  32263. Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
  32264. return writeFloat(this, value, offset, false, noAssert);
  32265. };
  32266. function writeDouble(buf, value, offset, littleEndian, noAssert) {
  32267. value = +value;
  32268. offset = offset >>> 0;
  32269. if (!noAssert) {
  32270. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308);
  32271. }
  32272. ieee754.write(buf, value, offset, littleEndian, 52, 8);
  32273. return offset + 8;
  32274. }
  32275. Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
  32276. return writeDouble(this, value, offset, true, noAssert);
  32277. };
  32278. Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
  32279. return writeDouble(this, value, offset, false, noAssert);
  32280. }; // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  32281. Buffer.prototype.copy = function copy(target, targetStart, start, end) {
  32282. if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer');
  32283. if (!start) start = 0;
  32284. if (!end && end !== 0) end = this.length;
  32285. if (targetStart >= target.length) targetStart = target.length;
  32286. if (!targetStart) targetStart = 0;
  32287. if (end > 0 && end < start) end = start; // Copy 0 bytes; we're done
  32288. if (end === start) return 0;
  32289. if (target.length === 0 || this.length === 0) return 0; // Fatal error conditions
  32290. if (targetStart < 0) {
  32291. throw new RangeError('targetStart out of bounds');
  32292. }
  32293. if (start < 0 || start >= this.length) throw new RangeError('Index out of range');
  32294. if (end < 0) throw new RangeError('sourceEnd out of bounds'); // Are we oob?
  32295. if (end > this.length) end = this.length;
  32296. if (target.length - targetStart < end - start) {
  32297. end = target.length - targetStart + start;
  32298. }
  32299. var len = end - start;
  32300. if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
  32301. // Use built-in when available, missing from IE11
  32302. this.copyWithin(targetStart, start, end);
  32303. } else if (this === target && start < targetStart && targetStart < end) {
  32304. // descending copy from end
  32305. for (var i = len - 1; i >= 0; --i) {
  32306. target[i + targetStart] = this[i + start];
  32307. }
  32308. } else {
  32309. Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart);
  32310. }
  32311. return len;
  32312. }; // Usage:
  32313. // buffer.fill(number[, offset[, end]])
  32314. // buffer.fill(buffer[, offset[, end]])
  32315. // buffer.fill(string[, offset[, end]][, encoding])
  32316. Buffer.prototype.fill = function fill(val, start, end, encoding) {
  32317. // Handle string cases:
  32318. if (typeof val === 'string') {
  32319. if (typeof start === 'string') {
  32320. encoding = start;
  32321. start = 0;
  32322. end = this.length;
  32323. } else if (typeof end === 'string') {
  32324. encoding = end;
  32325. end = this.length;
  32326. }
  32327. if (encoding !== undefined && typeof encoding !== 'string') {
  32328. throw new TypeError('encoding must be a string');
  32329. }
  32330. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  32331. throw new TypeError('Unknown encoding: ' + encoding);
  32332. }
  32333. if (val.length === 1) {
  32334. var code = val.charCodeAt(0);
  32335. if (encoding === 'utf8' && code < 128 || encoding === 'latin1') {
  32336. // Fast path: If `val` fits into a single byte, use that numeric value.
  32337. val = code;
  32338. }
  32339. }
  32340. } else if (typeof val === 'number') {
  32341. val = val & 255;
  32342. } // Invalid ranges are not set to a default, so can range check early.
  32343. if (start < 0 || this.length < start || this.length < end) {
  32344. throw new RangeError('Out of range index');
  32345. }
  32346. if (end <= start) {
  32347. return this;
  32348. }
  32349. start = start >>> 0;
  32350. end = end === undefined ? this.length : end >>> 0;
  32351. if (!val) val = 0;
  32352. var i;
  32353. if (typeof val === 'number') {
  32354. for (i = start; i < end; ++i) {
  32355. this[i] = val;
  32356. }
  32357. } else {
  32358. var bytes = Buffer.isBuffer(val) ? val : Buffer.from(val, encoding);
  32359. var len = bytes.length;
  32360. if (len === 0) {
  32361. throw new TypeError('The value "' + val + '" is invalid for argument "value"');
  32362. }
  32363. for (i = 0; i < end - start; ++i) {
  32364. this[i + start] = bytes[i % len];
  32365. }
  32366. }
  32367. return this;
  32368. }; // HELPER FUNCTIONS
  32369. // ================
  32370. var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
  32371. function base64clean(str) {
  32372. // Node takes equal signs as end of the Base64 encoding
  32373. str = str.split('=')[0]; // Node strips out invalid characters like \n and \t from the string, base64-js does not
  32374. str = str.trim().replace(INVALID_BASE64_RE, ''); // Node converts strings with length < 2 to ''
  32375. if (str.length < 2) return ''; // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  32376. while (str.length % 4 !== 0) {
  32377. str = str + '=';
  32378. }
  32379. return str;
  32380. }
  32381. function toHex(n) {
  32382. if (n < 16) return '0' + n.toString(16);
  32383. return n.toString(16);
  32384. }
  32385. function utf8ToBytes(string, units) {
  32386. units = units || Infinity;
  32387. var codePoint;
  32388. var length = string.length;
  32389. var leadSurrogate = null;
  32390. var bytes = [];
  32391. for (var i = 0; i < length; ++i) {
  32392. codePoint = string.charCodeAt(i); // is surrogate component
  32393. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  32394. // last char was a lead
  32395. if (!leadSurrogate) {
  32396. // no lead yet
  32397. if (codePoint > 0xDBFF) {
  32398. // unexpected trail
  32399. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  32400. continue;
  32401. } else if (i + 1 === length) {
  32402. // unpaired lead
  32403. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  32404. continue;
  32405. } // valid lead
  32406. leadSurrogate = codePoint;
  32407. continue;
  32408. } // 2 leads in a row
  32409. if (codePoint < 0xDC00) {
  32410. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  32411. leadSurrogate = codePoint;
  32412. continue;
  32413. } // valid surrogate pair
  32414. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
  32415. } else if (leadSurrogate) {
  32416. // valid bmp char, but last char was a lead
  32417. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  32418. }
  32419. leadSurrogate = null; // encode utf8
  32420. if (codePoint < 0x80) {
  32421. if ((units -= 1) < 0) break;
  32422. bytes.push(codePoint);
  32423. } else if (codePoint < 0x800) {
  32424. if ((units -= 2) < 0) break;
  32425. bytes.push(codePoint >> 0x6 | 0xC0, codePoint & 0x3F | 0x80);
  32426. } else if (codePoint < 0x10000) {
  32427. if ((units -= 3) < 0) break;
  32428. bytes.push(codePoint >> 0xC | 0xE0, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80);
  32429. } else if (codePoint < 0x110000) {
  32430. if ((units -= 4) < 0) break;
  32431. bytes.push(codePoint >> 0x12 | 0xF0, codePoint >> 0xC & 0x3F | 0x80, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80);
  32432. } else {
  32433. throw new Error('Invalid code point');
  32434. }
  32435. }
  32436. return bytes;
  32437. }
  32438. function asciiToBytes(str) {
  32439. var byteArray = [];
  32440. for (var i = 0; i < str.length; ++i) {
  32441. // Node's code seems to be doing this and not & 0x7F..
  32442. byteArray.push(str.charCodeAt(i) & 0xFF);
  32443. }
  32444. return byteArray;
  32445. }
  32446. function utf16leToBytes(str, units) {
  32447. var c, hi, lo;
  32448. var byteArray = [];
  32449. for (var i = 0; i < str.length; ++i) {
  32450. if ((units -= 2) < 0) break;
  32451. c = str.charCodeAt(i);
  32452. hi = c >> 8;
  32453. lo = c % 256;
  32454. byteArray.push(lo);
  32455. byteArray.push(hi);
  32456. }
  32457. return byteArray;
  32458. }
  32459. function base64ToBytes(str) {
  32460. return base64.toByteArray(base64clean(str));
  32461. }
  32462. function blitBuffer(src, dst, offset, length) {
  32463. for (var i = 0; i < length; ++i) {
  32464. if (i + offset >= dst.length || i >= src.length) break;
  32465. dst[i + offset] = src[i];
  32466. }
  32467. return i;
  32468. } // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
  32469. // the `instanceof` check but they should be treated as of that type.
  32470. // See: https://github.com/feross/buffer/issues/166
  32471. function isInstance(obj, type) {
  32472. return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name;
  32473. }
  32474. function numberIsNaN(obj) {
  32475. // For IE11 support
  32476. return obj !== obj; // eslint-disable-line no-self-compare
  32477. }
  32478. }).call(this,require("buffer").Buffer)
  32479. },{"base64-js":182,"buffer":216,"ieee754":385}],217:[function(require,module,exports){
  32480. (function (Buffer){
  32481. "use strict";
  32482. module.exports = function xor(a, b) {
  32483. var length = Math.min(a.length, b.length);
  32484. var buffer = new Buffer(length);
  32485. for (var i = 0; i < length; ++i) {
  32486. buffer[i] = a[i] ^ b[i];
  32487. }
  32488. return buffer;
  32489. };
  32490. }).call(this,require("buffer").Buffer)
  32491. },{"buffer":216}],218:[function(require,module,exports){
  32492. "use strict";
  32493. var Buffer = require('safe-buffer').Buffer;
  32494. var Transform = require('stream').Transform;
  32495. var StringDecoder = require('string_decoder').StringDecoder;
  32496. var inherits = require('inherits');
  32497. function CipherBase(hashMode) {
  32498. Transform.call(this);
  32499. this.hashMode = typeof hashMode === 'string';
  32500. if (this.hashMode) {
  32501. this[hashMode] = this._finalOrDigest;
  32502. } else {
  32503. this.final = this._finalOrDigest;
  32504. }
  32505. if (this._final) {
  32506. this.__final = this._final;
  32507. this._final = null;
  32508. }
  32509. this._decoder = null;
  32510. this._encoding = null;
  32511. }
  32512. inherits(CipherBase, Transform);
  32513. CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
  32514. if (typeof data === 'string') {
  32515. data = Buffer.from(data, inputEnc);
  32516. }
  32517. var outData = this._update(data);
  32518. if (this.hashMode) return this;
  32519. if (outputEnc) {
  32520. outData = this._toString(outData, outputEnc);
  32521. }
  32522. return outData;
  32523. };
  32524. CipherBase.prototype.setAutoPadding = function () {};
  32525. CipherBase.prototype.getAuthTag = function () {
  32526. throw new Error('trying to get auth tag in unsupported state');
  32527. };
  32528. CipherBase.prototype.setAuthTag = function () {
  32529. throw new Error('trying to set auth tag in unsupported state');
  32530. };
  32531. CipherBase.prototype.setAAD = function () {
  32532. throw new Error('trying to set aad in unsupported state');
  32533. };
  32534. CipherBase.prototype._transform = function (data, _, next) {
  32535. var err;
  32536. try {
  32537. if (this.hashMode) {
  32538. this._update(data);
  32539. } else {
  32540. this.push(this._update(data));
  32541. }
  32542. } catch (e) {
  32543. err = e;
  32544. } finally {
  32545. next(err);
  32546. }
  32547. };
  32548. CipherBase.prototype._flush = function (done) {
  32549. var err;
  32550. try {
  32551. this.push(this.__final());
  32552. } catch (e) {
  32553. err = e;
  32554. }
  32555. done(err);
  32556. };
  32557. CipherBase.prototype._finalOrDigest = function (outputEnc) {
  32558. var outData = this.__final() || Buffer.alloc(0);
  32559. if (outputEnc) {
  32560. outData = this._toString(outData, outputEnc, true);
  32561. }
  32562. return outData;
  32563. };
  32564. CipherBase.prototype._toString = function (value, enc, fin) {
  32565. if (!this._decoder) {
  32566. this._decoder = new StringDecoder(enc);
  32567. this._encoding = enc;
  32568. }
  32569. if (this._encoding !== enc) throw new Error('can\'t switch encodings');
  32570. var out = this._decoder.write(value);
  32571. if (fin) {
  32572. out += this._decoder.end();
  32573. }
  32574. return out;
  32575. };
  32576. module.exports = CipherBase;
  32577. },{"inherits":387,"safe-buffer":494,"stream":506,"string_decoder":520}],219:[function(require,module,exports){
  32578. module.exports = function (it) {
  32579. if (typeof it != 'function') {
  32580. throw TypeError(String(it) + ' is not a function');
  32581. } return it;
  32582. };
  32583. },{}],220:[function(require,module,exports){
  32584. var isObject = require('../internals/is-object');
  32585. module.exports = function (it) {
  32586. if (!isObject(it) && it !== null) {
  32587. throw TypeError("Can't set " + String(it) + ' as a prototype');
  32588. } return it;
  32589. };
  32590. },{"../internals/is-object":263}],221:[function(require,module,exports){
  32591. var wellKnownSymbol = require('../internals/well-known-symbol');
  32592. var create = require('../internals/object-create');
  32593. var definePropertyModule = require('../internals/object-define-property');
  32594. var UNSCOPABLES = wellKnownSymbol('unscopables');
  32595. var ArrayPrototype = Array.prototype;
  32596. // Array.prototype[@@unscopables]
  32597. // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables
  32598. if (ArrayPrototype[UNSCOPABLES] == undefined) {
  32599. definePropertyModule.f(ArrayPrototype, UNSCOPABLES, {
  32600. configurable: true,
  32601. value: create(null)
  32602. });
  32603. }
  32604. // add a key to Array.prototype[@@unscopables]
  32605. module.exports = function (key) {
  32606. ArrayPrototype[UNSCOPABLES][key] = true;
  32607. };
  32608. },{"../internals/object-create":276,"../internals/object-define-property":278,"../internals/well-known-symbol":314}],222:[function(require,module,exports){
  32609. module.exports = function (it, Constructor, name) {
  32610. if (!(it instanceof Constructor)) {
  32611. throw TypeError('Incorrect ' + (name ? name + ' ' : '') + 'invocation');
  32612. } return it;
  32613. };
  32614. },{}],223:[function(require,module,exports){
  32615. var isObject = require('../internals/is-object');
  32616. module.exports = function (it) {
  32617. if (!isObject(it)) {
  32618. throw TypeError(String(it) + ' is not an object');
  32619. } return it;
  32620. };
  32621. },{"../internals/is-object":263}],224:[function(require,module,exports){
  32622. var toIndexedObject = require('../internals/to-indexed-object');
  32623. var toLength = require('../internals/to-length');
  32624. var toAbsoluteIndex = require('../internals/to-absolute-index');
  32625. // `Array.prototype.{ indexOf, includes }` methods implementation
  32626. var createMethod = function (IS_INCLUDES) {
  32627. return function ($this, el, fromIndex) {
  32628. var O = toIndexedObject($this);
  32629. var length = toLength(O.length);
  32630. var index = toAbsoluteIndex(fromIndex, length);
  32631. var value;
  32632. // Array#includes uses SameValueZero equality algorithm
  32633. // eslint-disable-next-line no-self-compare
  32634. if (IS_INCLUDES && el != el) while (length > index) {
  32635. value = O[index++];
  32636. // eslint-disable-next-line no-self-compare
  32637. if (value != value) return true;
  32638. // Array#indexOf ignores holes, Array#includes - not
  32639. } else for (;length > index; index++) {
  32640. if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0;
  32641. } return !IS_INCLUDES && -1;
  32642. };
  32643. };
  32644. module.exports = {
  32645. // `Array.prototype.includes` method
  32646. // https://tc39.github.io/ecma262/#sec-array.prototype.includes
  32647. includes: createMethod(true),
  32648. // `Array.prototype.indexOf` method
  32649. // https://tc39.github.io/ecma262/#sec-array.prototype.indexof
  32650. indexOf: createMethod(false)
  32651. };
  32652. },{"../internals/to-absolute-index":304,"../internals/to-indexed-object":305,"../internals/to-length":307}],225:[function(require,module,exports){
  32653. var bind = require('../internals/function-bind-context');
  32654. var IndexedObject = require('../internals/indexed-object');
  32655. var toObject = require('../internals/to-object');
  32656. var toLength = require('../internals/to-length');
  32657. var arraySpeciesCreate = require('../internals/array-species-create');
  32658. var push = [].push;
  32659. // `Array.prototype.{ forEach, map, filter, some, every, find, findIndex }` methods implementation
  32660. var createMethod = function (TYPE) {
  32661. var IS_MAP = TYPE == 1;
  32662. var IS_FILTER = TYPE == 2;
  32663. var IS_SOME = TYPE == 3;
  32664. var IS_EVERY = TYPE == 4;
  32665. var IS_FIND_INDEX = TYPE == 6;
  32666. var NO_HOLES = TYPE == 5 || IS_FIND_INDEX;
  32667. return function ($this, callbackfn, that, specificCreate) {
  32668. var O = toObject($this);
  32669. var self = IndexedObject(O);
  32670. var boundFunction = bind(callbackfn, that, 3);
  32671. var length = toLength(self.length);
  32672. var index = 0;
  32673. var create = specificCreate || arraySpeciesCreate;
  32674. var target = IS_MAP ? create($this, length) : IS_FILTER ? create($this, 0) : undefined;
  32675. var value, result;
  32676. for (;length > index; index++) if (NO_HOLES || index in self) {
  32677. value = self[index];
  32678. result = boundFunction(value, index, O);
  32679. if (TYPE) {
  32680. if (IS_MAP) target[index] = result; // map
  32681. else if (result) switch (TYPE) {
  32682. case 3: return true; // some
  32683. case 5: return value; // find
  32684. case 6: return index; // findIndex
  32685. case 2: push.call(target, value); // filter
  32686. } else if (IS_EVERY) return false; // every
  32687. }
  32688. }
  32689. return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : target;
  32690. };
  32691. };
  32692. module.exports = {
  32693. // `Array.prototype.forEach` method
  32694. // https://tc39.github.io/ecma262/#sec-array.prototype.foreach
  32695. forEach: createMethod(0),
  32696. // `Array.prototype.map` method
  32697. // https://tc39.github.io/ecma262/#sec-array.prototype.map
  32698. map: createMethod(1),
  32699. // `Array.prototype.filter` method
  32700. // https://tc39.github.io/ecma262/#sec-array.prototype.filter
  32701. filter: createMethod(2),
  32702. // `Array.prototype.some` method
  32703. // https://tc39.github.io/ecma262/#sec-array.prototype.some
  32704. some: createMethod(3),
  32705. // `Array.prototype.every` method
  32706. // https://tc39.github.io/ecma262/#sec-array.prototype.every
  32707. every: createMethod(4),
  32708. // `Array.prototype.find` method
  32709. // https://tc39.github.io/ecma262/#sec-array.prototype.find
  32710. find: createMethod(5),
  32711. // `Array.prototype.findIndex` method
  32712. // https://tc39.github.io/ecma262/#sec-array.prototype.findIndex
  32713. findIndex: createMethod(6)
  32714. };
  32715. },{"../internals/array-species-create":227,"../internals/function-bind-context":248,"../internals/indexed-object":257,"../internals/to-length":307,"../internals/to-object":308}],226:[function(require,module,exports){
  32716. var DESCRIPTORS = require('../internals/descriptors');
  32717. var fails = require('../internals/fails');
  32718. var has = require('../internals/has');
  32719. var defineProperty = Object.defineProperty;
  32720. var cache = {};
  32721. var thrower = function (it) { throw it; };
  32722. module.exports = function (METHOD_NAME, options) {
  32723. if (has(cache, METHOD_NAME)) return cache[METHOD_NAME];
  32724. if (!options) options = {};
  32725. var method = [][METHOD_NAME];
  32726. var ACCESSORS = has(options, 'ACCESSORS') ? options.ACCESSORS : false;
  32727. var argument0 = has(options, 0) ? options[0] : thrower;
  32728. var argument1 = has(options, 1) ? options[1] : undefined;
  32729. return cache[METHOD_NAME] = !!method && !fails(function () {
  32730. if (ACCESSORS && !DESCRIPTORS) return true;
  32731. var O = { length: -1 };
  32732. if (ACCESSORS) defineProperty(O, 1, { enumerable: true, get: thrower });
  32733. else O[1] = 1;
  32734. method.call(O, argument0, argument1);
  32735. });
  32736. };
  32737. },{"../internals/descriptors":240,"../internals/fails":247,"../internals/has":252}],227:[function(require,module,exports){
  32738. var isObject = require('../internals/is-object');
  32739. var isArray = require('../internals/is-array');
  32740. var wellKnownSymbol = require('../internals/well-known-symbol');
  32741. var SPECIES = wellKnownSymbol('species');
  32742. // `ArraySpeciesCreate` abstract operation
  32743. // https://tc39.github.io/ecma262/#sec-arrayspeciescreate
  32744. module.exports = function (originalArray, length) {
  32745. var C;
  32746. if (isArray(originalArray)) {
  32747. C = originalArray.constructor;
  32748. // cross-realm fallback
  32749. if (typeof C == 'function' && (C === Array || isArray(C.prototype))) C = undefined;
  32750. else if (isObject(C)) {
  32751. C = C[SPECIES];
  32752. if (C === null) C = undefined;
  32753. }
  32754. } return new (C === undefined ? Array : C)(length === 0 ? 0 : length);
  32755. };
  32756. },{"../internals/is-array":261,"../internals/is-object":263,"../internals/well-known-symbol":314}],228:[function(require,module,exports){
  32757. var anObject = require('../internals/an-object');
  32758. // call something on iterator step with safe closing on error
  32759. module.exports = function (iterator, fn, value, ENTRIES) {
  32760. try {
  32761. return ENTRIES ? fn(anObject(value)[0], value[1]) : fn(value);
  32762. // 7.4.6 IteratorClose(iterator, completion)
  32763. } catch (error) {
  32764. var returnMethod = iterator['return'];
  32765. if (returnMethod !== undefined) anObject(returnMethod.call(iterator));
  32766. throw error;
  32767. }
  32768. };
  32769. },{"../internals/an-object":223}],229:[function(require,module,exports){
  32770. var wellKnownSymbol = require('../internals/well-known-symbol');
  32771. var ITERATOR = wellKnownSymbol('iterator');
  32772. var SAFE_CLOSING = false;
  32773. try {
  32774. var called = 0;
  32775. var iteratorWithReturn = {
  32776. next: function () {
  32777. return { done: !!called++ };
  32778. },
  32779. 'return': function () {
  32780. SAFE_CLOSING = true;
  32781. }
  32782. };
  32783. iteratorWithReturn[ITERATOR] = function () {
  32784. return this;
  32785. };
  32786. // eslint-disable-next-line no-throw-literal
  32787. Array.from(iteratorWithReturn, function () { throw 2; });
  32788. } catch (error) { /* empty */ }
  32789. module.exports = function (exec, SKIP_CLOSING) {
  32790. if (!SKIP_CLOSING && !SAFE_CLOSING) return false;
  32791. var ITERATION_SUPPORT = false;
  32792. try {
  32793. var object = {};
  32794. object[ITERATOR] = function () {
  32795. return {
  32796. next: function () {
  32797. return { done: ITERATION_SUPPORT = true };
  32798. }
  32799. };
  32800. };
  32801. exec(object);
  32802. } catch (error) { /* empty */ }
  32803. return ITERATION_SUPPORT;
  32804. };
  32805. },{"../internals/well-known-symbol":314}],230:[function(require,module,exports){
  32806. var toString = {}.toString;
  32807. module.exports = function (it) {
  32808. return toString.call(it).slice(8, -1);
  32809. };
  32810. },{}],231:[function(require,module,exports){
  32811. var TO_STRING_TAG_SUPPORT = require('../internals/to-string-tag-support');
  32812. var classofRaw = require('../internals/classof-raw');
  32813. var wellKnownSymbol = require('../internals/well-known-symbol');
  32814. var TO_STRING_TAG = wellKnownSymbol('toStringTag');
  32815. // ES3 wrong here
  32816. var CORRECT_ARGUMENTS = classofRaw(function () { return arguments; }()) == 'Arguments';
  32817. // fallback for IE11 Script Access Denied error
  32818. var tryGet = function (it, key) {
  32819. try {
  32820. return it[key];
  32821. } catch (error) { /* empty */ }
  32822. };
  32823. // getting tag from ES6+ `Object.prototype.toString`
  32824. module.exports = TO_STRING_TAG_SUPPORT ? classofRaw : function (it) {
  32825. var O, tag, result;
  32826. return it === undefined ? 'Undefined' : it === null ? 'Null'
  32827. // @@toStringTag case
  32828. : typeof (tag = tryGet(O = Object(it), TO_STRING_TAG)) == 'string' ? tag
  32829. // builtinTag case
  32830. : CORRECT_ARGUMENTS ? classofRaw(O)
  32831. // ES3 arguments fallback
  32832. : (result = classofRaw(O)) == 'Object' && typeof O.callee == 'function' ? 'Arguments' : result;
  32833. };
  32834. },{"../internals/classof-raw":230,"../internals/to-string-tag-support":310,"../internals/well-known-symbol":314}],232:[function(require,module,exports){
  32835. var has = require('../internals/has');
  32836. var ownKeys = require('../internals/own-keys');
  32837. var getOwnPropertyDescriptorModule = require('../internals/object-get-own-property-descriptor');
  32838. var definePropertyModule = require('../internals/object-define-property');
  32839. module.exports = function (target, source) {
  32840. var keys = ownKeys(source);
  32841. var defineProperty = definePropertyModule.f;
  32842. var getOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;
  32843. for (var i = 0; i < keys.length; i++) {
  32844. var key = keys[i];
  32845. if (!has(target, key)) defineProperty(target, key, getOwnPropertyDescriptor(source, key));
  32846. }
  32847. };
  32848. },{"../internals/has":252,"../internals/object-define-property":278,"../internals/object-get-own-property-descriptor":279,"../internals/own-keys":289}],233:[function(require,module,exports){
  32849. var wellKnownSymbol = require('../internals/well-known-symbol');
  32850. var MATCH = wellKnownSymbol('match');
  32851. module.exports = function (METHOD_NAME) {
  32852. var regexp = /./;
  32853. try {
  32854. '/./'[METHOD_NAME](regexp);
  32855. } catch (e) {
  32856. try {
  32857. regexp[MATCH] = false;
  32858. return '/./'[METHOD_NAME](regexp);
  32859. } catch (f) { /* empty */ }
  32860. } return false;
  32861. };
  32862. },{"../internals/well-known-symbol":314}],234:[function(require,module,exports){
  32863. var fails = require('../internals/fails');
  32864. module.exports = !fails(function () {
  32865. function F() { /* empty */ }
  32866. F.prototype.constructor = null;
  32867. return Object.getPrototypeOf(new F()) !== F.prototype;
  32868. });
  32869. },{"../internals/fails":247}],235:[function(require,module,exports){
  32870. 'use strict';
  32871. var IteratorPrototype = require('../internals/iterators-core').IteratorPrototype;
  32872. var create = require('../internals/object-create');
  32873. var createPropertyDescriptor = require('../internals/create-property-descriptor');
  32874. var setToStringTag = require('../internals/set-to-string-tag');
  32875. var Iterators = require('../internals/iterators');
  32876. var returnThis = function () { return this; };
  32877. module.exports = function (IteratorConstructor, NAME, next) {
  32878. var TO_STRING_TAG = NAME + ' Iterator';
  32879. IteratorConstructor.prototype = create(IteratorPrototype, { next: createPropertyDescriptor(1, next) });
  32880. setToStringTag(IteratorConstructor, TO_STRING_TAG, false, true);
  32881. Iterators[TO_STRING_TAG] = returnThis;
  32882. return IteratorConstructor;
  32883. };
  32884. },{"../internals/create-property-descriptor":237,"../internals/iterators":268,"../internals/iterators-core":267,"../internals/object-create":276,"../internals/set-to-string-tag":298}],236:[function(require,module,exports){
  32885. var DESCRIPTORS = require('../internals/descriptors');
  32886. var definePropertyModule = require('../internals/object-define-property');
  32887. var createPropertyDescriptor = require('../internals/create-property-descriptor');
  32888. module.exports = DESCRIPTORS ? function (object, key, value) {
  32889. return definePropertyModule.f(object, key, createPropertyDescriptor(1, value));
  32890. } : function (object, key, value) {
  32891. object[key] = value;
  32892. return object;
  32893. };
  32894. },{"../internals/create-property-descriptor":237,"../internals/descriptors":240,"../internals/object-define-property":278}],237:[function(require,module,exports){
  32895. module.exports = function (bitmap, value) {
  32896. return {
  32897. enumerable: !(bitmap & 1),
  32898. configurable: !(bitmap & 2),
  32899. writable: !(bitmap & 4),
  32900. value: value
  32901. };
  32902. };
  32903. },{}],238:[function(require,module,exports){
  32904. 'use strict';
  32905. var $ = require('../internals/export');
  32906. var createIteratorConstructor = require('../internals/create-iterator-constructor');
  32907. var getPrototypeOf = require('../internals/object-get-prototype-of');
  32908. var setPrototypeOf = require('../internals/object-set-prototype-of');
  32909. var setToStringTag = require('../internals/set-to-string-tag');
  32910. var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
  32911. var redefine = require('../internals/redefine');
  32912. var wellKnownSymbol = require('../internals/well-known-symbol');
  32913. var IS_PURE = require('../internals/is-pure');
  32914. var Iterators = require('../internals/iterators');
  32915. var IteratorsCore = require('../internals/iterators-core');
  32916. var IteratorPrototype = IteratorsCore.IteratorPrototype;
  32917. var BUGGY_SAFARI_ITERATORS = IteratorsCore.BUGGY_SAFARI_ITERATORS;
  32918. var ITERATOR = wellKnownSymbol('iterator');
  32919. var KEYS = 'keys';
  32920. var VALUES = 'values';
  32921. var ENTRIES = 'entries';
  32922. var returnThis = function () { return this; };
  32923. module.exports = function (Iterable, NAME, IteratorConstructor, next, DEFAULT, IS_SET, FORCED) {
  32924. createIteratorConstructor(IteratorConstructor, NAME, next);
  32925. var getIterationMethod = function (KIND) {
  32926. if (KIND === DEFAULT && defaultIterator) return defaultIterator;
  32927. if (!BUGGY_SAFARI_ITERATORS && KIND in IterablePrototype) return IterablePrototype[KIND];
  32928. switch (KIND) {
  32929. case KEYS: return function keys() { return new IteratorConstructor(this, KIND); };
  32930. case VALUES: return function values() { return new IteratorConstructor(this, KIND); };
  32931. case ENTRIES: return function entries() { return new IteratorConstructor(this, KIND); };
  32932. } return function () { return new IteratorConstructor(this); };
  32933. };
  32934. var TO_STRING_TAG = NAME + ' Iterator';
  32935. var INCORRECT_VALUES_NAME = false;
  32936. var IterablePrototype = Iterable.prototype;
  32937. var nativeIterator = IterablePrototype[ITERATOR]
  32938. || IterablePrototype['@@iterator']
  32939. || DEFAULT && IterablePrototype[DEFAULT];
  32940. var defaultIterator = !BUGGY_SAFARI_ITERATORS && nativeIterator || getIterationMethod(DEFAULT);
  32941. var anyNativeIterator = NAME == 'Array' ? IterablePrototype.entries || nativeIterator : nativeIterator;
  32942. var CurrentIteratorPrototype, methods, KEY;
  32943. // fix native
  32944. if (anyNativeIterator) {
  32945. CurrentIteratorPrototype = getPrototypeOf(anyNativeIterator.call(new Iterable()));
  32946. if (IteratorPrototype !== Object.prototype && CurrentIteratorPrototype.next) {
  32947. if (!IS_PURE && getPrototypeOf(CurrentIteratorPrototype) !== IteratorPrototype) {
  32948. if (setPrototypeOf) {
  32949. setPrototypeOf(CurrentIteratorPrototype, IteratorPrototype);
  32950. } else if (typeof CurrentIteratorPrototype[ITERATOR] != 'function') {
  32951. createNonEnumerableProperty(CurrentIteratorPrototype, ITERATOR, returnThis);
  32952. }
  32953. }
  32954. // Set @@toStringTag to native iterators
  32955. setToStringTag(CurrentIteratorPrototype, TO_STRING_TAG, true, true);
  32956. if (IS_PURE) Iterators[TO_STRING_TAG] = returnThis;
  32957. }
  32958. }
  32959. // fix Array#{values, @@iterator}.name in V8 / FF
  32960. if (DEFAULT == VALUES && nativeIterator && nativeIterator.name !== VALUES) {
  32961. INCORRECT_VALUES_NAME = true;
  32962. defaultIterator = function values() { return nativeIterator.call(this); };
  32963. }
  32964. // define iterator
  32965. if ((!IS_PURE || FORCED) && IterablePrototype[ITERATOR] !== defaultIterator) {
  32966. createNonEnumerableProperty(IterablePrototype, ITERATOR, defaultIterator);
  32967. }
  32968. Iterators[NAME] = defaultIterator;
  32969. // export additional methods
  32970. if (DEFAULT) {
  32971. methods = {
  32972. values: getIterationMethod(VALUES),
  32973. keys: IS_SET ? defaultIterator : getIterationMethod(KEYS),
  32974. entries: getIterationMethod(ENTRIES)
  32975. };
  32976. if (FORCED) for (KEY in methods) {
  32977. if (BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME || !(KEY in IterablePrototype)) {
  32978. redefine(IterablePrototype, KEY, methods[KEY]);
  32979. }
  32980. } else $({ target: NAME, proto: true, forced: BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME }, methods);
  32981. }
  32982. return methods;
  32983. };
  32984. },{"../internals/create-iterator-constructor":235,"../internals/create-non-enumerable-property":236,"../internals/export":246,"../internals/is-pure":264,"../internals/iterators":268,"../internals/iterators-core":267,"../internals/object-get-prototype-of":283,"../internals/object-set-prototype-of":287,"../internals/redefine":294,"../internals/set-to-string-tag":298,"../internals/well-known-symbol":314}],239:[function(require,module,exports){
  32985. var path = require('../internals/path');
  32986. var has = require('../internals/has');
  32987. var wrappedWellKnownSymbolModule = require('../internals/well-known-symbol-wrapped');
  32988. var defineProperty = require('../internals/object-define-property').f;
  32989. module.exports = function (NAME) {
  32990. var Symbol = path.Symbol || (path.Symbol = {});
  32991. if (!has(Symbol, NAME)) defineProperty(Symbol, NAME, {
  32992. value: wrappedWellKnownSymbolModule.f(NAME)
  32993. });
  32994. };
  32995. },{"../internals/has":252,"../internals/object-define-property":278,"../internals/path":290,"../internals/well-known-symbol-wrapped":313}],240:[function(require,module,exports){
  32996. var fails = require('../internals/fails');
  32997. // Thank's IE8 for his funny defineProperty
  32998. module.exports = !fails(function () {
  32999. return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] != 7;
  33000. });
  33001. },{"../internals/fails":247}],241:[function(require,module,exports){
  33002. var global = require('../internals/global');
  33003. var isObject = require('../internals/is-object');
  33004. var document = global.document;
  33005. // typeof document.createElement is 'object' in old IE
  33006. var EXISTS = isObject(document) && isObject(document.createElement);
  33007. module.exports = function (it) {
  33008. return EXISTS ? document.createElement(it) : {};
  33009. };
  33010. },{"../internals/global":251,"../internals/is-object":263}],242:[function(require,module,exports){
  33011. var userAgent = require('../internals/engine-user-agent');
  33012. module.exports = /(iphone|ipod|ipad).*applewebkit/i.test(userAgent);
  33013. },{"../internals/engine-user-agent":243}],243:[function(require,module,exports){
  33014. var getBuiltIn = require('../internals/get-built-in');
  33015. module.exports = getBuiltIn('navigator', 'userAgent') || '';
  33016. },{"../internals/get-built-in":249}],244:[function(require,module,exports){
  33017. var global = require('../internals/global');
  33018. var userAgent = require('../internals/engine-user-agent');
  33019. var process = global.process;
  33020. var versions = process && process.versions;
  33021. var v8 = versions && versions.v8;
  33022. var match, version;
  33023. if (v8) {
  33024. match = v8.split('.');
  33025. version = match[0] + match[1];
  33026. } else if (userAgent) {
  33027. match = userAgent.match(/Edge\/(\d+)/);
  33028. if (!match || match[1] >= 74) {
  33029. match = userAgent.match(/Chrome\/(\d+)/);
  33030. if (match) version = match[1];
  33031. }
  33032. }
  33033. module.exports = version && +version;
  33034. },{"../internals/engine-user-agent":243,"../internals/global":251}],245:[function(require,module,exports){
  33035. // IE8- don't enum bug keys
  33036. module.exports = [
  33037. 'constructor',
  33038. 'hasOwnProperty',
  33039. 'isPrototypeOf',
  33040. 'propertyIsEnumerable',
  33041. 'toLocaleString',
  33042. 'toString',
  33043. 'valueOf'
  33044. ];
  33045. },{}],246:[function(require,module,exports){
  33046. var global = require('../internals/global');
  33047. var getOwnPropertyDescriptor = require('../internals/object-get-own-property-descriptor').f;
  33048. var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
  33049. var redefine = require('../internals/redefine');
  33050. var setGlobal = require('../internals/set-global');
  33051. var copyConstructorProperties = require('../internals/copy-constructor-properties');
  33052. var isForced = require('../internals/is-forced');
  33053. /*
  33054. options.target - name of the target object
  33055. options.global - target is the global object
  33056. options.stat - export as static methods of target
  33057. options.proto - export as prototype methods of target
  33058. options.real - real prototype method for the `pure` version
  33059. options.forced - export even if the native feature is available
  33060. options.bind - bind methods to the target, required for the `pure` version
  33061. options.wrap - wrap constructors to preventing global pollution, required for the `pure` version
  33062. options.unsafe - use the simple assignment of property instead of delete + defineProperty
  33063. options.sham - add a flag to not completely full polyfills
  33064. options.enumerable - export as enumerable property
  33065. options.noTargetGet - prevent calling a getter on target
  33066. */
  33067. module.exports = function (options, source) {
  33068. var TARGET = options.target;
  33069. var GLOBAL = options.global;
  33070. var STATIC = options.stat;
  33071. var FORCED, target, key, targetProperty, sourceProperty, descriptor;
  33072. if (GLOBAL) {
  33073. target = global;
  33074. } else if (STATIC) {
  33075. target = global[TARGET] || setGlobal(TARGET, {});
  33076. } else {
  33077. target = (global[TARGET] || {}).prototype;
  33078. }
  33079. if (target) for (key in source) {
  33080. sourceProperty = source[key];
  33081. if (options.noTargetGet) {
  33082. descriptor = getOwnPropertyDescriptor(target, key);
  33083. targetProperty = descriptor && descriptor.value;
  33084. } else targetProperty = target[key];
  33085. FORCED = isForced(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced);
  33086. // contained in target
  33087. if (!FORCED && targetProperty !== undefined) {
  33088. if (typeof sourceProperty === typeof targetProperty) continue;
  33089. copyConstructorProperties(sourceProperty, targetProperty);
  33090. }
  33091. // add a flag to not completely full polyfills
  33092. if (options.sham || (targetProperty && targetProperty.sham)) {
  33093. createNonEnumerableProperty(sourceProperty, 'sham', true);
  33094. }
  33095. // extend global
  33096. redefine(target, key, sourceProperty, options);
  33097. }
  33098. };
  33099. },{"../internals/copy-constructor-properties":232,"../internals/create-non-enumerable-property":236,"../internals/global":251,"../internals/is-forced":262,"../internals/object-get-own-property-descriptor":279,"../internals/redefine":294,"../internals/set-global":296}],247:[function(require,module,exports){
  33100. module.exports = function (exec) {
  33101. try {
  33102. return !!exec();
  33103. } catch (error) {
  33104. return true;
  33105. }
  33106. };
  33107. },{}],248:[function(require,module,exports){
  33108. var aFunction = require('../internals/a-function');
  33109. // optional / simple context binding
  33110. module.exports = function (fn, that, length) {
  33111. aFunction(fn);
  33112. if (that === undefined) return fn;
  33113. switch (length) {
  33114. case 0: return function () {
  33115. return fn.call(that);
  33116. };
  33117. case 1: return function (a) {
  33118. return fn.call(that, a);
  33119. };
  33120. case 2: return function (a, b) {
  33121. return fn.call(that, a, b);
  33122. };
  33123. case 3: return function (a, b, c) {
  33124. return fn.call(that, a, b, c);
  33125. };
  33126. }
  33127. return function (/* ...args */) {
  33128. return fn.apply(that, arguments);
  33129. };
  33130. };
  33131. },{"../internals/a-function":219}],249:[function(require,module,exports){
  33132. var path = require('../internals/path');
  33133. var global = require('../internals/global');
  33134. var aFunction = function (variable) {
  33135. return typeof variable == 'function' ? variable : undefined;
  33136. };
  33137. module.exports = function (namespace, method) {
  33138. return arguments.length < 2 ? aFunction(path[namespace]) || aFunction(global[namespace])
  33139. : path[namespace] && path[namespace][method] || global[namespace] && global[namespace][method];
  33140. };
  33141. },{"../internals/global":251,"../internals/path":290}],250:[function(require,module,exports){
  33142. var classof = require('../internals/classof');
  33143. var Iterators = require('../internals/iterators');
  33144. var wellKnownSymbol = require('../internals/well-known-symbol');
  33145. var ITERATOR = wellKnownSymbol('iterator');
  33146. module.exports = function (it) {
  33147. if (it != undefined) return it[ITERATOR]
  33148. || it['@@iterator']
  33149. || Iterators[classof(it)];
  33150. };
  33151. },{"../internals/classof":231,"../internals/iterators":268,"../internals/well-known-symbol":314}],251:[function(require,module,exports){
  33152. (function (global){
  33153. var check = function (it) {
  33154. return it && it.Math == Math && it;
  33155. };
  33156. // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
  33157. module.exports =
  33158. // eslint-disable-next-line no-undef
  33159. check(typeof globalThis == 'object' && globalThis) ||
  33160. check(typeof window == 'object' && window) ||
  33161. check(typeof self == 'object' && self) ||
  33162. check(typeof global == 'object' && global) ||
  33163. // eslint-disable-next-line no-new-func
  33164. Function('return this')();
  33165. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  33166. },{}],252:[function(require,module,exports){
  33167. var hasOwnProperty = {}.hasOwnProperty;
  33168. module.exports = function (it, key) {
  33169. return hasOwnProperty.call(it, key);
  33170. };
  33171. },{}],253:[function(require,module,exports){
  33172. module.exports = {};
  33173. },{}],254:[function(require,module,exports){
  33174. var global = require('../internals/global');
  33175. module.exports = function (a, b) {
  33176. var console = global.console;
  33177. if (console && console.error) {
  33178. arguments.length === 1 ? console.error(a) : console.error(a, b);
  33179. }
  33180. };
  33181. },{"../internals/global":251}],255:[function(require,module,exports){
  33182. var getBuiltIn = require('../internals/get-built-in');
  33183. module.exports = getBuiltIn('document', 'documentElement');
  33184. },{"../internals/get-built-in":249}],256:[function(require,module,exports){
  33185. var DESCRIPTORS = require('../internals/descriptors');
  33186. var fails = require('../internals/fails');
  33187. var createElement = require('../internals/document-create-element');
  33188. // Thank's IE8 for his funny defineProperty
  33189. module.exports = !DESCRIPTORS && !fails(function () {
  33190. return Object.defineProperty(createElement('div'), 'a', {
  33191. get: function () { return 7; }
  33192. }).a != 7;
  33193. });
  33194. },{"../internals/descriptors":240,"../internals/document-create-element":241,"../internals/fails":247}],257:[function(require,module,exports){
  33195. var fails = require('../internals/fails');
  33196. var classof = require('../internals/classof-raw');
  33197. var split = ''.split;
  33198. // fallback for non-array-like ES3 and non-enumerable old V8 strings
  33199. module.exports = fails(function () {
  33200. // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346
  33201. // eslint-disable-next-line no-prototype-builtins
  33202. return !Object('z').propertyIsEnumerable(0);
  33203. }) ? function (it) {
  33204. return classof(it) == 'String' ? split.call(it, '') : Object(it);
  33205. } : Object;
  33206. },{"../internals/classof-raw":230,"../internals/fails":247}],258:[function(require,module,exports){
  33207. var store = require('../internals/shared-store');
  33208. var functionToString = Function.toString;
  33209. // this helper broken in `3.4.1-3.4.4`, so we can't use `shared` helper
  33210. if (typeof store.inspectSource != 'function') {
  33211. store.inspectSource = function (it) {
  33212. return functionToString.call(it);
  33213. };
  33214. }
  33215. module.exports = store.inspectSource;
  33216. },{"../internals/shared-store":300}],259:[function(require,module,exports){
  33217. var NATIVE_WEAK_MAP = require('../internals/native-weak-map');
  33218. var global = require('../internals/global');
  33219. var isObject = require('../internals/is-object');
  33220. var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
  33221. var objectHas = require('../internals/has');
  33222. var sharedKey = require('../internals/shared-key');
  33223. var hiddenKeys = require('../internals/hidden-keys');
  33224. var WeakMap = global.WeakMap;
  33225. var set, get, has;
  33226. var enforce = function (it) {
  33227. return has(it) ? get(it) : set(it, {});
  33228. };
  33229. var getterFor = function (TYPE) {
  33230. return function (it) {
  33231. var state;
  33232. if (!isObject(it) || (state = get(it)).type !== TYPE) {
  33233. throw TypeError('Incompatible receiver, ' + TYPE + ' required');
  33234. } return state;
  33235. };
  33236. };
  33237. if (NATIVE_WEAK_MAP) {
  33238. var store = new WeakMap();
  33239. var wmget = store.get;
  33240. var wmhas = store.has;
  33241. var wmset = store.set;
  33242. set = function (it, metadata) {
  33243. wmset.call(store, it, metadata);
  33244. return metadata;
  33245. };
  33246. get = function (it) {
  33247. return wmget.call(store, it) || {};
  33248. };
  33249. has = function (it) {
  33250. return wmhas.call(store, it);
  33251. };
  33252. } else {
  33253. var STATE = sharedKey('state');
  33254. hiddenKeys[STATE] = true;
  33255. set = function (it, metadata) {
  33256. createNonEnumerableProperty(it, STATE, metadata);
  33257. return metadata;
  33258. };
  33259. get = function (it) {
  33260. return objectHas(it, STATE) ? it[STATE] : {};
  33261. };
  33262. has = function (it) {
  33263. return objectHas(it, STATE);
  33264. };
  33265. }
  33266. module.exports = {
  33267. set: set,
  33268. get: get,
  33269. has: has,
  33270. enforce: enforce,
  33271. getterFor: getterFor
  33272. };
  33273. },{"../internals/create-non-enumerable-property":236,"../internals/global":251,"../internals/has":252,"../internals/hidden-keys":253,"../internals/is-object":263,"../internals/native-weak-map":272,"../internals/shared-key":299}],260:[function(require,module,exports){
  33274. var wellKnownSymbol = require('../internals/well-known-symbol');
  33275. var Iterators = require('../internals/iterators');
  33276. var ITERATOR = wellKnownSymbol('iterator');
  33277. var ArrayPrototype = Array.prototype;
  33278. // check on default Array iterator
  33279. module.exports = function (it) {
  33280. return it !== undefined && (Iterators.Array === it || ArrayPrototype[ITERATOR] === it);
  33281. };
  33282. },{"../internals/iterators":268,"../internals/well-known-symbol":314}],261:[function(require,module,exports){
  33283. var classof = require('../internals/classof-raw');
  33284. // `IsArray` abstract operation
  33285. // https://tc39.github.io/ecma262/#sec-isarray
  33286. module.exports = Array.isArray || function isArray(arg) {
  33287. return classof(arg) == 'Array';
  33288. };
  33289. },{"../internals/classof-raw":230}],262:[function(require,module,exports){
  33290. var fails = require('../internals/fails');
  33291. var replacement = /#|\.prototype\./;
  33292. var isForced = function (feature, detection) {
  33293. var value = data[normalize(feature)];
  33294. return value == POLYFILL ? true
  33295. : value == NATIVE ? false
  33296. : typeof detection == 'function' ? fails(detection)
  33297. : !!detection;
  33298. };
  33299. var normalize = isForced.normalize = function (string) {
  33300. return String(string).replace(replacement, '.').toLowerCase();
  33301. };
  33302. var data = isForced.data = {};
  33303. var NATIVE = isForced.NATIVE = 'N';
  33304. var POLYFILL = isForced.POLYFILL = 'P';
  33305. module.exports = isForced;
  33306. },{"../internals/fails":247}],263:[function(require,module,exports){
  33307. module.exports = function (it) {
  33308. return typeof it === 'object' ? it !== null : typeof it === 'function';
  33309. };
  33310. },{}],264:[function(require,module,exports){
  33311. module.exports = false;
  33312. },{}],265:[function(require,module,exports){
  33313. var isObject = require('../internals/is-object');
  33314. var classof = require('../internals/classof-raw');
  33315. var wellKnownSymbol = require('../internals/well-known-symbol');
  33316. var MATCH = wellKnownSymbol('match');
  33317. // `IsRegExp` abstract operation
  33318. // https://tc39.github.io/ecma262/#sec-isregexp
  33319. module.exports = function (it) {
  33320. var isRegExp;
  33321. return isObject(it) && ((isRegExp = it[MATCH]) !== undefined ? !!isRegExp : classof(it) == 'RegExp');
  33322. };
  33323. },{"../internals/classof-raw":230,"../internals/is-object":263,"../internals/well-known-symbol":314}],266:[function(require,module,exports){
  33324. var anObject = require('../internals/an-object');
  33325. var isArrayIteratorMethod = require('../internals/is-array-iterator-method');
  33326. var toLength = require('../internals/to-length');
  33327. var bind = require('../internals/function-bind-context');
  33328. var getIteratorMethod = require('../internals/get-iterator-method');
  33329. var callWithSafeIterationClosing = require('../internals/call-with-safe-iteration-closing');
  33330. var Result = function (stopped, result) {
  33331. this.stopped = stopped;
  33332. this.result = result;
  33333. };
  33334. var iterate = module.exports = function (iterable, fn, that, AS_ENTRIES, IS_ITERATOR) {
  33335. var boundFunction = bind(fn, that, AS_ENTRIES ? 2 : 1);
  33336. var iterator, iterFn, index, length, result, next, step;
  33337. if (IS_ITERATOR) {
  33338. iterator = iterable;
  33339. } else {
  33340. iterFn = getIteratorMethod(iterable);
  33341. if (typeof iterFn != 'function') throw TypeError('Target is not iterable');
  33342. // optimisation for array iterators
  33343. if (isArrayIteratorMethod(iterFn)) {
  33344. for (index = 0, length = toLength(iterable.length); length > index; index++) {
  33345. result = AS_ENTRIES
  33346. ? boundFunction(anObject(step = iterable[index])[0], step[1])
  33347. : boundFunction(iterable[index]);
  33348. if (result && result instanceof Result) return result;
  33349. } return new Result(false);
  33350. }
  33351. iterator = iterFn.call(iterable);
  33352. }
  33353. next = iterator.next;
  33354. while (!(step = next.call(iterator)).done) {
  33355. result = callWithSafeIterationClosing(iterator, boundFunction, step.value, AS_ENTRIES);
  33356. if (typeof result == 'object' && result && result instanceof Result) return result;
  33357. } return new Result(false);
  33358. };
  33359. iterate.stop = function (result) {
  33360. return new Result(true, result);
  33361. };
  33362. },{"../internals/an-object":223,"../internals/call-with-safe-iteration-closing":228,"../internals/function-bind-context":248,"../internals/get-iterator-method":250,"../internals/is-array-iterator-method":260,"../internals/to-length":307}],267:[function(require,module,exports){
  33363. 'use strict';
  33364. var getPrototypeOf = require('../internals/object-get-prototype-of');
  33365. var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
  33366. var has = require('../internals/has');
  33367. var wellKnownSymbol = require('../internals/well-known-symbol');
  33368. var IS_PURE = require('../internals/is-pure');
  33369. var ITERATOR = wellKnownSymbol('iterator');
  33370. var BUGGY_SAFARI_ITERATORS = false;
  33371. var returnThis = function () { return this; };
  33372. // `%IteratorPrototype%` object
  33373. // https://tc39.github.io/ecma262/#sec-%iteratorprototype%-object
  33374. var IteratorPrototype, PrototypeOfArrayIteratorPrototype, arrayIterator;
  33375. if ([].keys) {
  33376. arrayIterator = [].keys();
  33377. // Safari 8 has buggy iterators w/o `next`
  33378. if (!('next' in arrayIterator)) BUGGY_SAFARI_ITERATORS = true;
  33379. else {
  33380. PrototypeOfArrayIteratorPrototype = getPrototypeOf(getPrototypeOf(arrayIterator));
  33381. if (PrototypeOfArrayIteratorPrototype !== Object.prototype) IteratorPrototype = PrototypeOfArrayIteratorPrototype;
  33382. }
  33383. }
  33384. if (IteratorPrototype == undefined) IteratorPrototype = {};
  33385. // 25.1.2.1.1 %IteratorPrototype%[@@iterator]()
  33386. if (!IS_PURE && !has(IteratorPrototype, ITERATOR)) {
  33387. createNonEnumerableProperty(IteratorPrototype, ITERATOR, returnThis);
  33388. }
  33389. module.exports = {
  33390. IteratorPrototype: IteratorPrototype,
  33391. BUGGY_SAFARI_ITERATORS: BUGGY_SAFARI_ITERATORS
  33392. };
  33393. },{"../internals/create-non-enumerable-property":236,"../internals/has":252,"../internals/is-pure":264,"../internals/object-get-prototype-of":283,"../internals/well-known-symbol":314}],268:[function(require,module,exports){
  33394. arguments[4][253][0].apply(exports,arguments)
  33395. },{"dup":253}],269:[function(require,module,exports){
  33396. var global = require('../internals/global');
  33397. var getOwnPropertyDescriptor = require('../internals/object-get-own-property-descriptor').f;
  33398. var classof = require('../internals/classof-raw');
  33399. var macrotask = require('../internals/task').set;
  33400. var IS_IOS = require('../internals/engine-is-ios');
  33401. var MutationObserver = global.MutationObserver || global.WebKitMutationObserver;
  33402. var process = global.process;
  33403. var Promise = global.Promise;
  33404. var IS_NODE = classof(process) == 'process';
  33405. // Node.js 11 shows ExperimentalWarning on getting `queueMicrotask`
  33406. var queueMicrotaskDescriptor = getOwnPropertyDescriptor(global, 'queueMicrotask');
  33407. var queueMicrotask = queueMicrotaskDescriptor && queueMicrotaskDescriptor.value;
  33408. var flush, head, last, notify, toggle, node, promise, then;
  33409. // modern engines have queueMicrotask method
  33410. if (!queueMicrotask) {
  33411. flush = function () {
  33412. var parent, fn;
  33413. if (IS_NODE && (parent = process.domain)) parent.exit();
  33414. while (head) {
  33415. fn = head.fn;
  33416. head = head.next;
  33417. try {
  33418. fn();
  33419. } catch (error) {
  33420. if (head) notify();
  33421. else last = undefined;
  33422. throw error;
  33423. }
  33424. } last = undefined;
  33425. if (parent) parent.enter();
  33426. };
  33427. // Node.js
  33428. if (IS_NODE) {
  33429. notify = function () {
  33430. process.nextTick(flush);
  33431. };
  33432. // browsers with MutationObserver, except iOS - https://github.com/zloirock/core-js/issues/339
  33433. } else if (MutationObserver && !IS_IOS) {
  33434. toggle = true;
  33435. node = document.createTextNode('');
  33436. new MutationObserver(flush).observe(node, { characterData: true });
  33437. notify = function () {
  33438. node.data = toggle = !toggle;
  33439. };
  33440. // environments with maybe non-completely correct, but existent Promise
  33441. } else if (Promise && Promise.resolve) {
  33442. // Promise.resolve without an argument throws an error in LG WebOS 2
  33443. promise = Promise.resolve(undefined);
  33444. then = promise.then;
  33445. notify = function () {
  33446. then.call(promise, flush);
  33447. };
  33448. // for other environments - macrotask based on:
  33449. // - setImmediate
  33450. // - MessageChannel
  33451. // - window.postMessag
  33452. // - onreadystatechange
  33453. // - setTimeout
  33454. } else {
  33455. notify = function () {
  33456. // strange IE + webpack dev server bug - use .call(global)
  33457. macrotask.call(global, flush);
  33458. };
  33459. }
  33460. }
  33461. module.exports = queueMicrotask || function (fn) {
  33462. var task = { fn: fn, next: undefined };
  33463. if (last) last.next = task;
  33464. if (!head) {
  33465. head = task;
  33466. notify();
  33467. } last = task;
  33468. };
  33469. },{"../internals/classof-raw":230,"../internals/engine-is-ios":242,"../internals/global":251,"../internals/object-get-own-property-descriptor":279,"../internals/task":303}],270:[function(require,module,exports){
  33470. var global = require('../internals/global');
  33471. module.exports = global.Promise;
  33472. },{"../internals/global":251}],271:[function(require,module,exports){
  33473. var fails = require('../internals/fails');
  33474. module.exports = !!Object.getOwnPropertySymbols && !fails(function () {
  33475. // Chrome 38 Symbol has incorrect toString conversion
  33476. // eslint-disable-next-line no-undef
  33477. return !String(Symbol());
  33478. });
  33479. },{"../internals/fails":247}],272:[function(require,module,exports){
  33480. var global = require('../internals/global');
  33481. var inspectSource = require('../internals/inspect-source');
  33482. var WeakMap = global.WeakMap;
  33483. module.exports = typeof WeakMap === 'function' && /native code/.test(inspectSource(WeakMap));
  33484. },{"../internals/global":251,"../internals/inspect-source":258}],273:[function(require,module,exports){
  33485. 'use strict';
  33486. var aFunction = require('../internals/a-function');
  33487. var PromiseCapability = function (C) {
  33488. var resolve, reject;
  33489. this.promise = new C(function ($$resolve, $$reject) {
  33490. if (resolve !== undefined || reject !== undefined) throw TypeError('Bad Promise constructor');
  33491. resolve = $$resolve;
  33492. reject = $$reject;
  33493. });
  33494. this.resolve = aFunction(resolve);
  33495. this.reject = aFunction(reject);
  33496. };
  33497. // 25.4.1.5 NewPromiseCapability(C)
  33498. module.exports.f = function (C) {
  33499. return new PromiseCapability(C);
  33500. };
  33501. },{"../internals/a-function":219}],274:[function(require,module,exports){
  33502. var isRegExp = require('../internals/is-regexp');
  33503. module.exports = function (it) {
  33504. if (isRegExp(it)) {
  33505. throw TypeError("The method doesn't accept regular expressions");
  33506. } return it;
  33507. };
  33508. },{"../internals/is-regexp":265}],275:[function(require,module,exports){
  33509. 'use strict';
  33510. var DESCRIPTORS = require('../internals/descriptors');
  33511. var fails = require('../internals/fails');
  33512. var objectKeys = require('../internals/object-keys');
  33513. var getOwnPropertySymbolsModule = require('../internals/object-get-own-property-symbols');
  33514. var propertyIsEnumerableModule = require('../internals/object-property-is-enumerable');
  33515. var toObject = require('../internals/to-object');
  33516. var IndexedObject = require('../internals/indexed-object');
  33517. var nativeAssign = Object.assign;
  33518. var defineProperty = Object.defineProperty;
  33519. // `Object.assign` method
  33520. // https://tc39.github.io/ecma262/#sec-object.assign
  33521. module.exports = !nativeAssign || fails(function () {
  33522. // should have correct order of operations (Edge bug)
  33523. if (DESCRIPTORS && nativeAssign({ b: 1 }, nativeAssign(defineProperty({}, 'a', {
  33524. enumerable: true,
  33525. get: function () {
  33526. defineProperty(this, 'b', {
  33527. value: 3,
  33528. enumerable: false
  33529. });
  33530. }
  33531. }), { b: 2 })).b !== 1) return true;
  33532. // should work with symbols and should have deterministic property order (V8 bug)
  33533. var A = {};
  33534. var B = {};
  33535. // eslint-disable-next-line no-undef
  33536. var symbol = Symbol();
  33537. var alphabet = 'abcdefghijklmnopqrst';
  33538. A[symbol] = 7;
  33539. alphabet.split('').forEach(function (chr) { B[chr] = chr; });
  33540. return nativeAssign({}, A)[symbol] != 7 || objectKeys(nativeAssign({}, B)).join('') != alphabet;
  33541. }) ? function assign(target, source) { // eslint-disable-line no-unused-vars
  33542. var T = toObject(target);
  33543. var argumentsLength = arguments.length;
  33544. var index = 1;
  33545. var getOwnPropertySymbols = getOwnPropertySymbolsModule.f;
  33546. var propertyIsEnumerable = propertyIsEnumerableModule.f;
  33547. while (argumentsLength > index) {
  33548. var S = IndexedObject(arguments[index++]);
  33549. var keys = getOwnPropertySymbols ? objectKeys(S).concat(getOwnPropertySymbols(S)) : objectKeys(S);
  33550. var length = keys.length;
  33551. var j = 0;
  33552. var key;
  33553. while (length > j) {
  33554. key = keys[j++];
  33555. if (!DESCRIPTORS || propertyIsEnumerable.call(S, key)) T[key] = S[key];
  33556. }
  33557. } return T;
  33558. } : nativeAssign;
  33559. },{"../internals/descriptors":240,"../internals/fails":247,"../internals/indexed-object":257,"../internals/object-get-own-property-symbols":282,"../internals/object-keys":285,"../internals/object-property-is-enumerable":286,"../internals/to-object":308}],276:[function(require,module,exports){
  33560. var anObject = require('../internals/an-object');
  33561. var defineProperties = require('../internals/object-define-properties');
  33562. var enumBugKeys = require('../internals/enum-bug-keys');
  33563. var hiddenKeys = require('../internals/hidden-keys');
  33564. var html = require('../internals/html');
  33565. var documentCreateElement = require('../internals/document-create-element');
  33566. var sharedKey = require('../internals/shared-key');
  33567. var GT = '>';
  33568. var LT = '<';
  33569. var PROTOTYPE = 'prototype';
  33570. var SCRIPT = 'script';
  33571. var IE_PROTO = sharedKey('IE_PROTO');
  33572. var EmptyConstructor = function () { /* empty */ };
  33573. var scriptTag = function (content) {
  33574. return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT;
  33575. };
  33576. // Create object with fake `null` prototype: use ActiveX Object with cleared prototype
  33577. var NullProtoObjectViaActiveX = function (activeXDocument) {
  33578. activeXDocument.write(scriptTag(''));
  33579. activeXDocument.close();
  33580. var temp = activeXDocument.parentWindow.Object;
  33581. activeXDocument = null; // avoid memory leak
  33582. return temp;
  33583. };
  33584. // Create object with fake `null` prototype: use iframe Object with cleared prototype
  33585. var NullProtoObjectViaIFrame = function () {
  33586. // Thrash, waste and sodomy: IE GC bug
  33587. var iframe = documentCreateElement('iframe');
  33588. var JS = 'java' + SCRIPT + ':';
  33589. var iframeDocument;
  33590. iframe.style.display = 'none';
  33591. html.appendChild(iframe);
  33592. // https://github.com/zloirock/core-js/issues/475
  33593. iframe.src = String(JS);
  33594. iframeDocument = iframe.contentWindow.document;
  33595. iframeDocument.open();
  33596. iframeDocument.write(scriptTag('document.F=Object'));
  33597. iframeDocument.close();
  33598. return iframeDocument.F;
  33599. };
  33600. // Check for document.domain and active x support
  33601. // No need to use active x approach when document.domain is not set
  33602. // see https://github.com/es-shims/es5-shim/issues/150
  33603. // variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
  33604. // avoid IE GC bug
  33605. var activeXDocument;
  33606. var NullProtoObject = function () {
  33607. try {
  33608. /* global ActiveXObject */
  33609. activeXDocument = document.domain && new ActiveXObject('htmlfile');
  33610. } catch (error) { /* ignore */ }
  33611. NullProtoObject = activeXDocument ? NullProtoObjectViaActiveX(activeXDocument) : NullProtoObjectViaIFrame();
  33612. var length = enumBugKeys.length;
  33613. while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]];
  33614. return NullProtoObject();
  33615. };
  33616. hiddenKeys[IE_PROTO] = true;
  33617. // `Object.create` method
  33618. // https://tc39.github.io/ecma262/#sec-object.create
  33619. module.exports = Object.create || function create(O, Properties) {
  33620. var result;
  33621. if (O !== null) {
  33622. EmptyConstructor[PROTOTYPE] = anObject(O);
  33623. result = new EmptyConstructor();
  33624. EmptyConstructor[PROTOTYPE] = null;
  33625. // add "__proto__" for Object.getPrototypeOf polyfill
  33626. result[IE_PROTO] = O;
  33627. } else result = NullProtoObject();
  33628. return Properties === undefined ? result : defineProperties(result, Properties);
  33629. };
  33630. },{"../internals/an-object":223,"../internals/document-create-element":241,"../internals/enum-bug-keys":245,"../internals/hidden-keys":253,"../internals/html":255,"../internals/object-define-properties":277,"../internals/shared-key":299}],277:[function(require,module,exports){
  33631. var DESCRIPTORS = require('../internals/descriptors');
  33632. var definePropertyModule = require('../internals/object-define-property');
  33633. var anObject = require('../internals/an-object');
  33634. var objectKeys = require('../internals/object-keys');
  33635. // `Object.defineProperties` method
  33636. // https://tc39.github.io/ecma262/#sec-object.defineproperties
  33637. module.exports = DESCRIPTORS ? Object.defineProperties : function defineProperties(O, Properties) {
  33638. anObject(O);
  33639. var keys = objectKeys(Properties);
  33640. var length = keys.length;
  33641. var index = 0;
  33642. var key;
  33643. while (length > index) definePropertyModule.f(O, key = keys[index++], Properties[key]);
  33644. return O;
  33645. };
  33646. },{"../internals/an-object":223,"../internals/descriptors":240,"../internals/object-define-property":278,"../internals/object-keys":285}],278:[function(require,module,exports){
  33647. var DESCRIPTORS = require('../internals/descriptors');
  33648. var IE8_DOM_DEFINE = require('../internals/ie8-dom-define');
  33649. var anObject = require('../internals/an-object');
  33650. var toPrimitive = require('../internals/to-primitive');
  33651. var nativeDefineProperty = Object.defineProperty;
  33652. // `Object.defineProperty` method
  33653. // https://tc39.github.io/ecma262/#sec-object.defineproperty
  33654. exports.f = DESCRIPTORS ? nativeDefineProperty : function defineProperty(O, P, Attributes) {
  33655. anObject(O);
  33656. P = toPrimitive(P, true);
  33657. anObject(Attributes);
  33658. if (IE8_DOM_DEFINE) try {
  33659. return nativeDefineProperty(O, P, Attributes);
  33660. } catch (error) { /* empty */ }
  33661. if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported');
  33662. if ('value' in Attributes) O[P] = Attributes.value;
  33663. return O;
  33664. };
  33665. },{"../internals/an-object":223,"../internals/descriptors":240,"../internals/ie8-dom-define":256,"../internals/to-primitive":309}],279:[function(require,module,exports){
  33666. var DESCRIPTORS = require('../internals/descriptors');
  33667. var propertyIsEnumerableModule = require('../internals/object-property-is-enumerable');
  33668. var createPropertyDescriptor = require('../internals/create-property-descriptor');
  33669. var toIndexedObject = require('../internals/to-indexed-object');
  33670. var toPrimitive = require('../internals/to-primitive');
  33671. var has = require('../internals/has');
  33672. var IE8_DOM_DEFINE = require('../internals/ie8-dom-define');
  33673. var nativeGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  33674. // `Object.getOwnPropertyDescriptor` method
  33675. // https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptor
  33676. exports.f = DESCRIPTORS ? nativeGetOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) {
  33677. O = toIndexedObject(O);
  33678. P = toPrimitive(P, true);
  33679. if (IE8_DOM_DEFINE) try {
  33680. return nativeGetOwnPropertyDescriptor(O, P);
  33681. } catch (error) { /* empty */ }
  33682. if (has(O, P)) return createPropertyDescriptor(!propertyIsEnumerableModule.f.call(O, P), O[P]);
  33683. };
  33684. },{"../internals/create-property-descriptor":237,"../internals/descriptors":240,"../internals/has":252,"../internals/ie8-dom-define":256,"../internals/object-property-is-enumerable":286,"../internals/to-indexed-object":305,"../internals/to-primitive":309}],280:[function(require,module,exports){
  33685. var toIndexedObject = require('../internals/to-indexed-object');
  33686. var nativeGetOwnPropertyNames = require('../internals/object-get-own-property-names').f;
  33687. var toString = {}.toString;
  33688. var windowNames = typeof window == 'object' && window && Object.getOwnPropertyNames
  33689. ? Object.getOwnPropertyNames(window) : [];
  33690. var getWindowNames = function (it) {
  33691. try {
  33692. return nativeGetOwnPropertyNames(it);
  33693. } catch (error) {
  33694. return windowNames.slice();
  33695. }
  33696. };
  33697. // fallback for IE11 buggy Object.getOwnPropertyNames with iframe and window
  33698. module.exports.f = function getOwnPropertyNames(it) {
  33699. return windowNames && toString.call(it) == '[object Window]'
  33700. ? getWindowNames(it)
  33701. : nativeGetOwnPropertyNames(toIndexedObject(it));
  33702. };
  33703. },{"../internals/object-get-own-property-names":281,"../internals/to-indexed-object":305}],281:[function(require,module,exports){
  33704. var internalObjectKeys = require('../internals/object-keys-internal');
  33705. var enumBugKeys = require('../internals/enum-bug-keys');
  33706. var hiddenKeys = enumBugKeys.concat('length', 'prototype');
  33707. // `Object.getOwnPropertyNames` method
  33708. // https://tc39.github.io/ecma262/#sec-object.getownpropertynames
  33709. exports.f = Object.getOwnPropertyNames || function getOwnPropertyNames(O) {
  33710. return internalObjectKeys(O, hiddenKeys);
  33711. };
  33712. },{"../internals/enum-bug-keys":245,"../internals/object-keys-internal":284}],282:[function(require,module,exports){
  33713. exports.f = Object.getOwnPropertySymbols;
  33714. },{}],283:[function(require,module,exports){
  33715. var has = require('../internals/has');
  33716. var toObject = require('../internals/to-object');
  33717. var sharedKey = require('../internals/shared-key');
  33718. var CORRECT_PROTOTYPE_GETTER = require('../internals/correct-prototype-getter');
  33719. var IE_PROTO = sharedKey('IE_PROTO');
  33720. var ObjectPrototype = Object.prototype;
  33721. // `Object.getPrototypeOf` method
  33722. // https://tc39.github.io/ecma262/#sec-object.getprototypeof
  33723. module.exports = CORRECT_PROTOTYPE_GETTER ? Object.getPrototypeOf : function (O) {
  33724. O = toObject(O);
  33725. if (has(O, IE_PROTO)) return O[IE_PROTO];
  33726. if (typeof O.constructor == 'function' && O instanceof O.constructor) {
  33727. return O.constructor.prototype;
  33728. } return O instanceof Object ? ObjectPrototype : null;
  33729. };
  33730. },{"../internals/correct-prototype-getter":234,"../internals/has":252,"../internals/shared-key":299,"../internals/to-object":308}],284:[function(require,module,exports){
  33731. var has = require('../internals/has');
  33732. var toIndexedObject = require('../internals/to-indexed-object');
  33733. var indexOf = require('../internals/array-includes').indexOf;
  33734. var hiddenKeys = require('../internals/hidden-keys');
  33735. module.exports = function (object, names) {
  33736. var O = toIndexedObject(object);
  33737. var i = 0;
  33738. var result = [];
  33739. var key;
  33740. for (key in O) !has(hiddenKeys, key) && has(O, key) && result.push(key);
  33741. // Don't enum bug & hidden keys
  33742. while (names.length > i) if (has(O, key = names[i++])) {
  33743. ~indexOf(result, key) || result.push(key);
  33744. }
  33745. return result;
  33746. };
  33747. },{"../internals/array-includes":224,"../internals/has":252,"../internals/hidden-keys":253,"../internals/to-indexed-object":305}],285:[function(require,module,exports){
  33748. var internalObjectKeys = require('../internals/object-keys-internal');
  33749. var enumBugKeys = require('../internals/enum-bug-keys');
  33750. // `Object.keys` method
  33751. // https://tc39.github.io/ecma262/#sec-object.keys
  33752. module.exports = Object.keys || function keys(O) {
  33753. return internalObjectKeys(O, enumBugKeys);
  33754. };
  33755. },{"../internals/enum-bug-keys":245,"../internals/object-keys-internal":284}],286:[function(require,module,exports){
  33756. 'use strict';
  33757. var nativePropertyIsEnumerable = {}.propertyIsEnumerable;
  33758. var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  33759. // Nashorn ~ JDK8 bug
  33760. var NASHORN_BUG = getOwnPropertyDescriptor && !nativePropertyIsEnumerable.call({ 1: 2 }, 1);
  33761. // `Object.prototype.propertyIsEnumerable` method implementation
  33762. // https://tc39.github.io/ecma262/#sec-object.prototype.propertyisenumerable
  33763. exports.f = NASHORN_BUG ? function propertyIsEnumerable(V) {
  33764. var descriptor = getOwnPropertyDescriptor(this, V);
  33765. return !!descriptor && descriptor.enumerable;
  33766. } : nativePropertyIsEnumerable;
  33767. },{}],287:[function(require,module,exports){
  33768. var anObject = require('../internals/an-object');
  33769. var aPossiblePrototype = require('../internals/a-possible-prototype');
  33770. // `Object.setPrototypeOf` method
  33771. // https://tc39.github.io/ecma262/#sec-object.setprototypeof
  33772. // Works with __proto__ only. Old v8 can't work with null proto objects.
  33773. /* eslint-disable no-proto */
  33774. module.exports = Object.setPrototypeOf || ('__proto__' in {} ? function () {
  33775. var CORRECT_SETTER = false;
  33776. var test = {};
  33777. var setter;
  33778. try {
  33779. setter = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set;
  33780. setter.call(test, []);
  33781. CORRECT_SETTER = test instanceof Array;
  33782. } catch (error) { /* empty */ }
  33783. return function setPrototypeOf(O, proto) {
  33784. anObject(O);
  33785. aPossiblePrototype(proto);
  33786. if (CORRECT_SETTER) setter.call(O, proto);
  33787. else O.__proto__ = proto;
  33788. return O;
  33789. };
  33790. }() : undefined);
  33791. },{"../internals/a-possible-prototype":220,"../internals/an-object":223}],288:[function(require,module,exports){
  33792. var DESCRIPTORS = require('../internals/descriptors');
  33793. var objectKeys = require('../internals/object-keys');
  33794. var toIndexedObject = require('../internals/to-indexed-object');
  33795. var propertyIsEnumerable = require('../internals/object-property-is-enumerable').f;
  33796. // `Object.{ entries, values }` methods implementation
  33797. var createMethod = function (TO_ENTRIES) {
  33798. return function (it) {
  33799. var O = toIndexedObject(it);
  33800. var keys = objectKeys(O);
  33801. var length = keys.length;
  33802. var i = 0;
  33803. var result = [];
  33804. var key;
  33805. while (length > i) {
  33806. key = keys[i++];
  33807. if (!DESCRIPTORS || propertyIsEnumerable.call(O, key)) {
  33808. result.push(TO_ENTRIES ? [key, O[key]] : O[key]);
  33809. }
  33810. }
  33811. return result;
  33812. };
  33813. };
  33814. module.exports = {
  33815. // `Object.entries` method
  33816. // https://tc39.github.io/ecma262/#sec-object.entries
  33817. entries: createMethod(true),
  33818. // `Object.values` method
  33819. // https://tc39.github.io/ecma262/#sec-object.values
  33820. values: createMethod(false)
  33821. };
  33822. },{"../internals/descriptors":240,"../internals/object-keys":285,"../internals/object-property-is-enumerable":286,"../internals/to-indexed-object":305}],289:[function(require,module,exports){
  33823. var getBuiltIn = require('../internals/get-built-in');
  33824. var getOwnPropertyNamesModule = require('../internals/object-get-own-property-names');
  33825. var getOwnPropertySymbolsModule = require('../internals/object-get-own-property-symbols');
  33826. var anObject = require('../internals/an-object');
  33827. // all object keys, includes non-enumerable and symbols
  33828. module.exports = getBuiltIn('Reflect', 'ownKeys') || function ownKeys(it) {
  33829. var keys = getOwnPropertyNamesModule.f(anObject(it));
  33830. var getOwnPropertySymbols = getOwnPropertySymbolsModule.f;
  33831. return getOwnPropertySymbols ? keys.concat(getOwnPropertySymbols(it)) : keys;
  33832. };
  33833. },{"../internals/an-object":223,"../internals/get-built-in":249,"../internals/object-get-own-property-names":281,"../internals/object-get-own-property-symbols":282}],290:[function(require,module,exports){
  33834. var global = require('../internals/global');
  33835. module.exports = global;
  33836. },{"../internals/global":251}],291:[function(require,module,exports){
  33837. module.exports = function (exec) {
  33838. try {
  33839. return { error: false, value: exec() };
  33840. } catch (error) {
  33841. return { error: true, value: error };
  33842. }
  33843. };
  33844. },{}],292:[function(require,module,exports){
  33845. var anObject = require('../internals/an-object');
  33846. var isObject = require('../internals/is-object');
  33847. var newPromiseCapability = require('../internals/new-promise-capability');
  33848. module.exports = function (C, x) {
  33849. anObject(C);
  33850. if (isObject(x) && x.constructor === C) return x;
  33851. var promiseCapability = newPromiseCapability.f(C);
  33852. var resolve = promiseCapability.resolve;
  33853. resolve(x);
  33854. return promiseCapability.promise;
  33855. };
  33856. },{"../internals/an-object":223,"../internals/is-object":263,"../internals/new-promise-capability":273}],293:[function(require,module,exports){
  33857. var redefine = require('../internals/redefine');
  33858. module.exports = function (target, src, options) {
  33859. for (var key in src) redefine(target, key, src[key], options);
  33860. return target;
  33861. };
  33862. },{"../internals/redefine":294}],294:[function(require,module,exports){
  33863. var global = require('../internals/global');
  33864. var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
  33865. var has = require('../internals/has');
  33866. var setGlobal = require('../internals/set-global');
  33867. var inspectSource = require('../internals/inspect-source');
  33868. var InternalStateModule = require('../internals/internal-state');
  33869. var getInternalState = InternalStateModule.get;
  33870. var enforceInternalState = InternalStateModule.enforce;
  33871. var TEMPLATE = String(String).split('String');
  33872. (module.exports = function (O, key, value, options) {
  33873. var unsafe = options ? !!options.unsafe : false;
  33874. var simple = options ? !!options.enumerable : false;
  33875. var noTargetGet = options ? !!options.noTargetGet : false;
  33876. if (typeof value == 'function') {
  33877. if (typeof key == 'string' && !has(value, 'name')) createNonEnumerableProperty(value, 'name', key);
  33878. enforceInternalState(value).source = TEMPLATE.join(typeof key == 'string' ? key : '');
  33879. }
  33880. if (O === global) {
  33881. if (simple) O[key] = value;
  33882. else setGlobal(key, value);
  33883. return;
  33884. } else if (!unsafe) {
  33885. delete O[key];
  33886. } else if (!noTargetGet && O[key]) {
  33887. simple = true;
  33888. }
  33889. if (simple) O[key] = value;
  33890. else createNonEnumerableProperty(O, key, value);
  33891. // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
  33892. })(Function.prototype, 'toString', function toString() {
  33893. return typeof this == 'function' && getInternalState(this).source || inspectSource(this);
  33894. });
  33895. },{"../internals/create-non-enumerable-property":236,"../internals/global":251,"../internals/has":252,"../internals/inspect-source":258,"../internals/internal-state":259,"../internals/set-global":296}],295:[function(require,module,exports){
  33896. // `RequireObjectCoercible` abstract operation
  33897. // https://tc39.github.io/ecma262/#sec-requireobjectcoercible
  33898. module.exports = function (it) {
  33899. if (it == undefined) throw TypeError("Can't call method on " + it);
  33900. return it;
  33901. };
  33902. },{}],296:[function(require,module,exports){
  33903. var global = require('../internals/global');
  33904. var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
  33905. module.exports = function (key, value) {
  33906. try {
  33907. createNonEnumerableProperty(global, key, value);
  33908. } catch (error) {
  33909. global[key] = value;
  33910. } return value;
  33911. };
  33912. },{"../internals/create-non-enumerable-property":236,"../internals/global":251}],297:[function(require,module,exports){
  33913. 'use strict';
  33914. var getBuiltIn = require('../internals/get-built-in');
  33915. var definePropertyModule = require('../internals/object-define-property');
  33916. var wellKnownSymbol = require('../internals/well-known-symbol');
  33917. var DESCRIPTORS = require('../internals/descriptors');
  33918. var SPECIES = wellKnownSymbol('species');
  33919. module.exports = function (CONSTRUCTOR_NAME) {
  33920. var Constructor = getBuiltIn(CONSTRUCTOR_NAME);
  33921. var defineProperty = definePropertyModule.f;
  33922. if (DESCRIPTORS && Constructor && !Constructor[SPECIES]) {
  33923. defineProperty(Constructor, SPECIES, {
  33924. configurable: true,
  33925. get: function () { return this; }
  33926. });
  33927. }
  33928. };
  33929. },{"../internals/descriptors":240,"../internals/get-built-in":249,"../internals/object-define-property":278,"../internals/well-known-symbol":314}],298:[function(require,module,exports){
  33930. var defineProperty = require('../internals/object-define-property').f;
  33931. var has = require('../internals/has');
  33932. var wellKnownSymbol = require('../internals/well-known-symbol');
  33933. var TO_STRING_TAG = wellKnownSymbol('toStringTag');
  33934. module.exports = function (it, TAG, STATIC) {
  33935. if (it && !has(it = STATIC ? it : it.prototype, TO_STRING_TAG)) {
  33936. defineProperty(it, TO_STRING_TAG, { configurable: true, value: TAG });
  33937. }
  33938. };
  33939. },{"../internals/has":252,"../internals/object-define-property":278,"../internals/well-known-symbol":314}],299:[function(require,module,exports){
  33940. var shared = require('../internals/shared');
  33941. var uid = require('../internals/uid');
  33942. var keys = shared('keys');
  33943. module.exports = function (key) {
  33944. return keys[key] || (keys[key] = uid(key));
  33945. };
  33946. },{"../internals/shared":301,"../internals/uid":311}],300:[function(require,module,exports){
  33947. var global = require('../internals/global');
  33948. var setGlobal = require('../internals/set-global');
  33949. var SHARED = '__core-js_shared__';
  33950. var store = global[SHARED] || setGlobal(SHARED, {});
  33951. module.exports = store;
  33952. },{"../internals/global":251,"../internals/set-global":296}],301:[function(require,module,exports){
  33953. var IS_PURE = require('../internals/is-pure');
  33954. var store = require('../internals/shared-store');
  33955. (module.exports = function (key, value) {
  33956. return store[key] || (store[key] = value !== undefined ? value : {});
  33957. })('versions', []).push({
  33958. version: '3.6.5',
  33959. mode: IS_PURE ? 'pure' : 'global',
  33960. copyright: '© 2020 Denis Pushkarev (zloirock.ru)'
  33961. });
  33962. },{"../internals/is-pure":264,"../internals/shared-store":300}],302:[function(require,module,exports){
  33963. var anObject = require('../internals/an-object');
  33964. var aFunction = require('../internals/a-function');
  33965. var wellKnownSymbol = require('../internals/well-known-symbol');
  33966. var SPECIES = wellKnownSymbol('species');
  33967. // `SpeciesConstructor` abstract operation
  33968. // https://tc39.github.io/ecma262/#sec-speciesconstructor
  33969. module.exports = function (O, defaultConstructor) {
  33970. var C = anObject(O).constructor;
  33971. var S;
  33972. return C === undefined || (S = anObject(C)[SPECIES]) == undefined ? defaultConstructor : aFunction(S);
  33973. };
  33974. },{"../internals/a-function":219,"../internals/an-object":223,"../internals/well-known-symbol":314}],303:[function(require,module,exports){
  33975. var global = require('../internals/global');
  33976. var fails = require('../internals/fails');
  33977. var classof = require('../internals/classof-raw');
  33978. var bind = require('../internals/function-bind-context');
  33979. var html = require('../internals/html');
  33980. var createElement = require('../internals/document-create-element');
  33981. var IS_IOS = require('../internals/engine-is-ios');
  33982. var location = global.location;
  33983. var set = global.setImmediate;
  33984. var clear = global.clearImmediate;
  33985. var process = global.process;
  33986. var MessageChannel = global.MessageChannel;
  33987. var Dispatch = global.Dispatch;
  33988. var counter = 0;
  33989. var queue = {};
  33990. var ONREADYSTATECHANGE = 'onreadystatechange';
  33991. var defer, channel, port;
  33992. var run = function (id) {
  33993. // eslint-disable-next-line no-prototype-builtins
  33994. if (queue.hasOwnProperty(id)) {
  33995. var fn = queue[id];
  33996. delete queue[id];
  33997. fn();
  33998. }
  33999. };
  34000. var runner = function (id) {
  34001. return function () {
  34002. run(id);
  34003. };
  34004. };
  34005. var listener = function (event) {
  34006. run(event.data);
  34007. };
  34008. var post = function (id) {
  34009. // old engines have not location.origin
  34010. global.postMessage(id + '', location.protocol + '//' + location.host);
  34011. };
  34012. // Node.js 0.9+ & IE10+ has setImmediate, otherwise:
  34013. if (!set || !clear) {
  34014. set = function setImmediate(fn) {
  34015. var args = [];
  34016. var i = 1;
  34017. while (arguments.length > i) args.push(arguments[i++]);
  34018. queue[++counter] = function () {
  34019. // eslint-disable-next-line no-new-func
  34020. (typeof fn == 'function' ? fn : Function(fn)).apply(undefined, args);
  34021. };
  34022. defer(counter);
  34023. return counter;
  34024. };
  34025. clear = function clearImmediate(id) {
  34026. delete queue[id];
  34027. };
  34028. // Node.js 0.8-
  34029. if (classof(process) == 'process') {
  34030. defer = function (id) {
  34031. process.nextTick(runner(id));
  34032. };
  34033. // Sphere (JS game engine) Dispatch API
  34034. } else if (Dispatch && Dispatch.now) {
  34035. defer = function (id) {
  34036. Dispatch.now(runner(id));
  34037. };
  34038. // Browsers with MessageChannel, includes WebWorkers
  34039. // except iOS - https://github.com/zloirock/core-js/issues/624
  34040. } else if (MessageChannel && !IS_IOS) {
  34041. channel = new MessageChannel();
  34042. port = channel.port2;
  34043. channel.port1.onmessage = listener;
  34044. defer = bind(port.postMessage, port, 1);
  34045. // Browsers with postMessage, skip WebWorkers
  34046. // IE8 has postMessage, but it's sync & typeof its postMessage is 'object'
  34047. } else if (
  34048. global.addEventListener &&
  34049. typeof postMessage == 'function' &&
  34050. !global.importScripts &&
  34051. !fails(post) &&
  34052. location.protocol !== 'file:'
  34053. ) {
  34054. defer = post;
  34055. global.addEventListener('message', listener, false);
  34056. // IE8-
  34057. } else if (ONREADYSTATECHANGE in createElement('script')) {
  34058. defer = function (id) {
  34059. html.appendChild(createElement('script'))[ONREADYSTATECHANGE] = function () {
  34060. html.removeChild(this);
  34061. run(id);
  34062. };
  34063. };
  34064. // Rest old browsers
  34065. } else {
  34066. defer = function (id) {
  34067. setTimeout(runner(id), 0);
  34068. };
  34069. }
  34070. }
  34071. module.exports = {
  34072. set: set,
  34073. clear: clear
  34074. };
  34075. },{"../internals/classof-raw":230,"../internals/document-create-element":241,"../internals/engine-is-ios":242,"../internals/fails":247,"../internals/function-bind-context":248,"../internals/global":251,"../internals/html":255}],304:[function(require,module,exports){
  34076. var toInteger = require('../internals/to-integer');
  34077. var max = Math.max;
  34078. var min = Math.min;
  34079. // Helper for a popular repeating case of the spec:
  34080. // Let integer be ? ToInteger(index).
  34081. // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length).
  34082. module.exports = function (index, length) {
  34083. var integer = toInteger(index);
  34084. return integer < 0 ? max(integer + length, 0) : min(integer, length);
  34085. };
  34086. },{"../internals/to-integer":306}],305:[function(require,module,exports){
  34087. // toObject with fallback for non-array-like ES3 strings
  34088. var IndexedObject = require('../internals/indexed-object');
  34089. var requireObjectCoercible = require('../internals/require-object-coercible');
  34090. module.exports = function (it) {
  34091. return IndexedObject(requireObjectCoercible(it));
  34092. };
  34093. },{"../internals/indexed-object":257,"../internals/require-object-coercible":295}],306:[function(require,module,exports){
  34094. var ceil = Math.ceil;
  34095. var floor = Math.floor;
  34096. // `ToInteger` abstract operation
  34097. // https://tc39.github.io/ecma262/#sec-tointeger
  34098. module.exports = function (argument) {
  34099. return isNaN(argument = +argument) ? 0 : (argument > 0 ? floor : ceil)(argument);
  34100. };
  34101. },{}],307:[function(require,module,exports){
  34102. var toInteger = require('../internals/to-integer');
  34103. var min = Math.min;
  34104. // `ToLength` abstract operation
  34105. // https://tc39.github.io/ecma262/#sec-tolength
  34106. module.exports = function (argument) {
  34107. return argument > 0 ? min(toInteger(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991
  34108. };
  34109. },{"../internals/to-integer":306}],308:[function(require,module,exports){
  34110. var requireObjectCoercible = require('../internals/require-object-coercible');
  34111. // `ToObject` abstract operation
  34112. // https://tc39.github.io/ecma262/#sec-toobject
  34113. module.exports = function (argument) {
  34114. return Object(requireObjectCoercible(argument));
  34115. };
  34116. },{"../internals/require-object-coercible":295}],309:[function(require,module,exports){
  34117. var isObject = require('../internals/is-object');
  34118. // `ToPrimitive` abstract operation
  34119. // https://tc39.github.io/ecma262/#sec-toprimitive
  34120. // instead of the ES6 spec version, we didn't implement @@toPrimitive case
  34121. // and the second argument - flag - preferred type is a string
  34122. module.exports = function (input, PREFERRED_STRING) {
  34123. if (!isObject(input)) return input;
  34124. var fn, val;
  34125. if (PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
  34126. if (typeof (fn = input.valueOf) == 'function' && !isObject(val = fn.call(input))) return val;
  34127. if (!PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
  34128. throw TypeError("Can't convert object to primitive value");
  34129. };
  34130. },{"../internals/is-object":263}],310:[function(require,module,exports){
  34131. var wellKnownSymbol = require('../internals/well-known-symbol');
  34132. var TO_STRING_TAG = wellKnownSymbol('toStringTag');
  34133. var test = {};
  34134. test[TO_STRING_TAG] = 'z';
  34135. module.exports = String(test) === '[object z]';
  34136. },{"../internals/well-known-symbol":314}],311:[function(require,module,exports){
  34137. var id = 0;
  34138. var postfix = Math.random();
  34139. module.exports = function (key) {
  34140. return 'Symbol(' + String(key === undefined ? '' : key) + ')_' + (++id + postfix).toString(36);
  34141. };
  34142. },{}],312:[function(require,module,exports){
  34143. var NATIVE_SYMBOL = require('../internals/native-symbol');
  34144. module.exports = NATIVE_SYMBOL
  34145. // eslint-disable-next-line no-undef
  34146. && !Symbol.sham
  34147. // eslint-disable-next-line no-undef
  34148. && typeof Symbol.iterator == 'symbol';
  34149. },{"../internals/native-symbol":271}],313:[function(require,module,exports){
  34150. var wellKnownSymbol = require('../internals/well-known-symbol');
  34151. exports.f = wellKnownSymbol;
  34152. },{"../internals/well-known-symbol":314}],314:[function(require,module,exports){
  34153. var global = require('../internals/global');
  34154. var shared = require('../internals/shared');
  34155. var has = require('../internals/has');
  34156. var uid = require('../internals/uid');
  34157. var NATIVE_SYMBOL = require('../internals/native-symbol');
  34158. var USE_SYMBOL_AS_UID = require('../internals/use-symbol-as-uid');
  34159. var WellKnownSymbolsStore = shared('wks');
  34160. var Symbol = global.Symbol;
  34161. var createWellKnownSymbol = USE_SYMBOL_AS_UID ? Symbol : Symbol && Symbol.withoutSetter || uid;
  34162. module.exports = function (name) {
  34163. if (!has(WellKnownSymbolsStore, name)) {
  34164. if (NATIVE_SYMBOL && has(Symbol, name)) WellKnownSymbolsStore[name] = Symbol[name];
  34165. else WellKnownSymbolsStore[name] = createWellKnownSymbol('Symbol.' + name);
  34166. } return WellKnownSymbolsStore[name];
  34167. };
  34168. },{"../internals/global":251,"../internals/has":252,"../internals/native-symbol":271,"../internals/shared":301,"../internals/uid":311,"../internals/use-symbol-as-uid":312}],315:[function(require,module,exports){
  34169. 'use strict';
  34170. var $ = require('../internals/export');
  34171. var $findIndex = require('../internals/array-iteration').findIndex;
  34172. var addToUnscopables = require('../internals/add-to-unscopables');
  34173. var arrayMethodUsesToLength = require('../internals/array-method-uses-to-length');
  34174. var FIND_INDEX = 'findIndex';
  34175. var SKIPS_HOLES = true;
  34176. var USES_TO_LENGTH = arrayMethodUsesToLength(FIND_INDEX);
  34177. // Shouldn't skip holes
  34178. if (FIND_INDEX in []) Array(1)[FIND_INDEX](function () { SKIPS_HOLES = false; });
  34179. // `Array.prototype.findIndex` method
  34180. // https://tc39.github.io/ecma262/#sec-array.prototype.findindex
  34181. $({ target: 'Array', proto: true, forced: SKIPS_HOLES || !USES_TO_LENGTH }, {
  34182. findIndex: function findIndex(callbackfn /* , that = undefined */) {
  34183. return $findIndex(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
  34184. }
  34185. });
  34186. // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables
  34187. addToUnscopables(FIND_INDEX);
  34188. },{"../internals/add-to-unscopables":221,"../internals/array-iteration":225,"../internals/array-method-uses-to-length":226,"../internals/export":246}],316:[function(require,module,exports){
  34189. 'use strict';
  34190. var $ = require('../internals/export');
  34191. var $find = require('../internals/array-iteration').find;
  34192. var addToUnscopables = require('../internals/add-to-unscopables');
  34193. var arrayMethodUsesToLength = require('../internals/array-method-uses-to-length');
  34194. var FIND = 'find';
  34195. var SKIPS_HOLES = true;
  34196. var USES_TO_LENGTH = arrayMethodUsesToLength(FIND);
  34197. // Shouldn't skip holes
  34198. if (FIND in []) Array(1)[FIND](function () { SKIPS_HOLES = false; });
  34199. // `Array.prototype.find` method
  34200. // https://tc39.github.io/ecma262/#sec-array.prototype.find
  34201. $({ target: 'Array', proto: true, forced: SKIPS_HOLES || !USES_TO_LENGTH }, {
  34202. find: function find(callbackfn /* , that = undefined */) {
  34203. return $find(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
  34204. }
  34205. });
  34206. // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables
  34207. addToUnscopables(FIND);
  34208. },{"../internals/add-to-unscopables":221,"../internals/array-iteration":225,"../internals/array-method-uses-to-length":226,"../internals/export":246}],317:[function(require,module,exports){
  34209. 'use strict';
  34210. var $ = require('../internals/export');
  34211. var $includes = require('../internals/array-includes').includes;
  34212. var addToUnscopables = require('../internals/add-to-unscopables');
  34213. var arrayMethodUsesToLength = require('../internals/array-method-uses-to-length');
  34214. var USES_TO_LENGTH = arrayMethodUsesToLength('indexOf', { ACCESSORS: true, 1: 0 });
  34215. // `Array.prototype.includes` method
  34216. // https://tc39.github.io/ecma262/#sec-array.prototype.includes
  34217. $({ target: 'Array', proto: true, forced: !USES_TO_LENGTH }, {
  34218. includes: function includes(el /* , fromIndex = 0 */) {
  34219. return $includes(this, el, arguments.length > 1 ? arguments[1] : undefined);
  34220. }
  34221. });
  34222. // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables
  34223. addToUnscopables('includes');
  34224. },{"../internals/add-to-unscopables":221,"../internals/array-includes":224,"../internals/array-method-uses-to-length":226,"../internals/export":246}],318:[function(require,module,exports){
  34225. 'use strict';
  34226. var toIndexedObject = require('../internals/to-indexed-object');
  34227. var addToUnscopables = require('../internals/add-to-unscopables');
  34228. var Iterators = require('../internals/iterators');
  34229. var InternalStateModule = require('../internals/internal-state');
  34230. var defineIterator = require('../internals/define-iterator');
  34231. var ARRAY_ITERATOR = 'Array Iterator';
  34232. var setInternalState = InternalStateModule.set;
  34233. var getInternalState = InternalStateModule.getterFor(ARRAY_ITERATOR);
  34234. // `Array.prototype.entries` method
  34235. // https://tc39.github.io/ecma262/#sec-array.prototype.entries
  34236. // `Array.prototype.keys` method
  34237. // https://tc39.github.io/ecma262/#sec-array.prototype.keys
  34238. // `Array.prototype.values` method
  34239. // https://tc39.github.io/ecma262/#sec-array.prototype.values
  34240. // `Array.prototype[@@iterator]` method
  34241. // https://tc39.github.io/ecma262/#sec-array.prototype-@@iterator
  34242. // `CreateArrayIterator` internal method
  34243. // https://tc39.github.io/ecma262/#sec-createarrayiterator
  34244. module.exports = defineIterator(Array, 'Array', function (iterated, kind) {
  34245. setInternalState(this, {
  34246. type: ARRAY_ITERATOR,
  34247. target: toIndexedObject(iterated), // target
  34248. index: 0, // next index
  34249. kind: kind // kind
  34250. });
  34251. // `%ArrayIteratorPrototype%.next` method
  34252. // https://tc39.github.io/ecma262/#sec-%arrayiteratorprototype%.next
  34253. }, function () {
  34254. var state = getInternalState(this);
  34255. var target = state.target;
  34256. var kind = state.kind;
  34257. var index = state.index++;
  34258. if (!target || index >= target.length) {
  34259. state.target = undefined;
  34260. return { value: undefined, done: true };
  34261. }
  34262. if (kind == 'keys') return { value: index, done: false };
  34263. if (kind == 'values') return { value: target[index], done: false };
  34264. return { value: [index, target[index]], done: false };
  34265. }, 'values');
  34266. // argumentsList[@@iterator] is %ArrayProto_values%
  34267. // https://tc39.github.io/ecma262/#sec-createunmappedargumentsobject
  34268. // https://tc39.github.io/ecma262/#sec-createmappedargumentsobject
  34269. Iterators.Arguments = Iterators.Array;
  34270. // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables
  34271. addToUnscopables('keys');
  34272. addToUnscopables('values');
  34273. addToUnscopables('entries');
  34274. },{"../internals/add-to-unscopables":221,"../internals/define-iterator":238,"../internals/internal-state":259,"../internals/iterators":268,"../internals/to-indexed-object":305}],319:[function(require,module,exports){
  34275. var $ = require('../internals/export');
  34276. // `Number.isNaN` method
  34277. // https://tc39.github.io/ecma262/#sec-number.isnan
  34278. $({ target: 'Number', stat: true }, {
  34279. isNaN: function isNaN(number) {
  34280. // eslint-disable-next-line no-self-compare
  34281. return number != number;
  34282. }
  34283. });
  34284. },{"../internals/export":246}],320:[function(require,module,exports){
  34285. var $ = require('../internals/export');
  34286. var assign = require('../internals/object-assign');
  34287. // `Object.assign` method
  34288. // https://tc39.github.io/ecma262/#sec-object.assign
  34289. $({ target: 'Object', stat: true, forced: Object.assign !== assign }, {
  34290. assign: assign
  34291. });
  34292. },{"../internals/export":246,"../internals/object-assign":275}],321:[function(require,module,exports){
  34293. var $ = require('../internals/export');
  34294. var toObject = require('../internals/to-object');
  34295. var nativeKeys = require('../internals/object-keys');
  34296. var fails = require('../internals/fails');
  34297. var FAILS_ON_PRIMITIVES = fails(function () { nativeKeys(1); });
  34298. // `Object.keys` method
  34299. // https://tc39.github.io/ecma262/#sec-object.keys
  34300. $({ target: 'Object', stat: true, forced: FAILS_ON_PRIMITIVES }, {
  34301. keys: function keys(it) {
  34302. return nativeKeys(toObject(it));
  34303. }
  34304. });
  34305. },{"../internals/export":246,"../internals/fails":247,"../internals/object-keys":285,"../internals/to-object":308}],322:[function(require,module,exports){
  34306. var $ = require('../internals/export');
  34307. var $values = require('../internals/object-to-array').values;
  34308. // `Object.values` method
  34309. // https://tc39.github.io/ecma262/#sec-object.values
  34310. $({ target: 'Object', stat: true }, {
  34311. values: function values(O) {
  34312. return $values(O);
  34313. }
  34314. });
  34315. },{"../internals/export":246,"../internals/object-to-array":288}],323:[function(require,module,exports){
  34316. 'use strict';
  34317. var $ = require('../internals/export');
  34318. var IS_PURE = require('../internals/is-pure');
  34319. var global = require('../internals/global');
  34320. var getBuiltIn = require('../internals/get-built-in');
  34321. var NativePromise = require('../internals/native-promise-constructor');
  34322. var redefine = require('../internals/redefine');
  34323. var redefineAll = require('../internals/redefine-all');
  34324. var setToStringTag = require('../internals/set-to-string-tag');
  34325. var setSpecies = require('../internals/set-species');
  34326. var isObject = require('../internals/is-object');
  34327. var aFunction = require('../internals/a-function');
  34328. var anInstance = require('../internals/an-instance');
  34329. var classof = require('../internals/classof-raw');
  34330. var inspectSource = require('../internals/inspect-source');
  34331. var iterate = require('../internals/iterate');
  34332. var checkCorrectnessOfIteration = require('../internals/check-correctness-of-iteration');
  34333. var speciesConstructor = require('../internals/species-constructor');
  34334. var task = require('../internals/task').set;
  34335. var microtask = require('../internals/microtask');
  34336. var promiseResolve = require('../internals/promise-resolve');
  34337. var hostReportErrors = require('../internals/host-report-errors');
  34338. var newPromiseCapabilityModule = require('../internals/new-promise-capability');
  34339. var perform = require('../internals/perform');
  34340. var InternalStateModule = require('../internals/internal-state');
  34341. var isForced = require('../internals/is-forced');
  34342. var wellKnownSymbol = require('../internals/well-known-symbol');
  34343. var V8_VERSION = require('../internals/engine-v8-version');
  34344. var SPECIES = wellKnownSymbol('species');
  34345. var PROMISE = 'Promise';
  34346. var getInternalState = InternalStateModule.get;
  34347. var setInternalState = InternalStateModule.set;
  34348. var getInternalPromiseState = InternalStateModule.getterFor(PROMISE);
  34349. var PromiseConstructor = NativePromise;
  34350. var TypeError = global.TypeError;
  34351. var document = global.document;
  34352. var process = global.process;
  34353. var $fetch = getBuiltIn('fetch');
  34354. var newPromiseCapability = newPromiseCapabilityModule.f;
  34355. var newGenericPromiseCapability = newPromiseCapability;
  34356. var IS_NODE = classof(process) == 'process';
  34357. var DISPATCH_EVENT = !!(document && document.createEvent && global.dispatchEvent);
  34358. var UNHANDLED_REJECTION = 'unhandledrejection';
  34359. var REJECTION_HANDLED = 'rejectionhandled';
  34360. var PENDING = 0;
  34361. var FULFILLED = 1;
  34362. var REJECTED = 2;
  34363. var HANDLED = 1;
  34364. var UNHANDLED = 2;
  34365. var Internal, OwnPromiseCapability, PromiseWrapper, nativeThen;
  34366. var FORCED = isForced(PROMISE, function () {
  34367. var GLOBAL_CORE_JS_PROMISE = inspectSource(PromiseConstructor) !== String(PromiseConstructor);
  34368. if (!GLOBAL_CORE_JS_PROMISE) {
  34369. // V8 6.6 (Node 10 and Chrome 66) have a bug with resolving custom thenables
  34370. // https://bugs.chromium.org/p/chromium/issues/detail?id=830565
  34371. // We can't detect it synchronously, so just check versions
  34372. if (V8_VERSION === 66) return true;
  34373. // Unhandled rejections tracking support, NodeJS Promise without it fails @@species test
  34374. if (!IS_NODE && typeof PromiseRejectionEvent != 'function') return true;
  34375. }
  34376. // We need Promise#finally in the pure version for preventing prototype pollution
  34377. if (IS_PURE && !PromiseConstructor.prototype['finally']) return true;
  34378. // We can't use @@species feature detection in V8 since it causes
  34379. // deoptimization and performance degradation
  34380. // https://github.com/zloirock/core-js/issues/679
  34381. if (V8_VERSION >= 51 && /native code/.test(PromiseConstructor)) return false;
  34382. // Detect correctness of subclassing with @@species support
  34383. var promise = PromiseConstructor.resolve(1);
  34384. var FakePromise = function (exec) {
  34385. exec(function () { /* empty */ }, function () { /* empty */ });
  34386. };
  34387. var constructor = promise.constructor = {};
  34388. constructor[SPECIES] = FakePromise;
  34389. return !(promise.then(function () { /* empty */ }) instanceof FakePromise);
  34390. });
  34391. var INCORRECT_ITERATION = FORCED || !checkCorrectnessOfIteration(function (iterable) {
  34392. PromiseConstructor.all(iterable)['catch'](function () { /* empty */ });
  34393. });
  34394. // helpers
  34395. var isThenable = function (it) {
  34396. var then;
  34397. return isObject(it) && typeof (then = it.then) == 'function' ? then : false;
  34398. };
  34399. var notify = function (promise, state, isReject) {
  34400. if (state.notified) return;
  34401. state.notified = true;
  34402. var chain = state.reactions;
  34403. microtask(function () {
  34404. var value = state.value;
  34405. var ok = state.state == FULFILLED;
  34406. var index = 0;
  34407. // variable length - can't use forEach
  34408. while (chain.length > index) {
  34409. var reaction = chain[index++];
  34410. var handler = ok ? reaction.ok : reaction.fail;
  34411. var resolve = reaction.resolve;
  34412. var reject = reaction.reject;
  34413. var domain = reaction.domain;
  34414. var result, then, exited;
  34415. try {
  34416. if (handler) {
  34417. if (!ok) {
  34418. if (state.rejection === UNHANDLED) onHandleUnhandled(promise, state);
  34419. state.rejection = HANDLED;
  34420. }
  34421. if (handler === true) result = value;
  34422. else {
  34423. if (domain) domain.enter();
  34424. result = handler(value); // can throw
  34425. if (domain) {
  34426. domain.exit();
  34427. exited = true;
  34428. }
  34429. }
  34430. if (result === reaction.promise) {
  34431. reject(TypeError('Promise-chain cycle'));
  34432. } else if (then = isThenable(result)) {
  34433. then.call(result, resolve, reject);
  34434. } else resolve(result);
  34435. } else reject(value);
  34436. } catch (error) {
  34437. if (domain && !exited) domain.exit();
  34438. reject(error);
  34439. }
  34440. }
  34441. state.reactions = [];
  34442. state.notified = false;
  34443. if (isReject && !state.rejection) onUnhandled(promise, state);
  34444. });
  34445. };
  34446. var dispatchEvent = function (name, promise, reason) {
  34447. var event, handler;
  34448. if (DISPATCH_EVENT) {
  34449. event = document.createEvent('Event');
  34450. event.promise = promise;
  34451. event.reason = reason;
  34452. event.initEvent(name, false, true);
  34453. global.dispatchEvent(event);
  34454. } else event = { promise: promise, reason: reason };
  34455. if (handler = global['on' + name]) handler(event);
  34456. else if (name === UNHANDLED_REJECTION) hostReportErrors('Unhandled promise rejection', reason);
  34457. };
  34458. var onUnhandled = function (promise, state) {
  34459. task.call(global, function () {
  34460. var value = state.value;
  34461. var IS_UNHANDLED = isUnhandled(state);
  34462. var result;
  34463. if (IS_UNHANDLED) {
  34464. result = perform(function () {
  34465. if (IS_NODE) {
  34466. process.emit('unhandledRejection', value, promise);
  34467. } else dispatchEvent(UNHANDLED_REJECTION, promise, value);
  34468. });
  34469. // Browsers should not trigger `rejectionHandled` event if it was handled here, NodeJS - should
  34470. state.rejection = IS_NODE || isUnhandled(state) ? UNHANDLED : HANDLED;
  34471. if (result.error) throw result.value;
  34472. }
  34473. });
  34474. };
  34475. var isUnhandled = function (state) {
  34476. return state.rejection !== HANDLED && !state.parent;
  34477. };
  34478. var onHandleUnhandled = function (promise, state) {
  34479. task.call(global, function () {
  34480. if (IS_NODE) {
  34481. process.emit('rejectionHandled', promise);
  34482. } else dispatchEvent(REJECTION_HANDLED, promise, state.value);
  34483. });
  34484. };
  34485. var bind = function (fn, promise, state, unwrap) {
  34486. return function (value) {
  34487. fn(promise, state, value, unwrap);
  34488. };
  34489. };
  34490. var internalReject = function (promise, state, value, unwrap) {
  34491. if (state.done) return;
  34492. state.done = true;
  34493. if (unwrap) state = unwrap;
  34494. state.value = value;
  34495. state.state = REJECTED;
  34496. notify(promise, state, true);
  34497. };
  34498. var internalResolve = function (promise, state, value, unwrap) {
  34499. if (state.done) return;
  34500. state.done = true;
  34501. if (unwrap) state = unwrap;
  34502. try {
  34503. if (promise === value) throw TypeError("Promise can't be resolved itself");
  34504. var then = isThenable(value);
  34505. if (then) {
  34506. microtask(function () {
  34507. var wrapper = { done: false };
  34508. try {
  34509. then.call(value,
  34510. bind(internalResolve, promise, wrapper, state),
  34511. bind(internalReject, promise, wrapper, state)
  34512. );
  34513. } catch (error) {
  34514. internalReject(promise, wrapper, error, state);
  34515. }
  34516. });
  34517. } else {
  34518. state.value = value;
  34519. state.state = FULFILLED;
  34520. notify(promise, state, false);
  34521. }
  34522. } catch (error) {
  34523. internalReject(promise, { done: false }, error, state);
  34524. }
  34525. };
  34526. // constructor polyfill
  34527. if (FORCED) {
  34528. // 25.4.3.1 Promise(executor)
  34529. PromiseConstructor = function Promise(executor) {
  34530. anInstance(this, PromiseConstructor, PROMISE);
  34531. aFunction(executor);
  34532. Internal.call(this);
  34533. var state = getInternalState(this);
  34534. try {
  34535. executor(bind(internalResolve, this, state), bind(internalReject, this, state));
  34536. } catch (error) {
  34537. internalReject(this, state, error);
  34538. }
  34539. };
  34540. // eslint-disable-next-line no-unused-vars
  34541. Internal = function Promise(executor) {
  34542. setInternalState(this, {
  34543. type: PROMISE,
  34544. done: false,
  34545. notified: false,
  34546. parent: false,
  34547. reactions: [],
  34548. rejection: false,
  34549. state: PENDING,
  34550. value: undefined
  34551. });
  34552. };
  34553. Internal.prototype = redefineAll(PromiseConstructor.prototype, {
  34554. // `Promise.prototype.then` method
  34555. // https://tc39.github.io/ecma262/#sec-promise.prototype.then
  34556. then: function then(onFulfilled, onRejected) {
  34557. var state = getInternalPromiseState(this);
  34558. var reaction = newPromiseCapability(speciesConstructor(this, PromiseConstructor));
  34559. reaction.ok = typeof onFulfilled == 'function' ? onFulfilled : true;
  34560. reaction.fail = typeof onRejected == 'function' && onRejected;
  34561. reaction.domain = IS_NODE ? process.domain : undefined;
  34562. state.parent = true;
  34563. state.reactions.push(reaction);
  34564. if (state.state != PENDING) notify(this, state, false);
  34565. return reaction.promise;
  34566. },
  34567. // `Promise.prototype.catch` method
  34568. // https://tc39.github.io/ecma262/#sec-promise.prototype.catch
  34569. 'catch': function (onRejected) {
  34570. return this.then(undefined, onRejected);
  34571. }
  34572. });
  34573. OwnPromiseCapability = function () {
  34574. var promise = new Internal();
  34575. var state = getInternalState(promise);
  34576. this.promise = promise;
  34577. this.resolve = bind(internalResolve, promise, state);
  34578. this.reject = bind(internalReject, promise, state);
  34579. };
  34580. newPromiseCapabilityModule.f = newPromiseCapability = function (C) {
  34581. return C === PromiseConstructor || C === PromiseWrapper
  34582. ? new OwnPromiseCapability(C)
  34583. : newGenericPromiseCapability(C);
  34584. };
  34585. if (!IS_PURE && typeof NativePromise == 'function') {
  34586. nativeThen = NativePromise.prototype.then;
  34587. // wrap native Promise#then for native async functions
  34588. redefine(NativePromise.prototype, 'then', function then(onFulfilled, onRejected) {
  34589. var that = this;
  34590. return new PromiseConstructor(function (resolve, reject) {
  34591. nativeThen.call(that, resolve, reject);
  34592. }).then(onFulfilled, onRejected);
  34593. // https://github.com/zloirock/core-js/issues/640
  34594. }, { unsafe: true });
  34595. // wrap fetch result
  34596. if (typeof $fetch == 'function') $({ global: true, enumerable: true, forced: true }, {
  34597. // eslint-disable-next-line no-unused-vars
  34598. fetch: function fetch(input /* , init */) {
  34599. return promiseResolve(PromiseConstructor, $fetch.apply(global, arguments));
  34600. }
  34601. });
  34602. }
  34603. }
  34604. $({ global: true, wrap: true, forced: FORCED }, {
  34605. Promise: PromiseConstructor
  34606. });
  34607. setToStringTag(PromiseConstructor, PROMISE, false, true);
  34608. setSpecies(PROMISE);
  34609. PromiseWrapper = getBuiltIn(PROMISE);
  34610. // statics
  34611. $({ target: PROMISE, stat: true, forced: FORCED }, {
  34612. // `Promise.reject` method
  34613. // https://tc39.github.io/ecma262/#sec-promise.reject
  34614. reject: function reject(r) {
  34615. var capability = newPromiseCapability(this);
  34616. capability.reject.call(undefined, r);
  34617. return capability.promise;
  34618. }
  34619. });
  34620. $({ target: PROMISE, stat: true, forced: IS_PURE || FORCED }, {
  34621. // `Promise.resolve` method
  34622. // https://tc39.github.io/ecma262/#sec-promise.resolve
  34623. resolve: function resolve(x) {
  34624. return promiseResolve(IS_PURE && this === PromiseWrapper ? PromiseConstructor : this, x);
  34625. }
  34626. });
  34627. $({ target: PROMISE, stat: true, forced: INCORRECT_ITERATION }, {
  34628. // `Promise.all` method
  34629. // https://tc39.github.io/ecma262/#sec-promise.all
  34630. all: function all(iterable) {
  34631. var C = this;
  34632. var capability = newPromiseCapability(C);
  34633. var resolve = capability.resolve;
  34634. var reject = capability.reject;
  34635. var result = perform(function () {
  34636. var $promiseResolve = aFunction(C.resolve);
  34637. var values = [];
  34638. var counter = 0;
  34639. var remaining = 1;
  34640. iterate(iterable, function (promise) {
  34641. var index = counter++;
  34642. var alreadyCalled = false;
  34643. values.push(undefined);
  34644. remaining++;
  34645. $promiseResolve.call(C, promise).then(function (value) {
  34646. if (alreadyCalled) return;
  34647. alreadyCalled = true;
  34648. values[index] = value;
  34649. --remaining || resolve(values);
  34650. }, reject);
  34651. });
  34652. --remaining || resolve(values);
  34653. });
  34654. if (result.error) reject(result.value);
  34655. return capability.promise;
  34656. },
  34657. // `Promise.race` method
  34658. // https://tc39.github.io/ecma262/#sec-promise.race
  34659. race: function race(iterable) {
  34660. var C = this;
  34661. var capability = newPromiseCapability(C);
  34662. var reject = capability.reject;
  34663. var result = perform(function () {
  34664. var $promiseResolve = aFunction(C.resolve);
  34665. iterate(iterable, function (promise) {
  34666. $promiseResolve.call(C, promise).then(capability.resolve, reject);
  34667. });
  34668. });
  34669. if (result.error) reject(result.value);
  34670. return capability.promise;
  34671. }
  34672. });
  34673. },{"../internals/a-function":219,"../internals/an-instance":222,"../internals/check-correctness-of-iteration":229,"../internals/classof-raw":230,"../internals/engine-v8-version":244,"../internals/export":246,"../internals/get-built-in":249,"../internals/global":251,"../internals/host-report-errors":254,"../internals/inspect-source":258,"../internals/internal-state":259,"../internals/is-forced":262,"../internals/is-object":263,"../internals/is-pure":264,"../internals/iterate":266,"../internals/microtask":269,"../internals/native-promise-constructor":270,"../internals/new-promise-capability":273,"../internals/perform":291,"../internals/promise-resolve":292,"../internals/redefine":294,"../internals/redefine-all":293,"../internals/set-species":297,"../internals/set-to-string-tag":298,"../internals/species-constructor":302,"../internals/task":303,"../internals/well-known-symbol":314}],324:[function(require,module,exports){
  34674. var $ = require('../internals/export');
  34675. var toAbsoluteIndex = require('../internals/to-absolute-index');
  34676. var fromCharCode = String.fromCharCode;
  34677. var nativeFromCodePoint = String.fromCodePoint;
  34678. // length should be 1, old FF problem
  34679. var INCORRECT_LENGTH = !!nativeFromCodePoint && nativeFromCodePoint.length != 1;
  34680. // `String.fromCodePoint` method
  34681. // https://tc39.github.io/ecma262/#sec-string.fromcodepoint
  34682. $({ target: 'String', stat: true, forced: INCORRECT_LENGTH }, {
  34683. fromCodePoint: function fromCodePoint(x) { // eslint-disable-line no-unused-vars
  34684. var elements = [];
  34685. var length = arguments.length;
  34686. var i = 0;
  34687. var code;
  34688. while (length > i) {
  34689. code = +arguments[i++];
  34690. if (toAbsoluteIndex(code, 0x10FFFF) !== code) throw RangeError(code + ' is not a valid code point');
  34691. elements.push(code < 0x10000
  34692. ? fromCharCode(code)
  34693. : fromCharCode(((code -= 0x10000) >> 10) + 0xD800, code % 0x400 + 0xDC00)
  34694. );
  34695. } return elements.join('');
  34696. }
  34697. });
  34698. },{"../internals/export":246,"../internals/to-absolute-index":304}],325:[function(require,module,exports){
  34699. 'use strict';
  34700. var $ = require('../internals/export');
  34701. var notARegExp = require('../internals/not-a-regexp');
  34702. var requireObjectCoercible = require('../internals/require-object-coercible');
  34703. var correctIsRegExpLogic = require('../internals/correct-is-regexp-logic');
  34704. // `String.prototype.includes` method
  34705. // https://tc39.github.io/ecma262/#sec-string.prototype.includes
  34706. $({ target: 'String', proto: true, forced: !correctIsRegExpLogic('includes') }, {
  34707. includes: function includes(searchString /* , position = 0 */) {
  34708. return !!~String(requireObjectCoercible(this))
  34709. .indexOf(notARegExp(searchString), arguments.length > 1 ? arguments[1] : undefined);
  34710. }
  34711. });
  34712. },{"../internals/correct-is-regexp-logic":233,"../internals/export":246,"../internals/not-a-regexp":274,"../internals/require-object-coercible":295}],326:[function(require,module,exports){
  34713. var defineWellKnownSymbol = require('../internals/define-well-known-symbol');
  34714. // `Symbol.asyncIterator` well-known symbol
  34715. // https://tc39.github.io/ecma262/#sec-symbol.asynciterator
  34716. defineWellKnownSymbol('asyncIterator');
  34717. },{"../internals/define-well-known-symbol":239}],327:[function(require,module,exports){
  34718. 'use strict';
  34719. var $ = require('../internals/export');
  34720. var global = require('../internals/global');
  34721. var getBuiltIn = require('../internals/get-built-in');
  34722. var IS_PURE = require('../internals/is-pure');
  34723. var DESCRIPTORS = require('../internals/descriptors');
  34724. var NATIVE_SYMBOL = require('../internals/native-symbol');
  34725. var USE_SYMBOL_AS_UID = require('../internals/use-symbol-as-uid');
  34726. var fails = require('../internals/fails');
  34727. var has = require('../internals/has');
  34728. var isArray = require('../internals/is-array');
  34729. var isObject = require('../internals/is-object');
  34730. var anObject = require('../internals/an-object');
  34731. var toObject = require('../internals/to-object');
  34732. var toIndexedObject = require('../internals/to-indexed-object');
  34733. var toPrimitive = require('../internals/to-primitive');
  34734. var createPropertyDescriptor = require('../internals/create-property-descriptor');
  34735. var nativeObjectCreate = require('../internals/object-create');
  34736. var objectKeys = require('../internals/object-keys');
  34737. var getOwnPropertyNamesModule = require('../internals/object-get-own-property-names');
  34738. var getOwnPropertyNamesExternal = require('../internals/object-get-own-property-names-external');
  34739. var getOwnPropertySymbolsModule = require('../internals/object-get-own-property-symbols');
  34740. var getOwnPropertyDescriptorModule = require('../internals/object-get-own-property-descriptor');
  34741. var definePropertyModule = require('../internals/object-define-property');
  34742. var propertyIsEnumerableModule = require('../internals/object-property-is-enumerable');
  34743. var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
  34744. var redefine = require('../internals/redefine');
  34745. var shared = require('../internals/shared');
  34746. var sharedKey = require('../internals/shared-key');
  34747. var hiddenKeys = require('../internals/hidden-keys');
  34748. var uid = require('../internals/uid');
  34749. var wellKnownSymbol = require('../internals/well-known-symbol');
  34750. var wrappedWellKnownSymbolModule = require('../internals/well-known-symbol-wrapped');
  34751. var defineWellKnownSymbol = require('../internals/define-well-known-symbol');
  34752. var setToStringTag = require('../internals/set-to-string-tag');
  34753. var InternalStateModule = require('../internals/internal-state');
  34754. var $forEach = require('../internals/array-iteration').forEach;
  34755. var HIDDEN = sharedKey('hidden');
  34756. var SYMBOL = 'Symbol';
  34757. var PROTOTYPE = 'prototype';
  34758. var TO_PRIMITIVE = wellKnownSymbol('toPrimitive');
  34759. var setInternalState = InternalStateModule.set;
  34760. var getInternalState = InternalStateModule.getterFor(SYMBOL);
  34761. var ObjectPrototype = Object[PROTOTYPE];
  34762. var $Symbol = global.Symbol;
  34763. var $stringify = getBuiltIn('JSON', 'stringify');
  34764. var nativeGetOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;
  34765. var nativeDefineProperty = definePropertyModule.f;
  34766. var nativeGetOwnPropertyNames = getOwnPropertyNamesExternal.f;
  34767. var nativePropertyIsEnumerable = propertyIsEnumerableModule.f;
  34768. var AllSymbols = shared('symbols');
  34769. var ObjectPrototypeSymbols = shared('op-symbols');
  34770. var StringToSymbolRegistry = shared('string-to-symbol-registry');
  34771. var SymbolToStringRegistry = shared('symbol-to-string-registry');
  34772. var WellKnownSymbolsStore = shared('wks');
  34773. var QObject = global.QObject;
  34774. // Don't use setters in Qt Script, https://github.com/zloirock/core-js/issues/173
  34775. var USE_SETTER = !QObject || !QObject[PROTOTYPE] || !QObject[PROTOTYPE].findChild;
  34776. // fallback for old Android, https://code.google.com/p/v8/issues/detail?id=687
  34777. var setSymbolDescriptor = DESCRIPTORS && fails(function () {
  34778. return nativeObjectCreate(nativeDefineProperty({}, 'a', {
  34779. get: function () { return nativeDefineProperty(this, 'a', { value: 7 }).a; }
  34780. })).a != 7;
  34781. }) ? function (O, P, Attributes) {
  34782. var ObjectPrototypeDescriptor = nativeGetOwnPropertyDescriptor(ObjectPrototype, P);
  34783. if (ObjectPrototypeDescriptor) delete ObjectPrototype[P];
  34784. nativeDefineProperty(O, P, Attributes);
  34785. if (ObjectPrototypeDescriptor && O !== ObjectPrototype) {
  34786. nativeDefineProperty(ObjectPrototype, P, ObjectPrototypeDescriptor);
  34787. }
  34788. } : nativeDefineProperty;
  34789. var wrap = function (tag, description) {
  34790. var symbol = AllSymbols[tag] = nativeObjectCreate($Symbol[PROTOTYPE]);
  34791. setInternalState(symbol, {
  34792. type: SYMBOL,
  34793. tag: tag,
  34794. description: description
  34795. });
  34796. if (!DESCRIPTORS) symbol.description = description;
  34797. return symbol;
  34798. };
  34799. var isSymbol = USE_SYMBOL_AS_UID ? function (it) {
  34800. return typeof it == 'symbol';
  34801. } : function (it) {
  34802. return Object(it) instanceof $Symbol;
  34803. };
  34804. var $defineProperty = function defineProperty(O, P, Attributes) {
  34805. if (O === ObjectPrototype) $defineProperty(ObjectPrototypeSymbols, P, Attributes);
  34806. anObject(O);
  34807. var key = toPrimitive(P, true);
  34808. anObject(Attributes);
  34809. if (has(AllSymbols, key)) {
  34810. if (!Attributes.enumerable) {
  34811. if (!has(O, HIDDEN)) nativeDefineProperty(O, HIDDEN, createPropertyDescriptor(1, {}));
  34812. O[HIDDEN][key] = true;
  34813. } else {
  34814. if (has(O, HIDDEN) && O[HIDDEN][key]) O[HIDDEN][key] = false;
  34815. Attributes = nativeObjectCreate(Attributes, { enumerable: createPropertyDescriptor(0, false) });
  34816. } return setSymbolDescriptor(O, key, Attributes);
  34817. } return nativeDefineProperty(O, key, Attributes);
  34818. };
  34819. var $defineProperties = function defineProperties(O, Properties) {
  34820. anObject(O);
  34821. var properties = toIndexedObject(Properties);
  34822. var keys = objectKeys(properties).concat($getOwnPropertySymbols(properties));
  34823. $forEach(keys, function (key) {
  34824. if (!DESCRIPTORS || $propertyIsEnumerable.call(properties, key)) $defineProperty(O, key, properties[key]);
  34825. });
  34826. return O;
  34827. };
  34828. var $create = function create(O, Properties) {
  34829. return Properties === undefined ? nativeObjectCreate(O) : $defineProperties(nativeObjectCreate(O), Properties);
  34830. };
  34831. var $propertyIsEnumerable = function propertyIsEnumerable(V) {
  34832. var P = toPrimitive(V, true);
  34833. var enumerable = nativePropertyIsEnumerable.call(this, P);
  34834. if (this === ObjectPrototype && has(AllSymbols, P) && !has(ObjectPrototypeSymbols, P)) return false;
  34835. return enumerable || !has(this, P) || !has(AllSymbols, P) || has(this, HIDDEN) && this[HIDDEN][P] ? enumerable : true;
  34836. };
  34837. var $getOwnPropertyDescriptor = function getOwnPropertyDescriptor(O, P) {
  34838. var it = toIndexedObject(O);
  34839. var key = toPrimitive(P, true);
  34840. if (it === ObjectPrototype && has(AllSymbols, key) && !has(ObjectPrototypeSymbols, key)) return;
  34841. var descriptor = nativeGetOwnPropertyDescriptor(it, key);
  34842. if (descriptor && has(AllSymbols, key) && !(has(it, HIDDEN) && it[HIDDEN][key])) {
  34843. descriptor.enumerable = true;
  34844. }
  34845. return descriptor;
  34846. };
  34847. var $getOwnPropertyNames = function getOwnPropertyNames(O) {
  34848. var names = nativeGetOwnPropertyNames(toIndexedObject(O));
  34849. var result = [];
  34850. $forEach(names, function (key) {
  34851. if (!has(AllSymbols, key) && !has(hiddenKeys, key)) result.push(key);
  34852. });
  34853. return result;
  34854. };
  34855. var $getOwnPropertySymbols = function getOwnPropertySymbols(O) {
  34856. var IS_OBJECT_PROTOTYPE = O === ObjectPrototype;
  34857. var names = nativeGetOwnPropertyNames(IS_OBJECT_PROTOTYPE ? ObjectPrototypeSymbols : toIndexedObject(O));
  34858. var result = [];
  34859. $forEach(names, function (key) {
  34860. if (has(AllSymbols, key) && (!IS_OBJECT_PROTOTYPE || has(ObjectPrototype, key))) {
  34861. result.push(AllSymbols[key]);
  34862. }
  34863. });
  34864. return result;
  34865. };
  34866. // `Symbol` constructor
  34867. // https://tc39.github.io/ecma262/#sec-symbol-constructor
  34868. if (!NATIVE_SYMBOL) {
  34869. $Symbol = function Symbol() {
  34870. if (this instanceof $Symbol) throw TypeError('Symbol is not a constructor');
  34871. var description = !arguments.length || arguments[0] === undefined ? undefined : String(arguments[0]);
  34872. var tag = uid(description);
  34873. var setter = function (value) {
  34874. if (this === ObjectPrototype) setter.call(ObjectPrototypeSymbols, value);
  34875. if (has(this, HIDDEN) && has(this[HIDDEN], tag)) this[HIDDEN][tag] = false;
  34876. setSymbolDescriptor(this, tag, createPropertyDescriptor(1, value));
  34877. };
  34878. if (DESCRIPTORS && USE_SETTER) setSymbolDescriptor(ObjectPrototype, tag, { configurable: true, set: setter });
  34879. return wrap(tag, description);
  34880. };
  34881. redefine($Symbol[PROTOTYPE], 'toString', function toString() {
  34882. return getInternalState(this).tag;
  34883. });
  34884. redefine($Symbol, 'withoutSetter', function (description) {
  34885. return wrap(uid(description), description);
  34886. });
  34887. propertyIsEnumerableModule.f = $propertyIsEnumerable;
  34888. definePropertyModule.f = $defineProperty;
  34889. getOwnPropertyDescriptorModule.f = $getOwnPropertyDescriptor;
  34890. getOwnPropertyNamesModule.f = getOwnPropertyNamesExternal.f = $getOwnPropertyNames;
  34891. getOwnPropertySymbolsModule.f = $getOwnPropertySymbols;
  34892. wrappedWellKnownSymbolModule.f = function (name) {
  34893. return wrap(wellKnownSymbol(name), name);
  34894. };
  34895. if (DESCRIPTORS) {
  34896. // https://github.com/tc39/proposal-Symbol-description
  34897. nativeDefineProperty($Symbol[PROTOTYPE], 'description', {
  34898. configurable: true,
  34899. get: function description() {
  34900. return getInternalState(this).description;
  34901. }
  34902. });
  34903. if (!IS_PURE) {
  34904. redefine(ObjectPrototype, 'propertyIsEnumerable', $propertyIsEnumerable, { unsafe: true });
  34905. }
  34906. }
  34907. }
  34908. $({ global: true, wrap: true, forced: !NATIVE_SYMBOL, sham: !NATIVE_SYMBOL }, {
  34909. Symbol: $Symbol
  34910. });
  34911. $forEach(objectKeys(WellKnownSymbolsStore), function (name) {
  34912. defineWellKnownSymbol(name);
  34913. });
  34914. $({ target: SYMBOL, stat: true, forced: !NATIVE_SYMBOL }, {
  34915. // `Symbol.for` method
  34916. // https://tc39.github.io/ecma262/#sec-symbol.for
  34917. 'for': function (key) {
  34918. var string = String(key);
  34919. if (has(StringToSymbolRegistry, string)) return StringToSymbolRegistry[string];
  34920. var symbol = $Symbol(string);
  34921. StringToSymbolRegistry[string] = symbol;
  34922. SymbolToStringRegistry[symbol] = string;
  34923. return symbol;
  34924. },
  34925. // `Symbol.keyFor` method
  34926. // https://tc39.github.io/ecma262/#sec-symbol.keyfor
  34927. keyFor: function keyFor(sym) {
  34928. if (!isSymbol(sym)) throw TypeError(sym + ' is not a symbol');
  34929. if (has(SymbolToStringRegistry, sym)) return SymbolToStringRegistry[sym];
  34930. },
  34931. useSetter: function () { USE_SETTER = true; },
  34932. useSimple: function () { USE_SETTER = false; }
  34933. });
  34934. $({ target: 'Object', stat: true, forced: !NATIVE_SYMBOL, sham: !DESCRIPTORS }, {
  34935. // `Object.create` method
  34936. // https://tc39.github.io/ecma262/#sec-object.create
  34937. create: $create,
  34938. // `Object.defineProperty` method
  34939. // https://tc39.github.io/ecma262/#sec-object.defineproperty
  34940. defineProperty: $defineProperty,
  34941. // `Object.defineProperties` method
  34942. // https://tc39.github.io/ecma262/#sec-object.defineproperties
  34943. defineProperties: $defineProperties,
  34944. // `Object.getOwnPropertyDescriptor` method
  34945. // https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptors
  34946. getOwnPropertyDescriptor: $getOwnPropertyDescriptor
  34947. });
  34948. $({ target: 'Object', stat: true, forced: !NATIVE_SYMBOL }, {
  34949. // `Object.getOwnPropertyNames` method
  34950. // https://tc39.github.io/ecma262/#sec-object.getownpropertynames
  34951. getOwnPropertyNames: $getOwnPropertyNames,
  34952. // `Object.getOwnPropertySymbols` method
  34953. // https://tc39.github.io/ecma262/#sec-object.getownpropertysymbols
  34954. getOwnPropertySymbols: $getOwnPropertySymbols
  34955. });
  34956. // Chrome 38 and 39 `Object.getOwnPropertySymbols` fails on primitives
  34957. // https://bugs.chromium.org/p/v8/issues/detail?id=3443
  34958. $({ target: 'Object', stat: true, forced: fails(function () { getOwnPropertySymbolsModule.f(1); }) }, {
  34959. getOwnPropertySymbols: function getOwnPropertySymbols(it) {
  34960. return getOwnPropertySymbolsModule.f(toObject(it));
  34961. }
  34962. });
  34963. // `JSON.stringify` method behavior with symbols
  34964. // https://tc39.github.io/ecma262/#sec-json.stringify
  34965. if ($stringify) {
  34966. var FORCED_JSON_STRINGIFY = !NATIVE_SYMBOL || fails(function () {
  34967. var symbol = $Symbol();
  34968. // MS Edge converts symbol values to JSON as {}
  34969. return $stringify([symbol]) != '[null]'
  34970. // WebKit converts symbol values to JSON as null
  34971. || $stringify({ a: symbol }) != '{}'
  34972. // V8 throws on boxed symbols
  34973. || $stringify(Object(symbol)) != '{}';
  34974. });
  34975. $({ target: 'JSON', stat: true, forced: FORCED_JSON_STRINGIFY }, {
  34976. // eslint-disable-next-line no-unused-vars
  34977. stringify: function stringify(it, replacer, space) {
  34978. var args = [it];
  34979. var index = 1;
  34980. var $replacer;
  34981. while (arguments.length > index) args.push(arguments[index++]);
  34982. $replacer = replacer;
  34983. if (!isObject(replacer) && it === undefined || isSymbol(it)) return; // IE8 returns string on undefined
  34984. if (!isArray(replacer)) replacer = function (key, value) {
  34985. if (typeof $replacer == 'function') value = $replacer.call(this, key, value);
  34986. if (!isSymbol(value)) return value;
  34987. };
  34988. args[1] = replacer;
  34989. return $stringify.apply(null, args);
  34990. }
  34991. });
  34992. }
  34993. // `Symbol.prototype[@@toPrimitive]` method
  34994. // https://tc39.github.io/ecma262/#sec-symbol.prototype-@@toprimitive
  34995. if (!$Symbol[PROTOTYPE][TO_PRIMITIVE]) {
  34996. createNonEnumerableProperty($Symbol[PROTOTYPE], TO_PRIMITIVE, $Symbol[PROTOTYPE].valueOf);
  34997. }
  34998. // `Symbol.prototype[@@toStringTag]` property
  34999. // https://tc39.github.io/ecma262/#sec-symbol.prototype-@@tostringtag
  35000. setToStringTag($Symbol, SYMBOL);
  35001. hiddenKeys[HIDDEN] = true;
  35002. },{"../internals/an-object":223,"../internals/array-iteration":225,"../internals/create-non-enumerable-property":236,"../internals/create-property-descriptor":237,"../internals/define-well-known-symbol":239,"../internals/descriptors":240,"../internals/export":246,"../internals/fails":247,"../internals/get-built-in":249,"../internals/global":251,"../internals/has":252,"../internals/hidden-keys":253,"../internals/internal-state":259,"../internals/is-array":261,"../internals/is-object":263,"../internals/is-pure":264,"../internals/native-symbol":271,"../internals/object-create":276,"../internals/object-define-property":278,"../internals/object-get-own-property-descriptor":279,"../internals/object-get-own-property-names":281,"../internals/object-get-own-property-names-external":280,"../internals/object-get-own-property-symbols":282,"../internals/object-keys":285,"../internals/object-property-is-enumerable":286,"../internals/redefine":294,"../internals/set-to-string-tag":298,"../internals/shared":301,"../internals/shared-key":299,"../internals/to-indexed-object":305,"../internals/to-object":308,"../internals/to-primitive":309,"../internals/uid":311,"../internals/use-symbol-as-uid":312,"../internals/well-known-symbol":314,"../internals/well-known-symbol-wrapped":313}],328:[function(require,module,exports){
  35003. (function (Buffer){
  35004. "use strict";
  35005. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  35006. // Copyright Joyent, Inc. and other Node contributors.
  35007. //
  35008. // Permission is hereby granted, free of charge, to any person obtaining a
  35009. // copy of this software and associated documentation files (the
  35010. // "Software"), to deal in the Software without restriction, including
  35011. // without limitation the rights to use, copy, modify, merge, publish,
  35012. // distribute, sublicense, and/or sell copies of the Software, and to permit
  35013. // persons to whom the Software is furnished to do so, subject to the
  35014. // following conditions:
  35015. //
  35016. // The above copyright notice and this permission notice shall be included
  35017. // in all copies or substantial portions of the Software.
  35018. //
  35019. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  35020. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  35021. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  35022. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  35023. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  35024. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  35025. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  35026. // NOTE: These type checking functions intentionally don't use `instanceof`
  35027. // because it is fragile and can be easily faked with `Object.create()`.
  35028. function isArray(arg) {
  35029. if (Array.isArray) {
  35030. return Array.isArray(arg);
  35031. }
  35032. return objectToString(arg) === '[object Array]';
  35033. }
  35034. exports.isArray = isArray;
  35035. function isBoolean(arg) {
  35036. return typeof arg === 'boolean';
  35037. }
  35038. exports.isBoolean = isBoolean;
  35039. function isNull(arg) {
  35040. return arg === null;
  35041. }
  35042. exports.isNull = isNull;
  35043. function isNullOrUndefined(arg) {
  35044. return arg == null;
  35045. }
  35046. exports.isNullOrUndefined = isNullOrUndefined;
  35047. function isNumber(arg) {
  35048. return typeof arg === 'number';
  35049. }
  35050. exports.isNumber = isNumber;
  35051. function isString(arg) {
  35052. return typeof arg === 'string';
  35053. }
  35054. exports.isString = isString;
  35055. function isSymbol(arg) {
  35056. return _typeof(arg) === 'symbol';
  35057. }
  35058. exports.isSymbol = isSymbol;
  35059. function isUndefined(arg) {
  35060. return arg === void 0;
  35061. }
  35062. exports.isUndefined = isUndefined;
  35063. function isRegExp(re) {
  35064. return objectToString(re) === '[object RegExp]';
  35065. }
  35066. exports.isRegExp = isRegExp;
  35067. function isObject(arg) {
  35068. return _typeof(arg) === 'object' && arg !== null;
  35069. }
  35070. exports.isObject = isObject;
  35071. function isDate(d) {
  35072. return objectToString(d) === '[object Date]';
  35073. }
  35074. exports.isDate = isDate;
  35075. function isError(e) {
  35076. return objectToString(e) === '[object Error]' || e instanceof Error;
  35077. }
  35078. exports.isError = isError;
  35079. function isFunction(arg) {
  35080. return typeof arg === 'function';
  35081. }
  35082. exports.isFunction = isFunction;
  35083. function isPrimitive(arg) {
  35084. return arg === null || typeof arg === 'boolean' || typeof arg === 'number' || typeof arg === 'string' || _typeof(arg) === 'symbol' || // ES6 symbol
  35085. typeof arg === 'undefined';
  35086. }
  35087. exports.isPrimitive = isPrimitive;
  35088. exports.isBuffer = Buffer.isBuffer;
  35089. function objectToString(o) {
  35090. return Object.prototype.toString.call(o);
  35091. }
  35092. }).call(this,{"isBuffer":require("../../is-buffer/index.js")})
  35093. },{"../../is-buffer/index.js":388}],329:[function(require,module,exports){
  35094. (function (Buffer){
  35095. "use strict";
  35096. var elliptic = require('elliptic');
  35097. var BN = require('bn.js');
  35098. module.exports = function createECDH(curve) {
  35099. return new ECDH(curve);
  35100. };
  35101. var aliases = {
  35102. secp256k1: {
  35103. name: 'secp256k1',
  35104. byteLength: 32
  35105. },
  35106. secp224r1: {
  35107. name: 'p224',
  35108. byteLength: 28
  35109. },
  35110. prime256v1: {
  35111. name: 'p256',
  35112. byteLength: 32
  35113. },
  35114. prime192v1: {
  35115. name: 'p192',
  35116. byteLength: 24
  35117. },
  35118. ed25519: {
  35119. name: 'ed25519',
  35120. byteLength: 32
  35121. },
  35122. secp384r1: {
  35123. name: 'p384',
  35124. byteLength: 48
  35125. },
  35126. secp521r1: {
  35127. name: 'p521',
  35128. byteLength: 66
  35129. }
  35130. };
  35131. aliases.p224 = aliases.secp224r1;
  35132. aliases.p256 = aliases.secp256r1 = aliases.prime256v1;
  35133. aliases.p192 = aliases.secp192r1 = aliases.prime192v1;
  35134. aliases.p384 = aliases.secp384r1;
  35135. aliases.p521 = aliases.secp521r1;
  35136. function ECDH(curve) {
  35137. this.curveType = aliases[curve];
  35138. if (!this.curveType) {
  35139. this.curveType = {
  35140. name: curve
  35141. };
  35142. }
  35143. this.curve = new elliptic.ec(this.curveType.name); // eslint-disable-line new-cap
  35144. this.keys = void 0;
  35145. }
  35146. ECDH.prototype.generateKeys = function (enc, format) {
  35147. this.keys = this.curve.genKeyPair();
  35148. return this.getPublicKey(enc, format);
  35149. };
  35150. ECDH.prototype.computeSecret = function (other, inenc, enc) {
  35151. inenc = inenc || 'utf8';
  35152. if (!Buffer.isBuffer(other)) {
  35153. other = new Buffer(other, inenc);
  35154. }
  35155. var otherPub = this.curve.keyFromPublic(other).getPublic();
  35156. var out = otherPub.mul(this.keys.getPrivate()).getX();
  35157. return formatReturnValue(out, enc, this.curveType.byteLength);
  35158. };
  35159. ECDH.prototype.getPublicKey = function (enc, format) {
  35160. var key = this.keys.getPublic(format === 'compressed', true);
  35161. if (format === 'hybrid') {
  35162. if (key[key.length - 1] % 2) {
  35163. key[0] = 7;
  35164. } else {
  35165. key[0] = 6;
  35166. }
  35167. }
  35168. return formatReturnValue(key, enc);
  35169. };
  35170. ECDH.prototype.getPrivateKey = function (enc) {
  35171. return formatReturnValue(this.keys.getPrivate(), enc);
  35172. };
  35173. ECDH.prototype.setPublicKey = function (pub, enc) {
  35174. enc = enc || 'utf8';
  35175. if (!Buffer.isBuffer(pub)) {
  35176. pub = new Buffer(pub, enc);
  35177. }
  35178. this.keys._importPublic(pub);
  35179. return this;
  35180. };
  35181. ECDH.prototype.setPrivateKey = function (priv, enc) {
  35182. enc = enc || 'utf8';
  35183. if (!Buffer.isBuffer(priv)) {
  35184. priv = new Buffer(priv, enc);
  35185. }
  35186. var _priv = new BN(priv);
  35187. _priv = _priv.toString(16);
  35188. this.keys = this.curve.genKeyPair();
  35189. this.keys._importPrivate(_priv);
  35190. return this;
  35191. };
  35192. function formatReturnValue(bn, enc, len) {
  35193. if (!Array.isArray(bn)) {
  35194. bn = bn.toArray();
  35195. }
  35196. var buf = new Buffer(bn);
  35197. if (len && buf.length < len) {
  35198. var zeros = new Buffer(len - buf.length);
  35199. zeros.fill(0);
  35200. buf = Buffer.concat([zeros, buf]);
  35201. }
  35202. if (!enc) {
  35203. return buf;
  35204. } else {
  35205. return buf.toString(enc);
  35206. }
  35207. }
  35208. }).call(this,require("buffer").Buffer)
  35209. },{"bn.js":330,"buffer":216,"elliptic":350}],330:[function(require,module,exports){
  35210. arguments[4][181][0].apply(exports,arguments)
  35211. },{"buffer":185,"dup":181}],331:[function(require,module,exports){
  35212. 'use strict';
  35213. var inherits = require('inherits');
  35214. var MD5 = require('md5.js');
  35215. var RIPEMD160 = require('ripemd160');
  35216. var sha = require('sha.js');
  35217. var Base = require('cipher-base');
  35218. function Hash(hash) {
  35219. Base.call(this, 'digest');
  35220. this._hash = hash;
  35221. }
  35222. inherits(Hash, Base);
  35223. Hash.prototype._update = function (data) {
  35224. this._hash.update(data);
  35225. };
  35226. Hash.prototype._final = function () {
  35227. return this._hash.digest();
  35228. };
  35229. module.exports = function createHash(alg) {
  35230. alg = alg.toLowerCase();
  35231. if (alg === 'md5') return new MD5();
  35232. if (alg === 'rmd160' || alg === 'ripemd160') return new RIPEMD160();
  35233. return new Hash(sha(alg));
  35234. };
  35235. },{"cipher-base":218,"inherits":387,"md5.js":434,"ripemd160":493,"sha.js":499}],332:[function(require,module,exports){
  35236. "use strict";
  35237. var MD5 = require('md5.js');
  35238. module.exports = function (buffer) {
  35239. return new MD5().update(buffer).digest();
  35240. };
  35241. },{"md5.js":434}],333:[function(require,module,exports){
  35242. 'use strict';
  35243. var inherits = require('inherits');
  35244. var Legacy = require('./legacy');
  35245. var Base = require('cipher-base');
  35246. var Buffer = require('safe-buffer').Buffer;
  35247. var md5 = require('create-hash/md5');
  35248. var RIPEMD160 = require('ripemd160');
  35249. var sha = require('sha.js');
  35250. var ZEROS = Buffer.alloc(128);
  35251. function Hmac(alg, key) {
  35252. Base.call(this, 'digest');
  35253. if (typeof key === 'string') {
  35254. key = Buffer.from(key);
  35255. }
  35256. var blocksize = alg === 'sha512' || alg === 'sha384' ? 128 : 64;
  35257. this._alg = alg;
  35258. this._key = key;
  35259. if (key.length > blocksize) {
  35260. var hash = alg === 'rmd160' ? new RIPEMD160() : sha(alg);
  35261. key = hash.update(key).digest();
  35262. } else if (key.length < blocksize) {
  35263. key = Buffer.concat([key, ZEROS], blocksize);
  35264. }
  35265. var ipad = this._ipad = Buffer.allocUnsafe(blocksize);
  35266. var opad = this._opad = Buffer.allocUnsafe(blocksize);
  35267. for (var i = 0; i < blocksize; i++) {
  35268. ipad[i] = key[i] ^ 0x36;
  35269. opad[i] = key[i] ^ 0x5C;
  35270. }
  35271. this._hash = alg === 'rmd160' ? new RIPEMD160() : sha(alg);
  35272. this._hash.update(ipad);
  35273. }
  35274. inherits(Hmac, Base);
  35275. Hmac.prototype._update = function (data) {
  35276. this._hash.update(data);
  35277. };
  35278. Hmac.prototype._final = function () {
  35279. var h = this._hash.digest();
  35280. var hash = this._alg === 'rmd160' ? new RIPEMD160() : sha(this._alg);
  35281. return hash.update(this._opad).update(h).digest();
  35282. };
  35283. module.exports = function createHmac(alg, key) {
  35284. alg = alg.toLowerCase();
  35285. if (alg === 'rmd160' || alg === 'ripemd160') {
  35286. return new Hmac('rmd160', key);
  35287. }
  35288. if (alg === 'md5') {
  35289. return new Legacy(md5, key);
  35290. }
  35291. return new Hmac(alg, key);
  35292. };
  35293. },{"./legacy":334,"cipher-base":218,"create-hash/md5":332,"inherits":387,"ripemd160":493,"safe-buffer":494,"sha.js":499}],334:[function(require,module,exports){
  35294. 'use strict';
  35295. var inherits = require('inherits');
  35296. var Buffer = require('safe-buffer').Buffer;
  35297. var Base = require('cipher-base');
  35298. var ZEROS = Buffer.alloc(128);
  35299. var blocksize = 64;
  35300. function Hmac(alg, key) {
  35301. Base.call(this, 'digest');
  35302. if (typeof key === 'string') {
  35303. key = Buffer.from(key);
  35304. }
  35305. this._alg = alg;
  35306. this._key = key;
  35307. if (key.length > blocksize) {
  35308. key = alg(key);
  35309. } else if (key.length < blocksize) {
  35310. key = Buffer.concat([key, ZEROS], blocksize);
  35311. }
  35312. var ipad = this._ipad = Buffer.allocUnsafe(blocksize);
  35313. var opad = this._opad = Buffer.allocUnsafe(blocksize);
  35314. for (var i = 0; i < blocksize; i++) {
  35315. ipad[i] = key[i] ^ 0x36;
  35316. opad[i] = key[i] ^ 0x5C;
  35317. }
  35318. this._hash = [ipad];
  35319. }
  35320. inherits(Hmac, Base);
  35321. Hmac.prototype._update = function (data) {
  35322. this._hash.push(data);
  35323. };
  35324. Hmac.prototype._final = function () {
  35325. var h = this._alg(Buffer.concat(this._hash));
  35326. return this._alg(Buffer.concat([this._opad, h]));
  35327. };
  35328. module.exports = Hmac;
  35329. },{"cipher-base":218,"inherits":387,"safe-buffer":494}],335:[function(require,module,exports){
  35330. 'use strict';
  35331. exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = require('randombytes');
  35332. exports.createHash = exports.Hash = require('create-hash');
  35333. exports.createHmac = exports.Hmac = require('create-hmac');
  35334. var algos = require('browserify-sign/algos');
  35335. var algoKeys = Object.keys(algos);
  35336. var hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(algoKeys);
  35337. exports.getHashes = function () {
  35338. return hashes;
  35339. };
  35340. var p = require('pbkdf2');
  35341. exports.pbkdf2 = p.pbkdf2;
  35342. exports.pbkdf2Sync = p.pbkdf2Sync;
  35343. var aes = require('browserify-cipher');
  35344. exports.Cipher = aes.Cipher;
  35345. exports.createCipher = aes.createCipher;
  35346. exports.Cipheriv = aes.Cipheriv;
  35347. exports.createCipheriv = aes.createCipheriv;
  35348. exports.Decipher = aes.Decipher;
  35349. exports.createDecipher = aes.createDecipher;
  35350. exports.Decipheriv = aes.Decipheriv;
  35351. exports.createDecipheriv = aes.createDecipheriv;
  35352. exports.getCiphers = aes.getCiphers;
  35353. exports.listCiphers = aes.listCiphers;
  35354. var dh = require('diffie-hellman');
  35355. exports.DiffieHellmanGroup = dh.DiffieHellmanGroup;
  35356. exports.createDiffieHellmanGroup = dh.createDiffieHellmanGroup;
  35357. exports.getDiffieHellman = dh.getDiffieHellman;
  35358. exports.createDiffieHellman = dh.createDiffieHellman;
  35359. exports.DiffieHellman = dh.DiffieHellman;
  35360. var sign = require('browserify-sign');
  35361. exports.createSign = sign.createSign;
  35362. exports.Sign = sign.Sign;
  35363. exports.createVerify = sign.createVerify;
  35364. exports.Verify = sign.Verify;
  35365. exports.createECDH = require('create-ecdh');
  35366. var publicEncrypt = require('public-encrypt');
  35367. exports.publicEncrypt = publicEncrypt.publicEncrypt;
  35368. exports.privateEncrypt = publicEncrypt.privateEncrypt;
  35369. exports.publicDecrypt = publicEncrypt.publicDecrypt;
  35370. exports.privateDecrypt = publicEncrypt.privateDecrypt; // the least I can do is make error messages for the rest of the node.js/crypto api.
  35371. // ;[
  35372. // 'createCredentials'
  35373. // ].forEach(function (name) {
  35374. // exports[name] = function () {
  35375. // throw new Error([
  35376. // 'sorry, ' + name + ' is not implemented yet',
  35377. // 'we accept pull requests',
  35378. // 'https://github.com/crypto-browserify/crypto-browserify'
  35379. // ].join('\n'))
  35380. // }
  35381. // })
  35382. var rf = require('randomfill');
  35383. exports.randomFill = rf.randomFill;
  35384. exports.randomFillSync = rf.randomFillSync;
  35385. exports.createCredentials = function () {
  35386. throw new Error(['sorry, createCredentials is not implemented yet', 'we accept pull requests', 'https://github.com/crypto-browserify/crypto-browserify'].join('\n'));
  35387. };
  35388. exports.constants = {
  35389. 'DH_CHECK_P_NOT_SAFE_PRIME': 2,
  35390. 'DH_CHECK_P_NOT_PRIME': 1,
  35391. 'DH_UNABLE_TO_CHECK_GENERATOR': 4,
  35392. 'DH_NOT_SUITABLE_GENERATOR': 8,
  35393. 'NPN_ENABLED': 1,
  35394. 'ALPN_ENABLED': 1,
  35395. 'RSA_PKCS1_PADDING': 1,
  35396. 'RSA_SSLV23_PADDING': 2,
  35397. 'RSA_NO_PADDING': 3,
  35398. 'RSA_PKCS1_OAEP_PADDING': 4,
  35399. 'RSA_X931_PADDING': 5,
  35400. 'RSA_PKCS1_PSS_PADDING': 6,
  35401. 'POINT_CONVERSION_COMPRESSED': 2,
  35402. 'POINT_CONVERSION_UNCOMPRESSED': 4,
  35403. 'POINT_CONVERSION_HYBRID': 6
  35404. };
  35405. },{"browserify-cipher":203,"browserify-sign":211,"browserify-sign/algos":208,"create-ecdh":329,"create-hash":331,"create-hmac":333,"diffie-hellman":345,"pbkdf2":460,"public-encrypt":468,"randombytes":475,"randomfill":476}],336:[function(require,module,exports){
  35406. "use strict";
  35407. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  35408. !function (t, e) {
  35409. "object" == (typeof exports === "undefined" ? "undefined" : _typeof(exports)) && "undefined" != typeof module ? module.exports = e() : "function" == typeof define && define.amd ? define(e) : t.dayjs = e();
  35410. }(void 0, function () {
  35411. "use strict";
  35412. var t = "millisecond",
  35413. e = "second",
  35414. n = "minute",
  35415. r = "hour",
  35416. i = "day",
  35417. s = "week",
  35418. u = "month",
  35419. a = "quarter",
  35420. o = "year",
  35421. f = "date",
  35422. h = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?.?(\d+)?$/,
  35423. c = /\[([^\]]+)]|Y{2,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,
  35424. d = function d(t, e, n) {
  35425. var r = String(t);
  35426. return !r || r.length >= e ? t : "" + Array(e + 1 - r.length).join(n) + t;
  35427. },
  35428. $ = {
  35429. s: d,
  35430. z: function z(t) {
  35431. var e = -t.utcOffset(),
  35432. n = Math.abs(e),
  35433. r = Math.floor(n / 60),
  35434. i = n % 60;
  35435. return (e <= 0 ? "+" : "-") + d(r, 2, "0") + ":" + d(i, 2, "0");
  35436. },
  35437. m: function t(e, n) {
  35438. if (e.date() < n.date()) return -t(n, e);
  35439. var r = 12 * (n.year() - e.year()) + (n.month() - e.month()),
  35440. i = e.add(r, u),
  35441. s = n - i < 0,
  35442. a = e.add(r + (s ? -1 : 1), u);
  35443. return +(-(r + (n - i) / (s ? i - a : a - i)) || 0);
  35444. },
  35445. a: function a(t) {
  35446. return t < 0 ? Math.ceil(t) || 0 : Math.floor(t);
  35447. },
  35448. p: function p(h) {
  35449. return {
  35450. M: u,
  35451. y: o,
  35452. w: s,
  35453. d: i,
  35454. D: f,
  35455. h: r,
  35456. m: n,
  35457. s: e,
  35458. ms: t,
  35459. Q: a
  35460. }[h] || String(h || "").toLowerCase().replace(/s$/, "");
  35461. },
  35462. u: function u(t) {
  35463. return void 0 === t;
  35464. }
  35465. },
  35466. l = {
  35467. name: "en",
  35468. weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),
  35469. months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_")
  35470. },
  35471. y = "en",
  35472. M = {};
  35473. M[y] = l;
  35474. var m = function m(t) {
  35475. return t instanceof S;
  35476. },
  35477. D = function D(t, e, n) {
  35478. var r;
  35479. if (!t) return y;
  35480. if ("string" == typeof t) M[t] && (r = t), e && (M[t] = e, r = t);else {
  35481. var i = t.name;
  35482. M[i] = t, r = i;
  35483. }
  35484. return !n && r && (y = r), r || !n && y;
  35485. },
  35486. v = function v(t, e) {
  35487. if (m(t)) return t.clone();
  35488. var n = "object" == _typeof(e) ? e : {};
  35489. return n.date = t, n.args = arguments, new S(n);
  35490. },
  35491. g = $;
  35492. g.l = D, g.i = m, g.w = function (t, e) {
  35493. return v(t, {
  35494. locale: e.$L,
  35495. utc: e.$u,
  35496. $offset: e.$offset
  35497. });
  35498. };
  35499. var S = function () {
  35500. function d(t) {
  35501. this.$L = this.$L || D(t.locale, null, !0), this.parse(t);
  35502. }
  35503. var $ = d.prototype;
  35504. return $.parse = function (t) {
  35505. this.$d = function (t) {
  35506. var e = t.date,
  35507. n = t.utc;
  35508. if (null === e) return new Date(NaN);
  35509. if (g.u(e)) return new Date();
  35510. if (e instanceof Date) return new Date(e);
  35511. if ("string" == typeof e && !/Z$/i.test(e)) {
  35512. var r = e.match(h);
  35513. if (r) {
  35514. var i = r[2] - 1 || 0,
  35515. s = (r[7] || "0").substring(0, 3);
  35516. 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);
  35517. }
  35518. }
  35519. return new Date(e);
  35520. }(t), this.init();
  35521. }, $.init = function () {
  35522. var t = this.$d;
  35523. 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();
  35524. }, $.$utils = function () {
  35525. return g;
  35526. }, $.isValid = function () {
  35527. return !("Invalid Date" === this.$d.toString());
  35528. }, $.isSame = function (t, e) {
  35529. var n = v(t);
  35530. return this.startOf(e) <= n && n <= this.endOf(e);
  35531. }, $.isAfter = function (t, e) {
  35532. return v(t) < this.startOf(e);
  35533. }, $.isBefore = function (t, e) {
  35534. return this.endOf(e) < v(t);
  35535. }, $.$g = function (t, e, n) {
  35536. return g.u(t) ? this[e] : this.set(n, t);
  35537. }, $.unix = function () {
  35538. return Math.floor(this.valueOf() / 1e3);
  35539. }, $.valueOf = function () {
  35540. return this.$d.getTime();
  35541. }, $.startOf = function (t, a) {
  35542. var h = this,
  35543. c = !!g.u(a) || a,
  35544. d = g.p(t),
  35545. $ = function $(t, e) {
  35546. var n = g.w(h.$u ? Date.UTC(h.$y, e, t) : new Date(h.$y, e, t), h);
  35547. return c ? n : n.endOf(i);
  35548. },
  35549. l = function l(t, e) {
  35550. return g.w(h.toDate()[t].apply(h.toDate("s"), (c ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(e)), h);
  35551. },
  35552. y = this.$W,
  35553. M = this.$M,
  35554. m = this.$D,
  35555. D = "set" + (this.$u ? "UTC" : "");
  35556. switch (d) {
  35557. case o:
  35558. return c ? $(1, 0) : $(31, 11);
  35559. case u:
  35560. return c ? $(1, M) : $(0, M + 1);
  35561. case s:
  35562. var v = this.$locale().weekStart || 0,
  35563. S = (y < v ? y + 7 : y) - v;
  35564. return $(c ? m - S : m + (6 - S), M);
  35565. case i:
  35566. case f:
  35567. return l(D + "Hours", 0);
  35568. case r:
  35569. return l(D + "Minutes", 1);
  35570. case n:
  35571. return l(D + "Seconds", 2);
  35572. case e:
  35573. return l(D + "Milliseconds", 3);
  35574. default:
  35575. return this.clone();
  35576. }
  35577. }, $.endOf = function (t) {
  35578. return this.startOf(t, !1);
  35579. }, $.$set = function (s, a) {
  35580. var h,
  35581. c = g.p(s),
  35582. d = "set" + (this.$u ? "UTC" : ""),
  35583. $ = (h = {}, h[i] = d + "Date", h[f] = d + "Date", h[u] = d + "Month", h[o] = d + "FullYear", h[r] = d + "Hours", h[n] = d + "Minutes", h[e] = d + "Seconds", h[t] = d + "Milliseconds", h)[c],
  35584. l = c === i ? this.$D + (a - this.$W) : a;
  35585. if (c === u || c === o) {
  35586. var y = this.clone().set(f, 1);
  35587. y.$d[$](l), y.init(), this.$d = y.set(f, Math.min(this.$D, y.daysInMonth())).$d;
  35588. } else $ && this.$d[$](l);
  35589. return this.init(), this;
  35590. }, $.set = function (t, e) {
  35591. return this.clone().$set(t, e);
  35592. }, $.get = function (t) {
  35593. return this[g.p(t)]();
  35594. }, $.add = function (t, a) {
  35595. var f,
  35596. h = this;
  35597. t = Number(t);
  35598. var c = g.p(a),
  35599. d = function d(e) {
  35600. var n = v(h);
  35601. return g.w(n.date(n.date() + Math.round(e * t)), h);
  35602. };
  35603. if (c === u) return this.set(u, this.$M + t);
  35604. if (c === o) return this.set(o, this.$y + t);
  35605. if (c === i) return d(1);
  35606. if (c === s) return d(7);
  35607. var $ = (f = {}, f[n] = 6e4, f[r] = 36e5, f[e] = 1e3, f)[c] || 1,
  35608. l = this.$d.getTime() + t * $;
  35609. return g.w(l, this);
  35610. }, $.subtract = function (t, e) {
  35611. return this.add(-1 * t, e);
  35612. }, $.format = function (t) {
  35613. var e = this;
  35614. if (!this.isValid()) return "Invalid Date";
  35615. var n = t || "YYYY-MM-DDTHH:mm:ssZ",
  35616. r = g.z(this),
  35617. i = this.$locale(),
  35618. s = this.$H,
  35619. u = this.$m,
  35620. a = this.$M,
  35621. o = i.weekdays,
  35622. f = i.months,
  35623. h = function h(t, r, i, s) {
  35624. return t && (t[r] || t(e, n)) || i[r].substr(0, s);
  35625. },
  35626. d = function d(t) {
  35627. return g.s(s % 12 || 12, t, "0");
  35628. },
  35629. $ = i.meridiem || function (t, e, n) {
  35630. var r = t < 12 ? "AM" : "PM";
  35631. return n ? r.toLowerCase() : r;
  35632. },
  35633. l = {
  35634. YY: String(this.$y).slice(-2),
  35635. YYYY: this.$y,
  35636. M: a + 1,
  35637. MM: g.s(a + 1, 2, "0"),
  35638. MMM: h(i.monthsShort, a, f, 3),
  35639. MMMM: h(f, a),
  35640. D: this.$D,
  35641. DD: g.s(this.$D, 2, "0"),
  35642. d: String(this.$W),
  35643. dd: h(i.weekdaysMin, this.$W, o, 2),
  35644. ddd: h(i.weekdaysShort, this.$W, o, 3),
  35645. dddd: o[this.$W],
  35646. H: String(s),
  35647. HH: g.s(s, 2, "0"),
  35648. h: d(1),
  35649. hh: d(2),
  35650. a: $(s, u, !0),
  35651. A: $(s, u, !1),
  35652. m: String(u),
  35653. mm: g.s(u, 2, "0"),
  35654. s: String(this.$s),
  35655. ss: g.s(this.$s, 2, "0"),
  35656. SSS: g.s(this.$ms, 3, "0"),
  35657. Z: r
  35658. };
  35659. return n.replace(c, function (t, e) {
  35660. return e || l[t] || r.replace(":", "");
  35661. });
  35662. }, $.utcOffset = function () {
  35663. return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
  35664. }, $.diff = function (t, f, h) {
  35665. var c,
  35666. d = g.p(f),
  35667. $ = v(t),
  35668. l = 6e4 * ($.utcOffset() - this.utcOffset()),
  35669. y = this - $,
  35670. M = g.m(this, $);
  35671. return M = (c = {}, c[o] = M / 12, c[u] = M, c[a] = M / 3, c[s] = (y - l) / 6048e5, c[i] = (y - l) / 864e5, c[r] = y / 36e5, c[n] = y / 6e4, c[e] = y / 1e3, c)[d] || y, h ? M : g.a(M);
  35672. }, $.daysInMonth = function () {
  35673. return this.endOf(u).$D;
  35674. }, $.$locale = function () {
  35675. return M[this.$L];
  35676. }, $.locale = function (t, e) {
  35677. if (!t) return this.$L;
  35678. var n = this.clone(),
  35679. r = D(t, e, !0);
  35680. return r && (n.$L = r), n;
  35681. }, $.clone = function () {
  35682. return g.w(this.$d, this);
  35683. }, $.toDate = function () {
  35684. return new Date(this.valueOf());
  35685. }, $.toJSON = function () {
  35686. return this.isValid() ? this.toISOString() : null;
  35687. }, $.toISOString = function () {
  35688. return this.$d.toISOString();
  35689. }, $.toString = function () {
  35690. return this.$d.toUTCString();
  35691. }, d;
  35692. }(),
  35693. p = S.prototype;
  35694. return v.prototype = p, [["$ms", t], ["$s", e], ["$m", n], ["$H", r], ["$W", i], ["$M", u], ["$y", o], ["$D", f]].forEach(function (t) {
  35695. p[t[1]] = function (e) {
  35696. return this.$g(e, t[0], t[1]);
  35697. };
  35698. }), v.extend = function (t, e) {
  35699. return t(e, S, v), v;
  35700. }, v.locale = D, v.isDayjs = m, v.unix = function (t) {
  35701. return v(1e3 * t);
  35702. }, v.en = M[y], v.Ls = M, v;
  35703. });
  35704. },{}],337:[function(require,module,exports){
  35705. "use strict";
  35706. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  35707. !function (t, e) {
  35708. "object" == (typeof exports === "undefined" ? "undefined" : _typeof(exports)) && "undefined" != typeof module ? module.exports = e() : "function" == typeof define && define.amd ? define(e) : t.dayjs_plugin_customParseFormat = e();
  35709. }(void 0, function () {
  35710. "use strict";
  35711. var t,
  35712. e = /(\[[^[]*\])|([-:/.()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,
  35713. n = /\d\d/,
  35714. r = /\d\d?/,
  35715. o = /\d*[^\s\d-:/()]+/;
  35716. var i = function i(t) {
  35717. return function (e) {
  35718. this[t] = +e;
  35719. };
  35720. },
  35721. s = [/[+-]\d\d:?\d\d/, function (t) {
  35722. var e, n;
  35723. (this.zone || (this.zone = {})).offset = (e = t.match(/([+-]|\d\d)/g), 0 === (n = 60 * e[1] + +e[2]) ? 0 : "+" === e[0] ? -n : n);
  35724. }],
  35725. a = function a(e) {
  35726. var n = t[e];
  35727. return n && (n.indexOf ? n : n.s.concat(n.f));
  35728. },
  35729. h = {
  35730. A: [/[AP]M/, function (t) {
  35731. this.afternoon = "PM" === t;
  35732. }],
  35733. a: [/[ap]m/, function (t) {
  35734. this.afternoon = "pm" === t;
  35735. }],
  35736. S: [/\d/, function (t) {
  35737. this.milliseconds = 100 * +t;
  35738. }],
  35739. SS: [n, function (t) {
  35740. this.milliseconds = 10 * +t;
  35741. }],
  35742. SSS: [/\d{3}/, function (t) {
  35743. this.milliseconds = +t;
  35744. }],
  35745. s: [r, i("seconds")],
  35746. ss: [r, i("seconds")],
  35747. m: [r, i("minutes")],
  35748. mm: [r, i("minutes")],
  35749. H: [r, i("hours")],
  35750. h: [r, i("hours")],
  35751. HH: [r, i("hours")],
  35752. hh: [r, i("hours")],
  35753. D: [r, i("day")],
  35754. DD: [n, i("day")],
  35755. Do: [o, function (e) {
  35756. var n = t.ordinal,
  35757. r = e.match(/\d+/);
  35758. if (this.day = r[0], n) for (var o = 1; o <= 31; o += 1) {
  35759. n(o).replace(/\[|\]/g, "") === e && (this.day = o);
  35760. }
  35761. }],
  35762. M: [r, i("month")],
  35763. MM: [n, i("month")],
  35764. MMM: [o, function (t) {
  35765. var e = a("months"),
  35766. n = (a("monthsShort") || e.map(function (t) {
  35767. return t.substr(0, 3);
  35768. })).indexOf(t) + 1;
  35769. if (n < 1) throw new Error();
  35770. this.month = n % 12 || n;
  35771. }],
  35772. MMMM: [o, function (t) {
  35773. var e = a("months").indexOf(t) + 1;
  35774. if (e < 1) throw new Error();
  35775. this.month = e % 12 || e;
  35776. }],
  35777. Y: [/[+-]?\d+/, i("year")],
  35778. YY: [n, function (t) {
  35779. t = +t, this.year = t + (t > 68 ? 1900 : 2e3);
  35780. }],
  35781. YYYY: [/\d{4}/, i("year")],
  35782. Z: s,
  35783. ZZ: s
  35784. };
  35785. var f = function f(t, n, r) {
  35786. try {
  35787. var o = function (t) {
  35788. for (var n = t.match(e), r = n.length, o = 0; o < r; o += 1) {
  35789. var i = n[o],
  35790. s = h[i],
  35791. a = s && s[0],
  35792. f = s && s[1];
  35793. n[o] = f ? {
  35794. regex: a,
  35795. parser: f
  35796. } : i.replace(/^\[|\]$/g, "");
  35797. }
  35798. return function (t) {
  35799. for (var e = {}, o = 0, i = 0; o < r; o += 1) {
  35800. var s = n[o];
  35801. if ("string" == typeof s) i += s.length;else {
  35802. var a = s.regex,
  35803. h = s.parser,
  35804. f = t.substr(i),
  35805. u = a.exec(f)[0];
  35806. h.call(e, u), t = t.replace(u, "");
  35807. }
  35808. }
  35809. return function (t) {
  35810. var e = t.afternoon;
  35811. if (void 0 !== e) {
  35812. var n = t.hours;
  35813. e ? n < 12 && (t.hours += 12) : 12 === n && (t.hours = 0), delete t.afternoon;
  35814. }
  35815. }(e), e;
  35816. };
  35817. }(n)(t),
  35818. i = o.year,
  35819. s = o.month,
  35820. a = o.day,
  35821. f = o.hours,
  35822. u = o.minutes,
  35823. d = o.seconds,
  35824. c = o.milliseconds,
  35825. l = o.zone,
  35826. m = new Date(),
  35827. v = a || (i || s ? 1 : m.getDate()),
  35828. p = i || m.getFullYear(),
  35829. y = 0;
  35830. i && !s || (y = s > 0 ? s - 1 : m.getMonth());
  35831. var D = f || 0,
  35832. M = u || 0,
  35833. g = d || 0,
  35834. Y = c || 0;
  35835. return l ? new Date(Date.UTC(p, y, v, D, M, g, Y + 60 * l.offset * 1e3)) : r ? new Date(Date.UTC(p, y, v, D, M, g, Y)) : new Date(p, y, v, D, M, g, Y);
  35836. } catch (t) {
  35837. return new Date("");
  35838. }
  35839. };
  35840. return function (e, n, r) {
  35841. var o = n.prototype,
  35842. i = o.parse;
  35843. o.parse = function (e) {
  35844. var n = e.date,
  35845. o = e.utc,
  35846. s = e.args;
  35847. this.$u = o;
  35848. var a = s[1];
  35849. if ("string" == typeof a) {
  35850. var h = !0 === s[2],
  35851. u = !0 === s[3],
  35852. d = h || u,
  35853. c = s[2];
  35854. u && (c = s[2]), h || (t = c ? r.Ls[c] : this.$locale()), this.$d = f(n, a, o), this.init(), c && !0 !== c && (this.$L = this.locale(c).$L), d && n !== this.format(a) && (this.$d = new Date(""));
  35855. } else if (a instanceof Array) for (var l = a.length, m = 1; m <= l; m += 1) {
  35856. s[1] = a[m - 1];
  35857. var v = r.apply(this, s);
  35858. if (v.isValid()) {
  35859. this.$d = v.$d, this.$L = v.$L, this.init();
  35860. break;
  35861. }
  35862. m === l && (this.$d = new Date(""));
  35863. } else i.call(this, e);
  35864. };
  35865. };
  35866. });
  35867. },{}],338:[function(require,module,exports){
  35868. "use strict";
  35869. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  35870. !function (t, i) {
  35871. "object" == (typeof exports === "undefined" ? "undefined" : _typeof(exports)) && "undefined" != typeof module ? module.exports = i() : "function" == typeof define && define.amd ? define(i) : t.dayjs_plugin_utc = i();
  35872. }(void 0, function () {
  35873. "use strict";
  35874. return function (t, i, e) {
  35875. var s = new Date().getTimezoneOffset(),
  35876. n = i.prototype;
  35877. e.utc = function (t) {
  35878. return new i({
  35879. date: t,
  35880. utc: !0,
  35881. args: arguments
  35882. });
  35883. }, n.utc = function () {
  35884. return e(this.toDate(), {
  35885. locale: this.$L,
  35886. utc: !0
  35887. });
  35888. }, n.local = function () {
  35889. return e(this.toDate(), {
  35890. locale: this.$L,
  35891. utc: !1
  35892. });
  35893. };
  35894. var u = n.parse;
  35895. n.parse = function (t) {
  35896. t.utc && (this.$u = !0), this.$utils().u(t.$offset) || (this.$offset = t.$offset), u.call(this, t);
  35897. };
  35898. var o = n.init;
  35899. n.init = function () {
  35900. if (this.$u) {
  35901. var t = this.$d;
  35902. 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();
  35903. } else o.call(this);
  35904. };
  35905. var f = n.utcOffset;
  35906. n.utcOffset = function (t, i) {
  35907. var e = this.$utils().u;
  35908. if (e(t)) return this.$u ? 0 : e(this.$offset) ? f.call(this) : this.$offset;
  35909. var n = Math.abs(t) <= 16 ? 60 * t : t,
  35910. u = this;
  35911. return i ? (u.$offset = n, u.$u = 0 === t, u) : (0 !== t ? (u = this.local().add(n + s, "minute")).$offset = n : u = this.utc(), u);
  35912. };
  35913. var r = n.format;
  35914. n.format = function (t) {
  35915. var i = t || (this.$u ? "YYYY-MM-DDTHH:mm:ss[Z]" : "");
  35916. return r.call(this, i);
  35917. }, n.valueOf = function () {
  35918. var t = this.$utils().u(this.$offset) ? 0 : this.$offset + s;
  35919. return this.$d.valueOf() - 6e4 * t;
  35920. }, n.isUTC = function () {
  35921. return !!this.$u;
  35922. }, n.toISOString = function () {
  35923. return this.toDate().toISOString();
  35924. }, n.toString = function () {
  35925. return this.toDate().toUTCString();
  35926. };
  35927. var a = n.toDate;
  35928. n.toDate = function (t) {
  35929. return "s" === t && this.$offset ? e(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate() : a.call(this);
  35930. };
  35931. var c = n.diff;
  35932. n.diff = function (t, i, s) {
  35933. var n = this.local(),
  35934. u = e(t).local();
  35935. return c.call(n, u, i, s);
  35936. };
  35937. };
  35938. });
  35939. },{}],339:[function(require,module,exports){
  35940. 'use strict';
  35941. exports.utils = require('./des/utils');
  35942. exports.Cipher = require('./des/cipher');
  35943. exports.DES = require('./des/des');
  35944. exports.CBC = require('./des/cbc');
  35945. exports.EDE = require('./des/ede');
  35946. },{"./des/cbc":340,"./des/cipher":341,"./des/des":342,"./des/ede":343,"./des/utils":344}],340:[function(require,module,exports){
  35947. 'use strict';
  35948. var assert = require('minimalistic-assert');
  35949. var inherits = require('inherits');
  35950. var proto = {};
  35951. function CBCState(iv) {
  35952. assert.equal(iv.length, 8, 'Invalid IV length');
  35953. this.iv = new Array(8);
  35954. for (var i = 0; i < this.iv.length; i++) {
  35955. this.iv[i] = iv[i];
  35956. }
  35957. }
  35958. function instantiate(Base) {
  35959. function CBC(options) {
  35960. Base.call(this, options);
  35961. this._cbcInit();
  35962. }
  35963. inherits(CBC, Base);
  35964. var keys = Object.keys(proto);
  35965. for (var i = 0; i < keys.length; i++) {
  35966. var key = keys[i];
  35967. CBC.prototype[key] = proto[key];
  35968. }
  35969. CBC.create = function create(options) {
  35970. return new CBC(options);
  35971. };
  35972. return CBC;
  35973. }
  35974. exports.instantiate = instantiate;
  35975. proto._cbcInit = function _cbcInit() {
  35976. var state = new CBCState(this.options.iv);
  35977. this._cbcState = state;
  35978. };
  35979. proto._update = function _update(inp, inOff, out, outOff) {
  35980. var state = this._cbcState;
  35981. var superProto = this.constructor.super_.prototype;
  35982. var iv = state.iv;
  35983. if (this.type === 'encrypt') {
  35984. for (var i = 0; i < this.blockSize; i++) {
  35985. iv[i] ^= inp[inOff + i];
  35986. }
  35987. superProto._update.call(this, iv, 0, out, outOff);
  35988. for (var i = 0; i < this.blockSize; i++) {
  35989. iv[i] = out[outOff + i];
  35990. }
  35991. } else {
  35992. superProto._update.call(this, inp, inOff, out, outOff);
  35993. for (var i = 0; i < this.blockSize; i++) {
  35994. out[outOff + i] ^= iv[i];
  35995. }
  35996. for (var i = 0; i < this.blockSize; i++) {
  35997. iv[i] = inp[inOff + i];
  35998. }
  35999. }
  36000. };
  36001. },{"inherits":387,"minimalistic-assert":437}],341:[function(require,module,exports){
  36002. 'use strict';
  36003. var assert = require('minimalistic-assert');
  36004. function Cipher(options) {
  36005. this.options = options;
  36006. this.type = this.options.type;
  36007. this.blockSize = 8;
  36008. this._init();
  36009. this.buffer = new Array(this.blockSize);
  36010. this.bufferOff = 0;
  36011. }
  36012. module.exports = Cipher;
  36013. Cipher.prototype._init = function _init() {// Might be overrided
  36014. };
  36015. Cipher.prototype.update = function update(data) {
  36016. if (data.length === 0) return [];
  36017. if (this.type === 'decrypt') return this._updateDecrypt(data);else return this._updateEncrypt(data);
  36018. };
  36019. Cipher.prototype._buffer = function _buffer(data, off) {
  36020. // Append data to buffer
  36021. var min = Math.min(this.buffer.length - this.bufferOff, data.length - off);
  36022. for (var i = 0; i < min; i++) {
  36023. this.buffer[this.bufferOff + i] = data[off + i];
  36024. }
  36025. this.bufferOff += min; // Shift next
  36026. return min;
  36027. };
  36028. Cipher.prototype._flushBuffer = function _flushBuffer(out, off) {
  36029. this._update(this.buffer, 0, out, off);
  36030. this.bufferOff = 0;
  36031. return this.blockSize;
  36032. };
  36033. Cipher.prototype._updateEncrypt = function _updateEncrypt(data) {
  36034. var inputOff = 0;
  36035. var outputOff = 0;
  36036. var count = (this.bufferOff + data.length) / this.blockSize | 0;
  36037. var out = new Array(count * this.blockSize);
  36038. if (this.bufferOff !== 0) {
  36039. inputOff += this._buffer(data, inputOff);
  36040. if (this.bufferOff === this.buffer.length) outputOff += this._flushBuffer(out, outputOff);
  36041. } // Write blocks
  36042. var max = data.length - (data.length - inputOff) % this.blockSize;
  36043. for (; inputOff < max; inputOff += this.blockSize) {
  36044. this._update(data, inputOff, out, outputOff);
  36045. outputOff += this.blockSize;
  36046. } // Queue rest
  36047. for (; inputOff < data.length; inputOff++, this.bufferOff++) {
  36048. this.buffer[this.bufferOff] = data[inputOff];
  36049. }
  36050. return out;
  36051. };
  36052. Cipher.prototype._updateDecrypt = function _updateDecrypt(data) {
  36053. var inputOff = 0;
  36054. var outputOff = 0;
  36055. var count = Math.ceil((this.bufferOff + data.length) / this.blockSize) - 1;
  36056. var out = new Array(count * this.blockSize); // TODO(indutny): optimize it, this is far from optimal
  36057. for (; count > 0; count--) {
  36058. inputOff += this._buffer(data, inputOff);
  36059. outputOff += this._flushBuffer(out, outputOff);
  36060. } // Buffer rest of the input
  36061. inputOff += this._buffer(data, inputOff);
  36062. return out;
  36063. };
  36064. Cipher.prototype.final = function final(buffer) {
  36065. var first;
  36066. if (buffer) first = this.update(buffer);
  36067. var last;
  36068. if (this.type === 'encrypt') last = this._finalEncrypt();else last = this._finalDecrypt();
  36069. if (first) return first.concat(last);else return last;
  36070. };
  36071. Cipher.prototype._pad = function _pad(buffer, off) {
  36072. if (off === 0) return false;
  36073. while (off < buffer.length) {
  36074. buffer[off++] = 0;
  36075. }
  36076. return true;
  36077. };
  36078. Cipher.prototype._finalEncrypt = function _finalEncrypt() {
  36079. if (!this._pad(this.buffer, this.bufferOff)) return [];
  36080. var out = new Array(this.blockSize);
  36081. this._update(this.buffer, 0, out, 0);
  36082. return out;
  36083. };
  36084. Cipher.prototype._unpad = function _unpad(buffer) {
  36085. return buffer;
  36086. };
  36087. Cipher.prototype._finalDecrypt = function _finalDecrypt() {
  36088. assert.equal(this.bufferOff, this.blockSize, 'Not enough data to decrypt');
  36089. var out = new Array(this.blockSize);
  36090. this._flushBuffer(out, 0);
  36091. return this._unpad(out);
  36092. };
  36093. },{"minimalistic-assert":437}],342:[function(require,module,exports){
  36094. 'use strict';
  36095. var assert = require('minimalistic-assert');
  36096. var inherits = require('inherits');
  36097. var utils = require('./utils');
  36098. var Cipher = require('./cipher');
  36099. function DESState() {
  36100. this.tmp = new Array(2);
  36101. this.keys = null;
  36102. }
  36103. function DES(options) {
  36104. Cipher.call(this, options);
  36105. var state = new DESState();
  36106. this._desState = state;
  36107. this.deriveKeys(state, options.key);
  36108. }
  36109. inherits(DES, Cipher);
  36110. module.exports = DES;
  36111. DES.create = function create(options) {
  36112. return new DES(options);
  36113. };
  36114. var shiftTable = [1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1];
  36115. DES.prototype.deriveKeys = function deriveKeys(state, key) {
  36116. state.keys = new Array(16 * 2);
  36117. assert.equal(key.length, this.blockSize, 'Invalid key length');
  36118. var kL = utils.readUInt32BE(key, 0);
  36119. var kR = utils.readUInt32BE(key, 4);
  36120. utils.pc1(kL, kR, state.tmp, 0);
  36121. kL = state.tmp[0];
  36122. kR = state.tmp[1];
  36123. for (var i = 0; i < state.keys.length; i += 2) {
  36124. var shift = shiftTable[i >>> 1];
  36125. kL = utils.r28shl(kL, shift);
  36126. kR = utils.r28shl(kR, shift);
  36127. utils.pc2(kL, kR, state.keys, i);
  36128. }
  36129. };
  36130. DES.prototype._update = function _update(inp, inOff, out, outOff) {
  36131. var state = this._desState;
  36132. var l = utils.readUInt32BE(inp, inOff);
  36133. var r = utils.readUInt32BE(inp, inOff + 4); // Initial Permutation
  36134. utils.ip(l, r, state.tmp, 0);
  36135. l = state.tmp[0];
  36136. r = state.tmp[1];
  36137. if (this.type === 'encrypt') this._encrypt(state, l, r, state.tmp, 0);else this._decrypt(state, l, r, state.tmp, 0);
  36138. l = state.tmp[0];
  36139. r = state.tmp[1];
  36140. utils.writeUInt32BE(out, l, outOff);
  36141. utils.writeUInt32BE(out, r, outOff + 4);
  36142. };
  36143. DES.prototype._pad = function _pad(buffer, off) {
  36144. var value = buffer.length - off;
  36145. for (var i = off; i < buffer.length; i++) {
  36146. buffer[i] = value;
  36147. }
  36148. return true;
  36149. };
  36150. DES.prototype._unpad = function _unpad(buffer) {
  36151. var pad = buffer[buffer.length - 1];
  36152. for (var i = buffer.length - pad; i < buffer.length; i++) {
  36153. assert.equal(buffer[i], pad);
  36154. }
  36155. return buffer.slice(0, buffer.length - pad);
  36156. };
  36157. DES.prototype._encrypt = function _encrypt(state, lStart, rStart, out, off) {
  36158. var l = lStart;
  36159. var r = rStart; // Apply f() x16 times
  36160. for (var i = 0; i < state.keys.length; i += 2) {
  36161. var keyL = state.keys[i];
  36162. var keyR = state.keys[i + 1]; // f(r, k)
  36163. utils.expand(r, state.tmp, 0);
  36164. keyL ^= state.tmp[0];
  36165. keyR ^= state.tmp[1];
  36166. var s = utils.substitute(keyL, keyR);
  36167. var f = utils.permute(s);
  36168. var t = r;
  36169. r = (l ^ f) >>> 0;
  36170. l = t;
  36171. } // Reverse Initial Permutation
  36172. utils.rip(r, l, out, off);
  36173. };
  36174. DES.prototype._decrypt = function _decrypt(state, lStart, rStart, out, off) {
  36175. var l = rStart;
  36176. var r = lStart; // Apply f() x16 times
  36177. for (var i = state.keys.length - 2; i >= 0; i -= 2) {
  36178. var keyL = state.keys[i];
  36179. var keyR = state.keys[i + 1]; // f(r, k)
  36180. utils.expand(l, state.tmp, 0);
  36181. keyL ^= state.tmp[0];
  36182. keyR ^= state.tmp[1];
  36183. var s = utils.substitute(keyL, keyR);
  36184. var f = utils.permute(s);
  36185. var t = l;
  36186. l = (r ^ f) >>> 0;
  36187. r = t;
  36188. } // Reverse Initial Permutation
  36189. utils.rip(l, r, out, off);
  36190. };
  36191. },{"./cipher":341,"./utils":344,"inherits":387,"minimalistic-assert":437}],343:[function(require,module,exports){
  36192. 'use strict';
  36193. var assert = require('minimalistic-assert');
  36194. var inherits = require('inherits');
  36195. var Cipher = require('./cipher');
  36196. var DES = require('./des');
  36197. function EDEState(type, key) {
  36198. assert.equal(key.length, 24, 'Invalid key length');
  36199. var k1 = key.slice(0, 8);
  36200. var k2 = key.slice(8, 16);
  36201. var k3 = key.slice(16, 24);
  36202. if (type === 'encrypt') {
  36203. this.ciphers = [DES.create({
  36204. type: 'encrypt',
  36205. key: k1
  36206. }), DES.create({
  36207. type: 'decrypt',
  36208. key: k2
  36209. }), DES.create({
  36210. type: 'encrypt',
  36211. key: k3
  36212. })];
  36213. } else {
  36214. this.ciphers = [DES.create({
  36215. type: 'decrypt',
  36216. key: k3
  36217. }), DES.create({
  36218. type: 'encrypt',
  36219. key: k2
  36220. }), DES.create({
  36221. type: 'decrypt',
  36222. key: k1
  36223. })];
  36224. }
  36225. }
  36226. function EDE(options) {
  36227. Cipher.call(this, options);
  36228. var state = new EDEState(this.type, this.options.key);
  36229. this._edeState = state;
  36230. }
  36231. inherits(EDE, Cipher);
  36232. module.exports = EDE;
  36233. EDE.create = function create(options) {
  36234. return new EDE(options);
  36235. };
  36236. EDE.prototype._update = function _update(inp, inOff, out, outOff) {
  36237. var state = this._edeState;
  36238. state.ciphers[0]._update(inp, inOff, out, outOff);
  36239. state.ciphers[1]._update(out, outOff, out, outOff);
  36240. state.ciphers[2]._update(out, outOff, out, outOff);
  36241. };
  36242. EDE.prototype._pad = DES.prototype._pad;
  36243. EDE.prototype._unpad = DES.prototype._unpad;
  36244. },{"./cipher":341,"./des":342,"inherits":387,"minimalistic-assert":437}],344:[function(require,module,exports){
  36245. 'use strict';
  36246. exports.readUInt32BE = function readUInt32BE(bytes, off) {
  36247. var res = bytes[0 + off] << 24 | bytes[1 + off] << 16 | bytes[2 + off] << 8 | bytes[3 + off];
  36248. return res >>> 0;
  36249. };
  36250. exports.writeUInt32BE = function writeUInt32BE(bytes, value, off) {
  36251. bytes[0 + off] = value >>> 24;
  36252. bytes[1 + off] = value >>> 16 & 0xff;
  36253. bytes[2 + off] = value >>> 8 & 0xff;
  36254. bytes[3 + off] = value & 0xff;
  36255. };
  36256. exports.ip = function ip(inL, inR, out, off) {
  36257. var outL = 0;
  36258. var outR = 0;
  36259. for (var i = 6; i >= 0; i -= 2) {
  36260. for (var j = 0; j <= 24; j += 8) {
  36261. outL <<= 1;
  36262. outL |= inR >>> j + i & 1;
  36263. }
  36264. for (var j = 0; j <= 24; j += 8) {
  36265. outL <<= 1;
  36266. outL |= inL >>> j + i & 1;
  36267. }
  36268. }
  36269. for (var i = 6; i >= 0; i -= 2) {
  36270. for (var j = 1; j <= 25; j += 8) {
  36271. outR <<= 1;
  36272. outR |= inR >>> j + i & 1;
  36273. }
  36274. for (var j = 1; j <= 25; j += 8) {
  36275. outR <<= 1;
  36276. outR |= inL >>> j + i & 1;
  36277. }
  36278. }
  36279. out[off + 0] = outL >>> 0;
  36280. out[off + 1] = outR >>> 0;
  36281. };
  36282. exports.rip = function rip(inL, inR, out, off) {
  36283. var outL = 0;
  36284. var outR = 0;
  36285. for (var i = 0; i < 4; i++) {
  36286. for (var j = 24; j >= 0; j -= 8) {
  36287. outL <<= 1;
  36288. outL |= inR >>> j + i & 1;
  36289. outL <<= 1;
  36290. outL |= inL >>> j + i & 1;
  36291. }
  36292. }
  36293. for (var i = 4; i < 8; i++) {
  36294. for (var j = 24; j >= 0; j -= 8) {
  36295. outR <<= 1;
  36296. outR |= inR >>> j + i & 1;
  36297. outR <<= 1;
  36298. outR |= inL >>> j + i & 1;
  36299. }
  36300. }
  36301. out[off + 0] = outL >>> 0;
  36302. out[off + 1] = outR >>> 0;
  36303. };
  36304. exports.pc1 = function pc1(inL, inR, out, off) {
  36305. var outL = 0;
  36306. var outR = 0; // 7, 15, 23, 31, 39, 47, 55, 63
  36307. // 6, 14, 22, 30, 39, 47, 55, 63
  36308. // 5, 13, 21, 29, 39, 47, 55, 63
  36309. // 4, 12, 20, 28
  36310. for (var i = 7; i >= 5; i--) {
  36311. for (var j = 0; j <= 24; j += 8) {
  36312. outL <<= 1;
  36313. outL |= inR >> j + i & 1;
  36314. }
  36315. for (var j = 0; j <= 24; j += 8) {
  36316. outL <<= 1;
  36317. outL |= inL >> j + i & 1;
  36318. }
  36319. }
  36320. for (var j = 0; j <= 24; j += 8) {
  36321. outL <<= 1;
  36322. outL |= inR >> j + i & 1;
  36323. } // 1, 9, 17, 25, 33, 41, 49, 57
  36324. // 2, 10, 18, 26, 34, 42, 50, 58
  36325. // 3, 11, 19, 27, 35, 43, 51, 59
  36326. // 36, 44, 52, 60
  36327. for (var i = 1; i <= 3; i++) {
  36328. for (var j = 0; j <= 24; j += 8) {
  36329. outR <<= 1;
  36330. outR |= inR >> j + i & 1;
  36331. }
  36332. for (var j = 0; j <= 24; j += 8) {
  36333. outR <<= 1;
  36334. outR |= inL >> j + i & 1;
  36335. }
  36336. }
  36337. for (var j = 0; j <= 24; j += 8) {
  36338. outR <<= 1;
  36339. outR |= inL >> j + i & 1;
  36340. }
  36341. out[off + 0] = outL >>> 0;
  36342. out[off + 1] = outR >>> 0;
  36343. };
  36344. exports.r28shl = function r28shl(num, shift) {
  36345. return num << shift & 0xfffffff | num >>> 28 - shift;
  36346. };
  36347. var pc2table = [// inL => outL
  36348. 14, 11, 17, 4, 27, 23, 25, 0, 13, 22, 7, 18, 5, 9, 16, 24, 2, 20, 12, 21, 1, 8, 15, 26, // inR => outR
  36349. 15, 4, 25, 19, 9, 1, 26, 16, 5, 11, 23, 8, 12, 7, 17, 0, 22, 3, 10, 14, 6, 20, 27, 24];
  36350. exports.pc2 = function pc2(inL, inR, out, off) {
  36351. var outL = 0;
  36352. var outR = 0;
  36353. var len = pc2table.length >>> 1;
  36354. for (var i = 0; i < len; i++) {
  36355. outL <<= 1;
  36356. outL |= inL >>> pc2table[i] & 0x1;
  36357. }
  36358. for (var i = len; i < pc2table.length; i++) {
  36359. outR <<= 1;
  36360. outR |= inR >>> pc2table[i] & 0x1;
  36361. }
  36362. out[off + 0] = outL >>> 0;
  36363. out[off + 1] = outR >>> 0;
  36364. };
  36365. exports.expand = function expand(r, out, off) {
  36366. var outL = 0;
  36367. var outR = 0;
  36368. outL = (r & 1) << 5 | r >>> 27;
  36369. for (var i = 23; i >= 15; i -= 4) {
  36370. outL <<= 6;
  36371. outL |= r >>> i & 0x3f;
  36372. }
  36373. for (var i = 11; i >= 3; i -= 4) {
  36374. outR |= r >>> i & 0x3f;
  36375. outR <<= 6;
  36376. }
  36377. outR |= (r & 0x1f) << 1 | r >>> 31;
  36378. out[off + 0] = outL >>> 0;
  36379. out[off + 1] = outR >>> 0;
  36380. };
  36381. 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];
  36382. exports.substitute = function substitute(inL, inR) {
  36383. var out = 0;
  36384. for (var i = 0; i < 4; i++) {
  36385. var b = inL >>> 18 - i * 6 & 0x3f;
  36386. var sb = sTable[i * 0x40 + b];
  36387. out <<= 4;
  36388. out |= sb;
  36389. }
  36390. for (var i = 0; i < 4; i++) {
  36391. var b = inR >>> 18 - i * 6 & 0x3f;
  36392. var sb = sTable[4 * 0x40 + i * 0x40 + b];
  36393. out <<= 4;
  36394. out |= sb;
  36395. }
  36396. return out >>> 0;
  36397. };
  36398. 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];
  36399. exports.permute = function permute(num) {
  36400. var out = 0;
  36401. for (var i = 0; i < permuteTable.length; i++) {
  36402. out <<= 1;
  36403. out |= num >>> permuteTable[i] & 0x1;
  36404. }
  36405. return out >>> 0;
  36406. };
  36407. exports.padSplit = function padSplit(num, size, group) {
  36408. var str = num.toString(2);
  36409. while (str.length < size) {
  36410. str = '0' + str;
  36411. }
  36412. var out = [];
  36413. for (var i = 0; i < size; i += group) {
  36414. out.push(str.slice(i, i + group));
  36415. }
  36416. return out.join(' ');
  36417. };
  36418. },{}],345:[function(require,module,exports){
  36419. (function (Buffer){
  36420. "use strict";
  36421. var generatePrime = require('./lib/generatePrime');
  36422. var primes = require('./lib/primes.json');
  36423. var DH = require('./lib/dh');
  36424. function getDiffieHellman(mod) {
  36425. var prime = new Buffer(primes[mod].prime, 'hex');
  36426. var gen = new Buffer(primes[mod].gen, 'hex');
  36427. return new DH(prime, gen);
  36428. }
  36429. var ENCODINGS = {
  36430. 'binary': true,
  36431. 'hex': true,
  36432. 'base64': true
  36433. };
  36434. function createDiffieHellman(prime, enc, generator, genc) {
  36435. if (Buffer.isBuffer(enc) || ENCODINGS[enc] === undefined) {
  36436. return createDiffieHellman(prime, 'binary', enc, generator);
  36437. }
  36438. enc = enc || 'binary';
  36439. genc = genc || 'binary';
  36440. generator = generator || new Buffer([2]);
  36441. if (!Buffer.isBuffer(generator)) {
  36442. generator = new Buffer(generator, genc);
  36443. }
  36444. if (typeof prime === 'number') {
  36445. return new DH(generatePrime(prime, generator), generator, true);
  36446. }
  36447. if (!Buffer.isBuffer(prime)) {
  36448. prime = new Buffer(prime, enc);
  36449. }
  36450. return new DH(prime, generator, true);
  36451. }
  36452. exports.DiffieHellmanGroup = exports.createDiffieHellmanGroup = exports.getDiffieHellman = getDiffieHellman;
  36453. exports.createDiffieHellman = exports.DiffieHellman = createDiffieHellman;
  36454. }).call(this,require("buffer").Buffer)
  36455. },{"./lib/dh":346,"./lib/generatePrime":347,"./lib/primes.json":348,"buffer":216}],346:[function(require,module,exports){
  36456. (function (Buffer){
  36457. "use strict";
  36458. var BN = require('bn.js');
  36459. var MillerRabin = require('miller-rabin');
  36460. var millerRabin = new MillerRabin();
  36461. var TWENTYFOUR = new BN(24);
  36462. var ELEVEN = new BN(11);
  36463. var TEN = new BN(10);
  36464. var THREE = new BN(3);
  36465. var SEVEN = new BN(7);
  36466. var primes = require('./generatePrime');
  36467. var randomBytes = require('randombytes');
  36468. module.exports = DH;
  36469. function setPublicKey(pub, enc) {
  36470. enc = enc || 'utf8';
  36471. if (!Buffer.isBuffer(pub)) {
  36472. pub = new Buffer(pub, enc);
  36473. }
  36474. this._pub = new BN(pub);
  36475. return this;
  36476. }
  36477. function setPrivateKey(priv, enc) {
  36478. enc = enc || 'utf8';
  36479. if (!Buffer.isBuffer(priv)) {
  36480. priv = new Buffer(priv, enc);
  36481. }
  36482. this._priv = new BN(priv);
  36483. return this;
  36484. }
  36485. var primeCache = {};
  36486. function checkPrime(prime, generator) {
  36487. var gen = generator.toString('hex');
  36488. var hex = [gen, prime.toString(16)].join('_');
  36489. if (hex in primeCache) {
  36490. return primeCache[hex];
  36491. }
  36492. var error = 0;
  36493. if (prime.isEven() || !primes.simpleSieve || !primes.fermatTest(prime) || !millerRabin.test(prime)) {
  36494. //not a prime so +1
  36495. error += 1;
  36496. if (gen === '02' || gen === '05') {
  36497. // we'd be able to check the generator
  36498. // it would fail so +8
  36499. error += 8;
  36500. } else {
  36501. //we wouldn't be able to test the generator
  36502. // so +4
  36503. error += 4;
  36504. }
  36505. primeCache[hex] = error;
  36506. return error;
  36507. }
  36508. if (!millerRabin.test(prime.shrn(1))) {
  36509. //not a safe prime
  36510. error += 2;
  36511. }
  36512. var rem;
  36513. switch (gen) {
  36514. case '02':
  36515. if (prime.mod(TWENTYFOUR).cmp(ELEVEN)) {
  36516. // unsuidable generator
  36517. error += 8;
  36518. }
  36519. break;
  36520. case '05':
  36521. rem = prime.mod(TEN);
  36522. if (rem.cmp(THREE) && rem.cmp(SEVEN)) {
  36523. // prime mod 10 needs to equal 3 or 7
  36524. error += 8;
  36525. }
  36526. break;
  36527. default:
  36528. error += 4;
  36529. }
  36530. primeCache[hex] = error;
  36531. return error;
  36532. }
  36533. function DH(prime, generator, malleable) {
  36534. this.setGenerator(generator);
  36535. this.__prime = new BN(prime);
  36536. this._prime = BN.mont(this.__prime);
  36537. this._primeLen = prime.length;
  36538. this._pub = undefined;
  36539. this._priv = undefined;
  36540. this._primeCode = undefined;
  36541. if (malleable) {
  36542. this.setPublicKey = setPublicKey;
  36543. this.setPrivateKey = setPrivateKey;
  36544. } else {
  36545. this._primeCode = 8;
  36546. }
  36547. }
  36548. Object.defineProperty(DH.prototype, 'verifyError', {
  36549. enumerable: true,
  36550. get: function get() {
  36551. if (typeof this._primeCode !== 'number') {
  36552. this._primeCode = checkPrime(this.__prime, this.__gen);
  36553. }
  36554. return this._primeCode;
  36555. }
  36556. });
  36557. DH.prototype.generateKeys = function () {
  36558. if (!this._priv) {
  36559. this._priv = new BN(randomBytes(this._primeLen));
  36560. }
  36561. this._pub = this._gen.toRed(this._prime).redPow(this._priv).fromRed();
  36562. return this.getPublicKey();
  36563. };
  36564. DH.prototype.computeSecret = function (other) {
  36565. other = new BN(other);
  36566. other = other.toRed(this._prime);
  36567. var secret = other.redPow(this._priv).fromRed();
  36568. var out = new Buffer(secret.toArray());
  36569. var prime = this.getPrime();
  36570. if (out.length < prime.length) {
  36571. var front = new Buffer(prime.length - out.length);
  36572. front.fill(0);
  36573. out = Buffer.concat([front, out]);
  36574. }
  36575. return out;
  36576. };
  36577. DH.prototype.getPublicKey = function getPublicKey(enc) {
  36578. return formatReturnValue(this._pub, enc);
  36579. };
  36580. DH.prototype.getPrivateKey = function getPrivateKey(enc) {
  36581. return formatReturnValue(this._priv, enc);
  36582. };
  36583. DH.prototype.getPrime = function (enc) {
  36584. return formatReturnValue(this.__prime, enc);
  36585. };
  36586. DH.prototype.getGenerator = function (enc) {
  36587. return formatReturnValue(this._gen, enc);
  36588. };
  36589. DH.prototype.setGenerator = function (gen, enc) {
  36590. enc = enc || 'utf8';
  36591. if (!Buffer.isBuffer(gen)) {
  36592. gen = new Buffer(gen, enc);
  36593. }
  36594. this.__gen = gen;
  36595. this._gen = new BN(gen);
  36596. return this;
  36597. };
  36598. function formatReturnValue(bn, enc) {
  36599. var buf = new Buffer(bn.toArray());
  36600. if (!enc) {
  36601. return buf;
  36602. } else {
  36603. return buf.toString(enc);
  36604. }
  36605. }
  36606. }).call(this,require("buffer").Buffer)
  36607. },{"./generatePrime":347,"bn.js":349,"buffer":216,"miller-rabin":435,"randombytes":475}],347:[function(require,module,exports){
  36608. "use strict";
  36609. var randomBytes = require('randombytes');
  36610. module.exports = findPrime;
  36611. findPrime.simpleSieve = simpleSieve;
  36612. findPrime.fermatTest = fermatTest;
  36613. var BN = require('bn.js');
  36614. var TWENTYFOUR = new BN(24);
  36615. var MillerRabin = require('miller-rabin');
  36616. var millerRabin = new MillerRabin();
  36617. var ONE = new BN(1);
  36618. var TWO = new BN(2);
  36619. var FIVE = new BN(5);
  36620. var SIXTEEN = new BN(16);
  36621. var EIGHT = new BN(8);
  36622. var TEN = new BN(10);
  36623. var THREE = new BN(3);
  36624. var SEVEN = new BN(7);
  36625. var ELEVEN = new BN(11);
  36626. var FOUR = new BN(4);
  36627. var TWELVE = new BN(12);
  36628. var primes = null;
  36629. function _getPrimes() {
  36630. if (primes !== null) return primes;
  36631. var limit = 0x100000;
  36632. var res = [];
  36633. res[0] = 2;
  36634. for (var i = 1, k = 3; k < limit; k += 2) {
  36635. var sqrt = Math.ceil(Math.sqrt(k));
  36636. for (var j = 0; j < i && res[j] <= sqrt; j++) {
  36637. if (k % res[j] === 0) break;
  36638. }
  36639. if (i !== j && res[j] <= sqrt) continue;
  36640. res[i++] = k;
  36641. }
  36642. primes = res;
  36643. return res;
  36644. }
  36645. function simpleSieve(p) {
  36646. var primes = _getPrimes();
  36647. for (var i = 0; i < primes.length; i++) {
  36648. if (p.modn(primes[i]) === 0) {
  36649. if (p.cmpn(primes[i]) === 0) {
  36650. return true;
  36651. } else {
  36652. return false;
  36653. }
  36654. }
  36655. }
  36656. return true;
  36657. }
  36658. function fermatTest(p) {
  36659. var red = BN.mont(p);
  36660. return TWO.toRed(red).redPow(p.subn(1)).fromRed().cmpn(1) === 0;
  36661. }
  36662. function findPrime(bits, gen) {
  36663. if (bits < 16) {
  36664. // this is what openssl does
  36665. if (gen === 2 || gen === 5) {
  36666. return new BN([0x8c, 0x7b]);
  36667. } else {
  36668. return new BN([0x8c, 0x27]);
  36669. }
  36670. }
  36671. gen = new BN(gen);
  36672. var num, n2;
  36673. while (true) {
  36674. num = new BN(randomBytes(Math.ceil(bits / 8)));
  36675. while (num.bitLength() > bits) {
  36676. num.ishrn(1);
  36677. }
  36678. if (num.isEven()) {
  36679. num.iadd(ONE);
  36680. }
  36681. if (!num.testn(1)) {
  36682. num.iadd(TWO);
  36683. }
  36684. if (!gen.cmp(TWO)) {
  36685. while (num.mod(TWENTYFOUR).cmp(ELEVEN)) {
  36686. num.iadd(FOUR);
  36687. }
  36688. } else if (!gen.cmp(FIVE)) {
  36689. while (num.mod(TEN).cmp(THREE)) {
  36690. num.iadd(FOUR);
  36691. }
  36692. }
  36693. n2 = num.shrn(1);
  36694. if (simpleSieve(n2) && simpleSieve(num) && fermatTest(n2) && fermatTest(num) && millerRabin.test(n2) && millerRabin.test(num)) {
  36695. return num;
  36696. }
  36697. }
  36698. }
  36699. },{"bn.js":349,"miller-rabin":435,"randombytes":475}],348:[function(require,module,exports){
  36700. module.exports={
  36701. "modp1": {
  36702. "gen": "02",
  36703. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a63a3620ffffffffffffffff"
  36704. },
  36705. "modp2": {
  36706. "gen": "02",
  36707. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece65381ffffffffffffffff"
  36708. },
  36709. "modp5": {
  36710. "gen": "02",
  36711. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca237327ffffffffffffffff"
  36712. },
  36713. "modp14": {
  36714. "gen": "02",
  36715. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aacaa68ffffffffffffffff"
  36716. },
  36717. "modp15": {
  36718. "gen": "02",
  36719. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a93ad2caffffffffffffffff"
  36720. },
  36721. "modp16": {
  36722. "gen": "02",
  36723. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c934063199ffffffffffffffff"
  36724. },
  36725. "modp17": {
  36726. "gen": "02",
  36727. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dcc4024ffffffffffffffff"
  36728. },
  36729. "modp18": {
  36730. "gen": "02",
  36731. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dbe115974a3926f12fee5e438777cb6a932df8cd8bec4d073b931ba3bc832b68d9dd300741fa7bf8afc47ed2576f6936ba424663aab639c5ae4f5683423b4742bf1c978238f16cbe39d652de3fdb8befc848ad922222e04a4037c0713eb57a81a23f0c73473fc646cea306b4bcbc8862f8385ddfa9d4b7fa2c087e879683303ed5bdd3a062b3cf5b3a278a66d2a13f83f44f82ddf310ee074ab6a364597e899a0255dc164f31cc50846851df9ab48195ded7ea1b1d510bd7ee74d73faf36bc31ecfa268359046f4eb879f924009438b481c6cd7889a002ed5ee382bc9190da6fc026e479558e4475677e9aa9e3050e2765694dfc81f56e880b96e7160c980dd98edd3dfffffffffffffffff"
  36732. }
  36733. }
  36734. },{}],349:[function(require,module,exports){
  36735. arguments[4][181][0].apply(exports,arguments)
  36736. },{"buffer":185,"dup":181}],350:[function(require,module,exports){
  36737. 'use strict';
  36738. var elliptic = exports;
  36739. elliptic.version = require('../package.json').version;
  36740. elliptic.utils = require('./elliptic/utils');
  36741. elliptic.rand = require('brorand');
  36742. elliptic.curve = require('./elliptic/curve');
  36743. elliptic.curves = require('./elliptic/curves'); // Protocols
  36744. elliptic.ec = require('./elliptic/ec');
  36745. elliptic.eddsa = require('./elliptic/eddsa');
  36746. },{"../package.json":366,"./elliptic/curve":353,"./elliptic/curves":356,"./elliptic/ec":357,"./elliptic/eddsa":360,"./elliptic/utils":364,"brorand":184}],351:[function(require,module,exports){
  36747. 'use strict';
  36748. var BN = require('bn.js');
  36749. var utils = require('../utils');
  36750. var getNAF = utils.getNAF;
  36751. var getJSF = utils.getJSF;
  36752. var assert = utils.assert;
  36753. function BaseCurve(type, conf) {
  36754. this.type = type;
  36755. this.p = new BN(conf.p, 16); // Use Montgomery, when there is no fast reduction for the prime
  36756. this.red = conf.prime ? BN.red(conf.prime) : BN.mont(this.p); // Useful for many curves
  36757. this.zero = new BN(0).toRed(this.red);
  36758. this.one = new BN(1).toRed(this.red);
  36759. this.two = new BN(2).toRed(this.red); // Curve configuration, optional
  36760. this.n = conf.n && new BN(conf.n, 16);
  36761. this.g = conf.g && this.pointFromJSON(conf.g, conf.gRed); // Temporary arrays
  36762. this._wnafT1 = new Array(4);
  36763. this._wnafT2 = new Array(4);
  36764. this._wnafT3 = new Array(4);
  36765. this._wnafT4 = new Array(4);
  36766. this._bitLength = this.n ? this.n.bitLength() : 0; // Generalized Greg Maxwell's trick
  36767. var adjustCount = this.n && this.p.div(this.n);
  36768. if (!adjustCount || adjustCount.cmpn(100) > 0) {
  36769. this.redN = null;
  36770. } else {
  36771. this._maxwellTrick = true;
  36772. this.redN = this.n.toRed(this.red);
  36773. }
  36774. }
  36775. module.exports = BaseCurve;
  36776. BaseCurve.prototype.point = function point() {
  36777. throw new Error('Not implemented');
  36778. };
  36779. BaseCurve.prototype.validate = function validate() {
  36780. throw new Error('Not implemented');
  36781. };
  36782. BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) {
  36783. assert(p.precomputed);
  36784. var doubles = p._getDoubles();
  36785. var naf = getNAF(k, 1, this._bitLength);
  36786. var I = (1 << doubles.step + 1) - (doubles.step % 2 === 0 ? 2 : 1);
  36787. I /= 3; // Translate into more windowed form
  36788. var repr = [];
  36789. for (var j = 0; j < naf.length; j += doubles.step) {
  36790. var nafW = 0;
  36791. for (var k = j + doubles.step - 1; k >= j; k--) {
  36792. nafW = (nafW << 1) + naf[k];
  36793. }
  36794. repr.push(nafW);
  36795. }
  36796. var a = this.jpoint(null, null, null);
  36797. var b = this.jpoint(null, null, null);
  36798. for (var i = I; i > 0; i--) {
  36799. for (var j = 0; j < repr.length; j++) {
  36800. var nafW = repr[j];
  36801. if (nafW === i) b = b.mixedAdd(doubles.points[j]);else if (nafW === -i) b = b.mixedAdd(doubles.points[j].neg());
  36802. }
  36803. a = a.add(b);
  36804. }
  36805. return a.toP();
  36806. };
  36807. BaseCurve.prototype._wnafMul = function _wnafMul(p, k) {
  36808. var w = 4; // Precompute window
  36809. var nafPoints = p._getNAFPoints(w);
  36810. w = nafPoints.wnd;
  36811. var wnd = nafPoints.points; // Get NAF form
  36812. var naf = getNAF(k, w, this._bitLength); // Add `this`*(N+1) for every w-NAF index
  36813. var acc = this.jpoint(null, null, null);
  36814. for (var i = naf.length - 1; i >= 0; i--) {
  36815. // Count zeroes
  36816. for (var k = 0; i >= 0 && naf[i] === 0; i--) {
  36817. k++;
  36818. }
  36819. if (i >= 0) k++;
  36820. acc = acc.dblp(k);
  36821. if (i < 0) break;
  36822. var z = naf[i];
  36823. assert(z !== 0);
  36824. if (p.type === 'affine') {
  36825. // J +- P
  36826. if (z > 0) acc = acc.mixedAdd(wnd[z - 1 >> 1]);else acc = acc.mixedAdd(wnd[-z - 1 >> 1].neg());
  36827. } else {
  36828. // J +- J
  36829. if (z > 0) acc = acc.add(wnd[z - 1 >> 1]);else acc = acc.add(wnd[-z - 1 >> 1].neg());
  36830. }
  36831. }
  36832. return p.type === 'affine' ? acc.toP() : acc;
  36833. };
  36834. BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW, points, coeffs, len, jacobianResult) {
  36835. var wndWidth = this._wnafT1;
  36836. var wnd = this._wnafT2;
  36837. var naf = this._wnafT3; // Fill all arrays
  36838. var max = 0;
  36839. for (var i = 0; i < len; i++) {
  36840. var p = points[i];
  36841. var nafPoints = p._getNAFPoints(defW);
  36842. wndWidth[i] = nafPoints.wnd;
  36843. wnd[i] = nafPoints.points;
  36844. } // Comb small window NAFs
  36845. for (var i = len - 1; i >= 1; i -= 2) {
  36846. var a = i - 1;
  36847. var b = i;
  36848. if (wndWidth[a] !== 1 || wndWidth[b] !== 1) {
  36849. naf[a] = getNAF(coeffs[a], wndWidth[a], this._bitLength);
  36850. naf[b] = getNAF(coeffs[b], wndWidth[b], this._bitLength);
  36851. max = Math.max(naf[a].length, max);
  36852. max = Math.max(naf[b].length, max);
  36853. continue;
  36854. }
  36855. var comb = [points[a],
  36856. /* 1 */
  36857. null,
  36858. /* 3 */
  36859. null,
  36860. /* 5 */
  36861. points[b]
  36862. /* 7 */
  36863. ]; // Try to avoid Projective points, if possible
  36864. if (points[a].y.cmp(points[b].y) === 0) {
  36865. comb[1] = points[a].add(points[b]);
  36866. comb[2] = points[a].toJ().mixedAdd(points[b].neg());
  36867. } else if (points[a].y.cmp(points[b].y.redNeg()) === 0) {
  36868. comb[1] = points[a].toJ().mixedAdd(points[b]);
  36869. comb[2] = points[a].add(points[b].neg());
  36870. } else {
  36871. comb[1] = points[a].toJ().mixedAdd(points[b]);
  36872. comb[2] = points[a].toJ().mixedAdd(points[b].neg());
  36873. }
  36874. var index = [-3,
  36875. /* -1 -1 */
  36876. -1,
  36877. /* -1 0 */
  36878. -5,
  36879. /* -1 1 */
  36880. -7,
  36881. /* 0 -1 */
  36882. 0,
  36883. /* 0 0 */
  36884. 7,
  36885. /* 0 1 */
  36886. 5,
  36887. /* 1 -1 */
  36888. 1,
  36889. /* 1 0 */
  36890. 3
  36891. /* 1 1 */
  36892. ];
  36893. var jsf = getJSF(coeffs[a], coeffs[b]);
  36894. max = Math.max(jsf[0].length, max);
  36895. naf[a] = new Array(max);
  36896. naf[b] = new Array(max);
  36897. for (var j = 0; j < max; j++) {
  36898. var ja = jsf[0][j] | 0;
  36899. var jb = jsf[1][j] | 0;
  36900. naf[a][j] = index[(ja + 1) * 3 + (jb + 1)];
  36901. naf[b][j] = 0;
  36902. wnd[a] = comb;
  36903. }
  36904. }
  36905. var acc = this.jpoint(null, null, null);
  36906. var tmp = this._wnafT4;
  36907. for (var i = max; i >= 0; i--) {
  36908. var k = 0;
  36909. while (i >= 0) {
  36910. var zero = true;
  36911. for (var j = 0; j < len; j++) {
  36912. tmp[j] = naf[j][i] | 0;
  36913. if (tmp[j] !== 0) zero = false;
  36914. }
  36915. if (!zero) break;
  36916. k++;
  36917. i--;
  36918. }
  36919. if (i >= 0) k++;
  36920. acc = acc.dblp(k);
  36921. if (i < 0) break;
  36922. for (var j = 0; j < len; j++) {
  36923. var z = tmp[j];
  36924. var p;
  36925. 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();
  36926. if (p.type === 'affine') acc = acc.mixedAdd(p);else acc = acc.add(p);
  36927. }
  36928. } // Zeroify references
  36929. for (var i = 0; i < len; i++) {
  36930. wnd[i] = null;
  36931. }
  36932. if (jacobianResult) return acc;else return acc.toP();
  36933. };
  36934. function BasePoint(curve, type) {
  36935. this.curve = curve;
  36936. this.type = type;
  36937. this.precomputed = null;
  36938. }
  36939. BaseCurve.BasePoint = BasePoint;
  36940. BasePoint.prototype.eq = function eq()
  36941. /*other*/
  36942. {
  36943. throw new Error('Not implemented');
  36944. };
  36945. BasePoint.prototype.validate = function validate() {
  36946. return this.curve.validate(this);
  36947. };
  36948. BaseCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
  36949. bytes = utils.toArray(bytes, enc);
  36950. var len = this.p.byteLength(); // uncompressed, hybrid-odd, hybrid-even
  36951. if ((bytes[0] === 0x04 || bytes[0] === 0x06 || bytes[0] === 0x07) && bytes.length - 1 === 2 * len) {
  36952. if (bytes[0] === 0x06) assert(bytes[bytes.length - 1] % 2 === 0);else if (bytes[0] === 0x07) assert(bytes[bytes.length - 1] % 2 === 1);
  36953. var res = this.point(bytes.slice(1, 1 + len), bytes.slice(1 + len, 1 + 2 * len));
  36954. return res;
  36955. } else if ((bytes[0] === 0x02 || bytes[0] === 0x03) && bytes.length - 1 === len) {
  36956. return this.pointFromX(bytes.slice(1, 1 + len), bytes[0] === 0x03);
  36957. }
  36958. throw new Error('Unknown point format');
  36959. };
  36960. BasePoint.prototype.encodeCompressed = function encodeCompressed(enc) {
  36961. return this.encode(enc, true);
  36962. };
  36963. BasePoint.prototype._encode = function _encode(compact) {
  36964. var len = this.curve.p.byteLength();
  36965. var x = this.getX().toArray('be', len);
  36966. if (compact) return [this.getY().isEven() ? 0x02 : 0x03].concat(x);
  36967. return [0x04].concat(x, this.getY().toArray('be', len));
  36968. };
  36969. BasePoint.prototype.encode = function encode(enc, compact) {
  36970. return utils.encode(this._encode(compact), enc);
  36971. };
  36972. BasePoint.prototype.precompute = function precompute(power) {
  36973. if (this.precomputed) return this;
  36974. var precomputed = {
  36975. doubles: null,
  36976. naf: null,
  36977. beta: null
  36978. };
  36979. precomputed.naf = this._getNAFPoints(8);
  36980. precomputed.doubles = this._getDoubles(4, power);
  36981. precomputed.beta = this._getBeta();
  36982. this.precomputed = precomputed;
  36983. return this;
  36984. };
  36985. BasePoint.prototype._hasDoubles = function _hasDoubles(k) {
  36986. if (!this.precomputed) return false;
  36987. var doubles = this.precomputed.doubles;
  36988. if (!doubles) return false;
  36989. return doubles.points.length >= Math.ceil((k.bitLength() + 1) / doubles.step);
  36990. };
  36991. BasePoint.prototype._getDoubles = function _getDoubles(step, power) {
  36992. if (this.precomputed && this.precomputed.doubles) return this.precomputed.doubles;
  36993. var doubles = [this];
  36994. var acc = this;
  36995. for (var i = 0; i < power; i += step) {
  36996. for (var j = 0; j < step; j++) {
  36997. acc = acc.dbl();
  36998. }
  36999. doubles.push(acc);
  37000. }
  37001. return {
  37002. step: step,
  37003. points: doubles
  37004. };
  37005. };
  37006. BasePoint.prototype._getNAFPoints = function _getNAFPoints(wnd) {
  37007. if (this.precomputed && this.precomputed.naf) return this.precomputed.naf;
  37008. var res = [this];
  37009. var max = (1 << wnd) - 1;
  37010. var dbl = max === 1 ? null : this.dbl();
  37011. for (var i = 1; i < max; i++) {
  37012. res[i] = res[i - 1].add(dbl);
  37013. }
  37014. return {
  37015. wnd: wnd,
  37016. points: res
  37017. };
  37018. };
  37019. BasePoint.prototype._getBeta = function _getBeta() {
  37020. return null;
  37021. };
  37022. BasePoint.prototype.dblp = function dblp(k) {
  37023. var r = this;
  37024. for (var i = 0; i < k; i++) {
  37025. r = r.dbl();
  37026. }
  37027. return r;
  37028. };
  37029. },{"../utils":364,"bn.js":365}],352:[function(require,module,exports){
  37030. 'use strict';
  37031. var utils = require('../utils');
  37032. var BN = require('bn.js');
  37033. var inherits = require('inherits');
  37034. var Base = require('./base');
  37035. var assert = utils.assert;
  37036. function EdwardsCurve(conf) {
  37037. // NOTE: Important as we are creating point in Base.call()
  37038. this.twisted = (conf.a | 0) !== 1;
  37039. this.mOneA = this.twisted && (conf.a | 0) === -1;
  37040. this.extended = this.mOneA;
  37041. Base.call(this, 'edwards', conf);
  37042. this.a = new BN(conf.a, 16).umod(this.red.m);
  37043. this.a = this.a.toRed(this.red);
  37044. this.c = new BN(conf.c, 16).toRed(this.red);
  37045. this.c2 = this.c.redSqr();
  37046. this.d = new BN(conf.d, 16).toRed(this.red);
  37047. this.dd = this.d.redAdd(this.d);
  37048. assert(!this.twisted || this.c.fromRed().cmpn(1) === 0);
  37049. this.oneC = (conf.c | 0) === 1;
  37050. }
  37051. inherits(EdwardsCurve, Base);
  37052. module.exports = EdwardsCurve;
  37053. EdwardsCurve.prototype._mulA = function _mulA(num) {
  37054. if (this.mOneA) return num.redNeg();else return this.a.redMul(num);
  37055. };
  37056. EdwardsCurve.prototype._mulC = function _mulC(num) {
  37057. if (this.oneC) return num;else return this.c.redMul(num);
  37058. }; // Just for compatibility with Short curve
  37059. EdwardsCurve.prototype.jpoint = function jpoint(x, y, z, t) {
  37060. return this.point(x, y, z, t);
  37061. };
  37062. EdwardsCurve.prototype.pointFromX = function pointFromX(x, odd) {
  37063. x = new BN(x, 16);
  37064. if (!x.red) x = x.toRed(this.red);
  37065. var x2 = x.redSqr();
  37066. var rhs = this.c2.redSub(this.a.redMul(x2));
  37067. var lhs = this.one.redSub(this.c2.redMul(this.d).redMul(x2));
  37068. var y2 = rhs.redMul(lhs.redInvm());
  37069. var y = y2.redSqrt();
  37070. if (y.redSqr().redSub(y2).cmp(this.zero) !== 0) throw new Error('invalid point');
  37071. var isOdd = y.fromRed().isOdd();
  37072. if (odd && !isOdd || !odd && isOdd) y = y.redNeg();
  37073. return this.point(x, y);
  37074. };
  37075. EdwardsCurve.prototype.pointFromY = function pointFromY(y, odd) {
  37076. y = new BN(y, 16);
  37077. if (!y.red) y = y.toRed(this.red); // x^2 = (y^2 - c^2) / (c^2 d y^2 - a)
  37078. var y2 = y.redSqr();
  37079. var lhs = y2.redSub(this.c2);
  37080. var rhs = y2.redMul(this.d).redMul(this.c2).redSub(this.a);
  37081. var x2 = lhs.redMul(rhs.redInvm());
  37082. if (x2.cmp(this.zero) === 0) {
  37083. if (odd) throw new Error('invalid point');else return this.point(this.zero, y);
  37084. }
  37085. var x = x2.redSqrt();
  37086. if (x.redSqr().redSub(x2).cmp(this.zero) !== 0) throw new Error('invalid point');
  37087. if (x.fromRed().isOdd() !== odd) x = x.redNeg();
  37088. return this.point(x, y);
  37089. };
  37090. EdwardsCurve.prototype.validate = function validate(point) {
  37091. if (point.isInfinity()) return true; // Curve: A * X^2 + Y^2 = C^2 * (1 + D * X^2 * Y^2)
  37092. point.normalize();
  37093. var x2 = point.x.redSqr();
  37094. var y2 = point.y.redSqr();
  37095. var lhs = x2.redMul(this.a).redAdd(y2);
  37096. var rhs = this.c2.redMul(this.one.redAdd(this.d.redMul(x2).redMul(y2)));
  37097. return lhs.cmp(rhs) === 0;
  37098. };
  37099. function Point(curve, x, y, z, t) {
  37100. Base.BasePoint.call(this, curve, 'projective');
  37101. if (x === null && y === null && z === null) {
  37102. this.x = this.curve.zero;
  37103. this.y = this.curve.one;
  37104. this.z = this.curve.one;
  37105. this.t = this.curve.zero;
  37106. this.zOne = true;
  37107. } else {
  37108. this.x = new BN(x, 16);
  37109. this.y = new BN(y, 16);
  37110. this.z = z ? new BN(z, 16) : this.curve.one;
  37111. this.t = t && new BN(t, 16);
  37112. if (!this.x.red) this.x = this.x.toRed(this.curve.red);
  37113. if (!this.y.red) this.y = this.y.toRed(this.curve.red);
  37114. if (!this.z.red) this.z = this.z.toRed(this.curve.red);
  37115. if (this.t && !this.t.red) this.t = this.t.toRed(this.curve.red);
  37116. this.zOne = this.z === this.curve.one; // Use extended coordinates
  37117. if (this.curve.extended && !this.t) {
  37118. this.t = this.x.redMul(this.y);
  37119. if (!this.zOne) this.t = this.t.redMul(this.z.redInvm());
  37120. }
  37121. }
  37122. }
  37123. inherits(Point, Base.BasePoint);
  37124. EdwardsCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
  37125. return Point.fromJSON(this, obj);
  37126. };
  37127. EdwardsCurve.prototype.point = function point(x, y, z, t) {
  37128. return new Point(this, x, y, z, t);
  37129. };
  37130. Point.fromJSON = function fromJSON(curve, obj) {
  37131. return new Point(curve, obj[0], obj[1], obj[2]);
  37132. };
  37133. Point.prototype.inspect = function inspect() {
  37134. if (this.isInfinity()) return '<EC Point Infinity>';
  37135. return '<EC Point x: ' + this.x.fromRed().toString(16, 2) + ' y: ' + this.y.fromRed().toString(16, 2) + ' z: ' + this.z.fromRed().toString(16, 2) + '>';
  37136. };
  37137. Point.prototype.isInfinity = function isInfinity() {
  37138. // XXX This code assumes that zero is always zero in red
  37139. return this.x.cmpn(0) === 0 && (this.y.cmp(this.z) === 0 || this.zOne && this.y.cmp(this.curve.c) === 0);
  37140. };
  37141. Point.prototype._extDbl = function _extDbl() {
  37142. // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
  37143. // #doubling-dbl-2008-hwcd
  37144. // 4M + 4S
  37145. // A = X1^2
  37146. var a = this.x.redSqr(); // B = Y1^2
  37147. var b = this.y.redSqr(); // C = 2 * Z1^2
  37148. var c = this.z.redSqr();
  37149. c = c.redIAdd(c); // D = a * A
  37150. var d = this.curve._mulA(a); // E = (X1 + Y1)^2 - A - B
  37151. var e = this.x.redAdd(this.y).redSqr().redISub(a).redISub(b); // G = D + B
  37152. var g = d.redAdd(b); // F = G - C
  37153. var f = g.redSub(c); // H = D - B
  37154. var h = d.redSub(b); // X3 = E * F
  37155. var nx = e.redMul(f); // Y3 = G * H
  37156. var ny = g.redMul(h); // T3 = E * H
  37157. var nt = e.redMul(h); // Z3 = F * G
  37158. var nz = f.redMul(g);
  37159. return this.curve.point(nx, ny, nz, nt);
  37160. };
  37161. Point.prototype._projDbl = function _projDbl() {
  37162. // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
  37163. // #doubling-dbl-2008-bbjlp
  37164. // #doubling-dbl-2007-bl
  37165. // and others
  37166. // Generally 3M + 4S or 2M + 4S
  37167. // B = (X1 + Y1)^2
  37168. var b = this.x.redAdd(this.y).redSqr(); // C = X1^2
  37169. var c = this.x.redSqr(); // D = Y1^2
  37170. var d = this.y.redSqr();
  37171. var nx;
  37172. var ny;
  37173. var nz;
  37174. if (this.curve.twisted) {
  37175. // E = a * C
  37176. var e = this.curve._mulA(c); // F = E + D
  37177. var f = e.redAdd(d);
  37178. if (this.zOne) {
  37179. // X3 = (B - C - D) * (F - 2)
  37180. nx = b.redSub(c).redSub(d).redMul(f.redSub(this.curve.two)); // Y3 = F * (E - D)
  37181. ny = f.redMul(e.redSub(d)); // Z3 = F^2 - 2 * F
  37182. nz = f.redSqr().redSub(f).redSub(f);
  37183. } else {
  37184. // H = Z1^2
  37185. var h = this.z.redSqr(); // J = F - 2 * H
  37186. var j = f.redSub(h).redISub(h); // X3 = (B-C-D)*J
  37187. nx = b.redSub(c).redISub(d).redMul(j); // Y3 = F * (E - D)
  37188. ny = f.redMul(e.redSub(d)); // Z3 = F * J
  37189. nz = f.redMul(j);
  37190. }
  37191. } else {
  37192. // E = C + D
  37193. var e = c.redAdd(d); // H = (c * Z1)^2
  37194. var h = this.curve._mulC(this.z).redSqr(); // J = E - 2 * H
  37195. var j = e.redSub(h).redSub(h); // X3 = c * (B - E) * J
  37196. nx = this.curve._mulC(b.redISub(e)).redMul(j); // Y3 = c * E * (C - D)
  37197. ny = this.curve._mulC(e).redMul(c.redISub(d)); // Z3 = E * J
  37198. nz = e.redMul(j);
  37199. }
  37200. return this.curve.point(nx, ny, nz);
  37201. };
  37202. Point.prototype.dbl = function dbl() {
  37203. if (this.isInfinity()) return this; // Double in extended coordinates
  37204. if (this.curve.extended) return this._extDbl();else return this._projDbl();
  37205. };
  37206. Point.prototype._extAdd = function _extAdd(p) {
  37207. // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
  37208. // #addition-add-2008-hwcd-3
  37209. // 8M
  37210. // A = (Y1 - X1) * (Y2 - X2)
  37211. var a = this.y.redSub(this.x).redMul(p.y.redSub(p.x)); // B = (Y1 + X1) * (Y2 + X2)
  37212. var b = this.y.redAdd(this.x).redMul(p.y.redAdd(p.x)); // C = T1 * k * T2
  37213. var c = this.t.redMul(this.curve.dd).redMul(p.t); // D = Z1 * 2 * Z2
  37214. var d = this.z.redMul(p.z.redAdd(p.z)); // E = B - A
  37215. var e = b.redSub(a); // F = D - C
  37216. var f = d.redSub(c); // G = D + C
  37217. var g = d.redAdd(c); // H = B + A
  37218. var h = b.redAdd(a); // X3 = E * F
  37219. var nx = e.redMul(f); // Y3 = G * H
  37220. var ny = g.redMul(h); // T3 = E * H
  37221. var nt = e.redMul(h); // Z3 = F * G
  37222. var nz = f.redMul(g);
  37223. return this.curve.point(nx, ny, nz, nt);
  37224. };
  37225. Point.prototype._projAdd = function _projAdd(p) {
  37226. // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
  37227. // #addition-add-2008-bbjlp
  37228. // #addition-add-2007-bl
  37229. // 10M + 1S
  37230. // A = Z1 * Z2
  37231. var a = this.z.redMul(p.z); // B = A^2
  37232. var b = a.redSqr(); // C = X1 * X2
  37233. var c = this.x.redMul(p.x); // D = Y1 * Y2
  37234. var d = this.y.redMul(p.y); // E = d * C * D
  37235. var e = this.curve.d.redMul(c).redMul(d); // F = B - E
  37236. var f = b.redSub(e); // G = B + E
  37237. var g = b.redAdd(e); // X3 = A * F * ((X1 + Y1) * (X2 + Y2) - C - D)
  37238. var tmp = this.x.redAdd(this.y).redMul(p.x.redAdd(p.y)).redISub(c).redISub(d);
  37239. var nx = a.redMul(f).redMul(tmp);
  37240. var ny;
  37241. var nz;
  37242. if (this.curve.twisted) {
  37243. // Y3 = A * G * (D - a * C)
  37244. ny = a.redMul(g).redMul(d.redSub(this.curve._mulA(c))); // Z3 = F * G
  37245. nz = f.redMul(g);
  37246. } else {
  37247. // Y3 = A * G * (D - C)
  37248. ny = a.redMul(g).redMul(d.redSub(c)); // Z3 = c * F * G
  37249. nz = this.curve._mulC(f).redMul(g);
  37250. }
  37251. return this.curve.point(nx, ny, nz);
  37252. };
  37253. Point.prototype.add = function add(p) {
  37254. if (this.isInfinity()) return p;
  37255. if (p.isInfinity()) return this;
  37256. if (this.curve.extended) return this._extAdd(p);else return this._projAdd(p);
  37257. };
  37258. Point.prototype.mul = function mul(k) {
  37259. if (this._hasDoubles(k)) return this.curve._fixedNafMul(this, k);else return this.curve._wnafMul(this, k);
  37260. };
  37261. Point.prototype.mulAdd = function mulAdd(k1, p, k2) {
  37262. return this.curve._wnafMulAdd(1, [this, p], [k1, k2], 2, false);
  37263. };
  37264. Point.prototype.jmulAdd = function jmulAdd(k1, p, k2) {
  37265. return this.curve._wnafMulAdd(1, [this, p], [k1, k2], 2, true);
  37266. };
  37267. Point.prototype.normalize = function normalize() {
  37268. if (this.zOne) return this; // Normalize coordinates
  37269. var zi = this.z.redInvm();
  37270. this.x = this.x.redMul(zi);
  37271. this.y = this.y.redMul(zi);
  37272. if (this.t) this.t = this.t.redMul(zi);
  37273. this.z = this.curve.one;
  37274. this.zOne = true;
  37275. return this;
  37276. };
  37277. Point.prototype.neg = function neg() {
  37278. return this.curve.point(this.x.redNeg(), this.y, this.z, this.t && this.t.redNeg());
  37279. };
  37280. Point.prototype.getX = function getX() {
  37281. this.normalize();
  37282. return this.x.fromRed();
  37283. };
  37284. Point.prototype.getY = function getY() {
  37285. this.normalize();
  37286. return this.y.fromRed();
  37287. };
  37288. Point.prototype.eq = function eq(other) {
  37289. return this === other || this.getX().cmp(other.getX()) === 0 && this.getY().cmp(other.getY()) === 0;
  37290. };
  37291. Point.prototype.eqXToP = function eqXToP(x) {
  37292. var rx = x.toRed(this.curve.red).redMul(this.z);
  37293. if (this.x.cmp(rx) === 0) return true;
  37294. var xc = x.clone();
  37295. var t = this.curve.redN.redMul(this.z);
  37296. for (;;) {
  37297. xc.iadd(this.curve.n);
  37298. if (xc.cmp(this.curve.p) >= 0) return false;
  37299. rx.redIAdd(t);
  37300. if (this.x.cmp(rx) === 0) return true;
  37301. }
  37302. }; // Compatibility with BaseCurve
  37303. Point.prototype.toP = Point.prototype.normalize;
  37304. Point.prototype.mixedAdd = Point.prototype.add;
  37305. },{"../utils":364,"./base":351,"bn.js":365,"inherits":387}],353:[function(require,module,exports){
  37306. 'use strict';
  37307. var curve = exports;
  37308. curve.base = require('./base');
  37309. curve.short = require('./short');
  37310. curve.mont = require('./mont');
  37311. curve.edwards = require('./edwards');
  37312. },{"./base":351,"./edwards":352,"./mont":354,"./short":355}],354:[function(require,module,exports){
  37313. 'use strict';
  37314. var BN = require('bn.js');
  37315. var inherits = require('inherits');
  37316. var Base = require('./base');
  37317. var utils = require('../utils');
  37318. function MontCurve(conf) {
  37319. Base.call(this, 'mont', conf);
  37320. this.a = new BN(conf.a, 16).toRed(this.red);
  37321. this.b = new BN(conf.b, 16).toRed(this.red);
  37322. this.i4 = new BN(4).toRed(this.red).redInvm();
  37323. this.two = new BN(2).toRed(this.red);
  37324. this.a24 = this.i4.redMul(this.a.redAdd(this.two));
  37325. }
  37326. inherits(MontCurve, Base);
  37327. module.exports = MontCurve;
  37328. MontCurve.prototype.validate = function validate(point) {
  37329. var x = point.normalize().x;
  37330. var x2 = x.redSqr();
  37331. var rhs = x2.redMul(x).redAdd(x2.redMul(this.a)).redAdd(x);
  37332. var y = rhs.redSqrt();
  37333. return y.redSqr().cmp(rhs) === 0;
  37334. };
  37335. function Point(curve, x, z) {
  37336. Base.BasePoint.call(this, curve, 'projective');
  37337. if (x === null && z === null) {
  37338. this.x = this.curve.one;
  37339. this.z = this.curve.zero;
  37340. } else {
  37341. this.x = new BN(x, 16);
  37342. this.z = new BN(z, 16);
  37343. if (!this.x.red) this.x = this.x.toRed(this.curve.red);
  37344. if (!this.z.red) this.z = this.z.toRed(this.curve.red);
  37345. }
  37346. }
  37347. inherits(Point, Base.BasePoint);
  37348. MontCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
  37349. return this.point(utils.toArray(bytes, enc), 1);
  37350. };
  37351. MontCurve.prototype.point = function point(x, z) {
  37352. return new Point(this, x, z);
  37353. };
  37354. MontCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
  37355. return Point.fromJSON(this, obj);
  37356. };
  37357. Point.prototype.precompute = function precompute() {// No-op
  37358. };
  37359. Point.prototype._encode = function _encode() {
  37360. return this.getX().toArray('be', this.curve.p.byteLength());
  37361. };
  37362. Point.fromJSON = function fromJSON(curve, obj) {
  37363. return new Point(curve, obj[0], obj[1] || curve.one);
  37364. };
  37365. Point.prototype.inspect = function inspect() {
  37366. if (this.isInfinity()) return '<EC Point Infinity>';
  37367. return '<EC Point x: ' + this.x.fromRed().toString(16, 2) + ' z: ' + this.z.fromRed().toString(16, 2) + '>';
  37368. };
  37369. Point.prototype.isInfinity = function isInfinity() {
  37370. // XXX This code assumes that zero is always zero in red
  37371. return this.z.cmpn(0) === 0;
  37372. };
  37373. Point.prototype.dbl = function dbl() {
  37374. // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#doubling-dbl-1987-m-3
  37375. // 2M + 2S + 4A
  37376. // A = X1 + Z1
  37377. var a = this.x.redAdd(this.z); // AA = A^2
  37378. var aa = a.redSqr(); // B = X1 - Z1
  37379. var b = this.x.redSub(this.z); // BB = B^2
  37380. var bb = b.redSqr(); // C = AA - BB
  37381. var c = aa.redSub(bb); // X3 = AA * BB
  37382. var nx = aa.redMul(bb); // Z3 = C * (BB + A24 * C)
  37383. var nz = c.redMul(bb.redAdd(this.curve.a24.redMul(c)));
  37384. return this.curve.point(nx, nz);
  37385. };
  37386. Point.prototype.add = function add() {
  37387. throw new Error('Not supported on Montgomery curve');
  37388. };
  37389. Point.prototype.diffAdd = function diffAdd(p, diff) {
  37390. // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#diffadd-dadd-1987-m-3
  37391. // 4M + 2S + 6A
  37392. // A = X2 + Z2
  37393. var a = this.x.redAdd(this.z); // B = X2 - Z2
  37394. var b = this.x.redSub(this.z); // C = X3 + Z3
  37395. var c = p.x.redAdd(p.z); // D = X3 - Z3
  37396. var d = p.x.redSub(p.z); // DA = D * A
  37397. var da = d.redMul(a); // CB = C * B
  37398. var cb = c.redMul(b); // X5 = Z1 * (DA + CB)^2
  37399. var nx = diff.z.redMul(da.redAdd(cb).redSqr()); // Z5 = X1 * (DA - CB)^2
  37400. var nz = diff.x.redMul(da.redISub(cb).redSqr());
  37401. return this.curve.point(nx, nz);
  37402. };
  37403. Point.prototype.mul = function mul(k) {
  37404. var t = k.clone();
  37405. var a = this; // (N / 2) * Q + Q
  37406. var b = this.curve.point(null, null); // (N / 2) * Q
  37407. var c = this; // Q
  37408. for (var bits = []; t.cmpn(0) !== 0; t.iushrn(1)) {
  37409. bits.push(t.andln(1));
  37410. }
  37411. for (var i = bits.length - 1; i >= 0; i--) {
  37412. if (bits[i] === 0) {
  37413. // N * Q + Q = ((N / 2) * Q + Q)) + (N / 2) * Q
  37414. a = a.diffAdd(b, c); // N * Q = 2 * ((N / 2) * Q + Q))
  37415. b = b.dbl();
  37416. } else {
  37417. // N * Q = ((N / 2) * Q + Q) + ((N / 2) * Q)
  37418. b = a.diffAdd(b, c); // N * Q + Q = 2 * ((N / 2) * Q + Q)
  37419. a = a.dbl();
  37420. }
  37421. }
  37422. return b;
  37423. };
  37424. Point.prototype.mulAdd = function mulAdd() {
  37425. throw new Error('Not supported on Montgomery curve');
  37426. };
  37427. Point.prototype.jumlAdd = function jumlAdd() {
  37428. throw new Error('Not supported on Montgomery curve');
  37429. };
  37430. Point.prototype.eq = function eq(other) {
  37431. return this.getX().cmp(other.getX()) === 0;
  37432. };
  37433. Point.prototype.normalize = function normalize() {
  37434. this.x = this.x.redMul(this.z.redInvm());
  37435. this.z = this.curve.one;
  37436. return this;
  37437. };
  37438. Point.prototype.getX = function getX() {
  37439. // Normalize coordinates
  37440. this.normalize();
  37441. return this.x.fromRed();
  37442. };
  37443. },{"../utils":364,"./base":351,"bn.js":365,"inherits":387}],355:[function(require,module,exports){
  37444. 'use strict';
  37445. var utils = require('../utils');
  37446. var BN = require('bn.js');
  37447. var inherits = require('inherits');
  37448. var Base = require('./base');
  37449. var assert = utils.assert;
  37450. function ShortCurve(conf) {
  37451. Base.call(this, 'short', conf);
  37452. this.a = new BN(conf.a, 16).toRed(this.red);
  37453. this.b = new BN(conf.b, 16).toRed(this.red);
  37454. this.tinv = this.two.redInvm();
  37455. this.zeroA = this.a.fromRed().cmpn(0) === 0;
  37456. this.threeA = this.a.fromRed().sub(this.p).cmpn(-3) === 0; // If the curve is endomorphic, precalculate beta and lambda
  37457. this.endo = this._getEndomorphism(conf);
  37458. this._endoWnafT1 = new Array(4);
  37459. this._endoWnafT2 = new Array(4);
  37460. }
  37461. inherits(ShortCurve, Base);
  37462. module.exports = ShortCurve;
  37463. ShortCurve.prototype._getEndomorphism = function _getEndomorphism(conf) {
  37464. // No efficient endomorphism
  37465. if (!this.zeroA || !this.g || !this.n || this.p.modn(3) !== 1) return; // Compute beta and lambda, that lambda * P = (beta * Px; Py)
  37466. var beta;
  37467. var lambda;
  37468. if (conf.beta) {
  37469. beta = new BN(conf.beta, 16).toRed(this.red);
  37470. } else {
  37471. var betas = this._getEndoRoots(this.p); // Choose the smallest beta
  37472. beta = betas[0].cmp(betas[1]) < 0 ? betas[0] : betas[1];
  37473. beta = beta.toRed(this.red);
  37474. }
  37475. if (conf.lambda) {
  37476. lambda = new BN(conf.lambda, 16);
  37477. } else {
  37478. // Choose the lambda that is matching selected beta
  37479. var lambdas = this._getEndoRoots(this.n);
  37480. if (this.g.mul(lambdas[0]).x.cmp(this.g.x.redMul(beta)) === 0) {
  37481. lambda = lambdas[0];
  37482. } else {
  37483. lambda = lambdas[1];
  37484. assert(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta)) === 0);
  37485. }
  37486. } // Get basis vectors, used for balanced length-two representation
  37487. var basis;
  37488. if (conf.basis) {
  37489. basis = conf.basis.map(function (vec) {
  37490. return {
  37491. a: new BN(vec.a, 16),
  37492. b: new BN(vec.b, 16)
  37493. };
  37494. });
  37495. } else {
  37496. basis = this._getEndoBasis(lambda);
  37497. }
  37498. return {
  37499. beta: beta,
  37500. lambda: lambda,
  37501. basis: basis
  37502. };
  37503. };
  37504. ShortCurve.prototype._getEndoRoots = function _getEndoRoots(num) {
  37505. // Find roots of for x^2 + x + 1 in F
  37506. // Root = (-1 +- Sqrt(-3)) / 2
  37507. //
  37508. var red = num === this.p ? this.red : BN.mont(num);
  37509. var tinv = new BN(2).toRed(red).redInvm();
  37510. var ntinv = tinv.redNeg();
  37511. var s = new BN(3).toRed(red).redNeg().redSqrt().redMul(tinv);
  37512. var l1 = ntinv.redAdd(s).fromRed();
  37513. var l2 = ntinv.redSub(s).fromRed();
  37514. return [l1, l2];
  37515. };
  37516. ShortCurve.prototype._getEndoBasis = function _getEndoBasis(lambda) {
  37517. // aprxSqrt >= sqrt(this.n)
  37518. var aprxSqrt = this.n.ushrn(Math.floor(this.n.bitLength() / 2)); // 3.74
  37519. // Run EGCD, until r(L + 1) < aprxSqrt
  37520. var u = lambda;
  37521. var v = this.n.clone();
  37522. var x1 = new BN(1);
  37523. var y1 = new BN(0);
  37524. var x2 = new BN(0);
  37525. var y2 = new BN(1); // NOTE: all vectors are roots of: a + b * lambda = 0 (mod n)
  37526. var a0;
  37527. var b0; // First vector
  37528. var a1;
  37529. var b1; // Second vector
  37530. var a2;
  37531. var b2;
  37532. var prevR;
  37533. var i = 0;
  37534. var r;
  37535. var x;
  37536. while (u.cmpn(0) !== 0) {
  37537. var q = v.div(u);
  37538. r = v.sub(q.mul(u));
  37539. x = x2.sub(q.mul(x1));
  37540. var y = y2.sub(q.mul(y1));
  37541. if (!a1 && r.cmp(aprxSqrt) < 0) {
  37542. a0 = prevR.neg();
  37543. b0 = x1;
  37544. a1 = r.neg();
  37545. b1 = x;
  37546. } else if (a1 && ++i === 2) {
  37547. break;
  37548. }
  37549. prevR = r;
  37550. v = u;
  37551. u = r;
  37552. x2 = x1;
  37553. x1 = x;
  37554. y2 = y1;
  37555. y1 = y;
  37556. }
  37557. a2 = r.neg();
  37558. b2 = x;
  37559. var len1 = a1.sqr().add(b1.sqr());
  37560. var len2 = a2.sqr().add(b2.sqr());
  37561. if (len2.cmp(len1) >= 0) {
  37562. a2 = a0;
  37563. b2 = b0;
  37564. } // Normalize signs
  37565. if (a1.negative) {
  37566. a1 = a1.neg();
  37567. b1 = b1.neg();
  37568. }
  37569. if (a2.negative) {
  37570. a2 = a2.neg();
  37571. b2 = b2.neg();
  37572. }
  37573. return [{
  37574. a: a1,
  37575. b: b1
  37576. }, {
  37577. a: a2,
  37578. b: b2
  37579. }];
  37580. };
  37581. ShortCurve.prototype._endoSplit = function _endoSplit(k) {
  37582. var basis = this.endo.basis;
  37583. var v1 = basis[0];
  37584. var v2 = basis[1];
  37585. var c1 = v2.b.mul(k).divRound(this.n);
  37586. var c2 = v1.b.neg().mul(k).divRound(this.n);
  37587. var p1 = c1.mul(v1.a);
  37588. var p2 = c2.mul(v2.a);
  37589. var q1 = c1.mul(v1.b);
  37590. var q2 = c2.mul(v2.b); // Calculate answer
  37591. var k1 = k.sub(p1).sub(p2);
  37592. var k2 = q1.add(q2).neg();
  37593. return {
  37594. k1: k1,
  37595. k2: k2
  37596. };
  37597. };
  37598. ShortCurve.prototype.pointFromX = function pointFromX(x, odd) {
  37599. x = new BN(x, 16);
  37600. if (!x.red) x = x.toRed(this.red);
  37601. var y2 = x.redSqr().redMul(x).redIAdd(x.redMul(this.a)).redIAdd(this.b);
  37602. var y = y2.redSqrt();
  37603. if (y.redSqr().redSub(y2).cmp(this.zero) !== 0) throw new Error('invalid point'); // XXX Is there any way to tell if the number is odd without converting it
  37604. // to non-red form?
  37605. var isOdd = y.fromRed().isOdd();
  37606. if (odd && !isOdd || !odd && isOdd) y = y.redNeg();
  37607. return this.point(x, y);
  37608. };
  37609. ShortCurve.prototype.validate = function validate(point) {
  37610. if (point.inf) return true;
  37611. var x = point.x;
  37612. var y = point.y;
  37613. var ax = this.a.redMul(x);
  37614. var rhs = x.redSqr().redMul(x).redIAdd(ax).redIAdd(this.b);
  37615. return y.redSqr().redISub(rhs).cmpn(0) === 0;
  37616. };
  37617. ShortCurve.prototype._endoWnafMulAdd = function _endoWnafMulAdd(points, coeffs, jacobianResult) {
  37618. var npoints = this._endoWnafT1;
  37619. var ncoeffs = this._endoWnafT2;
  37620. for (var i = 0; i < points.length; i++) {
  37621. var split = this._endoSplit(coeffs[i]);
  37622. var p = points[i];
  37623. var beta = p._getBeta();
  37624. if (split.k1.negative) {
  37625. split.k1.ineg();
  37626. p = p.neg(true);
  37627. }
  37628. if (split.k2.negative) {
  37629. split.k2.ineg();
  37630. beta = beta.neg(true);
  37631. }
  37632. npoints[i * 2] = p;
  37633. npoints[i * 2 + 1] = beta;
  37634. ncoeffs[i * 2] = split.k1;
  37635. ncoeffs[i * 2 + 1] = split.k2;
  37636. }
  37637. var res = this._wnafMulAdd(1, npoints, ncoeffs, i * 2, jacobianResult); // Clean-up references to points and coefficients
  37638. for (var j = 0; j < i * 2; j++) {
  37639. npoints[j] = null;
  37640. ncoeffs[j] = null;
  37641. }
  37642. return res;
  37643. };
  37644. function Point(curve, x, y, isRed) {
  37645. Base.BasePoint.call(this, curve, 'affine');
  37646. if (x === null && y === null) {
  37647. this.x = null;
  37648. this.y = null;
  37649. this.inf = true;
  37650. } else {
  37651. this.x = new BN(x, 16);
  37652. this.y = new BN(y, 16); // Force redgomery representation when loading from JSON
  37653. if (isRed) {
  37654. this.x.forceRed(this.curve.red);
  37655. this.y.forceRed(this.curve.red);
  37656. }
  37657. if (!this.x.red) this.x = this.x.toRed(this.curve.red);
  37658. if (!this.y.red) this.y = this.y.toRed(this.curve.red);
  37659. this.inf = false;
  37660. }
  37661. }
  37662. inherits(Point, Base.BasePoint);
  37663. ShortCurve.prototype.point = function point(x, y, isRed) {
  37664. return new Point(this, x, y, isRed);
  37665. };
  37666. ShortCurve.prototype.pointFromJSON = function pointFromJSON(obj, red) {
  37667. return Point.fromJSON(this, obj, red);
  37668. };
  37669. Point.prototype._getBeta = function _getBeta() {
  37670. if (!this.curve.endo) return;
  37671. var pre = this.precomputed;
  37672. if (pre && pre.beta) return pre.beta;
  37673. var beta = this.curve.point(this.x.redMul(this.curve.endo.beta), this.y);
  37674. if (pre) {
  37675. var curve = this.curve;
  37676. var endoMul = function endoMul(p) {
  37677. return curve.point(p.x.redMul(curve.endo.beta), p.y);
  37678. };
  37679. pre.beta = beta;
  37680. beta.precomputed = {
  37681. beta: null,
  37682. naf: pre.naf && {
  37683. wnd: pre.naf.wnd,
  37684. points: pre.naf.points.map(endoMul)
  37685. },
  37686. doubles: pre.doubles && {
  37687. step: pre.doubles.step,
  37688. points: pre.doubles.points.map(endoMul)
  37689. }
  37690. };
  37691. }
  37692. return beta;
  37693. };
  37694. Point.prototype.toJSON = function toJSON() {
  37695. if (!this.precomputed) return [this.x, this.y];
  37696. return [this.x, this.y, this.precomputed && {
  37697. doubles: this.precomputed.doubles && {
  37698. step: this.precomputed.doubles.step,
  37699. points: this.precomputed.doubles.points.slice(1)
  37700. },
  37701. naf: this.precomputed.naf && {
  37702. wnd: this.precomputed.naf.wnd,
  37703. points: this.precomputed.naf.points.slice(1)
  37704. }
  37705. }];
  37706. };
  37707. Point.fromJSON = function fromJSON(curve, obj, red) {
  37708. if (typeof obj === 'string') obj = JSON.parse(obj);
  37709. var res = curve.point(obj[0], obj[1], red);
  37710. if (!obj[2]) return res;
  37711. function obj2point(obj) {
  37712. return curve.point(obj[0], obj[1], red);
  37713. }
  37714. var pre = obj[2];
  37715. res.precomputed = {
  37716. beta: null,
  37717. doubles: pre.doubles && {
  37718. step: pre.doubles.step,
  37719. points: [res].concat(pre.doubles.points.map(obj2point))
  37720. },
  37721. naf: pre.naf && {
  37722. wnd: pre.naf.wnd,
  37723. points: [res].concat(pre.naf.points.map(obj2point))
  37724. }
  37725. };
  37726. return res;
  37727. };
  37728. Point.prototype.inspect = function inspect() {
  37729. if (this.isInfinity()) return '<EC Point Infinity>';
  37730. return '<EC Point x: ' + this.x.fromRed().toString(16, 2) + ' y: ' + this.y.fromRed().toString(16, 2) + '>';
  37731. };
  37732. Point.prototype.isInfinity = function isInfinity() {
  37733. return this.inf;
  37734. };
  37735. Point.prototype.add = function add(p) {
  37736. // O + P = P
  37737. if (this.inf) return p; // P + O = P
  37738. if (p.inf) return this; // P + P = 2P
  37739. if (this.eq(p)) return this.dbl(); // P + (-P) = O
  37740. if (this.neg().eq(p)) return this.curve.point(null, null); // P + Q = O
  37741. if (this.x.cmp(p.x) === 0) return this.curve.point(null, null);
  37742. var c = this.y.redSub(p.y);
  37743. if (c.cmpn(0) !== 0) c = c.redMul(this.x.redSub(p.x).redInvm());
  37744. var nx = c.redSqr().redISub(this.x).redISub(p.x);
  37745. var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
  37746. return this.curve.point(nx, ny);
  37747. };
  37748. Point.prototype.dbl = function dbl() {
  37749. if (this.inf) return this; // 2P = O
  37750. var ys1 = this.y.redAdd(this.y);
  37751. if (ys1.cmpn(0) === 0) return this.curve.point(null, null);
  37752. var a = this.curve.a;
  37753. var x2 = this.x.redSqr();
  37754. var dyinv = ys1.redInvm();
  37755. var c = x2.redAdd(x2).redIAdd(x2).redIAdd(a).redMul(dyinv);
  37756. var nx = c.redSqr().redISub(this.x.redAdd(this.x));
  37757. var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
  37758. return this.curve.point(nx, ny);
  37759. };
  37760. Point.prototype.getX = function getX() {
  37761. return this.x.fromRed();
  37762. };
  37763. Point.prototype.getY = function getY() {
  37764. return this.y.fromRed();
  37765. };
  37766. Point.prototype.mul = function mul(k) {
  37767. k = new BN(k, 16);
  37768. 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);
  37769. };
  37770. Point.prototype.mulAdd = function mulAdd(k1, p2, k2) {
  37771. var points = [this, p2];
  37772. var coeffs = [k1, k2];
  37773. if (this.curve.endo) return this.curve._endoWnafMulAdd(points, coeffs);else return this.curve._wnafMulAdd(1, points, coeffs, 2);
  37774. };
  37775. Point.prototype.jmulAdd = function jmulAdd(k1, p2, k2) {
  37776. var points = [this, p2];
  37777. var coeffs = [k1, k2];
  37778. if (this.curve.endo) return this.curve._endoWnafMulAdd(points, coeffs, true);else return this.curve._wnafMulAdd(1, points, coeffs, 2, true);
  37779. };
  37780. Point.prototype.eq = function eq(p) {
  37781. return this === p || this.inf === p.inf && (this.inf || this.x.cmp(p.x) === 0 && this.y.cmp(p.y) === 0);
  37782. };
  37783. Point.prototype.neg = function neg(_precompute) {
  37784. if (this.inf) return this;
  37785. var res = this.curve.point(this.x, this.y.redNeg());
  37786. if (_precompute && this.precomputed) {
  37787. var pre = this.precomputed;
  37788. var negate = function negate(p) {
  37789. return p.neg();
  37790. };
  37791. res.precomputed = {
  37792. naf: pre.naf && {
  37793. wnd: pre.naf.wnd,
  37794. points: pre.naf.points.map(negate)
  37795. },
  37796. doubles: pre.doubles && {
  37797. step: pre.doubles.step,
  37798. points: pre.doubles.points.map(negate)
  37799. }
  37800. };
  37801. }
  37802. return res;
  37803. };
  37804. Point.prototype.toJ = function toJ() {
  37805. if (this.inf) return this.curve.jpoint(null, null, null);
  37806. var res = this.curve.jpoint(this.x, this.y, this.curve.one);
  37807. return res;
  37808. };
  37809. function JPoint(curve, x, y, z) {
  37810. Base.BasePoint.call(this, curve, 'jacobian');
  37811. if (x === null && y === null && z === null) {
  37812. this.x = this.curve.one;
  37813. this.y = this.curve.one;
  37814. this.z = new BN(0);
  37815. } else {
  37816. this.x = new BN(x, 16);
  37817. this.y = new BN(y, 16);
  37818. this.z = new BN(z, 16);
  37819. }
  37820. if (!this.x.red) this.x = this.x.toRed(this.curve.red);
  37821. if (!this.y.red) this.y = this.y.toRed(this.curve.red);
  37822. if (!this.z.red) this.z = this.z.toRed(this.curve.red);
  37823. this.zOne = this.z === this.curve.one;
  37824. }
  37825. inherits(JPoint, Base.BasePoint);
  37826. ShortCurve.prototype.jpoint = function jpoint(x, y, z) {
  37827. return new JPoint(this, x, y, z);
  37828. };
  37829. JPoint.prototype.toP = function toP() {
  37830. if (this.isInfinity()) return this.curve.point(null, null);
  37831. var zinv = this.z.redInvm();
  37832. var zinv2 = zinv.redSqr();
  37833. var ax = this.x.redMul(zinv2);
  37834. var ay = this.y.redMul(zinv2).redMul(zinv);
  37835. return this.curve.point(ax, ay);
  37836. };
  37837. JPoint.prototype.neg = function neg() {
  37838. return this.curve.jpoint(this.x, this.y.redNeg(), this.z);
  37839. };
  37840. JPoint.prototype.add = function add(p) {
  37841. // O + P = P
  37842. if (this.isInfinity()) return p; // P + O = P
  37843. if (p.isInfinity()) return this; // 12M + 4S + 7A
  37844. var pz2 = p.z.redSqr();
  37845. var z2 = this.z.redSqr();
  37846. var u1 = this.x.redMul(pz2);
  37847. var u2 = p.x.redMul(z2);
  37848. var s1 = this.y.redMul(pz2.redMul(p.z));
  37849. var s2 = p.y.redMul(z2.redMul(this.z));
  37850. var h = u1.redSub(u2);
  37851. var r = s1.redSub(s2);
  37852. if (h.cmpn(0) === 0) {
  37853. if (r.cmpn(0) !== 0) return this.curve.jpoint(null, null, null);else return this.dbl();
  37854. }
  37855. var h2 = h.redSqr();
  37856. var h3 = h2.redMul(h);
  37857. var v = u1.redMul(h2);
  37858. var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
  37859. var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
  37860. var nz = this.z.redMul(p.z).redMul(h);
  37861. return this.curve.jpoint(nx, ny, nz);
  37862. };
  37863. JPoint.prototype.mixedAdd = function mixedAdd(p) {
  37864. // O + P = P
  37865. if (this.isInfinity()) return p.toJ(); // P + O = P
  37866. if (p.isInfinity()) return this; // 8M + 3S + 7A
  37867. var z2 = this.z.redSqr();
  37868. var u1 = this.x;
  37869. var u2 = p.x.redMul(z2);
  37870. var s1 = this.y;
  37871. var s2 = p.y.redMul(z2).redMul(this.z);
  37872. var h = u1.redSub(u2);
  37873. var r = s1.redSub(s2);
  37874. if (h.cmpn(0) === 0) {
  37875. if (r.cmpn(0) !== 0) return this.curve.jpoint(null, null, null);else return this.dbl();
  37876. }
  37877. var h2 = h.redSqr();
  37878. var h3 = h2.redMul(h);
  37879. var v = u1.redMul(h2);
  37880. var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
  37881. var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
  37882. var nz = this.z.redMul(h);
  37883. return this.curve.jpoint(nx, ny, nz);
  37884. };
  37885. JPoint.prototype.dblp = function dblp(pow) {
  37886. if (pow === 0) return this;
  37887. if (this.isInfinity()) return this;
  37888. if (!pow) return this.dbl();
  37889. if (this.curve.zeroA || this.curve.threeA) {
  37890. var r = this;
  37891. for (var i = 0; i < pow; i++) {
  37892. r = r.dbl();
  37893. }
  37894. return r;
  37895. } // 1M + 2S + 1A + N * (4S + 5M + 8A)
  37896. // N = 1 => 6M + 6S + 9A
  37897. var a = this.curve.a;
  37898. var tinv = this.curve.tinv;
  37899. var jx = this.x;
  37900. var jy = this.y;
  37901. var jz = this.z;
  37902. var jz4 = jz.redSqr().redSqr(); // Reuse results
  37903. var jyd = jy.redAdd(jy);
  37904. for (var i = 0; i < pow; i++) {
  37905. var jx2 = jx.redSqr();
  37906. var jyd2 = jyd.redSqr();
  37907. var jyd4 = jyd2.redSqr();
  37908. var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
  37909. var t1 = jx.redMul(jyd2);
  37910. var nx = c.redSqr().redISub(t1.redAdd(t1));
  37911. var t2 = t1.redISub(nx);
  37912. var dny = c.redMul(t2);
  37913. dny = dny.redIAdd(dny).redISub(jyd4);
  37914. var nz = jyd.redMul(jz);
  37915. if (i + 1 < pow) jz4 = jz4.redMul(jyd4);
  37916. jx = nx;
  37917. jz = nz;
  37918. jyd = dny;
  37919. }
  37920. return this.curve.jpoint(jx, jyd.redMul(tinv), jz);
  37921. };
  37922. JPoint.prototype.dbl = function dbl() {
  37923. if (this.isInfinity()) return this;
  37924. if (this.curve.zeroA) return this._zeroDbl();else if (this.curve.threeA) return this._threeDbl();else return this._dbl();
  37925. };
  37926. JPoint.prototype._zeroDbl = function _zeroDbl() {
  37927. var nx;
  37928. var ny;
  37929. var nz; // Z = 1
  37930. if (this.zOne) {
  37931. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
  37932. // #doubling-mdbl-2007-bl
  37933. // 1M + 5S + 14A
  37934. // XX = X1^2
  37935. var xx = this.x.redSqr(); // YY = Y1^2
  37936. var yy = this.y.redSqr(); // YYYY = YY^2
  37937. var yyyy = yy.redSqr(); // S = 2 * ((X1 + YY)^2 - XX - YYYY)
  37938. var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
  37939. s = s.redIAdd(s); // M = 3 * XX + a; a = 0
  37940. var m = xx.redAdd(xx).redIAdd(xx); // T = M ^ 2 - 2*S
  37941. var t = m.redSqr().redISub(s).redISub(s); // 8 * YYYY
  37942. var yyyy8 = yyyy.redIAdd(yyyy);
  37943. yyyy8 = yyyy8.redIAdd(yyyy8);
  37944. yyyy8 = yyyy8.redIAdd(yyyy8); // X3 = T
  37945. nx = t; // Y3 = M * (S - T) - 8 * YYYY
  37946. ny = m.redMul(s.redISub(t)).redISub(yyyy8); // Z3 = 2*Y1
  37947. nz = this.y.redAdd(this.y);
  37948. } else {
  37949. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
  37950. // #doubling-dbl-2009-l
  37951. // 2M + 5S + 13A
  37952. // A = X1^2
  37953. var a = this.x.redSqr(); // B = Y1^2
  37954. var b = this.y.redSqr(); // C = B^2
  37955. var c = b.redSqr(); // D = 2 * ((X1 + B)^2 - A - C)
  37956. var d = this.x.redAdd(b).redSqr().redISub(a).redISub(c);
  37957. d = d.redIAdd(d); // E = 3 * A
  37958. var e = a.redAdd(a).redIAdd(a); // F = E^2
  37959. var f = e.redSqr(); // 8 * C
  37960. var c8 = c.redIAdd(c);
  37961. c8 = c8.redIAdd(c8);
  37962. c8 = c8.redIAdd(c8); // X3 = F - 2 * D
  37963. nx = f.redISub(d).redISub(d); // Y3 = E * (D - X3) - 8 * C
  37964. ny = e.redMul(d.redISub(nx)).redISub(c8); // Z3 = 2 * Y1 * Z1
  37965. nz = this.y.redMul(this.z);
  37966. nz = nz.redIAdd(nz);
  37967. }
  37968. return this.curve.jpoint(nx, ny, nz);
  37969. };
  37970. JPoint.prototype._threeDbl = function _threeDbl() {
  37971. var nx;
  37972. var ny;
  37973. var nz; // Z = 1
  37974. if (this.zOne) {
  37975. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html
  37976. // #doubling-mdbl-2007-bl
  37977. // 1M + 5S + 15A
  37978. // XX = X1^2
  37979. var xx = this.x.redSqr(); // YY = Y1^2
  37980. var yy = this.y.redSqr(); // YYYY = YY^2
  37981. var yyyy = yy.redSqr(); // S = 2 * ((X1 + YY)^2 - XX - YYYY)
  37982. var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
  37983. s = s.redIAdd(s); // M = 3 * XX + a
  37984. var m = xx.redAdd(xx).redIAdd(xx).redIAdd(this.curve.a); // T = M^2 - 2 * S
  37985. var t = m.redSqr().redISub(s).redISub(s); // X3 = T
  37986. nx = t; // Y3 = M * (S - T) - 8 * YYYY
  37987. var yyyy8 = yyyy.redIAdd(yyyy);
  37988. yyyy8 = yyyy8.redIAdd(yyyy8);
  37989. yyyy8 = yyyy8.redIAdd(yyyy8);
  37990. ny = m.redMul(s.redISub(t)).redISub(yyyy8); // Z3 = 2 * Y1
  37991. nz = this.y.redAdd(this.y);
  37992. } else {
  37993. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#doubling-dbl-2001-b
  37994. // 3M + 5S
  37995. // delta = Z1^2
  37996. var delta = this.z.redSqr(); // gamma = Y1^2
  37997. var gamma = this.y.redSqr(); // beta = X1 * gamma
  37998. var beta = this.x.redMul(gamma); // alpha = 3 * (X1 - delta) * (X1 + delta)
  37999. var alpha = this.x.redSub(delta).redMul(this.x.redAdd(delta));
  38000. alpha = alpha.redAdd(alpha).redIAdd(alpha); // X3 = alpha^2 - 8 * beta
  38001. var beta4 = beta.redIAdd(beta);
  38002. beta4 = beta4.redIAdd(beta4);
  38003. var beta8 = beta4.redAdd(beta4);
  38004. nx = alpha.redSqr().redISub(beta8); // Z3 = (Y1 + Z1)^2 - gamma - delta
  38005. nz = this.y.redAdd(this.z).redSqr().redISub(gamma).redISub(delta); // Y3 = alpha * (4 * beta - X3) - 8 * gamma^2
  38006. var ggamma8 = gamma.redSqr();
  38007. ggamma8 = ggamma8.redIAdd(ggamma8);
  38008. ggamma8 = ggamma8.redIAdd(ggamma8);
  38009. ggamma8 = ggamma8.redIAdd(ggamma8);
  38010. ny = alpha.redMul(beta4.redISub(nx)).redISub(ggamma8);
  38011. }
  38012. return this.curve.jpoint(nx, ny, nz);
  38013. };
  38014. JPoint.prototype._dbl = function _dbl() {
  38015. var a = this.curve.a; // 4M + 6S + 10A
  38016. var jx = this.x;
  38017. var jy = this.y;
  38018. var jz = this.z;
  38019. var jz4 = jz.redSqr().redSqr();
  38020. var jx2 = jx.redSqr();
  38021. var jy2 = jy.redSqr();
  38022. var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
  38023. var jxd4 = jx.redAdd(jx);
  38024. jxd4 = jxd4.redIAdd(jxd4);
  38025. var t1 = jxd4.redMul(jy2);
  38026. var nx = c.redSqr().redISub(t1.redAdd(t1));
  38027. var t2 = t1.redISub(nx);
  38028. var jyd8 = jy2.redSqr();
  38029. jyd8 = jyd8.redIAdd(jyd8);
  38030. jyd8 = jyd8.redIAdd(jyd8);
  38031. jyd8 = jyd8.redIAdd(jyd8);
  38032. var ny = c.redMul(t2).redISub(jyd8);
  38033. var nz = jy.redAdd(jy).redMul(jz);
  38034. return this.curve.jpoint(nx, ny, nz);
  38035. };
  38036. JPoint.prototype.trpl = function trpl() {
  38037. if (!this.curve.zeroA) return this.dbl().add(this); // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#tripling-tpl-2007-bl
  38038. // 5M + 10S + ...
  38039. // XX = X1^2
  38040. var xx = this.x.redSqr(); // YY = Y1^2
  38041. var yy = this.y.redSqr(); // ZZ = Z1^2
  38042. var zz = this.z.redSqr(); // YYYY = YY^2
  38043. var yyyy = yy.redSqr(); // M = 3 * XX + a * ZZ2; a = 0
  38044. var m = xx.redAdd(xx).redIAdd(xx); // MM = M^2
  38045. var mm = m.redSqr(); // E = 6 * ((X1 + YY)^2 - XX - YYYY) - MM
  38046. var e = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
  38047. e = e.redIAdd(e);
  38048. e = e.redAdd(e).redIAdd(e);
  38049. e = e.redISub(mm); // EE = E^2
  38050. var ee = e.redSqr(); // T = 16*YYYY
  38051. var t = yyyy.redIAdd(yyyy);
  38052. t = t.redIAdd(t);
  38053. t = t.redIAdd(t);
  38054. t = t.redIAdd(t); // U = (M + E)^2 - MM - EE - T
  38055. var u = m.redIAdd(e).redSqr().redISub(mm).redISub(ee).redISub(t); // X3 = 4 * (X1 * EE - 4 * YY * U)
  38056. var yyu4 = yy.redMul(u);
  38057. yyu4 = yyu4.redIAdd(yyu4);
  38058. yyu4 = yyu4.redIAdd(yyu4);
  38059. var nx = this.x.redMul(ee).redISub(yyu4);
  38060. nx = nx.redIAdd(nx);
  38061. nx = nx.redIAdd(nx); // Y3 = 8 * Y1 * (U * (T - U) - E * EE)
  38062. var ny = this.y.redMul(u.redMul(t.redISub(u)).redISub(e.redMul(ee)));
  38063. ny = ny.redIAdd(ny);
  38064. ny = ny.redIAdd(ny);
  38065. ny = ny.redIAdd(ny); // Z3 = (Z1 + E)^2 - ZZ - EE
  38066. var nz = this.z.redAdd(e).redSqr().redISub(zz).redISub(ee);
  38067. return this.curve.jpoint(nx, ny, nz);
  38068. };
  38069. JPoint.prototype.mul = function mul(k, kbase) {
  38070. k = new BN(k, kbase);
  38071. return this.curve._wnafMul(this, k);
  38072. };
  38073. JPoint.prototype.eq = function eq(p) {
  38074. if (p.type === 'affine') return this.eq(p.toJ());
  38075. if (this === p) return true; // x1 * z2^2 == x2 * z1^2
  38076. var z2 = this.z.redSqr();
  38077. var pz2 = p.z.redSqr();
  38078. if (this.x.redMul(pz2).redISub(p.x.redMul(z2)).cmpn(0) !== 0) return false; // y1 * z2^3 == y2 * z1^3
  38079. var z3 = z2.redMul(this.z);
  38080. var pz3 = pz2.redMul(p.z);
  38081. return this.y.redMul(pz3).redISub(p.y.redMul(z3)).cmpn(0) === 0;
  38082. };
  38083. JPoint.prototype.eqXToP = function eqXToP(x) {
  38084. var zs = this.z.redSqr();
  38085. var rx = x.toRed(this.curve.red).redMul(zs);
  38086. if (this.x.cmp(rx) === 0) return true;
  38087. var xc = x.clone();
  38088. var t = this.curve.redN.redMul(zs);
  38089. for (;;) {
  38090. xc.iadd(this.curve.n);
  38091. if (xc.cmp(this.curve.p) >= 0) return false;
  38092. rx.redIAdd(t);
  38093. if (this.x.cmp(rx) === 0) return true;
  38094. }
  38095. };
  38096. JPoint.prototype.inspect = function inspect() {
  38097. if (this.isInfinity()) return '<EC JPoint Infinity>';
  38098. return '<EC JPoint x: ' + this.x.toString(16, 2) + ' y: ' + this.y.toString(16, 2) + ' z: ' + this.z.toString(16, 2) + '>';
  38099. };
  38100. JPoint.prototype.isInfinity = function isInfinity() {
  38101. // XXX This code assumes that zero is always zero in red
  38102. return this.z.cmpn(0) === 0;
  38103. };
  38104. },{"../utils":364,"./base":351,"bn.js":365,"inherits":387}],356:[function(require,module,exports){
  38105. 'use strict';
  38106. var curves = exports;
  38107. var hash = require('hash.js');
  38108. var curve = require('./curve');
  38109. var utils = require('./utils');
  38110. var assert = utils.assert;
  38111. function PresetCurve(options) {
  38112. 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);
  38113. this.g = this.curve.g;
  38114. this.n = this.curve.n;
  38115. this.hash = options.hash;
  38116. assert(this.g.validate(), 'Invalid curve');
  38117. assert(this.g.mul(this.n).isInfinity(), 'Invalid curve, G*N != O');
  38118. }
  38119. curves.PresetCurve = PresetCurve;
  38120. function defineCurve(name, options) {
  38121. Object.defineProperty(curves, name, {
  38122. configurable: true,
  38123. enumerable: true,
  38124. get: function get() {
  38125. var curve = new PresetCurve(options);
  38126. Object.defineProperty(curves, name, {
  38127. configurable: true,
  38128. enumerable: true,
  38129. value: curve
  38130. });
  38131. return curve;
  38132. }
  38133. });
  38134. }
  38135. defineCurve('p192', {
  38136. type: 'short',
  38137. prime: 'p192',
  38138. p: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff',
  38139. a: 'ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc',
  38140. b: '64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1',
  38141. n: 'ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831',
  38142. hash: hash.sha256,
  38143. gRed: false,
  38144. g: ['188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012', '07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811']
  38145. });
  38146. defineCurve('p224', {
  38147. type: 'short',
  38148. prime: 'p224',
  38149. p: 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001',
  38150. a: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe',
  38151. b: 'b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4',
  38152. n: 'ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d',
  38153. hash: hash.sha256,
  38154. gRed: false,
  38155. g: ['b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21', 'bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34']
  38156. });
  38157. defineCurve('p256', {
  38158. type: 'short',
  38159. prime: null,
  38160. p: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff',
  38161. a: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc',
  38162. b: '5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b',
  38163. n: 'ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551',
  38164. hash: hash.sha256,
  38165. gRed: false,
  38166. g: ['6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296', '4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5']
  38167. });
  38168. defineCurve('p384', {
  38169. type: 'short',
  38170. prime: null,
  38171. p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'fffffffe ffffffff 00000000 00000000 ffffffff',
  38172. a: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'fffffffe ffffffff 00000000 00000000 fffffffc',
  38173. b: 'b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f ' + '5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef',
  38174. n: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 ' + 'f4372ddf 581a0db2 48b0a77a ecec196a ccc52973',
  38175. hash: hash.sha384,
  38176. gRed: false,
  38177. 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']
  38178. });
  38179. defineCurve('p521', {
  38180. type: 'short',
  38181. prime: null,
  38182. p: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'ffffffff ffffffff ffffffff ffffffff ffffffff',
  38183. a: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'ffffffff ffffffff ffffffff ffffffff fffffffc',
  38184. b: '00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b ' + '99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd ' + '3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00',
  38185. n: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 ' + 'f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409',
  38186. hash: hash.sha512,
  38187. gRed: false,
  38188. 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']
  38189. });
  38190. defineCurve('curve25519', {
  38191. type: 'mont',
  38192. prime: 'p25519',
  38193. p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
  38194. a: '76d06',
  38195. b: '1',
  38196. n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
  38197. hash: hash.sha256,
  38198. gRed: false,
  38199. g: ['9']
  38200. });
  38201. defineCurve('ed25519', {
  38202. type: 'edwards',
  38203. prime: 'p25519',
  38204. p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
  38205. a: '-1',
  38206. c: '1',
  38207. // -121665 * (121666^(-1)) (mod P)
  38208. d: '52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3',
  38209. n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
  38210. hash: hash.sha256,
  38211. gRed: false,
  38212. g: ['216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a', // 4/5
  38213. '6666666666666666666666666666666666666666666666666666666666666658']
  38214. });
  38215. var pre;
  38216. try {
  38217. pre = require('./precomputed/secp256k1');
  38218. } catch (e) {
  38219. pre = undefined;
  38220. }
  38221. defineCurve('secp256k1', {
  38222. type: 'short',
  38223. prime: 'k256',
  38224. p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f',
  38225. a: '0',
  38226. b: '7',
  38227. n: 'ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141',
  38228. h: '1',
  38229. hash: hash.sha256,
  38230. // Precomputed endomorphism
  38231. beta: '7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee',
  38232. lambda: '5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72',
  38233. basis: [{
  38234. a: '3086d221a7d46bcde86c90e49284eb15',
  38235. b: '-e4437ed6010e88286f547fa90abfe4c3'
  38236. }, {
  38237. a: '114ca50f7a8e2f3f657c1108d9d44cfd8',
  38238. b: '3086d221a7d46bcde86c90e49284eb15'
  38239. }],
  38240. gRed: false,
  38241. g: ['79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798', '483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8', pre]
  38242. });
  38243. },{"./curve":353,"./precomputed/secp256k1":363,"./utils":364,"hash.js":372}],357:[function(require,module,exports){
  38244. 'use strict';
  38245. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  38246. var BN = require('bn.js');
  38247. var HmacDRBG = require('hmac-drbg');
  38248. var utils = require('../utils');
  38249. var curves = require('../curves');
  38250. var rand = require('brorand');
  38251. var assert = utils.assert;
  38252. var KeyPair = require('./key');
  38253. var Signature = require('./signature');
  38254. function EC(options) {
  38255. if (!(this instanceof EC)) return new EC(options); // Shortcut `elliptic.ec(curve-name)`
  38256. if (typeof options === 'string') {
  38257. assert(curves.hasOwnProperty(options), 'Unknown curve ' + options);
  38258. options = curves[options];
  38259. } // Shortcut for `elliptic.ec(elliptic.curves.curveName)`
  38260. if (options instanceof curves.PresetCurve) options = {
  38261. curve: options
  38262. };
  38263. this.curve = options.curve.curve;
  38264. this.n = this.curve.n;
  38265. this.nh = this.n.ushrn(1);
  38266. this.g = this.curve.g; // Point on curve
  38267. this.g = options.curve.g;
  38268. this.g.precompute(options.curve.n.bitLength() + 1); // Hash for function for DRBG
  38269. this.hash = options.hash || options.curve.hash;
  38270. }
  38271. module.exports = EC;
  38272. EC.prototype.keyPair = function keyPair(options) {
  38273. return new KeyPair(this, options);
  38274. };
  38275. EC.prototype.keyFromPrivate = function keyFromPrivate(priv, enc) {
  38276. return KeyPair.fromPrivate(this, priv, enc);
  38277. };
  38278. EC.prototype.keyFromPublic = function keyFromPublic(pub, enc) {
  38279. return KeyPair.fromPublic(this, pub, enc);
  38280. };
  38281. EC.prototype.genKeyPair = function genKeyPair(options) {
  38282. if (!options) options = {}; // Instantiate Hmac_DRBG
  38283. var drbg = new HmacDRBG({
  38284. hash: this.hash,
  38285. pers: options.pers,
  38286. persEnc: options.persEnc || 'utf8',
  38287. entropy: options.entropy || rand(this.hash.hmacStrength),
  38288. entropyEnc: options.entropy && options.entropyEnc || 'utf8',
  38289. nonce: this.n.toArray()
  38290. });
  38291. var bytes = this.n.byteLength();
  38292. var ns2 = this.n.sub(new BN(2));
  38293. do {
  38294. var priv = new BN(drbg.generate(bytes));
  38295. if (priv.cmp(ns2) > 0) continue;
  38296. priv.iaddn(1);
  38297. return this.keyFromPrivate(priv);
  38298. } while (true);
  38299. };
  38300. EC.prototype._truncateToN = function truncateToN(msg, truncOnly) {
  38301. var delta = msg.byteLength() * 8 - this.n.bitLength();
  38302. if (delta > 0) msg = msg.ushrn(delta);
  38303. if (!truncOnly && msg.cmp(this.n) >= 0) return msg.sub(this.n);else return msg;
  38304. };
  38305. EC.prototype.sign = function sign(msg, key, enc, options) {
  38306. if (_typeof(enc) === 'object') {
  38307. options = enc;
  38308. enc = null;
  38309. }
  38310. if (!options) options = {};
  38311. key = this.keyFromPrivate(key, enc);
  38312. msg = this._truncateToN(new BN(msg, 16)); // Zero-extend key to provide enough entropy
  38313. var bytes = this.n.byteLength();
  38314. var bkey = key.getPrivate().toArray('be', bytes); // Zero-extend nonce to have the same byte size as N
  38315. var nonce = msg.toArray('be', bytes); // Instantiate Hmac_DRBG
  38316. var drbg = new HmacDRBG({
  38317. hash: this.hash,
  38318. entropy: bkey,
  38319. nonce: nonce,
  38320. pers: options.pers,
  38321. persEnc: options.persEnc || 'utf8'
  38322. }); // Number of bytes to generate
  38323. var ns1 = this.n.sub(new BN(1));
  38324. for (var iter = 0; true; iter++) {
  38325. var k = options.k ? options.k(iter) : new BN(drbg.generate(this.n.byteLength()));
  38326. k = this._truncateToN(k, true);
  38327. if (k.cmpn(1) <= 0 || k.cmp(ns1) >= 0) continue;
  38328. var kp = this.g.mul(k);
  38329. if (kp.isInfinity()) continue;
  38330. var kpX = kp.getX();
  38331. var r = kpX.umod(this.n);
  38332. if (r.cmpn(0) === 0) continue;
  38333. var s = k.invm(this.n).mul(r.mul(key.getPrivate()).iadd(msg));
  38334. s = s.umod(this.n);
  38335. if (s.cmpn(0) === 0) continue;
  38336. var recoveryParam = (kp.getY().isOdd() ? 1 : 0) | (kpX.cmp(r) !== 0 ? 2 : 0); // Use complement of `s`, if it is > `n / 2`
  38337. if (options.canonical && s.cmp(this.nh) > 0) {
  38338. s = this.n.sub(s);
  38339. recoveryParam ^= 1;
  38340. }
  38341. return new Signature({
  38342. r: r,
  38343. s: s,
  38344. recoveryParam: recoveryParam
  38345. });
  38346. }
  38347. };
  38348. EC.prototype.verify = function verify(msg, signature, key, enc) {
  38349. msg = this._truncateToN(new BN(msg, 16));
  38350. key = this.keyFromPublic(key, enc);
  38351. signature = new Signature(signature, 'hex'); // Perform primitive values validation
  38352. var r = signature.r;
  38353. var s = signature.s;
  38354. if (r.cmpn(1) < 0 || r.cmp(this.n) >= 0) return false;
  38355. if (s.cmpn(1) < 0 || s.cmp(this.n) >= 0) return false; // Validate signature
  38356. var sinv = s.invm(this.n);
  38357. var u1 = sinv.mul(msg).umod(this.n);
  38358. var u2 = sinv.mul(r).umod(this.n);
  38359. if (!this.curve._maxwellTrick) {
  38360. var p = this.g.mulAdd(u1, key.getPublic(), u2);
  38361. if (p.isInfinity()) return false;
  38362. return p.getX().umod(this.n).cmp(r) === 0;
  38363. } // NOTE: Greg Maxwell's trick, inspired by:
  38364. // https://git.io/vad3K
  38365. var p = this.g.jmulAdd(u1, key.getPublic(), u2);
  38366. if (p.isInfinity()) return false; // Compare `p.x` of Jacobian point with `r`,
  38367. // this will do `p.x == r * p.z^2` instead of multiplying `p.x` by the
  38368. // inverse of `p.z^2`
  38369. return p.eqXToP(r);
  38370. };
  38371. EC.prototype.recoverPubKey = function (msg, signature, j, enc) {
  38372. assert((3 & j) === j, 'The recovery param is more than two bits');
  38373. signature = new Signature(signature, enc);
  38374. var n = this.n;
  38375. var e = new BN(msg);
  38376. var r = signature.r;
  38377. var s = signature.s; // A set LSB signifies that the y-coordinate is odd
  38378. var isYOdd = j & 1;
  38379. var isSecondKey = j >> 1;
  38380. if (r.cmp(this.curve.p.umod(this.curve.n)) >= 0 && isSecondKey) throw new Error('Unable to find sencond key candinate'); // 1.1. Let x = r + jn.
  38381. if (isSecondKey) r = this.curve.pointFromX(r.add(this.curve.n), isYOdd);else r = this.curve.pointFromX(r, isYOdd);
  38382. var rInv = signature.r.invm(n);
  38383. var s1 = n.sub(e).mul(rInv).umod(n);
  38384. var s2 = s.mul(rInv).umod(n); // 1.6.1 Compute Q = r^-1 (sR - eG)
  38385. // Q = r^-1 (sR + -eG)
  38386. return this.g.mulAdd(s1, r, s2);
  38387. };
  38388. EC.prototype.getKeyRecoveryParam = function (e, signature, Q, enc) {
  38389. signature = new Signature(signature, enc);
  38390. if (signature.recoveryParam !== null) return signature.recoveryParam;
  38391. for (var i = 0; i < 4; i++) {
  38392. var Qprime;
  38393. try {
  38394. Qprime = this.recoverPubKey(e, signature, i);
  38395. } catch (e) {
  38396. continue;
  38397. }
  38398. if (Qprime.eq(Q)) return i;
  38399. }
  38400. throw new Error('Unable to find valid recovery factor');
  38401. };
  38402. },{"../curves":356,"../utils":364,"./key":358,"./signature":359,"bn.js":365,"brorand":184,"hmac-drbg":384}],358:[function(require,module,exports){
  38403. 'use strict';
  38404. var BN = require('bn.js');
  38405. var utils = require('../utils');
  38406. var assert = utils.assert;
  38407. function KeyPair(ec, options) {
  38408. this.ec = ec;
  38409. this.priv = null;
  38410. this.pub = null; // KeyPair(ec, { priv: ..., pub: ... })
  38411. if (options.priv) this._importPrivate(options.priv, options.privEnc);
  38412. if (options.pub) this._importPublic(options.pub, options.pubEnc);
  38413. }
  38414. module.exports = KeyPair;
  38415. KeyPair.fromPublic = function fromPublic(ec, pub, enc) {
  38416. if (pub instanceof KeyPair) return pub;
  38417. return new KeyPair(ec, {
  38418. pub: pub,
  38419. pubEnc: enc
  38420. });
  38421. };
  38422. KeyPair.fromPrivate = function fromPrivate(ec, priv, enc) {
  38423. if (priv instanceof KeyPair) return priv;
  38424. return new KeyPair(ec, {
  38425. priv: priv,
  38426. privEnc: enc
  38427. });
  38428. };
  38429. KeyPair.prototype.validate = function validate() {
  38430. var pub = this.getPublic();
  38431. if (pub.isInfinity()) return {
  38432. result: false,
  38433. reason: 'Invalid public key'
  38434. };
  38435. if (!pub.validate()) return {
  38436. result: false,
  38437. reason: 'Public key is not a point'
  38438. };
  38439. if (!pub.mul(this.ec.curve.n).isInfinity()) return {
  38440. result: false,
  38441. reason: 'Public key * N != O'
  38442. };
  38443. return {
  38444. result: true,
  38445. reason: null
  38446. };
  38447. };
  38448. KeyPair.prototype.getPublic = function getPublic(compact, enc) {
  38449. // compact is optional argument
  38450. if (typeof compact === 'string') {
  38451. enc = compact;
  38452. compact = null;
  38453. }
  38454. if (!this.pub) this.pub = this.ec.g.mul(this.priv);
  38455. if (!enc) return this.pub;
  38456. return this.pub.encode(enc, compact);
  38457. };
  38458. KeyPair.prototype.getPrivate = function getPrivate(enc) {
  38459. if (enc === 'hex') return this.priv.toString(16, 2);else return this.priv;
  38460. };
  38461. KeyPair.prototype._importPrivate = function _importPrivate(key, enc) {
  38462. this.priv = new BN(key, enc || 16); // Ensure that the priv won't be bigger than n, otherwise we may fail
  38463. // in fixed multiplication method
  38464. this.priv = this.priv.umod(this.ec.curve.n);
  38465. };
  38466. KeyPair.prototype._importPublic = function _importPublic(key, enc) {
  38467. if (key.x || key.y) {
  38468. // Montgomery points only have an `x` coordinate.
  38469. // Weierstrass/Edwards points on the other hand have both `x` and
  38470. // `y` coordinates.
  38471. if (this.ec.curve.type === 'mont') {
  38472. assert(key.x, 'Need x coordinate');
  38473. } else if (this.ec.curve.type === 'short' || this.ec.curve.type === 'edwards') {
  38474. assert(key.x && key.y, 'Need both x and y coordinate');
  38475. }
  38476. this.pub = this.ec.curve.point(key.x, key.y);
  38477. return;
  38478. }
  38479. this.pub = this.ec.curve.decodePoint(key, enc);
  38480. }; // ECDH
  38481. KeyPair.prototype.derive = function derive(pub) {
  38482. return pub.mul(this.priv).getX();
  38483. }; // ECDSA
  38484. KeyPair.prototype.sign = function sign(msg, enc, options) {
  38485. return this.ec.sign(msg, this, enc, options);
  38486. };
  38487. KeyPair.prototype.verify = function verify(msg, signature) {
  38488. return this.ec.verify(msg, signature, this);
  38489. };
  38490. KeyPair.prototype.inspect = function inspect() {
  38491. return '<Key priv: ' + (this.priv && this.priv.toString(16, 2)) + ' pub: ' + (this.pub && this.pub.inspect()) + ' >';
  38492. };
  38493. },{"../utils":364,"bn.js":365}],359:[function(require,module,exports){
  38494. 'use strict';
  38495. var BN = require('bn.js');
  38496. var utils = require('../utils');
  38497. var assert = utils.assert;
  38498. function Signature(options, enc) {
  38499. if (options instanceof Signature) return options;
  38500. if (this._importDER(options, enc)) return;
  38501. assert(options.r && options.s, 'Signature without r or s');
  38502. this.r = new BN(options.r, 16);
  38503. this.s = new BN(options.s, 16);
  38504. if (options.recoveryParam === undefined) this.recoveryParam = null;else this.recoveryParam = options.recoveryParam;
  38505. }
  38506. module.exports = Signature;
  38507. function Position() {
  38508. this.place = 0;
  38509. }
  38510. function getLength(buf, p) {
  38511. var initial = buf[p.place++];
  38512. if (!(initial & 0x80)) {
  38513. return initial;
  38514. }
  38515. var octetLen = initial & 0xf; // Indefinite length or overflow
  38516. if (octetLen === 0 || octetLen > 4) {
  38517. return false;
  38518. }
  38519. var val = 0;
  38520. for (var i = 0, off = p.place; i < octetLen; i++, off++) {
  38521. val <<= 8;
  38522. val |= buf[off];
  38523. val >>>= 0;
  38524. } // Leading zeroes
  38525. if (val <= 0x7f) {
  38526. return false;
  38527. }
  38528. p.place = off;
  38529. return val;
  38530. }
  38531. function rmPadding(buf) {
  38532. var i = 0;
  38533. var len = buf.length - 1;
  38534. while (!buf[i] && !(buf[i + 1] & 0x80) && i < len) {
  38535. i++;
  38536. }
  38537. if (i === 0) {
  38538. return buf;
  38539. }
  38540. return buf.slice(i);
  38541. }
  38542. Signature.prototype._importDER = function _importDER(data, enc) {
  38543. data = utils.toArray(data, enc);
  38544. var p = new Position();
  38545. if (data[p.place++] !== 0x30) {
  38546. return false;
  38547. }
  38548. var len = getLength(data, p);
  38549. if (len === false) {
  38550. return false;
  38551. }
  38552. if (len + p.place !== data.length) {
  38553. return false;
  38554. }
  38555. if (data[p.place++] !== 0x02) {
  38556. return false;
  38557. }
  38558. var rlen = getLength(data, p);
  38559. if (rlen === false) {
  38560. return false;
  38561. }
  38562. var r = data.slice(p.place, rlen + p.place);
  38563. p.place += rlen;
  38564. if (data[p.place++] !== 0x02) {
  38565. return false;
  38566. }
  38567. var slen = getLength(data, p);
  38568. if (slen === false) {
  38569. return false;
  38570. }
  38571. if (data.length !== slen + p.place) {
  38572. return false;
  38573. }
  38574. var s = data.slice(p.place, slen + p.place);
  38575. if (r[0] === 0) {
  38576. if (r[1] & 0x80) {
  38577. r = r.slice(1);
  38578. } else {
  38579. // Leading zeroes
  38580. return false;
  38581. }
  38582. }
  38583. if (s[0] === 0) {
  38584. if (s[1] & 0x80) {
  38585. s = s.slice(1);
  38586. } else {
  38587. // Leading zeroes
  38588. return false;
  38589. }
  38590. }
  38591. this.r = new BN(r);
  38592. this.s = new BN(s);
  38593. this.recoveryParam = null;
  38594. return true;
  38595. };
  38596. function constructLength(arr, len) {
  38597. if (len < 0x80) {
  38598. arr.push(len);
  38599. return;
  38600. }
  38601. var octets = 1 + (Math.log(len) / Math.LN2 >>> 3);
  38602. arr.push(octets | 0x80);
  38603. while (--octets) {
  38604. arr.push(len >>> (octets << 3) & 0xff);
  38605. }
  38606. arr.push(len);
  38607. }
  38608. Signature.prototype.toDER = function toDER(enc) {
  38609. var r = this.r.toArray();
  38610. var s = this.s.toArray(); // Pad values
  38611. if (r[0] & 0x80) r = [0].concat(r); // Pad values
  38612. if (s[0] & 0x80) s = [0].concat(s);
  38613. r = rmPadding(r);
  38614. s = rmPadding(s);
  38615. while (!s[0] && !(s[1] & 0x80)) {
  38616. s = s.slice(1);
  38617. }
  38618. var arr = [0x02];
  38619. constructLength(arr, r.length);
  38620. arr = arr.concat(r);
  38621. arr.push(0x02);
  38622. constructLength(arr, s.length);
  38623. var backHalf = arr.concat(s);
  38624. var res = [0x30];
  38625. constructLength(res, backHalf.length);
  38626. res = res.concat(backHalf);
  38627. return utils.encode(res, enc);
  38628. };
  38629. },{"../utils":364,"bn.js":365}],360:[function(require,module,exports){
  38630. 'use strict';
  38631. var hash = require('hash.js');
  38632. var curves = require('../curves');
  38633. var utils = require('../utils');
  38634. var assert = utils.assert;
  38635. var parseBytes = utils.parseBytes;
  38636. var KeyPair = require('./key');
  38637. var Signature = require('./signature');
  38638. function EDDSA(curve) {
  38639. assert(curve === 'ed25519', 'only tested with ed25519 so far');
  38640. if (!(this instanceof EDDSA)) return new EDDSA(curve);
  38641. var curve = curves[curve].curve;
  38642. this.curve = curve;
  38643. this.g = curve.g;
  38644. this.g.precompute(curve.n.bitLength() + 1);
  38645. this.pointClass = curve.point().constructor;
  38646. this.encodingLength = Math.ceil(curve.n.bitLength() / 8);
  38647. this.hash = hash.sha512;
  38648. }
  38649. module.exports = EDDSA;
  38650. /**
  38651. * @param {Array|String} message - message bytes
  38652. * @param {Array|String|KeyPair} secret - secret bytes or a keypair
  38653. * @returns {Signature} - signature
  38654. */
  38655. EDDSA.prototype.sign = function sign(message, secret) {
  38656. message = parseBytes(message);
  38657. var key = this.keyFromSecret(secret);
  38658. var r = this.hashInt(key.messagePrefix(), message);
  38659. var R = this.g.mul(r);
  38660. var Rencoded = this.encodePoint(R);
  38661. var s_ = this.hashInt(Rencoded, key.pubBytes(), message).mul(key.priv());
  38662. var S = r.add(s_).umod(this.curve.n);
  38663. return this.makeSignature({
  38664. R: R,
  38665. S: S,
  38666. Rencoded: Rencoded
  38667. });
  38668. };
  38669. /**
  38670. * @param {Array} message - message bytes
  38671. * @param {Array|String|Signature} sig - sig bytes
  38672. * @param {Array|String|Point|KeyPair} pub - public key
  38673. * @returns {Boolean} - true if public key matches sig of message
  38674. */
  38675. EDDSA.prototype.verify = function verify(message, sig, pub) {
  38676. message = parseBytes(message);
  38677. sig = this.makeSignature(sig);
  38678. var key = this.keyFromPublic(pub);
  38679. var h = this.hashInt(sig.Rencoded(), key.pubBytes(), message);
  38680. var SG = this.g.mul(sig.S());
  38681. var RplusAh = sig.R().add(key.pub().mul(h));
  38682. return RplusAh.eq(SG);
  38683. };
  38684. EDDSA.prototype.hashInt = function hashInt() {
  38685. var hash = this.hash();
  38686. for (var i = 0; i < arguments.length; i++) {
  38687. hash.update(arguments[i]);
  38688. }
  38689. return utils.intFromLE(hash.digest()).umod(this.curve.n);
  38690. };
  38691. EDDSA.prototype.keyFromPublic = function keyFromPublic(pub) {
  38692. return KeyPair.fromPublic(this, pub);
  38693. };
  38694. EDDSA.prototype.keyFromSecret = function keyFromSecret(secret) {
  38695. return KeyPair.fromSecret(this, secret);
  38696. };
  38697. EDDSA.prototype.makeSignature = function makeSignature(sig) {
  38698. if (sig instanceof Signature) return sig;
  38699. return new Signature(this, sig);
  38700. };
  38701. /**
  38702. * * https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-03#section-5.2
  38703. *
  38704. * EDDSA defines methods for encoding and decoding points and integers. These are
  38705. * helper convenience methods, that pass along to utility functions implied
  38706. * parameters.
  38707. *
  38708. */
  38709. EDDSA.prototype.encodePoint = function encodePoint(point) {
  38710. var enc = point.getY().toArray('le', this.encodingLength);
  38711. enc[this.encodingLength - 1] |= point.getX().isOdd() ? 0x80 : 0;
  38712. return enc;
  38713. };
  38714. EDDSA.prototype.decodePoint = function decodePoint(bytes) {
  38715. bytes = utils.parseBytes(bytes);
  38716. var lastIx = bytes.length - 1;
  38717. var normed = bytes.slice(0, lastIx).concat(bytes[lastIx] & ~0x80);
  38718. var xIsOdd = (bytes[lastIx] & 0x80) !== 0;
  38719. var y = utils.intFromLE(normed);
  38720. return this.curve.pointFromY(y, xIsOdd);
  38721. };
  38722. EDDSA.prototype.encodeInt = function encodeInt(num) {
  38723. return num.toArray('le', this.encodingLength);
  38724. };
  38725. EDDSA.prototype.decodeInt = function decodeInt(bytes) {
  38726. return utils.intFromLE(bytes);
  38727. };
  38728. EDDSA.prototype.isPoint = function isPoint(val) {
  38729. return val instanceof this.pointClass;
  38730. };
  38731. },{"../curves":356,"../utils":364,"./key":361,"./signature":362,"hash.js":372}],361:[function(require,module,exports){
  38732. 'use strict';
  38733. var utils = require('../utils');
  38734. var assert = utils.assert;
  38735. var parseBytes = utils.parseBytes;
  38736. var cachedProperty = utils.cachedProperty;
  38737. /**
  38738. * @param {EDDSA} eddsa - instance
  38739. * @param {Object} params - public/private key parameters
  38740. *
  38741. * @param {Array<Byte>} [params.secret] - secret seed bytes
  38742. * @param {Point} [params.pub] - public key point (aka `A` in eddsa terms)
  38743. * @param {Array<Byte>} [params.pub] - public key point encoded as bytes
  38744. *
  38745. */
  38746. function KeyPair(eddsa, params) {
  38747. this.eddsa = eddsa;
  38748. this._secret = parseBytes(params.secret);
  38749. if (eddsa.isPoint(params.pub)) this._pub = params.pub;else this._pubBytes = parseBytes(params.pub);
  38750. }
  38751. KeyPair.fromPublic = function fromPublic(eddsa, pub) {
  38752. if (pub instanceof KeyPair) return pub;
  38753. return new KeyPair(eddsa, {
  38754. pub: pub
  38755. });
  38756. };
  38757. KeyPair.fromSecret = function fromSecret(eddsa, secret) {
  38758. if (secret instanceof KeyPair) return secret;
  38759. return new KeyPair(eddsa, {
  38760. secret: secret
  38761. });
  38762. };
  38763. KeyPair.prototype.secret = function secret() {
  38764. return this._secret;
  38765. };
  38766. cachedProperty(KeyPair, 'pubBytes', function pubBytes() {
  38767. return this.eddsa.encodePoint(this.pub());
  38768. });
  38769. cachedProperty(KeyPair, 'pub', function pub() {
  38770. if (this._pubBytes) return this.eddsa.decodePoint(this._pubBytes);
  38771. return this.eddsa.g.mul(this.priv());
  38772. });
  38773. cachedProperty(KeyPair, 'privBytes', function privBytes() {
  38774. var eddsa = this.eddsa;
  38775. var hash = this.hash();
  38776. var lastIx = eddsa.encodingLength - 1;
  38777. var a = hash.slice(0, eddsa.encodingLength);
  38778. a[0] &= 248;
  38779. a[lastIx] &= 127;
  38780. a[lastIx] |= 64;
  38781. return a;
  38782. });
  38783. cachedProperty(KeyPair, 'priv', function priv() {
  38784. return this.eddsa.decodeInt(this.privBytes());
  38785. });
  38786. cachedProperty(KeyPair, 'hash', function hash() {
  38787. return this.eddsa.hash().update(this.secret()).digest();
  38788. });
  38789. cachedProperty(KeyPair, 'messagePrefix', function messagePrefix() {
  38790. return this.hash().slice(this.eddsa.encodingLength);
  38791. });
  38792. KeyPair.prototype.sign = function sign(message) {
  38793. assert(this._secret, 'KeyPair can only verify');
  38794. return this.eddsa.sign(message, this);
  38795. };
  38796. KeyPair.prototype.verify = function verify(message, sig) {
  38797. return this.eddsa.verify(message, sig, this);
  38798. };
  38799. KeyPair.prototype.getSecret = function getSecret(enc) {
  38800. assert(this._secret, 'KeyPair is public only');
  38801. return utils.encode(this.secret(), enc);
  38802. };
  38803. KeyPair.prototype.getPublic = function getPublic(enc) {
  38804. return utils.encode(this.pubBytes(), enc);
  38805. };
  38806. module.exports = KeyPair;
  38807. },{"../utils":364}],362:[function(require,module,exports){
  38808. 'use strict';
  38809. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  38810. var BN = require('bn.js');
  38811. var utils = require('../utils');
  38812. var assert = utils.assert;
  38813. var cachedProperty = utils.cachedProperty;
  38814. var parseBytes = utils.parseBytes;
  38815. /**
  38816. * @param {EDDSA} eddsa - eddsa instance
  38817. * @param {Array<Bytes>|Object} sig -
  38818. * @param {Array<Bytes>|Point} [sig.R] - R point as Point or bytes
  38819. * @param {Array<Bytes>|bn} [sig.S] - S scalar as bn or bytes
  38820. * @param {Array<Bytes>} [sig.Rencoded] - R point encoded
  38821. * @param {Array<Bytes>} [sig.Sencoded] - S scalar encoded
  38822. */
  38823. function Signature(eddsa, sig) {
  38824. this.eddsa = eddsa;
  38825. if (_typeof(sig) !== 'object') sig = parseBytes(sig);
  38826. if (Array.isArray(sig)) {
  38827. sig = {
  38828. R: sig.slice(0, eddsa.encodingLength),
  38829. S: sig.slice(eddsa.encodingLength)
  38830. };
  38831. }
  38832. assert(sig.R && sig.S, 'Signature without R or S');
  38833. if (eddsa.isPoint(sig.R)) this._R = sig.R;
  38834. if (sig.S instanceof BN) this._S = sig.S;
  38835. this._Rencoded = Array.isArray(sig.R) ? sig.R : sig.Rencoded;
  38836. this._Sencoded = Array.isArray(sig.S) ? sig.S : sig.Sencoded;
  38837. }
  38838. cachedProperty(Signature, 'S', function S() {
  38839. return this.eddsa.decodeInt(this.Sencoded());
  38840. });
  38841. cachedProperty(Signature, 'R', function R() {
  38842. return this.eddsa.decodePoint(this.Rencoded());
  38843. });
  38844. cachedProperty(Signature, 'Rencoded', function Rencoded() {
  38845. return this.eddsa.encodePoint(this.R());
  38846. });
  38847. cachedProperty(Signature, 'Sencoded', function Sencoded() {
  38848. return this.eddsa.encodeInt(this.S());
  38849. });
  38850. Signature.prototype.toBytes = function toBytes() {
  38851. return this.Rencoded().concat(this.Sencoded());
  38852. };
  38853. Signature.prototype.toHex = function toHex() {
  38854. return utils.encode(this.toBytes(), 'hex').toUpperCase();
  38855. };
  38856. module.exports = Signature;
  38857. },{"../utils":364,"bn.js":365}],363:[function(require,module,exports){
  38858. "use strict";
  38859. module.exports = {
  38860. doubles: {
  38861. step: 4,
  38862. 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']]
  38863. },
  38864. naf: {
  38865. wnd: 7,
  38866. 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']]
  38867. }
  38868. };
  38869. },{}],364:[function(require,module,exports){
  38870. 'use strict';
  38871. var utils = exports;
  38872. var BN = require('bn.js');
  38873. var minAssert = require('minimalistic-assert');
  38874. var minUtils = require('minimalistic-crypto-utils');
  38875. utils.assert = minAssert;
  38876. utils.toArray = minUtils.toArray;
  38877. utils.zero2 = minUtils.zero2;
  38878. utils.toHex = minUtils.toHex;
  38879. utils.encode = minUtils.encode; // Represent num in a w-NAF form
  38880. function getNAF(num, w, bits) {
  38881. var naf = new Array(Math.max(num.bitLength(), bits) + 1);
  38882. naf.fill(0);
  38883. var ws = 1 << w + 1;
  38884. var k = num.clone();
  38885. for (var i = 0; i < naf.length; i++) {
  38886. var z;
  38887. var mod = k.andln(ws - 1);
  38888. if (k.isOdd()) {
  38889. if (mod > (ws >> 1) - 1) z = (ws >> 1) - mod;else z = mod;
  38890. k.isubn(z);
  38891. } else {
  38892. z = 0;
  38893. }
  38894. naf[i] = z;
  38895. k.iushrn(1);
  38896. }
  38897. return naf;
  38898. }
  38899. utils.getNAF = getNAF; // Represent k1, k2 in a Joint Sparse Form
  38900. function getJSF(k1, k2) {
  38901. var jsf = [[], []];
  38902. k1 = k1.clone();
  38903. k2 = k2.clone();
  38904. var d1 = 0;
  38905. var d2 = 0;
  38906. while (k1.cmpn(-d1) > 0 || k2.cmpn(-d2) > 0) {
  38907. // First phase
  38908. var m14 = k1.andln(3) + d1 & 3;
  38909. var m24 = k2.andln(3) + d2 & 3;
  38910. if (m14 === 3) m14 = -1;
  38911. if (m24 === 3) m24 = -1;
  38912. var u1;
  38913. if ((m14 & 1) === 0) {
  38914. u1 = 0;
  38915. } else {
  38916. var m8 = k1.andln(7) + d1 & 7;
  38917. if ((m8 === 3 || m8 === 5) && m24 === 2) u1 = -m14;else u1 = m14;
  38918. }
  38919. jsf[0].push(u1);
  38920. var u2;
  38921. if ((m24 & 1) === 0) {
  38922. u2 = 0;
  38923. } else {
  38924. var m8 = k2.andln(7) + d2 & 7;
  38925. if ((m8 === 3 || m8 === 5) && m14 === 2) u2 = -m24;else u2 = m24;
  38926. }
  38927. jsf[1].push(u2); // Second phase
  38928. if (2 * d1 === u1 + 1) d1 = 1 - d1;
  38929. if (2 * d2 === u2 + 1) d2 = 1 - d2;
  38930. k1.iushrn(1);
  38931. k2.iushrn(1);
  38932. }
  38933. return jsf;
  38934. }
  38935. utils.getJSF = getJSF;
  38936. function cachedProperty(obj, name, computer) {
  38937. var key = '_' + name;
  38938. obj.prototype[name] = function cachedProperty() {
  38939. return this[key] !== undefined ? this[key] : this[key] = computer.call(this);
  38940. };
  38941. }
  38942. utils.cachedProperty = cachedProperty;
  38943. function parseBytes(bytes) {
  38944. return typeof bytes === 'string' ? utils.toArray(bytes, 'hex') : bytes;
  38945. }
  38946. utils.parseBytes = parseBytes;
  38947. function intFromLE(bytes) {
  38948. return new BN(bytes, 'hex', 'le');
  38949. }
  38950. utils.intFromLE = intFromLE;
  38951. },{"bn.js":365,"minimalistic-assert":437,"minimalistic-crypto-utils":438}],365:[function(require,module,exports){
  38952. arguments[4][181][0].apply(exports,arguments)
  38953. },{"buffer":185,"dup":181}],366:[function(require,module,exports){
  38954. module.exports={
  38955. "_from": "elliptic@^6.5.3",
  38956. "_id": "elliptic@6.5.3",
  38957. "_inBundle": false,
  38958. "_integrity": "sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw==",
  38959. "_location": "/elliptic",
  38960. "_phantomChildren": {},
  38961. "_requested": {
  38962. "type": "range",
  38963. "registry": true,
  38964. "raw": "elliptic@^6.5.3",
  38965. "name": "elliptic",
  38966. "escapedName": "elliptic",
  38967. "rawSpec": "^6.5.3",
  38968. "saveSpec": null,
  38969. "fetchSpec": "^6.5.3"
  38970. },
  38971. "_requiredBy": [
  38972. "/browserify-sign",
  38973. "/create-ecdh"
  38974. ],
  38975. "_resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.3.tgz",
  38976. "_shasum": "cb59eb2efdaf73a0bd78ccd7015a62ad6e0f93d6",
  38977. "_spec": "elliptic@^6.5.3",
  38978. "_where": "/mnt/d/dev/git/exceljs/node_modules/browserify-sign",
  38979. "author": {
  38980. "name": "Fedor Indutny",
  38981. "email": "fedor@indutny.com"
  38982. },
  38983. "bugs": {
  38984. "url": "https://github.com/indutny/elliptic/issues"
  38985. },
  38986. "bundleDependencies": false,
  38987. "dependencies": {
  38988. "bn.js": "^4.4.0",
  38989. "brorand": "^1.0.1",
  38990. "hash.js": "^1.0.0",
  38991. "hmac-drbg": "^1.0.0",
  38992. "inherits": "^2.0.1",
  38993. "minimalistic-assert": "^1.0.0",
  38994. "minimalistic-crypto-utils": "^1.0.0"
  38995. },
  38996. "deprecated": false,
  38997. "description": "EC cryptography",
  38998. "devDependencies": {
  38999. "brfs": "^1.4.3",
  39000. "coveralls": "^3.0.8",
  39001. "grunt": "^1.0.4",
  39002. "grunt-browserify": "^5.0.0",
  39003. "grunt-cli": "^1.2.0",
  39004. "grunt-contrib-connect": "^1.0.0",
  39005. "grunt-contrib-copy": "^1.0.0",
  39006. "grunt-contrib-uglify": "^1.0.1",
  39007. "grunt-mocha-istanbul": "^3.0.1",
  39008. "grunt-saucelabs": "^9.0.1",
  39009. "istanbul": "^0.4.2",
  39010. "jscs": "^3.0.7",
  39011. "jshint": "^2.10.3",
  39012. "mocha": "^6.2.2"
  39013. },
  39014. "files": [
  39015. "lib"
  39016. ],
  39017. "homepage": "https://github.com/indutny/elliptic",
  39018. "keywords": [
  39019. "EC",
  39020. "Elliptic",
  39021. "curve",
  39022. "Cryptography"
  39023. ],
  39024. "license": "MIT",
  39025. "main": "lib/elliptic.js",
  39026. "name": "elliptic",
  39027. "repository": {
  39028. "type": "git",
  39029. "url": "git+ssh://git@github.com/indutny/elliptic.git"
  39030. },
  39031. "scripts": {
  39032. "jscs": "jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",
  39033. "jshint": "jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",
  39034. "lint": "npm run jscs && npm run jshint",
  39035. "test": "npm run lint && npm run unit",
  39036. "unit": "istanbul test _mocha --reporter=spec test/index.js",
  39037. "version": "grunt dist && git add dist/"
  39038. },
  39039. "version": "6.5.3"
  39040. }
  39041. },{}],367:[function(require,module,exports){
  39042. "use strict";
  39043. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  39044. // Copyright Joyent, Inc. and other Node contributors.
  39045. //
  39046. // Permission is hereby granted, free of charge, to any person obtaining a
  39047. // copy of this software and associated documentation files (the
  39048. // "Software"), to deal in the Software without restriction, including
  39049. // without limitation the rights to use, copy, modify, merge, publish,
  39050. // distribute, sublicense, and/or sell copies of the Software, and to permit
  39051. // persons to whom the Software is furnished to do so, subject to the
  39052. // following conditions:
  39053. //
  39054. // The above copyright notice and this permission notice shall be included
  39055. // in all copies or substantial portions of the Software.
  39056. //
  39057. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  39058. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  39059. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  39060. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  39061. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  39062. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  39063. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  39064. var objectCreate = Object.create || objectCreatePolyfill;
  39065. var objectKeys = Object.keys || objectKeysPolyfill;
  39066. var bind = Function.prototype.bind || functionBindPolyfill;
  39067. function EventEmitter() {
  39068. if (!this._events || !Object.prototype.hasOwnProperty.call(this, '_events')) {
  39069. this._events = objectCreate(null);
  39070. this._eventsCount = 0;
  39071. }
  39072. this._maxListeners = this._maxListeners || undefined;
  39073. }
  39074. module.exports = EventEmitter; // Backwards-compat with node 0.10.x
  39075. EventEmitter.EventEmitter = EventEmitter;
  39076. EventEmitter.prototype._events = undefined;
  39077. EventEmitter.prototype._maxListeners = undefined; // By default EventEmitters will print a warning if more than 10 listeners are
  39078. // added to it. This is a useful default which helps finding memory leaks.
  39079. var defaultMaxListeners = 10;
  39080. var hasDefineProperty;
  39081. try {
  39082. var o = {};
  39083. if (Object.defineProperty) Object.defineProperty(o, 'x', {
  39084. value: 0
  39085. });
  39086. hasDefineProperty = o.x === 0;
  39087. } catch (err) {
  39088. hasDefineProperty = false;
  39089. }
  39090. if (hasDefineProperty) {
  39091. Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
  39092. enumerable: true,
  39093. get: function get() {
  39094. return defaultMaxListeners;
  39095. },
  39096. set: function set(arg) {
  39097. // check whether the input is a positive number (whose value is zero or
  39098. // greater and not a NaN).
  39099. if (typeof arg !== 'number' || arg < 0 || arg !== arg) throw new TypeError('"defaultMaxListeners" must be a positive number');
  39100. defaultMaxListeners = arg;
  39101. }
  39102. });
  39103. } else {
  39104. EventEmitter.defaultMaxListeners = defaultMaxListeners;
  39105. } // Obviously not all Emitters should be limited to 10. This function allows
  39106. // that to be increased. Set to zero for unlimited.
  39107. EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
  39108. if (typeof n !== 'number' || n < 0 || isNaN(n)) throw new TypeError('"n" argument must be a positive number');
  39109. this._maxListeners = n;
  39110. return this;
  39111. };
  39112. function $getMaxListeners(that) {
  39113. if (that._maxListeners === undefined) return EventEmitter.defaultMaxListeners;
  39114. return that._maxListeners;
  39115. }
  39116. EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
  39117. return $getMaxListeners(this);
  39118. }; // These standalone emit* functions are used to optimize calling of event
  39119. // handlers for fast cases because emit() itself often has a variable number of
  39120. // arguments and can be deoptimized because of that. These functions always have
  39121. // the same number of arguments and thus do not get deoptimized, so the code
  39122. // inside them can execute faster.
  39123. function emitNone(handler, isFn, self) {
  39124. if (isFn) handler.call(self);else {
  39125. var len = handler.length;
  39126. var listeners = arrayClone(handler, len);
  39127. for (var i = 0; i < len; ++i) {
  39128. listeners[i].call(self);
  39129. }
  39130. }
  39131. }
  39132. function emitOne(handler, isFn, self, arg1) {
  39133. if (isFn) handler.call(self, arg1);else {
  39134. var len = handler.length;
  39135. var listeners = arrayClone(handler, len);
  39136. for (var i = 0; i < len; ++i) {
  39137. listeners[i].call(self, arg1);
  39138. }
  39139. }
  39140. }
  39141. function emitTwo(handler, isFn, self, arg1, arg2) {
  39142. if (isFn) handler.call(self, arg1, arg2);else {
  39143. var len = handler.length;
  39144. var listeners = arrayClone(handler, len);
  39145. for (var i = 0; i < len; ++i) {
  39146. listeners[i].call(self, arg1, arg2);
  39147. }
  39148. }
  39149. }
  39150. function emitThree(handler, isFn, self, arg1, arg2, arg3) {
  39151. if (isFn) handler.call(self, arg1, arg2, arg3);else {
  39152. var len = handler.length;
  39153. var listeners = arrayClone(handler, len);
  39154. for (var i = 0; i < len; ++i) {
  39155. listeners[i].call(self, arg1, arg2, arg3);
  39156. }
  39157. }
  39158. }
  39159. function emitMany(handler, isFn, self, args) {
  39160. if (isFn) handler.apply(self, args);else {
  39161. var len = handler.length;
  39162. var listeners = arrayClone(handler, len);
  39163. for (var i = 0; i < len; ++i) {
  39164. listeners[i].apply(self, args);
  39165. }
  39166. }
  39167. }
  39168. EventEmitter.prototype.emit = function emit(type) {
  39169. var er, handler, len, args, i, events;
  39170. var doError = type === 'error';
  39171. events = this._events;
  39172. if (events) doError = doError && events.error == null;else if (!doError) return false; // If there is no 'error' event listener then throw.
  39173. if (doError) {
  39174. if (arguments.length > 1) er = arguments[1];
  39175. if (er instanceof Error) {
  39176. throw er; // Unhandled 'error' event
  39177. } else {
  39178. // At least give some kind of context to the user
  39179. var err = new Error('Unhandled "error" event. (' + er + ')');
  39180. err.context = er;
  39181. throw err;
  39182. }
  39183. return false;
  39184. }
  39185. handler = events[type];
  39186. if (!handler) return false;
  39187. var isFn = typeof handler === 'function';
  39188. len = arguments.length;
  39189. switch (len) {
  39190. // fast cases
  39191. case 1:
  39192. emitNone(handler, isFn, this);
  39193. break;
  39194. case 2:
  39195. emitOne(handler, isFn, this, arguments[1]);
  39196. break;
  39197. case 3:
  39198. emitTwo(handler, isFn, this, arguments[1], arguments[2]);
  39199. break;
  39200. case 4:
  39201. emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);
  39202. break;
  39203. // slower
  39204. default:
  39205. args = new Array(len - 1);
  39206. for (i = 1; i < len; i++) {
  39207. args[i - 1] = arguments[i];
  39208. }
  39209. emitMany(handler, isFn, this, args);
  39210. }
  39211. return true;
  39212. };
  39213. function _addListener(target, type, listener, prepend) {
  39214. var m;
  39215. var events;
  39216. var existing;
  39217. if (typeof listener !== 'function') throw new TypeError('"listener" argument must be a function');
  39218. events = target._events;
  39219. if (!events) {
  39220. events = target._events = objectCreate(null);
  39221. target._eventsCount = 0;
  39222. } else {
  39223. // To avoid recursion in the case that type === "newListener"! Before
  39224. // adding it to the listeners, first emit "newListener".
  39225. if (events.newListener) {
  39226. target.emit('newListener', type, listener.listener ? listener.listener : listener); // Re-assign `events` because a newListener handler could have caused the
  39227. // this._events to be assigned to a new object
  39228. events = target._events;
  39229. }
  39230. existing = events[type];
  39231. }
  39232. if (!existing) {
  39233. // Optimize the case of one listener. Don't need the extra array object.
  39234. existing = events[type] = listener;
  39235. ++target._eventsCount;
  39236. } else {
  39237. if (typeof existing === 'function') {
  39238. // Adding the second element, need to change to array.
  39239. existing = events[type] = prepend ? [listener, existing] : [existing, listener];
  39240. } else {
  39241. // If we've already got an array, just append.
  39242. if (prepend) {
  39243. existing.unshift(listener);
  39244. } else {
  39245. existing.push(listener);
  39246. }
  39247. } // Check for listener leak
  39248. if (!existing.warned) {
  39249. m = $getMaxListeners(target);
  39250. if (m && m > 0 && existing.length > m) {
  39251. existing.warned = true;
  39252. var w = new Error('Possible EventEmitter memory leak detected. ' + existing.length + ' "' + String(type) + '" listeners ' + 'added. Use emitter.setMaxListeners() to ' + 'increase limit.');
  39253. w.name = 'MaxListenersExceededWarning';
  39254. w.emitter = target;
  39255. w.type = type;
  39256. w.count = existing.length;
  39257. if ((typeof console === "undefined" ? "undefined" : _typeof(console)) === 'object' && console.warn) {
  39258. console.warn('%s: %s', w.name, w.message);
  39259. }
  39260. }
  39261. }
  39262. }
  39263. return target;
  39264. }
  39265. EventEmitter.prototype.addListener = function addListener(type, listener) {
  39266. return _addListener(this, type, listener, false);
  39267. };
  39268. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  39269. EventEmitter.prototype.prependListener = function prependListener(type, listener) {
  39270. return _addListener(this, type, listener, true);
  39271. };
  39272. function onceWrapper() {
  39273. if (!this.fired) {
  39274. this.target.removeListener(this.type, this.wrapFn);
  39275. this.fired = true;
  39276. switch (arguments.length) {
  39277. case 0:
  39278. return this.listener.call(this.target);
  39279. case 1:
  39280. return this.listener.call(this.target, arguments[0]);
  39281. case 2:
  39282. return this.listener.call(this.target, arguments[0], arguments[1]);
  39283. case 3:
  39284. return this.listener.call(this.target, arguments[0], arguments[1], arguments[2]);
  39285. default:
  39286. var args = new Array(arguments.length);
  39287. for (var i = 0; i < args.length; ++i) {
  39288. args[i] = arguments[i];
  39289. }
  39290. this.listener.apply(this.target, args);
  39291. }
  39292. }
  39293. }
  39294. function _onceWrap(target, type, listener) {
  39295. var state = {
  39296. fired: false,
  39297. wrapFn: undefined,
  39298. target: target,
  39299. type: type,
  39300. listener: listener
  39301. };
  39302. var wrapped = bind.call(onceWrapper, state);
  39303. wrapped.listener = listener;
  39304. state.wrapFn = wrapped;
  39305. return wrapped;
  39306. }
  39307. EventEmitter.prototype.once = function once(type, listener) {
  39308. if (typeof listener !== 'function') throw new TypeError('"listener" argument must be a function');
  39309. this.on(type, _onceWrap(this, type, listener));
  39310. return this;
  39311. };
  39312. EventEmitter.prototype.prependOnceListener = function prependOnceListener(type, listener) {
  39313. if (typeof listener !== 'function') throw new TypeError('"listener" argument must be a function');
  39314. this.prependListener(type, _onceWrap(this, type, listener));
  39315. return this;
  39316. }; // Emits a 'removeListener' event if and only if the listener was removed.
  39317. EventEmitter.prototype.removeListener = function removeListener(type, listener) {
  39318. var list, events, position, i, originalListener;
  39319. if (typeof listener !== 'function') throw new TypeError('"listener" argument must be a function');
  39320. events = this._events;
  39321. if (!events) return this;
  39322. list = events[type];
  39323. if (!list) return this;
  39324. if (list === listener || list.listener === listener) {
  39325. if (--this._eventsCount === 0) this._events = objectCreate(null);else {
  39326. delete events[type];
  39327. if (events.removeListener) this.emit('removeListener', type, list.listener || listener);
  39328. }
  39329. } else if (typeof list !== 'function') {
  39330. position = -1;
  39331. for (i = list.length - 1; i >= 0; i--) {
  39332. if (list[i] === listener || list[i].listener === listener) {
  39333. originalListener = list[i].listener;
  39334. position = i;
  39335. break;
  39336. }
  39337. }
  39338. if (position < 0) return this;
  39339. if (position === 0) list.shift();else spliceOne(list, position);
  39340. if (list.length === 1) events[type] = list[0];
  39341. if (events.removeListener) this.emit('removeListener', type, originalListener || listener);
  39342. }
  39343. return this;
  39344. };
  39345. EventEmitter.prototype.removeAllListeners = function removeAllListeners(type) {
  39346. var listeners, events, i;
  39347. events = this._events;
  39348. if (!events) return this; // not listening for removeListener, no need to emit
  39349. if (!events.removeListener) {
  39350. if (arguments.length === 0) {
  39351. this._events = objectCreate(null);
  39352. this._eventsCount = 0;
  39353. } else if (events[type]) {
  39354. if (--this._eventsCount === 0) this._events = objectCreate(null);else delete events[type];
  39355. }
  39356. return this;
  39357. } // emit removeListener for all listeners on all events
  39358. if (arguments.length === 0) {
  39359. var keys = objectKeys(events);
  39360. var key;
  39361. for (i = 0; i < keys.length; ++i) {
  39362. key = keys[i];
  39363. if (key === 'removeListener') continue;
  39364. this.removeAllListeners(key);
  39365. }
  39366. this.removeAllListeners('removeListener');
  39367. this._events = objectCreate(null);
  39368. this._eventsCount = 0;
  39369. return this;
  39370. }
  39371. listeners = events[type];
  39372. if (typeof listeners === 'function') {
  39373. this.removeListener(type, listeners);
  39374. } else if (listeners) {
  39375. // LIFO order
  39376. for (i = listeners.length - 1; i >= 0; i--) {
  39377. this.removeListener(type, listeners[i]);
  39378. }
  39379. }
  39380. return this;
  39381. };
  39382. function _listeners(target, type, unwrap) {
  39383. var events = target._events;
  39384. if (!events) return [];
  39385. var evlistener = events[type];
  39386. if (!evlistener) return [];
  39387. if (typeof evlistener === 'function') return unwrap ? [evlistener.listener || evlistener] : [evlistener];
  39388. return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
  39389. }
  39390. EventEmitter.prototype.listeners = function listeners(type) {
  39391. return _listeners(this, type, true);
  39392. };
  39393. EventEmitter.prototype.rawListeners = function rawListeners(type) {
  39394. return _listeners(this, type, false);
  39395. };
  39396. EventEmitter.listenerCount = function (emitter, type) {
  39397. if (typeof emitter.listenerCount === 'function') {
  39398. return emitter.listenerCount(type);
  39399. } else {
  39400. return listenerCount.call(emitter, type);
  39401. }
  39402. };
  39403. EventEmitter.prototype.listenerCount = listenerCount;
  39404. function listenerCount(type) {
  39405. var events = this._events;
  39406. if (events) {
  39407. var evlistener = events[type];
  39408. if (typeof evlistener === 'function') {
  39409. return 1;
  39410. } else if (evlistener) {
  39411. return evlistener.length;
  39412. }
  39413. }
  39414. return 0;
  39415. }
  39416. EventEmitter.prototype.eventNames = function eventNames() {
  39417. return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
  39418. }; // About 1.5x faster than the two-arg version of Array#splice().
  39419. function spliceOne(list, index) {
  39420. for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1) {
  39421. list[i] = list[k];
  39422. }
  39423. list.pop();
  39424. }
  39425. function arrayClone(arr, n) {
  39426. var copy = new Array(n);
  39427. for (var i = 0; i < n; ++i) {
  39428. copy[i] = arr[i];
  39429. }
  39430. return copy;
  39431. }
  39432. function unwrapListeners(arr) {
  39433. var ret = new Array(arr.length);
  39434. for (var i = 0; i < ret.length; ++i) {
  39435. ret[i] = arr[i].listener || arr[i];
  39436. }
  39437. return ret;
  39438. }
  39439. function objectCreatePolyfill(proto) {
  39440. var F = function F() {};
  39441. F.prototype = proto;
  39442. return new F();
  39443. }
  39444. function objectKeysPolyfill(obj) {
  39445. var keys = [];
  39446. for (var k in obj) {
  39447. if (Object.prototype.hasOwnProperty.call(obj, k)) {
  39448. keys.push(k);
  39449. }
  39450. }
  39451. return k;
  39452. }
  39453. function functionBindPolyfill(context) {
  39454. var fn = this;
  39455. return function () {
  39456. return fn.apply(context, arguments);
  39457. };
  39458. }
  39459. },{}],368:[function(require,module,exports){
  39460. "use strict";
  39461. var Buffer = require('safe-buffer').Buffer;
  39462. var MD5 = require('md5.js');
  39463. /* eslint-disable camelcase */
  39464. function EVP_BytesToKey(password, salt, keyBits, ivLen) {
  39465. if (!Buffer.isBuffer(password)) password = Buffer.from(password, 'binary');
  39466. if (salt) {
  39467. if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, 'binary');
  39468. if (salt.length !== 8) throw new RangeError('salt should be Buffer with 8 byte length');
  39469. }
  39470. var keyLen = keyBits / 8;
  39471. var key = Buffer.alloc(keyLen);
  39472. var iv = Buffer.alloc(ivLen || 0);
  39473. var tmp = Buffer.alloc(0);
  39474. while (keyLen > 0 || ivLen > 0) {
  39475. var hash = new MD5();
  39476. hash.update(tmp);
  39477. hash.update(password);
  39478. if (salt) hash.update(salt);
  39479. tmp = hash.digest();
  39480. var used = 0;
  39481. if (keyLen > 0) {
  39482. var keyStart = key.length - keyLen;
  39483. used = Math.min(keyLen, tmp.length);
  39484. tmp.copy(key, keyStart, 0, used);
  39485. keyLen -= used;
  39486. }
  39487. if (used < tmp.length && ivLen > 0) {
  39488. var ivStart = iv.length - ivLen;
  39489. var length = Math.min(ivLen, tmp.length - used);
  39490. tmp.copy(iv, ivStart, used, used + length);
  39491. ivLen -= length;
  39492. }
  39493. }
  39494. tmp.fill(0);
  39495. return {
  39496. key: key,
  39497. iv: iv
  39498. };
  39499. }
  39500. module.exports = EVP_BytesToKey;
  39501. },{"md5.js":434,"safe-buffer":494}],369:[function(require,module,exports){
  39502. "use strict";
  39503. Object.defineProperty(exports, "__esModule", {
  39504. value: true
  39505. });
  39506. var format_1 = require("@fast-csv/format");
  39507. Object.defineProperty(exports, "format", {
  39508. enumerable: true,
  39509. get: function get() {
  39510. return format_1.format;
  39511. }
  39512. });
  39513. Object.defineProperty(exports, "write", {
  39514. enumerable: true,
  39515. get: function get() {
  39516. return format_1.write;
  39517. }
  39518. });
  39519. Object.defineProperty(exports, "writeToStream", {
  39520. enumerable: true,
  39521. get: function get() {
  39522. return format_1.writeToStream;
  39523. }
  39524. });
  39525. Object.defineProperty(exports, "writeToBuffer", {
  39526. enumerable: true,
  39527. get: function get() {
  39528. return format_1.writeToBuffer;
  39529. }
  39530. });
  39531. Object.defineProperty(exports, "writeToString", {
  39532. enumerable: true,
  39533. get: function get() {
  39534. return format_1.writeToString;
  39535. }
  39536. });
  39537. Object.defineProperty(exports, "writeToPath", {
  39538. enumerable: true,
  39539. get: function get() {
  39540. return format_1.writeToPath;
  39541. }
  39542. });
  39543. Object.defineProperty(exports, "CsvFormatterStream", {
  39544. enumerable: true,
  39545. get: function get() {
  39546. return format_1.CsvFormatterStream;
  39547. }
  39548. });
  39549. Object.defineProperty(exports, "FormatterOptions", {
  39550. enumerable: true,
  39551. get: function get() {
  39552. return format_1.FormatterOptions;
  39553. }
  39554. });
  39555. var parse_1 = require("@fast-csv/parse");
  39556. Object.defineProperty(exports, "parse", {
  39557. enumerable: true,
  39558. get: function get() {
  39559. return parse_1.parse;
  39560. }
  39561. });
  39562. Object.defineProperty(exports, "parseString", {
  39563. enumerable: true,
  39564. get: function get() {
  39565. return parse_1.parseString;
  39566. }
  39567. });
  39568. Object.defineProperty(exports, "parseStream", {
  39569. enumerable: true,
  39570. get: function get() {
  39571. return parse_1.parseStream;
  39572. }
  39573. });
  39574. Object.defineProperty(exports, "parseFile", {
  39575. enumerable: true,
  39576. get: function get() {
  39577. return parse_1.parseFile;
  39578. }
  39579. });
  39580. Object.defineProperty(exports, "ParserOptions", {
  39581. enumerable: true,
  39582. get: function get() {
  39583. return parse_1.ParserOptions;
  39584. }
  39585. });
  39586. Object.defineProperty(exports, "CsvParserStream", {
  39587. enumerable: true,
  39588. get: function get() {
  39589. return parse_1.CsvParserStream;
  39590. }
  39591. });
  39592. },{"@fast-csv/format":148,"@fast-csv/parse":152}],370:[function(require,module,exports){
  39593. 'use strict';
  39594. var Buffer = require('safe-buffer').Buffer;
  39595. var Transform = require('readable-stream').Transform;
  39596. var inherits = require('inherits');
  39597. function throwIfNotStringOrBuffer(val, prefix) {
  39598. if (!Buffer.isBuffer(val) && typeof val !== 'string') {
  39599. throw new TypeError(prefix + ' must be a string or a buffer');
  39600. }
  39601. }
  39602. function HashBase(blockSize) {
  39603. Transform.call(this);
  39604. this._block = Buffer.allocUnsafe(blockSize);
  39605. this._blockSize = blockSize;
  39606. this._blockOffset = 0;
  39607. this._length = [0, 0, 0, 0];
  39608. this._finalized = false;
  39609. }
  39610. inherits(HashBase, Transform);
  39611. HashBase.prototype._transform = function (chunk, encoding, callback) {
  39612. var error = null;
  39613. try {
  39614. this.update(chunk, encoding);
  39615. } catch (err) {
  39616. error = err;
  39617. }
  39618. callback(error);
  39619. };
  39620. HashBase.prototype._flush = function (callback) {
  39621. var error = null;
  39622. try {
  39623. this.push(this.digest());
  39624. } catch (err) {
  39625. error = err;
  39626. }
  39627. callback(error);
  39628. };
  39629. HashBase.prototype.update = function (data, encoding) {
  39630. throwIfNotStringOrBuffer(data, 'Data');
  39631. if (this._finalized) throw new Error('Digest already called');
  39632. if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding); // consume data
  39633. var block = this._block;
  39634. var offset = 0;
  39635. while (this._blockOffset + data.length - offset >= this._blockSize) {
  39636. for (var i = this._blockOffset; i < this._blockSize;) {
  39637. block[i++] = data[offset++];
  39638. }
  39639. this._update();
  39640. this._blockOffset = 0;
  39641. }
  39642. while (offset < data.length) {
  39643. block[this._blockOffset++] = data[offset++];
  39644. } // update length
  39645. for (var j = 0, carry = data.length * 8; carry > 0; ++j) {
  39646. this._length[j] += carry;
  39647. carry = this._length[j] / 0x0100000000 | 0;
  39648. if (carry > 0) this._length[j] -= 0x0100000000 * carry;
  39649. }
  39650. return this;
  39651. };
  39652. HashBase.prototype._update = function () {
  39653. throw new Error('_update is not implemented');
  39654. };
  39655. HashBase.prototype.digest = function (encoding) {
  39656. if (this._finalized) throw new Error('Digest already called');
  39657. this._finalized = true;
  39658. var digest = this._digest();
  39659. if (encoding !== undefined) digest = digest.toString(encoding); // reset state
  39660. this._block.fill(0);
  39661. this._blockOffset = 0;
  39662. for (var i = 0; i < 4; ++i) {
  39663. this._length[i] = 0;
  39664. }
  39665. return digest;
  39666. };
  39667. HashBase.prototype._digest = function () {
  39668. throw new Error('_digest is not implemented');
  39669. };
  39670. module.exports = HashBase;
  39671. },{"inherits":387,"readable-stream":491,"safe-buffer":371}],371:[function(require,module,exports){
  39672. arguments[4][214][0].apply(exports,arguments)
  39673. },{"buffer":216,"dup":214}],372:[function(require,module,exports){
  39674. "use strict";
  39675. var hash = exports;
  39676. hash.utils = require('./hash/utils');
  39677. hash.common = require('./hash/common');
  39678. hash.sha = require('./hash/sha');
  39679. hash.ripemd = require('./hash/ripemd');
  39680. hash.hmac = require('./hash/hmac'); // Proxy hash functions to the main object
  39681. hash.sha1 = hash.sha.sha1;
  39682. hash.sha256 = hash.sha.sha256;
  39683. hash.sha224 = hash.sha.sha224;
  39684. hash.sha384 = hash.sha.sha384;
  39685. hash.sha512 = hash.sha.sha512;
  39686. hash.ripemd160 = hash.ripemd.ripemd160;
  39687. },{"./hash/common":373,"./hash/hmac":374,"./hash/ripemd":375,"./hash/sha":376,"./hash/utils":383}],373:[function(require,module,exports){
  39688. 'use strict';
  39689. var utils = require('./utils');
  39690. var assert = require('minimalistic-assert');
  39691. function BlockHash() {
  39692. this.pending = null;
  39693. this.pendingTotal = 0;
  39694. this.blockSize = this.constructor.blockSize;
  39695. this.outSize = this.constructor.outSize;
  39696. this.hmacStrength = this.constructor.hmacStrength;
  39697. this.padLength = this.constructor.padLength / 8;
  39698. this.endian = 'big';
  39699. this._delta8 = this.blockSize / 8;
  39700. this._delta32 = this.blockSize / 32;
  39701. }
  39702. exports.BlockHash = BlockHash;
  39703. BlockHash.prototype.update = function update(msg, enc) {
  39704. // Convert message to array, pad it, and join into 32bit blocks
  39705. msg = utils.toArray(msg, enc);
  39706. if (!this.pending) this.pending = msg;else this.pending = this.pending.concat(msg);
  39707. this.pendingTotal += msg.length; // Enough data, try updating
  39708. if (this.pending.length >= this._delta8) {
  39709. msg = this.pending; // Process pending data in blocks
  39710. var r = msg.length % this._delta8;
  39711. this.pending = msg.slice(msg.length - r, msg.length);
  39712. if (this.pending.length === 0) this.pending = null;
  39713. msg = utils.join32(msg, 0, msg.length - r, this.endian);
  39714. for (var i = 0; i < msg.length; i += this._delta32) {
  39715. this._update(msg, i, i + this._delta32);
  39716. }
  39717. }
  39718. return this;
  39719. };
  39720. BlockHash.prototype.digest = function digest(enc) {
  39721. this.update(this._pad());
  39722. assert(this.pending === null);
  39723. return this._digest(enc);
  39724. };
  39725. BlockHash.prototype._pad = function pad() {
  39726. var len = this.pendingTotal;
  39727. var bytes = this._delta8;
  39728. var k = bytes - (len + this.padLength) % bytes;
  39729. var res = new Array(k + this.padLength);
  39730. res[0] = 0x80;
  39731. for (var i = 1; i < k; i++) {
  39732. res[i] = 0;
  39733. } // Append length
  39734. len <<= 3;
  39735. if (this.endian === 'big') {
  39736. for (var t = 8; t < this.padLength; t++) {
  39737. res[i++] = 0;
  39738. }
  39739. res[i++] = 0;
  39740. res[i++] = 0;
  39741. res[i++] = 0;
  39742. res[i++] = 0;
  39743. res[i++] = len >>> 24 & 0xff;
  39744. res[i++] = len >>> 16 & 0xff;
  39745. res[i++] = len >>> 8 & 0xff;
  39746. res[i++] = len & 0xff;
  39747. } else {
  39748. res[i++] = len & 0xff;
  39749. res[i++] = len >>> 8 & 0xff;
  39750. res[i++] = len >>> 16 & 0xff;
  39751. res[i++] = len >>> 24 & 0xff;
  39752. res[i++] = 0;
  39753. res[i++] = 0;
  39754. res[i++] = 0;
  39755. res[i++] = 0;
  39756. for (t = 8; t < this.padLength; t++) {
  39757. res[i++] = 0;
  39758. }
  39759. }
  39760. return res;
  39761. };
  39762. },{"./utils":383,"minimalistic-assert":437}],374:[function(require,module,exports){
  39763. 'use strict';
  39764. var utils = require('./utils');
  39765. var assert = require('minimalistic-assert');
  39766. function Hmac(hash, key, enc) {
  39767. if (!(this instanceof Hmac)) return new Hmac(hash, key, enc);
  39768. this.Hash = hash;
  39769. this.blockSize = hash.blockSize / 8;
  39770. this.outSize = hash.outSize / 8;
  39771. this.inner = null;
  39772. this.outer = null;
  39773. this._init(utils.toArray(key, enc));
  39774. }
  39775. module.exports = Hmac;
  39776. Hmac.prototype._init = function init(key) {
  39777. // Shorten key, if needed
  39778. if (key.length > this.blockSize) key = new this.Hash().update(key).digest();
  39779. assert(key.length <= this.blockSize); // Add padding to key
  39780. for (var i = key.length; i < this.blockSize; i++) {
  39781. key.push(0);
  39782. }
  39783. for (i = 0; i < key.length; i++) {
  39784. key[i] ^= 0x36;
  39785. }
  39786. this.inner = new this.Hash().update(key); // 0x36 ^ 0x5c = 0x6a
  39787. for (i = 0; i < key.length; i++) {
  39788. key[i] ^= 0x6a;
  39789. }
  39790. this.outer = new this.Hash().update(key);
  39791. };
  39792. Hmac.prototype.update = function update(msg, enc) {
  39793. this.inner.update(msg, enc);
  39794. return this;
  39795. };
  39796. Hmac.prototype.digest = function digest(enc) {
  39797. this.outer.update(this.inner.digest());
  39798. return this.outer.digest(enc);
  39799. };
  39800. },{"./utils":383,"minimalistic-assert":437}],375:[function(require,module,exports){
  39801. 'use strict';
  39802. var utils = require('./utils');
  39803. var common = require('./common');
  39804. var rotl32 = utils.rotl32;
  39805. var sum32 = utils.sum32;
  39806. var sum32_3 = utils.sum32_3;
  39807. var sum32_4 = utils.sum32_4;
  39808. var BlockHash = common.BlockHash;
  39809. function RIPEMD160() {
  39810. if (!(this instanceof RIPEMD160)) return new RIPEMD160();
  39811. BlockHash.call(this);
  39812. this.h = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
  39813. this.endian = 'little';
  39814. }
  39815. utils.inherits(RIPEMD160, BlockHash);
  39816. exports.ripemd160 = RIPEMD160;
  39817. RIPEMD160.blockSize = 512;
  39818. RIPEMD160.outSize = 160;
  39819. RIPEMD160.hmacStrength = 192;
  39820. RIPEMD160.padLength = 64;
  39821. RIPEMD160.prototype._update = function update(msg, start) {
  39822. var A = this.h[0];
  39823. var B = this.h[1];
  39824. var C = this.h[2];
  39825. var D = this.h[3];
  39826. var E = this.h[4];
  39827. var Ah = A;
  39828. var Bh = B;
  39829. var Ch = C;
  39830. var Dh = D;
  39831. var Eh = E;
  39832. for (var j = 0; j < 80; j++) {
  39833. var T = sum32(rotl32(sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)), s[j]), E);
  39834. A = E;
  39835. E = D;
  39836. D = rotl32(C, 10);
  39837. C = B;
  39838. B = T;
  39839. T = sum32(rotl32(sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)), sh[j]), Eh);
  39840. Ah = Eh;
  39841. Eh = Dh;
  39842. Dh = rotl32(Ch, 10);
  39843. Ch = Bh;
  39844. Bh = T;
  39845. }
  39846. T = sum32_3(this.h[1], C, Dh);
  39847. this.h[1] = sum32_3(this.h[2], D, Eh);
  39848. this.h[2] = sum32_3(this.h[3], E, Ah);
  39849. this.h[3] = sum32_3(this.h[4], A, Bh);
  39850. this.h[4] = sum32_3(this.h[0], B, Ch);
  39851. this.h[0] = T;
  39852. };
  39853. RIPEMD160.prototype._digest = function digest(enc) {
  39854. if (enc === 'hex') return utils.toHex32(this.h, 'little');else return utils.split32(this.h, 'little');
  39855. };
  39856. function f(j, x, y, z) {
  39857. 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);
  39858. }
  39859. function K(j) {
  39860. 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;
  39861. }
  39862. function Kh(j) {
  39863. 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;
  39864. }
  39865. 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];
  39866. 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];
  39867. 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];
  39868. 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];
  39869. },{"./common":373,"./utils":383}],376:[function(require,module,exports){
  39870. 'use strict';
  39871. exports.sha1 = require('./sha/1');
  39872. exports.sha224 = require('./sha/224');
  39873. exports.sha256 = require('./sha/256');
  39874. exports.sha384 = require('./sha/384');
  39875. exports.sha512 = require('./sha/512');
  39876. },{"./sha/1":377,"./sha/224":378,"./sha/256":379,"./sha/384":380,"./sha/512":381}],377:[function(require,module,exports){
  39877. 'use strict';
  39878. var utils = require('../utils');
  39879. var common = require('../common');
  39880. var shaCommon = require('./common');
  39881. var rotl32 = utils.rotl32;
  39882. var sum32 = utils.sum32;
  39883. var sum32_5 = utils.sum32_5;
  39884. var ft_1 = shaCommon.ft_1;
  39885. var BlockHash = common.BlockHash;
  39886. var sha1_K = [0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6];
  39887. function SHA1() {
  39888. if (!(this instanceof SHA1)) return new SHA1();
  39889. BlockHash.call(this);
  39890. this.h = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
  39891. this.W = new Array(80);
  39892. }
  39893. utils.inherits(SHA1, BlockHash);
  39894. module.exports = SHA1;
  39895. SHA1.blockSize = 512;
  39896. SHA1.outSize = 160;
  39897. SHA1.hmacStrength = 80;
  39898. SHA1.padLength = 64;
  39899. SHA1.prototype._update = function _update(msg, start) {
  39900. var W = this.W;
  39901. for (var i = 0; i < 16; i++) {
  39902. W[i] = msg[start + i];
  39903. }
  39904. for (; i < W.length; i++) {
  39905. W[i] = rotl32(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
  39906. }
  39907. var a = this.h[0];
  39908. var b = this.h[1];
  39909. var c = this.h[2];
  39910. var d = this.h[3];
  39911. var e = this.h[4];
  39912. for (i = 0; i < W.length; i++) {
  39913. var s = ~~(i / 20);
  39914. var t = sum32_5(rotl32(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]);
  39915. e = d;
  39916. d = c;
  39917. c = rotl32(b, 30);
  39918. b = a;
  39919. a = t;
  39920. }
  39921. this.h[0] = sum32(this.h[0], a);
  39922. this.h[1] = sum32(this.h[1], b);
  39923. this.h[2] = sum32(this.h[2], c);
  39924. this.h[3] = sum32(this.h[3], d);
  39925. this.h[4] = sum32(this.h[4], e);
  39926. };
  39927. SHA1.prototype._digest = function digest(enc) {
  39928. if (enc === 'hex') return utils.toHex32(this.h, 'big');else return utils.split32(this.h, 'big');
  39929. };
  39930. },{"../common":373,"../utils":383,"./common":382}],378:[function(require,module,exports){
  39931. 'use strict';
  39932. var utils = require('../utils');
  39933. var SHA256 = require('./256');
  39934. function SHA224() {
  39935. if (!(this instanceof SHA224)) return new SHA224();
  39936. SHA256.call(this);
  39937. this.h = [0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4];
  39938. }
  39939. utils.inherits(SHA224, SHA256);
  39940. module.exports = SHA224;
  39941. SHA224.blockSize = 512;
  39942. SHA224.outSize = 224;
  39943. SHA224.hmacStrength = 192;
  39944. SHA224.padLength = 64;
  39945. SHA224.prototype._digest = function digest(enc) {
  39946. // Just truncate output
  39947. if (enc === 'hex') return utils.toHex32(this.h.slice(0, 7), 'big');else return utils.split32(this.h.slice(0, 7), 'big');
  39948. };
  39949. },{"../utils":383,"./256":379}],379:[function(require,module,exports){
  39950. 'use strict';
  39951. var utils = require('../utils');
  39952. var common = require('../common');
  39953. var shaCommon = require('./common');
  39954. var assert = require('minimalistic-assert');
  39955. var sum32 = utils.sum32;
  39956. var sum32_4 = utils.sum32_4;
  39957. var sum32_5 = utils.sum32_5;
  39958. var ch32 = shaCommon.ch32;
  39959. var maj32 = shaCommon.maj32;
  39960. var s0_256 = shaCommon.s0_256;
  39961. var s1_256 = shaCommon.s1_256;
  39962. var g0_256 = shaCommon.g0_256;
  39963. var g1_256 = shaCommon.g1_256;
  39964. var BlockHash = common.BlockHash;
  39965. 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];
  39966. function SHA256() {
  39967. if (!(this instanceof SHA256)) return new SHA256();
  39968. BlockHash.call(this);
  39969. this.h = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];
  39970. this.k = sha256_K;
  39971. this.W = new Array(64);
  39972. }
  39973. utils.inherits(SHA256, BlockHash);
  39974. module.exports = SHA256;
  39975. SHA256.blockSize = 512;
  39976. SHA256.outSize = 256;
  39977. SHA256.hmacStrength = 192;
  39978. SHA256.padLength = 64;
  39979. SHA256.prototype._update = function _update(msg, start) {
  39980. var W = this.W;
  39981. for (var i = 0; i < 16; i++) {
  39982. W[i] = msg[start + i];
  39983. }
  39984. for (; i < W.length; i++) {
  39985. W[i] = sum32_4(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]);
  39986. }
  39987. var a = this.h[0];
  39988. var b = this.h[1];
  39989. var c = this.h[2];
  39990. var d = this.h[3];
  39991. var e = this.h[4];
  39992. var f = this.h[5];
  39993. var g = this.h[6];
  39994. var h = this.h[7];
  39995. assert(this.k.length === W.length);
  39996. for (i = 0; i < W.length; i++) {
  39997. var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]);
  39998. var T2 = sum32(s0_256(a), maj32(a, b, c));
  39999. h = g;
  40000. g = f;
  40001. f = e;
  40002. e = sum32(d, T1);
  40003. d = c;
  40004. c = b;
  40005. b = a;
  40006. a = sum32(T1, T2);
  40007. }
  40008. this.h[0] = sum32(this.h[0], a);
  40009. this.h[1] = sum32(this.h[1], b);
  40010. this.h[2] = sum32(this.h[2], c);
  40011. this.h[3] = sum32(this.h[3], d);
  40012. this.h[4] = sum32(this.h[4], e);
  40013. this.h[5] = sum32(this.h[5], f);
  40014. this.h[6] = sum32(this.h[6], g);
  40015. this.h[7] = sum32(this.h[7], h);
  40016. };
  40017. SHA256.prototype._digest = function digest(enc) {
  40018. if (enc === 'hex') return utils.toHex32(this.h, 'big');else return utils.split32(this.h, 'big');
  40019. };
  40020. },{"../common":373,"../utils":383,"./common":382,"minimalistic-assert":437}],380:[function(require,module,exports){
  40021. 'use strict';
  40022. var utils = require('../utils');
  40023. var SHA512 = require('./512');
  40024. function SHA384() {
  40025. if (!(this instanceof SHA384)) return new SHA384();
  40026. SHA512.call(this);
  40027. this.h = [0xcbbb9d5d, 0xc1059ed8, 0x629a292a, 0x367cd507, 0x9159015a, 0x3070dd17, 0x152fecd8, 0xf70e5939, 0x67332667, 0xffc00b31, 0x8eb44a87, 0x68581511, 0xdb0c2e0d, 0x64f98fa7, 0x47b5481d, 0xbefa4fa4];
  40028. }
  40029. utils.inherits(SHA384, SHA512);
  40030. module.exports = SHA384;
  40031. SHA384.blockSize = 1024;
  40032. SHA384.outSize = 384;
  40033. SHA384.hmacStrength = 192;
  40034. SHA384.padLength = 128;
  40035. SHA384.prototype._digest = function digest(enc) {
  40036. if (enc === 'hex') return utils.toHex32(this.h.slice(0, 12), 'big');else return utils.split32(this.h.slice(0, 12), 'big');
  40037. };
  40038. },{"../utils":383,"./512":381}],381:[function(require,module,exports){
  40039. 'use strict';
  40040. var utils = require('../utils');
  40041. var common = require('../common');
  40042. var assert = require('minimalistic-assert');
  40043. var rotr64_hi = utils.rotr64_hi;
  40044. var rotr64_lo = utils.rotr64_lo;
  40045. var shr64_hi = utils.shr64_hi;
  40046. var shr64_lo = utils.shr64_lo;
  40047. var sum64 = utils.sum64;
  40048. var sum64_hi = utils.sum64_hi;
  40049. var sum64_lo = utils.sum64_lo;
  40050. var sum64_4_hi = utils.sum64_4_hi;
  40051. var sum64_4_lo = utils.sum64_4_lo;
  40052. var sum64_5_hi = utils.sum64_5_hi;
  40053. var sum64_5_lo = utils.sum64_5_lo;
  40054. var BlockHash = common.BlockHash;
  40055. 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];
  40056. function SHA512() {
  40057. if (!(this instanceof SHA512)) return new SHA512();
  40058. BlockHash.call(this);
  40059. this.h = [0x6a09e667, 0xf3bcc908, 0xbb67ae85, 0x84caa73b, 0x3c6ef372, 0xfe94f82b, 0xa54ff53a, 0x5f1d36f1, 0x510e527f, 0xade682d1, 0x9b05688c, 0x2b3e6c1f, 0x1f83d9ab, 0xfb41bd6b, 0x5be0cd19, 0x137e2179];
  40060. this.k = sha512_K;
  40061. this.W = new Array(160);
  40062. }
  40063. utils.inherits(SHA512, BlockHash);
  40064. module.exports = SHA512;
  40065. SHA512.blockSize = 1024;
  40066. SHA512.outSize = 512;
  40067. SHA512.hmacStrength = 192;
  40068. SHA512.padLength = 128;
  40069. SHA512.prototype._prepareBlock = function _prepareBlock(msg, start) {
  40070. var W = this.W; // 32 x 32bit words
  40071. for (var i = 0; i < 32; i++) {
  40072. W[i] = msg[start + i];
  40073. }
  40074. for (; i < W.length; i += 2) {
  40075. var c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 2
  40076. var c0_lo = g1_512_lo(W[i - 4], W[i - 3]);
  40077. var c1_hi = W[i - 14]; // i - 7
  40078. var c1_lo = W[i - 13];
  40079. var c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 15
  40080. var c2_lo = g0_512_lo(W[i - 30], W[i - 29]);
  40081. var c3_hi = W[i - 32]; // i - 16
  40082. var c3_lo = W[i - 31];
  40083. W[i] = sum64_4_hi(c0_hi, c0_lo, c1_hi, c1_lo, c2_hi, c2_lo, c3_hi, c3_lo);
  40084. W[i + 1] = sum64_4_lo(c0_hi, c0_lo, c1_hi, c1_lo, c2_hi, c2_lo, c3_hi, c3_lo);
  40085. }
  40086. };
  40087. SHA512.prototype._update = function _update(msg, start) {
  40088. this._prepareBlock(msg, start);
  40089. var W = this.W;
  40090. var ah = this.h[0];
  40091. var al = this.h[1];
  40092. var bh = this.h[2];
  40093. var bl = this.h[3];
  40094. var ch = this.h[4];
  40095. var cl = this.h[5];
  40096. var dh = this.h[6];
  40097. var dl = this.h[7];
  40098. var eh = this.h[8];
  40099. var el = this.h[9];
  40100. var fh = this.h[10];
  40101. var fl = this.h[11];
  40102. var gh = this.h[12];
  40103. var gl = this.h[13];
  40104. var hh = this.h[14];
  40105. var hl = this.h[15];
  40106. assert(this.k.length === W.length);
  40107. for (var i = 0; i < W.length; i += 2) {
  40108. var c0_hi = hh;
  40109. var c0_lo = hl;
  40110. var c1_hi = s1_512_hi(eh, el);
  40111. var c1_lo = s1_512_lo(eh, el);
  40112. var c2_hi = ch64_hi(eh, el, fh, fl, gh, gl);
  40113. var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl);
  40114. var c3_hi = this.k[i];
  40115. var c3_lo = this.k[i + 1];
  40116. var c4_hi = W[i];
  40117. var c4_lo = W[i + 1];
  40118. 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);
  40119. 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);
  40120. c0_hi = s0_512_hi(ah, al);
  40121. c0_lo = s0_512_lo(ah, al);
  40122. c1_hi = maj64_hi(ah, al, bh, bl, ch, cl);
  40123. c1_lo = maj64_lo(ah, al, bh, bl, ch, cl);
  40124. var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo);
  40125. var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo);
  40126. hh = gh;
  40127. hl = gl;
  40128. gh = fh;
  40129. gl = fl;
  40130. fh = eh;
  40131. fl = el;
  40132. eh = sum64_hi(dh, dl, T1_hi, T1_lo);
  40133. el = sum64_lo(dl, dl, T1_hi, T1_lo);
  40134. dh = ch;
  40135. dl = cl;
  40136. ch = bh;
  40137. cl = bl;
  40138. bh = ah;
  40139. bl = al;
  40140. ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo);
  40141. al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo);
  40142. }
  40143. sum64(this.h, 0, ah, al);
  40144. sum64(this.h, 2, bh, bl);
  40145. sum64(this.h, 4, ch, cl);
  40146. sum64(this.h, 6, dh, dl);
  40147. sum64(this.h, 8, eh, el);
  40148. sum64(this.h, 10, fh, fl);
  40149. sum64(this.h, 12, gh, gl);
  40150. sum64(this.h, 14, hh, hl);
  40151. };
  40152. SHA512.prototype._digest = function digest(enc) {
  40153. if (enc === 'hex') return utils.toHex32(this.h, 'big');else return utils.split32(this.h, 'big');
  40154. };
  40155. function ch64_hi(xh, xl, yh, yl, zh) {
  40156. var r = xh & yh ^ ~xh & zh;
  40157. if (r < 0) r += 0x100000000;
  40158. return r;
  40159. }
  40160. function ch64_lo(xh, xl, yh, yl, zh, zl) {
  40161. var r = xl & yl ^ ~xl & zl;
  40162. if (r < 0) r += 0x100000000;
  40163. return r;
  40164. }
  40165. function maj64_hi(xh, xl, yh, yl, zh) {
  40166. var r = xh & yh ^ xh & zh ^ yh & zh;
  40167. if (r < 0) r += 0x100000000;
  40168. return r;
  40169. }
  40170. function maj64_lo(xh, xl, yh, yl, zh, zl) {
  40171. var r = xl & yl ^ xl & zl ^ yl & zl;
  40172. if (r < 0) r += 0x100000000;
  40173. return r;
  40174. }
  40175. function s0_512_hi(xh, xl) {
  40176. var c0_hi = rotr64_hi(xh, xl, 28);
  40177. var c1_hi = rotr64_hi(xl, xh, 2); // 34
  40178. var c2_hi = rotr64_hi(xl, xh, 7); // 39
  40179. var r = c0_hi ^ c1_hi ^ c2_hi;
  40180. if (r < 0) r += 0x100000000;
  40181. return r;
  40182. }
  40183. function s0_512_lo(xh, xl) {
  40184. var c0_lo = rotr64_lo(xh, xl, 28);
  40185. var c1_lo = rotr64_lo(xl, xh, 2); // 34
  40186. var c2_lo = rotr64_lo(xl, xh, 7); // 39
  40187. var r = c0_lo ^ c1_lo ^ c2_lo;
  40188. if (r < 0) r += 0x100000000;
  40189. return r;
  40190. }
  40191. function s1_512_hi(xh, xl) {
  40192. var c0_hi = rotr64_hi(xh, xl, 14);
  40193. var c1_hi = rotr64_hi(xh, xl, 18);
  40194. var c2_hi = rotr64_hi(xl, xh, 9); // 41
  40195. var r = c0_hi ^ c1_hi ^ c2_hi;
  40196. if (r < 0) r += 0x100000000;
  40197. return r;
  40198. }
  40199. function s1_512_lo(xh, xl) {
  40200. var c0_lo = rotr64_lo(xh, xl, 14);
  40201. var c1_lo = rotr64_lo(xh, xl, 18);
  40202. var c2_lo = rotr64_lo(xl, xh, 9); // 41
  40203. var r = c0_lo ^ c1_lo ^ c2_lo;
  40204. if (r < 0) r += 0x100000000;
  40205. return r;
  40206. }
  40207. function g0_512_hi(xh, xl) {
  40208. var c0_hi = rotr64_hi(xh, xl, 1);
  40209. var c1_hi = rotr64_hi(xh, xl, 8);
  40210. var c2_hi = shr64_hi(xh, xl, 7);
  40211. var r = c0_hi ^ c1_hi ^ c2_hi;
  40212. if (r < 0) r += 0x100000000;
  40213. return r;
  40214. }
  40215. function g0_512_lo(xh, xl) {
  40216. var c0_lo = rotr64_lo(xh, xl, 1);
  40217. var c1_lo = rotr64_lo(xh, xl, 8);
  40218. var c2_lo = shr64_lo(xh, xl, 7);
  40219. var r = c0_lo ^ c1_lo ^ c2_lo;
  40220. if (r < 0) r += 0x100000000;
  40221. return r;
  40222. }
  40223. function g1_512_hi(xh, xl) {
  40224. var c0_hi = rotr64_hi(xh, xl, 19);
  40225. var c1_hi = rotr64_hi(xl, xh, 29); // 61
  40226. var c2_hi = shr64_hi(xh, xl, 6);
  40227. var r = c0_hi ^ c1_hi ^ c2_hi;
  40228. if (r < 0) r += 0x100000000;
  40229. return r;
  40230. }
  40231. function g1_512_lo(xh, xl) {
  40232. var c0_lo = rotr64_lo(xh, xl, 19);
  40233. var c1_lo = rotr64_lo(xl, xh, 29); // 61
  40234. var c2_lo = shr64_lo(xh, xl, 6);
  40235. var r = c0_lo ^ c1_lo ^ c2_lo;
  40236. if (r < 0) r += 0x100000000;
  40237. return r;
  40238. }
  40239. },{"../common":373,"../utils":383,"minimalistic-assert":437}],382:[function(require,module,exports){
  40240. 'use strict';
  40241. var utils = require('../utils');
  40242. var rotr32 = utils.rotr32;
  40243. function ft_1(s, x, y, z) {
  40244. if (s === 0) return ch32(x, y, z);
  40245. if (s === 1 || s === 3) return p32(x, y, z);
  40246. if (s === 2) return maj32(x, y, z);
  40247. }
  40248. exports.ft_1 = ft_1;
  40249. function ch32(x, y, z) {
  40250. return x & y ^ ~x & z;
  40251. }
  40252. exports.ch32 = ch32;
  40253. function maj32(x, y, z) {
  40254. return x & y ^ x & z ^ y & z;
  40255. }
  40256. exports.maj32 = maj32;
  40257. function p32(x, y, z) {
  40258. return x ^ y ^ z;
  40259. }
  40260. exports.p32 = p32;
  40261. function s0_256(x) {
  40262. return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
  40263. }
  40264. exports.s0_256 = s0_256;
  40265. function s1_256(x) {
  40266. return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
  40267. }
  40268. exports.s1_256 = s1_256;
  40269. function g0_256(x) {
  40270. return rotr32(x, 7) ^ rotr32(x, 18) ^ x >>> 3;
  40271. }
  40272. exports.g0_256 = g0_256;
  40273. function g1_256(x) {
  40274. return rotr32(x, 17) ^ rotr32(x, 19) ^ x >>> 10;
  40275. }
  40276. exports.g1_256 = g1_256;
  40277. },{"../utils":383}],383:[function(require,module,exports){
  40278. 'use strict';
  40279. var assert = require('minimalistic-assert');
  40280. var inherits = require('inherits');
  40281. exports.inherits = inherits;
  40282. function isSurrogatePair(msg, i) {
  40283. if ((msg.charCodeAt(i) & 0xFC00) !== 0xD800) {
  40284. return false;
  40285. }
  40286. if (i < 0 || i + 1 >= msg.length) {
  40287. return false;
  40288. }
  40289. return (msg.charCodeAt(i + 1) & 0xFC00) === 0xDC00;
  40290. }
  40291. function toArray(msg, enc) {
  40292. if (Array.isArray(msg)) return msg.slice();
  40293. if (!msg) return [];
  40294. var res = [];
  40295. if (typeof msg === 'string') {
  40296. if (!enc) {
  40297. // Inspired by stringToUtf8ByteArray() in closure-library by Google
  40298. // https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143
  40299. // Apache License 2.0
  40300. // https://github.com/google/closure-library/blob/master/LICENSE
  40301. var p = 0;
  40302. for (var i = 0; i < msg.length; i++) {
  40303. var c = msg.charCodeAt(i);
  40304. if (c < 128) {
  40305. res[p++] = c;
  40306. } else if (c < 2048) {
  40307. res[p++] = c >> 6 | 192;
  40308. res[p++] = c & 63 | 128;
  40309. } else if (isSurrogatePair(msg, i)) {
  40310. c = 0x10000 + ((c & 0x03FF) << 10) + (msg.charCodeAt(++i) & 0x03FF);
  40311. res[p++] = c >> 18 | 240;
  40312. res[p++] = c >> 12 & 63 | 128;
  40313. res[p++] = c >> 6 & 63 | 128;
  40314. res[p++] = c & 63 | 128;
  40315. } else {
  40316. res[p++] = c >> 12 | 224;
  40317. res[p++] = c >> 6 & 63 | 128;
  40318. res[p++] = c & 63 | 128;
  40319. }
  40320. }
  40321. } else if (enc === 'hex') {
  40322. msg = msg.replace(/[^a-z0-9]+/ig, '');
  40323. if (msg.length % 2 !== 0) msg = '0' + msg;
  40324. for (i = 0; i < msg.length; i += 2) {
  40325. res.push(parseInt(msg[i] + msg[i + 1], 16));
  40326. }
  40327. }
  40328. } else {
  40329. for (i = 0; i < msg.length; i++) {
  40330. res[i] = msg[i] | 0;
  40331. }
  40332. }
  40333. return res;
  40334. }
  40335. exports.toArray = toArray;
  40336. function toHex(msg) {
  40337. var res = '';
  40338. for (var i = 0; i < msg.length; i++) {
  40339. res += zero2(msg[i].toString(16));
  40340. }
  40341. return res;
  40342. }
  40343. exports.toHex = toHex;
  40344. function htonl(w) {
  40345. var res = w >>> 24 | w >>> 8 & 0xff00 | w << 8 & 0xff0000 | (w & 0xff) << 24;
  40346. return res >>> 0;
  40347. }
  40348. exports.htonl = htonl;
  40349. function toHex32(msg, endian) {
  40350. var res = '';
  40351. for (var i = 0; i < msg.length; i++) {
  40352. var w = msg[i];
  40353. if (endian === 'little') w = htonl(w);
  40354. res += zero8(w.toString(16));
  40355. }
  40356. return res;
  40357. }
  40358. exports.toHex32 = toHex32;
  40359. function zero2(word) {
  40360. if (word.length === 1) return '0' + word;else return word;
  40361. }
  40362. exports.zero2 = zero2;
  40363. function zero8(word) {
  40364. 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;
  40365. }
  40366. exports.zero8 = zero8;
  40367. function join32(msg, start, end, endian) {
  40368. var len = end - start;
  40369. assert(len % 4 === 0);
  40370. var res = new Array(len / 4);
  40371. for (var i = 0, k = start; i < res.length; i++, k += 4) {
  40372. var w;
  40373. 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];
  40374. res[i] = w >>> 0;
  40375. }
  40376. return res;
  40377. }
  40378. exports.join32 = join32;
  40379. function split32(msg, endian) {
  40380. var res = new Array(msg.length * 4);
  40381. for (var i = 0, k = 0; i < msg.length; i++, k += 4) {
  40382. var m = msg[i];
  40383. if (endian === 'big') {
  40384. res[k] = m >>> 24;
  40385. res[k + 1] = m >>> 16 & 0xff;
  40386. res[k + 2] = m >>> 8 & 0xff;
  40387. res[k + 3] = m & 0xff;
  40388. } else {
  40389. res[k + 3] = m >>> 24;
  40390. res[k + 2] = m >>> 16 & 0xff;
  40391. res[k + 1] = m >>> 8 & 0xff;
  40392. res[k] = m & 0xff;
  40393. }
  40394. }
  40395. return res;
  40396. }
  40397. exports.split32 = split32;
  40398. function rotr32(w, b) {
  40399. return w >>> b | w << 32 - b;
  40400. }
  40401. exports.rotr32 = rotr32;
  40402. function rotl32(w, b) {
  40403. return w << b | w >>> 32 - b;
  40404. }
  40405. exports.rotl32 = rotl32;
  40406. function sum32(a, b) {
  40407. return a + b >>> 0;
  40408. }
  40409. exports.sum32 = sum32;
  40410. function sum32_3(a, b, c) {
  40411. return a + b + c >>> 0;
  40412. }
  40413. exports.sum32_3 = sum32_3;
  40414. function sum32_4(a, b, c, d) {
  40415. return a + b + c + d >>> 0;
  40416. }
  40417. exports.sum32_4 = sum32_4;
  40418. function sum32_5(a, b, c, d, e) {
  40419. return a + b + c + d + e >>> 0;
  40420. }
  40421. exports.sum32_5 = sum32_5;
  40422. function sum64(buf, pos, ah, al) {
  40423. var bh = buf[pos];
  40424. var bl = buf[pos + 1];
  40425. var lo = al + bl >>> 0;
  40426. var hi = (lo < al ? 1 : 0) + ah + bh;
  40427. buf[pos] = hi >>> 0;
  40428. buf[pos + 1] = lo;
  40429. }
  40430. exports.sum64 = sum64;
  40431. function sum64_hi(ah, al, bh, bl) {
  40432. var lo = al + bl >>> 0;
  40433. var hi = (lo < al ? 1 : 0) + ah + bh;
  40434. return hi >>> 0;
  40435. }
  40436. exports.sum64_hi = sum64_hi;
  40437. function sum64_lo(ah, al, bh, bl) {
  40438. var lo = al + bl;
  40439. return lo >>> 0;
  40440. }
  40441. exports.sum64_lo = sum64_lo;
  40442. function sum64_4_hi(ah, al, bh, bl, ch, cl, dh, dl) {
  40443. var carry = 0;
  40444. var lo = al;
  40445. lo = lo + bl >>> 0;
  40446. carry += lo < al ? 1 : 0;
  40447. lo = lo + cl >>> 0;
  40448. carry += lo < cl ? 1 : 0;
  40449. lo = lo + dl >>> 0;
  40450. carry += lo < dl ? 1 : 0;
  40451. var hi = ah + bh + ch + dh + carry;
  40452. return hi >>> 0;
  40453. }
  40454. exports.sum64_4_hi = sum64_4_hi;
  40455. function sum64_4_lo(ah, al, bh, bl, ch, cl, dh, dl) {
  40456. var lo = al + bl + cl + dl;
  40457. return lo >>> 0;
  40458. }
  40459. exports.sum64_4_lo = sum64_4_lo;
  40460. function sum64_5_hi(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
  40461. var carry = 0;
  40462. var lo = al;
  40463. lo = lo + bl >>> 0;
  40464. carry += lo < al ? 1 : 0;
  40465. lo = lo + cl >>> 0;
  40466. carry += lo < cl ? 1 : 0;
  40467. lo = lo + dl >>> 0;
  40468. carry += lo < dl ? 1 : 0;
  40469. lo = lo + el >>> 0;
  40470. carry += lo < el ? 1 : 0;
  40471. var hi = ah + bh + ch + dh + eh + carry;
  40472. return hi >>> 0;
  40473. }
  40474. exports.sum64_5_hi = sum64_5_hi;
  40475. function sum64_5_lo(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
  40476. var lo = al + bl + cl + dl + el;
  40477. return lo >>> 0;
  40478. }
  40479. exports.sum64_5_lo = sum64_5_lo;
  40480. function rotr64_hi(ah, al, num) {
  40481. var r = al << 32 - num | ah >>> num;
  40482. return r >>> 0;
  40483. }
  40484. exports.rotr64_hi = rotr64_hi;
  40485. function rotr64_lo(ah, al, num) {
  40486. var r = ah << 32 - num | al >>> num;
  40487. return r >>> 0;
  40488. }
  40489. exports.rotr64_lo = rotr64_lo;
  40490. function shr64_hi(ah, al, num) {
  40491. return ah >>> num;
  40492. }
  40493. exports.shr64_hi = shr64_hi;
  40494. function shr64_lo(ah, al, num) {
  40495. var r = ah << 32 - num | al >>> num;
  40496. return r >>> 0;
  40497. }
  40498. exports.shr64_lo = shr64_lo;
  40499. },{"inherits":387,"minimalistic-assert":437}],384:[function(require,module,exports){
  40500. 'use strict';
  40501. var hash = require('hash.js');
  40502. var utils = require('minimalistic-crypto-utils');
  40503. var assert = require('minimalistic-assert');
  40504. function HmacDRBG(options) {
  40505. if (!(this instanceof HmacDRBG)) return new HmacDRBG(options);
  40506. this.hash = options.hash;
  40507. this.predResist = !!options.predResist;
  40508. this.outLen = this.hash.outSize;
  40509. this.minEntropy = options.minEntropy || this.hash.hmacStrength;
  40510. this._reseed = null;
  40511. this.reseedInterval = null;
  40512. this.K = null;
  40513. this.V = null;
  40514. var entropy = utils.toArray(options.entropy, options.entropyEnc || 'hex');
  40515. var nonce = utils.toArray(options.nonce, options.nonceEnc || 'hex');
  40516. var pers = utils.toArray(options.pers, options.persEnc || 'hex');
  40517. assert(entropy.length >= this.minEntropy / 8, 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
  40518. this._init(entropy, nonce, pers);
  40519. }
  40520. module.exports = HmacDRBG;
  40521. HmacDRBG.prototype._init = function init(entropy, nonce, pers) {
  40522. var seed = entropy.concat(nonce).concat(pers);
  40523. this.K = new Array(this.outLen / 8);
  40524. this.V = new Array(this.outLen / 8);
  40525. for (var i = 0; i < this.V.length; i++) {
  40526. this.K[i] = 0x00;
  40527. this.V[i] = 0x01;
  40528. }
  40529. this._update(seed);
  40530. this._reseed = 1;
  40531. this.reseedInterval = 0x1000000000000; // 2^48
  40532. };
  40533. HmacDRBG.prototype._hmac = function hmac() {
  40534. return new hash.hmac(this.hash, this.K);
  40535. };
  40536. HmacDRBG.prototype._update = function update(seed) {
  40537. var kmac = this._hmac().update(this.V).update([0x00]);
  40538. if (seed) kmac = kmac.update(seed);
  40539. this.K = kmac.digest();
  40540. this.V = this._hmac().update(this.V).digest();
  40541. if (!seed) return;
  40542. this.K = this._hmac().update(this.V).update([0x01]).update(seed).digest();
  40543. this.V = this._hmac().update(this.V).digest();
  40544. };
  40545. HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc) {
  40546. // Optional entropy enc
  40547. if (typeof entropyEnc !== 'string') {
  40548. addEnc = add;
  40549. add = entropyEnc;
  40550. entropyEnc = null;
  40551. }
  40552. entropy = utils.toArray(entropy, entropyEnc);
  40553. add = utils.toArray(add, addEnc);
  40554. assert(entropy.length >= this.minEntropy / 8, 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
  40555. this._update(entropy.concat(add || []));
  40556. this._reseed = 1;
  40557. };
  40558. HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) {
  40559. if (this._reseed > this.reseedInterval) throw new Error('Reseed is required'); // Optional encoding
  40560. if (typeof enc !== 'string') {
  40561. addEnc = add;
  40562. add = enc;
  40563. enc = null;
  40564. } // Optional additional data
  40565. if (add) {
  40566. add = utils.toArray(add, addEnc || 'hex');
  40567. this._update(add);
  40568. }
  40569. var temp = [];
  40570. while (temp.length < len) {
  40571. this.V = this._hmac().update(this.V).digest();
  40572. temp = temp.concat(this.V);
  40573. }
  40574. var res = temp.slice(0, len);
  40575. this._update(add);
  40576. this._reseed++;
  40577. return utils.encode(res, enc);
  40578. };
  40579. },{"hash.js":372,"minimalistic-assert":437,"minimalistic-crypto-utils":438}],385:[function(require,module,exports){
  40580. "use strict";
  40581. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  40582. var e, m;
  40583. var eLen = nBytes * 8 - mLen - 1;
  40584. var eMax = (1 << eLen) - 1;
  40585. var eBias = eMax >> 1;
  40586. var nBits = -7;
  40587. var i = isLE ? nBytes - 1 : 0;
  40588. var d = isLE ? -1 : 1;
  40589. var s = buffer[offset + i];
  40590. i += d;
  40591. e = s & (1 << -nBits) - 1;
  40592. s >>= -nBits;
  40593. nBits += eLen;
  40594. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  40595. m = e & (1 << -nBits) - 1;
  40596. e >>= -nBits;
  40597. nBits += mLen;
  40598. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  40599. if (e === 0) {
  40600. e = 1 - eBias;
  40601. } else if (e === eMax) {
  40602. return m ? NaN : (s ? -1 : 1) * Infinity;
  40603. } else {
  40604. m = m + Math.pow(2, mLen);
  40605. e = e - eBias;
  40606. }
  40607. return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
  40608. };
  40609. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  40610. var e, m, c;
  40611. var eLen = nBytes * 8 - mLen - 1;
  40612. var eMax = (1 << eLen) - 1;
  40613. var eBias = eMax >> 1;
  40614. var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
  40615. var i = isLE ? 0 : nBytes - 1;
  40616. var d = isLE ? 1 : -1;
  40617. var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
  40618. value = Math.abs(value);
  40619. if (isNaN(value) || value === Infinity) {
  40620. m = isNaN(value) ? 1 : 0;
  40621. e = eMax;
  40622. } else {
  40623. e = Math.floor(Math.log(value) / Math.LN2);
  40624. if (value * (c = Math.pow(2, -e)) < 1) {
  40625. e--;
  40626. c *= 2;
  40627. }
  40628. if (e + eBias >= 1) {
  40629. value += rt / c;
  40630. } else {
  40631. value += rt * Math.pow(2, 1 - eBias);
  40632. }
  40633. if (value * c >= 2) {
  40634. e++;
  40635. c /= 2;
  40636. }
  40637. if (e + eBias >= eMax) {
  40638. m = 0;
  40639. e = eMax;
  40640. } else if (e + eBias >= 1) {
  40641. m = (value * c - 1) * Math.pow(2, mLen);
  40642. e = e + eBias;
  40643. } else {
  40644. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  40645. e = 0;
  40646. }
  40647. }
  40648. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  40649. e = e << mLen | m;
  40650. eLen += mLen;
  40651. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  40652. buffer[offset + i - d] |= s * 128;
  40653. };
  40654. },{}],386:[function(require,module,exports){
  40655. (function (global){
  40656. 'use strict';
  40657. var Mutation = global.MutationObserver || global.WebKitMutationObserver;
  40658. var scheduleDrain;
  40659. {
  40660. if (Mutation) {
  40661. var called = 0;
  40662. var observer = new Mutation(nextTick);
  40663. var element = global.document.createTextNode('');
  40664. observer.observe(element, {
  40665. characterData: true
  40666. });
  40667. scheduleDrain = function scheduleDrain() {
  40668. element.data = called = ++called % 2;
  40669. };
  40670. } else if (!global.setImmediate && typeof global.MessageChannel !== 'undefined') {
  40671. var channel = new global.MessageChannel();
  40672. channel.port1.onmessage = nextTick;
  40673. scheduleDrain = function scheduleDrain() {
  40674. channel.port2.postMessage(0);
  40675. };
  40676. } else if ('document' in global && 'onreadystatechange' in global.document.createElement('script')) {
  40677. scheduleDrain = function scheduleDrain() {
  40678. // Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
  40679. // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
  40680. var scriptEl = global.document.createElement('script');
  40681. scriptEl.onreadystatechange = function () {
  40682. nextTick();
  40683. scriptEl.onreadystatechange = null;
  40684. scriptEl.parentNode.removeChild(scriptEl);
  40685. scriptEl = null;
  40686. };
  40687. global.document.documentElement.appendChild(scriptEl);
  40688. };
  40689. } else {
  40690. scheduleDrain = function scheduleDrain() {
  40691. setTimeout(nextTick, 0);
  40692. };
  40693. }
  40694. }
  40695. var draining;
  40696. var queue = []; //named nextTick for less confusing stack traces
  40697. function nextTick() {
  40698. draining = true;
  40699. var i, oldQueue;
  40700. var len = queue.length;
  40701. while (len) {
  40702. oldQueue = queue;
  40703. queue = [];
  40704. i = -1;
  40705. while (++i < len) {
  40706. oldQueue[i]();
  40707. }
  40708. len = queue.length;
  40709. }
  40710. draining = false;
  40711. }
  40712. module.exports = immediate;
  40713. function immediate(task) {
  40714. if (queue.push(task) === 1 && !draining) {
  40715. scheduleDrain();
  40716. }
  40717. }
  40718. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  40719. },{}],387:[function(require,module,exports){
  40720. "use strict";
  40721. if (typeof Object.create === 'function') {
  40722. // implementation from standard node.js 'util' module
  40723. module.exports = function inherits(ctor, superCtor) {
  40724. if (superCtor) {
  40725. ctor.super_ = superCtor;
  40726. ctor.prototype = Object.create(superCtor.prototype, {
  40727. constructor: {
  40728. value: ctor,
  40729. enumerable: false,
  40730. writable: true,
  40731. configurable: true
  40732. }
  40733. });
  40734. }
  40735. };
  40736. } else {
  40737. // old school shim for old browsers
  40738. module.exports = function inherits(ctor, superCtor) {
  40739. if (superCtor) {
  40740. ctor.super_ = superCtor;
  40741. var TempCtor = function TempCtor() {};
  40742. TempCtor.prototype = superCtor.prototype;
  40743. ctor.prototype = new TempCtor();
  40744. ctor.prototype.constructor = ctor;
  40745. }
  40746. };
  40747. }
  40748. },{}],388:[function(require,module,exports){
  40749. "use strict";
  40750. /*!
  40751. * Determine if an object is a Buffer
  40752. *
  40753. * @author Feross Aboukhadijeh <https://feross.org>
  40754. * @license MIT
  40755. */
  40756. // The _isBuffer check is for Safari 5-7 support, because it's missing
  40757. // Object.prototype.constructor. Remove this eventually
  40758. module.exports = function (obj) {
  40759. return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer);
  40760. };
  40761. function isBuffer(obj) {
  40762. return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj);
  40763. } // For Node v0.10 support. Remove this eventually.
  40764. function isSlowBuffer(obj) {
  40765. return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0));
  40766. }
  40767. },{}],389:[function(require,module,exports){
  40768. "use strict";
  40769. var toString = {}.toString;
  40770. module.exports = Array.isArray || function (arr) {
  40771. return toString.call(arr) == '[object Array]';
  40772. };
  40773. },{}],390:[function(require,module,exports){
  40774. 'use strict';
  40775. var utils = require('./utils');
  40776. var support = require('./support'); // private property
  40777. var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; // public method for encoding
  40778. exports.encode = function (input) {
  40779. var output = [];
  40780. var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
  40781. var i = 0,
  40782. len = input.length,
  40783. remainingBytes = len;
  40784. var isArray = utils.getTypeOf(input) !== "string";
  40785. while (i < input.length) {
  40786. remainingBytes = len - i;
  40787. if (!isArray) {
  40788. chr1 = input.charCodeAt(i++);
  40789. chr2 = i < len ? input.charCodeAt(i++) : 0;
  40790. chr3 = i < len ? input.charCodeAt(i++) : 0;
  40791. } else {
  40792. chr1 = input[i++];
  40793. chr2 = i < len ? input[i++] : 0;
  40794. chr3 = i < len ? input[i++] : 0;
  40795. }
  40796. enc1 = chr1 >> 2;
  40797. enc2 = (chr1 & 3) << 4 | chr2 >> 4;
  40798. enc3 = remainingBytes > 1 ? (chr2 & 15) << 2 | chr3 >> 6 : 64;
  40799. enc4 = remainingBytes > 2 ? chr3 & 63 : 64;
  40800. output.push(_keyStr.charAt(enc1) + _keyStr.charAt(enc2) + _keyStr.charAt(enc3) + _keyStr.charAt(enc4));
  40801. }
  40802. return output.join("");
  40803. }; // public method for decoding
  40804. exports.decode = function (input) {
  40805. var chr1, chr2, chr3;
  40806. var enc1, enc2, enc3, enc4;
  40807. var i = 0,
  40808. resultIndex = 0;
  40809. var dataUrlPrefix = "data:";
  40810. if (input.substr(0, dataUrlPrefix.length) === dataUrlPrefix) {
  40811. // This is a common error: people give a data url
  40812. // (data:image/png;base64,iVBOR...) with a {base64: true} and
  40813. // wonders why things don't work.
  40814. // We can detect that the string input looks like a data url but we
  40815. // *can't* be sure it is one: removing everything up to the comma would
  40816. // be too dangerous.
  40817. throw new Error("Invalid base64 input, it looks like a data url.");
  40818. }
  40819. input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
  40820. var totalLength = input.length * 3 / 4;
  40821. if (input.charAt(input.length - 1) === _keyStr.charAt(64)) {
  40822. totalLength--;
  40823. }
  40824. if (input.charAt(input.length - 2) === _keyStr.charAt(64)) {
  40825. totalLength--;
  40826. }
  40827. if (totalLength % 1 !== 0) {
  40828. // totalLength is not an integer, the length does not match a valid
  40829. // base64 content. That can happen if:
  40830. // - the input is not a base64 content
  40831. // - the input is *almost* a base64 content, with a extra chars at the
  40832. // beginning or at the end
  40833. // - the input uses a base64 variant (base64url for example)
  40834. throw new Error("Invalid base64 input, bad content length.");
  40835. }
  40836. var output;
  40837. if (support.uint8array) {
  40838. output = new Uint8Array(totalLength | 0);
  40839. } else {
  40840. output = new Array(totalLength | 0);
  40841. }
  40842. while (i < input.length) {
  40843. enc1 = _keyStr.indexOf(input.charAt(i++));
  40844. enc2 = _keyStr.indexOf(input.charAt(i++));
  40845. enc3 = _keyStr.indexOf(input.charAt(i++));
  40846. enc4 = _keyStr.indexOf(input.charAt(i++));
  40847. chr1 = enc1 << 2 | enc2 >> 4;
  40848. chr2 = (enc2 & 15) << 4 | enc3 >> 2;
  40849. chr3 = (enc3 & 3) << 6 | enc4;
  40850. output[resultIndex++] = chr1;
  40851. if (enc3 !== 64) {
  40852. output[resultIndex++] = chr2;
  40853. }
  40854. if (enc4 !== 64) {
  40855. output[resultIndex++] = chr3;
  40856. }
  40857. }
  40858. return output;
  40859. };
  40860. },{"./support":419,"./utils":421}],391:[function(require,module,exports){
  40861. 'use strict';
  40862. var external = require("./external");
  40863. var DataWorker = require('./stream/DataWorker');
  40864. var DataLengthProbe = require('./stream/DataLengthProbe');
  40865. var Crc32Probe = require('./stream/Crc32Probe');
  40866. var DataLengthProbe = require('./stream/DataLengthProbe');
  40867. /**
  40868. * Represent a compressed object, with everything needed to decompress it.
  40869. * @constructor
  40870. * @param {number} compressedSize the size of the data compressed.
  40871. * @param {number} uncompressedSize the size of the data after decompression.
  40872. * @param {number} crc32 the crc32 of the decompressed file.
  40873. * @param {object} compression the type of compression, see lib/compressions.js.
  40874. * @param {String|ArrayBuffer|Uint8Array|Buffer} data the compressed data.
  40875. */
  40876. function CompressedObject(compressedSize, uncompressedSize, crc32, compression, data) {
  40877. this.compressedSize = compressedSize;
  40878. this.uncompressedSize = uncompressedSize;
  40879. this.crc32 = crc32;
  40880. this.compression = compression;
  40881. this.compressedContent = data;
  40882. }
  40883. CompressedObject.prototype = {
  40884. /**
  40885. * Create a worker to get the uncompressed content.
  40886. * @return {GenericWorker} the worker.
  40887. */
  40888. getContentWorker: function getContentWorker() {
  40889. var worker = new DataWorker(external.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new DataLengthProbe("data_length"));
  40890. var that = this;
  40891. worker.on("end", function () {
  40892. if (this.streamInfo['data_length'] !== that.uncompressedSize) {
  40893. throw new Error("Bug : uncompressed data size mismatch");
  40894. }
  40895. });
  40896. return worker;
  40897. },
  40898. /**
  40899. * Create a worker to get the compressed content.
  40900. * @return {GenericWorker} the worker.
  40901. */
  40902. getCompressedWorker: function getCompressedWorker() {
  40903. return new DataWorker(external.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize", this.compressedSize).withStreamInfo("uncompressedSize", this.uncompressedSize).withStreamInfo("crc32", this.crc32).withStreamInfo("compression", this.compression);
  40904. }
  40905. };
  40906. /**
  40907. * Chain the given worker with other workers to compress the content with the
  40908. * given compression.
  40909. * @param {GenericWorker} uncompressedWorker the worker to pipe.
  40910. * @param {Object} compression the compression object.
  40911. * @param {Object} compressionOptions the options to use when compressing.
  40912. * @return {GenericWorker} the new worker compressing the content.
  40913. */
  40914. CompressedObject.createWorkerFrom = function (uncompressedWorker, compression, compressionOptions) {
  40915. return uncompressedWorker.pipe(new Crc32Probe()).pipe(new DataLengthProbe("uncompressedSize")).pipe(compression.compressWorker(compressionOptions)).pipe(new DataLengthProbe("compressedSize")).withStreamInfo("compression", compression);
  40916. };
  40917. module.exports = CompressedObject;
  40918. },{"./external":395,"./stream/Crc32Probe":414,"./stream/DataLengthProbe":415,"./stream/DataWorker":416}],392:[function(require,module,exports){
  40919. 'use strict';
  40920. var GenericWorker = require("./stream/GenericWorker");
  40921. exports.STORE = {
  40922. magic: "\x00\x00",
  40923. compressWorker: function compressWorker(compressionOptions) {
  40924. return new GenericWorker("STORE compression");
  40925. },
  40926. uncompressWorker: function uncompressWorker() {
  40927. return new GenericWorker("STORE decompression");
  40928. }
  40929. };
  40930. exports.DEFLATE = require('./flate');
  40931. },{"./flate":396,"./stream/GenericWorker":417}],393:[function(require,module,exports){
  40932. 'use strict';
  40933. var utils = require('./utils');
  40934. /**
  40935. * The following functions come from pako, from pako/lib/zlib/crc32.js
  40936. * released under the MIT license, see pako https://github.com/nodeca/pako/
  40937. */
  40938. // Use ordinary array, since untyped makes no boost here
  40939. function makeTable() {
  40940. var c,
  40941. table = [];
  40942. for (var n = 0; n < 256; n++) {
  40943. c = n;
  40944. for (var k = 0; k < 8; k++) {
  40945. c = c & 1 ? 0xEDB88320 ^ c >>> 1 : c >>> 1;
  40946. }
  40947. table[n] = c;
  40948. }
  40949. return table;
  40950. } // Create table on load. Just 255 signed longs. Not a problem.
  40951. var crcTable = makeTable();
  40952. function crc32(crc, buf, len, pos) {
  40953. var t = crcTable,
  40954. end = pos + len;
  40955. crc = crc ^ -1;
  40956. for (var i = pos; i < end; i++) {
  40957. crc = crc >>> 8 ^ t[(crc ^ buf[i]) & 0xFF];
  40958. }
  40959. return crc ^ -1; // >>> 0;
  40960. } // That's all for the pako functions.
  40961. /**
  40962. * Compute the crc32 of a string.
  40963. * This is almost the same as the function crc32, but for strings. Using the
  40964. * same function for the two use cases leads to horrible performances.
  40965. * @param {Number} crc the starting value of the crc.
  40966. * @param {String} str the string to use.
  40967. * @param {Number} len the length of the string.
  40968. * @param {Number} pos the starting position for the crc32 computation.
  40969. * @return {Number} the computed crc32.
  40970. */
  40971. function crc32str(crc, str, len, pos) {
  40972. var t = crcTable,
  40973. end = pos + len;
  40974. crc = crc ^ -1;
  40975. for (var i = pos; i < end; i++) {
  40976. crc = crc >>> 8 ^ t[(crc ^ str.charCodeAt(i)) & 0xFF];
  40977. }
  40978. return crc ^ -1; // >>> 0;
  40979. }
  40980. module.exports = function crc32wrapper(input, crc) {
  40981. if (typeof input === "undefined" || !input.length) {
  40982. return 0;
  40983. }
  40984. var isArray = utils.getTypeOf(input) !== "string";
  40985. if (isArray) {
  40986. return crc32(crc | 0, input, input.length, 0);
  40987. } else {
  40988. return crc32str(crc | 0, input, input.length, 0);
  40989. }
  40990. };
  40991. },{"./utils":421}],394:[function(require,module,exports){
  40992. 'use strict';
  40993. exports.base64 = false;
  40994. exports.binary = false;
  40995. exports.dir = false;
  40996. exports.createFolders = true;
  40997. exports.date = null;
  40998. exports.compression = null;
  40999. exports.compressionOptions = null;
  41000. exports.comment = null;
  41001. exports.unixPermissions = null;
  41002. exports.dosPermissions = null;
  41003. },{}],395:[function(require,module,exports){
  41004. /* global Promise */
  41005. 'use strict'; // load the global object first:
  41006. // - it should be better integrated in the system (unhandledRejection in node)
  41007. // - the environment may have a custom Promise implementation (see zone.js)
  41008. var ES6Promise = null;
  41009. if (typeof Promise !== "undefined") {
  41010. ES6Promise = Promise;
  41011. } else {
  41012. ES6Promise = require("lie");
  41013. }
  41014. /**
  41015. * Let the user use/change some implementations.
  41016. */
  41017. module.exports = {
  41018. Promise: ES6Promise
  41019. };
  41020. },{"lie":425}],396:[function(require,module,exports){
  41021. 'use strict';
  41022. var USE_TYPEDARRAY = typeof Uint8Array !== 'undefined' && typeof Uint16Array !== 'undefined' && typeof Uint32Array !== 'undefined';
  41023. var pako = require("pako");
  41024. var utils = require("./utils");
  41025. var GenericWorker = require("./stream/GenericWorker");
  41026. var ARRAY_TYPE = USE_TYPEDARRAY ? "uint8array" : "array";
  41027. exports.magic = "\x08\x00";
  41028. /**
  41029. * Create a worker that uses pako to inflate/deflate.
  41030. * @constructor
  41031. * @param {String} action the name of the pako function to call : either "Deflate" or "Inflate".
  41032. * @param {Object} options the options to use when (de)compressing.
  41033. */
  41034. function FlateWorker(action, options) {
  41035. GenericWorker.call(this, "FlateWorker/" + action);
  41036. this._pako = null;
  41037. this._pakoAction = action;
  41038. this._pakoOptions = options; // the `meta` object from the last chunk received
  41039. // this allow this worker to pass around metadata
  41040. this.meta = {};
  41041. }
  41042. utils.inherits(FlateWorker, GenericWorker);
  41043. /**
  41044. * @see GenericWorker.processChunk
  41045. */
  41046. FlateWorker.prototype.processChunk = function (chunk) {
  41047. this.meta = chunk.meta;
  41048. if (this._pako === null) {
  41049. this._createPako();
  41050. }
  41051. this._pako.push(utils.transformTo(ARRAY_TYPE, chunk.data), false);
  41052. };
  41053. /**
  41054. * @see GenericWorker.flush
  41055. */
  41056. FlateWorker.prototype.flush = function () {
  41057. GenericWorker.prototype.flush.call(this);
  41058. if (this._pako === null) {
  41059. this._createPako();
  41060. }
  41061. this._pako.push([], true);
  41062. };
  41063. /**
  41064. * @see GenericWorker.cleanUp
  41065. */
  41066. FlateWorker.prototype.cleanUp = function () {
  41067. GenericWorker.prototype.cleanUp.call(this);
  41068. this._pako = null;
  41069. };
  41070. /**
  41071. * Create the _pako object.
  41072. * TODO: lazy-loading this object isn't the best solution but it's the
  41073. * quickest. The best solution is to lazy-load the worker list. See also the
  41074. * issue #446.
  41075. */
  41076. FlateWorker.prototype._createPako = function () {
  41077. this._pako = new pako[this._pakoAction]({
  41078. raw: true,
  41079. level: this._pakoOptions.level || -1 // default compression
  41080. });
  41081. var self = this;
  41082. this._pako.onData = function (data) {
  41083. self.push({
  41084. data: data,
  41085. meta: self.meta
  41086. });
  41087. };
  41088. };
  41089. exports.compressWorker = function (compressionOptions) {
  41090. return new FlateWorker("Deflate", compressionOptions);
  41091. };
  41092. exports.uncompressWorker = function () {
  41093. return new FlateWorker("Inflate", {});
  41094. };
  41095. },{"./stream/GenericWorker":417,"./utils":421,"pako":439}],397:[function(require,module,exports){
  41096. 'use strict';
  41097. var utils = require('../utils');
  41098. var GenericWorker = require('../stream/GenericWorker');
  41099. var utf8 = require('../utf8');
  41100. var crc32 = require('../crc32');
  41101. var signature = require('../signature');
  41102. /**
  41103. * Transform an integer into a string in hexadecimal.
  41104. * @private
  41105. * @param {number} dec the number to convert.
  41106. * @param {number} bytes the number of bytes to generate.
  41107. * @returns {string} the result.
  41108. */
  41109. var decToHex = function decToHex(dec, bytes) {
  41110. var hex = "",
  41111. i;
  41112. for (i = 0; i < bytes; i++) {
  41113. hex += String.fromCharCode(dec & 0xff);
  41114. dec = dec >>> 8;
  41115. }
  41116. return hex;
  41117. };
  41118. /**
  41119. * Generate the UNIX part of the external file attributes.
  41120. * @param {Object} unixPermissions the unix permissions or null.
  41121. * @param {Boolean} isDir true if the entry is a directory, false otherwise.
  41122. * @return {Number} a 32 bit integer.
  41123. *
  41124. * adapted from http://unix.stackexchange.com/questions/14705/the-zip-formats-external-file-attribute :
  41125. *
  41126. * TTTTsstrwxrwxrwx0000000000ADVSHR
  41127. * ^^^^____________________________ file type, see zipinfo.c (UNX_*)
  41128. * ^^^_________________________ setuid, setgid, sticky
  41129. * ^^^^^^^^^________________ permissions
  41130. * ^^^^^^^^^^______ not used ?
  41131. * ^^^^^^ DOS attribute bits : Archive, Directory, Volume label, System file, Hidden, Read only
  41132. */
  41133. var generateUnixExternalFileAttr = function generateUnixExternalFileAttr(unixPermissions, isDir) {
  41134. var result = unixPermissions;
  41135. if (!unixPermissions) {
  41136. // I can't use octal values in strict mode, hence the hexa.
  41137. // 040775 => 0x41fd
  41138. // 0100664 => 0x81b4
  41139. result = isDir ? 0x41fd : 0x81b4;
  41140. }
  41141. return (result & 0xFFFF) << 16;
  41142. };
  41143. /**
  41144. * Generate the DOS part of the external file attributes.
  41145. * @param {Object} dosPermissions the dos permissions or null.
  41146. * @param {Boolean} isDir true if the entry is a directory, false otherwise.
  41147. * @return {Number} a 32 bit integer.
  41148. *
  41149. * Bit 0 Read-Only
  41150. * Bit 1 Hidden
  41151. * Bit 2 System
  41152. * Bit 3 Volume Label
  41153. * Bit 4 Directory
  41154. * Bit 5 Archive
  41155. */
  41156. var generateDosExternalFileAttr = function generateDosExternalFileAttr(dosPermissions, isDir) {
  41157. // the dir flag is already set for compatibility
  41158. return (dosPermissions || 0) & 0x3F;
  41159. };
  41160. /**
  41161. * Generate the various parts used in the construction of the final zip file.
  41162. * @param {Object} streamInfo the hash with information about the compressed file.
  41163. * @param {Boolean} streamedContent is the content streamed ?
  41164. * @param {Boolean} streamingEnded is the stream finished ?
  41165. * @param {number} offset the current offset from the start of the zip file.
  41166. * @param {String} platform let's pretend we are this platform (change platform dependents fields)
  41167. * @param {Function} encodeFileName the function to encode the file name / comment.
  41168. * @return {Object} the zip parts.
  41169. */
  41170. var generateZipParts = function generateZipParts(streamInfo, streamedContent, streamingEnded, offset, platform, encodeFileName) {
  41171. var file = streamInfo['file'],
  41172. compression = streamInfo['compression'],
  41173. useCustomEncoding = encodeFileName !== utf8.utf8encode,
  41174. encodedFileName = utils.transformTo("string", encodeFileName(file.name)),
  41175. utfEncodedFileName = utils.transformTo("string", utf8.utf8encode(file.name)),
  41176. comment = file.comment,
  41177. encodedComment = utils.transformTo("string", encodeFileName(comment)),
  41178. utfEncodedComment = utils.transformTo("string", utf8.utf8encode(comment)),
  41179. useUTF8ForFileName = utfEncodedFileName.length !== file.name.length,
  41180. useUTF8ForComment = utfEncodedComment.length !== comment.length,
  41181. dosTime,
  41182. dosDate,
  41183. extraFields = "",
  41184. unicodePathExtraField = "",
  41185. unicodeCommentExtraField = "",
  41186. dir = file.dir,
  41187. date = file.date;
  41188. var dataInfo = {
  41189. crc32: 0,
  41190. compressedSize: 0,
  41191. uncompressedSize: 0
  41192. }; // if the content is streamed, the sizes/crc32 are only available AFTER
  41193. // the end of the stream.
  41194. if (!streamedContent || streamingEnded) {
  41195. dataInfo.crc32 = streamInfo['crc32'];
  41196. dataInfo.compressedSize = streamInfo['compressedSize'];
  41197. dataInfo.uncompressedSize = streamInfo['uncompressedSize'];
  41198. }
  41199. var bitflag = 0;
  41200. if (streamedContent) {
  41201. // Bit 3: the sizes/crc32 are set to zero in the local header.
  41202. // The correct values are put in the data descriptor immediately
  41203. // following the compressed data.
  41204. bitflag |= 0x0008;
  41205. }
  41206. if (!useCustomEncoding && (useUTF8ForFileName || useUTF8ForComment)) {
  41207. // Bit 11: Language encoding flag (EFS).
  41208. bitflag |= 0x0800;
  41209. }
  41210. var extFileAttr = 0;
  41211. var versionMadeBy = 0;
  41212. if (dir) {
  41213. // dos or unix, we set the dos dir flag
  41214. extFileAttr |= 0x00010;
  41215. }
  41216. if (platform === "UNIX") {
  41217. versionMadeBy = 0x031E; // UNIX, version 3.0
  41218. extFileAttr |= generateUnixExternalFileAttr(file.unixPermissions, dir);
  41219. } else {
  41220. // DOS or other, fallback to DOS
  41221. versionMadeBy = 0x0014; // DOS, version 2.0
  41222. extFileAttr |= generateDosExternalFileAttr(file.dosPermissions, dir);
  41223. } // date
  41224. // @see http://www.delorie.com/djgpp/doc/rbinter/it/52/13.html
  41225. // @see http://www.delorie.com/djgpp/doc/rbinter/it/65/16.html
  41226. // @see http://www.delorie.com/djgpp/doc/rbinter/it/66/16.html
  41227. dosTime = date.getUTCHours();
  41228. dosTime = dosTime << 6;
  41229. dosTime = dosTime | date.getUTCMinutes();
  41230. dosTime = dosTime << 5;
  41231. dosTime = dosTime | date.getUTCSeconds() / 2;
  41232. dosDate = date.getUTCFullYear() - 1980;
  41233. dosDate = dosDate << 4;
  41234. dosDate = dosDate | date.getUTCMonth() + 1;
  41235. dosDate = dosDate << 5;
  41236. dosDate = dosDate | date.getUTCDate();
  41237. if (useUTF8ForFileName) {
  41238. // set the unicode path extra field. unzip needs at least one extra
  41239. // field to correctly handle unicode path, so using the path is as good
  41240. // as any other information. This could improve the situation with
  41241. // other archive managers too.
  41242. // This field is usually used without the utf8 flag, with a non
  41243. // unicode path in the header (winrar, winzip). This helps (a bit)
  41244. // with the messy Windows' default compressed folders feature but
  41245. // breaks on p7zip which doesn't seek the unicode path extra field.
  41246. // So for now, UTF-8 everywhere !
  41247. unicodePathExtraField = // Version
  41248. decToHex(1, 1) + // NameCRC32
  41249. decToHex(crc32(encodedFileName), 4) + // UnicodeName
  41250. utfEncodedFileName;
  41251. extraFields += // Info-ZIP Unicode Path Extra Field
  41252. "\x75\x70" + // size
  41253. decToHex(unicodePathExtraField.length, 2) + // content
  41254. unicodePathExtraField;
  41255. }
  41256. if (useUTF8ForComment) {
  41257. unicodeCommentExtraField = // Version
  41258. decToHex(1, 1) + // CommentCRC32
  41259. decToHex(crc32(encodedComment), 4) + // UnicodeName
  41260. utfEncodedComment;
  41261. extraFields += // Info-ZIP Unicode Path Extra Field
  41262. "\x75\x63" + // size
  41263. decToHex(unicodeCommentExtraField.length, 2) + // content
  41264. unicodeCommentExtraField;
  41265. }
  41266. var header = ""; // version needed to extract
  41267. header += "\x0A\x00"; // general purpose bit flag
  41268. header += decToHex(bitflag, 2); // compression method
  41269. header += compression.magic; // last mod file time
  41270. header += decToHex(dosTime, 2); // last mod file date
  41271. header += decToHex(dosDate, 2); // crc-32
  41272. header += decToHex(dataInfo.crc32, 4); // compressed size
  41273. header += decToHex(dataInfo.compressedSize, 4); // uncompressed size
  41274. header += decToHex(dataInfo.uncompressedSize, 4); // file name length
  41275. header += decToHex(encodedFileName.length, 2); // extra field length
  41276. header += decToHex(extraFields.length, 2);
  41277. var fileRecord = signature.LOCAL_FILE_HEADER + header + encodedFileName + extraFields;
  41278. var dirRecord = signature.CENTRAL_FILE_HEADER + // version made by (00: DOS)
  41279. decToHex(versionMadeBy, 2) + // file header (common to file and central directory)
  41280. header + // file comment length
  41281. decToHex(encodedComment.length, 2) + // disk number start
  41282. "\x00\x00" + // internal file attributes TODO
  41283. "\x00\x00" + // external file attributes
  41284. decToHex(extFileAttr, 4) + // relative offset of local header
  41285. decToHex(offset, 4) + // file name
  41286. encodedFileName + // extra field
  41287. extraFields + // file comment
  41288. encodedComment;
  41289. return {
  41290. fileRecord: fileRecord,
  41291. dirRecord: dirRecord
  41292. };
  41293. };
  41294. /**
  41295. * Generate the EOCD record.
  41296. * @param {Number} entriesCount the number of entries in the zip file.
  41297. * @param {Number} centralDirLength the length (in bytes) of the central dir.
  41298. * @param {Number} localDirLength the length (in bytes) of the local dir.
  41299. * @param {String} comment the zip file comment as a binary string.
  41300. * @param {Function} encodeFileName the function to encode the comment.
  41301. * @return {String} the EOCD record.
  41302. */
  41303. var generateCentralDirectoryEnd = function generateCentralDirectoryEnd(entriesCount, centralDirLength, localDirLength, comment, encodeFileName) {
  41304. var dirEnd = "";
  41305. var encodedComment = utils.transformTo("string", encodeFileName(comment)); // end of central dir signature
  41306. dirEnd = signature.CENTRAL_DIRECTORY_END + // number of this disk
  41307. "\x00\x00" + // number of the disk with the start of the central directory
  41308. "\x00\x00" + // total number of entries in the central directory on this disk
  41309. decToHex(entriesCount, 2) + // total number of entries in the central directory
  41310. decToHex(entriesCount, 2) + // size of the central directory 4 bytes
  41311. decToHex(centralDirLength, 4) + // offset of start of central directory with respect to the starting disk number
  41312. decToHex(localDirLength, 4) + // .ZIP file comment length
  41313. decToHex(encodedComment.length, 2) + // .ZIP file comment
  41314. encodedComment;
  41315. return dirEnd;
  41316. };
  41317. /**
  41318. * Generate data descriptors for a file entry.
  41319. * @param {Object} streamInfo the hash generated by a worker, containing information
  41320. * on the file entry.
  41321. * @return {String} the data descriptors.
  41322. */
  41323. var generateDataDescriptors = function generateDataDescriptors(streamInfo) {
  41324. var descriptor = "";
  41325. descriptor = signature.DATA_DESCRIPTOR + // crc-32 4 bytes
  41326. decToHex(streamInfo['crc32'], 4) + // compressed size 4 bytes
  41327. decToHex(streamInfo['compressedSize'], 4) + // uncompressed size 4 bytes
  41328. decToHex(streamInfo['uncompressedSize'], 4);
  41329. return descriptor;
  41330. };
  41331. /**
  41332. * A worker to concatenate other workers to create a zip file.
  41333. * @param {Boolean} streamFiles `true` to stream the content of the files,
  41334. * `false` to accumulate it.
  41335. * @param {String} comment the comment to use.
  41336. * @param {String} platform the platform to use, "UNIX" or "DOS".
  41337. * @param {Function} encodeFileName the function to encode file names and comments.
  41338. */
  41339. function ZipFileWorker(streamFiles, comment, platform, encodeFileName) {
  41340. GenericWorker.call(this, "ZipFileWorker"); // The number of bytes written so far. This doesn't count accumulated chunks.
  41341. this.bytesWritten = 0; // The comment of the zip file
  41342. this.zipComment = comment; // The platform "generating" the zip file.
  41343. this.zipPlatform = platform; // the function to encode file names and comments.
  41344. this.encodeFileName = encodeFileName; // Should we stream the content of the files ?
  41345. this.streamFiles = streamFiles; // If `streamFiles` is false, we will need to accumulate the content of the
  41346. // files to calculate sizes / crc32 (and write them *before* the content).
  41347. // This boolean indicates if we are accumulating chunks (it will change a lot
  41348. // during the lifetime of this worker).
  41349. this.accumulate = false; // The buffer receiving chunks when accumulating content.
  41350. this.contentBuffer = []; // The list of generated directory records.
  41351. this.dirRecords = []; // The offset (in bytes) from the beginning of the zip file for the current source.
  41352. this.currentSourceOffset = 0; // The total number of entries in this zip file.
  41353. this.entriesCount = 0; // the name of the file currently being added, null when handling the end of the zip file.
  41354. // Used for the emitted metadata.
  41355. this.currentFile = null;
  41356. this._sources = [];
  41357. }
  41358. utils.inherits(ZipFileWorker, GenericWorker);
  41359. /**
  41360. * @see GenericWorker.push
  41361. */
  41362. ZipFileWorker.prototype.push = function (chunk) {
  41363. var currentFilePercent = chunk.meta.percent || 0;
  41364. var entriesCount = this.entriesCount;
  41365. var remainingFiles = this._sources.length;
  41366. if (this.accumulate) {
  41367. this.contentBuffer.push(chunk);
  41368. } else {
  41369. this.bytesWritten += chunk.data.length;
  41370. GenericWorker.prototype.push.call(this, {
  41371. data: chunk.data,
  41372. meta: {
  41373. currentFile: this.currentFile,
  41374. percent: entriesCount ? (currentFilePercent + 100 * (entriesCount - remainingFiles - 1)) / entriesCount : 100
  41375. }
  41376. });
  41377. }
  41378. };
  41379. /**
  41380. * The worker started a new source (an other worker).
  41381. * @param {Object} streamInfo the streamInfo object from the new source.
  41382. */
  41383. ZipFileWorker.prototype.openedSource = function (streamInfo) {
  41384. this.currentSourceOffset = this.bytesWritten;
  41385. this.currentFile = streamInfo['file'].name;
  41386. var streamedContent = this.streamFiles && !streamInfo['file'].dir; // don't stream folders (because they don't have any content)
  41387. if (streamedContent) {
  41388. var record = generateZipParts(streamInfo, streamedContent, false, this.currentSourceOffset, this.zipPlatform, this.encodeFileName);
  41389. this.push({
  41390. data: record.fileRecord,
  41391. meta: {
  41392. percent: 0
  41393. }
  41394. });
  41395. } else {
  41396. // we need to wait for the whole file before pushing anything
  41397. this.accumulate = true;
  41398. }
  41399. };
  41400. /**
  41401. * The worker finished a source (an other worker).
  41402. * @param {Object} streamInfo the streamInfo object from the finished source.
  41403. */
  41404. ZipFileWorker.prototype.closedSource = function (streamInfo) {
  41405. this.accumulate = false;
  41406. var streamedContent = this.streamFiles && !streamInfo['file'].dir;
  41407. var record = generateZipParts(streamInfo, streamedContent, true, this.currentSourceOffset, this.zipPlatform, this.encodeFileName);
  41408. this.dirRecords.push(record.dirRecord);
  41409. if (streamedContent) {
  41410. // after the streamed file, we put data descriptors
  41411. this.push({
  41412. data: generateDataDescriptors(streamInfo),
  41413. meta: {
  41414. percent: 100
  41415. }
  41416. });
  41417. } else {
  41418. // the content wasn't streamed, we need to push everything now
  41419. // first the file record, then the content
  41420. this.push({
  41421. data: record.fileRecord,
  41422. meta: {
  41423. percent: 0
  41424. }
  41425. });
  41426. while (this.contentBuffer.length) {
  41427. this.push(this.contentBuffer.shift());
  41428. }
  41429. }
  41430. this.currentFile = null;
  41431. };
  41432. /**
  41433. * @see GenericWorker.flush
  41434. */
  41435. ZipFileWorker.prototype.flush = function () {
  41436. var localDirLength = this.bytesWritten;
  41437. for (var i = 0; i < this.dirRecords.length; i++) {
  41438. this.push({
  41439. data: this.dirRecords[i],
  41440. meta: {
  41441. percent: 100
  41442. }
  41443. });
  41444. }
  41445. var centralDirLength = this.bytesWritten - localDirLength;
  41446. var dirEnd = generateCentralDirectoryEnd(this.dirRecords.length, centralDirLength, localDirLength, this.zipComment, this.encodeFileName);
  41447. this.push({
  41448. data: dirEnd,
  41449. meta: {
  41450. percent: 100
  41451. }
  41452. });
  41453. };
  41454. /**
  41455. * Prepare the next source to be read.
  41456. */
  41457. ZipFileWorker.prototype.prepareNextSource = function () {
  41458. this.previous = this._sources.shift();
  41459. this.openedSource(this.previous.streamInfo);
  41460. if (this.isPaused) {
  41461. this.previous.pause();
  41462. } else {
  41463. this.previous.resume();
  41464. }
  41465. };
  41466. /**
  41467. * @see GenericWorker.registerPrevious
  41468. */
  41469. ZipFileWorker.prototype.registerPrevious = function (previous) {
  41470. this._sources.push(previous);
  41471. var self = this;
  41472. previous.on('data', function (chunk) {
  41473. self.processChunk(chunk);
  41474. });
  41475. previous.on('end', function () {
  41476. self.closedSource(self.previous.streamInfo);
  41477. if (self._sources.length) {
  41478. self.prepareNextSource();
  41479. } else {
  41480. self.end();
  41481. }
  41482. });
  41483. previous.on('error', function (e) {
  41484. self.error(e);
  41485. });
  41486. return this;
  41487. };
  41488. /**
  41489. * @see GenericWorker.resume
  41490. */
  41491. ZipFileWorker.prototype.resume = function () {
  41492. if (!GenericWorker.prototype.resume.call(this)) {
  41493. return false;
  41494. }
  41495. if (!this.previous && this._sources.length) {
  41496. this.prepareNextSource();
  41497. return true;
  41498. }
  41499. if (!this.previous && !this._sources.length && !this.generatedError) {
  41500. this.end();
  41501. return true;
  41502. }
  41503. };
  41504. /**
  41505. * @see GenericWorker.error
  41506. */
  41507. ZipFileWorker.prototype.error = function (e) {
  41508. var sources = this._sources;
  41509. if (!GenericWorker.prototype.error.call(this, e)) {
  41510. return false;
  41511. }
  41512. for (var i = 0; i < sources.length; i++) {
  41513. try {
  41514. sources[i].error(e);
  41515. } catch (e) {// the `error` exploded, nothing to do
  41516. }
  41517. }
  41518. return true;
  41519. };
  41520. /**
  41521. * @see GenericWorker.lock
  41522. */
  41523. ZipFileWorker.prototype.lock = function () {
  41524. GenericWorker.prototype.lock.call(this);
  41525. var sources = this._sources;
  41526. for (var i = 0; i < sources.length; i++) {
  41527. sources[i].lock();
  41528. }
  41529. };
  41530. module.exports = ZipFileWorker;
  41531. },{"../crc32":393,"../signature":412,"../stream/GenericWorker":417,"../utf8":420,"../utils":421}],398:[function(require,module,exports){
  41532. 'use strict';
  41533. var compressions = require('../compressions');
  41534. var ZipFileWorker = require('./ZipFileWorker');
  41535. /**
  41536. * Find the compression to use.
  41537. * @param {String} fileCompression the compression defined at the file level, if any.
  41538. * @param {String} zipCompression the compression defined at the load() level.
  41539. * @return {Object} the compression object to use.
  41540. */
  41541. var getCompression = function getCompression(fileCompression, zipCompression) {
  41542. var compressionName = fileCompression || zipCompression;
  41543. var compression = compressions[compressionName];
  41544. if (!compression) {
  41545. throw new Error(compressionName + " is not a valid compression method !");
  41546. }
  41547. return compression;
  41548. };
  41549. /**
  41550. * Create a worker to generate a zip file.
  41551. * @param {JSZip} zip the JSZip instance at the right root level.
  41552. * @param {Object} options to generate the zip file.
  41553. * @param {String} comment the comment to use.
  41554. */
  41555. exports.generateWorker = function (zip, options, comment) {
  41556. var zipFileWorker = new ZipFileWorker(options.streamFiles, comment, options.platform, options.encodeFileName);
  41557. var entriesCount = 0;
  41558. try {
  41559. zip.forEach(function (relativePath, file) {
  41560. entriesCount++;
  41561. var compression = getCompression(file.options.compression, options.compression);
  41562. var compressionOptions = file.options.compressionOptions || options.compressionOptions || {};
  41563. var dir = file.dir,
  41564. date = file.date;
  41565. file._compressWorker(compression, compressionOptions).withStreamInfo("file", {
  41566. name: relativePath,
  41567. dir: dir,
  41568. date: date,
  41569. comment: file.comment || "",
  41570. unixPermissions: file.unixPermissions,
  41571. dosPermissions: file.dosPermissions
  41572. }).pipe(zipFileWorker);
  41573. });
  41574. zipFileWorker.entriesCount = entriesCount;
  41575. } catch (e) {
  41576. zipFileWorker.error(e);
  41577. }
  41578. return zipFileWorker;
  41579. };
  41580. },{"../compressions":392,"./ZipFileWorker":397}],399:[function(require,module,exports){
  41581. 'use strict';
  41582. /**
  41583. * Representation a of zip file in js
  41584. * @constructor
  41585. */
  41586. function JSZip() {
  41587. // if this constructor is used without `new`, it adds `new` before itself:
  41588. if (!(this instanceof JSZip)) {
  41589. return new JSZip();
  41590. }
  41591. if (arguments.length) {
  41592. throw new Error("The constructor with parameters has been removed in JSZip 3.0, please check the upgrade guide.");
  41593. } // object containing the files :
  41594. // {
  41595. // "folder/" : {...},
  41596. // "folder/data.txt" : {...}
  41597. // }
  41598. this.files = {};
  41599. this.comment = null; // Where we are in the hierarchy
  41600. this.root = "";
  41601. this.clone = function () {
  41602. var newObj = new JSZip();
  41603. for (var i in this) {
  41604. if (typeof this[i] !== "function") {
  41605. newObj[i] = this[i];
  41606. }
  41607. }
  41608. return newObj;
  41609. };
  41610. }
  41611. JSZip.prototype = require('./object');
  41612. JSZip.prototype.loadAsync = require('./load');
  41613. JSZip.support = require('./support');
  41614. JSZip.defaults = require('./defaults'); // TODO find a better way to handle this version,
  41615. // a require('package.json').version doesn't work with webpack, see #327
  41616. JSZip.version = "3.5.0";
  41617. JSZip.loadAsync = function (content, options) {
  41618. return new JSZip().loadAsync(content, options);
  41619. };
  41620. JSZip.external = require("./external");
  41621. module.exports = JSZip;
  41622. },{"./defaults":394,"./external":395,"./load":400,"./object":404,"./support":419}],400:[function(require,module,exports){
  41623. 'use strict';
  41624. var utils = require('./utils');
  41625. var external = require("./external");
  41626. var utf8 = require('./utf8');
  41627. var utils = require('./utils');
  41628. var ZipEntries = require('./zipEntries');
  41629. var Crc32Probe = require('./stream/Crc32Probe');
  41630. var nodejsUtils = require("./nodejsUtils");
  41631. /**
  41632. * Check the CRC32 of an entry.
  41633. * @param {ZipEntry} zipEntry the zip entry to check.
  41634. * @return {Promise} the result.
  41635. */
  41636. function checkEntryCRC32(zipEntry) {
  41637. return new external.Promise(function (resolve, reject) {
  41638. var worker = zipEntry.decompressed.getContentWorker().pipe(new Crc32Probe());
  41639. worker.on("error", function (e) {
  41640. reject(e);
  41641. }).on("end", function () {
  41642. if (worker.streamInfo.crc32 !== zipEntry.decompressed.crc32) {
  41643. reject(new Error("Corrupted zip : CRC32 mismatch"));
  41644. } else {
  41645. resolve();
  41646. }
  41647. }).resume();
  41648. });
  41649. }
  41650. module.exports = function (data, options) {
  41651. var zip = this;
  41652. options = utils.extend(options || {}, {
  41653. base64: false,
  41654. checkCRC32: false,
  41655. optimizedBinaryString: false,
  41656. createFolders: false,
  41657. decodeFileName: utf8.utf8decode
  41658. });
  41659. if (nodejsUtils.isNode && nodejsUtils.isStream(data)) {
  41660. return external.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file."));
  41661. }
  41662. return utils.prepareContent("the loaded zip file", data, true, options.optimizedBinaryString, options.base64).then(function (data) {
  41663. var zipEntries = new ZipEntries(options);
  41664. zipEntries.load(data);
  41665. return zipEntries;
  41666. }).then(function checkCRC32(zipEntries) {
  41667. var promises = [external.Promise.resolve(zipEntries)];
  41668. var files = zipEntries.files;
  41669. if (options.checkCRC32) {
  41670. for (var i = 0; i < files.length; i++) {
  41671. promises.push(checkEntryCRC32(files[i]));
  41672. }
  41673. }
  41674. return external.Promise.all(promises);
  41675. }).then(function addFiles(results) {
  41676. var zipEntries = results.shift();
  41677. var files = zipEntries.files;
  41678. for (var i = 0; i < files.length; i++) {
  41679. var input = files[i];
  41680. zip.file(input.fileNameStr, input.decompressed, {
  41681. binary: true,
  41682. optimizedBinaryString: true,
  41683. date: input.date,
  41684. dir: input.dir,
  41685. comment: input.fileCommentStr.length ? input.fileCommentStr : null,
  41686. unixPermissions: input.unixPermissions,
  41687. dosPermissions: input.dosPermissions,
  41688. createFolders: options.createFolders
  41689. });
  41690. }
  41691. if (zipEntries.zipComment.length) {
  41692. zip.comment = zipEntries.zipComment;
  41693. }
  41694. return zip;
  41695. });
  41696. };
  41697. },{"./external":395,"./nodejsUtils":403,"./stream/Crc32Probe":414,"./utf8":420,"./utils":421,"./zipEntries":422}],401:[function(require,module,exports){
  41698. "use strict";
  41699. var utils = require('../utils');
  41700. var GenericWorker = require('../stream/GenericWorker');
  41701. /**
  41702. * A worker that use a nodejs stream as source.
  41703. * @constructor
  41704. * @param {String} filename the name of the file entry for this stream.
  41705. * @param {Readable} stream the nodejs stream.
  41706. */
  41707. function NodejsStreamInputAdapter(filename, stream) {
  41708. GenericWorker.call(this, "Nodejs stream input adapter for " + filename);
  41709. this._upstreamEnded = false;
  41710. this._bindStream(stream);
  41711. }
  41712. utils.inherits(NodejsStreamInputAdapter, GenericWorker);
  41713. /**
  41714. * Prepare the stream and bind the callbacks on it.
  41715. * Do this ASAP on node 0.10 ! A lazy binding doesn't always work.
  41716. * @param {Stream} stream the nodejs stream to use.
  41717. */
  41718. NodejsStreamInputAdapter.prototype._bindStream = function (stream) {
  41719. var self = this;
  41720. this._stream = stream;
  41721. stream.pause();
  41722. stream.on("data", function (chunk) {
  41723. self.push({
  41724. data: chunk,
  41725. meta: {
  41726. percent: 0
  41727. }
  41728. });
  41729. }).on("error", function (e) {
  41730. if (self.isPaused) {
  41731. this.generatedError = e;
  41732. } else {
  41733. self.error(e);
  41734. }
  41735. }).on("end", function () {
  41736. if (self.isPaused) {
  41737. self._upstreamEnded = true;
  41738. } else {
  41739. self.end();
  41740. }
  41741. });
  41742. };
  41743. NodejsStreamInputAdapter.prototype.pause = function () {
  41744. if (!GenericWorker.prototype.pause.call(this)) {
  41745. return false;
  41746. }
  41747. this._stream.pause();
  41748. return true;
  41749. };
  41750. NodejsStreamInputAdapter.prototype.resume = function () {
  41751. if (!GenericWorker.prototype.resume.call(this)) {
  41752. return false;
  41753. }
  41754. if (this._upstreamEnded) {
  41755. this.end();
  41756. } else {
  41757. this._stream.resume();
  41758. }
  41759. return true;
  41760. };
  41761. module.exports = NodejsStreamInputAdapter;
  41762. },{"../stream/GenericWorker":417,"../utils":421}],402:[function(require,module,exports){
  41763. 'use strict';
  41764. var Readable = require('readable-stream').Readable;
  41765. var utils = require('../utils');
  41766. utils.inherits(NodejsStreamOutputAdapter, Readable);
  41767. /**
  41768. * A nodejs stream using a worker as source.
  41769. * @see the SourceWrapper in http://nodejs.org/api/stream.html
  41770. * @constructor
  41771. * @param {StreamHelper} helper the helper wrapping the worker
  41772. * @param {Object} options the nodejs stream options
  41773. * @param {Function} updateCb the update callback.
  41774. */
  41775. function NodejsStreamOutputAdapter(helper, options, updateCb) {
  41776. Readable.call(this, options);
  41777. this._helper = helper;
  41778. var self = this;
  41779. helper.on("data", function (data, meta) {
  41780. if (!self.push(data)) {
  41781. self._helper.pause();
  41782. }
  41783. if (updateCb) {
  41784. updateCb(meta);
  41785. }
  41786. }).on("error", function (e) {
  41787. self.emit('error', e);
  41788. }).on("end", function () {
  41789. self.push(null);
  41790. });
  41791. }
  41792. NodejsStreamOutputAdapter.prototype._read = function () {
  41793. this._helper.resume();
  41794. };
  41795. module.exports = NodejsStreamOutputAdapter;
  41796. },{"../utils":421,"readable-stream":405}],403:[function(require,module,exports){
  41797. (function (Buffer){
  41798. 'use strict';
  41799. module.exports = {
  41800. /**
  41801. * True if this is running in Nodejs, will be undefined in a browser.
  41802. * In a browser, browserify won't include this file and the whole module
  41803. * will be resolved an empty object.
  41804. */
  41805. isNode: typeof Buffer !== "undefined",
  41806. /**
  41807. * Create a new nodejs Buffer from an existing content.
  41808. * @param {Object} data the data to pass to the constructor.
  41809. * @param {String} encoding the encoding to use.
  41810. * @return {Buffer} a new Buffer.
  41811. */
  41812. newBufferFrom: function newBufferFrom(data, encoding) {
  41813. if (Buffer.from && Buffer.from !== Uint8Array.from) {
  41814. return Buffer.from(data, encoding);
  41815. } else {
  41816. if (typeof data === "number") {
  41817. // Safeguard for old Node.js versions. On newer versions,
  41818. // Buffer.from(number) / Buffer(number, encoding) already throw.
  41819. throw new Error("The \"data\" argument must not be a number");
  41820. }
  41821. return new Buffer(data, encoding);
  41822. }
  41823. },
  41824. /**
  41825. * Create a new nodejs Buffer with the specified size.
  41826. * @param {Integer} size the size of the buffer.
  41827. * @return {Buffer} a new Buffer.
  41828. */
  41829. allocBuffer: function allocBuffer(size) {
  41830. if (Buffer.alloc) {
  41831. return Buffer.alloc(size);
  41832. } else {
  41833. var buf = new Buffer(size);
  41834. buf.fill(0);
  41835. return buf;
  41836. }
  41837. },
  41838. /**
  41839. * Find out if an object is a Buffer.
  41840. * @param {Object} b the object to test.
  41841. * @return {Boolean} true if the object is a Buffer, false otherwise.
  41842. */
  41843. isBuffer: function isBuffer(b) {
  41844. return Buffer.isBuffer(b);
  41845. },
  41846. isStream: function isStream(obj) {
  41847. return obj && typeof obj.on === "function" && typeof obj.pause === "function" && typeof obj.resume === "function";
  41848. }
  41849. };
  41850. }).call(this,require("buffer").Buffer)
  41851. },{"buffer":216}],404:[function(require,module,exports){
  41852. 'use strict';
  41853. var utf8 = require('./utf8');
  41854. var utils = require('./utils');
  41855. var GenericWorker = require('./stream/GenericWorker');
  41856. var StreamHelper = require('./stream/StreamHelper');
  41857. var defaults = require('./defaults');
  41858. var CompressedObject = require('./compressedObject');
  41859. var ZipObject = require('./zipObject');
  41860. var generate = require("./generate");
  41861. var nodejsUtils = require("./nodejsUtils");
  41862. var NodejsStreamInputAdapter = require("./nodejs/NodejsStreamInputAdapter");
  41863. /**
  41864. * Add a file in the current folder.
  41865. * @private
  41866. * @param {string} name the name of the file
  41867. * @param {String|ArrayBuffer|Uint8Array|Buffer} data the data of the file
  41868. * @param {Object} originalOptions the options of the file
  41869. * @return {Object} the new file.
  41870. */
  41871. var fileAdd = function fileAdd(name, data, originalOptions) {
  41872. // be sure sub folders exist
  41873. var dataType = utils.getTypeOf(data),
  41874. parent;
  41875. /*
  41876. * Correct options.
  41877. */
  41878. var o = utils.extend(originalOptions || {}, defaults);
  41879. o.date = o.date || new Date();
  41880. if (o.compression !== null) {
  41881. o.compression = o.compression.toUpperCase();
  41882. }
  41883. if (typeof o.unixPermissions === "string") {
  41884. o.unixPermissions = parseInt(o.unixPermissions, 8);
  41885. } // UNX_IFDIR 0040000 see zipinfo.c
  41886. if (o.unixPermissions && o.unixPermissions & 0x4000) {
  41887. o.dir = true;
  41888. } // Bit 4 Directory
  41889. if (o.dosPermissions && o.dosPermissions & 0x0010) {
  41890. o.dir = true;
  41891. }
  41892. if (o.dir) {
  41893. name = forceTrailingSlash(name);
  41894. }
  41895. if (o.createFolders && (parent = parentFolder(name))) {
  41896. folderAdd.call(this, parent, true);
  41897. }
  41898. var isUnicodeString = dataType === "string" && o.binary === false && o.base64 === false;
  41899. if (!originalOptions || typeof originalOptions.binary === "undefined") {
  41900. o.binary = !isUnicodeString;
  41901. }
  41902. var isCompressedEmpty = data instanceof CompressedObject && data.uncompressedSize === 0;
  41903. if (isCompressedEmpty || o.dir || !data || data.length === 0) {
  41904. o.base64 = false;
  41905. o.binary = true;
  41906. data = "";
  41907. o.compression = "STORE";
  41908. dataType = "string";
  41909. }
  41910. /*
  41911. * Convert content to fit.
  41912. */
  41913. var zipObjectContent = null;
  41914. if (data instanceof CompressedObject || data instanceof GenericWorker) {
  41915. zipObjectContent = data;
  41916. } else if (nodejsUtils.isNode && nodejsUtils.isStream(data)) {
  41917. zipObjectContent = new NodejsStreamInputAdapter(name, data);
  41918. } else {
  41919. zipObjectContent = utils.prepareContent(name, data, o.binary, o.optimizedBinaryString, o.base64);
  41920. }
  41921. var object = new ZipObject(name, zipObjectContent, o);
  41922. this.files[name] = object;
  41923. /*
  41924. TODO: we can't throw an exception because we have async promises
  41925. (we can have a promise of a Date() for example) but returning a
  41926. promise is useless because file(name, data) returns the JSZip
  41927. object for chaining. Should we break that to allow the user
  41928. to catch the error ?
  41929. return external.Promise.resolve(zipObjectContent)
  41930. .then(function () {
  41931. return object;
  41932. });
  41933. */
  41934. };
  41935. /**
  41936. * Find the parent folder of the path.
  41937. * @private
  41938. * @param {string} path the path to use
  41939. * @return {string} the parent folder, or ""
  41940. */
  41941. var parentFolder = function parentFolder(path) {
  41942. if (path.slice(-1) === '/') {
  41943. path = path.substring(0, path.length - 1);
  41944. }
  41945. var lastSlash = path.lastIndexOf('/');
  41946. return lastSlash > 0 ? path.substring(0, lastSlash) : "";
  41947. };
  41948. /**
  41949. * Returns the path with a slash at the end.
  41950. * @private
  41951. * @param {String} path the path to check.
  41952. * @return {String} the path with a trailing slash.
  41953. */
  41954. var forceTrailingSlash = function forceTrailingSlash(path) {
  41955. // Check the name ends with a /
  41956. if (path.slice(-1) !== "/") {
  41957. path += "/"; // IE doesn't like substr(-1)
  41958. }
  41959. return path;
  41960. };
  41961. /**
  41962. * Add a (sub) folder in the current folder.
  41963. * @private
  41964. * @param {string} name the folder's name
  41965. * @param {boolean=} [createFolders] If true, automatically create sub
  41966. * folders. Defaults to false.
  41967. * @return {Object} the new folder.
  41968. */
  41969. var folderAdd = function folderAdd(name, createFolders) {
  41970. createFolders = typeof createFolders !== 'undefined' ? createFolders : defaults.createFolders;
  41971. name = forceTrailingSlash(name); // Does this folder already exist?
  41972. if (!this.files[name]) {
  41973. fileAdd.call(this, name, null, {
  41974. dir: true,
  41975. createFolders: createFolders
  41976. });
  41977. }
  41978. return this.files[name];
  41979. };
  41980. /**
  41981. * Cross-window, cross-Node-context regular expression detection
  41982. * @param {Object} object Anything
  41983. * @return {Boolean} true if the object is a regular expression,
  41984. * false otherwise
  41985. */
  41986. function isRegExp(object) {
  41987. return Object.prototype.toString.call(object) === "[object RegExp]";
  41988. } // return the actual prototype of JSZip
  41989. var out = {
  41990. /**
  41991. * @see loadAsync
  41992. */
  41993. load: function load() {
  41994. throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.");
  41995. },
  41996. /**
  41997. * Call a callback function for each entry at this folder level.
  41998. * @param {Function} cb the callback function:
  41999. * function (relativePath, file) {...}
  42000. * It takes 2 arguments : the relative path and the file.
  42001. */
  42002. forEach: function forEach(cb) {
  42003. var filename, relativePath, file;
  42004. for (filename in this.files) {
  42005. if (!this.files.hasOwnProperty(filename)) {
  42006. continue;
  42007. }
  42008. file = this.files[filename];
  42009. relativePath = filename.slice(this.root.length, filename.length);
  42010. if (relativePath && filename.slice(0, this.root.length) === this.root) {
  42011. // the file is in the current root
  42012. cb(relativePath, file); // TODO reverse the parameters ? need to be clean AND consistent with the filter search fn...
  42013. }
  42014. }
  42015. },
  42016. /**
  42017. * Filter nested files/folders with the specified function.
  42018. * @param {Function} search the predicate to use :
  42019. * function (relativePath, file) {...}
  42020. * It takes 2 arguments : the relative path and the file.
  42021. * @return {Array} An array of matching elements.
  42022. */
  42023. filter: function filter(search) {
  42024. var result = [];
  42025. this.forEach(function (relativePath, entry) {
  42026. if (search(relativePath, entry)) {
  42027. // the file matches the function
  42028. result.push(entry);
  42029. }
  42030. });
  42031. return result;
  42032. },
  42033. /**
  42034. * Add a file to the zip file, or search a file.
  42035. * @param {string|RegExp} name The name of the file to add (if data is defined),
  42036. * the name of the file to find (if no data) or a regex to match files.
  42037. * @param {String|ArrayBuffer|Uint8Array|Buffer} data The file data, either raw or base64 encoded
  42038. * @param {Object} o File options
  42039. * @return {JSZip|Object|Array} this JSZip object (when adding a file),
  42040. * a file (when searching by string) or an array of files (when searching by regex).
  42041. */
  42042. file: function file(name, data, o) {
  42043. if (arguments.length === 1) {
  42044. if (isRegExp(name)) {
  42045. var regexp = name;
  42046. return this.filter(function (relativePath, file) {
  42047. return !file.dir && regexp.test(relativePath);
  42048. });
  42049. } else {
  42050. // text
  42051. var obj = this.files[this.root + name];
  42052. if (obj && !obj.dir) {
  42053. return obj;
  42054. } else {
  42055. return null;
  42056. }
  42057. }
  42058. } else {
  42059. // more than one argument : we have data !
  42060. name = this.root + name;
  42061. fileAdd.call(this, name, data, o);
  42062. }
  42063. return this;
  42064. },
  42065. /**
  42066. * Add a directory to the zip file, or search.
  42067. * @param {String|RegExp} arg The name of the directory to add, or a regex to search folders.
  42068. * @return {JSZip} an object with the new directory as the root, or an array containing matching folders.
  42069. */
  42070. folder: function folder(arg) {
  42071. if (!arg) {
  42072. return this;
  42073. }
  42074. if (isRegExp(arg)) {
  42075. return this.filter(function (relativePath, file) {
  42076. return file.dir && arg.test(relativePath);
  42077. });
  42078. } // else, name is a new folder
  42079. var name = this.root + arg;
  42080. var newFolder = folderAdd.call(this, name); // Allow chaining by returning a new object with this folder as the root
  42081. var ret = this.clone();
  42082. ret.root = newFolder.name;
  42083. return ret;
  42084. },
  42085. /**
  42086. * Delete a file, or a directory and all sub-files, from the zip
  42087. * @param {string} name the name of the file to delete
  42088. * @return {JSZip} this JSZip object
  42089. */
  42090. remove: function remove(name) {
  42091. name = this.root + name;
  42092. var file = this.files[name];
  42093. if (!file) {
  42094. // Look for any folders
  42095. if (name.slice(-1) !== "/") {
  42096. name += "/";
  42097. }
  42098. file = this.files[name];
  42099. }
  42100. if (file && !file.dir) {
  42101. // file
  42102. delete this.files[name];
  42103. } else {
  42104. // maybe a folder, delete recursively
  42105. var kids = this.filter(function (relativePath, file) {
  42106. return file.name.slice(0, name.length) === name;
  42107. });
  42108. for (var i = 0; i < kids.length; i++) {
  42109. delete this.files[kids[i].name];
  42110. }
  42111. }
  42112. return this;
  42113. },
  42114. /**
  42115. * Generate the complete zip file
  42116. * @param {Object} options the options to generate the zip file :
  42117. * - compression, "STORE" by default.
  42118. * - type, "base64" by default. Values are : string, base64, uint8array, arraybuffer, blob.
  42119. * @return {String|Uint8Array|ArrayBuffer|Buffer|Blob} the zip file
  42120. */
  42121. generate: function generate(options) {
  42122. throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.");
  42123. },
  42124. /**
  42125. * Generate the complete zip file as an internal stream.
  42126. * @param {Object} options the options to generate the zip file :
  42127. * - compression, "STORE" by default.
  42128. * - type, "base64" by default. Values are : string, base64, uint8array, arraybuffer, blob.
  42129. * @return {StreamHelper} the streamed zip file.
  42130. */
  42131. generateInternalStream: function generateInternalStream(options) {
  42132. var worker,
  42133. opts = {};
  42134. try {
  42135. opts = utils.extend(options || {}, {
  42136. streamFiles: false,
  42137. compression: "STORE",
  42138. compressionOptions: null,
  42139. type: "",
  42140. platform: "DOS",
  42141. comment: null,
  42142. mimeType: 'application/zip',
  42143. encodeFileName: utf8.utf8encode
  42144. });
  42145. opts.type = opts.type.toLowerCase();
  42146. opts.compression = opts.compression.toUpperCase(); // "binarystring" is preferred but the internals use "string".
  42147. if (opts.type === "binarystring") {
  42148. opts.type = "string";
  42149. }
  42150. if (!opts.type) {
  42151. throw new Error("No output type specified.");
  42152. }
  42153. utils.checkSupport(opts.type); // accept nodejs `process.platform`
  42154. if (opts.platform === 'darwin' || opts.platform === 'freebsd' || opts.platform === 'linux' || opts.platform === 'sunos') {
  42155. opts.platform = "UNIX";
  42156. }
  42157. if (opts.platform === 'win32') {
  42158. opts.platform = "DOS";
  42159. }
  42160. var comment = opts.comment || this.comment || "";
  42161. worker = generate.generateWorker(this, opts, comment);
  42162. } catch (e) {
  42163. worker = new GenericWorker("error");
  42164. worker.error(e);
  42165. }
  42166. return new StreamHelper(worker, opts.type || "string", opts.mimeType);
  42167. },
  42168. /**
  42169. * Generate the complete zip file asynchronously.
  42170. * @see generateInternalStream
  42171. */
  42172. generateAsync: function generateAsync(options, onUpdate) {
  42173. return this.generateInternalStream(options).accumulate(onUpdate);
  42174. },
  42175. /**
  42176. * Generate the complete zip file asynchronously.
  42177. * @see generateInternalStream
  42178. */
  42179. generateNodeStream: function generateNodeStream(options, onUpdate) {
  42180. options = options || {};
  42181. if (!options.type) {
  42182. options.type = "nodebuffer";
  42183. }
  42184. return this.generateInternalStream(options).toNodejsStream(onUpdate);
  42185. }
  42186. };
  42187. module.exports = out;
  42188. },{"./compressedObject":391,"./defaults":394,"./generate":398,"./nodejs/NodejsStreamInputAdapter":401,"./nodejsUtils":403,"./stream/GenericWorker":417,"./stream/StreamHelper":418,"./utf8":420,"./utils":421,"./zipObject":424}],405:[function(require,module,exports){
  42189. "use strict";
  42190. /*
  42191. * This file is used by module bundlers (browserify/webpack/etc) when
  42192. * including a stream implementation. We use "readable-stream" to get a
  42193. * consistent behavior between nodejs versions but bundlers often have a shim
  42194. * for "stream". Using this shim greatly improve the compatibility and greatly
  42195. * reduce the final size of the bundle (only one stream implementation, not
  42196. * two).
  42197. */
  42198. module.exports = require("stream");
  42199. },{"stream":506}],406:[function(require,module,exports){
  42200. 'use strict';
  42201. var DataReader = require('./DataReader');
  42202. var utils = require('../utils');
  42203. function ArrayReader(data) {
  42204. DataReader.call(this, data);
  42205. for (var i = 0; i < this.data.length; i++) {
  42206. data[i] = data[i] & 0xFF;
  42207. }
  42208. }
  42209. utils.inherits(ArrayReader, DataReader);
  42210. /**
  42211. * @see DataReader.byteAt
  42212. */
  42213. ArrayReader.prototype.byteAt = function (i) {
  42214. return this.data[this.zero + i];
  42215. };
  42216. /**
  42217. * @see DataReader.lastIndexOfSignature
  42218. */
  42219. ArrayReader.prototype.lastIndexOfSignature = function (sig) {
  42220. var sig0 = sig.charCodeAt(0),
  42221. sig1 = sig.charCodeAt(1),
  42222. sig2 = sig.charCodeAt(2),
  42223. sig3 = sig.charCodeAt(3);
  42224. for (var i = this.length - 4; i >= 0; --i) {
  42225. if (this.data[i] === sig0 && this.data[i + 1] === sig1 && this.data[i + 2] === sig2 && this.data[i + 3] === sig3) {
  42226. return i - this.zero;
  42227. }
  42228. }
  42229. return -1;
  42230. };
  42231. /**
  42232. * @see DataReader.readAndCheckSignature
  42233. */
  42234. ArrayReader.prototype.readAndCheckSignature = function (sig) {
  42235. var sig0 = sig.charCodeAt(0),
  42236. sig1 = sig.charCodeAt(1),
  42237. sig2 = sig.charCodeAt(2),
  42238. sig3 = sig.charCodeAt(3),
  42239. data = this.readData(4);
  42240. return sig0 === data[0] && sig1 === data[1] && sig2 === data[2] && sig3 === data[3];
  42241. };
  42242. /**
  42243. * @see DataReader.readData
  42244. */
  42245. ArrayReader.prototype.readData = function (size) {
  42246. this.checkOffset(size);
  42247. if (size === 0) {
  42248. return [];
  42249. }
  42250. var result = this.data.slice(this.zero + this.index, this.zero + this.index + size);
  42251. this.index += size;
  42252. return result;
  42253. };
  42254. module.exports = ArrayReader;
  42255. },{"../utils":421,"./DataReader":407}],407:[function(require,module,exports){
  42256. 'use strict';
  42257. var utils = require('../utils');
  42258. function DataReader(data) {
  42259. this.data = data; // type : see implementation
  42260. this.length = data.length;
  42261. this.index = 0;
  42262. this.zero = 0;
  42263. }
  42264. DataReader.prototype = {
  42265. /**
  42266. * Check that the offset will not go too far.
  42267. * @param {string} offset the additional offset to check.
  42268. * @throws {Error} an Error if the offset is out of bounds.
  42269. */
  42270. checkOffset: function checkOffset(offset) {
  42271. this.checkIndex(this.index + offset);
  42272. },
  42273. /**
  42274. * Check that the specified index will not be too far.
  42275. * @param {string} newIndex the index to check.
  42276. * @throws {Error} an Error if the index is out of bounds.
  42277. */
  42278. checkIndex: function checkIndex(newIndex) {
  42279. if (this.length < this.zero + newIndex || newIndex < 0) {
  42280. throw new Error("End of data reached (data length = " + this.length + ", asked index = " + newIndex + "). Corrupted zip ?");
  42281. }
  42282. },
  42283. /**
  42284. * Change the index.
  42285. * @param {number} newIndex The new index.
  42286. * @throws {Error} if the new index is out of the data.
  42287. */
  42288. setIndex: function setIndex(newIndex) {
  42289. this.checkIndex(newIndex);
  42290. this.index = newIndex;
  42291. },
  42292. /**
  42293. * Skip the next n bytes.
  42294. * @param {number} n the number of bytes to skip.
  42295. * @throws {Error} if the new index is out of the data.
  42296. */
  42297. skip: function skip(n) {
  42298. this.setIndex(this.index + n);
  42299. },
  42300. /**
  42301. * Get the byte at the specified index.
  42302. * @param {number} i the index to use.
  42303. * @return {number} a byte.
  42304. */
  42305. byteAt: function byteAt(i) {// see implementations
  42306. },
  42307. /**
  42308. * Get the next number with a given byte size.
  42309. * @param {number} size the number of bytes to read.
  42310. * @return {number} the corresponding number.
  42311. */
  42312. readInt: function readInt(size) {
  42313. var result = 0,
  42314. i;
  42315. this.checkOffset(size);
  42316. for (i = this.index + size - 1; i >= this.index; i--) {
  42317. result = (result << 8) + this.byteAt(i);
  42318. }
  42319. this.index += size;
  42320. return result;
  42321. },
  42322. /**
  42323. * Get the next string with a given byte size.
  42324. * @param {number} size the number of bytes to read.
  42325. * @return {string} the corresponding string.
  42326. */
  42327. readString: function readString(size) {
  42328. return utils.transformTo("string", this.readData(size));
  42329. },
  42330. /**
  42331. * Get raw data without conversion, <size> bytes.
  42332. * @param {number} size the number of bytes to read.
  42333. * @return {Object} the raw data, implementation specific.
  42334. */
  42335. readData: function readData(size) {// see implementations
  42336. },
  42337. /**
  42338. * Find the last occurrence of a zip signature (4 bytes).
  42339. * @param {string} sig the signature to find.
  42340. * @return {number} the index of the last occurrence, -1 if not found.
  42341. */
  42342. lastIndexOfSignature: function lastIndexOfSignature(sig) {// see implementations
  42343. },
  42344. /**
  42345. * Read the signature (4 bytes) at the current position and compare it with sig.
  42346. * @param {string} sig the expected signature
  42347. * @return {boolean} true if the signature matches, false otherwise.
  42348. */
  42349. readAndCheckSignature: function readAndCheckSignature(sig) {// see implementations
  42350. },
  42351. /**
  42352. * Get the next date.
  42353. * @return {Date} the date.
  42354. */
  42355. readDate: function readDate() {
  42356. var dostime = this.readInt(4);
  42357. return new Date(Date.UTC((dostime >> 25 & 0x7f) + 1980, // year
  42358. (dostime >> 21 & 0x0f) - 1, // month
  42359. dostime >> 16 & 0x1f, // day
  42360. dostime >> 11 & 0x1f, // hour
  42361. dostime >> 5 & 0x3f, // minute
  42362. (dostime & 0x1f) << 1)); // second
  42363. }
  42364. };
  42365. module.exports = DataReader;
  42366. },{"../utils":421}],408:[function(require,module,exports){
  42367. 'use strict';
  42368. var Uint8ArrayReader = require('./Uint8ArrayReader');
  42369. var utils = require('../utils');
  42370. function NodeBufferReader(data) {
  42371. Uint8ArrayReader.call(this, data);
  42372. }
  42373. utils.inherits(NodeBufferReader, Uint8ArrayReader);
  42374. /**
  42375. * @see DataReader.readData
  42376. */
  42377. NodeBufferReader.prototype.readData = function (size) {
  42378. this.checkOffset(size);
  42379. var result = this.data.slice(this.zero + this.index, this.zero + this.index + size);
  42380. this.index += size;
  42381. return result;
  42382. };
  42383. module.exports = NodeBufferReader;
  42384. },{"../utils":421,"./Uint8ArrayReader":410}],409:[function(require,module,exports){
  42385. 'use strict';
  42386. var DataReader = require('./DataReader');
  42387. var utils = require('../utils');
  42388. function StringReader(data) {
  42389. DataReader.call(this, data);
  42390. }
  42391. utils.inherits(StringReader, DataReader);
  42392. /**
  42393. * @see DataReader.byteAt
  42394. */
  42395. StringReader.prototype.byteAt = function (i) {
  42396. return this.data.charCodeAt(this.zero + i);
  42397. };
  42398. /**
  42399. * @see DataReader.lastIndexOfSignature
  42400. */
  42401. StringReader.prototype.lastIndexOfSignature = function (sig) {
  42402. return this.data.lastIndexOf(sig) - this.zero;
  42403. };
  42404. /**
  42405. * @see DataReader.readAndCheckSignature
  42406. */
  42407. StringReader.prototype.readAndCheckSignature = function (sig) {
  42408. var data = this.readData(4);
  42409. return sig === data;
  42410. };
  42411. /**
  42412. * @see DataReader.readData
  42413. */
  42414. StringReader.prototype.readData = function (size) {
  42415. this.checkOffset(size); // this will work because the constructor applied the "& 0xff" mask.
  42416. var result = this.data.slice(this.zero + this.index, this.zero + this.index + size);
  42417. this.index += size;
  42418. return result;
  42419. };
  42420. module.exports = StringReader;
  42421. },{"../utils":421,"./DataReader":407}],410:[function(require,module,exports){
  42422. 'use strict';
  42423. var ArrayReader = require('./ArrayReader');
  42424. var utils = require('../utils');
  42425. function Uint8ArrayReader(data) {
  42426. ArrayReader.call(this, data);
  42427. }
  42428. utils.inherits(Uint8ArrayReader, ArrayReader);
  42429. /**
  42430. * @see DataReader.readData
  42431. */
  42432. Uint8ArrayReader.prototype.readData = function (size) {
  42433. this.checkOffset(size);
  42434. if (size === 0) {
  42435. // in IE10, when using subarray(idx, idx), we get the array [0x00] instead of [].
  42436. return new Uint8Array(0);
  42437. }
  42438. var result = this.data.subarray(this.zero + this.index, this.zero + this.index + size);
  42439. this.index += size;
  42440. return result;
  42441. };
  42442. module.exports = Uint8ArrayReader;
  42443. },{"../utils":421,"./ArrayReader":406}],411:[function(require,module,exports){
  42444. 'use strict';
  42445. var utils = require('../utils');
  42446. var support = require('../support');
  42447. var ArrayReader = require('./ArrayReader');
  42448. var StringReader = require('./StringReader');
  42449. var NodeBufferReader = require('./NodeBufferReader');
  42450. var Uint8ArrayReader = require('./Uint8ArrayReader');
  42451. /**
  42452. * Create a reader adapted to the data.
  42453. * @param {String|ArrayBuffer|Uint8Array|Buffer} data the data to read.
  42454. * @return {DataReader} the data reader.
  42455. */
  42456. module.exports = function (data) {
  42457. var type = utils.getTypeOf(data);
  42458. utils.checkSupport(type);
  42459. if (type === "string" && !support.uint8array) {
  42460. return new StringReader(data);
  42461. }
  42462. if (type === "nodebuffer") {
  42463. return new NodeBufferReader(data);
  42464. }
  42465. if (support.uint8array) {
  42466. return new Uint8ArrayReader(utils.transformTo("uint8array", data));
  42467. }
  42468. return new ArrayReader(utils.transformTo("array", data));
  42469. };
  42470. },{"../support":419,"../utils":421,"./ArrayReader":406,"./NodeBufferReader":408,"./StringReader":409,"./Uint8ArrayReader":410}],412:[function(require,module,exports){
  42471. 'use strict';
  42472. exports.LOCAL_FILE_HEADER = "PK\x03\x04";
  42473. exports.CENTRAL_FILE_HEADER = "PK\x01\x02";
  42474. exports.CENTRAL_DIRECTORY_END = "PK\x05\x06";
  42475. exports.ZIP64_CENTRAL_DIRECTORY_LOCATOR = "PK\x06\x07";
  42476. exports.ZIP64_CENTRAL_DIRECTORY_END = "PK\x06\x06";
  42477. exports.DATA_DESCRIPTOR = "PK\x07\x08";
  42478. },{}],413:[function(require,module,exports){
  42479. 'use strict';
  42480. var GenericWorker = require('./GenericWorker');
  42481. var utils = require('../utils');
  42482. /**
  42483. * A worker which convert chunks to a specified type.
  42484. * @constructor
  42485. * @param {String} destType the destination type.
  42486. */
  42487. function ConvertWorker(destType) {
  42488. GenericWorker.call(this, "ConvertWorker to " + destType);
  42489. this.destType = destType;
  42490. }
  42491. utils.inherits(ConvertWorker, GenericWorker);
  42492. /**
  42493. * @see GenericWorker.processChunk
  42494. */
  42495. ConvertWorker.prototype.processChunk = function (chunk) {
  42496. this.push({
  42497. data: utils.transformTo(this.destType, chunk.data),
  42498. meta: chunk.meta
  42499. });
  42500. };
  42501. module.exports = ConvertWorker;
  42502. },{"../utils":421,"./GenericWorker":417}],414:[function(require,module,exports){
  42503. 'use strict';
  42504. var GenericWorker = require('./GenericWorker');
  42505. var crc32 = require('../crc32');
  42506. var utils = require('../utils');
  42507. /**
  42508. * A worker which calculate the crc32 of the data flowing through.
  42509. * @constructor
  42510. */
  42511. function Crc32Probe() {
  42512. GenericWorker.call(this, "Crc32Probe");
  42513. this.withStreamInfo("crc32", 0);
  42514. }
  42515. utils.inherits(Crc32Probe, GenericWorker);
  42516. /**
  42517. * @see GenericWorker.processChunk
  42518. */
  42519. Crc32Probe.prototype.processChunk = function (chunk) {
  42520. this.streamInfo.crc32 = crc32(chunk.data, this.streamInfo.crc32 || 0);
  42521. this.push(chunk);
  42522. };
  42523. module.exports = Crc32Probe;
  42524. },{"../crc32":393,"../utils":421,"./GenericWorker":417}],415:[function(require,module,exports){
  42525. 'use strict';
  42526. var utils = require('../utils');
  42527. var GenericWorker = require('./GenericWorker');
  42528. /**
  42529. * A worker which calculate the total length of the data flowing through.
  42530. * @constructor
  42531. * @param {String} propName the name used to expose the length
  42532. */
  42533. function DataLengthProbe(propName) {
  42534. GenericWorker.call(this, "DataLengthProbe for " + propName);
  42535. this.propName = propName;
  42536. this.withStreamInfo(propName, 0);
  42537. }
  42538. utils.inherits(DataLengthProbe, GenericWorker);
  42539. /**
  42540. * @see GenericWorker.processChunk
  42541. */
  42542. DataLengthProbe.prototype.processChunk = function (chunk) {
  42543. if (chunk) {
  42544. var length = this.streamInfo[this.propName] || 0;
  42545. this.streamInfo[this.propName] = length + chunk.data.length;
  42546. }
  42547. GenericWorker.prototype.processChunk.call(this, chunk);
  42548. };
  42549. module.exports = DataLengthProbe;
  42550. },{"../utils":421,"./GenericWorker":417}],416:[function(require,module,exports){
  42551. 'use strict';
  42552. var utils = require('../utils');
  42553. var GenericWorker = require('./GenericWorker'); // the size of the generated chunks
  42554. // TODO expose this as a public variable
  42555. var DEFAULT_BLOCK_SIZE = 16 * 1024;
  42556. /**
  42557. * A worker that reads a content and emits chunks.
  42558. * @constructor
  42559. * @param {Promise} dataP the promise of the data to split
  42560. */
  42561. function DataWorker(dataP) {
  42562. GenericWorker.call(this, "DataWorker");
  42563. var self = this;
  42564. this.dataIsReady = false;
  42565. this.index = 0;
  42566. this.max = 0;
  42567. this.data = null;
  42568. this.type = "";
  42569. this._tickScheduled = false;
  42570. dataP.then(function (data) {
  42571. self.dataIsReady = true;
  42572. self.data = data;
  42573. self.max = data && data.length || 0;
  42574. self.type = utils.getTypeOf(data);
  42575. if (!self.isPaused) {
  42576. self._tickAndRepeat();
  42577. }
  42578. }, function (e) {
  42579. self.error(e);
  42580. });
  42581. }
  42582. utils.inherits(DataWorker, GenericWorker);
  42583. /**
  42584. * @see GenericWorker.cleanUp
  42585. */
  42586. DataWorker.prototype.cleanUp = function () {
  42587. GenericWorker.prototype.cleanUp.call(this);
  42588. this.data = null;
  42589. };
  42590. /**
  42591. * @see GenericWorker.resume
  42592. */
  42593. DataWorker.prototype.resume = function () {
  42594. if (!GenericWorker.prototype.resume.call(this)) {
  42595. return false;
  42596. }
  42597. if (!this._tickScheduled && this.dataIsReady) {
  42598. this._tickScheduled = true;
  42599. utils.delay(this._tickAndRepeat, [], this);
  42600. }
  42601. return true;
  42602. };
  42603. /**
  42604. * Trigger a tick a schedule an other call to this function.
  42605. */
  42606. DataWorker.prototype._tickAndRepeat = function () {
  42607. this._tickScheduled = false;
  42608. if (this.isPaused || this.isFinished) {
  42609. return;
  42610. }
  42611. this._tick();
  42612. if (!this.isFinished) {
  42613. utils.delay(this._tickAndRepeat, [], this);
  42614. this._tickScheduled = true;
  42615. }
  42616. };
  42617. /**
  42618. * Read and push a chunk.
  42619. */
  42620. DataWorker.prototype._tick = function () {
  42621. if (this.isPaused || this.isFinished) {
  42622. return false;
  42623. }
  42624. var size = DEFAULT_BLOCK_SIZE;
  42625. var data = null,
  42626. nextIndex = Math.min(this.max, this.index + size);
  42627. if (this.index >= this.max) {
  42628. // EOF
  42629. return this.end();
  42630. } else {
  42631. switch (this.type) {
  42632. case "string":
  42633. data = this.data.substring(this.index, nextIndex);
  42634. break;
  42635. case "uint8array":
  42636. data = this.data.subarray(this.index, nextIndex);
  42637. break;
  42638. case "array":
  42639. case "nodebuffer":
  42640. data = this.data.slice(this.index, nextIndex);
  42641. break;
  42642. }
  42643. this.index = nextIndex;
  42644. return this.push({
  42645. data: data,
  42646. meta: {
  42647. percent: this.max ? this.index / this.max * 100 : 0
  42648. }
  42649. });
  42650. }
  42651. };
  42652. module.exports = DataWorker;
  42653. },{"../utils":421,"./GenericWorker":417}],417:[function(require,module,exports){
  42654. 'use strict';
  42655. /**
  42656. * A worker that does nothing but passing chunks to the next one. This is like
  42657. * a nodejs stream but with some differences. On the good side :
  42658. * - it works on IE 6-9 without any issue / polyfill
  42659. * - it weights less than the full dependencies bundled with browserify
  42660. * - it forwards errors (no need to declare an error handler EVERYWHERE)
  42661. *
  42662. * A chunk is an object with 2 attributes : `meta` and `data`. The former is an
  42663. * object containing anything (`percent` for example), see each worker for more
  42664. * details. The latter is the real data (String, Uint8Array, etc).
  42665. *
  42666. * @constructor
  42667. * @param {String} name the name of the stream (mainly used for debugging purposes)
  42668. */
  42669. function GenericWorker(name) {
  42670. // the name of the worker
  42671. this.name = name || "default"; // an object containing metadata about the workers chain
  42672. this.streamInfo = {}; // an error which happened when the worker was paused
  42673. this.generatedError = null; // an object containing metadata to be merged by this worker into the general metadata
  42674. this.extraStreamInfo = {}; // true if the stream is paused (and should not do anything), false otherwise
  42675. this.isPaused = true; // true if the stream is finished (and should not do anything), false otherwise
  42676. this.isFinished = false; // true if the stream is locked to prevent further structure updates (pipe), false otherwise
  42677. this.isLocked = false; // the event listeners
  42678. this._listeners = {
  42679. 'data': [],
  42680. 'end': [],
  42681. 'error': []
  42682. }; // the previous worker, if any
  42683. this.previous = null;
  42684. }
  42685. GenericWorker.prototype = {
  42686. /**
  42687. * Push a chunk to the next workers.
  42688. * @param {Object} chunk the chunk to push
  42689. */
  42690. push: function push(chunk) {
  42691. this.emit("data", chunk);
  42692. },
  42693. /**
  42694. * End the stream.
  42695. * @return {Boolean} true if this call ended the worker, false otherwise.
  42696. */
  42697. end: function end() {
  42698. if (this.isFinished) {
  42699. return false;
  42700. }
  42701. this.flush();
  42702. try {
  42703. this.emit("end");
  42704. this.cleanUp();
  42705. this.isFinished = true;
  42706. } catch (e) {
  42707. this.emit("error", e);
  42708. }
  42709. return true;
  42710. },
  42711. /**
  42712. * End the stream with an error.
  42713. * @param {Error} e the error which caused the premature end.
  42714. * @return {Boolean} true if this call ended the worker with an error, false otherwise.
  42715. */
  42716. error: function error(e) {
  42717. if (this.isFinished) {
  42718. return false;
  42719. }
  42720. if (this.isPaused) {
  42721. this.generatedError = e;
  42722. } else {
  42723. this.isFinished = true;
  42724. this.emit("error", e); // in the workers chain exploded in the middle of the chain,
  42725. // the error event will go downward but we also need to notify
  42726. // workers upward that there has been an error.
  42727. if (this.previous) {
  42728. this.previous.error(e);
  42729. }
  42730. this.cleanUp();
  42731. }
  42732. return true;
  42733. },
  42734. /**
  42735. * Add a callback on an event.
  42736. * @param {String} name the name of the event (data, end, error)
  42737. * @param {Function} listener the function to call when the event is triggered
  42738. * @return {GenericWorker} the current object for chainability
  42739. */
  42740. on: function on(name, listener) {
  42741. this._listeners[name].push(listener);
  42742. return this;
  42743. },
  42744. /**
  42745. * Clean any references when a worker is ending.
  42746. */
  42747. cleanUp: function cleanUp() {
  42748. this.streamInfo = this.generatedError = this.extraStreamInfo = null;
  42749. this._listeners = [];
  42750. },
  42751. /**
  42752. * Trigger an event. This will call registered callback with the provided arg.
  42753. * @param {String} name the name of the event (data, end, error)
  42754. * @param {Object} arg the argument to call the callback with.
  42755. */
  42756. emit: function emit(name, arg) {
  42757. if (this._listeners[name]) {
  42758. for (var i = 0; i < this._listeners[name].length; i++) {
  42759. this._listeners[name][i].call(this, arg);
  42760. }
  42761. }
  42762. },
  42763. /**
  42764. * Chain a worker with an other.
  42765. * @param {Worker} next the worker receiving events from the current one.
  42766. * @return {worker} the next worker for chainability
  42767. */
  42768. pipe: function pipe(next) {
  42769. return next.registerPrevious(this);
  42770. },
  42771. /**
  42772. * Same as `pipe` in the other direction.
  42773. * Using an API with `pipe(next)` is very easy.
  42774. * Implementing the API with the point of view of the next one registering
  42775. * a source is easier, see the ZipFileWorker.
  42776. * @param {Worker} previous the previous worker, sending events to this one
  42777. * @return {Worker} the current worker for chainability
  42778. */
  42779. registerPrevious: function registerPrevious(previous) {
  42780. if (this.isLocked) {
  42781. throw new Error("The stream '" + this + "' has already been used.");
  42782. } // sharing the streamInfo...
  42783. this.streamInfo = previous.streamInfo; // ... and adding our own bits
  42784. this.mergeStreamInfo();
  42785. this.previous = previous;
  42786. var self = this;
  42787. previous.on('data', function (chunk) {
  42788. self.processChunk(chunk);
  42789. });
  42790. previous.on('end', function () {
  42791. self.end();
  42792. });
  42793. previous.on('error', function (e) {
  42794. self.error(e);
  42795. });
  42796. return this;
  42797. },
  42798. /**
  42799. * Pause the stream so it doesn't send events anymore.
  42800. * @return {Boolean} true if this call paused the worker, false otherwise.
  42801. */
  42802. pause: function pause() {
  42803. if (this.isPaused || this.isFinished) {
  42804. return false;
  42805. }
  42806. this.isPaused = true;
  42807. if (this.previous) {
  42808. this.previous.pause();
  42809. }
  42810. return true;
  42811. },
  42812. /**
  42813. * Resume a paused stream.
  42814. * @return {Boolean} true if this call resumed the worker, false otherwise.
  42815. */
  42816. resume: function resume() {
  42817. if (!this.isPaused || this.isFinished) {
  42818. return false;
  42819. }
  42820. this.isPaused = false; // if true, the worker tried to resume but failed
  42821. var withError = false;
  42822. if (this.generatedError) {
  42823. this.error(this.generatedError);
  42824. withError = true;
  42825. }
  42826. if (this.previous) {
  42827. this.previous.resume();
  42828. }
  42829. return !withError;
  42830. },
  42831. /**
  42832. * Flush any remaining bytes as the stream is ending.
  42833. */
  42834. flush: function flush() {},
  42835. /**
  42836. * Process a chunk. This is usually the method overridden.
  42837. * @param {Object} chunk the chunk to process.
  42838. */
  42839. processChunk: function processChunk(chunk) {
  42840. this.push(chunk);
  42841. },
  42842. /**
  42843. * Add a key/value to be added in the workers chain streamInfo once activated.
  42844. * @param {String} key the key to use
  42845. * @param {Object} value the associated value
  42846. * @return {Worker} the current worker for chainability
  42847. */
  42848. withStreamInfo: function withStreamInfo(key, value) {
  42849. this.extraStreamInfo[key] = value;
  42850. this.mergeStreamInfo();
  42851. return this;
  42852. },
  42853. /**
  42854. * Merge this worker's streamInfo into the chain's streamInfo.
  42855. */
  42856. mergeStreamInfo: function mergeStreamInfo() {
  42857. for (var key in this.extraStreamInfo) {
  42858. if (!this.extraStreamInfo.hasOwnProperty(key)) {
  42859. continue;
  42860. }
  42861. this.streamInfo[key] = this.extraStreamInfo[key];
  42862. }
  42863. },
  42864. /**
  42865. * Lock the stream to prevent further updates on the workers chain.
  42866. * After calling this method, all calls to pipe will fail.
  42867. */
  42868. lock: function lock() {
  42869. if (this.isLocked) {
  42870. throw new Error("The stream '" + this + "' has already been used.");
  42871. }
  42872. this.isLocked = true;
  42873. if (this.previous) {
  42874. this.previous.lock();
  42875. }
  42876. },
  42877. /**
  42878. *
  42879. * Pretty print the workers chain.
  42880. */
  42881. toString: function toString() {
  42882. var me = "Worker " + this.name;
  42883. if (this.previous) {
  42884. return this.previous + " -> " + me;
  42885. } else {
  42886. return me;
  42887. }
  42888. }
  42889. };
  42890. module.exports = GenericWorker;
  42891. },{}],418:[function(require,module,exports){
  42892. (function (Buffer){
  42893. 'use strict';
  42894. var utils = require('../utils');
  42895. var ConvertWorker = require('./ConvertWorker');
  42896. var GenericWorker = require('./GenericWorker');
  42897. var base64 = require('../base64');
  42898. var support = require("../support");
  42899. var external = require("../external");
  42900. var NodejsStreamOutputAdapter = null;
  42901. if (support.nodestream) {
  42902. try {
  42903. NodejsStreamOutputAdapter = require('../nodejs/NodejsStreamOutputAdapter');
  42904. } catch (e) {}
  42905. }
  42906. /**
  42907. * Apply the final transformation of the data. If the user wants a Blob for
  42908. * example, it's easier to work with an U8intArray and finally do the
  42909. * ArrayBuffer/Blob conversion.
  42910. * @param {String} type the name of the final type
  42911. * @param {String|Uint8Array|Buffer} content the content to transform
  42912. * @param {String} mimeType the mime type of the content, if applicable.
  42913. * @return {String|Uint8Array|ArrayBuffer|Buffer|Blob} the content in the right format.
  42914. */
  42915. function transformZipOutput(type, content, mimeType) {
  42916. switch (type) {
  42917. case "blob":
  42918. return utils.newBlob(utils.transformTo("arraybuffer", content), mimeType);
  42919. case "base64":
  42920. return base64.encode(content);
  42921. default:
  42922. return utils.transformTo(type, content);
  42923. }
  42924. }
  42925. /**
  42926. * Concatenate an array of data of the given type.
  42927. * @param {String} type the type of the data in the given array.
  42928. * @param {Array} dataArray the array containing the data chunks to concatenate
  42929. * @return {String|Uint8Array|Buffer} the concatenated data
  42930. * @throws Error if the asked type is unsupported
  42931. */
  42932. function concat(type, dataArray) {
  42933. var i,
  42934. index = 0,
  42935. res = null,
  42936. totalLength = 0;
  42937. for (i = 0; i < dataArray.length; i++) {
  42938. totalLength += dataArray[i].length;
  42939. }
  42940. switch (type) {
  42941. case "string":
  42942. return dataArray.join("");
  42943. case "array":
  42944. return Array.prototype.concat.apply([], dataArray);
  42945. case "uint8array":
  42946. res = new Uint8Array(totalLength);
  42947. for (i = 0; i < dataArray.length; i++) {
  42948. res.set(dataArray[i], index);
  42949. index += dataArray[i].length;
  42950. }
  42951. return res;
  42952. case "nodebuffer":
  42953. return Buffer.concat(dataArray);
  42954. default:
  42955. throw new Error("concat : unsupported type '" + type + "'");
  42956. }
  42957. }
  42958. /**
  42959. * Listen a StreamHelper, accumulate its content and concatenate it into a
  42960. * complete block.
  42961. * @param {StreamHelper} helper the helper to use.
  42962. * @param {Function} updateCallback a callback called on each update. Called
  42963. * with one arg :
  42964. * - the metadata linked to the update received.
  42965. * @return Promise the promise for the accumulation.
  42966. */
  42967. function _accumulate(helper, updateCallback) {
  42968. return new external.Promise(function (resolve, reject) {
  42969. var dataArray = [];
  42970. var chunkType = helper._internalType,
  42971. resultType = helper._outputType,
  42972. mimeType = helper._mimeType;
  42973. helper.on('data', function (data, meta) {
  42974. dataArray.push(data);
  42975. if (updateCallback) {
  42976. updateCallback(meta);
  42977. }
  42978. }).on('error', function (err) {
  42979. dataArray = [];
  42980. reject(err);
  42981. }).on('end', function () {
  42982. try {
  42983. var result = transformZipOutput(resultType, concat(chunkType, dataArray), mimeType);
  42984. resolve(result);
  42985. } catch (e) {
  42986. reject(e);
  42987. }
  42988. dataArray = [];
  42989. }).resume();
  42990. });
  42991. }
  42992. /**
  42993. * An helper to easily use workers outside of JSZip.
  42994. * @constructor
  42995. * @param {Worker} worker the worker to wrap
  42996. * @param {String} outputType the type of data expected by the use
  42997. * @param {String} mimeType the mime type of the content, if applicable.
  42998. */
  42999. function StreamHelper(worker, outputType, mimeType) {
  43000. var internalType = outputType;
  43001. switch (outputType) {
  43002. case "blob":
  43003. case "arraybuffer":
  43004. internalType = "uint8array";
  43005. break;
  43006. case "base64":
  43007. internalType = "string";
  43008. break;
  43009. }
  43010. try {
  43011. // the type used internally
  43012. this._internalType = internalType; // the type used to output results
  43013. this._outputType = outputType; // the mime type
  43014. this._mimeType = mimeType;
  43015. utils.checkSupport(internalType);
  43016. this._worker = worker.pipe(new ConvertWorker(internalType)); // the last workers can be rewired without issues but we need to
  43017. // prevent any updates on previous workers.
  43018. worker.lock();
  43019. } catch (e) {
  43020. this._worker = new GenericWorker("error");
  43021. this._worker.error(e);
  43022. }
  43023. }
  43024. StreamHelper.prototype = {
  43025. /**
  43026. * Listen a StreamHelper, accumulate its content and concatenate it into a
  43027. * complete block.
  43028. * @param {Function} updateCb the update callback.
  43029. * @return Promise the promise for the accumulation.
  43030. */
  43031. accumulate: function accumulate(updateCb) {
  43032. return _accumulate(this, updateCb);
  43033. },
  43034. /**
  43035. * Add a listener on an event triggered on a stream.
  43036. * @param {String} evt the name of the event
  43037. * @param {Function} fn the listener
  43038. * @return {StreamHelper} the current helper.
  43039. */
  43040. on: function on(evt, fn) {
  43041. var self = this;
  43042. if (evt === "data") {
  43043. this._worker.on(evt, function (chunk) {
  43044. fn.call(self, chunk.data, chunk.meta);
  43045. });
  43046. } else {
  43047. this._worker.on(evt, function () {
  43048. utils.delay(fn, arguments, self);
  43049. });
  43050. }
  43051. return this;
  43052. },
  43053. /**
  43054. * Resume the flow of chunks.
  43055. * @return {StreamHelper} the current helper.
  43056. */
  43057. resume: function resume() {
  43058. utils.delay(this._worker.resume, [], this._worker);
  43059. return this;
  43060. },
  43061. /**
  43062. * Pause the flow of chunks.
  43063. * @return {StreamHelper} the current helper.
  43064. */
  43065. pause: function pause() {
  43066. this._worker.pause();
  43067. return this;
  43068. },
  43069. /**
  43070. * Return a nodejs stream for this helper.
  43071. * @param {Function} updateCb the update callback.
  43072. * @return {NodejsStreamOutputAdapter} the nodejs stream.
  43073. */
  43074. toNodejsStream: function toNodejsStream(updateCb) {
  43075. utils.checkSupport("nodestream");
  43076. if (this._outputType !== "nodebuffer") {
  43077. // an object stream containing blob/arraybuffer/uint8array/string
  43078. // is strange and I don't know if it would be useful.
  43079. // I you find this comment and have a good usecase, please open a
  43080. // bug report !
  43081. throw new Error(this._outputType + " is not supported by this method");
  43082. }
  43083. return new NodejsStreamOutputAdapter(this, {
  43084. objectMode: this._outputType !== "nodebuffer"
  43085. }, updateCb);
  43086. }
  43087. };
  43088. module.exports = StreamHelper;
  43089. }).call(this,require("buffer").Buffer)
  43090. },{"../base64":390,"../external":395,"../nodejs/NodejsStreamOutputAdapter":402,"../support":419,"../utils":421,"./ConvertWorker":413,"./GenericWorker":417,"buffer":216}],419:[function(require,module,exports){
  43091. (function (Buffer){
  43092. 'use strict';
  43093. exports.base64 = true;
  43094. exports.array = true;
  43095. exports.string = true;
  43096. exports.arraybuffer = typeof ArrayBuffer !== "undefined" && typeof Uint8Array !== "undefined";
  43097. exports.nodebuffer = typeof Buffer !== "undefined"; // contains true if JSZip can read/generate Uint8Array, false otherwise.
  43098. exports.uint8array = typeof Uint8Array !== "undefined";
  43099. if (typeof ArrayBuffer === "undefined") {
  43100. exports.blob = false;
  43101. } else {
  43102. var buffer = new ArrayBuffer(0);
  43103. try {
  43104. exports.blob = new Blob([buffer], {
  43105. type: "application/zip"
  43106. }).size === 0;
  43107. } catch (e) {
  43108. try {
  43109. var Builder = self.BlobBuilder || self.WebKitBlobBuilder || self.MozBlobBuilder || self.MSBlobBuilder;
  43110. var builder = new Builder();
  43111. builder.append(buffer);
  43112. exports.blob = builder.getBlob('application/zip').size === 0;
  43113. } catch (e) {
  43114. exports.blob = false;
  43115. }
  43116. }
  43117. }
  43118. try {
  43119. exports.nodestream = !!require('readable-stream').Readable;
  43120. } catch (e) {
  43121. exports.nodestream = false;
  43122. }
  43123. }).call(this,require("buffer").Buffer)
  43124. },{"buffer":216,"readable-stream":405}],420:[function(require,module,exports){
  43125. 'use strict';
  43126. var utils = require('./utils');
  43127. var support = require('./support');
  43128. var nodejsUtils = require('./nodejsUtils');
  43129. var GenericWorker = require('./stream/GenericWorker');
  43130. /**
  43131. * The following functions come from pako, from pako/lib/utils/strings
  43132. * released under the MIT license, see pako https://github.com/nodeca/pako/
  43133. */
  43134. // Table with utf8 lengths (calculated by first byte of sequence)
  43135. // Note, that 5 & 6-byte values and some 4-byte values can not be represented in JS,
  43136. // because max possible codepoint is 0x10ffff
  43137. var _utf8len = new Array(256);
  43138. for (var i = 0; i < 256; i++) {
  43139. _utf8len[i] = i >= 252 ? 6 : i >= 248 ? 5 : i >= 240 ? 4 : i >= 224 ? 3 : i >= 192 ? 2 : 1;
  43140. }
  43141. _utf8len[254] = _utf8len[254] = 1; // Invalid sequence start
  43142. // convert string to array (typed, when possible)
  43143. var string2buf = function string2buf(str) {
  43144. var buf,
  43145. c,
  43146. c2,
  43147. m_pos,
  43148. i,
  43149. str_len = str.length,
  43150. buf_len = 0; // count binary size
  43151. for (m_pos = 0; m_pos < str_len; m_pos++) {
  43152. c = str.charCodeAt(m_pos);
  43153. if ((c & 0xfc00) === 0xd800 && m_pos + 1 < str_len) {
  43154. c2 = str.charCodeAt(m_pos + 1);
  43155. if ((c2 & 0xfc00) === 0xdc00) {
  43156. c = 0x10000 + (c - 0xd800 << 10) + (c2 - 0xdc00);
  43157. m_pos++;
  43158. }
  43159. }
  43160. buf_len += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4;
  43161. } // allocate buffer
  43162. if (support.uint8array) {
  43163. buf = new Uint8Array(buf_len);
  43164. } else {
  43165. buf = new Array(buf_len);
  43166. } // convert
  43167. for (i = 0, m_pos = 0; i < buf_len; m_pos++) {
  43168. c = str.charCodeAt(m_pos);
  43169. if ((c & 0xfc00) === 0xd800 && m_pos + 1 < str_len) {
  43170. c2 = str.charCodeAt(m_pos + 1);
  43171. if ((c2 & 0xfc00) === 0xdc00) {
  43172. c = 0x10000 + (c - 0xd800 << 10) + (c2 - 0xdc00);
  43173. m_pos++;
  43174. }
  43175. }
  43176. if (c < 0x80) {
  43177. /* one byte */
  43178. buf[i++] = c;
  43179. } else if (c < 0x800) {
  43180. /* two bytes */
  43181. buf[i++] = 0xC0 | c >>> 6;
  43182. buf[i++] = 0x80 | c & 0x3f;
  43183. } else if (c < 0x10000) {
  43184. /* three bytes */
  43185. buf[i++] = 0xE0 | c >>> 12;
  43186. buf[i++] = 0x80 | c >>> 6 & 0x3f;
  43187. buf[i++] = 0x80 | c & 0x3f;
  43188. } else {
  43189. /* four bytes */
  43190. buf[i++] = 0xf0 | c >>> 18;
  43191. buf[i++] = 0x80 | c >>> 12 & 0x3f;
  43192. buf[i++] = 0x80 | c >>> 6 & 0x3f;
  43193. buf[i++] = 0x80 | c & 0x3f;
  43194. }
  43195. }
  43196. return buf;
  43197. }; // Calculate max possible position in utf8 buffer,
  43198. // that will not break sequence. If that's not possible
  43199. // - (very small limits) return max size as is.
  43200. //
  43201. // buf[] - utf8 bytes array
  43202. // max - length limit (mandatory);
  43203. var utf8border = function utf8border(buf, max) {
  43204. var pos;
  43205. max = max || buf.length;
  43206. if (max > buf.length) {
  43207. max = buf.length;
  43208. } // go back from last position, until start of sequence found
  43209. pos = max - 1;
  43210. while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) {
  43211. pos--;
  43212. } // Fuckup - very small and broken sequence,
  43213. // return max, because we should return something anyway.
  43214. if (pos < 0) {
  43215. return max;
  43216. } // If we came to start of buffer - that means vuffer is too small,
  43217. // return max too.
  43218. if (pos === 0) {
  43219. return max;
  43220. }
  43221. return pos + _utf8len[buf[pos]] > max ? pos : max;
  43222. }; // convert array to string
  43223. var buf2string = function buf2string(buf) {
  43224. var str, i, out, c, c_len;
  43225. var len = buf.length; // Reserve max possible length (2 words per char)
  43226. // NB: by unknown reasons, Array is significantly faster for
  43227. // String.fromCharCode.apply than Uint16Array.
  43228. var utf16buf = new Array(len * 2);
  43229. for (out = 0, i = 0; i < len;) {
  43230. c = buf[i++]; // quick process ascii
  43231. if (c < 0x80) {
  43232. utf16buf[out++] = c;
  43233. continue;
  43234. }
  43235. c_len = _utf8len[c]; // skip 5 & 6 byte codes
  43236. if (c_len > 4) {
  43237. utf16buf[out++] = 0xfffd;
  43238. i += c_len - 1;
  43239. continue;
  43240. } // apply mask on first byte
  43241. c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07; // join the rest
  43242. while (c_len > 1 && i < len) {
  43243. c = c << 6 | buf[i++] & 0x3f;
  43244. c_len--;
  43245. } // terminated by end of string?
  43246. if (c_len > 1) {
  43247. utf16buf[out++] = 0xfffd;
  43248. continue;
  43249. }
  43250. if (c < 0x10000) {
  43251. utf16buf[out++] = c;
  43252. } else {
  43253. c -= 0x10000;
  43254. utf16buf[out++] = 0xd800 | c >> 10 & 0x3ff;
  43255. utf16buf[out++] = 0xdc00 | c & 0x3ff;
  43256. }
  43257. } // shrinkBuf(utf16buf, out)
  43258. if (utf16buf.length !== out) {
  43259. if (utf16buf.subarray) {
  43260. utf16buf = utf16buf.subarray(0, out);
  43261. } else {
  43262. utf16buf.length = out;
  43263. }
  43264. } // return String.fromCharCode.apply(null, utf16buf);
  43265. return utils.applyFromCharCode(utf16buf);
  43266. }; // That's all for the pako functions.
  43267. /**
  43268. * Transform a javascript string into an array (typed if possible) of bytes,
  43269. * UTF-8 encoded.
  43270. * @param {String} str the string to encode
  43271. * @return {Array|Uint8Array|Buffer} the UTF-8 encoded string.
  43272. */
  43273. exports.utf8encode = function utf8encode(str) {
  43274. if (support.nodebuffer) {
  43275. return nodejsUtils.newBufferFrom(str, "utf-8");
  43276. }
  43277. return string2buf(str);
  43278. };
  43279. /**
  43280. * Transform a bytes array (or a representation) representing an UTF-8 encoded
  43281. * string into a javascript string.
  43282. * @param {Array|Uint8Array|Buffer} buf the data de decode
  43283. * @return {String} the decoded string.
  43284. */
  43285. exports.utf8decode = function utf8decode(buf) {
  43286. if (support.nodebuffer) {
  43287. return utils.transformTo("nodebuffer", buf).toString("utf-8");
  43288. }
  43289. buf = utils.transformTo(support.uint8array ? "uint8array" : "array", buf);
  43290. return buf2string(buf);
  43291. };
  43292. /**
  43293. * A worker to decode utf8 encoded binary chunks into string chunks.
  43294. * @constructor
  43295. */
  43296. function Utf8DecodeWorker() {
  43297. GenericWorker.call(this, "utf-8 decode"); // the last bytes if a chunk didn't end with a complete codepoint.
  43298. this.leftOver = null;
  43299. }
  43300. utils.inherits(Utf8DecodeWorker, GenericWorker);
  43301. /**
  43302. * @see GenericWorker.processChunk
  43303. */
  43304. Utf8DecodeWorker.prototype.processChunk = function (chunk) {
  43305. var data = utils.transformTo(support.uint8array ? "uint8array" : "array", chunk.data); // 1st step, re-use what's left of the previous chunk
  43306. if (this.leftOver && this.leftOver.length) {
  43307. if (support.uint8array) {
  43308. var previousData = data;
  43309. data = new Uint8Array(previousData.length + this.leftOver.length);
  43310. data.set(this.leftOver, 0);
  43311. data.set(previousData, this.leftOver.length);
  43312. } else {
  43313. data = this.leftOver.concat(data);
  43314. }
  43315. this.leftOver = null;
  43316. }
  43317. var nextBoundary = utf8border(data);
  43318. var usableData = data;
  43319. if (nextBoundary !== data.length) {
  43320. if (support.uint8array) {
  43321. usableData = data.subarray(0, nextBoundary);
  43322. this.leftOver = data.subarray(nextBoundary, data.length);
  43323. } else {
  43324. usableData = data.slice(0, nextBoundary);
  43325. this.leftOver = data.slice(nextBoundary, data.length);
  43326. }
  43327. }
  43328. this.push({
  43329. data: exports.utf8decode(usableData),
  43330. meta: chunk.meta
  43331. });
  43332. };
  43333. /**
  43334. * @see GenericWorker.flush
  43335. */
  43336. Utf8DecodeWorker.prototype.flush = function () {
  43337. if (this.leftOver && this.leftOver.length) {
  43338. this.push({
  43339. data: exports.utf8decode(this.leftOver),
  43340. meta: {}
  43341. });
  43342. this.leftOver = null;
  43343. }
  43344. };
  43345. exports.Utf8DecodeWorker = Utf8DecodeWorker;
  43346. /**
  43347. * A worker to endcode string chunks into utf8 encoded binary chunks.
  43348. * @constructor
  43349. */
  43350. function Utf8EncodeWorker() {
  43351. GenericWorker.call(this, "utf-8 encode");
  43352. }
  43353. utils.inherits(Utf8EncodeWorker, GenericWorker);
  43354. /**
  43355. * @see GenericWorker.processChunk
  43356. */
  43357. Utf8EncodeWorker.prototype.processChunk = function (chunk) {
  43358. this.push({
  43359. data: exports.utf8encode(chunk.data),
  43360. meta: chunk.meta
  43361. });
  43362. };
  43363. exports.Utf8EncodeWorker = Utf8EncodeWorker;
  43364. },{"./nodejsUtils":403,"./stream/GenericWorker":417,"./support":419,"./utils":421}],421:[function(require,module,exports){
  43365. 'use strict';
  43366. var support = require('./support');
  43367. var base64 = require('./base64');
  43368. var nodejsUtils = require('./nodejsUtils');
  43369. var setImmediate = require('set-immediate-shim');
  43370. var external = require("./external");
  43371. /**
  43372. * Convert a string that pass as a "binary string": it should represent a byte
  43373. * array but may have > 255 char codes. Be sure to take only the first byte
  43374. * and returns the byte array.
  43375. * @param {String} str the string to transform.
  43376. * @return {Array|Uint8Array} the string in a binary format.
  43377. */
  43378. function string2binary(str) {
  43379. var result = null;
  43380. if (support.uint8array) {
  43381. result = new Uint8Array(str.length);
  43382. } else {
  43383. result = new Array(str.length);
  43384. }
  43385. return stringToArrayLike(str, result);
  43386. }
  43387. /**
  43388. * Create a new blob with the given content and the given type.
  43389. * @param {String|ArrayBuffer} part the content to put in the blob. DO NOT use
  43390. * an Uint8Array because the stock browser of android 4 won't accept it (it
  43391. * will be silently converted to a string, "[object Uint8Array]").
  43392. *
  43393. * Use only ONE part to build the blob to avoid a memory leak in IE11 / Edge:
  43394. * when a large amount of Array is used to create the Blob, the amount of
  43395. * memory consumed is nearly 100 times the original data amount.
  43396. *
  43397. * @param {String} type the mime type of the blob.
  43398. * @return {Blob} the created blob.
  43399. */
  43400. exports.newBlob = function (part, type) {
  43401. exports.checkSupport("blob");
  43402. try {
  43403. // Blob constructor
  43404. return new Blob([part], {
  43405. type: type
  43406. });
  43407. } catch (e) {
  43408. try {
  43409. // deprecated, browser only, old way
  43410. var Builder = self.BlobBuilder || self.WebKitBlobBuilder || self.MozBlobBuilder || self.MSBlobBuilder;
  43411. var builder = new Builder();
  43412. builder.append(part);
  43413. return builder.getBlob(type);
  43414. } catch (e) {
  43415. // well, fuck ?!
  43416. throw new Error("Bug : can't construct the Blob.");
  43417. }
  43418. }
  43419. };
  43420. /**
  43421. * The identity function.
  43422. * @param {Object} input the input.
  43423. * @return {Object} the same input.
  43424. */
  43425. function identity(input) {
  43426. return input;
  43427. }
  43428. /**
  43429. * Fill in an array with a string.
  43430. * @param {String} str the string to use.
  43431. * @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to fill in (will be mutated).
  43432. * @return {Array|ArrayBuffer|Uint8Array|Buffer} the updated array.
  43433. */
  43434. function stringToArrayLike(str, array) {
  43435. for (var i = 0; i < str.length; ++i) {
  43436. array[i] = str.charCodeAt(i) & 0xFF;
  43437. }
  43438. return array;
  43439. }
  43440. /**
  43441. * An helper for the function arrayLikeToString.
  43442. * This contains static information and functions that
  43443. * can be optimized by the browser JIT compiler.
  43444. */
  43445. var arrayToStringHelper = {
  43446. /**
  43447. * Transform an array of int into a string, chunk by chunk.
  43448. * See the performances notes on arrayLikeToString.
  43449. * @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to transform.
  43450. * @param {String} type the type of the array.
  43451. * @param {Integer} chunk the chunk size.
  43452. * @return {String} the resulting string.
  43453. * @throws Error if the chunk is too big for the stack.
  43454. */
  43455. stringifyByChunk: function stringifyByChunk(array, type, chunk) {
  43456. var result = [],
  43457. k = 0,
  43458. len = array.length; // shortcut
  43459. if (len <= chunk) {
  43460. return String.fromCharCode.apply(null, array);
  43461. }
  43462. while (k < len) {
  43463. if (type === "array" || type === "nodebuffer") {
  43464. result.push(String.fromCharCode.apply(null, array.slice(k, Math.min(k + chunk, len))));
  43465. } else {
  43466. result.push(String.fromCharCode.apply(null, array.subarray(k, Math.min(k + chunk, len))));
  43467. }
  43468. k += chunk;
  43469. }
  43470. return result.join("");
  43471. },
  43472. /**
  43473. * Call String.fromCharCode on every item in the array.
  43474. * This is the naive implementation, which generate A LOT of intermediate string.
  43475. * This should be used when everything else fail.
  43476. * @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to transform.
  43477. * @return {String} the result.
  43478. */
  43479. stringifyByChar: function stringifyByChar(array) {
  43480. var resultStr = "";
  43481. for (var i = 0; i < array.length; i++) {
  43482. resultStr += String.fromCharCode(array[i]);
  43483. }
  43484. return resultStr;
  43485. },
  43486. applyCanBeUsed: {
  43487. /**
  43488. * true if the browser accepts to use String.fromCharCode on Uint8Array
  43489. */
  43490. uint8array: function () {
  43491. try {
  43492. return support.uint8array && String.fromCharCode.apply(null, new Uint8Array(1)).length === 1;
  43493. } catch (e) {
  43494. return false;
  43495. }
  43496. }(),
  43497. /**
  43498. * true if the browser accepts to use String.fromCharCode on nodejs Buffer.
  43499. */
  43500. nodebuffer: function () {
  43501. try {
  43502. return support.nodebuffer && String.fromCharCode.apply(null, nodejsUtils.allocBuffer(1)).length === 1;
  43503. } catch (e) {
  43504. return false;
  43505. }
  43506. }()
  43507. }
  43508. };
  43509. /**
  43510. * Transform an array-like object to a string.
  43511. * @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to transform.
  43512. * @return {String} the result.
  43513. */
  43514. function arrayLikeToString(array) {
  43515. // Performances notes :
  43516. // --------------------
  43517. // String.fromCharCode.apply(null, array) is the fastest, see
  43518. // see http://jsperf.com/converting-a-uint8array-to-a-string/2
  43519. // but the stack is limited (and we can get huge arrays !).
  43520. //
  43521. // result += String.fromCharCode(array[i]); generate too many strings !
  43522. //
  43523. // This code is inspired by http://jsperf.com/arraybuffer-to-string-apply-performance/2
  43524. // TODO : we now have workers that split the work. Do we still need that ?
  43525. var chunk = 65536,
  43526. type = exports.getTypeOf(array),
  43527. canUseApply = true;
  43528. if (type === "uint8array") {
  43529. canUseApply = arrayToStringHelper.applyCanBeUsed.uint8array;
  43530. } else if (type === "nodebuffer") {
  43531. canUseApply = arrayToStringHelper.applyCanBeUsed.nodebuffer;
  43532. }
  43533. if (canUseApply) {
  43534. while (chunk > 1) {
  43535. try {
  43536. return arrayToStringHelper.stringifyByChunk(array, type, chunk);
  43537. } catch (e) {
  43538. chunk = Math.floor(chunk / 2);
  43539. }
  43540. }
  43541. } // no apply or chunk error : slow and painful algorithm
  43542. // default browser on android 4.*
  43543. return arrayToStringHelper.stringifyByChar(array);
  43544. }
  43545. exports.applyFromCharCode = arrayLikeToString;
  43546. /**
  43547. * Copy the data from an array-like to an other array-like.
  43548. * @param {Array|ArrayBuffer|Uint8Array|Buffer} arrayFrom the origin array.
  43549. * @param {Array|ArrayBuffer|Uint8Array|Buffer} arrayTo the destination array which will be mutated.
  43550. * @return {Array|ArrayBuffer|Uint8Array|Buffer} the updated destination array.
  43551. */
  43552. function arrayLikeToArrayLike(arrayFrom, arrayTo) {
  43553. for (var i = 0; i < arrayFrom.length; i++) {
  43554. arrayTo[i] = arrayFrom[i];
  43555. }
  43556. return arrayTo;
  43557. } // a matrix containing functions to transform everything into everything.
  43558. var transform = {}; // string to ?
  43559. transform["string"] = {
  43560. "string": identity,
  43561. "array": function array(input) {
  43562. return stringToArrayLike(input, new Array(input.length));
  43563. },
  43564. "arraybuffer": function arraybuffer(input) {
  43565. return transform["string"]["uint8array"](input).buffer;
  43566. },
  43567. "uint8array": function uint8array(input) {
  43568. return stringToArrayLike(input, new Uint8Array(input.length));
  43569. },
  43570. "nodebuffer": function nodebuffer(input) {
  43571. return stringToArrayLike(input, nodejsUtils.allocBuffer(input.length));
  43572. }
  43573. }; // array to ?
  43574. transform["array"] = {
  43575. "string": arrayLikeToString,
  43576. "array": identity,
  43577. "arraybuffer": function arraybuffer(input) {
  43578. return new Uint8Array(input).buffer;
  43579. },
  43580. "uint8array": function uint8array(input) {
  43581. return new Uint8Array(input);
  43582. },
  43583. "nodebuffer": function nodebuffer(input) {
  43584. return nodejsUtils.newBufferFrom(input);
  43585. }
  43586. }; // arraybuffer to ?
  43587. transform["arraybuffer"] = {
  43588. "string": function string(input) {
  43589. return arrayLikeToString(new Uint8Array(input));
  43590. },
  43591. "array": function array(input) {
  43592. return arrayLikeToArrayLike(new Uint8Array(input), new Array(input.byteLength));
  43593. },
  43594. "arraybuffer": identity,
  43595. "uint8array": function uint8array(input) {
  43596. return new Uint8Array(input);
  43597. },
  43598. "nodebuffer": function nodebuffer(input) {
  43599. return nodejsUtils.newBufferFrom(new Uint8Array(input));
  43600. }
  43601. }; // uint8array to ?
  43602. transform["uint8array"] = {
  43603. "string": arrayLikeToString,
  43604. "array": function array(input) {
  43605. return arrayLikeToArrayLike(input, new Array(input.length));
  43606. },
  43607. "arraybuffer": function arraybuffer(input) {
  43608. return input.buffer;
  43609. },
  43610. "uint8array": identity,
  43611. "nodebuffer": function nodebuffer(input) {
  43612. return nodejsUtils.newBufferFrom(input);
  43613. }
  43614. }; // nodebuffer to ?
  43615. transform["nodebuffer"] = {
  43616. "string": arrayLikeToString,
  43617. "array": function array(input) {
  43618. return arrayLikeToArrayLike(input, new Array(input.length));
  43619. },
  43620. "arraybuffer": function arraybuffer(input) {
  43621. return transform["nodebuffer"]["uint8array"](input).buffer;
  43622. },
  43623. "uint8array": function uint8array(input) {
  43624. return arrayLikeToArrayLike(input, new Uint8Array(input.length));
  43625. },
  43626. "nodebuffer": identity
  43627. };
  43628. /**
  43629. * Transform an input into any type.
  43630. * The supported output type are : string, array, uint8array, arraybuffer, nodebuffer.
  43631. * If no output type is specified, the unmodified input will be returned.
  43632. * @param {String} outputType the output type.
  43633. * @param {String|Array|ArrayBuffer|Uint8Array|Buffer} input the input to convert.
  43634. * @throws {Error} an Error if the browser doesn't support the requested output type.
  43635. */
  43636. exports.transformTo = function (outputType, input) {
  43637. if (!input) {
  43638. // undefined, null, etc
  43639. // an empty string won't harm.
  43640. input = "";
  43641. }
  43642. if (!outputType) {
  43643. return input;
  43644. }
  43645. exports.checkSupport(outputType);
  43646. var inputType = exports.getTypeOf(input);
  43647. var result = transform[inputType][outputType](input);
  43648. return result;
  43649. };
  43650. /**
  43651. * Return the type of the input.
  43652. * The type will be in a format valid for JSZip.utils.transformTo : string, array, uint8array, arraybuffer.
  43653. * @param {Object} input the input to identify.
  43654. * @return {String} the (lowercase) type of the input.
  43655. */
  43656. exports.getTypeOf = function (input) {
  43657. if (typeof input === "string") {
  43658. return "string";
  43659. }
  43660. if (Object.prototype.toString.call(input) === "[object Array]") {
  43661. return "array";
  43662. }
  43663. if (support.nodebuffer && nodejsUtils.isBuffer(input)) {
  43664. return "nodebuffer";
  43665. }
  43666. if (support.uint8array && input instanceof Uint8Array) {
  43667. return "uint8array";
  43668. }
  43669. if (support.arraybuffer && input instanceof ArrayBuffer) {
  43670. return "arraybuffer";
  43671. }
  43672. };
  43673. /**
  43674. * Throw an exception if the type is not supported.
  43675. * @param {String} type the type to check.
  43676. * @throws {Error} an Error if the browser doesn't support the requested type.
  43677. */
  43678. exports.checkSupport = function (type) {
  43679. var supported = support[type.toLowerCase()];
  43680. if (!supported) {
  43681. throw new Error(type + " is not supported by this platform");
  43682. }
  43683. };
  43684. exports.MAX_VALUE_16BITS = 65535;
  43685. exports.MAX_VALUE_32BITS = -1; // well, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" is parsed as -1
  43686. /**
  43687. * Prettify a string read as binary.
  43688. * @param {string} str the string to prettify.
  43689. * @return {string} a pretty string.
  43690. */
  43691. exports.pretty = function (str) {
  43692. var res = '',
  43693. code,
  43694. i;
  43695. for (i = 0; i < (str || "").length; i++) {
  43696. code = str.charCodeAt(i);
  43697. res += '\\x' + (code < 16 ? "0" : "") + code.toString(16).toUpperCase();
  43698. }
  43699. return res;
  43700. };
  43701. /**
  43702. * Defer the call of a function.
  43703. * @param {Function} callback the function to call asynchronously.
  43704. * @param {Array} args the arguments to give to the callback.
  43705. */
  43706. exports.delay = function (callback, args, self) {
  43707. setImmediate(function () {
  43708. callback.apply(self || null, args || []);
  43709. });
  43710. };
  43711. /**
  43712. * Extends a prototype with an other, without calling a constructor with
  43713. * side effects. Inspired by nodejs' `utils.inherits`
  43714. * @param {Function} ctor the constructor to augment
  43715. * @param {Function} superCtor the parent constructor to use
  43716. */
  43717. exports.inherits = function (ctor, superCtor) {
  43718. var Obj = function Obj() {};
  43719. Obj.prototype = superCtor.prototype;
  43720. ctor.prototype = new Obj();
  43721. };
  43722. /**
  43723. * Merge the objects passed as parameters into a new one.
  43724. * @private
  43725. * @param {...Object} var_args All objects to merge.
  43726. * @return {Object} a new object with the data of the others.
  43727. */
  43728. exports.extend = function () {
  43729. var result = {},
  43730. i,
  43731. attr;
  43732. for (i = 0; i < arguments.length; i++) {
  43733. // arguments is not enumerable in some browsers
  43734. for (attr in arguments[i]) {
  43735. if (arguments[i].hasOwnProperty(attr) && typeof result[attr] === "undefined") {
  43736. result[attr] = arguments[i][attr];
  43737. }
  43738. }
  43739. }
  43740. return result;
  43741. };
  43742. /**
  43743. * Transform arbitrary content into a Promise.
  43744. * @param {String} name a name for the content being processed.
  43745. * @param {Object} inputData the content to process.
  43746. * @param {Boolean} isBinary true if the content is not an unicode string
  43747. * @param {Boolean} isOptimizedBinaryString true if the string content only has one byte per character.
  43748. * @param {Boolean} isBase64 true if the string content is encoded with base64.
  43749. * @return {Promise} a promise in a format usable by JSZip.
  43750. */
  43751. exports.prepareContent = function (name, inputData, isBinary, isOptimizedBinaryString, isBase64) {
  43752. // if inputData is already a promise, this flatten it.
  43753. var promise = external.Promise.resolve(inputData).then(function (data) {
  43754. var isBlob = support.blob && (data instanceof Blob || ['[object File]', '[object Blob]'].indexOf(Object.prototype.toString.call(data)) !== -1);
  43755. if (isBlob && typeof FileReader !== "undefined") {
  43756. return new external.Promise(function (resolve, reject) {
  43757. var reader = new FileReader();
  43758. reader.onload = function (e) {
  43759. resolve(e.target.result);
  43760. };
  43761. reader.onerror = function (e) {
  43762. reject(e.target.error);
  43763. };
  43764. reader.readAsArrayBuffer(data);
  43765. });
  43766. } else {
  43767. return data;
  43768. }
  43769. });
  43770. return promise.then(function (data) {
  43771. var dataType = exports.getTypeOf(data);
  43772. if (!dataType) {
  43773. return external.Promise.reject(new Error("Can't read the data of '" + name + "'. Is it " + "in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?"));
  43774. } // special case : it's way easier to work with Uint8Array than with ArrayBuffer
  43775. if (dataType === "arraybuffer") {
  43776. data = exports.transformTo("uint8array", data);
  43777. } else if (dataType === "string") {
  43778. if (isBase64) {
  43779. data = base64.decode(data);
  43780. } else if (isBinary) {
  43781. // optimizedBinaryString === true means that the file has already been filtered with a 0xFF mask
  43782. if (isOptimizedBinaryString !== true) {
  43783. // this is a string, not in a base64 format.
  43784. // Be sure that this is a correct "binary string"
  43785. data = string2binary(data);
  43786. }
  43787. }
  43788. }
  43789. return data;
  43790. });
  43791. };
  43792. },{"./base64":390,"./external":395,"./nodejsUtils":403,"./support":419,"set-immediate-shim":497}],422:[function(require,module,exports){
  43793. 'use strict';
  43794. var readerFor = require('./reader/readerFor');
  43795. var utils = require('./utils');
  43796. var sig = require('./signature');
  43797. var ZipEntry = require('./zipEntry');
  43798. var utf8 = require('./utf8');
  43799. var support = require('./support'); // class ZipEntries {{{
  43800. /**
  43801. * All the entries in the zip file.
  43802. * @constructor
  43803. * @param {Object} loadOptions Options for loading the stream.
  43804. */
  43805. function ZipEntries(loadOptions) {
  43806. this.files = [];
  43807. this.loadOptions = loadOptions;
  43808. }
  43809. ZipEntries.prototype = {
  43810. /**
  43811. * Check that the reader is on the specified signature.
  43812. * @param {string} expectedSignature the expected signature.
  43813. * @throws {Error} if it is an other signature.
  43814. */
  43815. checkSignature: function checkSignature(expectedSignature) {
  43816. if (!this.reader.readAndCheckSignature(expectedSignature)) {
  43817. this.reader.index -= 4;
  43818. var signature = this.reader.readString(4);
  43819. throw new Error("Corrupted zip or bug: unexpected signature " + "(" + utils.pretty(signature) + ", expected " + utils.pretty(expectedSignature) + ")");
  43820. }
  43821. },
  43822. /**
  43823. * Check if the given signature is at the given index.
  43824. * @param {number} askedIndex the index to check.
  43825. * @param {string} expectedSignature the signature to expect.
  43826. * @return {boolean} true if the signature is here, false otherwise.
  43827. */
  43828. isSignature: function isSignature(askedIndex, expectedSignature) {
  43829. var currentIndex = this.reader.index;
  43830. this.reader.setIndex(askedIndex);
  43831. var signature = this.reader.readString(4);
  43832. var result = signature === expectedSignature;
  43833. this.reader.setIndex(currentIndex);
  43834. return result;
  43835. },
  43836. /**
  43837. * Read the end of the central directory.
  43838. */
  43839. readBlockEndOfCentral: function readBlockEndOfCentral() {
  43840. this.diskNumber = this.reader.readInt(2);
  43841. this.diskWithCentralDirStart = this.reader.readInt(2);
  43842. this.centralDirRecordsOnThisDisk = this.reader.readInt(2);
  43843. this.centralDirRecords = this.reader.readInt(2);
  43844. this.centralDirSize = this.reader.readInt(4);
  43845. this.centralDirOffset = this.reader.readInt(4);
  43846. this.zipCommentLength = this.reader.readInt(2); // warning : the encoding depends of the system locale
  43847. // On a linux machine with LANG=en_US.utf8, this field is utf8 encoded.
  43848. // On a windows machine, this field is encoded with the localized windows code page.
  43849. var zipComment = this.reader.readData(this.zipCommentLength);
  43850. var decodeParamType = support.uint8array ? "uint8array" : "array"; // To get consistent behavior with the generation part, we will assume that
  43851. // this is utf8 encoded unless specified otherwise.
  43852. var decodeContent = utils.transformTo(decodeParamType, zipComment);
  43853. this.zipComment = this.loadOptions.decodeFileName(decodeContent);
  43854. },
  43855. /**
  43856. * Read the end of the Zip 64 central directory.
  43857. * Not merged with the method readEndOfCentral :
  43858. * The end of central can coexist with its Zip64 brother,
  43859. * I don't want to read the wrong number of bytes !
  43860. */
  43861. readBlockZip64EndOfCentral: function readBlockZip64EndOfCentral() {
  43862. this.zip64EndOfCentralSize = this.reader.readInt(8);
  43863. this.reader.skip(4); // this.versionMadeBy = this.reader.readString(2);
  43864. // this.versionNeeded = this.reader.readInt(2);
  43865. this.diskNumber = this.reader.readInt(4);
  43866. this.diskWithCentralDirStart = this.reader.readInt(4);
  43867. this.centralDirRecordsOnThisDisk = this.reader.readInt(8);
  43868. this.centralDirRecords = this.reader.readInt(8);
  43869. this.centralDirSize = this.reader.readInt(8);
  43870. this.centralDirOffset = this.reader.readInt(8);
  43871. this.zip64ExtensibleData = {};
  43872. var extraDataSize = this.zip64EndOfCentralSize - 44,
  43873. index = 0,
  43874. extraFieldId,
  43875. extraFieldLength,
  43876. extraFieldValue;
  43877. while (index < extraDataSize) {
  43878. extraFieldId = this.reader.readInt(2);
  43879. extraFieldLength = this.reader.readInt(4);
  43880. extraFieldValue = this.reader.readData(extraFieldLength);
  43881. this.zip64ExtensibleData[extraFieldId] = {
  43882. id: extraFieldId,
  43883. length: extraFieldLength,
  43884. value: extraFieldValue
  43885. };
  43886. }
  43887. },
  43888. /**
  43889. * Read the end of the Zip 64 central directory locator.
  43890. */
  43891. readBlockZip64EndOfCentralLocator: function readBlockZip64EndOfCentralLocator() {
  43892. this.diskWithZip64CentralDirStart = this.reader.readInt(4);
  43893. this.relativeOffsetEndOfZip64CentralDir = this.reader.readInt(8);
  43894. this.disksCount = this.reader.readInt(4);
  43895. if (this.disksCount > 1) {
  43896. throw new Error("Multi-volumes zip are not supported");
  43897. }
  43898. },
  43899. /**
  43900. * Read the local files, based on the offset read in the central part.
  43901. */
  43902. readLocalFiles: function readLocalFiles() {
  43903. var i, file;
  43904. for (i = 0; i < this.files.length; i++) {
  43905. file = this.files[i];
  43906. this.reader.setIndex(file.localHeaderOffset);
  43907. this.checkSignature(sig.LOCAL_FILE_HEADER);
  43908. file.readLocalPart(this.reader);
  43909. file.handleUTF8();
  43910. file.processAttributes();
  43911. }
  43912. },
  43913. /**
  43914. * Read the central directory.
  43915. */
  43916. readCentralDir: function readCentralDir() {
  43917. var file;
  43918. this.reader.setIndex(this.centralDirOffset);
  43919. while (this.reader.readAndCheckSignature(sig.CENTRAL_FILE_HEADER)) {
  43920. file = new ZipEntry({
  43921. zip64: this.zip64
  43922. }, this.loadOptions);
  43923. file.readCentralPart(this.reader);
  43924. this.files.push(file);
  43925. }
  43926. if (this.centralDirRecords !== this.files.length) {
  43927. if (this.centralDirRecords !== 0 && this.files.length === 0) {
  43928. // We expected some records but couldn't find ANY.
  43929. // This is really suspicious, as if something went wrong.
  43930. throw new Error("Corrupted zip or bug: expected " + this.centralDirRecords + " records in central dir, got " + this.files.length);
  43931. } else {// We found some records but not all.
  43932. // Something is wrong but we got something for the user: no error here.
  43933. // console.warn("expected", this.centralDirRecords, "records in central dir, got", this.files.length);
  43934. }
  43935. }
  43936. },
  43937. /**
  43938. * Read the end of central directory.
  43939. */
  43940. readEndOfCentral: function readEndOfCentral() {
  43941. var offset = this.reader.lastIndexOfSignature(sig.CENTRAL_DIRECTORY_END);
  43942. if (offset < 0) {
  43943. // Check if the content is a truncated zip or complete garbage.
  43944. // A "LOCAL_FILE_HEADER" is not required at the beginning (auto
  43945. // extractible zip for example) but it can give a good hint.
  43946. // If an ajax request was used without responseType, we will also
  43947. // get unreadable data.
  43948. var isGarbage = !this.isSignature(0, sig.LOCAL_FILE_HEADER);
  43949. if (isGarbage) {
  43950. throw 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");
  43951. } else {
  43952. throw new Error("Corrupted zip: can't find end of central directory");
  43953. }
  43954. }
  43955. this.reader.setIndex(offset);
  43956. var endOfCentralDirOffset = offset;
  43957. this.checkSignature(sig.CENTRAL_DIRECTORY_END);
  43958. this.readBlockEndOfCentral();
  43959. /* extract from the zip spec :
  43960. 4) If one of the fields in the end of central directory
  43961. record is too small to hold required data, the field
  43962. should be set to -1 (0xFFFF or 0xFFFFFFFF) and the
  43963. ZIP64 format record should be created.
  43964. 5) The end of central directory record and the
  43965. Zip64 end of central directory locator record must
  43966. reside on the same disk when splitting or spanning
  43967. an archive.
  43968. */
  43969. if (this.diskNumber === utils.MAX_VALUE_16BITS || this.diskWithCentralDirStart === utils.MAX_VALUE_16BITS || this.centralDirRecordsOnThisDisk === utils.MAX_VALUE_16BITS || this.centralDirRecords === utils.MAX_VALUE_16BITS || this.centralDirSize === utils.MAX_VALUE_32BITS || this.centralDirOffset === utils.MAX_VALUE_32BITS) {
  43970. this.zip64 = true;
  43971. /*
  43972. Warning : the zip64 extension is supported, but ONLY if the 64bits integer read from
  43973. the zip file can fit into a 32bits integer. This cannot be solved : JavaScript represents
  43974. all numbers as 64-bit double precision IEEE 754 floating point numbers.
  43975. So, we have 53bits for integers and bitwise operations treat everything as 32bits.
  43976. see https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/Bitwise_Operators
  43977. and http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf section 8.5
  43978. */
  43979. // should look for a zip64 EOCD locator
  43980. offset = this.reader.lastIndexOfSignature(sig.ZIP64_CENTRAL_DIRECTORY_LOCATOR);
  43981. if (offset < 0) {
  43982. throw new Error("Corrupted zip: can't find the ZIP64 end of central directory locator");
  43983. }
  43984. this.reader.setIndex(offset);
  43985. this.checkSignature(sig.ZIP64_CENTRAL_DIRECTORY_LOCATOR);
  43986. this.readBlockZip64EndOfCentralLocator(); // now the zip64 EOCD record
  43987. if (!this.isSignature(this.relativeOffsetEndOfZip64CentralDir, sig.ZIP64_CENTRAL_DIRECTORY_END)) {
  43988. // console.warn("ZIP64 end of central directory not where expected.");
  43989. this.relativeOffsetEndOfZip64CentralDir = this.reader.lastIndexOfSignature(sig.ZIP64_CENTRAL_DIRECTORY_END);
  43990. if (this.relativeOffsetEndOfZip64CentralDir < 0) {
  43991. throw new Error("Corrupted zip: can't find the ZIP64 end of central directory");
  43992. }
  43993. }
  43994. this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir);
  43995. this.checkSignature(sig.ZIP64_CENTRAL_DIRECTORY_END);
  43996. this.readBlockZip64EndOfCentral();
  43997. }
  43998. var expectedEndOfCentralDirOffset = this.centralDirOffset + this.centralDirSize;
  43999. if (this.zip64) {
  44000. expectedEndOfCentralDirOffset += 20; // end of central dir 64 locator
  44001. expectedEndOfCentralDirOffset += 12
  44002. /* should not include the leading 12 bytes */
  44003. + this.zip64EndOfCentralSize;
  44004. }
  44005. var extraBytes = endOfCentralDirOffset - expectedEndOfCentralDirOffset;
  44006. if (extraBytes > 0) {
  44007. // console.warn(extraBytes, "extra bytes at beginning or within zipfile");
  44008. if (this.isSignature(endOfCentralDirOffset, sig.CENTRAL_FILE_HEADER)) {// The offsets seem wrong, but we have something at the specified offset.
  44009. // So… we keep it.
  44010. } else {
  44011. // the offset is wrong, update the "zero" of the reader
  44012. // this happens if data has been prepended (crx files for example)
  44013. this.reader.zero = extraBytes;
  44014. }
  44015. } else if (extraBytes < 0) {
  44016. throw new Error("Corrupted zip: missing " + Math.abs(extraBytes) + " bytes.");
  44017. }
  44018. },
  44019. prepareReader: function prepareReader(data) {
  44020. this.reader = readerFor(data);
  44021. },
  44022. /**
  44023. * Read a zip file and create ZipEntries.
  44024. * @param {String|ArrayBuffer|Uint8Array|Buffer} data the binary string representing a zip file.
  44025. */
  44026. load: function load(data) {
  44027. this.prepareReader(data);
  44028. this.readEndOfCentral();
  44029. this.readCentralDir();
  44030. this.readLocalFiles();
  44031. }
  44032. }; // }}} end of ZipEntries
  44033. module.exports = ZipEntries;
  44034. },{"./reader/readerFor":411,"./signature":412,"./support":419,"./utf8":420,"./utils":421,"./zipEntry":423}],423:[function(require,module,exports){
  44035. 'use strict';
  44036. var readerFor = require('./reader/readerFor');
  44037. var utils = require('./utils');
  44038. var CompressedObject = require('./compressedObject');
  44039. var crc32fn = require('./crc32');
  44040. var utf8 = require('./utf8');
  44041. var compressions = require('./compressions');
  44042. var support = require('./support');
  44043. var MADE_BY_DOS = 0x00;
  44044. var MADE_BY_UNIX = 0x03;
  44045. /**
  44046. * Find a compression registered in JSZip.
  44047. * @param {string} compressionMethod the method magic to find.
  44048. * @return {Object|null} the JSZip compression object, null if none found.
  44049. */
  44050. var findCompression = function findCompression(compressionMethod) {
  44051. for (var method in compressions) {
  44052. if (!compressions.hasOwnProperty(method)) {
  44053. continue;
  44054. }
  44055. if (compressions[method].magic === compressionMethod) {
  44056. return compressions[method];
  44057. }
  44058. }
  44059. return null;
  44060. }; // class ZipEntry {{{
  44061. /**
  44062. * An entry in the zip file.
  44063. * @constructor
  44064. * @param {Object} options Options of the current file.
  44065. * @param {Object} loadOptions Options for loading the stream.
  44066. */
  44067. function ZipEntry(options, loadOptions) {
  44068. this.options = options;
  44069. this.loadOptions = loadOptions;
  44070. }
  44071. ZipEntry.prototype = {
  44072. /**
  44073. * say if the file is encrypted.
  44074. * @return {boolean} true if the file is encrypted, false otherwise.
  44075. */
  44076. isEncrypted: function isEncrypted() {
  44077. // bit 1 is set
  44078. return (this.bitFlag & 0x0001) === 0x0001;
  44079. },
  44080. /**
  44081. * say if the file has utf-8 filename/comment.
  44082. * @return {boolean} true if the filename/comment is in utf-8, false otherwise.
  44083. */
  44084. useUTF8: function useUTF8() {
  44085. // bit 11 is set
  44086. return (this.bitFlag & 0x0800) === 0x0800;
  44087. },
  44088. /**
  44089. * Read the local part of a zip file and add the info in this object.
  44090. * @param {DataReader} reader the reader to use.
  44091. */
  44092. readLocalPart: function readLocalPart(reader) {
  44093. var compression, localExtraFieldsLength; // we already know everything from the central dir !
  44094. // If the central dir data are false, we are doomed.
  44095. // On the bright side, the local part is scary : zip64, data descriptors, both, etc.
  44096. // The less data we get here, the more reliable this should be.
  44097. // Let's skip the whole header and dash to the data !
  44098. reader.skip(22); // in some zip created on windows, the filename stored in the central dir contains \ instead of /.
  44099. // Strangely, the filename here is OK.
  44100. // I would love to treat these zip files as corrupted (see http://www.info-zip.org/FAQ.html#backslashes
  44101. // or APPNOTE#4.4.17.1, "All slashes MUST be forward slashes '/'") but there are a lot of bad zip generators...
  44102. // Search "unzip mismatching "local" filename continuing with "central" filename version" on
  44103. // the internet.
  44104. //
  44105. // I think I see the logic here : the central directory is used to display
  44106. // content and the local directory is used to extract the files. Mixing / and \
  44107. // may be used to display \ to windows users and use / when extracting the files.
  44108. // Unfortunately, this lead also to some issues : http://seclists.org/fulldisclosure/2009/Sep/394
  44109. this.fileNameLength = reader.readInt(2);
  44110. localExtraFieldsLength = reader.readInt(2); // can't be sure this will be the same as the central dir
  44111. // the fileName is stored as binary data, the handleUTF8 method will take care of the encoding.
  44112. this.fileName = reader.readData(this.fileNameLength);
  44113. reader.skip(localExtraFieldsLength);
  44114. if (this.compressedSize === -1 || this.uncompressedSize === -1) {
  44115. throw new Error("Bug or corrupted zip : didn't get enough information from the central directory " + "(compressedSize === -1 || uncompressedSize === -1)");
  44116. }
  44117. compression = findCompression(this.compressionMethod);
  44118. if (compression === null) {
  44119. // no compression found
  44120. throw new Error("Corrupted zip : compression " + utils.pretty(this.compressionMethod) + " unknown (inner file : " + utils.transformTo("string", this.fileName) + ")");
  44121. }
  44122. this.decompressed = new CompressedObject(this.compressedSize, this.uncompressedSize, this.crc32, compression, reader.readData(this.compressedSize));
  44123. },
  44124. /**
  44125. * Read the central part of a zip file and add the info in this object.
  44126. * @param {DataReader} reader the reader to use.
  44127. */
  44128. readCentralPart: function readCentralPart(reader) {
  44129. this.versionMadeBy = reader.readInt(2);
  44130. reader.skip(2); // this.versionNeeded = reader.readInt(2);
  44131. this.bitFlag = reader.readInt(2);
  44132. this.compressionMethod = reader.readString(2);
  44133. this.date = reader.readDate();
  44134. this.crc32 = reader.readInt(4);
  44135. this.compressedSize = reader.readInt(4);
  44136. this.uncompressedSize = reader.readInt(4);
  44137. var fileNameLength = reader.readInt(2);
  44138. this.extraFieldsLength = reader.readInt(2);
  44139. this.fileCommentLength = reader.readInt(2);
  44140. this.diskNumberStart = reader.readInt(2);
  44141. this.internalFileAttributes = reader.readInt(2);
  44142. this.externalFileAttributes = reader.readInt(4);
  44143. this.localHeaderOffset = reader.readInt(4);
  44144. if (this.isEncrypted()) {
  44145. throw new Error("Encrypted zip are not supported");
  44146. } // will be read in the local part, see the comments there
  44147. reader.skip(fileNameLength);
  44148. this.readExtraFields(reader);
  44149. this.parseZIP64ExtraField(reader);
  44150. this.fileComment = reader.readData(this.fileCommentLength);
  44151. },
  44152. /**
  44153. * Parse the external file attributes and get the unix/dos permissions.
  44154. */
  44155. processAttributes: function processAttributes() {
  44156. this.unixPermissions = null;
  44157. this.dosPermissions = null;
  44158. var madeBy = this.versionMadeBy >> 8; // Check if we have the DOS directory flag set.
  44159. // We look for it in the DOS and UNIX permissions
  44160. // but some unknown platform could set it as a compatibility flag.
  44161. this.dir = this.externalFileAttributes & 0x0010 ? true : false;
  44162. if (madeBy === MADE_BY_DOS) {
  44163. // first 6 bits (0 to 5)
  44164. this.dosPermissions = this.externalFileAttributes & 0x3F;
  44165. }
  44166. if (madeBy === MADE_BY_UNIX) {
  44167. this.unixPermissions = this.externalFileAttributes >> 16 & 0xFFFF; // the octal permissions are in (this.unixPermissions & 0x01FF).toString(8);
  44168. } // fail safe : if the name ends with a / it probably means a folder
  44169. if (!this.dir && this.fileNameStr.slice(-1) === '/') {
  44170. this.dir = true;
  44171. }
  44172. },
  44173. /**
  44174. * Parse the ZIP64 extra field and merge the info in the current ZipEntry.
  44175. * @param {DataReader} reader the reader to use.
  44176. */
  44177. parseZIP64ExtraField: function parseZIP64ExtraField(reader) {
  44178. if (!this.extraFields[0x0001]) {
  44179. return;
  44180. } // should be something, preparing the extra reader
  44181. var extraReader = readerFor(this.extraFields[0x0001].value); // I really hope that these 64bits integer can fit in 32 bits integer, because js
  44182. // won't let us have more.
  44183. if (this.uncompressedSize === utils.MAX_VALUE_32BITS) {
  44184. this.uncompressedSize = extraReader.readInt(8);
  44185. }
  44186. if (this.compressedSize === utils.MAX_VALUE_32BITS) {
  44187. this.compressedSize = extraReader.readInt(8);
  44188. }
  44189. if (this.localHeaderOffset === utils.MAX_VALUE_32BITS) {
  44190. this.localHeaderOffset = extraReader.readInt(8);
  44191. }
  44192. if (this.diskNumberStart === utils.MAX_VALUE_32BITS) {
  44193. this.diskNumberStart = extraReader.readInt(4);
  44194. }
  44195. },
  44196. /**
  44197. * Read the central part of a zip file and add the info in this object.
  44198. * @param {DataReader} reader the reader to use.
  44199. */
  44200. readExtraFields: function readExtraFields(reader) {
  44201. var end = reader.index + this.extraFieldsLength,
  44202. extraFieldId,
  44203. extraFieldLength,
  44204. extraFieldValue;
  44205. if (!this.extraFields) {
  44206. this.extraFields = {};
  44207. }
  44208. while (reader.index + 4 < end) {
  44209. extraFieldId = reader.readInt(2);
  44210. extraFieldLength = reader.readInt(2);
  44211. extraFieldValue = reader.readData(extraFieldLength);
  44212. this.extraFields[extraFieldId] = {
  44213. id: extraFieldId,
  44214. length: extraFieldLength,
  44215. value: extraFieldValue
  44216. };
  44217. }
  44218. reader.setIndex(end);
  44219. },
  44220. /**
  44221. * Apply an UTF8 transformation if needed.
  44222. */
  44223. handleUTF8: function handleUTF8() {
  44224. var decodeParamType = support.uint8array ? "uint8array" : "array";
  44225. if (this.useUTF8()) {
  44226. this.fileNameStr = utf8.utf8decode(this.fileName);
  44227. this.fileCommentStr = utf8.utf8decode(this.fileComment);
  44228. } else {
  44229. var upath = this.findExtraFieldUnicodePath();
  44230. if (upath !== null) {
  44231. this.fileNameStr = upath;
  44232. } else {
  44233. // ASCII text or unsupported code page
  44234. var fileNameByteArray = utils.transformTo(decodeParamType, this.fileName);
  44235. this.fileNameStr = this.loadOptions.decodeFileName(fileNameByteArray);
  44236. }
  44237. var ucomment = this.findExtraFieldUnicodeComment();
  44238. if (ucomment !== null) {
  44239. this.fileCommentStr = ucomment;
  44240. } else {
  44241. // ASCII text or unsupported code page
  44242. var commentByteArray = utils.transformTo(decodeParamType, this.fileComment);
  44243. this.fileCommentStr = this.loadOptions.decodeFileName(commentByteArray);
  44244. }
  44245. }
  44246. },
  44247. /**
  44248. * Find the unicode path declared in the extra field, if any.
  44249. * @return {String} the unicode path, null otherwise.
  44250. */
  44251. findExtraFieldUnicodePath: function findExtraFieldUnicodePath() {
  44252. var upathField = this.extraFields[0x7075];
  44253. if (upathField) {
  44254. var extraReader = readerFor(upathField.value); // wrong version
  44255. if (extraReader.readInt(1) !== 1) {
  44256. return null;
  44257. } // the crc of the filename changed, this field is out of date.
  44258. if (crc32fn(this.fileName) !== extraReader.readInt(4)) {
  44259. return null;
  44260. }
  44261. return utf8.utf8decode(extraReader.readData(upathField.length - 5));
  44262. }
  44263. return null;
  44264. },
  44265. /**
  44266. * Find the unicode comment declared in the extra field, if any.
  44267. * @return {String} the unicode comment, null otherwise.
  44268. */
  44269. findExtraFieldUnicodeComment: function findExtraFieldUnicodeComment() {
  44270. var ucommentField = this.extraFields[0x6375];
  44271. if (ucommentField) {
  44272. var extraReader = readerFor(ucommentField.value); // wrong version
  44273. if (extraReader.readInt(1) !== 1) {
  44274. return null;
  44275. } // the crc of the comment changed, this field is out of date.
  44276. if (crc32fn(this.fileComment) !== extraReader.readInt(4)) {
  44277. return null;
  44278. }
  44279. return utf8.utf8decode(extraReader.readData(ucommentField.length - 5));
  44280. }
  44281. return null;
  44282. }
  44283. };
  44284. module.exports = ZipEntry;
  44285. },{"./compressedObject":391,"./compressions":392,"./crc32":393,"./reader/readerFor":411,"./support":419,"./utf8":420,"./utils":421}],424:[function(require,module,exports){
  44286. 'use strict';
  44287. var StreamHelper = require('./stream/StreamHelper');
  44288. var DataWorker = require('./stream/DataWorker');
  44289. var utf8 = require('./utf8');
  44290. var CompressedObject = require('./compressedObject');
  44291. var GenericWorker = require('./stream/GenericWorker');
  44292. /**
  44293. * A simple object representing a file in the zip file.
  44294. * @constructor
  44295. * @param {string} name the name of the file
  44296. * @param {String|ArrayBuffer|Uint8Array|Buffer} data the data
  44297. * @param {Object} options the options of the file
  44298. */
  44299. var ZipObject = function ZipObject(name, data, options) {
  44300. this.name = name;
  44301. this.dir = options.dir;
  44302. this.date = options.date;
  44303. this.comment = options.comment;
  44304. this.unixPermissions = options.unixPermissions;
  44305. this.dosPermissions = options.dosPermissions;
  44306. this._data = data;
  44307. this._dataBinary = options.binary; // keep only the compression
  44308. this.options = {
  44309. compression: options.compression,
  44310. compressionOptions: options.compressionOptions
  44311. };
  44312. };
  44313. ZipObject.prototype = {
  44314. /**
  44315. * Create an internal stream for the content of this object.
  44316. * @param {String} type the type of each chunk.
  44317. * @return StreamHelper the stream.
  44318. */
  44319. internalStream: function internalStream(type) {
  44320. var result = null,
  44321. outputType = "string";
  44322. try {
  44323. if (!type) {
  44324. throw new Error("No output type specified.");
  44325. }
  44326. outputType = type.toLowerCase();
  44327. var askUnicodeString = outputType === "string" || outputType === "text";
  44328. if (outputType === "binarystring" || outputType === "text") {
  44329. outputType = "string";
  44330. }
  44331. result = this._decompressWorker();
  44332. var isUnicodeString = !this._dataBinary;
  44333. if (isUnicodeString && !askUnicodeString) {
  44334. result = result.pipe(new utf8.Utf8EncodeWorker());
  44335. }
  44336. if (!isUnicodeString && askUnicodeString) {
  44337. result = result.pipe(new utf8.Utf8DecodeWorker());
  44338. }
  44339. } catch (e) {
  44340. result = new GenericWorker("error");
  44341. result.error(e);
  44342. }
  44343. return new StreamHelper(result, outputType, "");
  44344. },
  44345. /**
  44346. * Prepare the content in the asked type.
  44347. * @param {String} type the type of the result.
  44348. * @param {Function} onUpdate a function to call on each internal update.
  44349. * @return Promise the promise of the result.
  44350. */
  44351. async: function async(type, onUpdate) {
  44352. return this.internalStream(type).accumulate(onUpdate);
  44353. },
  44354. /**
  44355. * Prepare the content as a nodejs stream.
  44356. * @param {String} type the type of each chunk.
  44357. * @param {Function} onUpdate a function to call on each internal update.
  44358. * @return Stream the stream.
  44359. */
  44360. nodeStream: function nodeStream(type, onUpdate) {
  44361. return this.internalStream(type || "nodebuffer").toNodejsStream(onUpdate);
  44362. },
  44363. /**
  44364. * Return a worker for the compressed content.
  44365. * @private
  44366. * @param {Object} compression the compression object to use.
  44367. * @param {Object} compressionOptions the options to use when compressing.
  44368. * @return Worker the worker.
  44369. */
  44370. _compressWorker: function _compressWorker(compression, compressionOptions) {
  44371. if (this._data instanceof CompressedObject && this._data.compression.magic === compression.magic) {
  44372. return this._data.getCompressedWorker();
  44373. } else {
  44374. var result = this._decompressWorker();
  44375. if (!this._dataBinary) {
  44376. result = result.pipe(new utf8.Utf8EncodeWorker());
  44377. }
  44378. return CompressedObject.createWorkerFrom(result, compression, compressionOptions);
  44379. }
  44380. },
  44381. /**
  44382. * Return a worker for the decompressed content.
  44383. * @private
  44384. * @return Worker the worker.
  44385. */
  44386. _decompressWorker: function _decompressWorker() {
  44387. if (this._data instanceof CompressedObject) {
  44388. return this._data.getContentWorker();
  44389. } else if (this._data instanceof GenericWorker) {
  44390. return this._data;
  44391. } else {
  44392. return new DataWorker(this._data);
  44393. }
  44394. }
  44395. };
  44396. var removedMethods = ["asText", "asBinary", "asNodeBuffer", "asUint8Array", "asArrayBuffer"];
  44397. var removedFn = function removedFn() {
  44398. throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.");
  44399. };
  44400. for (var i = 0; i < removedMethods.length; i++) {
  44401. ZipObject.prototype[removedMethods[i]] = removedFn;
  44402. }
  44403. module.exports = ZipObject;
  44404. },{"./compressedObject":391,"./stream/DataWorker":416,"./stream/GenericWorker":417,"./stream/StreamHelper":418,"./utf8":420}],425:[function(require,module,exports){
  44405. 'use strict';
  44406. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  44407. var immediate = require('immediate');
  44408. /* istanbul ignore next */
  44409. function INTERNAL() {}
  44410. var handlers = {};
  44411. var REJECTED = ['REJECTED'];
  44412. var FULFILLED = ['FULFILLED'];
  44413. var PENDING = ['PENDING'];
  44414. module.exports = Promise;
  44415. function Promise(resolver) {
  44416. if (typeof resolver !== 'function') {
  44417. throw new TypeError('resolver must be a function');
  44418. }
  44419. this.state = PENDING;
  44420. this.queue = [];
  44421. this.outcome = void 0;
  44422. if (resolver !== INTERNAL) {
  44423. safelyResolveThenable(this, resolver);
  44424. }
  44425. }
  44426. Promise.prototype["finally"] = function (callback) {
  44427. if (typeof callback !== 'function') {
  44428. return this;
  44429. }
  44430. var p = this.constructor;
  44431. return this.then(resolve, reject);
  44432. function resolve(value) {
  44433. function yes() {
  44434. return value;
  44435. }
  44436. return p.resolve(callback()).then(yes);
  44437. }
  44438. function reject(reason) {
  44439. function no() {
  44440. throw reason;
  44441. }
  44442. return p.resolve(callback()).then(no);
  44443. }
  44444. };
  44445. Promise.prototype["catch"] = function (onRejected) {
  44446. return this.then(null, onRejected);
  44447. };
  44448. Promise.prototype.then = function (onFulfilled, onRejected) {
  44449. if (typeof onFulfilled !== 'function' && this.state === FULFILLED || typeof onRejected !== 'function' && this.state === REJECTED) {
  44450. return this;
  44451. }
  44452. var promise = new this.constructor(INTERNAL);
  44453. if (this.state !== PENDING) {
  44454. var resolver = this.state === FULFILLED ? onFulfilled : onRejected;
  44455. unwrap(promise, resolver, this.outcome);
  44456. } else {
  44457. this.queue.push(new QueueItem(promise, onFulfilled, onRejected));
  44458. }
  44459. return promise;
  44460. };
  44461. function QueueItem(promise, onFulfilled, onRejected) {
  44462. this.promise = promise;
  44463. if (typeof onFulfilled === 'function') {
  44464. this.onFulfilled = onFulfilled;
  44465. this.callFulfilled = this.otherCallFulfilled;
  44466. }
  44467. if (typeof onRejected === 'function') {
  44468. this.onRejected = onRejected;
  44469. this.callRejected = this.otherCallRejected;
  44470. }
  44471. }
  44472. QueueItem.prototype.callFulfilled = function (value) {
  44473. handlers.resolve(this.promise, value);
  44474. };
  44475. QueueItem.prototype.otherCallFulfilled = function (value) {
  44476. unwrap(this.promise, this.onFulfilled, value);
  44477. };
  44478. QueueItem.prototype.callRejected = function (value) {
  44479. handlers.reject(this.promise, value);
  44480. };
  44481. QueueItem.prototype.otherCallRejected = function (value) {
  44482. unwrap(this.promise, this.onRejected, value);
  44483. };
  44484. function unwrap(promise, func, value) {
  44485. immediate(function () {
  44486. var returnValue;
  44487. try {
  44488. returnValue = func(value);
  44489. } catch (e) {
  44490. return handlers.reject(promise, e);
  44491. }
  44492. if (returnValue === promise) {
  44493. handlers.reject(promise, new TypeError('Cannot resolve promise with itself'));
  44494. } else {
  44495. handlers.resolve(promise, returnValue);
  44496. }
  44497. });
  44498. }
  44499. handlers.resolve = function (self, value) {
  44500. var result = tryCatch(getThen, value);
  44501. if (result.status === 'error') {
  44502. return handlers.reject(self, result.value);
  44503. }
  44504. var thenable = result.value;
  44505. if (thenable) {
  44506. safelyResolveThenable(self, thenable);
  44507. } else {
  44508. self.state = FULFILLED;
  44509. self.outcome = value;
  44510. var i = -1;
  44511. var len = self.queue.length;
  44512. while (++i < len) {
  44513. self.queue[i].callFulfilled(value);
  44514. }
  44515. }
  44516. return self;
  44517. };
  44518. handlers.reject = function (self, error) {
  44519. self.state = REJECTED;
  44520. self.outcome = error;
  44521. var i = -1;
  44522. var len = self.queue.length;
  44523. while (++i < len) {
  44524. self.queue[i].callRejected(error);
  44525. }
  44526. return self;
  44527. };
  44528. function getThen(obj) {
  44529. // Make sure we only access the accessor once as required by the spec
  44530. var then = obj && obj.then;
  44531. if (obj && (_typeof(obj) === 'object' || typeof obj === 'function') && typeof then === 'function') {
  44532. return function appyThen() {
  44533. then.apply(obj, arguments);
  44534. };
  44535. }
  44536. }
  44537. function safelyResolveThenable(self, thenable) {
  44538. // Either fulfill, reject or reject with error
  44539. var called = false;
  44540. function onError(value) {
  44541. if (called) {
  44542. return;
  44543. }
  44544. called = true;
  44545. handlers.reject(self, value);
  44546. }
  44547. function onSuccess(value) {
  44548. if (called) {
  44549. return;
  44550. }
  44551. called = true;
  44552. handlers.resolve(self, value);
  44553. }
  44554. function tryToUnwrap() {
  44555. thenable(onSuccess, onError);
  44556. }
  44557. var result = tryCatch(tryToUnwrap);
  44558. if (result.status === 'error') {
  44559. onError(result.value);
  44560. }
  44561. }
  44562. function tryCatch(func, value) {
  44563. var out = {};
  44564. try {
  44565. out.value = func(value);
  44566. out.status = 'success';
  44567. } catch (e) {
  44568. out.status = 'error';
  44569. out.value = e;
  44570. }
  44571. return out;
  44572. }
  44573. Promise.resolve = resolve;
  44574. function resolve(value) {
  44575. if (value instanceof this) {
  44576. return value;
  44577. }
  44578. return handlers.resolve(new this(INTERNAL), value);
  44579. }
  44580. Promise.reject = reject;
  44581. function reject(reason) {
  44582. var promise = new this(INTERNAL);
  44583. return handlers.reject(promise, reason);
  44584. }
  44585. Promise.all = all;
  44586. function all(iterable) {
  44587. var self = this;
  44588. if (Object.prototype.toString.call(iterable) !== '[object Array]') {
  44589. return this.reject(new TypeError('must be an array'));
  44590. }
  44591. var len = iterable.length;
  44592. var called = false;
  44593. if (!len) {
  44594. return this.resolve([]);
  44595. }
  44596. var values = new Array(len);
  44597. var resolved = 0;
  44598. var i = -1;
  44599. var promise = new this(INTERNAL);
  44600. while (++i < len) {
  44601. allResolver(iterable[i], i);
  44602. }
  44603. return promise;
  44604. function allResolver(value, i) {
  44605. self.resolve(value).then(resolveFromAll, function (error) {
  44606. if (!called) {
  44607. called = true;
  44608. handlers.reject(promise, error);
  44609. }
  44610. });
  44611. function resolveFromAll(outValue) {
  44612. values[i] = outValue;
  44613. if (++resolved === len && !called) {
  44614. called = true;
  44615. handlers.resolve(promise, values);
  44616. }
  44617. }
  44618. }
  44619. }
  44620. Promise.race = race;
  44621. function race(iterable) {
  44622. var self = this;
  44623. if (Object.prototype.toString.call(iterable) !== '[object Array]') {
  44624. return this.reject(new TypeError('must be an array'));
  44625. }
  44626. var len = iterable.length;
  44627. var called = false;
  44628. if (!len) {
  44629. return this.resolve([]);
  44630. }
  44631. var i = -1;
  44632. var promise = new this(INTERNAL);
  44633. while (++i < len) {
  44634. resolver(iterable[i]);
  44635. }
  44636. return promise;
  44637. function resolver(value) {
  44638. self.resolve(value).then(function (response) {
  44639. if (!called) {
  44640. called = true;
  44641. handlers.resolve(promise, response);
  44642. }
  44643. }, function (error) {
  44644. if (!called) {
  44645. called = true;
  44646. handlers.reject(promise, error);
  44647. }
  44648. });
  44649. }
  44650. }
  44651. },{"immediate":386}],426:[function(require,module,exports){
  44652. (function (global){
  44653. "use strict";
  44654. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  44655. /**
  44656. * lodash (Custom Build) <https://lodash.com/>
  44657. * Build: `lodash modularize exports="npm" -o ./`
  44658. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  44659. * Released under MIT license <https://lodash.com/license>
  44660. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  44661. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  44662. */
  44663. /** Used as references for various `Number` constants. */
  44664. var INFINITY = 1 / 0;
  44665. /** `Object#toString` result references. */
  44666. var symbolTag = '[object Symbol]';
  44667. /**
  44668. * Used to match `RegExp`
  44669. * [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns).
  44670. */
  44671. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  44672. reHasRegExpChar = RegExp(reRegExpChar.source);
  44673. /** Detect free variable `global` from Node.js. */
  44674. var freeGlobal = (typeof global === "undefined" ? "undefined" : _typeof(global)) == 'object' && global && global.Object === Object && global;
  44675. /** Detect free variable `self`. */
  44676. var freeSelf = (typeof self === "undefined" ? "undefined" : _typeof(self)) == 'object' && self && self.Object === Object && self;
  44677. /** Used as a reference to the global object. */
  44678. var root = freeGlobal || freeSelf || Function('return this')();
  44679. /** Used for built-in method references. */
  44680. var objectProto = Object.prototype;
  44681. /**
  44682. * Used to resolve the
  44683. * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  44684. * of values.
  44685. */
  44686. var objectToString = objectProto.toString;
  44687. /** Built-in value references. */
  44688. var _Symbol = root.Symbol;
  44689. /** Used to convert symbols to primitives and strings. */
  44690. var symbolProto = _Symbol ? _Symbol.prototype : undefined,
  44691. symbolToString = symbolProto ? symbolProto.toString : undefined;
  44692. /**
  44693. * The base implementation of `_.toString` which doesn't convert nullish
  44694. * values to empty strings.
  44695. *
  44696. * @private
  44697. * @param {*} value The value to process.
  44698. * @returns {string} Returns the string.
  44699. */
  44700. function baseToString(value) {
  44701. // Exit early for strings to avoid a performance hit in some environments.
  44702. if (typeof value == 'string') {
  44703. return value;
  44704. }
  44705. if (isSymbol(value)) {
  44706. return symbolToString ? symbolToString.call(value) : '';
  44707. }
  44708. var result = value + '';
  44709. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  44710. }
  44711. /**
  44712. * Checks if `value` is object-like. A value is object-like if it's not `null`
  44713. * and has a `typeof` result of "object".
  44714. *
  44715. * @static
  44716. * @memberOf _
  44717. * @since 4.0.0
  44718. * @category Lang
  44719. * @param {*} value The value to check.
  44720. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  44721. * @example
  44722. *
  44723. * _.isObjectLike({});
  44724. * // => true
  44725. *
  44726. * _.isObjectLike([1, 2, 3]);
  44727. * // => true
  44728. *
  44729. * _.isObjectLike(_.noop);
  44730. * // => false
  44731. *
  44732. * _.isObjectLike(null);
  44733. * // => false
  44734. */
  44735. function isObjectLike(value) {
  44736. return !!value && _typeof(value) == 'object';
  44737. }
  44738. /**
  44739. * Checks if `value` is classified as a `Symbol` primitive or object.
  44740. *
  44741. * @static
  44742. * @memberOf _
  44743. * @since 4.0.0
  44744. * @category Lang
  44745. * @param {*} value The value to check.
  44746. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  44747. * @example
  44748. *
  44749. * _.isSymbol(Symbol.iterator);
  44750. * // => true
  44751. *
  44752. * _.isSymbol('abc');
  44753. * // => false
  44754. */
  44755. function isSymbol(value) {
  44756. return _typeof(value) == 'symbol' || isObjectLike(value) && objectToString.call(value) == symbolTag;
  44757. }
  44758. /**
  44759. * Converts `value` to a string. An empty string is returned for `null`
  44760. * and `undefined` values. The sign of `-0` is preserved.
  44761. *
  44762. * @static
  44763. * @memberOf _
  44764. * @since 4.0.0
  44765. * @category Lang
  44766. * @param {*} value The value to process.
  44767. * @returns {string} Returns the string.
  44768. * @example
  44769. *
  44770. * _.toString(null);
  44771. * // => ''
  44772. *
  44773. * _.toString(-0);
  44774. * // => '-0'
  44775. *
  44776. * _.toString([1, 2, 3]);
  44777. * // => '1,2,3'
  44778. */
  44779. function toString(value) {
  44780. return value == null ? '' : baseToString(value);
  44781. }
  44782. /**
  44783. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  44784. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  44785. *
  44786. * @static
  44787. * @memberOf _
  44788. * @since 3.0.0
  44789. * @category String
  44790. * @param {string} [string=''] The string to escape.
  44791. * @returns {string} Returns the escaped string.
  44792. * @example
  44793. *
  44794. * _.escapeRegExp('[lodash](https://lodash.com/)');
  44795. * // => '\[lodash\]\(https://lodash\.com/\)'
  44796. */
  44797. function escapeRegExp(string) {
  44798. string = toString(string);
  44799. return string && reHasRegExpChar.test(string) ? string.replace(reRegExpChar, '\\$&') : string;
  44800. }
  44801. module.exports = escapeRegExp;
  44802. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  44803. },{}],427:[function(require,module,exports){
  44804. (function (global){
  44805. "use strict";
  44806. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  44807. /**
  44808. * lodash (Custom Build) <https://lodash.com/>
  44809. * Build: `lodash modularize exports="npm" -o ./`
  44810. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  44811. * Released under MIT license <https://lodash.com/license>
  44812. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  44813. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  44814. */
  44815. /** Used as the size to enable large array optimizations. */
  44816. var LARGE_ARRAY_SIZE = 200;
  44817. /** Used as the `TypeError` message for "Functions" methods. */
  44818. var FUNC_ERROR_TEXT = 'Expected a function';
  44819. /** Used to stand-in for `undefined` hash values. */
  44820. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  44821. /** Used to compose bitmasks for comparison styles. */
  44822. var UNORDERED_COMPARE_FLAG = 1,
  44823. PARTIAL_COMPARE_FLAG = 2;
  44824. /** Used as references for various `Number` constants. */
  44825. var INFINITY = 1 / 0,
  44826. MAX_SAFE_INTEGER = 9007199254740991;
  44827. /** `Object#toString` result references. */
  44828. var argsTag = '[object Arguments]',
  44829. arrayTag = '[object Array]',
  44830. boolTag = '[object Boolean]',
  44831. dateTag = '[object Date]',
  44832. errorTag = '[object Error]',
  44833. funcTag = '[object Function]',
  44834. genTag = '[object GeneratorFunction]',
  44835. mapTag = '[object Map]',
  44836. numberTag = '[object Number]',
  44837. objectTag = '[object Object]',
  44838. promiseTag = '[object Promise]',
  44839. regexpTag = '[object RegExp]',
  44840. setTag = '[object Set]',
  44841. stringTag = '[object String]',
  44842. symbolTag = '[object Symbol]',
  44843. weakMapTag = '[object WeakMap]';
  44844. var arrayBufferTag = '[object ArrayBuffer]',
  44845. dataViewTag = '[object DataView]',
  44846. float32Tag = '[object Float32Array]',
  44847. float64Tag = '[object Float64Array]',
  44848. int8Tag = '[object Int8Array]',
  44849. int16Tag = '[object Int16Array]',
  44850. int32Tag = '[object Int32Array]',
  44851. uint8Tag = '[object Uint8Array]',
  44852. uint8ClampedTag = '[object Uint8ClampedArray]',
  44853. uint16Tag = '[object Uint16Array]',
  44854. uint32Tag = '[object Uint32Array]';
  44855. /** Used to match property names within property paths. */
  44856. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  44857. reIsPlainProp = /^\w*$/,
  44858. reLeadingDot = /^\./,
  44859. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  44860. /**
  44861. * Used to match `RegExp`
  44862. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  44863. */
  44864. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  44865. /** Used to match backslashes in property paths. */
  44866. var reEscapeChar = /\\(\\)?/g;
  44867. /** Used to detect host constructors (Safari). */
  44868. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  44869. /** Used to detect unsigned integer values. */
  44870. var reIsUint = /^(?:0|[1-9]\d*)$/;
  44871. /** Used to identify `toStringTag` values of typed arrays. */
  44872. var typedArrayTags = {};
  44873. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = typedArrayTags[uint32Tag] = true;
  44874. 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;
  44875. /** Detect free variable `global` from Node.js. */
  44876. var freeGlobal = (typeof global === "undefined" ? "undefined" : _typeof(global)) == 'object' && global && global.Object === Object && global;
  44877. /** Detect free variable `self`. */
  44878. var freeSelf = (typeof self === "undefined" ? "undefined" : _typeof(self)) == 'object' && self && self.Object === Object && self;
  44879. /** Used as a reference to the global object. */
  44880. var root = freeGlobal || freeSelf || Function('return this')();
  44881. /** Detect free variable `exports`. */
  44882. var freeExports = (typeof exports === "undefined" ? "undefined" : _typeof(exports)) == 'object' && exports && !exports.nodeType && exports;
  44883. /** Detect free variable `module`. */
  44884. var freeModule = freeExports && (typeof module === "undefined" ? "undefined" : _typeof(module)) == 'object' && module && !module.nodeType && module;
  44885. /** Detect the popular CommonJS extension `module.exports`. */
  44886. var moduleExports = freeModule && freeModule.exports === freeExports;
  44887. /** Detect free variable `process` from Node.js. */
  44888. var freeProcess = moduleExports && freeGlobal.process;
  44889. /** Used to access faster Node.js helpers. */
  44890. var nodeUtil = function () {
  44891. try {
  44892. return freeProcess && freeProcess.binding('util');
  44893. } catch (e) {}
  44894. }();
  44895. /* Node.js helper references. */
  44896. var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  44897. /**
  44898. * A specialized version of `baseAggregator` for arrays.
  44899. *
  44900. * @private
  44901. * @param {Array} [array] The array to iterate over.
  44902. * @param {Function} setter The function to set `accumulator` values.
  44903. * @param {Function} iteratee The iteratee to transform keys.
  44904. * @param {Object} accumulator The initial aggregated object.
  44905. * @returns {Function} Returns `accumulator`.
  44906. */
  44907. function arrayAggregator(array, setter, iteratee, accumulator) {
  44908. var index = -1,
  44909. length = array ? array.length : 0;
  44910. while (++index < length) {
  44911. var value = array[index];
  44912. setter(accumulator, value, iteratee(value), array);
  44913. }
  44914. return accumulator;
  44915. }
  44916. /**
  44917. * A specialized version of `_.some` for arrays without support for iteratee
  44918. * shorthands.
  44919. *
  44920. * @private
  44921. * @param {Array} [array] The array to iterate over.
  44922. * @param {Function} predicate The function invoked per iteration.
  44923. * @returns {boolean} Returns `true` if any element passes the predicate check,
  44924. * else `false`.
  44925. */
  44926. function arraySome(array, predicate) {
  44927. var index = -1,
  44928. length = array ? array.length : 0;
  44929. while (++index < length) {
  44930. if (predicate(array[index], index, array)) {
  44931. return true;
  44932. }
  44933. }
  44934. return false;
  44935. }
  44936. /**
  44937. * The base implementation of `_.property` without support for deep paths.
  44938. *
  44939. * @private
  44940. * @param {string} key The key of the property to get.
  44941. * @returns {Function} Returns the new accessor function.
  44942. */
  44943. function baseProperty(key) {
  44944. return function (object) {
  44945. return object == null ? undefined : object[key];
  44946. };
  44947. }
  44948. /**
  44949. * The base implementation of `_.times` without support for iteratee shorthands
  44950. * or max array length checks.
  44951. *
  44952. * @private
  44953. * @param {number} n The number of times to invoke `iteratee`.
  44954. * @param {Function} iteratee The function invoked per iteration.
  44955. * @returns {Array} Returns the array of results.
  44956. */
  44957. function baseTimes(n, iteratee) {
  44958. var index = -1,
  44959. result = Array(n);
  44960. while (++index < n) {
  44961. result[index] = iteratee(index);
  44962. }
  44963. return result;
  44964. }
  44965. /**
  44966. * The base implementation of `_.unary` without support for storing metadata.
  44967. *
  44968. * @private
  44969. * @param {Function} func The function to cap arguments for.
  44970. * @returns {Function} Returns the new capped function.
  44971. */
  44972. function baseUnary(func) {
  44973. return function (value) {
  44974. return func(value);
  44975. };
  44976. }
  44977. /**
  44978. * Gets the value at `key` of `object`.
  44979. *
  44980. * @private
  44981. * @param {Object} [object] The object to query.
  44982. * @param {string} key The key of the property to get.
  44983. * @returns {*} Returns the property value.
  44984. */
  44985. function getValue(object, key) {
  44986. return object == null ? undefined : object[key];
  44987. }
  44988. /**
  44989. * Checks if `value` is a host object in IE < 9.
  44990. *
  44991. * @private
  44992. * @param {*} value The value to check.
  44993. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  44994. */
  44995. function isHostObject(value) {
  44996. // Many host objects are `Object` objects that can coerce to strings
  44997. // despite having improperly defined `toString` methods.
  44998. var result = false;
  44999. if (value != null && typeof value.toString != 'function') {
  45000. try {
  45001. result = !!(value + '');
  45002. } catch (e) {}
  45003. }
  45004. return result;
  45005. }
  45006. /**
  45007. * Converts `map` to its key-value pairs.
  45008. *
  45009. * @private
  45010. * @param {Object} map The map to convert.
  45011. * @returns {Array} Returns the key-value pairs.
  45012. */
  45013. function mapToArray(map) {
  45014. var index = -1,
  45015. result = Array(map.size);
  45016. map.forEach(function (value, key) {
  45017. result[++index] = [key, value];
  45018. });
  45019. return result;
  45020. }
  45021. /**
  45022. * Creates a unary function that invokes `func` with its argument transformed.
  45023. *
  45024. * @private
  45025. * @param {Function} func The function to wrap.
  45026. * @param {Function} transform The argument transform.
  45027. * @returns {Function} Returns the new function.
  45028. */
  45029. function overArg(func, transform) {
  45030. return function (arg) {
  45031. return func(transform(arg));
  45032. };
  45033. }
  45034. /**
  45035. * Converts `set` to an array of its values.
  45036. *
  45037. * @private
  45038. * @param {Object} set The set to convert.
  45039. * @returns {Array} Returns the values.
  45040. */
  45041. function setToArray(set) {
  45042. var index = -1,
  45043. result = Array(set.size);
  45044. set.forEach(function (value) {
  45045. result[++index] = value;
  45046. });
  45047. return result;
  45048. }
  45049. /** Used for built-in method references. */
  45050. var arrayProto = Array.prototype,
  45051. funcProto = Function.prototype,
  45052. objectProto = Object.prototype;
  45053. /** Used to detect overreaching core-js shims. */
  45054. var coreJsData = root['__core-js_shared__'];
  45055. /** Used to detect methods masquerading as native. */
  45056. var maskSrcKey = function () {
  45057. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  45058. return uid ? 'Symbol(src)_1.' + uid : '';
  45059. }();
  45060. /** Used to resolve the decompiled source of functions. */
  45061. var funcToString = funcProto.toString;
  45062. /** Used to check objects for own properties. */
  45063. var hasOwnProperty = objectProto.hasOwnProperty;
  45064. /**
  45065. * Used to resolve the
  45066. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  45067. * of values.
  45068. */
  45069. var objectToString = objectProto.toString;
  45070. /** Used to detect if a method is native. */
  45071. var reIsNative = RegExp('^' + funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
  45072. /** Built-in value references. */
  45073. var _Symbol = root.Symbol,
  45074. Uint8Array = root.Uint8Array,
  45075. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  45076. splice = arrayProto.splice;
  45077. /* Built-in method references for those with the same name as other `lodash` methods. */
  45078. var nativeKeys = overArg(Object.keys, Object);
  45079. /* Built-in method references that are verified to be native. */
  45080. var DataView = getNative(root, 'DataView'),
  45081. Map = getNative(root, 'Map'),
  45082. Promise = getNative(root, 'Promise'),
  45083. Set = getNative(root, 'Set'),
  45084. WeakMap = getNative(root, 'WeakMap'),
  45085. nativeCreate = getNative(Object, 'create');
  45086. /** Used to detect maps, sets, and weakmaps. */
  45087. var dataViewCtorString = toSource(DataView),
  45088. mapCtorString = toSource(Map),
  45089. promiseCtorString = toSource(Promise),
  45090. setCtorString = toSource(Set),
  45091. weakMapCtorString = toSource(WeakMap);
  45092. /** Used to convert symbols to primitives and strings. */
  45093. var symbolProto = _Symbol ? _Symbol.prototype : undefined,
  45094. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  45095. symbolToString = symbolProto ? symbolProto.toString : undefined;
  45096. /**
  45097. * Creates a hash object.
  45098. *
  45099. * @private
  45100. * @constructor
  45101. * @param {Array} [entries] The key-value pairs to cache.
  45102. */
  45103. function Hash(entries) {
  45104. var index = -1,
  45105. length = entries ? entries.length : 0;
  45106. this.clear();
  45107. while (++index < length) {
  45108. var entry = entries[index];
  45109. this.set(entry[0], entry[1]);
  45110. }
  45111. }
  45112. /**
  45113. * Removes all key-value entries from the hash.
  45114. *
  45115. * @private
  45116. * @name clear
  45117. * @memberOf Hash
  45118. */
  45119. function hashClear() {
  45120. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  45121. }
  45122. /**
  45123. * Removes `key` and its value from the hash.
  45124. *
  45125. * @private
  45126. * @name delete
  45127. * @memberOf Hash
  45128. * @param {Object} hash The hash to modify.
  45129. * @param {string} key The key of the value to remove.
  45130. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  45131. */
  45132. function hashDelete(key) {
  45133. return this.has(key) && delete this.__data__[key];
  45134. }
  45135. /**
  45136. * Gets the hash value for `key`.
  45137. *
  45138. * @private
  45139. * @name get
  45140. * @memberOf Hash
  45141. * @param {string} key The key of the value to get.
  45142. * @returns {*} Returns the entry value.
  45143. */
  45144. function hashGet(key) {
  45145. var data = this.__data__;
  45146. if (nativeCreate) {
  45147. var result = data[key];
  45148. return result === HASH_UNDEFINED ? undefined : result;
  45149. }
  45150. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  45151. }
  45152. /**
  45153. * Checks if a hash value for `key` exists.
  45154. *
  45155. * @private
  45156. * @name has
  45157. * @memberOf Hash
  45158. * @param {string} key The key of the entry to check.
  45159. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  45160. */
  45161. function hashHas(key) {
  45162. var data = this.__data__;
  45163. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  45164. }
  45165. /**
  45166. * Sets the hash `key` to `value`.
  45167. *
  45168. * @private
  45169. * @name set
  45170. * @memberOf Hash
  45171. * @param {string} key The key of the value to set.
  45172. * @param {*} value The value to set.
  45173. * @returns {Object} Returns the hash instance.
  45174. */
  45175. function hashSet(key, value) {
  45176. var data = this.__data__;
  45177. data[key] = nativeCreate && value === undefined ? HASH_UNDEFINED : value;
  45178. return this;
  45179. } // Add methods to `Hash`.
  45180. Hash.prototype.clear = hashClear;
  45181. Hash.prototype['delete'] = hashDelete;
  45182. Hash.prototype.get = hashGet;
  45183. Hash.prototype.has = hashHas;
  45184. Hash.prototype.set = hashSet;
  45185. /**
  45186. * Creates an list cache object.
  45187. *
  45188. * @private
  45189. * @constructor
  45190. * @param {Array} [entries] The key-value pairs to cache.
  45191. */
  45192. function ListCache(entries) {
  45193. var index = -1,
  45194. length = entries ? entries.length : 0;
  45195. this.clear();
  45196. while (++index < length) {
  45197. var entry = entries[index];
  45198. this.set(entry[0], entry[1]);
  45199. }
  45200. }
  45201. /**
  45202. * Removes all key-value entries from the list cache.
  45203. *
  45204. * @private
  45205. * @name clear
  45206. * @memberOf ListCache
  45207. */
  45208. function listCacheClear() {
  45209. this.__data__ = [];
  45210. }
  45211. /**
  45212. * Removes `key` and its value from the list cache.
  45213. *
  45214. * @private
  45215. * @name delete
  45216. * @memberOf ListCache
  45217. * @param {string} key The key of the value to remove.
  45218. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  45219. */
  45220. function listCacheDelete(key) {
  45221. var data = this.__data__,
  45222. index = assocIndexOf(data, key);
  45223. if (index < 0) {
  45224. return false;
  45225. }
  45226. var lastIndex = data.length - 1;
  45227. if (index == lastIndex) {
  45228. data.pop();
  45229. } else {
  45230. splice.call(data, index, 1);
  45231. }
  45232. return true;
  45233. }
  45234. /**
  45235. * Gets the list cache value for `key`.
  45236. *
  45237. * @private
  45238. * @name get
  45239. * @memberOf ListCache
  45240. * @param {string} key The key of the value to get.
  45241. * @returns {*} Returns the entry value.
  45242. */
  45243. function listCacheGet(key) {
  45244. var data = this.__data__,
  45245. index = assocIndexOf(data, key);
  45246. return index < 0 ? undefined : data[index][1];
  45247. }
  45248. /**
  45249. * Checks if a list cache value for `key` exists.
  45250. *
  45251. * @private
  45252. * @name has
  45253. * @memberOf ListCache
  45254. * @param {string} key The key of the entry to check.
  45255. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  45256. */
  45257. function listCacheHas(key) {
  45258. return assocIndexOf(this.__data__, key) > -1;
  45259. }
  45260. /**
  45261. * Sets the list cache `key` to `value`.
  45262. *
  45263. * @private
  45264. * @name set
  45265. * @memberOf ListCache
  45266. * @param {string} key The key of the value to set.
  45267. * @param {*} value The value to set.
  45268. * @returns {Object} Returns the list cache instance.
  45269. */
  45270. function listCacheSet(key, value) {
  45271. var data = this.__data__,
  45272. index = assocIndexOf(data, key);
  45273. if (index < 0) {
  45274. data.push([key, value]);
  45275. } else {
  45276. data[index][1] = value;
  45277. }
  45278. return this;
  45279. } // Add methods to `ListCache`.
  45280. ListCache.prototype.clear = listCacheClear;
  45281. ListCache.prototype['delete'] = listCacheDelete;
  45282. ListCache.prototype.get = listCacheGet;
  45283. ListCache.prototype.has = listCacheHas;
  45284. ListCache.prototype.set = listCacheSet;
  45285. /**
  45286. * Creates a map cache object to store key-value pairs.
  45287. *
  45288. * @private
  45289. * @constructor
  45290. * @param {Array} [entries] The key-value pairs to cache.
  45291. */
  45292. function MapCache(entries) {
  45293. var index = -1,
  45294. length = entries ? entries.length : 0;
  45295. this.clear();
  45296. while (++index < length) {
  45297. var entry = entries[index];
  45298. this.set(entry[0], entry[1]);
  45299. }
  45300. }
  45301. /**
  45302. * Removes all key-value entries from the map.
  45303. *
  45304. * @private
  45305. * @name clear
  45306. * @memberOf MapCache
  45307. */
  45308. function mapCacheClear() {
  45309. this.__data__ = {
  45310. 'hash': new Hash(),
  45311. 'map': new (Map || ListCache)(),
  45312. 'string': new Hash()
  45313. };
  45314. }
  45315. /**
  45316. * Removes `key` and its value from the map.
  45317. *
  45318. * @private
  45319. * @name delete
  45320. * @memberOf MapCache
  45321. * @param {string} key The key of the value to remove.
  45322. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  45323. */
  45324. function mapCacheDelete(key) {
  45325. return getMapData(this, key)['delete'](key);
  45326. }
  45327. /**
  45328. * Gets the map value for `key`.
  45329. *
  45330. * @private
  45331. * @name get
  45332. * @memberOf MapCache
  45333. * @param {string} key The key of the value to get.
  45334. * @returns {*} Returns the entry value.
  45335. */
  45336. function mapCacheGet(key) {
  45337. return getMapData(this, key).get(key);
  45338. }
  45339. /**
  45340. * Checks if a map value for `key` exists.
  45341. *
  45342. * @private
  45343. * @name has
  45344. * @memberOf MapCache
  45345. * @param {string} key The key of the entry to check.
  45346. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  45347. */
  45348. function mapCacheHas(key) {
  45349. return getMapData(this, key).has(key);
  45350. }
  45351. /**
  45352. * Sets the map `key` to `value`.
  45353. *
  45354. * @private
  45355. * @name set
  45356. * @memberOf MapCache
  45357. * @param {string} key The key of the value to set.
  45358. * @param {*} value The value to set.
  45359. * @returns {Object} Returns the map cache instance.
  45360. */
  45361. function mapCacheSet(key, value) {
  45362. getMapData(this, key).set(key, value);
  45363. return this;
  45364. } // Add methods to `MapCache`.
  45365. MapCache.prototype.clear = mapCacheClear;
  45366. MapCache.prototype['delete'] = mapCacheDelete;
  45367. MapCache.prototype.get = mapCacheGet;
  45368. MapCache.prototype.has = mapCacheHas;
  45369. MapCache.prototype.set = mapCacheSet;
  45370. /**
  45371. *
  45372. * Creates an array cache object to store unique values.
  45373. *
  45374. * @private
  45375. * @constructor
  45376. * @param {Array} [values] The values to cache.
  45377. */
  45378. function SetCache(values) {
  45379. var index = -1,
  45380. length = values ? values.length : 0;
  45381. this.__data__ = new MapCache();
  45382. while (++index < length) {
  45383. this.add(values[index]);
  45384. }
  45385. }
  45386. /**
  45387. * Adds `value` to the array cache.
  45388. *
  45389. * @private
  45390. * @name add
  45391. * @memberOf SetCache
  45392. * @alias push
  45393. * @param {*} value The value to cache.
  45394. * @returns {Object} Returns the cache instance.
  45395. */
  45396. function setCacheAdd(value) {
  45397. this.__data__.set(value, HASH_UNDEFINED);
  45398. return this;
  45399. }
  45400. /**
  45401. * Checks if `value` is in the array cache.
  45402. *
  45403. * @private
  45404. * @name has
  45405. * @memberOf SetCache
  45406. * @param {*} value The value to search for.
  45407. * @returns {number} Returns `true` if `value` is found, else `false`.
  45408. */
  45409. function setCacheHas(value) {
  45410. return this.__data__.has(value);
  45411. } // Add methods to `SetCache`.
  45412. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  45413. SetCache.prototype.has = setCacheHas;
  45414. /**
  45415. * Creates a stack cache object to store key-value pairs.
  45416. *
  45417. * @private
  45418. * @constructor
  45419. * @param {Array} [entries] The key-value pairs to cache.
  45420. */
  45421. function Stack(entries) {
  45422. this.__data__ = new ListCache(entries);
  45423. }
  45424. /**
  45425. * Removes all key-value entries from the stack.
  45426. *
  45427. * @private
  45428. * @name clear
  45429. * @memberOf Stack
  45430. */
  45431. function stackClear() {
  45432. this.__data__ = new ListCache();
  45433. }
  45434. /**
  45435. * Removes `key` and its value from the stack.
  45436. *
  45437. * @private
  45438. * @name delete
  45439. * @memberOf Stack
  45440. * @param {string} key The key of the value to remove.
  45441. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  45442. */
  45443. function stackDelete(key) {
  45444. return this.__data__['delete'](key);
  45445. }
  45446. /**
  45447. * Gets the stack value for `key`.
  45448. *
  45449. * @private
  45450. * @name get
  45451. * @memberOf Stack
  45452. * @param {string} key The key of the value to get.
  45453. * @returns {*} Returns the entry value.
  45454. */
  45455. function stackGet(key) {
  45456. return this.__data__.get(key);
  45457. }
  45458. /**
  45459. * Checks if a stack value for `key` exists.
  45460. *
  45461. * @private
  45462. * @name has
  45463. * @memberOf Stack
  45464. * @param {string} key The key of the entry to check.
  45465. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  45466. */
  45467. function stackHas(key) {
  45468. return this.__data__.has(key);
  45469. }
  45470. /**
  45471. * Sets the stack `key` to `value`.
  45472. *
  45473. * @private
  45474. * @name set
  45475. * @memberOf Stack
  45476. * @param {string} key The key of the value to set.
  45477. * @param {*} value The value to set.
  45478. * @returns {Object} Returns the stack cache instance.
  45479. */
  45480. function stackSet(key, value) {
  45481. var cache = this.__data__;
  45482. if (cache instanceof ListCache) {
  45483. var pairs = cache.__data__;
  45484. if (!Map || pairs.length < LARGE_ARRAY_SIZE - 1) {
  45485. pairs.push([key, value]);
  45486. return this;
  45487. }
  45488. cache = this.__data__ = new MapCache(pairs);
  45489. }
  45490. cache.set(key, value);
  45491. return this;
  45492. } // Add methods to `Stack`.
  45493. Stack.prototype.clear = stackClear;
  45494. Stack.prototype['delete'] = stackDelete;
  45495. Stack.prototype.get = stackGet;
  45496. Stack.prototype.has = stackHas;
  45497. Stack.prototype.set = stackSet;
  45498. /**
  45499. * Creates an array of the enumerable property names of the array-like `value`.
  45500. *
  45501. * @private
  45502. * @param {*} value The value to query.
  45503. * @param {boolean} inherited Specify returning inherited property names.
  45504. * @returns {Array} Returns the array of property names.
  45505. */
  45506. function arrayLikeKeys(value, inherited) {
  45507. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  45508. // Safari 9 makes `arguments.length` enumerable in strict mode.
  45509. var result = isArray(value) || isArguments(value) ? baseTimes(value.length, String) : [];
  45510. var length = result.length,
  45511. skipIndexes = !!length;
  45512. for (var key in value) {
  45513. if ((inherited || hasOwnProperty.call(value, key)) && !(skipIndexes && (key == 'length' || isIndex(key, length)))) {
  45514. result.push(key);
  45515. }
  45516. }
  45517. return result;
  45518. }
  45519. /**
  45520. * Gets the index at which the `key` is found in `array` of key-value pairs.
  45521. *
  45522. * @private
  45523. * @param {Array} array The array to inspect.
  45524. * @param {*} key The key to search for.
  45525. * @returns {number} Returns the index of the matched value, else `-1`.
  45526. */
  45527. function assocIndexOf(array, key) {
  45528. var length = array.length;
  45529. while (length--) {
  45530. if (eq(array[length][0], key)) {
  45531. return length;
  45532. }
  45533. }
  45534. return -1;
  45535. }
  45536. /**
  45537. * Aggregates elements of `collection` on `accumulator` with keys transformed
  45538. * by `iteratee` and values set by `setter`.
  45539. *
  45540. * @private
  45541. * @param {Array|Object} collection The collection to iterate over.
  45542. * @param {Function} setter The function to set `accumulator` values.
  45543. * @param {Function} iteratee The iteratee to transform keys.
  45544. * @param {Object} accumulator The initial aggregated object.
  45545. * @returns {Function} Returns `accumulator`.
  45546. */
  45547. function baseAggregator(collection, setter, iteratee, accumulator) {
  45548. baseEach(collection, function (value, key, collection) {
  45549. setter(accumulator, value, iteratee(value), collection);
  45550. });
  45551. return accumulator;
  45552. }
  45553. /**
  45554. * The base implementation of `_.forEach` without support for iteratee shorthands.
  45555. *
  45556. * @private
  45557. * @param {Array|Object} collection The collection to iterate over.
  45558. * @param {Function} iteratee The function invoked per iteration.
  45559. * @returns {Array|Object} Returns `collection`.
  45560. */
  45561. var baseEach = createBaseEach(baseForOwn);
  45562. /**
  45563. * The base implementation of `baseForOwn` which iterates over `object`
  45564. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  45565. * Iteratee functions may exit iteration early by explicitly returning `false`.
  45566. *
  45567. * @private
  45568. * @param {Object} object The object to iterate over.
  45569. * @param {Function} iteratee The function invoked per iteration.
  45570. * @param {Function} keysFunc The function to get the keys of `object`.
  45571. * @returns {Object} Returns `object`.
  45572. */
  45573. var baseFor = createBaseFor();
  45574. /**
  45575. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  45576. *
  45577. * @private
  45578. * @param {Object} object The object to iterate over.
  45579. * @param {Function} iteratee The function invoked per iteration.
  45580. * @returns {Object} Returns `object`.
  45581. */
  45582. function baseForOwn(object, iteratee) {
  45583. return object && baseFor(object, iteratee, keys);
  45584. }
  45585. /**
  45586. * The base implementation of `_.get` without support for default values.
  45587. *
  45588. * @private
  45589. * @param {Object} object The object to query.
  45590. * @param {Array|string} path The path of the property to get.
  45591. * @returns {*} Returns the resolved value.
  45592. */
  45593. function baseGet(object, path) {
  45594. path = isKey(path, object) ? [path] : castPath(path);
  45595. var index = 0,
  45596. length = path.length;
  45597. while (object != null && index < length) {
  45598. object = object[toKey(path[index++])];
  45599. }
  45600. return index && index == length ? object : undefined;
  45601. }
  45602. /**
  45603. * The base implementation of `getTag`.
  45604. *
  45605. * @private
  45606. * @param {*} value The value to query.
  45607. * @returns {string} Returns the `toStringTag`.
  45608. */
  45609. function baseGetTag(value) {
  45610. return objectToString.call(value);
  45611. }
  45612. /**
  45613. * The base implementation of `_.hasIn` without support for deep paths.
  45614. *
  45615. * @private
  45616. * @param {Object} [object] The object to query.
  45617. * @param {Array|string} key The key to check.
  45618. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  45619. */
  45620. function baseHasIn(object, key) {
  45621. return object != null && key in Object(object);
  45622. }
  45623. /**
  45624. * The base implementation of `_.isEqual` which supports partial comparisons
  45625. * and tracks traversed objects.
  45626. *
  45627. * @private
  45628. * @param {*} value The value to compare.
  45629. * @param {*} other The other value to compare.
  45630. * @param {Function} [customizer] The function to customize comparisons.
  45631. * @param {boolean} [bitmask] The bitmask of comparison flags.
  45632. * The bitmask may be composed of the following flags:
  45633. * 1 - Unordered comparison
  45634. * 2 - Partial comparison
  45635. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  45636. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  45637. */
  45638. function baseIsEqual(value, other, customizer, bitmask, stack) {
  45639. if (value === other) {
  45640. return true;
  45641. }
  45642. if (value == null || other == null || !isObject(value) && !isObjectLike(other)) {
  45643. return value !== value && other !== other;
  45644. }
  45645. return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
  45646. }
  45647. /**
  45648. * A specialized version of `baseIsEqual` for arrays and objects which performs
  45649. * deep comparisons and tracks traversed objects enabling objects with circular
  45650. * references to be compared.
  45651. *
  45652. * @private
  45653. * @param {Object} object The object to compare.
  45654. * @param {Object} other The other object to compare.
  45655. * @param {Function} equalFunc The function to determine equivalents of values.
  45656. * @param {Function} [customizer] The function to customize comparisons.
  45657. * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual`
  45658. * for more details.
  45659. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  45660. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  45661. */
  45662. function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
  45663. var objIsArr = isArray(object),
  45664. othIsArr = isArray(other),
  45665. objTag = arrayTag,
  45666. othTag = arrayTag;
  45667. if (!objIsArr) {
  45668. objTag = getTag(object);
  45669. objTag = objTag == argsTag ? objectTag : objTag;
  45670. }
  45671. if (!othIsArr) {
  45672. othTag = getTag(other);
  45673. othTag = othTag == argsTag ? objectTag : othTag;
  45674. }
  45675. var objIsObj = objTag == objectTag && !isHostObject(object),
  45676. othIsObj = othTag == objectTag && !isHostObject(other),
  45677. isSameTag = objTag == othTag;
  45678. if (isSameTag && !objIsObj) {
  45679. stack || (stack = new Stack());
  45680. return objIsArr || isTypedArray(object) ? equalArrays(object, other, equalFunc, customizer, bitmask, stack) : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack);
  45681. }
  45682. if (!(bitmask & PARTIAL_COMPARE_FLAG)) {
  45683. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  45684. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  45685. if (objIsWrapped || othIsWrapped) {
  45686. var objUnwrapped = objIsWrapped ? object.value() : object,
  45687. othUnwrapped = othIsWrapped ? other.value() : other;
  45688. stack || (stack = new Stack());
  45689. return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack);
  45690. }
  45691. }
  45692. if (!isSameTag) {
  45693. return false;
  45694. }
  45695. stack || (stack = new Stack());
  45696. return equalObjects(object, other, equalFunc, customizer, bitmask, stack);
  45697. }
  45698. /**
  45699. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  45700. *
  45701. * @private
  45702. * @param {Object} object The object to inspect.
  45703. * @param {Object} source The object of property values to match.
  45704. * @param {Array} matchData The property names, values, and compare flags to match.
  45705. * @param {Function} [customizer] The function to customize comparisons.
  45706. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  45707. */
  45708. function baseIsMatch(object, source, matchData, customizer) {
  45709. var index = matchData.length,
  45710. length = index,
  45711. noCustomizer = !customizer;
  45712. if (object == null) {
  45713. return !length;
  45714. }
  45715. object = Object(object);
  45716. while (index--) {
  45717. var data = matchData[index];
  45718. if (noCustomizer && data[2] ? data[1] !== object[data[0]] : !(data[0] in object)) {
  45719. return false;
  45720. }
  45721. }
  45722. while (++index < length) {
  45723. data = matchData[index];
  45724. var key = data[0],
  45725. objValue = object[key],
  45726. srcValue = data[1];
  45727. if (noCustomizer && data[2]) {
  45728. if (objValue === undefined && !(key in object)) {
  45729. return false;
  45730. }
  45731. } else {
  45732. var stack = new Stack();
  45733. if (customizer) {
  45734. var result = customizer(objValue, srcValue, key, object, source, stack);
  45735. }
  45736. if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack) : result)) {
  45737. return false;
  45738. }
  45739. }
  45740. }
  45741. return true;
  45742. }
  45743. /**
  45744. * The base implementation of `_.isNative` without bad shim checks.
  45745. *
  45746. * @private
  45747. * @param {*} value The value to check.
  45748. * @returns {boolean} Returns `true` if `value` is a native function,
  45749. * else `false`.
  45750. */
  45751. function baseIsNative(value) {
  45752. if (!isObject(value) || isMasked(value)) {
  45753. return false;
  45754. }
  45755. var pattern = isFunction(value) || isHostObject(value) ? reIsNative : reIsHostCtor;
  45756. return pattern.test(toSource(value));
  45757. }
  45758. /**
  45759. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  45760. *
  45761. * @private
  45762. * @param {*} value The value to check.
  45763. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  45764. */
  45765. function baseIsTypedArray(value) {
  45766. return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
  45767. }
  45768. /**
  45769. * The base implementation of `_.iteratee`.
  45770. *
  45771. * @private
  45772. * @param {*} [value=_.identity] The value to convert to an iteratee.
  45773. * @returns {Function} Returns the iteratee.
  45774. */
  45775. function baseIteratee(value) {
  45776. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  45777. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  45778. if (typeof value == 'function') {
  45779. return value;
  45780. }
  45781. if (value == null) {
  45782. return identity;
  45783. }
  45784. if (_typeof(value) == 'object') {
  45785. return isArray(value) ? baseMatchesProperty(value[0], value[1]) : baseMatches(value);
  45786. }
  45787. return property(value);
  45788. }
  45789. /**
  45790. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  45791. *
  45792. * @private
  45793. * @param {Object} object The object to query.
  45794. * @returns {Array} Returns the array of property names.
  45795. */
  45796. function baseKeys(object) {
  45797. if (!isPrototype(object)) {
  45798. return nativeKeys(object);
  45799. }
  45800. var result = [];
  45801. for (var key in Object(object)) {
  45802. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  45803. result.push(key);
  45804. }
  45805. }
  45806. return result;
  45807. }
  45808. /**
  45809. * The base implementation of `_.matches` which doesn't clone `source`.
  45810. *
  45811. * @private
  45812. * @param {Object} source The object of property values to match.
  45813. * @returns {Function} Returns the new spec function.
  45814. */
  45815. function baseMatches(source) {
  45816. var matchData = getMatchData(source);
  45817. if (matchData.length == 1 && matchData[0][2]) {
  45818. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  45819. }
  45820. return function (object) {
  45821. return object === source || baseIsMatch(object, source, matchData);
  45822. };
  45823. }
  45824. /**
  45825. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  45826. *
  45827. * @private
  45828. * @param {string} path The path of the property to get.
  45829. * @param {*} srcValue The value to match.
  45830. * @returns {Function} Returns the new spec function.
  45831. */
  45832. function baseMatchesProperty(path, srcValue) {
  45833. if (isKey(path) && isStrictComparable(srcValue)) {
  45834. return matchesStrictComparable(toKey(path), srcValue);
  45835. }
  45836. return function (object) {
  45837. var objValue = get(object, path);
  45838. return objValue === undefined && objValue === srcValue ? hasIn(object, path) : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
  45839. };
  45840. }
  45841. /**
  45842. * A specialized version of `baseProperty` which supports deep paths.
  45843. *
  45844. * @private
  45845. * @param {Array|string} path The path of the property to get.
  45846. * @returns {Function} Returns the new accessor function.
  45847. */
  45848. function basePropertyDeep(path) {
  45849. return function (object) {
  45850. return baseGet(object, path);
  45851. };
  45852. }
  45853. /**
  45854. * The base implementation of `_.toString` which doesn't convert nullish
  45855. * values to empty strings.
  45856. *
  45857. * @private
  45858. * @param {*} value The value to process.
  45859. * @returns {string} Returns the string.
  45860. */
  45861. function baseToString(value) {
  45862. // Exit early for strings to avoid a performance hit in some environments.
  45863. if (typeof value == 'string') {
  45864. return value;
  45865. }
  45866. if (isSymbol(value)) {
  45867. return symbolToString ? symbolToString.call(value) : '';
  45868. }
  45869. var result = value + '';
  45870. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  45871. }
  45872. /**
  45873. * Casts `value` to a path array if it's not one.
  45874. *
  45875. * @private
  45876. * @param {*} value The value to inspect.
  45877. * @returns {Array} Returns the cast property path array.
  45878. */
  45879. function castPath(value) {
  45880. return isArray(value) ? value : stringToPath(value);
  45881. }
  45882. /**
  45883. * Creates a function like `_.groupBy`.
  45884. *
  45885. * @private
  45886. * @param {Function} setter The function to set accumulator values.
  45887. * @param {Function} [initializer] The accumulator object initializer.
  45888. * @returns {Function} Returns the new aggregator function.
  45889. */
  45890. function createAggregator(setter, initializer) {
  45891. return function (collection, iteratee) {
  45892. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  45893. accumulator = initializer ? initializer() : {};
  45894. return func(collection, setter, baseIteratee(iteratee, 2), accumulator);
  45895. };
  45896. }
  45897. /**
  45898. * Creates a `baseEach` or `baseEachRight` function.
  45899. *
  45900. * @private
  45901. * @param {Function} eachFunc The function to iterate over a collection.
  45902. * @param {boolean} [fromRight] Specify iterating from right to left.
  45903. * @returns {Function} Returns the new base function.
  45904. */
  45905. function createBaseEach(eachFunc, fromRight) {
  45906. return function (collection, iteratee) {
  45907. if (collection == null) {
  45908. return collection;
  45909. }
  45910. if (!isArrayLike(collection)) {
  45911. return eachFunc(collection, iteratee);
  45912. }
  45913. var length = collection.length,
  45914. index = fromRight ? length : -1,
  45915. iterable = Object(collection);
  45916. while (fromRight ? index-- : ++index < length) {
  45917. if (iteratee(iterable[index], index, iterable) === false) {
  45918. break;
  45919. }
  45920. }
  45921. return collection;
  45922. };
  45923. }
  45924. /**
  45925. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  45926. *
  45927. * @private
  45928. * @param {boolean} [fromRight] Specify iterating from right to left.
  45929. * @returns {Function} Returns the new base function.
  45930. */
  45931. function createBaseFor(fromRight) {
  45932. return function (object, iteratee, keysFunc) {
  45933. var index = -1,
  45934. iterable = Object(object),
  45935. props = keysFunc(object),
  45936. length = props.length;
  45937. while (length--) {
  45938. var key = props[fromRight ? length : ++index];
  45939. if (iteratee(iterable[key], key, iterable) === false) {
  45940. break;
  45941. }
  45942. }
  45943. return object;
  45944. };
  45945. }
  45946. /**
  45947. * A specialized version of `baseIsEqualDeep` for arrays with support for
  45948. * partial deep comparisons.
  45949. *
  45950. * @private
  45951. * @param {Array} array The array to compare.
  45952. * @param {Array} other The other array to compare.
  45953. * @param {Function} equalFunc The function to determine equivalents of values.
  45954. * @param {Function} customizer The function to customize comparisons.
  45955. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  45956. * for more details.
  45957. * @param {Object} stack Tracks traversed `array` and `other` objects.
  45958. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  45959. */
  45960. function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
  45961. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  45962. arrLength = array.length,
  45963. othLength = other.length;
  45964. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  45965. return false;
  45966. } // Assume cyclic values are equal.
  45967. var stacked = stack.get(array);
  45968. if (stacked && stack.get(other)) {
  45969. return stacked == other;
  45970. }
  45971. var index = -1,
  45972. result = true,
  45973. seen = bitmask & UNORDERED_COMPARE_FLAG ? new SetCache() : undefined;
  45974. stack.set(array, other);
  45975. stack.set(other, array); // Ignore non-index properties.
  45976. while (++index < arrLength) {
  45977. var arrValue = array[index],
  45978. othValue = other[index];
  45979. if (customizer) {
  45980. var compared = isPartial ? customizer(othValue, arrValue, index, other, array, stack) : customizer(arrValue, othValue, index, array, other, stack);
  45981. }
  45982. if (compared !== undefined) {
  45983. if (compared) {
  45984. continue;
  45985. }
  45986. result = false;
  45987. break;
  45988. } // Recursively compare arrays (susceptible to call stack limits).
  45989. if (seen) {
  45990. if (!arraySome(other, function (othValue, othIndex) {
  45991. if (!seen.has(othIndex) && (arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  45992. return seen.add(othIndex);
  45993. }
  45994. })) {
  45995. result = false;
  45996. break;
  45997. }
  45998. } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  45999. result = false;
  46000. break;
  46001. }
  46002. }
  46003. stack['delete'](array);
  46004. stack['delete'](other);
  46005. return result;
  46006. }
  46007. /**
  46008. * A specialized version of `baseIsEqualDeep` for comparing objects of
  46009. * the same `toStringTag`.
  46010. *
  46011. * **Note:** This function only supports comparing values with tags of
  46012. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  46013. *
  46014. * @private
  46015. * @param {Object} object The object to compare.
  46016. * @param {Object} other The other object to compare.
  46017. * @param {string} tag The `toStringTag` of the objects to compare.
  46018. * @param {Function} equalFunc The function to determine equivalents of values.
  46019. * @param {Function} customizer The function to customize comparisons.
  46020. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  46021. * for more details.
  46022. * @param {Object} stack Tracks traversed `object` and `other` objects.
  46023. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  46024. */
  46025. function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) {
  46026. switch (tag) {
  46027. case dataViewTag:
  46028. if (object.byteLength != other.byteLength || object.byteOffset != other.byteOffset) {
  46029. return false;
  46030. }
  46031. object = object.buffer;
  46032. other = other.buffer;
  46033. case arrayBufferTag:
  46034. if (object.byteLength != other.byteLength || !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  46035. return false;
  46036. }
  46037. return true;
  46038. case boolTag:
  46039. case dateTag:
  46040. case numberTag:
  46041. // Coerce booleans to `1` or `0` and dates to milliseconds.
  46042. // Invalid dates are coerced to `NaN`.
  46043. return eq(+object, +other);
  46044. case errorTag:
  46045. return object.name == other.name && object.message == other.message;
  46046. case regexpTag:
  46047. case stringTag:
  46048. // Coerce regexes to strings and treat strings, primitives and objects,
  46049. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  46050. // for more details.
  46051. return object == other + '';
  46052. case mapTag:
  46053. var convert = mapToArray;
  46054. case setTag:
  46055. var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
  46056. convert || (convert = setToArray);
  46057. if (object.size != other.size && !isPartial) {
  46058. return false;
  46059. } // Assume cyclic values are equal.
  46060. var stacked = stack.get(object);
  46061. if (stacked) {
  46062. return stacked == other;
  46063. }
  46064. bitmask |= UNORDERED_COMPARE_FLAG; // Recursively compare objects (susceptible to call stack limits).
  46065. stack.set(object, other);
  46066. var result = equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack);
  46067. stack['delete'](object);
  46068. return result;
  46069. case symbolTag:
  46070. if (symbolValueOf) {
  46071. return symbolValueOf.call(object) == symbolValueOf.call(other);
  46072. }
  46073. }
  46074. return false;
  46075. }
  46076. /**
  46077. * A specialized version of `baseIsEqualDeep` for objects with support for
  46078. * partial deep comparisons.
  46079. *
  46080. * @private
  46081. * @param {Object} object The object to compare.
  46082. * @param {Object} other The other object to compare.
  46083. * @param {Function} equalFunc The function to determine equivalents of values.
  46084. * @param {Function} customizer The function to customize comparisons.
  46085. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  46086. * for more details.
  46087. * @param {Object} stack Tracks traversed `object` and `other` objects.
  46088. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  46089. */
  46090. function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
  46091. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  46092. objProps = keys(object),
  46093. objLength = objProps.length,
  46094. othProps = keys(other),
  46095. othLength = othProps.length;
  46096. if (objLength != othLength && !isPartial) {
  46097. return false;
  46098. }
  46099. var index = objLength;
  46100. while (index--) {
  46101. var key = objProps[index];
  46102. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  46103. return false;
  46104. }
  46105. } // Assume cyclic values are equal.
  46106. var stacked = stack.get(object);
  46107. if (stacked && stack.get(other)) {
  46108. return stacked == other;
  46109. }
  46110. var result = true;
  46111. stack.set(object, other);
  46112. stack.set(other, object);
  46113. var skipCtor = isPartial;
  46114. while (++index < objLength) {
  46115. key = objProps[index];
  46116. var objValue = object[key],
  46117. othValue = other[key];
  46118. if (customizer) {
  46119. var compared = isPartial ? customizer(othValue, objValue, key, other, object, stack) : customizer(objValue, othValue, key, object, other, stack);
  46120. } // Recursively compare objects (susceptible to call stack limits).
  46121. if (!(compared === undefined ? objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack) : compared)) {
  46122. result = false;
  46123. break;
  46124. }
  46125. skipCtor || (skipCtor = key == 'constructor');
  46126. }
  46127. if (result && !skipCtor) {
  46128. var objCtor = object.constructor,
  46129. othCtor = other.constructor; // Non `Object` object instances with different constructors are not equal.
  46130. if (objCtor != othCtor && 'constructor' in object && 'constructor' in other && !(typeof objCtor == 'function' && objCtor instanceof objCtor && typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  46131. result = false;
  46132. }
  46133. }
  46134. stack['delete'](object);
  46135. stack['delete'](other);
  46136. return result;
  46137. }
  46138. /**
  46139. * Gets the data for `map`.
  46140. *
  46141. * @private
  46142. * @param {Object} map The map to query.
  46143. * @param {string} key The reference key.
  46144. * @returns {*} Returns the map data.
  46145. */
  46146. function getMapData(map, key) {
  46147. var data = map.__data__;
  46148. return isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
  46149. }
  46150. /**
  46151. * Gets the property names, values, and compare flags of `object`.
  46152. *
  46153. * @private
  46154. * @param {Object} object The object to query.
  46155. * @returns {Array} Returns the match data of `object`.
  46156. */
  46157. function getMatchData(object) {
  46158. var result = keys(object),
  46159. length = result.length;
  46160. while (length--) {
  46161. var key = result[length],
  46162. value = object[key];
  46163. result[length] = [key, value, isStrictComparable(value)];
  46164. }
  46165. return result;
  46166. }
  46167. /**
  46168. * Gets the native function at `key` of `object`.
  46169. *
  46170. * @private
  46171. * @param {Object} object The object to query.
  46172. * @param {string} key The key of the method to get.
  46173. * @returns {*} Returns the function if it's native, else `undefined`.
  46174. */
  46175. function getNative(object, key) {
  46176. var value = getValue(object, key);
  46177. return baseIsNative(value) ? value : undefined;
  46178. }
  46179. /**
  46180. * Gets the `toStringTag` of `value`.
  46181. *
  46182. * @private
  46183. * @param {*} value The value to query.
  46184. * @returns {string} Returns the `toStringTag`.
  46185. */
  46186. var getTag = baseGetTag; // Fallback for data views, maps, sets, and weak maps in IE 11,
  46187. // for data views in Edge < 14, and promises in Node.js.
  46188. 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) {
  46189. getTag = function getTag(value) {
  46190. var result = objectToString.call(value),
  46191. Ctor = result == objectTag ? value.constructor : undefined,
  46192. ctorString = Ctor ? toSource(Ctor) : undefined;
  46193. if (ctorString) {
  46194. switch (ctorString) {
  46195. case dataViewCtorString:
  46196. return dataViewTag;
  46197. case mapCtorString:
  46198. return mapTag;
  46199. case promiseCtorString:
  46200. return promiseTag;
  46201. case setCtorString:
  46202. return setTag;
  46203. case weakMapCtorString:
  46204. return weakMapTag;
  46205. }
  46206. }
  46207. return result;
  46208. };
  46209. }
  46210. /**
  46211. * Checks if `path` exists on `object`.
  46212. *
  46213. * @private
  46214. * @param {Object} object The object to query.
  46215. * @param {Array|string} path The path to check.
  46216. * @param {Function} hasFunc The function to check properties.
  46217. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  46218. */
  46219. function hasPath(object, path, hasFunc) {
  46220. path = isKey(path, object) ? [path] : castPath(path);
  46221. var result,
  46222. index = -1,
  46223. length = path.length;
  46224. while (++index < length) {
  46225. var key = toKey(path[index]);
  46226. if (!(result = object != null && hasFunc(object, key))) {
  46227. break;
  46228. }
  46229. object = object[key];
  46230. }
  46231. if (result) {
  46232. return result;
  46233. }
  46234. var length = object ? object.length : 0;
  46235. return !!length && isLength(length) && isIndex(key, length) && (isArray(object) || isArguments(object));
  46236. }
  46237. /**
  46238. * Checks if `value` is a valid array-like index.
  46239. *
  46240. * @private
  46241. * @param {*} value The value to check.
  46242. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  46243. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  46244. */
  46245. function isIndex(value, length) {
  46246. length = length == null ? MAX_SAFE_INTEGER : length;
  46247. return !!length && (typeof value == 'number' || reIsUint.test(value)) && value > -1 && value % 1 == 0 && value < length;
  46248. }
  46249. /**
  46250. * Checks if `value` is a property name and not a property path.
  46251. *
  46252. * @private
  46253. * @param {*} value The value to check.
  46254. * @param {Object} [object] The object to query keys on.
  46255. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  46256. */
  46257. function isKey(value, object) {
  46258. if (isArray(value)) {
  46259. return false;
  46260. }
  46261. var type = _typeof(value);
  46262. if (type == 'number' || type == 'symbol' || type == 'boolean' || value == null || isSymbol(value)) {
  46263. return true;
  46264. }
  46265. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object != null && value in Object(object);
  46266. }
  46267. /**
  46268. * Checks if `value` is suitable for use as unique object key.
  46269. *
  46270. * @private
  46271. * @param {*} value The value to check.
  46272. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  46273. */
  46274. function isKeyable(value) {
  46275. var type = _typeof(value);
  46276. return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean' ? value !== '__proto__' : value === null;
  46277. }
  46278. /**
  46279. * Checks if `func` has its source masked.
  46280. *
  46281. * @private
  46282. * @param {Function} func The function to check.
  46283. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  46284. */
  46285. function isMasked(func) {
  46286. return !!maskSrcKey && maskSrcKey in func;
  46287. }
  46288. /**
  46289. * Checks if `value` is likely a prototype object.
  46290. *
  46291. * @private
  46292. * @param {*} value The value to check.
  46293. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  46294. */
  46295. function isPrototype(value) {
  46296. var Ctor = value && value.constructor,
  46297. proto = typeof Ctor == 'function' && Ctor.prototype || objectProto;
  46298. return value === proto;
  46299. }
  46300. /**
  46301. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  46302. *
  46303. * @private
  46304. * @param {*} value The value to check.
  46305. * @returns {boolean} Returns `true` if `value` if suitable for strict
  46306. * equality comparisons, else `false`.
  46307. */
  46308. function isStrictComparable(value) {
  46309. return value === value && !isObject(value);
  46310. }
  46311. /**
  46312. * A specialized version of `matchesProperty` for source values suitable
  46313. * for strict equality comparisons, i.e. `===`.
  46314. *
  46315. * @private
  46316. * @param {string} key The key of the property to get.
  46317. * @param {*} srcValue The value to match.
  46318. * @returns {Function} Returns the new spec function.
  46319. */
  46320. function matchesStrictComparable(key, srcValue) {
  46321. return function (object) {
  46322. if (object == null) {
  46323. return false;
  46324. }
  46325. return object[key] === srcValue && (srcValue !== undefined || key in Object(object));
  46326. };
  46327. }
  46328. /**
  46329. * Converts `string` to a property path array.
  46330. *
  46331. * @private
  46332. * @param {string} string The string to convert.
  46333. * @returns {Array} Returns the property path array.
  46334. */
  46335. var stringToPath = memoize(function (string) {
  46336. string = toString(string);
  46337. var result = [];
  46338. if (reLeadingDot.test(string)) {
  46339. result.push('');
  46340. }
  46341. string.replace(rePropName, function (match, number, quote, string) {
  46342. result.push(quote ? string.replace(reEscapeChar, '$1') : number || match);
  46343. });
  46344. return result;
  46345. });
  46346. /**
  46347. * Converts `value` to a string key if it's not a string or symbol.
  46348. *
  46349. * @private
  46350. * @param {*} value The value to inspect.
  46351. * @returns {string|symbol} Returns the key.
  46352. */
  46353. function toKey(value) {
  46354. if (typeof value == 'string' || isSymbol(value)) {
  46355. return value;
  46356. }
  46357. var result = value + '';
  46358. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  46359. }
  46360. /**
  46361. * Converts `func` to its source code.
  46362. *
  46363. * @private
  46364. * @param {Function} func The function to process.
  46365. * @returns {string} Returns the source code.
  46366. */
  46367. function toSource(func) {
  46368. if (func != null) {
  46369. try {
  46370. return funcToString.call(func);
  46371. } catch (e) {}
  46372. try {
  46373. return func + '';
  46374. } catch (e) {}
  46375. }
  46376. return '';
  46377. }
  46378. /**
  46379. * Creates an object composed of keys generated from the results of running
  46380. * each element of `collection` thru `iteratee`. The order of grouped values
  46381. * is determined by the order they occur in `collection`. The corresponding
  46382. * value of each key is an array of elements responsible for generating the
  46383. * key. The iteratee is invoked with one argument: (value).
  46384. *
  46385. * @static
  46386. * @memberOf _
  46387. * @since 0.1.0
  46388. * @category Collection
  46389. * @param {Array|Object} collection The collection to iterate over.
  46390. * @param {Function} [iteratee=_.identity]
  46391. * The iteratee to transform keys.
  46392. * @returns {Object} Returns the composed aggregate object.
  46393. * @example
  46394. *
  46395. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  46396. * // => { '4': [4.2], '6': [6.1, 6.3] }
  46397. *
  46398. * // The `_.property` iteratee shorthand.
  46399. * _.groupBy(['one', 'two', 'three'], 'length');
  46400. * // => { '3': ['one', 'two'], '5': ['three'] }
  46401. */
  46402. var groupBy = createAggregator(function (result, value, key) {
  46403. if (hasOwnProperty.call(result, key)) {
  46404. result[key].push(value);
  46405. } else {
  46406. result[key] = [value];
  46407. }
  46408. });
  46409. /**
  46410. * Creates a function that memoizes the result of `func`. If `resolver` is
  46411. * provided, it determines the cache key for storing the result based on the
  46412. * arguments provided to the memoized function. By default, the first argument
  46413. * provided to the memoized function is used as the map cache key. The `func`
  46414. * is invoked with the `this` binding of the memoized function.
  46415. *
  46416. * **Note:** The cache is exposed as the `cache` property on the memoized
  46417. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  46418. * constructor with one whose instances implement the
  46419. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  46420. * method interface of `delete`, `get`, `has`, and `set`.
  46421. *
  46422. * @static
  46423. * @memberOf _
  46424. * @since 0.1.0
  46425. * @category Function
  46426. * @param {Function} func The function to have its output memoized.
  46427. * @param {Function} [resolver] The function to resolve the cache key.
  46428. * @returns {Function} Returns the new memoized function.
  46429. * @example
  46430. *
  46431. * var object = { 'a': 1, 'b': 2 };
  46432. * var other = { 'c': 3, 'd': 4 };
  46433. *
  46434. * var values = _.memoize(_.values);
  46435. * values(object);
  46436. * // => [1, 2]
  46437. *
  46438. * values(other);
  46439. * // => [3, 4]
  46440. *
  46441. * object.a = 2;
  46442. * values(object);
  46443. * // => [1, 2]
  46444. *
  46445. * // Modify the result cache.
  46446. * values.cache.set(object, ['a', 'b']);
  46447. * values(object);
  46448. * // => ['a', 'b']
  46449. *
  46450. * // Replace `_.memoize.Cache`.
  46451. * _.memoize.Cache = WeakMap;
  46452. */
  46453. function memoize(func, resolver) {
  46454. if (typeof func != 'function' || resolver && typeof resolver != 'function') {
  46455. throw new TypeError(FUNC_ERROR_TEXT);
  46456. }
  46457. var memoized = function memoized() {
  46458. var args = arguments,
  46459. key = resolver ? resolver.apply(this, args) : args[0],
  46460. cache = memoized.cache;
  46461. if (cache.has(key)) {
  46462. return cache.get(key);
  46463. }
  46464. var result = func.apply(this, args);
  46465. memoized.cache = cache.set(key, result);
  46466. return result;
  46467. };
  46468. memoized.cache = new (memoize.Cache || MapCache)();
  46469. return memoized;
  46470. } // Assign cache to `_.memoize`.
  46471. memoize.Cache = MapCache;
  46472. /**
  46473. * Performs a
  46474. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  46475. * comparison between two values to determine if they are equivalent.
  46476. *
  46477. * @static
  46478. * @memberOf _
  46479. * @since 4.0.0
  46480. * @category Lang
  46481. * @param {*} value The value to compare.
  46482. * @param {*} other The other value to compare.
  46483. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  46484. * @example
  46485. *
  46486. * var object = { 'a': 1 };
  46487. * var other = { 'a': 1 };
  46488. *
  46489. * _.eq(object, object);
  46490. * // => true
  46491. *
  46492. * _.eq(object, other);
  46493. * // => false
  46494. *
  46495. * _.eq('a', 'a');
  46496. * // => true
  46497. *
  46498. * _.eq('a', Object('a'));
  46499. * // => false
  46500. *
  46501. * _.eq(NaN, NaN);
  46502. * // => true
  46503. */
  46504. function eq(value, other) {
  46505. return value === other || value !== value && other !== other;
  46506. }
  46507. /**
  46508. * Checks if `value` is likely an `arguments` object.
  46509. *
  46510. * @static
  46511. * @memberOf _
  46512. * @since 0.1.0
  46513. * @category Lang
  46514. * @param {*} value The value to check.
  46515. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  46516. * else `false`.
  46517. * @example
  46518. *
  46519. * _.isArguments(function() { return arguments; }());
  46520. * // => true
  46521. *
  46522. * _.isArguments([1, 2, 3]);
  46523. * // => false
  46524. */
  46525. function isArguments(value) {
  46526. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  46527. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') && (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  46528. }
  46529. /**
  46530. * Checks if `value` is classified as an `Array` object.
  46531. *
  46532. * @static
  46533. * @memberOf _
  46534. * @since 0.1.0
  46535. * @category Lang
  46536. * @param {*} value The value to check.
  46537. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  46538. * @example
  46539. *
  46540. * _.isArray([1, 2, 3]);
  46541. * // => true
  46542. *
  46543. * _.isArray(document.body.children);
  46544. * // => false
  46545. *
  46546. * _.isArray('abc');
  46547. * // => false
  46548. *
  46549. * _.isArray(_.noop);
  46550. * // => false
  46551. */
  46552. var isArray = Array.isArray;
  46553. /**
  46554. * Checks if `value` is array-like. A value is considered array-like if it's
  46555. * not a function and has a `value.length` that's an integer greater than or
  46556. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  46557. *
  46558. * @static
  46559. * @memberOf _
  46560. * @since 4.0.0
  46561. * @category Lang
  46562. * @param {*} value The value to check.
  46563. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  46564. * @example
  46565. *
  46566. * _.isArrayLike([1, 2, 3]);
  46567. * // => true
  46568. *
  46569. * _.isArrayLike(document.body.children);
  46570. * // => true
  46571. *
  46572. * _.isArrayLike('abc');
  46573. * // => true
  46574. *
  46575. * _.isArrayLike(_.noop);
  46576. * // => false
  46577. */
  46578. function isArrayLike(value) {
  46579. return value != null && isLength(value.length) && !isFunction(value);
  46580. }
  46581. /**
  46582. * This method is like `_.isArrayLike` except that it also checks if `value`
  46583. * is an object.
  46584. *
  46585. * @static
  46586. * @memberOf _
  46587. * @since 4.0.0
  46588. * @category Lang
  46589. * @param {*} value The value to check.
  46590. * @returns {boolean} Returns `true` if `value` is an array-like object,
  46591. * else `false`.
  46592. * @example
  46593. *
  46594. * _.isArrayLikeObject([1, 2, 3]);
  46595. * // => true
  46596. *
  46597. * _.isArrayLikeObject(document.body.children);
  46598. * // => true
  46599. *
  46600. * _.isArrayLikeObject('abc');
  46601. * // => false
  46602. *
  46603. * _.isArrayLikeObject(_.noop);
  46604. * // => false
  46605. */
  46606. function isArrayLikeObject(value) {
  46607. return isObjectLike(value) && isArrayLike(value);
  46608. }
  46609. /**
  46610. * Checks if `value` is classified as a `Function` object.
  46611. *
  46612. * @static
  46613. * @memberOf _
  46614. * @since 0.1.0
  46615. * @category Lang
  46616. * @param {*} value The value to check.
  46617. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  46618. * @example
  46619. *
  46620. * _.isFunction(_);
  46621. * // => true
  46622. *
  46623. * _.isFunction(/abc/);
  46624. * // => false
  46625. */
  46626. function isFunction(value) {
  46627. // The use of `Object#toString` avoids issues with the `typeof` operator
  46628. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  46629. var tag = isObject(value) ? objectToString.call(value) : '';
  46630. return tag == funcTag || tag == genTag;
  46631. }
  46632. /**
  46633. * Checks if `value` is a valid array-like length.
  46634. *
  46635. * **Note:** This method is loosely based on
  46636. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  46637. *
  46638. * @static
  46639. * @memberOf _
  46640. * @since 4.0.0
  46641. * @category Lang
  46642. * @param {*} value The value to check.
  46643. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  46644. * @example
  46645. *
  46646. * _.isLength(3);
  46647. * // => true
  46648. *
  46649. * _.isLength(Number.MIN_VALUE);
  46650. * // => false
  46651. *
  46652. * _.isLength(Infinity);
  46653. * // => false
  46654. *
  46655. * _.isLength('3');
  46656. * // => false
  46657. */
  46658. function isLength(value) {
  46659. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  46660. }
  46661. /**
  46662. * Checks if `value` is the
  46663. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  46664. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  46665. *
  46666. * @static
  46667. * @memberOf _
  46668. * @since 0.1.0
  46669. * @category Lang
  46670. * @param {*} value The value to check.
  46671. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  46672. * @example
  46673. *
  46674. * _.isObject({});
  46675. * // => true
  46676. *
  46677. * _.isObject([1, 2, 3]);
  46678. * // => true
  46679. *
  46680. * _.isObject(_.noop);
  46681. * // => true
  46682. *
  46683. * _.isObject(null);
  46684. * // => false
  46685. */
  46686. function isObject(value) {
  46687. var type = _typeof(value);
  46688. return !!value && (type == 'object' || type == 'function');
  46689. }
  46690. /**
  46691. * Checks if `value` is object-like. A value is object-like if it's not `null`
  46692. * and has a `typeof` result of "object".
  46693. *
  46694. * @static
  46695. * @memberOf _
  46696. * @since 4.0.0
  46697. * @category Lang
  46698. * @param {*} value The value to check.
  46699. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  46700. * @example
  46701. *
  46702. * _.isObjectLike({});
  46703. * // => true
  46704. *
  46705. * _.isObjectLike([1, 2, 3]);
  46706. * // => true
  46707. *
  46708. * _.isObjectLike(_.noop);
  46709. * // => false
  46710. *
  46711. * _.isObjectLike(null);
  46712. * // => false
  46713. */
  46714. function isObjectLike(value) {
  46715. return !!value && _typeof(value) == 'object';
  46716. }
  46717. /**
  46718. * Checks if `value` is classified as a `Symbol` primitive or object.
  46719. *
  46720. * @static
  46721. * @memberOf _
  46722. * @since 4.0.0
  46723. * @category Lang
  46724. * @param {*} value The value to check.
  46725. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  46726. * @example
  46727. *
  46728. * _.isSymbol(Symbol.iterator);
  46729. * // => true
  46730. *
  46731. * _.isSymbol('abc');
  46732. * // => false
  46733. */
  46734. function isSymbol(value) {
  46735. return _typeof(value) == 'symbol' || isObjectLike(value) && objectToString.call(value) == symbolTag;
  46736. }
  46737. /**
  46738. * Checks if `value` is classified as a typed array.
  46739. *
  46740. * @static
  46741. * @memberOf _
  46742. * @since 3.0.0
  46743. * @category Lang
  46744. * @param {*} value The value to check.
  46745. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  46746. * @example
  46747. *
  46748. * _.isTypedArray(new Uint8Array);
  46749. * // => true
  46750. *
  46751. * _.isTypedArray([]);
  46752. * // => false
  46753. */
  46754. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  46755. /**
  46756. * Converts `value` to a string. An empty string is returned for `null`
  46757. * and `undefined` values. The sign of `-0` is preserved.
  46758. *
  46759. * @static
  46760. * @memberOf _
  46761. * @since 4.0.0
  46762. * @category Lang
  46763. * @param {*} value The value to process.
  46764. * @returns {string} Returns the string.
  46765. * @example
  46766. *
  46767. * _.toString(null);
  46768. * // => ''
  46769. *
  46770. * _.toString(-0);
  46771. * // => '-0'
  46772. *
  46773. * _.toString([1, 2, 3]);
  46774. * // => '1,2,3'
  46775. */
  46776. function toString(value) {
  46777. return value == null ? '' : baseToString(value);
  46778. }
  46779. /**
  46780. * Gets the value at `path` of `object`. If the resolved value is
  46781. * `undefined`, the `defaultValue` is returned in its place.
  46782. *
  46783. * @static
  46784. * @memberOf _
  46785. * @since 3.7.0
  46786. * @category Object
  46787. * @param {Object} object The object to query.
  46788. * @param {Array|string} path The path of the property to get.
  46789. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  46790. * @returns {*} Returns the resolved value.
  46791. * @example
  46792. *
  46793. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  46794. *
  46795. * _.get(object, 'a[0].b.c');
  46796. * // => 3
  46797. *
  46798. * _.get(object, ['a', '0', 'b', 'c']);
  46799. * // => 3
  46800. *
  46801. * _.get(object, 'a.b.c', 'default');
  46802. * // => 'default'
  46803. */
  46804. function get(object, path, defaultValue) {
  46805. var result = object == null ? undefined : baseGet(object, path);
  46806. return result === undefined ? defaultValue : result;
  46807. }
  46808. /**
  46809. * Checks if `path` is a direct or inherited property of `object`.
  46810. *
  46811. * @static
  46812. * @memberOf _
  46813. * @since 4.0.0
  46814. * @category Object
  46815. * @param {Object} object The object to query.
  46816. * @param {Array|string} path The path to check.
  46817. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  46818. * @example
  46819. *
  46820. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  46821. *
  46822. * _.hasIn(object, 'a');
  46823. * // => true
  46824. *
  46825. * _.hasIn(object, 'a.b');
  46826. * // => true
  46827. *
  46828. * _.hasIn(object, ['a', 'b']);
  46829. * // => true
  46830. *
  46831. * _.hasIn(object, 'b');
  46832. * // => false
  46833. */
  46834. function hasIn(object, path) {
  46835. return object != null && hasPath(object, path, baseHasIn);
  46836. }
  46837. /**
  46838. * Creates an array of the own enumerable property names of `object`.
  46839. *
  46840. * **Note:** Non-object values are coerced to objects. See the
  46841. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  46842. * for more details.
  46843. *
  46844. * @static
  46845. * @since 0.1.0
  46846. * @memberOf _
  46847. * @category Object
  46848. * @param {Object} object The object to query.
  46849. * @returns {Array} Returns the array of property names.
  46850. * @example
  46851. *
  46852. * function Foo() {
  46853. * this.a = 1;
  46854. * this.b = 2;
  46855. * }
  46856. *
  46857. * Foo.prototype.c = 3;
  46858. *
  46859. * _.keys(new Foo);
  46860. * // => ['a', 'b'] (iteration order is not guaranteed)
  46861. *
  46862. * _.keys('hi');
  46863. * // => ['0', '1']
  46864. */
  46865. function keys(object) {
  46866. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  46867. }
  46868. /**
  46869. * This method returns the first argument it receives.
  46870. *
  46871. * @static
  46872. * @since 0.1.0
  46873. * @memberOf _
  46874. * @category Util
  46875. * @param {*} value Any value.
  46876. * @returns {*} Returns `value`.
  46877. * @example
  46878. *
  46879. * var object = { 'a': 1 };
  46880. *
  46881. * console.log(_.identity(object) === object);
  46882. * // => true
  46883. */
  46884. function identity(value) {
  46885. return value;
  46886. }
  46887. /**
  46888. * Creates a function that returns the value at `path` of a given object.
  46889. *
  46890. * @static
  46891. * @memberOf _
  46892. * @since 2.4.0
  46893. * @category Util
  46894. * @param {Array|string} path The path of the property to get.
  46895. * @returns {Function} Returns the new accessor function.
  46896. * @example
  46897. *
  46898. * var objects = [
  46899. * { 'a': { 'b': 2 } },
  46900. * { 'a': { 'b': 1 } }
  46901. * ];
  46902. *
  46903. * _.map(objects, _.property('a.b'));
  46904. * // => [2, 1]
  46905. *
  46906. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  46907. * // => [1, 2]
  46908. */
  46909. function property(path) {
  46910. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  46911. }
  46912. module.exports = groupBy;
  46913. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  46914. },{}],428:[function(require,module,exports){
  46915. "use strict";
  46916. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  46917. /**
  46918. * lodash 3.0.3 (Custom Build) <https://lodash.com/>
  46919. * Build: `lodash modularize exports="npm" -o ./`
  46920. * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
  46921. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  46922. * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  46923. * Available under MIT license <https://lodash.com/license>
  46924. */
  46925. /** `Object#toString` result references. */
  46926. var boolTag = '[object Boolean]';
  46927. /** Used for built-in method references. */
  46928. var objectProto = Object.prototype;
  46929. /**
  46930. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  46931. * of values.
  46932. */
  46933. var objectToString = objectProto.toString;
  46934. /**
  46935. * Checks if `value` is classified as a boolean primitive or object.
  46936. *
  46937. * @static
  46938. * @memberOf _
  46939. * @category Lang
  46940. * @param {*} value The value to check.
  46941. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  46942. * @example
  46943. *
  46944. * _.isBoolean(false);
  46945. * // => true
  46946. *
  46947. * _.isBoolean(null);
  46948. * // => false
  46949. */
  46950. function isBoolean(value) {
  46951. return value === true || value === false || isObjectLike(value) && objectToString.call(value) == boolTag;
  46952. }
  46953. /**
  46954. * Checks if `value` is object-like. A value is object-like if it's not `null`
  46955. * and has a `typeof` result of "object".
  46956. *
  46957. * @static
  46958. * @memberOf _
  46959. * @category Lang
  46960. * @param {*} value The value to check.
  46961. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  46962. * @example
  46963. *
  46964. * _.isObjectLike({});
  46965. * // => true
  46966. *
  46967. * _.isObjectLike([1, 2, 3]);
  46968. * // => true
  46969. *
  46970. * _.isObjectLike(_.noop);
  46971. * // => false
  46972. *
  46973. * _.isObjectLike(null);
  46974. * // => false
  46975. */
  46976. function isObjectLike(value) {
  46977. return !!value && _typeof(value) == 'object';
  46978. }
  46979. module.exports = isBoolean;
  46980. },{}],429:[function(require,module,exports){
  46981. (function (global){
  46982. "use strict";
  46983. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  46984. /**
  46985. * Lodash (Custom Build) <https://lodash.com/>
  46986. * Build: `lodash modularize exports="npm" -o ./`
  46987. * Copyright JS Foundation and other contributors <https://js.foundation/>
  46988. * Released under MIT license <https://lodash.com/license>
  46989. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  46990. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  46991. */
  46992. /** Used as the size to enable large array optimizations. */
  46993. var LARGE_ARRAY_SIZE = 200;
  46994. /** Used to stand-in for `undefined` hash values. */
  46995. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  46996. /** Used to compose bitmasks for value comparisons. */
  46997. var COMPARE_PARTIAL_FLAG = 1,
  46998. COMPARE_UNORDERED_FLAG = 2;
  46999. /** Used as references for various `Number` constants. */
  47000. var MAX_SAFE_INTEGER = 9007199254740991;
  47001. /** `Object#toString` result references. */
  47002. var argsTag = '[object Arguments]',
  47003. arrayTag = '[object Array]',
  47004. asyncTag = '[object AsyncFunction]',
  47005. boolTag = '[object Boolean]',
  47006. dateTag = '[object Date]',
  47007. errorTag = '[object Error]',
  47008. funcTag = '[object Function]',
  47009. genTag = '[object GeneratorFunction]',
  47010. mapTag = '[object Map]',
  47011. numberTag = '[object Number]',
  47012. nullTag = '[object Null]',
  47013. objectTag = '[object Object]',
  47014. promiseTag = '[object Promise]',
  47015. proxyTag = '[object Proxy]',
  47016. regexpTag = '[object RegExp]',
  47017. setTag = '[object Set]',
  47018. stringTag = '[object String]',
  47019. symbolTag = '[object Symbol]',
  47020. undefinedTag = '[object Undefined]',
  47021. weakMapTag = '[object WeakMap]';
  47022. var arrayBufferTag = '[object ArrayBuffer]',
  47023. dataViewTag = '[object DataView]',
  47024. float32Tag = '[object Float32Array]',
  47025. float64Tag = '[object Float64Array]',
  47026. int8Tag = '[object Int8Array]',
  47027. int16Tag = '[object Int16Array]',
  47028. int32Tag = '[object Int32Array]',
  47029. uint8Tag = '[object Uint8Array]',
  47030. uint8ClampedTag = '[object Uint8ClampedArray]',
  47031. uint16Tag = '[object Uint16Array]',
  47032. uint32Tag = '[object Uint32Array]';
  47033. /**
  47034. * Used to match `RegExp`
  47035. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  47036. */
  47037. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  47038. /** Used to detect host constructors (Safari). */
  47039. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  47040. /** Used to detect unsigned integer values. */
  47041. var reIsUint = /^(?:0|[1-9]\d*)$/;
  47042. /** Used to identify `toStringTag` values of typed arrays. */
  47043. var typedArrayTags = {};
  47044. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = typedArrayTags[uint32Tag] = true;
  47045. 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;
  47046. /** Detect free variable `global` from Node.js. */
  47047. var freeGlobal = (typeof global === "undefined" ? "undefined" : _typeof(global)) == 'object' && global && global.Object === Object && global;
  47048. /** Detect free variable `self`. */
  47049. var freeSelf = (typeof self === "undefined" ? "undefined" : _typeof(self)) == 'object' && self && self.Object === Object && self;
  47050. /** Used as a reference to the global object. */
  47051. var root = freeGlobal || freeSelf || Function('return this')();
  47052. /** Detect free variable `exports`. */
  47053. var freeExports = (typeof exports === "undefined" ? "undefined" : _typeof(exports)) == 'object' && exports && !exports.nodeType && exports;
  47054. /** Detect free variable `module`. */
  47055. var freeModule = freeExports && (typeof module === "undefined" ? "undefined" : _typeof(module)) == 'object' && module && !module.nodeType && module;
  47056. /** Detect the popular CommonJS extension `module.exports`. */
  47057. var moduleExports = freeModule && freeModule.exports === freeExports;
  47058. /** Detect free variable `process` from Node.js. */
  47059. var freeProcess = moduleExports && freeGlobal.process;
  47060. /** Used to access faster Node.js helpers. */
  47061. var nodeUtil = function () {
  47062. try {
  47063. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  47064. } catch (e) {}
  47065. }();
  47066. /* Node.js helper references. */
  47067. var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  47068. /**
  47069. * A specialized version of `_.filter` for arrays without support for
  47070. * iteratee shorthands.
  47071. *
  47072. * @private
  47073. * @param {Array} [array] The array to iterate over.
  47074. * @param {Function} predicate The function invoked per iteration.
  47075. * @returns {Array} Returns the new filtered array.
  47076. */
  47077. function arrayFilter(array, predicate) {
  47078. var index = -1,
  47079. length = array == null ? 0 : array.length,
  47080. resIndex = 0,
  47081. result = [];
  47082. while (++index < length) {
  47083. var value = array[index];
  47084. if (predicate(value, index, array)) {
  47085. result[resIndex++] = value;
  47086. }
  47087. }
  47088. return result;
  47089. }
  47090. /**
  47091. * Appends the elements of `values` to `array`.
  47092. *
  47093. * @private
  47094. * @param {Array} array The array to modify.
  47095. * @param {Array} values The values to append.
  47096. * @returns {Array} Returns `array`.
  47097. */
  47098. function arrayPush(array, values) {
  47099. var index = -1,
  47100. length = values.length,
  47101. offset = array.length;
  47102. while (++index < length) {
  47103. array[offset + index] = values[index];
  47104. }
  47105. return array;
  47106. }
  47107. /**
  47108. * A specialized version of `_.some` for arrays without support for iteratee
  47109. * shorthands.
  47110. *
  47111. * @private
  47112. * @param {Array} [array] The array to iterate over.
  47113. * @param {Function} predicate The function invoked per iteration.
  47114. * @returns {boolean} Returns `true` if any element passes the predicate check,
  47115. * else `false`.
  47116. */
  47117. function arraySome(array, predicate) {
  47118. var index = -1,
  47119. length = array == null ? 0 : array.length;
  47120. while (++index < length) {
  47121. if (predicate(array[index], index, array)) {
  47122. return true;
  47123. }
  47124. }
  47125. return false;
  47126. }
  47127. /**
  47128. * The base implementation of `_.times` without support for iteratee shorthands
  47129. * or max array length checks.
  47130. *
  47131. * @private
  47132. * @param {number} n The number of times to invoke `iteratee`.
  47133. * @param {Function} iteratee The function invoked per iteration.
  47134. * @returns {Array} Returns the array of results.
  47135. */
  47136. function baseTimes(n, iteratee) {
  47137. var index = -1,
  47138. result = Array(n);
  47139. while (++index < n) {
  47140. result[index] = iteratee(index);
  47141. }
  47142. return result;
  47143. }
  47144. /**
  47145. * The base implementation of `_.unary` without support for storing metadata.
  47146. *
  47147. * @private
  47148. * @param {Function} func The function to cap arguments for.
  47149. * @returns {Function} Returns the new capped function.
  47150. */
  47151. function baseUnary(func) {
  47152. return function (value) {
  47153. return func(value);
  47154. };
  47155. }
  47156. /**
  47157. * Checks if a `cache` value for `key` exists.
  47158. *
  47159. * @private
  47160. * @param {Object} cache The cache to query.
  47161. * @param {string} key The key of the entry to check.
  47162. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  47163. */
  47164. function cacheHas(cache, key) {
  47165. return cache.has(key);
  47166. }
  47167. /**
  47168. * Gets the value at `key` of `object`.
  47169. *
  47170. * @private
  47171. * @param {Object} [object] The object to query.
  47172. * @param {string} key The key of the property to get.
  47173. * @returns {*} Returns the property value.
  47174. */
  47175. function getValue(object, key) {
  47176. return object == null ? undefined : object[key];
  47177. }
  47178. /**
  47179. * Converts `map` to its key-value pairs.
  47180. *
  47181. * @private
  47182. * @param {Object} map The map to convert.
  47183. * @returns {Array} Returns the key-value pairs.
  47184. */
  47185. function mapToArray(map) {
  47186. var index = -1,
  47187. result = Array(map.size);
  47188. map.forEach(function (value, key) {
  47189. result[++index] = [key, value];
  47190. });
  47191. return result;
  47192. }
  47193. /**
  47194. * Creates a unary function that invokes `func` with its argument transformed.
  47195. *
  47196. * @private
  47197. * @param {Function} func The function to wrap.
  47198. * @param {Function} transform The argument transform.
  47199. * @returns {Function} Returns the new function.
  47200. */
  47201. function overArg(func, transform) {
  47202. return function (arg) {
  47203. return func(transform(arg));
  47204. };
  47205. }
  47206. /**
  47207. * Converts `set` to an array of its values.
  47208. *
  47209. * @private
  47210. * @param {Object} set The set to convert.
  47211. * @returns {Array} Returns the values.
  47212. */
  47213. function setToArray(set) {
  47214. var index = -1,
  47215. result = Array(set.size);
  47216. set.forEach(function (value) {
  47217. result[++index] = value;
  47218. });
  47219. return result;
  47220. }
  47221. /** Used for built-in method references. */
  47222. var arrayProto = Array.prototype,
  47223. funcProto = Function.prototype,
  47224. objectProto = Object.prototype;
  47225. /** Used to detect overreaching core-js shims. */
  47226. var coreJsData = root['__core-js_shared__'];
  47227. /** Used to resolve the decompiled source of functions. */
  47228. var funcToString = funcProto.toString;
  47229. /** Used to check objects for own properties. */
  47230. var hasOwnProperty = objectProto.hasOwnProperty;
  47231. /** Used to detect methods masquerading as native. */
  47232. var maskSrcKey = function () {
  47233. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  47234. return uid ? 'Symbol(src)_1.' + uid : '';
  47235. }();
  47236. /**
  47237. * Used to resolve the
  47238. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  47239. * of values.
  47240. */
  47241. var nativeObjectToString = objectProto.toString;
  47242. /** Used to detect if a method is native. */
  47243. var reIsNative = RegExp('^' + funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
  47244. /** Built-in value references. */
  47245. var Buffer = moduleExports ? root.Buffer : undefined,
  47246. _Symbol = root.Symbol,
  47247. Uint8Array = root.Uint8Array,
  47248. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  47249. splice = arrayProto.splice,
  47250. symToStringTag = _Symbol ? _Symbol.toStringTag : undefined;
  47251. /* Built-in method references for those with the same name as other `lodash` methods. */
  47252. var nativeGetSymbols = Object.getOwnPropertySymbols,
  47253. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  47254. nativeKeys = overArg(Object.keys, Object);
  47255. /* Built-in method references that are verified to be native. */
  47256. var DataView = getNative(root, 'DataView'),
  47257. Map = getNative(root, 'Map'),
  47258. Promise = getNative(root, 'Promise'),
  47259. Set = getNative(root, 'Set'),
  47260. WeakMap = getNative(root, 'WeakMap'),
  47261. nativeCreate = getNative(Object, 'create');
  47262. /** Used to detect maps, sets, and weakmaps. */
  47263. var dataViewCtorString = toSource(DataView),
  47264. mapCtorString = toSource(Map),
  47265. promiseCtorString = toSource(Promise),
  47266. setCtorString = toSource(Set),
  47267. weakMapCtorString = toSource(WeakMap);
  47268. /** Used to convert symbols to primitives and strings. */
  47269. var symbolProto = _Symbol ? _Symbol.prototype : undefined,
  47270. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
  47271. /**
  47272. * Creates a hash object.
  47273. *
  47274. * @private
  47275. * @constructor
  47276. * @param {Array} [entries] The key-value pairs to cache.
  47277. */
  47278. function Hash(entries) {
  47279. var index = -1,
  47280. length = entries == null ? 0 : entries.length;
  47281. this.clear();
  47282. while (++index < length) {
  47283. var entry = entries[index];
  47284. this.set(entry[0], entry[1]);
  47285. }
  47286. }
  47287. /**
  47288. * Removes all key-value entries from the hash.
  47289. *
  47290. * @private
  47291. * @name clear
  47292. * @memberOf Hash
  47293. */
  47294. function hashClear() {
  47295. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  47296. this.size = 0;
  47297. }
  47298. /**
  47299. * Removes `key` and its value from the hash.
  47300. *
  47301. * @private
  47302. * @name delete
  47303. * @memberOf Hash
  47304. * @param {Object} hash The hash to modify.
  47305. * @param {string} key The key of the value to remove.
  47306. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  47307. */
  47308. function hashDelete(key) {
  47309. var result = this.has(key) && delete this.__data__[key];
  47310. this.size -= result ? 1 : 0;
  47311. return result;
  47312. }
  47313. /**
  47314. * Gets the hash value for `key`.
  47315. *
  47316. * @private
  47317. * @name get
  47318. * @memberOf Hash
  47319. * @param {string} key The key of the value to get.
  47320. * @returns {*} Returns the entry value.
  47321. */
  47322. function hashGet(key) {
  47323. var data = this.__data__;
  47324. if (nativeCreate) {
  47325. var result = data[key];
  47326. return result === HASH_UNDEFINED ? undefined : result;
  47327. }
  47328. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  47329. }
  47330. /**
  47331. * Checks if a hash value for `key` exists.
  47332. *
  47333. * @private
  47334. * @name has
  47335. * @memberOf Hash
  47336. * @param {string} key The key of the entry to check.
  47337. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  47338. */
  47339. function hashHas(key) {
  47340. var data = this.__data__;
  47341. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  47342. }
  47343. /**
  47344. * Sets the hash `key` to `value`.
  47345. *
  47346. * @private
  47347. * @name set
  47348. * @memberOf Hash
  47349. * @param {string} key The key of the value to set.
  47350. * @param {*} value The value to set.
  47351. * @returns {Object} Returns the hash instance.
  47352. */
  47353. function hashSet(key, value) {
  47354. var data = this.__data__;
  47355. this.size += this.has(key) ? 0 : 1;
  47356. data[key] = nativeCreate && value === undefined ? HASH_UNDEFINED : value;
  47357. return this;
  47358. } // Add methods to `Hash`.
  47359. Hash.prototype.clear = hashClear;
  47360. Hash.prototype['delete'] = hashDelete;
  47361. Hash.prototype.get = hashGet;
  47362. Hash.prototype.has = hashHas;
  47363. Hash.prototype.set = hashSet;
  47364. /**
  47365. * Creates an list cache object.
  47366. *
  47367. * @private
  47368. * @constructor
  47369. * @param {Array} [entries] The key-value pairs to cache.
  47370. */
  47371. function ListCache(entries) {
  47372. var index = -1,
  47373. length = entries == null ? 0 : entries.length;
  47374. this.clear();
  47375. while (++index < length) {
  47376. var entry = entries[index];
  47377. this.set(entry[0], entry[1]);
  47378. }
  47379. }
  47380. /**
  47381. * Removes all key-value entries from the list cache.
  47382. *
  47383. * @private
  47384. * @name clear
  47385. * @memberOf ListCache
  47386. */
  47387. function listCacheClear() {
  47388. this.__data__ = [];
  47389. this.size = 0;
  47390. }
  47391. /**
  47392. * Removes `key` and its value from the list cache.
  47393. *
  47394. * @private
  47395. * @name delete
  47396. * @memberOf ListCache
  47397. * @param {string} key The key of the value to remove.
  47398. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  47399. */
  47400. function listCacheDelete(key) {
  47401. var data = this.__data__,
  47402. index = assocIndexOf(data, key);
  47403. if (index < 0) {
  47404. return false;
  47405. }
  47406. var lastIndex = data.length - 1;
  47407. if (index == lastIndex) {
  47408. data.pop();
  47409. } else {
  47410. splice.call(data, index, 1);
  47411. }
  47412. --this.size;
  47413. return true;
  47414. }
  47415. /**
  47416. * Gets the list cache value for `key`.
  47417. *
  47418. * @private
  47419. * @name get
  47420. * @memberOf ListCache
  47421. * @param {string} key The key of the value to get.
  47422. * @returns {*} Returns the entry value.
  47423. */
  47424. function listCacheGet(key) {
  47425. var data = this.__data__,
  47426. index = assocIndexOf(data, key);
  47427. return index < 0 ? undefined : data[index][1];
  47428. }
  47429. /**
  47430. * Checks if a list cache value for `key` exists.
  47431. *
  47432. * @private
  47433. * @name has
  47434. * @memberOf ListCache
  47435. * @param {string} key The key of the entry to check.
  47436. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  47437. */
  47438. function listCacheHas(key) {
  47439. return assocIndexOf(this.__data__, key) > -1;
  47440. }
  47441. /**
  47442. * Sets the list cache `key` to `value`.
  47443. *
  47444. * @private
  47445. * @name set
  47446. * @memberOf ListCache
  47447. * @param {string} key The key of the value to set.
  47448. * @param {*} value The value to set.
  47449. * @returns {Object} Returns the list cache instance.
  47450. */
  47451. function listCacheSet(key, value) {
  47452. var data = this.__data__,
  47453. index = assocIndexOf(data, key);
  47454. if (index < 0) {
  47455. ++this.size;
  47456. data.push([key, value]);
  47457. } else {
  47458. data[index][1] = value;
  47459. }
  47460. return this;
  47461. } // Add methods to `ListCache`.
  47462. ListCache.prototype.clear = listCacheClear;
  47463. ListCache.prototype['delete'] = listCacheDelete;
  47464. ListCache.prototype.get = listCacheGet;
  47465. ListCache.prototype.has = listCacheHas;
  47466. ListCache.prototype.set = listCacheSet;
  47467. /**
  47468. * Creates a map cache object to store key-value pairs.
  47469. *
  47470. * @private
  47471. * @constructor
  47472. * @param {Array} [entries] The key-value pairs to cache.
  47473. */
  47474. function MapCache(entries) {
  47475. var index = -1,
  47476. length = entries == null ? 0 : entries.length;
  47477. this.clear();
  47478. while (++index < length) {
  47479. var entry = entries[index];
  47480. this.set(entry[0], entry[1]);
  47481. }
  47482. }
  47483. /**
  47484. * Removes all key-value entries from the map.
  47485. *
  47486. * @private
  47487. * @name clear
  47488. * @memberOf MapCache
  47489. */
  47490. function mapCacheClear() {
  47491. this.size = 0;
  47492. this.__data__ = {
  47493. 'hash': new Hash(),
  47494. 'map': new (Map || ListCache)(),
  47495. 'string': new Hash()
  47496. };
  47497. }
  47498. /**
  47499. * Removes `key` and its value from the map.
  47500. *
  47501. * @private
  47502. * @name delete
  47503. * @memberOf MapCache
  47504. * @param {string} key The key of the value to remove.
  47505. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  47506. */
  47507. function mapCacheDelete(key) {
  47508. var result = getMapData(this, key)['delete'](key);
  47509. this.size -= result ? 1 : 0;
  47510. return result;
  47511. }
  47512. /**
  47513. * Gets the map value for `key`.
  47514. *
  47515. * @private
  47516. * @name get
  47517. * @memberOf MapCache
  47518. * @param {string} key The key of the value to get.
  47519. * @returns {*} Returns the entry value.
  47520. */
  47521. function mapCacheGet(key) {
  47522. return getMapData(this, key).get(key);
  47523. }
  47524. /**
  47525. * Checks if a map value for `key` exists.
  47526. *
  47527. * @private
  47528. * @name has
  47529. * @memberOf MapCache
  47530. * @param {string} key The key of the entry to check.
  47531. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  47532. */
  47533. function mapCacheHas(key) {
  47534. return getMapData(this, key).has(key);
  47535. }
  47536. /**
  47537. * Sets the map `key` to `value`.
  47538. *
  47539. * @private
  47540. * @name set
  47541. * @memberOf MapCache
  47542. * @param {string} key The key of the value to set.
  47543. * @param {*} value The value to set.
  47544. * @returns {Object} Returns the map cache instance.
  47545. */
  47546. function mapCacheSet(key, value) {
  47547. var data = getMapData(this, key),
  47548. size = data.size;
  47549. data.set(key, value);
  47550. this.size += data.size == size ? 0 : 1;
  47551. return this;
  47552. } // Add methods to `MapCache`.
  47553. MapCache.prototype.clear = mapCacheClear;
  47554. MapCache.prototype['delete'] = mapCacheDelete;
  47555. MapCache.prototype.get = mapCacheGet;
  47556. MapCache.prototype.has = mapCacheHas;
  47557. MapCache.prototype.set = mapCacheSet;
  47558. /**
  47559. *
  47560. * Creates an array cache object to store unique values.
  47561. *
  47562. * @private
  47563. * @constructor
  47564. * @param {Array} [values] The values to cache.
  47565. */
  47566. function SetCache(values) {
  47567. var index = -1,
  47568. length = values == null ? 0 : values.length;
  47569. this.__data__ = new MapCache();
  47570. while (++index < length) {
  47571. this.add(values[index]);
  47572. }
  47573. }
  47574. /**
  47575. * Adds `value` to the array cache.
  47576. *
  47577. * @private
  47578. * @name add
  47579. * @memberOf SetCache
  47580. * @alias push
  47581. * @param {*} value The value to cache.
  47582. * @returns {Object} Returns the cache instance.
  47583. */
  47584. function setCacheAdd(value) {
  47585. this.__data__.set(value, HASH_UNDEFINED);
  47586. return this;
  47587. }
  47588. /**
  47589. * Checks if `value` is in the array cache.
  47590. *
  47591. * @private
  47592. * @name has
  47593. * @memberOf SetCache
  47594. * @param {*} value The value to search for.
  47595. * @returns {number} Returns `true` if `value` is found, else `false`.
  47596. */
  47597. function setCacheHas(value) {
  47598. return this.__data__.has(value);
  47599. } // Add methods to `SetCache`.
  47600. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  47601. SetCache.prototype.has = setCacheHas;
  47602. /**
  47603. * Creates a stack cache object to store key-value pairs.
  47604. *
  47605. * @private
  47606. * @constructor
  47607. * @param {Array} [entries] The key-value pairs to cache.
  47608. */
  47609. function Stack(entries) {
  47610. var data = this.__data__ = new ListCache(entries);
  47611. this.size = data.size;
  47612. }
  47613. /**
  47614. * Removes all key-value entries from the stack.
  47615. *
  47616. * @private
  47617. * @name clear
  47618. * @memberOf Stack
  47619. */
  47620. function stackClear() {
  47621. this.__data__ = new ListCache();
  47622. this.size = 0;
  47623. }
  47624. /**
  47625. * Removes `key` and its value from the stack.
  47626. *
  47627. * @private
  47628. * @name delete
  47629. * @memberOf Stack
  47630. * @param {string} key The key of the value to remove.
  47631. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  47632. */
  47633. function stackDelete(key) {
  47634. var data = this.__data__,
  47635. result = data['delete'](key);
  47636. this.size = data.size;
  47637. return result;
  47638. }
  47639. /**
  47640. * Gets the stack value for `key`.
  47641. *
  47642. * @private
  47643. * @name get
  47644. * @memberOf Stack
  47645. * @param {string} key The key of the value to get.
  47646. * @returns {*} Returns the entry value.
  47647. */
  47648. function stackGet(key) {
  47649. return this.__data__.get(key);
  47650. }
  47651. /**
  47652. * Checks if a stack value for `key` exists.
  47653. *
  47654. * @private
  47655. * @name has
  47656. * @memberOf Stack
  47657. * @param {string} key The key of the entry to check.
  47658. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  47659. */
  47660. function stackHas(key) {
  47661. return this.__data__.has(key);
  47662. }
  47663. /**
  47664. * Sets the stack `key` to `value`.
  47665. *
  47666. * @private
  47667. * @name set
  47668. * @memberOf Stack
  47669. * @param {string} key The key of the value to set.
  47670. * @param {*} value The value to set.
  47671. * @returns {Object} Returns the stack cache instance.
  47672. */
  47673. function stackSet(key, value) {
  47674. var data = this.__data__;
  47675. if (data instanceof ListCache) {
  47676. var pairs = data.__data__;
  47677. if (!Map || pairs.length < LARGE_ARRAY_SIZE - 1) {
  47678. pairs.push([key, value]);
  47679. this.size = ++data.size;
  47680. return this;
  47681. }
  47682. data = this.__data__ = new MapCache(pairs);
  47683. }
  47684. data.set(key, value);
  47685. this.size = data.size;
  47686. return this;
  47687. } // Add methods to `Stack`.
  47688. Stack.prototype.clear = stackClear;
  47689. Stack.prototype['delete'] = stackDelete;
  47690. Stack.prototype.get = stackGet;
  47691. Stack.prototype.has = stackHas;
  47692. Stack.prototype.set = stackSet;
  47693. /**
  47694. * Creates an array of the enumerable property names of the array-like `value`.
  47695. *
  47696. * @private
  47697. * @param {*} value The value to query.
  47698. * @param {boolean} inherited Specify returning inherited property names.
  47699. * @returns {Array} Returns the array of property names.
  47700. */
  47701. function arrayLikeKeys(value, inherited) {
  47702. var isArr = isArray(value),
  47703. isArg = !isArr && isArguments(value),
  47704. isBuff = !isArr && !isArg && isBuffer(value),
  47705. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  47706. skipIndexes = isArr || isArg || isBuff || isType,
  47707. result = skipIndexes ? baseTimes(value.length, String) : [],
  47708. length = result.length;
  47709. for (var key in value) {
  47710. if ((inherited || hasOwnProperty.call(value, key)) && !(skipIndexes && ( // Safari 9 has enumerable `arguments.length` in strict mode.
  47711. key == 'length' || // Node.js 0.10 has enumerable non-index properties on buffers.
  47712. isBuff && (key == 'offset' || key == 'parent') || // PhantomJS 2 has enumerable non-index properties on typed arrays.
  47713. isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset') || // Skip index properties.
  47714. isIndex(key, length)))) {
  47715. result.push(key);
  47716. }
  47717. }
  47718. return result;
  47719. }
  47720. /**
  47721. * Gets the index at which the `key` is found in `array` of key-value pairs.
  47722. *
  47723. * @private
  47724. * @param {Array} array The array to inspect.
  47725. * @param {*} key The key to search for.
  47726. * @returns {number} Returns the index of the matched value, else `-1`.
  47727. */
  47728. function assocIndexOf(array, key) {
  47729. var length = array.length;
  47730. while (length--) {
  47731. if (eq(array[length][0], key)) {
  47732. return length;
  47733. }
  47734. }
  47735. return -1;
  47736. }
  47737. /**
  47738. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  47739. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  47740. * symbols of `object`.
  47741. *
  47742. * @private
  47743. * @param {Object} object The object to query.
  47744. * @param {Function} keysFunc The function to get the keys of `object`.
  47745. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  47746. * @returns {Array} Returns the array of property names and symbols.
  47747. */
  47748. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  47749. var result = keysFunc(object);
  47750. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  47751. }
  47752. /**
  47753. * The base implementation of `getTag` without fallbacks for buggy environments.
  47754. *
  47755. * @private
  47756. * @param {*} value The value to query.
  47757. * @returns {string} Returns the `toStringTag`.
  47758. */
  47759. function baseGetTag(value) {
  47760. if (value == null) {
  47761. return value === undefined ? undefinedTag : nullTag;
  47762. }
  47763. return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
  47764. }
  47765. /**
  47766. * The base implementation of `_.isArguments`.
  47767. *
  47768. * @private
  47769. * @param {*} value The value to check.
  47770. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  47771. */
  47772. function baseIsArguments(value) {
  47773. return isObjectLike(value) && baseGetTag(value) == argsTag;
  47774. }
  47775. /**
  47776. * The base implementation of `_.isEqual` which supports partial comparisons
  47777. * and tracks traversed objects.
  47778. *
  47779. * @private
  47780. * @param {*} value The value to compare.
  47781. * @param {*} other The other value to compare.
  47782. * @param {boolean} bitmask The bitmask flags.
  47783. * 1 - Unordered comparison
  47784. * 2 - Partial comparison
  47785. * @param {Function} [customizer] The function to customize comparisons.
  47786. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  47787. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  47788. */
  47789. function baseIsEqual(value, other, bitmask, customizer, stack) {
  47790. if (value === other) {
  47791. return true;
  47792. }
  47793. if (value == null || other == null || !isObjectLike(value) && !isObjectLike(other)) {
  47794. return value !== value && other !== other;
  47795. }
  47796. return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  47797. }
  47798. /**
  47799. * A specialized version of `baseIsEqual` for arrays and objects which performs
  47800. * deep comparisons and tracks traversed objects enabling objects with circular
  47801. * references to be compared.
  47802. *
  47803. * @private
  47804. * @param {Object} object The object to compare.
  47805. * @param {Object} other The other object to compare.
  47806. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  47807. * @param {Function} customizer The function to customize comparisons.
  47808. * @param {Function} equalFunc The function to determine equivalents of values.
  47809. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  47810. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  47811. */
  47812. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  47813. var objIsArr = isArray(object),
  47814. othIsArr = isArray(other),
  47815. objTag = objIsArr ? arrayTag : getTag(object),
  47816. othTag = othIsArr ? arrayTag : getTag(other);
  47817. objTag = objTag == argsTag ? objectTag : objTag;
  47818. othTag = othTag == argsTag ? objectTag : othTag;
  47819. var objIsObj = objTag == objectTag,
  47820. othIsObj = othTag == objectTag,
  47821. isSameTag = objTag == othTag;
  47822. if (isSameTag && isBuffer(object)) {
  47823. if (!isBuffer(other)) {
  47824. return false;
  47825. }
  47826. objIsArr = true;
  47827. objIsObj = false;
  47828. }
  47829. if (isSameTag && !objIsObj) {
  47830. stack || (stack = new Stack());
  47831. return objIsArr || isTypedArray(object) ? equalArrays(object, other, bitmask, customizer, equalFunc, stack) : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  47832. }
  47833. if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
  47834. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  47835. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  47836. if (objIsWrapped || othIsWrapped) {
  47837. var objUnwrapped = objIsWrapped ? object.value() : object,
  47838. othUnwrapped = othIsWrapped ? other.value() : other;
  47839. stack || (stack = new Stack());
  47840. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  47841. }
  47842. }
  47843. if (!isSameTag) {
  47844. return false;
  47845. }
  47846. stack || (stack = new Stack());
  47847. return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  47848. }
  47849. /**
  47850. * The base implementation of `_.isNative` without bad shim checks.
  47851. *
  47852. * @private
  47853. * @param {*} value The value to check.
  47854. * @returns {boolean} Returns `true` if `value` is a native function,
  47855. * else `false`.
  47856. */
  47857. function baseIsNative(value) {
  47858. if (!isObject(value) || isMasked(value)) {
  47859. return false;
  47860. }
  47861. var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  47862. return pattern.test(toSource(value));
  47863. }
  47864. /**
  47865. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  47866. *
  47867. * @private
  47868. * @param {*} value The value to check.
  47869. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  47870. */
  47871. function baseIsTypedArray(value) {
  47872. return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
  47873. }
  47874. /**
  47875. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  47876. *
  47877. * @private
  47878. * @param {Object} object The object to query.
  47879. * @returns {Array} Returns the array of property names.
  47880. */
  47881. function baseKeys(object) {
  47882. if (!isPrototype(object)) {
  47883. return nativeKeys(object);
  47884. }
  47885. var result = [];
  47886. for (var key in Object(object)) {
  47887. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  47888. result.push(key);
  47889. }
  47890. }
  47891. return result;
  47892. }
  47893. /**
  47894. * A specialized version of `baseIsEqualDeep` for arrays with support for
  47895. * partial deep comparisons.
  47896. *
  47897. * @private
  47898. * @param {Array} array The array to compare.
  47899. * @param {Array} other The other array to compare.
  47900. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  47901. * @param {Function} customizer The function to customize comparisons.
  47902. * @param {Function} equalFunc The function to determine equivalents of values.
  47903. * @param {Object} stack Tracks traversed `array` and `other` objects.
  47904. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  47905. */
  47906. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  47907. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  47908. arrLength = array.length,
  47909. othLength = other.length;
  47910. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  47911. return false;
  47912. } // Assume cyclic values are equal.
  47913. var stacked = stack.get(array);
  47914. if (stacked && stack.get(other)) {
  47915. return stacked == other;
  47916. }
  47917. var index = -1,
  47918. result = true,
  47919. seen = bitmask & COMPARE_UNORDERED_FLAG ? new SetCache() : undefined;
  47920. stack.set(array, other);
  47921. stack.set(other, array); // Ignore non-index properties.
  47922. while (++index < arrLength) {
  47923. var arrValue = array[index],
  47924. othValue = other[index];
  47925. if (customizer) {
  47926. var compared = isPartial ? customizer(othValue, arrValue, index, other, array, stack) : customizer(arrValue, othValue, index, array, other, stack);
  47927. }
  47928. if (compared !== undefined) {
  47929. if (compared) {
  47930. continue;
  47931. }
  47932. result = false;
  47933. break;
  47934. } // Recursively compare arrays (susceptible to call stack limits).
  47935. if (seen) {
  47936. if (!arraySome(other, function (othValue, othIndex) {
  47937. if (!cacheHas(seen, othIndex) && (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  47938. return seen.push(othIndex);
  47939. }
  47940. })) {
  47941. result = false;
  47942. break;
  47943. }
  47944. } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  47945. result = false;
  47946. break;
  47947. }
  47948. }
  47949. stack['delete'](array);
  47950. stack['delete'](other);
  47951. return result;
  47952. }
  47953. /**
  47954. * A specialized version of `baseIsEqualDeep` for comparing objects of
  47955. * the same `toStringTag`.
  47956. *
  47957. * **Note:** This function only supports comparing values with tags of
  47958. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  47959. *
  47960. * @private
  47961. * @param {Object} object The object to compare.
  47962. * @param {Object} other The other object to compare.
  47963. * @param {string} tag The `toStringTag` of the objects to compare.
  47964. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  47965. * @param {Function} customizer The function to customize comparisons.
  47966. * @param {Function} equalFunc The function to determine equivalents of values.
  47967. * @param {Object} stack Tracks traversed `object` and `other` objects.
  47968. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  47969. */
  47970. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  47971. switch (tag) {
  47972. case dataViewTag:
  47973. if (object.byteLength != other.byteLength || object.byteOffset != other.byteOffset) {
  47974. return false;
  47975. }
  47976. object = object.buffer;
  47977. other = other.buffer;
  47978. case arrayBufferTag:
  47979. if (object.byteLength != other.byteLength || !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  47980. return false;
  47981. }
  47982. return true;
  47983. case boolTag:
  47984. case dateTag:
  47985. case numberTag:
  47986. // Coerce booleans to `1` or `0` and dates to milliseconds.
  47987. // Invalid dates are coerced to `NaN`.
  47988. return eq(+object, +other);
  47989. case errorTag:
  47990. return object.name == other.name && object.message == other.message;
  47991. case regexpTag:
  47992. case stringTag:
  47993. // Coerce regexes to strings and treat strings, primitives and objects,
  47994. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  47995. // for more details.
  47996. return object == other + '';
  47997. case mapTag:
  47998. var convert = mapToArray;
  47999. case setTag:
  48000. var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
  48001. convert || (convert = setToArray);
  48002. if (object.size != other.size && !isPartial) {
  48003. return false;
  48004. } // Assume cyclic values are equal.
  48005. var stacked = stack.get(object);
  48006. if (stacked) {
  48007. return stacked == other;
  48008. }
  48009. bitmask |= COMPARE_UNORDERED_FLAG; // Recursively compare objects (susceptible to call stack limits).
  48010. stack.set(object, other);
  48011. var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  48012. stack['delete'](object);
  48013. return result;
  48014. case symbolTag:
  48015. if (symbolValueOf) {
  48016. return symbolValueOf.call(object) == symbolValueOf.call(other);
  48017. }
  48018. }
  48019. return false;
  48020. }
  48021. /**
  48022. * A specialized version of `baseIsEqualDeep` for objects with support for
  48023. * partial deep comparisons.
  48024. *
  48025. * @private
  48026. * @param {Object} object The object to compare.
  48027. * @param {Object} other The other object to compare.
  48028. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  48029. * @param {Function} customizer The function to customize comparisons.
  48030. * @param {Function} equalFunc The function to determine equivalents of values.
  48031. * @param {Object} stack Tracks traversed `object` and `other` objects.
  48032. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  48033. */
  48034. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  48035. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  48036. objProps = getAllKeys(object),
  48037. objLength = objProps.length,
  48038. othProps = getAllKeys(other),
  48039. othLength = othProps.length;
  48040. if (objLength != othLength && !isPartial) {
  48041. return false;
  48042. }
  48043. var index = objLength;
  48044. while (index--) {
  48045. var key = objProps[index];
  48046. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  48047. return false;
  48048. }
  48049. } // Assume cyclic values are equal.
  48050. var stacked = stack.get(object);
  48051. if (stacked && stack.get(other)) {
  48052. return stacked == other;
  48053. }
  48054. var result = true;
  48055. stack.set(object, other);
  48056. stack.set(other, object);
  48057. var skipCtor = isPartial;
  48058. while (++index < objLength) {
  48059. key = objProps[index];
  48060. var objValue = object[key],
  48061. othValue = other[key];
  48062. if (customizer) {
  48063. var compared = isPartial ? customizer(othValue, objValue, key, other, object, stack) : customizer(objValue, othValue, key, object, other, stack);
  48064. } // Recursively compare objects (susceptible to call stack limits).
  48065. if (!(compared === undefined ? objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack) : compared)) {
  48066. result = false;
  48067. break;
  48068. }
  48069. skipCtor || (skipCtor = key == 'constructor');
  48070. }
  48071. if (result && !skipCtor) {
  48072. var objCtor = object.constructor,
  48073. othCtor = other.constructor; // Non `Object` object instances with different constructors are not equal.
  48074. if (objCtor != othCtor && 'constructor' in object && 'constructor' in other && !(typeof objCtor == 'function' && objCtor instanceof objCtor && typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  48075. result = false;
  48076. }
  48077. }
  48078. stack['delete'](object);
  48079. stack['delete'](other);
  48080. return result;
  48081. }
  48082. /**
  48083. * Creates an array of own enumerable property names and symbols of `object`.
  48084. *
  48085. * @private
  48086. * @param {Object} object The object to query.
  48087. * @returns {Array} Returns the array of property names and symbols.
  48088. */
  48089. function getAllKeys(object) {
  48090. return baseGetAllKeys(object, keys, getSymbols);
  48091. }
  48092. /**
  48093. * Gets the data for `map`.
  48094. *
  48095. * @private
  48096. * @param {Object} map The map to query.
  48097. * @param {string} key The reference key.
  48098. * @returns {*} Returns the map data.
  48099. */
  48100. function getMapData(map, key) {
  48101. var data = map.__data__;
  48102. return isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
  48103. }
  48104. /**
  48105. * Gets the native function at `key` of `object`.
  48106. *
  48107. * @private
  48108. * @param {Object} object The object to query.
  48109. * @param {string} key The key of the method to get.
  48110. * @returns {*} Returns the function if it's native, else `undefined`.
  48111. */
  48112. function getNative(object, key) {
  48113. var value = getValue(object, key);
  48114. return baseIsNative(value) ? value : undefined;
  48115. }
  48116. /**
  48117. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  48118. *
  48119. * @private
  48120. * @param {*} value The value to query.
  48121. * @returns {string} Returns the raw `toStringTag`.
  48122. */
  48123. function getRawTag(value) {
  48124. var isOwn = hasOwnProperty.call(value, symToStringTag),
  48125. tag = value[symToStringTag];
  48126. try {
  48127. value[symToStringTag] = undefined;
  48128. var unmasked = true;
  48129. } catch (e) {}
  48130. var result = nativeObjectToString.call(value);
  48131. if (unmasked) {
  48132. if (isOwn) {
  48133. value[symToStringTag] = tag;
  48134. } else {
  48135. delete value[symToStringTag];
  48136. }
  48137. }
  48138. return result;
  48139. }
  48140. /**
  48141. * Creates an array of the own enumerable symbols of `object`.
  48142. *
  48143. * @private
  48144. * @param {Object} object The object to query.
  48145. * @returns {Array} Returns the array of symbols.
  48146. */
  48147. var getSymbols = !nativeGetSymbols ? stubArray : function (object) {
  48148. if (object == null) {
  48149. return [];
  48150. }
  48151. object = Object(object);
  48152. return arrayFilter(nativeGetSymbols(object), function (symbol) {
  48153. return propertyIsEnumerable.call(object, symbol);
  48154. });
  48155. };
  48156. /**
  48157. * Gets the `toStringTag` of `value`.
  48158. *
  48159. * @private
  48160. * @param {*} value The value to query.
  48161. * @returns {string} Returns the `toStringTag`.
  48162. */
  48163. var getTag = baseGetTag; // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  48164. 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) {
  48165. getTag = function getTag(value) {
  48166. var result = baseGetTag(value),
  48167. Ctor = result == objectTag ? value.constructor : undefined,
  48168. ctorString = Ctor ? toSource(Ctor) : '';
  48169. if (ctorString) {
  48170. switch (ctorString) {
  48171. case dataViewCtorString:
  48172. return dataViewTag;
  48173. case mapCtorString:
  48174. return mapTag;
  48175. case promiseCtorString:
  48176. return promiseTag;
  48177. case setCtorString:
  48178. return setTag;
  48179. case weakMapCtorString:
  48180. return weakMapTag;
  48181. }
  48182. }
  48183. return result;
  48184. };
  48185. }
  48186. /**
  48187. * Checks if `value` is a valid array-like index.
  48188. *
  48189. * @private
  48190. * @param {*} value The value to check.
  48191. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  48192. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  48193. */
  48194. function isIndex(value, length) {
  48195. length = length == null ? MAX_SAFE_INTEGER : length;
  48196. return !!length && (typeof value == 'number' || reIsUint.test(value)) && value > -1 && value % 1 == 0 && value < length;
  48197. }
  48198. /**
  48199. * Checks if `value` is suitable for use as unique object key.
  48200. *
  48201. * @private
  48202. * @param {*} value The value to check.
  48203. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  48204. */
  48205. function isKeyable(value) {
  48206. var type = _typeof(value);
  48207. return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean' ? value !== '__proto__' : value === null;
  48208. }
  48209. /**
  48210. * Checks if `func` has its source masked.
  48211. *
  48212. * @private
  48213. * @param {Function} func The function to check.
  48214. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  48215. */
  48216. function isMasked(func) {
  48217. return !!maskSrcKey && maskSrcKey in func;
  48218. }
  48219. /**
  48220. * Checks if `value` is likely a prototype object.
  48221. *
  48222. * @private
  48223. * @param {*} value The value to check.
  48224. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  48225. */
  48226. function isPrototype(value) {
  48227. var Ctor = value && value.constructor,
  48228. proto = typeof Ctor == 'function' && Ctor.prototype || objectProto;
  48229. return value === proto;
  48230. }
  48231. /**
  48232. * Converts `value` to a string using `Object.prototype.toString`.
  48233. *
  48234. * @private
  48235. * @param {*} value The value to convert.
  48236. * @returns {string} Returns the converted string.
  48237. */
  48238. function objectToString(value) {
  48239. return nativeObjectToString.call(value);
  48240. }
  48241. /**
  48242. * Converts `func` to its source code.
  48243. *
  48244. * @private
  48245. * @param {Function} func The function to convert.
  48246. * @returns {string} Returns the source code.
  48247. */
  48248. function toSource(func) {
  48249. if (func != null) {
  48250. try {
  48251. return funcToString.call(func);
  48252. } catch (e) {}
  48253. try {
  48254. return func + '';
  48255. } catch (e) {}
  48256. }
  48257. return '';
  48258. }
  48259. /**
  48260. * Performs a
  48261. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  48262. * comparison between two values to determine if they are equivalent.
  48263. *
  48264. * @static
  48265. * @memberOf _
  48266. * @since 4.0.0
  48267. * @category Lang
  48268. * @param {*} value The value to compare.
  48269. * @param {*} other The other value to compare.
  48270. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  48271. * @example
  48272. *
  48273. * var object = { 'a': 1 };
  48274. * var other = { 'a': 1 };
  48275. *
  48276. * _.eq(object, object);
  48277. * // => true
  48278. *
  48279. * _.eq(object, other);
  48280. * // => false
  48281. *
  48282. * _.eq('a', 'a');
  48283. * // => true
  48284. *
  48285. * _.eq('a', Object('a'));
  48286. * // => false
  48287. *
  48288. * _.eq(NaN, NaN);
  48289. * // => true
  48290. */
  48291. function eq(value, other) {
  48292. return value === other || value !== value && other !== other;
  48293. }
  48294. /**
  48295. * Checks if `value` is likely an `arguments` object.
  48296. *
  48297. * @static
  48298. * @memberOf _
  48299. * @since 0.1.0
  48300. * @category Lang
  48301. * @param {*} value The value to check.
  48302. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  48303. * else `false`.
  48304. * @example
  48305. *
  48306. * _.isArguments(function() { return arguments; }());
  48307. * // => true
  48308. *
  48309. * _.isArguments([1, 2, 3]);
  48310. * // => false
  48311. */
  48312. var isArguments = baseIsArguments(function () {
  48313. return arguments;
  48314. }()) ? baseIsArguments : function (value) {
  48315. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
  48316. };
  48317. /**
  48318. * Checks if `value` is classified as an `Array` object.
  48319. *
  48320. * @static
  48321. * @memberOf _
  48322. * @since 0.1.0
  48323. * @category Lang
  48324. * @param {*} value The value to check.
  48325. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  48326. * @example
  48327. *
  48328. * _.isArray([1, 2, 3]);
  48329. * // => true
  48330. *
  48331. * _.isArray(document.body.children);
  48332. * // => false
  48333. *
  48334. * _.isArray('abc');
  48335. * // => false
  48336. *
  48337. * _.isArray(_.noop);
  48338. * // => false
  48339. */
  48340. var isArray = Array.isArray;
  48341. /**
  48342. * Checks if `value` is array-like. A value is considered array-like if it's
  48343. * not a function and has a `value.length` that's an integer greater than or
  48344. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  48345. *
  48346. * @static
  48347. * @memberOf _
  48348. * @since 4.0.0
  48349. * @category Lang
  48350. * @param {*} value The value to check.
  48351. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  48352. * @example
  48353. *
  48354. * _.isArrayLike([1, 2, 3]);
  48355. * // => true
  48356. *
  48357. * _.isArrayLike(document.body.children);
  48358. * // => true
  48359. *
  48360. * _.isArrayLike('abc');
  48361. * // => true
  48362. *
  48363. * _.isArrayLike(_.noop);
  48364. * // => false
  48365. */
  48366. function isArrayLike(value) {
  48367. return value != null && isLength(value.length) && !isFunction(value);
  48368. }
  48369. /**
  48370. * Checks if `value` is a buffer.
  48371. *
  48372. * @static
  48373. * @memberOf _
  48374. * @since 4.3.0
  48375. * @category Lang
  48376. * @param {*} value The value to check.
  48377. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  48378. * @example
  48379. *
  48380. * _.isBuffer(new Buffer(2));
  48381. * // => true
  48382. *
  48383. * _.isBuffer(new Uint8Array(2));
  48384. * // => false
  48385. */
  48386. var isBuffer = nativeIsBuffer || stubFalse;
  48387. /**
  48388. * Performs a deep comparison between two values to determine if they are
  48389. * equivalent.
  48390. *
  48391. * **Note:** This method supports comparing arrays, array buffers, booleans,
  48392. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  48393. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  48394. * by their own, not inherited, enumerable properties. Functions and DOM
  48395. * nodes are compared by strict equality, i.e. `===`.
  48396. *
  48397. * @static
  48398. * @memberOf _
  48399. * @since 0.1.0
  48400. * @category Lang
  48401. * @param {*} value The value to compare.
  48402. * @param {*} other The other value to compare.
  48403. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  48404. * @example
  48405. *
  48406. * var object = { 'a': 1 };
  48407. * var other = { 'a': 1 };
  48408. *
  48409. * _.isEqual(object, other);
  48410. * // => true
  48411. *
  48412. * object === other;
  48413. * // => false
  48414. */
  48415. function isEqual(value, other) {
  48416. return baseIsEqual(value, other);
  48417. }
  48418. /**
  48419. * Checks if `value` is classified as a `Function` object.
  48420. *
  48421. * @static
  48422. * @memberOf _
  48423. * @since 0.1.0
  48424. * @category Lang
  48425. * @param {*} value The value to check.
  48426. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  48427. * @example
  48428. *
  48429. * _.isFunction(_);
  48430. * // => true
  48431. *
  48432. * _.isFunction(/abc/);
  48433. * // => false
  48434. */
  48435. function isFunction(value) {
  48436. if (!isObject(value)) {
  48437. return false;
  48438. } // The use of `Object#toString` avoids issues with the `typeof` operator
  48439. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  48440. var tag = baseGetTag(value);
  48441. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  48442. }
  48443. /**
  48444. * Checks if `value` is a valid array-like length.
  48445. *
  48446. * **Note:** This method is loosely based on
  48447. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  48448. *
  48449. * @static
  48450. * @memberOf _
  48451. * @since 4.0.0
  48452. * @category Lang
  48453. * @param {*} value The value to check.
  48454. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  48455. * @example
  48456. *
  48457. * _.isLength(3);
  48458. * // => true
  48459. *
  48460. * _.isLength(Number.MIN_VALUE);
  48461. * // => false
  48462. *
  48463. * _.isLength(Infinity);
  48464. * // => false
  48465. *
  48466. * _.isLength('3');
  48467. * // => false
  48468. */
  48469. function isLength(value) {
  48470. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  48471. }
  48472. /**
  48473. * Checks if `value` is the
  48474. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  48475. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  48476. *
  48477. * @static
  48478. * @memberOf _
  48479. * @since 0.1.0
  48480. * @category Lang
  48481. * @param {*} value The value to check.
  48482. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  48483. * @example
  48484. *
  48485. * _.isObject({});
  48486. * // => true
  48487. *
  48488. * _.isObject([1, 2, 3]);
  48489. * // => true
  48490. *
  48491. * _.isObject(_.noop);
  48492. * // => true
  48493. *
  48494. * _.isObject(null);
  48495. * // => false
  48496. */
  48497. function isObject(value) {
  48498. var type = _typeof(value);
  48499. return value != null && (type == 'object' || type == 'function');
  48500. }
  48501. /**
  48502. * Checks if `value` is object-like. A value is object-like if it's not `null`
  48503. * and has a `typeof` result of "object".
  48504. *
  48505. * @static
  48506. * @memberOf _
  48507. * @since 4.0.0
  48508. * @category Lang
  48509. * @param {*} value The value to check.
  48510. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  48511. * @example
  48512. *
  48513. * _.isObjectLike({});
  48514. * // => true
  48515. *
  48516. * _.isObjectLike([1, 2, 3]);
  48517. * // => true
  48518. *
  48519. * _.isObjectLike(_.noop);
  48520. * // => false
  48521. *
  48522. * _.isObjectLike(null);
  48523. * // => false
  48524. */
  48525. function isObjectLike(value) {
  48526. return value != null && _typeof(value) == 'object';
  48527. }
  48528. /**
  48529. * Checks if `value` is classified as a typed array.
  48530. *
  48531. * @static
  48532. * @memberOf _
  48533. * @since 3.0.0
  48534. * @category Lang
  48535. * @param {*} value The value to check.
  48536. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  48537. * @example
  48538. *
  48539. * _.isTypedArray(new Uint8Array);
  48540. * // => true
  48541. *
  48542. * _.isTypedArray([]);
  48543. * // => false
  48544. */
  48545. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  48546. /**
  48547. * Creates an array of the own enumerable property names of `object`.
  48548. *
  48549. * **Note:** Non-object values are coerced to objects. See the
  48550. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  48551. * for more details.
  48552. *
  48553. * @static
  48554. * @since 0.1.0
  48555. * @memberOf _
  48556. * @category Object
  48557. * @param {Object} object The object to query.
  48558. * @returns {Array} Returns the array of property names.
  48559. * @example
  48560. *
  48561. * function Foo() {
  48562. * this.a = 1;
  48563. * this.b = 2;
  48564. * }
  48565. *
  48566. * Foo.prototype.c = 3;
  48567. *
  48568. * _.keys(new Foo);
  48569. * // => ['a', 'b'] (iteration order is not guaranteed)
  48570. *
  48571. * _.keys('hi');
  48572. * // => ['0', '1']
  48573. */
  48574. function keys(object) {
  48575. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  48576. }
  48577. /**
  48578. * This method returns a new empty array.
  48579. *
  48580. * @static
  48581. * @memberOf _
  48582. * @since 4.13.0
  48583. * @category Util
  48584. * @returns {Array} Returns the new empty array.
  48585. * @example
  48586. *
  48587. * var arrays = _.times(2, _.stubArray);
  48588. *
  48589. * console.log(arrays);
  48590. * // => [[], []]
  48591. *
  48592. * console.log(arrays[0] === arrays[1]);
  48593. * // => false
  48594. */
  48595. function stubArray() {
  48596. return [];
  48597. }
  48598. /**
  48599. * This method returns `false`.
  48600. *
  48601. * @static
  48602. * @memberOf _
  48603. * @since 4.13.0
  48604. * @category Util
  48605. * @returns {boolean} Returns `false`.
  48606. * @example
  48607. *
  48608. * _.times(2, _.stubFalse);
  48609. * // => [false, false]
  48610. */
  48611. function stubFalse() {
  48612. return false;
  48613. }
  48614. module.exports = isEqual;
  48615. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  48616. },{}],430:[function(require,module,exports){
  48617. (function (global){
  48618. "use strict";
  48619. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  48620. /**
  48621. * Lodash (Custom Build) <https://lodash.com/>
  48622. * Build: `lodash modularize exports="npm" -o ./`
  48623. * Copyright JS Foundation and other contributors <https://js.foundation/>
  48624. * Released under MIT license <https://lodash.com/license>
  48625. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  48626. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  48627. */
  48628. /** `Object#toString` result references. */
  48629. var asyncTag = '[object AsyncFunction]',
  48630. funcTag = '[object Function]',
  48631. genTag = '[object GeneratorFunction]',
  48632. nullTag = '[object Null]',
  48633. proxyTag = '[object Proxy]',
  48634. undefinedTag = '[object Undefined]';
  48635. /** Detect free variable `global` from Node.js. */
  48636. var freeGlobal = (typeof global === "undefined" ? "undefined" : _typeof(global)) == 'object' && global && global.Object === Object && global;
  48637. /** Detect free variable `self`. */
  48638. var freeSelf = (typeof self === "undefined" ? "undefined" : _typeof(self)) == 'object' && self && self.Object === Object && self;
  48639. /** Used as a reference to the global object. */
  48640. var root = freeGlobal || freeSelf || Function('return this')();
  48641. /** Used for built-in method references. */
  48642. var objectProto = Object.prototype;
  48643. /** Used to check objects for own properties. */
  48644. var hasOwnProperty = objectProto.hasOwnProperty;
  48645. /**
  48646. * Used to resolve the
  48647. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  48648. * of values.
  48649. */
  48650. var nativeObjectToString = objectProto.toString;
  48651. /** Built-in value references. */
  48652. var _Symbol = root.Symbol,
  48653. symToStringTag = _Symbol ? _Symbol.toStringTag : undefined;
  48654. /**
  48655. * The base implementation of `getTag` without fallbacks for buggy environments.
  48656. *
  48657. * @private
  48658. * @param {*} value The value to query.
  48659. * @returns {string} Returns the `toStringTag`.
  48660. */
  48661. function baseGetTag(value) {
  48662. if (value == null) {
  48663. return value === undefined ? undefinedTag : nullTag;
  48664. }
  48665. return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
  48666. }
  48667. /**
  48668. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  48669. *
  48670. * @private
  48671. * @param {*} value The value to query.
  48672. * @returns {string} Returns the raw `toStringTag`.
  48673. */
  48674. function getRawTag(value) {
  48675. var isOwn = hasOwnProperty.call(value, symToStringTag),
  48676. tag = value[symToStringTag];
  48677. try {
  48678. value[symToStringTag] = undefined;
  48679. var unmasked = true;
  48680. } catch (e) {}
  48681. var result = nativeObjectToString.call(value);
  48682. if (unmasked) {
  48683. if (isOwn) {
  48684. value[symToStringTag] = tag;
  48685. } else {
  48686. delete value[symToStringTag];
  48687. }
  48688. }
  48689. return result;
  48690. }
  48691. /**
  48692. * Converts `value` to a string using `Object.prototype.toString`.
  48693. *
  48694. * @private
  48695. * @param {*} value The value to convert.
  48696. * @returns {string} Returns the converted string.
  48697. */
  48698. function objectToString(value) {
  48699. return nativeObjectToString.call(value);
  48700. }
  48701. /**
  48702. * Checks if `value` is classified as a `Function` object.
  48703. *
  48704. * @static
  48705. * @memberOf _
  48706. * @since 0.1.0
  48707. * @category Lang
  48708. * @param {*} value The value to check.
  48709. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  48710. * @example
  48711. *
  48712. * _.isFunction(_);
  48713. * // => true
  48714. *
  48715. * _.isFunction(/abc/);
  48716. * // => false
  48717. */
  48718. function isFunction(value) {
  48719. if (!isObject(value)) {
  48720. return false;
  48721. } // The use of `Object#toString` avoids issues with the `typeof` operator
  48722. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  48723. var tag = baseGetTag(value);
  48724. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  48725. }
  48726. /**
  48727. * Checks if `value` is the
  48728. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  48729. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  48730. *
  48731. * @static
  48732. * @memberOf _
  48733. * @since 0.1.0
  48734. * @category Lang
  48735. * @param {*} value The value to check.
  48736. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  48737. * @example
  48738. *
  48739. * _.isObject({});
  48740. * // => true
  48741. *
  48742. * _.isObject([1, 2, 3]);
  48743. * // => true
  48744. *
  48745. * _.isObject(_.noop);
  48746. * // => true
  48747. *
  48748. * _.isObject(null);
  48749. * // => false
  48750. */
  48751. function isObject(value) {
  48752. var type = _typeof(value);
  48753. return value != null && (type == 'object' || type == 'function');
  48754. }
  48755. module.exports = isFunction;
  48756. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  48757. },{}],431:[function(require,module,exports){
  48758. "use strict";
  48759. /**
  48760. * lodash 4.0.0 (Custom Build) <https://lodash.com/>
  48761. * Build: `lodash modularize exports="npm" -o ./`
  48762. * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
  48763. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  48764. * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  48765. * Available under MIT license <https://lodash.com/license>
  48766. */
  48767. /**
  48768. * Checks if `value` is `null` or `undefined`.
  48769. *
  48770. * @static
  48771. * @memberOf _
  48772. * @category Lang
  48773. * @param {*} value The value to check.
  48774. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  48775. * @example
  48776. *
  48777. * _.isNil(null);
  48778. * // => true
  48779. *
  48780. * _.isNil(void 0);
  48781. * // => true
  48782. *
  48783. * _.isNil(NaN);
  48784. * // => false
  48785. */
  48786. function isNil(value) {
  48787. return value == null;
  48788. }
  48789. module.exports = isNil;
  48790. },{}],432:[function(require,module,exports){
  48791. "use strict";
  48792. /**
  48793. * lodash 3.0.1 (Custom Build) <https://lodash.com/>
  48794. * Build: `lodash modern modularize exports="npm" -o ./`
  48795. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  48796. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  48797. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  48798. * Available under MIT license <https://lodash.com/license>
  48799. */
  48800. /**
  48801. * Checks if `value` is `undefined`.
  48802. *
  48803. * @static
  48804. * @memberOf _
  48805. * @category Lang
  48806. * @param {*} value The value to check.
  48807. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  48808. * @example
  48809. *
  48810. * _.isUndefined(void 0);
  48811. * // => true
  48812. *
  48813. * _.isUndefined(null);
  48814. * // => false
  48815. */
  48816. function isUndefined(value) {
  48817. return value === undefined;
  48818. }
  48819. module.exports = isUndefined;
  48820. },{}],433:[function(require,module,exports){
  48821. (function (global){
  48822. "use strict";
  48823. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  48824. /**
  48825. * lodash (Custom Build) <https://lodash.com/>
  48826. * Build: `lodash modularize exports="npm" -o ./`
  48827. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  48828. * Released under MIT license <https://lodash.com/license>
  48829. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  48830. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  48831. */
  48832. /** Used as the size to enable large array optimizations. */
  48833. var LARGE_ARRAY_SIZE = 200;
  48834. /** Used to stand-in for `undefined` hash values. */
  48835. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  48836. /** Used as references for various `Number` constants. */
  48837. var INFINITY = 1 / 0;
  48838. /** `Object#toString` result references. */
  48839. var funcTag = '[object Function]',
  48840. genTag = '[object GeneratorFunction]';
  48841. /**
  48842. * Used to match `RegExp`
  48843. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  48844. */
  48845. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  48846. /** Used to detect host constructors (Safari). */
  48847. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  48848. /** Detect free variable `global` from Node.js. */
  48849. var freeGlobal = (typeof global === "undefined" ? "undefined" : _typeof(global)) == 'object' && global && global.Object === Object && global;
  48850. /** Detect free variable `self`. */
  48851. var freeSelf = (typeof self === "undefined" ? "undefined" : _typeof(self)) == 'object' && self && self.Object === Object && self;
  48852. /** Used as a reference to the global object. */
  48853. var root = freeGlobal || freeSelf || Function('return this')();
  48854. /**
  48855. * A specialized version of `_.includes` for arrays without support for
  48856. * specifying an index to search from.
  48857. *
  48858. * @private
  48859. * @param {Array} [array] The array to inspect.
  48860. * @param {*} target The value to search for.
  48861. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  48862. */
  48863. function arrayIncludes(array, value) {
  48864. var length = array ? array.length : 0;
  48865. return !!length && baseIndexOf(array, value, 0) > -1;
  48866. }
  48867. /**
  48868. * This function is like `arrayIncludes` except that it accepts a comparator.
  48869. *
  48870. * @private
  48871. * @param {Array} [array] The array to inspect.
  48872. * @param {*} target The value to search for.
  48873. * @param {Function} comparator The comparator invoked per element.
  48874. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  48875. */
  48876. function arrayIncludesWith(array, value, comparator) {
  48877. var index = -1,
  48878. length = array ? array.length : 0;
  48879. while (++index < length) {
  48880. if (comparator(value, array[index])) {
  48881. return true;
  48882. }
  48883. }
  48884. return false;
  48885. }
  48886. /**
  48887. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  48888. * support for iteratee shorthands.
  48889. *
  48890. * @private
  48891. * @param {Array} array The array to inspect.
  48892. * @param {Function} predicate The function invoked per iteration.
  48893. * @param {number} fromIndex The index to search from.
  48894. * @param {boolean} [fromRight] Specify iterating from right to left.
  48895. * @returns {number} Returns the index of the matched value, else `-1`.
  48896. */
  48897. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  48898. var length = array.length,
  48899. index = fromIndex + (fromRight ? 1 : -1);
  48900. while (fromRight ? index-- : ++index < length) {
  48901. if (predicate(array[index], index, array)) {
  48902. return index;
  48903. }
  48904. }
  48905. return -1;
  48906. }
  48907. /**
  48908. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  48909. *
  48910. * @private
  48911. * @param {Array} array The array to inspect.
  48912. * @param {*} value The value to search for.
  48913. * @param {number} fromIndex The index to search from.
  48914. * @returns {number} Returns the index of the matched value, else `-1`.
  48915. */
  48916. function baseIndexOf(array, value, fromIndex) {
  48917. if (value !== value) {
  48918. return baseFindIndex(array, baseIsNaN, fromIndex);
  48919. }
  48920. var index = fromIndex - 1,
  48921. length = array.length;
  48922. while (++index < length) {
  48923. if (array[index] === value) {
  48924. return index;
  48925. }
  48926. }
  48927. return -1;
  48928. }
  48929. /**
  48930. * The base implementation of `_.isNaN` without support for number objects.
  48931. *
  48932. * @private
  48933. * @param {*} value The value to check.
  48934. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  48935. */
  48936. function baseIsNaN(value) {
  48937. return value !== value;
  48938. }
  48939. /**
  48940. * Checks if a cache value for `key` exists.
  48941. *
  48942. * @private
  48943. * @param {Object} cache The cache to query.
  48944. * @param {string} key The key of the entry to check.
  48945. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  48946. */
  48947. function cacheHas(cache, key) {
  48948. return cache.has(key);
  48949. }
  48950. /**
  48951. * Gets the value at `key` of `object`.
  48952. *
  48953. * @private
  48954. * @param {Object} [object] The object to query.
  48955. * @param {string} key The key of the property to get.
  48956. * @returns {*} Returns the property value.
  48957. */
  48958. function getValue(object, key) {
  48959. return object == null ? undefined : object[key];
  48960. }
  48961. /**
  48962. * Checks if `value` is a host object in IE < 9.
  48963. *
  48964. * @private
  48965. * @param {*} value The value to check.
  48966. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  48967. */
  48968. function isHostObject(value) {
  48969. // Many host objects are `Object` objects that can coerce to strings
  48970. // despite having improperly defined `toString` methods.
  48971. var result = false;
  48972. if (value != null && typeof value.toString != 'function') {
  48973. try {
  48974. result = !!(value + '');
  48975. } catch (e) {}
  48976. }
  48977. return result;
  48978. }
  48979. /**
  48980. * Converts `set` to an array of its values.
  48981. *
  48982. * @private
  48983. * @param {Object} set The set to convert.
  48984. * @returns {Array} Returns the values.
  48985. */
  48986. function setToArray(set) {
  48987. var index = -1,
  48988. result = Array(set.size);
  48989. set.forEach(function (value) {
  48990. result[++index] = value;
  48991. });
  48992. return result;
  48993. }
  48994. /** Used for built-in method references. */
  48995. var arrayProto = Array.prototype,
  48996. funcProto = Function.prototype,
  48997. objectProto = Object.prototype;
  48998. /** Used to detect overreaching core-js shims. */
  48999. var coreJsData = root['__core-js_shared__'];
  49000. /** Used to detect methods masquerading as native. */
  49001. var maskSrcKey = function () {
  49002. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  49003. return uid ? 'Symbol(src)_1.' + uid : '';
  49004. }();
  49005. /** Used to resolve the decompiled source of functions. */
  49006. var funcToString = funcProto.toString;
  49007. /** Used to check objects for own properties. */
  49008. var hasOwnProperty = objectProto.hasOwnProperty;
  49009. /**
  49010. * Used to resolve the
  49011. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  49012. * of values.
  49013. */
  49014. var objectToString = objectProto.toString;
  49015. /** Used to detect if a method is native. */
  49016. var reIsNative = RegExp('^' + funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
  49017. /** Built-in value references. */
  49018. var splice = arrayProto.splice;
  49019. /* Built-in method references that are verified to be native. */
  49020. var Map = getNative(root, 'Map'),
  49021. Set = getNative(root, 'Set'),
  49022. nativeCreate = getNative(Object, 'create');
  49023. /**
  49024. * Creates a hash object.
  49025. *
  49026. * @private
  49027. * @constructor
  49028. * @param {Array} [entries] The key-value pairs to cache.
  49029. */
  49030. function Hash(entries) {
  49031. var index = -1,
  49032. length = entries ? entries.length : 0;
  49033. this.clear();
  49034. while (++index < length) {
  49035. var entry = entries[index];
  49036. this.set(entry[0], entry[1]);
  49037. }
  49038. }
  49039. /**
  49040. * Removes all key-value entries from the hash.
  49041. *
  49042. * @private
  49043. * @name clear
  49044. * @memberOf Hash
  49045. */
  49046. function hashClear() {
  49047. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  49048. }
  49049. /**
  49050. * Removes `key` and its value from the hash.
  49051. *
  49052. * @private
  49053. * @name delete
  49054. * @memberOf Hash
  49055. * @param {Object} hash The hash to modify.
  49056. * @param {string} key The key of the value to remove.
  49057. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  49058. */
  49059. function hashDelete(key) {
  49060. return this.has(key) && delete this.__data__[key];
  49061. }
  49062. /**
  49063. * Gets the hash value for `key`.
  49064. *
  49065. * @private
  49066. * @name get
  49067. * @memberOf Hash
  49068. * @param {string} key The key of the value to get.
  49069. * @returns {*} Returns the entry value.
  49070. */
  49071. function hashGet(key) {
  49072. var data = this.__data__;
  49073. if (nativeCreate) {
  49074. var result = data[key];
  49075. return result === HASH_UNDEFINED ? undefined : result;
  49076. }
  49077. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  49078. }
  49079. /**
  49080. * Checks if a hash value for `key` exists.
  49081. *
  49082. * @private
  49083. * @name has
  49084. * @memberOf Hash
  49085. * @param {string} key The key of the entry to check.
  49086. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  49087. */
  49088. function hashHas(key) {
  49089. var data = this.__data__;
  49090. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  49091. }
  49092. /**
  49093. * Sets the hash `key` to `value`.
  49094. *
  49095. * @private
  49096. * @name set
  49097. * @memberOf Hash
  49098. * @param {string} key The key of the value to set.
  49099. * @param {*} value The value to set.
  49100. * @returns {Object} Returns the hash instance.
  49101. */
  49102. function hashSet(key, value) {
  49103. var data = this.__data__;
  49104. data[key] = nativeCreate && value === undefined ? HASH_UNDEFINED : value;
  49105. return this;
  49106. } // Add methods to `Hash`.
  49107. Hash.prototype.clear = hashClear;
  49108. Hash.prototype['delete'] = hashDelete;
  49109. Hash.prototype.get = hashGet;
  49110. Hash.prototype.has = hashHas;
  49111. Hash.prototype.set = hashSet;
  49112. /**
  49113. * Creates an list cache object.
  49114. *
  49115. * @private
  49116. * @constructor
  49117. * @param {Array} [entries] The key-value pairs to cache.
  49118. */
  49119. function ListCache(entries) {
  49120. var index = -1,
  49121. length = entries ? entries.length : 0;
  49122. this.clear();
  49123. while (++index < length) {
  49124. var entry = entries[index];
  49125. this.set(entry[0], entry[1]);
  49126. }
  49127. }
  49128. /**
  49129. * Removes all key-value entries from the list cache.
  49130. *
  49131. * @private
  49132. * @name clear
  49133. * @memberOf ListCache
  49134. */
  49135. function listCacheClear() {
  49136. this.__data__ = [];
  49137. }
  49138. /**
  49139. * Removes `key` and its value from the list cache.
  49140. *
  49141. * @private
  49142. * @name delete
  49143. * @memberOf ListCache
  49144. * @param {string} key The key of the value to remove.
  49145. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  49146. */
  49147. function listCacheDelete(key) {
  49148. var data = this.__data__,
  49149. index = assocIndexOf(data, key);
  49150. if (index < 0) {
  49151. return false;
  49152. }
  49153. var lastIndex = data.length - 1;
  49154. if (index == lastIndex) {
  49155. data.pop();
  49156. } else {
  49157. splice.call(data, index, 1);
  49158. }
  49159. return true;
  49160. }
  49161. /**
  49162. * Gets the list cache value for `key`.
  49163. *
  49164. * @private
  49165. * @name get
  49166. * @memberOf ListCache
  49167. * @param {string} key The key of the value to get.
  49168. * @returns {*} Returns the entry value.
  49169. */
  49170. function listCacheGet(key) {
  49171. var data = this.__data__,
  49172. index = assocIndexOf(data, key);
  49173. return index < 0 ? undefined : data[index][1];
  49174. }
  49175. /**
  49176. * Checks if a list cache value for `key` exists.
  49177. *
  49178. * @private
  49179. * @name has
  49180. * @memberOf ListCache
  49181. * @param {string} key The key of the entry to check.
  49182. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  49183. */
  49184. function listCacheHas(key) {
  49185. return assocIndexOf(this.__data__, key) > -1;
  49186. }
  49187. /**
  49188. * Sets the list cache `key` to `value`.
  49189. *
  49190. * @private
  49191. * @name set
  49192. * @memberOf ListCache
  49193. * @param {string} key The key of the value to set.
  49194. * @param {*} value The value to set.
  49195. * @returns {Object} Returns the list cache instance.
  49196. */
  49197. function listCacheSet(key, value) {
  49198. var data = this.__data__,
  49199. index = assocIndexOf(data, key);
  49200. if (index < 0) {
  49201. data.push([key, value]);
  49202. } else {
  49203. data[index][1] = value;
  49204. }
  49205. return this;
  49206. } // Add methods to `ListCache`.
  49207. ListCache.prototype.clear = listCacheClear;
  49208. ListCache.prototype['delete'] = listCacheDelete;
  49209. ListCache.prototype.get = listCacheGet;
  49210. ListCache.prototype.has = listCacheHas;
  49211. ListCache.prototype.set = listCacheSet;
  49212. /**
  49213. * Creates a map cache object to store key-value pairs.
  49214. *
  49215. * @private
  49216. * @constructor
  49217. * @param {Array} [entries] The key-value pairs to cache.
  49218. */
  49219. function MapCache(entries) {
  49220. var index = -1,
  49221. length = entries ? entries.length : 0;
  49222. this.clear();
  49223. while (++index < length) {
  49224. var entry = entries[index];
  49225. this.set(entry[0], entry[1]);
  49226. }
  49227. }
  49228. /**
  49229. * Removes all key-value entries from the map.
  49230. *
  49231. * @private
  49232. * @name clear
  49233. * @memberOf MapCache
  49234. */
  49235. function mapCacheClear() {
  49236. this.__data__ = {
  49237. 'hash': new Hash(),
  49238. 'map': new (Map || ListCache)(),
  49239. 'string': new Hash()
  49240. };
  49241. }
  49242. /**
  49243. * Removes `key` and its value from the map.
  49244. *
  49245. * @private
  49246. * @name delete
  49247. * @memberOf MapCache
  49248. * @param {string} key The key of the value to remove.
  49249. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  49250. */
  49251. function mapCacheDelete(key) {
  49252. return getMapData(this, key)['delete'](key);
  49253. }
  49254. /**
  49255. * Gets the map value for `key`.
  49256. *
  49257. * @private
  49258. * @name get
  49259. * @memberOf MapCache
  49260. * @param {string} key The key of the value to get.
  49261. * @returns {*} Returns the entry value.
  49262. */
  49263. function mapCacheGet(key) {
  49264. return getMapData(this, key).get(key);
  49265. }
  49266. /**
  49267. * Checks if a map value for `key` exists.
  49268. *
  49269. * @private
  49270. * @name has
  49271. * @memberOf MapCache
  49272. * @param {string} key The key of the entry to check.
  49273. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  49274. */
  49275. function mapCacheHas(key) {
  49276. return getMapData(this, key).has(key);
  49277. }
  49278. /**
  49279. * Sets the map `key` to `value`.
  49280. *
  49281. * @private
  49282. * @name set
  49283. * @memberOf MapCache
  49284. * @param {string} key The key of the value to set.
  49285. * @param {*} value The value to set.
  49286. * @returns {Object} Returns the map cache instance.
  49287. */
  49288. function mapCacheSet(key, value) {
  49289. getMapData(this, key).set(key, value);
  49290. return this;
  49291. } // Add methods to `MapCache`.
  49292. MapCache.prototype.clear = mapCacheClear;
  49293. MapCache.prototype['delete'] = mapCacheDelete;
  49294. MapCache.prototype.get = mapCacheGet;
  49295. MapCache.prototype.has = mapCacheHas;
  49296. MapCache.prototype.set = mapCacheSet;
  49297. /**
  49298. *
  49299. * Creates an array cache object to store unique values.
  49300. *
  49301. * @private
  49302. * @constructor
  49303. * @param {Array} [values] The values to cache.
  49304. */
  49305. function SetCache(values) {
  49306. var index = -1,
  49307. length = values ? values.length : 0;
  49308. this.__data__ = new MapCache();
  49309. while (++index < length) {
  49310. this.add(values[index]);
  49311. }
  49312. }
  49313. /**
  49314. * Adds `value` to the array cache.
  49315. *
  49316. * @private
  49317. * @name add
  49318. * @memberOf SetCache
  49319. * @alias push
  49320. * @param {*} value The value to cache.
  49321. * @returns {Object} Returns the cache instance.
  49322. */
  49323. function setCacheAdd(value) {
  49324. this.__data__.set(value, HASH_UNDEFINED);
  49325. return this;
  49326. }
  49327. /**
  49328. * Checks if `value` is in the array cache.
  49329. *
  49330. * @private
  49331. * @name has
  49332. * @memberOf SetCache
  49333. * @param {*} value The value to search for.
  49334. * @returns {number} Returns `true` if `value` is found, else `false`.
  49335. */
  49336. function setCacheHas(value) {
  49337. return this.__data__.has(value);
  49338. } // Add methods to `SetCache`.
  49339. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  49340. SetCache.prototype.has = setCacheHas;
  49341. /**
  49342. * Gets the index at which the `key` is found in `array` of key-value pairs.
  49343. *
  49344. * @private
  49345. * @param {Array} array The array to inspect.
  49346. * @param {*} key The key to search for.
  49347. * @returns {number} Returns the index of the matched value, else `-1`.
  49348. */
  49349. function assocIndexOf(array, key) {
  49350. var length = array.length;
  49351. while (length--) {
  49352. if (eq(array[length][0], key)) {
  49353. return length;
  49354. }
  49355. }
  49356. return -1;
  49357. }
  49358. /**
  49359. * The base implementation of `_.isNative` without bad shim checks.
  49360. *
  49361. * @private
  49362. * @param {*} value The value to check.
  49363. * @returns {boolean} Returns `true` if `value` is a native function,
  49364. * else `false`.
  49365. */
  49366. function baseIsNative(value) {
  49367. if (!isObject(value) || isMasked(value)) {
  49368. return false;
  49369. }
  49370. var pattern = isFunction(value) || isHostObject(value) ? reIsNative : reIsHostCtor;
  49371. return pattern.test(toSource(value));
  49372. }
  49373. /**
  49374. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  49375. *
  49376. * @private
  49377. * @param {Array} array The array to inspect.
  49378. * @param {Function} [iteratee] The iteratee invoked per element.
  49379. * @param {Function} [comparator] The comparator invoked per element.
  49380. * @returns {Array} Returns the new duplicate free array.
  49381. */
  49382. function baseUniq(array, iteratee, comparator) {
  49383. var index = -1,
  49384. includes = arrayIncludes,
  49385. length = array.length,
  49386. isCommon = true,
  49387. result = [],
  49388. seen = result;
  49389. if (comparator) {
  49390. isCommon = false;
  49391. includes = arrayIncludesWith;
  49392. } else if (length >= LARGE_ARRAY_SIZE) {
  49393. var set = iteratee ? null : createSet(array);
  49394. if (set) {
  49395. return setToArray(set);
  49396. }
  49397. isCommon = false;
  49398. includes = cacheHas;
  49399. seen = new SetCache();
  49400. } else {
  49401. seen = iteratee ? [] : result;
  49402. }
  49403. outer: while (++index < length) {
  49404. var value = array[index],
  49405. computed = iteratee ? iteratee(value) : value;
  49406. value = comparator || value !== 0 ? value : 0;
  49407. if (isCommon && computed === computed) {
  49408. var seenIndex = seen.length;
  49409. while (seenIndex--) {
  49410. if (seen[seenIndex] === computed) {
  49411. continue outer;
  49412. }
  49413. }
  49414. if (iteratee) {
  49415. seen.push(computed);
  49416. }
  49417. result.push(value);
  49418. } else if (!includes(seen, computed, comparator)) {
  49419. if (seen !== result) {
  49420. seen.push(computed);
  49421. }
  49422. result.push(value);
  49423. }
  49424. }
  49425. return result;
  49426. }
  49427. /**
  49428. * Creates a set object of `values`.
  49429. *
  49430. * @private
  49431. * @param {Array} values The values to add to the set.
  49432. * @returns {Object} Returns the new set.
  49433. */
  49434. var createSet = !(Set && 1 / setToArray(new Set([, -0]))[1] == INFINITY) ? noop : function (values) {
  49435. return new Set(values);
  49436. };
  49437. /**
  49438. * Gets the data for `map`.
  49439. *
  49440. * @private
  49441. * @param {Object} map The map to query.
  49442. * @param {string} key The reference key.
  49443. * @returns {*} Returns the map data.
  49444. */
  49445. function getMapData(map, key) {
  49446. var data = map.__data__;
  49447. return isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
  49448. }
  49449. /**
  49450. * Gets the native function at `key` of `object`.
  49451. *
  49452. * @private
  49453. * @param {Object} object The object to query.
  49454. * @param {string} key The key of the method to get.
  49455. * @returns {*} Returns the function if it's native, else `undefined`.
  49456. */
  49457. function getNative(object, key) {
  49458. var value = getValue(object, key);
  49459. return baseIsNative(value) ? value : undefined;
  49460. }
  49461. /**
  49462. * Checks if `value` is suitable for use as unique object key.
  49463. *
  49464. * @private
  49465. * @param {*} value The value to check.
  49466. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  49467. */
  49468. function isKeyable(value) {
  49469. var type = _typeof(value);
  49470. return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean' ? value !== '__proto__' : value === null;
  49471. }
  49472. /**
  49473. * Checks if `func` has its source masked.
  49474. *
  49475. * @private
  49476. * @param {Function} func The function to check.
  49477. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  49478. */
  49479. function isMasked(func) {
  49480. return !!maskSrcKey && maskSrcKey in func;
  49481. }
  49482. /**
  49483. * Converts `func` to its source code.
  49484. *
  49485. * @private
  49486. * @param {Function} func The function to process.
  49487. * @returns {string} Returns the source code.
  49488. */
  49489. function toSource(func) {
  49490. if (func != null) {
  49491. try {
  49492. return funcToString.call(func);
  49493. } catch (e) {}
  49494. try {
  49495. return func + '';
  49496. } catch (e) {}
  49497. }
  49498. return '';
  49499. }
  49500. /**
  49501. * Creates a duplicate-free version of an array, using
  49502. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  49503. * for equality comparisons, in which only the first occurrence of each
  49504. * element is kept.
  49505. *
  49506. * @static
  49507. * @memberOf _
  49508. * @since 0.1.0
  49509. * @category Array
  49510. * @param {Array} array The array to inspect.
  49511. * @returns {Array} Returns the new duplicate free array.
  49512. * @example
  49513. *
  49514. * _.uniq([2, 1, 2]);
  49515. * // => [2, 1]
  49516. */
  49517. function uniq(array) {
  49518. return array && array.length ? baseUniq(array) : [];
  49519. }
  49520. /**
  49521. * Performs a
  49522. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  49523. * comparison between two values to determine if they are equivalent.
  49524. *
  49525. * @static
  49526. * @memberOf _
  49527. * @since 4.0.0
  49528. * @category Lang
  49529. * @param {*} value The value to compare.
  49530. * @param {*} other The other value to compare.
  49531. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  49532. * @example
  49533. *
  49534. * var object = { 'a': 1 };
  49535. * var other = { 'a': 1 };
  49536. *
  49537. * _.eq(object, object);
  49538. * // => true
  49539. *
  49540. * _.eq(object, other);
  49541. * // => false
  49542. *
  49543. * _.eq('a', 'a');
  49544. * // => true
  49545. *
  49546. * _.eq('a', Object('a'));
  49547. * // => false
  49548. *
  49549. * _.eq(NaN, NaN);
  49550. * // => true
  49551. */
  49552. function eq(value, other) {
  49553. return value === other || value !== value && other !== other;
  49554. }
  49555. /**
  49556. * Checks if `value` is classified as a `Function` object.
  49557. *
  49558. * @static
  49559. * @memberOf _
  49560. * @since 0.1.0
  49561. * @category Lang
  49562. * @param {*} value The value to check.
  49563. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  49564. * @example
  49565. *
  49566. * _.isFunction(_);
  49567. * // => true
  49568. *
  49569. * _.isFunction(/abc/);
  49570. * // => false
  49571. */
  49572. function isFunction(value) {
  49573. // The use of `Object#toString` avoids issues with the `typeof` operator
  49574. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  49575. var tag = isObject(value) ? objectToString.call(value) : '';
  49576. return tag == funcTag || tag == genTag;
  49577. }
  49578. /**
  49579. * Checks if `value` is the
  49580. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  49581. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  49582. *
  49583. * @static
  49584. * @memberOf _
  49585. * @since 0.1.0
  49586. * @category Lang
  49587. * @param {*} value The value to check.
  49588. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  49589. * @example
  49590. *
  49591. * _.isObject({});
  49592. * // => true
  49593. *
  49594. * _.isObject([1, 2, 3]);
  49595. * // => true
  49596. *
  49597. * _.isObject(_.noop);
  49598. * // => true
  49599. *
  49600. * _.isObject(null);
  49601. * // => false
  49602. */
  49603. function isObject(value) {
  49604. var type = _typeof(value);
  49605. return !!value && (type == 'object' || type == 'function');
  49606. }
  49607. /**
  49608. * This method returns `undefined`.
  49609. *
  49610. * @static
  49611. * @memberOf _
  49612. * @since 2.3.0
  49613. * @category Util
  49614. * @example
  49615. *
  49616. * _.times(2, _.noop);
  49617. * // => [undefined, undefined]
  49618. */
  49619. function noop() {// No operation performed.
  49620. }
  49621. module.exports = uniq;
  49622. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  49623. },{}],434:[function(require,module,exports){
  49624. 'use strict';
  49625. var inherits = require('inherits');
  49626. var HashBase = require('hash-base');
  49627. var Buffer = require('safe-buffer').Buffer;
  49628. var ARRAY16 = new Array(16);
  49629. function MD5() {
  49630. HashBase.call(this, 64); // state
  49631. this._a = 0x67452301;
  49632. this._b = 0xefcdab89;
  49633. this._c = 0x98badcfe;
  49634. this._d = 0x10325476;
  49635. }
  49636. inherits(MD5, HashBase);
  49637. MD5.prototype._update = function () {
  49638. var M = ARRAY16;
  49639. for (var i = 0; i < 16; ++i) {
  49640. M[i] = this._block.readInt32LE(i * 4);
  49641. }
  49642. var a = this._a;
  49643. var b = this._b;
  49644. var c = this._c;
  49645. var d = this._d;
  49646. a = fnF(a, b, c, d, M[0], 0xd76aa478, 7);
  49647. d = fnF(d, a, b, c, M[1], 0xe8c7b756, 12);
  49648. c = fnF(c, d, a, b, M[2], 0x242070db, 17);
  49649. b = fnF(b, c, d, a, M[3], 0xc1bdceee, 22);
  49650. a = fnF(a, b, c, d, M[4], 0xf57c0faf, 7);
  49651. d = fnF(d, a, b, c, M[5], 0x4787c62a, 12);
  49652. c = fnF(c, d, a, b, M[6], 0xa8304613, 17);
  49653. b = fnF(b, c, d, a, M[7], 0xfd469501, 22);
  49654. a = fnF(a, b, c, d, M[8], 0x698098d8, 7);
  49655. d = fnF(d, a, b, c, M[9], 0x8b44f7af, 12);
  49656. c = fnF(c, d, a, b, M[10], 0xffff5bb1, 17);
  49657. b = fnF(b, c, d, a, M[11], 0x895cd7be, 22);
  49658. a = fnF(a, b, c, d, M[12], 0x6b901122, 7);
  49659. d = fnF(d, a, b, c, M[13], 0xfd987193, 12);
  49660. c = fnF(c, d, a, b, M[14], 0xa679438e, 17);
  49661. b = fnF(b, c, d, a, M[15], 0x49b40821, 22);
  49662. a = fnG(a, b, c, d, M[1], 0xf61e2562, 5);
  49663. d = fnG(d, a, b, c, M[6], 0xc040b340, 9);
  49664. c = fnG(c, d, a, b, M[11], 0x265e5a51, 14);
  49665. b = fnG(b, c, d, a, M[0], 0xe9b6c7aa, 20);
  49666. a = fnG(a, b, c, d, M[5], 0xd62f105d, 5);
  49667. d = fnG(d, a, b, c, M[10], 0x02441453, 9);
  49668. c = fnG(c, d, a, b, M[15], 0xd8a1e681, 14);
  49669. b = fnG(b, c, d, a, M[4], 0xe7d3fbc8, 20);
  49670. a = fnG(a, b, c, d, M[9], 0x21e1cde6, 5);
  49671. d = fnG(d, a, b, c, M[14], 0xc33707d6, 9);
  49672. c = fnG(c, d, a, b, M[3], 0xf4d50d87, 14);
  49673. b = fnG(b, c, d, a, M[8], 0x455a14ed, 20);
  49674. a = fnG(a, b, c, d, M[13], 0xa9e3e905, 5);
  49675. d = fnG(d, a, b, c, M[2], 0xfcefa3f8, 9);
  49676. c = fnG(c, d, a, b, M[7], 0x676f02d9, 14);
  49677. b = fnG(b, c, d, a, M[12], 0x8d2a4c8a, 20);
  49678. a = fnH(a, b, c, d, M[5], 0xfffa3942, 4);
  49679. d = fnH(d, a, b, c, M[8], 0x8771f681, 11);
  49680. c = fnH(c, d, a, b, M[11], 0x6d9d6122, 16);
  49681. b = fnH(b, c, d, a, M[14], 0xfde5380c, 23);
  49682. a = fnH(a, b, c, d, M[1], 0xa4beea44, 4);
  49683. d = fnH(d, a, b, c, M[4], 0x4bdecfa9, 11);
  49684. c = fnH(c, d, a, b, M[7], 0xf6bb4b60, 16);
  49685. b = fnH(b, c, d, a, M[10], 0xbebfbc70, 23);
  49686. a = fnH(a, b, c, d, M[13], 0x289b7ec6, 4);
  49687. d = fnH(d, a, b, c, M[0], 0xeaa127fa, 11);
  49688. c = fnH(c, d, a, b, M[3], 0xd4ef3085, 16);
  49689. b = fnH(b, c, d, a, M[6], 0x04881d05, 23);
  49690. a = fnH(a, b, c, d, M[9], 0xd9d4d039, 4);
  49691. d = fnH(d, a, b, c, M[12], 0xe6db99e5, 11);
  49692. c = fnH(c, d, a, b, M[15], 0x1fa27cf8, 16);
  49693. b = fnH(b, c, d, a, M[2], 0xc4ac5665, 23);
  49694. a = fnI(a, b, c, d, M[0], 0xf4292244, 6);
  49695. d = fnI(d, a, b, c, M[7], 0x432aff97, 10);
  49696. c = fnI(c, d, a, b, M[14], 0xab9423a7, 15);
  49697. b = fnI(b, c, d, a, M[5], 0xfc93a039, 21);
  49698. a = fnI(a, b, c, d, M[12], 0x655b59c3, 6);
  49699. d = fnI(d, a, b, c, M[3], 0x8f0ccc92, 10);
  49700. c = fnI(c, d, a, b, M[10], 0xffeff47d, 15);
  49701. b = fnI(b, c, d, a, M[1], 0x85845dd1, 21);
  49702. a = fnI(a, b, c, d, M[8], 0x6fa87e4f, 6);
  49703. d = fnI(d, a, b, c, M[15], 0xfe2ce6e0, 10);
  49704. c = fnI(c, d, a, b, M[6], 0xa3014314, 15);
  49705. b = fnI(b, c, d, a, M[13], 0x4e0811a1, 21);
  49706. a = fnI(a, b, c, d, M[4], 0xf7537e82, 6);
  49707. d = fnI(d, a, b, c, M[11], 0xbd3af235, 10);
  49708. c = fnI(c, d, a, b, M[2], 0x2ad7d2bb, 15);
  49709. b = fnI(b, c, d, a, M[9], 0xeb86d391, 21);
  49710. this._a = this._a + a | 0;
  49711. this._b = this._b + b | 0;
  49712. this._c = this._c + c | 0;
  49713. this._d = this._d + d | 0;
  49714. };
  49715. MD5.prototype._digest = function () {
  49716. // create padding and handle blocks
  49717. this._block[this._blockOffset++] = 0x80;
  49718. if (this._blockOffset > 56) {
  49719. this._block.fill(0, this._blockOffset, 64);
  49720. this._update();
  49721. this._blockOffset = 0;
  49722. }
  49723. this._block.fill(0, this._blockOffset, 56);
  49724. this._block.writeUInt32LE(this._length[0], 56);
  49725. this._block.writeUInt32LE(this._length[1], 60);
  49726. this._update(); // produce result
  49727. var buffer = Buffer.allocUnsafe(16);
  49728. buffer.writeInt32LE(this._a, 0);
  49729. buffer.writeInt32LE(this._b, 4);
  49730. buffer.writeInt32LE(this._c, 8);
  49731. buffer.writeInt32LE(this._d, 12);
  49732. return buffer;
  49733. };
  49734. function rotl(x, n) {
  49735. return x << n | x >>> 32 - n;
  49736. }
  49737. function fnF(a, b, c, d, m, k, s) {
  49738. return rotl(a + (b & c | ~b & d) + m + k | 0, s) + b | 0;
  49739. }
  49740. function fnG(a, b, c, d, m, k, s) {
  49741. return rotl(a + (b & d | c & ~d) + m + k | 0, s) + b | 0;
  49742. }
  49743. function fnH(a, b, c, d, m, k, s) {
  49744. return rotl(a + (b ^ c ^ d) + m + k | 0, s) + b | 0;
  49745. }
  49746. function fnI(a, b, c, d, m, k, s) {
  49747. return rotl(a + (c ^ (b | ~d)) + m + k | 0, s) + b | 0;
  49748. }
  49749. module.exports = MD5;
  49750. },{"hash-base":370,"inherits":387,"safe-buffer":494}],435:[function(require,module,exports){
  49751. "use strict";
  49752. var bn = require('bn.js');
  49753. var brorand = require('brorand');
  49754. function MillerRabin(rand) {
  49755. this.rand = rand || new brorand.Rand();
  49756. }
  49757. module.exports = MillerRabin;
  49758. MillerRabin.create = function create(rand) {
  49759. return new MillerRabin(rand);
  49760. };
  49761. MillerRabin.prototype._randbelow = function _randbelow(n) {
  49762. var len = n.bitLength();
  49763. var min_bytes = Math.ceil(len / 8); // Generage random bytes until a number less than n is found.
  49764. // This ensures that 0..n-1 have an equal probability of being selected.
  49765. do {
  49766. var a = new bn(this.rand.generate(min_bytes));
  49767. } while (a.cmp(n) >= 0);
  49768. return a;
  49769. };
  49770. MillerRabin.prototype._randrange = function _randrange(start, stop) {
  49771. // Generate a random number greater than or equal to start and less than stop.
  49772. var size = stop.sub(start);
  49773. return start.add(this._randbelow(size));
  49774. };
  49775. MillerRabin.prototype.test = function test(n, k, cb) {
  49776. var len = n.bitLength();
  49777. var red = bn.mont(n);
  49778. var rone = new bn(1).toRed(red);
  49779. if (!k) k = Math.max(1, len / 48 | 0); // Find d and s, (n - 1) = (2 ^ s) * d;
  49780. var n1 = n.subn(1);
  49781. for (var s = 0; !n1.testn(s); s++) {}
  49782. var d = n.shrn(s);
  49783. var rn1 = n1.toRed(red);
  49784. var prime = true;
  49785. for (; k > 0; k--) {
  49786. var a = this._randrange(new bn(2), n1);
  49787. if (cb) cb(a);
  49788. var x = a.toRed(red).redPow(d);
  49789. if (x.cmp(rone) === 0 || x.cmp(rn1) === 0) continue;
  49790. for (var i = 1; i < s; i++) {
  49791. x = x.redSqr();
  49792. if (x.cmp(rone) === 0) return false;
  49793. if (x.cmp(rn1) === 0) break;
  49794. }
  49795. if (i === s) return false;
  49796. }
  49797. return prime;
  49798. };
  49799. MillerRabin.prototype.getDivisor = function getDivisor(n, k) {
  49800. var len = n.bitLength();
  49801. var red = bn.mont(n);
  49802. var rone = new bn(1).toRed(red);
  49803. if (!k) k = Math.max(1, len / 48 | 0); // Find d and s, (n - 1) = (2 ^ s) * d;
  49804. var n1 = n.subn(1);
  49805. for (var s = 0; !n1.testn(s); s++) {}
  49806. var d = n.shrn(s);
  49807. var rn1 = n1.toRed(red);
  49808. for (; k > 0; k--) {
  49809. var a = this._randrange(new bn(2), n1);
  49810. var g = n.gcd(a);
  49811. if (g.cmpn(1) !== 0) return g;
  49812. var x = a.toRed(red).redPow(d);
  49813. if (x.cmp(rone) === 0 || x.cmp(rn1) === 0) continue;
  49814. for (var i = 1; i < s; i++) {
  49815. x = x.redSqr();
  49816. if (x.cmp(rone) === 0) return x.fromRed().subn(1).gcd(n);
  49817. if (x.cmp(rn1) === 0) break;
  49818. }
  49819. if (i === s) {
  49820. x = x.redSqr();
  49821. return x.fromRed().subn(1).gcd(n);
  49822. }
  49823. }
  49824. return false;
  49825. };
  49826. },{"bn.js":436,"brorand":184}],436:[function(require,module,exports){
  49827. arguments[4][181][0].apply(exports,arguments)
  49828. },{"buffer":185,"dup":181}],437:[function(require,module,exports){
  49829. "use strict";
  49830. module.exports = assert;
  49831. function assert(val, msg) {
  49832. if (!val) throw new Error(msg || 'Assertion failed');
  49833. }
  49834. assert.equal = function assertEqual(l, r, msg) {
  49835. if (l != r) throw new Error(msg || 'Assertion failed: ' + l + ' != ' + r);
  49836. };
  49837. },{}],438:[function(require,module,exports){
  49838. 'use strict';
  49839. var utils = exports;
  49840. function toArray(msg, enc) {
  49841. if (Array.isArray(msg)) return msg.slice();
  49842. if (!msg) return [];
  49843. var res = [];
  49844. if (typeof msg !== 'string') {
  49845. for (var i = 0; i < msg.length; i++) {
  49846. res[i] = msg[i] | 0;
  49847. }
  49848. return res;
  49849. }
  49850. if (enc === 'hex') {
  49851. msg = msg.replace(/[^a-z0-9]+/ig, '');
  49852. if (msg.length % 2 !== 0) msg = '0' + msg;
  49853. for (var i = 0; i < msg.length; i += 2) {
  49854. res.push(parseInt(msg[i] + msg[i + 1], 16));
  49855. }
  49856. } else {
  49857. for (var i = 0; i < msg.length; i++) {
  49858. var c = msg.charCodeAt(i);
  49859. var hi = c >> 8;
  49860. var lo = c & 0xff;
  49861. if (hi) res.push(hi, lo);else res.push(lo);
  49862. }
  49863. }
  49864. return res;
  49865. }
  49866. utils.toArray = toArray;
  49867. function zero2(word) {
  49868. if (word.length === 1) return '0' + word;else return word;
  49869. }
  49870. utils.zero2 = zero2;
  49871. function toHex(msg) {
  49872. var res = '';
  49873. for (var i = 0; i < msg.length; i++) {
  49874. res += zero2(msg[i].toString(16));
  49875. }
  49876. return res;
  49877. }
  49878. utils.toHex = toHex;
  49879. utils.encode = function encode(arr, enc) {
  49880. if (enc === 'hex') return toHex(arr);else return arr;
  49881. };
  49882. },{}],439:[function(require,module,exports){
  49883. // Top level file is just a mixin of submodules & constants
  49884. 'use strict';
  49885. var assign = require('./lib/utils/common').assign;
  49886. var deflate = require('./lib/deflate');
  49887. var inflate = require('./lib/inflate');
  49888. var constants = require('./lib/zlib/constants');
  49889. var pako = {};
  49890. assign(pako, deflate, inflate, constants);
  49891. module.exports = pako;
  49892. },{"./lib/deflate":440,"./lib/inflate":441,"./lib/utils/common":442,"./lib/zlib/constants":445}],440:[function(require,module,exports){
  49893. 'use strict';
  49894. var zlib_deflate = require('./zlib/deflate');
  49895. var utils = require('./utils/common');
  49896. var strings = require('./utils/strings');
  49897. var msg = require('./zlib/messages');
  49898. var ZStream = require('./zlib/zstream');
  49899. var toString = Object.prototype.toString;
  49900. /* Public constants ==========================================================*/
  49901. /* ===========================================================================*/
  49902. var Z_NO_FLUSH = 0;
  49903. var Z_FINISH = 4;
  49904. var Z_OK = 0;
  49905. var Z_STREAM_END = 1;
  49906. var Z_SYNC_FLUSH = 2;
  49907. var Z_DEFAULT_COMPRESSION = -1;
  49908. var Z_DEFAULT_STRATEGY = 0;
  49909. var Z_DEFLATED = 8;
  49910. /* ===========================================================================*/
  49911. /**
  49912. * class Deflate
  49913. *
  49914. * Generic JS-style wrapper for zlib calls. If you don't need
  49915. * streaming behaviour - use more simple functions: [[deflate]],
  49916. * [[deflateRaw]] and [[gzip]].
  49917. **/
  49918. /* internal
  49919. * Deflate.chunks -> Array
  49920. *
  49921. * Chunks of output data, if [[Deflate#onData]] not overridden.
  49922. **/
  49923. /**
  49924. * Deflate.result -> Uint8Array|Array
  49925. *
  49926. * Compressed result, generated by default [[Deflate#onData]]
  49927. * and [[Deflate#onEnd]] handlers. Filled after you push last chunk
  49928. * (call [[Deflate#push]] with `Z_FINISH` / `true` param) or if you
  49929. * push a chunk with explicit flush (call [[Deflate#push]] with
  49930. * `Z_SYNC_FLUSH` param).
  49931. **/
  49932. /**
  49933. * Deflate.err -> Number
  49934. *
  49935. * Error code after deflate finished. 0 (Z_OK) on success.
  49936. * You will not need it in real life, because deflate errors
  49937. * are possible only on wrong options or bad `onData` / `onEnd`
  49938. * custom handlers.
  49939. **/
  49940. /**
  49941. * Deflate.msg -> String
  49942. *
  49943. * Error message, if [[Deflate.err]] != 0
  49944. **/
  49945. /**
  49946. * new Deflate(options)
  49947. * - options (Object): zlib deflate options.
  49948. *
  49949. * Creates new deflator instance with specified params. Throws exception
  49950. * on bad params. Supported options:
  49951. *
  49952. * - `level`
  49953. * - `windowBits`
  49954. * - `memLevel`
  49955. * - `strategy`
  49956. * - `dictionary`
  49957. *
  49958. * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
  49959. * for more information on these.
  49960. *
  49961. * Additional options, for internal needs:
  49962. *
  49963. * - `chunkSize` - size of generated data chunks (16K by default)
  49964. * - `raw` (Boolean) - do raw deflate
  49965. * - `gzip` (Boolean) - create gzip wrapper
  49966. * - `to` (String) - if equal to 'string', then result will be "binary string"
  49967. * (each char code [0..255])
  49968. * - `header` (Object) - custom header for gzip
  49969. * - `text` (Boolean) - true if compressed data believed to be text
  49970. * - `time` (Number) - modification time, unix timestamp
  49971. * - `os` (Number) - operation system code
  49972. * - `extra` (Array) - array of bytes with extra data (max 65536)
  49973. * - `name` (String) - file name (binary string)
  49974. * - `comment` (String) - comment (binary string)
  49975. * - `hcrc` (Boolean) - true if header crc should be added
  49976. *
  49977. * ##### Example:
  49978. *
  49979. * ```javascript
  49980. * var pako = require('pako')
  49981. * , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])
  49982. * , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);
  49983. *
  49984. * var deflate = new pako.Deflate({ level: 3});
  49985. *
  49986. * deflate.push(chunk1, false);
  49987. * deflate.push(chunk2, true); // true -> last chunk
  49988. *
  49989. * if (deflate.err) { throw new Error(deflate.err); }
  49990. *
  49991. * console.log(deflate.result);
  49992. * ```
  49993. **/
  49994. function Deflate(options) {
  49995. if (!(this instanceof Deflate)) return new Deflate(options);
  49996. this.options = utils.assign({
  49997. level: Z_DEFAULT_COMPRESSION,
  49998. method: Z_DEFLATED,
  49999. chunkSize: 16384,
  50000. windowBits: 15,
  50001. memLevel: 8,
  50002. strategy: Z_DEFAULT_STRATEGY,
  50003. to: ''
  50004. }, options || {});
  50005. var opt = this.options;
  50006. if (opt.raw && opt.windowBits > 0) {
  50007. opt.windowBits = -opt.windowBits;
  50008. } else if (opt.gzip && opt.windowBits > 0 && opt.windowBits < 16) {
  50009. opt.windowBits += 16;
  50010. }
  50011. this.err = 0; // error code, if happens (0 = Z_OK)
  50012. this.msg = ''; // error message
  50013. this.ended = false; // used to avoid multiple onEnd() calls
  50014. this.chunks = []; // chunks of compressed data
  50015. this.strm = new ZStream();
  50016. this.strm.avail_out = 0;
  50017. var status = zlib_deflate.deflateInit2(this.strm, opt.level, opt.method, opt.windowBits, opt.memLevel, opt.strategy);
  50018. if (status !== Z_OK) {
  50019. throw new Error(msg[status]);
  50020. }
  50021. if (opt.header) {
  50022. zlib_deflate.deflateSetHeader(this.strm, opt.header);
  50023. }
  50024. if (opt.dictionary) {
  50025. var dict; // Convert data if needed
  50026. if (typeof opt.dictionary === 'string') {
  50027. // If we need to compress text, change encoding to utf8.
  50028. dict = strings.string2buf(opt.dictionary);
  50029. } else if (toString.call(opt.dictionary) === '[object ArrayBuffer]') {
  50030. dict = new Uint8Array(opt.dictionary);
  50031. } else {
  50032. dict = opt.dictionary;
  50033. }
  50034. status = zlib_deflate.deflateSetDictionary(this.strm, dict);
  50035. if (status !== Z_OK) {
  50036. throw new Error(msg[status]);
  50037. }
  50038. this._dict_set = true;
  50039. }
  50040. }
  50041. /**
  50042. * Deflate#push(data[, mode]) -> Boolean
  50043. * - data (Uint8Array|Array|ArrayBuffer|String): input data. Strings will be
  50044. * converted to utf8 byte sequence.
  50045. * - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
  50046. * See constants. Skipped or `false` means Z_NO_FLUSH, `true` means Z_FINISH.
  50047. *
  50048. * Sends input data to deflate pipe, generating [[Deflate#onData]] calls with
  50049. * new compressed chunks. Returns `true` on success. The last data block must have
  50050. * mode Z_FINISH (or `true`). That will flush internal pending buffers and call
  50051. * [[Deflate#onEnd]]. For interim explicit flushes (without ending the stream) you
  50052. * can use mode Z_SYNC_FLUSH, keeping the compression context.
  50053. *
  50054. * On fail call [[Deflate#onEnd]] with error code and return false.
  50055. *
  50056. * We strongly recommend to use `Uint8Array` on input for best speed (output
  50057. * array format is detected automatically). Also, don't skip last param and always
  50058. * use the same type in your code (boolean or number). That will improve JS speed.
  50059. *
  50060. * For regular `Array`-s make sure all elements are [0..255].
  50061. *
  50062. * ##### Example
  50063. *
  50064. * ```javascript
  50065. * push(chunk, false); // push one of data chunks
  50066. * ...
  50067. * push(chunk, true); // push last chunk
  50068. * ```
  50069. **/
  50070. Deflate.prototype.push = function (data, mode) {
  50071. var strm = this.strm;
  50072. var chunkSize = this.options.chunkSize;
  50073. var status, _mode;
  50074. if (this.ended) {
  50075. return false;
  50076. }
  50077. _mode = mode === ~~mode ? mode : mode === true ? Z_FINISH : Z_NO_FLUSH; // Convert data if needed
  50078. if (typeof data === 'string') {
  50079. // If we need to compress text, change encoding to utf8.
  50080. strm.input = strings.string2buf(data);
  50081. } else if (toString.call(data) === '[object ArrayBuffer]') {
  50082. strm.input = new Uint8Array(data);
  50083. } else {
  50084. strm.input = data;
  50085. }
  50086. strm.next_in = 0;
  50087. strm.avail_in = strm.input.length;
  50088. do {
  50089. if (strm.avail_out === 0) {
  50090. strm.output = new utils.Buf8(chunkSize);
  50091. strm.next_out = 0;
  50092. strm.avail_out = chunkSize;
  50093. }
  50094. status = zlib_deflate.deflate(strm, _mode);
  50095. /* no bad return value */
  50096. if (status !== Z_STREAM_END && status !== Z_OK) {
  50097. this.onEnd(status);
  50098. this.ended = true;
  50099. return false;
  50100. }
  50101. if (strm.avail_out === 0 || strm.avail_in === 0 && (_mode === Z_FINISH || _mode === Z_SYNC_FLUSH)) {
  50102. if (this.options.to === 'string') {
  50103. this.onData(strings.buf2binstring(utils.shrinkBuf(strm.output, strm.next_out)));
  50104. } else {
  50105. this.onData(utils.shrinkBuf(strm.output, strm.next_out));
  50106. }
  50107. }
  50108. } while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== Z_STREAM_END); // Finalize on the last chunk.
  50109. if (_mode === Z_FINISH) {
  50110. status = zlib_deflate.deflateEnd(this.strm);
  50111. this.onEnd(status);
  50112. this.ended = true;
  50113. return status === Z_OK;
  50114. } // callback interim results if Z_SYNC_FLUSH.
  50115. if (_mode === Z_SYNC_FLUSH) {
  50116. this.onEnd(Z_OK);
  50117. strm.avail_out = 0;
  50118. return true;
  50119. }
  50120. return true;
  50121. };
  50122. /**
  50123. * Deflate#onData(chunk) -> Void
  50124. * - chunk (Uint8Array|Array|String): output data. Type of array depends
  50125. * on js engine support. When string output requested, each chunk
  50126. * will be string.
  50127. *
  50128. * By default, stores data blocks in `chunks[]` property and glue
  50129. * those in `onEnd`. Override this handler, if you need another behaviour.
  50130. **/
  50131. Deflate.prototype.onData = function (chunk) {
  50132. this.chunks.push(chunk);
  50133. };
  50134. /**
  50135. * Deflate#onEnd(status) -> Void
  50136. * - status (Number): deflate status. 0 (Z_OK) on success,
  50137. * other if not.
  50138. *
  50139. * Called once after you tell deflate that the input stream is
  50140. * complete (Z_FINISH) or should be flushed (Z_SYNC_FLUSH)
  50141. * or if an error happened. By default - join collected chunks,
  50142. * free memory and fill `results` / `err` properties.
  50143. **/
  50144. Deflate.prototype.onEnd = function (status) {
  50145. // On success - join
  50146. if (status === Z_OK) {
  50147. if (this.options.to === 'string') {
  50148. this.result = this.chunks.join('');
  50149. } else {
  50150. this.result = utils.flattenChunks(this.chunks);
  50151. }
  50152. }
  50153. this.chunks = [];
  50154. this.err = status;
  50155. this.msg = this.strm.msg;
  50156. };
  50157. /**
  50158. * deflate(data[, options]) -> Uint8Array|Array|String
  50159. * - data (Uint8Array|Array|String): input data to compress.
  50160. * - options (Object): zlib deflate options.
  50161. *
  50162. * Compress `data` with deflate algorithm and `options`.
  50163. *
  50164. * Supported options are:
  50165. *
  50166. * - level
  50167. * - windowBits
  50168. * - memLevel
  50169. * - strategy
  50170. * - dictionary
  50171. *
  50172. * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
  50173. * for more information on these.
  50174. *
  50175. * Sugar (options):
  50176. *
  50177. * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify
  50178. * negative windowBits implicitly.
  50179. * - `to` (String) - if equal to 'string', then result will be "binary string"
  50180. * (each char code [0..255])
  50181. *
  50182. * ##### Example:
  50183. *
  50184. * ```javascript
  50185. * var pako = require('pako')
  50186. * , data = Uint8Array([1,2,3,4,5,6,7,8,9]);
  50187. *
  50188. * console.log(pako.deflate(data));
  50189. * ```
  50190. **/
  50191. function deflate(input, options) {
  50192. var deflator = new Deflate(options);
  50193. deflator.push(input, true); // That will never happens, if you don't cheat with options :)
  50194. if (deflator.err) {
  50195. throw deflator.msg || msg[deflator.err];
  50196. }
  50197. return deflator.result;
  50198. }
  50199. /**
  50200. * deflateRaw(data[, options]) -> Uint8Array|Array|String
  50201. * - data (Uint8Array|Array|String): input data to compress.
  50202. * - options (Object): zlib deflate options.
  50203. *
  50204. * The same as [[deflate]], but creates raw data, without wrapper
  50205. * (header and adler32 crc).
  50206. **/
  50207. function deflateRaw(input, options) {
  50208. options = options || {};
  50209. options.raw = true;
  50210. return deflate(input, options);
  50211. }
  50212. /**
  50213. * gzip(data[, options]) -> Uint8Array|Array|String
  50214. * - data (Uint8Array|Array|String): input data to compress.
  50215. * - options (Object): zlib deflate options.
  50216. *
  50217. * The same as [[deflate]], but create gzip wrapper instead of
  50218. * deflate one.
  50219. **/
  50220. function gzip(input, options) {
  50221. options = options || {};
  50222. options.gzip = true;
  50223. return deflate(input, options);
  50224. }
  50225. exports.Deflate = Deflate;
  50226. exports.deflate = deflate;
  50227. exports.deflateRaw = deflateRaw;
  50228. exports.gzip = gzip;
  50229. },{"./utils/common":442,"./utils/strings":443,"./zlib/deflate":447,"./zlib/messages":452,"./zlib/zstream":454}],441:[function(require,module,exports){
  50230. 'use strict';
  50231. var zlib_inflate = require('./zlib/inflate');
  50232. var utils = require('./utils/common');
  50233. var strings = require('./utils/strings');
  50234. var c = require('./zlib/constants');
  50235. var msg = require('./zlib/messages');
  50236. var ZStream = require('./zlib/zstream');
  50237. var GZheader = require('./zlib/gzheader');
  50238. var toString = Object.prototype.toString;
  50239. /**
  50240. * class Inflate
  50241. *
  50242. * Generic JS-style wrapper for zlib calls. If you don't need
  50243. * streaming behaviour - use more simple functions: [[inflate]]
  50244. * and [[inflateRaw]].
  50245. **/
  50246. /* internal
  50247. * inflate.chunks -> Array
  50248. *
  50249. * Chunks of output data, if [[Inflate#onData]] not overridden.
  50250. **/
  50251. /**
  50252. * Inflate.result -> Uint8Array|Array|String
  50253. *
  50254. * Uncompressed result, generated by default [[Inflate#onData]]
  50255. * and [[Inflate#onEnd]] handlers. Filled after you push last chunk
  50256. * (call [[Inflate#push]] with `Z_FINISH` / `true` param) or if you
  50257. * push a chunk with explicit flush (call [[Inflate#push]] with
  50258. * `Z_SYNC_FLUSH` param).
  50259. **/
  50260. /**
  50261. * Inflate.err -> Number
  50262. *
  50263. * Error code after inflate finished. 0 (Z_OK) on success.
  50264. * Should be checked if broken data possible.
  50265. **/
  50266. /**
  50267. * Inflate.msg -> String
  50268. *
  50269. * Error message, if [[Inflate.err]] != 0
  50270. **/
  50271. /**
  50272. * new Inflate(options)
  50273. * - options (Object): zlib inflate options.
  50274. *
  50275. * Creates new inflator instance with specified params. Throws exception
  50276. * on bad params. Supported options:
  50277. *
  50278. * - `windowBits`
  50279. * - `dictionary`
  50280. *
  50281. * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
  50282. * for more information on these.
  50283. *
  50284. * Additional options, for internal needs:
  50285. *
  50286. * - `chunkSize` - size of generated data chunks (16K by default)
  50287. * - `raw` (Boolean) - do raw inflate
  50288. * - `to` (String) - if equal to 'string', then result will be converted
  50289. * from utf8 to utf16 (javascript) string. When string output requested,
  50290. * chunk length can differ from `chunkSize`, depending on content.
  50291. *
  50292. * By default, when no options set, autodetect deflate/gzip data format via
  50293. * wrapper header.
  50294. *
  50295. * ##### Example:
  50296. *
  50297. * ```javascript
  50298. * var pako = require('pako')
  50299. * , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])
  50300. * , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);
  50301. *
  50302. * var inflate = new pako.Inflate({ level: 3});
  50303. *
  50304. * inflate.push(chunk1, false);
  50305. * inflate.push(chunk2, true); // true -> last chunk
  50306. *
  50307. * if (inflate.err) { throw new Error(inflate.err); }
  50308. *
  50309. * console.log(inflate.result);
  50310. * ```
  50311. **/
  50312. function Inflate(options) {
  50313. if (!(this instanceof Inflate)) return new Inflate(options);
  50314. this.options = utils.assign({
  50315. chunkSize: 16384,
  50316. windowBits: 0,
  50317. to: ''
  50318. }, options || {});
  50319. var opt = this.options; // Force window size for `raw` data, if not set directly,
  50320. // because we have no header for autodetect.
  50321. if (opt.raw && opt.windowBits >= 0 && opt.windowBits < 16) {
  50322. opt.windowBits = -opt.windowBits;
  50323. if (opt.windowBits === 0) {
  50324. opt.windowBits = -15;
  50325. }
  50326. } // If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate
  50327. if (opt.windowBits >= 0 && opt.windowBits < 16 && !(options && options.windowBits)) {
  50328. opt.windowBits += 32;
  50329. } // Gzip header has no info about windows size, we can do autodetect only
  50330. // for deflate. So, if window size not set, force it to max when gzip possible
  50331. if (opt.windowBits > 15 && opt.windowBits < 48) {
  50332. // bit 3 (16) -> gzipped data
  50333. // bit 4 (32) -> autodetect gzip/deflate
  50334. if ((opt.windowBits & 15) === 0) {
  50335. opt.windowBits |= 15;
  50336. }
  50337. }
  50338. this.err = 0; // error code, if happens (0 = Z_OK)
  50339. this.msg = ''; // error message
  50340. this.ended = false; // used to avoid multiple onEnd() calls
  50341. this.chunks = []; // chunks of compressed data
  50342. this.strm = new ZStream();
  50343. this.strm.avail_out = 0;
  50344. var status = zlib_inflate.inflateInit2(this.strm, opt.windowBits);
  50345. if (status !== c.Z_OK) {
  50346. throw new Error(msg[status]);
  50347. }
  50348. this.header = new GZheader();
  50349. zlib_inflate.inflateGetHeader(this.strm, this.header); // Setup dictionary
  50350. if (opt.dictionary) {
  50351. // Convert data if needed
  50352. if (typeof opt.dictionary === 'string') {
  50353. opt.dictionary = strings.string2buf(opt.dictionary);
  50354. } else if (toString.call(opt.dictionary) === '[object ArrayBuffer]') {
  50355. opt.dictionary = new Uint8Array(opt.dictionary);
  50356. }
  50357. if (opt.raw) {
  50358. //In raw mode we need to set the dictionary early
  50359. status = zlib_inflate.inflateSetDictionary(this.strm, opt.dictionary);
  50360. if (status !== c.Z_OK) {
  50361. throw new Error(msg[status]);
  50362. }
  50363. }
  50364. }
  50365. }
  50366. /**
  50367. * Inflate#push(data[, mode]) -> Boolean
  50368. * - data (Uint8Array|Array|ArrayBuffer|String): input data
  50369. * - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
  50370. * See constants. Skipped or `false` means Z_NO_FLUSH, `true` means Z_FINISH.
  50371. *
  50372. * Sends input data to inflate pipe, generating [[Inflate#onData]] calls with
  50373. * new output chunks. Returns `true` on success. The last data block must have
  50374. * mode Z_FINISH (or `true`). That will flush internal pending buffers and call
  50375. * [[Inflate#onEnd]]. For interim explicit flushes (without ending the stream) you
  50376. * can use mode Z_SYNC_FLUSH, keeping the decompression context.
  50377. *
  50378. * On fail call [[Inflate#onEnd]] with error code and return false.
  50379. *
  50380. * We strongly recommend to use `Uint8Array` on input for best speed (output
  50381. * format is detected automatically). Also, don't skip last param and always
  50382. * use the same type in your code (boolean or number). That will improve JS speed.
  50383. *
  50384. * For regular `Array`-s make sure all elements are [0..255].
  50385. *
  50386. * ##### Example
  50387. *
  50388. * ```javascript
  50389. * push(chunk, false); // push one of data chunks
  50390. * ...
  50391. * push(chunk, true); // push last chunk
  50392. * ```
  50393. **/
  50394. Inflate.prototype.push = function (data, mode) {
  50395. var strm = this.strm;
  50396. var chunkSize = this.options.chunkSize;
  50397. var dictionary = this.options.dictionary;
  50398. var status, _mode;
  50399. var next_out_utf8, tail, utf8str; // Flag to properly process Z_BUF_ERROR on testing inflate call
  50400. // when we check that all output data was flushed.
  50401. var allowBufError = false;
  50402. if (this.ended) {
  50403. return false;
  50404. }
  50405. _mode = mode === ~~mode ? mode : mode === true ? c.Z_FINISH : c.Z_NO_FLUSH; // Convert data if needed
  50406. if (typeof data === 'string') {
  50407. // Only binary strings can be decompressed on practice
  50408. strm.input = strings.binstring2buf(data);
  50409. } else if (toString.call(data) === '[object ArrayBuffer]') {
  50410. strm.input = new Uint8Array(data);
  50411. } else {
  50412. strm.input = data;
  50413. }
  50414. strm.next_in = 0;
  50415. strm.avail_in = strm.input.length;
  50416. do {
  50417. if (strm.avail_out === 0) {
  50418. strm.output = new utils.Buf8(chunkSize);
  50419. strm.next_out = 0;
  50420. strm.avail_out = chunkSize;
  50421. }
  50422. status = zlib_inflate.inflate(strm, c.Z_NO_FLUSH);
  50423. /* no bad return value */
  50424. if (status === c.Z_NEED_DICT && dictionary) {
  50425. status = zlib_inflate.inflateSetDictionary(this.strm, dictionary);
  50426. }
  50427. if (status === c.Z_BUF_ERROR && allowBufError === true) {
  50428. status = c.Z_OK;
  50429. allowBufError = false;
  50430. }
  50431. if (status !== c.Z_STREAM_END && status !== c.Z_OK) {
  50432. this.onEnd(status);
  50433. this.ended = true;
  50434. return false;
  50435. }
  50436. if (strm.next_out) {
  50437. if (strm.avail_out === 0 || status === c.Z_STREAM_END || strm.avail_in === 0 && (_mode === c.Z_FINISH || _mode === c.Z_SYNC_FLUSH)) {
  50438. if (this.options.to === 'string') {
  50439. next_out_utf8 = strings.utf8border(strm.output, strm.next_out);
  50440. tail = strm.next_out - next_out_utf8;
  50441. utf8str = strings.buf2string(strm.output, next_out_utf8); // move tail
  50442. strm.next_out = tail;
  50443. strm.avail_out = chunkSize - tail;
  50444. if (tail) {
  50445. utils.arraySet(strm.output, strm.output, next_out_utf8, tail, 0);
  50446. }
  50447. this.onData(utf8str);
  50448. } else {
  50449. this.onData(utils.shrinkBuf(strm.output, strm.next_out));
  50450. }
  50451. }
  50452. } // When no more input data, we should check that internal inflate buffers
  50453. // are flushed. The only way to do it when avail_out = 0 - run one more
  50454. // inflate pass. But if output data not exists, inflate return Z_BUF_ERROR.
  50455. // Here we set flag to process this error properly.
  50456. //
  50457. // NOTE. Deflate does not return error in this case and does not needs such
  50458. // logic.
  50459. if (strm.avail_in === 0 && strm.avail_out === 0) {
  50460. allowBufError = true;
  50461. }
  50462. } while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== c.Z_STREAM_END);
  50463. if (status === c.Z_STREAM_END) {
  50464. _mode = c.Z_FINISH;
  50465. } // Finalize on the last chunk.
  50466. if (_mode === c.Z_FINISH) {
  50467. status = zlib_inflate.inflateEnd(this.strm);
  50468. this.onEnd(status);
  50469. this.ended = true;
  50470. return status === c.Z_OK;
  50471. } // callback interim results if Z_SYNC_FLUSH.
  50472. if (_mode === c.Z_SYNC_FLUSH) {
  50473. this.onEnd(c.Z_OK);
  50474. strm.avail_out = 0;
  50475. return true;
  50476. }
  50477. return true;
  50478. };
  50479. /**
  50480. * Inflate#onData(chunk) -> Void
  50481. * - chunk (Uint8Array|Array|String): output data. Type of array depends
  50482. * on js engine support. When string output requested, each chunk
  50483. * will be string.
  50484. *
  50485. * By default, stores data blocks in `chunks[]` property and glue
  50486. * those in `onEnd`. Override this handler, if you need another behaviour.
  50487. **/
  50488. Inflate.prototype.onData = function (chunk) {
  50489. this.chunks.push(chunk);
  50490. };
  50491. /**
  50492. * Inflate#onEnd(status) -> Void
  50493. * - status (Number): inflate status. 0 (Z_OK) on success,
  50494. * other if not.
  50495. *
  50496. * Called either after you tell inflate that the input stream is
  50497. * complete (Z_FINISH) or should be flushed (Z_SYNC_FLUSH)
  50498. * or if an error happened. By default - join collected chunks,
  50499. * free memory and fill `results` / `err` properties.
  50500. **/
  50501. Inflate.prototype.onEnd = function (status) {
  50502. // On success - join
  50503. if (status === c.Z_OK) {
  50504. if (this.options.to === 'string') {
  50505. // Glue & convert here, until we teach pako to send
  50506. // utf8 aligned strings to onData
  50507. this.result = this.chunks.join('');
  50508. } else {
  50509. this.result = utils.flattenChunks(this.chunks);
  50510. }
  50511. }
  50512. this.chunks = [];
  50513. this.err = status;
  50514. this.msg = this.strm.msg;
  50515. };
  50516. /**
  50517. * inflate(data[, options]) -> Uint8Array|Array|String
  50518. * - data (Uint8Array|Array|String): input data to decompress.
  50519. * - options (Object): zlib inflate options.
  50520. *
  50521. * Decompress `data` with inflate/ungzip and `options`. Autodetect
  50522. * format via wrapper header by default. That's why we don't provide
  50523. * separate `ungzip` method.
  50524. *
  50525. * Supported options are:
  50526. *
  50527. * - windowBits
  50528. *
  50529. * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
  50530. * for more information.
  50531. *
  50532. * Sugar (options):
  50533. *
  50534. * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify
  50535. * negative windowBits implicitly.
  50536. * - `to` (String) - if equal to 'string', then result will be converted
  50537. * from utf8 to utf16 (javascript) string. When string output requested,
  50538. * chunk length can differ from `chunkSize`, depending on content.
  50539. *
  50540. *
  50541. * ##### Example:
  50542. *
  50543. * ```javascript
  50544. * var pako = require('pako')
  50545. * , input = pako.deflate([1,2,3,4,5,6,7,8,9])
  50546. * , output;
  50547. *
  50548. * try {
  50549. * output = pako.inflate(input);
  50550. * } catch (err)
  50551. * console.log(err);
  50552. * }
  50553. * ```
  50554. **/
  50555. function inflate(input, options) {
  50556. var inflator = new Inflate(options);
  50557. inflator.push(input, true); // That will never happens, if you don't cheat with options :)
  50558. if (inflator.err) {
  50559. throw inflator.msg || msg[inflator.err];
  50560. }
  50561. return inflator.result;
  50562. }
  50563. /**
  50564. * inflateRaw(data[, options]) -> Uint8Array|Array|String
  50565. * - data (Uint8Array|Array|String): input data to decompress.
  50566. * - options (Object): zlib inflate options.
  50567. *
  50568. * The same as [[inflate]], but creates raw data, without wrapper
  50569. * (header and adler32 crc).
  50570. **/
  50571. function inflateRaw(input, options) {
  50572. options = options || {};
  50573. options.raw = true;
  50574. return inflate(input, options);
  50575. }
  50576. /**
  50577. * ungzip(data[, options]) -> Uint8Array|Array|String
  50578. * - data (Uint8Array|Array|String): input data to decompress.
  50579. * - options (Object): zlib inflate options.
  50580. *
  50581. * Just shortcut to [[inflate]], because it autodetects format
  50582. * by header.content. Done for convenience.
  50583. **/
  50584. exports.Inflate = Inflate;
  50585. exports.inflate = inflate;
  50586. exports.inflateRaw = inflateRaw;
  50587. exports.ungzip = inflate;
  50588. },{"./utils/common":442,"./utils/strings":443,"./zlib/constants":445,"./zlib/gzheader":448,"./zlib/inflate":450,"./zlib/messages":452,"./zlib/zstream":454}],442:[function(require,module,exports){
  50589. 'use strict';
  50590. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  50591. var TYPED_OK = typeof Uint8Array !== 'undefined' && typeof Uint16Array !== 'undefined' && typeof Int32Array !== 'undefined';
  50592. function _has(obj, key) {
  50593. return Object.prototype.hasOwnProperty.call(obj, key);
  50594. }
  50595. exports.assign = function (obj
  50596. /*from1, from2, from3, ...*/
  50597. ) {
  50598. var sources = Array.prototype.slice.call(arguments, 1);
  50599. while (sources.length) {
  50600. var source = sources.shift();
  50601. if (!source) {
  50602. continue;
  50603. }
  50604. if (_typeof(source) !== 'object') {
  50605. throw new TypeError(source + 'must be non-object');
  50606. }
  50607. for (var p in source) {
  50608. if (_has(source, p)) {
  50609. obj[p] = source[p];
  50610. }
  50611. }
  50612. }
  50613. return obj;
  50614. }; // reduce buffer size, avoiding mem copy
  50615. exports.shrinkBuf = function (buf, size) {
  50616. if (buf.length === size) {
  50617. return buf;
  50618. }
  50619. if (buf.subarray) {
  50620. return buf.subarray(0, size);
  50621. }
  50622. buf.length = size;
  50623. return buf;
  50624. };
  50625. var fnTyped = {
  50626. arraySet: function arraySet(dest, src, src_offs, len, dest_offs) {
  50627. if (src.subarray && dest.subarray) {
  50628. dest.set(src.subarray(src_offs, src_offs + len), dest_offs);
  50629. return;
  50630. } // Fallback to ordinary array
  50631. for (var i = 0; i < len; i++) {
  50632. dest[dest_offs + i] = src[src_offs + i];
  50633. }
  50634. },
  50635. // Join array of chunks to single array.
  50636. flattenChunks: function flattenChunks(chunks) {
  50637. var i, l, len, pos, chunk, result; // calculate data length
  50638. len = 0;
  50639. for (i = 0, l = chunks.length; i < l; i++) {
  50640. len += chunks[i].length;
  50641. } // join chunks
  50642. result = new Uint8Array(len);
  50643. pos = 0;
  50644. for (i = 0, l = chunks.length; i < l; i++) {
  50645. chunk = chunks[i];
  50646. result.set(chunk, pos);
  50647. pos += chunk.length;
  50648. }
  50649. return result;
  50650. }
  50651. };
  50652. var fnUntyped = {
  50653. arraySet: function arraySet(dest, src, src_offs, len, dest_offs) {
  50654. for (var i = 0; i < len; i++) {
  50655. dest[dest_offs + i] = src[src_offs + i];
  50656. }
  50657. },
  50658. // Join array of chunks to single array.
  50659. flattenChunks: function flattenChunks(chunks) {
  50660. return [].concat.apply([], chunks);
  50661. }
  50662. }; // Enable/Disable typed arrays use, for testing
  50663. //
  50664. exports.setTyped = function (on) {
  50665. if (on) {
  50666. exports.Buf8 = Uint8Array;
  50667. exports.Buf16 = Uint16Array;
  50668. exports.Buf32 = Int32Array;
  50669. exports.assign(exports, fnTyped);
  50670. } else {
  50671. exports.Buf8 = Array;
  50672. exports.Buf16 = Array;
  50673. exports.Buf32 = Array;
  50674. exports.assign(exports, fnUntyped);
  50675. }
  50676. };
  50677. exports.setTyped(TYPED_OK);
  50678. },{}],443:[function(require,module,exports){
  50679. // String encode/decode helpers
  50680. 'use strict';
  50681. var utils = require('./common'); // Quick check if we can use fast array to bin string conversion
  50682. //
  50683. // - apply(Array) can fail on Android 2.2
  50684. // - apply(Uint8Array) can fail on iOS 5.1 Safari
  50685. //
  50686. var STR_APPLY_OK = true;
  50687. var STR_APPLY_UIA_OK = true;
  50688. try {
  50689. String.fromCharCode.apply(null, [0]);
  50690. } catch (__) {
  50691. STR_APPLY_OK = false;
  50692. }
  50693. try {
  50694. String.fromCharCode.apply(null, new Uint8Array(1));
  50695. } catch (__) {
  50696. STR_APPLY_UIA_OK = false;
  50697. } // Table with utf8 lengths (calculated by first byte of sequence)
  50698. // Note, that 5 & 6-byte values and some 4-byte values can not be represented in JS,
  50699. // because max possible codepoint is 0x10ffff
  50700. var _utf8len = new utils.Buf8(256);
  50701. for (var q = 0; q < 256; q++) {
  50702. _utf8len[q] = q >= 252 ? 6 : q >= 248 ? 5 : q >= 240 ? 4 : q >= 224 ? 3 : q >= 192 ? 2 : 1;
  50703. }
  50704. _utf8len[254] = _utf8len[254] = 1; // Invalid sequence start
  50705. // convert string to array (typed, when possible)
  50706. exports.string2buf = function (str) {
  50707. var buf,
  50708. c,
  50709. c2,
  50710. m_pos,
  50711. i,
  50712. str_len = str.length,
  50713. buf_len = 0; // count binary size
  50714. for (m_pos = 0; m_pos < str_len; m_pos++) {
  50715. c = str.charCodeAt(m_pos);
  50716. if ((c & 0xfc00) === 0xd800 && m_pos + 1 < str_len) {
  50717. c2 = str.charCodeAt(m_pos + 1);
  50718. if ((c2 & 0xfc00) === 0xdc00) {
  50719. c = 0x10000 + (c - 0xd800 << 10) + (c2 - 0xdc00);
  50720. m_pos++;
  50721. }
  50722. }
  50723. buf_len += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4;
  50724. } // allocate buffer
  50725. buf = new utils.Buf8(buf_len); // convert
  50726. for (i = 0, m_pos = 0; i < buf_len; m_pos++) {
  50727. c = str.charCodeAt(m_pos);
  50728. if ((c & 0xfc00) === 0xd800 && m_pos + 1 < str_len) {
  50729. c2 = str.charCodeAt(m_pos + 1);
  50730. if ((c2 & 0xfc00) === 0xdc00) {
  50731. c = 0x10000 + (c - 0xd800 << 10) + (c2 - 0xdc00);
  50732. m_pos++;
  50733. }
  50734. }
  50735. if (c < 0x80) {
  50736. /* one byte */
  50737. buf[i++] = c;
  50738. } else if (c < 0x800) {
  50739. /* two bytes */
  50740. buf[i++] = 0xC0 | c >>> 6;
  50741. buf[i++] = 0x80 | c & 0x3f;
  50742. } else if (c < 0x10000) {
  50743. /* three bytes */
  50744. buf[i++] = 0xE0 | c >>> 12;
  50745. buf[i++] = 0x80 | c >>> 6 & 0x3f;
  50746. buf[i++] = 0x80 | c & 0x3f;
  50747. } else {
  50748. /* four bytes */
  50749. buf[i++] = 0xf0 | c >>> 18;
  50750. buf[i++] = 0x80 | c >>> 12 & 0x3f;
  50751. buf[i++] = 0x80 | c >>> 6 & 0x3f;
  50752. buf[i++] = 0x80 | c & 0x3f;
  50753. }
  50754. }
  50755. return buf;
  50756. }; // Helper (used in 2 places)
  50757. function buf2binstring(buf, len) {
  50758. // On Chrome, the arguments in a function call that are allowed is `65534`.
  50759. // If the length of the buffer is smaller than that, we can use this optimization,
  50760. // otherwise we will take a slower path.
  50761. if (len < 65534) {
  50762. if (buf.subarray && STR_APPLY_UIA_OK || !buf.subarray && STR_APPLY_OK) {
  50763. return String.fromCharCode.apply(null, utils.shrinkBuf(buf, len));
  50764. }
  50765. }
  50766. var result = '';
  50767. for (var i = 0; i < len; i++) {
  50768. result += String.fromCharCode(buf[i]);
  50769. }
  50770. return result;
  50771. } // Convert byte array to binary string
  50772. exports.buf2binstring = function (buf) {
  50773. return buf2binstring(buf, buf.length);
  50774. }; // Convert binary string (typed, when possible)
  50775. exports.binstring2buf = function (str) {
  50776. var buf = new utils.Buf8(str.length);
  50777. for (var i = 0, len = buf.length; i < len; i++) {
  50778. buf[i] = str.charCodeAt(i);
  50779. }
  50780. return buf;
  50781. }; // convert array to string
  50782. exports.buf2string = function (buf, max) {
  50783. var i, out, c, c_len;
  50784. var len = max || buf.length; // Reserve max possible length (2 words per char)
  50785. // NB: by unknown reasons, Array is significantly faster for
  50786. // String.fromCharCode.apply than Uint16Array.
  50787. var utf16buf = new Array(len * 2);
  50788. for (out = 0, i = 0; i < len;) {
  50789. c = buf[i++]; // quick process ascii
  50790. if (c < 0x80) {
  50791. utf16buf[out++] = c;
  50792. continue;
  50793. }
  50794. c_len = _utf8len[c]; // skip 5 & 6 byte codes
  50795. if (c_len > 4) {
  50796. utf16buf[out++] = 0xfffd;
  50797. i += c_len - 1;
  50798. continue;
  50799. } // apply mask on first byte
  50800. c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07; // join the rest
  50801. while (c_len > 1 && i < len) {
  50802. c = c << 6 | buf[i++] & 0x3f;
  50803. c_len--;
  50804. } // terminated by end of string?
  50805. if (c_len > 1) {
  50806. utf16buf[out++] = 0xfffd;
  50807. continue;
  50808. }
  50809. if (c < 0x10000) {
  50810. utf16buf[out++] = c;
  50811. } else {
  50812. c -= 0x10000;
  50813. utf16buf[out++] = 0xd800 | c >> 10 & 0x3ff;
  50814. utf16buf[out++] = 0xdc00 | c & 0x3ff;
  50815. }
  50816. }
  50817. return buf2binstring(utf16buf, out);
  50818. }; // Calculate max possible position in utf8 buffer,
  50819. // that will not break sequence. If that's not possible
  50820. // - (very small limits) return max size as is.
  50821. //
  50822. // buf[] - utf8 bytes array
  50823. // max - length limit (mandatory);
  50824. exports.utf8border = function (buf, max) {
  50825. var pos;
  50826. max = max || buf.length;
  50827. if (max > buf.length) {
  50828. max = buf.length;
  50829. } // go back from last position, until start of sequence found
  50830. pos = max - 1;
  50831. while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) {
  50832. pos--;
  50833. } // Very small and broken sequence,
  50834. // return max, because we should return something anyway.
  50835. if (pos < 0) {
  50836. return max;
  50837. } // If we came to start of buffer - that means buffer is too small,
  50838. // return max too.
  50839. if (pos === 0) {
  50840. return max;
  50841. }
  50842. return pos + _utf8len[buf[pos]] > max ? pos : max;
  50843. };
  50844. },{"./common":442}],444:[function(require,module,exports){
  50845. 'use strict'; // Note: adler32 takes 12% for level 0 and 2% for level 6.
  50846. // It isn't worth it to make additional optimizations as in original.
  50847. // Small size is preferable.
  50848. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  50849. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  50850. //
  50851. // This software is provided 'as-is', without any express or implied
  50852. // warranty. In no event will the authors be held liable for any damages
  50853. // arising from the use of this software.
  50854. //
  50855. // Permission is granted to anyone to use this software for any purpose,
  50856. // including commercial applications, and to alter it and redistribute it
  50857. // freely, subject to the following restrictions:
  50858. //
  50859. // 1. The origin of this software must not be misrepresented; you must not
  50860. // claim that you wrote the original software. If you use this software
  50861. // in a product, an acknowledgment in the product documentation would be
  50862. // appreciated but is not required.
  50863. // 2. Altered source versions must be plainly marked as such, and must not be
  50864. // misrepresented as being the original software.
  50865. // 3. This notice may not be removed or altered from any source distribution.
  50866. function adler32(adler, buf, len, pos) {
  50867. var s1 = adler & 0xffff | 0,
  50868. s2 = adler >>> 16 & 0xffff | 0,
  50869. n = 0;
  50870. while (len !== 0) {
  50871. // Set limit ~ twice less than 5552, to keep
  50872. // s2 in 31-bits, because we force signed ints.
  50873. // in other case %= will fail.
  50874. n = len > 2000 ? 2000 : len;
  50875. len -= n;
  50876. do {
  50877. s1 = s1 + buf[pos++] | 0;
  50878. s2 = s2 + s1 | 0;
  50879. } while (--n);
  50880. s1 %= 65521;
  50881. s2 %= 65521;
  50882. }
  50883. return s1 | s2 << 16 | 0;
  50884. }
  50885. module.exports = adler32;
  50886. },{}],445:[function(require,module,exports){
  50887. 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  50888. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  50889. //
  50890. // This software is provided 'as-is', without any express or implied
  50891. // warranty. In no event will the authors be held liable for any damages
  50892. // arising from the use of this software.
  50893. //
  50894. // Permission is granted to anyone to use this software for any purpose,
  50895. // including commercial applications, and to alter it and redistribute it
  50896. // freely, subject to the following restrictions:
  50897. //
  50898. // 1. The origin of this software must not be misrepresented; you must not
  50899. // claim that you wrote the original software. If you use this software
  50900. // in a product, an acknowledgment in the product documentation would be
  50901. // appreciated but is not required.
  50902. // 2. Altered source versions must be plainly marked as such, and must not be
  50903. // misrepresented as being the original software.
  50904. // 3. This notice may not be removed or altered from any source distribution.
  50905. module.exports = {
  50906. /* Allowed flush values; see deflate() and inflate() below for details */
  50907. Z_NO_FLUSH: 0,
  50908. Z_PARTIAL_FLUSH: 1,
  50909. Z_SYNC_FLUSH: 2,
  50910. Z_FULL_FLUSH: 3,
  50911. Z_FINISH: 4,
  50912. Z_BLOCK: 5,
  50913. Z_TREES: 6,
  50914. /* Return codes for the compression/decompression functions. Negative values
  50915. * are errors, positive values are used for special but normal events.
  50916. */
  50917. Z_OK: 0,
  50918. Z_STREAM_END: 1,
  50919. Z_NEED_DICT: 2,
  50920. Z_ERRNO: -1,
  50921. Z_STREAM_ERROR: -2,
  50922. Z_DATA_ERROR: -3,
  50923. //Z_MEM_ERROR: -4,
  50924. Z_BUF_ERROR: -5,
  50925. //Z_VERSION_ERROR: -6,
  50926. /* compression levels */
  50927. Z_NO_COMPRESSION: 0,
  50928. Z_BEST_SPEED: 1,
  50929. Z_BEST_COMPRESSION: 9,
  50930. Z_DEFAULT_COMPRESSION: -1,
  50931. Z_FILTERED: 1,
  50932. Z_HUFFMAN_ONLY: 2,
  50933. Z_RLE: 3,
  50934. Z_FIXED: 4,
  50935. Z_DEFAULT_STRATEGY: 0,
  50936. /* Possible values of the data_type field (though see inflate()) */
  50937. Z_BINARY: 0,
  50938. Z_TEXT: 1,
  50939. //Z_ASCII: 1, // = Z_TEXT (deprecated)
  50940. Z_UNKNOWN: 2,
  50941. /* The deflate compression method */
  50942. Z_DEFLATED: 8 //Z_NULL: null // Use -1 or null inline, depending on var type
  50943. };
  50944. },{}],446:[function(require,module,exports){
  50945. 'use strict'; // Note: we can't get significant speed boost here.
  50946. // So write code to minimize size - no pregenerated tables
  50947. // and array tools dependencies.
  50948. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  50949. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  50950. //
  50951. // This software is provided 'as-is', without any express or implied
  50952. // warranty. In no event will the authors be held liable for any damages
  50953. // arising from the use of this software.
  50954. //
  50955. // Permission is granted to anyone to use this software for any purpose,
  50956. // including commercial applications, and to alter it and redistribute it
  50957. // freely, subject to the following restrictions:
  50958. //
  50959. // 1. The origin of this software must not be misrepresented; you must not
  50960. // claim that you wrote the original software. If you use this software
  50961. // in a product, an acknowledgment in the product documentation would be
  50962. // appreciated but is not required.
  50963. // 2. Altered source versions must be plainly marked as such, and must not be
  50964. // misrepresented as being the original software.
  50965. // 3. This notice may not be removed or altered from any source distribution.
  50966. // Use ordinary array, since untyped makes no boost here
  50967. function makeTable() {
  50968. var c,
  50969. table = [];
  50970. for (var n = 0; n < 256; n++) {
  50971. c = n;
  50972. for (var k = 0; k < 8; k++) {
  50973. c = c & 1 ? 0xEDB88320 ^ c >>> 1 : c >>> 1;
  50974. }
  50975. table[n] = c;
  50976. }
  50977. return table;
  50978. } // Create table on load. Just 255 signed longs. Not a problem.
  50979. var crcTable = makeTable();
  50980. function crc32(crc, buf, len, pos) {
  50981. var t = crcTable,
  50982. end = pos + len;
  50983. crc ^= -1;
  50984. for (var i = pos; i < end; i++) {
  50985. crc = crc >>> 8 ^ t[(crc ^ buf[i]) & 0xFF];
  50986. }
  50987. return crc ^ -1; // >>> 0;
  50988. }
  50989. module.exports = crc32;
  50990. },{}],447:[function(require,module,exports){
  50991. 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  50992. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  50993. //
  50994. // This software is provided 'as-is', without any express or implied
  50995. // warranty. In no event will the authors be held liable for any damages
  50996. // arising from the use of this software.
  50997. //
  50998. // Permission is granted to anyone to use this software for any purpose,
  50999. // including commercial applications, and to alter it and redistribute it
  51000. // freely, subject to the following restrictions:
  51001. //
  51002. // 1. The origin of this software must not be misrepresented; you must not
  51003. // claim that you wrote the original software. If you use this software
  51004. // in a product, an acknowledgment in the product documentation would be
  51005. // appreciated but is not required.
  51006. // 2. Altered source versions must be plainly marked as such, and must not be
  51007. // misrepresented as being the original software.
  51008. // 3. This notice may not be removed or altered from any source distribution.
  51009. var utils = require('../utils/common');
  51010. var trees = require('./trees');
  51011. var adler32 = require('./adler32');
  51012. var crc32 = require('./crc32');
  51013. var msg = require('./messages');
  51014. /* Public constants ==========================================================*/
  51015. /* ===========================================================================*/
  51016. /* Allowed flush values; see deflate() and inflate() below for details */
  51017. var Z_NO_FLUSH = 0;
  51018. var Z_PARTIAL_FLUSH = 1; //var Z_SYNC_FLUSH = 2;
  51019. var Z_FULL_FLUSH = 3;
  51020. var Z_FINISH = 4;
  51021. var Z_BLOCK = 5; //var Z_TREES = 6;
  51022. /* Return codes for the compression/decompression functions. Negative values
  51023. * are errors, positive values are used for special but normal events.
  51024. */
  51025. var Z_OK = 0;
  51026. var Z_STREAM_END = 1; //var Z_NEED_DICT = 2;
  51027. //var Z_ERRNO = -1;
  51028. var Z_STREAM_ERROR = -2;
  51029. var Z_DATA_ERROR = -3; //var Z_MEM_ERROR = -4;
  51030. var Z_BUF_ERROR = -5; //var Z_VERSION_ERROR = -6;
  51031. /* compression levels */
  51032. //var Z_NO_COMPRESSION = 0;
  51033. //var Z_BEST_SPEED = 1;
  51034. //var Z_BEST_COMPRESSION = 9;
  51035. var Z_DEFAULT_COMPRESSION = -1;
  51036. var Z_FILTERED = 1;
  51037. var Z_HUFFMAN_ONLY = 2;
  51038. var Z_RLE = 3;
  51039. var Z_FIXED = 4;
  51040. var Z_DEFAULT_STRATEGY = 0;
  51041. /* Possible values of the data_type field (though see inflate()) */
  51042. //var Z_BINARY = 0;
  51043. //var Z_TEXT = 1;
  51044. //var Z_ASCII = 1; // = Z_TEXT
  51045. var Z_UNKNOWN = 2;
  51046. /* The deflate compression method */
  51047. var Z_DEFLATED = 8;
  51048. /*============================================================================*/
  51049. var MAX_MEM_LEVEL = 9;
  51050. /* Maximum value for memLevel in deflateInit2 */
  51051. var MAX_WBITS = 15;
  51052. /* 32K LZ77 window */
  51053. var DEF_MEM_LEVEL = 8;
  51054. var LENGTH_CODES = 29;
  51055. /* number of length codes, not counting the special END_BLOCK code */
  51056. var LITERALS = 256;
  51057. /* number of literal bytes 0..255 */
  51058. var L_CODES = LITERALS + 1 + LENGTH_CODES;
  51059. /* number of Literal or Length codes, including the END_BLOCK code */
  51060. var D_CODES = 30;
  51061. /* number of distance codes */
  51062. var BL_CODES = 19;
  51063. /* number of codes used to transfer the bit lengths */
  51064. var HEAP_SIZE = 2 * L_CODES + 1;
  51065. /* maximum heap size */
  51066. var MAX_BITS = 15;
  51067. /* All codes must not exceed MAX_BITS bits */
  51068. var MIN_MATCH = 3;
  51069. var MAX_MATCH = 258;
  51070. var MIN_LOOKAHEAD = MAX_MATCH + MIN_MATCH + 1;
  51071. var PRESET_DICT = 0x20;
  51072. var INIT_STATE = 42;
  51073. var EXTRA_STATE = 69;
  51074. var NAME_STATE = 73;
  51075. var COMMENT_STATE = 91;
  51076. var HCRC_STATE = 103;
  51077. var BUSY_STATE = 113;
  51078. var FINISH_STATE = 666;
  51079. var BS_NEED_MORE = 1;
  51080. /* block not completed, need more input or more output */
  51081. var BS_BLOCK_DONE = 2;
  51082. /* block flush performed */
  51083. var BS_FINISH_STARTED = 3;
  51084. /* finish started, need only more output at next deflate */
  51085. var BS_FINISH_DONE = 4;
  51086. /* finish done, accept no more input or output */
  51087. var OS_CODE = 0x03; // Unix :) . Don't detect, use this default.
  51088. function err(strm, errorCode) {
  51089. strm.msg = msg[errorCode];
  51090. return errorCode;
  51091. }
  51092. function rank(f) {
  51093. return (f << 1) - (f > 4 ? 9 : 0);
  51094. }
  51095. function zero(buf) {
  51096. var len = buf.length;
  51097. while (--len >= 0) {
  51098. buf[len] = 0;
  51099. }
  51100. }
  51101. /* =========================================================================
  51102. * Flush as much pending output as possible. All deflate() output goes
  51103. * through this function so some applications may wish to modify it
  51104. * to avoid allocating a large strm->output buffer and copying into it.
  51105. * (See also read_buf()).
  51106. */
  51107. function flush_pending(strm) {
  51108. var s = strm.state; //_tr_flush_bits(s);
  51109. var len = s.pending;
  51110. if (len > strm.avail_out) {
  51111. len = strm.avail_out;
  51112. }
  51113. if (len === 0) {
  51114. return;
  51115. }
  51116. utils.arraySet(strm.output, s.pending_buf, s.pending_out, len, strm.next_out);
  51117. strm.next_out += len;
  51118. s.pending_out += len;
  51119. strm.total_out += len;
  51120. strm.avail_out -= len;
  51121. s.pending -= len;
  51122. if (s.pending === 0) {
  51123. s.pending_out = 0;
  51124. }
  51125. }
  51126. function flush_block_only(s, last) {
  51127. trees._tr_flush_block(s, s.block_start >= 0 ? s.block_start : -1, s.strstart - s.block_start, last);
  51128. s.block_start = s.strstart;
  51129. flush_pending(s.strm);
  51130. }
  51131. function put_byte(s, b) {
  51132. s.pending_buf[s.pending++] = b;
  51133. }
  51134. /* =========================================================================
  51135. * Put a short in the pending buffer. The 16-bit value is put in MSB order.
  51136. * IN assertion: the stream state is correct and there is enough room in
  51137. * pending_buf.
  51138. */
  51139. function putShortMSB(s, b) {
  51140. // put_byte(s, (Byte)(b >> 8));
  51141. // put_byte(s, (Byte)(b & 0xff));
  51142. s.pending_buf[s.pending++] = b >>> 8 & 0xff;
  51143. s.pending_buf[s.pending++] = b & 0xff;
  51144. }
  51145. /* ===========================================================================
  51146. * Read a new buffer from the current input stream, update the adler32
  51147. * and total number of bytes read. All deflate() input goes through
  51148. * this function so some applications may wish to modify it to avoid
  51149. * allocating a large strm->input buffer and copying from it.
  51150. * (See also flush_pending()).
  51151. */
  51152. function read_buf(strm, buf, start, size) {
  51153. var len = strm.avail_in;
  51154. if (len > size) {
  51155. len = size;
  51156. }
  51157. if (len === 0) {
  51158. return 0;
  51159. }
  51160. strm.avail_in -= len; // zmemcpy(buf, strm->next_in, len);
  51161. utils.arraySet(buf, strm.input, strm.next_in, len, start);
  51162. if (strm.state.wrap === 1) {
  51163. strm.adler = adler32(strm.adler, buf, len, start);
  51164. } else if (strm.state.wrap === 2) {
  51165. strm.adler = crc32(strm.adler, buf, len, start);
  51166. }
  51167. strm.next_in += len;
  51168. strm.total_in += len;
  51169. return len;
  51170. }
  51171. /* ===========================================================================
  51172. * Set match_start to the longest match starting at the given string and
  51173. * return its length. Matches shorter or equal to prev_length are discarded,
  51174. * in which case the result is equal to prev_length and match_start is
  51175. * garbage.
  51176. * IN assertions: cur_match is the head of the hash chain for the current
  51177. * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
  51178. * OUT assertion: the match length is not greater than s->lookahead.
  51179. */
  51180. function longest_match(s, cur_match) {
  51181. var chain_length = s.max_chain_length;
  51182. /* max hash chain length */
  51183. var scan = s.strstart;
  51184. /* current string */
  51185. var match;
  51186. /* matched string */
  51187. var len;
  51188. /* length of current match */
  51189. var best_len = s.prev_length;
  51190. /* best match length so far */
  51191. var nice_match = s.nice_match;
  51192. /* stop if match long enough */
  51193. var limit = s.strstart > s.w_size - MIN_LOOKAHEAD ? s.strstart - (s.w_size - MIN_LOOKAHEAD) : 0
  51194. /*NIL*/
  51195. ;
  51196. var _win = s.window; // shortcut
  51197. var wmask = s.w_mask;
  51198. var prev = s.prev;
  51199. /* Stop when cur_match becomes <= limit. To simplify the code,
  51200. * we prevent matches with the string of window index 0.
  51201. */
  51202. var strend = s.strstart + MAX_MATCH;
  51203. var scan_end1 = _win[scan + best_len - 1];
  51204. var scan_end = _win[scan + best_len];
  51205. /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
  51206. * It is easy to get rid of this optimization if necessary.
  51207. */
  51208. // Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  51209. /* Do not waste too much time if we already have a good match: */
  51210. if (s.prev_length >= s.good_match) {
  51211. chain_length >>= 2;
  51212. }
  51213. /* Do not look for matches beyond the end of the input. This is necessary
  51214. * to make deflate deterministic.
  51215. */
  51216. if (nice_match > s.lookahead) {
  51217. nice_match = s.lookahead;
  51218. } // Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  51219. do {
  51220. // Assert(cur_match < s->strstart, "no future");
  51221. match = cur_match;
  51222. /* Skip to next match if the match length cannot increase
  51223. * or if the match length is less than 2. Note that the checks below
  51224. * for insufficient lookahead only occur occasionally for performance
  51225. * reasons. Therefore uninitialized memory will be accessed, and
  51226. * conditional jumps will be made that depend on those values.
  51227. * However the length of the match is limited to the lookahead, so
  51228. * the output of deflate is not affected by the uninitialized values.
  51229. */
  51230. if (_win[match + best_len] !== scan_end || _win[match + best_len - 1] !== scan_end1 || _win[match] !== _win[scan] || _win[++match] !== _win[scan + 1]) {
  51231. continue;
  51232. }
  51233. /* The check at best_len-1 can be removed because it will be made
  51234. * again later. (This heuristic is not always a win.)
  51235. * It is not necessary to compare scan[2] and match[2] since they
  51236. * are always equal when the other bytes match, given that
  51237. * the hash keys are equal and that HASH_BITS >= 8.
  51238. */
  51239. scan += 2;
  51240. match++; // Assert(*scan == *match, "match[2]?");
  51241. /* We check for insufficient lookahead only every 8th comparison;
  51242. * the 256th check will be made at strstart+258.
  51243. */
  51244. do {
  51245. /*jshint noempty:false*/
  51246. } while (_win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && scan < strend); // Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  51247. len = MAX_MATCH - (strend - scan);
  51248. scan = strend - MAX_MATCH;
  51249. if (len > best_len) {
  51250. s.match_start = cur_match;
  51251. best_len = len;
  51252. if (len >= nice_match) {
  51253. break;
  51254. }
  51255. scan_end1 = _win[scan + best_len - 1];
  51256. scan_end = _win[scan + best_len];
  51257. }
  51258. } while ((cur_match = prev[cur_match & wmask]) > limit && --chain_length !== 0);
  51259. if (best_len <= s.lookahead) {
  51260. return best_len;
  51261. }
  51262. return s.lookahead;
  51263. }
  51264. /* ===========================================================================
  51265. * Fill the window when the lookahead becomes insufficient.
  51266. * Updates strstart and lookahead.
  51267. *
  51268. * IN assertion: lookahead < MIN_LOOKAHEAD
  51269. * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
  51270. * At least one byte has been read, or avail_in == 0; reads are
  51271. * performed for at least two bytes (required for the zip translate_eol
  51272. * option -- not supported here).
  51273. */
  51274. function fill_window(s) {
  51275. var _w_size = s.w_size;
  51276. var p, n, m, more, str; //Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
  51277. do {
  51278. more = s.window_size - s.lookahead - s.strstart; // JS ints have 32 bit, block below not needed
  51279. /* Deal with !@#$% 64K limit: */
  51280. //if (sizeof(int) <= 2) {
  51281. // if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  51282. // more = wsize;
  51283. //
  51284. // } else if (more == (unsigned)(-1)) {
  51285. // /* Very unlikely, but possible on 16 bit machine if
  51286. // * strstart == 0 && lookahead == 1 (input done a byte at time)
  51287. // */
  51288. // more--;
  51289. // }
  51290. //}
  51291. /* If the window is almost full and there is insufficient lookahead,
  51292. * move the upper half to the lower one to make room in the upper half.
  51293. */
  51294. if (s.strstart >= _w_size + (_w_size - MIN_LOOKAHEAD)) {
  51295. utils.arraySet(s.window, s.window, _w_size, _w_size, 0);
  51296. s.match_start -= _w_size;
  51297. s.strstart -= _w_size;
  51298. /* we now have strstart >= MAX_DIST */
  51299. s.block_start -= _w_size;
  51300. /* Slide the hash table (could be avoided with 32 bit values
  51301. at the expense of memory usage). We slide even when level == 0
  51302. to keep the hash table consistent if we switch back to level > 0
  51303. later. (Using level 0 permanently is not an optimal usage of
  51304. zlib, so we don't care about this pathological case.)
  51305. */
  51306. n = s.hash_size;
  51307. p = n;
  51308. do {
  51309. m = s.head[--p];
  51310. s.head[p] = m >= _w_size ? m - _w_size : 0;
  51311. } while (--n);
  51312. n = _w_size;
  51313. p = n;
  51314. do {
  51315. m = s.prev[--p];
  51316. s.prev[p] = m >= _w_size ? m - _w_size : 0;
  51317. /* If n is not on any hash chain, prev[n] is garbage but
  51318. * its value will never be used.
  51319. */
  51320. } while (--n);
  51321. more += _w_size;
  51322. }
  51323. if (s.strm.avail_in === 0) {
  51324. break;
  51325. }
  51326. /* If there was no sliding:
  51327. * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
  51328. * more == window_size - lookahead - strstart
  51329. * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
  51330. * => more >= window_size - 2*WSIZE + 2
  51331. * In the BIG_MEM or MMAP case (not yet supported),
  51332. * window_size == input_size + MIN_LOOKAHEAD &&
  51333. * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
  51334. * Otherwise, window_size == 2*WSIZE so more >= 2.
  51335. * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
  51336. */
  51337. //Assert(more >= 2, "more < 2");
  51338. n = read_buf(s.strm, s.window, s.strstart + s.lookahead, more);
  51339. s.lookahead += n;
  51340. /* Initialize the hash value now that we have some input: */
  51341. if (s.lookahead + s.insert >= MIN_MATCH) {
  51342. str = s.strstart - s.insert;
  51343. s.ins_h = s.window[str];
  51344. /* UPDATE_HASH(s, s->ins_h, s->window[str + 1]); */
  51345. s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str + 1]) & s.hash_mask; //#if MIN_MATCH != 3
  51346. // Call update_hash() MIN_MATCH-3 more times
  51347. //#endif
  51348. while (s.insert) {
  51349. /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */
  51350. s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
  51351. s.prev[str & s.w_mask] = s.head[s.ins_h];
  51352. s.head[s.ins_h] = str;
  51353. str++;
  51354. s.insert--;
  51355. if (s.lookahead + s.insert < MIN_MATCH) {
  51356. break;
  51357. }
  51358. }
  51359. }
  51360. /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
  51361. * but this is not important since only literal bytes will be emitted.
  51362. */
  51363. } while (s.lookahead < MIN_LOOKAHEAD && s.strm.avail_in !== 0);
  51364. /* If the WIN_INIT bytes after the end of the current data have never been
  51365. * written, then zero those bytes in order to avoid memory check reports of
  51366. * the use of uninitialized (or uninitialised as Julian writes) bytes by
  51367. * the longest match routines. Update the high water mark for the next
  51368. * time through here. WIN_INIT is set to MAX_MATCH since the longest match
  51369. * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
  51370. */
  51371. // if (s.high_water < s.window_size) {
  51372. // var curr = s.strstart + s.lookahead;
  51373. // var init = 0;
  51374. //
  51375. // if (s.high_water < curr) {
  51376. // /* Previous high water mark below current data -- zero WIN_INIT
  51377. // * bytes or up to end of window, whichever is less.
  51378. // */
  51379. // init = s.window_size - curr;
  51380. // if (init > WIN_INIT)
  51381. // init = WIN_INIT;
  51382. // zmemzero(s->window + curr, (unsigned)init);
  51383. // s->high_water = curr + init;
  51384. // }
  51385. // else if (s->high_water < (ulg)curr + WIN_INIT) {
  51386. // /* High water mark at or above current data, but below current data
  51387. // * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
  51388. // * to end of window, whichever is less.
  51389. // */
  51390. // init = (ulg)curr + WIN_INIT - s->high_water;
  51391. // if (init > s->window_size - s->high_water)
  51392. // init = s->window_size - s->high_water;
  51393. // zmemzero(s->window + s->high_water, (unsigned)init);
  51394. // s->high_water += init;
  51395. // }
  51396. // }
  51397. //
  51398. // Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
  51399. // "not enough room for search");
  51400. }
  51401. /* ===========================================================================
  51402. * Copy without compression as much as possible from the input stream, return
  51403. * the current block state.
  51404. * This function does not insert new strings in the dictionary since
  51405. * uncompressible data is probably not useful. This function is used
  51406. * only for the level=0 compression option.
  51407. * NOTE: this function should be optimized to avoid extra copying from
  51408. * window to pending_buf.
  51409. */
  51410. function deflate_stored(s, flush) {
  51411. /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
  51412. * to pending_buf_size, and each stored block has a 5 byte header:
  51413. */
  51414. var max_block_size = 0xffff;
  51415. if (max_block_size > s.pending_buf_size - 5) {
  51416. max_block_size = s.pending_buf_size - 5;
  51417. }
  51418. /* Copy as much as possible from input to output: */
  51419. for (;;) {
  51420. /* Fill the window as much as possible: */
  51421. if (s.lookahead <= 1) {
  51422. //Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  51423. // s->block_start >= (long)s->w_size, "slide too late");
  51424. // if (!(s.strstart < s.w_size + (s.w_size - MIN_LOOKAHEAD) ||
  51425. // s.block_start >= s.w_size)) {
  51426. // throw new Error("slide too late");
  51427. // }
  51428. fill_window(s);
  51429. if (s.lookahead === 0 && flush === Z_NO_FLUSH) {
  51430. return BS_NEED_MORE;
  51431. }
  51432. if (s.lookahead === 0) {
  51433. break;
  51434. }
  51435. /* flush the current block */
  51436. } //Assert(s->block_start >= 0L, "block gone");
  51437. // if (s.block_start < 0) throw new Error("block gone");
  51438. s.strstart += s.lookahead;
  51439. s.lookahead = 0;
  51440. /* Emit a stored block if pending_buf will be full: */
  51441. var max_start = s.block_start + max_block_size;
  51442. if (s.strstart === 0 || s.strstart >= max_start) {
  51443. /* strstart == 0 is possible when wraparound on 16-bit machine */
  51444. s.lookahead = s.strstart - max_start;
  51445. s.strstart = max_start;
  51446. /*** FLUSH_BLOCK(s, 0); ***/
  51447. flush_block_only(s, false);
  51448. if (s.strm.avail_out === 0) {
  51449. return BS_NEED_MORE;
  51450. }
  51451. /***/
  51452. }
  51453. /* Flush if we may have to slide, otherwise block_start may become
  51454. * negative and the data will be gone:
  51455. */
  51456. if (s.strstart - s.block_start >= s.w_size - MIN_LOOKAHEAD) {
  51457. /*** FLUSH_BLOCK(s, 0); ***/
  51458. flush_block_only(s, false);
  51459. if (s.strm.avail_out === 0) {
  51460. return BS_NEED_MORE;
  51461. }
  51462. /***/
  51463. }
  51464. }
  51465. s.insert = 0;
  51466. if (flush === Z_FINISH) {
  51467. /*** FLUSH_BLOCK(s, 1); ***/
  51468. flush_block_only(s, true);
  51469. if (s.strm.avail_out === 0) {
  51470. return BS_FINISH_STARTED;
  51471. }
  51472. /***/
  51473. return BS_FINISH_DONE;
  51474. }
  51475. if (s.strstart > s.block_start) {
  51476. /*** FLUSH_BLOCK(s, 0); ***/
  51477. flush_block_only(s, false);
  51478. if (s.strm.avail_out === 0) {
  51479. return BS_NEED_MORE;
  51480. }
  51481. /***/
  51482. }
  51483. return BS_NEED_MORE;
  51484. }
  51485. /* ===========================================================================
  51486. * Compress as much as possible from the input stream, return the current
  51487. * block state.
  51488. * This function does not perform lazy evaluation of matches and inserts
  51489. * new strings in the dictionary only for unmatched strings or for short
  51490. * matches. It is used only for the fast compression options.
  51491. */
  51492. function deflate_fast(s, flush) {
  51493. var hash_head;
  51494. /* head of the hash chain */
  51495. var bflush;
  51496. /* set if current block must be flushed */
  51497. for (;;) {
  51498. /* Make sure that we always have enough lookahead, except
  51499. * at the end of the input file. We need MAX_MATCH bytes
  51500. * for the next match, plus MIN_MATCH bytes to insert the
  51501. * string following the next match.
  51502. */
  51503. if (s.lookahead < MIN_LOOKAHEAD) {
  51504. fill_window(s);
  51505. if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {
  51506. return BS_NEED_MORE;
  51507. }
  51508. if (s.lookahead === 0) {
  51509. break;
  51510. /* flush the current block */
  51511. }
  51512. }
  51513. /* Insert the string window[strstart .. strstart+2] in the
  51514. * dictionary, and set hash_head to the head of the hash chain:
  51515. */
  51516. hash_head = 0
  51517. /*NIL*/
  51518. ;
  51519. if (s.lookahead >= MIN_MATCH) {
  51520. /*** INSERT_STRING(s, s.strstart, hash_head); ***/
  51521. s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
  51522. hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
  51523. s.head[s.ins_h] = s.strstart;
  51524. /***/
  51525. }
  51526. /* Find the longest match, discarding those <= prev_length.
  51527. * At this point we have always match_length < MIN_MATCH
  51528. */
  51529. if (hash_head !== 0
  51530. /*NIL*/
  51531. && s.strstart - hash_head <= s.w_size - MIN_LOOKAHEAD) {
  51532. /* To simplify the code, we prevent matches with the string
  51533. * of window index 0 (in particular we have to avoid a match
  51534. * of the string with itself at the start of the input file).
  51535. */
  51536. s.match_length = longest_match(s, hash_head);
  51537. /* longest_match() sets match_start */
  51538. }
  51539. if (s.match_length >= MIN_MATCH) {
  51540. // check_match(s, s.strstart, s.match_start, s.match_length); // for debug only
  51541. /*** _tr_tally_dist(s, s.strstart - s.match_start,
  51542. s.match_length - MIN_MATCH, bflush); ***/
  51543. bflush = trees._tr_tally(s, s.strstart - s.match_start, s.match_length - MIN_MATCH);
  51544. s.lookahead -= s.match_length;
  51545. /* Insert new strings in the hash table only if the match length
  51546. * is not too large. This saves time but degrades compression.
  51547. */
  51548. if (s.match_length <= s.max_lazy_match
  51549. /*max_insert_length*/
  51550. && s.lookahead >= MIN_MATCH) {
  51551. s.match_length--;
  51552. /* string at strstart already in table */
  51553. do {
  51554. s.strstart++;
  51555. /*** INSERT_STRING(s, s.strstart, hash_head); ***/
  51556. s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
  51557. hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
  51558. s.head[s.ins_h] = s.strstart;
  51559. /***/
  51560. /* strstart never exceeds WSIZE-MAX_MATCH, so there are
  51561. * always MIN_MATCH bytes ahead.
  51562. */
  51563. } while (--s.match_length !== 0);
  51564. s.strstart++;
  51565. } else {
  51566. s.strstart += s.match_length;
  51567. s.match_length = 0;
  51568. s.ins_h = s.window[s.strstart];
  51569. /* UPDATE_HASH(s, s.ins_h, s.window[s.strstart+1]); */
  51570. s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + 1]) & s.hash_mask; //#if MIN_MATCH != 3
  51571. // Call UPDATE_HASH() MIN_MATCH-3 more times
  51572. //#endif
  51573. /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
  51574. * matter since it will be recomputed at next deflate call.
  51575. */
  51576. }
  51577. } else {
  51578. /* No match, output a literal byte */
  51579. //Tracevv((stderr,"%c", s.window[s.strstart]));
  51580. /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
  51581. bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
  51582. s.lookahead--;
  51583. s.strstart++;
  51584. }
  51585. if (bflush) {
  51586. /*** FLUSH_BLOCK(s, 0); ***/
  51587. flush_block_only(s, false);
  51588. if (s.strm.avail_out === 0) {
  51589. return BS_NEED_MORE;
  51590. }
  51591. /***/
  51592. }
  51593. }
  51594. s.insert = s.strstart < MIN_MATCH - 1 ? s.strstart : MIN_MATCH - 1;
  51595. if (flush === Z_FINISH) {
  51596. /*** FLUSH_BLOCK(s, 1); ***/
  51597. flush_block_only(s, true);
  51598. if (s.strm.avail_out === 0) {
  51599. return BS_FINISH_STARTED;
  51600. }
  51601. /***/
  51602. return BS_FINISH_DONE;
  51603. }
  51604. if (s.last_lit) {
  51605. /*** FLUSH_BLOCK(s, 0); ***/
  51606. flush_block_only(s, false);
  51607. if (s.strm.avail_out === 0) {
  51608. return BS_NEED_MORE;
  51609. }
  51610. /***/
  51611. }
  51612. return BS_BLOCK_DONE;
  51613. }
  51614. /* ===========================================================================
  51615. * Same as above, but achieves better compression. We use a lazy
  51616. * evaluation for matches: a match is finally adopted only if there is
  51617. * no better match at the next window position.
  51618. */
  51619. function deflate_slow(s, flush) {
  51620. var hash_head;
  51621. /* head of hash chain */
  51622. var bflush;
  51623. /* set if current block must be flushed */
  51624. var max_insert;
  51625. /* Process the input block. */
  51626. for (;;) {
  51627. /* Make sure that we always have enough lookahead, except
  51628. * at the end of the input file. We need MAX_MATCH bytes
  51629. * for the next match, plus MIN_MATCH bytes to insert the
  51630. * string following the next match.
  51631. */
  51632. if (s.lookahead < MIN_LOOKAHEAD) {
  51633. fill_window(s);
  51634. if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {
  51635. return BS_NEED_MORE;
  51636. }
  51637. if (s.lookahead === 0) {
  51638. break;
  51639. }
  51640. /* flush the current block */
  51641. }
  51642. /* Insert the string window[strstart .. strstart+2] in the
  51643. * dictionary, and set hash_head to the head of the hash chain:
  51644. */
  51645. hash_head = 0
  51646. /*NIL*/
  51647. ;
  51648. if (s.lookahead >= MIN_MATCH) {
  51649. /*** INSERT_STRING(s, s.strstart, hash_head); ***/
  51650. s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
  51651. hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
  51652. s.head[s.ins_h] = s.strstart;
  51653. /***/
  51654. }
  51655. /* Find the longest match, discarding those <= prev_length.
  51656. */
  51657. s.prev_length = s.match_length;
  51658. s.prev_match = s.match_start;
  51659. s.match_length = MIN_MATCH - 1;
  51660. if (hash_head !== 0
  51661. /*NIL*/
  51662. && s.prev_length < s.max_lazy_match && s.strstart - hash_head <= s.w_size - MIN_LOOKAHEAD
  51663. /*MAX_DIST(s)*/
  51664. ) {
  51665. /* To simplify the code, we prevent matches with the string
  51666. * of window index 0 (in particular we have to avoid a match
  51667. * of the string with itself at the start of the input file).
  51668. */
  51669. s.match_length = longest_match(s, hash_head);
  51670. /* longest_match() sets match_start */
  51671. if (s.match_length <= 5 && (s.strategy === Z_FILTERED || s.match_length === MIN_MATCH && s.strstart - s.match_start > 4096
  51672. /*TOO_FAR*/
  51673. )) {
  51674. /* If prev_match is also MIN_MATCH, match_start is garbage
  51675. * but we will ignore the current match anyway.
  51676. */
  51677. s.match_length = MIN_MATCH - 1;
  51678. }
  51679. }
  51680. /* If there was a match at the previous step and the current
  51681. * match is not better, output the previous match:
  51682. */
  51683. if (s.prev_length >= MIN_MATCH && s.match_length <= s.prev_length) {
  51684. max_insert = s.strstart + s.lookahead - MIN_MATCH;
  51685. /* Do not insert strings in hash table beyond this. */
  51686. //check_match(s, s.strstart-1, s.prev_match, s.prev_length);
  51687. /***_tr_tally_dist(s, s.strstart - 1 - s.prev_match,
  51688. s.prev_length - MIN_MATCH, bflush);***/
  51689. bflush = trees._tr_tally(s, s.strstart - 1 - s.prev_match, s.prev_length - MIN_MATCH);
  51690. /* Insert in hash table all strings up to the end of the match.
  51691. * strstart-1 and strstart are already inserted. If there is not
  51692. * enough lookahead, the last two strings are not inserted in
  51693. * the hash table.
  51694. */
  51695. s.lookahead -= s.prev_length - 1;
  51696. s.prev_length -= 2;
  51697. do {
  51698. if (++s.strstart <= max_insert) {
  51699. /*** INSERT_STRING(s, s.strstart, hash_head); ***/
  51700. s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
  51701. hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
  51702. s.head[s.ins_h] = s.strstart;
  51703. /***/
  51704. }
  51705. } while (--s.prev_length !== 0);
  51706. s.match_available = 0;
  51707. s.match_length = MIN_MATCH - 1;
  51708. s.strstart++;
  51709. if (bflush) {
  51710. /*** FLUSH_BLOCK(s, 0); ***/
  51711. flush_block_only(s, false);
  51712. if (s.strm.avail_out === 0) {
  51713. return BS_NEED_MORE;
  51714. }
  51715. /***/
  51716. }
  51717. } else if (s.match_available) {
  51718. /* If there was no match at the previous position, output a
  51719. * single literal. If there was a match but the current match
  51720. * is longer, truncate the previous match to a single literal.
  51721. */
  51722. //Tracevv((stderr,"%c", s->window[s->strstart-1]));
  51723. /*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/
  51724. bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]);
  51725. if (bflush) {
  51726. /*** FLUSH_BLOCK_ONLY(s, 0) ***/
  51727. flush_block_only(s, false);
  51728. /***/
  51729. }
  51730. s.strstart++;
  51731. s.lookahead--;
  51732. if (s.strm.avail_out === 0) {
  51733. return BS_NEED_MORE;
  51734. }
  51735. } else {
  51736. /* There is no previous match to compare with, wait for
  51737. * the next step to decide.
  51738. */
  51739. s.match_available = 1;
  51740. s.strstart++;
  51741. s.lookahead--;
  51742. }
  51743. } //Assert (flush != Z_NO_FLUSH, "no flush?");
  51744. if (s.match_available) {
  51745. //Tracevv((stderr,"%c", s->window[s->strstart-1]));
  51746. /*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/
  51747. bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]);
  51748. s.match_available = 0;
  51749. }
  51750. s.insert = s.strstart < MIN_MATCH - 1 ? s.strstart : MIN_MATCH - 1;
  51751. if (flush === Z_FINISH) {
  51752. /*** FLUSH_BLOCK(s, 1); ***/
  51753. flush_block_only(s, true);
  51754. if (s.strm.avail_out === 0) {
  51755. return BS_FINISH_STARTED;
  51756. }
  51757. /***/
  51758. return BS_FINISH_DONE;
  51759. }
  51760. if (s.last_lit) {
  51761. /*** FLUSH_BLOCK(s, 0); ***/
  51762. flush_block_only(s, false);
  51763. if (s.strm.avail_out === 0) {
  51764. return BS_NEED_MORE;
  51765. }
  51766. /***/
  51767. }
  51768. return BS_BLOCK_DONE;
  51769. }
  51770. /* ===========================================================================
  51771. * For Z_RLE, simply look for runs of bytes, generate matches only of distance
  51772. * one. Do not maintain a hash table. (It will be regenerated if this run of
  51773. * deflate switches away from Z_RLE.)
  51774. */
  51775. function deflate_rle(s, flush) {
  51776. var bflush;
  51777. /* set if current block must be flushed */
  51778. var prev;
  51779. /* byte at distance one to match */
  51780. var scan, strend;
  51781. /* scan goes up to strend for length of run */
  51782. var _win = s.window;
  51783. for (;;) {
  51784. /* Make sure that we always have enough lookahead, except
  51785. * at the end of the input file. We need MAX_MATCH bytes
  51786. * for the longest run, plus one for the unrolled loop.
  51787. */
  51788. if (s.lookahead <= MAX_MATCH) {
  51789. fill_window(s);
  51790. if (s.lookahead <= MAX_MATCH && flush === Z_NO_FLUSH) {
  51791. return BS_NEED_MORE;
  51792. }
  51793. if (s.lookahead === 0) {
  51794. break;
  51795. }
  51796. /* flush the current block */
  51797. }
  51798. /* See how many times the previous byte repeats */
  51799. s.match_length = 0;
  51800. if (s.lookahead >= MIN_MATCH && s.strstart > 0) {
  51801. scan = s.strstart - 1;
  51802. prev = _win[scan];
  51803. if (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan]) {
  51804. strend = s.strstart + MAX_MATCH;
  51805. do {
  51806. /*jshint noempty:false*/
  51807. } while (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && scan < strend);
  51808. s.match_length = MAX_MATCH - (strend - scan);
  51809. if (s.match_length > s.lookahead) {
  51810. s.match_length = s.lookahead;
  51811. }
  51812. } //Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
  51813. }
  51814. /* Emit match if have run of MIN_MATCH or longer, else emit literal */
  51815. if (s.match_length >= MIN_MATCH) {
  51816. //check_match(s, s.strstart, s.strstart - 1, s.match_length);
  51817. /*** _tr_tally_dist(s, 1, s.match_length - MIN_MATCH, bflush); ***/
  51818. bflush = trees._tr_tally(s, 1, s.match_length - MIN_MATCH);
  51819. s.lookahead -= s.match_length;
  51820. s.strstart += s.match_length;
  51821. s.match_length = 0;
  51822. } else {
  51823. /* No match, output a literal byte */
  51824. //Tracevv((stderr,"%c", s->window[s->strstart]));
  51825. /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
  51826. bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
  51827. s.lookahead--;
  51828. s.strstart++;
  51829. }
  51830. if (bflush) {
  51831. /*** FLUSH_BLOCK(s, 0); ***/
  51832. flush_block_only(s, false);
  51833. if (s.strm.avail_out === 0) {
  51834. return BS_NEED_MORE;
  51835. }
  51836. /***/
  51837. }
  51838. }
  51839. s.insert = 0;
  51840. if (flush === Z_FINISH) {
  51841. /*** FLUSH_BLOCK(s, 1); ***/
  51842. flush_block_only(s, true);
  51843. if (s.strm.avail_out === 0) {
  51844. return BS_FINISH_STARTED;
  51845. }
  51846. /***/
  51847. return BS_FINISH_DONE;
  51848. }
  51849. if (s.last_lit) {
  51850. /*** FLUSH_BLOCK(s, 0); ***/
  51851. flush_block_only(s, false);
  51852. if (s.strm.avail_out === 0) {
  51853. return BS_NEED_MORE;
  51854. }
  51855. /***/
  51856. }
  51857. return BS_BLOCK_DONE;
  51858. }
  51859. /* ===========================================================================
  51860. * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table.
  51861. * (It will be regenerated if this run of deflate switches away from Huffman.)
  51862. */
  51863. function deflate_huff(s, flush) {
  51864. var bflush;
  51865. /* set if current block must be flushed */
  51866. for (;;) {
  51867. /* Make sure that we have a literal to write. */
  51868. if (s.lookahead === 0) {
  51869. fill_window(s);
  51870. if (s.lookahead === 0) {
  51871. if (flush === Z_NO_FLUSH) {
  51872. return BS_NEED_MORE;
  51873. }
  51874. break;
  51875. /* flush the current block */
  51876. }
  51877. }
  51878. /* Output a literal byte */
  51879. s.match_length = 0; //Tracevv((stderr,"%c", s->window[s->strstart]));
  51880. /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
  51881. bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
  51882. s.lookahead--;
  51883. s.strstart++;
  51884. if (bflush) {
  51885. /*** FLUSH_BLOCK(s, 0); ***/
  51886. flush_block_only(s, false);
  51887. if (s.strm.avail_out === 0) {
  51888. return BS_NEED_MORE;
  51889. }
  51890. /***/
  51891. }
  51892. }
  51893. s.insert = 0;
  51894. if (flush === Z_FINISH) {
  51895. /*** FLUSH_BLOCK(s, 1); ***/
  51896. flush_block_only(s, true);
  51897. if (s.strm.avail_out === 0) {
  51898. return BS_FINISH_STARTED;
  51899. }
  51900. /***/
  51901. return BS_FINISH_DONE;
  51902. }
  51903. if (s.last_lit) {
  51904. /*** FLUSH_BLOCK(s, 0); ***/
  51905. flush_block_only(s, false);
  51906. if (s.strm.avail_out === 0) {
  51907. return BS_NEED_MORE;
  51908. }
  51909. /***/
  51910. }
  51911. return BS_BLOCK_DONE;
  51912. }
  51913. /* Values for max_lazy_match, good_match and max_chain_length, depending on
  51914. * the desired pack level (0..9). The values given below have been tuned to
  51915. * exclude worst case performance for pathological files. Better values may be
  51916. * found for specific files.
  51917. */
  51918. function Config(good_length, max_lazy, nice_length, max_chain, func) {
  51919. this.good_length = good_length;
  51920. this.max_lazy = max_lazy;
  51921. this.nice_length = nice_length;
  51922. this.max_chain = max_chain;
  51923. this.func = func;
  51924. }
  51925. var configuration_table;
  51926. configuration_table = [
  51927. /* good lazy nice chain */
  51928. new Config(0, 0, 0, 0, deflate_stored),
  51929. /* 0 store only */
  51930. new Config(4, 4, 8, 4, deflate_fast),
  51931. /* 1 max speed, no lazy matches */
  51932. new Config(4, 5, 16, 8, deflate_fast),
  51933. /* 2 */
  51934. new Config(4, 6, 32, 32, deflate_fast),
  51935. /* 3 */
  51936. new Config(4, 4, 16, 16, deflate_slow),
  51937. /* 4 lazy matches */
  51938. new Config(8, 16, 32, 32, deflate_slow),
  51939. /* 5 */
  51940. new Config(8, 16, 128, 128, deflate_slow),
  51941. /* 6 */
  51942. new Config(8, 32, 128, 256, deflate_slow),
  51943. /* 7 */
  51944. new Config(32, 128, 258, 1024, deflate_slow),
  51945. /* 8 */
  51946. new Config(32, 258, 258, 4096, deflate_slow)
  51947. /* 9 max compression */
  51948. ];
  51949. /* ===========================================================================
  51950. * Initialize the "longest match" routines for a new zlib stream
  51951. */
  51952. function lm_init(s) {
  51953. s.window_size = 2 * s.w_size;
  51954. /*** CLEAR_HASH(s); ***/
  51955. zero(s.head); // Fill with NIL (= 0);
  51956. /* Set the default configuration parameters:
  51957. */
  51958. s.max_lazy_match = configuration_table[s.level].max_lazy;
  51959. s.good_match = configuration_table[s.level].good_length;
  51960. s.nice_match = configuration_table[s.level].nice_length;
  51961. s.max_chain_length = configuration_table[s.level].max_chain;
  51962. s.strstart = 0;
  51963. s.block_start = 0;
  51964. s.lookahead = 0;
  51965. s.insert = 0;
  51966. s.match_length = s.prev_length = MIN_MATCH - 1;
  51967. s.match_available = 0;
  51968. s.ins_h = 0;
  51969. }
  51970. function DeflateState() {
  51971. this.strm = null;
  51972. /* pointer back to this zlib stream */
  51973. this.status = 0;
  51974. /* as the name implies */
  51975. this.pending_buf = null;
  51976. /* output still pending */
  51977. this.pending_buf_size = 0;
  51978. /* size of pending_buf */
  51979. this.pending_out = 0;
  51980. /* next pending byte to output to the stream */
  51981. this.pending = 0;
  51982. /* nb of bytes in the pending buffer */
  51983. this.wrap = 0;
  51984. /* bit 0 true for zlib, bit 1 true for gzip */
  51985. this.gzhead = null;
  51986. /* gzip header information to write */
  51987. this.gzindex = 0;
  51988. /* where in extra, name, or comment */
  51989. this.method = Z_DEFLATED;
  51990. /* can only be DEFLATED */
  51991. this.last_flush = -1;
  51992. /* value of flush param for previous deflate call */
  51993. this.w_size = 0;
  51994. /* LZ77 window size (32K by default) */
  51995. this.w_bits = 0;
  51996. /* log2(w_size) (8..16) */
  51997. this.w_mask = 0;
  51998. /* w_size - 1 */
  51999. this.window = null;
  52000. /* Sliding window. Input bytes are read into the second half of the window,
  52001. * and move to the first half later to keep a dictionary of at least wSize
  52002. * bytes. With this organization, matches are limited to a distance of
  52003. * wSize-MAX_MATCH bytes, but this ensures that IO is always
  52004. * performed with a length multiple of the block size.
  52005. */
  52006. this.window_size = 0;
  52007. /* Actual size of window: 2*wSize, except when the user input buffer
  52008. * is directly used as sliding window.
  52009. */
  52010. this.prev = null;
  52011. /* Link to older string with same hash index. To limit the size of this
  52012. * array to 64K, this link is maintained only for the last 32K strings.
  52013. * An index in this array is thus a window index modulo 32K.
  52014. */
  52015. this.head = null;
  52016. /* Heads of the hash chains or NIL. */
  52017. this.ins_h = 0;
  52018. /* hash index of string to be inserted */
  52019. this.hash_size = 0;
  52020. /* number of elements in hash table */
  52021. this.hash_bits = 0;
  52022. /* log2(hash_size) */
  52023. this.hash_mask = 0;
  52024. /* hash_size-1 */
  52025. this.hash_shift = 0;
  52026. /* Number of bits by which ins_h must be shifted at each input
  52027. * step. It must be such that after MIN_MATCH steps, the oldest
  52028. * byte no longer takes part in the hash key, that is:
  52029. * hash_shift * MIN_MATCH >= hash_bits
  52030. */
  52031. this.block_start = 0;
  52032. /* Window position at the beginning of the current output block. Gets
  52033. * negative when the window is moved backwards.
  52034. */
  52035. this.match_length = 0;
  52036. /* length of best match */
  52037. this.prev_match = 0;
  52038. /* previous match */
  52039. this.match_available = 0;
  52040. /* set if previous match exists */
  52041. this.strstart = 0;
  52042. /* start of string to insert */
  52043. this.match_start = 0;
  52044. /* start of matching string */
  52045. this.lookahead = 0;
  52046. /* number of valid bytes ahead in window */
  52047. this.prev_length = 0;
  52048. /* Length of the best match at previous step. Matches not greater than this
  52049. * are discarded. This is used in the lazy match evaluation.
  52050. */
  52051. this.max_chain_length = 0;
  52052. /* To speed up deflation, hash chains are never searched beyond this
  52053. * length. A higher limit improves compression ratio but degrades the
  52054. * speed.
  52055. */
  52056. this.max_lazy_match = 0;
  52057. /* Attempt to find a better match only when the current match is strictly
  52058. * smaller than this value. This mechanism is used only for compression
  52059. * levels >= 4.
  52060. */
  52061. // That's alias to max_lazy_match, don't use directly
  52062. //this.max_insert_length = 0;
  52063. /* Insert new strings in the hash table only if the match length is not
  52064. * greater than this length. This saves time but degrades compression.
  52065. * max_insert_length is used only for compression levels <= 3.
  52066. */
  52067. this.level = 0;
  52068. /* compression level (1..9) */
  52069. this.strategy = 0;
  52070. /* favor or force Huffman coding*/
  52071. this.good_match = 0;
  52072. /* Use a faster search when the previous match is longer than this */
  52073. this.nice_match = 0;
  52074. /* Stop searching when current match exceeds this */
  52075. /* used by trees.c: */
  52076. /* Didn't use ct_data typedef below to suppress compiler warning */
  52077. // struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  52078. // struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  52079. // struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  52080. // Use flat array of DOUBLE size, with interleaved fata,
  52081. // because JS does not support effective
  52082. this.dyn_ltree = new utils.Buf16(HEAP_SIZE * 2);
  52083. this.dyn_dtree = new utils.Buf16((2 * D_CODES + 1) * 2);
  52084. this.bl_tree = new utils.Buf16((2 * BL_CODES + 1) * 2);
  52085. zero(this.dyn_ltree);
  52086. zero(this.dyn_dtree);
  52087. zero(this.bl_tree);
  52088. this.l_desc = null;
  52089. /* desc. for literal tree */
  52090. this.d_desc = null;
  52091. /* desc. for distance tree */
  52092. this.bl_desc = null;
  52093. /* desc. for bit length tree */
  52094. //ush bl_count[MAX_BITS+1];
  52095. this.bl_count = new utils.Buf16(MAX_BITS + 1);
  52096. /* number of codes at each bit length for an optimal tree */
  52097. //int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  52098. this.heap = new utils.Buf16(2 * L_CODES + 1);
  52099. /* heap used to build the Huffman trees */
  52100. zero(this.heap);
  52101. this.heap_len = 0;
  52102. /* number of elements in the heap */
  52103. this.heap_max = 0;
  52104. /* element of largest frequency */
  52105. /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
  52106. * The same heap array is used to build all trees.
  52107. */
  52108. this.depth = new utils.Buf16(2 * L_CODES + 1); //uch depth[2*L_CODES+1];
  52109. zero(this.depth);
  52110. /* Depth of each subtree used as tie breaker for trees of equal frequency
  52111. */
  52112. this.l_buf = 0;
  52113. /* buffer index for literals or lengths */
  52114. this.lit_bufsize = 0;
  52115. /* Size of match buffer for literals/lengths. There are 4 reasons for
  52116. * limiting lit_bufsize to 64K:
  52117. * - frequencies can be kept in 16 bit counters
  52118. * - if compression is not successful for the first block, all input
  52119. * data is still in the window so we can still emit a stored block even
  52120. * when input comes from standard input. (This can also be done for
  52121. * all blocks if lit_bufsize is not greater than 32K.)
  52122. * - if compression is not successful for a file smaller than 64K, we can
  52123. * even emit a stored file instead of a stored block (saving 5 bytes).
  52124. * This is applicable only for zip (not gzip or zlib).
  52125. * - creating new Huffman trees less frequently may not provide fast
  52126. * adaptation to changes in the input data statistics. (Take for
  52127. * example a binary file with poorly compressible code followed by
  52128. * a highly compressible string table.) Smaller buffer sizes give
  52129. * fast adaptation but have of course the overhead of transmitting
  52130. * trees more frequently.
  52131. * - I can't count above 4
  52132. */
  52133. this.last_lit = 0;
  52134. /* running index in l_buf */
  52135. this.d_buf = 0;
  52136. /* Buffer index for distances. To simplify the code, d_buf and l_buf have
  52137. * the same number of elements. To use different lengths, an extra flag
  52138. * array would be necessary.
  52139. */
  52140. this.opt_len = 0;
  52141. /* bit length of current block with optimal trees */
  52142. this.static_len = 0;
  52143. /* bit length of current block with static trees */
  52144. this.matches = 0;
  52145. /* number of string matches in current block */
  52146. this.insert = 0;
  52147. /* bytes at end of window left to insert */
  52148. this.bi_buf = 0;
  52149. /* Output buffer. bits are inserted starting at the bottom (least
  52150. * significant bits).
  52151. */
  52152. this.bi_valid = 0;
  52153. /* Number of valid bits in bi_buf. All bits above the last valid bit
  52154. * are always zero.
  52155. */
  52156. // Used for window memory init. We safely ignore it for JS. That makes
  52157. // sense only for pointers and memory check tools.
  52158. //this.high_water = 0;
  52159. /* High water mark offset in window for initialized bytes -- bytes above
  52160. * this are set to zero in order to avoid memory check warnings when
  52161. * longest match routines access bytes past the input. This is then
  52162. * updated to the new high water mark.
  52163. */
  52164. }
  52165. function deflateResetKeep(strm) {
  52166. var s;
  52167. if (!strm || !strm.state) {
  52168. return err(strm, Z_STREAM_ERROR);
  52169. }
  52170. strm.total_in = strm.total_out = 0;
  52171. strm.data_type = Z_UNKNOWN;
  52172. s = strm.state;
  52173. s.pending = 0;
  52174. s.pending_out = 0;
  52175. if (s.wrap < 0) {
  52176. s.wrap = -s.wrap;
  52177. /* was made negative by deflate(..., Z_FINISH); */
  52178. }
  52179. s.status = s.wrap ? INIT_STATE : BUSY_STATE;
  52180. strm.adler = s.wrap === 2 ? 0 // crc32(0, Z_NULL, 0)
  52181. : 1; // adler32(0, Z_NULL, 0)
  52182. s.last_flush = Z_NO_FLUSH;
  52183. trees._tr_init(s);
  52184. return Z_OK;
  52185. }
  52186. function deflateReset(strm) {
  52187. var ret = deflateResetKeep(strm);
  52188. if (ret === Z_OK) {
  52189. lm_init(strm.state);
  52190. }
  52191. return ret;
  52192. }
  52193. function deflateSetHeader(strm, head) {
  52194. if (!strm || !strm.state) {
  52195. return Z_STREAM_ERROR;
  52196. }
  52197. if (strm.state.wrap !== 2) {
  52198. return Z_STREAM_ERROR;
  52199. }
  52200. strm.state.gzhead = head;
  52201. return Z_OK;
  52202. }
  52203. function deflateInit2(strm, level, method, windowBits, memLevel, strategy) {
  52204. if (!strm) {
  52205. // === Z_NULL
  52206. return Z_STREAM_ERROR;
  52207. }
  52208. var wrap = 1;
  52209. if (level === Z_DEFAULT_COMPRESSION) {
  52210. level = 6;
  52211. }
  52212. if (windowBits < 0) {
  52213. /* suppress zlib wrapper */
  52214. wrap = 0;
  52215. windowBits = -windowBits;
  52216. } else if (windowBits > 15) {
  52217. wrap = 2;
  52218. /* write gzip wrapper instead */
  52219. windowBits -= 16;
  52220. }
  52221. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method !== Z_DEFLATED || windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
  52222. return err(strm, Z_STREAM_ERROR);
  52223. }
  52224. if (windowBits === 8) {
  52225. windowBits = 9;
  52226. }
  52227. /* until 256-byte window bug fixed */
  52228. var s = new DeflateState();
  52229. strm.state = s;
  52230. s.strm = strm;
  52231. s.wrap = wrap;
  52232. s.gzhead = null;
  52233. s.w_bits = windowBits;
  52234. s.w_size = 1 << s.w_bits;
  52235. s.w_mask = s.w_size - 1;
  52236. s.hash_bits = memLevel + 7;
  52237. s.hash_size = 1 << s.hash_bits;
  52238. s.hash_mask = s.hash_size - 1;
  52239. s.hash_shift = ~~((s.hash_bits + MIN_MATCH - 1) / MIN_MATCH);
  52240. s.window = new utils.Buf8(s.w_size * 2);
  52241. s.head = new utils.Buf16(s.hash_size);
  52242. s.prev = new utils.Buf16(s.w_size); // Don't need mem init magic for JS.
  52243. //s.high_water = 0; /* nothing written to s->window yet */
  52244. s.lit_bufsize = 1 << memLevel + 6;
  52245. /* 16K elements by default */
  52246. s.pending_buf_size = s.lit_bufsize * 4; //overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  52247. //s->pending_buf = (uchf *) overlay;
  52248. s.pending_buf = new utils.Buf8(s.pending_buf_size); // It is offset from `s.pending_buf` (size is `s.lit_bufsize * 2`)
  52249. //s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  52250. s.d_buf = 1 * s.lit_bufsize; //s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  52251. s.l_buf = (1 + 2) * s.lit_bufsize;
  52252. s.level = level;
  52253. s.strategy = strategy;
  52254. s.method = method;
  52255. return deflateReset(strm);
  52256. }
  52257. function deflateInit(strm, level) {
  52258. return deflateInit2(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY);
  52259. }
  52260. function deflate(strm, flush) {
  52261. var old_flush, s;
  52262. var beg, val; // for gzip header write only
  52263. if (!strm || !strm.state || flush > Z_BLOCK || flush < 0) {
  52264. return strm ? err(strm, Z_STREAM_ERROR) : Z_STREAM_ERROR;
  52265. }
  52266. s = strm.state;
  52267. if (!strm.output || !strm.input && strm.avail_in !== 0 || s.status === FINISH_STATE && flush !== Z_FINISH) {
  52268. return err(strm, strm.avail_out === 0 ? Z_BUF_ERROR : Z_STREAM_ERROR);
  52269. }
  52270. s.strm = strm;
  52271. /* just in case */
  52272. old_flush = s.last_flush;
  52273. s.last_flush = flush;
  52274. /* Write the header */
  52275. if (s.status === INIT_STATE) {
  52276. if (s.wrap === 2) {
  52277. // GZIP header
  52278. strm.adler = 0; //crc32(0L, Z_NULL, 0);
  52279. put_byte(s, 31);
  52280. put_byte(s, 139);
  52281. put_byte(s, 8);
  52282. if (!s.gzhead) {
  52283. // s->gzhead == Z_NULL
  52284. put_byte(s, 0);
  52285. put_byte(s, 0);
  52286. put_byte(s, 0);
  52287. put_byte(s, 0);
  52288. put_byte(s, 0);
  52289. put_byte(s, s.level === 9 ? 2 : s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ? 4 : 0);
  52290. put_byte(s, OS_CODE);
  52291. s.status = BUSY_STATE;
  52292. } else {
  52293. put_byte(s, (s.gzhead.text ? 1 : 0) + (s.gzhead.hcrc ? 2 : 0) + (!s.gzhead.extra ? 0 : 4) + (!s.gzhead.name ? 0 : 8) + (!s.gzhead.comment ? 0 : 16));
  52294. put_byte(s, s.gzhead.time & 0xff);
  52295. put_byte(s, s.gzhead.time >> 8 & 0xff);
  52296. put_byte(s, s.gzhead.time >> 16 & 0xff);
  52297. put_byte(s, s.gzhead.time >> 24 & 0xff);
  52298. put_byte(s, s.level === 9 ? 2 : s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ? 4 : 0);
  52299. put_byte(s, s.gzhead.os & 0xff);
  52300. if (s.gzhead.extra && s.gzhead.extra.length) {
  52301. put_byte(s, s.gzhead.extra.length & 0xff);
  52302. put_byte(s, s.gzhead.extra.length >> 8 & 0xff);
  52303. }
  52304. if (s.gzhead.hcrc) {
  52305. strm.adler = crc32(strm.adler, s.pending_buf, s.pending, 0);
  52306. }
  52307. s.gzindex = 0;
  52308. s.status = EXTRA_STATE;
  52309. }
  52310. } else // DEFLATE header
  52311. {
  52312. var header = Z_DEFLATED + (s.w_bits - 8 << 4) << 8;
  52313. var level_flags = -1;
  52314. if (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2) {
  52315. level_flags = 0;
  52316. } else if (s.level < 6) {
  52317. level_flags = 1;
  52318. } else if (s.level === 6) {
  52319. level_flags = 2;
  52320. } else {
  52321. level_flags = 3;
  52322. }
  52323. header |= level_flags << 6;
  52324. if (s.strstart !== 0) {
  52325. header |= PRESET_DICT;
  52326. }
  52327. header += 31 - header % 31;
  52328. s.status = BUSY_STATE;
  52329. putShortMSB(s, header);
  52330. /* Save the adler32 of the preset dictionary: */
  52331. if (s.strstart !== 0) {
  52332. putShortMSB(s, strm.adler >>> 16);
  52333. putShortMSB(s, strm.adler & 0xffff);
  52334. }
  52335. strm.adler = 1; // adler32(0L, Z_NULL, 0);
  52336. }
  52337. } //#ifdef GZIP
  52338. if (s.status === EXTRA_STATE) {
  52339. if (s.gzhead.extra
  52340. /* != Z_NULL*/
  52341. ) {
  52342. beg = s.pending;
  52343. /* start of bytes to update crc */
  52344. while (s.gzindex < (s.gzhead.extra.length & 0xffff)) {
  52345. if (s.pending === s.pending_buf_size) {
  52346. if (s.gzhead.hcrc && s.pending > beg) {
  52347. strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  52348. }
  52349. flush_pending(strm);
  52350. beg = s.pending;
  52351. if (s.pending === s.pending_buf_size) {
  52352. break;
  52353. }
  52354. }
  52355. put_byte(s, s.gzhead.extra[s.gzindex] & 0xff);
  52356. s.gzindex++;
  52357. }
  52358. if (s.gzhead.hcrc && s.pending > beg) {
  52359. strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  52360. }
  52361. if (s.gzindex === s.gzhead.extra.length) {
  52362. s.gzindex = 0;
  52363. s.status = NAME_STATE;
  52364. }
  52365. } else {
  52366. s.status = NAME_STATE;
  52367. }
  52368. }
  52369. if (s.status === NAME_STATE) {
  52370. if (s.gzhead.name
  52371. /* != Z_NULL*/
  52372. ) {
  52373. beg = s.pending;
  52374. /* start of bytes to update crc */
  52375. //int val;
  52376. do {
  52377. if (s.pending === s.pending_buf_size) {
  52378. if (s.gzhead.hcrc && s.pending > beg) {
  52379. strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  52380. }
  52381. flush_pending(strm);
  52382. beg = s.pending;
  52383. if (s.pending === s.pending_buf_size) {
  52384. val = 1;
  52385. break;
  52386. }
  52387. } // JS specific: little magic to add zero terminator to end of string
  52388. if (s.gzindex < s.gzhead.name.length) {
  52389. val = s.gzhead.name.charCodeAt(s.gzindex++) & 0xff;
  52390. } else {
  52391. val = 0;
  52392. }
  52393. put_byte(s, val);
  52394. } while (val !== 0);
  52395. if (s.gzhead.hcrc && s.pending > beg) {
  52396. strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  52397. }
  52398. if (val === 0) {
  52399. s.gzindex = 0;
  52400. s.status = COMMENT_STATE;
  52401. }
  52402. } else {
  52403. s.status = COMMENT_STATE;
  52404. }
  52405. }
  52406. if (s.status === COMMENT_STATE) {
  52407. if (s.gzhead.comment
  52408. /* != Z_NULL*/
  52409. ) {
  52410. beg = s.pending;
  52411. /* start of bytes to update crc */
  52412. //int val;
  52413. do {
  52414. if (s.pending === s.pending_buf_size) {
  52415. if (s.gzhead.hcrc && s.pending > beg) {
  52416. strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  52417. }
  52418. flush_pending(strm);
  52419. beg = s.pending;
  52420. if (s.pending === s.pending_buf_size) {
  52421. val = 1;
  52422. break;
  52423. }
  52424. } // JS specific: little magic to add zero terminator to end of string
  52425. if (s.gzindex < s.gzhead.comment.length) {
  52426. val = s.gzhead.comment.charCodeAt(s.gzindex++) & 0xff;
  52427. } else {
  52428. val = 0;
  52429. }
  52430. put_byte(s, val);
  52431. } while (val !== 0);
  52432. if (s.gzhead.hcrc && s.pending > beg) {
  52433. strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  52434. }
  52435. if (val === 0) {
  52436. s.status = HCRC_STATE;
  52437. }
  52438. } else {
  52439. s.status = HCRC_STATE;
  52440. }
  52441. }
  52442. if (s.status === HCRC_STATE) {
  52443. if (s.gzhead.hcrc) {
  52444. if (s.pending + 2 > s.pending_buf_size) {
  52445. flush_pending(strm);
  52446. }
  52447. if (s.pending + 2 <= s.pending_buf_size) {
  52448. put_byte(s, strm.adler & 0xff);
  52449. put_byte(s, strm.adler >> 8 & 0xff);
  52450. strm.adler = 0; //crc32(0L, Z_NULL, 0);
  52451. s.status = BUSY_STATE;
  52452. }
  52453. } else {
  52454. s.status = BUSY_STATE;
  52455. }
  52456. } //#endif
  52457. /* Flush as much pending output as possible */
  52458. if (s.pending !== 0) {
  52459. flush_pending(strm);
  52460. if (strm.avail_out === 0) {
  52461. /* Since avail_out is 0, deflate will be called again with
  52462. * more output space, but possibly with both pending and
  52463. * avail_in equal to zero. There won't be anything to do,
  52464. * but this is not an error situation so make sure we
  52465. * return OK instead of BUF_ERROR at next call of deflate:
  52466. */
  52467. s.last_flush = -1;
  52468. return Z_OK;
  52469. }
  52470. /* Make sure there is something to do and avoid duplicate consecutive
  52471. * flushes. For repeated and useless calls with Z_FINISH, we keep
  52472. * returning Z_STREAM_END instead of Z_BUF_ERROR.
  52473. */
  52474. } else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) && flush !== Z_FINISH) {
  52475. return err(strm, Z_BUF_ERROR);
  52476. }
  52477. /* User must not provide more input after the first FINISH: */
  52478. if (s.status === FINISH_STATE && strm.avail_in !== 0) {
  52479. return err(strm, Z_BUF_ERROR);
  52480. }
  52481. /* Start a new block or continue the current one.
  52482. */
  52483. if (strm.avail_in !== 0 || s.lookahead !== 0 || flush !== Z_NO_FLUSH && s.status !== FINISH_STATE) {
  52484. var bstate = s.strategy === Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : s.strategy === Z_RLE ? deflate_rle(s, flush) : configuration_table[s.level].func(s, flush);
  52485. if (bstate === BS_FINISH_STARTED || bstate === BS_FINISH_DONE) {
  52486. s.status = FINISH_STATE;
  52487. }
  52488. if (bstate === BS_NEED_MORE || bstate === BS_FINISH_STARTED) {
  52489. if (strm.avail_out === 0) {
  52490. s.last_flush = -1;
  52491. /* avoid BUF_ERROR next call, see above */
  52492. }
  52493. return Z_OK;
  52494. /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
  52495. * of deflate should use the same flush parameter to make sure
  52496. * that the flush is complete. So we don't have to output an
  52497. * empty block here, this will be done at next call. This also
  52498. * ensures that for a very small output buffer, we emit at most
  52499. * one empty block.
  52500. */
  52501. }
  52502. if (bstate === BS_BLOCK_DONE) {
  52503. if (flush === Z_PARTIAL_FLUSH) {
  52504. trees._tr_align(s);
  52505. } else if (flush !== Z_BLOCK) {
  52506. /* FULL_FLUSH or SYNC_FLUSH */
  52507. trees._tr_stored_block(s, 0, 0, false);
  52508. /* For a full flush, this empty block will be recognized
  52509. * as a special marker by inflate_sync().
  52510. */
  52511. if (flush === Z_FULL_FLUSH) {
  52512. /*** CLEAR_HASH(s); ***/
  52513. /* forget history */
  52514. zero(s.head); // Fill with NIL (= 0);
  52515. if (s.lookahead === 0) {
  52516. s.strstart = 0;
  52517. s.block_start = 0;
  52518. s.insert = 0;
  52519. }
  52520. }
  52521. }
  52522. flush_pending(strm);
  52523. if (strm.avail_out === 0) {
  52524. s.last_flush = -1;
  52525. /* avoid BUF_ERROR at next call, see above */
  52526. return Z_OK;
  52527. }
  52528. }
  52529. } //Assert(strm->avail_out > 0, "bug2");
  52530. //if (strm.avail_out <= 0) { throw new Error("bug2");}
  52531. if (flush !== Z_FINISH) {
  52532. return Z_OK;
  52533. }
  52534. if (s.wrap <= 0) {
  52535. return Z_STREAM_END;
  52536. }
  52537. /* Write the trailer */
  52538. if (s.wrap === 2) {
  52539. put_byte(s, strm.adler & 0xff);
  52540. put_byte(s, strm.adler >> 8 & 0xff);
  52541. put_byte(s, strm.adler >> 16 & 0xff);
  52542. put_byte(s, strm.adler >> 24 & 0xff);
  52543. put_byte(s, strm.total_in & 0xff);
  52544. put_byte(s, strm.total_in >> 8 & 0xff);
  52545. put_byte(s, strm.total_in >> 16 & 0xff);
  52546. put_byte(s, strm.total_in >> 24 & 0xff);
  52547. } else {
  52548. putShortMSB(s, strm.adler >>> 16);
  52549. putShortMSB(s, strm.adler & 0xffff);
  52550. }
  52551. flush_pending(strm);
  52552. /* If avail_out is zero, the application will call deflate again
  52553. * to flush the rest.
  52554. */
  52555. if (s.wrap > 0) {
  52556. s.wrap = -s.wrap;
  52557. }
  52558. /* write the trailer only once! */
  52559. return s.pending !== 0 ? Z_OK : Z_STREAM_END;
  52560. }
  52561. function deflateEnd(strm) {
  52562. var status;
  52563. if (!strm
  52564. /*== Z_NULL*/
  52565. || !strm.state
  52566. /*== Z_NULL*/
  52567. ) {
  52568. return Z_STREAM_ERROR;
  52569. }
  52570. status = strm.state.status;
  52571. if (status !== INIT_STATE && status !== EXTRA_STATE && status !== NAME_STATE && status !== COMMENT_STATE && status !== HCRC_STATE && status !== BUSY_STATE && status !== FINISH_STATE) {
  52572. return err(strm, Z_STREAM_ERROR);
  52573. }
  52574. strm.state = null;
  52575. return status === BUSY_STATE ? err(strm, Z_DATA_ERROR) : Z_OK;
  52576. }
  52577. /* =========================================================================
  52578. * Initializes the compression dictionary from the given byte
  52579. * sequence without producing any compressed output.
  52580. */
  52581. function deflateSetDictionary(strm, dictionary) {
  52582. var dictLength = dictionary.length;
  52583. var s;
  52584. var str, n;
  52585. var wrap;
  52586. var avail;
  52587. var next;
  52588. var input;
  52589. var tmpDict;
  52590. if (!strm
  52591. /*== Z_NULL*/
  52592. || !strm.state
  52593. /*== Z_NULL*/
  52594. ) {
  52595. return Z_STREAM_ERROR;
  52596. }
  52597. s = strm.state;
  52598. wrap = s.wrap;
  52599. if (wrap === 2 || wrap === 1 && s.status !== INIT_STATE || s.lookahead) {
  52600. return Z_STREAM_ERROR;
  52601. }
  52602. /* when using zlib wrappers, compute Adler-32 for provided dictionary */
  52603. if (wrap === 1) {
  52604. /* adler32(strm->adler, dictionary, dictLength); */
  52605. strm.adler = adler32(strm.adler, dictionary, dictLength, 0);
  52606. }
  52607. s.wrap = 0;
  52608. /* avoid computing Adler-32 in read_buf */
  52609. /* if dictionary would fill window, just replace the history */
  52610. if (dictLength >= s.w_size) {
  52611. if (wrap === 0) {
  52612. /* already empty otherwise */
  52613. /*** CLEAR_HASH(s); ***/
  52614. zero(s.head); // Fill with NIL (= 0);
  52615. s.strstart = 0;
  52616. s.block_start = 0;
  52617. s.insert = 0;
  52618. }
  52619. /* use the tail */
  52620. // dictionary = dictionary.slice(dictLength - s.w_size);
  52621. tmpDict = new utils.Buf8(s.w_size);
  52622. utils.arraySet(tmpDict, dictionary, dictLength - s.w_size, s.w_size, 0);
  52623. dictionary = tmpDict;
  52624. dictLength = s.w_size;
  52625. }
  52626. /* insert dictionary into window and hash */
  52627. avail = strm.avail_in;
  52628. next = strm.next_in;
  52629. input = strm.input;
  52630. strm.avail_in = dictLength;
  52631. strm.next_in = 0;
  52632. strm.input = dictionary;
  52633. fill_window(s);
  52634. while (s.lookahead >= MIN_MATCH) {
  52635. str = s.strstart;
  52636. n = s.lookahead - (MIN_MATCH - 1);
  52637. do {
  52638. /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */
  52639. s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
  52640. s.prev[str & s.w_mask] = s.head[s.ins_h];
  52641. s.head[s.ins_h] = str;
  52642. str++;
  52643. } while (--n);
  52644. s.strstart = str;
  52645. s.lookahead = MIN_MATCH - 1;
  52646. fill_window(s);
  52647. }
  52648. s.strstart += s.lookahead;
  52649. s.block_start = s.strstart;
  52650. s.insert = s.lookahead;
  52651. s.lookahead = 0;
  52652. s.match_length = s.prev_length = MIN_MATCH - 1;
  52653. s.match_available = 0;
  52654. strm.next_in = next;
  52655. strm.input = input;
  52656. strm.avail_in = avail;
  52657. s.wrap = wrap;
  52658. return Z_OK;
  52659. }
  52660. exports.deflateInit = deflateInit;
  52661. exports.deflateInit2 = deflateInit2;
  52662. exports.deflateReset = deflateReset;
  52663. exports.deflateResetKeep = deflateResetKeep;
  52664. exports.deflateSetHeader = deflateSetHeader;
  52665. exports.deflate = deflate;
  52666. exports.deflateEnd = deflateEnd;
  52667. exports.deflateSetDictionary = deflateSetDictionary;
  52668. exports.deflateInfo = 'pako deflate (from Nodeca project)';
  52669. /* Not implemented
  52670. exports.deflateBound = deflateBound;
  52671. exports.deflateCopy = deflateCopy;
  52672. exports.deflateParams = deflateParams;
  52673. exports.deflatePending = deflatePending;
  52674. exports.deflatePrime = deflatePrime;
  52675. exports.deflateTune = deflateTune;
  52676. */
  52677. },{"../utils/common":442,"./adler32":444,"./crc32":446,"./messages":452,"./trees":453}],448:[function(require,module,exports){
  52678. 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  52679. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  52680. //
  52681. // This software is provided 'as-is', without any express or implied
  52682. // warranty. In no event will the authors be held liable for any damages
  52683. // arising from the use of this software.
  52684. //
  52685. // Permission is granted to anyone to use this software for any purpose,
  52686. // including commercial applications, and to alter it and redistribute it
  52687. // freely, subject to the following restrictions:
  52688. //
  52689. // 1. The origin of this software must not be misrepresented; you must not
  52690. // claim that you wrote the original software. If you use this software
  52691. // in a product, an acknowledgment in the product documentation would be
  52692. // appreciated but is not required.
  52693. // 2. Altered source versions must be plainly marked as such, and must not be
  52694. // misrepresented as being the original software.
  52695. // 3. This notice may not be removed or altered from any source distribution.
  52696. function GZheader() {
  52697. /* true if compressed data believed to be text */
  52698. this.text = 0;
  52699. /* modification time */
  52700. this.time = 0;
  52701. /* extra flags (not used when writing a gzip file) */
  52702. this.xflags = 0;
  52703. /* operating system */
  52704. this.os = 0;
  52705. /* pointer to extra field or Z_NULL if none */
  52706. this.extra = null;
  52707. /* extra field length (valid if extra != Z_NULL) */
  52708. this.extra_len = 0; // Actually, we don't need it in JS,
  52709. // but leave for few code modifications
  52710. //
  52711. // Setup limits is not necessary because in js we should not preallocate memory
  52712. // for inflate use constant limit in 65536 bytes
  52713. //
  52714. /* space at extra (only when reading header) */
  52715. // this.extra_max = 0;
  52716. /* pointer to zero-terminated file name or Z_NULL */
  52717. this.name = '';
  52718. /* space at name (only when reading header) */
  52719. // this.name_max = 0;
  52720. /* pointer to zero-terminated comment or Z_NULL */
  52721. this.comment = '';
  52722. /* space at comment (only when reading header) */
  52723. // this.comm_max = 0;
  52724. /* true if there was or will be a header crc */
  52725. this.hcrc = 0;
  52726. /* true when done reading gzip header (not used when writing a gzip file) */
  52727. this.done = false;
  52728. }
  52729. module.exports = GZheader;
  52730. },{}],449:[function(require,module,exports){
  52731. 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  52732. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  52733. //
  52734. // This software is provided 'as-is', without any express or implied
  52735. // warranty. In no event will the authors be held liable for any damages
  52736. // arising from the use of this software.
  52737. //
  52738. // Permission is granted to anyone to use this software for any purpose,
  52739. // including commercial applications, and to alter it and redistribute it
  52740. // freely, subject to the following restrictions:
  52741. //
  52742. // 1. The origin of this software must not be misrepresented; you must not
  52743. // claim that you wrote the original software. If you use this software
  52744. // in a product, an acknowledgment in the product documentation would be
  52745. // appreciated but is not required.
  52746. // 2. Altered source versions must be plainly marked as such, and must not be
  52747. // misrepresented as being the original software.
  52748. // 3. This notice may not be removed or altered from any source distribution.
  52749. // See state defs from inflate.js
  52750. var BAD = 30;
  52751. /* got a data error -- remain here until reset */
  52752. var TYPE = 12;
  52753. /* i: waiting for type bits, including last-flag bit */
  52754. /*
  52755. Decode literal, length, and distance codes and write out the resulting
  52756. literal and match bytes until either not enough input or output is
  52757. available, an end-of-block is encountered, or a data error is encountered.
  52758. When large enough input and output buffers are supplied to inflate(), for
  52759. example, a 16K input buffer and a 64K output buffer, more than 95% of the
  52760. inflate execution time is spent in this routine.
  52761. Entry assumptions:
  52762. state.mode === LEN
  52763. strm.avail_in >= 6
  52764. strm.avail_out >= 258
  52765. start >= strm.avail_out
  52766. state.bits < 8
  52767. On return, state.mode is one of:
  52768. LEN -- ran out of enough output space or enough available input
  52769. TYPE -- reached end of block code, inflate() to interpret next block
  52770. BAD -- error in block data
  52771. Notes:
  52772. - The maximum input bits used by a length/distance pair is 15 bits for the
  52773. length code, 5 bits for the length extra, 15 bits for the distance code,
  52774. and 13 bits for the distance extra. This totals 48 bits, or six bytes.
  52775. Therefore if strm.avail_in >= 6, then there is enough input to avoid
  52776. checking for available input while decoding.
  52777. - The maximum bytes that a single length/distance pair can output is 258
  52778. bytes, which is the maximum length that can be coded. inflate_fast()
  52779. requires strm.avail_out >= 258 for each loop to avoid checking for
  52780. output space.
  52781. */
  52782. module.exports = function inflate_fast(strm, start) {
  52783. var state;
  52784. var _in;
  52785. /* local strm.input */
  52786. var last;
  52787. /* have enough input while in < last */
  52788. var _out;
  52789. /* local strm.output */
  52790. var beg;
  52791. /* inflate()'s initial strm.output */
  52792. var end;
  52793. /* while out < end, enough space available */
  52794. //#ifdef INFLATE_STRICT
  52795. var dmax;
  52796. /* maximum distance from zlib header */
  52797. //#endif
  52798. var wsize;
  52799. /* window size or zero if not using window */
  52800. var whave;
  52801. /* valid bytes in the window */
  52802. var wnext;
  52803. /* window write index */
  52804. // Use `s_window` instead `window`, avoid conflict with instrumentation tools
  52805. var s_window;
  52806. /* allocated sliding window, if wsize != 0 */
  52807. var hold;
  52808. /* local strm.hold */
  52809. var bits;
  52810. /* local strm.bits */
  52811. var lcode;
  52812. /* local strm.lencode */
  52813. var dcode;
  52814. /* local strm.distcode */
  52815. var lmask;
  52816. /* mask for first level of length codes */
  52817. var dmask;
  52818. /* mask for first level of distance codes */
  52819. var here;
  52820. /* retrieved table entry */
  52821. var op;
  52822. /* code bits, operation, extra bits, or */
  52823. /* window position, window bytes to copy */
  52824. var len;
  52825. /* match length, unused bytes */
  52826. var dist;
  52827. /* match distance */
  52828. var from;
  52829. /* where to copy match from */
  52830. var from_source;
  52831. var input, output; // JS specific, because we have no pointers
  52832. /* copy state to local variables */
  52833. state = strm.state; //here = state.here;
  52834. _in = strm.next_in;
  52835. input = strm.input;
  52836. last = _in + (strm.avail_in - 5);
  52837. _out = strm.next_out;
  52838. output = strm.output;
  52839. beg = _out - (start - strm.avail_out);
  52840. end = _out + (strm.avail_out - 257); //#ifdef INFLATE_STRICT
  52841. dmax = state.dmax; //#endif
  52842. wsize = state.wsize;
  52843. whave = state.whave;
  52844. wnext = state.wnext;
  52845. s_window = state.window;
  52846. hold = state.hold;
  52847. bits = state.bits;
  52848. lcode = state.lencode;
  52849. dcode = state.distcode;
  52850. lmask = (1 << state.lenbits) - 1;
  52851. dmask = (1 << state.distbits) - 1;
  52852. /* decode literals and length/distances until end-of-block or not enough
  52853. input data or output space */
  52854. top: do {
  52855. if (bits < 15) {
  52856. hold += input[_in++] << bits;
  52857. bits += 8;
  52858. hold += input[_in++] << bits;
  52859. bits += 8;
  52860. }
  52861. here = lcode[hold & lmask];
  52862. dolen: for (;;) {
  52863. // Goto emulation
  52864. op = here >>> 24
  52865. /*here.bits*/
  52866. ;
  52867. hold >>>= op;
  52868. bits -= op;
  52869. op = here >>> 16 & 0xff
  52870. /*here.op*/
  52871. ;
  52872. if (op === 0) {
  52873. /* literal */
  52874. //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
  52875. // "inflate: literal '%c'\n" :
  52876. // "inflate: literal 0x%02x\n", here.val));
  52877. output[_out++] = here & 0xffff
  52878. /*here.val*/
  52879. ;
  52880. } else if (op & 16) {
  52881. /* length base */
  52882. len = here & 0xffff
  52883. /*here.val*/
  52884. ;
  52885. op &= 15;
  52886. /* number of extra bits */
  52887. if (op) {
  52888. if (bits < op) {
  52889. hold += input[_in++] << bits;
  52890. bits += 8;
  52891. }
  52892. len += hold & (1 << op) - 1;
  52893. hold >>>= op;
  52894. bits -= op;
  52895. } //Tracevv((stderr, "inflate: length %u\n", len));
  52896. if (bits < 15) {
  52897. hold += input[_in++] << bits;
  52898. bits += 8;
  52899. hold += input[_in++] << bits;
  52900. bits += 8;
  52901. }
  52902. here = dcode[hold & dmask];
  52903. dodist: for (;;) {
  52904. // goto emulation
  52905. op = here >>> 24
  52906. /*here.bits*/
  52907. ;
  52908. hold >>>= op;
  52909. bits -= op;
  52910. op = here >>> 16 & 0xff
  52911. /*here.op*/
  52912. ;
  52913. if (op & 16) {
  52914. /* distance base */
  52915. dist = here & 0xffff
  52916. /*here.val*/
  52917. ;
  52918. op &= 15;
  52919. /* number of extra bits */
  52920. if (bits < op) {
  52921. hold += input[_in++] << bits;
  52922. bits += 8;
  52923. if (bits < op) {
  52924. hold += input[_in++] << bits;
  52925. bits += 8;
  52926. }
  52927. }
  52928. dist += hold & (1 << op) - 1; //#ifdef INFLATE_STRICT
  52929. if (dist > dmax) {
  52930. strm.msg = 'invalid distance too far back';
  52931. state.mode = BAD;
  52932. break top;
  52933. } //#endif
  52934. hold >>>= op;
  52935. bits -= op; //Tracevv((stderr, "inflate: distance %u\n", dist));
  52936. op = _out - beg;
  52937. /* max distance in output */
  52938. if (dist > op) {
  52939. /* see if copy from window */
  52940. op = dist - op;
  52941. /* distance back in window */
  52942. if (op > whave) {
  52943. if (state.sane) {
  52944. strm.msg = 'invalid distance too far back';
  52945. state.mode = BAD;
  52946. break top;
  52947. } // (!) This block is disabled in zlib defaults,
  52948. // don't enable it for binary compatibility
  52949. //#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
  52950. // if (len <= op - whave) {
  52951. // do {
  52952. // output[_out++] = 0;
  52953. // } while (--len);
  52954. // continue top;
  52955. // }
  52956. // len -= op - whave;
  52957. // do {
  52958. // output[_out++] = 0;
  52959. // } while (--op > whave);
  52960. // if (op === 0) {
  52961. // from = _out - dist;
  52962. // do {
  52963. // output[_out++] = output[from++];
  52964. // } while (--len);
  52965. // continue top;
  52966. // }
  52967. //#endif
  52968. }
  52969. from = 0; // window index
  52970. from_source = s_window;
  52971. if (wnext === 0) {
  52972. /* very common case */
  52973. from += wsize - op;
  52974. if (op < len) {
  52975. /* some from window */
  52976. len -= op;
  52977. do {
  52978. output[_out++] = s_window[from++];
  52979. } while (--op);
  52980. from = _out - dist;
  52981. /* rest from output */
  52982. from_source = output;
  52983. }
  52984. } else if (wnext < op) {
  52985. /* wrap around window */
  52986. from += wsize + wnext - op;
  52987. op -= wnext;
  52988. if (op < len) {
  52989. /* some from end of window */
  52990. len -= op;
  52991. do {
  52992. output[_out++] = s_window[from++];
  52993. } while (--op);
  52994. from = 0;
  52995. if (wnext < len) {
  52996. /* some from start of window */
  52997. op = wnext;
  52998. len -= op;
  52999. do {
  53000. output[_out++] = s_window[from++];
  53001. } while (--op);
  53002. from = _out - dist;
  53003. /* rest from output */
  53004. from_source = output;
  53005. }
  53006. }
  53007. } else {
  53008. /* contiguous in window */
  53009. from += wnext - op;
  53010. if (op < len) {
  53011. /* some from window */
  53012. len -= op;
  53013. do {
  53014. output[_out++] = s_window[from++];
  53015. } while (--op);
  53016. from = _out - dist;
  53017. /* rest from output */
  53018. from_source = output;
  53019. }
  53020. }
  53021. while (len > 2) {
  53022. output[_out++] = from_source[from++];
  53023. output[_out++] = from_source[from++];
  53024. output[_out++] = from_source[from++];
  53025. len -= 3;
  53026. }
  53027. if (len) {
  53028. output[_out++] = from_source[from++];
  53029. if (len > 1) {
  53030. output[_out++] = from_source[from++];
  53031. }
  53032. }
  53033. } else {
  53034. from = _out - dist;
  53035. /* copy direct from output */
  53036. do {
  53037. /* minimum length is three */
  53038. output[_out++] = output[from++];
  53039. output[_out++] = output[from++];
  53040. output[_out++] = output[from++];
  53041. len -= 3;
  53042. } while (len > 2);
  53043. if (len) {
  53044. output[_out++] = output[from++];
  53045. if (len > 1) {
  53046. output[_out++] = output[from++];
  53047. }
  53048. }
  53049. }
  53050. } else if ((op & 64) === 0) {
  53051. /* 2nd level distance code */
  53052. here = dcode[(here & 0xffff) + (
  53053. /*here.val*/
  53054. hold & (1 << op) - 1)];
  53055. continue dodist;
  53056. } else {
  53057. strm.msg = 'invalid distance code';
  53058. state.mode = BAD;
  53059. break top;
  53060. }
  53061. break; // need to emulate goto via "continue"
  53062. }
  53063. } else if ((op & 64) === 0) {
  53064. /* 2nd level length code */
  53065. here = lcode[(here & 0xffff) + (
  53066. /*here.val*/
  53067. hold & (1 << op) - 1)];
  53068. continue dolen;
  53069. } else if (op & 32) {
  53070. /* end-of-block */
  53071. //Tracevv((stderr, "inflate: end of block\n"));
  53072. state.mode = TYPE;
  53073. break top;
  53074. } else {
  53075. strm.msg = 'invalid literal/length code';
  53076. state.mode = BAD;
  53077. break top;
  53078. }
  53079. break; // need to emulate goto via "continue"
  53080. }
  53081. } while (_in < last && _out < end);
  53082. /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
  53083. len = bits >> 3;
  53084. _in -= len;
  53085. bits -= len << 3;
  53086. hold &= (1 << bits) - 1;
  53087. /* update state and return */
  53088. strm.next_in = _in;
  53089. strm.next_out = _out;
  53090. strm.avail_in = _in < last ? 5 + (last - _in) : 5 - (_in - last);
  53091. strm.avail_out = _out < end ? 257 + (end - _out) : 257 - (_out - end);
  53092. state.hold = hold;
  53093. state.bits = bits;
  53094. return;
  53095. };
  53096. },{}],450:[function(require,module,exports){
  53097. 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  53098. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  53099. //
  53100. // This software is provided 'as-is', without any express or implied
  53101. // warranty. In no event will the authors be held liable for any damages
  53102. // arising from the use of this software.
  53103. //
  53104. // Permission is granted to anyone to use this software for any purpose,
  53105. // including commercial applications, and to alter it and redistribute it
  53106. // freely, subject to the following restrictions:
  53107. //
  53108. // 1. The origin of this software must not be misrepresented; you must not
  53109. // claim that you wrote the original software. If you use this software
  53110. // in a product, an acknowledgment in the product documentation would be
  53111. // appreciated but is not required.
  53112. // 2. Altered source versions must be plainly marked as such, and must not be
  53113. // misrepresented as being the original software.
  53114. // 3. This notice may not be removed or altered from any source distribution.
  53115. var utils = require('../utils/common');
  53116. var adler32 = require('./adler32');
  53117. var crc32 = require('./crc32');
  53118. var inflate_fast = require('./inffast');
  53119. var inflate_table = require('./inftrees');
  53120. var CODES = 0;
  53121. var LENS = 1;
  53122. var DISTS = 2;
  53123. /* Public constants ==========================================================*/
  53124. /* ===========================================================================*/
  53125. /* Allowed flush values; see deflate() and inflate() below for details */
  53126. //var Z_NO_FLUSH = 0;
  53127. //var Z_PARTIAL_FLUSH = 1;
  53128. //var Z_SYNC_FLUSH = 2;
  53129. //var Z_FULL_FLUSH = 3;
  53130. var Z_FINISH = 4;
  53131. var Z_BLOCK = 5;
  53132. var Z_TREES = 6;
  53133. /* Return codes for the compression/decompression functions. Negative values
  53134. * are errors, positive values are used for special but normal events.
  53135. */
  53136. var Z_OK = 0;
  53137. var Z_STREAM_END = 1;
  53138. var Z_NEED_DICT = 2; //var Z_ERRNO = -1;
  53139. var Z_STREAM_ERROR = -2;
  53140. var Z_DATA_ERROR = -3;
  53141. var Z_MEM_ERROR = -4;
  53142. var Z_BUF_ERROR = -5; //var Z_VERSION_ERROR = -6;
  53143. /* The deflate compression method */
  53144. var Z_DEFLATED = 8;
  53145. /* STATES ====================================================================*/
  53146. /* ===========================================================================*/
  53147. var HEAD = 1;
  53148. /* i: waiting for magic header */
  53149. var FLAGS = 2;
  53150. /* i: waiting for method and flags (gzip) */
  53151. var TIME = 3;
  53152. /* i: waiting for modification time (gzip) */
  53153. var OS = 4;
  53154. /* i: waiting for extra flags and operating system (gzip) */
  53155. var EXLEN = 5;
  53156. /* i: waiting for extra length (gzip) */
  53157. var EXTRA = 6;
  53158. /* i: waiting for extra bytes (gzip) */
  53159. var NAME = 7;
  53160. /* i: waiting for end of file name (gzip) */
  53161. var COMMENT = 8;
  53162. /* i: waiting for end of comment (gzip) */
  53163. var HCRC = 9;
  53164. /* i: waiting for header crc (gzip) */
  53165. var DICTID = 10;
  53166. /* i: waiting for dictionary check value */
  53167. var DICT = 11;
  53168. /* waiting for inflateSetDictionary() call */
  53169. var TYPE = 12;
  53170. /* i: waiting for type bits, including last-flag bit */
  53171. var TYPEDO = 13;
  53172. /* i: same, but skip check to exit inflate on new block */
  53173. var STORED = 14;
  53174. /* i: waiting for stored size (length and complement) */
  53175. var COPY_ = 15;
  53176. /* i/o: same as COPY below, but only first time in */
  53177. var COPY = 16;
  53178. /* i/o: waiting for input or output to copy stored block */
  53179. var TABLE = 17;
  53180. /* i: waiting for dynamic block table lengths */
  53181. var LENLENS = 18;
  53182. /* i: waiting for code length code lengths */
  53183. var CODELENS = 19;
  53184. /* i: waiting for length/lit and distance code lengths */
  53185. var LEN_ = 20;
  53186. /* i: same as LEN below, but only first time in */
  53187. var LEN = 21;
  53188. /* i: waiting for length/lit/eob code */
  53189. var LENEXT = 22;
  53190. /* i: waiting for length extra bits */
  53191. var DIST = 23;
  53192. /* i: waiting for distance code */
  53193. var DISTEXT = 24;
  53194. /* i: waiting for distance extra bits */
  53195. var MATCH = 25;
  53196. /* o: waiting for output space to copy string */
  53197. var LIT = 26;
  53198. /* o: waiting for output space to write literal */
  53199. var CHECK = 27;
  53200. /* i: waiting for 32-bit check value */
  53201. var LENGTH = 28;
  53202. /* i: waiting for 32-bit length (gzip) */
  53203. var DONE = 29;
  53204. /* finished check, done -- remain here until reset */
  53205. var BAD = 30;
  53206. /* got a data error -- remain here until reset */
  53207. var MEM = 31;
  53208. /* got an inflate() memory error -- remain here until reset */
  53209. var SYNC = 32;
  53210. /* looking for synchronization bytes to restart inflate() */
  53211. /* ===========================================================================*/
  53212. var ENOUGH_LENS = 852;
  53213. var ENOUGH_DISTS = 592; //var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);
  53214. var MAX_WBITS = 15;
  53215. /* 32K LZ77 window */
  53216. var DEF_WBITS = MAX_WBITS;
  53217. function zswap32(q) {
  53218. return (q >>> 24 & 0xff) + (q >>> 8 & 0xff00) + ((q & 0xff00) << 8) + ((q & 0xff) << 24);
  53219. }
  53220. function InflateState() {
  53221. this.mode = 0;
  53222. /* current inflate mode */
  53223. this.last = false;
  53224. /* true if processing last block */
  53225. this.wrap = 0;
  53226. /* bit 0 true for zlib, bit 1 true for gzip */
  53227. this.havedict = false;
  53228. /* true if dictionary provided */
  53229. this.flags = 0;
  53230. /* gzip header method and flags (0 if zlib) */
  53231. this.dmax = 0;
  53232. /* zlib header max distance (INFLATE_STRICT) */
  53233. this.check = 0;
  53234. /* protected copy of check value */
  53235. this.total = 0;
  53236. /* protected copy of output count */
  53237. // TODO: may be {}
  53238. this.head = null;
  53239. /* where to save gzip header information */
  53240. /* sliding window */
  53241. this.wbits = 0;
  53242. /* log base 2 of requested window size */
  53243. this.wsize = 0;
  53244. /* window size or zero if not using window */
  53245. this.whave = 0;
  53246. /* valid bytes in the window */
  53247. this.wnext = 0;
  53248. /* window write index */
  53249. this.window = null;
  53250. /* allocated sliding window, if needed */
  53251. /* bit accumulator */
  53252. this.hold = 0;
  53253. /* input bit accumulator */
  53254. this.bits = 0;
  53255. /* number of bits in "in" */
  53256. /* for string and stored block copying */
  53257. this.length = 0;
  53258. /* literal or length of data to copy */
  53259. this.offset = 0;
  53260. /* distance back to copy string from */
  53261. /* for table and code decoding */
  53262. this.extra = 0;
  53263. /* extra bits needed */
  53264. /* fixed and dynamic code tables */
  53265. this.lencode = null;
  53266. /* starting table for length/literal codes */
  53267. this.distcode = null;
  53268. /* starting table for distance codes */
  53269. this.lenbits = 0;
  53270. /* index bits for lencode */
  53271. this.distbits = 0;
  53272. /* index bits for distcode */
  53273. /* dynamic table building */
  53274. this.ncode = 0;
  53275. /* number of code length code lengths */
  53276. this.nlen = 0;
  53277. /* number of length code lengths */
  53278. this.ndist = 0;
  53279. /* number of distance code lengths */
  53280. this.have = 0;
  53281. /* number of code lengths in lens[] */
  53282. this.next = null;
  53283. /* next available space in codes[] */
  53284. this.lens = new utils.Buf16(320);
  53285. /* temporary storage for code lengths */
  53286. this.work = new utils.Buf16(288);
  53287. /* work area for code table building */
  53288. /*
  53289. because we don't have pointers in js, we use lencode and distcode directly
  53290. as buffers so we don't need codes
  53291. */
  53292. //this.codes = new utils.Buf32(ENOUGH); /* space for code tables */
  53293. this.lendyn = null;
  53294. /* dynamic table for length/literal codes (JS specific) */
  53295. this.distdyn = null;
  53296. /* dynamic table for distance codes (JS specific) */
  53297. this.sane = 0;
  53298. /* if false, allow invalid distance too far */
  53299. this.back = 0;
  53300. /* bits back of last unprocessed length/lit */
  53301. this.was = 0;
  53302. /* initial length of match */
  53303. }
  53304. function inflateResetKeep(strm) {
  53305. var state;
  53306. if (!strm || !strm.state) {
  53307. return Z_STREAM_ERROR;
  53308. }
  53309. state = strm.state;
  53310. strm.total_in = strm.total_out = state.total = 0;
  53311. strm.msg = '';
  53312. /*Z_NULL*/
  53313. if (state.wrap) {
  53314. /* to support ill-conceived Java test suite */
  53315. strm.adler = state.wrap & 1;
  53316. }
  53317. state.mode = HEAD;
  53318. state.last = 0;
  53319. state.havedict = 0;
  53320. state.dmax = 32768;
  53321. state.head = null
  53322. /*Z_NULL*/
  53323. ;
  53324. state.hold = 0;
  53325. state.bits = 0; //state.lencode = state.distcode = state.next = state.codes;
  53326. state.lencode = state.lendyn = new utils.Buf32(ENOUGH_LENS);
  53327. state.distcode = state.distdyn = new utils.Buf32(ENOUGH_DISTS);
  53328. state.sane = 1;
  53329. state.back = -1; //Tracev((stderr, "inflate: reset\n"));
  53330. return Z_OK;
  53331. }
  53332. function inflateReset(strm) {
  53333. var state;
  53334. if (!strm || !strm.state) {
  53335. return Z_STREAM_ERROR;
  53336. }
  53337. state = strm.state;
  53338. state.wsize = 0;
  53339. state.whave = 0;
  53340. state.wnext = 0;
  53341. return inflateResetKeep(strm);
  53342. }
  53343. function inflateReset2(strm, windowBits) {
  53344. var wrap;
  53345. var state;
  53346. /* get the state */
  53347. if (!strm || !strm.state) {
  53348. return Z_STREAM_ERROR;
  53349. }
  53350. state = strm.state;
  53351. /* extract wrap request from windowBits parameter */
  53352. if (windowBits < 0) {
  53353. wrap = 0;
  53354. windowBits = -windowBits;
  53355. } else {
  53356. wrap = (windowBits >> 4) + 1;
  53357. if (windowBits < 48) {
  53358. windowBits &= 15;
  53359. }
  53360. }
  53361. /* set number of window bits, free window if different */
  53362. if (windowBits && (windowBits < 8 || windowBits > 15)) {
  53363. return Z_STREAM_ERROR;
  53364. }
  53365. if (state.window !== null && state.wbits !== windowBits) {
  53366. state.window = null;
  53367. }
  53368. /* update state and reset the rest of it */
  53369. state.wrap = wrap;
  53370. state.wbits = windowBits;
  53371. return inflateReset(strm);
  53372. }
  53373. function inflateInit2(strm, windowBits) {
  53374. var ret;
  53375. var state;
  53376. if (!strm) {
  53377. return Z_STREAM_ERROR;
  53378. } //strm.msg = Z_NULL; /* in case we return an error */
  53379. state = new InflateState(); //if (state === Z_NULL) return Z_MEM_ERROR;
  53380. //Tracev((stderr, "inflate: allocated\n"));
  53381. strm.state = state;
  53382. state.window = null
  53383. /*Z_NULL*/
  53384. ;
  53385. ret = inflateReset2(strm, windowBits);
  53386. if (ret !== Z_OK) {
  53387. strm.state = null
  53388. /*Z_NULL*/
  53389. ;
  53390. }
  53391. return ret;
  53392. }
  53393. function inflateInit(strm) {
  53394. return inflateInit2(strm, DEF_WBITS);
  53395. }
  53396. /*
  53397. Return state with length and distance decoding tables and index sizes set to
  53398. fixed code decoding. Normally this returns fixed tables from inffixed.h.
  53399. If BUILDFIXED is defined, then instead this routine builds the tables the
  53400. first time it's called, and returns those tables the first time and
  53401. thereafter. This reduces the size of the code by about 2K bytes, in
  53402. exchange for a little execution time. However, BUILDFIXED should not be
  53403. used for threaded applications, since the rewriting of the tables and virgin
  53404. may not be thread-safe.
  53405. */
  53406. var virgin = true;
  53407. var lenfix, distfix; // We have no pointers in JS, so keep tables separate
  53408. function fixedtables(state) {
  53409. /* build fixed huffman tables if first call (may not be thread safe) */
  53410. if (virgin) {
  53411. var sym;
  53412. lenfix = new utils.Buf32(512);
  53413. distfix = new utils.Buf32(32);
  53414. /* literal/length table */
  53415. sym = 0;
  53416. while (sym < 144) {
  53417. state.lens[sym++] = 8;
  53418. }
  53419. while (sym < 256) {
  53420. state.lens[sym++] = 9;
  53421. }
  53422. while (sym < 280) {
  53423. state.lens[sym++] = 7;
  53424. }
  53425. while (sym < 288) {
  53426. state.lens[sym++] = 8;
  53427. }
  53428. inflate_table(LENS, state.lens, 0, 288, lenfix, 0, state.work, {
  53429. bits: 9
  53430. });
  53431. /* distance table */
  53432. sym = 0;
  53433. while (sym < 32) {
  53434. state.lens[sym++] = 5;
  53435. }
  53436. inflate_table(DISTS, state.lens, 0, 32, distfix, 0, state.work, {
  53437. bits: 5
  53438. });
  53439. /* do this just once */
  53440. virgin = false;
  53441. }
  53442. state.lencode = lenfix;
  53443. state.lenbits = 9;
  53444. state.distcode = distfix;
  53445. state.distbits = 5;
  53446. }
  53447. /*
  53448. Update the window with the last wsize (normally 32K) bytes written before
  53449. returning. If window does not exist yet, create it. This is only called
  53450. when a window is already in use, or when output has been written during this
  53451. inflate call, but the end of the deflate stream has not been reached yet.
  53452. It is also called to create a window for dictionary data when a dictionary
  53453. is loaded.
  53454. Providing output buffers larger than 32K to inflate() should provide a speed
  53455. advantage, since only the last 32K of output is copied to the sliding window
  53456. upon return from inflate(), and since all distances after the first 32K of
  53457. output will fall in the output data, making match copies simpler and faster.
  53458. The advantage may be dependent on the size of the processor's data caches.
  53459. */
  53460. function updatewindow(strm, src, end, copy) {
  53461. var dist;
  53462. var state = strm.state;
  53463. /* if it hasn't been done already, allocate space for the window */
  53464. if (state.window === null) {
  53465. state.wsize = 1 << state.wbits;
  53466. state.wnext = 0;
  53467. state.whave = 0;
  53468. state.window = new utils.Buf8(state.wsize);
  53469. }
  53470. /* copy state->wsize or less output bytes into the circular window */
  53471. if (copy >= state.wsize) {
  53472. utils.arraySet(state.window, src, end - state.wsize, state.wsize, 0);
  53473. state.wnext = 0;
  53474. state.whave = state.wsize;
  53475. } else {
  53476. dist = state.wsize - state.wnext;
  53477. if (dist > copy) {
  53478. dist = copy;
  53479. } //zmemcpy(state->window + state->wnext, end - copy, dist);
  53480. utils.arraySet(state.window, src, end - copy, dist, state.wnext);
  53481. copy -= dist;
  53482. if (copy) {
  53483. //zmemcpy(state->window, end - copy, copy);
  53484. utils.arraySet(state.window, src, end - copy, copy, 0);
  53485. state.wnext = copy;
  53486. state.whave = state.wsize;
  53487. } else {
  53488. state.wnext += dist;
  53489. if (state.wnext === state.wsize) {
  53490. state.wnext = 0;
  53491. }
  53492. if (state.whave < state.wsize) {
  53493. state.whave += dist;
  53494. }
  53495. }
  53496. }
  53497. return 0;
  53498. }
  53499. function inflate(strm, flush) {
  53500. var state;
  53501. var input, output; // input/output buffers
  53502. var next;
  53503. /* next input INDEX */
  53504. var put;
  53505. /* next output INDEX */
  53506. var have, left;
  53507. /* available input and output */
  53508. var hold;
  53509. /* bit buffer */
  53510. var bits;
  53511. /* bits in bit buffer */
  53512. var _in, _out;
  53513. /* save starting available input and output */
  53514. var copy;
  53515. /* number of stored or match bytes to copy */
  53516. var from;
  53517. /* where to copy match bytes from */
  53518. var from_source;
  53519. var here = 0;
  53520. /* current decoding table entry */
  53521. var here_bits, here_op, here_val; // paked "here" denormalized (JS specific)
  53522. //var last; /* parent table entry */
  53523. var last_bits, last_op, last_val; // paked "last" denormalized (JS specific)
  53524. var len;
  53525. /* length to copy for repeats, bits to drop */
  53526. var ret;
  53527. /* return code */
  53528. var hbuf = new utils.Buf8(4);
  53529. /* buffer for gzip header crc calculation */
  53530. var opts;
  53531. var n; // temporary var for NEED_BITS
  53532. var order =
  53533. /* permutation of code lengths */
  53534. [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
  53535. if (!strm || !strm.state || !strm.output || !strm.input && strm.avail_in !== 0) {
  53536. return Z_STREAM_ERROR;
  53537. }
  53538. state = strm.state;
  53539. if (state.mode === TYPE) {
  53540. state.mode = TYPEDO;
  53541. }
  53542. /* skip check */
  53543. //--- LOAD() ---
  53544. put = strm.next_out;
  53545. output = strm.output;
  53546. left = strm.avail_out;
  53547. next = strm.next_in;
  53548. input = strm.input;
  53549. have = strm.avail_in;
  53550. hold = state.hold;
  53551. bits = state.bits; //---
  53552. _in = have;
  53553. _out = left;
  53554. ret = Z_OK;
  53555. inf_leave: // goto emulation
  53556. for (;;) {
  53557. switch (state.mode) {
  53558. case HEAD:
  53559. if (state.wrap === 0) {
  53560. state.mode = TYPEDO;
  53561. break;
  53562. } //=== NEEDBITS(16);
  53563. while (bits < 16) {
  53564. if (have === 0) {
  53565. break inf_leave;
  53566. }
  53567. have--;
  53568. hold += input[next++] << bits;
  53569. bits += 8;
  53570. } //===//
  53571. if (state.wrap & 2 && hold === 0x8b1f) {
  53572. /* gzip header */
  53573. state.check = 0
  53574. /*crc32(0L, Z_NULL, 0)*/
  53575. ; //=== CRC2(state.check, hold);
  53576. hbuf[0] = hold & 0xff;
  53577. hbuf[1] = hold >>> 8 & 0xff;
  53578. state.check = crc32(state.check, hbuf, 2, 0); //===//
  53579. //=== INITBITS();
  53580. hold = 0;
  53581. bits = 0; //===//
  53582. state.mode = FLAGS;
  53583. break;
  53584. }
  53585. state.flags = 0;
  53586. /* expect zlib header */
  53587. if (state.head) {
  53588. state.head.done = false;
  53589. }
  53590. if (!(state.wrap & 1) ||
  53591. /* check if zlib header allowed */
  53592. (((hold & 0xff) <<
  53593. /*BITS(8)*/
  53594. 8) + (hold >> 8)) % 31) {
  53595. strm.msg = 'incorrect header check';
  53596. state.mode = BAD;
  53597. break;
  53598. }
  53599. if ((hold & 0x0f) !==
  53600. /*BITS(4)*/
  53601. Z_DEFLATED) {
  53602. strm.msg = 'unknown compression method';
  53603. state.mode = BAD;
  53604. break;
  53605. } //--- DROPBITS(4) ---//
  53606. hold >>>= 4;
  53607. bits -= 4; //---//
  53608. len = (hold & 0x0f) +
  53609. /*BITS(4)*/
  53610. 8;
  53611. if (state.wbits === 0) {
  53612. state.wbits = len;
  53613. } else if (len > state.wbits) {
  53614. strm.msg = 'invalid window size';
  53615. state.mode = BAD;
  53616. break;
  53617. }
  53618. state.dmax = 1 << len; //Tracev((stderr, "inflate: zlib header ok\n"));
  53619. strm.adler = state.check = 1
  53620. /*adler32(0L, Z_NULL, 0)*/
  53621. ;
  53622. state.mode = hold & 0x200 ? DICTID : TYPE; //=== INITBITS();
  53623. hold = 0;
  53624. bits = 0; //===//
  53625. break;
  53626. case FLAGS:
  53627. //=== NEEDBITS(16); */
  53628. while (bits < 16) {
  53629. if (have === 0) {
  53630. break inf_leave;
  53631. }
  53632. have--;
  53633. hold += input[next++] << bits;
  53634. bits += 8;
  53635. } //===//
  53636. state.flags = hold;
  53637. if ((state.flags & 0xff) !== Z_DEFLATED) {
  53638. strm.msg = 'unknown compression method';
  53639. state.mode = BAD;
  53640. break;
  53641. }
  53642. if (state.flags & 0xe000) {
  53643. strm.msg = 'unknown header flags set';
  53644. state.mode = BAD;
  53645. break;
  53646. }
  53647. if (state.head) {
  53648. state.head.text = hold >> 8 & 1;
  53649. }
  53650. if (state.flags & 0x0200) {
  53651. //=== CRC2(state.check, hold);
  53652. hbuf[0] = hold & 0xff;
  53653. hbuf[1] = hold >>> 8 & 0xff;
  53654. state.check = crc32(state.check, hbuf, 2, 0); //===//
  53655. } //=== INITBITS();
  53656. hold = 0;
  53657. bits = 0; //===//
  53658. state.mode = TIME;
  53659. /* falls through */
  53660. case TIME:
  53661. //=== NEEDBITS(32); */
  53662. while (bits < 32) {
  53663. if (have === 0) {
  53664. break inf_leave;
  53665. }
  53666. have--;
  53667. hold += input[next++] << bits;
  53668. bits += 8;
  53669. } //===//
  53670. if (state.head) {
  53671. state.head.time = hold;
  53672. }
  53673. if (state.flags & 0x0200) {
  53674. //=== CRC4(state.check, hold)
  53675. hbuf[0] = hold & 0xff;
  53676. hbuf[1] = hold >>> 8 & 0xff;
  53677. hbuf[2] = hold >>> 16 & 0xff;
  53678. hbuf[3] = hold >>> 24 & 0xff;
  53679. state.check = crc32(state.check, hbuf, 4, 0); //===
  53680. } //=== INITBITS();
  53681. hold = 0;
  53682. bits = 0; //===//
  53683. state.mode = OS;
  53684. /* falls through */
  53685. case OS:
  53686. //=== NEEDBITS(16); */
  53687. while (bits < 16) {
  53688. if (have === 0) {
  53689. break inf_leave;
  53690. }
  53691. have--;
  53692. hold += input[next++] << bits;
  53693. bits += 8;
  53694. } //===//
  53695. if (state.head) {
  53696. state.head.xflags = hold & 0xff;
  53697. state.head.os = hold >> 8;
  53698. }
  53699. if (state.flags & 0x0200) {
  53700. //=== CRC2(state.check, hold);
  53701. hbuf[0] = hold & 0xff;
  53702. hbuf[1] = hold >>> 8 & 0xff;
  53703. state.check = crc32(state.check, hbuf, 2, 0); //===//
  53704. } //=== INITBITS();
  53705. hold = 0;
  53706. bits = 0; //===//
  53707. state.mode = EXLEN;
  53708. /* falls through */
  53709. case EXLEN:
  53710. if (state.flags & 0x0400) {
  53711. //=== NEEDBITS(16); */
  53712. while (bits < 16) {
  53713. if (have === 0) {
  53714. break inf_leave;
  53715. }
  53716. have--;
  53717. hold += input[next++] << bits;
  53718. bits += 8;
  53719. } //===//
  53720. state.length = hold;
  53721. if (state.head) {
  53722. state.head.extra_len = hold;
  53723. }
  53724. if (state.flags & 0x0200) {
  53725. //=== CRC2(state.check, hold);
  53726. hbuf[0] = hold & 0xff;
  53727. hbuf[1] = hold >>> 8 & 0xff;
  53728. state.check = crc32(state.check, hbuf, 2, 0); //===//
  53729. } //=== INITBITS();
  53730. hold = 0;
  53731. bits = 0; //===//
  53732. } else if (state.head) {
  53733. state.head.extra = null
  53734. /*Z_NULL*/
  53735. ;
  53736. }
  53737. state.mode = EXTRA;
  53738. /* falls through */
  53739. case EXTRA:
  53740. if (state.flags & 0x0400) {
  53741. copy = state.length;
  53742. if (copy > have) {
  53743. copy = have;
  53744. }
  53745. if (copy) {
  53746. if (state.head) {
  53747. len = state.head.extra_len - state.length;
  53748. if (!state.head.extra) {
  53749. // Use untyped array for more convenient processing later
  53750. state.head.extra = new Array(state.head.extra_len);
  53751. }
  53752. utils.arraySet(state.head.extra, input, next, // extra field is limited to 65536 bytes
  53753. // - no need for additional size check
  53754. copy,
  53755. /*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/
  53756. len); //zmemcpy(state.head.extra + len, next,
  53757. // len + copy > state.head.extra_max ?
  53758. // state.head.extra_max - len : copy);
  53759. }
  53760. if (state.flags & 0x0200) {
  53761. state.check = crc32(state.check, input, copy, next);
  53762. }
  53763. have -= copy;
  53764. next += copy;
  53765. state.length -= copy;
  53766. }
  53767. if (state.length) {
  53768. break inf_leave;
  53769. }
  53770. }
  53771. state.length = 0;
  53772. state.mode = NAME;
  53773. /* falls through */
  53774. case NAME:
  53775. if (state.flags & 0x0800) {
  53776. if (have === 0) {
  53777. break inf_leave;
  53778. }
  53779. copy = 0;
  53780. do {
  53781. // TODO: 2 or 1 bytes?
  53782. len = input[next + copy++];
  53783. /* use constant limit because in js we should not preallocate memory */
  53784. if (state.head && len && state.length < 65536
  53785. /*state.head.name_max*/
  53786. ) {
  53787. state.head.name += String.fromCharCode(len);
  53788. }
  53789. } while (len && copy < have);
  53790. if (state.flags & 0x0200) {
  53791. state.check = crc32(state.check, input, copy, next);
  53792. }
  53793. have -= copy;
  53794. next += copy;
  53795. if (len) {
  53796. break inf_leave;
  53797. }
  53798. } else if (state.head) {
  53799. state.head.name = null;
  53800. }
  53801. state.length = 0;
  53802. state.mode = COMMENT;
  53803. /* falls through */
  53804. case COMMENT:
  53805. if (state.flags & 0x1000) {
  53806. if (have === 0) {
  53807. break inf_leave;
  53808. }
  53809. copy = 0;
  53810. do {
  53811. len = input[next + copy++];
  53812. /* use constant limit because in js we should not preallocate memory */
  53813. if (state.head && len && state.length < 65536
  53814. /*state.head.comm_max*/
  53815. ) {
  53816. state.head.comment += String.fromCharCode(len);
  53817. }
  53818. } while (len && copy < have);
  53819. if (state.flags & 0x0200) {
  53820. state.check = crc32(state.check, input, copy, next);
  53821. }
  53822. have -= copy;
  53823. next += copy;
  53824. if (len) {
  53825. break inf_leave;
  53826. }
  53827. } else if (state.head) {
  53828. state.head.comment = null;
  53829. }
  53830. state.mode = HCRC;
  53831. /* falls through */
  53832. case HCRC:
  53833. if (state.flags & 0x0200) {
  53834. //=== NEEDBITS(16); */
  53835. while (bits < 16) {
  53836. if (have === 0) {
  53837. break inf_leave;
  53838. }
  53839. have--;
  53840. hold += input[next++] << bits;
  53841. bits += 8;
  53842. } //===//
  53843. if (hold !== (state.check & 0xffff)) {
  53844. strm.msg = 'header crc mismatch';
  53845. state.mode = BAD;
  53846. break;
  53847. } //=== INITBITS();
  53848. hold = 0;
  53849. bits = 0; //===//
  53850. }
  53851. if (state.head) {
  53852. state.head.hcrc = state.flags >> 9 & 1;
  53853. state.head.done = true;
  53854. }
  53855. strm.adler = state.check = 0;
  53856. state.mode = TYPE;
  53857. break;
  53858. case DICTID:
  53859. //=== NEEDBITS(32); */
  53860. while (bits < 32) {
  53861. if (have === 0) {
  53862. break inf_leave;
  53863. }
  53864. have--;
  53865. hold += input[next++] << bits;
  53866. bits += 8;
  53867. } //===//
  53868. strm.adler = state.check = zswap32(hold); //=== INITBITS();
  53869. hold = 0;
  53870. bits = 0; //===//
  53871. state.mode = DICT;
  53872. /* falls through */
  53873. case DICT:
  53874. if (state.havedict === 0) {
  53875. //--- RESTORE() ---
  53876. strm.next_out = put;
  53877. strm.avail_out = left;
  53878. strm.next_in = next;
  53879. strm.avail_in = have;
  53880. state.hold = hold;
  53881. state.bits = bits; //---
  53882. return Z_NEED_DICT;
  53883. }
  53884. strm.adler = state.check = 1
  53885. /*adler32(0L, Z_NULL, 0)*/
  53886. ;
  53887. state.mode = TYPE;
  53888. /* falls through */
  53889. case TYPE:
  53890. if (flush === Z_BLOCK || flush === Z_TREES) {
  53891. break inf_leave;
  53892. }
  53893. /* falls through */
  53894. case TYPEDO:
  53895. if (state.last) {
  53896. //--- BYTEBITS() ---//
  53897. hold >>>= bits & 7;
  53898. bits -= bits & 7; //---//
  53899. state.mode = CHECK;
  53900. break;
  53901. } //=== NEEDBITS(3); */
  53902. while (bits < 3) {
  53903. if (have === 0) {
  53904. break inf_leave;
  53905. }
  53906. have--;
  53907. hold += input[next++] << bits;
  53908. bits += 8;
  53909. } //===//
  53910. state.last = hold & 0x01
  53911. /*BITS(1)*/
  53912. ; //--- DROPBITS(1) ---//
  53913. hold >>>= 1;
  53914. bits -= 1; //---//
  53915. switch (hold & 0x03) {
  53916. /*BITS(2)*/
  53917. case 0:
  53918. /* stored block */
  53919. //Tracev((stderr, "inflate: stored block%s\n",
  53920. // state.last ? " (last)" : ""));
  53921. state.mode = STORED;
  53922. break;
  53923. case 1:
  53924. /* fixed block */
  53925. fixedtables(state); //Tracev((stderr, "inflate: fixed codes block%s\n",
  53926. // state.last ? " (last)" : ""));
  53927. state.mode = LEN_;
  53928. /* decode codes */
  53929. if (flush === Z_TREES) {
  53930. //--- DROPBITS(2) ---//
  53931. hold >>>= 2;
  53932. bits -= 2; //---//
  53933. break inf_leave;
  53934. }
  53935. break;
  53936. case 2:
  53937. /* dynamic block */
  53938. //Tracev((stderr, "inflate: dynamic codes block%s\n",
  53939. // state.last ? " (last)" : ""));
  53940. state.mode = TABLE;
  53941. break;
  53942. case 3:
  53943. strm.msg = 'invalid block type';
  53944. state.mode = BAD;
  53945. } //--- DROPBITS(2) ---//
  53946. hold >>>= 2;
  53947. bits -= 2; //---//
  53948. break;
  53949. case STORED:
  53950. //--- BYTEBITS() ---// /* go to byte boundary */
  53951. hold >>>= bits & 7;
  53952. bits -= bits & 7; //---//
  53953. //=== NEEDBITS(32); */
  53954. while (bits < 32) {
  53955. if (have === 0) {
  53956. break inf_leave;
  53957. }
  53958. have--;
  53959. hold += input[next++] << bits;
  53960. bits += 8;
  53961. } //===//
  53962. if ((hold & 0xffff) !== (hold >>> 16 ^ 0xffff)) {
  53963. strm.msg = 'invalid stored block lengths';
  53964. state.mode = BAD;
  53965. break;
  53966. }
  53967. state.length = hold & 0xffff; //Tracev((stderr, "inflate: stored length %u\n",
  53968. // state.length));
  53969. //=== INITBITS();
  53970. hold = 0;
  53971. bits = 0; //===//
  53972. state.mode = COPY_;
  53973. if (flush === Z_TREES) {
  53974. break inf_leave;
  53975. }
  53976. /* falls through */
  53977. case COPY_:
  53978. state.mode = COPY;
  53979. /* falls through */
  53980. case COPY:
  53981. copy = state.length;
  53982. if (copy) {
  53983. if (copy > have) {
  53984. copy = have;
  53985. }
  53986. if (copy > left) {
  53987. copy = left;
  53988. }
  53989. if (copy === 0) {
  53990. break inf_leave;
  53991. } //--- zmemcpy(put, next, copy); ---
  53992. utils.arraySet(output, input, next, copy, put); //---//
  53993. have -= copy;
  53994. next += copy;
  53995. left -= copy;
  53996. put += copy;
  53997. state.length -= copy;
  53998. break;
  53999. } //Tracev((stderr, "inflate: stored end\n"));
  54000. state.mode = TYPE;
  54001. break;
  54002. case TABLE:
  54003. //=== NEEDBITS(14); */
  54004. while (bits < 14) {
  54005. if (have === 0) {
  54006. break inf_leave;
  54007. }
  54008. have--;
  54009. hold += input[next++] << bits;
  54010. bits += 8;
  54011. } //===//
  54012. state.nlen = (hold & 0x1f) +
  54013. /*BITS(5)*/
  54014. 257; //--- DROPBITS(5) ---//
  54015. hold >>>= 5;
  54016. bits -= 5; //---//
  54017. state.ndist = (hold & 0x1f) +
  54018. /*BITS(5)*/
  54019. 1; //--- DROPBITS(5) ---//
  54020. hold >>>= 5;
  54021. bits -= 5; //---//
  54022. state.ncode = (hold & 0x0f) +
  54023. /*BITS(4)*/
  54024. 4; //--- DROPBITS(4) ---//
  54025. hold >>>= 4;
  54026. bits -= 4; //---//
  54027. //#ifndef PKZIP_BUG_WORKAROUND
  54028. if (state.nlen > 286 || state.ndist > 30) {
  54029. strm.msg = 'too many length or distance symbols';
  54030. state.mode = BAD;
  54031. break;
  54032. } //#endif
  54033. //Tracev((stderr, "inflate: table sizes ok\n"));
  54034. state.have = 0;
  54035. state.mode = LENLENS;
  54036. /* falls through */
  54037. case LENLENS:
  54038. while (state.have < state.ncode) {
  54039. //=== NEEDBITS(3);
  54040. while (bits < 3) {
  54041. if (have === 0) {
  54042. break inf_leave;
  54043. }
  54044. have--;
  54045. hold += input[next++] << bits;
  54046. bits += 8;
  54047. } //===//
  54048. state.lens[order[state.have++]] = hold & 0x07; //BITS(3);
  54049. //--- DROPBITS(3) ---//
  54050. hold >>>= 3;
  54051. bits -= 3; //---//
  54052. }
  54053. while (state.have < 19) {
  54054. state.lens[order[state.have++]] = 0;
  54055. } // We have separate tables & no pointers. 2 commented lines below not needed.
  54056. //state.next = state.codes;
  54057. //state.lencode = state.next;
  54058. // Switch to use dynamic table
  54059. state.lencode = state.lendyn;
  54060. state.lenbits = 7;
  54061. opts = {
  54062. bits: state.lenbits
  54063. };
  54064. ret = inflate_table(CODES, state.lens, 0, 19, state.lencode, 0, state.work, opts);
  54065. state.lenbits = opts.bits;
  54066. if (ret) {
  54067. strm.msg = 'invalid code lengths set';
  54068. state.mode = BAD;
  54069. break;
  54070. } //Tracev((stderr, "inflate: code lengths ok\n"));
  54071. state.have = 0;
  54072. state.mode = CODELENS;
  54073. /* falls through */
  54074. case CODELENS:
  54075. while (state.have < state.nlen + state.ndist) {
  54076. for (;;) {
  54077. here = state.lencode[hold & (1 << state.lenbits) - 1];
  54078. /*BITS(state.lenbits)*/
  54079. here_bits = here >>> 24;
  54080. here_op = here >>> 16 & 0xff;
  54081. here_val = here & 0xffff;
  54082. if (here_bits <= bits) {
  54083. break;
  54084. } //--- PULLBYTE() ---//
  54085. if (have === 0) {
  54086. break inf_leave;
  54087. }
  54088. have--;
  54089. hold += input[next++] << bits;
  54090. bits += 8; //---//
  54091. }
  54092. if (here_val < 16) {
  54093. //--- DROPBITS(here.bits) ---//
  54094. hold >>>= here_bits;
  54095. bits -= here_bits; //---//
  54096. state.lens[state.have++] = here_val;
  54097. } else {
  54098. if (here_val === 16) {
  54099. //=== NEEDBITS(here.bits + 2);
  54100. n = here_bits + 2;
  54101. while (bits < n) {
  54102. if (have === 0) {
  54103. break inf_leave;
  54104. }
  54105. have--;
  54106. hold += input[next++] << bits;
  54107. bits += 8;
  54108. } //===//
  54109. //--- DROPBITS(here.bits) ---//
  54110. hold >>>= here_bits;
  54111. bits -= here_bits; //---//
  54112. if (state.have === 0) {
  54113. strm.msg = 'invalid bit length repeat';
  54114. state.mode = BAD;
  54115. break;
  54116. }
  54117. len = state.lens[state.have - 1];
  54118. copy = 3 + (hold & 0x03); //BITS(2);
  54119. //--- DROPBITS(2) ---//
  54120. hold >>>= 2;
  54121. bits -= 2; //---//
  54122. } else if (here_val === 17) {
  54123. //=== NEEDBITS(here.bits + 3);
  54124. n = here_bits + 3;
  54125. while (bits < n) {
  54126. if (have === 0) {
  54127. break inf_leave;
  54128. }
  54129. have--;
  54130. hold += input[next++] << bits;
  54131. bits += 8;
  54132. } //===//
  54133. //--- DROPBITS(here.bits) ---//
  54134. hold >>>= here_bits;
  54135. bits -= here_bits; //---//
  54136. len = 0;
  54137. copy = 3 + (hold & 0x07); //BITS(3);
  54138. //--- DROPBITS(3) ---//
  54139. hold >>>= 3;
  54140. bits -= 3; //---//
  54141. } else {
  54142. //=== NEEDBITS(here.bits + 7);
  54143. n = here_bits + 7;
  54144. while (bits < n) {
  54145. if (have === 0) {
  54146. break inf_leave;
  54147. }
  54148. have--;
  54149. hold += input[next++] << bits;
  54150. bits += 8;
  54151. } //===//
  54152. //--- DROPBITS(here.bits) ---//
  54153. hold >>>= here_bits;
  54154. bits -= here_bits; //---//
  54155. len = 0;
  54156. copy = 11 + (hold & 0x7f); //BITS(7);
  54157. //--- DROPBITS(7) ---//
  54158. hold >>>= 7;
  54159. bits -= 7; //---//
  54160. }
  54161. if (state.have + copy > state.nlen + state.ndist) {
  54162. strm.msg = 'invalid bit length repeat';
  54163. state.mode = BAD;
  54164. break;
  54165. }
  54166. while (copy--) {
  54167. state.lens[state.have++] = len;
  54168. }
  54169. }
  54170. }
  54171. /* handle error breaks in while */
  54172. if (state.mode === BAD) {
  54173. break;
  54174. }
  54175. /* check for end-of-block code (better have one) */
  54176. if (state.lens[256] === 0) {
  54177. strm.msg = 'invalid code -- missing end-of-block';
  54178. state.mode = BAD;
  54179. break;
  54180. }
  54181. /* build code tables -- note: do not change the lenbits or distbits
  54182. values here (9 and 6) without reading the comments in inftrees.h
  54183. concerning the ENOUGH constants, which depend on those values */
  54184. state.lenbits = 9;
  54185. opts = {
  54186. bits: state.lenbits
  54187. };
  54188. ret = inflate_table(LENS, state.lens, 0, state.nlen, state.lencode, 0, state.work, opts); // We have separate tables & no pointers. 2 commented lines below not needed.
  54189. // state.next_index = opts.table_index;
  54190. state.lenbits = opts.bits; // state.lencode = state.next;
  54191. if (ret) {
  54192. strm.msg = 'invalid literal/lengths set';
  54193. state.mode = BAD;
  54194. break;
  54195. }
  54196. state.distbits = 6; //state.distcode.copy(state.codes);
  54197. // Switch to use dynamic table
  54198. state.distcode = state.distdyn;
  54199. opts = {
  54200. bits: state.distbits
  54201. };
  54202. ret = inflate_table(DISTS, state.lens, state.nlen, state.ndist, state.distcode, 0, state.work, opts); // We have separate tables & no pointers. 2 commented lines below not needed.
  54203. // state.next_index = opts.table_index;
  54204. state.distbits = opts.bits; // state.distcode = state.next;
  54205. if (ret) {
  54206. strm.msg = 'invalid distances set';
  54207. state.mode = BAD;
  54208. break;
  54209. } //Tracev((stderr, 'inflate: codes ok\n'));
  54210. state.mode = LEN_;
  54211. if (flush === Z_TREES) {
  54212. break inf_leave;
  54213. }
  54214. /* falls through */
  54215. case LEN_:
  54216. state.mode = LEN;
  54217. /* falls through */
  54218. case LEN:
  54219. if (have >= 6 && left >= 258) {
  54220. //--- RESTORE() ---
  54221. strm.next_out = put;
  54222. strm.avail_out = left;
  54223. strm.next_in = next;
  54224. strm.avail_in = have;
  54225. state.hold = hold;
  54226. state.bits = bits; //---
  54227. inflate_fast(strm, _out); //--- LOAD() ---
  54228. put = strm.next_out;
  54229. output = strm.output;
  54230. left = strm.avail_out;
  54231. next = strm.next_in;
  54232. input = strm.input;
  54233. have = strm.avail_in;
  54234. hold = state.hold;
  54235. bits = state.bits; //---
  54236. if (state.mode === TYPE) {
  54237. state.back = -1;
  54238. }
  54239. break;
  54240. }
  54241. state.back = 0;
  54242. for (;;) {
  54243. here = state.lencode[hold & (1 << state.lenbits) - 1];
  54244. /*BITS(state.lenbits)*/
  54245. here_bits = here >>> 24;
  54246. here_op = here >>> 16 & 0xff;
  54247. here_val = here & 0xffff;
  54248. if (here_bits <= bits) {
  54249. break;
  54250. } //--- PULLBYTE() ---//
  54251. if (have === 0) {
  54252. break inf_leave;
  54253. }
  54254. have--;
  54255. hold += input[next++] << bits;
  54256. bits += 8; //---//
  54257. }
  54258. if (here_op && (here_op & 0xf0) === 0) {
  54259. last_bits = here_bits;
  54260. last_op = here_op;
  54261. last_val = here_val;
  54262. for (;;) {
  54263. here = state.lencode[last_val + ((hold & (1 << last_bits + last_op) - 1) >>
  54264. /*BITS(last.bits + last.op)*/
  54265. last_bits)];
  54266. here_bits = here >>> 24;
  54267. here_op = here >>> 16 & 0xff;
  54268. here_val = here & 0xffff;
  54269. if (last_bits + here_bits <= bits) {
  54270. break;
  54271. } //--- PULLBYTE() ---//
  54272. if (have === 0) {
  54273. break inf_leave;
  54274. }
  54275. have--;
  54276. hold += input[next++] << bits;
  54277. bits += 8; //---//
  54278. } //--- DROPBITS(last.bits) ---//
  54279. hold >>>= last_bits;
  54280. bits -= last_bits; //---//
  54281. state.back += last_bits;
  54282. } //--- DROPBITS(here.bits) ---//
  54283. hold >>>= here_bits;
  54284. bits -= here_bits; //---//
  54285. state.back += here_bits;
  54286. state.length = here_val;
  54287. if (here_op === 0) {
  54288. //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
  54289. // "inflate: literal '%c'\n" :
  54290. // "inflate: literal 0x%02x\n", here.val));
  54291. state.mode = LIT;
  54292. break;
  54293. }
  54294. if (here_op & 32) {
  54295. //Tracevv((stderr, "inflate: end of block\n"));
  54296. state.back = -1;
  54297. state.mode = TYPE;
  54298. break;
  54299. }
  54300. if (here_op & 64) {
  54301. strm.msg = 'invalid literal/length code';
  54302. state.mode = BAD;
  54303. break;
  54304. }
  54305. state.extra = here_op & 15;
  54306. state.mode = LENEXT;
  54307. /* falls through */
  54308. case LENEXT:
  54309. if (state.extra) {
  54310. //=== NEEDBITS(state.extra);
  54311. n = state.extra;
  54312. while (bits < n) {
  54313. if (have === 0) {
  54314. break inf_leave;
  54315. }
  54316. have--;
  54317. hold += input[next++] << bits;
  54318. bits += 8;
  54319. } //===//
  54320. state.length += hold & (1 << state.extra) - 1
  54321. /*BITS(state.extra)*/
  54322. ; //--- DROPBITS(state.extra) ---//
  54323. hold >>>= state.extra;
  54324. bits -= state.extra; //---//
  54325. state.back += state.extra;
  54326. } //Tracevv((stderr, "inflate: length %u\n", state.length));
  54327. state.was = state.length;
  54328. state.mode = DIST;
  54329. /* falls through */
  54330. case DIST:
  54331. for (;;) {
  54332. here = state.distcode[hold & (1 << state.distbits) - 1];
  54333. /*BITS(state.distbits)*/
  54334. here_bits = here >>> 24;
  54335. here_op = here >>> 16 & 0xff;
  54336. here_val = here & 0xffff;
  54337. if (here_bits <= bits) {
  54338. break;
  54339. } //--- PULLBYTE() ---//
  54340. if (have === 0) {
  54341. break inf_leave;
  54342. }
  54343. have--;
  54344. hold += input[next++] << bits;
  54345. bits += 8; //---//
  54346. }
  54347. if ((here_op & 0xf0) === 0) {
  54348. last_bits = here_bits;
  54349. last_op = here_op;
  54350. last_val = here_val;
  54351. for (;;) {
  54352. here = state.distcode[last_val + ((hold & (1 << last_bits + last_op) - 1) >>
  54353. /*BITS(last.bits + last.op)*/
  54354. last_bits)];
  54355. here_bits = here >>> 24;
  54356. here_op = here >>> 16 & 0xff;
  54357. here_val = here & 0xffff;
  54358. if (last_bits + here_bits <= bits) {
  54359. break;
  54360. } //--- PULLBYTE() ---//
  54361. if (have === 0) {
  54362. break inf_leave;
  54363. }
  54364. have--;
  54365. hold += input[next++] << bits;
  54366. bits += 8; //---//
  54367. } //--- DROPBITS(last.bits) ---//
  54368. hold >>>= last_bits;
  54369. bits -= last_bits; //---//
  54370. state.back += last_bits;
  54371. } //--- DROPBITS(here.bits) ---//
  54372. hold >>>= here_bits;
  54373. bits -= here_bits; //---//
  54374. state.back += here_bits;
  54375. if (here_op & 64) {
  54376. strm.msg = 'invalid distance code';
  54377. state.mode = BAD;
  54378. break;
  54379. }
  54380. state.offset = here_val;
  54381. state.extra = here_op & 15;
  54382. state.mode = DISTEXT;
  54383. /* falls through */
  54384. case DISTEXT:
  54385. if (state.extra) {
  54386. //=== NEEDBITS(state.extra);
  54387. n = state.extra;
  54388. while (bits < n) {
  54389. if (have === 0) {
  54390. break inf_leave;
  54391. }
  54392. have--;
  54393. hold += input[next++] << bits;
  54394. bits += 8;
  54395. } //===//
  54396. state.offset += hold & (1 << state.extra) - 1
  54397. /*BITS(state.extra)*/
  54398. ; //--- DROPBITS(state.extra) ---//
  54399. hold >>>= state.extra;
  54400. bits -= state.extra; //---//
  54401. state.back += state.extra;
  54402. } //#ifdef INFLATE_STRICT
  54403. if (state.offset > state.dmax) {
  54404. strm.msg = 'invalid distance too far back';
  54405. state.mode = BAD;
  54406. break;
  54407. } //#endif
  54408. //Tracevv((stderr, "inflate: distance %u\n", state.offset));
  54409. state.mode = MATCH;
  54410. /* falls through */
  54411. case MATCH:
  54412. if (left === 0) {
  54413. break inf_leave;
  54414. }
  54415. copy = _out - left;
  54416. if (state.offset > copy) {
  54417. /* copy from window */
  54418. copy = state.offset - copy;
  54419. if (copy > state.whave) {
  54420. if (state.sane) {
  54421. strm.msg = 'invalid distance too far back';
  54422. state.mode = BAD;
  54423. break;
  54424. } // (!) This block is disabled in zlib defaults,
  54425. // don't enable it for binary compatibility
  54426. //#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
  54427. // Trace((stderr, "inflate.c too far\n"));
  54428. // copy -= state.whave;
  54429. // if (copy > state.length) { copy = state.length; }
  54430. // if (copy > left) { copy = left; }
  54431. // left -= copy;
  54432. // state.length -= copy;
  54433. // do {
  54434. // output[put++] = 0;
  54435. // } while (--copy);
  54436. // if (state.length === 0) { state.mode = LEN; }
  54437. // break;
  54438. //#endif
  54439. }
  54440. if (copy > state.wnext) {
  54441. copy -= state.wnext;
  54442. from = state.wsize - copy;
  54443. } else {
  54444. from = state.wnext - copy;
  54445. }
  54446. if (copy > state.length) {
  54447. copy = state.length;
  54448. }
  54449. from_source = state.window;
  54450. } else {
  54451. /* copy from output */
  54452. from_source = output;
  54453. from = put - state.offset;
  54454. copy = state.length;
  54455. }
  54456. if (copy > left) {
  54457. copy = left;
  54458. }
  54459. left -= copy;
  54460. state.length -= copy;
  54461. do {
  54462. output[put++] = from_source[from++];
  54463. } while (--copy);
  54464. if (state.length === 0) {
  54465. state.mode = LEN;
  54466. }
  54467. break;
  54468. case LIT:
  54469. if (left === 0) {
  54470. break inf_leave;
  54471. }
  54472. output[put++] = state.length;
  54473. left--;
  54474. state.mode = LEN;
  54475. break;
  54476. case CHECK:
  54477. if (state.wrap) {
  54478. //=== NEEDBITS(32);
  54479. while (bits < 32) {
  54480. if (have === 0) {
  54481. break inf_leave;
  54482. }
  54483. have--; // Use '|' instead of '+' to make sure that result is signed
  54484. hold |= input[next++] << bits;
  54485. bits += 8;
  54486. } //===//
  54487. _out -= left;
  54488. strm.total_out += _out;
  54489. state.total += _out;
  54490. if (_out) {
  54491. strm.adler = state.check =
  54492. /*UPDATE(state.check, put - _out, _out);*/
  54493. state.flags ? crc32(state.check, output, _out, put - _out) : adler32(state.check, output, _out, put - _out);
  54494. }
  54495. _out = left; // NB: crc32 stored as signed 32-bit int, zswap32 returns signed too
  54496. if ((state.flags ? hold : zswap32(hold)) !== state.check) {
  54497. strm.msg = 'incorrect data check';
  54498. state.mode = BAD;
  54499. break;
  54500. } //=== INITBITS();
  54501. hold = 0;
  54502. bits = 0; //===//
  54503. //Tracev((stderr, "inflate: check matches trailer\n"));
  54504. }
  54505. state.mode = LENGTH;
  54506. /* falls through */
  54507. case LENGTH:
  54508. if (state.wrap && state.flags) {
  54509. //=== NEEDBITS(32);
  54510. while (bits < 32) {
  54511. if (have === 0) {
  54512. break inf_leave;
  54513. }
  54514. have--;
  54515. hold += input[next++] << bits;
  54516. bits += 8;
  54517. } //===//
  54518. if (hold !== (state.total & 0xffffffff)) {
  54519. strm.msg = 'incorrect length check';
  54520. state.mode = BAD;
  54521. break;
  54522. } //=== INITBITS();
  54523. hold = 0;
  54524. bits = 0; //===//
  54525. //Tracev((stderr, "inflate: length matches trailer\n"));
  54526. }
  54527. state.mode = DONE;
  54528. /* falls through */
  54529. case DONE:
  54530. ret = Z_STREAM_END;
  54531. break inf_leave;
  54532. case BAD:
  54533. ret = Z_DATA_ERROR;
  54534. break inf_leave;
  54535. case MEM:
  54536. return Z_MEM_ERROR;
  54537. case SYNC:
  54538. /* falls through */
  54539. default:
  54540. return Z_STREAM_ERROR;
  54541. }
  54542. } // inf_leave <- here is real place for "goto inf_leave", emulated via "break inf_leave"
  54543. /*
  54544. Return from inflate(), updating the total counts and the check value.
  54545. If there was no progress during the inflate() call, return a buffer
  54546. error. Call updatewindow() to create and/or update the window state.
  54547. Note: a memory error from inflate() is non-recoverable.
  54548. */
  54549. //--- RESTORE() ---
  54550. strm.next_out = put;
  54551. strm.avail_out = left;
  54552. strm.next_in = next;
  54553. strm.avail_in = have;
  54554. state.hold = hold;
  54555. state.bits = bits; //---
  54556. if (state.wsize || _out !== strm.avail_out && state.mode < BAD && (state.mode < CHECK || flush !== Z_FINISH)) {
  54557. if (updatewindow(strm, strm.output, strm.next_out, _out - strm.avail_out)) {
  54558. state.mode = MEM;
  54559. return Z_MEM_ERROR;
  54560. }
  54561. }
  54562. _in -= strm.avail_in;
  54563. _out -= strm.avail_out;
  54564. strm.total_in += _in;
  54565. strm.total_out += _out;
  54566. state.total += _out;
  54567. if (state.wrap && _out) {
  54568. strm.adler = state.check =
  54569. /*UPDATE(state.check, strm.next_out - _out, _out);*/
  54570. state.flags ? crc32(state.check, output, _out, strm.next_out - _out) : adler32(state.check, output, _out, strm.next_out - _out);
  54571. }
  54572. strm.data_type = state.bits + (state.last ? 64 : 0) + (state.mode === TYPE ? 128 : 0) + (state.mode === LEN_ || state.mode === COPY_ ? 256 : 0);
  54573. if ((_in === 0 && _out === 0 || flush === Z_FINISH) && ret === Z_OK) {
  54574. ret = Z_BUF_ERROR;
  54575. }
  54576. return ret;
  54577. }
  54578. function inflateEnd(strm) {
  54579. if (!strm || !strm.state
  54580. /*|| strm->zfree == (free_func)0*/
  54581. ) {
  54582. return Z_STREAM_ERROR;
  54583. }
  54584. var state = strm.state;
  54585. if (state.window) {
  54586. state.window = null;
  54587. }
  54588. strm.state = null;
  54589. return Z_OK;
  54590. }
  54591. function inflateGetHeader(strm, head) {
  54592. var state;
  54593. /* check state */
  54594. if (!strm || !strm.state) {
  54595. return Z_STREAM_ERROR;
  54596. }
  54597. state = strm.state;
  54598. if ((state.wrap & 2) === 0) {
  54599. return Z_STREAM_ERROR;
  54600. }
  54601. /* save header structure */
  54602. state.head = head;
  54603. head.done = false;
  54604. return Z_OK;
  54605. }
  54606. function inflateSetDictionary(strm, dictionary) {
  54607. var dictLength = dictionary.length;
  54608. var state;
  54609. var dictid;
  54610. var ret;
  54611. /* check state */
  54612. if (!strm
  54613. /* == Z_NULL */
  54614. || !strm.state
  54615. /* == Z_NULL */
  54616. ) {
  54617. return Z_STREAM_ERROR;
  54618. }
  54619. state = strm.state;
  54620. if (state.wrap !== 0 && state.mode !== DICT) {
  54621. return Z_STREAM_ERROR;
  54622. }
  54623. /* check for correct dictionary identifier */
  54624. if (state.mode === DICT) {
  54625. dictid = 1;
  54626. /* adler32(0, null, 0)*/
  54627. /* dictid = adler32(dictid, dictionary, dictLength); */
  54628. dictid = adler32(dictid, dictionary, dictLength, 0);
  54629. if (dictid !== state.check) {
  54630. return Z_DATA_ERROR;
  54631. }
  54632. }
  54633. /* copy dictionary to window using updatewindow(), which will amend the
  54634. existing dictionary if appropriate */
  54635. ret = updatewindow(strm, dictionary, dictLength, dictLength);
  54636. if (ret) {
  54637. state.mode = MEM;
  54638. return Z_MEM_ERROR;
  54639. }
  54640. state.havedict = 1; // Tracev((stderr, "inflate: dictionary set\n"));
  54641. return Z_OK;
  54642. }
  54643. exports.inflateReset = inflateReset;
  54644. exports.inflateReset2 = inflateReset2;
  54645. exports.inflateResetKeep = inflateResetKeep;
  54646. exports.inflateInit = inflateInit;
  54647. exports.inflateInit2 = inflateInit2;
  54648. exports.inflate = inflate;
  54649. exports.inflateEnd = inflateEnd;
  54650. exports.inflateGetHeader = inflateGetHeader;
  54651. exports.inflateSetDictionary = inflateSetDictionary;
  54652. exports.inflateInfo = 'pako inflate (from Nodeca project)';
  54653. /* Not implemented
  54654. exports.inflateCopy = inflateCopy;
  54655. exports.inflateGetDictionary = inflateGetDictionary;
  54656. exports.inflateMark = inflateMark;
  54657. exports.inflatePrime = inflatePrime;
  54658. exports.inflateSync = inflateSync;
  54659. exports.inflateSyncPoint = inflateSyncPoint;
  54660. exports.inflateUndermine = inflateUndermine;
  54661. */
  54662. },{"../utils/common":442,"./adler32":444,"./crc32":446,"./inffast":449,"./inftrees":451}],451:[function(require,module,exports){
  54663. 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  54664. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  54665. //
  54666. // This software is provided 'as-is', without any express or implied
  54667. // warranty. In no event will the authors be held liable for any damages
  54668. // arising from the use of this software.
  54669. //
  54670. // Permission is granted to anyone to use this software for any purpose,
  54671. // including commercial applications, and to alter it and redistribute it
  54672. // freely, subject to the following restrictions:
  54673. //
  54674. // 1. The origin of this software must not be misrepresented; you must not
  54675. // claim that you wrote the original software. If you use this software
  54676. // in a product, an acknowledgment in the product documentation would be
  54677. // appreciated but is not required.
  54678. // 2. Altered source versions must be plainly marked as such, and must not be
  54679. // misrepresented as being the original software.
  54680. // 3. This notice may not be removed or altered from any source distribution.
  54681. var utils = require('../utils/common');
  54682. var MAXBITS = 15;
  54683. var ENOUGH_LENS = 852;
  54684. var ENOUGH_DISTS = 592; //var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);
  54685. var CODES = 0;
  54686. var LENS = 1;
  54687. var DISTS = 2;
  54688. var lbase = [
  54689. /* Length codes 257..285 base */
  54690. 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];
  54691. var lext = [
  54692. /* Length codes 257..285 extra */
  54693. 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];
  54694. var dbase = [
  54695. /* Distance codes 0..29 base */
  54696. 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];
  54697. var dext = [
  54698. /* Distance codes 0..29 extra */
  54699. 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];
  54700. module.exports = function inflate_table(type, lens, lens_index, codes, table, table_index, work, opts) {
  54701. var bits = opts.bits; //here = opts.here; /* table entry for duplication */
  54702. var len = 0;
  54703. /* a code's length in bits */
  54704. var sym = 0;
  54705. /* index of code symbols */
  54706. var min = 0,
  54707. max = 0;
  54708. /* minimum and maximum code lengths */
  54709. var root = 0;
  54710. /* number of index bits for root table */
  54711. var curr = 0;
  54712. /* number of index bits for current table */
  54713. var drop = 0;
  54714. /* code bits to drop for sub-table */
  54715. var left = 0;
  54716. /* number of prefix codes available */
  54717. var used = 0;
  54718. /* code entries in table used */
  54719. var huff = 0;
  54720. /* Huffman code */
  54721. var incr;
  54722. /* for incrementing code, index */
  54723. var fill;
  54724. /* index for replicating entries */
  54725. var low;
  54726. /* low bits for current root entry */
  54727. var mask;
  54728. /* mask for low root bits */
  54729. var next;
  54730. /* next available space in table */
  54731. var base = null;
  54732. /* base value table to use */
  54733. var base_index = 0; // var shoextra; /* extra bits table to use */
  54734. var end;
  54735. /* use base and extra for symbol > end */
  54736. var count = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1]; /* number of codes of each length */
  54737. var offs = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1]; /* offsets in table for each length */
  54738. var extra = null;
  54739. var extra_index = 0;
  54740. var here_bits, here_op, here_val;
  54741. /*
  54742. Process a set of code lengths to create a canonical Huffman code. The
  54743. code lengths are lens[0..codes-1]. Each length corresponds to the
  54744. symbols 0..codes-1. The Huffman code is generated by first sorting the
  54745. symbols by length from short to long, and retaining the symbol order
  54746. for codes with equal lengths. Then the code starts with all zero bits
  54747. for the first code of the shortest length, and the codes are integer
  54748. increments for the same length, and zeros are appended as the length
  54749. increases. For the deflate format, these bits are stored backwards
  54750. from their more natural integer increment ordering, and so when the
  54751. decoding tables are built in the large loop below, the integer codes
  54752. are incremented backwards.
  54753. This routine assumes, but does not check, that all of the entries in
  54754. lens[] are in the range 0..MAXBITS. The caller must assure this.
  54755. 1..MAXBITS is interpreted as that code length. zero means that that
  54756. symbol does not occur in this code.
  54757. The codes are sorted by computing a count of codes for each length,
  54758. creating from that a table of starting indices for each length in the
  54759. sorted table, and then entering the symbols in order in the sorted
  54760. table. The sorted table is work[], with that space being provided by
  54761. the caller.
  54762. The length counts are used for other purposes as well, i.e. finding
  54763. the minimum and maximum length codes, determining if there are any
  54764. codes at all, checking for a valid set of lengths, and looking ahead
  54765. at length counts to determine sub-table sizes when building the
  54766. decoding tables.
  54767. */
  54768. /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
  54769. for (len = 0; len <= MAXBITS; len++) {
  54770. count[len] = 0;
  54771. }
  54772. for (sym = 0; sym < codes; sym++) {
  54773. count[lens[lens_index + sym]]++;
  54774. }
  54775. /* bound code lengths, force root to be within code lengths */
  54776. root = bits;
  54777. for (max = MAXBITS; max >= 1; max--) {
  54778. if (count[max] !== 0) {
  54779. break;
  54780. }
  54781. }
  54782. if (root > max) {
  54783. root = max;
  54784. }
  54785. if (max === 0) {
  54786. /* no symbols to code at all */
  54787. //table.op[opts.table_index] = 64; //here.op = (var char)64; /* invalid code marker */
  54788. //table.bits[opts.table_index] = 1; //here.bits = (var char)1;
  54789. //table.val[opts.table_index++] = 0; //here.val = (var short)0;
  54790. table[table_index++] = 1 << 24 | 64 << 16 | 0; //table.op[opts.table_index] = 64;
  54791. //table.bits[opts.table_index] = 1;
  54792. //table.val[opts.table_index++] = 0;
  54793. table[table_index++] = 1 << 24 | 64 << 16 | 0;
  54794. opts.bits = 1;
  54795. return 0;
  54796. /* no symbols, but wait for decoding to report error */
  54797. }
  54798. for (min = 1; min < max; min++) {
  54799. if (count[min] !== 0) {
  54800. break;
  54801. }
  54802. }
  54803. if (root < min) {
  54804. root = min;
  54805. }
  54806. /* check for an over-subscribed or incomplete set of lengths */
  54807. left = 1;
  54808. for (len = 1; len <= MAXBITS; len++) {
  54809. left <<= 1;
  54810. left -= count[len];
  54811. if (left < 0) {
  54812. return -1;
  54813. }
  54814. /* over-subscribed */
  54815. }
  54816. if (left > 0 && (type === CODES || max !== 1)) {
  54817. return -1;
  54818. /* incomplete set */
  54819. }
  54820. /* generate offsets into symbol table for each length for sorting */
  54821. offs[1] = 0;
  54822. for (len = 1; len < MAXBITS; len++) {
  54823. offs[len + 1] = offs[len] + count[len];
  54824. }
  54825. /* sort symbols by length, by symbol order within each length */
  54826. for (sym = 0; sym < codes; sym++) {
  54827. if (lens[lens_index + sym] !== 0) {
  54828. work[offs[lens[lens_index + sym]]++] = sym;
  54829. }
  54830. }
  54831. /*
  54832. Create and fill in decoding tables. In this loop, the table being
  54833. filled is at next and has curr index bits. The code being used is huff
  54834. with length len. That code is converted to an index by dropping drop
  54835. bits off of the bottom. For codes where len is less than drop + curr,
  54836. those top drop + curr - len bits are incremented through all values to
  54837. fill the table with replicated entries.
  54838. root is the number of index bits for the root table. When len exceeds
  54839. root, sub-tables are created pointed to by the root entry with an index
  54840. of the low root bits of huff. This is saved in low to check for when a
  54841. new sub-table should be started. drop is zero when the root table is
  54842. being filled, and drop is root when sub-tables are being filled.
  54843. When a new sub-table is needed, it is necessary to look ahead in the
  54844. code lengths to determine what size sub-table is needed. The length
  54845. counts are used for this, and so count[] is decremented as codes are
  54846. entered in the tables.
  54847. used keeps track of how many table entries have been allocated from the
  54848. provided *table space. It is checked for LENS and DIST tables against
  54849. the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
  54850. the initial root table size constants. See the comments in inftrees.h
  54851. for more information.
  54852. sym increments through all symbols, and the loop terminates when
  54853. all codes of length max, i.e. all codes, have been processed. This
  54854. routine permits incomplete codes, so another loop after this one fills
  54855. in the rest of the decoding tables with invalid code markers.
  54856. */
  54857. /* set up for code type */
  54858. // poor man optimization - use if-else instead of switch,
  54859. // to avoid deopts in old v8
  54860. if (type === CODES) {
  54861. base = extra = work;
  54862. /* dummy value--not used */
  54863. end = 19;
  54864. } else if (type === LENS) {
  54865. base = lbase;
  54866. base_index -= 257;
  54867. extra = lext;
  54868. extra_index -= 257;
  54869. end = 256;
  54870. } else {
  54871. /* DISTS */
  54872. base = dbase;
  54873. extra = dext;
  54874. end = -1;
  54875. }
  54876. /* initialize opts for loop */
  54877. huff = 0;
  54878. /* starting code */
  54879. sym = 0;
  54880. /* starting code symbol */
  54881. len = min;
  54882. /* starting code length */
  54883. next = table_index;
  54884. /* current table to fill in */
  54885. curr = root;
  54886. /* current table index bits */
  54887. drop = 0;
  54888. /* current bits to drop from code for index */
  54889. low = -1;
  54890. /* trigger new sub-table when len > root */
  54891. used = 1 << root;
  54892. /* use root table entries */
  54893. mask = used - 1;
  54894. /* mask for comparing low */
  54895. /* check available table space */
  54896. if (type === LENS && used > ENOUGH_LENS || type === DISTS && used > ENOUGH_DISTS) {
  54897. return 1;
  54898. }
  54899. /* process all codes and make table entries */
  54900. for (;;) {
  54901. /* create table entry */
  54902. here_bits = len - drop;
  54903. if (work[sym] < end) {
  54904. here_op = 0;
  54905. here_val = work[sym];
  54906. } else if (work[sym] > end) {
  54907. here_op = extra[extra_index + work[sym]];
  54908. here_val = base[base_index + work[sym]];
  54909. } else {
  54910. here_op = 32 + 64;
  54911. /* end of block */
  54912. here_val = 0;
  54913. }
  54914. /* replicate for those indices with low len bits equal to huff */
  54915. incr = 1 << len - drop;
  54916. fill = 1 << curr;
  54917. min = fill;
  54918. /* save offset to next table */
  54919. do {
  54920. fill -= incr;
  54921. table[next + (huff >> drop) + fill] = here_bits << 24 | here_op << 16 | here_val | 0;
  54922. } while (fill !== 0);
  54923. /* backwards increment the len-bit code huff */
  54924. incr = 1 << len - 1;
  54925. while (huff & incr) {
  54926. incr >>= 1;
  54927. }
  54928. if (incr !== 0) {
  54929. huff &= incr - 1;
  54930. huff += incr;
  54931. } else {
  54932. huff = 0;
  54933. }
  54934. /* go to next symbol, update count, len */
  54935. sym++;
  54936. if (--count[len] === 0) {
  54937. if (len === max) {
  54938. break;
  54939. }
  54940. len = lens[lens_index + work[sym]];
  54941. }
  54942. /* create new sub-table if needed */
  54943. if (len > root && (huff & mask) !== low) {
  54944. /* if first time, transition to sub-tables */
  54945. if (drop === 0) {
  54946. drop = root;
  54947. }
  54948. /* increment past last table */
  54949. next += min;
  54950. /* here min is 1 << curr */
  54951. /* determine length of next table */
  54952. curr = len - drop;
  54953. left = 1 << curr;
  54954. while (curr + drop < max) {
  54955. left -= count[curr + drop];
  54956. if (left <= 0) {
  54957. break;
  54958. }
  54959. curr++;
  54960. left <<= 1;
  54961. }
  54962. /* check for enough space */
  54963. used += 1 << curr;
  54964. if (type === LENS && used > ENOUGH_LENS || type === DISTS && used > ENOUGH_DISTS) {
  54965. return 1;
  54966. }
  54967. /* point entry in root table to sub-table */
  54968. low = huff & mask;
  54969. /*table.op[low] = curr;
  54970. table.bits[low] = root;
  54971. table.val[low] = next - opts.table_index;*/
  54972. table[low] = root << 24 | curr << 16 | next - table_index | 0;
  54973. }
  54974. }
  54975. /* fill in remaining table entry if code is incomplete (guaranteed to have
  54976. at most one remaining entry, since if the code is incomplete, the
  54977. maximum code length that was allowed to get this far is one bit) */
  54978. if (huff !== 0) {
  54979. //table.op[next + huff] = 64; /* invalid code marker */
  54980. //table.bits[next + huff] = len - drop;
  54981. //table.val[next + huff] = 0;
  54982. table[next + huff] = len - drop << 24 | 64 << 16 | 0;
  54983. }
  54984. /* set return parameters */
  54985. //opts.table_index += used;
  54986. opts.bits = root;
  54987. return 0;
  54988. };
  54989. },{"../utils/common":442}],452:[function(require,module,exports){
  54990. 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  54991. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  54992. //
  54993. // This software is provided 'as-is', without any express or implied
  54994. // warranty. In no event will the authors be held liable for any damages
  54995. // arising from the use of this software.
  54996. //
  54997. // Permission is granted to anyone to use this software for any purpose,
  54998. // including commercial applications, and to alter it and redistribute it
  54999. // freely, subject to the following restrictions:
  55000. //
  55001. // 1. The origin of this software must not be misrepresented; you must not
  55002. // claim that you wrote the original software. If you use this software
  55003. // in a product, an acknowledgment in the product documentation would be
  55004. // appreciated but is not required.
  55005. // 2. Altered source versions must be plainly marked as such, and must not be
  55006. // misrepresented as being the original software.
  55007. // 3. This notice may not be removed or altered from any source distribution.
  55008. module.exports = {
  55009. 2: 'need dictionary',
  55010. /* Z_NEED_DICT 2 */
  55011. 1: 'stream end',
  55012. /* Z_STREAM_END 1 */
  55013. 0: '',
  55014. /* Z_OK 0 */
  55015. '-1': 'file error',
  55016. /* Z_ERRNO (-1) */
  55017. '-2': 'stream error',
  55018. /* Z_STREAM_ERROR (-2) */
  55019. '-3': 'data error',
  55020. /* Z_DATA_ERROR (-3) */
  55021. '-4': 'insufficient memory',
  55022. /* Z_MEM_ERROR (-4) */
  55023. '-5': 'buffer error',
  55024. /* Z_BUF_ERROR (-5) */
  55025. '-6': 'incompatible version'
  55026. /* Z_VERSION_ERROR (-6) */
  55027. };
  55028. },{}],453:[function(require,module,exports){
  55029. 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  55030. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  55031. //
  55032. // This software is provided 'as-is', without any express or implied
  55033. // warranty. In no event will the authors be held liable for any damages
  55034. // arising from the use of this software.
  55035. //
  55036. // Permission is granted to anyone to use this software for any purpose,
  55037. // including commercial applications, and to alter it and redistribute it
  55038. // freely, subject to the following restrictions:
  55039. //
  55040. // 1. The origin of this software must not be misrepresented; you must not
  55041. // claim that you wrote the original software. If you use this software
  55042. // in a product, an acknowledgment in the product documentation would be
  55043. // appreciated but is not required.
  55044. // 2. Altered source versions must be plainly marked as such, and must not be
  55045. // misrepresented as being the original software.
  55046. // 3. This notice may not be removed or altered from any source distribution.
  55047. /* eslint-disable space-unary-ops */
  55048. var utils = require('../utils/common');
  55049. /* Public constants ==========================================================*/
  55050. /* ===========================================================================*/
  55051. //var Z_FILTERED = 1;
  55052. //var Z_HUFFMAN_ONLY = 2;
  55053. //var Z_RLE = 3;
  55054. var Z_FIXED = 4; //var Z_DEFAULT_STRATEGY = 0;
  55055. /* Possible values of the data_type field (though see inflate()) */
  55056. var Z_BINARY = 0;
  55057. var Z_TEXT = 1; //var Z_ASCII = 1; // = Z_TEXT
  55058. var Z_UNKNOWN = 2;
  55059. /*============================================================================*/
  55060. function zero(buf) {
  55061. var len = buf.length;
  55062. while (--len >= 0) {
  55063. buf[len] = 0;
  55064. }
  55065. } // From zutil.h
  55066. var STORED_BLOCK = 0;
  55067. var STATIC_TREES = 1;
  55068. var DYN_TREES = 2;
  55069. /* The three kinds of block type */
  55070. var MIN_MATCH = 3;
  55071. var MAX_MATCH = 258;
  55072. /* The minimum and maximum match lengths */
  55073. // From deflate.h
  55074. /* ===========================================================================
  55075. * Internal compression state.
  55076. */
  55077. var LENGTH_CODES = 29;
  55078. /* number of length codes, not counting the special END_BLOCK code */
  55079. var LITERALS = 256;
  55080. /* number of literal bytes 0..255 */
  55081. var L_CODES = LITERALS + 1 + LENGTH_CODES;
  55082. /* number of Literal or Length codes, including the END_BLOCK code */
  55083. var D_CODES = 30;
  55084. /* number of distance codes */
  55085. var BL_CODES = 19;
  55086. /* number of codes used to transfer the bit lengths */
  55087. var HEAP_SIZE = 2 * L_CODES + 1;
  55088. /* maximum heap size */
  55089. var MAX_BITS = 15;
  55090. /* All codes must not exceed MAX_BITS bits */
  55091. var Buf_size = 16;
  55092. /* size of bit buffer in bi_buf */
  55093. /* ===========================================================================
  55094. * Constants
  55095. */
  55096. var MAX_BL_BITS = 7;
  55097. /* Bit length codes must not exceed MAX_BL_BITS bits */
  55098. var END_BLOCK = 256;
  55099. /* end of block literal code */
  55100. var REP_3_6 = 16;
  55101. /* repeat previous bit length 3-6 times (2 bits of repeat count) */
  55102. var REPZ_3_10 = 17;
  55103. /* repeat a zero length 3-10 times (3 bits of repeat count) */
  55104. var REPZ_11_138 = 18;
  55105. /* repeat a zero length 11-138 times (7 bits of repeat count) */
  55106. /* eslint-disable comma-spacing,array-bracket-spacing */
  55107. var extra_lbits =
  55108. /* extra bits for each length code */
  55109. [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];
  55110. var extra_dbits =
  55111. /* extra bits for each distance code */
  55112. [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];
  55113. var extra_blbits =
  55114. /* extra bits for each bit length code */
  55115. [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7];
  55116. var bl_order = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
  55117. /* eslint-enable comma-spacing,array-bracket-spacing */
  55118. /* The lengths of the bit length codes are sent in order of decreasing
  55119. * probability, to avoid transmitting the lengths for unused bit length codes.
  55120. */
  55121. /* ===========================================================================
  55122. * Local data. These are initialized only once.
  55123. */
  55124. // We pre-fill arrays with 0 to avoid uninitialized gaps
  55125. var DIST_CODE_LEN = 512;
  55126. /* see definition of array dist_code below */
  55127. // !!!! Use flat array instead of structure, Freq = i*2, Len = i*2+1
  55128. var static_ltree = new Array((L_CODES + 2) * 2);
  55129. zero(static_ltree);
  55130. /* The static literal tree. Since the bit lengths are imposed, there is no
  55131. * need for the L_CODES extra codes used during heap construction. However
  55132. * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
  55133. * below).
  55134. */
  55135. var static_dtree = new Array(D_CODES * 2);
  55136. zero(static_dtree);
  55137. /* The static distance tree. (Actually a trivial tree since all codes use
  55138. * 5 bits.)
  55139. */
  55140. var _dist_code = new Array(DIST_CODE_LEN);
  55141. zero(_dist_code);
  55142. /* Distance codes. The first 256 values correspond to the distances
  55143. * 3 .. 258, the last 256 values correspond to the top 8 bits of
  55144. * the 15 bit distances.
  55145. */
  55146. var _length_code = new Array(MAX_MATCH - MIN_MATCH + 1);
  55147. zero(_length_code);
  55148. /* length code for each normalized match length (0 == MIN_MATCH) */
  55149. var base_length = new Array(LENGTH_CODES);
  55150. zero(base_length);
  55151. /* First normalized length for each code (0 = MIN_MATCH) */
  55152. var base_dist = new Array(D_CODES);
  55153. zero(base_dist);
  55154. /* First normalized distance for each code (0 = distance of 1) */
  55155. function StaticTreeDesc(static_tree, extra_bits, extra_base, elems, max_length) {
  55156. this.static_tree = static_tree;
  55157. /* static tree or NULL */
  55158. this.extra_bits = extra_bits;
  55159. /* extra bits for each code or NULL */
  55160. this.extra_base = extra_base;
  55161. /* base index for extra_bits */
  55162. this.elems = elems;
  55163. /* max number of elements in the tree */
  55164. this.max_length = max_length;
  55165. /* max bit length for the codes */
  55166. // show if `static_tree` has data or dummy - needed for monomorphic objects
  55167. this.has_stree = static_tree && static_tree.length;
  55168. }
  55169. var static_l_desc;
  55170. var static_d_desc;
  55171. var static_bl_desc;
  55172. function TreeDesc(dyn_tree, stat_desc) {
  55173. this.dyn_tree = dyn_tree;
  55174. /* the dynamic tree */
  55175. this.max_code = 0;
  55176. /* largest code with non zero frequency */
  55177. this.stat_desc = stat_desc;
  55178. /* the corresponding static tree */
  55179. }
  55180. function d_code(dist) {
  55181. return dist < 256 ? _dist_code[dist] : _dist_code[256 + (dist >>> 7)];
  55182. }
  55183. /* ===========================================================================
  55184. * Output a short LSB first on the stream.
  55185. * IN assertion: there is enough room in pendingBuf.
  55186. */
  55187. function put_short(s, w) {
  55188. // put_byte(s, (uch)((w) & 0xff));
  55189. // put_byte(s, (uch)((ush)(w) >> 8));
  55190. s.pending_buf[s.pending++] = w & 0xff;
  55191. s.pending_buf[s.pending++] = w >>> 8 & 0xff;
  55192. }
  55193. /* ===========================================================================
  55194. * Send a value on a given number of bits.
  55195. * IN assertion: length <= 16 and value fits in length bits.
  55196. */
  55197. function send_bits(s, value, length) {
  55198. if (s.bi_valid > Buf_size - length) {
  55199. s.bi_buf |= value << s.bi_valid & 0xffff;
  55200. put_short(s, s.bi_buf);
  55201. s.bi_buf = value >> Buf_size - s.bi_valid;
  55202. s.bi_valid += length - Buf_size;
  55203. } else {
  55204. s.bi_buf |= value << s.bi_valid & 0xffff;
  55205. s.bi_valid += length;
  55206. }
  55207. }
  55208. function send_code(s, c, tree) {
  55209. send_bits(s, tree[c * 2]
  55210. /*.Code*/
  55211. , tree[c * 2 + 1]
  55212. /*.Len*/
  55213. );
  55214. }
  55215. /* ===========================================================================
  55216. * Reverse the first len bits of a code, using straightforward code (a faster
  55217. * method would use a table)
  55218. * IN assertion: 1 <= len <= 15
  55219. */
  55220. function bi_reverse(code, len) {
  55221. var res = 0;
  55222. do {
  55223. res |= code & 1;
  55224. code >>>= 1;
  55225. res <<= 1;
  55226. } while (--len > 0);
  55227. return res >>> 1;
  55228. }
  55229. /* ===========================================================================
  55230. * Flush the bit buffer, keeping at most 7 bits in it.
  55231. */
  55232. function bi_flush(s) {
  55233. if (s.bi_valid === 16) {
  55234. put_short(s, s.bi_buf);
  55235. s.bi_buf = 0;
  55236. s.bi_valid = 0;
  55237. } else if (s.bi_valid >= 8) {
  55238. s.pending_buf[s.pending++] = s.bi_buf & 0xff;
  55239. s.bi_buf >>= 8;
  55240. s.bi_valid -= 8;
  55241. }
  55242. }
  55243. /* ===========================================================================
  55244. * Compute the optimal bit lengths for a tree and update the total bit length
  55245. * for the current block.
  55246. * IN assertion: the fields freq and dad are set, heap[heap_max] and
  55247. * above are the tree nodes sorted by increasing frequency.
  55248. * OUT assertions: the field len is set to the optimal bit length, the
  55249. * array bl_count contains the frequencies for each bit length.
  55250. * The length opt_len is updated; static_len is also updated if stree is
  55251. * not null.
  55252. */
  55253. function gen_bitlen(s, desc) // deflate_state *s;
  55254. // tree_desc *desc; /* the tree descriptor */
  55255. {
  55256. var tree = desc.dyn_tree;
  55257. var max_code = desc.max_code;
  55258. var stree = desc.stat_desc.static_tree;
  55259. var has_stree = desc.stat_desc.has_stree;
  55260. var extra = desc.stat_desc.extra_bits;
  55261. var base = desc.stat_desc.extra_base;
  55262. var max_length = desc.stat_desc.max_length;
  55263. var h;
  55264. /* heap index */
  55265. var n, m;
  55266. /* iterate over the tree elements */
  55267. var bits;
  55268. /* bit length */
  55269. var xbits;
  55270. /* extra bits */
  55271. var f;
  55272. /* frequency */
  55273. var overflow = 0;
  55274. /* number of elements with bit length too large */
  55275. for (bits = 0; bits <= MAX_BITS; bits++) {
  55276. s.bl_count[bits] = 0;
  55277. }
  55278. /* In a first pass, compute the optimal bit lengths (which may
  55279. * overflow in the case of the bit length tree).
  55280. */
  55281. tree[s.heap[s.heap_max] * 2 + 1]
  55282. /*.Len*/
  55283. = 0;
  55284. /* root of the heap */
  55285. for (h = s.heap_max + 1; h < HEAP_SIZE; h++) {
  55286. n = s.heap[h];
  55287. bits = tree[tree[n * 2 + 1]
  55288. /*.Dad*/
  55289. * 2 + 1]
  55290. /*.Len*/
  55291. + 1;
  55292. if (bits > max_length) {
  55293. bits = max_length;
  55294. overflow++;
  55295. }
  55296. tree[n * 2 + 1]
  55297. /*.Len*/
  55298. = bits;
  55299. /* We overwrite tree[n].Dad which is no longer needed */
  55300. if (n > max_code) {
  55301. continue;
  55302. }
  55303. /* not a leaf node */
  55304. s.bl_count[bits]++;
  55305. xbits = 0;
  55306. if (n >= base) {
  55307. xbits = extra[n - base];
  55308. }
  55309. f = tree[n * 2]
  55310. /*.Freq*/
  55311. ;
  55312. s.opt_len += f * (bits + xbits);
  55313. if (has_stree) {
  55314. s.static_len += f * (stree[n * 2 + 1]
  55315. /*.Len*/
  55316. + xbits);
  55317. }
  55318. }
  55319. if (overflow === 0) {
  55320. return;
  55321. } // Trace((stderr,"\nbit length overflow\n"));
  55322. /* This happens for example on obj2 and pic of the Calgary corpus */
  55323. /* Find the first bit length which could increase: */
  55324. do {
  55325. bits = max_length - 1;
  55326. while (s.bl_count[bits] === 0) {
  55327. bits--;
  55328. }
  55329. s.bl_count[bits]--;
  55330. /* move one leaf down the tree */
  55331. s.bl_count[bits + 1] += 2;
  55332. /* move one overflow item as its brother */
  55333. s.bl_count[max_length]--;
  55334. /* The brother of the overflow item also moves one step up,
  55335. * but this does not affect bl_count[max_length]
  55336. */
  55337. overflow -= 2;
  55338. } while (overflow > 0);
  55339. /* Now recompute all bit lengths, scanning in increasing frequency.
  55340. * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
  55341. * lengths instead of fixing only the wrong ones. This idea is taken
  55342. * from 'ar' written by Haruhiko Okumura.)
  55343. */
  55344. for (bits = max_length; bits !== 0; bits--) {
  55345. n = s.bl_count[bits];
  55346. while (n !== 0) {
  55347. m = s.heap[--h];
  55348. if (m > max_code) {
  55349. continue;
  55350. }
  55351. if (tree[m * 2 + 1]
  55352. /*.Len*/
  55353. !== bits) {
  55354. // Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  55355. s.opt_len += (bits - tree[m * 2 + 1]
  55356. /*.Len*/
  55357. ) * tree[m * 2]
  55358. /*.Freq*/
  55359. ;
  55360. tree[m * 2 + 1]
  55361. /*.Len*/
  55362. = bits;
  55363. }
  55364. n--;
  55365. }
  55366. }
  55367. }
  55368. /* ===========================================================================
  55369. * Generate the codes for a given tree and bit counts (which need not be
  55370. * optimal).
  55371. * IN assertion: the array bl_count contains the bit length statistics for
  55372. * the given tree and the field len is set for all tree elements.
  55373. * OUT assertion: the field code is set for all tree elements of non
  55374. * zero code length.
  55375. */
  55376. function gen_codes(tree, max_code, bl_count) // ct_data *tree; /* the tree to decorate */
  55377. // int max_code; /* largest code with non zero frequency */
  55378. // ushf *bl_count; /* number of codes at each bit length */
  55379. {
  55380. var next_code = new Array(MAX_BITS + 1);
  55381. /* next code value for each bit length */
  55382. var code = 0;
  55383. /* running code value */
  55384. var bits;
  55385. /* bit index */
  55386. var n;
  55387. /* code index */
  55388. /* The distribution counts are first used to generate the code values
  55389. * without bit reversal.
  55390. */
  55391. for (bits = 1; bits <= MAX_BITS; bits++) {
  55392. next_code[bits] = code = code + bl_count[bits - 1] << 1;
  55393. }
  55394. /* Check that the bit counts in bl_count are consistent. The last code
  55395. * must be all ones.
  55396. */
  55397. //Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  55398. // "inconsistent bit counts");
  55399. //Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  55400. for (n = 0; n <= max_code; n++) {
  55401. var len = tree[n * 2 + 1]
  55402. /*.Len*/
  55403. ;
  55404. if (len === 0) {
  55405. continue;
  55406. }
  55407. /* Now reverse the bits */
  55408. tree[n * 2]
  55409. /*.Code*/
  55410. = bi_reverse(next_code[len]++, len); //Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  55411. // n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  55412. }
  55413. }
  55414. /* ===========================================================================
  55415. * Initialize the various 'constant' tables.
  55416. */
  55417. function tr_static_init() {
  55418. var n;
  55419. /* iterates over tree elements */
  55420. var bits;
  55421. /* bit counter */
  55422. var length;
  55423. /* length value */
  55424. var code;
  55425. /* code value */
  55426. var dist;
  55427. /* distance index */
  55428. var bl_count = new Array(MAX_BITS + 1);
  55429. /* number of codes at each bit length for an optimal tree */
  55430. // do check in _tr_init()
  55431. //if (static_init_done) return;
  55432. /* For some embedded targets, global variables are not initialized: */
  55433. /*#ifdef NO_INIT_GLOBAL_POINTERS
  55434. static_l_desc.static_tree = static_ltree;
  55435. static_l_desc.extra_bits = extra_lbits;
  55436. static_d_desc.static_tree = static_dtree;
  55437. static_d_desc.extra_bits = extra_dbits;
  55438. static_bl_desc.extra_bits = extra_blbits;
  55439. #endif*/
  55440. /* Initialize the mapping length (0..255) -> length code (0..28) */
  55441. length = 0;
  55442. for (code = 0; code < LENGTH_CODES - 1; code++) {
  55443. base_length[code] = length;
  55444. for (n = 0; n < 1 << extra_lbits[code]; n++) {
  55445. _length_code[length++] = code;
  55446. }
  55447. } //Assert (length == 256, "tr_static_init: length != 256");
  55448. /* Note that the length 255 (match length 258) can be represented
  55449. * in two different ways: code 284 + 5 bits or code 285, so we
  55450. * overwrite length_code[255] to use the best encoding:
  55451. */
  55452. _length_code[length - 1] = code;
  55453. /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
  55454. dist = 0;
  55455. for (code = 0; code < 16; code++) {
  55456. base_dist[code] = dist;
  55457. for (n = 0; n < 1 << extra_dbits[code]; n++) {
  55458. _dist_code[dist++] = code;
  55459. }
  55460. } //Assert (dist == 256, "tr_static_init: dist != 256");
  55461. dist >>= 7;
  55462. /* from now on, all distances are divided by 128 */
  55463. for (; code < D_CODES; code++) {
  55464. base_dist[code] = dist << 7;
  55465. for (n = 0; n < 1 << extra_dbits[code] - 7; n++) {
  55466. _dist_code[256 + dist++] = code;
  55467. }
  55468. } //Assert (dist == 256, "tr_static_init: 256+dist != 512");
  55469. /* Construct the codes of the static literal tree */
  55470. for (bits = 0; bits <= MAX_BITS; bits++) {
  55471. bl_count[bits] = 0;
  55472. }
  55473. n = 0;
  55474. while (n <= 143) {
  55475. static_ltree[n * 2 + 1]
  55476. /*.Len*/
  55477. = 8;
  55478. n++;
  55479. bl_count[8]++;
  55480. }
  55481. while (n <= 255) {
  55482. static_ltree[n * 2 + 1]
  55483. /*.Len*/
  55484. = 9;
  55485. n++;
  55486. bl_count[9]++;
  55487. }
  55488. while (n <= 279) {
  55489. static_ltree[n * 2 + 1]
  55490. /*.Len*/
  55491. = 7;
  55492. n++;
  55493. bl_count[7]++;
  55494. }
  55495. while (n <= 287) {
  55496. static_ltree[n * 2 + 1]
  55497. /*.Len*/
  55498. = 8;
  55499. n++;
  55500. bl_count[8]++;
  55501. }
  55502. /* Codes 286 and 287 do not exist, but we must include them in the
  55503. * tree construction to get a canonical Huffman tree (longest code
  55504. * all ones)
  55505. */
  55506. gen_codes(static_ltree, L_CODES + 1, bl_count);
  55507. /* The static distance tree is trivial: */
  55508. for (n = 0; n < D_CODES; n++) {
  55509. static_dtree[n * 2 + 1]
  55510. /*.Len*/
  55511. = 5;
  55512. static_dtree[n * 2]
  55513. /*.Code*/
  55514. = bi_reverse(n, 5);
  55515. } // Now data ready and we can init static trees
  55516. static_l_desc = new StaticTreeDesc(static_ltree, extra_lbits, LITERALS + 1, L_CODES, MAX_BITS);
  55517. static_d_desc = new StaticTreeDesc(static_dtree, extra_dbits, 0, D_CODES, MAX_BITS);
  55518. static_bl_desc = new StaticTreeDesc(new Array(0), extra_blbits, 0, BL_CODES, MAX_BL_BITS); //static_init_done = true;
  55519. }
  55520. /* ===========================================================================
  55521. * Initialize a new block.
  55522. */
  55523. function init_block(s) {
  55524. var n;
  55525. /* iterates over tree elements */
  55526. /* Initialize the trees. */
  55527. for (n = 0; n < L_CODES; n++) {
  55528. s.dyn_ltree[n * 2]
  55529. /*.Freq*/
  55530. = 0;
  55531. }
  55532. for (n = 0; n < D_CODES; n++) {
  55533. s.dyn_dtree[n * 2]
  55534. /*.Freq*/
  55535. = 0;
  55536. }
  55537. for (n = 0; n < BL_CODES; n++) {
  55538. s.bl_tree[n * 2]
  55539. /*.Freq*/
  55540. = 0;
  55541. }
  55542. s.dyn_ltree[END_BLOCK * 2]
  55543. /*.Freq*/
  55544. = 1;
  55545. s.opt_len = s.static_len = 0;
  55546. s.last_lit = s.matches = 0;
  55547. }
  55548. /* ===========================================================================
  55549. * Flush the bit buffer and align the output on a byte boundary
  55550. */
  55551. function bi_windup(s) {
  55552. if (s.bi_valid > 8) {
  55553. put_short(s, s.bi_buf);
  55554. } else if (s.bi_valid > 0) {
  55555. //put_byte(s, (Byte)s->bi_buf);
  55556. s.pending_buf[s.pending++] = s.bi_buf;
  55557. }
  55558. s.bi_buf = 0;
  55559. s.bi_valid = 0;
  55560. }
  55561. /* ===========================================================================
  55562. * Copy a stored block, storing first the length and its
  55563. * one's complement if requested.
  55564. */
  55565. function copy_block(s, buf, len, header) //DeflateState *s;
  55566. //charf *buf; /* the input data */
  55567. //unsigned len; /* its length */
  55568. //int header; /* true if block header must be written */
  55569. {
  55570. bi_windup(s);
  55571. /* align on byte boundary */
  55572. if (header) {
  55573. put_short(s, len);
  55574. put_short(s, ~len);
  55575. } // while (len--) {
  55576. // put_byte(s, *buf++);
  55577. // }
  55578. utils.arraySet(s.pending_buf, s.window, buf, len, s.pending);
  55579. s.pending += len;
  55580. }
  55581. /* ===========================================================================
  55582. * Compares to subtrees, using the tree depth as tie breaker when
  55583. * the subtrees have equal frequency. This minimizes the worst case length.
  55584. */
  55585. function smaller(tree, n, m, depth) {
  55586. var _n2 = n * 2;
  55587. var _m2 = m * 2;
  55588. return tree[_n2]
  55589. /*.Freq*/
  55590. < tree[_m2]
  55591. /*.Freq*/
  55592. || tree[_n2]
  55593. /*.Freq*/
  55594. === tree[_m2]
  55595. /*.Freq*/
  55596. && depth[n] <= depth[m];
  55597. }
  55598. /* ===========================================================================
  55599. * Restore the heap property by moving down the tree starting at node k,
  55600. * exchanging a node with the smallest of its two sons if necessary, stopping
  55601. * when the heap property is re-established (each father smaller than its
  55602. * two sons).
  55603. */
  55604. function pqdownheap(s, tree, k) // deflate_state *s;
  55605. // ct_data *tree; /* the tree to restore */
  55606. // int k; /* node to move down */
  55607. {
  55608. var v = s.heap[k];
  55609. var j = k << 1;
  55610. /* left son of k */
  55611. while (j <= s.heap_len) {
  55612. /* Set j to the smallest of the two sons: */
  55613. if (j < s.heap_len && smaller(tree, s.heap[j + 1], s.heap[j], s.depth)) {
  55614. j++;
  55615. }
  55616. /* Exit if v is smaller than both sons */
  55617. if (smaller(tree, v, s.heap[j], s.depth)) {
  55618. break;
  55619. }
  55620. /* Exchange v with the smallest son */
  55621. s.heap[k] = s.heap[j];
  55622. k = j;
  55623. /* And continue down the tree, setting j to the left son of k */
  55624. j <<= 1;
  55625. }
  55626. s.heap[k] = v;
  55627. } // inlined manually
  55628. // var SMALLEST = 1;
  55629. /* ===========================================================================
  55630. * Send the block data compressed using the given Huffman trees
  55631. */
  55632. function compress_block(s, ltree, dtree) // deflate_state *s;
  55633. // const ct_data *ltree; /* literal tree */
  55634. // const ct_data *dtree; /* distance tree */
  55635. {
  55636. var dist;
  55637. /* distance of matched string */
  55638. var lc;
  55639. /* match length or unmatched char (if dist == 0) */
  55640. var lx = 0;
  55641. /* running index in l_buf */
  55642. var code;
  55643. /* the code to send */
  55644. var extra;
  55645. /* number of extra bits to send */
  55646. if (s.last_lit !== 0) {
  55647. do {
  55648. dist = s.pending_buf[s.d_buf + lx * 2] << 8 | s.pending_buf[s.d_buf + lx * 2 + 1];
  55649. lc = s.pending_buf[s.l_buf + lx];
  55650. lx++;
  55651. if (dist === 0) {
  55652. send_code(s, lc, ltree);
  55653. /* send a literal byte */
  55654. //Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  55655. } else {
  55656. /* Here, lc is the match length - MIN_MATCH */
  55657. code = _length_code[lc];
  55658. send_code(s, code + LITERALS + 1, ltree);
  55659. /* send the length code */
  55660. extra = extra_lbits[code];
  55661. if (extra !== 0) {
  55662. lc -= base_length[code];
  55663. send_bits(s, lc, extra);
  55664. /* send the extra length bits */
  55665. }
  55666. dist--;
  55667. /* dist is now the match distance - 1 */
  55668. code = d_code(dist); //Assert (code < D_CODES, "bad d_code");
  55669. send_code(s, code, dtree);
  55670. /* send the distance code */
  55671. extra = extra_dbits[code];
  55672. if (extra !== 0) {
  55673. dist -= base_dist[code];
  55674. send_bits(s, dist, extra);
  55675. /* send the extra distance bits */
  55676. }
  55677. }
  55678. /* literal or match pair ? */
  55679. /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
  55680. //Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  55681. // "pendingBuf overflow");
  55682. } while (lx < s.last_lit);
  55683. }
  55684. send_code(s, END_BLOCK, ltree);
  55685. }
  55686. /* ===========================================================================
  55687. * Construct one Huffman tree and assigns the code bit strings and lengths.
  55688. * Update the total bit length for the current block.
  55689. * IN assertion: the field freq is set for all tree elements.
  55690. * OUT assertions: the fields len and code are set to the optimal bit length
  55691. * and corresponding code. The length opt_len is updated; static_len is
  55692. * also updated if stree is not null. The field max_code is set.
  55693. */
  55694. function build_tree(s, desc) // deflate_state *s;
  55695. // tree_desc *desc; /* the tree descriptor */
  55696. {
  55697. var tree = desc.dyn_tree;
  55698. var stree = desc.stat_desc.static_tree;
  55699. var has_stree = desc.stat_desc.has_stree;
  55700. var elems = desc.stat_desc.elems;
  55701. var n, m;
  55702. /* iterate over heap elements */
  55703. var max_code = -1;
  55704. /* largest code with non zero frequency */
  55705. var node;
  55706. /* new node being created */
  55707. /* Construct the initial heap, with least frequent element in
  55708. * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
  55709. * heap[0] is not used.
  55710. */
  55711. s.heap_len = 0;
  55712. s.heap_max = HEAP_SIZE;
  55713. for (n = 0; n < elems; n++) {
  55714. if (tree[n * 2]
  55715. /*.Freq*/
  55716. !== 0) {
  55717. s.heap[++s.heap_len] = max_code = n;
  55718. s.depth[n] = 0;
  55719. } else {
  55720. tree[n * 2 + 1]
  55721. /*.Len*/
  55722. = 0;
  55723. }
  55724. }
  55725. /* The pkzip format requires that at least one distance code exists,
  55726. * and that at least one bit should be sent even if there is only one
  55727. * possible code. So to avoid special checks later on we force at least
  55728. * two codes of non zero frequency.
  55729. */
  55730. while (s.heap_len < 2) {
  55731. node = s.heap[++s.heap_len] = max_code < 2 ? ++max_code : 0;
  55732. tree[node * 2]
  55733. /*.Freq*/
  55734. = 1;
  55735. s.depth[node] = 0;
  55736. s.opt_len--;
  55737. if (has_stree) {
  55738. s.static_len -= stree[node * 2 + 1]
  55739. /*.Len*/
  55740. ;
  55741. }
  55742. /* node is 0 or 1 so it does not have extra bits */
  55743. }
  55744. desc.max_code = max_code;
  55745. /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
  55746. * establish sub-heaps of increasing lengths:
  55747. */
  55748. for (n = s.heap_len >> 1
  55749. /*int /2*/
  55750. ; n >= 1; n--) {
  55751. pqdownheap(s, tree, n);
  55752. }
  55753. /* Construct the Huffman tree by repeatedly combining the least two
  55754. * frequent nodes.
  55755. */
  55756. node = elems;
  55757. /* next internal node of the tree */
  55758. do {
  55759. //pqremove(s, tree, n); /* n = node of least frequency */
  55760. /*** pqremove ***/
  55761. n = s.heap[1
  55762. /*SMALLEST*/
  55763. ];
  55764. s.heap[1
  55765. /*SMALLEST*/
  55766. ] = s.heap[s.heap_len--];
  55767. pqdownheap(s, tree, 1
  55768. /*SMALLEST*/
  55769. );
  55770. /***/
  55771. m = s.heap[1
  55772. /*SMALLEST*/
  55773. ];
  55774. /* m = node of next least frequency */
  55775. s.heap[--s.heap_max] = n;
  55776. /* keep the nodes sorted by frequency */
  55777. s.heap[--s.heap_max] = m;
  55778. /* Create a new node father of n and m */
  55779. tree[node * 2]
  55780. /*.Freq*/
  55781. = tree[n * 2]
  55782. /*.Freq*/
  55783. + tree[m * 2]
  55784. /*.Freq*/
  55785. ;
  55786. s.depth[node] = (s.depth[n] >= s.depth[m] ? s.depth[n] : s.depth[m]) + 1;
  55787. tree[n * 2 + 1]
  55788. /*.Dad*/
  55789. = tree[m * 2 + 1]
  55790. /*.Dad*/
  55791. = node;
  55792. /* and insert the new node in the heap */
  55793. s.heap[1
  55794. /*SMALLEST*/
  55795. ] = node++;
  55796. pqdownheap(s, tree, 1
  55797. /*SMALLEST*/
  55798. );
  55799. } while (s.heap_len >= 2);
  55800. s.heap[--s.heap_max] = s.heap[1
  55801. /*SMALLEST*/
  55802. ];
  55803. /* At this point, the fields freq and dad are set. We can now
  55804. * generate the bit lengths.
  55805. */
  55806. gen_bitlen(s, desc);
  55807. /* The field len is now set, we can generate the bit codes */
  55808. gen_codes(tree, max_code, s.bl_count);
  55809. }
  55810. /* ===========================================================================
  55811. * Scan a literal or distance tree to determine the frequencies of the codes
  55812. * in the bit length tree.
  55813. */
  55814. function scan_tree(s, tree, max_code) // deflate_state *s;
  55815. // ct_data *tree; /* the tree to be scanned */
  55816. // int max_code; /* and its largest code of non zero frequency */
  55817. {
  55818. var n;
  55819. /* iterates over all tree elements */
  55820. var prevlen = -1;
  55821. /* last emitted length */
  55822. var curlen;
  55823. /* length of current code */
  55824. var nextlen = tree[0 * 2 + 1]
  55825. /*.Len*/
  55826. ;
  55827. /* length of next code */
  55828. var count = 0;
  55829. /* repeat count of the current code */
  55830. var max_count = 7;
  55831. /* max repeat count */
  55832. var min_count = 4;
  55833. /* min repeat count */
  55834. if (nextlen === 0) {
  55835. max_count = 138;
  55836. min_count = 3;
  55837. }
  55838. tree[(max_code + 1) * 2 + 1]
  55839. /*.Len*/
  55840. = 0xffff;
  55841. /* guard */
  55842. for (n = 0; n <= max_code; n++) {
  55843. curlen = nextlen;
  55844. nextlen = tree[(n + 1) * 2 + 1]
  55845. /*.Len*/
  55846. ;
  55847. if (++count < max_count && curlen === nextlen) {
  55848. continue;
  55849. } else if (count < min_count) {
  55850. s.bl_tree[curlen * 2]
  55851. /*.Freq*/
  55852. += count;
  55853. } else if (curlen !== 0) {
  55854. if (curlen !== prevlen) {
  55855. s.bl_tree[curlen * 2] /*.Freq*/++;
  55856. }
  55857. s.bl_tree[REP_3_6 * 2] /*.Freq*/++;
  55858. } else if (count <= 10) {
  55859. s.bl_tree[REPZ_3_10 * 2] /*.Freq*/++;
  55860. } else {
  55861. s.bl_tree[REPZ_11_138 * 2] /*.Freq*/++;
  55862. }
  55863. count = 0;
  55864. prevlen = curlen;
  55865. if (nextlen === 0) {
  55866. max_count = 138;
  55867. min_count = 3;
  55868. } else if (curlen === nextlen) {
  55869. max_count = 6;
  55870. min_count = 3;
  55871. } else {
  55872. max_count = 7;
  55873. min_count = 4;
  55874. }
  55875. }
  55876. }
  55877. /* ===========================================================================
  55878. * Send a literal or distance tree in compressed form, using the codes in
  55879. * bl_tree.
  55880. */
  55881. function send_tree(s, tree, max_code) // deflate_state *s;
  55882. // ct_data *tree; /* the tree to be scanned */
  55883. // int max_code; /* and its largest code of non zero frequency */
  55884. {
  55885. var n;
  55886. /* iterates over all tree elements */
  55887. var prevlen = -1;
  55888. /* last emitted length */
  55889. var curlen;
  55890. /* length of current code */
  55891. var nextlen = tree[0 * 2 + 1]
  55892. /*.Len*/
  55893. ;
  55894. /* length of next code */
  55895. var count = 0;
  55896. /* repeat count of the current code */
  55897. var max_count = 7;
  55898. /* max repeat count */
  55899. var min_count = 4;
  55900. /* min repeat count */
  55901. /* tree[max_code+1].Len = -1; */
  55902. /* guard already set */
  55903. if (nextlen === 0) {
  55904. max_count = 138;
  55905. min_count = 3;
  55906. }
  55907. for (n = 0; n <= max_code; n++) {
  55908. curlen = nextlen;
  55909. nextlen = tree[(n + 1) * 2 + 1]
  55910. /*.Len*/
  55911. ;
  55912. if (++count < max_count && curlen === nextlen) {
  55913. continue;
  55914. } else if (count < min_count) {
  55915. do {
  55916. send_code(s, curlen, s.bl_tree);
  55917. } while (--count !== 0);
  55918. } else if (curlen !== 0) {
  55919. if (curlen !== prevlen) {
  55920. send_code(s, curlen, s.bl_tree);
  55921. count--;
  55922. } //Assert(count >= 3 && count <= 6, " 3_6?");
  55923. send_code(s, REP_3_6, s.bl_tree);
  55924. send_bits(s, count - 3, 2);
  55925. } else if (count <= 10) {
  55926. send_code(s, REPZ_3_10, s.bl_tree);
  55927. send_bits(s, count - 3, 3);
  55928. } else {
  55929. send_code(s, REPZ_11_138, s.bl_tree);
  55930. send_bits(s, count - 11, 7);
  55931. }
  55932. count = 0;
  55933. prevlen = curlen;
  55934. if (nextlen === 0) {
  55935. max_count = 138;
  55936. min_count = 3;
  55937. } else if (curlen === nextlen) {
  55938. max_count = 6;
  55939. min_count = 3;
  55940. } else {
  55941. max_count = 7;
  55942. min_count = 4;
  55943. }
  55944. }
  55945. }
  55946. /* ===========================================================================
  55947. * Construct the Huffman tree for the bit lengths and return the index in
  55948. * bl_order of the last bit length code to send.
  55949. */
  55950. function build_bl_tree(s) {
  55951. var max_blindex;
  55952. /* index of last bit length code of non zero freq */
  55953. /* Determine the bit length frequencies for literal and distance trees */
  55954. scan_tree(s, s.dyn_ltree, s.l_desc.max_code);
  55955. scan_tree(s, s.dyn_dtree, s.d_desc.max_code);
  55956. /* Build the bit length tree: */
  55957. build_tree(s, s.bl_desc);
  55958. /* opt_len now includes the length of the tree representations, except
  55959. * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
  55960. */
  55961. /* Determine the number of bit length codes to send. The pkzip format
  55962. * requires that at least 4 bit length codes be sent. (appnote.txt says
  55963. * 3 but the actual value used is 4.)
  55964. */
  55965. for (max_blindex = BL_CODES - 1; max_blindex >= 3; max_blindex--) {
  55966. if (s.bl_tree[bl_order[max_blindex] * 2 + 1]
  55967. /*.Len*/
  55968. !== 0) {
  55969. break;
  55970. }
  55971. }
  55972. /* Update opt_len to include the bit length tree and counts */
  55973. s.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4; //Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  55974. // s->opt_len, s->static_len));
  55975. return max_blindex;
  55976. }
  55977. /* ===========================================================================
  55978. * Send the header for a block using dynamic Huffman trees: the counts, the
  55979. * lengths of the bit length codes, the literal tree and the distance tree.
  55980. * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
  55981. */
  55982. function send_all_trees(s, lcodes, dcodes, blcodes) // deflate_state *s;
  55983. // int lcodes, dcodes, blcodes; /* number of codes for each tree */
  55984. {
  55985. var rank;
  55986. /* index in bl_order */
  55987. //Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  55988. //Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  55989. // "too many codes");
  55990. //Tracev((stderr, "\nbl counts: "));
  55991. send_bits(s, lcodes - 257, 5);
  55992. /* not +255 as stated in appnote.txt */
  55993. send_bits(s, dcodes - 1, 5);
  55994. send_bits(s, blcodes - 4, 4);
  55995. /* not -3 as stated in appnote.txt */
  55996. for (rank = 0; rank < blcodes; rank++) {
  55997. //Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  55998. send_bits(s, s.bl_tree[bl_order[rank] * 2 + 1]
  55999. /*.Len*/
  56000. , 3);
  56001. } //Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  56002. send_tree(s, s.dyn_ltree, lcodes - 1);
  56003. /* literal tree */
  56004. //Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  56005. send_tree(s, s.dyn_dtree, dcodes - 1);
  56006. /* distance tree */
  56007. //Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  56008. }
  56009. /* ===========================================================================
  56010. * Check if the data type is TEXT or BINARY, using the following algorithm:
  56011. * - TEXT if the two conditions below are satisfied:
  56012. * a) There are no non-portable control characters belonging to the
  56013. * "black list" (0..6, 14..25, 28..31).
  56014. * b) There is at least one printable character belonging to the
  56015. * "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
  56016. * - BINARY otherwise.
  56017. * - The following partially-portable control characters form a
  56018. * "gray list" that is ignored in this detection algorithm:
  56019. * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
  56020. * IN assertion: the fields Freq of dyn_ltree are set.
  56021. */
  56022. function detect_data_type(s) {
  56023. /* black_mask is the bit mask of black-listed bytes
  56024. * set bits 0..6, 14..25, and 28..31
  56025. * 0xf3ffc07f = binary 11110011111111111100000001111111
  56026. */
  56027. var black_mask = 0xf3ffc07f;
  56028. var n;
  56029. /* Check for non-textual ("black-listed") bytes. */
  56030. for (n = 0; n <= 31; n++, black_mask >>>= 1) {
  56031. if (black_mask & 1 && s.dyn_ltree[n * 2]
  56032. /*.Freq*/
  56033. !== 0) {
  56034. return Z_BINARY;
  56035. }
  56036. }
  56037. /* Check for textual ("white-listed") bytes. */
  56038. if (s.dyn_ltree[9 * 2]
  56039. /*.Freq*/
  56040. !== 0 || s.dyn_ltree[10 * 2]
  56041. /*.Freq*/
  56042. !== 0 || s.dyn_ltree[13 * 2]
  56043. /*.Freq*/
  56044. !== 0) {
  56045. return Z_TEXT;
  56046. }
  56047. for (n = 32; n < LITERALS; n++) {
  56048. if (s.dyn_ltree[n * 2]
  56049. /*.Freq*/
  56050. !== 0) {
  56051. return Z_TEXT;
  56052. }
  56053. }
  56054. /* There are no "black-listed" or "white-listed" bytes:
  56055. * this stream either is empty or has tolerated ("gray-listed") bytes only.
  56056. */
  56057. return Z_BINARY;
  56058. }
  56059. var static_init_done = false;
  56060. /* ===========================================================================
  56061. * Initialize the tree data structures for a new zlib stream.
  56062. */
  56063. function _tr_init(s) {
  56064. if (!static_init_done) {
  56065. tr_static_init();
  56066. static_init_done = true;
  56067. }
  56068. s.l_desc = new TreeDesc(s.dyn_ltree, static_l_desc);
  56069. s.d_desc = new TreeDesc(s.dyn_dtree, static_d_desc);
  56070. s.bl_desc = new TreeDesc(s.bl_tree, static_bl_desc);
  56071. s.bi_buf = 0;
  56072. s.bi_valid = 0;
  56073. /* Initialize the first block of the first file: */
  56074. init_block(s);
  56075. }
  56076. /* ===========================================================================
  56077. * Send a stored block
  56078. */
  56079. function _tr_stored_block(s, buf, stored_len, last) //DeflateState *s;
  56080. //charf *buf; /* input block */
  56081. //ulg stored_len; /* length of input block */
  56082. //int last; /* one if this is the last block for a file */
  56083. {
  56084. send_bits(s, (STORED_BLOCK << 1) + (last ? 1 : 0), 3);
  56085. /* send block type */
  56086. copy_block(s, buf, stored_len, true);
  56087. /* with header */
  56088. }
  56089. /* ===========================================================================
  56090. * Send one empty static block to give enough lookahead for inflate.
  56091. * This takes 10 bits, of which 7 may remain in the bit buffer.
  56092. */
  56093. function _tr_align(s) {
  56094. send_bits(s, STATIC_TREES << 1, 3);
  56095. send_code(s, END_BLOCK, static_ltree);
  56096. bi_flush(s);
  56097. }
  56098. /* ===========================================================================
  56099. * Determine the best encoding for the current block: dynamic trees, static
  56100. * trees or store, and output the encoded block to the zip file.
  56101. */
  56102. function _tr_flush_block(s, buf, stored_len, last) //DeflateState *s;
  56103. //charf *buf; /* input block, or NULL if too old */
  56104. //ulg stored_len; /* length of input block */
  56105. //int last; /* one if this is the last block for a file */
  56106. {
  56107. var opt_lenb, static_lenb;
  56108. /* opt_len and static_len in bytes */
  56109. var max_blindex = 0;
  56110. /* index of last bit length code of non zero freq */
  56111. /* Build the Huffman trees unless a stored block is forced */
  56112. if (s.level > 0) {
  56113. /* Check if the file is binary or text */
  56114. if (s.strm.data_type === Z_UNKNOWN) {
  56115. s.strm.data_type = detect_data_type(s);
  56116. }
  56117. /* Construct the literal and distance trees */
  56118. build_tree(s, s.l_desc); // Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  56119. // s->static_len));
  56120. build_tree(s, s.d_desc); // Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  56121. // s->static_len));
  56122. /* At this point, opt_len and static_len are the total bit lengths of
  56123. * the compressed block data, excluding the tree representations.
  56124. */
  56125. /* Build the bit length tree for the above two trees, and get the index
  56126. * in bl_order of the last bit length code to send.
  56127. */
  56128. max_blindex = build_bl_tree(s);
  56129. /* Determine the best encoding. Compute the block lengths in bytes. */
  56130. opt_lenb = s.opt_len + 3 + 7 >>> 3;
  56131. static_lenb = s.static_len + 3 + 7 >>> 3; // Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  56132. // opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  56133. // s->last_lit));
  56134. if (static_lenb <= opt_lenb) {
  56135. opt_lenb = static_lenb;
  56136. }
  56137. } else {
  56138. // Assert(buf != (char*)0, "lost buf");
  56139. opt_lenb = static_lenb = stored_len + 5;
  56140. /* force a stored block */
  56141. }
  56142. if (stored_len + 4 <= opt_lenb && buf !== -1) {
  56143. /* 4: two words for the lengths */
  56144. /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
  56145. * Otherwise we can't have processed more than WSIZE input bytes since
  56146. * the last block flush, because compression would have been
  56147. * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
  56148. * transform a block into a stored block.
  56149. */
  56150. _tr_stored_block(s, buf, stored_len, last);
  56151. } else if (s.strategy === Z_FIXED || static_lenb === opt_lenb) {
  56152. send_bits(s, (STATIC_TREES << 1) + (last ? 1 : 0), 3);
  56153. compress_block(s, static_ltree, static_dtree);
  56154. } else {
  56155. send_bits(s, (DYN_TREES << 1) + (last ? 1 : 0), 3);
  56156. send_all_trees(s, s.l_desc.max_code + 1, s.d_desc.max_code + 1, max_blindex + 1);
  56157. compress_block(s, s.dyn_ltree, s.dyn_dtree);
  56158. } // Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  56159. /* The above check is made mod 2^32, for files larger than 512 MB
  56160. * and uLong implemented on 32 bits.
  56161. */
  56162. init_block(s);
  56163. if (last) {
  56164. bi_windup(s);
  56165. } // Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  56166. // s->compressed_len-7*last));
  56167. }
  56168. /* ===========================================================================
  56169. * Save the match info and tally the frequency counts. Return true if
  56170. * the current block must be flushed.
  56171. */
  56172. function _tr_tally(s, dist, lc) // deflate_state *s;
  56173. // unsigned dist; /* distance of matched string */
  56174. // unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */
  56175. {
  56176. //var out_length, in_length, dcode;
  56177. s.pending_buf[s.d_buf + s.last_lit * 2] = dist >>> 8 & 0xff;
  56178. s.pending_buf[s.d_buf + s.last_lit * 2 + 1] = dist & 0xff;
  56179. s.pending_buf[s.l_buf + s.last_lit] = lc & 0xff;
  56180. s.last_lit++;
  56181. if (dist === 0) {
  56182. /* lc is the unmatched char */
  56183. s.dyn_ltree[lc * 2] /*.Freq*/++;
  56184. } else {
  56185. s.matches++;
  56186. /* Here, lc is the match length - MIN_MATCH */
  56187. dist--;
  56188. /* dist = match distance - 1 */
  56189. //Assert((ush)dist < (ush)MAX_DIST(s) &&
  56190. // (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  56191. // (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  56192. s.dyn_ltree[(_length_code[lc] + LITERALS + 1) * 2] /*.Freq*/++;
  56193. s.dyn_dtree[d_code(dist) * 2] /*.Freq*/++;
  56194. } // (!) This block is disabled in zlib defaults,
  56195. // don't enable it for binary compatibility
  56196. //#ifdef TRUNCATE_BLOCK
  56197. // /* Try to guess if it is profitable to stop the current block here */
  56198. // if ((s.last_lit & 0x1fff) === 0 && s.level > 2) {
  56199. // /* Compute an upper bound for the compressed length */
  56200. // out_length = s.last_lit*8;
  56201. // in_length = s.strstart - s.block_start;
  56202. //
  56203. // for (dcode = 0; dcode < D_CODES; dcode++) {
  56204. // out_length += s.dyn_dtree[dcode*2]/*.Freq*/ * (5 + extra_dbits[dcode]);
  56205. // }
  56206. // out_length >>>= 3;
  56207. // //Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  56208. // // s->last_lit, in_length, out_length,
  56209. // // 100L - out_length*100L/in_length));
  56210. // if (s.matches < (s.last_lit>>1)/*int /2*/ && out_length < (in_length>>1)/*int /2*/) {
  56211. // return true;
  56212. // }
  56213. // }
  56214. //#endif
  56215. return s.last_lit === s.lit_bufsize - 1;
  56216. /* We avoid equality with lit_bufsize because of wraparound at 64K
  56217. * on 16 bit machines and because stored blocks are restricted to
  56218. * 64K-1 bytes.
  56219. */
  56220. }
  56221. exports._tr_init = _tr_init;
  56222. exports._tr_stored_block = _tr_stored_block;
  56223. exports._tr_flush_block = _tr_flush_block;
  56224. exports._tr_tally = _tr_tally;
  56225. exports._tr_align = _tr_align;
  56226. },{"../utils/common":442}],454:[function(require,module,exports){
  56227. 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  56228. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  56229. //
  56230. // This software is provided 'as-is', without any express or implied
  56231. // warranty. In no event will the authors be held liable for any damages
  56232. // arising from the use of this software.
  56233. //
  56234. // Permission is granted to anyone to use this software for any purpose,
  56235. // including commercial applications, and to alter it and redistribute it
  56236. // freely, subject to the following restrictions:
  56237. //
  56238. // 1. The origin of this software must not be misrepresented; you must not
  56239. // claim that you wrote the original software. If you use this software
  56240. // in a product, an acknowledgment in the product documentation would be
  56241. // appreciated but is not required.
  56242. // 2. Altered source versions must be plainly marked as such, and must not be
  56243. // misrepresented as being the original software.
  56244. // 3. This notice may not be removed or altered from any source distribution.
  56245. function ZStream() {
  56246. /* next input byte */
  56247. this.input = null; // JS specific, because we have no pointers
  56248. this.next_in = 0;
  56249. /* number of bytes available at input */
  56250. this.avail_in = 0;
  56251. /* total number of input bytes read so far */
  56252. this.total_in = 0;
  56253. /* next output byte should be put there */
  56254. this.output = null; // JS specific, because we have no pointers
  56255. this.next_out = 0;
  56256. /* remaining free space at output */
  56257. this.avail_out = 0;
  56258. /* total number of bytes output so far */
  56259. this.total_out = 0;
  56260. /* last error message, NULL if no error */
  56261. this.msg = ''
  56262. /*Z_NULL*/
  56263. ;
  56264. /* not visible by applications */
  56265. this.state = null;
  56266. /* best guess about the data type: binary or text */
  56267. this.data_type = 2
  56268. /*Z_UNKNOWN*/
  56269. ;
  56270. /* adler32 value of the uncompressed data */
  56271. this.adler = 0;
  56272. }
  56273. module.exports = ZStream;
  56274. },{}],455:[function(require,module,exports){
  56275. module.exports={"2.16.840.1.101.3.4.1.1": "aes-128-ecb",
  56276. "2.16.840.1.101.3.4.1.2": "aes-128-cbc",
  56277. "2.16.840.1.101.3.4.1.3": "aes-128-ofb",
  56278. "2.16.840.1.101.3.4.1.4": "aes-128-cfb",
  56279. "2.16.840.1.101.3.4.1.21": "aes-192-ecb",
  56280. "2.16.840.1.101.3.4.1.22": "aes-192-cbc",
  56281. "2.16.840.1.101.3.4.1.23": "aes-192-ofb",
  56282. "2.16.840.1.101.3.4.1.24": "aes-192-cfb",
  56283. "2.16.840.1.101.3.4.1.41": "aes-256-ecb",
  56284. "2.16.840.1.101.3.4.1.42": "aes-256-cbc",
  56285. "2.16.840.1.101.3.4.1.43": "aes-256-ofb",
  56286. "2.16.840.1.101.3.4.1.44": "aes-256-cfb"
  56287. }
  56288. },{}],456:[function(require,module,exports){
  56289. // from https://github.com/indutny/self-signed/blob/gh-pages/lib/asn1.js
  56290. // Fedor, you are amazing.
  56291. 'use strict';
  56292. var asn1 = require('asn1.js');
  56293. exports.certificate = require('./certificate');
  56294. var RSAPrivateKey = asn1.define('RSAPrivateKey', function () {
  56295. 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());
  56296. });
  56297. exports.RSAPrivateKey = RSAPrivateKey;
  56298. var RSAPublicKey = asn1.define('RSAPublicKey', function () {
  56299. this.seq().obj(this.key('modulus').int(), this.key('publicExponent').int());
  56300. });
  56301. exports.RSAPublicKey = RSAPublicKey;
  56302. var PublicKey = asn1.define('SubjectPublicKeyInfo', function () {
  56303. this.seq().obj(this.key('algorithm').use(AlgorithmIdentifier), this.key('subjectPublicKey').bitstr());
  56304. });
  56305. exports.PublicKey = PublicKey;
  56306. var AlgorithmIdentifier = asn1.define('AlgorithmIdentifier', function () {
  56307. 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());
  56308. });
  56309. var PrivateKeyInfo = asn1.define('PrivateKeyInfo', function () {
  56310. this.seq().obj(this.key('version').int(), this.key('algorithm').use(AlgorithmIdentifier), this.key('subjectPrivateKey').octstr());
  56311. });
  56312. exports.PrivateKey = PrivateKeyInfo;
  56313. var EncryptedPrivateKeyInfo = asn1.define('EncryptedPrivateKeyInfo', function () {
  56314. 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());
  56315. });
  56316. exports.EncryptedPrivateKey = EncryptedPrivateKeyInfo;
  56317. var DSAPrivateKey = asn1.define('DSAPrivateKey', function () {
  56318. 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());
  56319. });
  56320. exports.DSAPrivateKey = DSAPrivateKey;
  56321. exports.DSAparam = asn1.define('DSAparam', function () {
  56322. this.int();
  56323. });
  56324. var ECPrivateKey = asn1.define('ECPrivateKey', function () {
  56325. 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());
  56326. });
  56327. exports.ECPrivateKey = ECPrivateKey;
  56328. var ECParameters = asn1.define('ECParameters', function () {
  56329. this.choice({
  56330. namedCurve: this.objid()
  56331. });
  56332. });
  56333. exports.signature = asn1.define('signature', function () {
  56334. this.seq().obj(this.key('r').int(), this.key('s').int());
  56335. });
  56336. },{"./certificate":457,"asn1.js":167}],457:[function(require,module,exports){
  56337. // from https://github.com/Rantanen/node-dtls/blob/25a7dc861bda38cfeac93a723500eea4f0ac2e86/Certificate.js
  56338. // thanks to @Rantanen
  56339. 'use strict';
  56340. var asn = require('asn1.js');
  56341. var Time = asn.define('Time', function () {
  56342. this.choice({
  56343. utcTime: this.utctime(),
  56344. generalTime: this.gentime()
  56345. });
  56346. });
  56347. var AttributeTypeValue = asn.define('AttributeTypeValue', function () {
  56348. this.seq().obj(this.key('type').objid(), this.key('value').any());
  56349. });
  56350. var AlgorithmIdentifier = asn.define('AlgorithmIdentifier', function () {
  56351. this.seq().obj(this.key('algorithm').objid(), this.key('parameters').optional(), this.key('curve').objid().optional());
  56352. });
  56353. var SubjectPublicKeyInfo = asn.define('SubjectPublicKeyInfo', function () {
  56354. this.seq().obj(this.key('algorithm').use(AlgorithmIdentifier), this.key('subjectPublicKey').bitstr());
  56355. });
  56356. var RelativeDistinguishedName = asn.define('RelativeDistinguishedName', function () {
  56357. this.setof(AttributeTypeValue);
  56358. });
  56359. var RDNSequence = asn.define('RDNSequence', function () {
  56360. this.seqof(RelativeDistinguishedName);
  56361. });
  56362. var Name = asn.define('Name', function () {
  56363. this.choice({
  56364. rdnSequence: this.use(RDNSequence)
  56365. });
  56366. });
  56367. var Validity = asn.define('Validity', function () {
  56368. this.seq().obj(this.key('notBefore').use(Time), this.key('notAfter').use(Time));
  56369. });
  56370. var Extension = asn.define('Extension', function () {
  56371. this.seq().obj(this.key('extnID').objid(), this.key('critical').bool().def(false), this.key('extnValue').octstr());
  56372. });
  56373. var TBSCertificate = asn.define('TBSCertificate', function () {
  56374. 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());
  56375. });
  56376. var X509Certificate = asn.define('X509Certificate', function () {
  56377. this.seq().obj(this.key('tbsCertificate').use(TBSCertificate), this.key('signatureAlgorithm').use(AlgorithmIdentifier), this.key('signatureValue').bitstr());
  56378. });
  56379. module.exports = X509Certificate;
  56380. },{"asn1.js":167}],458:[function(require,module,exports){
  56381. "use strict";
  56382. // adapted from https://github.com/apatil/pemstrip
  56383. 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;
  56384. var startRegex = /^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----/m;
  56385. var fullRegex = /^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----([0-9A-z\n\r+/=]+)-----END \1-----$/m;
  56386. var evp = require('evp_bytestokey');
  56387. var ciphers = require('browserify-aes');
  56388. var Buffer = require('safe-buffer').Buffer;
  56389. module.exports = function (okey, password) {
  56390. var key = okey.toString();
  56391. var match = key.match(findProc);
  56392. var decrypted;
  56393. if (!match) {
  56394. var match2 = key.match(fullRegex);
  56395. decrypted = Buffer.from(match2[2].replace(/[\r\n]/g, ''), 'base64');
  56396. } else {
  56397. var suite = 'aes' + match[1];
  56398. var iv = Buffer.from(match[2], 'hex');
  56399. var cipherText = Buffer.from(match[3].replace(/[\r\n]/g, ''), 'base64');
  56400. var cipherKey = evp(password, iv.slice(0, 8), parseInt(match[1], 10)).key;
  56401. var out = [];
  56402. var cipher = ciphers.createDecipheriv(suite, cipherKey, iv);
  56403. out.push(cipher.update(cipherText));
  56404. out.push(cipher.final());
  56405. decrypted = Buffer.concat(out);
  56406. }
  56407. var tag = key.match(startRegex)[1];
  56408. return {
  56409. tag: tag,
  56410. data: decrypted
  56411. };
  56412. };
  56413. },{"browserify-aes":188,"evp_bytestokey":368,"safe-buffer":494}],459:[function(require,module,exports){
  56414. "use strict";
  56415. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  56416. var asn1 = require('./asn1');
  56417. var aesid = require('./aesid.json');
  56418. var fixProc = require('./fixProc');
  56419. var ciphers = require('browserify-aes');
  56420. var compat = require('pbkdf2');
  56421. var Buffer = require('safe-buffer').Buffer;
  56422. module.exports = parseKeys;
  56423. function parseKeys(buffer) {
  56424. var password;
  56425. if (_typeof(buffer) === 'object' && !Buffer.isBuffer(buffer)) {
  56426. password = buffer.passphrase;
  56427. buffer = buffer.key;
  56428. }
  56429. if (typeof buffer === 'string') {
  56430. buffer = Buffer.from(buffer);
  56431. }
  56432. var stripped = fixProc(buffer, password);
  56433. var type = stripped.tag;
  56434. var data = stripped.data;
  56435. var subtype, ndata;
  56436. switch (type) {
  56437. case 'CERTIFICATE':
  56438. ndata = asn1.certificate.decode(data, 'der').tbsCertificate.subjectPublicKeyInfo;
  56439. // falls through
  56440. case 'PUBLIC KEY':
  56441. if (!ndata) {
  56442. ndata = asn1.PublicKey.decode(data, 'der');
  56443. }
  56444. subtype = ndata.algorithm.algorithm.join('.');
  56445. switch (subtype) {
  56446. case '1.2.840.113549.1.1.1':
  56447. return asn1.RSAPublicKey.decode(ndata.subjectPublicKey.data, 'der');
  56448. case '1.2.840.10045.2.1':
  56449. ndata.subjectPrivateKey = ndata.subjectPublicKey;
  56450. return {
  56451. type: 'ec',
  56452. data: ndata
  56453. };
  56454. case '1.2.840.10040.4.1':
  56455. ndata.algorithm.params.pub_key = asn1.DSAparam.decode(ndata.subjectPublicKey.data, 'der');
  56456. return {
  56457. type: 'dsa',
  56458. data: ndata.algorithm.params
  56459. };
  56460. default:
  56461. throw new Error('unknown key id ' + subtype);
  56462. }
  56463. // throw new Error('unknown key type ' + type)
  56464. case 'ENCRYPTED PRIVATE KEY':
  56465. data = asn1.EncryptedPrivateKey.decode(data, 'der');
  56466. data = decrypt(data, password);
  56467. // falls through
  56468. case 'PRIVATE KEY':
  56469. ndata = asn1.PrivateKey.decode(data, 'der');
  56470. subtype = ndata.algorithm.algorithm.join('.');
  56471. switch (subtype) {
  56472. case '1.2.840.113549.1.1.1':
  56473. return asn1.RSAPrivateKey.decode(ndata.subjectPrivateKey, 'der');
  56474. case '1.2.840.10045.2.1':
  56475. return {
  56476. curve: ndata.algorithm.curve,
  56477. privateKey: asn1.ECPrivateKey.decode(ndata.subjectPrivateKey, 'der').privateKey
  56478. };
  56479. case '1.2.840.10040.4.1':
  56480. ndata.algorithm.params.priv_key = asn1.DSAparam.decode(ndata.subjectPrivateKey, 'der');
  56481. return {
  56482. type: 'dsa',
  56483. params: ndata.algorithm.params
  56484. };
  56485. default:
  56486. throw new Error('unknown key id ' + subtype);
  56487. }
  56488. // throw new Error('unknown key type ' + type)
  56489. case 'RSA PUBLIC KEY':
  56490. return asn1.RSAPublicKey.decode(data, 'der');
  56491. case 'RSA PRIVATE KEY':
  56492. return asn1.RSAPrivateKey.decode(data, 'der');
  56493. case 'DSA PRIVATE KEY':
  56494. return {
  56495. type: 'dsa',
  56496. params: asn1.DSAPrivateKey.decode(data, 'der')
  56497. };
  56498. case 'EC PRIVATE KEY':
  56499. data = asn1.ECPrivateKey.decode(data, 'der');
  56500. return {
  56501. curve: data.parameters.value,
  56502. privateKey: data.privateKey
  56503. };
  56504. default:
  56505. throw new Error('unknown key type ' + type);
  56506. }
  56507. }
  56508. parseKeys.signature = asn1.signature;
  56509. function decrypt(data, password) {
  56510. var salt = data.algorithm.decrypt.kde.kdeparams.salt;
  56511. var iters = parseInt(data.algorithm.decrypt.kde.kdeparams.iters.toString(), 10);
  56512. var algo = aesid[data.algorithm.decrypt.cipher.algo.join('.')];
  56513. var iv = data.algorithm.decrypt.cipher.iv;
  56514. var cipherText = data.subjectPrivateKey;
  56515. var keylen = parseInt(algo.split('-')[1], 10) / 8;
  56516. var key = compat.pbkdf2Sync(password, salt, iters, keylen, 'sha1');
  56517. var cipher = ciphers.createDecipheriv(algo, key, iv);
  56518. var out = [];
  56519. out.push(cipher.update(cipherText));
  56520. out.push(cipher.final());
  56521. return Buffer.concat(out);
  56522. }
  56523. },{"./aesid.json":455,"./asn1":456,"./fixProc":458,"browserify-aes":188,"pbkdf2":460,"safe-buffer":494}],460:[function(require,module,exports){
  56524. "use strict";
  56525. exports.pbkdf2 = require('./lib/async');
  56526. exports.pbkdf2Sync = require('./lib/sync');
  56527. },{"./lib/async":461,"./lib/sync":464}],461:[function(require,module,exports){
  56528. (function (process,global){
  56529. "use strict";
  56530. var Buffer = require('safe-buffer').Buffer;
  56531. var checkParameters = require('./precondition');
  56532. var defaultEncoding = require('./default-encoding');
  56533. var sync = require('./sync');
  56534. var toBuffer = require('./to-buffer');
  56535. var ZERO_BUF;
  56536. var subtle = global.crypto && global.crypto.subtle;
  56537. var toBrowser = {
  56538. sha: 'SHA-1',
  56539. 'sha-1': 'SHA-1',
  56540. sha1: 'SHA-1',
  56541. sha256: 'SHA-256',
  56542. 'sha-256': 'SHA-256',
  56543. sha384: 'SHA-384',
  56544. 'sha-384': 'SHA-384',
  56545. 'sha-512': 'SHA-512',
  56546. sha512: 'SHA-512'
  56547. };
  56548. var checks = [];
  56549. function checkNative(algo) {
  56550. if (global.process && !global.process.browser) {
  56551. return Promise.resolve(false);
  56552. }
  56553. if (!subtle || !subtle.importKey || !subtle.deriveBits) {
  56554. return Promise.resolve(false);
  56555. }
  56556. if (checks[algo] !== undefined) {
  56557. return checks[algo];
  56558. }
  56559. ZERO_BUF = ZERO_BUF || Buffer.alloc(8);
  56560. var prom = browserPbkdf2(ZERO_BUF, ZERO_BUF, 10, 128, algo).then(function () {
  56561. return true;
  56562. }).catch(function () {
  56563. return false;
  56564. });
  56565. checks[algo] = prom;
  56566. return prom;
  56567. }
  56568. function browserPbkdf2(password, salt, iterations, length, algo) {
  56569. return subtle.importKey('raw', password, {
  56570. name: 'PBKDF2'
  56571. }, false, ['deriveBits']).then(function (key) {
  56572. return subtle.deriveBits({
  56573. name: 'PBKDF2',
  56574. salt: salt,
  56575. iterations: iterations,
  56576. hash: {
  56577. name: algo
  56578. }
  56579. }, key, length << 3);
  56580. }).then(function (res) {
  56581. return Buffer.from(res);
  56582. });
  56583. }
  56584. function resolvePromise(promise, callback) {
  56585. promise.then(function (out) {
  56586. process.nextTick(function () {
  56587. callback(null, out);
  56588. });
  56589. }, function (e) {
  56590. process.nextTick(function () {
  56591. callback(e);
  56592. });
  56593. });
  56594. }
  56595. module.exports = function (password, salt, iterations, keylen, digest, callback) {
  56596. if (typeof digest === 'function') {
  56597. callback = digest;
  56598. digest = undefined;
  56599. }
  56600. digest = digest || 'sha1';
  56601. var algo = toBrowser[digest.toLowerCase()];
  56602. if (!algo || typeof global.Promise !== 'function') {
  56603. return process.nextTick(function () {
  56604. var out;
  56605. try {
  56606. out = sync(password, salt, iterations, keylen, digest);
  56607. } catch (e) {
  56608. return callback(e);
  56609. }
  56610. callback(null, out);
  56611. });
  56612. }
  56613. checkParameters(iterations, keylen);
  56614. password = toBuffer(password, defaultEncoding, 'Password');
  56615. salt = toBuffer(salt, defaultEncoding, 'Salt');
  56616. if (typeof callback !== 'function') throw new Error('No callback provided to pbkdf2');
  56617. resolvePromise(checkNative(algo).then(function (resp) {
  56618. if (resp) return browserPbkdf2(password, salt, iterations, keylen, algo);
  56619. return sync(password, salt, iterations, keylen, digest);
  56620. }), callback);
  56621. };
  56622. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  56623. },{"./default-encoding":462,"./precondition":463,"./sync":464,"./to-buffer":465,"_process":467,"safe-buffer":494}],462:[function(require,module,exports){
  56624. (function (process){
  56625. "use strict";
  56626. var defaultEncoding;
  56627. /* istanbul ignore next */
  56628. if (process.browser) {
  56629. defaultEncoding = 'utf-8';
  56630. } else if (process.version) {
  56631. var pVersionMajor = parseInt(process.version.split('.')[0].slice(1), 10);
  56632. defaultEncoding = pVersionMajor >= 6 ? 'utf-8' : 'binary';
  56633. } else {
  56634. defaultEncoding = 'utf-8';
  56635. }
  56636. module.exports = defaultEncoding;
  56637. }).call(this,require('_process'))
  56638. },{"_process":467}],463:[function(require,module,exports){
  56639. "use strict";
  56640. var MAX_ALLOC = Math.pow(2, 30) - 1; // default in iojs
  56641. module.exports = function (iterations, keylen) {
  56642. if (typeof iterations !== 'number') {
  56643. throw new TypeError('Iterations not a number');
  56644. }
  56645. if (iterations < 0) {
  56646. throw new TypeError('Bad iterations');
  56647. }
  56648. if (typeof keylen !== 'number') {
  56649. throw new TypeError('Key length not a number');
  56650. }
  56651. if (keylen < 0 || keylen > MAX_ALLOC || keylen !== keylen) {
  56652. /* eslint no-self-compare: 0 */
  56653. throw new TypeError('Bad key length');
  56654. }
  56655. };
  56656. },{}],464:[function(require,module,exports){
  56657. "use strict";
  56658. var md5 = require('create-hash/md5');
  56659. var RIPEMD160 = require('ripemd160');
  56660. var sha = require('sha.js');
  56661. var Buffer = require('safe-buffer').Buffer;
  56662. var checkParameters = require('./precondition');
  56663. var defaultEncoding = require('./default-encoding');
  56664. var toBuffer = require('./to-buffer');
  56665. var ZEROS = Buffer.alloc(128);
  56666. var sizes = {
  56667. md5: 16,
  56668. sha1: 20,
  56669. sha224: 28,
  56670. sha256: 32,
  56671. sha384: 48,
  56672. sha512: 64,
  56673. rmd160: 20,
  56674. ripemd160: 20
  56675. };
  56676. function Hmac(alg, key, saltLen) {
  56677. var hash = getDigest(alg);
  56678. var blocksize = alg === 'sha512' || alg === 'sha384' ? 128 : 64;
  56679. if (key.length > blocksize) {
  56680. key = hash(key);
  56681. } else if (key.length < blocksize) {
  56682. key = Buffer.concat([key, ZEROS], blocksize);
  56683. }
  56684. var ipad = Buffer.allocUnsafe(blocksize + sizes[alg]);
  56685. var opad = Buffer.allocUnsafe(blocksize + sizes[alg]);
  56686. for (var i = 0; i < blocksize; i++) {
  56687. ipad[i] = key[i] ^ 0x36;
  56688. opad[i] = key[i] ^ 0x5C;
  56689. }
  56690. var ipad1 = Buffer.allocUnsafe(blocksize + saltLen + 4);
  56691. ipad.copy(ipad1, 0, 0, blocksize);
  56692. this.ipad1 = ipad1;
  56693. this.ipad2 = ipad;
  56694. this.opad = opad;
  56695. this.alg = alg;
  56696. this.blocksize = blocksize;
  56697. this.hash = hash;
  56698. this.size = sizes[alg];
  56699. }
  56700. Hmac.prototype.run = function (data, ipad) {
  56701. data.copy(ipad, this.blocksize);
  56702. var h = this.hash(ipad);
  56703. h.copy(this.opad, this.blocksize);
  56704. return this.hash(this.opad);
  56705. };
  56706. function getDigest(alg) {
  56707. function shaFunc(data) {
  56708. return sha(alg).update(data).digest();
  56709. }
  56710. function rmd160Func(data) {
  56711. return new RIPEMD160().update(data).digest();
  56712. }
  56713. if (alg === 'rmd160' || alg === 'ripemd160') return rmd160Func;
  56714. if (alg === 'md5') return md5;
  56715. return shaFunc;
  56716. }
  56717. function pbkdf2(password, salt, iterations, keylen, digest) {
  56718. checkParameters(iterations, keylen);
  56719. password = toBuffer(password, defaultEncoding, 'Password');
  56720. salt = toBuffer(salt, defaultEncoding, 'Salt');
  56721. digest = digest || 'sha1';
  56722. var hmac = new Hmac(digest, password, salt.length);
  56723. var DK = Buffer.allocUnsafe(keylen);
  56724. var block1 = Buffer.allocUnsafe(salt.length + 4);
  56725. salt.copy(block1, 0, 0, salt.length);
  56726. var destPos = 0;
  56727. var hLen = sizes[digest];
  56728. var l = Math.ceil(keylen / hLen);
  56729. for (var i = 1; i <= l; i++) {
  56730. block1.writeUInt32BE(i, salt.length);
  56731. var T = hmac.run(block1, hmac.ipad1);
  56732. var U = T;
  56733. for (var j = 1; j < iterations; j++) {
  56734. U = hmac.run(U, hmac.ipad2);
  56735. for (var k = 0; k < hLen; k++) {
  56736. T[k] ^= U[k];
  56737. }
  56738. }
  56739. T.copy(DK, destPos);
  56740. destPos += hLen;
  56741. }
  56742. return DK;
  56743. }
  56744. module.exports = pbkdf2;
  56745. },{"./default-encoding":462,"./precondition":463,"./to-buffer":465,"create-hash/md5":332,"ripemd160":493,"safe-buffer":494,"sha.js":499}],465:[function(require,module,exports){
  56746. "use strict";
  56747. var Buffer = require('safe-buffer').Buffer;
  56748. module.exports = function (thing, encoding, name) {
  56749. if (Buffer.isBuffer(thing)) {
  56750. return thing;
  56751. } else if (typeof thing === 'string') {
  56752. return Buffer.from(thing, encoding);
  56753. } else if (ArrayBuffer.isView(thing)) {
  56754. return Buffer.from(thing.buffer);
  56755. } else {
  56756. throw new TypeError(name + ' must be a string, a Buffer, a typed array or a DataView');
  56757. }
  56758. };
  56759. },{"safe-buffer":494}],466:[function(require,module,exports){
  56760. (function (process){
  56761. 'use strict';
  56762. if (typeof process === 'undefined' || !process.version || process.version.indexOf('v0.') === 0 || process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
  56763. module.exports = {
  56764. nextTick: nextTick
  56765. };
  56766. } else {
  56767. module.exports = process;
  56768. }
  56769. function nextTick(fn, arg1, arg2, arg3) {
  56770. if (typeof fn !== 'function') {
  56771. throw new TypeError('"callback" argument must be a function');
  56772. }
  56773. var len = arguments.length;
  56774. var args, i;
  56775. switch (len) {
  56776. case 0:
  56777. case 1:
  56778. return process.nextTick(fn);
  56779. case 2:
  56780. return process.nextTick(function afterTickOne() {
  56781. fn.call(null, arg1);
  56782. });
  56783. case 3:
  56784. return process.nextTick(function afterTickTwo() {
  56785. fn.call(null, arg1, arg2);
  56786. });
  56787. case 4:
  56788. return process.nextTick(function afterTickThree() {
  56789. fn.call(null, arg1, arg2, arg3);
  56790. });
  56791. default:
  56792. args = new Array(len - 1);
  56793. i = 0;
  56794. while (i < args.length) {
  56795. args[i++] = arguments[i];
  56796. }
  56797. return process.nextTick(function afterTick() {
  56798. fn.apply(null, args);
  56799. });
  56800. }
  56801. }
  56802. }).call(this,require('_process'))
  56803. },{"_process":467}],467:[function(require,module,exports){
  56804. "use strict";
  56805. // shim for using process in browser
  56806. var process = module.exports = {}; // cached from whatever global is present so that test runners that stub it
  56807. // don't break things. But we need to wrap it in a try catch in case it is
  56808. // wrapped in strict mode code which doesn't define any globals. It's inside a
  56809. // function because try/catches deoptimize in certain engines.
  56810. var cachedSetTimeout;
  56811. var cachedClearTimeout;
  56812. function defaultSetTimout() {
  56813. throw new Error('setTimeout has not been defined');
  56814. }
  56815. function defaultClearTimeout() {
  56816. throw new Error('clearTimeout has not been defined');
  56817. }
  56818. (function () {
  56819. try {
  56820. if (typeof setTimeout === 'function') {
  56821. cachedSetTimeout = setTimeout;
  56822. } else {
  56823. cachedSetTimeout = defaultSetTimout;
  56824. }
  56825. } catch (e) {
  56826. cachedSetTimeout = defaultSetTimout;
  56827. }
  56828. try {
  56829. if (typeof clearTimeout === 'function') {
  56830. cachedClearTimeout = clearTimeout;
  56831. } else {
  56832. cachedClearTimeout = defaultClearTimeout;
  56833. }
  56834. } catch (e) {
  56835. cachedClearTimeout = defaultClearTimeout;
  56836. }
  56837. })();
  56838. function runTimeout(fun) {
  56839. if (cachedSetTimeout === setTimeout) {
  56840. //normal enviroments in sane situations
  56841. return setTimeout(fun, 0);
  56842. } // if setTimeout wasn't available but was latter defined
  56843. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  56844. cachedSetTimeout = setTimeout;
  56845. return setTimeout(fun, 0);
  56846. }
  56847. try {
  56848. // when when somebody has screwed with setTimeout but no I.E. maddness
  56849. return cachedSetTimeout(fun, 0);
  56850. } catch (e) {
  56851. try {
  56852. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  56853. return cachedSetTimeout.call(null, fun, 0);
  56854. } catch (e) {
  56855. // 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
  56856. return cachedSetTimeout.call(this, fun, 0);
  56857. }
  56858. }
  56859. }
  56860. function runClearTimeout(marker) {
  56861. if (cachedClearTimeout === clearTimeout) {
  56862. //normal enviroments in sane situations
  56863. return clearTimeout(marker);
  56864. } // if clearTimeout wasn't available but was latter defined
  56865. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  56866. cachedClearTimeout = clearTimeout;
  56867. return clearTimeout(marker);
  56868. }
  56869. try {
  56870. // when when somebody has screwed with setTimeout but no I.E. maddness
  56871. return cachedClearTimeout(marker);
  56872. } catch (e) {
  56873. try {
  56874. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  56875. return cachedClearTimeout.call(null, marker);
  56876. } catch (e) {
  56877. // 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.
  56878. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  56879. return cachedClearTimeout.call(this, marker);
  56880. }
  56881. }
  56882. }
  56883. var queue = [];
  56884. var draining = false;
  56885. var currentQueue;
  56886. var queueIndex = -1;
  56887. function cleanUpNextTick() {
  56888. if (!draining || !currentQueue) {
  56889. return;
  56890. }
  56891. draining = false;
  56892. if (currentQueue.length) {
  56893. queue = currentQueue.concat(queue);
  56894. } else {
  56895. queueIndex = -1;
  56896. }
  56897. if (queue.length) {
  56898. drainQueue();
  56899. }
  56900. }
  56901. function drainQueue() {
  56902. if (draining) {
  56903. return;
  56904. }
  56905. var timeout = runTimeout(cleanUpNextTick);
  56906. draining = true;
  56907. var len = queue.length;
  56908. while (len) {
  56909. currentQueue = queue;
  56910. queue = [];
  56911. while (++queueIndex < len) {
  56912. if (currentQueue) {
  56913. currentQueue[queueIndex].run();
  56914. }
  56915. }
  56916. queueIndex = -1;
  56917. len = queue.length;
  56918. }
  56919. currentQueue = null;
  56920. draining = false;
  56921. runClearTimeout(timeout);
  56922. }
  56923. process.nextTick = function (fun) {
  56924. var args = new Array(arguments.length - 1);
  56925. if (arguments.length > 1) {
  56926. for (var i = 1; i < arguments.length; i++) {
  56927. args[i - 1] = arguments[i];
  56928. }
  56929. }
  56930. queue.push(new Item(fun, args));
  56931. if (queue.length === 1 && !draining) {
  56932. runTimeout(drainQueue);
  56933. }
  56934. }; // v8 likes predictible objects
  56935. function Item(fun, array) {
  56936. this.fun = fun;
  56937. this.array = array;
  56938. }
  56939. Item.prototype.run = function () {
  56940. this.fun.apply(null, this.array);
  56941. };
  56942. process.title = 'browser';
  56943. process.browser = true;
  56944. process.env = {};
  56945. process.argv = [];
  56946. process.version = ''; // empty string to avoid regexp issues
  56947. process.versions = {};
  56948. function noop() {}
  56949. process.on = noop;
  56950. process.addListener = noop;
  56951. process.once = noop;
  56952. process.off = noop;
  56953. process.removeListener = noop;
  56954. process.removeAllListeners = noop;
  56955. process.emit = noop;
  56956. process.prependListener = noop;
  56957. process.prependOnceListener = noop;
  56958. process.listeners = function (name) {
  56959. return [];
  56960. };
  56961. process.binding = function (name) {
  56962. throw new Error('process.binding is not supported');
  56963. };
  56964. process.cwd = function () {
  56965. return '/';
  56966. };
  56967. process.chdir = function (dir) {
  56968. throw new Error('process.chdir is not supported');
  56969. };
  56970. process.umask = function () {
  56971. return 0;
  56972. };
  56973. },{}],468:[function(require,module,exports){
  56974. "use strict";
  56975. exports.publicEncrypt = require('./publicEncrypt');
  56976. exports.privateDecrypt = require('./privateDecrypt');
  56977. exports.privateEncrypt = function privateEncrypt(key, buf) {
  56978. return exports.publicEncrypt(key, buf, true);
  56979. };
  56980. exports.publicDecrypt = function publicDecrypt(key, buf) {
  56981. return exports.privateDecrypt(key, buf, true);
  56982. };
  56983. },{"./privateDecrypt":471,"./publicEncrypt":472}],469:[function(require,module,exports){
  56984. "use strict";
  56985. var createHash = require('create-hash');
  56986. var Buffer = require('safe-buffer').Buffer;
  56987. module.exports = function (seed, len) {
  56988. var t = Buffer.alloc(0);
  56989. var i = 0;
  56990. var c;
  56991. while (t.length < len) {
  56992. c = i2ops(i++);
  56993. t = Buffer.concat([t, createHash('sha1').update(seed).update(c).digest()]);
  56994. }
  56995. return t.slice(0, len);
  56996. };
  56997. function i2ops(c) {
  56998. var out = Buffer.allocUnsafe(4);
  56999. out.writeUInt32BE(c, 0);
  57000. return out;
  57001. }
  57002. },{"create-hash":331,"safe-buffer":494}],470:[function(require,module,exports){
  57003. arguments[4][181][0].apply(exports,arguments)
  57004. },{"buffer":185,"dup":181}],471:[function(require,module,exports){
  57005. "use strict";
  57006. var parseKeys = require('parse-asn1');
  57007. var mgf = require('./mgf');
  57008. var xor = require('./xor');
  57009. var BN = require('bn.js');
  57010. var crt = require('browserify-rsa');
  57011. var createHash = require('create-hash');
  57012. var withPublic = require('./withPublic');
  57013. var Buffer = require('safe-buffer').Buffer;
  57014. module.exports = function privateDecrypt(privateKey, enc, reverse) {
  57015. var padding;
  57016. if (privateKey.padding) {
  57017. padding = privateKey.padding;
  57018. } else if (reverse) {
  57019. padding = 1;
  57020. } else {
  57021. padding = 4;
  57022. }
  57023. var key = parseKeys(privateKey);
  57024. var k = key.modulus.byteLength();
  57025. if (enc.length > k || new BN(enc).cmp(key.modulus) >= 0) {
  57026. throw new Error('decryption error');
  57027. }
  57028. var msg;
  57029. if (reverse) {
  57030. msg = withPublic(new BN(enc), key);
  57031. } else {
  57032. msg = crt(enc, key);
  57033. }
  57034. var zBuffer = Buffer.alloc(k - msg.length);
  57035. msg = Buffer.concat([zBuffer, msg], k);
  57036. if (padding === 4) {
  57037. return oaep(key, msg);
  57038. } else if (padding === 1) {
  57039. return pkcs1(key, msg, reverse);
  57040. } else if (padding === 3) {
  57041. return msg;
  57042. } else {
  57043. throw new Error('unknown padding');
  57044. }
  57045. };
  57046. function oaep(key, msg) {
  57047. var k = key.modulus.byteLength();
  57048. var iHash = createHash('sha1').update(Buffer.alloc(0)).digest();
  57049. var hLen = iHash.length;
  57050. if (msg[0] !== 0) {
  57051. throw new Error('decryption error');
  57052. }
  57053. var maskedSeed = msg.slice(1, hLen + 1);
  57054. var maskedDb = msg.slice(hLen + 1);
  57055. var seed = xor(maskedSeed, mgf(maskedDb, hLen));
  57056. var db = xor(maskedDb, mgf(seed, k - hLen - 1));
  57057. if (compare(iHash, db.slice(0, hLen))) {
  57058. throw new Error('decryption error');
  57059. }
  57060. var i = hLen;
  57061. while (db[i] === 0) {
  57062. i++;
  57063. }
  57064. if (db[i++] !== 1) {
  57065. throw new Error('decryption error');
  57066. }
  57067. return db.slice(i);
  57068. }
  57069. function pkcs1(key, msg, reverse) {
  57070. var p1 = msg.slice(0, 2);
  57071. var i = 2;
  57072. var status = 0;
  57073. while (msg[i++] !== 0) {
  57074. if (i >= msg.length) {
  57075. status++;
  57076. break;
  57077. }
  57078. }
  57079. var ps = msg.slice(2, i - 1);
  57080. if (p1.toString('hex') !== '0002' && !reverse || p1.toString('hex') !== '0001' && reverse) {
  57081. status++;
  57082. }
  57083. if (ps.length < 8) {
  57084. status++;
  57085. }
  57086. if (status) {
  57087. throw new Error('decryption error');
  57088. }
  57089. return msg.slice(i);
  57090. }
  57091. function compare(a, b) {
  57092. a = Buffer.from(a);
  57093. b = Buffer.from(b);
  57094. var dif = 0;
  57095. var len = a.length;
  57096. if (a.length !== b.length) {
  57097. dif++;
  57098. len = Math.min(a.length, b.length);
  57099. }
  57100. var i = -1;
  57101. while (++i < len) {
  57102. dif += a[i] ^ b[i];
  57103. }
  57104. return dif;
  57105. }
  57106. },{"./mgf":469,"./withPublic":473,"./xor":474,"bn.js":470,"browserify-rsa":206,"create-hash":331,"parse-asn1":459,"safe-buffer":494}],472:[function(require,module,exports){
  57107. "use strict";
  57108. var parseKeys = require('parse-asn1');
  57109. var randomBytes = require('randombytes');
  57110. var createHash = require('create-hash');
  57111. var mgf = require('./mgf');
  57112. var xor = require('./xor');
  57113. var BN = require('bn.js');
  57114. var withPublic = require('./withPublic');
  57115. var crt = require('browserify-rsa');
  57116. var Buffer = require('safe-buffer').Buffer;
  57117. module.exports = function publicEncrypt(publicKey, msg, reverse) {
  57118. var padding;
  57119. if (publicKey.padding) {
  57120. padding = publicKey.padding;
  57121. } else if (reverse) {
  57122. padding = 1;
  57123. } else {
  57124. padding = 4;
  57125. }
  57126. var key = parseKeys(publicKey);
  57127. var paddedMsg;
  57128. if (padding === 4) {
  57129. paddedMsg = oaep(key, msg);
  57130. } else if (padding === 1) {
  57131. paddedMsg = pkcs1(key, msg, reverse);
  57132. } else if (padding === 3) {
  57133. paddedMsg = new BN(msg);
  57134. if (paddedMsg.cmp(key.modulus) >= 0) {
  57135. throw new Error('data too long for modulus');
  57136. }
  57137. } else {
  57138. throw new Error('unknown padding');
  57139. }
  57140. if (reverse) {
  57141. return crt(paddedMsg, key);
  57142. } else {
  57143. return withPublic(paddedMsg, key);
  57144. }
  57145. };
  57146. function oaep(key, msg) {
  57147. var k = key.modulus.byteLength();
  57148. var mLen = msg.length;
  57149. var iHash = createHash('sha1').update(Buffer.alloc(0)).digest();
  57150. var hLen = iHash.length;
  57151. var hLen2 = 2 * hLen;
  57152. if (mLen > k - hLen2 - 2) {
  57153. throw new Error('message too long');
  57154. }
  57155. var ps = Buffer.alloc(k - mLen - hLen2 - 2);
  57156. var dblen = k - hLen - 1;
  57157. var seed = randomBytes(hLen);
  57158. var maskedDb = xor(Buffer.concat([iHash, ps, Buffer.alloc(1, 1), msg], dblen), mgf(seed, dblen));
  57159. var maskedSeed = xor(seed, mgf(maskedDb, hLen));
  57160. return new BN(Buffer.concat([Buffer.alloc(1), maskedSeed, maskedDb], k));
  57161. }
  57162. function pkcs1(key, msg, reverse) {
  57163. var mLen = msg.length;
  57164. var k = key.modulus.byteLength();
  57165. if (mLen > k - 11) {
  57166. throw new Error('message too long');
  57167. }
  57168. var ps;
  57169. if (reverse) {
  57170. ps = Buffer.alloc(k - mLen - 3, 0xff);
  57171. } else {
  57172. ps = nonZero(k - mLen - 3);
  57173. }
  57174. return new BN(Buffer.concat([Buffer.from([0, reverse ? 1 : 2]), ps, Buffer.alloc(1), msg], k));
  57175. }
  57176. function nonZero(len) {
  57177. var out = Buffer.allocUnsafe(len);
  57178. var i = 0;
  57179. var cache = randomBytes(len * 2);
  57180. var cur = 0;
  57181. var num;
  57182. while (i < len) {
  57183. if (cur === cache.length) {
  57184. cache = randomBytes(len * 2);
  57185. cur = 0;
  57186. }
  57187. num = cache[cur++];
  57188. if (num) {
  57189. out[i++] = num;
  57190. }
  57191. }
  57192. return out;
  57193. }
  57194. },{"./mgf":469,"./withPublic":473,"./xor":474,"bn.js":470,"browserify-rsa":206,"create-hash":331,"parse-asn1":459,"randombytes":475,"safe-buffer":494}],473:[function(require,module,exports){
  57195. "use strict";
  57196. var BN = require('bn.js');
  57197. var Buffer = require('safe-buffer').Buffer;
  57198. function withPublic(paddedMsg, key) {
  57199. return Buffer.from(paddedMsg.toRed(BN.mont(key.modulus)).redPow(new BN(key.publicExponent)).fromRed().toArray());
  57200. }
  57201. module.exports = withPublic;
  57202. },{"bn.js":470,"safe-buffer":494}],474:[function(require,module,exports){
  57203. "use strict";
  57204. module.exports = function xor(a, b) {
  57205. var len = a.length;
  57206. var i = -1;
  57207. while (++i < len) {
  57208. a[i] ^= b[i];
  57209. }
  57210. return a;
  57211. };
  57212. },{}],475:[function(require,module,exports){
  57213. (function (process,global){
  57214. 'use strict'; // limit of Crypto.getRandomValues()
  57215. // https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
  57216. var MAX_BYTES = 65536; // Node supports requesting up to this number of bytes
  57217. // https://github.com/nodejs/node/blob/master/lib/internal/crypto/random.js#L48
  57218. var MAX_UINT32 = 4294967295;
  57219. function oldBrowser() {
  57220. throw new Error('Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11');
  57221. }
  57222. var Buffer = require('safe-buffer').Buffer;
  57223. var crypto = global.crypto || global.msCrypto;
  57224. if (crypto && crypto.getRandomValues) {
  57225. module.exports = randomBytes;
  57226. } else {
  57227. module.exports = oldBrowser;
  57228. }
  57229. function randomBytes(size, cb) {
  57230. // phantomjs needs to throw
  57231. if (size > MAX_UINT32) throw new RangeError('requested too many random bytes');
  57232. var bytes = Buffer.allocUnsafe(size);
  57233. if (size > 0) {
  57234. // getRandomValues fails on IE if size == 0
  57235. if (size > MAX_BYTES) {
  57236. // this is the max bytes crypto.getRandomValues
  57237. // can do at once see https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
  57238. for (var generated = 0; generated < size; generated += MAX_BYTES) {
  57239. // buffer.slice automatically checks if the end is past the end of
  57240. // the buffer so we don't have to here
  57241. crypto.getRandomValues(bytes.slice(generated, generated + MAX_BYTES));
  57242. }
  57243. } else {
  57244. crypto.getRandomValues(bytes);
  57245. }
  57246. }
  57247. if (typeof cb === 'function') {
  57248. return process.nextTick(function () {
  57249. cb(null, bytes);
  57250. });
  57251. }
  57252. return bytes;
  57253. }
  57254. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  57255. },{"_process":467,"safe-buffer":494}],476:[function(require,module,exports){
  57256. (function (process,global){
  57257. 'use strict';
  57258. function oldBrowser() {
  57259. throw new Error('secure random number generation not supported by this browser\nuse chrome, FireFox or Internet Explorer 11');
  57260. }
  57261. var safeBuffer = require('safe-buffer');
  57262. var randombytes = require('randombytes');
  57263. var Buffer = safeBuffer.Buffer;
  57264. var kBufferMaxLength = safeBuffer.kMaxLength;
  57265. var crypto = global.crypto || global.msCrypto;
  57266. var kMaxUint32 = Math.pow(2, 32) - 1;
  57267. function assertOffset(offset, length) {
  57268. if (typeof offset !== 'number' || offset !== offset) {
  57269. // eslint-disable-line no-self-compare
  57270. throw new TypeError('offset must be a number');
  57271. }
  57272. if (offset > kMaxUint32 || offset < 0) {
  57273. throw new TypeError('offset must be a uint32');
  57274. }
  57275. if (offset > kBufferMaxLength || offset > length) {
  57276. throw new RangeError('offset out of range');
  57277. }
  57278. }
  57279. function assertSize(size, offset, length) {
  57280. if (typeof size !== 'number' || size !== size) {
  57281. // eslint-disable-line no-self-compare
  57282. throw new TypeError('size must be a number');
  57283. }
  57284. if (size > kMaxUint32 || size < 0) {
  57285. throw new TypeError('size must be a uint32');
  57286. }
  57287. if (size + offset > length || size > kBufferMaxLength) {
  57288. throw new RangeError('buffer too small');
  57289. }
  57290. }
  57291. if (crypto && crypto.getRandomValues || !process.browser) {
  57292. exports.randomFill = randomFill;
  57293. exports.randomFillSync = randomFillSync;
  57294. } else {
  57295. exports.randomFill = oldBrowser;
  57296. exports.randomFillSync = oldBrowser;
  57297. }
  57298. function randomFill(buf, offset, size, cb) {
  57299. if (!Buffer.isBuffer(buf) && !(buf instanceof global.Uint8Array)) {
  57300. throw new TypeError('"buf" argument must be a Buffer or Uint8Array');
  57301. }
  57302. if (typeof offset === 'function') {
  57303. cb = offset;
  57304. offset = 0;
  57305. size = buf.length;
  57306. } else if (typeof size === 'function') {
  57307. cb = size;
  57308. size = buf.length - offset;
  57309. } else if (typeof cb !== 'function') {
  57310. throw new TypeError('"cb" argument must be a function');
  57311. }
  57312. assertOffset(offset, buf.length);
  57313. assertSize(size, offset, buf.length);
  57314. return actualFill(buf, offset, size, cb);
  57315. }
  57316. function actualFill(buf, offset, size, cb) {
  57317. if (process.browser) {
  57318. var ourBuf = buf.buffer;
  57319. var uint = new Uint8Array(ourBuf, offset, size);
  57320. crypto.getRandomValues(uint);
  57321. if (cb) {
  57322. process.nextTick(function () {
  57323. cb(null, buf);
  57324. });
  57325. return;
  57326. }
  57327. return buf;
  57328. }
  57329. if (cb) {
  57330. randombytes(size, function (err, bytes) {
  57331. if (err) {
  57332. return cb(err);
  57333. }
  57334. bytes.copy(buf, offset);
  57335. cb(null, buf);
  57336. });
  57337. return;
  57338. }
  57339. var bytes = randombytes(size);
  57340. bytes.copy(buf, offset);
  57341. return buf;
  57342. }
  57343. function randomFillSync(buf, offset, size) {
  57344. if (typeof offset === 'undefined') {
  57345. offset = 0;
  57346. }
  57347. if (!Buffer.isBuffer(buf) && !(buf instanceof global.Uint8Array)) {
  57348. throw new TypeError('"buf" argument must be a Buffer or Uint8Array');
  57349. }
  57350. assertOffset(offset, buf.length);
  57351. if (size === undefined) size = buf.length - offset;
  57352. assertSize(size, offset, buf.length);
  57353. return actualFill(buf, offset, size);
  57354. }
  57355. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  57356. },{"_process":467,"randombytes":475,"safe-buffer":494}],477:[function(require,module,exports){
  57357. 'use strict';
  57358. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  57359. function _inheritsLoose(subClass, superClass) {
  57360. subClass.prototype = Object.create(superClass.prototype);
  57361. subClass.prototype.constructor = subClass;
  57362. subClass.__proto__ = superClass;
  57363. }
  57364. var codes = {};
  57365. function createErrorType(code, message, Base) {
  57366. if (!Base) {
  57367. Base = Error;
  57368. }
  57369. function getMessage(arg1, arg2, arg3) {
  57370. if (typeof message === 'string') {
  57371. return message;
  57372. } else {
  57373. return message(arg1, arg2, arg3);
  57374. }
  57375. }
  57376. var NodeError = /*#__PURE__*/function (_Base) {
  57377. _inheritsLoose(NodeError, _Base);
  57378. function NodeError(arg1, arg2, arg3) {
  57379. return _Base.call(this, getMessage(arg1, arg2, arg3)) || this;
  57380. }
  57381. return NodeError;
  57382. }(Base);
  57383. NodeError.prototype.name = Base.name;
  57384. NodeError.prototype.code = code;
  57385. codes[code] = NodeError;
  57386. } // https://github.com/nodejs/node/blob/v10.8.0/lib/internal/errors.js
  57387. function oneOf(expected, thing) {
  57388. if (Array.isArray(expected)) {
  57389. var len = expected.length;
  57390. expected = expected.map(function (i) {
  57391. return String(i);
  57392. });
  57393. if (len > 2) {
  57394. return "one of ".concat(thing, " ").concat(expected.slice(0, len - 1).join(', '), ", or ") + expected[len - 1];
  57395. } else if (len === 2) {
  57396. return "one of ".concat(thing, " ").concat(expected[0], " or ").concat(expected[1]);
  57397. } else {
  57398. return "of ".concat(thing, " ").concat(expected[0]);
  57399. }
  57400. } else {
  57401. return "of ".concat(thing, " ").concat(String(expected));
  57402. }
  57403. } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
  57404. function startsWith(str, search, pos) {
  57405. return str.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;
  57406. } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
  57407. function endsWith(str, search, this_len) {
  57408. if (this_len === undefined || this_len > str.length) {
  57409. this_len = str.length;
  57410. }
  57411. return str.substring(this_len - search.length, this_len) === search;
  57412. } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes
  57413. function includes(str, search, start) {
  57414. if (typeof start !== 'number') {
  57415. start = 0;
  57416. }
  57417. if (start + search.length > str.length) {
  57418. return false;
  57419. } else {
  57420. return str.indexOf(search, start) !== -1;
  57421. }
  57422. }
  57423. createErrorType('ERR_INVALID_OPT_VALUE', function (name, value) {
  57424. return 'The value "' + value + '" is invalid for option "' + name + '"';
  57425. }, TypeError);
  57426. createErrorType('ERR_INVALID_ARG_TYPE', function (name, expected, actual) {
  57427. // determiner: 'must be' or 'must not be'
  57428. var determiner;
  57429. if (typeof expected === 'string' && startsWith(expected, 'not ')) {
  57430. determiner = 'must not be';
  57431. expected = expected.replace(/^not /, '');
  57432. } else {
  57433. determiner = 'must be';
  57434. }
  57435. var msg;
  57436. if (endsWith(name, ' argument')) {
  57437. // For cases like 'first argument'
  57438. msg = "The ".concat(name, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
  57439. } else {
  57440. var type = includes(name, '.') ? 'property' : 'argument';
  57441. msg = "The \"".concat(name, "\" ").concat(type, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
  57442. }
  57443. msg += ". Received type ".concat(_typeof(actual));
  57444. return msg;
  57445. }, TypeError);
  57446. createErrorType('ERR_STREAM_PUSH_AFTER_EOF', 'stream.push() after EOF');
  57447. createErrorType('ERR_METHOD_NOT_IMPLEMENTED', function (name) {
  57448. return 'The ' + name + ' method is not implemented';
  57449. });
  57450. createErrorType('ERR_STREAM_PREMATURE_CLOSE', 'Premature close');
  57451. createErrorType('ERR_STREAM_DESTROYED', function (name) {
  57452. return 'Cannot call ' + name + ' after a stream was destroyed';
  57453. });
  57454. createErrorType('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times');
  57455. createErrorType('ERR_STREAM_CANNOT_PIPE', 'Cannot pipe, not readable');
  57456. createErrorType('ERR_STREAM_WRITE_AFTER_END', 'write after end');
  57457. createErrorType('ERR_STREAM_NULL_VALUES', 'May not write null values to stream', TypeError);
  57458. createErrorType('ERR_UNKNOWN_ENCODING', function (arg) {
  57459. return 'Unknown encoding: ' + arg;
  57460. }, TypeError);
  57461. createErrorType('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event');
  57462. module.exports.codes = codes;
  57463. },{}],478:[function(require,module,exports){
  57464. (function (process){
  57465. // Copyright Joyent, Inc. and other Node contributors.
  57466. //
  57467. // Permission is hereby granted, free of charge, to any person obtaining a
  57468. // copy of this software and associated documentation files (the
  57469. // "Software"), to deal in the Software without restriction, including
  57470. // without limitation the rights to use, copy, modify, merge, publish,
  57471. // distribute, sublicense, and/or sell copies of the Software, and to permit
  57472. // persons to whom the Software is furnished to do so, subject to the
  57473. // following conditions:
  57474. //
  57475. // The above copyright notice and this permission notice shall be included
  57476. // in all copies or substantial portions of the Software.
  57477. //
  57478. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  57479. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  57480. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  57481. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  57482. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  57483. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  57484. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  57485. // a duplex stream is just a stream that is both readable and writable.
  57486. // Since JS doesn't have multiple prototypal inheritance, this class
  57487. // prototypally inherits from Readable, and then parasitically from
  57488. // Writable.
  57489. 'use strict';
  57490. /*<replacement>*/
  57491. var objectKeys = Object.keys || function (obj) {
  57492. var keys = [];
  57493. for (var key in obj) {
  57494. keys.push(key);
  57495. }
  57496. return keys;
  57497. };
  57498. /*</replacement>*/
  57499. module.exports = Duplex;
  57500. var Readable = require('./_stream_readable');
  57501. var Writable = require('./_stream_writable');
  57502. require('inherits')(Duplex, Readable);
  57503. {
  57504. // Allow the keys array to be GC'ed.
  57505. var keys = objectKeys(Writable.prototype);
  57506. for (var v = 0; v < keys.length; v++) {
  57507. var method = keys[v];
  57508. if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
  57509. }
  57510. }
  57511. function Duplex(options) {
  57512. if (!(this instanceof Duplex)) return new Duplex(options);
  57513. Readable.call(this, options);
  57514. Writable.call(this, options);
  57515. this.allowHalfOpen = true;
  57516. if (options) {
  57517. if (options.readable === false) this.readable = false;
  57518. if (options.writable === false) this.writable = false;
  57519. if (options.allowHalfOpen === false) {
  57520. this.allowHalfOpen = false;
  57521. this.once('end', onend);
  57522. }
  57523. }
  57524. }
  57525. Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
  57526. // making it explicit this property is not enumerable
  57527. // because otherwise some prototype manipulation in
  57528. // userland will fail
  57529. enumerable: false,
  57530. get: function get() {
  57531. return this._writableState.highWaterMark;
  57532. }
  57533. });
  57534. Object.defineProperty(Duplex.prototype, 'writableBuffer', {
  57535. // making it explicit this property is not enumerable
  57536. // because otherwise some prototype manipulation in
  57537. // userland will fail
  57538. enumerable: false,
  57539. get: function get() {
  57540. return this._writableState && this._writableState.getBuffer();
  57541. }
  57542. });
  57543. Object.defineProperty(Duplex.prototype, 'writableLength', {
  57544. // making it explicit this property is not enumerable
  57545. // because otherwise some prototype manipulation in
  57546. // userland will fail
  57547. enumerable: false,
  57548. get: function get() {
  57549. return this._writableState.length;
  57550. }
  57551. }); // the no-half-open enforcer
  57552. function onend() {
  57553. // If the writable side ended, then we're ok.
  57554. if (this._writableState.ended) return; // no more data can be written.
  57555. // But allow more writes to happen in this tick.
  57556. process.nextTick(onEndNT, this);
  57557. }
  57558. function onEndNT(self) {
  57559. self.end();
  57560. }
  57561. Object.defineProperty(Duplex.prototype, 'destroyed', {
  57562. // making it explicit this property is not enumerable
  57563. // because otherwise some prototype manipulation in
  57564. // userland will fail
  57565. enumerable: false,
  57566. get: function get() {
  57567. if (this._readableState === undefined || this._writableState === undefined) {
  57568. return false;
  57569. }
  57570. return this._readableState.destroyed && this._writableState.destroyed;
  57571. },
  57572. set: function set(value) {
  57573. // we ignore the value if the stream
  57574. // has not been initialized yet
  57575. if (this._readableState === undefined || this._writableState === undefined) {
  57576. return;
  57577. } // backward compatibility, the user is explicitly
  57578. // managing destroyed
  57579. this._readableState.destroyed = value;
  57580. this._writableState.destroyed = value;
  57581. }
  57582. });
  57583. }).call(this,require('_process'))
  57584. },{"./_stream_readable":480,"./_stream_writable":482,"_process":467,"inherits":387}],479:[function(require,module,exports){
  57585. // Copyright Joyent, Inc. and other Node contributors.
  57586. //
  57587. // Permission is hereby granted, free of charge, to any person obtaining a
  57588. // copy of this software and associated documentation files (the
  57589. // "Software"), to deal in the Software without restriction, including
  57590. // without limitation the rights to use, copy, modify, merge, publish,
  57591. // distribute, sublicense, and/or sell copies of the Software, and to permit
  57592. // persons to whom the Software is furnished to do so, subject to the
  57593. // following conditions:
  57594. //
  57595. // The above copyright notice and this permission notice shall be included
  57596. // in all copies or substantial portions of the Software.
  57597. //
  57598. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  57599. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  57600. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  57601. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  57602. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  57603. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  57604. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  57605. // a passthrough stream.
  57606. // basically just the most minimal sort of Transform stream.
  57607. // Every written chunk gets output as-is.
  57608. 'use strict';
  57609. module.exports = PassThrough;
  57610. var Transform = require('./_stream_transform');
  57611. require('inherits')(PassThrough, Transform);
  57612. function PassThrough(options) {
  57613. if (!(this instanceof PassThrough)) return new PassThrough(options);
  57614. Transform.call(this, options);
  57615. }
  57616. PassThrough.prototype._transform = function (chunk, encoding, cb) {
  57617. cb(null, chunk);
  57618. };
  57619. },{"./_stream_transform":481,"inherits":387}],480:[function(require,module,exports){
  57620. (function (process,global){
  57621. // Copyright Joyent, Inc. and other Node contributors.
  57622. //
  57623. // Permission is hereby granted, free of charge, to any person obtaining a
  57624. // copy of this software and associated documentation files (the
  57625. // "Software"), to deal in the Software without restriction, including
  57626. // without limitation the rights to use, copy, modify, merge, publish,
  57627. // distribute, sublicense, and/or sell copies of the Software, and to permit
  57628. // persons to whom the Software is furnished to do so, subject to the
  57629. // following conditions:
  57630. //
  57631. // The above copyright notice and this permission notice shall be included
  57632. // in all copies or substantial portions of the Software.
  57633. //
  57634. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  57635. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  57636. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  57637. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  57638. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  57639. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  57640. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  57641. 'use strict';
  57642. module.exports = Readable;
  57643. /*<replacement>*/
  57644. var Duplex;
  57645. /*</replacement>*/
  57646. Readable.ReadableState = ReadableState;
  57647. /*<replacement>*/
  57648. var EE = require('events').EventEmitter;
  57649. var EElistenerCount = function EElistenerCount(emitter, type) {
  57650. return emitter.listeners(type).length;
  57651. };
  57652. /*</replacement>*/
  57653. /*<replacement>*/
  57654. var Stream = require('./internal/streams/stream');
  57655. /*</replacement>*/
  57656. var Buffer = require('buffer').Buffer;
  57657. var OurUint8Array = global.Uint8Array || function () {};
  57658. function _uint8ArrayToBuffer(chunk) {
  57659. return Buffer.from(chunk);
  57660. }
  57661. function _isUint8Array(obj) {
  57662. return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
  57663. }
  57664. /*<replacement>*/
  57665. var debugUtil = require('util');
  57666. var debug;
  57667. if (debugUtil && debugUtil.debuglog) {
  57668. debug = debugUtil.debuglog('stream');
  57669. } else {
  57670. debug = function debug() {};
  57671. }
  57672. /*</replacement>*/
  57673. var BufferList = require('./internal/streams/buffer_list');
  57674. var destroyImpl = require('./internal/streams/destroy');
  57675. var _require = require('./internal/streams/state'),
  57676. getHighWaterMark = _require.getHighWaterMark;
  57677. var _require$codes = require('../errors').codes,
  57678. ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
  57679. ERR_STREAM_PUSH_AFTER_EOF = _require$codes.ERR_STREAM_PUSH_AFTER_EOF,
  57680. ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
  57681. ERR_STREAM_UNSHIFT_AFTER_END_EVENT = _require$codes.ERR_STREAM_UNSHIFT_AFTER_END_EVENT; // Lazy loaded to improve the startup performance.
  57682. var StringDecoder;
  57683. var createReadableStreamAsyncIterator;
  57684. var from;
  57685. require('inherits')(Readable, Stream);
  57686. var errorOrDestroy = destroyImpl.errorOrDestroy;
  57687. var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
  57688. function prependListener(emitter, event, fn) {
  57689. // Sadly this is not cacheable as some libraries bundle their own
  57690. // event emitter implementation with them.
  57691. if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn); // This is a hack to make sure that our error handler is attached before any
  57692. // userland ones. NEVER DO THIS. This is here only because this code needs
  57693. // to continue to work with older versions of Node.js that do not include
  57694. // the prependListener() method. The goal is to eventually remove this hack.
  57695. 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]];
  57696. }
  57697. function ReadableState(options, stream, isDuplex) {
  57698. Duplex = Duplex || require('./_stream_duplex');
  57699. options = options || {}; // Duplex streams are both readable and writable, but share
  57700. // the same options object.
  57701. // However, some cases require setting options to different
  57702. // values for the readable and the writable sides of the duplex stream.
  57703. // These options can be provided separately as readableXXX and writableXXX.
  57704. if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex; // object stream flag. Used to make read(n) ignore n and to
  57705. // make all the buffer merging and length checks go away
  57706. this.objectMode = !!options.objectMode;
  57707. if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode; // the point at which it stops calling _read() to fill the buffer
  57708. // Note: 0 is a valid value, means "don't call _read preemptively ever"
  57709. this.highWaterMark = getHighWaterMark(this, options, 'readableHighWaterMark', isDuplex); // A linked list is used to store data chunks instead of an array because the
  57710. // linked list can remove elements from the beginning faster than
  57711. // array.shift()
  57712. this.buffer = new BufferList();
  57713. this.length = 0;
  57714. this.pipes = null;
  57715. this.pipesCount = 0;
  57716. this.flowing = null;
  57717. this.ended = false;
  57718. this.endEmitted = false;
  57719. this.reading = false; // a flag to be able to tell if the event 'readable'/'data' is emitted
  57720. // immediately, or on a later tick. We set this to true at first, because
  57721. // any actions that shouldn't happen until "later" should generally also
  57722. // not happen before the first read call.
  57723. this.sync = true; // whenever we return null, then we set a flag to say
  57724. // that we're awaiting a 'readable' event emission.
  57725. this.needReadable = false;
  57726. this.emittedReadable = false;
  57727. this.readableListening = false;
  57728. this.resumeScheduled = false;
  57729. this.paused = true; // Should close be emitted on destroy. Defaults to true.
  57730. this.emitClose = options.emitClose !== false; // Should .destroy() be called after 'end' (and potentially 'finish')
  57731. this.autoDestroy = !!options.autoDestroy; // has it been destroyed
  57732. this.destroyed = false; // Crypto is kind of old and crusty. Historically, its default string
  57733. // encoding is 'binary' so we have to make this configurable.
  57734. // Everything else in the universe uses 'utf8', though.
  57735. this.defaultEncoding = options.defaultEncoding || 'utf8'; // the number of writers that are awaiting a drain event in .pipe()s
  57736. this.awaitDrain = 0; // if true, a maybeReadMore has been scheduled
  57737. this.readingMore = false;
  57738. this.decoder = null;
  57739. this.encoding = null;
  57740. if (options.encoding) {
  57741. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  57742. this.decoder = new StringDecoder(options.encoding);
  57743. this.encoding = options.encoding;
  57744. }
  57745. }
  57746. function Readable(options) {
  57747. Duplex = Duplex || require('./_stream_duplex');
  57748. if (!(this instanceof Readable)) return new Readable(options); // Checking for a Stream.Duplex instance is faster here instead of inside
  57749. // the ReadableState constructor, at least with V8 6.5
  57750. var isDuplex = this instanceof Duplex;
  57751. this._readableState = new ReadableState(options, this, isDuplex); // legacy
  57752. this.readable = true;
  57753. if (options) {
  57754. if (typeof options.read === 'function') this._read = options.read;
  57755. if (typeof options.destroy === 'function') this._destroy = options.destroy;
  57756. }
  57757. Stream.call(this);
  57758. }
  57759. Object.defineProperty(Readable.prototype, 'destroyed', {
  57760. // making it explicit this property is not enumerable
  57761. // because otherwise some prototype manipulation in
  57762. // userland will fail
  57763. enumerable: false,
  57764. get: function get() {
  57765. if (this._readableState === undefined) {
  57766. return false;
  57767. }
  57768. return this._readableState.destroyed;
  57769. },
  57770. set: function set(value) {
  57771. // we ignore the value if the stream
  57772. // has not been initialized yet
  57773. if (!this._readableState) {
  57774. return;
  57775. } // backward compatibility, the user is explicitly
  57776. // managing destroyed
  57777. this._readableState.destroyed = value;
  57778. }
  57779. });
  57780. Readable.prototype.destroy = destroyImpl.destroy;
  57781. Readable.prototype._undestroy = destroyImpl.undestroy;
  57782. Readable.prototype._destroy = function (err, cb) {
  57783. cb(err);
  57784. }; // Manually shove something into the read() buffer.
  57785. // This returns true if the highWaterMark has not been hit yet,
  57786. // similar to how Writable.write() returns true if you should
  57787. // write() some more.
  57788. Readable.prototype.push = function (chunk, encoding) {
  57789. var state = this._readableState;
  57790. var skipChunkCheck;
  57791. if (!state.objectMode) {
  57792. if (typeof chunk === 'string') {
  57793. encoding = encoding || state.defaultEncoding;
  57794. if (encoding !== state.encoding) {
  57795. chunk = Buffer.from(chunk, encoding);
  57796. encoding = '';
  57797. }
  57798. skipChunkCheck = true;
  57799. }
  57800. } else {
  57801. skipChunkCheck = true;
  57802. }
  57803. return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
  57804. }; // Unshift should *always* be something directly out of read()
  57805. Readable.prototype.unshift = function (chunk) {
  57806. return readableAddChunk(this, chunk, null, true, false);
  57807. };
  57808. function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
  57809. debug('readableAddChunk', chunk);
  57810. var state = stream._readableState;
  57811. if (chunk === null) {
  57812. state.reading = false;
  57813. onEofChunk(stream, state);
  57814. } else {
  57815. var er;
  57816. if (!skipChunkCheck) er = chunkInvalid(state, chunk);
  57817. if (er) {
  57818. errorOrDestroy(stream, er);
  57819. } else if (state.objectMode || chunk && chunk.length > 0) {
  57820. if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
  57821. chunk = _uint8ArrayToBuffer(chunk);
  57822. }
  57823. if (addToFront) {
  57824. if (state.endEmitted) errorOrDestroy(stream, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());else addChunk(stream, state, chunk, true);
  57825. } else if (state.ended) {
  57826. errorOrDestroy(stream, new ERR_STREAM_PUSH_AFTER_EOF());
  57827. } else if (state.destroyed) {
  57828. return false;
  57829. } else {
  57830. state.reading = false;
  57831. if (state.decoder && !encoding) {
  57832. chunk = state.decoder.write(chunk);
  57833. if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
  57834. } else {
  57835. addChunk(stream, state, chunk, false);
  57836. }
  57837. }
  57838. } else if (!addToFront) {
  57839. state.reading = false;
  57840. maybeReadMore(stream, state);
  57841. }
  57842. } // We can push more data if we are below the highWaterMark.
  57843. // Also, if we have no data yet, we can stand some more bytes.
  57844. // This is to work around cases where hwm=0, such as the repl.
  57845. return !state.ended && (state.length < state.highWaterMark || state.length === 0);
  57846. }
  57847. function addChunk(stream, state, chunk, addToFront) {
  57848. if (state.flowing && state.length === 0 && !state.sync) {
  57849. state.awaitDrain = 0;
  57850. stream.emit('data', chunk);
  57851. } else {
  57852. // update the buffer info.
  57853. state.length += state.objectMode ? 1 : chunk.length;
  57854. if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
  57855. if (state.needReadable) emitReadable(stream);
  57856. }
  57857. maybeReadMore(stream, state);
  57858. }
  57859. function chunkInvalid(state, chunk) {
  57860. var er;
  57861. if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
  57862. er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer', 'Uint8Array'], chunk);
  57863. }
  57864. return er;
  57865. }
  57866. Readable.prototype.isPaused = function () {
  57867. return this._readableState.flowing === false;
  57868. }; // backwards compatibility.
  57869. Readable.prototype.setEncoding = function (enc) {
  57870. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  57871. var decoder = new StringDecoder(enc);
  57872. this._readableState.decoder = decoder; // If setEncoding(null), decoder.encoding equals utf8
  57873. this._readableState.encoding = this._readableState.decoder.encoding; // Iterate over current buffer to convert already stored Buffers:
  57874. var p = this._readableState.buffer.head;
  57875. var content = '';
  57876. while (p !== null) {
  57877. content += decoder.write(p.data);
  57878. p = p.next;
  57879. }
  57880. this._readableState.buffer.clear();
  57881. if (content !== '') this._readableState.buffer.push(content);
  57882. this._readableState.length = content.length;
  57883. return this;
  57884. }; // Don't raise the hwm > 1GB
  57885. var MAX_HWM = 0x40000000;
  57886. function computeNewHighWaterMark(n) {
  57887. if (n >= MAX_HWM) {
  57888. // TODO(ronag): Throw ERR_VALUE_OUT_OF_RANGE.
  57889. n = MAX_HWM;
  57890. } else {
  57891. // Get the next highest power of 2 to prevent increasing hwm excessively in
  57892. // tiny amounts
  57893. n--;
  57894. n |= n >>> 1;
  57895. n |= n >>> 2;
  57896. n |= n >>> 4;
  57897. n |= n >>> 8;
  57898. n |= n >>> 16;
  57899. n++;
  57900. }
  57901. return n;
  57902. } // This function is designed to be inlinable, so please take care when making
  57903. // changes to the function body.
  57904. function howMuchToRead(n, state) {
  57905. if (n <= 0 || state.length === 0 && state.ended) return 0;
  57906. if (state.objectMode) return 1;
  57907. if (n !== n) {
  57908. // Only flow one buffer at a time
  57909. if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
  57910. } // If we're asking for more than the current hwm, then raise the hwm.
  57911. if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
  57912. if (n <= state.length) return n; // Don't have enough
  57913. if (!state.ended) {
  57914. state.needReadable = true;
  57915. return 0;
  57916. }
  57917. return state.length;
  57918. } // you can override either this method, or the async _read(n) below.
  57919. Readable.prototype.read = function (n) {
  57920. debug('read', n);
  57921. n = parseInt(n, 10);
  57922. var state = this._readableState;
  57923. var nOrig = n;
  57924. if (n !== 0) state.emittedReadable = false; // if we're doing read(0) to trigger a readable event, but we
  57925. // already have a bunch of data in the buffer, then just trigger
  57926. // the 'readable' event and move on.
  57927. if (n === 0 && state.needReadable && ((state.highWaterMark !== 0 ? state.length >= state.highWaterMark : state.length > 0) || state.ended)) {
  57928. debug('read: emitReadable', state.length, state.ended);
  57929. if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
  57930. return null;
  57931. }
  57932. n = howMuchToRead(n, state); // if we've ended, and we're now clear, then finish it up.
  57933. if (n === 0 && state.ended) {
  57934. if (state.length === 0) endReadable(this);
  57935. return null;
  57936. } // All the actual chunk generation logic needs to be
  57937. // *below* the call to _read. The reason is that in certain
  57938. // synthetic stream cases, such as passthrough streams, _read
  57939. // may be a completely synchronous operation which may change
  57940. // the state of the read buffer, providing enough data when
  57941. // before there was *not* enough.
  57942. //
  57943. // So, the steps are:
  57944. // 1. Figure out what the state of things will be after we do
  57945. // a read from the buffer.
  57946. //
  57947. // 2. If that resulting state will trigger a _read, then call _read.
  57948. // Note that this may be asynchronous, or synchronous. Yes, it is
  57949. // deeply ugly to write APIs this way, but that still doesn't mean
  57950. // that the Readable class should behave improperly, as streams are
  57951. // designed to be sync/async agnostic.
  57952. // Take note if the _read call is sync or async (ie, if the read call
  57953. // has returned yet), so that we know whether or not it's safe to emit
  57954. // 'readable' etc.
  57955. //
  57956. // 3. Actually pull the requested chunks out of the buffer and return.
  57957. // if we need a readable event, then we need to do some reading.
  57958. var doRead = state.needReadable;
  57959. debug('need readable', doRead); // if we currently have less than the highWaterMark, then also read some
  57960. if (state.length === 0 || state.length - n < state.highWaterMark) {
  57961. doRead = true;
  57962. debug('length less than watermark', doRead);
  57963. } // however, if we've ended, then there's no point, and if we're already
  57964. // reading, then it's unnecessary.
  57965. if (state.ended || state.reading) {
  57966. doRead = false;
  57967. debug('reading or ended', doRead);
  57968. } else if (doRead) {
  57969. debug('do read');
  57970. state.reading = true;
  57971. state.sync = true; // if the length is currently zero, then we *need* a readable event.
  57972. if (state.length === 0) state.needReadable = true; // call internal read method
  57973. this._read(state.highWaterMark);
  57974. state.sync = false; // If _read pushed data synchronously, then `reading` will be false,
  57975. // and we need to re-evaluate how much data we can return to the user.
  57976. if (!state.reading) n = howMuchToRead(nOrig, state);
  57977. }
  57978. var ret;
  57979. if (n > 0) ret = fromList(n, state);else ret = null;
  57980. if (ret === null) {
  57981. state.needReadable = state.length <= state.highWaterMark;
  57982. n = 0;
  57983. } else {
  57984. state.length -= n;
  57985. state.awaitDrain = 0;
  57986. }
  57987. if (state.length === 0) {
  57988. // If we have nothing in the buffer, then we want to know
  57989. // as soon as we *do* get something into the buffer.
  57990. if (!state.ended) state.needReadable = true; // If we tried to read() past the EOF, then emit end on the next tick.
  57991. if (nOrig !== n && state.ended) endReadable(this);
  57992. }
  57993. if (ret !== null) this.emit('data', ret);
  57994. return ret;
  57995. };
  57996. function onEofChunk(stream, state) {
  57997. debug('onEofChunk');
  57998. if (state.ended) return;
  57999. if (state.decoder) {
  58000. var chunk = state.decoder.end();
  58001. if (chunk && chunk.length) {
  58002. state.buffer.push(chunk);
  58003. state.length += state.objectMode ? 1 : chunk.length;
  58004. }
  58005. }
  58006. state.ended = true;
  58007. if (state.sync) {
  58008. // if we are sync, wait until next tick to emit the data.
  58009. // Otherwise we risk emitting data in the flow()
  58010. // the readable code triggers during a read() call
  58011. emitReadable(stream);
  58012. } else {
  58013. // emit 'readable' now to make sure it gets picked up.
  58014. state.needReadable = false;
  58015. if (!state.emittedReadable) {
  58016. state.emittedReadable = true;
  58017. emitReadable_(stream);
  58018. }
  58019. }
  58020. } // Don't emit readable right away in sync mode, because this can trigger
  58021. // another read() call => stack overflow. This way, it might trigger
  58022. // a nextTick recursion warning, but that's not so bad.
  58023. function emitReadable(stream) {
  58024. var state = stream._readableState;
  58025. debug('emitReadable', state.needReadable, state.emittedReadable);
  58026. state.needReadable = false;
  58027. if (!state.emittedReadable) {
  58028. debug('emitReadable', state.flowing);
  58029. state.emittedReadable = true;
  58030. process.nextTick(emitReadable_, stream);
  58031. }
  58032. }
  58033. function emitReadable_(stream) {
  58034. var state = stream._readableState;
  58035. debug('emitReadable_', state.destroyed, state.length, state.ended);
  58036. if (!state.destroyed && (state.length || state.ended)) {
  58037. stream.emit('readable');
  58038. state.emittedReadable = false;
  58039. } // The stream needs another readable event if
  58040. // 1. It is not flowing, as the flow mechanism will take
  58041. // care of it.
  58042. // 2. It is not ended.
  58043. // 3. It is below the highWaterMark, so we can schedule
  58044. // another readable later.
  58045. state.needReadable = !state.flowing && !state.ended && state.length <= state.highWaterMark;
  58046. flow(stream);
  58047. } // at this point, the user has presumably seen the 'readable' event,
  58048. // and called read() to consume some data. that may have triggered
  58049. // in turn another _read(n) call, in which case reading = true if
  58050. // it's in progress.
  58051. // However, if we're not ended, or reading, and the length < hwm,
  58052. // then go ahead and try to read some more preemptively.
  58053. function maybeReadMore(stream, state) {
  58054. if (!state.readingMore) {
  58055. state.readingMore = true;
  58056. process.nextTick(maybeReadMore_, stream, state);
  58057. }
  58058. }
  58059. function maybeReadMore_(stream, state) {
  58060. // Attempt to read more data if we should.
  58061. //
  58062. // The conditions for reading more data are (one of):
  58063. // - Not enough data buffered (state.length < state.highWaterMark). The loop
  58064. // is responsible for filling the buffer with enough data if such data
  58065. // is available. If highWaterMark is 0 and we are not in the flowing mode
  58066. // we should _not_ attempt to buffer any extra data. We'll get more data
  58067. // when the stream consumer calls read() instead.
  58068. // - No data in the buffer, and the stream is in flowing mode. In this mode
  58069. // the loop below is responsible for ensuring read() is called. Failing to
  58070. // call read here would abort the flow and there's no other mechanism for
  58071. // continuing the flow if the stream consumer has just subscribed to the
  58072. // 'data' event.
  58073. //
  58074. // In addition to the above conditions to keep reading data, the following
  58075. // conditions prevent the data from being read:
  58076. // - The stream has ended (state.ended).
  58077. // - There is already a pending 'read' operation (state.reading). This is a
  58078. // case where the the stream has called the implementation defined _read()
  58079. // method, but they are processing the call asynchronously and have _not_
  58080. // called push() with new data. In this case we skip performing more
  58081. // read()s. The execution ends in this method again after the _read() ends
  58082. // up calling push() with more data.
  58083. while (!state.reading && !state.ended && (state.length < state.highWaterMark || state.flowing && state.length === 0)) {
  58084. var len = state.length;
  58085. debug('maybeReadMore read 0');
  58086. stream.read(0);
  58087. if (len === state.length) // didn't get any data, stop spinning.
  58088. break;
  58089. }
  58090. state.readingMore = false;
  58091. } // abstract method. to be overridden in specific implementation classes.
  58092. // call cb(er, data) where data is <= n in length.
  58093. // for virtual (non-string, non-buffer) streams, "length" is somewhat
  58094. // arbitrary, and perhaps not very meaningful.
  58095. Readable.prototype._read = function (n) {
  58096. errorOrDestroy(this, new ERR_METHOD_NOT_IMPLEMENTED('_read()'));
  58097. };
  58098. Readable.prototype.pipe = function (dest, pipeOpts) {
  58099. var src = this;
  58100. var state = this._readableState;
  58101. switch (state.pipesCount) {
  58102. case 0:
  58103. state.pipes = dest;
  58104. break;
  58105. case 1:
  58106. state.pipes = [state.pipes, dest];
  58107. break;
  58108. default:
  58109. state.pipes.push(dest);
  58110. break;
  58111. }
  58112. state.pipesCount += 1;
  58113. debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
  58114. var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
  58115. var endFn = doEnd ? onend : unpipe;
  58116. if (state.endEmitted) process.nextTick(endFn);else src.once('end', endFn);
  58117. dest.on('unpipe', onunpipe);
  58118. function onunpipe(readable, unpipeInfo) {
  58119. debug('onunpipe');
  58120. if (readable === src) {
  58121. if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
  58122. unpipeInfo.hasUnpiped = true;
  58123. cleanup();
  58124. }
  58125. }
  58126. }
  58127. function onend() {
  58128. debug('onend');
  58129. dest.end();
  58130. } // when the dest drains, it reduces the awaitDrain counter
  58131. // on the source. This would be more elegant with a .once()
  58132. // handler in flow(), but adding and removing repeatedly is
  58133. // too slow.
  58134. var ondrain = pipeOnDrain(src);
  58135. dest.on('drain', ondrain);
  58136. var cleanedUp = false;
  58137. function cleanup() {
  58138. debug('cleanup'); // cleanup event handlers once the pipe is broken
  58139. dest.removeListener('close', onclose);
  58140. dest.removeListener('finish', onfinish);
  58141. dest.removeListener('drain', ondrain);
  58142. dest.removeListener('error', onerror);
  58143. dest.removeListener('unpipe', onunpipe);
  58144. src.removeListener('end', onend);
  58145. src.removeListener('end', unpipe);
  58146. src.removeListener('data', ondata);
  58147. cleanedUp = true; // if the reader is waiting for a drain event from this
  58148. // specific writer, then it would cause it to never start
  58149. // flowing again.
  58150. // So, if this is awaiting a drain, then we just call it now.
  58151. // If we don't know, then assume that we are waiting for one.
  58152. if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
  58153. }
  58154. src.on('data', ondata);
  58155. function ondata(chunk) {
  58156. debug('ondata');
  58157. var ret = dest.write(chunk);
  58158. debug('dest.write', ret);
  58159. if (ret === false) {
  58160. // If the user unpiped during `dest.write()`, it is possible
  58161. // to get stuck in a permanently paused state if that write
  58162. // also returned false.
  58163. // => Check whether `dest` is still a piping destination.
  58164. if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
  58165. debug('false write response, pause', state.awaitDrain);
  58166. state.awaitDrain++;
  58167. }
  58168. src.pause();
  58169. }
  58170. } // if the dest has an error, then stop piping into it.
  58171. // however, don't suppress the throwing behavior for this.
  58172. function onerror(er) {
  58173. debug('onerror', er);
  58174. unpipe();
  58175. dest.removeListener('error', onerror);
  58176. if (EElistenerCount(dest, 'error') === 0) errorOrDestroy(dest, er);
  58177. } // Make sure our error handler is attached before userland ones.
  58178. prependListener(dest, 'error', onerror); // Both close and finish should trigger unpipe, but only once.
  58179. function onclose() {
  58180. dest.removeListener('finish', onfinish);
  58181. unpipe();
  58182. }
  58183. dest.once('close', onclose);
  58184. function onfinish() {
  58185. debug('onfinish');
  58186. dest.removeListener('close', onclose);
  58187. unpipe();
  58188. }
  58189. dest.once('finish', onfinish);
  58190. function unpipe() {
  58191. debug('unpipe');
  58192. src.unpipe(dest);
  58193. } // tell the dest that it's being piped to
  58194. dest.emit('pipe', src); // start the flow if it hasn't been started already.
  58195. if (!state.flowing) {
  58196. debug('pipe resume');
  58197. src.resume();
  58198. }
  58199. return dest;
  58200. };
  58201. function pipeOnDrain(src) {
  58202. return function pipeOnDrainFunctionResult() {
  58203. var state = src._readableState;
  58204. debug('pipeOnDrain', state.awaitDrain);
  58205. if (state.awaitDrain) state.awaitDrain--;
  58206. if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
  58207. state.flowing = true;
  58208. flow(src);
  58209. }
  58210. };
  58211. }
  58212. Readable.prototype.unpipe = function (dest) {
  58213. var state = this._readableState;
  58214. var unpipeInfo = {
  58215. hasUnpiped: false
  58216. }; // if we're not piping anywhere, then do nothing.
  58217. if (state.pipesCount === 0) return this; // just one destination. most common case.
  58218. if (state.pipesCount === 1) {
  58219. // passed in one, but it's not the right one.
  58220. if (dest && dest !== state.pipes) return this;
  58221. if (!dest) dest = state.pipes; // got a match.
  58222. state.pipes = null;
  58223. state.pipesCount = 0;
  58224. state.flowing = false;
  58225. if (dest) dest.emit('unpipe', this, unpipeInfo);
  58226. return this;
  58227. } // slow case. multiple pipe destinations.
  58228. if (!dest) {
  58229. // remove all.
  58230. var dests = state.pipes;
  58231. var len = state.pipesCount;
  58232. state.pipes = null;
  58233. state.pipesCount = 0;
  58234. state.flowing = false;
  58235. for (var i = 0; i < len; i++) {
  58236. dests[i].emit('unpipe', this, {
  58237. hasUnpiped: false
  58238. });
  58239. }
  58240. return this;
  58241. } // try to find the right one.
  58242. var index = indexOf(state.pipes, dest);
  58243. if (index === -1) return this;
  58244. state.pipes.splice(index, 1);
  58245. state.pipesCount -= 1;
  58246. if (state.pipesCount === 1) state.pipes = state.pipes[0];
  58247. dest.emit('unpipe', this, unpipeInfo);
  58248. return this;
  58249. }; // set up data events if they are asked for
  58250. // Ensure readable listeners eventually get something
  58251. Readable.prototype.on = function (ev, fn) {
  58252. var res = Stream.prototype.on.call(this, ev, fn);
  58253. var state = this._readableState;
  58254. if (ev === 'data') {
  58255. // update readableListening so that resume() may be a no-op
  58256. // a few lines down. This is needed to support once('readable').
  58257. state.readableListening = this.listenerCount('readable') > 0; // Try start flowing on next tick if stream isn't explicitly paused
  58258. if (state.flowing !== false) this.resume();
  58259. } else if (ev === 'readable') {
  58260. if (!state.endEmitted && !state.readableListening) {
  58261. state.readableListening = state.needReadable = true;
  58262. state.flowing = false;
  58263. state.emittedReadable = false;
  58264. debug('on readable', state.length, state.reading);
  58265. if (state.length) {
  58266. emitReadable(this);
  58267. } else if (!state.reading) {
  58268. process.nextTick(nReadingNextTick, this);
  58269. }
  58270. }
  58271. }
  58272. return res;
  58273. };
  58274. Readable.prototype.addListener = Readable.prototype.on;
  58275. Readable.prototype.removeListener = function (ev, fn) {
  58276. var res = Stream.prototype.removeListener.call(this, ev, fn);
  58277. if (ev === 'readable') {
  58278. // We need to check if there is someone still listening to
  58279. // readable and reset the state. However this needs to happen
  58280. // after readable has been emitted but before I/O (nextTick) to
  58281. // support once('readable', fn) cycles. This means that calling
  58282. // resume within the same tick will have no
  58283. // effect.
  58284. process.nextTick(updateReadableListening, this);
  58285. }
  58286. return res;
  58287. };
  58288. Readable.prototype.removeAllListeners = function (ev) {
  58289. var res = Stream.prototype.removeAllListeners.apply(this, arguments);
  58290. if (ev === 'readable' || ev === undefined) {
  58291. // We need to check if there is someone still listening to
  58292. // readable and reset the state. However this needs to happen
  58293. // after readable has been emitted but before I/O (nextTick) to
  58294. // support once('readable', fn) cycles. This means that calling
  58295. // resume within the same tick will have no
  58296. // effect.
  58297. process.nextTick(updateReadableListening, this);
  58298. }
  58299. return res;
  58300. };
  58301. function updateReadableListening(self) {
  58302. var state = self._readableState;
  58303. state.readableListening = self.listenerCount('readable') > 0;
  58304. if (state.resumeScheduled && !state.paused) {
  58305. // flowing needs to be set to true now, otherwise
  58306. // the upcoming resume will not flow.
  58307. state.flowing = true; // crude way to check if we should resume
  58308. } else if (self.listenerCount('data') > 0) {
  58309. self.resume();
  58310. }
  58311. }
  58312. function nReadingNextTick(self) {
  58313. debug('readable nexttick read 0');
  58314. self.read(0);
  58315. } // pause() and resume() are remnants of the legacy readable stream API
  58316. // If the user uses them, then switch into old mode.
  58317. Readable.prototype.resume = function () {
  58318. var state = this._readableState;
  58319. if (!state.flowing) {
  58320. debug('resume'); // we flow only if there is no one listening
  58321. // for readable, but we still have to call
  58322. // resume()
  58323. state.flowing = !state.readableListening;
  58324. resume(this, state);
  58325. }
  58326. state.paused = false;
  58327. return this;
  58328. };
  58329. function resume(stream, state) {
  58330. if (!state.resumeScheduled) {
  58331. state.resumeScheduled = true;
  58332. process.nextTick(resume_, stream, state);
  58333. }
  58334. }
  58335. function resume_(stream, state) {
  58336. debug('resume', state.reading);
  58337. if (!state.reading) {
  58338. stream.read(0);
  58339. }
  58340. state.resumeScheduled = false;
  58341. stream.emit('resume');
  58342. flow(stream);
  58343. if (state.flowing && !state.reading) stream.read(0);
  58344. }
  58345. Readable.prototype.pause = function () {
  58346. debug('call pause flowing=%j', this._readableState.flowing);
  58347. if (this._readableState.flowing !== false) {
  58348. debug('pause');
  58349. this._readableState.flowing = false;
  58350. this.emit('pause');
  58351. }
  58352. this._readableState.paused = true;
  58353. return this;
  58354. };
  58355. function flow(stream) {
  58356. var state = stream._readableState;
  58357. debug('flow', state.flowing);
  58358. while (state.flowing && stream.read() !== null) {
  58359. ;
  58360. }
  58361. } // wrap an old-style stream as the async data source.
  58362. // This is *not* part of the readable stream interface.
  58363. // It is an ugly unfortunate mess of history.
  58364. Readable.prototype.wrap = function (stream) {
  58365. var _this = this;
  58366. var state = this._readableState;
  58367. var paused = false;
  58368. stream.on('end', function () {
  58369. debug('wrapped end');
  58370. if (state.decoder && !state.ended) {
  58371. var chunk = state.decoder.end();
  58372. if (chunk && chunk.length) _this.push(chunk);
  58373. }
  58374. _this.push(null);
  58375. });
  58376. stream.on('data', function (chunk) {
  58377. debug('wrapped data');
  58378. if (state.decoder) chunk = state.decoder.write(chunk); // don't skip over falsy values in objectMode
  58379. if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
  58380. var ret = _this.push(chunk);
  58381. if (!ret) {
  58382. paused = true;
  58383. stream.pause();
  58384. }
  58385. }); // proxy all the other methods.
  58386. // important when wrapping filters and duplexes.
  58387. for (var i in stream) {
  58388. if (this[i] === undefined && typeof stream[i] === 'function') {
  58389. this[i] = function methodWrap(method) {
  58390. return function methodWrapReturnFunction() {
  58391. return stream[method].apply(stream, arguments);
  58392. };
  58393. }(i);
  58394. }
  58395. } // proxy certain important events.
  58396. for (var n = 0; n < kProxyEvents.length; n++) {
  58397. stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
  58398. } // when we try to consume some more bytes, simply unpause the
  58399. // underlying stream.
  58400. this._read = function (n) {
  58401. debug('wrapped _read', n);
  58402. if (paused) {
  58403. paused = false;
  58404. stream.resume();
  58405. }
  58406. };
  58407. return this;
  58408. };
  58409. if (typeof Symbol === 'function') {
  58410. Readable.prototype[Symbol.asyncIterator] = function () {
  58411. if (createReadableStreamAsyncIterator === undefined) {
  58412. createReadableStreamAsyncIterator = require('./internal/streams/async_iterator');
  58413. }
  58414. return createReadableStreamAsyncIterator(this);
  58415. };
  58416. }
  58417. Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
  58418. // making it explicit this property is not enumerable
  58419. // because otherwise some prototype manipulation in
  58420. // userland will fail
  58421. enumerable: false,
  58422. get: function get() {
  58423. return this._readableState.highWaterMark;
  58424. }
  58425. });
  58426. Object.defineProperty(Readable.prototype, 'readableBuffer', {
  58427. // making it explicit this property is not enumerable
  58428. // because otherwise some prototype manipulation in
  58429. // userland will fail
  58430. enumerable: false,
  58431. get: function get() {
  58432. return this._readableState && this._readableState.buffer;
  58433. }
  58434. });
  58435. Object.defineProperty(Readable.prototype, 'readableFlowing', {
  58436. // making it explicit this property is not enumerable
  58437. // because otherwise some prototype manipulation in
  58438. // userland will fail
  58439. enumerable: false,
  58440. get: function get() {
  58441. return this._readableState.flowing;
  58442. },
  58443. set: function set(state) {
  58444. if (this._readableState) {
  58445. this._readableState.flowing = state;
  58446. }
  58447. }
  58448. }); // exposed for testing purposes only.
  58449. Readable._fromList = fromList;
  58450. Object.defineProperty(Readable.prototype, 'readableLength', {
  58451. // making it explicit this property is not enumerable
  58452. // because otherwise some prototype manipulation in
  58453. // userland will fail
  58454. enumerable: false,
  58455. get: function get() {
  58456. return this._readableState.length;
  58457. }
  58458. }); // Pluck off n bytes from an array of buffers.
  58459. // Length is the combined lengths of all the buffers in the list.
  58460. // This function is designed to be inlinable, so please take care when making
  58461. // changes to the function body.
  58462. function fromList(n, state) {
  58463. // nothing buffered
  58464. if (state.length === 0) return null;
  58465. var ret;
  58466. if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
  58467. // read it all, truncate the list
  58468. if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.first();else ret = state.buffer.concat(state.length);
  58469. state.buffer.clear();
  58470. } else {
  58471. // read part of list
  58472. ret = state.buffer.consume(n, state.decoder);
  58473. }
  58474. return ret;
  58475. }
  58476. function endReadable(stream) {
  58477. var state = stream._readableState;
  58478. debug('endReadable', state.endEmitted);
  58479. if (!state.endEmitted) {
  58480. state.ended = true;
  58481. process.nextTick(endReadableNT, state, stream);
  58482. }
  58483. }
  58484. function endReadableNT(state, stream) {
  58485. debug('endReadableNT', state.endEmitted, state.length); // Check that we didn't get one last unshift.
  58486. if (!state.endEmitted && state.length === 0) {
  58487. state.endEmitted = true;
  58488. stream.readable = false;
  58489. stream.emit('end');
  58490. if (state.autoDestroy) {
  58491. // In case of duplex streams we need a way to detect
  58492. // if the writable side is ready for autoDestroy as well
  58493. var wState = stream._writableState;
  58494. if (!wState || wState.autoDestroy && wState.finished) {
  58495. stream.destroy();
  58496. }
  58497. }
  58498. }
  58499. }
  58500. if (typeof Symbol === 'function') {
  58501. Readable.from = function (iterable, opts) {
  58502. if (from === undefined) {
  58503. from = require('./internal/streams/from');
  58504. }
  58505. return from(Readable, iterable, opts);
  58506. };
  58507. }
  58508. function indexOf(xs, x) {
  58509. for (var i = 0, l = xs.length; i < l; i++) {
  58510. if (xs[i] === x) return i;
  58511. }
  58512. return -1;
  58513. }
  58514. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  58515. },{"../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":216,"events":367,"inherits":387,"string_decoder/":520,"util":185}],481:[function(require,module,exports){
  58516. // Copyright Joyent, Inc. and other Node contributors.
  58517. //
  58518. // Permission is hereby granted, free of charge, to any person obtaining a
  58519. // copy of this software and associated documentation files (the
  58520. // "Software"), to deal in the Software without restriction, including
  58521. // without limitation the rights to use, copy, modify, merge, publish,
  58522. // distribute, sublicense, and/or sell copies of the Software, and to permit
  58523. // persons to whom the Software is furnished to do so, subject to the
  58524. // following conditions:
  58525. //
  58526. // The above copyright notice and this permission notice shall be included
  58527. // in all copies or substantial portions of the Software.
  58528. //
  58529. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  58530. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  58531. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  58532. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  58533. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  58534. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  58535. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  58536. // a transform stream is a readable/writable stream where you do
  58537. // something with the data. Sometimes it's called a "filter",
  58538. // but that's not a great name for it, since that implies a thing where
  58539. // some bits pass through, and others are simply ignored. (That would
  58540. // be a valid example of a transform, of course.)
  58541. //
  58542. // While the output is causally related to the input, it's not a
  58543. // necessarily symmetric or synchronous transformation. For example,
  58544. // a zlib stream might take multiple plain-text writes(), and then
  58545. // emit a single compressed chunk some time in the future.
  58546. //
  58547. // Here's how this works:
  58548. //
  58549. // The Transform stream has all the aspects of the readable and writable
  58550. // stream classes. When you write(chunk), that calls _write(chunk,cb)
  58551. // internally, and returns false if there's a lot of pending writes
  58552. // buffered up. When you call read(), that calls _read(n) until
  58553. // there's enough pending readable data buffered up.
  58554. //
  58555. // In a transform stream, the written data is placed in a buffer. When
  58556. // _read(n) is called, it transforms the queued up data, calling the
  58557. // buffered _write cb's as it consumes chunks. If consuming a single
  58558. // written chunk would result in multiple output chunks, then the first
  58559. // outputted bit calls the readcb, and subsequent chunks just go into
  58560. // the read buffer, and will cause it to emit 'readable' if necessary.
  58561. //
  58562. // This way, back-pressure is actually determined by the reading side,
  58563. // since _read has to be called to start processing a new chunk. However,
  58564. // a pathological inflate type of transform can cause excessive buffering
  58565. // here. For example, imagine a stream where every byte of input is
  58566. // interpreted as an integer from 0-255, and then results in that many
  58567. // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
  58568. // 1kb of data being output. In this case, you could write a very small
  58569. // amount of input, and end up with a very large amount of output. In
  58570. // such a pathological inflating mechanism, there'd be no way to tell
  58571. // the system to stop doing the transform. A single 4MB write could
  58572. // cause the system to run out of memory.
  58573. //
  58574. // However, even in such a pathological case, only a single written chunk
  58575. // would be consumed, and then the rest would wait (un-transformed) until
  58576. // the results of the previous transformed chunk were consumed.
  58577. 'use strict';
  58578. module.exports = Transform;
  58579. var _require$codes = require('../errors').codes,
  58580. ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
  58581. ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
  58582. ERR_TRANSFORM_ALREADY_TRANSFORMING = _require$codes.ERR_TRANSFORM_ALREADY_TRANSFORMING,
  58583. ERR_TRANSFORM_WITH_LENGTH_0 = _require$codes.ERR_TRANSFORM_WITH_LENGTH_0;
  58584. var Duplex = require('./_stream_duplex');
  58585. require('inherits')(Transform, Duplex);
  58586. function afterTransform(er, data) {
  58587. var ts = this._transformState;
  58588. ts.transforming = false;
  58589. var cb = ts.writecb;
  58590. if (cb === null) {
  58591. return this.emit('error', new ERR_MULTIPLE_CALLBACK());
  58592. }
  58593. ts.writechunk = null;
  58594. ts.writecb = null;
  58595. if (data != null) // single equals check for both `null` and `undefined`
  58596. this.push(data);
  58597. cb(er);
  58598. var rs = this._readableState;
  58599. rs.reading = false;
  58600. if (rs.needReadable || rs.length < rs.highWaterMark) {
  58601. this._read(rs.highWaterMark);
  58602. }
  58603. }
  58604. function Transform(options) {
  58605. if (!(this instanceof Transform)) return new Transform(options);
  58606. Duplex.call(this, options);
  58607. this._transformState = {
  58608. afterTransform: afterTransform.bind(this),
  58609. needTransform: false,
  58610. transforming: false,
  58611. writecb: null,
  58612. writechunk: null,
  58613. writeencoding: null
  58614. }; // start out asking for a readable event once data is transformed.
  58615. this._readableState.needReadable = true; // we have implemented the _read method, and done the other things
  58616. // that Readable wants before the first _read call, so unset the
  58617. // sync guard flag.
  58618. this._readableState.sync = false;
  58619. if (options) {
  58620. if (typeof options.transform === 'function') this._transform = options.transform;
  58621. if (typeof options.flush === 'function') this._flush = options.flush;
  58622. } // When the writable side finishes, then flush out anything remaining.
  58623. this.on('prefinish', prefinish);
  58624. }
  58625. function prefinish() {
  58626. var _this = this;
  58627. if (typeof this._flush === 'function' && !this._readableState.destroyed) {
  58628. this._flush(function (er, data) {
  58629. done(_this, er, data);
  58630. });
  58631. } else {
  58632. done(this, null, null);
  58633. }
  58634. }
  58635. Transform.prototype.push = function (chunk, encoding) {
  58636. this._transformState.needTransform = false;
  58637. return Duplex.prototype.push.call(this, chunk, encoding);
  58638. }; // This is the part where you do stuff!
  58639. // override this function in implementation classes.
  58640. // 'chunk' is an input chunk.
  58641. //
  58642. // Call `push(newChunk)` to pass along transformed output
  58643. // to the readable side. You may call 'push' zero or more times.
  58644. //
  58645. // Call `cb(err)` when you are done with this chunk. If you pass
  58646. // an error, then that'll put the hurt on the whole operation. If you
  58647. // never call cb(), then you'll never get another chunk.
  58648. Transform.prototype._transform = function (chunk, encoding, cb) {
  58649. cb(new ERR_METHOD_NOT_IMPLEMENTED('_transform()'));
  58650. };
  58651. Transform.prototype._write = function (chunk, encoding, cb) {
  58652. var ts = this._transformState;
  58653. ts.writecb = cb;
  58654. ts.writechunk = chunk;
  58655. ts.writeencoding = encoding;
  58656. if (!ts.transforming) {
  58657. var rs = this._readableState;
  58658. if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
  58659. }
  58660. }; // Doesn't matter what the args are here.
  58661. // _transform does all the work.
  58662. // That we got here means that the readable side wants more data.
  58663. Transform.prototype._read = function (n) {
  58664. var ts = this._transformState;
  58665. if (ts.writechunk !== null && !ts.transforming) {
  58666. ts.transforming = true;
  58667. this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
  58668. } else {
  58669. // mark that we need a transform, so that any data that comes in
  58670. // will get processed, now that we've asked for it.
  58671. ts.needTransform = true;
  58672. }
  58673. };
  58674. Transform.prototype._destroy = function (err, cb) {
  58675. Duplex.prototype._destroy.call(this, err, function (err2) {
  58676. cb(err2);
  58677. });
  58678. };
  58679. function done(stream, er, data) {
  58680. if (er) return stream.emit('error', er);
  58681. if (data != null) // single equals check for both `null` and `undefined`
  58682. stream.push(data); // TODO(BridgeAR): Write a test for these two error cases
  58683. // if there's nothing in the write buffer, then that means
  58684. // that nothing more will ever be provided
  58685. if (stream._writableState.length) throw new ERR_TRANSFORM_WITH_LENGTH_0();
  58686. if (stream._transformState.transforming) throw new ERR_TRANSFORM_ALREADY_TRANSFORMING();
  58687. return stream.push(null);
  58688. }
  58689. },{"../errors":477,"./_stream_duplex":478,"inherits":387}],482:[function(require,module,exports){
  58690. (function (process,global){
  58691. // Copyright Joyent, Inc. and other Node contributors.
  58692. //
  58693. // Permission is hereby granted, free of charge, to any person obtaining a
  58694. // copy of this software and associated documentation files (the
  58695. // "Software"), to deal in the Software without restriction, including
  58696. // without limitation the rights to use, copy, modify, merge, publish,
  58697. // distribute, sublicense, and/or sell copies of the Software, and to permit
  58698. // persons to whom the Software is furnished to do so, subject to the
  58699. // following conditions:
  58700. //
  58701. // The above copyright notice and this permission notice shall be included
  58702. // in all copies or substantial portions of the Software.
  58703. //
  58704. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  58705. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  58706. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  58707. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  58708. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  58709. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  58710. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  58711. // A bit simpler than readable streams.
  58712. // Implement an async ._write(chunk, encoding, cb), and it'll handle all
  58713. // the drain event emission and buffering.
  58714. 'use strict';
  58715. module.exports = Writable;
  58716. /* <replacement> */
  58717. function WriteReq(chunk, encoding, cb) {
  58718. this.chunk = chunk;
  58719. this.encoding = encoding;
  58720. this.callback = cb;
  58721. this.next = null;
  58722. } // It seems a linked list but it is not
  58723. // there will be only 2 of these for each stream
  58724. function CorkedRequest(state) {
  58725. var _this = this;
  58726. this.next = null;
  58727. this.entry = null;
  58728. this.finish = function () {
  58729. onCorkedFinish(_this, state);
  58730. };
  58731. }
  58732. /* </replacement> */
  58733. /*<replacement>*/
  58734. var Duplex;
  58735. /*</replacement>*/
  58736. Writable.WritableState = WritableState;
  58737. /*<replacement>*/
  58738. var internalUtil = {
  58739. deprecate: require('util-deprecate')
  58740. };
  58741. /*</replacement>*/
  58742. /*<replacement>*/
  58743. var Stream = require('./internal/streams/stream');
  58744. /*</replacement>*/
  58745. var Buffer = require('buffer').Buffer;
  58746. var OurUint8Array = global.Uint8Array || function () {};
  58747. function _uint8ArrayToBuffer(chunk) {
  58748. return Buffer.from(chunk);
  58749. }
  58750. function _isUint8Array(obj) {
  58751. return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
  58752. }
  58753. var destroyImpl = require('./internal/streams/destroy');
  58754. var _require = require('./internal/streams/state'),
  58755. getHighWaterMark = _require.getHighWaterMark;
  58756. var _require$codes = require('../errors').codes,
  58757. ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
  58758. ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
  58759. ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
  58760. ERR_STREAM_CANNOT_PIPE = _require$codes.ERR_STREAM_CANNOT_PIPE,
  58761. ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED,
  58762. ERR_STREAM_NULL_VALUES = _require$codes.ERR_STREAM_NULL_VALUES,
  58763. ERR_STREAM_WRITE_AFTER_END = _require$codes.ERR_STREAM_WRITE_AFTER_END,
  58764. ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING;
  58765. var errorOrDestroy = destroyImpl.errorOrDestroy;
  58766. require('inherits')(Writable, Stream);
  58767. function nop() {}
  58768. function WritableState(options, stream, isDuplex) {
  58769. Duplex = Duplex || require('./_stream_duplex');
  58770. options = options || {}; // Duplex streams are both readable and writable, but share
  58771. // the same options object.
  58772. // However, some cases require setting options to different
  58773. // values for the readable and the writable sides of the duplex stream,
  58774. // e.g. options.readableObjectMode vs. options.writableObjectMode, etc.
  58775. if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex; // object stream flag to indicate whether or not this stream
  58776. // contains buffers or objects.
  58777. this.objectMode = !!options.objectMode;
  58778. if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode; // the point at which write() starts returning false
  58779. // Note: 0 is a valid value, means that we always return false if
  58780. // the entire buffer is not flushed immediately on write()
  58781. this.highWaterMark = getHighWaterMark(this, options, 'writableHighWaterMark', isDuplex); // if _final has been called
  58782. this.finalCalled = false; // drain event flag.
  58783. this.needDrain = false; // at the start of calling end()
  58784. this.ending = false; // when end() has been called, and returned
  58785. this.ended = false; // when 'finish' is emitted
  58786. this.finished = false; // has it been destroyed
  58787. this.destroyed = false; // should we decode strings into buffers before passing to _write?
  58788. // this is here so that some node-core streams can optimize string
  58789. // handling at a lower level.
  58790. var noDecode = options.decodeStrings === false;
  58791. this.decodeStrings = !noDecode; // Crypto is kind of old and crusty. Historically, its default string
  58792. // encoding is 'binary' so we have to make this configurable.
  58793. // Everything else in the universe uses 'utf8', though.
  58794. this.defaultEncoding = options.defaultEncoding || 'utf8'; // not an actual buffer we keep track of, but a measurement
  58795. // of how much we're waiting to get pushed to some underlying
  58796. // socket or file.
  58797. this.length = 0; // a flag to see when we're in the middle of a write.
  58798. this.writing = false; // when true all writes will be buffered until .uncork() call
  58799. this.corked = 0; // a flag to be able to tell if the onwrite cb is called immediately,
  58800. // or on a later tick. We set this to true at first, because any
  58801. // actions that shouldn't happen until "later" should generally also
  58802. // not happen before the first write call.
  58803. this.sync = true; // a flag to know if we're processing previously buffered items, which
  58804. // may call the _write() callback in the same tick, so that we don't
  58805. // end up in an overlapped onwrite situation.
  58806. this.bufferProcessing = false; // the callback that's passed to _write(chunk,cb)
  58807. this.onwrite = function (er) {
  58808. onwrite(stream, er);
  58809. }; // the callback that the user supplies to write(chunk,encoding,cb)
  58810. this.writecb = null; // the amount that is being written when _write is called.
  58811. this.writelen = 0;
  58812. this.bufferedRequest = null;
  58813. this.lastBufferedRequest = null; // number of pending user-supplied write callbacks
  58814. // this must be 0 before 'finish' can be emitted
  58815. this.pendingcb = 0; // emit prefinish if the only thing we're waiting for is _write cbs
  58816. // This is relevant for synchronous Transform streams
  58817. this.prefinished = false; // True if the error was already emitted and should not be thrown again
  58818. this.errorEmitted = false; // Should close be emitted on destroy. Defaults to true.
  58819. this.emitClose = options.emitClose !== false; // Should .destroy() be called after 'finish' (and potentially 'end')
  58820. this.autoDestroy = !!options.autoDestroy; // count buffered requests
  58821. this.bufferedRequestCount = 0; // allocate the first CorkedRequest, there is always
  58822. // one allocated and free to use, and we maintain at most two
  58823. this.corkedRequestsFree = new CorkedRequest(this);
  58824. }
  58825. WritableState.prototype.getBuffer = function getBuffer() {
  58826. var current = this.bufferedRequest;
  58827. var out = [];
  58828. while (current) {
  58829. out.push(current);
  58830. current = current.next;
  58831. }
  58832. return out;
  58833. };
  58834. (function () {
  58835. try {
  58836. Object.defineProperty(WritableState.prototype, 'buffer', {
  58837. get: internalUtil.deprecate(function writableStateBufferGetter() {
  58838. return this.getBuffer();
  58839. }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
  58840. });
  58841. } catch (_) {}
  58842. })(); // Test _writableState for inheritance to account for Duplex streams,
  58843. // whose prototype chain only points to Readable.
  58844. var realHasInstance;
  58845. if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
  58846. realHasInstance = Function.prototype[Symbol.hasInstance];
  58847. Object.defineProperty(Writable, Symbol.hasInstance, {
  58848. value: function value(object) {
  58849. if (realHasInstance.call(this, object)) return true;
  58850. if (this !== Writable) return false;
  58851. return object && object._writableState instanceof WritableState;
  58852. }
  58853. });
  58854. } else {
  58855. realHasInstance = function realHasInstance(object) {
  58856. return object instanceof this;
  58857. };
  58858. }
  58859. function Writable(options) {
  58860. Duplex = Duplex || require('./_stream_duplex'); // Writable ctor is applied to Duplexes, too.
  58861. // `realHasInstance` is necessary because using plain `instanceof`
  58862. // would return false, as no `_writableState` property is attached.
  58863. // Trying to use the custom `instanceof` for Writable here will also break the
  58864. // Node.js LazyTransform implementation, which has a non-trivial getter for
  58865. // `_writableState` that would lead to infinite recursion.
  58866. // Checking for a Stream.Duplex instance is faster here instead of inside
  58867. // the WritableState constructor, at least with V8 6.5
  58868. var isDuplex = this instanceof Duplex;
  58869. if (!isDuplex && !realHasInstance.call(Writable, this)) return new Writable(options);
  58870. this._writableState = new WritableState(options, this, isDuplex); // legacy.
  58871. this.writable = true;
  58872. if (options) {
  58873. if (typeof options.write === 'function') this._write = options.write;
  58874. if (typeof options.writev === 'function') this._writev = options.writev;
  58875. if (typeof options.destroy === 'function') this._destroy = options.destroy;
  58876. if (typeof options.final === 'function') this._final = options.final;
  58877. }
  58878. Stream.call(this);
  58879. } // Otherwise people can pipe Writable streams, which is just wrong.
  58880. Writable.prototype.pipe = function () {
  58881. errorOrDestroy(this, new ERR_STREAM_CANNOT_PIPE());
  58882. };
  58883. function writeAfterEnd(stream, cb) {
  58884. var er = new ERR_STREAM_WRITE_AFTER_END(); // TODO: defer error events consistently everywhere, not just the cb
  58885. errorOrDestroy(stream, er);
  58886. process.nextTick(cb, er);
  58887. } // Checks that a user-supplied chunk is valid, especially for the particular
  58888. // mode the stream is in. Currently this means that `null` is never accepted
  58889. // and undefined/non-string values are only allowed in object mode.
  58890. function validChunk(stream, state, chunk, cb) {
  58891. var er;
  58892. if (chunk === null) {
  58893. er = new ERR_STREAM_NULL_VALUES();
  58894. } else if (typeof chunk !== 'string' && !state.objectMode) {
  58895. er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer'], chunk);
  58896. }
  58897. if (er) {
  58898. errorOrDestroy(stream, er);
  58899. process.nextTick(cb, er);
  58900. return false;
  58901. }
  58902. return true;
  58903. }
  58904. Writable.prototype.write = function (chunk, encoding, cb) {
  58905. var state = this._writableState;
  58906. var ret = false;
  58907. var isBuf = !state.objectMode && _isUint8Array(chunk);
  58908. if (isBuf && !Buffer.isBuffer(chunk)) {
  58909. chunk = _uint8ArrayToBuffer(chunk);
  58910. }
  58911. if (typeof encoding === 'function') {
  58912. cb = encoding;
  58913. encoding = null;
  58914. }
  58915. if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
  58916. if (typeof cb !== 'function') cb = nop;
  58917. if (state.ending) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
  58918. state.pendingcb++;
  58919. ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
  58920. }
  58921. return ret;
  58922. };
  58923. Writable.prototype.cork = function () {
  58924. this._writableState.corked++;
  58925. };
  58926. Writable.prototype.uncork = function () {
  58927. var state = this._writableState;
  58928. if (state.corked) {
  58929. state.corked--;
  58930. if (!state.writing && !state.corked && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
  58931. }
  58932. };
  58933. Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
  58934. // node::ParseEncoding() requires lower case.
  58935. if (typeof encoding === 'string') encoding = encoding.toLowerCase();
  58936. 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);
  58937. this._writableState.defaultEncoding = encoding;
  58938. return this;
  58939. };
  58940. Object.defineProperty(Writable.prototype, 'writableBuffer', {
  58941. // making it explicit this property is not enumerable
  58942. // because otherwise some prototype manipulation in
  58943. // userland will fail
  58944. enumerable: false,
  58945. get: function get() {
  58946. return this._writableState && this._writableState.getBuffer();
  58947. }
  58948. });
  58949. function decodeChunk(state, chunk, encoding) {
  58950. if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
  58951. chunk = Buffer.from(chunk, encoding);
  58952. }
  58953. return chunk;
  58954. }
  58955. Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
  58956. // making it explicit this property is not enumerable
  58957. // because otherwise some prototype manipulation in
  58958. // userland will fail
  58959. enumerable: false,
  58960. get: function get() {
  58961. return this._writableState.highWaterMark;
  58962. }
  58963. }); // if we're already writing something, then just put this
  58964. // in the queue, and wait our turn. Otherwise, call _write
  58965. // If we return false, then we need a drain event, so set that flag.
  58966. function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
  58967. if (!isBuf) {
  58968. var newChunk = decodeChunk(state, chunk, encoding);
  58969. if (chunk !== newChunk) {
  58970. isBuf = true;
  58971. encoding = 'buffer';
  58972. chunk = newChunk;
  58973. }
  58974. }
  58975. var len = state.objectMode ? 1 : chunk.length;
  58976. state.length += len;
  58977. var ret = state.length < state.highWaterMark; // we must ensure that previous needDrain will not be reset to false.
  58978. if (!ret) state.needDrain = true;
  58979. if (state.writing || state.corked) {
  58980. var last = state.lastBufferedRequest;
  58981. state.lastBufferedRequest = {
  58982. chunk: chunk,
  58983. encoding: encoding,
  58984. isBuf: isBuf,
  58985. callback: cb,
  58986. next: null
  58987. };
  58988. if (last) {
  58989. last.next = state.lastBufferedRequest;
  58990. } else {
  58991. state.bufferedRequest = state.lastBufferedRequest;
  58992. }
  58993. state.bufferedRequestCount += 1;
  58994. } else {
  58995. doWrite(stream, state, false, len, chunk, encoding, cb);
  58996. }
  58997. return ret;
  58998. }
  58999. function doWrite(stream, state, writev, len, chunk, encoding, cb) {
  59000. state.writelen = len;
  59001. state.writecb = cb;
  59002. state.writing = true;
  59003. state.sync = true;
  59004. 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);
  59005. state.sync = false;
  59006. }
  59007. function onwriteError(stream, state, sync, er, cb) {
  59008. --state.pendingcb;
  59009. if (sync) {
  59010. // defer the callback if we are being called synchronously
  59011. // to avoid piling up things on the stack
  59012. process.nextTick(cb, er); // this can emit finish, and it will always happen
  59013. // after error
  59014. process.nextTick(finishMaybe, stream, state);
  59015. stream._writableState.errorEmitted = true;
  59016. errorOrDestroy(stream, er);
  59017. } else {
  59018. // the caller expect this to happen before if
  59019. // it is async
  59020. cb(er);
  59021. stream._writableState.errorEmitted = true;
  59022. errorOrDestroy(stream, er); // this can emit finish, but finish must
  59023. // always follow error
  59024. finishMaybe(stream, state);
  59025. }
  59026. }
  59027. function onwriteStateUpdate(state) {
  59028. state.writing = false;
  59029. state.writecb = null;
  59030. state.length -= state.writelen;
  59031. state.writelen = 0;
  59032. }
  59033. function onwrite(stream, er) {
  59034. var state = stream._writableState;
  59035. var sync = state.sync;
  59036. var cb = state.writecb;
  59037. if (typeof cb !== 'function') throw new ERR_MULTIPLE_CALLBACK();
  59038. onwriteStateUpdate(state);
  59039. if (er) onwriteError(stream, state, sync, er, cb);else {
  59040. // Check if we're actually ready to finish, but don't emit yet
  59041. var finished = needFinish(state) || stream.destroyed;
  59042. if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
  59043. clearBuffer(stream, state);
  59044. }
  59045. if (sync) {
  59046. process.nextTick(afterWrite, stream, state, finished, cb);
  59047. } else {
  59048. afterWrite(stream, state, finished, cb);
  59049. }
  59050. }
  59051. }
  59052. function afterWrite(stream, state, finished, cb) {
  59053. if (!finished) onwriteDrain(stream, state);
  59054. state.pendingcb--;
  59055. cb();
  59056. finishMaybe(stream, state);
  59057. } // Must force callback to be called on nextTick, so that we don't
  59058. // emit 'drain' before the write() consumer gets the 'false' return
  59059. // value, and has a chance to attach a 'drain' listener.
  59060. function onwriteDrain(stream, state) {
  59061. if (state.length === 0 && state.needDrain) {
  59062. state.needDrain = false;
  59063. stream.emit('drain');
  59064. }
  59065. } // if there's something in the buffer waiting, then process it
  59066. function clearBuffer(stream, state) {
  59067. state.bufferProcessing = true;
  59068. var entry = state.bufferedRequest;
  59069. if (stream._writev && entry && entry.next) {
  59070. // Fast case, write everything using _writev()
  59071. var l = state.bufferedRequestCount;
  59072. var buffer = new Array(l);
  59073. var holder = state.corkedRequestsFree;
  59074. holder.entry = entry;
  59075. var count = 0;
  59076. var allBuffers = true;
  59077. while (entry) {
  59078. buffer[count] = entry;
  59079. if (!entry.isBuf) allBuffers = false;
  59080. entry = entry.next;
  59081. count += 1;
  59082. }
  59083. buffer.allBuffers = allBuffers;
  59084. doWrite(stream, state, true, state.length, buffer, '', holder.finish); // doWrite is almost always async, defer these to save a bit of time
  59085. // as the hot path ends with doWrite
  59086. state.pendingcb++;
  59087. state.lastBufferedRequest = null;
  59088. if (holder.next) {
  59089. state.corkedRequestsFree = holder.next;
  59090. holder.next = null;
  59091. } else {
  59092. state.corkedRequestsFree = new CorkedRequest(state);
  59093. }
  59094. state.bufferedRequestCount = 0;
  59095. } else {
  59096. // Slow case, write chunks one-by-one
  59097. while (entry) {
  59098. var chunk = entry.chunk;
  59099. var encoding = entry.encoding;
  59100. var cb = entry.callback;
  59101. var len = state.objectMode ? 1 : chunk.length;
  59102. doWrite(stream, state, false, len, chunk, encoding, cb);
  59103. entry = entry.next;
  59104. state.bufferedRequestCount--; // if we didn't call the onwrite immediately, then
  59105. // it means that we need to wait until it does.
  59106. // also, that means that the chunk and cb are currently
  59107. // being processed, so move the buffer counter past them.
  59108. if (state.writing) {
  59109. break;
  59110. }
  59111. }
  59112. if (entry === null) state.lastBufferedRequest = null;
  59113. }
  59114. state.bufferedRequest = entry;
  59115. state.bufferProcessing = false;
  59116. }
  59117. Writable.prototype._write = function (chunk, encoding, cb) {
  59118. cb(new ERR_METHOD_NOT_IMPLEMENTED('_write()'));
  59119. };
  59120. Writable.prototype._writev = null;
  59121. Writable.prototype.end = function (chunk, encoding, cb) {
  59122. var state = this._writableState;
  59123. if (typeof chunk === 'function') {
  59124. cb = chunk;
  59125. chunk = null;
  59126. encoding = null;
  59127. } else if (typeof encoding === 'function') {
  59128. cb = encoding;
  59129. encoding = null;
  59130. }
  59131. if (chunk !== null && chunk !== undefined) this.write(chunk, encoding); // .end() fully uncorks
  59132. if (state.corked) {
  59133. state.corked = 1;
  59134. this.uncork();
  59135. } // ignore unnecessary end() calls.
  59136. if (!state.ending) endWritable(this, state, cb);
  59137. return this;
  59138. };
  59139. Object.defineProperty(Writable.prototype, 'writableLength', {
  59140. // making it explicit this property is not enumerable
  59141. // because otherwise some prototype manipulation in
  59142. // userland will fail
  59143. enumerable: false,
  59144. get: function get() {
  59145. return this._writableState.length;
  59146. }
  59147. });
  59148. function needFinish(state) {
  59149. return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
  59150. }
  59151. function callFinal(stream, state) {
  59152. stream._final(function (err) {
  59153. state.pendingcb--;
  59154. if (err) {
  59155. errorOrDestroy(stream, err);
  59156. }
  59157. state.prefinished = true;
  59158. stream.emit('prefinish');
  59159. finishMaybe(stream, state);
  59160. });
  59161. }
  59162. function prefinish(stream, state) {
  59163. if (!state.prefinished && !state.finalCalled) {
  59164. if (typeof stream._final === 'function' && !state.destroyed) {
  59165. state.pendingcb++;
  59166. state.finalCalled = true;
  59167. process.nextTick(callFinal, stream, state);
  59168. } else {
  59169. state.prefinished = true;
  59170. stream.emit('prefinish');
  59171. }
  59172. }
  59173. }
  59174. function finishMaybe(stream, state) {
  59175. var need = needFinish(state);
  59176. if (need) {
  59177. prefinish(stream, state);
  59178. if (state.pendingcb === 0) {
  59179. state.finished = true;
  59180. stream.emit('finish');
  59181. if (state.autoDestroy) {
  59182. // In case of duplex streams we need a way to detect
  59183. // if the readable side is ready for autoDestroy as well
  59184. var rState = stream._readableState;
  59185. if (!rState || rState.autoDestroy && rState.endEmitted) {
  59186. stream.destroy();
  59187. }
  59188. }
  59189. }
  59190. }
  59191. return need;
  59192. }
  59193. function endWritable(stream, state, cb) {
  59194. state.ending = true;
  59195. finishMaybe(stream, state);
  59196. if (cb) {
  59197. if (state.finished) process.nextTick(cb);else stream.once('finish', cb);
  59198. }
  59199. state.ended = true;
  59200. stream.writable = false;
  59201. }
  59202. function onCorkedFinish(corkReq, state, err) {
  59203. var entry = corkReq.entry;
  59204. corkReq.entry = null;
  59205. while (entry) {
  59206. var cb = entry.callback;
  59207. state.pendingcb--;
  59208. cb(err);
  59209. entry = entry.next;
  59210. } // reuse the free corkReq.
  59211. state.corkedRequestsFree.next = corkReq;
  59212. }
  59213. Object.defineProperty(Writable.prototype, 'destroyed', {
  59214. // making it explicit this property is not enumerable
  59215. // because otherwise some prototype manipulation in
  59216. // userland will fail
  59217. enumerable: false,
  59218. get: function get() {
  59219. if (this._writableState === undefined) {
  59220. return false;
  59221. }
  59222. return this._writableState.destroyed;
  59223. },
  59224. set: function set(value) {
  59225. // we ignore the value if the stream
  59226. // has not been initialized yet
  59227. if (!this._writableState) {
  59228. return;
  59229. } // backward compatibility, the user is explicitly
  59230. // managing destroyed
  59231. this._writableState.destroyed = value;
  59232. }
  59233. });
  59234. Writable.prototype.destroy = destroyImpl.destroy;
  59235. Writable.prototype._undestroy = destroyImpl.undestroy;
  59236. Writable.prototype._destroy = function (err, cb) {
  59237. cb(err);
  59238. };
  59239. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  59240. },{"../errors":477,"./_stream_duplex":478,"./internal/streams/destroy":485,"./internal/streams/state":489,"./internal/streams/stream":490,"_process":467,"buffer":216,"inherits":387,"util-deprecate":522}],483:[function(require,module,exports){
  59241. (function (process){
  59242. 'use strict';
  59243. var _Object$setPrototypeO;
  59244. function _defineProperty(obj, key, value) {
  59245. if (key in obj) {
  59246. Object.defineProperty(obj, key, {
  59247. value: value,
  59248. enumerable: true,
  59249. configurable: true,
  59250. writable: true
  59251. });
  59252. } else {
  59253. obj[key] = value;
  59254. }
  59255. return obj;
  59256. }
  59257. var finished = require('./end-of-stream');
  59258. var kLastResolve = Symbol('lastResolve');
  59259. var kLastReject = Symbol('lastReject');
  59260. var kError = Symbol('error');
  59261. var kEnded = Symbol('ended');
  59262. var kLastPromise = Symbol('lastPromise');
  59263. var kHandlePromise = Symbol('handlePromise');
  59264. var kStream = Symbol('stream');
  59265. function createIterResult(value, done) {
  59266. return {
  59267. value: value,
  59268. done: done
  59269. };
  59270. }
  59271. function readAndResolve(iter) {
  59272. var resolve = iter[kLastResolve];
  59273. if (resolve !== null) {
  59274. var data = iter[kStream].read(); // we defer if data is null
  59275. // we can be expecting either 'end' or
  59276. // 'error'
  59277. if (data !== null) {
  59278. iter[kLastPromise] = null;
  59279. iter[kLastResolve] = null;
  59280. iter[kLastReject] = null;
  59281. resolve(createIterResult(data, false));
  59282. }
  59283. }
  59284. }
  59285. function onReadable(iter) {
  59286. // we wait for the next tick, because it might
  59287. // emit an error with process.nextTick
  59288. process.nextTick(readAndResolve, iter);
  59289. }
  59290. function wrapForNext(lastPromise, iter) {
  59291. return function (resolve, reject) {
  59292. lastPromise.then(function () {
  59293. if (iter[kEnded]) {
  59294. resolve(createIterResult(undefined, true));
  59295. return;
  59296. }
  59297. iter[kHandlePromise](resolve, reject);
  59298. }, reject);
  59299. };
  59300. }
  59301. var AsyncIteratorPrototype = Object.getPrototypeOf(function () {});
  59302. var ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf((_Object$setPrototypeO = {
  59303. get stream() {
  59304. return this[kStream];
  59305. },
  59306. next: function next() {
  59307. var _this = this; // if we have detected an error in the meanwhile
  59308. // reject straight away
  59309. var error = this[kError];
  59310. if (error !== null) {
  59311. return Promise.reject(error);
  59312. }
  59313. if (this[kEnded]) {
  59314. return Promise.resolve(createIterResult(undefined, true));
  59315. }
  59316. if (this[kStream].destroyed) {
  59317. // We need to defer via nextTick because if .destroy(err) is
  59318. // called, the error will be emitted via nextTick, and
  59319. // we cannot guarantee that there is no error lingering around
  59320. // waiting to be emitted.
  59321. return new Promise(function (resolve, reject) {
  59322. process.nextTick(function () {
  59323. if (_this[kError]) {
  59324. reject(_this[kError]);
  59325. } else {
  59326. resolve(createIterResult(undefined, true));
  59327. }
  59328. });
  59329. });
  59330. } // if we have multiple next() calls
  59331. // we will wait for the previous Promise to finish
  59332. // this logic is optimized to support for await loops,
  59333. // where next() is only called once at a time
  59334. var lastPromise = this[kLastPromise];
  59335. var promise;
  59336. if (lastPromise) {
  59337. promise = new Promise(wrapForNext(lastPromise, this));
  59338. } else {
  59339. // fast path needed to support multiple this.push()
  59340. // without triggering the next() queue
  59341. var data = this[kStream].read();
  59342. if (data !== null) {
  59343. return Promise.resolve(createIterResult(data, false));
  59344. }
  59345. promise = new Promise(this[kHandlePromise]);
  59346. }
  59347. this[kLastPromise] = promise;
  59348. return promise;
  59349. }
  59350. }, _defineProperty(_Object$setPrototypeO, Symbol.asyncIterator, function () {
  59351. return this;
  59352. }), _defineProperty(_Object$setPrototypeO, "return", function _return() {
  59353. var _this2 = this; // destroy(err, cb) is a private API
  59354. // we can guarantee we have that here, because we control the
  59355. // Readable class this is attached to
  59356. return new Promise(function (resolve, reject) {
  59357. _this2[kStream].destroy(null, function (err) {
  59358. if (err) {
  59359. reject(err);
  59360. return;
  59361. }
  59362. resolve(createIterResult(undefined, true));
  59363. });
  59364. });
  59365. }), _Object$setPrototypeO), AsyncIteratorPrototype);
  59366. var createReadableStreamAsyncIterator = function createReadableStreamAsyncIterator(stream) {
  59367. var _Object$create;
  59368. var iterator = Object.create(ReadableStreamAsyncIteratorPrototype, (_Object$create = {}, _defineProperty(_Object$create, kStream, {
  59369. value: stream,
  59370. writable: true
  59371. }), _defineProperty(_Object$create, kLastResolve, {
  59372. value: null,
  59373. writable: true
  59374. }), _defineProperty(_Object$create, kLastReject, {
  59375. value: null,
  59376. writable: true
  59377. }), _defineProperty(_Object$create, kError, {
  59378. value: null,
  59379. writable: true
  59380. }), _defineProperty(_Object$create, kEnded, {
  59381. value: stream._readableState.endEmitted,
  59382. writable: true
  59383. }), _defineProperty(_Object$create, kHandlePromise, {
  59384. value: function value(resolve, reject) {
  59385. var data = iterator[kStream].read();
  59386. if (data) {
  59387. iterator[kLastPromise] = null;
  59388. iterator[kLastResolve] = null;
  59389. iterator[kLastReject] = null;
  59390. resolve(createIterResult(data, false));
  59391. } else {
  59392. iterator[kLastResolve] = resolve;
  59393. iterator[kLastReject] = reject;
  59394. }
  59395. },
  59396. writable: true
  59397. }), _Object$create));
  59398. iterator[kLastPromise] = null;
  59399. finished(stream, function (err) {
  59400. if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') {
  59401. var reject = iterator[kLastReject]; // reject if we are waiting for data in the Promise
  59402. // returned by next() and store the error
  59403. if (reject !== null) {
  59404. iterator[kLastPromise] = null;
  59405. iterator[kLastResolve] = null;
  59406. iterator[kLastReject] = null;
  59407. reject(err);
  59408. }
  59409. iterator[kError] = err;
  59410. return;
  59411. }
  59412. var resolve = iterator[kLastResolve];
  59413. if (resolve !== null) {
  59414. iterator[kLastPromise] = null;
  59415. iterator[kLastResolve] = null;
  59416. iterator[kLastReject] = null;
  59417. resolve(createIterResult(undefined, true));
  59418. }
  59419. iterator[kEnded] = true;
  59420. });
  59421. stream.on('readable', onReadable.bind(null, iterator));
  59422. return iterator;
  59423. };
  59424. module.exports = createReadableStreamAsyncIterator;
  59425. }).call(this,require('_process'))
  59426. },{"./end-of-stream":486,"_process":467}],484:[function(require,module,exports){
  59427. 'use strict';
  59428. function ownKeys(object, enumerableOnly) {
  59429. var keys = Object.keys(object);
  59430. if (Object.getOwnPropertySymbols) {
  59431. var symbols = Object.getOwnPropertySymbols(object);
  59432. if (enumerableOnly) symbols = symbols.filter(function (sym) {
  59433. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  59434. });
  59435. keys.push.apply(keys, symbols);
  59436. }
  59437. return keys;
  59438. }
  59439. function _objectSpread(target) {
  59440. for (var i = 1; i < arguments.length; i++) {
  59441. var source = arguments[i] != null ? arguments[i] : {};
  59442. if (i % 2) {
  59443. ownKeys(Object(source), true).forEach(function (key) {
  59444. _defineProperty(target, key, source[key]);
  59445. });
  59446. } else if (Object.getOwnPropertyDescriptors) {
  59447. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  59448. } else {
  59449. ownKeys(Object(source)).forEach(function (key) {
  59450. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  59451. });
  59452. }
  59453. }
  59454. return target;
  59455. }
  59456. function _defineProperty(obj, key, value) {
  59457. if (key in obj) {
  59458. Object.defineProperty(obj, key, {
  59459. value: value,
  59460. enumerable: true,
  59461. configurable: true,
  59462. writable: true
  59463. });
  59464. } else {
  59465. obj[key] = value;
  59466. }
  59467. return obj;
  59468. }
  59469. function _classCallCheck(instance, Constructor) {
  59470. if (!(instance instanceof Constructor)) {
  59471. throw new TypeError("Cannot call a class as a function");
  59472. }
  59473. }
  59474. function _defineProperties(target, props) {
  59475. for (var i = 0; i < props.length; i++) {
  59476. var descriptor = props[i];
  59477. descriptor.enumerable = descriptor.enumerable || false;
  59478. descriptor.configurable = true;
  59479. if ("value" in descriptor) descriptor.writable = true;
  59480. Object.defineProperty(target, descriptor.key, descriptor);
  59481. }
  59482. }
  59483. function _createClass(Constructor, protoProps, staticProps) {
  59484. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  59485. if (staticProps) _defineProperties(Constructor, staticProps);
  59486. return Constructor;
  59487. }
  59488. var _require = require('buffer'),
  59489. Buffer = _require.Buffer;
  59490. var _require2 = require('util'),
  59491. inspect = _require2.inspect;
  59492. var custom = inspect && inspect.custom || 'inspect';
  59493. function copyBuffer(src, target, offset) {
  59494. Buffer.prototype.copy.call(src, target, offset);
  59495. }
  59496. module.exports = /*#__PURE__*/function () {
  59497. function BufferList() {
  59498. _classCallCheck(this, BufferList);
  59499. this.head = null;
  59500. this.tail = null;
  59501. this.length = 0;
  59502. }
  59503. _createClass(BufferList, [{
  59504. key: "push",
  59505. value: function push(v) {
  59506. var entry = {
  59507. data: v,
  59508. next: null
  59509. };
  59510. if (this.length > 0) this.tail.next = entry;else this.head = entry;
  59511. this.tail = entry;
  59512. ++this.length;
  59513. }
  59514. }, {
  59515. key: "unshift",
  59516. value: function unshift(v) {
  59517. var entry = {
  59518. data: v,
  59519. next: this.head
  59520. };
  59521. if (this.length === 0) this.tail = entry;
  59522. this.head = entry;
  59523. ++this.length;
  59524. }
  59525. }, {
  59526. key: "shift",
  59527. value: function shift() {
  59528. if (this.length === 0) return;
  59529. var ret = this.head.data;
  59530. if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
  59531. --this.length;
  59532. return ret;
  59533. }
  59534. }, {
  59535. key: "clear",
  59536. value: function clear() {
  59537. this.head = this.tail = null;
  59538. this.length = 0;
  59539. }
  59540. }, {
  59541. key: "join",
  59542. value: function join(s) {
  59543. if (this.length === 0) return '';
  59544. var p = this.head;
  59545. var ret = '' + p.data;
  59546. while (p = p.next) {
  59547. ret += s + p.data;
  59548. }
  59549. return ret;
  59550. }
  59551. }, {
  59552. key: "concat",
  59553. value: function concat(n) {
  59554. if (this.length === 0) return Buffer.alloc(0);
  59555. var ret = Buffer.allocUnsafe(n >>> 0);
  59556. var p = this.head;
  59557. var i = 0;
  59558. while (p) {
  59559. copyBuffer(p.data, ret, i);
  59560. i += p.data.length;
  59561. p = p.next;
  59562. }
  59563. return ret;
  59564. } // Consumes a specified amount of bytes or characters from the buffered data.
  59565. }, {
  59566. key: "consume",
  59567. value: function consume(n, hasStrings) {
  59568. var ret;
  59569. if (n < this.head.data.length) {
  59570. // `slice` is the same for buffers and strings.
  59571. ret = this.head.data.slice(0, n);
  59572. this.head.data = this.head.data.slice(n);
  59573. } else if (n === this.head.data.length) {
  59574. // First chunk is a perfect match.
  59575. ret = this.shift();
  59576. } else {
  59577. // Result spans more than one buffer.
  59578. ret = hasStrings ? this._getString(n) : this._getBuffer(n);
  59579. }
  59580. return ret;
  59581. }
  59582. }, {
  59583. key: "first",
  59584. value: function first() {
  59585. return this.head.data;
  59586. } // Consumes a specified amount of characters from the buffered data.
  59587. }, {
  59588. key: "_getString",
  59589. value: function _getString(n) {
  59590. var p = this.head;
  59591. var c = 1;
  59592. var ret = p.data;
  59593. n -= ret.length;
  59594. while (p = p.next) {
  59595. var str = p.data;
  59596. var nb = n > str.length ? str.length : n;
  59597. if (nb === str.length) ret += str;else ret += str.slice(0, n);
  59598. n -= nb;
  59599. if (n === 0) {
  59600. if (nb === str.length) {
  59601. ++c;
  59602. if (p.next) this.head = p.next;else this.head = this.tail = null;
  59603. } else {
  59604. this.head = p;
  59605. p.data = str.slice(nb);
  59606. }
  59607. break;
  59608. }
  59609. ++c;
  59610. }
  59611. this.length -= c;
  59612. return ret;
  59613. } // Consumes a specified amount of bytes from the buffered data.
  59614. }, {
  59615. key: "_getBuffer",
  59616. value: function _getBuffer(n) {
  59617. var ret = Buffer.allocUnsafe(n);
  59618. var p = this.head;
  59619. var c = 1;
  59620. p.data.copy(ret);
  59621. n -= p.data.length;
  59622. while (p = p.next) {
  59623. var buf = p.data;
  59624. var nb = n > buf.length ? buf.length : n;
  59625. buf.copy(ret, ret.length - n, 0, nb);
  59626. n -= nb;
  59627. if (n === 0) {
  59628. if (nb === buf.length) {
  59629. ++c;
  59630. if (p.next) this.head = p.next;else this.head = this.tail = null;
  59631. } else {
  59632. this.head = p;
  59633. p.data = buf.slice(nb);
  59634. }
  59635. break;
  59636. }
  59637. ++c;
  59638. }
  59639. this.length -= c;
  59640. return ret;
  59641. } // Make sure the linked list only shows the minimal necessary information.
  59642. }, {
  59643. key: custom,
  59644. value: function value(_, options) {
  59645. return inspect(this, _objectSpread({}, options, {
  59646. // Only inspect one level.
  59647. depth: 0,
  59648. // It should not recurse.
  59649. customInspect: false
  59650. }));
  59651. }
  59652. }]);
  59653. return BufferList;
  59654. }();
  59655. },{"buffer":216,"util":185}],485:[function(require,module,exports){
  59656. (function (process){
  59657. 'use strict'; // undocumented cb() API, needed for core, not for public API
  59658. function destroy(err, cb) {
  59659. var _this = this;
  59660. var readableDestroyed = this._readableState && this._readableState.destroyed;
  59661. var writableDestroyed = this._writableState && this._writableState.destroyed;
  59662. if (readableDestroyed || writableDestroyed) {
  59663. if (cb) {
  59664. cb(err);
  59665. } else if (err) {
  59666. if (!this._writableState) {
  59667. process.nextTick(emitErrorNT, this, err);
  59668. } else if (!this._writableState.errorEmitted) {
  59669. this._writableState.errorEmitted = true;
  59670. process.nextTick(emitErrorNT, this, err);
  59671. }
  59672. }
  59673. return this;
  59674. } // we set destroyed to true before firing error callbacks in order
  59675. // to make it re-entrance safe in case destroy() is called within callbacks
  59676. if (this._readableState) {
  59677. this._readableState.destroyed = true;
  59678. } // if this is a duplex stream mark the writable part as destroyed as well
  59679. if (this._writableState) {
  59680. this._writableState.destroyed = true;
  59681. }
  59682. this._destroy(err || null, function (err) {
  59683. if (!cb && err) {
  59684. if (!_this._writableState) {
  59685. process.nextTick(emitErrorAndCloseNT, _this, err);
  59686. } else if (!_this._writableState.errorEmitted) {
  59687. _this._writableState.errorEmitted = true;
  59688. process.nextTick(emitErrorAndCloseNT, _this, err);
  59689. } else {
  59690. process.nextTick(emitCloseNT, _this);
  59691. }
  59692. } else if (cb) {
  59693. process.nextTick(emitCloseNT, _this);
  59694. cb(err);
  59695. } else {
  59696. process.nextTick(emitCloseNT, _this);
  59697. }
  59698. });
  59699. return this;
  59700. }
  59701. function emitErrorAndCloseNT(self, err) {
  59702. emitErrorNT(self, err);
  59703. emitCloseNT(self);
  59704. }
  59705. function emitCloseNT(self) {
  59706. if (self._writableState && !self._writableState.emitClose) return;
  59707. if (self._readableState && !self._readableState.emitClose) return;
  59708. self.emit('close');
  59709. }
  59710. function undestroy() {
  59711. if (this._readableState) {
  59712. this._readableState.destroyed = false;
  59713. this._readableState.reading = false;
  59714. this._readableState.ended = false;
  59715. this._readableState.endEmitted = false;
  59716. }
  59717. if (this._writableState) {
  59718. this._writableState.destroyed = false;
  59719. this._writableState.ended = false;
  59720. this._writableState.ending = false;
  59721. this._writableState.finalCalled = false;
  59722. this._writableState.prefinished = false;
  59723. this._writableState.finished = false;
  59724. this._writableState.errorEmitted = false;
  59725. }
  59726. }
  59727. function emitErrorNT(self, err) {
  59728. self.emit('error', err);
  59729. }
  59730. function errorOrDestroy(stream, err) {
  59731. // We have tests that rely on errors being emitted
  59732. // in the same tick, so changing this is semver major.
  59733. // For now when you opt-in to autoDestroy we allow
  59734. // the error to be emitted nextTick. In a future
  59735. // semver major update we should change the default to this.
  59736. var rState = stream._readableState;
  59737. var wState = stream._writableState;
  59738. if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);else stream.emit('error', err);
  59739. }
  59740. module.exports = {
  59741. destroy: destroy,
  59742. undestroy: undestroy,
  59743. errorOrDestroy: errorOrDestroy
  59744. };
  59745. }).call(this,require('_process'))
  59746. },{"_process":467}],486:[function(require,module,exports){
  59747. // Ported from https://github.com/mafintosh/end-of-stream with
  59748. // permission from the author, Mathias Buus (@mafintosh).
  59749. 'use strict';
  59750. var ERR_STREAM_PREMATURE_CLOSE = require('../../../errors').codes.ERR_STREAM_PREMATURE_CLOSE;
  59751. function once(callback) {
  59752. var called = false;
  59753. return function () {
  59754. if (called) return;
  59755. called = true;
  59756. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  59757. args[_key] = arguments[_key];
  59758. }
  59759. callback.apply(this, args);
  59760. };
  59761. }
  59762. function noop() {}
  59763. function isRequest(stream) {
  59764. return stream.setHeader && typeof stream.abort === 'function';
  59765. }
  59766. function eos(stream, opts, callback) {
  59767. if (typeof opts === 'function') return eos(stream, null, opts);
  59768. if (!opts) opts = {};
  59769. callback = once(callback || noop);
  59770. var readable = opts.readable || opts.readable !== false && stream.readable;
  59771. var writable = opts.writable || opts.writable !== false && stream.writable;
  59772. var onlegacyfinish = function onlegacyfinish() {
  59773. if (!stream.writable) onfinish();
  59774. };
  59775. var writableEnded = stream._writableState && stream._writableState.finished;
  59776. var onfinish = function onfinish() {
  59777. writable = false;
  59778. writableEnded = true;
  59779. if (!readable) callback.call(stream);
  59780. };
  59781. var readableEnded = stream._readableState && stream._readableState.endEmitted;
  59782. var onend = function onend() {
  59783. readable = false;
  59784. readableEnded = true;
  59785. if (!writable) callback.call(stream);
  59786. };
  59787. var onerror = function onerror(err) {
  59788. callback.call(stream, err);
  59789. };
  59790. var onclose = function onclose() {
  59791. var err;
  59792. if (readable && !readableEnded) {
  59793. if (!stream._readableState || !stream._readableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
  59794. return callback.call(stream, err);
  59795. }
  59796. if (writable && !writableEnded) {
  59797. if (!stream._writableState || !stream._writableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
  59798. return callback.call(stream, err);
  59799. }
  59800. };
  59801. var onrequest = function onrequest() {
  59802. stream.req.on('finish', onfinish);
  59803. };
  59804. if (isRequest(stream)) {
  59805. stream.on('complete', onfinish);
  59806. stream.on('abort', onclose);
  59807. if (stream.req) onrequest();else stream.on('request', onrequest);
  59808. } else if (writable && !stream._writableState) {
  59809. // legacy streams
  59810. stream.on('end', onlegacyfinish);
  59811. stream.on('close', onlegacyfinish);
  59812. }
  59813. stream.on('end', onend);
  59814. stream.on('finish', onfinish);
  59815. if (opts.error !== false) stream.on('error', onerror);
  59816. stream.on('close', onclose);
  59817. return function () {
  59818. stream.removeListener('complete', onfinish);
  59819. stream.removeListener('abort', onclose);
  59820. stream.removeListener('request', onrequest);
  59821. if (stream.req) stream.req.removeListener('finish', onfinish);
  59822. stream.removeListener('end', onlegacyfinish);
  59823. stream.removeListener('close', onlegacyfinish);
  59824. stream.removeListener('finish', onfinish);
  59825. stream.removeListener('end', onend);
  59826. stream.removeListener('error', onerror);
  59827. stream.removeListener('close', onclose);
  59828. };
  59829. }
  59830. module.exports = eos;
  59831. },{"../../../errors":477}],487:[function(require,module,exports){
  59832. "use strict";
  59833. module.exports = function () {
  59834. throw new Error('Readable.from is not available in the browser');
  59835. };
  59836. },{}],488:[function(require,module,exports){
  59837. // Ported from https://github.com/mafintosh/pump with
  59838. // permission from the author, Mathias Buus (@mafintosh).
  59839. 'use strict';
  59840. var eos;
  59841. function once(callback) {
  59842. var called = false;
  59843. return function () {
  59844. if (called) return;
  59845. called = true;
  59846. callback.apply(void 0, arguments);
  59847. };
  59848. }
  59849. var _require$codes = require('../../../errors').codes,
  59850. ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS,
  59851. ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED;
  59852. function noop(err) {
  59853. // Rethrow the error if it exists to avoid swallowing it
  59854. if (err) throw err;
  59855. }
  59856. function isRequest(stream) {
  59857. return stream.setHeader && typeof stream.abort === 'function';
  59858. }
  59859. function destroyer(stream, reading, writing, callback) {
  59860. callback = once(callback);
  59861. var closed = false;
  59862. stream.on('close', function () {
  59863. closed = true;
  59864. });
  59865. if (eos === undefined) eos = require('./end-of-stream');
  59866. eos(stream, {
  59867. readable: reading,
  59868. writable: writing
  59869. }, function (err) {
  59870. if (err) return callback(err);
  59871. closed = true;
  59872. callback();
  59873. });
  59874. var destroyed = false;
  59875. return function (err) {
  59876. if (closed) return;
  59877. if (destroyed) return;
  59878. destroyed = true; // request.destroy just do .end - .abort is what we want
  59879. if (isRequest(stream)) return stream.abort();
  59880. if (typeof stream.destroy === 'function') return stream.destroy();
  59881. callback(err || new ERR_STREAM_DESTROYED('pipe'));
  59882. };
  59883. }
  59884. function call(fn) {
  59885. fn();
  59886. }
  59887. function pipe(from, to) {
  59888. return from.pipe(to);
  59889. }
  59890. function popCallback(streams) {
  59891. if (!streams.length) return noop;
  59892. if (typeof streams[streams.length - 1] !== 'function') return noop;
  59893. return streams.pop();
  59894. }
  59895. function pipeline() {
  59896. for (var _len = arguments.length, streams = new Array(_len), _key = 0; _key < _len; _key++) {
  59897. streams[_key] = arguments[_key];
  59898. }
  59899. var callback = popCallback(streams);
  59900. if (Array.isArray(streams[0])) streams = streams[0];
  59901. if (streams.length < 2) {
  59902. throw new ERR_MISSING_ARGS('streams');
  59903. }
  59904. var error;
  59905. var destroys = streams.map(function (stream, i) {
  59906. var reading = i < streams.length - 1;
  59907. var writing = i > 0;
  59908. return destroyer(stream, reading, writing, function (err) {
  59909. if (!error) error = err;
  59910. if (err) destroys.forEach(call);
  59911. if (reading) return;
  59912. destroys.forEach(call);
  59913. callback(error);
  59914. });
  59915. });
  59916. return streams.reduce(pipe);
  59917. }
  59918. module.exports = pipeline;
  59919. },{"../../../errors":477,"./end-of-stream":486}],489:[function(require,module,exports){
  59920. 'use strict';
  59921. var ERR_INVALID_OPT_VALUE = require('../../../errors').codes.ERR_INVALID_OPT_VALUE;
  59922. function highWaterMarkFrom(options, isDuplex, duplexKey) {
  59923. return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
  59924. }
  59925. function getHighWaterMark(state, options, duplexKey, isDuplex) {
  59926. var hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
  59927. if (hwm != null) {
  59928. if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) {
  59929. var name = isDuplex ? duplexKey : 'highWaterMark';
  59930. throw new ERR_INVALID_OPT_VALUE(name, hwm);
  59931. }
  59932. return Math.floor(hwm);
  59933. } // Default value
  59934. return state.objectMode ? 16 : 16 * 1024;
  59935. }
  59936. module.exports = {
  59937. getHighWaterMark: getHighWaterMark
  59938. };
  59939. },{"../../../errors":477}],490:[function(require,module,exports){
  59940. "use strict";
  59941. module.exports = require('events').EventEmitter;
  59942. },{"events":367}],491:[function(require,module,exports){
  59943. "use strict";
  59944. exports = module.exports = require('./lib/_stream_readable.js');
  59945. exports.Stream = exports;
  59946. exports.Readable = exports;
  59947. exports.Writable = require('./lib/_stream_writable.js');
  59948. exports.Duplex = require('./lib/_stream_duplex.js');
  59949. exports.Transform = require('./lib/_stream_transform.js');
  59950. exports.PassThrough = require('./lib/_stream_passthrough.js');
  59951. exports.finished = require('./lib/internal/streams/end-of-stream.js');
  59952. exports.pipeline = require('./lib/internal/streams/pipeline.js');
  59953. },{"./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){
  59954. "use strict";
  59955. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  59956. /**
  59957. * Copyright (c) 2014-present, Facebook, Inc.
  59958. *
  59959. * This source code is licensed under the MIT license found in the
  59960. * LICENSE file in the root directory of this source tree.
  59961. */
  59962. var runtime = function (exports) {
  59963. "use strict";
  59964. var Op = Object.prototype;
  59965. var hasOwn = Op.hasOwnProperty;
  59966. var undefined; // More compressible than void 0.
  59967. var $Symbol = typeof Symbol === "function" ? Symbol : {};
  59968. var iteratorSymbol = $Symbol.iterator || "@@iterator";
  59969. var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
  59970. var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  59971. function define(obj, key, value) {
  59972. Object.defineProperty(obj, key, {
  59973. value: value,
  59974. enumerable: true,
  59975. configurable: true,
  59976. writable: true
  59977. });
  59978. return obj[key];
  59979. }
  59980. try {
  59981. // IE 8 has a broken Object.defineProperty that only works on DOM objects.
  59982. define({}, "");
  59983. } catch (err) {
  59984. define = function define(obj, key, value) {
  59985. return obj[key] = value;
  59986. };
  59987. }
  59988. function wrap(innerFn, outerFn, self, tryLocsList) {
  59989. // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
  59990. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
  59991. var generator = Object.create(protoGenerator.prototype);
  59992. var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next,
  59993. // .throw, and .return methods.
  59994. generator._invoke = makeInvokeMethod(innerFn, self, context);
  59995. return generator;
  59996. }
  59997. exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion
  59998. // record like context.tryEntries[i].completion. This interface could
  59999. // have been (and was previously) designed to take a closure to be
  60000. // invoked without arguments, but in all the cases we care about we
  60001. // already have an existing method we want to call, so there's no need
  60002. // to create a new function object. We can even get away with assuming
  60003. // the method takes exactly one argument, since that happens to be true
  60004. // in every case, so we don't have to touch the arguments object. The
  60005. // only additional allocation required is the completion record, which
  60006. // has a stable shape and so hopefully should be cheap to allocate.
  60007. function tryCatch(fn, obj, arg) {
  60008. try {
  60009. return {
  60010. type: "normal",
  60011. arg: fn.call(obj, arg)
  60012. };
  60013. } catch (err) {
  60014. return {
  60015. type: "throw",
  60016. arg: err
  60017. };
  60018. }
  60019. }
  60020. var GenStateSuspendedStart = "suspendedStart";
  60021. var GenStateSuspendedYield = "suspendedYield";
  60022. var GenStateExecuting = "executing";
  60023. var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as
  60024. // breaking out of the dispatch switch statement.
  60025. var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and
  60026. // .constructor.prototype properties for functions that return Generator
  60027. // objects. For full spec compliance, you may wish to configure your
  60028. // minifier not to mangle the names of these two functions.
  60029. function Generator() {}
  60030. function GeneratorFunction() {}
  60031. function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that
  60032. // don't natively support it.
  60033. var IteratorPrototype = {};
  60034. IteratorPrototype[iteratorSymbol] = function () {
  60035. return this;
  60036. };
  60037. var getProto = Object.getPrototypeOf;
  60038. var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  60039. if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
  60040. // This environment has a native %IteratorPrototype%; use it instead
  60041. // of the polyfill.
  60042. IteratorPrototype = NativeIteratorPrototype;
  60043. }
  60044. var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
  60045. GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
  60046. GeneratorFunctionPrototype.constructor = GeneratorFunction;
  60047. GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
  60048. // Iterator interface in terms of a single ._invoke method.
  60049. function defineIteratorMethods(prototype) {
  60050. ["next", "throw", "return"].forEach(function (method) {
  60051. define(prototype, method, function (arg) {
  60052. return this._invoke(method, arg);
  60053. });
  60054. });
  60055. }
  60056. exports.isGeneratorFunction = function (genFun) {
  60057. var ctor = typeof genFun === "function" && genFun.constructor;
  60058. return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can
  60059. // do is to check its .name property.
  60060. (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
  60061. };
  60062. exports.mark = function (genFun) {
  60063. if (Object.setPrototypeOf) {
  60064. Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
  60065. } else {
  60066. genFun.__proto__ = GeneratorFunctionPrototype;
  60067. define(genFun, toStringTagSymbol, "GeneratorFunction");
  60068. }
  60069. genFun.prototype = Object.create(Gp);
  60070. return genFun;
  60071. }; // Within the body of any async function, `await x` is transformed to
  60072. // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
  60073. // `hasOwn.call(value, "__await")` to determine if the yielded value is
  60074. // meant to be awaited.
  60075. exports.awrap = function (arg) {
  60076. return {
  60077. __await: arg
  60078. };
  60079. };
  60080. function AsyncIterator(generator, PromiseImpl) {
  60081. function invoke(method, arg, resolve, reject) {
  60082. var record = tryCatch(generator[method], generator, arg);
  60083. if (record.type === "throw") {
  60084. reject(record.arg);
  60085. } else {
  60086. var result = record.arg;
  60087. var value = result.value;
  60088. if (value && _typeof(value) === "object" && hasOwn.call(value, "__await")) {
  60089. return PromiseImpl.resolve(value.__await).then(function (value) {
  60090. invoke("next", value, resolve, reject);
  60091. }, function (err) {
  60092. invoke("throw", err, resolve, reject);
  60093. });
  60094. }
  60095. return PromiseImpl.resolve(value).then(function (unwrapped) {
  60096. // When a yielded Promise is resolved, its final value becomes
  60097. // the .value of the Promise<{value,done}> result for the
  60098. // current iteration.
  60099. result.value = unwrapped;
  60100. resolve(result);
  60101. }, function (error) {
  60102. // If a rejected Promise was yielded, throw the rejection back
  60103. // into the async generator function so it can be handled there.
  60104. return invoke("throw", error, resolve, reject);
  60105. });
  60106. }
  60107. }
  60108. var previousPromise;
  60109. function enqueue(method, arg) {
  60110. function callInvokeWithMethodAndArg() {
  60111. return new PromiseImpl(function (resolve, reject) {
  60112. invoke(method, arg, resolve, reject);
  60113. });
  60114. }
  60115. return previousPromise = // If enqueue has been called before, then we want to wait until
  60116. // all previous Promises have been resolved before calling invoke,
  60117. // so that results are always delivered in the correct order. If
  60118. // enqueue has not been called before, then it is important to
  60119. // call invoke immediately, without waiting on a callback to fire,
  60120. // so that the async generator function has the opportunity to do
  60121. // any necessary setup in a predictable way. This predictability
  60122. // is why the Promise constructor synchronously invokes its
  60123. // executor callback, and why async functions synchronously
  60124. // execute code before the first await. Since we implement simple
  60125. // async functions in terms of async generators, it is especially
  60126. // important to get this right, even though it requires care.
  60127. previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later
  60128. // invocations of the iterator.
  60129. callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  60130. } // Define the unified helper method that is used to implement .next,
  60131. // .throw, and .return (see defineIteratorMethods).
  60132. this._invoke = enqueue;
  60133. }
  60134. defineIteratorMethods(AsyncIterator.prototype);
  60135. AsyncIterator.prototype[asyncIteratorSymbol] = function () {
  60136. return this;
  60137. };
  60138. exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
  60139. // AsyncIterator objects; they just return a Promise for the value of
  60140. // the final result produced by the iterator.
  60141. exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  60142. if (PromiseImpl === void 0) PromiseImpl = Promise;
  60143. var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
  60144. return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
  60145. : iter.next().then(function (result) {
  60146. return result.done ? result.value : iter.next();
  60147. });
  60148. };
  60149. function makeInvokeMethod(innerFn, self, context) {
  60150. var state = GenStateSuspendedStart;
  60151. return function invoke(method, arg) {
  60152. if (state === GenStateExecuting) {
  60153. throw new Error("Generator is already running");
  60154. }
  60155. if (state === GenStateCompleted) {
  60156. if (method === "throw") {
  60157. throw arg;
  60158. } // Be forgiving, per 25.3.3.3.3 of the spec:
  60159. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
  60160. return doneResult();
  60161. }
  60162. context.method = method;
  60163. context.arg = arg;
  60164. while (true) {
  60165. var delegate = context.delegate;
  60166. if (delegate) {
  60167. var delegateResult = maybeInvokeDelegate(delegate, context);
  60168. if (delegateResult) {
  60169. if (delegateResult === ContinueSentinel) continue;
  60170. return delegateResult;
  60171. }
  60172. }
  60173. if (context.method === "next") {
  60174. // Setting context._sent for legacy support of Babel's
  60175. // function.sent implementation.
  60176. context.sent = context._sent = context.arg;
  60177. } else if (context.method === "throw") {
  60178. if (state === GenStateSuspendedStart) {
  60179. state = GenStateCompleted;
  60180. throw context.arg;
  60181. }
  60182. context.dispatchException(context.arg);
  60183. } else if (context.method === "return") {
  60184. context.abrupt("return", context.arg);
  60185. }
  60186. state = GenStateExecuting;
  60187. var record = tryCatch(innerFn, self, context);
  60188. if (record.type === "normal") {
  60189. // If an exception is thrown from innerFn, we leave state ===
  60190. // GenStateExecuting and loop back for another invocation.
  60191. state = context.done ? GenStateCompleted : GenStateSuspendedYield;
  60192. if (record.arg === ContinueSentinel) {
  60193. continue;
  60194. }
  60195. return {
  60196. value: record.arg,
  60197. done: context.done
  60198. };
  60199. } else if (record.type === "throw") {
  60200. state = GenStateCompleted; // Dispatch the exception by looping back around to the
  60201. // context.dispatchException(context.arg) call above.
  60202. context.method = "throw";
  60203. context.arg = record.arg;
  60204. }
  60205. }
  60206. };
  60207. } // Call delegate.iterator[context.method](context.arg) and handle the
  60208. // result, either by returning a { value, done } result from the
  60209. // delegate iterator, or by modifying context.method and context.arg,
  60210. // setting context.delegate to null, and returning the ContinueSentinel.
  60211. function maybeInvokeDelegate(delegate, context) {
  60212. var method = delegate.iterator[context.method];
  60213. if (method === undefined) {
  60214. // A .throw or .return when the delegate iterator has no .throw
  60215. // method always terminates the yield* loop.
  60216. context.delegate = null;
  60217. if (context.method === "throw") {
  60218. // Note: ["return"] must be used for ES3 parsing compatibility.
  60219. if (delegate.iterator["return"]) {
  60220. // If the delegate iterator has a return method, give it a
  60221. // chance to clean up.
  60222. context.method = "return";
  60223. context.arg = undefined;
  60224. maybeInvokeDelegate(delegate, context);
  60225. if (context.method === "throw") {
  60226. // If maybeInvokeDelegate(context) changed context.method from
  60227. // "return" to "throw", let that override the TypeError below.
  60228. return ContinueSentinel;
  60229. }
  60230. }
  60231. context.method = "throw";
  60232. context.arg = new TypeError("The iterator does not provide a 'throw' method");
  60233. }
  60234. return ContinueSentinel;
  60235. }
  60236. var record = tryCatch(method, delegate.iterator, context.arg);
  60237. if (record.type === "throw") {
  60238. context.method = "throw";
  60239. context.arg = record.arg;
  60240. context.delegate = null;
  60241. return ContinueSentinel;
  60242. }
  60243. var info = record.arg;
  60244. if (!info) {
  60245. context.method = "throw";
  60246. context.arg = new TypeError("iterator result is not an object");
  60247. context.delegate = null;
  60248. return ContinueSentinel;
  60249. }
  60250. if (info.done) {
  60251. // Assign the result of the finished delegate to the temporary
  60252. // variable specified by delegate.resultName (see delegateYield).
  60253. context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield).
  60254. context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the
  60255. // exception, let the outer generator proceed normally. If
  60256. // context.method was "next", forget context.arg since it has been
  60257. // "consumed" by the delegate iterator. If context.method was
  60258. // "return", allow the original .return call to continue in the
  60259. // outer generator.
  60260. if (context.method !== "return") {
  60261. context.method = "next";
  60262. context.arg = undefined;
  60263. }
  60264. } else {
  60265. // Re-yield the result returned by the delegate method.
  60266. return info;
  60267. } // The delegate iterator is finished, so forget it and continue with
  60268. // the outer generator.
  60269. context.delegate = null;
  60270. return ContinueSentinel;
  60271. } // Define Generator.prototype.{next,throw,return} in terms of the
  60272. // unified ._invoke helper method.
  60273. defineIteratorMethods(Gp);
  60274. define(Gp, toStringTagSymbol, "Generator"); // A Generator should always return itself as the iterator object when the
  60275. // @@iterator function is called on it. Some browsers' implementations of the
  60276. // iterator prototype chain incorrectly implement this, causing the Generator
  60277. // object to not be returned from this call. This ensures that doesn't happen.
  60278. // See https://github.com/facebook/regenerator/issues/274 for more details.
  60279. Gp[iteratorSymbol] = function () {
  60280. return this;
  60281. };
  60282. Gp.toString = function () {
  60283. return "[object Generator]";
  60284. };
  60285. function pushTryEntry(locs) {
  60286. var entry = {
  60287. tryLoc: locs[0]
  60288. };
  60289. if (1 in locs) {
  60290. entry.catchLoc = locs[1];
  60291. }
  60292. if (2 in locs) {
  60293. entry.finallyLoc = locs[2];
  60294. entry.afterLoc = locs[3];
  60295. }
  60296. this.tryEntries.push(entry);
  60297. }
  60298. function resetTryEntry(entry) {
  60299. var record = entry.completion || {};
  60300. record.type = "normal";
  60301. delete record.arg;
  60302. entry.completion = record;
  60303. }
  60304. function Context(tryLocsList) {
  60305. // The root entry object (effectively a try statement without a catch
  60306. // or a finally block) gives us a place to store values thrown from
  60307. // locations where there is no enclosing try statement.
  60308. this.tryEntries = [{
  60309. tryLoc: "root"
  60310. }];
  60311. tryLocsList.forEach(pushTryEntry, this);
  60312. this.reset(true);
  60313. }
  60314. exports.keys = function (object) {
  60315. var keys = [];
  60316. for (var key in object) {
  60317. keys.push(key);
  60318. }
  60319. keys.reverse(); // Rather than returning an object with a next method, we keep
  60320. // things simple and return the next function itself.
  60321. return function next() {
  60322. while (keys.length) {
  60323. var key = keys.pop();
  60324. if (key in object) {
  60325. next.value = key;
  60326. next.done = false;
  60327. return next;
  60328. }
  60329. } // To avoid creating an additional object, we just hang the .value
  60330. // and .done properties off the next function object itself. This
  60331. // also ensures that the minifier will not anonymize the function.
  60332. next.done = true;
  60333. return next;
  60334. };
  60335. };
  60336. function values(iterable) {
  60337. if (iterable) {
  60338. var iteratorMethod = iterable[iteratorSymbol];
  60339. if (iteratorMethod) {
  60340. return iteratorMethod.call(iterable);
  60341. }
  60342. if (typeof iterable.next === "function") {
  60343. return iterable;
  60344. }
  60345. if (!isNaN(iterable.length)) {
  60346. var i = -1,
  60347. next = function next() {
  60348. while (++i < iterable.length) {
  60349. if (hasOwn.call(iterable, i)) {
  60350. next.value = iterable[i];
  60351. next.done = false;
  60352. return next;
  60353. }
  60354. }
  60355. next.value = undefined;
  60356. next.done = true;
  60357. return next;
  60358. };
  60359. return next.next = next;
  60360. }
  60361. } // Return an iterator with no values.
  60362. return {
  60363. next: doneResult
  60364. };
  60365. }
  60366. exports.values = values;
  60367. function doneResult() {
  60368. return {
  60369. value: undefined,
  60370. done: true
  60371. };
  60372. }
  60373. Context.prototype = {
  60374. constructor: Context,
  60375. reset: function reset(skipTempReset) {
  60376. this.prev = 0;
  60377. this.next = 0; // Resetting context._sent for legacy support of Babel's
  60378. // function.sent implementation.
  60379. this.sent = this._sent = undefined;
  60380. this.done = false;
  60381. this.delegate = null;
  60382. this.method = "next";
  60383. this.arg = undefined;
  60384. this.tryEntries.forEach(resetTryEntry);
  60385. if (!skipTempReset) {
  60386. for (var name in this) {
  60387. // Not sure about the optimal order of these conditions:
  60388. if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
  60389. this[name] = undefined;
  60390. }
  60391. }
  60392. }
  60393. },
  60394. stop: function stop() {
  60395. this.done = true;
  60396. var rootEntry = this.tryEntries[0];
  60397. var rootRecord = rootEntry.completion;
  60398. if (rootRecord.type === "throw") {
  60399. throw rootRecord.arg;
  60400. }
  60401. return this.rval;
  60402. },
  60403. dispatchException: function dispatchException(exception) {
  60404. if (this.done) {
  60405. throw exception;
  60406. }
  60407. var context = this;
  60408. function handle(loc, caught) {
  60409. record.type = "throw";
  60410. record.arg = exception;
  60411. context.next = loc;
  60412. if (caught) {
  60413. // If the dispatched exception was caught by a catch block,
  60414. // then let that catch block handle the exception normally.
  60415. context.method = "next";
  60416. context.arg = undefined;
  60417. }
  60418. return !!caught;
  60419. }
  60420. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  60421. var entry = this.tryEntries[i];
  60422. var record = entry.completion;
  60423. if (entry.tryLoc === "root") {
  60424. // Exception thrown outside of any try block that could handle
  60425. // it, so set the completion value of the entire function to
  60426. // throw the exception.
  60427. return handle("end");
  60428. }
  60429. if (entry.tryLoc <= this.prev) {
  60430. var hasCatch = hasOwn.call(entry, "catchLoc");
  60431. var hasFinally = hasOwn.call(entry, "finallyLoc");
  60432. if (hasCatch && hasFinally) {
  60433. if (this.prev < entry.catchLoc) {
  60434. return handle(entry.catchLoc, true);
  60435. } else if (this.prev < entry.finallyLoc) {
  60436. return handle(entry.finallyLoc);
  60437. }
  60438. } else if (hasCatch) {
  60439. if (this.prev < entry.catchLoc) {
  60440. return handle(entry.catchLoc, true);
  60441. }
  60442. } else if (hasFinally) {
  60443. if (this.prev < entry.finallyLoc) {
  60444. return handle(entry.finallyLoc);
  60445. }
  60446. } else {
  60447. throw new Error("try statement without catch or finally");
  60448. }
  60449. }
  60450. }
  60451. },
  60452. abrupt: function abrupt(type, arg) {
  60453. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  60454. var entry = this.tryEntries[i];
  60455. if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
  60456. var finallyEntry = entry;
  60457. break;
  60458. }
  60459. }
  60460. if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
  60461. // Ignore the finally entry if control is not jumping to a
  60462. // location outside the try/catch block.
  60463. finallyEntry = null;
  60464. }
  60465. var record = finallyEntry ? finallyEntry.completion : {};
  60466. record.type = type;
  60467. record.arg = arg;
  60468. if (finallyEntry) {
  60469. this.method = "next";
  60470. this.next = finallyEntry.finallyLoc;
  60471. return ContinueSentinel;
  60472. }
  60473. return this.complete(record);
  60474. },
  60475. complete: function complete(record, afterLoc) {
  60476. if (record.type === "throw") {
  60477. throw record.arg;
  60478. }
  60479. if (record.type === "break" || record.type === "continue") {
  60480. this.next = record.arg;
  60481. } else if (record.type === "return") {
  60482. this.rval = this.arg = record.arg;
  60483. this.method = "return";
  60484. this.next = "end";
  60485. } else if (record.type === "normal" && afterLoc) {
  60486. this.next = afterLoc;
  60487. }
  60488. return ContinueSentinel;
  60489. },
  60490. finish: function finish(finallyLoc) {
  60491. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  60492. var entry = this.tryEntries[i];
  60493. if (entry.finallyLoc === finallyLoc) {
  60494. this.complete(entry.completion, entry.afterLoc);
  60495. resetTryEntry(entry);
  60496. return ContinueSentinel;
  60497. }
  60498. }
  60499. },
  60500. "catch": function _catch(tryLoc) {
  60501. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  60502. var entry = this.tryEntries[i];
  60503. if (entry.tryLoc === tryLoc) {
  60504. var record = entry.completion;
  60505. if (record.type === "throw") {
  60506. var thrown = record.arg;
  60507. resetTryEntry(entry);
  60508. }
  60509. return thrown;
  60510. }
  60511. } // The context.catch method must only be called with a location
  60512. // argument that corresponds to a known catch block.
  60513. throw new Error("illegal catch attempt");
  60514. },
  60515. delegateYield: function delegateYield(iterable, resultName, nextLoc) {
  60516. this.delegate = {
  60517. iterator: values(iterable),
  60518. resultName: resultName,
  60519. nextLoc: nextLoc
  60520. };
  60521. if (this.method === "next") {
  60522. // Deliberately forget the last sent value so that we don't
  60523. // accidentally pass it on to the delegate.
  60524. this.arg = undefined;
  60525. }
  60526. return ContinueSentinel;
  60527. }
  60528. }; // Regardless of whether this script is executing as a CommonJS module
  60529. // or not, return the runtime object so that we can declare the variable
  60530. // regeneratorRuntime in the outer scope, which allows this module to be
  60531. // injected easily by `bin/regenerator --include-runtime script.js`.
  60532. return exports;
  60533. }( // If this script is executing as a CommonJS module, use module.exports
  60534. // as the regeneratorRuntime namespace. Otherwise create a new empty
  60535. // object. Either way, the resulting object will be used to initialize
  60536. // the regeneratorRuntime variable at the top of this file.
  60537. (typeof module === "undefined" ? "undefined" : _typeof(module)) === "object" ? module.exports : {});
  60538. try {
  60539. regeneratorRuntime = runtime;
  60540. } catch (accidentalStrictMode) {
  60541. // This module should not be running in strict mode, so the above
  60542. // assignment should always work unless something is misconfigured. Just
  60543. // in case runtime.js accidentally runs in strict mode, we can escape
  60544. // strict mode using a global Function call. This could conceivably fail
  60545. // if a Content Security Policy forbids using Function, but in that case
  60546. // the proper solution is to fix the accidental strict mode problem. If
  60547. // you've misconfigured your bundler to force strict mode and applied a
  60548. // CSP to forbid Function, and you're not willing to fix either of those
  60549. // problems, please detail your unique predicament in a GitHub issue.
  60550. Function("r", "regeneratorRuntime = r")(runtime);
  60551. }
  60552. },{}],493:[function(require,module,exports){
  60553. 'use strict';
  60554. var Buffer = require('buffer').Buffer;
  60555. var inherits = require('inherits');
  60556. var HashBase = require('hash-base');
  60557. var ARRAY16 = new Array(16);
  60558. 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];
  60559. 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];
  60560. 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];
  60561. 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];
  60562. var hl = [0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e];
  60563. var hr = [0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000];
  60564. function RIPEMD160() {
  60565. HashBase.call(this, 64); // state
  60566. this._a = 0x67452301;
  60567. this._b = 0xefcdab89;
  60568. this._c = 0x98badcfe;
  60569. this._d = 0x10325476;
  60570. this._e = 0xc3d2e1f0;
  60571. }
  60572. inherits(RIPEMD160, HashBase);
  60573. RIPEMD160.prototype._update = function () {
  60574. var words = ARRAY16;
  60575. for (var j = 0; j < 16; ++j) {
  60576. words[j] = this._block.readInt32LE(j * 4);
  60577. }
  60578. var al = this._a | 0;
  60579. var bl = this._b | 0;
  60580. var cl = this._c | 0;
  60581. var dl = this._d | 0;
  60582. var el = this._e | 0;
  60583. var ar = this._a | 0;
  60584. var br = this._b | 0;
  60585. var cr = this._c | 0;
  60586. var dr = this._d | 0;
  60587. var er = this._e | 0; // computation
  60588. for (var i = 0; i < 80; i += 1) {
  60589. var tl;
  60590. var tr;
  60591. if (i < 16) {
  60592. tl = fn1(al, bl, cl, dl, el, words[zl[i]], hl[0], sl[i]);
  60593. tr = fn5(ar, br, cr, dr, er, words[zr[i]], hr[0], sr[i]);
  60594. } else if (i < 32) {
  60595. tl = fn2(al, bl, cl, dl, el, words[zl[i]], hl[1], sl[i]);
  60596. tr = fn4(ar, br, cr, dr, er, words[zr[i]], hr[1], sr[i]);
  60597. } else if (i < 48) {
  60598. tl = fn3(al, bl, cl, dl, el, words[zl[i]], hl[2], sl[i]);
  60599. tr = fn3(ar, br, cr, dr, er, words[zr[i]], hr[2], sr[i]);
  60600. } else if (i < 64) {
  60601. tl = fn4(al, bl, cl, dl, el, words[zl[i]], hl[3], sl[i]);
  60602. tr = fn2(ar, br, cr, dr, er, words[zr[i]], hr[3], sr[i]);
  60603. } else {
  60604. // if (i<80) {
  60605. tl = fn5(al, bl, cl, dl, el, words[zl[i]], hl[4], sl[i]);
  60606. tr = fn1(ar, br, cr, dr, er, words[zr[i]], hr[4], sr[i]);
  60607. }
  60608. al = el;
  60609. el = dl;
  60610. dl = rotl(cl, 10);
  60611. cl = bl;
  60612. bl = tl;
  60613. ar = er;
  60614. er = dr;
  60615. dr = rotl(cr, 10);
  60616. cr = br;
  60617. br = tr;
  60618. } // update state
  60619. var t = this._b + cl + dr | 0;
  60620. this._b = this._c + dl + er | 0;
  60621. this._c = this._d + el + ar | 0;
  60622. this._d = this._e + al + br | 0;
  60623. this._e = this._a + bl + cr | 0;
  60624. this._a = t;
  60625. };
  60626. RIPEMD160.prototype._digest = function () {
  60627. // create padding and handle blocks
  60628. this._block[this._blockOffset++] = 0x80;
  60629. if (this._blockOffset > 56) {
  60630. this._block.fill(0, this._blockOffset, 64);
  60631. this._update();
  60632. this._blockOffset = 0;
  60633. }
  60634. this._block.fill(0, this._blockOffset, 56);
  60635. this._block.writeUInt32LE(this._length[0], 56);
  60636. this._block.writeUInt32LE(this._length[1], 60);
  60637. this._update(); // produce result
  60638. var buffer = Buffer.alloc ? Buffer.alloc(20) : new Buffer(20);
  60639. buffer.writeInt32LE(this._a, 0);
  60640. buffer.writeInt32LE(this._b, 4);
  60641. buffer.writeInt32LE(this._c, 8);
  60642. buffer.writeInt32LE(this._d, 12);
  60643. buffer.writeInt32LE(this._e, 16);
  60644. return buffer;
  60645. };
  60646. function rotl(x, n) {
  60647. return x << n | x >>> 32 - n;
  60648. }
  60649. function fn1(a, b, c, d, e, m, k, s) {
  60650. return rotl(a + (b ^ c ^ d) + m + k | 0, s) + e | 0;
  60651. }
  60652. function fn2(a, b, c, d, e, m, k, s) {
  60653. return rotl(a + (b & c | ~b & d) + m + k | 0, s) + e | 0;
  60654. }
  60655. function fn3(a, b, c, d, e, m, k, s) {
  60656. return rotl(a + ((b | ~c) ^ d) + m + k | 0, s) + e | 0;
  60657. }
  60658. function fn4(a, b, c, d, e, m, k, s) {
  60659. return rotl(a + (b & d | c & ~d) + m + k | 0, s) + e | 0;
  60660. }
  60661. function fn5(a, b, c, d, e, m, k, s) {
  60662. return rotl(a + (b ^ (c | ~d)) + m + k | 0, s) + e | 0;
  60663. }
  60664. module.exports = RIPEMD160;
  60665. },{"buffer":216,"hash-base":370,"inherits":387}],494:[function(require,module,exports){
  60666. "use strict";
  60667. /* eslint-disable node/no-deprecated-api */
  60668. var buffer = require('buffer');
  60669. var Buffer = buffer.Buffer; // alternative to using Object.keys for old browsers
  60670. function copyProps(src, dst) {
  60671. for (var key in src) {
  60672. dst[key] = src[key];
  60673. }
  60674. }
  60675. if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
  60676. module.exports = buffer;
  60677. } else {
  60678. // Copy properties from require('buffer')
  60679. copyProps(buffer, exports);
  60680. exports.Buffer = SafeBuffer;
  60681. }
  60682. function SafeBuffer(arg, encodingOrOffset, length) {
  60683. return Buffer(arg, encodingOrOffset, length);
  60684. } // Copy static methods from Buffer
  60685. copyProps(Buffer, SafeBuffer);
  60686. SafeBuffer.from = function (arg, encodingOrOffset, length) {
  60687. if (typeof arg === 'number') {
  60688. throw new TypeError('Argument must not be a number');
  60689. }
  60690. return Buffer(arg, encodingOrOffset, length);
  60691. };
  60692. SafeBuffer.alloc = function (size, fill, encoding) {
  60693. if (typeof size !== 'number') {
  60694. throw new TypeError('Argument must be a number');
  60695. }
  60696. var buf = Buffer(size);
  60697. if (fill !== undefined) {
  60698. if (typeof encoding === 'string') {
  60699. buf.fill(fill, encoding);
  60700. } else {
  60701. buf.fill(fill);
  60702. }
  60703. } else {
  60704. buf.fill(0);
  60705. }
  60706. return buf;
  60707. };
  60708. SafeBuffer.allocUnsafe = function (size) {
  60709. if (typeof size !== 'number') {
  60710. throw new TypeError('Argument must be a number');
  60711. }
  60712. return Buffer(size);
  60713. };
  60714. SafeBuffer.allocUnsafeSlow = function (size) {
  60715. if (typeof size !== 'number') {
  60716. throw new TypeError('Argument must be a number');
  60717. }
  60718. return buffer.SlowBuffer(size);
  60719. };
  60720. },{"buffer":216}],495:[function(require,module,exports){
  60721. (function (process){
  60722. /* eslint-disable node/no-deprecated-api */
  60723. 'use strict';
  60724. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  60725. var buffer = require('buffer');
  60726. var Buffer = buffer.Buffer;
  60727. var safer = {};
  60728. var key;
  60729. for (key in buffer) {
  60730. if (!buffer.hasOwnProperty(key)) continue;
  60731. if (key === 'SlowBuffer' || key === 'Buffer') continue;
  60732. safer[key] = buffer[key];
  60733. }
  60734. var Safer = safer.Buffer = {};
  60735. for (key in Buffer) {
  60736. if (!Buffer.hasOwnProperty(key)) continue;
  60737. if (key === 'allocUnsafe' || key === 'allocUnsafeSlow') continue;
  60738. Safer[key] = Buffer[key];
  60739. }
  60740. safer.Buffer.prototype = Buffer.prototype;
  60741. if (!Safer.from || Safer.from === Uint8Array.from) {
  60742. Safer.from = function (value, encodingOrOffset, length) {
  60743. if (typeof value === 'number') {
  60744. throw new TypeError('The "value" argument must not be of type number. Received type ' + _typeof(value));
  60745. }
  60746. if (value && typeof value.length === 'undefined') {
  60747. throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type ' + _typeof(value));
  60748. }
  60749. return Buffer(value, encodingOrOffset, length);
  60750. };
  60751. }
  60752. if (!Safer.alloc) {
  60753. Safer.alloc = function (size, fill, encoding) {
  60754. if (typeof size !== 'number') {
  60755. throw new TypeError('The "size" argument must be of type number. Received type ' + _typeof(size));
  60756. }
  60757. if (size < 0 || size >= 2 * (1 << 30)) {
  60758. throw new RangeError('The value "' + size + '" is invalid for option "size"');
  60759. }
  60760. var buf = Buffer(size);
  60761. if (!fill || fill.length === 0) {
  60762. buf.fill(0);
  60763. } else if (typeof encoding === 'string') {
  60764. buf.fill(fill, encoding);
  60765. } else {
  60766. buf.fill(fill);
  60767. }
  60768. return buf;
  60769. };
  60770. }
  60771. if (!safer.kStringMaxLength) {
  60772. try {
  60773. safer.kStringMaxLength = process.binding('buffer').kStringMaxLength;
  60774. } catch (e) {// we can't determine kStringMaxLength in environments where process.binding
  60775. // is unsupported, so let's not set it
  60776. }
  60777. }
  60778. if (!safer.constants) {
  60779. safer.constants = {
  60780. MAX_LENGTH: safer.kMaxLength
  60781. };
  60782. if (safer.kStringMaxLength) {
  60783. safer.constants.MAX_STRING_LENGTH = safer.kStringMaxLength;
  60784. }
  60785. }
  60786. module.exports = safer;
  60787. }).call(this,require('_process'))
  60788. },{"_process":467,"buffer":216}],496:[function(require,module,exports){
  60789. "use strict";
  60790. function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
  60791. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  60792. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  60793. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  60794. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  60795. function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
  60796. function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  60797. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  60798. function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
  60799. function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
  60800. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  60801. Object.defineProperty(exports, "__esModule", {
  60802. value: true
  60803. });
  60804. var ed5 = require("xmlchars/xml/1.0/ed5");
  60805. var ed2 = require("xmlchars/xml/1.1/ed2");
  60806. var NSed3 = require("xmlchars/xmlns/1.0/ed3");
  60807. var isS = ed5.isS;
  60808. var isChar10 = ed5.isChar;
  60809. var isNameStartChar = ed5.isNameStartChar;
  60810. var isNameChar = ed5.isNameChar;
  60811. var S_LIST = ed5.S_LIST;
  60812. var NAME_RE = ed5.NAME_RE;
  60813. var isChar11 = ed2.isChar;
  60814. var isNCNameStartChar = NSed3.isNCNameStartChar;
  60815. var isNCNameChar = NSed3.isNCNameChar;
  60816. var NC_NAME_RE = NSed3.NC_NAME_RE;
  60817. var XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
  60818. var XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
  60819. var rootNS = {
  60820. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  60821. __proto__: null,
  60822. xml: XML_NAMESPACE,
  60823. xmlns: XMLNS_NAMESPACE
  60824. };
  60825. var XML_ENTITIES = {
  60826. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  60827. __proto__: null,
  60828. amp: "&",
  60829. gt: ">",
  60830. lt: "<",
  60831. quot: "\"",
  60832. apos: "'"
  60833. }; // EOC: end-of-chunk
  60834. var EOC = -1;
  60835. var NL_LIKE = -2;
  60836. var S_BEGIN = 0; // Initial state.
  60837. var S_BEGIN_WHITESPACE = 1; // leading whitespace
  60838. var S_DOCTYPE = 2; // <!DOCTYPE
  60839. var S_DOCTYPE_QUOTE = 3; // <!DOCTYPE "//blah
  60840. var S_DTD = 4; // <!DOCTYPE "//blah" [ ...
  60841. var S_DTD_QUOTED = 5; // <!DOCTYPE "//blah" [ "foo
  60842. var S_DTD_OPEN_WAKA = 6;
  60843. var S_DTD_OPEN_WAKA_BANG = 7;
  60844. var S_DTD_COMMENT = 8; // <!--
  60845. var S_DTD_COMMENT_ENDING = 9; // <!-- blah -
  60846. var S_DTD_COMMENT_ENDED = 10; // <!-- blah --
  60847. var S_DTD_PI = 11; // <?
  60848. var S_DTD_PI_ENDING = 12; // <?hi "there" ?
  60849. var S_TEXT = 13; // general stuff
  60850. var S_ENTITY = 14; // &amp and such
  60851. var S_OPEN_WAKA = 15; // <
  60852. var S_OPEN_WAKA_BANG = 16; // <!...
  60853. var S_COMMENT = 17; // <!--
  60854. var S_COMMENT_ENDING = 18; // <!-- blah -
  60855. var S_COMMENT_ENDED = 19; // <!-- blah --
  60856. var S_CDATA = 20; // <![CDATA[ something
  60857. var S_CDATA_ENDING = 21; // ]
  60858. var S_CDATA_ENDING_2 = 22; // ]]
  60859. var S_PI_FIRST_CHAR = 23; // <?hi, first char
  60860. var S_PI_REST = 24; // <?hi, rest of the name
  60861. var S_PI_BODY = 25; // <?hi there
  60862. var S_PI_ENDING = 26; // <?hi "there" ?
  60863. var S_XML_DECL_NAME_START = 27; // <?xml
  60864. var S_XML_DECL_NAME = 28; // <?xml foo
  60865. var S_XML_DECL_EQ = 29; // <?xml foo=
  60866. var S_XML_DECL_VALUE_START = 30; // <?xml foo=
  60867. var S_XML_DECL_VALUE = 31; // <?xml foo="bar"
  60868. var S_XML_DECL_SEPARATOR = 32; // <?xml foo="bar"
  60869. var S_XML_DECL_ENDING = 33; // <?xml ... ?
  60870. var S_OPEN_TAG = 34; // <strong
  60871. var S_OPEN_TAG_SLASH = 35; // <strong /
  60872. var S_ATTRIB = 36; // <a
  60873. var S_ATTRIB_NAME = 37; // <a foo
  60874. var S_ATTRIB_NAME_SAW_WHITE = 38; // <a foo _
  60875. var S_ATTRIB_VALUE = 39; // <a foo=
  60876. var S_ATTRIB_VALUE_QUOTED = 40; // <a foo="bar
  60877. var S_ATTRIB_VALUE_CLOSED = 41; // <a foo="bar"
  60878. var S_ATTRIB_VALUE_UNQUOTED = 42; // <a foo=bar
  60879. var S_CLOSE_TAG = 43; // </a
  60880. var S_CLOSE_TAG_SAW_WHITE = 44; // </a >
  60881. var TAB = 9;
  60882. var NL = 0xA;
  60883. var CR = 0xD;
  60884. var SPACE = 0x20;
  60885. var BANG = 0x21;
  60886. var DQUOTE = 0x22;
  60887. var AMP = 0x26;
  60888. var SQUOTE = 0x27;
  60889. var MINUS = 0x2D;
  60890. var FORWARD_SLASH = 0x2F;
  60891. var SEMICOLON = 0x3B;
  60892. var LESS = 0x3C;
  60893. var EQUAL = 0x3D;
  60894. var GREATER = 0x3E;
  60895. var QUESTION = 0x3F;
  60896. var OPEN_BRACKET = 0x5B;
  60897. var CLOSE_BRACKET = 0x5D;
  60898. var NEL = 0x85;
  60899. var LS = 0x2028; // Line Separator
  60900. var isQuote = function isQuote(c) {
  60901. return c === DQUOTE || c === SQUOTE;
  60902. };
  60903. var QUOTES = [DQUOTE, SQUOTE];
  60904. var DOCTYPE_TERMINATOR = [].concat(QUOTES, [OPEN_BRACKET, GREATER]);
  60905. var DTD_TERMINATOR = [].concat(QUOTES, [LESS, CLOSE_BRACKET]);
  60906. var XML_DECL_NAME_TERMINATOR = [EQUAL, QUESTION].concat(_toConsumableArray(S_LIST));
  60907. var ATTRIB_VALUE_UNQUOTED_TERMINATOR = [].concat(_toConsumableArray(S_LIST), [GREATER, AMP, LESS]);
  60908. function nsPairCheck(parser, prefix, uri) {
  60909. switch (prefix) {
  60910. case "xml":
  60911. if (uri !== XML_NAMESPACE) {
  60912. parser.fail("xml prefix must be bound to ".concat(XML_NAMESPACE, "."));
  60913. }
  60914. break;
  60915. case "xmlns":
  60916. if (uri !== XMLNS_NAMESPACE) {
  60917. parser.fail("xmlns prefix must be bound to ".concat(XMLNS_NAMESPACE, "."));
  60918. }
  60919. break;
  60920. default:
  60921. }
  60922. switch (uri) {
  60923. case XMLNS_NAMESPACE:
  60924. parser.fail(prefix === "" ? "the default namespace may not be set to ".concat(uri, ".") : "may not assign a prefix (even \"xmlns\") to the URI ".concat(XMLNS_NAMESPACE, "."));
  60925. break;
  60926. case XML_NAMESPACE:
  60927. switch (prefix) {
  60928. case "xml":
  60929. // Assinging the XML namespace to "xml" is fine.
  60930. break;
  60931. case "":
  60932. parser.fail("the default namespace may not be set to ".concat(uri, "."));
  60933. break;
  60934. default:
  60935. parser.fail("may not assign the xml namespace to another prefix.");
  60936. }
  60937. break;
  60938. default:
  60939. }
  60940. }
  60941. function nsMappingCheck(parser, mapping) {
  60942. for (var _i = 0, _Object$keys = Object.keys(mapping); _i < _Object$keys.length; _i++) {
  60943. var local = _Object$keys[_i];
  60944. nsPairCheck(parser, local, mapping[local]);
  60945. }
  60946. }
  60947. var isNCName = function isNCName(name) {
  60948. return NC_NAME_RE.test(name);
  60949. };
  60950. var isName = function isName(name) {
  60951. return NAME_RE.test(name);
  60952. };
  60953. var FORBIDDEN_START = 0;
  60954. var FORBIDDEN_BRACKET = 1;
  60955. var FORBIDDEN_BRACKET_BRACKET = 2;
  60956. /**
  60957. * The list of supported events.
  60958. */
  60959. exports.EVENTS = ["xmldecl", "text", "processinginstruction", "doctype", "comment", "opentagstart", "attribute", "opentag", "closetag", "cdata", "error", "end", "ready"];
  60960. var EVENT_NAME_TO_HANDLER_NAME = {
  60961. xmldecl: "xmldeclHandler",
  60962. text: "textHandler",
  60963. processinginstruction: "piHandler",
  60964. doctype: "doctypeHandler",
  60965. comment: "commentHandler",
  60966. opentagstart: "openTagStartHandler",
  60967. attribute: "attributeHandler",
  60968. opentag: "openTagHandler",
  60969. closetag: "closeTagHandler",
  60970. cdata: "cdataHandler",
  60971. error: "errorHandler",
  60972. end: "endHandler",
  60973. ready: "readyHandler"
  60974. };
  60975. var SaxesParser = /*#__PURE__*/function () {
  60976. /**
  60977. * @param opt The parser options.
  60978. */
  60979. function SaxesParser(opt) {
  60980. _classCallCheck(this, SaxesParser);
  60981. this.opt = opt !== null && opt !== void 0 ? opt : {};
  60982. this.fragmentOpt = !!this.opt.fragment;
  60983. var xmlnsOpt = this.xmlnsOpt = !!this.opt.xmlns;
  60984. this.trackPosition = this.opt.position !== false;
  60985. this.fileName = this.opt.fileName;
  60986. if (xmlnsOpt) {
  60987. // This is the function we use to perform name checks on PIs and entities.
  60988. // When namespaces are used, colons are not allowed in PI target names or
  60989. // entity names. So the check depends on whether namespaces are used. See:
  60990. //
  60991. // https://www.w3.org/XML/xml-names-19990114-errata.html
  60992. // NE08
  60993. //
  60994. this.nameStartCheck = isNCNameStartChar;
  60995. this.nameCheck = isNCNameChar;
  60996. this.isName = isNCName; // eslint-disable-next-line @typescript-eslint/unbound-method
  60997. this.processAttribs = this.processAttribsNS; // eslint-disable-next-line @typescript-eslint/unbound-method
  60998. this.pushAttrib = this.pushAttribNS; // eslint-disable-next-line @typescript-eslint/no-explicit-any
  60999. this.ns = Object.assign({
  61000. __proto__: null
  61001. }, rootNS);
  61002. var additional = this.opt.additionalNamespaces;
  61003. if (additional != null) {
  61004. nsMappingCheck(this, additional);
  61005. Object.assign(this.ns, additional);
  61006. }
  61007. } else {
  61008. this.nameStartCheck = isNameStartChar;
  61009. this.nameCheck = isNameChar;
  61010. this.isName = isName; // eslint-disable-next-line @typescript-eslint/unbound-method
  61011. this.processAttribs = this.processAttribsPlain; // eslint-disable-next-line @typescript-eslint/unbound-method
  61012. this.pushAttrib = this.pushAttribPlain;
  61013. } //
  61014. // The order of the members in this table needs to correspond to the state
  61015. // numbers given to the states that correspond to the methods being recorded
  61016. // here.
  61017. //
  61018. this.stateTable = [
  61019. /* eslint-disable @typescript-eslint/unbound-method */
  61020. 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];
  61021. this._init();
  61022. }
  61023. /**
  61024. * Indicates whether or not the parser is closed. If ``true``, wait for
  61025. * the ``ready`` event to write again.
  61026. */
  61027. _createClass(SaxesParser, [{
  61028. key: "_init",
  61029. value: function _init() {
  61030. var _a;
  61031. this.openWakaBang = "";
  61032. this.text = "";
  61033. this.name = "";
  61034. this.piTarget = "";
  61035. this.entity = "";
  61036. this.q = null;
  61037. this.tags = [];
  61038. this.tag = null;
  61039. this.topNS = null;
  61040. this.chunk = "";
  61041. this.chunkPosition = 0;
  61042. this.i = 0;
  61043. this.prevI = 0;
  61044. this.carriedFromPrevious = undefined;
  61045. this.forbiddenState = FORBIDDEN_START;
  61046. this.attribList = []; // The logic is organized so as to minimize the need to check
  61047. // this.opt.fragment while parsing.
  61048. var fragmentOpt = this.fragmentOpt;
  61049. this.state = fragmentOpt ? S_TEXT : S_BEGIN; // We want these to be all true if we are dealing with a fragment.
  61050. this.reportedTextBeforeRoot = this.reportedTextAfterRoot = this.closedRoot = this.sawRoot = fragmentOpt; // An XML declaration is intially possible only when parsing whole
  61051. // documents.
  61052. this.xmlDeclPossible = !fragmentOpt;
  61053. this.xmlDeclExpects = ["version"];
  61054. this.entityReturnState = undefined;
  61055. var defaultXMLVersion = this.opt.defaultXMLVersion;
  61056. if (defaultXMLVersion === undefined) {
  61057. if (this.opt.forceXMLVersion === true) {
  61058. throw new Error("forceXMLVersion set but defaultXMLVersion is not set");
  61059. }
  61060. defaultXMLVersion = "1.0";
  61061. }
  61062. this.setXMLVersion(defaultXMLVersion);
  61063. this.positionAtNewLine = 0;
  61064. this.doctype = false;
  61065. this._closed = false;
  61066. this.xmlDecl = {
  61067. version: undefined,
  61068. encoding: undefined,
  61069. standalone: undefined
  61070. };
  61071. this.line = 1;
  61072. this.column = 0;
  61073. this.ENTITIES = Object.create(XML_ENTITIES); // eslint-disable-next-line no-unused-expressions
  61074. (_a = this.readyHandler) === null || _a === void 0 ? void 0 : _a.call(this);
  61075. }
  61076. /**
  61077. * The stream position the parser is currently looking at. This field is
  61078. * zero-based.
  61079. *
  61080. * This field is not based on counting Unicode characters but is to be
  61081. * interpreted as a plain index into a JavaScript string.
  61082. */
  61083. }, {
  61084. key: "on",
  61085. /**
  61086. * Set an event listener on an event. The parser supports one handler per
  61087. * event type. If you try to set an event handler over an existing handler,
  61088. * the old handler is silently overwritten.
  61089. *
  61090. * @param name The event to listen to.
  61091. *
  61092. * @param handler The handler to set.
  61093. */
  61094. value: function on(name, handler) {
  61095. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  61096. this[EVENT_NAME_TO_HANDLER_NAME[name]] = handler;
  61097. }
  61098. /**
  61099. * Unset an event handler.
  61100. *
  61101. * @parma name The event to stop listening to.
  61102. */
  61103. }, {
  61104. key: "off",
  61105. value: function off(name) {
  61106. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  61107. this[EVENT_NAME_TO_HANDLER_NAME[name]] = undefined;
  61108. }
  61109. /**
  61110. * Make an error object. The error object will have a message that contains
  61111. * the ``fileName`` option passed at the creation of the parser. If position
  61112. * tracking was turned on, it will also have line and column number
  61113. * information.
  61114. *
  61115. * @param message The message describing the error to report.
  61116. *
  61117. * @returns An error object with a properly formatted message.
  61118. */
  61119. }, {
  61120. key: "makeError",
  61121. value: function makeError(message) {
  61122. var _a;
  61123. var msg = (_a = this.fileName) !== null && _a !== void 0 ? _a : "";
  61124. if (this.trackPosition) {
  61125. if (msg.length > 0) {
  61126. msg += ":";
  61127. }
  61128. msg += "".concat(this.line, ":").concat(this.column);
  61129. }
  61130. if (msg.length > 0) {
  61131. msg += ": ";
  61132. }
  61133. return new Error(msg + message);
  61134. }
  61135. /**
  61136. * Report a parsing error. This method is made public so that client code may
  61137. * check for issues that are outside the scope of this project and can report
  61138. * errors.
  61139. *
  61140. * @param message The error to report.
  61141. *
  61142. * @returns this
  61143. */
  61144. }, {
  61145. key: "fail",
  61146. value: function fail(message) {
  61147. var err = this.makeError(message);
  61148. var handler = this.errorHandler;
  61149. if (handler === undefined) {
  61150. throw err;
  61151. } else {
  61152. handler(err);
  61153. }
  61154. return this;
  61155. }
  61156. /**
  61157. * Write a XML data to the parser.
  61158. *
  61159. * @param chunk The XML data to write.
  61160. *
  61161. * @returns this
  61162. */
  61163. }, {
  61164. key: "write",
  61165. value: function write(chunk) {
  61166. if (this.closed) {
  61167. return this.fail("cannot write after close; assign an onready handler.");
  61168. }
  61169. var end = false;
  61170. if (chunk === null) {
  61171. // We cannot return immediately because carriedFromPrevious may need
  61172. // processing.
  61173. end = true;
  61174. chunk = "";
  61175. } else if (_typeof(chunk) === "object") {
  61176. chunk = chunk.toString();
  61177. } // We checked if performing a pre-decomposition of the string into an array
  61178. // of single complete characters (``Array.from(chunk)``) would be faster
  61179. // than the current repeated calls to ``charCodeAt``. As of August 2018, it
  61180. // isn't. (There may be Node-specific code that would perform faster than
  61181. // ``Array.from`` but don't want to be dependent on Node.)
  61182. if (this.carriedFromPrevious !== undefined) {
  61183. // The previous chunk had char we must carry over.
  61184. chunk = "".concat(this.carriedFromPrevious).concat(chunk);
  61185. this.carriedFromPrevious = undefined;
  61186. }
  61187. var limit = chunk.length;
  61188. var lastCode = chunk.charCodeAt(limit - 1);
  61189. if (!end && ( // A trailing CR or surrogate must be carried over to the next
  61190. // chunk.
  61191. lastCode === CR || lastCode >= 0xD800 && lastCode <= 0xDBFF)) {
  61192. // The chunk ends with a character that must be carried over. We cannot
  61193. // know how to handle it until we get the next chunk or the end of the
  61194. // stream. So save it for later.
  61195. this.carriedFromPrevious = chunk[limit - 1];
  61196. limit--;
  61197. chunk = chunk.slice(0, limit);
  61198. }
  61199. var stateTable = this.stateTable;
  61200. this.chunk = chunk;
  61201. this.i = 0;
  61202. while (this.i < limit) {
  61203. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  61204. stateTable[this.state].call(this);
  61205. }
  61206. this.chunkPosition += limit;
  61207. return end ? this.end() : this;
  61208. }
  61209. /**
  61210. * Close the current stream. Perform final well-formedness checks and reset
  61211. * the parser tstate.
  61212. *
  61213. * @returns this
  61214. */
  61215. }, {
  61216. key: "close",
  61217. value: function close() {
  61218. return this.write(null);
  61219. }
  61220. /**
  61221. * Get a single code point out of the current chunk. This updates the current
  61222. * position if we do position tracking.
  61223. *
  61224. * This is the algorithm to use for XML 1.0.
  61225. *
  61226. * @returns The character read.
  61227. */
  61228. }, {
  61229. key: "getCode10",
  61230. value: function getCode10() {
  61231. var chunk = this.chunk,
  61232. i = this.i;
  61233. this.prevI = i; // Yes, we do this instead of doing this.i++. Doing it this way, we do not
  61234. // read this.i again, which is a bit faster.
  61235. this.i = i + 1;
  61236. if (i >= chunk.length) {
  61237. return EOC;
  61238. } // Using charCodeAt and handling the surrogates ourselves is faster
  61239. // than using codePointAt.
  61240. var code = chunk.charCodeAt(i);
  61241. this.column++;
  61242. if (code < 0xD800) {
  61243. if (code >= SPACE || code === TAB) {
  61244. return code;
  61245. }
  61246. switch (code) {
  61247. case NL:
  61248. this.line++;
  61249. this.column = 0;
  61250. this.positionAtNewLine = this.position;
  61251. return NL;
  61252. case CR:
  61253. // We may get NaN if we read past the end of the chunk, which is fine.
  61254. if (chunk.charCodeAt(i + 1) === NL) {
  61255. // A \r\n sequence is converted to \n so we have to skip over the
  61256. // next character. We already know it has a size of 1 so ++ is fine
  61257. // here.
  61258. this.i = i + 2;
  61259. } // Otherwise, a \r is just converted to \n, so we don't have to skip
  61260. // ahead.
  61261. // In either case, \r becomes \n.
  61262. this.line++;
  61263. this.column = 0;
  61264. this.positionAtNewLine = this.position;
  61265. return NL_LIKE;
  61266. default:
  61267. // If we get here, then code < SPACE and it is not NL CR or TAB.
  61268. this.fail("disallowed character.");
  61269. return code;
  61270. }
  61271. }
  61272. if (code > 0xDBFF) {
  61273. // This is a specialized version of isChar10 that takes into account
  61274. // that in this context code > 0xDBFF and code <= 0xFFFF. So it does not
  61275. // test cases that don't need testing.
  61276. if (!(code >= 0xE000 && code <= 0xFFFD)) {
  61277. this.fail("disallowed character.");
  61278. }
  61279. return code;
  61280. }
  61281. var final = 0x10000 + (code - 0xD800) * 0x400 + (chunk.charCodeAt(i + 1) - 0xDC00);
  61282. this.i = i + 2; // This is a specialized version of isChar10 that takes into account that in
  61283. // this context necessarily final >= 0x10000.
  61284. if (final > 0x10FFFF) {
  61285. this.fail("disallowed character.");
  61286. }
  61287. return final;
  61288. }
  61289. /**
  61290. * Get a single code point out of the current chunk. This updates the current
  61291. * position if we do position tracking.
  61292. *
  61293. * This is the algorithm to use for XML 1.1.
  61294. *
  61295. * @returns {number} The character read.
  61296. */
  61297. }, {
  61298. key: "getCode11",
  61299. value: function getCode11() {
  61300. var chunk = this.chunk,
  61301. i = this.i;
  61302. this.prevI = i; // Yes, we do this instead of doing this.i++. Doing it this way, we do not
  61303. // read this.i again, which is a bit faster.
  61304. this.i = i + 1;
  61305. if (i >= chunk.length) {
  61306. return EOC;
  61307. } // Using charCodeAt and handling the surrogates ourselves is faster
  61308. // than using codePointAt.
  61309. var code = chunk.charCodeAt(i);
  61310. this.column++;
  61311. if (code < 0xD800) {
  61312. if (code > 0x1F && code < 0x7F || code > 0x9F && code !== LS || code === TAB) {
  61313. return code;
  61314. }
  61315. switch (code) {
  61316. case NL:
  61317. // 0xA
  61318. this.line++;
  61319. this.column = 0;
  61320. this.positionAtNewLine = this.position;
  61321. return NL;
  61322. case CR:
  61323. {
  61324. // 0xD
  61325. // We may get NaN if we read past the end of the chunk, which is
  61326. // fine.
  61327. var next = chunk.charCodeAt(i + 1);
  61328. if (next === NL || next === NEL) {
  61329. // A CR NL or CR NEL sequence is converted to NL so we have to skip
  61330. // over the next character. We already know it has a size of 1.
  61331. this.i = i + 2;
  61332. } // Otherwise, a CR is just converted to NL, no skip.
  61333. }
  61334. /* yes, fall through */
  61335. case NEL: // 0x85
  61336. case LS:
  61337. // Ox2028
  61338. this.line++;
  61339. this.column = 0;
  61340. this.positionAtNewLine = this.position;
  61341. return NL_LIKE;
  61342. default:
  61343. this.fail("disallowed character.");
  61344. return code;
  61345. }
  61346. }
  61347. if (code > 0xDBFF) {
  61348. // This is a specialized version of isCharAndNotRestricted that takes into
  61349. // account that in this context code > 0xDBFF and code <= 0xFFFF. So it
  61350. // does not test cases that don't need testing.
  61351. if (!(code >= 0xE000 && code <= 0xFFFD)) {
  61352. this.fail("disallowed character.");
  61353. }
  61354. return code;
  61355. }
  61356. var final = 0x10000 + (code - 0xD800) * 0x400 + (chunk.charCodeAt(i + 1) - 0xDC00);
  61357. this.i = i + 2; // This is a specialized version of isCharAndNotRestricted that takes into
  61358. // account that in this context necessarily final >= 0x10000.
  61359. if (final > 0x10FFFF) {
  61360. this.fail("disallowed character.");
  61361. }
  61362. return final;
  61363. }
  61364. /**
  61365. * Like ``getCode`` but with the return value normalized so that ``NL`` is
  61366. * returned for ``NL_LIKE``.
  61367. */
  61368. }, {
  61369. key: "getCodeNorm",
  61370. value: function getCodeNorm() {
  61371. var c = this.getCode();
  61372. return c === NL_LIKE ? NL : c;
  61373. }
  61374. }, {
  61375. key: "unget",
  61376. value: function unget() {
  61377. this.i = this.prevI;
  61378. this.column--;
  61379. }
  61380. /**
  61381. * Capture characters into a buffer until encountering one of a set of
  61382. * characters.
  61383. *
  61384. * @param chars An array of codepoints. Encountering a character in the array
  61385. * ends the capture. (``chars`` may safely contain ``NL``.)
  61386. *
  61387. * @return The character code that made the capture end, or ``EOC`` if we hit
  61388. * the end of the chunk. The return value cannot be NL_LIKE: NL is returned
  61389. * instead.
  61390. */
  61391. }, {
  61392. key: "captureTo",
  61393. value: function captureTo(chars) {
  61394. var start = this.i;
  61395. var chunk = this.chunk; // eslint-disable-next-line no-constant-condition
  61396. while (true) {
  61397. var c = this.getCode();
  61398. var isNLLike = c === NL_LIKE;
  61399. var final = isNLLike ? NL : c;
  61400. if (final === EOC || chars.includes(final)) {
  61401. this.text += chunk.slice(start, this.prevI);
  61402. return final;
  61403. }
  61404. if (isNLLike) {
  61405. this.text += "".concat(chunk.slice(start, this.prevI), "\n");
  61406. start = this.i;
  61407. }
  61408. }
  61409. }
  61410. /**
  61411. * Capture characters into a buffer until encountering a character.
  61412. *
  61413. * @param char The codepoint that ends the capture. **NOTE ``char`` MAY NOT
  61414. * CONTAIN ``NL``.** Passing ``NL`` will result in buggy behavior.
  61415. *
  61416. * @return ``true`` if we ran into the character. Otherwise, we ran into the
  61417. * end of the current chunk.
  61418. */
  61419. }, {
  61420. key: "captureToChar",
  61421. value: function captureToChar(char) {
  61422. var start = this.i;
  61423. var chunk = this.chunk; // eslint-disable-next-line no-constant-condition
  61424. while (true) {
  61425. var c = this.getCode();
  61426. switch (c) {
  61427. case NL_LIKE:
  61428. this.text += "".concat(chunk.slice(start, this.prevI), "\n");
  61429. start = this.i;
  61430. c = NL;
  61431. break;
  61432. case EOC:
  61433. this.text += chunk.slice(start);
  61434. return false;
  61435. default:
  61436. }
  61437. if (c === char) {
  61438. this.text += chunk.slice(start, this.prevI);
  61439. return true;
  61440. }
  61441. }
  61442. }
  61443. /**
  61444. * Capture characters that satisfy ``isNameChar`` into the ``name`` field of
  61445. * this parser.
  61446. *
  61447. * @return The character code that made the test fail, or ``EOC`` if we hit
  61448. * the end of the chunk. The return value cannot be NL_LIKE: NL is returned
  61449. * instead.
  61450. */
  61451. }, {
  61452. key: "captureNameChars",
  61453. value: function captureNameChars() {
  61454. var chunk = this.chunk,
  61455. start = this.i; // eslint-disable-next-line no-constant-condition
  61456. while (true) {
  61457. var c = this.getCode();
  61458. if (c === EOC) {
  61459. this.name += chunk.slice(start);
  61460. return EOC;
  61461. } // NL is not a name char so we don't have to test specifically for it.
  61462. if (!isNameChar(c)) {
  61463. this.name += chunk.slice(start, this.prevI);
  61464. return c === NL_LIKE ? NL : c;
  61465. }
  61466. }
  61467. }
  61468. /**
  61469. * Skip white spaces.
  61470. *
  61471. * @return The character that ended the skip, or ``EOC`` if we hit
  61472. * the end of the chunk. The return value cannot be NL_LIKE: NL is returned
  61473. * instead.
  61474. */
  61475. }, {
  61476. key: "skipSpaces",
  61477. value: function skipSpaces() {
  61478. // eslint-disable-next-line no-constant-condition
  61479. while (true) {
  61480. var c = this.getCodeNorm();
  61481. if (c === EOC || !isS(c)) {
  61482. return c;
  61483. }
  61484. }
  61485. }
  61486. }, {
  61487. key: "setXMLVersion",
  61488. value: function setXMLVersion(version) {
  61489. this.currentXMLVersion = version;
  61490. /* eslint-disable @typescript-eslint/unbound-method */
  61491. if (version === "1.0") {
  61492. this.isChar = isChar10;
  61493. this.getCode = this.getCode10;
  61494. } else {
  61495. this.isChar = isChar11;
  61496. this.getCode = this.getCode11;
  61497. }
  61498. /* eslint-enable @typescript-eslint/unbound-method */
  61499. } // STATE ENGINE METHODS
  61500. // This needs to be a state separate from S_BEGIN_WHITESPACE because we want
  61501. // to be sure never to come back to this state later.
  61502. }, {
  61503. key: "sBegin",
  61504. value: function sBegin() {
  61505. // We are essentially peeking at the first character of the chunk. Since
  61506. // S_BEGIN can be in effect only when we start working on the first chunk,
  61507. // the index at which we must look is necessarily 0. Note also that the
  61508. // following test does not depend on decoding surrogates.
  61509. // If the initial character is 0xFEFF, ignore it.
  61510. if (this.chunk.charCodeAt(0) === 0xFEFF) {
  61511. this.i++;
  61512. this.column++;
  61513. }
  61514. this.state = S_BEGIN_WHITESPACE;
  61515. }
  61516. }, {
  61517. key: "sBeginWhitespace",
  61518. value: function sBeginWhitespace() {
  61519. // We need to know whether we've encountered spaces or not because as soon
  61520. // as we run into a space, an XML declaration is no longer possible. Rather
  61521. // than slow down skipSpaces even in places where we don't care whether it
  61522. // skipped anything or not, we check whether prevI is equal to the value of
  61523. // i from before we skip spaces.
  61524. var iBefore = this.i;
  61525. var c = this.skipSpaces();
  61526. if (this.prevI !== iBefore) {
  61527. this.xmlDeclPossible = false;
  61528. }
  61529. switch (c) {
  61530. case LESS:
  61531. this.state = S_OPEN_WAKA; // We could naively call closeText but in this state, it is not normal
  61532. // to have text be filled with any data.
  61533. if (this.text.length !== 0) {
  61534. throw new Error("no-empty text at start");
  61535. }
  61536. break;
  61537. case EOC:
  61538. break;
  61539. default:
  61540. this.unget();
  61541. this.state = S_TEXT;
  61542. this.xmlDeclPossible = false;
  61543. }
  61544. }
  61545. }, {
  61546. key: "sDoctype",
  61547. value: function sDoctype() {
  61548. var _a;
  61549. var c = this.captureTo(DOCTYPE_TERMINATOR);
  61550. switch (c) {
  61551. case GREATER:
  61552. {
  61553. // eslint-disable-next-line no-unused-expressions
  61554. (_a = this.doctypeHandler) === null || _a === void 0 ? void 0 : _a.call(this, this.text);
  61555. this.text = "";
  61556. this.state = S_TEXT;
  61557. this.doctype = true; // just remember that we saw it.
  61558. break;
  61559. }
  61560. case EOC:
  61561. break;
  61562. default:
  61563. this.text += String.fromCodePoint(c);
  61564. if (c === OPEN_BRACKET) {
  61565. this.state = S_DTD;
  61566. } else if (isQuote(c)) {
  61567. this.state = S_DOCTYPE_QUOTE;
  61568. this.q = c;
  61569. }
  61570. }
  61571. }
  61572. }, {
  61573. key: "sDoctypeQuote",
  61574. value: function sDoctypeQuote() {
  61575. var q = this.q;
  61576. if (this.captureToChar(q)) {
  61577. this.text += String.fromCodePoint(q);
  61578. this.q = null;
  61579. this.state = S_DOCTYPE;
  61580. }
  61581. }
  61582. }, {
  61583. key: "sDTD",
  61584. value: function sDTD() {
  61585. var c = this.captureTo(DTD_TERMINATOR);
  61586. if (c === EOC) {
  61587. return;
  61588. }
  61589. this.text += String.fromCodePoint(c);
  61590. if (c === CLOSE_BRACKET) {
  61591. this.state = S_DOCTYPE;
  61592. } else if (c === LESS) {
  61593. this.state = S_DTD_OPEN_WAKA;
  61594. } else if (isQuote(c)) {
  61595. this.state = S_DTD_QUOTED;
  61596. this.q = c;
  61597. }
  61598. }
  61599. }, {
  61600. key: "sDTDQuoted",
  61601. value: function sDTDQuoted() {
  61602. var q = this.q;
  61603. if (this.captureToChar(q)) {
  61604. this.text += String.fromCodePoint(q);
  61605. this.state = S_DTD;
  61606. this.q = null;
  61607. }
  61608. }
  61609. }, {
  61610. key: "sDTDOpenWaka",
  61611. value: function sDTDOpenWaka() {
  61612. var c = this.getCodeNorm();
  61613. this.text += String.fromCodePoint(c);
  61614. switch (c) {
  61615. case BANG:
  61616. this.state = S_DTD_OPEN_WAKA_BANG;
  61617. this.openWakaBang = "";
  61618. break;
  61619. case QUESTION:
  61620. this.state = S_DTD_PI;
  61621. break;
  61622. default:
  61623. this.state = S_DTD;
  61624. }
  61625. }
  61626. }, {
  61627. key: "sDTDOpenWakaBang",
  61628. value: function sDTDOpenWakaBang() {
  61629. var char = String.fromCodePoint(this.getCodeNorm());
  61630. var owb = this.openWakaBang += char;
  61631. this.text += char;
  61632. if (owb !== "-") {
  61633. this.state = owb === "--" ? S_DTD_COMMENT : S_DTD;
  61634. this.openWakaBang = "";
  61635. }
  61636. }
  61637. }, {
  61638. key: "sDTDComment",
  61639. value: function sDTDComment() {
  61640. if (this.captureToChar(MINUS)) {
  61641. this.text += "-";
  61642. this.state = S_DTD_COMMENT_ENDING;
  61643. }
  61644. }
  61645. }, {
  61646. key: "sDTDCommentEnding",
  61647. value: function sDTDCommentEnding() {
  61648. var c = this.getCodeNorm();
  61649. this.text += String.fromCodePoint(c);
  61650. this.state = c === MINUS ? S_DTD_COMMENT_ENDED : S_DTD_COMMENT;
  61651. }
  61652. }, {
  61653. key: "sDTDCommentEnded",
  61654. value: function sDTDCommentEnded() {
  61655. var c = this.getCodeNorm();
  61656. this.text += String.fromCodePoint(c);
  61657. if (c === GREATER) {
  61658. this.state = S_DTD;
  61659. } else {
  61660. this.fail("malformed comment."); // <!-- blah -- bloo --> will be recorded as
  61661. // a comment of " blah -- bloo "
  61662. this.state = S_DTD_COMMENT;
  61663. }
  61664. }
  61665. }, {
  61666. key: "sDTDPI",
  61667. value: function sDTDPI() {
  61668. if (this.captureToChar(QUESTION)) {
  61669. this.text += "?";
  61670. this.state = S_DTD_PI_ENDING;
  61671. }
  61672. }
  61673. }, {
  61674. key: "sDTDPIEnding",
  61675. value: function sDTDPIEnding() {
  61676. var c = this.getCodeNorm();
  61677. this.text += String.fromCodePoint(c);
  61678. if (c === GREATER) {
  61679. this.state = S_DTD;
  61680. }
  61681. }
  61682. }, {
  61683. key: "sText",
  61684. value: function sText() {
  61685. //
  61686. // We did try a version of saxes where the S_TEXT state was split in two
  61687. // states: one for text inside the root element, and one for text
  61688. // outside. This was avoiding having to test this.tags.length to decide
  61689. // what implementation to actually use.
  61690. //
  61691. // Peformance testing on gigabyte-size files did not show any advantage to
  61692. // using the two states solution instead of the current one. Conversely, it
  61693. // made the code a bit more complicated elsewhere. For instance, a comment
  61694. // can appear before the root element so when a comment ended it was
  61695. // necessary to determine whether to return to the S_TEXT state or to the
  61696. // new text-outside-root state.
  61697. //
  61698. if (this.tags.length !== 0) {
  61699. this.handleTextInRoot();
  61700. } else {
  61701. this.handleTextOutsideRoot();
  61702. }
  61703. }
  61704. }, {
  61705. key: "sEntity",
  61706. value: function sEntity() {
  61707. // This is essentially a specialized version of captureToChar(SEMICOLON...)
  61708. var start = this.i;
  61709. var chunk = this.chunk; // eslint-disable-next-line no-labels, no-restricted-syntax
  61710. loop: // eslint-disable-next-line no-constant-condition
  61711. while (true) {
  61712. switch (this.getCode()) {
  61713. case NL_LIKE:
  61714. this.entity += "".concat(chunk.slice(start, this.prevI), "\n");
  61715. start = this.i;
  61716. break;
  61717. case SEMICOLON:
  61718. {
  61719. var entityReturnState = this.entityReturnState;
  61720. var entity = this.entity + chunk.slice(start, this.prevI);
  61721. this.state = entityReturnState;
  61722. var parsed = void 0;
  61723. if (entity === "") {
  61724. this.fail("empty entity name.");
  61725. parsed = "&;";
  61726. } else {
  61727. parsed = this.parseEntity(entity);
  61728. this.entity = "";
  61729. }
  61730. if (entityReturnState !== S_TEXT || this.textHandler !== undefined) {
  61731. this.text += parsed;
  61732. } // eslint-disable-next-line no-labels
  61733. break loop;
  61734. }
  61735. case EOC:
  61736. this.entity += chunk.slice(start); // eslint-disable-next-line no-labels
  61737. break loop;
  61738. default:
  61739. }
  61740. }
  61741. }
  61742. }, {
  61743. key: "sOpenWaka",
  61744. value: function sOpenWaka() {
  61745. // Reminder: a state handler is called with at least one character
  61746. // available in the current chunk. So the first call to get code inside of
  61747. // a state handler cannot return ``EOC``. That's why we don't test
  61748. // for it.
  61749. var c = this.getCode(); // either a /, ?, !, or text is coming next.
  61750. if (isNameStartChar(c)) {
  61751. this.state = S_OPEN_TAG;
  61752. this.unget();
  61753. this.xmlDeclPossible = false;
  61754. } else {
  61755. switch (c) {
  61756. case FORWARD_SLASH:
  61757. this.state = S_CLOSE_TAG;
  61758. this.xmlDeclPossible = false;
  61759. break;
  61760. case BANG:
  61761. this.state = S_OPEN_WAKA_BANG;
  61762. this.openWakaBang = "";
  61763. this.xmlDeclPossible = false;
  61764. break;
  61765. case QUESTION:
  61766. this.state = S_PI_FIRST_CHAR;
  61767. break;
  61768. default:
  61769. this.fail("disallowed character in tag name");
  61770. this.state = S_TEXT;
  61771. this.xmlDeclPossible = false;
  61772. }
  61773. }
  61774. }
  61775. }, {
  61776. key: "sOpenWakaBang",
  61777. value: function sOpenWakaBang() {
  61778. this.openWakaBang += String.fromCodePoint(this.getCodeNorm());
  61779. switch (this.openWakaBang) {
  61780. case "[CDATA[":
  61781. if (!this.sawRoot && !this.reportedTextBeforeRoot) {
  61782. this.fail("text data outside of root node.");
  61783. this.reportedTextBeforeRoot = true;
  61784. }
  61785. if (this.closedRoot && !this.reportedTextAfterRoot) {
  61786. this.fail("text data outside of root node.");
  61787. this.reportedTextAfterRoot = true;
  61788. }
  61789. this.state = S_CDATA;
  61790. this.openWakaBang = "";
  61791. break;
  61792. case "--":
  61793. this.state = S_COMMENT;
  61794. this.openWakaBang = "";
  61795. break;
  61796. case "DOCTYPE":
  61797. this.state = S_DOCTYPE;
  61798. if (this.doctype || this.sawRoot) {
  61799. this.fail("inappropriately located doctype declaration.");
  61800. }
  61801. this.openWakaBang = "";
  61802. break;
  61803. default:
  61804. // 7 happens to be the maximum length of the string that can possibly
  61805. // match one of the cases above.
  61806. if (this.openWakaBang.length >= 7) {
  61807. this.fail("incorrect syntax.");
  61808. }
  61809. }
  61810. }
  61811. }, {
  61812. key: "sComment",
  61813. value: function sComment() {
  61814. if (this.captureToChar(MINUS)) {
  61815. this.state = S_COMMENT_ENDING;
  61816. }
  61817. }
  61818. }, {
  61819. key: "sCommentEnding",
  61820. value: function sCommentEnding() {
  61821. var _a;
  61822. var c = this.getCodeNorm();
  61823. if (c === MINUS) {
  61824. this.state = S_COMMENT_ENDED; // eslint-disable-next-line no-unused-expressions
  61825. (_a = this.commentHandler) === null || _a === void 0 ? void 0 : _a.call(this, this.text);
  61826. this.text = "";
  61827. } else {
  61828. this.text += "-".concat(String.fromCodePoint(c));
  61829. this.state = S_COMMENT;
  61830. }
  61831. }
  61832. }, {
  61833. key: "sCommentEnded",
  61834. value: function sCommentEnded() {
  61835. var c = this.getCodeNorm();
  61836. if (c !== GREATER) {
  61837. this.fail("malformed comment."); // <!-- blah -- bloo --> will be recorded as
  61838. // a comment of " blah -- bloo "
  61839. this.text += "--".concat(String.fromCodePoint(c));
  61840. this.state = S_COMMENT;
  61841. } else {
  61842. this.state = S_TEXT;
  61843. }
  61844. }
  61845. }, {
  61846. key: "sCData",
  61847. value: function sCData() {
  61848. if (this.captureToChar(CLOSE_BRACKET)) {
  61849. this.state = S_CDATA_ENDING;
  61850. }
  61851. }
  61852. }, {
  61853. key: "sCDataEnding",
  61854. value: function sCDataEnding() {
  61855. var c = this.getCodeNorm();
  61856. if (c === CLOSE_BRACKET) {
  61857. this.state = S_CDATA_ENDING_2;
  61858. } else {
  61859. this.text += "]".concat(String.fromCodePoint(c));
  61860. this.state = S_CDATA;
  61861. }
  61862. }
  61863. }, {
  61864. key: "sCDataEnding2",
  61865. value: function sCDataEnding2() {
  61866. var _a;
  61867. var c = this.getCodeNorm();
  61868. switch (c) {
  61869. case GREATER:
  61870. {
  61871. // eslint-disable-next-line no-unused-expressions
  61872. (_a = this.cdataHandler) === null || _a === void 0 ? void 0 : _a.call(this, this.text);
  61873. this.text = "";
  61874. this.state = S_TEXT;
  61875. break;
  61876. }
  61877. case CLOSE_BRACKET:
  61878. this.text += "]";
  61879. break;
  61880. default:
  61881. this.text += "]]".concat(String.fromCodePoint(c));
  61882. this.state = S_CDATA;
  61883. }
  61884. } // We need this separate state to check the first character fo the pi target
  61885. // with this.nameStartCheck which allows less characters than this.nameCheck.
  61886. }, {
  61887. key: "sPIFirstChar",
  61888. value: function sPIFirstChar() {
  61889. var c = this.getCodeNorm(); // This is first because in the case where the file is well-formed this is
  61890. // the branch taken. We optimize for well-formedness.
  61891. if (this.nameStartCheck(c)) {
  61892. this.piTarget += String.fromCodePoint(c);
  61893. this.state = S_PI_REST;
  61894. } else if (c === QUESTION || isS(c)) {
  61895. this.fail("processing instruction without a target.");
  61896. this.state = c === QUESTION ? S_PI_ENDING : S_PI_BODY;
  61897. } else {
  61898. this.fail("disallowed character in processing instruction name.");
  61899. this.piTarget += String.fromCodePoint(c);
  61900. this.state = S_PI_REST;
  61901. }
  61902. }
  61903. }, {
  61904. key: "sPIRest",
  61905. value: function sPIRest() {
  61906. // Capture characters into a piTarget while ``this.nameCheck`` run on the
  61907. // character read returns true.
  61908. var chunk = this.chunk,
  61909. start = this.i; // eslint-disable-next-line no-constant-condition
  61910. while (true) {
  61911. var c = this.getCodeNorm();
  61912. if (c === EOC) {
  61913. this.piTarget += chunk.slice(start);
  61914. return;
  61915. } // NL cannot satisfy this.nameCheck so we don't have to test specifically
  61916. // for it.
  61917. if (!this.nameCheck(c)) {
  61918. this.piTarget += chunk.slice(start, this.prevI);
  61919. var isQuestion = c === QUESTION;
  61920. if (isQuestion || isS(c)) {
  61921. if (this.piTarget === "xml") {
  61922. if (!this.xmlDeclPossible) {
  61923. this.fail("an XML declaration must be at the start of the document.");
  61924. }
  61925. this.state = isQuestion ? S_XML_DECL_ENDING : S_XML_DECL_NAME_START;
  61926. } else {
  61927. this.state = isQuestion ? S_PI_ENDING : S_PI_BODY;
  61928. }
  61929. } else {
  61930. this.fail("disallowed character in processing instruction name.");
  61931. this.piTarget += String.fromCodePoint(c);
  61932. }
  61933. break;
  61934. }
  61935. }
  61936. }
  61937. }, {
  61938. key: "sPIBody",
  61939. value: function sPIBody() {
  61940. if (this.text.length === 0) {
  61941. var c = this.getCodeNorm();
  61942. if (c === QUESTION) {
  61943. this.state = S_PI_ENDING;
  61944. } else if (!isS(c)) {
  61945. this.text = String.fromCodePoint(c);
  61946. }
  61947. } // The question mark character is not valid inside any of the XML
  61948. // declaration name/value pairs.
  61949. else if (this.captureToChar(QUESTION)) {
  61950. this.state = S_PI_ENDING;
  61951. }
  61952. }
  61953. }, {
  61954. key: "sPIEnding",
  61955. value: function sPIEnding() {
  61956. var _a;
  61957. var c = this.getCodeNorm();
  61958. if (c === GREATER) {
  61959. var piTarget = this.piTarget;
  61960. if (piTarget.toLowerCase() === "xml") {
  61961. this.fail("the XML declaration must appear at the start of the document.");
  61962. } // eslint-disable-next-line no-unused-expressions
  61963. (_a = this.piHandler) === null || _a === void 0 ? void 0 : _a.call(this, {
  61964. target: piTarget,
  61965. body: this.text
  61966. });
  61967. this.piTarget = this.text = "";
  61968. this.state = S_TEXT;
  61969. } else if (c === QUESTION) {
  61970. // We ran into ?? as part of a processing instruction. We initially took
  61971. // the first ? as a sign that the PI was ending, but it is not. So we have
  61972. // to add it to the body but we take the new ? as a sign that the PI is
  61973. // ending.
  61974. this.text += "?";
  61975. } else {
  61976. this.text += "?".concat(String.fromCodePoint(c));
  61977. this.state = S_PI_BODY;
  61978. }
  61979. this.xmlDeclPossible = false;
  61980. }
  61981. }, {
  61982. key: "sXMLDeclNameStart",
  61983. value: function sXMLDeclNameStart() {
  61984. var c = this.skipSpaces(); // The question mark character is not valid inside any of the XML
  61985. // declaration name/value pairs.
  61986. if (c === QUESTION) {
  61987. // It is valid to go to S_XML_DECL_ENDING from this state.
  61988. this.state = S_XML_DECL_ENDING;
  61989. return;
  61990. }
  61991. if (c !== EOC) {
  61992. this.state = S_XML_DECL_NAME;
  61993. this.name = String.fromCodePoint(c);
  61994. }
  61995. }
  61996. }, {
  61997. key: "sXMLDeclName",
  61998. value: function sXMLDeclName() {
  61999. var c = this.captureTo(XML_DECL_NAME_TERMINATOR); // The question mark character is not valid inside any of the XML
  62000. // declaration name/value pairs.
  62001. if (c === QUESTION) {
  62002. this.state = S_XML_DECL_ENDING;
  62003. this.name += this.text;
  62004. this.text = "";
  62005. this.fail("XML declaration is incomplete.");
  62006. return;
  62007. }
  62008. if (!(isS(c) || c === EQUAL)) {
  62009. return;
  62010. }
  62011. this.name += this.text;
  62012. this.text = "";
  62013. if (!this.xmlDeclExpects.includes(this.name)) {
  62014. switch (this.name.length) {
  62015. case 0:
  62016. this.fail("did not expect any more name/value pairs.");
  62017. break;
  62018. case 1:
  62019. this.fail("expected the name ".concat(this.xmlDeclExpects[0], "."));
  62020. break;
  62021. default:
  62022. this.fail("expected one of ".concat(this.xmlDeclExpects.join(", ")));
  62023. }
  62024. }
  62025. this.state = c === EQUAL ? S_XML_DECL_VALUE_START : S_XML_DECL_EQ;
  62026. }
  62027. }, {
  62028. key: "sXMLDeclEq",
  62029. value: function sXMLDeclEq() {
  62030. var c = this.getCodeNorm(); // The question mark character is not valid inside any of the XML
  62031. // declaration name/value pairs.
  62032. if (c === QUESTION) {
  62033. this.state = S_XML_DECL_ENDING;
  62034. this.fail("XML declaration is incomplete.");
  62035. return;
  62036. }
  62037. if (isS(c)) {
  62038. return;
  62039. }
  62040. if (c !== EQUAL) {
  62041. this.fail("value required.");
  62042. }
  62043. this.state = S_XML_DECL_VALUE_START;
  62044. }
  62045. }, {
  62046. key: "sXMLDeclValueStart",
  62047. value: function sXMLDeclValueStart() {
  62048. var c = this.getCodeNorm(); // The question mark character is not valid inside any of the XML
  62049. // declaration name/value pairs.
  62050. if (c === QUESTION) {
  62051. this.state = S_XML_DECL_ENDING;
  62052. this.fail("XML declaration is incomplete.");
  62053. return;
  62054. }
  62055. if (isS(c)) {
  62056. return;
  62057. }
  62058. if (!isQuote(c)) {
  62059. this.fail("value must be quoted.");
  62060. this.q = SPACE;
  62061. } else {
  62062. this.q = c;
  62063. }
  62064. this.state = S_XML_DECL_VALUE;
  62065. }
  62066. }, {
  62067. key: "sXMLDeclValue",
  62068. value: function sXMLDeclValue() {
  62069. var c = this.captureTo([this.q, QUESTION]); // The question mark character is not valid inside any of the XML
  62070. // declaration name/value pairs.
  62071. if (c === QUESTION) {
  62072. this.state = S_XML_DECL_ENDING;
  62073. this.text = "";
  62074. this.fail("XML declaration is incomplete.");
  62075. return;
  62076. }
  62077. if (c === EOC) {
  62078. return;
  62079. }
  62080. var value = this.text;
  62081. this.text = "";
  62082. switch (this.name) {
  62083. case "version":
  62084. {
  62085. this.xmlDeclExpects = ["encoding", "standalone"];
  62086. var version = value;
  62087. this.xmlDecl.version = version; // This is the test specified by XML 1.0 but it is fine for XML 1.1.
  62088. if (!/^1\.[0-9]+$/.test(version)) {
  62089. this.fail("version number must match /^1\\.[0-9]+$/.");
  62090. } // When forceXMLVersion is set, the XML declaration is ignored.
  62091. else if (!this.opt.forceXMLVersion) {
  62092. this.setXMLVersion(version);
  62093. }
  62094. break;
  62095. }
  62096. case "encoding":
  62097. if (!/^[A-Za-z][A-Za-z0-9._-]*$/.test(value)) {
  62098. this.fail("encoding value must match \
  62099. /^[A-Za-z0-9][A-Za-z0-9._-]*$/.");
  62100. }
  62101. this.xmlDeclExpects = ["standalone"];
  62102. this.xmlDecl.encoding = value;
  62103. break;
  62104. case "standalone":
  62105. if (value !== "yes" && value !== "no") {
  62106. this.fail("standalone value must match \"yes\" or \"no\".");
  62107. }
  62108. this.xmlDeclExpects = [];
  62109. this.xmlDecl.standalone = value;
  62110. break;
  62111. default: // We don't need to raise an error here since we've already raised one
  62112. // when checking what name was expected.
  62113. }
  62114. this.name = "";
  62115. this.state = S_XML_DECL_SEPARATOR;
  62116. }
  62117. }, {
  62118. key: "sXMLDeclSeparator",
  62119. value: function sXMLDeclSeparator() {
  62120. var c = this.getCodeNorm(); // The question mark character is not valid inside any of the XML
  62121. // declaration name/value pairs.
  62122. if (c === QUESTION) {
  62123. // It is valid to go to S_XML_DECL_ENDING from this state.
  62124. this.state = S_XML_DECL_ENDING;
  62125. return;
  62126. }
  62127. if (!isS(c)) {
  62128. this.fail("whitespace required.");
  62129. this.unget();
  62130. }
  62131. this.state = S_XML_DECL_NAME_START;
  62132. }
  62133. }, {
  62134. key: "sXMLDeclEnding",
  62135. value: function sXMLDeclEnding() {
  62136. var _a;
  62137. var c = this.getCodeNorm();
  62138. if (c === GREATER) {
  62139. if (this.piTarget !== "xml") {
  62140. this.fail("processing instructions are not allowed before root.");
  62141. } else if (this.name !== "version" && this.xmlDeclExpects.includes("version")) {
  62142. this.fail("XML declaration must contain a version.");
  62143. } // eslint-disable-next-line no-unused-expressions
  62144. (_a = this.xmldeclHandler) === null || _a === void 0 ? void 0 : _a.call(this, this.xmlDecl);
  62145. this.name = "";
  62146. this.piTarget = this.text = "";
  62147. this.state = S_TEXT;
  62148. } else {
  62149. // We got here because the previous character was a ?, but the question
  62150. // mark character is not valid inside any of the XML declaration
  62151. // name/value pairs.
  62152. this.fail("The character ? is disallowed anywhere in XML declarations.");
  62153. }
  62154. this.xmlDeclPossible = false;
  62155. }
  62156. }, {
  62157. key: "sOpenTag",
  62158. value: function sOpenTag() {
  62159. var _a;
  62160. var c = this.captureNameChars();
  62161. if (c === EOC) {
  62162. return;
  62163. }
  62164. var tag = this.tag = {
  62165. name: this.name,
  62166. attributes: Object.create(null)
  62167. };
  62168. this.name = "";
  62169. if (this.xmlnsOpt) {
  62170. this.topNS = tag.ns = Object.create(null);
  62171. } // eslint-disable-next-line no-unused-expressions
  62172. (_a = this.openTagStartHandler) === null || _a === void 0 ? void 0 : _a.call(this, tag);
  62173. this.sawRoot = true;
  62174. if (!this.fragmentOpt && this.closedRoot) {
  62175. this.fail("documents may contain only one root.");
  62176. }
  62177. switch (c) {
  62178. case GREATER:
  62179. this.openTag();
  62180. break;
  62181. case FORWARD_SLASH:
  62182. this.state = S_OPEN_TAG_SLASH;
  62183. break;
  62184. default:
  62185. if (!isS(c)) {
  62186. this.fail("disallowed character in tag name.");
  62187. }
  62188. this.state = S_ATTRIB;
  62189. }
  62190. }
  62191. }, {
  62192. key: "sOpenTagSlash",
  62193. value: function sOpenTagSlash() {
  62194. if (this.getCode() === GREATER) {
  62195. this.openSelfClosingTag();
  62196. } else {
  62197. this.fail("forward-slash in opening tag not followed by >.");
  62198. this.state = S_ATTRIB;
  62199. }
  62200. }
  62201. }, {
  62202. key: "sAttrib",
  62203. value: function sAttrib() {
  62204. var c = this.skipSpaces();
  62205. if (c === EOC) {
  62206. return;
  62207. }
  62208. if (isNameStartChar(c)) {
  62209. this.unget();
  62210. this.state = S_ATTRIB_NAME;
  62211. } else if (c === GREATER) {
  62212. this.openTag();
  62213. } else if (c === FORWARD_SLASH) {
  62214. this.state = S_OPEN_TAG_SLASH;
  62215. } else {
  62216. this.fail("disallowed character in attribute name.");
  62217. }
  62218. }
  62219. }, {
  62220. key: "sAttribName",
  62221. value: function sAttribName() {
  62222. var c = this.captureNameChars();
  62223. if (c === EQUAL) {
  62224. this.state = S_ATTRIB_VALUE;
  62225. } else if (isS(c)) {
  62226. this.state = S_ATTRIB_NAME_SAW_WHITE;
  62227. } else if (c === GREATER) {
  62228. this.fail("attribute without value.");
  62229. this.pushAttrib(this.name, this.name);
  62230. this.name = this.text = "";
  62231. this.openTag();
  62232. } else if (c !== EOC) {
  62233. this.fail("disallowed character in attribute name.");
  62234. }
  62235. }
  62236. }, {
  62237. key: "sAttribNameSawWhite",
  62238. value: function sAttribNameSawWhite() {
  62239. var c = this.skipSpaces();
  62240. switch (c) {
  62241. case EOC:
  62242. return;
  62243. case EQUAL:
  62244. this.state = S_ATTRIB_VALUE;
  62245. break;
  62246. default:
  62247. this.fail("attribute without value."); // Should we do this???
  62248. // this.tag.attributes[this.name] = "";
  62249. this.text = "";
  62250. this.name = "";
  62251. if (c === GREATER) {
  62252. this.openTag();
  62253. } else if (isNameStartChar(c)) {
  62254. this.unget();
  62255. this.state = S_ATTRIB_NAME;
  62256. } else {
  62257. this.fail("disallowed character in attribute name.");
  62258. this.state = S_ATTRIB;
  62259. }
  62260. }
  62261. }
  62262. }, {
  62263. key: "sAttribValue",
  62264. value: function sAttribValue() {
  62265. var c = this.getCodeNorm();
  62266. if (isQuote(c)) {
  62267. this.q = c;
  62268. this.state = S_ATTRIB_VALUE_QUOTED;
  62269. } else if (!isS(c)) {
  62270. this.fail("unquoted attribute value.");
  62271. this.state = S_ATTRIB_VALUE_UNQUOTED;
  62272. this.unget();
  62273. }
  62274. }
  62275. }, {
  62276. key: "sAttribValueQuoted",
  62277. value: function sAttribValueQuoted() {
  62278. // We deliberately do not use captureTo here. The specialized code we use
  62279. // here is faster than using captureTo.
  62280. var q = this.q,
  62281. chunk = this.chunk;
  62282. var start = this.i; // eslint-disable-next-line no-constant-condition
  62283. while (true) {
  62284. switch (this.getCode()) {
  62285. case q:
  62286. this.pushAttrib(this.name, this.text + chunk.slice(start, this.prevI));
  62287. this.name = this.text = "";
  62288. this.q = null;
  62289. this.state = S_ATTRIB_VALUE_CLOSED;
  62290. return;
  62291. case AMP:
  62292. this.text += chunk.slice(start, this.prevI);
  62293. this.state = S_ENTITY;
  62294. this.entityReturnState = S_ATTRIB_VALUE_QUOTED;
  62295. return;
  62296. case NL:
  62297. case NL_LIKE:
  62298. case TAB:
  62299. this.text += "".concat(chunk.slice(start, this.prevI), " ");
  62300. start = this.i;
  62301. break;
  62302. case LESS:
  62303. this.text += chunk.slice(start, this.prevI);
  62304. this.fail("disallowed character.");
  62305. return;
  62306. case EOC:
  62307. this.text += chunk.slice(start);
  62308. return;
  62309. default:
  62310. }
  62311. }
  62312. }
  62313. }, {
  62314. key: "sAttribValueClosed",
  62315. value: function sAttribValueClosed() {
  62316. var c = this.getCodeNorm();
  62317. if (isS(c)) {
  62318. this.state = S_ATTRIB;
  62319. } else if (c === GREATER) {
  62320. this.openTag();
  62321. } else if (c === FORWARD_SLASH) {
  62322. this.state = S_OPEN_TAG_SLASH;
  62323. } else if (isNameStartChar(c)) {
  62324. this.fail("no whitespace between attributes.");
  62325. this.unget();
  62326. this.state = S_ATTRIB_NAME;
  62327. } else {
  62328. this.fail("disallowed character in attribute name.");
  62329. }
  62330. }
  62331. }, {
  62332. key: "sAttribValueUnquoted",
  62333. value: function sAttribValueUnquoted() {
  62334. // We don't do anything regarding EOL or space handling for unquoted
  62335. // attributes. We already have failed by the time we get here, and the
  62336. // contract that saxes upholds states that upon failure, it is not safe to
  62337. // rely on the data passed to event handlers (other than
  62338. // ``onerror``). Passing "bad" data is not a problem.
  62339. var c = this.captureTo(ATTRIB_VALUE_UNQUOTED_TERMINATOR);
  62340. switch (c) {
  62341. case AMP:
  62342. this.state = S_ENTITY;
  62343. this.entityReturnState = S_ATTRIB_VALUE_UNQUOTED;
  62344. break;
  62345. case LESS:
  62346. this.fail("disallowed character.");
  62347. break;
  62348. case EOC:
  62349. break;
  62350. default:
  62351. if (this.text.includes("]]>")) {
  62352. this.fail("the string \"]]>\" is disallowed in char data.");
  62353. }
  62354. this.pushAttrib(this.name, this.text);
  62355. this.name = this.text = "";
  62356. if (c === GREATER) {
  62357. this.openTag();
  62358. } else {
  62359. this.state = S_ATTRIB;
  62360. }
  62361. }
  62362. }
  62363. }, {
  62364. key: "sCloseTag",
  62365. value: function sCloseTag() {
  62366. var c = this.captureNameChars();
  62367. if (c === GREATER) {
  62368. this.closeTag();
  62369. } else if (isS(c)) {
  62370. this.state = S_CLOSE_TAG_SAW_WHITE;
  62371. } else if (c !== EOC) {
  62372. this.fail("disallowed character in closing tag.");
  62373. }
  62374. }
  62375. }, {
  62376. key: "sCloseTagSawWhite",
  62377. value: function sCloseTagSawWhite() {
  62378. switch (this.skipSpaces()) {
  62379. case GREATER:
  62380. this.closeTag();
  62381. break;
  62382. case EOC:
  62383. break;
  62384. default:
  62385. this.fail("disallowed character in closing tag.");
  62386. }
  62387. } // END OF STATE ENGINE METHODS
  62388. }, {
  62389. key: "handleTextInRoot",
  62390. value: function handleTextInRoot() {
  62391. // This is essentially a specialized version of captureTo which is optimized
  62392. // for performing the ]]> check. A previous version of this code, checked
  62393. // ``this.text`` for the presence of ]]>. It simplified the code but was
  62394. // very costly when character data contained a lot of entities to be parsed.
  62395. //
  62396. // Since we are using a specialized loop, we also keep track of the presence
  62397. // of ]]> in text data. The sequence ]]> is forbidden to appear as-is.
  62398. //
  62399. var start = this.i,
  62400. forbiddenState = this.forbiddenState;
  62401. var chunk = this.chunk,
  62402. handler = this.textHandler; // eslint-disable-next-line no-labels, no-restricted-syntax
  62403. scanLoop: // eslint-disable-next-line no-constant-condition
  62404. while (true) {
  62405. switch (this.getCode()) {
  62406. case LESS:
  62407. {
  62408. this.state = S_OPEN_WAKA;
  62409. if (handler !== undefined) {
  62410. var text = this.text;
  62411. var slice = chunk.slice(start, this.prevI);
  62412. if (text.length !== 0) {
  62413. handler(text + slice);
  62414. this.text = "";
  62415. } else if (slice.length !== 0) {
  62416. handler(slice);
  62417. }
  62418. }
  62419. forbiddenState = FORBIDDEN_START; // eslint-disable-next-line no-labels
  62420. break scanLoop;
  62421. }
  62422. case AMP:
  62423. this.state = S_ENTITY;
  62424. this.entityReturnState = S_TEXT;
  62425. if (handler !== undefined) {
  62426. this.text += chunk.slice(start, this.prevI);
  62427. }
  62428. forbiddenState = FORBIDDEN_START; // eslint-disable-next-line no-labels
  62429. break scanLoop;
  62430. case CLOSE_BRACKET:
  62431. switch (forbiddenState) {
  62432. case FORBIDDEN_START:
  62433. forbiddenState = FORBIDDEN_BRACKET;
  62434. break;
  62435. case FORBIDDEN_BRACKET:
  62436. forbiddenState = FORBIDDEN_BRACKET_BRACKET;
  62437. break;
  62438. case FORBIDDEN_BRACKET_BRACKET:
  62439. break;
  62440. default:
  62441. throw new Error("impossible state");
  62442. }
  62443. break;
  62444. case GREATER:
  62445. if (forbiddenState === FORBIDDEN_BRACKET_BRACKET) {
  62446. this.fail("the string \"]]>\" is disallowed in char data.");
  62447. }
  62448. forbiddenState = FORBIDDEN_START;
  62449. break;
  62450. case NL_LIKE:
  62451. if (handler !== undefined) {
  62452. this.text += "".concat(chunk.slice(start, this.prevI), "\n");
  62453. }
  62454. start = this.i;
  62455. forbiddenState = FORBIDDEN_START;
  62456. break;
  62457. case EOC:
  62458. if (handler !== undefined) {
  62459. this.text += chunk.slice(start);
  62460. } // eslint-disable-next-line no-labels
  62461. break scanLoop;
  62462. default:
  62463. forbiddenState = FORBIDDEN_START;
  62464. }
  62465. }
  62466. this.forbiddenState = forbiddenState;
  62467. }
  62468. }, {
  62469. key: "handleTextOutsideRoot",
  62470. value: function handleTextOutsideRoot() {
  62471. // This is essentially a specialized version of captureTo which is optimized
  62472. // for a specialized task. We keep track of the presence of non-space
  62473. // characters in the text since these are errors when appearing outside the
  62474. // document root element.
  62475. var start = this.i;
  62476. var chunk = this.chunk,
  62477. handler = this.textHandler;
  62478. var nonSpace = false; // eslint-disable-next-line no-labels, no-restricted-syntax
  62479. outRootLoop: // eslint-disable-next-line no-constant-condition
  62480. while (true) {
  62481. var code = this.getCode();
  62482. switch (code) {
  62483. case LESS:
  62484. {
  62485. this.state = S_OPEN_WAKA;
  62486. if (handler !== undefined) {
  62487. var text = this.text;
  62488. var slice = chunk.slice(start, this.prevI);
  62489. if (text.length !== 0) {
  62490. handler(text + slice);
  62491. this.text = "";
  62492. } else if (slice.length !== 0) {
  62493. handler(slice);
  62494. }
  62495. } // eslint-disable-next-line no-labels
  62496. break outRootLoop;
  62497. }
  62498. case AMP:
  62499. this.state = S_ENTITY;
  62500. this.entityReturnState = S_TEXT;
  62501. if (handler !== undefined) {
  62502. this.text += chunk.slice(start, this.prevI);
  62503. }
  62504. nonSpace = true; // eslint-disable-next-line no-labels
  62505. break outRootLoop;
  62506. case NL_LIKE:
  62507. if (handler !== undefined) {
  62508. this.text += "".concat(chunk.slice(start, this.prevI), "\n");
  62509. }
  62510. start = this.i;
  62511. break;
  62512. case EOC:
  62513. if (handler !== undefined) {
  62514. this.text += chunk.slice(start);
  62515. } // eslint-disable-next-line no-labels
  62516. break outRootLoop;
  62517. default:
  62518. if (!isS(code)) {
  62519. nonSpace = true;
  62520. }
  62521. }
  62522. }
  62523. if (!nonSpace) {
  62524. return;
  62525. } // We use the reportedTextBeforeRoot and reportedTextAfterRoot flags
  62526. // to avoid reporting errors for every single character that is out of
  62527. // place.
  62528. if (!this.sawRoot && !this.reportedTextBeforeRoot) {
  62529. this.fail("text data outside of root node.");
  62530. this.reportedTextBeforeRoot = true;
  62531. }
  62532. if (this.closedRoot && !this.reportedTextAfterRoot) {
  62533. this.fail("text data outside of root node.");
  62534. this.reportedTextAfterRoot = true;
  62535. }
  62536. }
  62537. }, {
  62538. key: "pushAttribNS",
  62539. value: function pushAttribNS(name, value) {
  62540. var _a;
  62541. var _this$qname = this.qname(name),
  62542. prefix = _this$qname.prefix,
  62543. local = _this$qname.local;
  62544. var attr = {
  62545. name: name,
  62546. prefix: prefix,
  62547. local: local,
  62548. value: value
  62549. };
  62550. this.attribList.push(attr); // eslint-disable-next-line no-unused-expressions
  62551. (_a = this.attributeHandler) === null || _a === void 0 ? void 0 : _a.call(this, attr);
  62552. if (prefix === "xmlns") {
  62553. var trimmed = value.trim();
  62554. if (this.currentXMLVersion === "1.0" && trimmed === "") {
  62555. this.fail("invalid attempt to undefine prefix in XML 1.0");
  62556. }
  62557. this.topNS[local] = trimmed;
  62558. nsPairCheck(this, local, trimmed);
  62559. } else if (name === "xmlns") {
  62560. var _trimmed = value.trim();
  62561. this.topNS[""] = _trimmed;
  62562. nsPairCheck(this, "", _trimmed);
  62563. }
  62564. }
  62565. }, {
  62566. key: "pushAttribPlain",
  62567. value: function pushAttribPlain(name, value) {
  62568. var _a;
  62569. var attr = {
  62570. name: name,
  62571. value: value
  62572. };
  62573. this.attribList.push(attr); // eslint-disable-next-line no-unused-expressions
  62574. (_a = this.attributeHandler) === null || _a === void 0 ? void 0 : _a.call(this, attr);
  62575. }
  62576. /**
  62577. * End parsing. This performs final well-formedness checks and resets the
  62578. * parser to a clean state.
  62579. *
  62580. * @returns this
  62581. */
  62582. }, {
  62583. key: "end",
  62584. value: function end() {
  62585. var _a, _b;
  62586. if (!this.sawRoot) {
  62587. this.fail("document must contain a root element.");
  62588. }
  62589. var tags = this.tags;
  62590. while (tags.length > 0) {
  62591. var tag = tags.pop();
  62592. this.fail("unclosed tag: ".concat(tag.name));
  62593. }
  62594. if (this.state !== S_BEGIN && this.state !== S_TEXT) {
  62595. this.fail("unexpected end.");
  62596. }
  62597. var text = this.text;
  62598. if (text.length !== 0) {
  62599. // eslint-disable-next-line no-unused-expressions
  62600. (_a = this.textHandler) === null || _a === void 0 ? void 0 : _a.call(this, text);
  62601. this.text = "";
  62602. }
  62603. this._closed = true; // eslint-disable-next-line no-unused-expressions
  62604. (_b = this.endHandler) === null || _b === void 0 ? void 0 : _b.call(this);
  62605. this._init();
  62606. return this;
  62607. }
  62608. /**
  62609. * Resolve a namespace prefix.
  62610. *
  62611. * @param prefix The prefix to resolve.
  62612. *
  62613. * @returns The namespace URI or ``undefined`` if the prefix is not defined.
  62614. */
  62615. }, {
  62616. key: "resolve",
  62617. value: function resolve(prefix) {
  62618. var _a, _b;
  62619. var uri = this.topNS[prefix];
  62620. if (uri !== undefined) {
  62621. return uri;
  62622. }
  62623. var tags = this.tags;
  62624. for (var index = tags.length - 1; index >= 0; index--) {
  62625. uri = tags[index].ns[prefix];
  62626. if (uri !== undefined) {
  62627. return uri;
  62628. }
  62629. }
  62630. uri = this.ns[prefix];
  62631. if (uri !== undefined) {
  62632. return uri;
  62633. }
  62634. return (_b = (_a = this.opt).resolvePrefix) === null || _b === void 0 ? void 0 : _b.call(_a, prefix);
  62635. }
  62636. /**
  62637. * Parse a qname into its prefix and local name parts.
  62638. *
  62639. * @param name The name to parse
  62640. *
  62641. * @returns
  62642. */
  62643. }, {
  62644. key: "qname",
  62645. value: function qname(name) {
  62646. // This is faster than using name.split(":").
  62647. var colon = name.indexOf(":");
  62648. if (colon === -1) {
  62649. return {
  62650. prefix: "",
  62651. local: name
  62652. };
  62653. }
  62654. var local = name.slice(colon + 1);
  62655. var prefix = name.slice(0, colon);
  62656. if (prefix === "" || local === "" || local.includes(":")) {
  62657. this.fail("malformed name: ".concat(name, "."));
  62658. }
  62659. return {
  62660. prefix: prefix,
  62661. local: local
  62662. };
  62663. }
  62664. }, {
  62665. key: "processAttribsNS",
  62666. value: function processAttribsNS() {
  62667. var _a;
  62668. var attribList = this.attribList;
  62669. var tag = this.tag;
  62670. {
  62671. // add namespace info to tag
  62672. var _this$qname2 = this.qname(tag.name),
  62673. prefix = _this$qname2.prefix,
  62674. local = _this$qname2.local;
  62675. tag.prefix = prefix;
  62676. tag.local = local;
  62677. var uri = tag.uri = (_a = this.resolve(prefix)) !== null && _a !== void 0 ? _a : "";
  62678. if (prefix !== "") {
  62679. if (prefix === "xmlns") {
  62680. this.fail("tags may not have \"xmlns\" as prefix.");
  62681. }
  62682. if (uri === "") {
  62683. this.fail("unbound namespace prefix: ".concat(JSON.stringify(prefix), "."));
  62684. tag.uri = prefix;
  62685. }
  62686. }
  62687. }
  62688. if (attribList.length === 0) {
  62689. return;
  62690. }
  62691. var attributes = tag.attributes;
  62692. var seen = new Set(); // Note: do not apply default ns to attributes:
  62693. // http://www.w3.org/TR/REC-xml-names/#defaulting
  62694. var _iterator = _createForOfIteratorHelper(attribList),
  62695. _step;
  62696. try {
  62697. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  62698. var attr = _step.value;
  62699. var name = attr.name,
  62700. _prefix = attr.prefix,
  62701. _local = attr.local;
  62702. var _uri = void 0;
  62703. var eqname = void 0;
  62704. if (_prefix === "") {
  62705. _uri = name === "xmlns" ? XMLNS_NAMESPACE : "";
  62706. eqname = name;
  62707. } else {
  62708. _uri = this.resolve(_prefix); // if there's any attributes with an undefined namespace,
  62709. // then fail on them now.
  62710. if (_uri === undefined) {
  62711. this.fail("unbound namespace prefix: ".concat(JSON.stringify(_prefix), "."));
  62712. _uri = _prefix;
  62713. }
  62714. eqname = "{".concat(_uri, "}").concat(_local);
  62715. }
  62716. if (seen.has(eqname)) {
  62717. this.fail("duplicate attribute: ".concat(eqname, "."));
  62718. }
  62719. seen.add(eqname);
  62720. attr.uri = _uri;
  62721. attributes[name] = attr;
  62722. }
  62723. } catch (err) {
  62724. _iterator.e(err);
  62725. } finally {
  62726. _iterator.f();
  62727. }
  62728. this.attribList = [];
  62729. }
  62730. }, {
  62731. key: "processAttribsPlain",
  62732. value: function processAttribsPlain() {
  62733. var attribList = this.attribList; // eslint-disable-next-line prefer-destructuring
  62734. var attributes = this.tag.attributes;
  62735. var _iterator2 = _createForOfIteratorHelper(attribList),
  62736. _step2;
  62737. try {
  62738. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  62739. var _step2$value = _step2.value,
  62740. name = _step2$value.name,
  62741. value = _step2$value.value;
  62742. if (attributes[name] !== undefined) {
  62743. this.fail("duplicate attribute: ".concat(name, "."));
  62744. }
  62745. attributes[name] = value;
  62746. }
  62747. } catch (err) {
  62748. _iterator2.e(err);
  62749. } finally {
  62750. _iterator2.f();
  62751. }
  62752. this.attribList = [];
  62753. }
  62754. /**
  62755. * Handle a complete open tag. This parser code calls this once it has seen
  62756. * the whole tag. This method checks for well-formeness and then emits
  62757. * ``onopentag``.
  62758. */
  62759. }, {
  62760. key: "openTag",
  62761. value: function openTag() {
  62762. var _a;
  62763. this.processAttribs();
  62764. var tags = this.tags;
  62765. var tag = this.tag;
  62766. tag.isSelfClosing = false; // There cannot be any pending text here due to the onopentagstart that was
  62767. // necessarily emitted before we get here. So we do not check text.
  62768. // eslint-disable-next-line no-unused-expressions
  62769. (_a = this.openTagHandler) === null || _a === void 0 ? void 0 : _a.call(this, tag);
  62770. tags.push(tag);
  62771. this.state = S_TEXT;
  62772. this.name = "";
  62773. }
  62774. /**
  62775. * Handle a complete self-closing tag. This parser code calls this once it has
  62776. * seen the whole tag. This method checks for well-formeness and then emits
  62777. * ``onopentag`` and ``onclosetag``.
  62778. */
  62779. }, {
  62780. key: "openSelfClosingTag",
  62781. value: function openSelfClosingTag() {
  62782. var _a, _b, _c;
  62783. this.processAttribs();
  62784. var tags = this.tags;
  62785. var tag = this.tag;
  62786. tag.isSelfClosing = true; // There cannot be any pending text here due to the onopentagstart that was
  62787. // necessarily emitted before we get here. So we do not check text.
  62788. // eslint-disable-next-line no-unused-expressions
  62789. (_a = this.openTagHandler) === null || _a === void 0 ? void 0 : _a.call(this, tag); // eslint-disable-next-line no-unused-expressions
  62790. (_b = this.closeTagHandler) === null || _b === void 0 ? void 0 : _b.call(this, tag);
  62791. var top = this.tag = (_c = tags[tags.length - 1]) !== null && _c !== void 0 ? _c : null;
  62792. if (top === null) {
  62793. this.closedRoot = true;
  62794. }
  62795. this.state = S_TEXT;
  62796. this.name = "";
  62797. }
  62798. /**
  62799. * Handle a complete close tag. This parser code calls this once it has seen
  62800. * the whole tag. This method checks for well-formeness and then emits
  62801. * ``onclosetag``.
  62802. */
  62803. }, {
  62804. key: "closeTag",
  62805. value: function closeTag() {
  62806. var tags = this.tags,
  62807. name = this.name; // Our state after this will be S_TEXT, no matter what, and we can clear
  62808. // tagName now.
  62809. this.state = S_TEXT;
  62810. this.name = "";
  62811. if (name === "") {
  62812. this.fail("weird empty close tag.");
  62813. this.text += "</>";
  62814. return;
  62815. }
  62816. var handler = this.closeTagHandler;
  62817. var l = tags.length;
  62818. while (l-- > 0) {
  62819. var tag = this.tag = tags.pop();
  62820. this.topNS = tag.ns; // eslint-disable-next-line no-unused-expressions
  62821. handler === null || handler === void 0 ? void 0 : handler(tag);
  62822. if (tag.name === name) {
  62823. break;
  62824. }
  62825. this.fail("unexpected close tag.");
  62826. }
  62827. if (l === 0) {
  62828. this.closedRoot = true;
  62829. } else if (l < 0) {
  62830. this.fail("unmatched closing tag: ".concat(name, "."));
  62831. this.text += "</".concat(name, ">");
  62832. }
  62833. }
  62834. /**
  62835. * Resolves an entity. Makes any necessary well-formedness checks.
  62836. *
  62837. * @param entity The entity to resolve.
  62838. *
  62839. * @returns The parsed entity.
  62840. */
  62841. }, {
  62842. key: "parseEntity",
  62843. value: function parseEntity(entity) {
  62844. // startsWith would be significantly slower for this test.
  62845. // eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
  62846. if (entity[0] !== "#") {
  62847. var defined = this.ENTITIES[entity];
  62848. if (defined !== undefined) {
  62849. return defined;
  62850. }
  62851. this.fail(this.isName(entity) ? "undefined entity." : "disallowed character in entity name.");
  62852. return "&".concat(entity, ";");
  62853. }
  62854. var num = NaN;
  62855. if (entity[1] === "x" && /^#x[0-9a-f]+$/i.test(entity)) {
  62856. num = parseInt(entity.slice(2), 16);
  62857. } else if (/^#[0-9]+$/.test(entity)) {
  62858. num = parseInt(entity.slice(1), 10);
  62859. } // The character reference is required to match the CHAR production.
  62860. if (!this.isChar(num)) {
  62861. this.fail("malformed character entity.");
  62862. return "&".concat(entity, ";");
  62863. }
  62864. return String.fromCodePoint(num);
  62865. }
  62866. }, {
  62867. key: "closed",
  62868. get: function get() {
  62869. return this._closed;
  62870. }
  62871. }, {
  62872. key: "position",
  62873. get: function get() {
  62874. return this.chunkPosition + this.i;
  62875. }
  62876. /**
  62877. * The column number of the next character to be read by the parser. *
  62878. * This field is zero-based. (The first column in a line is 0.)
  62879. *
  62880. * This field reports the index at which the next character would be in the
  62881. * line if the line were represented as a JavaScript string. Note that this
  62882. * *can* be different to a count based on the number of *Unicode characters*
  62883. * due to how JavaScript handles astral plane characters.
  62884. *
  62885. * See [[column]] for a number that corresponds to a count of Unicode
  62886. * characters.
  62887. */
  62888. }, {
  62889. key: "columnIndex",
  62890. get: function get() {
  62891. return this.position - this.positionAtNewLine;
  62892. }
  62893. }]);
  62894. return SaxesParser;
  62895. }();
  62896. exports.SaxesParser = SaxesParser;
  62897. },{"xmlchars/xml/1.0/ed5":541,"xmlchars/xml/1.1/ed2":542,"xmlchars/xmlns/1.0/ed3":543}],497:[function(require,module,exports){
  62898. (function (setImmediate){
  62899. 'use strict';
  62900. module.exports = typeof setImmediate === 'function' ? setImmediate : function setImmediate() {
  62901. var args = [].slice.apply(arguments);
  62902. args.splice(1, 0, 0);
  62903. setTimeout.apply(null, args);
  62904. };
  62905. }).call(this,require("timers").setImmediate)
  62906. },{"timers":521}],498:[function(require,module,exports){
  62907. "use strict";
  62908. var Buffer = require('safe-buffer').Buffer; // prototype class for hash functions
  62909. function Hash(blockSize, finalSize) {
  62910. this._block = Buffer.alloc(blockSize);
  62911. this._finalSize = finalSize;
  62912. this._blockSize = blockSize;
  62913. this._len = 0;
  62914. }
  62915. Hash.prototype.update = function (data, enc) {
  62916. if (typeof data === 'string') {
  62917. enc = enc || 'utf8';
  62918. data = Buffer.from(data, enc);
  62919. }
  62920. var block = this._block;
  62921. var blockSize = this._blockSize;
  62922. var length = data.length;
  62923. var accum = this._len;
  62924. for (var offset = 0; offset < length;) {
  62925. var assigned = accum % blockSize;
  62926. var remainder = Math.min(length - offset, blockSize - assigned);
  62927. for (var i = 0; i < remainder; i++) {
  62928. block[assigned + i] = data[offset + i];
  62929. }
  62930. accum += remainder;
  62931. offset += remainder;
  62932. if (accum % blockSize === 0) {
  62933. this._update(block);
  62934. }
  62935. }
  62936. this._len += length;
  62937. return this;
  62938. };
  62939. Hash.prototype.digest = function (enc) {
  62940. var rem = this._len % this._blockSize;
  62941. this._block[rem] = 0x80; // zero (rem + 1) trailing bits, where (rem + 1) is the smallest
  62942. // non-negative solution to the equation (length + 1 + (rem + 1)) === finalSize mod blockSize
  62943. this._block.fill(0, rem + 1);
  62944. if (rem >= this._finalSize) {
  62945. this._update(this._block);
  62946. this._block.fill(0);
  62947. }
  62948. var bits = this._len * 8; // uint32
  62949. if (bits <= 0xffffffff) {
  62950. this._block.writeUInt32BE(bits, this._blockSize - 4); // uint64
  62951. } else {
  62952. var lowBits = (bits & 0xffffffff) >>> 0;
  62953. var highBits = (bits - lowBits) / 0x100000000;
  62954. this._block.writeUInt32BE(highBits, this._blockSize - 8);
  62955. this._block.writeUInt32BE(lowBits, this._blockSize - 4);
  62956. }
  62957. this._update(this._block);
  62958. var hash = this._hash();
  62959. return enc ? hash.toString(enc) : hash;
  62960. };
  62961. Hash.prototype._update = function () {
  62962. throw new Error('_update must be implemented by subclass');
  62963. };
  62964. module.exports = Hash;
  62965. },{"safe-buffer":494}],499:[function(require,module,exports){
  62966. "use strict";
  62967. var _exports = module.exports = function SHA(algorithm) {
  62968. algorithm = algorithm.toLowerCase();
  62969. var Algorithm = _exports[algorithm];
  62970. if (!Algorithm) throw new Error(algorithm + ' is not supported (we accept pull requests)');
  62971. return new Algorithm();
  62972. };
  62973. _exports.sha = require('./sha');
  62974. _exports.sha1 = require('./sha1');
  62975. _exports.sha224 = require('./sha224');
  62976. _exports.sha256 = require('./sha256');
  62977. _exports.sha384 = require('./sha384');
  62978. _exports.sha512 = require('./sha512');
  62979. },{"./sha":500,"./sha1":501,"./sha224":502,"./sha256":503,"./sha384":504,"./sha512":505}],500:[function(require,module,exports){
  62980. "use strict";
  62981. /*
  62982. * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined
  62983. * in FIPS PUB 180-1
  62984. * This source code is derived from sha1.js of the same repository.
  62985. * The difference between SHA-0 and SHA-1 is just a bitwise rotate left
  62986. * operation was added.
  62987. */
  62988. var inherits = require('inherits');
  62989. var Hash = require('./hash');
  62990. var Buffer = require('safe-buffer').Buffer;
  62991. var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0];
  62992. var W = new Array(80);
  62993. function Sha() {
  62994. this.init();
  62995. this._w = W;
  62996. Hash.call(this, 64, 56);
  62997. }
  62998. inherits(Sha, Hash);
  62999. Sha.prototype.init = function () {
  63000. this._a = 0x67452301;
  63001. this._b = 0xefcdab89;
  63002. this._c = 0x98badcfe;
  63003. this._d = 0x10325476;
  63004. this._e = 0xc3d2e1f0;
  63005. return this;
  63006. };
  63007. function rotl5(num) {
  63008. return num << 5 | num >>> 27;
  63009. }
  63010. function rotl30(num) {
  63011. return num << 30 | num >>> 2;
  63012. }
  63013. function ft(s, b, c, d) {
  63014. if (s === 0) return b & c | ~b & d;
  63015. if (s === 2) return b & c | b & d | c & d;
  63016. return b ^ c ^ d;
  63017. }
  63018. Sha.prototype._update = function (M) {
  63019. var W = this._w;
  63020. var a = this._a | 0;
  63021. var b = this._b | 0;
  63022. var c = this._c | 0;
  63023. var d = this._d | 0;
  63024. var e = this._e | 0;
  63025. for (var i = 0; i < 16; ++i) {
  63026. W[i] = M.readInt32BE(i * 4);
  63027. }
  63028. for (; i < 80; ++i) {
  63029. W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
  63030. }
  63031. for (var j = 0; j < 80; ++j) {
  63032. var s = ~~(j / 20);
  63033. var t = rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s] | 0;
  63034. e = d;
  63035. d = c;
  63036. c = rotl30(b);
  63037. b = a;
  63038. a = t;
  63039. }
  63040. this._a = a + this._a | 0;
  63041. this._b = b + this._b | 0;
  63042. this._c = c + this._c | 0;
  63043. this._d = d + this._d | 0;
  63044. this._e = e + this._e | 0;
  63045. };
  63046. Sha.prototype._hash = function () {
  63047. var H = Buffer.allocUnsafe(20);
  63048. H.writeInt32BE(this._a | 0, 0);
  63049. H.writeInt32BE(this._b | 0, 4);
  63050. H.writeInt32BE(this._c | 0, 8);
  63051. H.writeInt32BE(this._d | 0, 12);
  63052. H.writeInt32BE(this._e | 0, 16);
  63053. return H;
  63054. };
  63055. module.exports = Sha;
  63056. },{"./hash":498,"inherits":387,"safe-buffer":494}],501:[function(require,module,exports){
  63057. "use strict";
  63058. /*
  63059. * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
  63060. * in FIPS PUB 180-1
  63061. * Version 2.1a Copyright Paul Johnston 2000 - 2002.
  63062. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  63063. * Distributed under the BSD License
  63064. * See http://pajhome.org.uk/crypt/md5 for details.
  63065. */
  63066. var inherits = require('inherits');
  63067. var Hash = require('./hash');
  63068. var Buffer = require('safe-buffer').Buffer;
  63069. var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0];
  63070. var W = new Array(80);
  63071. function Sha1() {
  63072. this.init();
  63073. this._w = W;
  63074. Hash.call(this, 64, 56);
  63075. }
  63076. inherits(Sha1, Hash);
  63077. Sha1.prototype.init = function () {
  63078. this._a = 0x67452301;
  63079. this._b = 0xefcdab89;
  63080. this._c = 0x98badcfe;
  63081. this._d = 0x10325476;
  63082. this._e = 0xc3d2e1f0;
  63083. return this;
  63084. };
  63085. function rotl1(num) {
  63086. return num << 1 | num >>> 31;
  63087. }
  63088. function rotl5(num) {
  63089. return num << 5 | num >>> 27;
  63090. }
  63091. function rotl30(num) {
  63092. return num << 30 | num >>> 2;
  63093. }
  63094. function ft(s, b, c, d) {
  63095. if (s === 0) return b & c | ~b & d;
  63096. if (s === 2) return b & c | b & d | c & d;
  63097. return b ^ c ^ d;
  63098. }
  63099. Sha1.prototype._update = function (M) {
  63100. var W = this._w;
  63101. var a = this._a | 0;
  63102. var b = this._b | 0;
  63103. var c = this._c | 0;
  63104. var d = this._d | 0;
  63105. var e = this._e | 0;
  63106. for (var i = 0; i < 16; ++i) {
  63107. W[i] = M.readInt32BE(i * 4);
  63108. }
  63109. for (; i < 80; ++i) {
  63110. W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]);
  63111. }
  63112. for (var j = 0; j < 80; ++j) {
  63113. var s = ~~(j / 20);
  63114. var t = rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s] | 0;
  63115. e = d;
  63116. d = c;
  63117. c = rotl30(b);
  63118. b = a;
  63119. a = t;
  63120. }
  63121. this._a = a + this._a | 0;
  63122. this._b = b + this._b | 0;
  63123. this._c = c + this._c | 0;
  63124. this._d = d + this._d | 0;
  63125. this._e = e + this._e | 0;
  63126. };
  63127. Sha1.prototype._hash = function () {
  63128. var H = Buffer.allocUnsafe(20);
  63129. H.writeInt32BE(this._a | 0, 0);
  63130. H.writeInt32BE(this._b | 0, 4);
  63131. H.writeInt32BE(this._c | 0, 8);
  63132. H.writeInt32BE(this._d | 0, 12);
  63133. H.writeInt32BE(this._e | 0, 16);
  63134. return H;
  63135. };
  63136. module.exports = Sha1;
  63137. },{"./hash":498,"inherits":387,"safe-buffer":494}],502:[function(require,module,exports){
  63138. "use strict";
  63139. /**
  63140. * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
  63141. * in FIPS 180-2
  63142. * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
  63143. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  63144. *
  63145. */
  63146. var inherits = require('inherits');
  63147. var Sha256 = require('./sha256');
  63148. var Hash = require('./hash');
  63149. var Buffer = require('safe-buffer').Buffer;
  63150. var W = new Array(64);
  63151. function Sha224() {
  63152. this.init();
  63153. this._w = W; // new Array(64)
  63154. Hash.call(this, 64, 56);
  63155. }
  63156. inherits(Sha224, Sha256);
  63157. Sha224.prototype.init = function () {
  63158. this._a = 0xc1059ed8;
  63159. this._b = 0x367cd507;
  63160. this._c = 0x3070dd17;
  63161. this._d = 0xf70e5939;
  63162. this._e = 0xffc00b31;
  63163. this._f = 0x68581511;
  63164. this._g = 0x64f98fa7;
  63165. this._h = 0xbefa4fa4;
  63166. return this;
  63167. };
  63168. Sha224.prototype._hash = function () {
  63169. var H = Buffer.allocUnsafe(28);
  63170. H.writeInt32BE(this._a, 0);
  63171. H.writeInt32BE(this._b, 4);
  63172. H.writeInt32BE(this._c, 8);
  63173. H.writeInt32BE(this._d, 12);
  63174. H.writeInt32BE(this._e, 16);
  63175. H.writeInt32BE(this._f, 20);
  63176. H.writeInt32BE(this._g, 24);
  63177. return H;
  63178. };
  63179. module.exports = Sha224;
  63180. },{"./hash":498,"./sha256":503,"inherits":387,"safe-buffer":494}],503:[function(require,module,exports){
  63181. "use strict";
  63182. /**
  63183. * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
  63184. * in FIPS 180-2
  63185. * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
  63186. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  63187. *
  63188. */
  63189. var inherits = require('inherits');
  63190. var Hash = require('./hash');
  63191. var Buffer = require('safe-buffer').Buffer;
  63192. 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];
  63193. var W = new Array(64);
  63194. function Sha256() {
  63195. this.init();
  63196. this._w = W; // new Array(64)
  63197. Hash.call(this, 64, 56);
  63198. }
  63199. inherits(Sha256, Hash);
  63200. Sha256.prototype.init = function () {
  63201. this._a = 0x6a09e667;
  63202. this._b = 0xbb67ae85;
  63203. this._c = 0x3c6ef372;
  63204. this._d = 0xa54ff53a;
  63205. this._e = 0x510e527f;
  63206. this._f = 0x9b05688c;
  63207. this._g = 0x1f83d9ab;
  63208. this._h = 0x5be0cd19;
  63209. return this;
  63210. };
  63211. function ch(x, y, z) {
  63212. return z ^ x & (y ^ z);
  63213. }
  63214. function maj(x, y, z) {
  63215. return x & y | z & (x | y);
  63216. }
  63217. function sigma0(x) {
  63218. return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10);
  63219. }
  63220. function sigma1(x) {
  63221. return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7);
  63222. }
  63223. function gamma0(x) {
  63224. return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ x >>> 3;
  63225. }
  63226. function gamma1(x) {
  63227. return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ x >>> 10;
  63228. }
  63229. Sha256.prototype._update = function (M) {
  63230. var W = this._w;
  63231. var a = this._a | 0;
  63232. var b = this._b | 0;
  63233. var c = this._c | 0;
  63234. var d = this._d | 0;
  63235. var e = this._e | 0;
  63236. var f = this._f | 0;
  63237. var g = this._g | 0;
  63238. var h = this._h | 0;
  63239. for (var i = 0; i < 16; ++i) {
  63240. W[i] = M.readInt32BE(i * 4);
  63241. }
  63242. for (; i < 64; ++i) {
  63243. W[i] = gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16] | 0;
  63244. }
  63245. for (var j = 0; j < 64; ++j) {
  63246. var T1 = h + sigma1(e) + ch(e, f, g) + K[j] + W[j] | 0;
  63247. var T2 = sigma0(a) + maj(a, b, c) | 0;
  63248. h = g;
  63249. g = f;
  63250. f = e;
  63251. e = d + T1 | 0;
  63252. d = c;
  63253. c = b;
  63254. b = a;
  63255. a = T1 + T2 | 0;
  63256. }
  63257. this._a = a + this._a | 0;
  63258. this._b = b + this._b | 0;
  63259. this._c = c + this._c | 0;
  63260. this._d = d + this._d | 0;
  63261. this._e = e + this._e | 0;
  63262. this._f = f + this._f | 0;
  63263. this._g = g + this._g | 0;
  63264. this._h = h + this._h | 0;
  63265. };
  63266. Sha256.prototype._hash = function () {
  63267. var H = Buffer.allocUnsafe(32);
  63268. H.writeInt32BE(this._a, 0);
  63269. H.writeInt32BE(this._b, 4);
  63270. H.writeInt32BE(this._c, 8);
  63271. H.writeInt32BE(this._d, 12);
  63272. H.writeInt32BE(this._e, 16);
  63273. H.writeInt32BE(this._f, 20);
  63274. H.writeInt32BE(this._g, 24);
  63275. H.writeInt32BE(this._h, 28);
  63276. return H;
  63277. };
  63278. module.exports = Sha256;
  63279. },{"./hash":498,"inherits":387,"safe-buffer":494}],504:[function(require,module,exports){
  63280. "use strict";
  63281. var inherits = require('inherits');
  63282. var SHA512 = require('./sha512');
  63283. var Hash = require('./hash');
  63284. var Buffer = require('safe-buffer').Buffer;
  63285. var W = new Array(160);
  63286. function Sha384() {
  63287. this.init();
  63288. this._w = W;
  63289. Hash.call(this, 128, 112);
  63290. }
  63291. inherits(Sha384, SHA512);
  63292. Sha384.prototype.init = function () {
  63293. this._ah = 0xcbbb9d5d;
  63294. this._bh = 0x629a292a;
  63295. this._ch = 0x9159015a;
  63296. this._dh = 0x152fecd8;
  63297. this._eh = 0x67332667;
  63298. this._fh = 0x8eb44a87;
  63299. this._gh = 0xdb0c2e0d;
  63300. this._hh = 0x47b5481d;
  63301. this._al = 0xc1059ed8;
  63302. this._bl = 0x367cd507;
  63303. this._cl = 0x3070dd17;
  63304. this._dl = 0xf70e5939;
  63305. this._el = 0xffc00b31;
  63306. this._fl = 0x68581511;
  63307. this._gl = 0x64f98fa7;
  63308. this._hl = 0xbefa4fa4;
  63309. return this;
  63310. };
  63311. Sha384.prototype._hash = function () {
  63312. var H = Buffer.allocUnsafe(48);
  63313. function writeInt64BE(h, l, offset) {
  63314. H.writeInt32BE(h, offset);
  63315. H.writeInt32BE(l, offset + 4);
  63316. }
  63317. writeInt64BE(this._ah, this._al, 0);
  63318. writeInt64BE(this._bh, this._bl, 8);
  63319. writeInt64BE(this._ch, this._cl, 16);
  63320. writeInt64BE(this._dh, this._dl, 24);
  63321. writeInt64BE(this._eh, this._el, 32);
  63322. writeInt64BE(this._fh, this._fl, 40);
  63323. return H;
  63324. };
  63325. module.exports = Sha384;
  63326. },{"./hash":498,"./sha512":505,"inherits":387,"safe-buffer":494}],505:[function(require,module,exports){
  63327. "use strict";
  63328. var inherits = require('inherits');
  63329. var Hash = require('./hash');
  63330. var Buffer = require('safe-buffer').Buffer;
  63331. 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];
  63332. var W = new Array(160);
  63333. function Sha512() {
  63334. this.init();
  63335. this._w = W;
  63336. Hash.call(this, 128, 112);
  63337. }
  63338. inherits(Sha512, Hash);
  63339. Sha512.prototype.init = function () {
  63340. this._ah = 0x6a09e667;
  63341. this._bh = 0xbb67ae85;
  63342. this._ch = 0x3c6ef372;
  63343. this._dh = 0xa54ff53a;
  63344. this._eh = 0x510e527f;
  63345. this._fh = 0x9b05688c;
  63346. this._gh = 0x1f83d9ab;
  63347. this._hh = 0x5be0cd19;
  63348. this._al = 0xf3bcc908;
  63349. this._bl = 0x84caa73b;
  63350. this._cl = 0xfe94f82b;
  63351. this._dl = 0x5f1d36f1;
  63352. this._el = 0xade682d1;
  63353. this._fl = 0x2b3e6c1f;
  63354. this._gl = 0xfb41bd6b;
  63355. this._hl = 0x137e2179;
  63356. return this;
  63357. };
  63358. function Ch(x, y, z) {
  63359. return z ^ x & (y ^ z);
  63360. }
  63361. function maj(x, y, z) {
  63362. return x & y | z & (x | y);
  63363. }
  63364. function sigma0(x, xl) {
  63365. return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25);
  63366. }
  63367. function sigma1(x, xl) {
  63368. return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23);
  63369. }
  63370. function Gamma0(x, xl) {
  63371. return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ x >>> 7;
  63372. }
  63373. function Gamma0l(x, xl) {
  63374. return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25);
  63375. }
  63376. function Gamma1(x, xl) {
  63377. return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ x >>> 6;
  63378. }
  63379. function Gamma1l(x, xl) {
  63380. return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26);
  63381. }
  63382. function getCarry(a, b) {
  63383. return a >>> 0 < b >>> 0 ? 1 : 0;
  63384. }
  63385. Sha512.prototype._update = function (M) {
  63386. var W = this._w;
  63387. var ah = this._ah | 0;
  63388. var bh = this._bh | 0;
  63389. var ch = this._ch | 0;
  63390. var dh = this._dh | 0;
  63391. var eh = this._eh | 0;
  63392. var fh = this._fh | 0;
  63393. var gh = this._gh | 0;
  63394. var hh = this._hh | 0;
  63395. var al = this._al | 0;
  63396. var bl = this._bl | 0;
  63397. var cl = this._cl | 0;
  63398. var dl = this._dl | 0;
  63399. var el = this._el | 0;
  63400. var fl = this._fl | 0;
  63401. var gl = this._gl | 0;
  63402. var hl = this._hl | 0;
  63403. for (var i = 0; i < 32; i += 2) {
  63404. W[i] = M.readInt32BE(i * 4);
  63405. W[i + 1] = M.readInt32BE(i * 4 + 4);
  63406. }
  63407. for (; i < 160; i += 2) {
  63408. var xh = W[i - 15 * 2];
  63409. var xl = W[i - 15 * 2 + 1];
  63410. var gamma0 = Gamma0(xh, xl);
  63411. var gamma0l = Gamma0l(xl, xh);
  63412. xh = W[i - 2 * 2];
  63413. xl = W[i - 2 * 2 + 1];
  63414. var gamma1 = Gamma1(xh, xl);
  63415. var gamma1l = Gamma1l(xl, xh); // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
  63416. var Wi7h = W[i - 7 * 2];
  63417. var Wi7l = W[i - 7 * 2 + 1];
  63418. var Wi16h = W[i - 16 * 2];
  63419. var Wi16l = W[i - 16 * 2 + 1];
  63420. var Wil = gamma0l + Wi7l | 0;
  63421. var Wih = gamma0 + Wi7h + getCarry(Wil, gamma0l) | 0;
  63422. Wil = Wil + gamma1l | 0;
  63423. Wih = Wih + gamma1 + getCarry(Wil, gamma1l) | 0;
  63424. Wil = Wil + Wi16l | 0;
  63425. Wih = Wih + Wi16h + getCarry(Wil, Wi16l) | 0;
  63426. W[i] = Wih;
  63427. W[i + 1] = Wil;
  63428. }
  63429. for (var j = 0; j < 160; j += 2) {
  63430. Wih = W[j];
  63431. Wil = W[j + 1];
  63432. var majh = maj(ah, bh, ch);
  63433. var majl = maj(al, bl, cl);
  63434. var sigma0h = sigma0(ah, al);
  63435. var sigma0l = sigma0(al, ah);
  63436. var sigma1h = sigma1(eh, el);
  63437. var sigma1l = sigma1(el, eh); // t1 = h + sigma1 + ch + K[j] + W[j]
  63438. var Kih = K[j];
  63439. var Kil = K[j + 1];
  63440. var chh = Ch(eh, fh, gh);
  63441. var chl = Ch(el, fl, gl);
  63442. var t1l = hl + sigma1l | 0;
  63443. var t1h = hh + sigma1h + getCarry(t1l, hl) | 0;
  63444. t1l = t1l + chl | 0;
  63445. t1h = t1h + chh + getCarry(t1l, chl) | 0;
  63446. t1l = t1l + Kil | 0;
  63447. t1h = t1h + Kih + getCarry(t1l, Kil) | 0;
  63448. t1l = t1l + Wil | 0;
  63449. t1h = t1h + Wih + getCarry(t1l, Wil) | 0; // t2 = sigma0 + maj
  63450. var t2l = sigma0l + majl | 0;
  63451. var t2h = sigma0h + majh + getCarry(t2l, sigma0l) | 0;
  63452. hh = gh;
  63453. hl = gl;
  63454. gh = fh;
  63455. gl = fl;
  63456. fh = eh;
  63457. fl = el;
  63458. el = dl + t1l | 0;
  63459. eh = dh + t1h + getCarry(el, dl) | 0;
  63460. dh = ch;
  63461. dl = cl;
  63462. ch = bh;
  63463. cl = bl;
  63464. bh = ah;
  63465. bl = al;
  63466. al = t1l + t2l | 0;
  63467. ah = t1h + t2h + getCarry(al, t1l) | 0;
  63468. }
  63469. this._al = this._al + al | 0;
  63470. this._bl = this._bl + bl | 0;
  63471. this._cl = this._cl + cl | 0;
  63472. this._dl = this._dl + dl | 0;
  63473. this._el = this._el + el | 0;
  63474. this._fl = this._fl + fl | 0;
  63475. this._gl = this._gl + gl | 0;
  63476. this._hl = this._hl + hl | 0;
  63477. this._ah = this._ah + ah + getCarry(this._al, al) | 0;
  63478. this._bh = this._bh + bh + getCarry(this._bl, bl) | 0;
  63479. this._ch = this._ch + ch + getCarry(this._cl, cl) | 0;
  63480. this._dh = this._dh + dh + getCarry(this._dl, dl) | 0;
  63481. this._eh = this._eh + eh + getCarry(this._el, el) | 0;
  63482. this._fh = this._fh + fh + getCarry(this._fl, fl) | 0;
  63483. this._gh = this._gh + gh + getCarry(this._gl, gl) | 0;
  63484. this._hh = this._hh + hh + getCarry(this._hl, hl) | 0;
  63485. };
  63486. Sha512.prototype._hash = function () {
  63487. var H = Buffer.allocUnsafe(64);
  63488. function writeInt64BE(h, l, offset) {
  63489. H.writeInt32BE(h, offset);
  63490. H.writeInt32BE(l, offset + 4);
  63491. }
  63492. writeInt64BE(this._ah, this._al, 0);
  63493. writeInt64BE(this._bh, this._bl, 8);
  63494. writeInt64BE(this._ch, this._cl, 16);
  63495. writeInt64BE(this._dh, this._dl, 24);
  63496. writeInt64BE(this._eh, this._el, 32);
  63497. writeInt64BE(this._fh, this._fl, 40);
  63498. writeInt64BE(this._gh, this._gl, 48);
  63499. writeInt64BE(this._hh, this._hl, 56);
  63500. return H;
  63501. };
  63502. module.exports = Sha512;
  63503. },{"./hash":498,"inherits":387,"safe-buffer":494}],506:[function(require,module,exports){
  63504. "use strict";
  63505. // Copyright Joyent, Inc. and other Node contributors.
  63506. //
  63507. // Permission is hereby granted, free of charge, to any person obtaining a
  63508. // copy of this software and associated documentation files (the
  63509. // "Software"), to deal in the Software without restriction, including
  63510. // without limitation the rights to use, copy, modify, merge, publish,
  63511. // distribute, sublicense, and/or sell copies of the Software, and to permit
  63512. // persons to whom the Software is furnished to do so, subject to the
  63513. // following conditions:
  63514. //
  63515. // The above copyright notice and this permission notice shall be included
  63516. // in all copies or substantial portions of the Software.
  63517. //
  63518. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  63519. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  63520. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  63521. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  63522. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  63523. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  63524. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  63525. module.exports = Stream;
  63526. var EE = require('events').EventEmitter;
  63527. var inherits = require('inherits');
  63528. inherits(Stream, EE);
  63529. Stream.Readable = require('readable-stream/readable.js');
  63530. Stream.Writable = require('readable-stream/writable.js');
  63531. Stream.Duplex = require('readable-stream/duplex.js');
  63532. Stream.Transform = require('readable-stream/transform.js');
  63533. Stream.PassThrough = require('readable-stream/passthrough.js'); // Backwards-compat with node 0.4.x
  63534. Stream.Stream = Stream; // old-style streams. Note that the pipe method (the only relevant
  63535. // part of this class) is overridden in the Readable class.
  63536. function Stream() {
  63537. EE.call(this);
  63538. }
  63539. Stream.prototype.pipe = function (dest, options) {
  63540. var source = this;
  63541. function ondata(chunk) {
  63542. if (dest.writable) {
  63543. if (false === dest.write(chunk) && source.pause) {
  63544. source.pause();
  63545. }
  63546. }
  63547. }
  63548. source.on('data', ondata);
  63549. function ondrain() {
  63550. if (source.readable && source.resume) {
  63551. source.resume();
  63552. }
  63553. }
  63554. dest.on('drain', ondrain); // If the 'end' option is not supplied, dest.end() will be called when
  63555. // source gets the 'end' or 'close' events. Only dest.end() once.
  63556. if (!dest._isStdio && (!options || options.end !== false)) {
  63557. source.on('end', onend);
  63558. source.on('close', onclose);
  63559. }
  63560. var didOnEnd = false;
  63561. function onend() {
  63562. if (didOnEnd) return;
  63563. didOnEnd = true;
  63564. dest.end();
  63565. }
  63566. function onclose() {
  63567. if (didOnEnd) return;
  63568. didOnEnd = true;
  63569. if (typeof dest.destroy === 'function') dest.destroy();
  63570. } // don't leave dangling pipes when there are errors.
  63571. function onerror(er) {
  63572. cleanup();
  63573. if (EE.listenerCount(this, 'error') === 0) {
  63574. throw er; // Unhandled stream error in pipe.
  63575. }
  63576. }
  63577. source.on('error', onerror);
  63578. dest.on('error', onerror); // remove all the event listeners that were added.
  63579. function cleanup() {
  63580. source.removeListener('data', ondata);
  63581. dest.removeListener('drain', ondrain);
  63582. source.removeListener('end', onend);
  63583. source.removeListener('close', onclose);
  63584. source.removeListener('error', onerror);
  63585. dest.removeListener('error', onerror);
  63586. source.removeListener('end', cleanup);
  63587. source.removeListener('close', cleanup);
  63588. dest.removeListener('close', cleanup);
  63589. }
  63590. source.on('end', cleanup);
  63591. source.on('close', cleanup);
  63592. dest.on('close', cleanup);
  63593. dest.emit('pipe', source); // Allow for unix-like usage: A.pipe(B).pipe(C)
  63594. return dest;
  63595. };
  63596. },{"events":367,"inherits":387,"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}],507:[function(require,module,exports){
  63597. "use strict";
  63598. module.exports = require('./lib/_stream_duplex.js');
  63599. },{"./lib/_stream_duplex.js":508}],508:[function(require,module,exports){
  63600. // Copyright Joyent, Inc. and other Node contributors.
  63601. //
  63602. // Permission is hereby granted, free of charge, to any person obtaining a
  63603. // copy of this software and associated documentation files (the
  63604. // "Software"), to deal in the Software without restriction, including
  63605. // without limitation the rights to use, copy, modify, merge, publish,
  63606. // distribute, sublicense, and/or sell copies of the Software, and to permit
  63607. // persons to whom the Software is furnished to do so, subject to the
  63608. // following conditions:
  63609. //
  63610. // The above copyright notice and this permission notice shall be included
  63611. // in all copies or substantial portions of the Software.
  63612. //
  63613. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  63614. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  63615. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  63616. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  63617. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  63618. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  63619. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  63620. // a duplex stream is just a stream that is both readable and writable.
  63621. // Since JS doesn't have multiple prototypal inheritance, this class
  63622. // prototypally inherits from Readable, and then parasitically from
  63623. // Writable.
  63624. 'use strict';
  63625. /*<replacement>*/
  63626. var pna = require('process-nextick-args');
  63627. /*</replacement>*/
  63628. /*<replacement>*/
  63629. var objectKeys = Object.keys || function (obj) {
  63630. var keys = [];
  63631. for (var key in obj) {
  63632. keys.push(key);
  63633. }
  63634. return keys;
  63635. };
  63636. /*</replacement>*/
  63637. module.exports = Duplex;
  63638. /*<replacement>*/
  63639. var util = Object.create(require('core-util-is'));
  63640. util.inherits = require('inherits');
  63641. /*</replacement>*/
  63642. var Readable = require('./_stream_readable');
  63643. var Writable = require('./_stream_writable');
  63644. util.inherits(Duplex, Readable);
  63645. {
  63646. // avoid scope creep, the keys array can then be collected
  63647. var keys = objectKeys(Writable.prototype);
  63648. for (var v = 0; v < keys.length; v++) {
  63649. var method = keys[v];
  63650. if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
  63651. }
  63652. }
  63653. function Duplex(options) {
  63654. if (!(this instanceof Duplex)) return new Duplex(options);
  63655. Readable.call(this, options);
  63656. Writable.call(this, options);
  63657. if (options && options.readable === false) this.readable = false;
  63658. if (options && options.writable === false) this.writable = false;
  63659. this.allowHalfOpen = true;
  63660. if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
  63661. this.once('end', onend);
  63662. }
  63663. Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
  63664. // making it explicit this property is not enumerable
  63665. // because otherwise some prototype manipulation in
  63666. // userland will fail
  63667. enumerable: false,
  63668. get: function get() {
  63669. return this._writableState.highWaterMark;
  63670. }
  63671. }); // the no-half-open enforcer
  63672. function onend() {
  63673. // if we allow half-open state, or if the writable side ended,
  63674. // then we're ok.
  63675. if (this.allowHalfOpen || this._writableState.ended) return; // no more data can be written.
  63676. // But allow more writes to happen in this tick.
  63677. pna.nextTick(onEndNT, this);
  63678. }
  63679. function onEndNT(self) {
  63680. self.end();
  63681. }
  63682. Object.defineProperty(Duplex.prototype, 'destroyed', {
  63683. get: function get() {
  63684. if (this._readableState === undefined || this._writableState === undefined) {
  63685. return false;
  63686. }
  63687. return this._readableState.destroyed && this._writableState.destroyed;
  63688. },
  63689. set: function set(value) {
  63690. // we ignore the value if the stream
  63691. // has not been initialized yet
  63692. if (this._readableState === undefined || this._writableState === undefined) {
  63693. return;
  63694. } // backward compatibility, the user is explicitly
  63695. // managing destroyed
  63696. this._readableState.destroyed = value;
  63697. this._writableState.destroyed = value;
  63698. }
  63699. });
  63700. Duplex.prototype._destroy = function (err, cb) {
  63701. this.push(null);
  63702. this.end();
  63703. pna.nextTick(cb, err);
  63704. };
  63705. },{"./_stream_readable":510,"./_stream_writable":512,"core-util-is":328,"inherits":387,"process-nextick-args":466}],509:[function(require,module,exports){
  63706. // Copyright Joyent, Inc. and other Node contributors.
  63707. //
  63708. // Permission is hereby granted, free of charge, to any person obtaining a
  63709. // copy of this software and associated documentation files (the
  63710. // "Software"), to deal in the Software without restriction, including
  63711. // without limitation the rights to use, copy, modify, merge, publish,
  63712. // distribute, sublicense, and/or sell copies of the Software, and to permit
  63713. // persons to whom the Software is furnished to do so, subject to the
  63714. // following conditions:
  63715. //
  63716. // The above copyright notice and this permission notice shall be included
  63717. // in all copies or substantial portions of the Software.
  63718. //
  63719. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  63720. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  63721. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  63722. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  63723. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  63724. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  63725. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  63726. // a passthrough stream.
  63727. // basically just the most minimal sort of Transform stream.
  63728. // Every written chunk gets output as-is.
  63729. 'use strict';
  63730. module.exports = PassThrough;
  63731. var Transform = require('./_stream_transform');
  63732. /*<replacement>*/
  63733. var util = Object.create(require('core-util-is'));
  63734. util.inherits = require('inherits');
  63735. /*</replacement>*/
  63736. util.inherits(PassThrough, Transform);
  63737. function PassThrough(options) {
  63738. if (!(this instanceof PassThrough)) return new PassThrough(options);
  63739. Transform.call(this, options);
  63740. }
  63741. PassThrough.prototype._transform = function (chunk, encoding, cb) {
  63742. cb(null, chunk);
  63743. };
  63744. },{"./_stream_transform":511,"core-util-is":328,"inherits":387}],510:[function(require,module,exports){
  63745. (function (process,global){
  63746. // Copyright Joyent, Inc. and other Node contributors.
  63747. //
  63748. // Permission is hereby granted, free of charge, to any person obtaining a
  63749. // copy of this software and associated documentation files (the
  63750. // "Software"), to deal in the Software without restriction, including
  63751. // without limitation the rights to use, copy, modify, merge, publish,
  63752. // distribute, sublicense, and/or sell copies of the Software, and to permit
  63753. // persons to whom the Software is furnished to do so, subject to the
  63754. // following conditions:
  63755. //
  63756. // The above copyright notice and this permission notice shall be included
  63757. // in all copies or substantial portions of the Software.
  63758. //
  63759. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  63760. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  63761. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  63762. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  63763. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  63764. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  63765. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  63766. 'use strict';
  63767. /*<replacement>*/
  63768. var pna = require('process-nextick-args');
  63769. /*</replacement>*/
  63770. module.exports = Readable;
  63771. /*<replacement>*/
  63772. var isArray = require('isarray');
  63773. /*</replacement>*/
  63774. /*<replacement>*/
  63775. var Duplex;
  63776. /*</replacement>*/
  63777. Readable.ReadableState = ReadableState;
  63778. /*<replacement>*/
  63779. var EE = require('events').EventEmitter;
  63780. var EElistenerCount = function EElistenerCount(emitter, type) {
  63781. return emitter.listeners(type).length;
  63782. };
  63783. /*</replacement>*/
  63784. /*<replacement>*/
  63785. var Stream = require('./internal/streams/stream');
  63786. /*</replacement>*/
  63787. /*<replacement>*/
  63788. var Buffer = require('safe-buffer').Buffer;
  63789. var OurUint8Array = global.Uint8Array || function () {};
  63790. function _uint8ArrayToBuffer(chunk) {
  63791. return Buffer.from(chunk);
  63792. }
  63793. function _isUint8Array(obj) {
  63794. return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
  63795. }
  63796. /*</replacement>*/
  63797. /*<replacement>*/
  63798. var util = Object.create(require('core-util-is'));
  63799. util.inherits = require('inherits');
  63800. /*</replacement>*/
  63801. /*<replacement>*/
  63802. var debugUtil = require('util');
  63803. var debug = void 0;
  63804. if (debugUtil && debugUtil.debuglog) {
  63805. debug = debugUtil.debuglog('stream');
  63806. } else {
  63807. debug = function debug() {};
  63808. }
  63809. /*</replacement>*/
  63810. var BufferList = require('./internal/streams/BufferList');
  63811. var destroyImpl = require('./internal/streams/destroy');
  63812. var StringDecoder;
  63813. util.inherits(Readable, Stream);
  63814. var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
  63815. function prependListener(emitter, event, fn) {
  63816. // Sadly this is not cacheable as some libraries bundle their own
  63817. // event emitter implementation with them.
  63818. if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn); // This is a hack to make sure that our error handler is attached before any
  63819. // userland ones. NEVER DO THIS. This is here only because this code needs
  63820. // to continue to work with older versions of Node.js that do not include
  63821. // the prependListener() method. The goal is to eventually remove this hack.
  63822. 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]];
  63823. }
  63824. function ReadableState(options, stream) {
  63825. Duplex = Duplex || require('./_stream_duplex');
  63826. options = options || {}; // Duplex streams are both readable and writable, but share
  63827. // the same options object.
  63828. // However, some cases require setting options to different
  63829. // values for the readable and the writable sides of the duplex stream.
  63830. // These options can be provided separately as readableXXX and writableXXX.
  63831. var isDuplex = stream instanceof Duplex; // object stream flag. Used to make read(n) ignore n and to
  63832. // make all the buffer merging and length checks go away
  63833. this.objectMode = !!options.objectMode;
  63834. if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode; // the point at which it stops calling _read() to fill the buffer
  63835. // Note: 0 is a valid value, means "don't call _read preemptively ever"
  63836. var hwm = options.highWaterMark;
  63837. var readableHwm = options.readableHighWaterMark;
  63838. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  63839. if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (readableHwm || readableHwm === 0)) this.highWaterMark = readableHwm;else this.highWaterMark = defaultHwm; // cast to ints.
  63840. this.highWaterMark = Math.floor(this.highWaterMark); // A linked list is used to store data chunks instead of an array because the
  63841. // linked list can remove elements from the beginning faster than
  63842. // array.shift()
  63843. this.buffer = new BufferList();
  63844. this.length = 0;
  63845. this.pipes = null;
  63846. this.pipesCount = 0;
  63847. this.flowing = null;
  63848. this.ended = false;
  63849. this.endEmitted = false;
  63850. this.reading = false; // a flag to be able to tell if the event 'readable'/'data' is emitted
  63851. // immediately, or on a later tick. We set this to true at first, because
  63852. // any actions that shouldn't happen until "later" should generally also
  63853. // not happen before the first read call.
  63854. this.sync = true; // whenever we return null, then we set a flag to say
  63855. // that we're awaiting a 'readable' event emission.
  63856. this.needReadable = false;
  63857. this.emittedReadable = false;
  63858. this.readableListening = false;
  63859. this.resumeScheduled = false; // has it been destroyed
  63860. this.destroyed = false; // Crypto is kind of old and crusty. Historically, its default string
  63861. // encoding is 'binary' so we have to make this configurable.
  63862. // Everything else in the universe uses 'utf8', though.
  63863. this.defaultEncoding = options.defaultEncoding || 'utf8'; // the number of writers that are awaiting a drain event in .pipe()s
  63864. this.awaitDrain = 0; // if true, a maybeReadMore has been scheduled
  63865. this.readingMore = false;
  63866. this.decoder = null;
  63867. this.encoding = null;
  63868. if (options.encoding) {
  63869. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  63870. this.decoder = new StringDecoder(options.encoding);
  63871. this.encoding = options.encoding;
  63872. }
  63873. }
  63874. function Readable(options) {
  63875. Duplex = Duplex || require('./_stream_duplex');
  63876. if (!(this instanceof Readable)) return new Readable(options);
  63877. this._readableState = new ReadableState(options, this); // legacy
  63878. this.readable = true;
  63879. if (options) {
  63880. if (typeof options.read === 'function') this._read = options.read;
  63881. if (typeof options.destroy === 'function') this._destroy = options.destroy;
  63882. }
  63883. Stream.call(this);
  63884. }
  63885. Object.defineProperty(Readable.prototype, 'destroyed', {
  63886. get: function get() {
  63887. if (this._readableState === undefined) {
  63888. return false;
  63889. }
  63890. return this._readableState.destroyed;
  63891. },
  63892. set: function set(value) {
  63893. // we ignore the value if the stream
  63894. // has not been initialized yet
  63895. if (!this._readableState) {
  63896. return;
  63897. } // backward compatibility, the user is explicitly
  63898. // managing destroyed
  63899. this._readableState.destroyed = value;
  63900. }
  63901. });
  63902. Readable.prototype.destroy = destroyImpl.destroy;
  63903. Readable.prototype._undestroy = destroyImpl.undestroy;
  63904. Readable.prototype._destroy = function (err, cb) {
  63905. this.push(null);
  63906. cb(err);
  63907. }; // Manually shove something into the read() buffer.
  63908. // This returns true if the highWaterMark has not been hit yet,
  63909. // similar to how Writable.write() returns true if you should
  63910. // write() some more.
  63911. Readable.prototype.push = function (chunk, encoding) {
  63912. var state = this._readableState;
  63913. var skipChunkCheck;
  63914. if (!state.objectMode) {
  63915. if (typeof chunk === 'string') {
  63916. encoding = encoding || state.defaultEncoding;
  63917. if (encoding !== state.encoding) {
  63918. chunk = Buffer.from(chunk, encoding);
  63919. encoding = '';
  63920. }
  63921. skipChunkCheck = true;
  63922. }
  63923. } else {
  63924. skipChunkCheck = true;
  63925. }
  63926. return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
  63927. }; // Unshift should *always* be something directly out of read()
  63928. Readable.prototype.unshift = function (chunk) {
  63929. return readableAddChunk(this, chunk, null, true, false);
  63930. };
  63931. function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
  63932. var state = stream._readableState;
  63933. if (chunk === null) {
  63934. state.reading = false;
  63935. onEofChunk(stream, state);
  63936. } else {
  63937. var er;
  63938. if (!skipChunkCheck) er = chunkInvalid(state, chunk);
  63939. if (er) {
  63940. stream.emit('error', er);
  63941. } else if (state.objectMode || chunk && chunk.length > 0) {
  63942. if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
  63943. chunk = _uint8ArrayToBuffer(chunk);
  63944. }
  63945. if (addToFront) {
  63946. if (state.endEmitted) stream.emit('error', new Error('stream.unshift() after end event'));else addChunk(stream, state, chunk, true);
  63947. } else if (state.ended) {
  63948. stream.emit('error', new Error('stream.push() after EOF'));
  63949. } else {
  63950. state.reading = false;
  63951. if (state.decoder && !encoding) {
  63952. chunk = state.decoder.write(chunk);
  63953. if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
  63954. } else {
  63955. addChunk(stream, state, chunk, false);
  63956. }
  63957. }
  63958. } else if (!addToFront) {
  63959. state.reading = false;
  63960. }
  63961. }
  63962. return needMoreData(state);
  63963. }
  63964. function addChunk(stream, state, chunk, addToFront) {
  63965. if (state.flowing && state.length === 0 && !state.sync) {
  63966. stream.emit('data', chunk);
  63967. stream.read(0);
  63968. } else {
  63969. // update the buffer info.
  63970. state.length += state.objectMode ? 1 : chunk.length;
  63971. if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
  63972. if (state.needReadable) emitReadable(stream);
  63973. }
  63974. maybeReadMore(stream, state);
  63975. }
  63976. function chunkInvalid(state, chunk) {
  63977. var er;
  63978. if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
  63979. er = new TypeError('Invalid non-string/buffer chunk');
  63980. }
  63981. return er;
  63982. } // if it's past the high water mark, we can push in some more.
  63983. // Also, if we have no data yet, we can stand some
  63984. // more bytes. This is to work around cases where hwm=0,
  63985. // such as the repl. Also, if the push() triggered a
  63986. // readable event, and the user called read(largeNumber) such that
  63987. // needReadable was set, then we ought to push more, so that another
  63988. // 'readable' event will be triggered.
  63989. function needMoreData(state) {
  63990. return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
  63991. }
  63992. Readable.prototype.isPaused = function () {
  63993. return this._readableState.flowing === false;
  63994. }; // backwards compatibility.
  63995. Readable.prototype.setEncoding = function (enc) {
  63996. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  63997. this._readableState.decoder = new StringDecoder(enc);
  63998. this._readableState.encoding = enc;
  63999. return this;
  64000. }; // Don't raise the hwm > 8MB
  64001. var MAX_HWM = 0x800000;
  64002. function computeNewHighWaterMark(n) {
  64003. if (n >= MAX_HWM) {
  64004. n = MAX_HWM;
  64005. } else {
  64006. // Get the next highest power of 2 to prevent increasing hwm excessively in
  64007. // tiny amounts
  64008. n--;
  64009. n |= n >>> 1;
  64010. n |= n >>> 2;
  64011. n |= n >>> 4;
  64012. n |= n >>> 8;
  64013. n |= n >>> 16;
  64014. n++;
  64015. }
  64016. return n;
  64017. } // This function is designed to be inlinable, so please take care when making
  64018. // changes to the function body.
  64019. function howMuchToRead(n, state) {
  64020. if (n <= 0 || state.length === 0 && state.ended) return 0;
  64021. if (state.objectMode) return 1;
  64022. if (n !== n) {
  64023. // Only flow one buffer at a time
  64024. if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
  64025. } // If we're asking for more than the current hwm, then raise the hwm.
  64026. if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
  64027. if (n <= state.length) return n; // Don't have enough
  64028. if (!state.ended) {
  64029. state.needReadable = true;
  64030. return 0;
  64031. }
  64032. return state.length;
  64033. } // you can override either this method, or the async _read(n) below.
  64034. Readable.prototype.read = function (n) {
  64035. debug('read', n);
  64036. n = parseInt(n, 10);
  64037. var state = this._readableState;
  64038. var nOrig = n;
  64039. if (n !== 0) state.emittedReadable = false; // if we're doing read(0) to trigger a readable event, but we
  64040. // already have a bunch of data in the buffer, then just trigger
  64041. // the 'readable' event and move on.
  64042. if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
  64043. debug('read: emitReadable', state.length, state.ended);
  64044. if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
  64045. return null;
  64046. }
  64047. n = howMuchToRead(n, state); // if we've ended, and we're now clear, then finish it up.
  64048. if (n === 0 && state.ended) {
  64049. if (state.length === 0) endReadable(this);
  64050. return null;
  64051. } // All the actual chunk generation logic needs to be
  64052. // *below* the call to _read. The reason is that in certain
  64053. // synthetic stream cases, such as passthrough streams, _read
  64054. // may be a completely synchronous operation which may change
  64055. // the state of the read buffer, providing enough data when
  64056. // before there was *not* enough.
  64057. //
  64058. // So, the steps are:
  64059. // 1. Figure out what the state of things will be after we do
  64060. // a read from the buffer.
  64061. //
  64062. // 2. If that resulting state will trigger a _read, then call _read.
  64063. // Note that this may be asynchronous, or synchronous. Yes, it is
  64064. // deeply ugly to write APIs this way, but that still doesn't mean
  64065. // that the Readable class should behave improperly, as streams are
  64066. // designed to be sync/async agnostic.
  64067. // Take note if the _read call is sync or async (ie, if the read call
  64068. // has returned yet), so that we know whether or not it's safe to emit
  64069. // 'readable' etc.
  64070. //
  64071. // 3. Actually pull the requested chunks out of the buffer and return.
  64072. // if we need a readable event, then we need to do some reading.
  64073. var doRead = state.needReadable;
  64074. debug('need readable', doRead); // if we currently have less than the highWaterMark, then also read some
  64075. if (state.length === 0 || state.length - n < state.highWaterMark) {
  64076. doRead = true;
  64077. debug('length less than watermark', doRead);
  64078. } // however, if we've ended, then there's no point, and if we're already
  64079. // reading, then it's unnecessary.
  64080. if (state.ended || state.reading) {
  64081. doRead = false;
  64082. debug('reading or ended', doRead);
  64083. } else if (doRead) {
  64084. debug('do read');
  64085. state.reading = true;
  64086. state.sync = true; // if the length is currently zero, then we *need* a readable event.
  64087. if (state.length === 0) state.needReadable = true; // call internal read method
  64088. this._read(state.highWaterMark);
  64089. state.sync = false; // If _read pushed data synchronously, then `reading` will be false,
  64090. // and we need to re-evaluate how much data we can return to the user.
  64091. if (!state.reading) n = howMuchToRead(nOrig, state);
  64092. }
  64093. var ret;
  64094. if (n > 0) ret = fromList(n, state);else ret = null;
  64095. if (ret === null) {
  64096. state.needReadable = true;
  64097. n = 0;
  64098. } else {
  64099. state.length -= n;
  64100. }
  64101. if (state.length === 0) {
  64102. // If we have nothing in the buffer, then we want to know
  64103. // as soon as we *do* get something into the buffer.
  64104. if (!state.ended) state.needReadable = true; // If we tried to read() past the EOF, then emit end on the next tick.
  64105. if (nOrig !== n && state.ended) endReadable(this);
  64106. }
  64107. if (ret !== null) this.emit('data', ret);
  64108. return ret;
  64109. };
  64110. function onEofChunk(stream, state) {
  64111. if (state.ended) return;
  64112. if (state.decoder) {
  64113. var chunk = state.decoder.end();
  64114. if (chunk && chunk.length) {
  64115. state.buffer.push(chunk);
  64116. state.length += state.objectMode ? 1 : chunk.length;
  64117. }
  64118. }
  64119. state.ended = true; // emit 'readable' now to make sure it gets picked up.
  64120. emitReadable(stream);
  64121. } // Don't emit readable right away in sync mode, because this can trigger
  64122. // another read() call => stack overflow. This way, it might trigger
  64123. // a nextTick recursion warning, but that's not so bad.
  64124. function emitReadable(stream) {
  64125. var state = stream._readableState;
  64126. state.needReadable = false;
  64127. if (!state.emittedReadable) {
  64128. debug('emitReadable', state.flowing);
  64129. state.emittedReadable = true;
  64130. if (state.sync) pna.nextTick(emitReadable_, stream);else emitReadable_(stream);
  64131. }
  64132. }
  64133. function emitReadable_(stream) {
  64134. debug('emit readable');
  64135. stream.emit('readable');
  64136. flow(stream);
  64137. } // at this point, the user has presumably seen the 'readable' event,
  64138. // and called read() to consume some data. that may have triggered
  64139. // in turn another _read(n) call, in which case reading = true if
  64140. // it's in progress.
  64141. // However, if we're not ended, or reading, and the length < hwm,
  64142. // then go ahead and try to read some more preemptively.
  64143. function maybeReadMore(stream, state) {
  64144. if (!state.readingMore) {
  64145. state.readingMore = true;
  64146. pna.nextTick(maybeReadMore_, stream, state);
  64147. }
  64148. }
  64149. function maybeReadMore_(stream, state) {
  64150. var len = state.length;
  64151. while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
  64152. debug('maybeReadMore read 0');
  64153. stream.read(0);
  64154. if (len === state.length) // didn't get any data, stop spinning.
  64155. break;else len = state.length;
  64156. }
  64157. state.readingMore = false;
  64158. } // abstract method. to be overridden in specific implementation classes.
  64159. // call cb(er, data) where data is <= n in length.
  64160. // for virtual (non-string, non-buffer) streams, "length" is somewhat
  64161. // arbitrary, and perhaps not very meaningful.
  64162. Readable.prototype._read = function (n) {
  64163. this.emit('error', new Error('_read() is not implemented'));
  64164. };
  64165. Readable.prototype.pipe = function (dest, pipeOpts) {
  64166. var src = this;
  64167. var state = this._readableState;
  64168. switch (state.pipesCount) {
  64169. case 0:
  64170. state.pipes = dest;
  64171. break;
  64172. case 1:
  64173. state.pipes = [state.pipes, dest];
  64174. break;
  64175. default:
  64176. state.pipes.push(dest);
  64177. break;
  64178. }
  64179. state.pipesCount += 1;
  64180. debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
  64181. var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
  64182. var endFn = doEnd ? onend : unpipe;
  64183. if (state.endEmitted) pna.nextTick(endFn);else src.once('end', endFn);
  64184. dest.on('unpipe', onunpipe);
  64185. function onunpipe(readable, unpipeInfo) {
  64186. debug('onunpipe');
  64187. if (readable === src) {
  64188. if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
  64189. unpipeInfo.hasUnpiped = true;
  64190. cleanup();
  64191. }
  64192. }
  64193. }
  64194. function onend() {
  64195. debug('onend');
  64196. dest.end();
  64197. } // when the dest drains, it reduces the awaitDrain counter
  64198. // on the source. This would be more elegant with a .once()
  64199. // handler in flow(), but adding and removing repeatedly is
  64200. // too slow.
  64201. var ondrain = pipeOnDrain(src);
  64202. dest.on('drain', ondrain);
  64203. var cleanedUp = false;
  64204. function cleanup() {
  64205. debug('cleanup'); // cleanup event handlers once the pipe is broken
  64206. dest.removeListener('close', onclose);
  64207. dest.removeListener('finish', onfinish);
  64208. dest.removeListener('drain', ondrain);
  64209. dest.removeListener('error', onerror);
  64210. dest.removeListener('unpipe', onunpipe);
  64211. src.removeListener('end', onend);
  64212. src.removeListener('end', unpipe);
  64213. src.removeListener('data', ondata);
  64214. cleanedUp = true; // if the reader is waiting for a drain event from this
  64215. // specific writer, then it would cause it to never start
  64216. // flowing again.
  64217. // So, if this is awaiting a drain, then we just call it now.
  64218. // If we don't know, then assume that we are waiting for one.
  64219. if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
  64220. } // If the user pushes more data while we're writing to dest then we'll end up
  64221. // in ondata again. However, we only want to increase awaitDrain once because
  64222. // dest will only emit one 'drain' event for the multiple writes.
  64223. // => Introduce a guard on increasing awaitDrain.
  64224. var increasedAwaitDrain = false;
  64225. src.on('data', ondata);
  64226. function ondata(chunk) {
  64227. debug('ondata');
  64228. increasedAwaitDrain = false;
  64229. var ret = dest.write(chunk);
  64230. if (false === ret && !increasedAwaitDrain) {
  64231. // If the user unpiped during `dest.write()`, it is possible
  64232. // to get stuck in a permanently paused state if that write
  64233. // also returned false.
  64234. // => Check whether `dest` is still a piping destination.
  64235. if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
  64236. debug('false write response, pause', src._readableState.awaitDrain);
  64237. src._readableState.awaitDrain++;
  64238. increasedAwaitDrain = true;
  64239. }
  64240. src.pause();
  64241. }
  64242. } // if the dest has an error, then stop piping into it.
  64243. // however, don't suppress the throwing behavior for this.
  64244. function onerror(er) {
  64245. debug('onerror', er);
  64246. unpipe();
  64247. dest.removeListener('error', onerror);
  64248. if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
  64249. } // Make sure our error handler is attached before userland ones.
  64250. prependListener(dest, 'error', onerror); // Both close and finish should trigger unpipe, but only once.
  64251. function onclose() {
  64252. dest.removeListener('finish', onfinish);
  64253. unpipe();
  64254. }
  64255. dest.once('close', onclose);
  64256. function onfinish() {
  64257. debug('onfinish');
  64258. dest.removeListener('close', onclose);
  64259. unpipe();
  64260. }
  64261. dest.once('finish', onfinish);
  64262. function unpipe() {
  64263. debug('unpipe');
  64264. src.unpipe(dest);
  64265. } // tell the dest that it's being piped to
  64266. dest.emit('pipe', src); // start the flow if it hasn't been started already.
  64267. if (!state.flowing) {
  64268. debug('pipe resume');
  64269. src.resume();
  64270. }
  64271. return dest;
  64272. };
  64273. function pipeOnDrain(src) {
  64274. return function () {
  64275. var state = src._readableState;
  64276. debug('pipeOnDrain', state.awaitDrain);
  64277. if (state.awaitDrain) state.awaitDrain--;
  64278. if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
  64279. state.flowing = true;
  64280. flow(src);
  64281. }
  64282. };
  64283. }
  64284. Readable.prototype.unpipe = function (dest) {
  64285. var state = this._readableState;
  64286. var unpipeInfo = {
  64287. hasUnpiped: false
  64288. }; // if we're not piping anywhere, then do nothing.
  64289. if (state.pipesCount === 0) return this; // just one destination. most common case.
  64290. if (state.pipesCount === 1) {
  64291. // passed in one, but it's not the right one.
  64292. if (dest && dest !== state.pipes) return this;
  64293. if (!dest) dest = state.pipes; // got a match.
  64294. state.pipes = null;
  64295. state.pipesCount = 0;
  64296. state.flowing = false;
  64297. if (dest) dest.emit('unpipe', this, unpipeInfo);
  64298. return this;
  64299. } // slow case. multiple pipe destinations.
  64300. if (!dest) {
  64301. // remove all.
  64302. var dests = state.pipes;
  64303. var len = state.pipesCount;
  64304. state.pipes = null;
  64305. state.pipesCount = 0;
  64306. state.flowing = false;
  64307. for (var i = 0; i < len; i++) {
  64308. dests[i].emit('unpipe', this, unpipeInfo);
  64309. }
  64310. return this;
  64311. } // try to find the right one.
  64312. var index = indexOf(state.pipes, dest);
  64313. if (index === -1) return this;
  64314. state.pipes.splice(index, 1);
  64315. state.pipesCount -= 1;
  64316. if (state.pipesCount === 1) state.pipes = state.pipes[0];
  64317. dest.emit('unpipe', this, unpipeInfo);
  64318. return this;
  64319. }; // set up data events if they are asked for
  64320. // Ensure readable listeners eventually get something
  64321. Readable.prototype.on = function (ev, fn) {
  64322. var res = Stream.prototype.on.call(this, ev, fn);
  64323. if (ev === 'data') {
  64324. // Start flowing on next tick if stream isn't explicitly paused
  64325. if (this._readableState.flowing !== false) this.resume();
  64326. } else if (ev === 'readable') {
  64327. var state = this._readableState;
  64328. if (!state.endEmitted && !state.readableListening) {
  64329. state.readableListening = state.needReadable = true;
  64330. state.emittedReadable = false;
  64331. if (!state.reading) {
  64332. pna.nextTick(nReadingNextTick, this);
  64333. } else if (state.length) {
  64334. emitReadable(this);
  64335. }
  64336. }
  64337. }
  64338. return res;
  64339. };
  64340. Readable.prototype.addListener = Readable.prototype.on;
  64341. function nReadingNextTick(self) {
  64342. debug('readable nexttick read 0');
  64343. self.read(0);
  64344. } // pause() and resume() are remnants of the legacy readable stream API
  64345. // If the user uses them, then switch into old mode.
  64346. Readable.prototype.resume = function () {
  64347. var state = this._readableState;
  64348. if (!state.flowing) {
  64349. debug('resume');
  64350. state.flowing = true;
  64351. resume(this, state);
  64352. }
  64353. return this;
  64354. };
  64355. function resume(stream, state) {
  64356. if (!state.resumeScheduled) {
  64357. state.resumeScheduled = true;
  64358. pna.nextTick(resume_, stream, state);
  64359. }
  64360. }
  64361. function resume_(stream, state) {
  64362. if (!state.reading) {
  64363. debug('resume read 0');
  64364. stream.read(0);
  64365. }
  64366. state.resumeScheduled = false;
  64367. state.awaitDrain = 0;
  64368. stream.emit('resume');
  64369. flow(stream);
  64370. if (state.flowing && !state.reading) stream.read(0);
  64371. }
  64372. Readable.prototype.pause = function () {
  64373. debug('call pause flowing=%j', this._readableState.flowing);
  64374. if (false !== this._readableState.flowing) {
  64375. debug('pause');
  64376. this._readableState.flowing = false;
  64377. this.emit('pause');
  64378. }
  64379. return this;
  64380. };
  64381. function flow(stream) {
  64382. var state = stream._readableState;
  64383. debug('flow', state.flowing);
  64384. while (state.flowing && stream.read() !== null) {}
  64385. } // wrap an old-style stream as the async data source.
  64386. // This is *not* part of the readable stream interface.
  64387. // It is an ugly unfortunate mess of history.
  64388. Readable.prototype.wrap = function (stream) {
  64389. var _this = this;
  64390. var state = this._readableState;
  64391. var paused = false;
  64392. stream.on('end', function () {
  64393. debug('wrapped end');
  64394. if (state.decoder && !state.ended) {
  64395. var chunk = state.decoder.end();
  64396. if (chunk && chunk.length) _this.push(chunk);
  64397. }
  64398. _this.push(null);
  64399. });
  64400. stream.on('data', function (chunk) {
  64401. debug('wrapped data');
  64402. if (state.decoder) chunk = state.decoder.write(chunk); // don't skip over falsy values in objectMode
  64403. if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
  64404. var ret = _this.push(chunk);
  64405. if (!ret) {
  64406. paused = true;
  64407. stream.pause();
  64408. }
  64409. }); // proxy all the other methods.
  64410. // important when wrapping filters and duplexes.
  64411. for (var i in stream) {
  64412. if (this[i] === undefined && typeof stream[i] === 'function') {
  64413. this[i] = function (method) {
  64414. return function () {
  64415. return stream[method].apply(stream, arguments);
  64416. };
  64417. }(i);
  64418. }
  64419. } // proxy certain important events.
  64420. for (var n = 0; n < kProxyEvents.length; n++) {
  64421. stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
  64422. } // when we try to consume some more bytes, simply unpause the
  64423. // underlying stream.
  64424. this._read = function (n) {
  64425. debug('wrapped _read', n);
  64426. if (paused) {
  64427. paused = false;
  64428. stream.resume();
  64429. }
  64430. };
  64431. return this;
  64432. };
  64433. Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
  64434. // making it explicit this property is not enumerable
  64435. // because otherwise some prototype manipulation in
  64436. // userland will fail
  64437. enumerable: false,
  64438. get: function get() {
  64439. return this._readableState.highWaterMark;
  64440. }
  64441. }); // exposed for testing purposes only.
  64442. Readable._fromList = fromList; // Pluck off n bytes from an array of buffers.
  64443. // Length is the combined lengths of all the buffers in the list.
  64444. // This function is designed to be inlinable, so please take care when making
  64445. // changes to the function body.
  64446. function fromList(n, state) {
  64447. // nothing buffered
  64448. if (state.length === 0) return null;
  64449. var ret;
  64450. if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
  64451. // read it all, truncate the list
  64452. 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);
  64453. state.buffer.clear();
  64454. } else {
  64455. // read part of list
  64456. ret = fromListPartial(n, state.buffer, state.decoder);
  64457. }
  64458. return ret;
  64459. } // Extracts only enough buffered data to satisfy the amount requested.
  64460. // This function is designed to be inlinable, so please take care when making
  64461. // changes to the function body.
  64462. function fromListPartial(n, list, hasStrings) {
  64463. var ret;
  64464. if (n < list.head.data.length) {
  64465. // slice is the same for buffers and strings
  64466. ret = list.head.data.slice(0, n);
  64467. list.head.data = list.head.data.slice(n);
  64468. } else if (n === list.head.data.length) {
  64469. // first chunk is a perfect match
  64470. ret = list.shift();
  64471. } else {
  64472. // result spans more than one buffer
  64473. ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
  64474. }
  64475. return ret;
  64476. } // Copies a specified amount of characters from the list of buffered data
  64477. // chunks.
  64478. // This function is designed to be inlinable, so please take care when making
  64479. // changes to the function body.
  64480. function copyFromBufferString(n, list) {
  64481. var p = list.head;
  64482. var c = 1;
  64483. var ret = p.data;
  64484. n -= ret.length;
  64485. while (p = p.next) {
  64486. var str = p.data;
  64487. var nb = n > str.length ? str.length : n;
  64488. if (nb === str.length) ret += str;else ret += str.slice(0, n);
  64489. n -= nb;
  64490. if (n === 0) {
  64491. if (nb === str.length) {
  64492. ++c;
  64493. if (p.next) list.head = p.next;else list.head = list.tail = null;
  64494. } else {
  64495. list.head = p;
  64496. p.data = str.slice(nb);
  64497. }
  64498. break;
  64499. }
  64500. ++c;
  64501. }
  64502. list.length -= c;
  64503. return ret;
  64504. } // Copies a specified amount of bytes from the list of buffered data chunks.
  64505. // This function is designed to be inlinable, so please take care when making
  64506. // changes to the function body.
  64507. function copyFromBuffer(n, list) {
  64508. var ret = Buffer.allocUnsafe(n);
  64509. var p = list.head;
  64510. var c = 1;
  64511. p.data.copy(ret);
  64512. n -= p.data.length;
  64513. while (p = p.next) {
  64514. var buf = p.data;
  64515. var nb = n > buf.length ? buf.length : n;
  64516. buf.copy(ret, ret.length - n, 0, nb);
  64517. n -= nb;
  64518. if (n === 0) {
  64519. if (nb === buf.length) {
  64520. ++c;
  64521. if (p.next) list.head = p.next;else list.head = list.tail = null;
  64522. } else {
  64523. list.head = p;
  64524. p.data = buf.slice(nb);
  64525. }
  64526. break;
  64527. }
  64528. ++c;
  64529. }
  64530. list.length -= c;
  64531. return ret;
  64532. }
  64533. function endReadable(stream) {
  64534. var state = stream._readableState; // If we get here before consuming all the bytes, then that is a
  64535. // bug in node. Should never happen.
  64536. if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
  64537. if (!state.endEmitted) {
  64538. state.ended = true;
  64539. pna.nextTick(endReadableNT, state, stream);
  64540. }
  64541. }
  64542. function endReadableNT(state, stream) {
  64543. // Check that we didn't get one last unshift.
  64544. if (!state.endEmitted && state.length === 0) {
  64545. state.endEmitted = true;
  64546. stream.readable = false;
  64547. stream.emit('end');
  64548. }
  64549. }
  64550. function indexOf(xs, x) {
  64551. for (var i = 0, l = xs.length; i < l; i++) {
  64552. if (xs[i] === x) return i;
  64553. }
  64554. return -1;
  64555. }
  64556. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  64557. },{"./_stream_duplex":508,"./internal/streams/BufferList":513,"./internal/streams/destroy":514,"./internal/streams/stream":515,"_process":467,"core-util-is":328,"events":367,"inherits":387,"isarray":389,"process-nextick-args":466,"safe-buffer":494,"string_decoder/":520,"util":185}],511:[function(require,module,exports){
  64558. // Copyright Joyent, Inc. and other Node contributors.
  64559. //
  64560. // Permission is hereby granted, free of charge, to any person obtaining a
  64561. // copy of this software and associated documentation files (the
  64562. // "Software"), to deal in the Software without restriction, including
  64563. // without limitation the rights to use, copy, modify, merge, publish,
  64564. // distribute, sublicense, and/or sell copies of the Software, and to permit
  64565. // persons to whom the Software is furnished to do so, subject to the
  64566. // following conditions:
  64567. //
  64568. // The above copyright notice and this permission notice shall be included
  64569. // in all copies or substantial portions of the Software.
  64570. //
  64571. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  64572. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  64573. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  64574. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  64575. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  64576. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  64577. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  64578. // a transform stream is a readable/writable stream where you do
  64579. // something with the data. Sometimes it's called a "filter",
  64580. // but that's not a great name for it, since that implies a thing where
  64581. // some bits pass through, and others are simply ignored. (That would
  64582. // be a valid example of a transform, of course.)
  64583. //
  64584. // While the output is causally related to the input, it's not a
  64585. // necessarily symmetric or synchronous transformation. For example,
  64586. // a zlib stream might take multiple plain-text writes(), and then
  64587. // emit a single compressed chunk some time in the future.
  64588. //
  64589. // Here's how this works:
  64590. //
  64591. // The Transform stream has all the aspects of the readable and writable
  64592. // stream classes. When you write(chunk), that calls _write(chunk,cb)
  64593. // internally, and returns false if there's a lot of pending writes
  64594. // buffered up. When you call read(), that calls _read(n) until
  64595. // there's enough pending readable data buffered up.
  64596. //
  64597. // In a transform stream, the written data is placed in a buffer. When
  64598. // _read(n) is called, it transforms the queued up data, calling the
  64599. // buffered _write cb's as it consumes chunks. If consuming a single
  64600. // written chunk would result in multiple output chunks, then the first
  64601. // outputted bit calls the readcb, and subsequent chunks just go into
  64602. // the read buffer, and will cause it to emit 'readable' if necessary.
  64603. //
  64604. // This way, back-pressure is actually determined by the reading side,
  64605. // since _read has to be called to start processing a new chunk. However,
  64606. // a pathological inflate type of transform can cause excessive buffering
  64607. // here. For example, imagine a stream where every byte of input is
  64608. // interpreted as an integer from 0-255, and then results in that many
  64609. // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
  64610. // 1kb of data being output. In this case, you could write a very small
  64611. // amount of input, and end up with a very large amount of output. In
  64612. // such a pathological inflating mechanism, there'd be no way to tell
  64613. // the system to stop doing the transform. A single 4MB write could
  64614. // cause the system to run out of memory.
  64615. //
  64616. // However, even in such a pathological case, only a single written chunk
  64617. // would be consumed, and then the rest would wait (un-transformed) until
  64618. // the results of the previous transformed chunk were consumed.
  64619. 'use strict';
  64620. module.exports = Transform;
  64621. var Duplex = require('./_stream_duplex');
  64622. /*<replacement>*/
  64623. var util = Object.create(require('core-util-is'));
  64624. util.inherits = require('inherits');
  64625. /*</replacement>*/
  64626. util.inherits(Transform, Duplex);
  64627. function afterTransform(er, data) {
  64628. var ts = this._transformState;
  64629. ts.transforming = false;
  64630. var cb = ts.writecb;
  64631. if (!cb) {
  64632. return this.emit('error', new Error('write callback called multiple times'));
  64633. }
  64634. ts.writechunk = null;
  64635. ts.writecb = null;
  64636. if (data != null) // single equals check for both `null` and `undefined`
  64637. this.push(data);
  64638. cb(er);
  64639. var rs = this._readableState;
  64640. rs.reading = false;
  64641. if (rs.needReadable || rs.length < rs.highWaterMark) {
  64642. this._read(rs.highWaterMark);
  64643. }
  64644. }
  64645. function Transform(options) {
  64646. if (!(this instanceof Transform)) return new Transform(options);
  64647. Duplex.call(this, options);
  64648. this._transformState = {
  64649. afterTransform: afterTransform.bind(this),
  64650. needTransform: false,
  64651. transforming: false,
  64652. writecb: null,
  64653. writechunk: null,
  64654. writeencoding: null
  64655. }; // start out asking for a readable event once data is transformed.
  64656. this._readableState.needReadable = true; // we have implemented the _read method, and done the other things
  64657. // that Readable wants before the first _read call, so unset the
  64658. // sync guard flag.
  64659. this._readableState.sync = false;
  64660. if (options) {
  64661. if (typeof options.transform === 'function') this._transform = options.transform;
  64662. if (typeof options.flush === 'function') this._flush = options.flush;
  64663. } // When the writable side finishes, then flush out anything remaining.
  64664. this.on('prefinish', prefinish);
  64665. }
  64666. function prefinish() {
  64667. var _this = this;
  64668. if (typeof this._flush === 'function') {
  64669. this._flush(function (er, data) {
  64670. done(_this, er, data);
  64671. });
  64672. } else {
  64673. done(this, null, null);
  64674. }
  64675. }
  64676. Transform.prototype.push = function (chunk, encoding) {
  64677. this._transformState.needTransform = false;
  64678. return Duplex.prototype.push.call(this, chunk, encoding);
  64679. }; // This is the part where you do stuff!
  64680. // override this function in implementation classes.
  64681. // 'chunk' is an input chunk.
  64682. //
  64683. // Call `push(newChunk)` to pass along transformed output
  64684. // to the readable side. You may call 'push' zero or more times.
  64685. //
  64686. // Call `cb(err)` when you are done with this chunk. If you pass
  64687. // an error, then that'll put the hurt on the whole operation. If you
  64688. // never call cb(), then you'll never get another chunk.
  64689. Transform.prototype._transform = function (chunk, encoding, cb) {
  64690. throw new Error('_transform() is not implemented');
  64691. };
  64692. Transform.prototype._write = function (chunk, encoding, cb) {
  64693. var ts = this._transformState;
  64694. ts.writecb = cb;
  64695. ts.writechunk = chunk;
  64696. ts.writeencoding = encoding;
  64697. if (!ts.transforming) {
  64698. var rs = this._readableState;
  64699. if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
  64700. }
  64701. }; // Doesn't matter what the args are here.
  64702. // _transform does all the work.
  64703. // That we got here means that the readable side wants more data.
  64704. Transform.prototype._read = function (n) {
  64705. var ts = this._transformState;
  64706. if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
  64707. ts.transforming = true;
  64708. this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
  64709. } else {
  64710. // mark that we need a transform, so that any data that comes in
  64711. // will get processed, now that we've asked for it.
  64712. ts.needTransform = true;
  64713. }
  64714. };
  64715. Transform.prototype._destroy = function (err, cb) {
  64716. var _this2 = this;
  64717. Duplex.prototype._destroy.call(this, err, function (err2) {
  64718. cb(err2);
  64719. _this2.emit('close');
  64720. });
  64721. };
  64722. function done(stream, er, data) {
  64723. if (er) return stream.emit('error', er);
  64724. if (data != null) // single equals check for both `null` and `undefined`
  64725. stream.push(data); // if there's nothing in the write buffer, then that means
  64726. // that nothing more will ever be provided
  64727. if (stream._writableState.length) throw new Error('Calling transform done when ws.length != 0');
  64728. if (stream._transformState.transforming) throw new Error('Calling transform done when still transforming');
  64729. return stream.push(null);
  64730. }
  64731. },{"./_stream_duplex":508,"core-util-is":328,"inherits":387}],512:[function(require,module,exports){
  64732. (function (process,global,setImmediate){
  64733. // Copyright Joyent, Inc. and other Node contributors.
  64734. //
  64735. // Permission is hereby granted, free of charge, to any person obtaining a
  64736. // copy of this software and associated documentation files (the
  64737. // "Software"), to deal in the Software without restriction, including
  64738. // without limitation the rights to use, copy, modify, merge, publish,
  64739. // distribute, sublicense, and/or sell copies of the Software, and to permit
  64740. // persons to whom the Software is furnished to do so, subject to the
  64741. // following conditions:
  64742. //
  64743. // The above copyright notice and this permission notice shall be included
  64744. // in all copies or substantial portions of the Software.
  64745. //
  64746. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  64747. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  64748. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  64749. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  64750. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  64751. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  64752. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  64753. // A bit simpler than readable streams.
  64754. // Implement an async ._write(chunk, encoding, cb), and it'll handle all
  64755. // the drain event emission and buffering.
  64756. 'use strict';
  64757. /*<replacement>*/
  64758. var pna = require('process-nextick-args');
  64759. /*</replacement>*/
  64760. module.exports = Writable;
  64761. /* <replacement> */
  64762. function WriteReq(chunk, encoding, cb) {
  64763. this.chunk = chunk;
  64764. this.encoding = encoding;
  64765. this.callback = cb;
  64766. this.next = null;
  64767. } // It seems a linked list but it is not
  64768. // there will be only 2 of these for each stream
  64769. function CorkedRequest(state) {
  64770. var _this = this;
  64771. this.next = null;
  64772. this.entry = null;
  64773. this.finish = function () {
  64774. onCorkedFinish(_this, state);
  64775. };
  64776. }
  64777. /* </replacement> */
  64778. /*<replacement>*/
  64779. var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : pna.nextTick;
  64780. /*</replacement>*/
  64781. /*<replacement>*/
  64782. var Duplex;
  64783. /*</replacement>*/
  64784. Writable.WritableState = WritableState;
  64785. /*<replacement>*/
  64786. var util = Object.create(require('core-util-is'));
  64787. util.inherits = require('inherits');
  64788. /*</replacement>*/
  64789. /*<replacement>*/
  64790. var internalUtil = {
  64791. deprecate: require('util-deprecate')
  64792. };
  64793. /*</replacement>*/
  64794. /*<replacement>*/
  64795. var Stream = require('./internal/streams/stream');
  64796. /*</replacement>*/
  64797. /*<replacement>*/
  64798. var Buffer = require('safe-buffer').Buffer;
  64799. var OurUint8Array = global.Uint8Array || function () {};
  64800. function _uint8ArrayToBuffer(chunk) {
  64801. return Buffer.from(chunk);
  64802. }
  64803. function _isUint8Array(obj) {
  64804. return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
  64805. }
  64806. /*</replacement>*/
  64807. var destroyImpl = require('./internal/streams/destroy');
  64808. util.inherits(Writable, Stream);
  64809. function nop() {}
  64810. function WritableState(options, stream) {
  64811. Duplex = Duplex || require('./_stream_duplex');
  64812. options = options || {}; // Duplex streams are both readable and writable, but share
  64813. // the same options object.
  64814. // However, some cases require setting options to different
  64815. // values for the readable and the writable sides of the duplex stream.
  64816. // These options can be provided separately as readableXXX and writableXXX.
  64817. var isDuplex = stream instanceof Duplex; // object stream flag to indicate whether or not this stream
  64818. // contains buffers or objects.
  64819. this.objectMode = !!options.objectMode;
  64820. if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode; // the point at which write() starts returning false
  64821. // Note: 0 is a valid value, means that we always return false if
  64822. // the entire buffer is not flushed immediately on write()
  64823. var hwm = options.highWaterMark;
  64824. var writableHwm = options.writableHighWaterMark;
  64825. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  64826. if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (writableHwm || writableHwm === 0)) this.highWaterMark = writableHwm;else this.highWaterMark = defaultHwm; // cast to ints.
  64827. this.highWaterMark = Math.floor(this.highWaterMark); // if _final has been called
  64828. this.finalCalled = false; // drain event flag.
  64829. this.needDrain = false; // at the start of calling end()
  64830. this.ending = false; // when end() has been called, and returned
  64831. this.ended = false; // when 'finish' is emitted
  64832. this.finished = false; // has it been destroyed
  64833. this.destroyed = false; // should we decode strings into buffers before passing to _write?
  64834. // this is here so that some node-core streams can optimize string
  64835. // handling at a lower level.
  64836. var noDecode = options.decodeStrings === false;
  64837. this.decodeStrings = !noDecode; // Crypto is kind of old and crusty. Historically, its default string
  64838. // encoding is 'binary' so we have to make this configurable.
  64839. // Everything else in the universe uses 'utf8', though.
  64840. this.defaultEncoding = options.defaultEncoding || 'utf8'; // not an actual buffer we keep track of, but a measurement
  64841. // of how much we're waiting to get pushed to some underlying
  64842. // socket or file.
  64843. this.length = 0; // a flag to see when we're in the middle of a write.
  64844. this.writing = false; // when true all writes will be buffered until .uncork() call
  64845. this.corked = 0; // a flag to be able to tell if the onwrite cb is called immediately,
  64846. // or on a later tick. We set this to true at first, because any
  64847. // actions that shouldn't happen until "later" should generally also
  64848. // not happen before the first write call.
  64849. this.sync = true; // a flag to know if we're processing previously buffered items, which
  64850. // may call the _write() callback in the same tick, so that we don't
  64851. // end up in an overlapped onwrite situation.
  64852. this.bufferProcessing = false; // the callback that's passed to _write(chunk,cb)
  64853. this.onwrite = function (er) {
  64854. onwrite(stream, er);
  64855. }; // the callback that the user supplies to write(chunk,encoding,cb)
  64856. this.writecb = null; // the amount that is being written when _write is called.
  64857. this.writelen = 0;
  64858. this.bufferedRequest = null;
  64859. this.lastBufferedRequest = null; // number of pending user-supplied write callbacks
  64860. // this must be 0 before 'finish' can be emitted
  64861. this.pendingcb = 0; // emit prefinish if the only thing we're waiting for is _write cbs
  64862. // This is relevant for synchronous Transform streams
  64863. this.prefinished = false; // True if the error was already emitted and should not be thrown again
  64864. this.errorEmitted = false; // count buffered requests
  64865. this.bufferedRequestCount = 0; // allocate the first CorkedRequest, there is always
  64866. // one allocated and free to use, and we maintain at most two
  64867. this.corkedRequestsFree = new CorkedRequest(this);
  64868. }
  64869. WritableState.prototype.getBuffer = function getBuffer() {
  64870. var current = this.bufferedRequest;
  64871. var out = [];
  64872. while (current) {
  64873. out.push(current);
  64874. current = current.next;
  64875. }
  64876. return out;
  64877. };
  64878. (function () {
  64879. try {
  64880. Object.defineProperty(WritableState.prototype, 'buffer', {
  64881. get: internalUtil.deprecate(function () {
  64882. return this.getBuffer();
  64883. }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
  64884. });
  64885. } catch (_) {}
  64886. })(); // Test _writableState for inheritance to account for Duplex streams,
  64887. // whose prototype chain only points to Readable.
  64888. var realHasInstance;
  64889. if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
  64890. realHasInstance = Function.prototype[Symbol.hasInstance];
  64891. Object.defineProperty(Writable, Symbol.hasInstance, {
  64892. value: function value(object) {
  64893. if (realHasInstance.call(this, object)) return true;
  64894. if (this !== Writable) return false;
  64895. return object && object._writableState instanceof WritableState;
  64896. }
  64897. });
  64898. } else {
  64899. realHasInstance = function realHasInstance(object) {
  64900. return object instanceof this;
  64901. };
  64902. }
  64903. function Writable(options) {
  64904. Duplex = Duplex || require('./_stream_duplex'); // Writable ctor is applied to Duplexes, too.
  64905. // `realHasInstance` is necessary because using plain `instanceof`
  64906. // would return false, as no `_writableState` property is attached.
  64907. // Trying to use the custom `instanceof` for Writable here will also break the
  64908. // Node.js LazyTransform implementation, which has a non-trivial getter for
  64909. // `_writableState` that would lead to infinite recursion.
  64910. if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) {
  64911. return new Writable(options);
  64912. }
  64913. this._writableState = new WritableState(options, this); // legacy.
  64914. this.writable = true;
  64915. if (options) {
  64916. if (typeof options.write === 'function') this._write = options.write;
  64917. if (typeof options.writev === 'function') this._writev = options.writev;
  64918. if (typeof options.destroy === 'function') this._destroy = options.destroy;
  64919. if (typeof options.final === 'function') this._final = options.final;
  64920. }
  64921. Stream.call(this);
  64922. } // Otherwise people can pipe Writable streams, which is just wrong.
  64923. Writable.prototype.pipe = function () {
  64924. this.emit('error', new Error('Cannot pipe, not readable'));
  64925. };
  64926. function writeAfterEnd(stream, cb) {
  64927. var er = new Error('write after end'); // TODO: defer error events consistently everywhere, not just the cb
  64928. stream.emit('error', er);
  64929. pna.nextTick(cb, er);
  64930. } // Checks that a user-supplied chunk is valid, especially for the particular
  64931. // mode the stream is in. Currently this means that `null` is never accepted
  64932. // and undefined/non-string values are only allowed in object mode.
  64933. function validChunk(stream, state, chunk, cb) {
  64934. var valid = true;
  64935. var er = false;
  64936. if (chunk === null) {
  64937. er = new TypeError('May not write null values to stream');
  64938. } else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
  64939. er = new TypeError('Invalid non-string/buffer chunk');
  64940. }
  64941. if (er) {
  64942. stream.emit('error', er);
  64943. pna.nextTick(cb, er);
  64944. valid = false;
  64945. }
  64946. return valid;
  64947. }
  64948. Writable.prototype.write = function (chunk, encoding, cb) {
  64949. var state = this._writableState;
  64950. var ret = false;
  64951. var isBuf = !state.objectMode && _isUint8Array(chunk);
  64952. if (isBuf && !Buffer.isBuffer(chunk)) {
  64953. chunk = _uint8ArrayToBuffer(chunk);
  64954. }
  64955. if (typeof encoding === 'function') {
  64956. cb = encoding;
  64957. encoding = null;
  64958. }
  64959. if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
  64960. if (typeof cb !== 'function') cb = nop;
  64961. if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
  64962. state.pendingcb++;
  64963. ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
  64964. }
  64965. return ret;
  64966. };
  64967. Writable.prototype.cork = function () {
  64968. var state = this._writableState;
  64969. state.corked++;
  64970. };
  64971. Writable.prototype.uncork = function () {
  64972. var state = this._writableState;
  64973. if (state.corked) {
  64974. state.corked--;
  64975. if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
  64976. }
  64977. };
  64978. Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
  64979. // node::ParseEncoding() requires lower case.
  64980. if (typeof encoding === 'string') encoding = encoding.toLowerCase();
  64981. 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);
  64982. this._writableState.defaultEncoding = encoding;
  64983. return this;
  64984. };
  64985. function decodeChunk(state, chunk, encoding) {
  64986. if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
  64987. chunk = Buffer.from(chunk, encoding);
  64988. }
  64989. return chunk;
  64990. }
  64991. Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
  64992. // making it explicit this property is not enumerable
  64993. // because otherwise some prototype manipulation in
  64994. // userland will fail
  64995. enumerable: false,
  64996. get: function get() {
  64997. return this._writableState.highWaterMark;
  64998. }
  64999. }); // if we're already writing something, then just put this
  65000. // in the queue, and wait our turn. Otherwise, call _write
  65001. // If we return false, then we need a drain event, so set that flag.
  65002. function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
  65003. if (!isBuf) {
  65004. var newChunk = decodeChunk(state, chunk, encoding);
  65005. if (chunk !== newChunk) {
  65006. isBuf = true;
  65007. encoding = 'buffer';
  65008. chunk = newChunk;
  65009. }
  65010. }
  65011. var len = state.objectMode ? 1 : chunk.length;
  65012. state.length += len;
  65013. var ret = state.length < state.highWaterMark; // we must ensure that previous needDrain will not be reset to false.
  65014. if (!ret) state.needDrain = true;
  65015. if (state.writing || state.corked) {
  65016. var last = state.lastBufferedRequest;
  65017. state.lastBufferedRequest = {
  65018. chunk: chunk,
  65019. encoding: encoding,
  65020. isBuf: isBuf,
  65021. callback: cb,
  65022. next: null
  65023. };
  65024. if (last) {
  65025. last.next = state.lastBufferedRequest;
  65026. } else {
  65027. state.bufferedRequest = state.lastBufferedRequest;
  65028. }
  65029. state.bufferedRequestCount += 1;
  65030. } else {
  65031. doWrite(stream, state, false, len, chunk, encoding, cb);
  65032. }
  65033. return ret;
  65034. }
  65035. function doWrite(stream, state, writev, len, chunk, encoding, cb) {
  65036. state.writelen = len;
  65037. state.writecb = cb;
  65038. state.writing = true;
  65039. state.sync = true;
  65040. if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
  65041. state.sync = false;
  65042. }
  65043. function onwriteError(stream, state, sync, er, cb) {
  65044. --state.pendingcb;
  65045. if (sync) {
  65046. // defer the callback if we are being called synchronously
  65047. // to avoid piling up things on the stack
  65048. pna.nextTick(cb, er); // this can emit finish, and it will always happen
  65049. // after error
  65050. pna.nextTick(finishMaybe, stream, state);
  65051. stream._writableState.errorEmitted = true;
  65052. stream.emit('error', er);
  65053. } else {
  65054. // the caller expect this to happen before if
  65055. // it is async
  65056. cb(er);
  65057. stream._writableState.errorEmitted = true;
  65058. stream.emit('error', er); // this can emit finish, but finish must
  65059. // always follow error
  65060. finishMaybe(stream, state);
  65061. }
  65062. }
  65063. function onwriteStateUpdate(state) {
  65064. state.writing = false;
  65065. state.writecb = null;
  65066. state.length -= state.writelen;
  65067. state.writelen = 0;
  65068. }
  65069. function onwrite(stream, er) {
  65070. var state = stream._writableState;
  65071. var sync = state.sync;
  65072. var cb = state.writecb;
  65073. onwriteStateUpdate(state);
  65074. if (er) onwriteError(stream, state, sync, er, cb);else {
  65075. // Check if we're actually ready to finish, but don't emit yet
  65076. var finished = needFinish(state);
  65077. if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
  65078. clearBuffer(stream, state);
  65079. }
  65080. if (sync) {
  65081. /*<replacement>*/
  65082. asyncWrite(afterWrite, stream, state, finished, cb);
  65083. /*</replacement>*/
  65084. } else {
  65085. afterWrite(stream, state, finished, cb);
  65086. }
  65087. }
  65088. }
  65089. function afterWrite(stream, state, finished, cb) {
  65090. if (!finished) onwriteDrain(stream, state);
  65091. state.pendingcb--;
  65092. cb();
  65093. finishMaybe(stream, state);
  65094. } // Must force callback to be called on nextTick, so that we don't
  65095. // emit 'drain' before the write() consumer gets the 'false' return
  65096. // value, and has a chance to attach a 'drain' listener.
  65097. function onwriteDrain(stream, state) {
  65098. if (state.length === 0 && state.needDrain) {
  65099. state.needDrain = false;
  65100. stream.emit('drain');
  65101. }
  65102. } // if there's something in the buffer waiting, then process it
  65103. function clearBuffer(stream, state) {
  65104. state.bufferProcessing = true;
  65105. var entry = state.bufferedRequest;
  65106. if (stream._writev && entry && entry.next) {
  65107. // Fast case, write everything using _writev()
  65108. var l = state.bufferedRequestCount;
  65109. var buffer = new Array(l);
  65110. var holder = state.corkedRequestsFree;
  65111. holder.entry = entry;
  65112. var count = 0;
  65113. var allBuffers = true;
  65114. while (entry) {
  65115. buffer[count] = entry;
  65116. if (!entry.isBuf) allBuffers = false;
  65117. entry = entry.next;
  65118. count += 1;
  65119. }
  65120. buffer.allBuffers = allBuffers;
  65121. doWrite(stream, state, true, state.length, buffer, '', holder.finish); // doWrite is almost always async, defer these to save a bit of time
  65122. // as the hot path ends with doWrite
  65123. state.pendingcb++;
  65124. state.lastBufferedRequest = null;
  65125. if (holder.next) {
  65126. state.corkedRequestsFree = holder.next;
  65127. holder.next = null;
  65128. } else {
  65129. state.corkedRequestsFree = new CorkedRequest(state);
  65130. }
  65131. state.bufferedRequestCount = 0;
  65132. } else {
  65133. // Slow case, write chunks one-by-one
  65134. while (entry) {
  65135. var chunk = entry.chunk;
  65136. var encoding = entry.encoding;
  65137. var cb = entry.callback;
  65138. var len = state.objectMode ? 1 : chunk.length;
  65139. doWrite(stream, state, false, len, chunk, encoding, cb);
  65140. entry = entry.next;
  65141. state.bufferedRequestCount--; // if we didn't call the onwrite immediately, then
  65142. // it means that we need to wait until it does.
  65143. // also, that means that the chunk and cb are currently
  65144. // being processed, so move the buffer counter past them.
  65145. if (state.writing) {
  65146. break;
  65147. }
  65148. }
  65149. if (entry === null) state.lastBufferedRequest = null;
  65150. }
  65151. state.bufferedRequest = entry;
  65152. state.bufferProcessing = false;
  65153. }
  65154. Writable.prototype._write = function (chunk, encoding, cb) {
  65155. cb(new Error('_write() is not implemented'));
  65156. };
  65157. Writable.prototype._writev = null;
  65158. Writable.prototype.end = function (chunk, encoding, cb) {
  65159. var state = this._writableState;
  65160. if (typeof chunk === 'function') {
  65161. cb = chunk;
  65162. chunk = null;
  65163. encoding = null;
  65164. } else if (typeof encoding === 'function') {
  65165. cb = encoding;
  65166. encoding = null;
  65167. }
  65168. if (chunk !== null && chunk !== undefined) this.write(chunk, encoding); // .end() fully uncorks
  65169. if (state.corked) {
  65170. state.corked = 1;
  65171. this.uncork();
  65172. } // ignore unnecessary end() calls.
  65173. if (!state.ending && !state.finished) endWritable(this, state, cb);
  65174. };
  65175. function needFinish(state) {
  65176. return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
  65177. }
  65178. function callFinal(stream, state) {
  65179. stream._final(function (err) {
  65180. state.pendingcb--;
  65181. if (err) {
  65182. stream.emit('error', err);
  65183. }
  65184. state.prefinished = true;
  65185. stream.emit('prefinish');
  65186. finishMaybe(stream, state);
  65187. });
  65188. }
  65189. function prefinish(stream, state) {
  65190. if (!state.prefinished && !state.finalCalled) {
  65191. if (typeof stream._final === 'function') {
  65192. state.pendingcb++;
  65193. state.finalCalled = true;
  65194. pna.nextTick(callFinal, stream, state);
  65195. } else {
  65196. state.prefinished = true;
  65197. stream.emit('prefinish');
  65198. }
  65199. }
  65200. }
  65201. function finishMaybe(stream, state) {
  65202. var need = needFinish(state);
  65203. if (need) {
  65204. prefinish(stream, state);
  65205. if (state.pendingcb === 0) {
  65206. state.finished = true;
  65207. stream.emit('finish');
  65208. }
  65209. }
  65210. return need;
  65211. }
  65212. function endWritable(stream, state, cb) {
  65213. state.ending = true;
  65214. finishMaybe(stream, state);
  65215. if (cb) {
  65216. if (state.finished) pna.nextTick(cb);else stream.once('finish', cb);
  65217. }
  65218. state.ended = true;
  65219. stream.writable = false;
  65220. }
  65221. function onCorkedFinish(corkReq, state, err) {
  65222. var entry = corkReq.entry;
  65223. corkReq.entry = null;
  65224. while (entry) {
  65225. var cb = entry.callback;
  65226. state.pendingcb--;
  65227. cb(err);
  65228. entry = entry.next;
  65229. }
  65230. if (state.corkedRequestsFree) {
  65231. state.corkedRequestsFree.next = corkReq;
  65232. } else {
  65233. state.corkedRequestsFree = corkReq;
  65234. }
  65235. }
  65236. Object.defineProperty(Writable.prototype, 'destroyed', {
  65237. get: function get() {
  65238. if (this._writableState === undefined) {
  65239. return false;
  65240. }
  65241. return this._writableState.destroyed;
  65242. },
  65243. set: function set(value) {
  65244. // we ignore the value if the stream
  65245. // has not been initialized yet
  65246. if (!this._writableState) {
  65247. return;
  65248. } // backward compatibility, the user is explicitly
  65249. // managing destroyed
  65250. this._writableState.destroyed = value;
  65251. }
  65252. });
  65253. Writable.prototype.destroy = destroyImpl.destroy;
  65254. Writable.prototype._undestroy = destroyImpl.undestroy;
  65255. Writable.prototype._destroy = function (err, cb) {
  65256. this.end();
  65257. cb(err);
  65258. };
  65259. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("timers").setImmediate)
  65260. },{"./_stream_duplex":508,"./internal/streams/destroy":514,"./internal/streams/stream":515,"_process":467,"core-util-is":328,"inherits":387,"process-nextick-args":466,"safe-buffer":494,"timers":521,"util-deprecate":522}],513:[function(require,module,exports){
  65261. 'use strict';
  65262. function _classCallCheck(instance, Constructor) {
  65263. if (!(instance instanceof Constructor)) {
  65264. throw new TypeError("Cannot call a class as a function");
  65265. }
  65266. }
  65267. var Buffer = require('safe-buffer').Buffer;
  65268. var util = require('util');
  65269. function copyBuffer(src, target, offset) {
  65270. src.copy(target, offset);
  65271. }
  65272. module.exports = function () {
  65273. function BufferList() {
  65274. _classCallCheck(this, BufferList);
  65275. this.head = null;
  65276. this.tail = null;
  65277. this.length = 0;
  65278. }
  65279. BufferList.prototype.push = function push(v) {
  65280. var entry = {
  65281. data: v,
  65282. next: null
  65283. };
  65284. if (this.length > 0) this.tail.next = entry;else this.head = entry;
  65285. this.tail = entry;
  65286. ++this.length;
  65287. };
  65288. BufferList.prototype.unshift = function unshift(v) {
  65289. var entry = {
  65290. data: v,
  65291. next: this.head
  65292. };
  65293. if (this.length === 0) this.tail = entry;
  65294. this.head = entry;
  65295. ++this.length;
  65296. };
  65297. BufferList.prototype.shift = function shift() {
  65298. if (this.length === 0) return;
  65299. var ret = this.head.data;
  65300. if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
  65301. --this.length;
  65302. return ret;
  65303. };
  65304. BufferList.prototype.clear = function clear() {
  65305. this.head = this.tail = null;
  65306. this.length = 0;
  65307. };
  65308. BufferList.prototype.join = function join(s) {
  65309. if (this.length === 0) return '';
  65310. var p = this.head;
  65311. var ret = '' + p.data;
  65312. while (p = p.next) {
  65313. ret += s + p.data;
  65314. }
  65315. return ret;
  65316. };
  65317. BufferList.prototype.concat = function concat(n) {
  65318. if (this.length === 0) return Buffer.alloc(0);
  65319. if (this.length === 1) return this.head.data;
  65320. var ret = Buffer.allocUnsafe(n >>> 0);
  65321. var p = this.head;
  65322. var i = 0;
  65323. while (p) {
  65324. copyBuffer(p.data, ret, i);
  65325. i += p.data.length;
  65326. p = p.next;
  65327. }
  65328. return ret;
  65329. };
  65330. return BufferList;
  65331. }();
  65332. if (util && util.inspect && util.inspect.custom) {
  65333. module.exports.prototype[util.inspect.custom] = function () {
  65334. var obj = util.inspect({
  65335. length: this.length
  65336. });
  65337. return this.constructor.name + ' ' + obj;
  65338. };
  65339. }
  65340. },{"safe-buffer":494,"util":185}],514:[function(require,module,exports){
  65341. 'use strict';
  65342. /*<replacement>*/
  65343. var pna = require('process-nextick-args');
  65344. /*</replacement>*/
  65345. // undocumented cb() API, needed for core, not for public API
  65346. function destroy(err, cb) {
  65347. var _this = this;
  65348. var readableDestroyed = this._readableState && this._readableState.destroyed;
  65349. var writableDestroyed = this._writableState && this._writableState.destroyed;
  65350. if (readableDestroyed || writableDestroyed) {
  65351. if (cb) {
  65352. cb(err);
  65353. } else if (err && (!this._writableState || !this._writableState.errorEmitted)) {
  65354. pna.nextTick(emitErrorNT, this, err);
  65355. }
  65356. return this;
  65357. } // we set destroyed to true before firing error callbacks in order
  65358. // to make it re-entrance safe in case destroy() is called within callbacks
  65359. if (this._readableState) {
  65360. this._readableState.destroyed = true;
  65361. } // if this is a duplex stream mark the writable part as destroyed as well
  65362. if (this._writableState) {
  65363. this._writableState.destroyed = true;
  65364. }
  65365. this._destroy(err || null, function (err) {
  65366. if (!cb && err) {
  65367. pna.nextTick(emitErrorNT, _this, err);
  65368. if (_this._writableState) {
  65369. _this._writableState.errorEmitted = true;
  65370. }
  65371. } else if (cb) {
  65372. cb(err);
  65373. }
  65374. });
  65375. return this;
  65376. }
  65377. function undestroy() {
  65378. if (this._readableState) {
  65379. this._readableState.destroyed = false;
  65380. this._readableState.reading = false;
  65381. this._readableState.ended = false;
  65382. this._readableState.endEmitted = false;
  65383. }
  65384. if (this._writableState) {
  65385. this._writableState.destroyed = false;
  65386. this._writableState.ended = false;
  65387. this._writableState.ending = false;
  65388. this._writableState.finished = false;
  65389. this._writableState.errorEmitted = false;
  65390. }
  65391. }
  65392. function emitErrorNT(self, err) {
  65393. self.emit('error', err);
  65394. }
  65395. module.exports = {
  65396. destroy: destroy,
  65397. undestroy: undestroy
  65398. };
  65399. },{"process-nextick-args":466}],515:[function(require,module,exports){
  65400. arguments[4][490][0].apply(exports,arguments)
  65401. },{"dup":490,"events":367}],516:[function(require,module,exports){
  65402. "use strict";
  65403. module.exports = require('./readable').PassThrough;
  65404. },{"./readable":517}],517:[function(require,module,exports){
  65405. "use strict";
  65406. exports = module.exports = require('./lib/_stream_readable.js');
  65407. exports.Stream = exports;
  65408. exports.Readable = exports;
  65409. exports.Writable = require('./lib/_stream_writable.js');
  65410. exports.Duplex = require('./lib/_stream_duplex.js');
  65411. exports.Transform = require('./lib/_stream_transform.js');
  65412. exports.PassThrough = require('./lib/_stream_passthrough.js');
  65413. },{"./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){
  65414. "use strict";
  65415. module.exports = require('./readable').Transform;
  65416. },{"./readable":517}],519:[function(require,module,exports){
  65417. "use strict";
  65418. module.exports = require('./lib/_stream_writable.js');
  65419. },{"./lib/_stream_writable.js":512}],520:[function(require,module,exports){
  65420. // Copyright Joyent, Inc. and other Node contributors.
  65421. //
  65422. // Permission is hereby granted, free of charge, to any person obtaining a
  65423. // copy of this software and associated documentation files (the
  65424. // "Software"), to deal in the Software without restriction, including
  65425. // without limitation the rights to use, copy, modify, merge, publish,
  65426. // distribute, sublicense, and/or sell copies of the Software, and to permit
  65427. // persons to whom the Software is furnished to do so, subject to the
  65428. // following conditions:
  65429. //
  65430. // The above copyright notice and this permission notice shall be included
  65431. // in all copies or substantial portions of the Software.
  65432. //
  65433. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  65434. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  65435. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  65436. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  65437. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  65438. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  65439. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  65440. 'use strict';
  65441. /*<replacement>*/
  65442. var Buffer = require('safe-buffer').Buffer;
  65443. /*</replacement>*/
  65444. var isEncoding = Buffer.isEncoding || function (encoding) {
  65445. encoding = '' + encoding;
  65446. switch (encoding && encoding.toLowerCase()) {
  65447. case 'hex':
  65448. case 'utf8':
  65449. case 'utf-8':
  65450. case 'ascii':
  65451. case 'binary':
  65452. case 'base64':
  65453. case 'ucs2':
  65454. case 'ucs-2':
  65455. case 'utf16le':
  65456. case 'utf-16le':
  65457. case 'raw':
  65458. return true;
  65459. default:
  65460. return false;
  65461. }
  65462. };
  65463. function _normalizeEncoding(enc) {
  65464. if (!enc) return 'utf8';
  65465. var retried;
  65466. while (true) {
  65467. switch (enc) {
  65468. case 'utf8':
  65469. case 'utf-8':
  65470. return 'utf8';
  65471. case 'ucs2':
  65472. case 'ucs-2':
  65473. case 'utf16le':
  65474. case 'utf-16le':
  65475. return 'utf16le';
  65476. case 'latin1':
  65477. case 'binary':
  65478. return 'latin1';
  65479. case 'base64':
  65480. case 'ascii':
  65481. case 'hex':
  65482. return enc;
  65483. default:
  65484. if (retried) return; // undefined
  65485. enc = ('' + enc).toLowerCase();
  65486. retried = true;
  65487. }
  65488. }
  65489. }
  65490. ; // Do not cache `Buffer.isEncoding` when checking encoding names as some
  65491. // modules monkey-patch it to support additional encodings
  65492. function normalizeEncoding(enc) {
  65493. var nenc = _normalizeEncoding(enc);
  65494. if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
  65495. return nenc || enc;
  65496. } // StringDecoder provides an interface for efficiently splitting a series of
  65497. // buffers into a series of JS strings without breaking apart multi-byte
  65498. // characters.
  65499. exports.StringDecoder = StringDecoder;
  65500. function StringDecoder(encoding) {
  65501. this.encoding = normalizeEncoding(encoding);
  65502. var nb;
  65503. switch (this.encoding) {
  65504. case 'utf16le':
  65505. this.text = utf16Text;
  65506. this.end = utf16End;
  65507. nb = 4;
  65508. break;
  65509. case 'utf8':
  65510. this.fillLast = utf8FillLast;
  65511. nb = 4;
  65512. break;
  65513. case 'base64':
  65514. this.text = base64Text;
  65515. this.end = base64End;
  65516. nb = 3;
  65517. break;
  65518. default:
  65519. this.write = simpleWrite;
  65520. this.end = simpleEnd;
  65521. return;
  65522. }
  65523. this.lastNeed = 0;
  65524. this.lastTotal = 0;
  65525. this.lastChar = Buffer.allocUnsafe(nb);
  65526. }
  65527. StringDecoder.prototype.write = function (buf) {
  65528. if (buf.length === 0) return '';
  65529. var r;
  65530. var i;
  65531. if (this.lastNeed) {
  65532. r = this.fillLast(buf);
  65533. if (r === undefined) return '';
  65534. i = this.lastNeed;
  65535. this.lastNeed = 0;
  65536. } else {
  65537. i = 0;
  65538. }
  65539. if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
  65540. return r || '';
  65541. };
  65542. StringDecoder.prototype.end = utf8End; // Returns only complete characters in a Buffer
  65543. StringDecoder.prototype.text = utf8Text; // Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
  65544. StringDecoder.prototype.fillLast = function (buf) {
  65545. if (this.lastNeed <= buf.length) {
  65546. buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
  65547. return this.lastChar.toString(this.encoding, 0, this.lastTotal);
  65548. }
  65549. buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
  65550. this.lastNeed -= buf.length;
  65551. }; // Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
  65552. // continuation byte. If an invalid byte is detected, -2 is returned.
  65553. function utf8CheckByte(byte) {
  65554. 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;
  65555. return byte >> 6 === 0x02 ? -1 : -2;
  65556. } // Checks at most 3 bytes at the end of a Buffer in order to detect an
  65557. // incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4)
  65558. // needed to complete the UTF-8 character (if applicable) are returned.
  65559. function utf8CheckIncomplete(self, buf, i) {
  65560. var j = buf.length - 1;
  65561. if (j < i) return 0;
  65562. var nb = utf8CheckByte(buf[j]);
  65563. if (nb >= 0) {
  65564. if (nb > 0) self.lastNeed = nb - 1;
  65565. return nb;
  65566. }
  65567. if (--j < i || nb === -2) return 0;
  65568. nb = utf8CheckByte(buf[j]);
  65569. if (nb >= 0) {
  65570. if (nb > 0) self.lastNeed = nb - 2;
  65571. return nb;
  65572. }
  65573. if (--j < i || nb === -2) return 0;
  65574. nb = utf8CheckByte(buf[j]);
  65575. if (nb >= 0) {
  65576. if (nb > 0) {
  65577. if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
  65578. }
  65579. return nb;
  65580. }
  65581. return 0;
  65582. } // Validates as many continuation bytes for a multi-byte UTF-8 character as
  65583. // needed or are available. If we see a non-continuation byte where we expect
  65584. // one, we "replace" the validated continuation bytes we've seen so far with
  65585. // a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding
  65586. // behavior. The continuation byte check is included three times in the case
  65587. // where all of the continuation bytes for a character exist in the same buffer.
  65588. // It is also done this way as a slight performance increase instead of using a
  65589. // loop.
  65590. function utf8CheckExtraBytes(self, buf, p) {
  65591. if ((buf[0] & 0xC0) !== 0x80) {
  65592. self.lastNeed = 0;
  65593. return "\uFFFD";
  65594. }
  65595. if (self.lastNeed > 1 && buf.length > 1) {
  65596. if ((buf[1] & 0xC0) !== 0x80) {
  65597. self.lastNeed = 1;
  65598. return "\uFFFD";
  65599. }
  65600. if (self.lastNeed > 2 && buf.length > 2) {
  65601. if ((buf[2] & 0xC0) !== 0x80) {
  65602. self.lastNeed = 2;
  65603. return "\uFFFD";
  65604. }
  65605. }
  65606. }
  65607. } // Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
  65608. function utf8FillLast(buf) {
  65609. var p = this.lastTotal - this.lastNeed;
  65610. var r = utf8CheckExtraBytes(this, buf, p);
  65611. if (r !== undefined) return r;
  65612. if (this.lastNeed <= buf.length) {
  65613. buf.copy(this.lastChar, p, 0, this.lastNeed);
  65614. return this.lastChar.toString(this.encoding, 0, this.lastTotal);
  65615. }
  65616. buf.copy(this.lastChar, p, 0, buf.length);
  65617. this.lastNeed -= buf.length;
  65618. } // Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a
  65619. // partial character, the character's bytes are buffered until the required
  65620. // number of bytes are available.
  65621. function utf8Text(buf, i) {
  65622. var total = utf8CheckIncomplete(this, buf, i);
  65623. if (!this.lastNeed) return buf.toString('utf8', i);
  65624. this.lastTotal = total;
  65625. var end = buf.length - (total - this.lastNeed);
  65626. buf.copy(this.lastChar, 0, end);
  65627. return buf.toString('utf8', i, end);
  65628. } // For UTF-8, a replacement character is added when ending on a partial
  65629. // character.
  65630. function utf8End(buf) {
  65631. var r = buf && buf.length ? this.write(buf) : '';
  65632. if (this.lastNeed) return r + "\uFFFD";
  65633. return r;
  65634. } // UTF-16LE typically needs two bytes per character, but even if we have an even
  65635. // number of bytes available, we need to check if we end on a leading/high
  65636. // surrogate. In that case, we need to wait for the next two bytes in order to
  65637. // decode the last character properly.
  65638. function utf16Text(buf, i) {
  65639. if ((buf.length - i) % 2 === 0) {
  65640. var r = buf.toString('utf16le', i);
  65641. if (r) {
  65642. var c = r.charCodeAt(r.length - 1);
  65643. if (c >= 0xD800 && c <= 0xDBFF) {
  65644. this.lastNeed = 2;
  65645. this.lastTotal = 4;
  65646. this.lastChar[0] = buf[buf.length - 2];
  65647. this.lastChar[1] = buf[buf.length - 1];
  65648. return r.slice(0, -1);
  65649. }
  65650. }
  65651. return r;
  65652. }
  65653. this.lastNeed = 1;
  65654. this.lastTotal = 2;
  65655. this.lastChar[0] = buf[buf.length - 1];
  65656. return buf.toString('utf16le', i, buf.length - 1);
  65657. } // For UTF-16LE we do not explicitly append special replacement characters if we
  65658. // end on a partial character, we simply let v8 handle that.
  65659. function utf16End(buf) {
  65660. var r = buf && buf.length ? this.write(buf) : '';
  65661. if (this.lastNeed) {
  65662. var end = this.lastTotal - this.lastNeed;
  65663. return r + this.lastChar.toString('utf16le', 0, end);
  65664. }
  65665. return r;
  65666. }
  65667. function base64Text(buf, i) {
  65668. var n = (buf.length - i) % 3;
  65669. if (n === 0) return buf.toString('base64', i);
  65670. this.lastNeed = 3 - n;
  65671. this.lastTotal = 3;
  65672. if (n === 1) {
  65673. this.lastChar[0] = buf[buf.length - 1];
  65674. } else {
  65675. this.lastChar[0] = buf[buf.length - 2];
  65676. this.lastChar[1] = buf[buf.length - 1];
  65677. }
  65678. return buf.toString('base64', i, buf.length - n);
  65679. }
  65680. function base64End(buf) {
  65681. var r = buf && buf.length ? this.write(buf) : '';
  65682. if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
  65683. return r;
  65684. } // Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex)
  65685. function simpleWrite(buf) {
  65686. return buf.toString(this.encoding);
  65687. }
  65688. function simpleEnd(buf) {
  65689. return buf && buf.length ? this.write(buf) : '';
  65690. }
  65691. },{"safe-buffer":494}],521:[function(require,module,exports){
  65692. (function (setImmediate,clearImmediate){
  65693. "use strict";
  65694. var nextTick = require('process/browser.js').nextTick;
  65695. var apply = Function.prototype.apply;
  65696. var slice = Array.prototype.slice;
  65697. var immediateIds = {};
  65698. var nextImmediateId = 0; // DOM APIs, for completeness
  65699. exports.setTimeout = function () {
  65700. return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
  65701. };
  65702. exports.setInterval = function () {
  65703. return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
  65704. };
  65705. exports.clearTimeout = exports.clearInterval = function (timeout) {
  65706. timeout.close();
  65707. };
  65708. function Timeout(id, clearFn) {
  65709. this._id = id;
  65710. this._clearFn = clearFn;
  65711. }
  65712. Timeout.prototype.unref = Timeout.prototype.ref = function () {};
  65713. Timeout.prototype.close = function () {
  65714. this._clearFn.call(window, this._id);
  65715. }; // Does not start the time, just sets up the members needed.
  65716. exports.enroll = function (item, msecs) {
  65717. clearTimeout(item._idleTimeoutId);
  65718. item._idleTimeout = msecs;
  65719. };
  65720. exports.unenroll = function (item) {
  65721. clearTimeout(item._idleTimeoutId);
  65722. item._idleTimeout = -1;
  65723. };
  65724. exports._unrefActive = exports.active = function (item) {
  65725. clearTimeout(item._idleTimeoutId);
  65726. var msecs = item._idleTimeout;
  65727. if (msecs >= 0) {
  65728. item._idleTimeoutId = setTimeout(function onTimeout() {
  65729. if (item._onTimeout) item._onTimeout();
  65730. }, msecs);
  65731. }
  65732. }; // That's not how node.js implements it but the exposed api is the same.
  65733. exports.setImmediate = typeof setImmediate === "function" ? setImmediate : function (fn) {
  65734. var id = nextImmediateId++;
  65735. var args = arguments.length < 2 ? false : slice.call(arguments, 1);
  65736. immediateIds[id] = true;
  65737. nextTick(function onNextTick() {
  65738. if (immediateIds[id]) {
  65739. // fn.call() is faster so we optimize for the common use-case
  65740. // @see http://jsperf.com/call-apply-segu
  65741. if (args) {
  65742. fn.apply(null, args);
  65743. } else {
  65744. fn.call(null);
  65745. } // Prevent ids from leaking
  65746. exports.clearImmediate(id);
  65747. }
  65748. });
  65749. return id;
  65750. };
  65751. exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate : function (id) {
  65752. delete immediateIds[id];
  65753. };
  65754. }).call(this,require("timers").setImmediate,require("timers").clearImmediate)
  65755. },{"process/browser.js":467,"timers":521}],522:[function(require,module,exports){
  65756. (function (global){
  65757. "use strict";
  65758. /**
  65759. * Module exports.
  65760. */
  65761. module.exports = deprecate;
  65762. /**
  65763. * Mark that a method should not be used.
  65764. * Returns a modified function which warns once by default.
  65765. *
  65766. * If `localStorage.noDeprecation = true` is set, then it is a no-op.
  65767. *
  65768. * If `localStorage.throwDeprecation = true` is set, then deprecated functions
  65769. * will throw an Error when invoked.
  65770. *
  65771. * If `localStorage.traceDeprecation = true` is set, then deprecated functions
  65772. * will invoke `console.trace()` instead of `console.error()`.
  65773. *
  65774. * @param {Function} fn - the function to deprecate
  65775. * @param {String} msg - the string to print to the console when `fn` is invoked
  65776. * @returns {Function} a new "deprecated" version of `fn`
  65777. * @api public
  65778. */
  65779. function deprecate(fn, msg) {
  65780. if (config('noDeprecation')) {
  65781. return fn;
  65782. }
  65783. var warned = false;
  65784. function deprecated() {
  65785. if (!warned) {
  65786. if (config('throwDeprecation')) {
  65787. throw new Error(msg);
  65788. } else if (config('traceDeprecation')) {
  65789. console.trace(msg);
  65790. } else {
  65791. console.warn(msg);
  65792. }
  65793. warned = true;
  65794. }
  65795. return fn.apply(this, arguments);
  65796. }
  65797. return deprecated;
  65798. }
  65799. /**
  65800. * Checks `localStorage` for boolean values for the given `name`.
  65801. *
  65802. * @param {String} name
  65803. * @returns {Boolean}
  65804. * @api private
  65805. */
  65806. function config(name) {
  65807. // accessing global.localStorage can trigger a DOMException in sandboxed iframes
  65808. try {
  65809. if (!global.localStorage) return false;
  65810. } catch (_) {
  65811. return false;
  65812. }
  65813. var val = global.localStorage[name];
  65814. if (null == val) return false;
  65815. return String(val).toLowerCase() === 'true';
  65816. }
  65817. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  65818. },{}],523:[function(require,module,exports){
  65819. "use strict";
  65820. if (typeof Object.create === 'function') {
  65821. // implementation from standard node.js 'util' module
  65822. module.exports = function inherits(ctor, superCtor) {
  65823. ctor.super_ = superCtor;
  65824. ctor.prototype = Object.create(superCtor.prototype, {
  65825. constructor: {
  65826. value: ctor,
  65827. enumerable: false,
  65828. writable: true,
  65829. configurable: true
  65830. }
  65831. });
  65832. };
  65833. } else {
  65834. // old school shim for old browsers
  65835. module.exports = function inherits(ctor, superCtor) {
  65836. ctor.super_ = superCtor;
  65837. var TempCtor = function TempCtor() {};
  65838. TempCtor.prototype = superCtor.prototype;
  65839. ctor.prototype = new TempCtor();
  65840. ctor.prototype.constructor = ctor;
  65841. };
  65842. }
  65843. },{}],524:[function(require,module,exports){
  65844. "use strict";
  65845. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  65846. module.exports = function isBuffer(arg) {
  65847. return arg && _typeof(arg) === 'object' && typeof arg.copy === 'function' && typeof arg.fill === 'function' && typeof arg.readUInt8 === 'function';
  65848. };
  65849. },{}],525:[function(require,module,exports){
  65850. (function (process,global){
  65851. "use strict";
  65852. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  65853. // Copyright Joyent, Inc. and other Node contributors.
  65854. //
  65855. // Permission is hereby granted, free of charge, to any person obtaining a
  65856. // copy of this software and associated documentation files (the
  65857. // "Software"), to deal in the Software without restriction, including
  65858. // without limitation the rights to use, copy, modify, merge, publish,
  65859. // distribute, sublicense, and/or sell copies of the Software, and to permit
  65860. // persons to whom the Software is furnished to do so, subject to the
  65861. // following conditions:
  65862. //
  65863. // The above copyright notice and this permission notice shall be included
  65864. // in all copies or substantial portions of the Software.
  65865. //
  65866. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  65867. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  65868. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  65869. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  65870. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  65871. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  65872. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  65873. var formatRegExp = /%[sdj%]/g;
  65874. exports.format = function (f) {
  65875. if (!isString(f)) {
  65876. var objects = [];
  65877. for (var i = 0; i < arguments.length; i++) {
  65878. objects.push(inspect(arguments[i]));
  65879. }
  65880. return objects.join(' ');
  65881. }
  65882. var i = 1;
  65883. var args = arguments;
  65884. var len = args.length;
  65885. var str = String(f).replace(formatRegExp, function (x) {
  65886. if (x === '%%') return '%';
  65887. if (i >= len) return x;
  65888. switch (x) {
  65889. case '%s':
  65890. return String(args[i++]);
  65891. case '%d':
  65892. return Number(args[i++]);
  65893. case '%j':
  65894. try {
  65895. return JSON.stringify(args[i++]);
  65896. } catch (_) {
  65897. return '[Circular]';
  65898. }
  65899. default:
  65900. return x;
  65901. }
  65902. });
  65903. for (var x = args[i]; i < len; x = args[++i]) {
  65904. if (isNull(x) || !isObject(x)) {
  65905. str += ' ' + x;
  65906. } else {
  65907. str += ' ' + inspect(x);
  65908. }
  65909. }
  65910. return str;
  65911. }; // Mark that a method should not be used.
  65912. // Returns a modified function which warns once by default.
  65913. // If --no-deprecation is set, then it is a no-op.
  65914. exports.deprecate = function (fn, msg) {
  65915. // Allow for deprecating things in the process of starting up.
  65916. if (isUndefined(global.process)) {
  65917. return function () {
  65918. return exports.deprecate(fn, msg).apply(this, arguments);
  65919. };
  65920. }
  65921. if (process.noDeprecation === true) {
  65922. return fn;
  65923. }
  65924. var warned = false;
  65925. function deprecated() {
  65926. if (!warned) {
  65927. if (process.throwDeprecation) {
  65928. throw new Error(msg);
  65929. } else if (process.traceDeprecation) {
  65930. console.trace(msg);
  65931. } else {
  65932. console.error(msg);
  65933. }
  65934. warned = true;
  65935. }
  65936. return fn.apply(this, arguments);
  65937. }
  65938. return deprecated;
  65939. };
  65940. var debugs = {};
  65941. var debugEnviron;
  65942. exports.debuglog = function (set) {
  65943. if (isUndefined(debugEnviron)) debugEnviron = process.env.NODE_DEBUG || '';
  65944. set = set.toUpperCase();
  65945. if (!debugs[set]) {
  65946. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  65947. var pid = process.pid;
  65948. debugs[set] = function () {
  65949. var msg = exports.format.apply(exports, arguments);
  65950. console.error('%s %d: %s', set, pid, msg);
  65951. };
  65952. } else {
  65953. debugs[set] = function () {};
  65954. }
  65955. }
  65956. return debugs[set];
  65957. };
  65958. /**
  65959. * Echos the value of a value. Trys to print the value out
  65960. * in the best way possible given the different types.
  65961. *
  65962. * @param {Object} obj The object to print out.
  65963. * @param {Object} opts Optional options object that alters the output.
  65964. */
  65965. /* legacy: obj, showHidden, depth, colors*/
  65966. function inspect(obj, opts) {
  65967. // default options
  65968. var ctx = {
  65969. seen: [],
  65970. stylize: stylizeNoColor
  65971. }; // legacy...
  65972. if (arguments.length >= 3) ctx.depth = arguments[2];
  65973. if (arguments.length >= 4) ctx.colors = arguments[3];
  65974. if (isBoolean(opts)) {
  65975. // legacy...
  65976. ctx.showHidden = opts;
  65977. } else if (opts) {
  65978. // got an "options" object
  65979. exports._extend(ctx, opts);
  65980. } // set default options
  65981. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  65982. if (isUndefined(ctx.depth)) ctx.depth = 2;
  65983. if (isUndefined(ctx.colors)) ctx.colors = false;
  65984. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  65985. if (ctx.colors) ctx.stylize = stylizeWithColor;
  65986. return formatValue(ctx, obj, ctx.depth);
  65987. }
  65988. exports.inspect = inspect; // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  65989. inspect.colors = {
  65990. 'bold': [1, 22],
  65991. 'italic': [3, 23],
  65992. 'underline': [4, 24],
  65993. 'inverse': [7, 27],
  65994. 'white': [37, 39],
  65995. 'grey': [90, 39],
  65996. 'black': [30, 39],
  65997. 'blue': [34, 39],
  65998. 'cyan': [36, 39],
  65999. 'green': [32, 39],
  66000. 'magenta': [35, 39],
  66001. 'red': [31, 39],
  66002. 'yellow': [33, 39]
  66003. }; // Don't use 'blue' not visible on cmd.exe
  66004. inspect.styles = {
  66005. 'special': 'cyan',
  66006. 'number': 'yellow',
  66007. 'boolean': 'yellow',
  66008. 'undefined': 'grey',
  66009. 'null': 'bold',
  66010. 'string': 'green',
  66011. 'date': 'magenta',
  66012. // "name": intentionally not styling
  66013. 'regexp': 'red'
  66014. };
  66015. function stylizeWithColor(str, styleType) {
  66016. var style = inspect.styles[styleType];
  66017. if (style) {
  66018. return "\x1B[" + inspect.colors[style][0] + 'm' + str + "\x1B[" + inspect.colors[style][1] + 'm';
  66019. } else {
  66020. return str;
  66021. }
  66022. }
  66023. function stylizeNoColor(str, styleType) {
  66024. return str;
  66025. }
  66026. function arrayToHash(array) {
  66027. var hash = {};
  66028. array.forEach(function (val, idx) {
  66029. hash[val] = true;
  66030. });
  66031. return hash;
  66032. }
  66033. function formatValue(ctx, value, recurseTimes) {
  66034. // Provide a hook for user-specified inspect functions.
  66035. // Check that value is an object with an inspect function on it
  66036. if (ctx.customInspect && value && isFunction(value.inspect) && // Filter out the util module, it's inspect function is special
  66037. value.inspect !== exports.inspect && // Also filter out any prototype objects using the circular check.
  66038. !(value.constructor && value.constructor.prototype === value)) {
  66039. var ret = value.inspect(recurseTimes, ctx);
  66040. if (!isString(ret)) {
  66041. ret = formatValue(ctx, ret, recurseTimes);
  66042. }
  66043. return ret;
  66044. } // Primitive types cannot have properties
  66045. var primitive = formatPrimitive(ctx, value);
  66046. if (primitive) {
  66047. return primitive;
  66048. } // Look up the keys of the object.
  66049. var keys = Object.keys(value);
  66050. var visibleKeys = arrayToHash(keys);
  66051. if (ctx.showHidden) {
  66052. keys = Object.getOwnPropertyNames(value);
  66053. } // IE doesn't make error fields non-enumerable
  66054. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  66055. if (isError(value) && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  66056. return formatError(value);
  66057. } // Some type of object without properties can be shortcutted.
  66058. if (keys.length === 0) {
  66059. if (isFunction(value)) {
  66060. var name = value.name ? ': ' + value.name : '';
  66061. return ctx.stylize('[Function' + name + ']', 'special');
  66062. }
  66063. if (isRegExp(value)) {
  66064. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  66065. }
  66066. if (isDate(value)) {
  66067. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  66068. }
  66069. if (isError(value)) {
  66070. return formatError(value);
  66071. }
  66072. }
  66073. var base = '',
  66074. array = false,
  66075. braces = ['{', '}']; // Make Array say that they are Array
  66076. if (isArray(value)) {
  66077. array = true;
  66078. braces = ['[', ']'];
  66079. } // Make functions say that they are functions
  66080. if (isFunction(value)) {
  66081. var n = value.name ? ': ' + value.name : '';
  66082. base = ' [Function' + n + ']';
  66083. } // Make RegExps say that they are RegExps
  66084. if (isRegExp(value)) {
  66085. base = ' ' + RegExp.prototype.toString.call(value);
  66086. } // Make dates with properties first say the date
  66087. if (isDate(value)) {
  66088. base = ' ' + Date.prototype.toUTCString.call(value);
  66089. } // Make error with message first say the error
  66090. if (isError(value)) {
  66091. base = ' ' + formatError(value);
  66092. }
  66093. if (keys.length === 0 && (!array || value.length == 0)) {
  66094. return braces[0] + base + braces[1];
  66095. }
  66096. if (recurseTimes < 0) {
  66097. if (isRegExp(value)) {
  66098. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  66099. } else {
  66100. return ctx.stylize('[Object]', 'special');
  66101. }
  66102. }
  66103. ctx.seen.push(value);
  66104. var output;
  66105. if (array) {
  66106. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  66107. } else {
  66108. output = keys.map(function (key) {
  66109. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  66110. });
  66111. }
  66112. ctx.seen.pop();
  66113. return reduceToSingleString(output, base, braces);
  66114. }
  66115. function formatPrimitive(ctx, value) {
  66116. if (isUndefined(value)) return ctx.stylize('undefined', 'undefined');
  66117. if (isString(value)) {
  66118. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '').replace(/'/g, "\\'").replace(/\\"/g, '"') + '\'';
  66119. return ctx.stylize(simple, 'string');
  66120. }
  66121. if (isNumber(value)) return ctx.stylize('' + value, 'number');
  66122. if (isBoolean(value)) return ctx.stylize('' + value, 'boolean'); // For some reason typeof null is "object", so special case here.
  66123. if (isNull(value)) return ctx.stylize('null', 'null');
  66124. }
  66125. function formatError(value) {
  66126. return '[' + Error.prototype.toString.call(value) + ']';
  66127. }
  66128. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  66129. var output = [];
  66130. for (var i = 0, l = value.length; i < l; ++i) {
  66131. if (hasOwnProperty(value, String(i))) {
  66132. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, String(i), true));
  66133. } else {
  66134. output.push('');
  66135. }
  66136. }
  66137. keys.forEach(function (key) {
  66138. if (!key.match(/^\d+$/)) {
  66139. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, key, true));
  66140. }
  66141. });
  66142. return output;
  66143. }
  66144. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  66145. var name, str, desc;
  66146. desc = Object.getOwnPropertyDescriptor(value, key) || {
  66147. value: value[key]
  66148. };
  66149. if (desc.get) {
  66150. if (desc.set) {
  66151. str = ctx.stylize('[Getter/Setter]', 'special');
  66152. } else {
  66153. str = ctx.stylize('[Getter]', 'special');
  66154. }
  66155. } else {
  66156. if (desc.set) {
  66157. str = ctx.stylize('[Setter]', 'special');
  66158. }
  66159. }
  66160. if (!hasOwnProperty(visibleKeys, key)) {
  66161. name = '[' + key + ']';
  66162. }
  66163. if (!str) {
  66164. if (ctx.seen.indexOf(desc.value) < 0) {
  66165. if (isNull(recurseTimes)) {
  66166. str = formatValue(ctx, desc.value, null);
  66167. } else {
  66168. str = formatValue(ctx, desc.value, recurseTimes - 1);
  66169. }
  66170. if (str.indexOf('\n') > -1) {
  66171. if (array) {
  66172. str = str.split('\n').map(function (line) {
  66173. return ' ' + line;
  66174. }).join('\n').substr(2);
  66175. } else {
  66176. str = '\n' + str.split('\n').map(function (line) {
  66177. return ' ' + line;
  66178. }).join('\n');
  66179. }
  66180. }
  66181. } else {
  66182. str = ctx.stylize('[Circular]', 'special');
  66183. }
  66184. }
  66185. if (isUndefined(name)) {
  66186. if (array && key.match(/^\d+$/)) {
  66187. return str;
  66188. }
  66189. name = JSON.stringify('' + key);
  66190. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  66191. name = name.substr(1, name.length - 2);
  66192. name = ctx.stylize(name, 'name');
  66193. } else {
  66194. name = name.replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'");
  66195. name = ctx.stylize(name, 'string');
  66196. }
  66197. }
  66198. return name + ': ' + str;
  66199. }
  66200. function reduceToSingleString(output, base, braces) {
  66201. var numLinesEst = 0;
  66202. var length = output.reduce(function (prev, cur) {
  66203. numLinesEst++;
  66204. if (cur.indexOf('\n') >= 0) numLinesEst++;
  66205. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  66206. }, 0);
  66207. if (length > 60) {
  66208. return braces[0] + (base === '' ? '' : base + '\n ') + ' ' + output.join(',\n ') + ' ' + braces[1];
  66209. }
  66210. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  66211. } // NOTE: These type checking functions intentionally don't use `instanceof`
  66212. // because it is fragile and can be easily faked with `Object.create()`.
  66213. function isArray(ar) {
  66214. return Array.isArray(ar);
  66215. }
  66216. exports.isArray = isArray;
  66217. function isBoolean(arg) {
  66218. return typeof arg === 'boolean';
  66219. }
  66220. exports.isBoolean = isBoolean;
  66221. function isNull(arg) {
  66222. return arg === null;
  66223. }
  66224. exports.isNull = isNull;
  66225. function isNullOrUndefined(arg) {
  66226. return arg == null;
  66227. }
  66228. exports.isNullOrUndefined = isNullOrUndefined;
  66229. function isNumber(arg) {
  66230. return typeof arg === 'number';
  66231. }
  66232. exports.isNumber = isNumber;
  66233. function isString(arg) {
  66234. return typeof arg === 'string';
  66235. }
  66236. exports.isString = isString;
  66237. function isSymbol(arg) {
  66238. return _typeof(arg) === 'symbol';
  66239. }
  66240. exports.isSymbol = isSymbol;
  66241. function isUndefined(arg) {
  66242. return arg === void 0;
  66243. }
  66244. exports.isUndefined = isUndefined;
  66245. function isRegExp(re) {
  66246. return isObject(re) && objectToString(re) === '[object RegExp]';
  66247. }
  66248. exports.isRegExp = isRegExp;
  66249. function isObject(arg) {
  66250. return _typeof(arg) === 'object' && arg !== null;
  66251. }
  66252. exports.isObject = isObject;
  66253. function isDate(d) {
  66254. return isObject(d) && objectToString(d) === '[object Date]';
  66255. }
  66256. exports.isDate = isDate;
  66257. function isError(e) {
  66258. return isObject(e) && (objectToString(e) === '[object Error]' || e instanceof Error);
  66259. }
  66260. exports.isError = isError;
  66261. function isFunction(arg) {
  66262. return typeof arg === 'function';
  66263. }
  66264. exports.isFunction = isFunction;
  66265. function isPrimitive(arg) {
  66266. return arg === null || typeof arg === 'boolean' || typeof arg === 'number' || typeof arg === 'string' || _typeof(arg) === 'symbol' || // ES6 symbol
  66267. typeof arg === 'undefined';
  66268. }
  66269. exports.isPrimitive = isPrimitive;
  66270. exports.isBuffer = require('./support/isBuffer');
  66271. function objectToString(o) {
  66272. return Object.prototype.toString.call(o);
  66273. }
  66274. function pad(n) {
  66275. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  66276. }
  66277. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; // 26 Feb 16:19:34
  66278. function timestamp() {
  66279. var d = new Date();
  66280. var time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(':');
  66281. return [d.getDate(), months[d.getMonth()], time].join(' ');
  66282. } // log is just a thin wrapper to console.log that prepends a timestamp
  66283. exports.log = function () {
  66284. console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
  66285. };
  66286. /**
  66287. * Inherit the prototype methods from one constructor into another.
  66288. *
  66289. * The Function.prototype.inherits from lang.js rewritten as a standalone
  66290. * function (not on Function.prototype). NOTE: If this file is to be loaded
  66291. * during bootstrapping this function needs to be rewritten using some native
  66292. * functions as prototype setup using normal JavaScript does not work as
  66293. * expected during bootstrapping (see mirror.js in r114903).
  66294. *
  66295. * @param {function} ctor Constructor function which needs to inherit the
  66296. * prototype.
  66297. * @param {function} superCtor Constructor function to inherit prototype from.
  66298. */
  66299. exports.inherits = require('inherits');
  66300. exports._extend = function (origin, add) {
  66301. // Don't do anything if add isn't an object
  66302. if (!add || !isObject(add)) return origin;
  66303. var keys = Object.keys(add);
  66304. var i = keys.length;
  66305. while (i--) {
  66306. origin[keys[i]] = add[keys[i]];
  66307. }
  66308. return origin;
  66309. };
  66310. function hasOwnProperty(obj, prop) {
  66311. return Object.prototype.hasOwnProperty.call(obj, prop);
  66312. }
  66313. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  66314. },{"./support/isBuffer":524,"_process":467,"inherits":523}],526:[function(require,module,exports){
  66315. "use strict";
  66316. Object.defineProperty(exports, "__esModule", {
  66317. value: true
  66318. });
  66319. Object.defineProperty(exports, "v1", {
  66320. enumerable: true,
  66321. get: function get() {
  66322. return _v.default;
  66323. }
  66324. });
  66325. Object.defineProperty(exports, "v3", {
  66326. enumerable: true,
  66327. get: function get() {
  66328. return _v2.default;
  66329. }
  66330. });
  66331. Object.defineProperty(exports, "v4", {
  66332. enumerable: true,
  66333. get: function get() {
  66334. return _v3.default;
  66335. }
  66336. });
  66337. Object.defineProperty(exports, "v5", {
  66338. enumerable: true,
  66339. get: function get() {
  66340. return _v4.default;
  66341. }
  66342. });
  66343. Object.defineProperty(exports, "NIL", {
  66344. enumerable: true,
  66345. get: function get() {
  66346. return _nil.default;
  66347. }
  66348. });
  66349. Object.defineProperty(exports, "version", {
  66350. enumerable: true,
  66351. get: function get() {
  66352. return _version.default;
  66353. }
  66354. });
  66355. Object.defineProperty(exports, "validate", {
  66356. enumerable: true,
  66357. get: function get() {
  66358. return _validate.default;
  66359. }
  66360. });
  66361. Object.defineProperty(exports, "stringify", {
  66362. enumerable: true,
  66363. get: function get() {
  66364. return _stringify.default;
  66365. }
  66366. });
  66367. Object.defineProperty(exports, "parse", {
  66368. enumerable: true,
  66369. get: function get() {
  66370. return _parse.default;
  66371. }
  66372. });
  66373. var _v = _interopRequireDefault(require("./v1.js"));
  66374. var _v2 = _interopRequireDefault(require("./v3.js"));
  66375. var _v3 = _interopRequireDefault(require("./v4.js"));
  66376. var _v4 = _interopRequireDefault(require("./v5.js"));
  66377. var _nil = _interopRequireDefault(require("./nil.js"));
  66378. var _version = _interopRequireDefault(require("./version.js"));
  66379. var _validate = _interopRequireDefault(require("./validate.js"));
  66380. var _stringify = _interopRequireDefault(require("./stringify.js"));
  66381. var _parse = _interopRequireDefault(require("./parse.js"));
  66382. function _interopRequireDefault(obj) {
  66383. return obj && obj.__esModule ? obj : {
  66384. default: obj
  66385. };
  66386. }
  66387. },{"./nil.js":528,"./parse.js":529,"./stringify.js":533,"./v1.js":534,"./v3.js":535,"./v4.js":537,"./v5.js":538,"./validate.js":539,"./version.js":540}],527:[function(require,module,exports){
  66388. "use strict";
  66389. Object.defineProperty(exports, "__esModule", {
  66390. value: true
  66391. });
  66392. exports.default = void 0;
  66393. /*
  66394. * Browser-compatible JavaScript MD5
  66395. *
  66396. * Modification of JavaScript MD5
  66397. * https://github.com/blueimp/JavaScript-MD5
  66398. *
  66399. * Copyright 2011, Sebastian Tschan
  66400. * https://blueimp.net
  66401. *
  66402. * Licensed under the MIT license:
  66403. * https://opensource.org/licenses/MIT
  66404. *
  66405. * Based on
  66406. * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
  66407. * Digest Algorithm, as defined in RFC 1321.
  66408. * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
  66409. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  66410. * Distributed under the BSD License
  66411. * See http://pajhome.org.uk/crypt/md5 for more info.
  66412. */
  66413. function md5(bytes) {
  66414. if (typeof bytes === 'string') {
  66415. var msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
  66416. bytes = new Uint8Array(msg.length);
  66417. for (var i = 0; i < msg.length; ++i) {
  66418. bytes[i] = msg.charCodeAt(i);
  66419. }
  66420. }
  66421. return md5ToHexEncodedArray(wordsToMd5(bytesToWords(bytes), bytes.length * 8));
  66422. }
  66423. /*
  66424. * Convert an array of little-endian words to an array of bytes
  66425. */
  66426. function md5ToHexEncodedArray(input) {
  66427. var output = [];
  66428. var length32 = input.length * 32;
  66429. var hexTab = '0123456789abcdef';
  66430. for (var i = 0; i < length32; i += 8) {
  66431. var x = input[i >> 5] >>> i % 32 & 0xff;
  66432. var hex = parseInt(hexTab.charAt(x >>> 4 & 0x0f) + hexTab.charAt(x & 0x0f), 16);
  66433. output.push(hex);
  66434. }
  66435. return output;
  66436. }
  66437. /**
  66438. * Calculate output length with padding and bit length
  66439. */
  66440. function getOutputLength(inputLength8) {
  66441. return (inputLength8 + 64 >>> 9 << 4) + 14 + 1;
  66442. }
  66443. /*
  66444. * Calculate the MD5 of an array of little-endian words, and a bit length.
  66445. */
  66446. function wordsToMd5(x, len) {
  66447. /* append padding */
  66448. x[len >> 5] |= 0x80 << len % 32;
  66449. x[getOutputLength(len) - 1] = len;
  66450. var a = 1732584193;
  66451. var b = -271733879;
  66452. var c = -1732584194;
  66453. var d = 271733878;
  66454. for (var i = 0; i < x.length; i += 16) {
  66455. var olda = a;
  66456. var oldb = b;
  66457. var oldc = c;
  66458. var oldd = d;
  66459. a = md5ff(a, b, c, d, x[i], 7, -680876936);
  66460. d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
  66461. c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
  66462. b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330);
  66463. a = md5ff(a, b, c, d, x[i + 4], 7, -176418897);
  66464. d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426);
  66465. c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341);
  66466. b = md5ff(b, c, d, a, x[i + 7], 22, -45705983);
  66467. a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416);
  66468. d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417);
  66469. c = md5ff(c, d, a, b, x[i + 10], 17, -42063);
  66470. b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162);
  66471. a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682);
  66472. d = md5ff(d, a, b, c, x[i + 13], 12, -40341101);
  66473. c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290);
  66474. b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329);
  66475. a = md5gg(a, b, c, d, x[i + 1], 5, -165796510);
  66476. d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632);
  66477. c = md5gg(c, d, a, b, x[i + 11], 14, 643717713);
  66478. b = md5gg(b, c, d, a, x[i], 20, -373897302);
  66479. a = md5gg(a, b, c, d, x[i + 5], 5, -701558691);
  66480. d = md5gg(d, a, b, c, x[i + 10], 9, 38016083);
  66481. c = md5gg(c, d, a, b, x[i + 15], 14, -660478335);
  66482. b = md5gg(b, c, d, a, x[i + 4], 20, -405537848);
  66483. a = md5gg(a, b, c, d, x[i + 9], 5, 568446438);
  66484. d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690);
  66485. c = md5gg(c, d, a, b, x[i + 3], 14, -187363961);
  66486. b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501);
  66487. a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467);
  66488. d = md5gg(d, a, b, c, x[i + 2], 9, -51403784);
  66489. c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473);
  66490. b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734);
  66491. a = md5hh(a, b, c, d, x[i + 5], 4, -378558);
  66492. d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463);
  66493. c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562);
  66494. b = md5hh(b, c, d, a, x[i + 14], 23, -35309556);
  66495. a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060);
  66496. d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353);
  66497. c = md5hh(c, d, a, b, x[i + 7], 16, -155497632);
  66498. b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640);
  66499. a = md5hh(a, b, c, d, x[i + 13], 4, 681279174);
  66500. d = md5hh(d, a, b, c, x[i], 11, -358537222);
  66501. c = md5hh(c, d, a, b, x[i + 3], 16, -722521979);
  66502. b = md5hh(b, c, d, a, x[i + 6], 23, 76029189);
  66503. a = md5hh(a, b, c, d, x[i + 9], 4, -640364487);
  66504. d = md5hh(d, a, b, c, x[i + 12], 11, -421815835);
  66505. c = md5hh(c, d, a, b, x[i + 15], 16, 530742520);
  66506. b = md5hh(b, c, d, a, x[i + 2], 23, -995338651);
  66507. a = md5ii(a, b, c, d, x[i], 6, -198630844);
  66508. d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415);
  66509. c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905);
  66510. b = md5ii(b, c, d, a, x[i + 5], 21, -57434055);
  66511. a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571);
  66512. d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606);
  66513. c = md5ii(c, d, a, b, x[i + 10], 15, -1051523);
  66514. b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799);
  66515. a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359);
  66516. d = md5ii(d, a, b, c, x[i + 15], 10, -30611744);
  66517. c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380);
  66518. b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649);
  66519. a = md5ii(a, b, c, d, x[i + 4], 6, -145523070);
  66520. d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379);
  66521. c = md5ii(c, d, a, b, x[i + 2], 15, 718787259);
  66522. b = md5ii(b, c, d, a, x[i + 9], 21, -343485551);
  66523. a = safeAdd(a, olda);
  66524. b = safeAdd(b, oldb);
  66525. c = safeAdd(c, oldc);
  66526. d = safeAdd(d, oldd);
  66527. }
  66528. return [a, b, c, d];
  66529. }
  66530. /*
  66531. * Convert an array bytes to an array of little-endian words
  66532. * Characters >255 have their high-byte silently ignored.
  66533. */
  66534. function bytesToWords(input) {
  66535. if (input.length === 0) {
  66536. return [];
  66537. }
  66538. var length8 = input.length * 8;
  66539. var output = new Uint32Array(getOutputLength(length8));
  66540. for (var i = 0; i < length8; i += 8) {
  66541. output[i >> 5] |= (input[i / 8] & 0xff) << i % 32;
  66542. }
  66543. return output;
  66544. }
  66545. /*
  66546. * Add integers, wrapping at 2^32. This uses 16-bit operations internally
  66547. * to work around bugs in some JS interpreters.
  66548. */
  66549. function safeAdd(x, y) {
  66550. var lsw = (x & 0xffff) + (y & 0xffff);
  66551. var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  66552. return msw << 16 | lsw & 0xffff;
  66553. }
  66554. /*
  66555. * Bitwise rotate a 32-bit number to the left.
  66556. */
  66557. function bitRotateLeft(num, cnt) {
  66558. return num << cnt | num >>> 32 - cnt;
  66559. }
  66560. /*
  66561. * These functions implement the four basic operations the algorithm uses.
  66562. */
  66563. function md5cmn(q, a, b, x, s, t) {
  66564. return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b);
  66565. }
  66566. function md5ff(a, b, c, d, x, s, t) {
  66567. return md5cmn(b & c | ~b & d, a, b, x, s, t);
  66568. }
  66569. function md5gg(a, b, c, d, x, s, t) {
  66570. return md5cmn(b & d | c & ~d, a, b, x, s, t);
  66571. }
  66572. function md5hh(a, b, c, d, x, s, t) {
  66573. return md5cmn(b ^ c ^ d, a, b, x, s, t);
  66574. }
  66575. function md5ii(a, b, c, d, x, s, t) {
  66576. return md5cmn(c ^ (b | ~d), a, b, x, s, t);
  66577. }
  66578. var _default = md5;
  66579. exports.default = _default;
  66580. },{}],528:[function(require,module,exports){
  66581. "use strict";
  66582. Object.defineProperty(exports, "__esModule", {
  66583. value: true
  66584. });
  66585. exports.default = void 0;
  66586. var _default = '00000000-0000-0000-0000-000000000000';
  66587. exports.default = _default;
  66588. },{}],529:[function(require,module,exports){
  66589. "use strict";
  66590. Object.defineProperty(exports, "__esModule", {
  66591. value: true
  66592. });
  66593. exports.default = void 0;
  66594. var _validate = _interopRequireDefault(require("./validate.js"));
  66595. function _interopRequireDefault(obj) {
  66596. return obj && obj.__esModule ? obj : {
  66597. default: obj
  66598. };
  66599. }
  66600. function parse(uuid) {
  66601. if (!(0, _validate.default)(uuid)) {
  66602. throw TypeError('Invalid UUID');
  66603. }
  66604. var v;
  66605. var arr = new Uint8Array(16); // Parse ########-....-....-....-............
  66606. arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;
  66607. arr[1] = v >>> 16 & 0xff;
  66608. arr[2] = v >>> 8 & 0xff;
  66609. arr[3] = v & 0xff; // Parse ........-####-....-....-............
  66610. arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8;
  66611. arr[5] = v & 0xff; // Parse ........-....-####-....-............
  66612. arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8;
  66613. arr[7] = v & 0xff; // Parse ........-....-....-####-............
  66614. arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8;
  66615. arr[9] = v & 0xff; // Parse ........-....-....-....-############
  66616. // (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
  66617. arr[10] = (v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000 & 0xff;
  66618. arr[11] = v / 0x100000000 & 0xff;
  66619. arr[12] = v >>> 24 & 0xff;
  66620. arr[13] = v >>> 16 & 0xff;
  66621. arr[14] = v >>> 8 & 0xff;
  66622. arr[15] = v & 0xff;
  66623. return arr;
  66624. }
  66625. var _default = parse;
  66626. exports.default = _default;
  66627. },{"./validate.js":539}],530:[function(require,module,exports){
  66628. "use strict";
  66629. Object.defineProperty(exports, "__esModule", {
  66630. value: true
  66631. });
  66632. exports.default = void 0;
  66633. 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;
  66634. exports.default = _default;
  66635. },{}],531:[function(require,module,exports){
  66636. "use strict";
  66637. Object.defineProperty(exports, "__esModule", {
  66638. value: true
  66639. });
  66640. exports.default = rng; // Unique ID creation requires a high quality random # generator. In the browser we therefore
  66641. // require the crypto API and do not support built-in fallback to lower quality random number
  66642. // generators (like Math.random()).
  66643. // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
  66644. // find the complete implementation of crypto (msCrypto) on IE11.
  66645. var getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
  66646. var rnds8 = new Uint8Array(16);
  66647. function rng() {
  66648. if (!getRandomValues) {
  66649. throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
  66650. }
  66651. return getRandomValues(rnds8);
  66652. }
  66653. },{}],532:[function(require,module,exports){
  66654. "use strict";
  66655. Object.defineProperty(exports, "__esModule", {
  66656. value: true
  66657. });
  66658. exports.default = void 0; // Adapted from Chris Veness' SHA1 code at
  66659. // http://www.movable-type.co.uk/scripts/sha1.html
  66660. function f(s, x, y, z) {
  66661. switch (s) {
  66662. case 0:
  66663. return x & y ^ ~x & z;
  66664. case 1:
  66665. return x ^ y ^ z;
  66666. case 2:
  66667. return x & y ^ x & z ^ y & z;
  66668. case 3:
  66669. return x ^ y ^ z;
  66670. }
  66671. }
  66672. function ROTL(x, n) {
  66673. return x << n | x >>> 32 - n;
  66674. }
  66675. function sha1(bytes) {
  66676. var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
  66677. var H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
  66678. if (typeof bytes === 'string') {
  66679. var msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
  66680. bytes = [];
  66681. for (var i = 0; i < msg.length; ++i) {
  66682. bytes.push(msg.charCodeAt(i));
  66683. }
  66684. } else if (!Array.isArray(bytes)) {
  66685. // Convert Array-like to Array
  66686. bytes = Array.prototype.slice.call(bytes);
  66687. }
  66688. bytes.push(0x80);
  66689. var l = bytes.length / 4 + 2;
  66690. var N = Math.ceil(l / 16);
  66691. var M = new Array(N);
  66692. for (var _i = 0; _i < N; ++_i) {
  66693. var arr = new Uint32Array(16);
  66694. for (var j = 0; j < 16; ++j) {
  66695. 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];
  66696. }
  66697. M[_i] = arr;
  66698. }
  66699. M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32);
  66700. M[N - 1][14] = Math.floor(M[N - 1][14]);
  66701. M[N - 1][15] = (bytes.length - 1) * 8 & 0xffffffff;
  66702. for (var _i2 = 0; _i2 < N; ++_i2) {
  66703. var W = new Uint32Array(80);
  66704. for (var t = 0; t < 16; ++t) {
  66705. W[t] = M[_i2][t];
  66706. }
  66707. for (var _t = 16; _t < 80; ++_t) {
  66708. W[_t] = ROTL(W[_t - 3] ^ W[_t - 8] ^ W[_t - 14] ^ W[_t - 16], 1);
  66709. }
  66710. var a = H[0];
  66711. var b = H[1];
  66712. var c = H[2];
  66713. var d = H[3];
  66714. var e = H[4];
  66715. for (var _t2 = 0; _t2 < 80; ++_t2) {
  66716. var s = Math.floor(_t2 / 20);
  66717. var T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[_t2] >>> 0;
  66718. e = d;
  66719. d = c;
  66720. c = ROTL(b, 30) >>> 0;
  66721. b = a;
  66722. a = T;
  66723. }
  66724. H[0] = H[0] + a >>> 0;
  66725. H[1] = H[1] + b >>> 0;
  66726. H[2] = H[2] + c >>> 0;
  66727. H[3] = H[3] + d >>> 0;
  66728. H[4] = H[4] + e >>> 0;
  66729. }
  66730. 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];
  66731. }
  66732. var _default = sha1;
  66733. exports.default = _default;
  66734. },{}],533:[function(require,module,exports){
  66735. "use strict";
  66736. Object.defineProperty(exports, "__esModule", {
  66737. value: true
  66738. });
  66739. exports.default = void 0;
  66740. var _validate = _interopRequireDefault(require("./validate.js"));
  66741. function _interopRequireDefault(obj) {
  66742. return obj && obj.__esModule ? obj : {
  66743. default: obj
  66744. };
  66745. }
  66746. /**
  66747. * Convert array of 16 byte values to UUID string format of the form:
  66748. * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
  66749. */
  66750. var byteToHex = [];
  66751. for (var i = 0; i < 256; ++i) {
  66752. byteToHex.push((i + 0x100).toString(16).substr(1));
  66753. }
  66754. function stringify(arr) {
  66755. var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  66756. // Note: Be careful editing this code! It's been tuned for performance
  66757. // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
  66758. var 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
  66759. // of the following:
  66760. // - One or more input array values don't map to a hex octet (leading to
  66761. // "undefined" in the uuid)
  66762. // - Invalid input values for the RFC `version` or `variant` fields
  66763. if (!(0, _validate.default)(uuid)) {
  66764. throw TypeError('Stringified UUID is invalid');
  66765. }
  66766. return uuid;
  66767. }
  66768. var _default = stringify;
  66769. exports.default = _default;
  66770. },{"./validate.js":539}],534:[function(require,module,exports){
  66771. "use strict";
  66772. Object.defineProperty(exports, "__esModule", {
  66773. value: true
  66774. });
  66775. exports.default = void 0;
  66776. var _rng = _interopRequireDefault(require("./rng.js"));
  66777. var _stringify = _interopRequireDefault(require("./stringify.js"));
  66778. function _interopRequireDefault(obj) {
  66779. return obj && obj.__esModule ? obj : {
  66780. default: obj
  66781. };
  66782. } // **`v1()` - Generate time-based UUID**
  66783. //
  66784. // Inspired by https://github.com/LiosK/UUID.js
  66785. // and http://docs.python.org/library/uuid.html
  66786. var _nodeId;
  66787. var _clockseq; // Previous uuid creation time
  66788. var _lastMSecs = 0;
  66789. var _lastNSecs = 0; // See https://github.com/uuidjs/uuid for API details
  66790. function v1(options, buf, offset) {
  66791. var i = buf && offset || 0;
  66792. var b = buf || new Array(16);
  66793. options = options || {};
  66794. var node = options.node || _nodeId;
  66795. var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq; // node and clockseq need to be initialized to random values if they're not
  66796. // specified. We do this lazily to minimize issues related to insufficient
  66797. // system entropy. See #189
  66798. if (node == null || clockseq == null) {
  66799. var seedBytes = options.random || (options.rng || _rng.default)();
  66800. if (node == null) {
  66801. // Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
  66802. node = _nodeId = [seedBytes[0] | 0x01, seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]];
  66803. }
  66804. if (clockseq == null) {
  66805. // Per 4.2.2, randomize (14 bit) clockseq
  66806. clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 0x3fff;
  66807. }
  66808. } // UUID timestamps are 100 nano-second units since the Gregorian epoch,
  66809. // (1582-10-15 00:00). JSNumbers aren't precise enough for this, so
  66810. // time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'
  66811. // (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.
  66812. var msecs = options.msecs !== undefined ? options.msecs : Date.now(); // Per 4.2.1.2, use count of uuid's generated during the current clock
  66813. // cycle to simulate higher resolution clock
  66814. var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1; // Time since last uuid creation (in msecs)
  66815. var dt = msecs - _lastMSecs + (nsecs - _lastNSecs) / 10000; // Per 4.2.1.2, Bump clockseq on clock regression
  66816. if (dt < 0 && options.clockseq === undefined) {
  66817. clockseq = clockseq + 1 & 0x3fff;
  66818. } // Reset nsecs if clock regresses (new clockseq) or we've moved onto a new
  66819. // time interval
  66820. if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) {
  66821. nsecs = 0;
  66822. } // Per 4.2.1.2 Throw error if too many uuids are requested
  66823. if (nsecs >= 10000) {
  66824. throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");
  66825. }
  66826. _lastMSecs = msecs;
  66827. _lastNSecs = nsecs;
  66828. _clockseq = clockseq; // Per 4.1.4 - Convert from unix epoch to Gregorian epoch
  66829. msecs += 12219292800000; // `time_low`
  66830. var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
  66831. b[i++] = tl >>> 24 & 0xff;
  66832. b[i++] = tl >>> 16 & 0xff;
  66833. b[i++] = tl >>> 8 & 0xff;
  66834. b[i++] = tl & 0xff; // `time_mid`
  66835. var tmh = msecs / 0x100000000 * 10000 & 0xfffffff;
  66836. b[i++] = tmh >>> 8 & 0xff;
  66837. b[i++] = tmh & 0xff; // `time_high_and_version`
  66838. b[i++] = tmh >>> 24 & 0xf | 0x10; // include version
  66839. b[i++] = tmh >>> 16 & 0xff; // `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)
  66840. b[i++] = clockseq >>> 8 | 0x80; // `clock_seq_low`
  66841. b[i++] = clockseq & 0xff; // `node`
  66842. for (var n = 0; n < 6; ++n) {
  66843. b[i + n] = node[n];
  66844. }
  66845. return buf || (0, _stringify.default)(b);
  66846. }
  66847. var _default = v1;
  66848. exports.default = _default;
  66849. },{"./rng.js":531,"./stringify.js":533}],535:[function(require,module,exports){
  66850. "use strict";
  66851. Object.defineProperty(exports, "__esModule", {
  66852. value: true
  66853. });
  66854. exports.default = void 0;
  66855. var _v = _interopRequireDefault(require("./v35.js"));
  66856. var _md = _interopRequireDefault(require("./md5.js"));
  66857. function _interopRequireDefault(obj) {
  66858. return obj && obj.__esModule ? obj : {
  66859. default: obj
  66860. };
  66861. }
  66862. var v3 = (0, _v.default)('v3', 0x30, _md.default);
  66863. var _default = v3;
  66864. exports.default = _default;
  66865. },{"./md5.js":527,"./v35.js":536}],536:[function(require,module,exports){
  66866. "use strict";
  66867. Object.defineProperty(exports, "__esModule", {
  66868. value: true
  66869. });
  66870. exports.default = _default;
  66871. exports.URL = exports.DNS = void 0;
  66872. var _stringify = _interopRequireDefault(require("./stringify.js"));
  66873. var _parse = _interopRequireDefault(require("./parse.js"));
  66874. function _interopRequireDefault(obj) {
  66875. return obj && obj.__esModule ? obj : {
  66876. default: obj
  66877. };
  66878. }
  66879. function stringToBytes(str) {
  66880. str = unescape(encodeURIComponent(str)); // UTF8 escape
  66881. var bytes = [];
  66882. for (var i = 0; i < str.length; ++i) {
  66883. bytes.push(str.charCodeAt(i));
  66884. }
  66885. return bytes;
  66886. }
  66887. var DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
  66888. exports.DNS = DNS;
  66889. var URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
  66890. exports.URL = URL;
  66891. function _default(name, version, hashfunc) {
  66892. function generateUUID(value, namespace, buf, offset) {
  66893. if (typeof value === 'string') {
  66894. value = stringToBytes(value);
  66895. }
  66896. if (typeof namespace === 'string') {
  66897. namespace = (0, _parse.default)(namespace);
  66898. }
  66899. if (namespace.length !== 16) {
  66900. throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');
  66901. } // Compute hash of namespace and value, Per 4.3
  66902. // Future: Use spread syntax when supported on all platforms, e.g. `bytes =
  66903. // hashfunc([...namespace, ... value])`
  66904. var bytes = new Uint8Array(16 + value.length);
  66905. bytes.set(namespace);
  66906. bytes.set(value, namespace.length);
  66907. bytes = hashfunc(bytes);
  66908. bytes[6] = bytes[6] & 0x0f | version;
  66909. bytes[8] = bytes[8] & 0x3f | 0x80;
  66910. if (buf) {
  66911. offset = offset || 0;
  66912. for (var i = 0; i < 16; ++i) {
  66913. buf[offset + i] = bytes[i];
  66914. }
  66915. return buf;
  66916. }
  66917. return (0, _stringify.default)(bytes);
  66918. } // Function#name is not settable on some platforms (#270)
  66919. try {
  66920. generateUUID.name = name; // eslint-disable-next-line no-empty
  66921. } catch (err) {} // For CommonJS default export support
  66922. generateUUID.DNS = DNS;
  66923. generateUUID.URL = URL;
  66924. return generateUUID;
  66925. }
  66926. },{"./parse.js":529,"./stringify.js":533}],537:[function(require,module,exports){
  66927. "use strict";
  66928. Object.defineProperty(exports, "__esModule", {
  66929. value: true
  66930. });
  66931. exports.default = void 0;
  66932. var _rng = _interopRequireDefault(require("./rng.js"));
  66933. var _stringify = _interopRequireDefault(require("./stringify.js"));
  66934. function _interopRequireDefault(obj) {
  66935. return obj && obj.__esModule ? obj : {
  66936. default: obj
  66937. };
  66938. }
  66939. function v4(options, buf, offset) {
  66940. options = options || {};
  66941. var rnds = options.random || (options.rng || _rng.default)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
  66942. rnds[6] = rnds[6] & 0x0f | 0x40;
  66943. rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
  66944. if (buf) {
  66945. offset = offset || 0;
  66946. for (var i = 0; i < 16; ++i) {
  66947. buf[offset + i] = rnds[i];
  66948. }
  66949. return buf;
  66950. }
  66951. return (0, _stringify.default)(rnds);
  66952. }
  66953. var _default = v4;
  66954. exports.default = _default;
  66955. },{"./rng.js":531,"./stringify.js":533}],538:[function(require,module,exports){
  66956. "use strict";
  66957. Object.defineProperty(exports, "__esModule", {
  66958. value: true
  66959. });
  66960. exports.default = void 0;
  66961. var _v = _interopRequireDefault(require("./v35.js"));
  66962. var _sha = _interopRequireDefault(require("./sha1.js"));
  66963. function _interopRequireDefault(obj) {
  66964. return obj && obj.__esModule ? obj : {
  66965. default: obj
  66966. };
  66967. }
  66968. var v5 = (0, _v.default)('v5', 0x50, _sha.default);
  66969. var _default = v5;
  66970. exports.default = _default;
  66971. },{"./sha1.js":532,"./v35.js":536}],539:[function(require,module,exports){
  66972. "use strict";
  66973. Object.defineProperty(exports, "__esModule", {
  66974. value: true
  66975. });
  66976. exports.default = void 0;
  66977. var _regex = _interopRequireDefault(require("./regex.js"));
  66978. function _interopRequireDefault(obj) {
  66979. return obj && obj.__esModule ? obj : {
  66980. default: obj
  66981. };
  66982. }
  66983. function validate(uuid) {
  66984. return typeof uuid === 'string' && _regex.default.test(uuid);
  66985. }
  66986. var _default = validate;
  66987. exports.default = _default;
  66988. },{"./regex.js":530}],540:[function(require,module,exports){
  66989. "use strict";
  66990. Object.defineProperty(exports, "__esModule", {
  66991. value: true
  66992. });
  66993. exports.default = void 0;
  66994. var _validate = _interopRequireDefault(require("./validate.js"));
  66995. function _interopRequireDefault(obj) {
  66996. return obj && obj.__esModule ? obj : {
  66997. default: obj
  66998. };
  66999. }
  67000. function version(uuid) {
  67001. if (!(0, _validate.default)(uuid)) {
  67002. throw TypeError('Invalid UUID');
  67003. }
  67004. return parseInt(uuid.substr(14, 1), 16);
  67005. }
  67006. var _default = version;
  67007. exports.default = _default;
  67008. },{"./validate.js":539}],541:[function(require,module,exports){
  67009. "use strict";
  67010. /**
  67011. * Character classes and associated utilities for the 5th edition of XML 1.0.
  67012. *
  67013. * @author Louis-Dominique Dubeau
  67014. * @license MIT
  67015. * @copyright Louis-Dominique Dubeau
  67016. */
  67017. Object.defineProperty(exports, "__esModule", {
  67018. value: true
  67019. }); //
  67020. // Fragments.
  67021. //
  67022. exports.CHAR = "\t\n\r -\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF";
  67023. exports.S = " \t\r\n"; // tslint:disable-next-line:max-line-length
  67024. exports.NAME_START_CHAR = ":A-Z_a-z\xC0-\xD6\xD8-\xF6\xF8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\uD800\uDC00-\uDB7F\uDFFF";
  67025. exports.NAME_CHAR = "-" + exports.NAME_START_CHAR + ".0-9\xB7\u0300-\u036F\u203F-\u2040"; //
  67026. // Regular expressions.
  67027. //
  67028. exports.CHAR_RE = new RegExp("^[" + exports.CHAR + "]$", "u");
  67029. exports.S_RE = new RegExp("^[" + exports.S + "]+$", "u");
  67030. exports.NAME_START_CHAR_RE = new RegExp("^[" + exports.NAME_START_CHAR + "]$", "u");
  67031. exports.NAME_CHAR_RE = new RegExp("^[" + exports.NAME_CHAR + "]$", "u");
  67032. exports.NAME_RE = new RegExp("^[" + exports.NAME_START_CHAR + "][" + exports.NAME_CHAR + "]*$", "u");
  67033. exports.NMTOKEN_RE = new RegExp("^[" + exports.NAME_CHAR + "]+$", "u");
  67034. var TAB = 9;
  67035. var NL = 0xA;
  67036. var CR = 0xD;
  67037. var SPACE = 0x20; //
  67038. // Lists.
  67039. //
  67040. /** All characters in the ``S`` production. */
  67041. exports.S_LIST = [SPACE, NL, CR, TAB];
  67042. /**
  67043. * Determines whether a codepoint matches the ``CHAR`` production.
  67044. *
  67045. * @param c The code point.
  67046. *
  67047. * @returns ``true`` if the codepoint matches ``CHAR``.
  67048. */
  67049. function isChar(c) {
  67050. return c >= SPACE && c <= 0xD7FF || c === NL || c === CR || c === TAB || c >= 0xE000 && c <= 0xFFFD || c >= 0x10000 && c <= 0x10FFFF;
  67051. }
  67052. exports.isChar = isChar;
  67053. /**
  67054. * Determines whether a codepoint matches the ``S`` (space) production.
  67055. *
  67056. * @param c The code point.
  67057. *
  67058. * @returns ``true`` if the codepoint matches ``S``.
  67059. */
  67060. function isS(c) {
  67061. return c === SPACE || c === NL || c === CR || c === TAB;
  67062. }
  67063. exports.isS = isS;
  67064. /**
  67065. * Determines whether a codepoint matches the ``NAME_START_CHAR`` production.
  67066. *
  67067. * @param c The code point.
  67068. *
  67069. * @returns ``true`` if the codepoint matches ``NAME_START_CHAR``.
  67070. */
  67071. function isNameStartChar(c) {
  67072. 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;
  67073. }
  67074. exports.isNameStartChar = isNameStartChar;
  67075. /**
  67076. * Determines whether a codepoint matches the ``NAME_CHAR`` production.
  67077. *
  67078. * @param c The code point.
  67079. *
  67080. * @returns ``true`` if the codepoint matches ``NAME_CHAR``.
  67081. */
  67082. function isNameChar(c) {
  67083. return isNameStartChar(c) || c >= 0x30 && c <= 0x39 || c === 0x2D || c === 0x2E || c === 0xB7 || c >= 0x0300 && c <= 0x036F || c >= 0x203F && c <= 0x2040;
  67084. }
  67085. exports.isNameChar = isNameChar;
  67086. },{}],542:[function(require,module,exports){
  67087. "use strict";
  67088. /**
  67089. * Character classes and associated utilities for the 2nd edition of XML 1.1.
  67090. *
  67091. * @author Louis-Dominique Dubeau
  67092. * @license MIT
  67093. * @copyright Louis-Dominique Dubeau
  67094. */
  67095. Object.defineProperty(exports, "__esModule", {
  67096. value: true
  67097. }); //
  67098. // Fragments.
  67099. //
  67100. exports.CHAR = "\x01-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF";
  67101. exports.RESTRICTED_CHAR = "\x01-\b\x0B\f\x0E-\x1F\x7F-\x84\x86-\x9F";
  67102. exports.S = " \t\r\n"; // tslint:disable-next-line:max-line-length
  67103. exports.NAME_START_CHAR = ":A-Z_a-z\xC0-\xD6\xD8-\xF6\xF8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\uD800\uDC00-\uDB7F\uDFFF";
  67104. exports.NAME_CHAR = "-" + exports.NAME_START_CHAR + ".0-9\xB7\u0300-\u036F\u203F-\u2040"; //
  67105. // Regular expressions.
  67106. //
  67107. exports.CHAR_RE = new RegExp("^[" + exports.CHAR + "]$", "u");
  67108. exports.RESTRICTED_CHAR_RE = new RegExp("^[" + exports.RESTRICTED_CHAR + "]$", "u");
  67109. exports.S_RE = new RegExp("^[" + exports.S + "]+$", "u");
  67110. exports.NAME_START_CHAR_RE = new RegExp("^[" + exports.NAME_START_CHAR + "]$", "u");
  67111. exports.NAME_CHAR_RE = new RegExp("^[" + exports.NAME_CHAR + "]$", "u");
  67112. exports.NAME_RE = new RegExp("^[" + exports.NAME_START_CHAR + "][" + exports.NAME_CHAR + "]*$", "u");
  67113. exports.NMTOKEN_RE = new RegExp("^[" + exports.NAME_CHAR + "]+$", "u");
  67114. var TAB = 9;
  67115. var NL = 0xA;
  67116. var CR = 0xD;
  67117. var SPACE = 0x20; //
  67118. // Lists.
  67119. //
  67120. /** All characters in the ``S`` production. */
  67121. exports.S_LIST = [SPACE, NL, CR, TAB];
  67122. /**
  67123. * Determines whether a codepoint matches the ``CHAR`` production.
  67124. *
  67125. * @param c The code point.
  67126. *
  67127. * @returns ``true`` if the codepoint matches ``CHAR``.
  67128. */
  67129. function isChar(c) {
  67130. return c >= 0x0001 && c <= 0xD7FF || c >= 0xE000 && c <= 0xFFFD || c >= 0x10000 && c <= 0x10FFFF;
  67131. }
  67132. exports.isChar = isChar;
  67133. /**
  67134. * Determines whether a codepoint matches the ``RESTRICTED_CHAR`` production.
  67135. *
  67136. * @param c The code point.
  67137. *
  67138. * @returns ``true`` if the codepoint matches ``RESTRICTED_CHAR``.
  67139. */
  67140. function isRestrictedChar(c) {
  67141. return c >= 0x1 && c <= 0x8 || c === 0xB || c === 0xC || c >= 0xE && c <= 0x1F || c >= 0x7F && c <= 0x84 || c >= 0x86 && c <= 0x9F;
  67142. }
  67143. exports.isRestrictedChar = isRestrictedChar;
  67144. /**
  67145. * Determines whether a codepoint matches the ``CHAR`` production and does not
  67146. * match the ``RESTRICTED_CHAR`` production. ``isCharAndNotRestricted(x)`` is
  67147. * equivalent to ``isChar(x) && !isRestrictedChar(x)``. This function is faster
  67148. * than running the two-call equivalent.
  67149. *
  67150. * @param c The code point.
  67151. *
  67152. * @returns ``true`` if the codepoint matches ``CHAR`` and does not match
  67153. * ``RESTRICTED_CHAR``.
  67154. */
  67155. function isCharAndNotRestricted(c) {
  67156. 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;
  67157. }
  67158. exports.isCharAndNotRestricted = isCharAndNotRestricted;
  67159. /**
  67160. * Determines whether a codepoint matches the ``S`` (space) production.
  67161. *
  67162. * @param c The code point.
  67163. *
  67164. * @returns ``true`` if the codepoint matches ``S``.
  67165. */
  67166. function isS(c) {
  67167. return c === SPACE || c === NL || c === CR || c === TAB;
  67168. }
  67169. exports.isS = isS;
  67170. /**
  67171. * Determines whether a codepoint matches the ``NAME_START_CHAR`` production.
  67172. *
  67173. * @param c The code point.
  67174. *
  67175. * @returns ``true`` if the codepoint matches ``NAME_START_CHAR``.
  67176. */
  67177. // tslint:disable-next-line:cyclomatic-complexity
  67178. function isNameStartChar(c) {
  67179. 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;
  67180. }
  67181. exports.isNameStartChar = isNameStartChar;
  67182. /**
  67183. * Determines whether a codepoint matches the ``NAME_CHAR`` production.
  67184. *
  67185. * @param c The code point.
  67186. *
  67187. * @returns ``true`` if the codepoint matches ``NAME_CHAR``.
  67188. */
  67189. function isNameChar(c) {
  67190. return isNameStartChar(c) || c >= 0x30 && c <= 0x39 || c === 0x2D || c === 0x2E || c === 0xB7 || c >= 0x0300 && c <= 0x036F || c >= 0x203F && c <= 0x2040;
  67191. }
  67192. exports.isNameChar = isNameChar;
  67193. },{}],543:[function(require,module,exports){
  67194. "use strict";
  67195. /**
  67196. * Character class utilities for XML NS 1.0 edition 3.
  67197. *
  67198. * @author Louis-Dominique Dubeau
  67199. * @license MIT
  67200. * @copyright Louis-Dominique Dubeau
  67201. */
  67202. Object.defineProperty(exports, "__esModule", {
  67203. value: true
  67204. }); //
  67205. // Fragments.
  67206. //
  67207. // tslint:disable-next-line:max-line-length
  67208. exports.NC_NAME_START_CHAR = "A-Z_a-z\xC0-\xD6\xD8-\xF6\xF8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\uD800\uDC00-\uDB7F\uDFFF";
  67209. exports.NC_NAME_CHAR = "-" + exports.NC_NAME_START_CHAR + ".0-9\xB7\u0300-\u036F\u203F-\u2040"; //
  67210. // Regular expressions.
  67211. //
  67212. exports.NC_NAME_START_CHAR_RE = new RegExp("^[" + exports.NC_NAME_START_CHAR + "]$", "u");
  67213. exports.NC_NAME_CHAR_RE = new RegExp("^[" + exports.NC_NAME_CHAR + "]$", "u");
  67214. exports.NC_NAME_RE = new RegExp("^[" + exports.NC_NAME_START_CHAR + "][" + exports.NC_NAME_CHAR + "]*$", "u");
  67215. /**
  67216. * Determines whether a codepoint matches [[NC_NAME_START_CHAR]].
  67217. *
  67218. * @param c The code point.
  67219. *
  67220. * @returns ``true`` if the codepoint matches.
  67221. */
  67222. // tslint:disable-next-line:cyclomatic-complexity
  67223. function isNCNameStartChar(c) {
  67224. 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;
  67225. }
  67226. exports.isNCNameStartChar = isNCNameStartChar;
  67227. /**
  67228. * Determines whether a codepoint matches [[NC_NAME_CHAR]].
  67229. *
  67230. * @param c The code point.
  67231. *
  67232. * @returns ``true`` if the codepoint matches.
  67233. */
  67234. function isNCNameChar(c) {
  67235. return isNCNameStartChar(c) || c === 0x2D || c === 0x2E || c >= 0x30 && c <= 0x39 || c === 0x00B7 || c >= 0x0300 && c <= 0x036F || c >= 0x203F && c <= 0x2040;
  67236. }
  67237. exports.isNCNameChar = isNCNameChar;
  67238. },{}]},{},[15])(15)
  67239. });
  67240. //# sourceMappingURL=exceljs.js.map