exceljs.bare.js 2.4 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885508865088750888508895089050891508925089350894508955089650897508985089950900509015090250903509045090550906509075090850909509105091150912509135091450915509165091750918509195092050921509225092350924509255092650927509285092950930509315093250933509345093550936509375093850939509405094150942509435094450945509465094750948509495095050951509525095350954509555095650957509585095950960509615096250963509645096550966509675096850969509705097150972509735097450975509765097750978509795098050981509825098350984509855098650987509885098950990509915099250993509945099550996509975099850999510005100151002510035100451005510065100751008510095101051011510125101351014510155101651017510185101951020510215102251023510245102551026510275102851029510305103151032510335103451035510365103751038510395104051041510425104351044510455104651047510485104951050510515105251053510545105551056510575105851059510605106151062510635106451065510665106751068510695107051071510725107351074510755107651077510785107951080510815108251083510845108551086510875108851089510905109151092510935109451095510965109751098510995110051101511025110351104511055110651107511085110951110511115111251113511145111551116511175111851119511205112151122511235112451125511265112751128511295113051131511325113351134511355113651137511385113951140511415114251143511445114551146511475114851149511505115151152511535115451155511565115751158511595116051161511625116351164511655116651167511685116951170511715117251173511745117551176511775117851179511805118151182511835118451185511865118751188511895119051191511925119351194511955119651197511985119951200512015120251203512045120551206512075120851209512105121151212512135121451215512165121751218512195122051221512225122351224512255122651227512285122951230512315123251233512345123551236512375123851239512405124151242512435124451245512465124751248512495125051251512525125351254512555125651257512585125951260512615126251263512645126551266512675126851269512705127151272512735127451275512765127751278512795128051281512825128351284512855128651287512885128951290512915129251293512945129551296512975129851299513005130151302513035130451305513065130751308513095131051311513125131351314513155131651317513185131951320513215132251323513245132551326513275132851329513305133151332513335133451335513365133751338513395134051341513425134351344513455134651347513485134951350513515135251353513545135551356513575135851359513605136151362513635136451365513665136751368513695137051371513725137351374513755137651377513785137951380513815138251383513845138551386513875138851389513905139151392513935139451395513965139751398513995140051401514025140351404514055140651407514085140951410514115141251413514145141551416514175141851419514205142151422514235142451425514265142751428514295143051431514325143351434514355143651437514385143951440514415144251443514445144551446514475144851449514505145151452514535145451455514565145751458514595146051461514625146351464514655146651467514685146951470514715147251473514745147551476514775147851479514805148151482514835148451485514865148751488514895149051491514925149351494514955149651497514985149951500515015150251503515045150551506515075150851509515105151151512515135151451515515165151751518515195152051521515225152351524515255152651527515285152951530515315153251533515345153551536515375153851539515405154151542515435154451545515465154751548515495155051551515525155351554515555155651557515585155951560515615156251563515645156551566515675156851569515705157151572515735157451575515765157751578515795158051581515825158351584515855158651587515885158951590515915159251593515945159551596515975159851599516005160151602516035160451605516065160751608516095161051611516125161351614516155161651617516185161951620516215162251623516245162551626516275162851629516305163151632516335163451635516365163751638516395164051641516425164351644516455164651647516485164951650516515165251653516545165551656516575165851659516605166151662516635166451665516665166751668516695167051671516725167351674516755167651677516785167951680516815168251683516845168551686516875168851689516905169151692516935169451695516965169751698516995170051701517025170351704517055170651707517085170951710517115171251713517145171551716517175171851719517205172151722517235172451725517265172751728517295173051731517325173351734517355173651737517385173951740517415174251743517445174551746517475174851749517505175151752517535175451755517565175751758517595176051761517625176351764517655176651767517685176951770517715177251773517745177551776517775177851779517805178151782517835178451785517865178751788517895179051791517925179351794517955179651797517985179951800518015180251803518045180551806518075180851809518105181151812518135181451815518165181751818518195182051821518225182351824518255182651827518285182951830518315183251833518345183551836518375183851839518405184151842518435184451845518465184751848518495185051851518525185351854518555185651857518585185951860518615186251863518645186551866518675186851869518705187151872518735187451875518765187751878518795188051881518825188351884518855188651887518885188951890518915189251893518945189551896518975189851899519005190151902519035190451905519065190751908519095191051911519125191351914519155191651917519185191951920519215192251923519245192551926519275192851929519305193151932519335193451935519365193751938519395194051941519425194351944519455194651947519485194951950519515195251953519545195551956519575195851959519605196151962519635196451965519665196751968519695197051971519725197351974519755197651977519785197951980519815198251983519845198551986519875198851989519905199151992519935199451995519965199751998519995200052001520025200352004520055200652007520085200952010520115201252013520145201552016520175201852019520205202152022520235202452025520265202752028520295203052031520325203352034520355203652037520385203952040520415204252043520445204552046520475204852049520505205152052520535205452055520565205752058520595206052061520625206352064520655206652067520685206952070520715207252073520745207552076520775207852079520805208152082520835208452085520865208752088520895209052091520925209352094520955209652097520985209952100521015210252103521045210552106521075210852109521105211152112521135211452115521165211752118521195212052121521225212352124521255212652127521285212952130521315213252133521345213552136521375213852139521405214152142521435214452145521465214752148521495215052151521525215352154521555215652157521585215952160521615216252163521645216552166521675216852169521705217152172521735217452175521765217752178521795218052181521825218352184521855218652187521885218952190521915219252193521945219552196521975219852199522005220152202522035220452205522065220752208522095221052211522125221352214522155221652217522185221952220522215222252223522245222552226522275222852229522305223152232522335223452235522365223752238522395224052241522425224352244522455224652247522485224952250522515225252253522545225552256522575225852259522605226152262522635226452265522665226752268522695227052271522725227352274522755227652277522785227952280522815228252283522845228552286522875228852289522905229152292522935229452295522965229752298522995230052301523025230352304523055230652307523085230952310523115231252313523145231552316523175231852319523205232152322523235232452325523265232752328523295233052331523325233352334523355233652337523385233952340523415234252343523445234552346523475234852349523505235152352523535235452355523565235752358523595236052361523625236352364523655236652367523685236952370523715237252373523745237552376523775237852379523805238152382523835238452385523865238752388523895239052391523925239352394523955239652397523985239952400524015240252403524045240552406524075240852409524105241152412524135241452415524165241752418524195242052421524225242352424524255242652427524285242952430524315243252433524345243552436524375243852439524405244152442524435244452445524465244752448524495245052451524525245352454524555245652457524585245952460524615246252463524645246552466524675246852469524705247152472524735247452475524765247752478524795248052481524825248352484524855248652487524885248952490524915249252493524945249552496524975249852499525005250152502525035250452505525065250752508525095251052511525125251352514525155251652517525185251952520525215252252523525245252552526525275252852529525305253152532525335253452535525365253752538525395254052541525425254352544525455254652547525485254952550525515255252553525545255552556525575255852559525605256152562525635256452565525665256752568525695257052571525725257352574525755257652577525785257952580525815258252583525845258552586525875258852589525905259152592525935259452595525965259752598525995260052601526025260352604526055260652607526085260952610526115261252613526145261552616526175261852619526205262152622526235262452625526265262752628526295263052631526325263352634526355263652637526385263952640526415264252643526445264552646526475264852649526505265152652526535265452655526565265752658526595266052661526625266352664526655266652667526685266952670526715267252673526745267552676526775267852679526805268152682526835268452685526865268752688526895269052691526925269352694526955269652697526985269952700527015270252703527045270552706527075270852709527105271152712527135271452715527165271752718527195272052721527225272352724527255272652727527285272952730527315273252733527345273552736527375273852739527405274152742527435274452745527465274752748527495275052751527525275352754527555275652757527585275952760527615276252763527645276552766527675276852769527705277152772527735277452775527765277752778527795278052781527825278352784527855278652787527885278952790527915279252793527945279552796527975279852799528005280152802528035280452805528065280752808528095281052811528125281352814528155281652817528185281952820528215282252823528245282552826528275282852829528305283152832528335283452835528365283752838528395284052841528425284352844528455284652847528485284952850528515285252853528545285552856528575285852859528605286152862528635286452865528665286752868528695287052871528725287352874528755287652877528785287952880528815288252883528845288552886528875288852889528905289152892528935289452895528965289752898528995290052901529025290352904529055290652907529085290952910529115291252913529145291552916529175291852919529205292152922529235292452925529265292752928529295293052931529325293352934529355293652937529385293952940529415294252943529445294552946529475294852949529505295152952529535295452955529565295752958529595296052961529625296352964529655296652967529685296952970529715297252973529745297552976529775297852979529805298152982529835298452985529865298752988529895299052991529925299352994529955299652997529985299953000530015300253003530045300553006530075300853009530105301153012530135301453015530165301753018530195302053021530225302353024530255302653027530285302953030530315303253033530345303553036530375303853039530405304153042530435304453045530465304753048530495305053051530525305353054530555305653057530585305953060530615306253063530645306553066530675306853069530705307153072530735307453075530765307753078530795308053081530825308353084530855308653087530885308953090530915309253093530945309553096530975309853099531005310153102531035310453105531065310753108531095311053111531125311353114531155311653117531185311953120531215312253123531245312553126531275312853129531305313153132531335313453135531365313753138531395314053141531425314353144531455314653147531485314953150531515315253153531545315553156531575315853159531605316153162531635316453165531665316753168531695317053171531725317353174531755317653177531785317953180531815318253183531845318553186531875318853189531905319153192531935319453195531965319753198531995320053201532025320353204532055320653207532085320953210532115321253213532145321553216532175321853219532205322153222532235322453225532265322753228532295323053231532325323353234532355323653237532385323953240532415324253243532445324553246532475324853249532505325153252532535325453255532565325753258532595326053261532625326353264532655326653267532685326953270532715327253273532745327553276532775327853279532805328153282532835328453285532865328753288532895329053291532925329353294532955329653297532985329953300533015330253303533045330553306533075330853309533105331153312533135331453315533165331753318533195332053321533225332353324533255332653327533285332953330533315333253333533345333553336533375333853339533405334153342533435334453345533465334753348533495335053351533525335353354533555335653357533585335953360533615336253363533645336553366533675336853369533705337153372533735337453375533765337753378533795338053381533825338353384533855338653387533885338953390533915339253393533945339553396533975339853399534005340153402534035340453405534065340753408534095341053411534125341353414534155341653417534185341953420534215342253423534245342553426534275342853429534305343153432534335343453435534365343753438534395344053441534425344353444534455344653447534485344953450534515345253453534545345553456534575345853459534605346153462534635346453465534665346753468534695347053471534725347353474534755347653477534785347953480534815348253483534845348553486534875348853489534905349153492534935349453495534965349753498534995350053501535025350353504535055350653507535085350953510535115351253513535145351553516535175351853519535205352153522535235352453525535265352753528535295353053531535325353353534535355353653537535385353953540535415354253543535445354553546535475354853549535505355153552535535355453555535565355753558535595356053561535625356353564535655356653567535685356953570535715357253573535745357553576535775357853579535805358153582535835358453585535865358753588535895359053591535925359353594535955359653597535985359953600536015360253603536045360553606536075360853609536105361153612536135361453615536165361753618536195362053621536225362353624536255362653627536285362953630536315363253633536345363553636536375363853639536405364153642536435364453645536465364753648536495365053651536525365353654536555365653657536585365953660536615366253663536645366553666536675366853669536705367153672536735367453675536765367753678536795368053681536825368353684536855368653687536885368953690536915369253693536945369553696536975369853699537005370153702537035370453705537065370753708537095371053711537125371353714537155371653717537185371953720537215372253723537245372553726537275372853729537305373153732537335373453735537365373753738537395374053741537425374353744537455374653747537485374953750537515375253753537545375553756537575375853759537605376153762537635376453765537665376753768537695377053771537725377353774537755377653777537785377953780537815378253783537845378553786537875378853789537905379153792537935379453795537965379753798537995380053801538025380353804538055380653807538085380953810538115381253813538145381553816538175381853819538205382153822538235382453825538265382753828538295383053831538325383353834538355383653837538385383953840538415384253843538445384553846538475384853849538505385153852538535385453855538565385753858538595386053861538625386353864538655386653867538685386953870538715387253873538745387553876538775387853879538805388153882538835388453885538865388753888538895389053891538925389353894538955389653897538985389953900539015390253903539045390553906539075390853909539105391153912539135391453915539165391753918539195392053921539225392353924539255392653927539285392953930539315393253933539345393553936539375393853939539405394153942539435394453945539465394753948539495395053951539525395353954539555395653957539585395953960539615396253963539645396553966539675396853969539705397153972539735397453975539765397753978539795398053981539825398353984539855398653987539885398953990539915399253993539945399553996539975399853999540005400154002540035400454005540065400754008540095401054011540125401354014540155401654017540185401954020540215402254023540245402554026540275402854029540305403154032540335403454035540365403754038540395404054041540425404354044540455404654047540485404954050540515405254053540545405554056540575405854059540605406154062540635406454065540665406754068540695407054071540725407354074540755407654077540785407954080540815408254083540845408554086540875408854089540905409154092540935409454095540965409754098540995410054101541025410354104541055410654107541085410954110541115411254113541145411554116541175411854119541205412154122541235412454125541265412754128541295413054131541325413354134541355413654137541385413954140541415414254143541445414554146541475414854149541505415154152541535415454155541565415754158541595416054161541625416354164541655416654167541685416954170541715417254173541745417554176541775417854179541805418154182541835418454185541865418754188541895419054191541925419354194541955419654197541985419954200542015420254203542045420554206542075420854209542105421154212542135421454215542165421754218542195422054221542225422354224542255422654227542285422954230542315423254233542345423554236542375423854239542405424154242542435424454245542465424754248542495425054251542525425354254542555425654257542585425954260542615426254263542645426554266542675426854269542705427154272542735427454275542765427754278542795428054281542825428354284542855428654287542885428954290542915429254293542945429554296542975429854299543005430154302543035430454305543065430754308543095431054311543125431354314543155431654317543185431954320543215432254323543245432554326543275432854329543305433154332543335433454335543365433754338543395434054341543425434354344543455434654347543485434954350543515435254353543545435554356543575435854359543605436154362543635436454365543665436754368543695437054371543725437354374543755437654377543785437954380543815438254383543845438554386543875438854389543905439154392543935439454395543965439754398543995440054401544025440354404544055440654407544085440954410544115441254413544145441554416544175441854419544205442154422544235442454425544265442754428544295443054431544325443354434544355443654437544385443954440544415444254443544445444554446544475444854449544505445154452544535445454455544565445754458544595446054461544625446354464544655446654467544685446954470544715447254473544745447554476544775447854479544805448154482544835448454485544865448754488544895449054491544925449354494544955449654497544985449954500545015450254503545045450554506545075450854509545105451154512545135451454515545165451754518545195452054521545225452354524545255452654527545285452954530545315453254533545345453554536545375453854539545405454154542545435454454545545465454754548545495455054551545525455354554545555455654557545585455954560545615456254563545645456554566545675456854569545705457154572545735457454575545765457754578545795458054581545825458354584545855458654587545885458954590545915459254593545945459554596545975459854599546005460154602546035460454605546065460754608546095461054611546125461354614546155461654617546185461954620546215462254623546245462554626546275462854629546305463154632546335463454635546365463754638546395464054641546425464354644546455464654647546485464954650546515465254653546545465554656546575465854659546605466154662546635466454665546665466754668546695467054671546725467354674546755467654677546785467954680546815468254683546845468554686546875468854689546905469154692546935469454695546965469754698546995470054701547025470354704547055470654707547085470954710547115471254713547145471554716547175471854719547205472154722547235472454725547265472754728547295473054731547325473354734547355473654737547385473954740547415474254743547445474554746547475474854749547505475154752547535475454755547565475754758547595476054761547625476354764547655476654767547685476954770547715477254773547745477554776547775477854779547805478154782547835478454785547865478754788547895479054791547925479354794547955479654797547985479954800548015480254803548045480554806548075480854809548105481154812548135481454815548165481754818548195482054821548225482354824548255482654827548285482954830548315483254833548345483554836548375483854839548405484154842548435484454845548465484754848548495485054851548525485354854548555485654857548585485954860548615486254863548645486554866548675486854869548705487154872548735487454875548765487754878548795488054881548825488354884548855488654887548885488954890548915489254893548945489554896548975489854899549005490154902549035490454905549065490754908549095491054911549125491354914549155491654917549185491954920549215492254923549245492554926549275492854929549305493154932549335493454935549365493754938549395494054941549425494354944549455494654947549485494954950549515495254953549545495554956549575495854959549605496154962549635496454965549665496754968549695497054971549725497354974549755497654977549785497954980549815498254983549845498554986549875498854989549905499154992549935499454995549965499754998549995500055001550025500355004550055500655007550085500955010550115501255013550145501555016550175501855019550205502155022550235502455025550265502755028550295503055031550325503355034550355503655037550385503955040550415504255043550445504555046550475504855049550505505155052550535505455055550565505755058550595506055061550625506355064550655506655067550685506955070550715507255073550745507555076550775507855079550805508155082550835508455085550865508755088550895509055091550925509355094550955509655097550985509955100551015510255103551045510555106551075510855109551105511155112551135511455115551165511755118551195512055121551225512355124551255512655127551285512955130551315513255133551345513555136551375513855139551405514155142551435514455145551465514755148551495515055151551525515355154551555515655157551585515955160551615516255163551645516555166551675516855169551705517155172551735517455175551765517755178551795518055181551825518355184551855518655187551885518955190551915519255193551945519555196551975519855199552005520155202552035520455205552065520755208552095521055211552125521355214552155521655217552185521955220552215522255223552245522555226552275522855229552305523155232552335523455235552365523755238552395524055241552425524355244552455524655247552485524955250552515525255253552545525555256552575525855259552605526155262552635526455265552665526755268552695527055271552725527355274552755527655277552785527955280552815528255283552845528555286552875528855289552905529155292552935529455295552965529755298552995530055301553025530355304553055530655307553085530955310553115531255313553145531555316553175531855319553205532155322553235532455325553265532755328553295533055331553325533355334553355533655337553385533955340553415534255343553445534555346553475534855349553505535155352553535535455355553565535755358553595536055361553625536355364553655536655367553685536955370553715537255373553745537555376553775537855379553805538155382553835538455385553865538755388553895539055391553925539355394553955539655397553985539955400554015540255403554045540555406554075540855409554105541155412554135541455415554165541755418554195542055421554225542355424554255542655427554285542955430554315543255433554345543555436554375543855439554405544155442554435544455445554465544755448554495545055451554525545355454554555545655457554585545955460554615546255463554645546555466554675546855469554705547155472554735547455475554765547755478554795548055481554825548355484554855548655487554885548955490554915549255493554945549555496554975549855499555005550155502555035550455505555065550755508555095551055511555125551355514555155551655517555185551955520555215552255523555245552555526555275552855529555305553155532555335553455535555365553755538555395554055541555425554355544555455554655547555485554955550555515555255553555545555555556555575555855559555605556155562555635556455565555665556755568555695557055571555725557355574555755557655577555785557955580555815558255583555845558555586555875558855589555905559155592555935559455595555965559755598555995560055601556025560355604556055560655607556085560955610556115561255613556145561555616556175561855619556205562155622556235562455625556265562755628556295563055631556325563355634556355563655637556385563955640556415564255643556445564555646556475564855649556505565155652556535565455655556565565755658556595566055661556625566355664556655566655667556685566955670556715567255673556745567555676556775567855679556805568155682556835568455685556865568755688556895569055691556925569355694556955569655697556985569955700557015570255703557045570555706557075570855709557105571155712557135571455715557165571755718557195572055721557225572355724557255572655727557285572955730557315573255733557345573555736557375573855739557405574155742557435574455745557465574755748557495575055751557525575355754557555575655757557585575955760557615576255763557645576555766557675576855769557705577155772557735577455775557765577755778557795578055781557825578355784557855578655787557885578955790557915579255793557945579555796557975579855799558005580155802558035580455805558065580755808558095581055811558125581355814558155581655817558185581955820558215582255823558245582555826558275582855829558305583155832558335583455835558365583755838558395584055841558425584355844558455584655847558485584955850558515585255853558545585555856558575585855859558605586155862558635586455865558665586755868558695587055871558725587355874558755587655877558785587955880558815588255883558845588555886558875588855889558905589155892558935589455895558965589755898558995590055901559025590355904559055590655907559085590955910559115591255913559145591555916559175591855919559205592155922559235592455925559265592755928559295593055931559325593355934559355593655937559385593955940559415594255943559445594555946559475594855949559505595155952559535595455955559565595755958559595596055961559625596355964559655596655967559685596955970559715597255973559745597555976559775597855979559805598155982559835598455985559865598755988559895599055991559925599355994559955599655997559985599956000560015600256003560045600556006560075600856009560105601156012560135601456015560165601756018560195602056021560225602356024560255602656027560285602956030560315603256033560345603556036560375603856039560405604156042560435604456045560465604756048560495605056051560525605356054560555605656057560585605956060560615606256063560645606556066560675606856069560705607156072560735607456075560765607756078560795608056081560825608356084560855608656087560885608956090560915609256093560945609556096560975609856099561005610156102561035610456105561065610756108561095611056111561125611356114561155611656117561185611956120561215612256123561245612556126561275612856129561305613156132561335613456135561365613756138561395614056141561425614356144561455614656147561485614956150561515615256153561545615556156561575615856159561605616156162561635616456165561665616756168561695617056171561725617356174561755617656177561785617956180561815618256183561845618556186561875618856189561905619156192561935619456195561965619756198561995620056201562025620356204562055620656207562085620956210562115621256213562145621556216562175621856219562205622156222562235622456225562265622756228562295623056231562325623356234562355623656237562385623956240562415624256243562445624556246562475624856249562505625156252562535625456255562565625756258562595626056261562625626356264562655626656267562685626956270562715627256273562745627556276562775627856279562805628156282562835628456285562865628756288562895629056291562925629356294562955629656297562985629956300563015630256303563045630556306563075630856309563105631156312563135631456315563165631756318563195632056321563225632356324563255632656327563285632956330563315633256333563345633556336563375633856339563405634156342563435634456345563465634756348563495635056351563525635356354563555635656357563585635956360563615636256363563645636556366563675636856369563705637156372563735637456375563765637756378563795638056381563825638356384563855638656387563885638956390563915639256393563945639556396563975639856399564005640156402564035640456405564065640756408564095641056411564125641356414564155641656417564185641956420564215642256423564245642556426564275642856429564305643156432564335643456435564365643756438564395644056441564425644356444564455644656447564485644956450564515645256453564545645556456564575645856459564605646156462564635646456465564665646756468564695647056471564725647356474564755647656477564785647956480564815648256483564845648556486564875648856489564905649156492564935649456495564965649756498564995650056501565025650356504565055650656507565085650956510565115651256513565145651556516565175651856519565205652156522565235652456525565265652756528565295653056531565325653356534565355653656537565385653956540565415654256543565445654556546565475654856549565505655156552565535655456555565565655756558565595656056561565625656356564565655656656567565685656956570565715657256573565745657556576565775657856579565805658156582565835658456585565865658756588565895659056591565925659356594565955659656597565985659956600566015660256603566045660556606566075660856609566105661156612566135661456615566165661756618566195662056621566225662356624566255662656627566285662956630566315663256633566345663556636566375663856639566405664156642566435664456645566465664756648566495665056651566525665356654566555665656657566585665956660566615666256663566645666556666566675666856669566705667156672566735667456675566765667756678566795668056681566825668356684566855668656687566885668956690566915669256693566945669556696566975669856699567005670156702567035670456705567065670756708567095671056711567125671356714567155671656717567185671956720567215672256723567245672556726567275672856729567305673156732567335673456735567365673756738567395674056741567425674356744567455674656747567485674956750567515675256753567545675556756567575675856759567605676156762567635676456765567665676756768567695677056771567725677356774567755677656777567785677956780567815678256783567845678556786567875678856789567905679156792567935679456795567965679756798567995680056801568025680356804568055680656807568085680956810568115681256813568145681556816568175681856819568205682156822568235682456825568265682756828568295683056831568325683356834568355683656837568385683956840568415684256843568445684556846568475684856849568505685156852568535685456855568565685756858568595686056861568625686356864568655686656867568685686956870568715687256873568745687556876568775687856879568805688156882568835688456885568865688756888568895689056891568925689356894568955689656897568985689956900569015690256903569045690556906569075690856909569105691156912569135691456915569165691756918569195692056921569225692356924569255692656927569285692956930569315693256933569345693556936569375693856939569405694156942569435694456945569465694756948569495695056951569525695356954569555695656957569585695956960569615696256963569645696556966569675696856969569705697156972569735697456975569765697756978569795698056981569825698356984569855698656987569885698956990569915699256993569945699556996569975699856999570005700157002570035700457005570065700757008570095701057011570125701357014570155701657017570185701957020570215702257023570245702557026570275702857029570305703157032570335703457035570365703757038570395704057041570425704357044570455704657047570485704957050570515705257053570545705557056570575705857059570605706157062570635706457065570665706757068570695707057071570725707357074570755707657077570785707957080570815708257083570845708557086570875708857089570905709157092570935709457095570965709757098570995710057101571025710357104571055710657107571085710957110571115711257113571145711557116571175711857119571205712157122571235712457125571265712757128571295713057131571325713357134571355713657137571385713957140571415714257143571445714557146571475714857149571505715157152571535715457155571565715757158571595716057161571625716357164571655716657167571685716957170571715717257173571745717557176571775717857179571805718157182571835718457185571865718757188571895719057191571925719357194571955719657197571985719957200572015720257203572045720557206572075720857209572105721157212572135721457215572165721757218572195722057221572225722357224572255722657227572285722957230572315723257233572345723557236572375723857239572405724157242572435724457245572465724757248572495725057251572525725357254572555725657257572585725957260572615726257263572645726557266572675726857269572705727157272572735727457275572765727757278572795728057281572825728357284572855728657287572885728957290572915729257293572945729557296572975729857299573005730157302573035730457305573065730757308573095731057311573125731357314573155731657317573185731957320573215732257323573245732557326573275732857329573305733157332573335733457335573365733757338573395734057341573425734357344573455734657347573485734957350573515735257353573545735557356573575735857359573605736157362573635736457365573665736757368573695737057371573725737357374573755737657377573785737957380573815738257383573845738557386573875738857389573905739157392573935739457395573965739757398573995740057401574025740357404574055740657407574085740957410574115741257413574145741557416574175741857419574205742157422574235742457425574265742757428574295743057431574325743357434574355743657437574385743957440574415744257443574445744557446574475744857449574505745157452574535745457455574565745757458574595746057461574625746357464574655746657467574685746957470574715747257473574745747557476574775747857479574805748157482574835748457485574865748757488574895749057491574925749357494574955749657497574985749957500575015750257503575045750557506575075750857509575105751157512575135751457515575165751757518575195752057521575225752357524575255752657527575285752957530575315753257533575345753557536575375753857539575405754157542575435754457545575465754757548575495755057551575525755357554575555755657557575585755957560575615756257563575645756557566575675756857569575705757157572575735757457575575765757757578575795758057581575825758357584575855758657587575885758957590575915759257593575945759557596575975759857599576005760157602576035760457605576065760757608576095761057611576125761357614576155761657617576185761957620576215762257623576245762557626576275762857629576305763157632576335763457635576365763757638576395764057641576425764357644576455764657647576485764957650576515765257653576545765557656576575765857659576605766157662576635766457665576665766757668576695767057671576725767357674576755767657677576785767957680576815768257683576845768557686576875768857689576905769157692576935769457695576965769757698576995770057701577025770357704577055770657707577085770957710577115771257713577145771557716577175771857719577205772157722577235772457725577265772757728577295773057731577325773357734577355773657737577385773957740577415774257743577445774557746577475774857749577505775157752577535775457755577565775757758577595776057761577625776357764577655776657767577685776957770577715777257773577745777557776577775777857779577805778157782577835778457785577865778757788577895779057791577925779357794577955779657797577985779957800578015780257803578045780557806578075780857809578105781157812578135781457815578165781757818578195782057821578225782357824578255782657827578285782957830578315783257833578345783557836578375783857839578405784157842578435784457845578465784757848578495785057851578525785357854578555785657857578585785957860578615786257863578645786557866578675786857869578705787157872578735787457875578765787757878578795788057881578825788357884578855788657887578885788957890578915789257893578945789557896578975789857899579005790157902579035790457905579065790757908579095791057911579125791357914579155791657917579185791957920579215792257923579245792557926579275792857929579305793157932579335793457935579365793757938579395794057941579425794357944579455794657947579485794957950579515795257953579545795557956579575795857959579605796157962579635796457965579665796757968579695797057971579725797357974579755797657977579785797957980579815798257983579845798557986579875798857989579905799157992579935799457995579965799757998579995800058001580025800358004580055800658007580085800958010580115801258013580145801558016580175801858019580205802158022580235802458025580265802758028580295803058031580325803358034580355803658037580385803958040580415804258043580445804558046580475804858049580505805158052580535805458055580565805758058580595806058061580625806358064580655806658067580685806958070580715807258073580745807558076580775807858079580805808158082580835808458085580865808758088580895809058091580925809358094580955809658097580985809958100581015810258103581045810558106581075810858109581105811158112581135811458115581165811758118581195812058121581225812358124581255812658127581285812958130581315813258133581345813558136581375813858139581405814158142581435814458145581465814758148581495815058151581525815358154581555815658157581585815958160581615816258163581645816558166581675816858169581705817158172581735817458175581765817758178581795818058181581825818358184581855818658187581885818958190581915819258193581945819558196581975819858199582005820158202582035820458205582065820758208582095821058211582125821358214582155821658217582185821958220582215822258223582245822558226582275822858229582305823158232582335823458235582365823758238582395824058241582425824358244582455824658247582485824958250582515825258253582545825558256582575825858259582605826158262582635826458265582665826758268582695827058271582725827358274582755827658277582785827958280582815828258283582845828558286582875828858289582905829158292582935829458295582965829758298582995830058301583025830358304583055830658307583085830958310583115831258313583145831558316583175831858319583205832158322583235832458325583265832758328583295833058331583325833358334583355833658337583385833958340583415834258343583445834558346583475834858349583505835158352583535835458355583565835758358583595836058361583625836358364583655836658367583685836958370583715837258373583745837558376583775837858379583805838158382583835838458385583865838758388583895839058391583925839358394583955839658397583985839958400584015840258403584045840558406584075840858409584105841158412584135841458415584165841758418584195842058421584225842358424584255842658427584285842958430584315843258433584345843558436584375843858439584405844158442584435844458445584465844758448584495845058451584525845358454584555845658457584585845958460584615846258463584645846558466584675846858469584705847158472584735847458475584765847758478584795848058481584825848358484584855848658487584885848958490584915849258493584945849558496584975849858499585005850158502585035850458505585065850758508585095851058511585125851358514585155851658517585185851958520585215852258523585245852558526585275852858529585305853158532585335853458535585365853758538585395854058541585425854358544585455854658547585485854958550585515855258553585545855558556585575855858559585605856158562585635856458565585665856758568585695857058571585725857358574585755857658577585785857958580585815858258583585845858558586585875858858589585905859158592585935859458595585965859758598585995860058601586025860358604586055860658607586085860958610586115861258613586145861558616586175861858619586205862158622586235862458625586265862758628586295863058631586325863358634586355863658637586385863958640586415864258643586445864558646586475864858649586505865158652586535865458655586565865758658586595866058661586625866358664586655866658667586685866958670586715867258673586745867558676586775867858679586805868158682586835868458685586865868758688586895869058691586925869358694586955869658697586985869958700587015870258703587045870558706587075870858709587105871158712587135871458715587165871758718587195872058721587225872358724587255872658727587285872958730587315873258733587345873558736587375873858739587405874158742587435874458745587465874758748587495875058751587525875358754587555875658757587585875958760587615876258763587645876558766587675876858769587705877158772587735877458775587765877758778587795878058781587825878358784587855878658787587885878958790587915879258793587945879558796587975879858799588005880158802588035880458805588065880758808588095881058811588125881358814588155881658817588185881958820588215882258823588245882558826588275882858829588305883158832588335883458835588365883758838588395884058841588425884358844588455884658847588485884958850588515885258853588545885558856588575885858859588605886158862588635886458865588665886758868588695887058871588725887358874588755887658877588785887958880588815888258883588845888558886588875888858889588905889158892588935889458895588965889758898588995890058901589025890358904589055890658907589085890958910589115891258913589145891558916589175891858919589205892158922589235892458925589265892758928589295893058931589325893358934589355893658937589385893958940589415894258943589445894558946589475894858949589505895158952589535895458955589565895758958589595896058961589625896358964589655896658967589685896958970589715897258973589745897558976589775897858979589805898158982589835898458985589865898758988589895899058991589925899358994589955899658997589985899959000590015900259003590045900559006590075900859009590105901159012590135901459015590165901759018590195902059021590225902359024590255902659027590285902959030590315903259033590345903559036590375903859039590405904159042590435904459045590465904759048590495905059051590525905359054590555905659057590585905959060590615906259063590645906559066590675906859069590705907159072590735907459075590765907759078590795908059081590825908359084590855908659087590885908959090590915909259093590945909559096590975909859099591005910159102591035910459105591065910759108591095911059111591125911359114591155911659117591185911959120591215912259123591245912559126591275912859129591305913159132591335913459135591365913759138591395914059141591425914359144591455914659147591485914959150591515915259153591545915559156591575915859159591605916159162591635916459165591665916759168591695917059171591725917359174591755917659177591785917959180591815918259183591845918559186591875918859189591905919159192591935919459195591965919759198591995920059201592025920359204592055920659207592085920959210592115921259213592145921559216592175921859219592205922159222592235922459225592265922759228592295923059231592325923359234592355923659237592385923959240592415924259243592445924559246592475924859249592505925159252592535925459255592565925759258592595926059261592625926359264592655926659267592685926959270592715927259273592745927559276592775927859279592805928159282592835928459285592865928759288592895929059291592925929359294592955929659297592985929959300593015930259303593045930559306593075930859309593105931159312593135931459315593165931759318593195932059321593225932359324593255932659327593285932959330593315933259333593345933559336593375933859339593405934159342593435934459345593465934759348593495935059351593525935359354593555935659357593585935959360593615936259363593645936559366593675936859369593705937159372593735937459375593765937759378593795938059381593825938359384593855938659387593885938959390593915939259393593945939559396593975939859399594005940159402594035940459405594065940759408594095941059411594125941359414594155941659417594185941959420594215942259423594245942559426594275942859429594305943159432594335943459435594365943759438594395944059441594425944359444594455944659447594485944959450594515945259453594545945559456594575945859459594605946159462594635946459465594665946759468594695947059471594725947359474594755947659477594785947959480594815948259483594845948559486594875948859489594905949159492594935949459495594965949759498594995950059501595025950359504595055950659507595085950959510595115951259513595145951559516595175951859519595205952159522595235952459525595265952759528595295953059531595325953359534595355953659537595385953959540595415954259543595445954559546595475954859549595505955159552595535955459555595565955759558595595956059561595625956359564595655956659567595685956959570595715957259573595745957559576595775957859579595805958159582595835958459585595865958759588595895959059591595925959359594595955959659597595985959959600596015960259603596045960559606596075960859609596105961159612596135961459615596165961759618596195962059621596225962359624596255962659627596285962959630596315963259633596345963559636596375963859639596405964159642596435964459645596465964759648596495965059651596525965359654596555965659657596585965959660596615966259663596645966559666596675966859669596705967159672596735967459675596765967759678596795968059681596825968359684596855968659687596885968959690596915969259693596945969559696596975969859699597005970159702597035970459705597065970759708597095971059711597125971359714597155971659717597185971959720597215972259723597245972559726597275972859729597305973159732597335973459735597365973759738597395974059741597425974359744597455974659747597485974959750597515975259753597545975559756597575975859759597605976159762597635976459765597665976759768597695977059771597725977359774597755977659777597785977959780597815978259783597845978559786597875978859789597905979159792597935979459795597965979759798597995980059801598025980359804598055980659807598085980959810598115981259813598145981559816598175981859819598205982159822598235982459825598265982759828598295983059831598325983359834598355983659837598385983959840598415984259843598445984559846598475984859849598505985159852598535985459855598565985759858598595986059861598625986359864598655986659867598685986959870598715987259873598745987559876598775987859879598805988159882598835988459885598865988759888598895989059891598925989359894598955989659897598985989959900599015990259903599045990559906599075990859909599105991159912599135991459915599165991759918599195992059921599225992359924599255992659927599285992959930599315993259933599345993559936599375993859939599405994159942599435994459945599465994759948599495995059951599525995359954599555995659957599585995959960599615996259963599645996559966599675996859969599705997159972599735997459975599765997759978599795998059981599825998359984599855998659987599885998959990599915999259993599945999559996599975999859999600006000160002600036000460005600066000760008600096001060011600126001360014600156001660017600186001960020600216002260023600246002560026600276002860029600306003160032600336003460035600366003760038600396004060041600426004360044600456004660047600486004960050600516005260053600546005560056600576005860059600606006160062600636006460065600666006760068600696007060071600726007360074600756007660077600786007960080600816008260083600846008560086600876008860089600906009160092600936009460095600966009760098600996010060101601026010360104601056010660107601086010960110601116011260113601146011560116601176011860119601206012160122601236012460125601266012760128601296013060131601326013360134601356013660137601386013960140601416014260143601446014560146601476014860149601506015160152601536015460155601566015760158601596016060161601626016360164601656016660167601686016960170601716017260173601746017560176601776017860179601806018160182601836018460185601866018760188601896019060191601926019360194601956019660197601986019960200602016020260203602046020560206602076020860209602106021160212602136021460215602166021760218602196022060221602226022360224602256022660227602286022960230602316023260233602346023560236602376023860239602406024160242602436024460245602466024760248602496025060251602526025360254602556025660257602586025960260602616026260263602646026560266602676026860269602706027160272602736027460275602766027760278602796028060281602826028360284602856028660287602886028960290602916029260293602946029560296602976029860299603006030160302603036030460305603066030760308603096031060311603126031360314603156031660317603186031960320603216032260323603246032560326603276032860329603306033160332603336033460335603366033760338603396034060341603426034360344603456034660347603486034960350603516035260353603546035560356603576035860359603606036160362603636036460365603666036760368603696037060371603726037360374603756037660377603786037960380603816038260383603846038560386603876038860389603906039160392603936039460395603966039760398603996040060401604026040360404604056040660407604086040960410604116041260413604146041560416604176041860419604206042160422604236042460425604266042760428604296043060431604326043360434604356043660437604386043960440604416044260443604446044560446604476044860449604506045160452604536045460455604566045760458604596046060461604626046360464604656046660467604686046960470604716047260473604746047560476604776047860479604806048160482604836048460485604866048760488604896049060491604926049360494604956049660497604986049960500605016050260503605046050560506605076050860509605106051160512605136051460515605166051760518605196052060521605226052360524605256052660527605286052960530605316053260533605346053560536605376053860539605406054160542605436054460545605466054760548605496055060551605526055360554605556055660557605586055960560605616056260563605646056560566605676056860569605706057160572605736057460575605766057760578605796058060581605826058360584605856058660587605886058960590605916059260593605946059560596605976059860599606006060160602606036060460605606066060760608606096061060611606126061360614606156061660617606186061960620606216062260623606246062560626606276062860629606306063160632606336063460635606366063760638606396064060641606426064360644606456064660647606486064960650606516065260653606546065560656606576065860659606606066160662606636066460665606666066760668606696067060671606726067360674606756067660677606786067960680606816068260683606846068560686606876068860689606906069160692606936069460695606966069760698606996070060701607026070360704607056070660707607086070960710607116071260713607146071560716607176071860719607206072160722607236072460725607266072760728607296073060731607326073360734607356073660737607386073960740607416074260743607446074560746607476074860749607506075160752607536075460755607566075760758607596076060761607626076360764607656076660767607686076960770607716077260773607746077560776607776077860779607806078160782607836078460785607866078760788607896079060791607926079360794607956079660797607986079960800608016080260803608046080560806608076080860809608106081160812608136081460815608166081760818608196082060821608226082360824608256082660827608286082960830608316083260833608346083560836608376083860839608406084160842608436084460845608466084760848608496085060851608526085360854608556085660857608586085960860608616086260863608646086560866608676086860869608706087160872608736087460875608766087760878608796088060881608826088360884608856088660887608886088960890608916089260893608946089560896608976089860899609006090160902609036090460905609066090760908609096091060911609126091360914609156091660917609186091960920609216092260923609246092560926609276092860929609306093160932609336093460935609366093760938609396094060941609426094360944609456094660947609486094960950609516095260953609546095560956609576095860959609606096160962609636096460965609666096760968609696097060971609726097360974609756097660977609786097960980609816098260983609846098560986609876098860989609906099160992609936099460995609966099760998609996100061001610026100361004610056100661007610086100961010610116101261013610146101561016610176101861019610206102161022610236102461025610266102761028610296103061031610326103361034610356103661037610386103961040610416104261043610446104561046610476104861049610506105161052610536105461055610566105761058610596106061061610626106361064610656106661067610686106961070610716107261073610746107561076610776107861079610806108161082610836108461085610866108761088610896109061091610926109361094610956109661097610986109961100611016110261103611046110561106611076110861109611106111161112611136111461115611166111761118611196112061121611226112361124611256112661127611286112961130611316113261133611346113561136611376113861139611406114161142611436114461145611466114761148611496115061151611526115361154611556115661157611586115961160611616116261163611646116561166611676116861169611706117161172611736117461175611766117761178611796118061181611826118361184611856118661187611886118961190611916119261193611946119561196611976119861199612006120161202612036120461205612066120761208612096121061211612126121361214612156121661217612186121961220612216122261223612246122561226612276122861229612306123161232612336123461235612366123761238612396124061241612426124361244612456124661247612486124961250612516125261253612546125561256612576125861259612606126161262612636126461265612666126761268612696127061271612726127361274612756127661277612786127961280612816128261283612846128561286612876128861289612906129161292612936129461295612966129761298612996130061301613026130361304613056130661307613086130961310613116131261313613146131561316613176131861319613206132161322613236132461325613266132761328613296133061331613326133361334613356133661337613386133961340613416134261343613446134561346613476134861349613506135161352613536135461355613566135761358613596136061361613626136361364613656136661367613686136961370613716137261373613746137561376613776137861379613806138161382613836138461385613866138761388613896139061391613926139361394613956139661397613986139961400614016140261403614046140561406614076140861409614106141161412614136141461415614166141761418614196142061421614226142361424614256142661427614286142961430614316143261433614346143561436614376143861439614406144161442614436144461445614466144761448614496145061451614526145361454614556145661457614586145961460614616146261463614646146561466614676146861469614706147161472614736147461475614766147761478614796148061481614826148361484614856148661487614886148961490614916149261493614946149561496614976149861499615006150161502615036150461505615066150761508615096151061511615126151361514615156151661517615186151961520615216152261523615246152561526615276152861529615306153161532615336153461535615366153761538615396154061541615426154361544615456154661547615486154961550615516155261553615546155561556615576155861559615606156161562615636156461565615666156761568615696157061571615726157361574615756157661577615786157961580615816158261583615846158561586615876158861589615906159161592615936159461595615966159761598615996160061601616026160361604616056160661607616086160961610616116161261613616146161561616616176161861619616206162161622616236162461625616266162761628616296163061631616326163361634616356163661637616386163961640616416164261643616446164561646616476164861649616506165161652616536165461655616566165761658616596166061661616626166361664616656166661667616686166961670616716167261673616746167561676616776167861679616806168161682616836168461685616866168761688616896169061691616926169361694616956169661697616986169961700617016170261703617046170561706617076170861709617106171161712617136171461715617166171761718617196172061721617226172361724617256172661727617286172961730617316173261733617346173561736617376173861739617406174161742617436174461745617466174761748617496175061751617526175361754617556175661757617586175961760617616176261763617646176561766617676176861769617706177161772617736177461775617766177761778617796178061781617826178361784617856178661787617886178961790617916179261793617946179561796617976179861799618006180161802618036180461805618066180761808618096181061811618126181361814618156181661817618186181961820618216182261823618246182561826618276182861829618306183161832618336183461835618366183761838618396184061841618426184361844618456184661847618486184961850618516185261853618546185561856618576185861859618606186161862618636186461865618666186761868618696187061871618726187361874618756187661877618786187961880618816188261883618846188561886618876188861889618906189161892618936189461895618966189761898618996190061901619026190361904619056190661907619086190961910619116191261913619146191561916619176191861919619206192161922619236192461925619266192761928619296193061931619326193361934619356193661937619386193961940619416194261943619446194561946619476194861949619506195161952619536195461955619566195761958619596196061961619626196361964619656196661967619686196961970619716197261973619746197561976619776197861979619806198161982619836198461985619866198761988619896199061991619926199361994619956199661997619986199962000620016200262003620046200562006620076200862009620106201162012620136201462015620166201762018620196202062021620226202362024620256202662027620286202962030620316203262033620346203562036620376203862039620406204162042620436204462045620466204762048620496205062051620526205362054620556205662057620586205962060620616206262063620646206562066620676206862069620706207162072620736207462075620766207762078620796208062081620826208362084620856208662087620886208962090620916209262093620946209562096620976209862099621006210162102621036210462105621066210762108621096211062111621126211362114621156211662117621186211962120621216212262123621246212562126621276212862129621306213162132621336213462135621366213762138621396214062141621426214362144621456214662147621486214962150621516215262153621546215562156621576215862159621606216162162621636216462165621666216762168621696217062171621726217362174621756217662177621786217962180621816218262183621846218562186621876218862189621906219162192621936219462195621966219762198621996220062201622026220362204622056220662207622086220962210622116221262213622146221562216622176221862219622206222162222622236222462225622266222762228622296223062231622326223362234622356223662237622386223962240622416224262243622446224562246622476224862249622506225162252622536225462255622566225762258622596226062261622626226362264622656226662267622686226962270622716227262273622746227562276622776227862279622806228162282622836228462285622866228762288622896229062291622926229362294622956229662297622986229962300623016230262303623046230562306623076230862309623106231162312623136231462315623166231762318623196232062321623226232362324623256232662327623286232962330623316233262333623346233562336623376233862339623406234162342623436234462345623466234762348623496235062351623526235362354623556235662357623586235962360623616236262363623646236562366623676236862369623706237162372623736237462375623766237762378623796238062381623826238362384623856238662387623886238962390623916239262393623946239562396623976239862399624006240162402624036240462405624066240762408624096241062411624126241362414624156241662417624186241962420624216242262423624246242562426624276242862429624306243162432624336243462435624366243762438624396244062441624426244362444624456244662447624486244962450624516245262453624546245562456624576245862459624606246162462624636246462465624666246762468624696247062471624726247362474624756247662477624786247962480624816248262483624846248562486624876248862489624906249162492624936249462495624966249762498624996250062501625026250362504625056250662507625086250962510625116251262513625146251562516625176251862519625206252162522625236252462525625266252762528625296253062531625326253362534625356253662537625386253962540625416254262543625446254562546625476254862549625506255162552625536255462555625566255762558625596256062561625626256362564625656256662567625686256962570625716257262573625746257562576625776257862579625806258162582625836258462585625866258762588625896259062591625926259362594625956259662597625986259962600626016260262603626046260562606626076260862609626106261162612626136261462615626166261762618626196262062621626226262362624626256262662627626286262962630626316263262633626346263562636626376263862639626406264162642626436264462645626466264762648626496265062651626526265362654626556265662657626586265962660626616266262663626646266562666626676266862669626706267162672626736267462675626766267762678626796268062681626826268362684626856268662687626886268962690626916269262693626946269562696626976269862699627006270162702627036270462705627066270762708627096271062711627126271362714627156271662717627186271962720627216272262723627246272562726627276272862729627306273162732627336273462735627366273762738627396274062741627426274362744627456274662747627486274962750627516275262753627546275562756627576275862759627606276162762627636276462765627666276762768627696277062771627726277362774627756277662777627786277962780627816278262783627846278562786627876278862789627906279162792627936279462795627966279762798627996280062801628026280362804628056280662807628086280962810628116281262813628146281562816628176281862819628206282162822628236282462825628266282762828628296283062831628326283362834628356283662837628386283962840628416284262843628446284562846628476284862849628506285162852628536285462855628566285762858628596286062861628626286362864628656286662867628686286962870628716287262873628746287562876628776287862879628806288162882628836288462885628866288762888628896289062891628926289362894628956289662897628986289962900629016290262903629046290562906629076290862909629106291162912629136291462915629166291762918629196292062921629226292362924629256292662927629286292962930629316293262933629346293562936629376293862939629406294162942629436294462945629466294762948629496295062951629526295362954629556295662957629586295962960629616296262963629646296562966629676296862969629706297162972629736297462975629766297762978629796298062981629826298362984629856298662987629886298962990629916299262993629946299562996629976299862999630006300163002630036300463005630066300763008630096301063011630126301363014630156301663017630186301963020630216302263023630246302563026630276302863029630306303163032630336303463035630366303763038630396304063041630426304363044630456304663047630486304963050630516305263053630546305563056630576305863059630606306163062630636306463065630666306763068630696307063071630726307363074630756307663077630786307963080630816308263083630846308563086630876308863089630906309163092630936309463095630966309763098630996310063101631026310363104631056310663107631086310963110631116311263113631146311563116631176311863119631206312163122631236312463125631266312763128631296313063131631326313363134631356313663137631386313963140631416314263143631446314563146631476314863149631506315163152631536315463155631566315763158631596316063161631626316363164631656316663167631686316963170631716317263173631746317563176631776317863179631806318163182631836318463185631866318763188631896319063191631926319363194631956319663197631986319963200632016320263203632046320563206632076320863209632106321163212632136321463215632166321763218632196322063221632226322363224632256322663227632286322963230632316323263233632346323563236632376323863239632406324163242632436324463245632466324763248632496325063251632526325363254632556325663257632586325963260632616326263263632646326563266632676326863269632706327163272632736327463275632766327763278632796328063281632826328363284632856328663287632886328963290632916329263293632946329563296632976329863299633006330163302633036330463305633066330763308633096331063311633126331363314633156331663317633186331963320633216332263323633246332563326633276332863329633306333163332633336333463335633366333763338633396334063341633426334363344633456334663347633486334963350633516335263353633546335563356633576335863359633606336163362633636336463365633666336763368633696337063371633726337363374633756337663377633786337963380633816338263383633846338563386633876338863389633906339163392633936339463395633966339763398633996340063401634026340363404634056340663407634086340963410634116341263413634146341563416634176341863419634206342163422634236342463425634266342763428634296343063431634326343363434634356343663437634386343963440634416344263443634446344563446634476344863449634506345163452634536345463455634566345763458634596346063461634626346363464634656346663467634686346963470634716347263473634746347563476634776347863479634806348163482634836348463485634866348763488634896349063491634926349363494634956349663497634986349963500635016350263503635046350563506635076350863509635106351163512635136351463515635166351763518635196352063521635226352363524635256352663527635286352963530635316353263533635346353563536635376353863539635406354163542635436354463545635466354763548635496355063551635526355363554635556355663557635586355963560635616356263563635646356563566635676356863569635706357163572635736357463575635766357763578635796358063581635826358363584635856358663587635886358963590635916359263593635946359563596635976359863599636006360163602636036360463605636066360763608636096361063611636126361363614636156361663617636186361963620636216362263623636246362563626636276362863629636306363163632636336363463635636366363763638636396364063641636426364363644636456364663647636486364963650636516365263653636546365563656636576365863659636606366163662636636366463665636666366763668636696367063671636726367363674636756367663677636786367963680636816368263683636846368563686636876368863689636906369163692636936369463695636966369763698636996370063701637026370363704637056370663707637086370963710637116371263713637146371563716637176371863719637206372163722637236372463725637266372763728637296373063731637326373363734637356373663737637386373963740637416374263743637446374563746637476374863749637506375163752637536375463755637566375763758637596376063761637626376363764637656376663767637686376963770637716377263773637746377563776637776377863779637806378163782637836378463785637866378763788637896379063791637926379363794637956379663797637986379963800638016380263803638046380563806638076380863809638106381163812638136381463815638166381763818638196382063821638226382363824638256382663827638286382963830638316383263833638346383563836638376383863839638406384163842638436384463845638466384763848638496385063851638526385363854638556385663857638586385963860638616386263863638646386563866638676386863869638706387163872638736387463875638766387763878638796388063881638826388363884638856388663887638886388963890638916389263893638946389563896638976389863899639006390163902639036390463905639066390763908639096391063911639126391363914639156391663917639186391963920639216392263923639246392563926639276392863929639306393163932639336393463935639366393763938639396394063941639426394363944639456394663947639486394963950639516395263953639546395563956639576395863959639606396163962639636396463965639666396763968639696397063971639726397363974639756397663977639786397963980639816398263983639846398563986639876398863989639906399163992639936399463995639966399763998639996400064001640026400364004640056400664007640086400964010640116401264013640146401564016640176401864019640206402164022640236402464025640266402764028640296403064031640326403364034640356403664037640386403964040640416404264043640446404564046640476404864049640506405164052640536405464055640566405764058640596406064061640626406364064640656406664067640686406964070640716407264073640746407564076640776407864079640806408164082640836408464085640866408764088640896409064091640926409364094640956409664097640986409964100641016410264103641046410564106641076410864109641106411164112641136411464115641166411764118641196412064121641226412364124641256412664127641286412964130641316413264133641346413564136641376413864139641406414164142641436414464145641466414764148641496415064151641526415364154641556415664157641586415964160641616416264163641646416564166641676416864169641706417164172641736417464175641766417764178641796418064181641826418364184641856418664187641886418964190641916419264193641946419564196641976419864199642006420164202642036420464205642066420764208642096421064211642126421364214642156421664217642186421964220642216422264223642246422564226642276422864229642306423164232642336423464235642366423764238642396424064241642426424364244642456424664247642486424964250642516425264253642546425564256642576425864259642606426164262642636426464265642666426764268642696427064271642726427364274642756427664277642786427964280642816428264283642846428564286642876428864289642906429164292642936429464295642966429764298642996430064301643026430364304643056430664307643086430964310643116431264313643146431564316643176431864319643206432164322643236432464325643266432764328643296433064331643326433364334643356433664337643386433964340643416434264343643446434564346643476434864349643506435164352643536435464355643566435764358643596436064361643626436364364643656436664367643686436964370643716437264373643746437564376643776437864379643806438164382643836438464385643866438764388643896439064391643926439364394643956439664397643986439964400644016440264403644046440564406644076440864409644106441164412644136441464415644166441764418644196442064421644226442364424644256442664427644286442964430644316443264433644346443564436644376443864439644406444164442644436444464445644466444764448644496445064451644526445364454644556445664457644586445964460644616446264463644646446564466644676446864469644706447164472644736447464475644766447764478644796448064481644826448364484644856448664487644886448964490644916449264493644946449564496644976449864499645006450164502645036450464505645066450764508645096451064511645126451364514645156451664517645186451964520645216452264523645246452564526645276452864529645306453164532645336453464535645366453764538645396454064541645426454364544645456454664547645486454964550645516455264553645546455564556645576455864559645606456164562645636456464565645666456764568645696457064571645726457364574645756457664577645786457964580645816458264583645846458564586645876458864589645906459164592645936459464595645966459764598645996460064601646026460364604646056460664607646086460964610646116461264613646146461564616646176461864619646206462164622646236462464625646266462764628646296463064631646326463364634646356463664637646386463964640646416464264643646446464564646646476464864649646506465164652646536465464655646566465764658646596466064661646626466364664646656466664667646686466964670646716467264673646746467564676646776467864679646806468164682646836468464685646866468764688646896469064691646926469364694646956469664697646986469964700647016470264703647046470564706647076470864709647106471164712647136471464715647166471764718647196472064721647226472364724647256472664727647286472964730647316473264733647346473564736647376473864739647406474164742647436474464745647466474764748647496475064751647526475364754647556475664757647586475964760647616476264763647646476564766647676476864769647706477164772647736477464775647766477764778647796478064781647826478364784647856478664787647886478964790647916479264793647946479564796647976479864799648006480164802648036480464805648066480764808648096481064811648126481364814648156481664817648186481964820648216482264823648246482564826648276482864829648306483164832648336483464835648366483764838648396484064841648426484364844648456484664847648486484964850648516485264853648546485564856648576485864859648606486164862648636486464865648666486764868648696487064871648726487364874648756487664877648786487964880648816488264883648846488564886648876488864889648906489164892648936489464895648966489764898648996490064901649026490364904649056490664907649086490964910649116491264913649146491564916649176491864919649206492164922649236492464925649266492764928649296493064931649326493364934649356493664937649386493964940649416494264943649446494564946649476494864949649506495164952649536495464955649566495764958649596496064961649626496364964649656496664967649686496964970649716497264973649746497564976649776497864979649806498164982649836498464985649866498764988649896499064991649926499364994649956499664997649986499965000650016500265003650046500565006650076500865009650106501165012650136501465015650166501765018650196502065021650226502365024650256502665027650286502965030650316503265033650346503565036650376503865039650406504165042650436504465045650466504765048650496505065051650526505365054650556505665057650586505965060650616506265063650646506565066650676506865069650706507165072650736507465075650766507765078650796508065081650826508365084650856508665087650886508965090650916509265093650946509565096650976509865099651006510165102651036510465105651066510765108651096511065111651126511365114651156511665117651186511965120651216512265123651246512565126651276512865129651306513165132651336513465135651366513765138651396514065141651426514365144651456514665147651486514965150651516515265153651546515565156651576515865159651606516165162651636516465165651666516765168651696517065171651726517365174651756517665177651786517965180651816518265183651846518565186651876518865189651906519165192651936519465195651966519765198651996520065201652026520365204652056520665207652086520965210652116521265213652146521565216652176521865219652206522165222652236522465225652266522765228652296523065231652326523365234652356523665237652386523965240652416524265243652446524565246652476524865249652506525165252652536525465255652566525765258652596526065261652626526365264652656526665267652686526965270652716527265273652746527565276652776527865279652806528165282652836528465285652866528765288652896529065291652926529365294652956529665297652986529965300653016530265303653046530565306653076530865309653106531165312653136531465315653166531765318653196532065321653226532365324653256532665327653286532965330653316533265333653346533565336653376533865339653406534165342653436534465345653466534765348653496535065351653526535365354653556535665357653586535965360653616536265363653646536565366653676536865369653706537165372653736537465375653766537765378653796538065381653826538365384653856538665387653886538965390653916539265393653946539565396653976539865399654006540165402654036540465405654066540765408654096541065411654126541365414654156541665417654186541965420654216542265423654246542565426654276542865429654306543165432654336543465435654366543765438654396544065441654426544365444654456544665447654486544965450654516545265453654546545565456654576545865459654606546165462654636546465465654666546765468654696547065471654726547365474654756547665477654786547965480654816548265483654846548565486654876548865489654906549165492654936549465495654966549765498654996550065501655026550365504655056550665507655086550965510655116551265513655146551565516655176551865519655206552165522655236552465525655266552765528655296553065531655326553365534655356553665537655386553965540655416554265543655446554565546655476554865549655506555165552655536555465555655566555765558655596556065561655626556365564655656556665567655686556965570655716557265573655746557565576655776557865579655806558165582655836558465585655866558765588655896559065591655926559365594655956559665597655986559965600656016560265603656046560565606656076560865609656106561165612656136561465615656166561765618656196562065621656226562365624656256562665627656286562965630656316563265633656346563565636656376563865639656406564165642656436564465645656466564765648656496565065651656526565365654656556565665657656586565965660656616566265663656646566565666656676566865669656706567165672656736567465675656766567765678656796568065681656826568365684656856568665687656886568965690656916569265693656946569565696656976569865699657006570165702657036570465705657066570765708657096571065711657126571365714657156571665717657186571965720657216572265723657246572565726657276572865729657306573165732657336573465735657366573765738657396574065741657426574365744657456574665747657486574965750657516575265753657546575565756657576575865759657606576165762657636576465765657666576765768657696577065771657726577365774657756577665777657786577965780657816578265783657846578565786657876578865789657906579165792657936579465795657966579765798657996580065801658026580365804658056580665807658086580965810658116581265813658146581565816658176581865819658206582165822658236582465825658266582765828658296583065831658326583365834658356583665837658386583965840658416584265843658446584565846658476584865849658506585165852658536585465855658566585765858658596586065861658626586365864658656586665867658686586965870658716587265873658746587565876658776587865879658806588165882658836588465885658866588765888658896589065891658926589365894658956589665897658986589965900659016590265903659046590565906659076590865909659106591165912659136591465915659166591765918659196592065921659226592365924659256592665927659286592965930659316593265933659346593565936659376593865939659406594165942659436594465945659466594765948659496595065951659526595365954659556595665957659586595965960659616596265963659646596565966659676596865969659706597165972659736597465975659766597765978659796598065981659826598365984659856598665987659886598965990659916599265993659946599565996659976599865999660006600166002660036600466005660066600766008660096601066011660126601366014660156601666017660186601966020660216602266023660246602566026660276602866029660306603166032660336603466035660366603766038660396604066041660426604366044660456604666047660486604966050660516605266053660546605566056660576605866059660606606166062660636606466065660666606766068660696607066071660726607366074660756607666077660786607966080660816608266083660846608566086660876608866089660906609166092660936609466095660966609766098660996610066101661026610366104661056610666107661086610966110661116611266113661146611566116661176611866119661206612166122661236612466125661266612766128661296613066131661326613366134661356613666137661386613966140661416614266143661446614566146661476614866149661506615166152661536615466155661566615766158661596616066161661626616366164661656616666167661686616966170661716617266173661746617566176661776617866179661806618166182661836618466185661866618766188661896619066191661926619366194661956619666197661986619966200662016620266203662046620566206662076620866209662106621166212662136621466215662166621766218662196622066221662226622366224662256622666227662286622966230662316623266233662346623566236662376623866239662406624166242662436624466245662466624766248662496625066251662526625366254662556625666257662586625966260662616626266263662646626566266662676626866269662706627166272662736627466275662766627766278662796628066281662826628366284662856628666287662886628966290662916629266293662946629566296662976629866299663006630166302663036630466305663066630766308663096631066311663126631366314663156631666317663186631966320663216632266323663246632566326663276632866329663306633166332663336633466335663366633766338663396634066341663426634366344663456634666347663486634966350663516635266353663546635566356663576635866359663606636166362663636636466365663666636766368663696637066371663726637366374663756637666377663786637966380663816638266383663846638566386663876638866389663906639166392663936639466395663966639766398663996640066401664026640366404664056640666407664086640966410664116641266413664146641566416664176641866419664206642166422664236642466425664266642766428664296643066431664326643366434664356643666437664386643966440664416644266443664446644566446664476644866449664506645166452664536645466455664566645766458664596646066461664626646366464664656646666467664686646966470664716647266473664746647566476664776647866479664806648166482664836648466485664866648766488664896649066491664926649366494664956649666497664986649966500665016650266503665046650566506665076650866509665106651166512665136651466515665166651766518665196652066521665226652366524665256652666527665286652966530665316653266533665346653566536665376653866539665406654166542665436654466545665466654766548665496655066551665526655366554665556655666557665586655966560665616656266563665646656566566665676656866569665706657166572665736657466575665766657766578665796658066581665826658366584665856658666587665886658966590665916659266593665946659566596665976659866599666006660166602666036660466605666066660766608666096661066611666126661366614666156661666617666186661966620666216662266623666246662566626666276662866629666306663166632666336663466635666366663766638666396664066641666426664366644666456664666647666486664966650666516665266653666546665566656666576665866659666606666166662666636666466665666666666766668666696667066671666726667366674666756667666677666786667966680666816668266683666846668566686666876668866689666906669166692666936669466695666966669766698666996670066701667026670366704667056670666707667086670966710667116671266713667146671566716667176671866719667206672166722667236672466725667266672766728667296673066731667326673366734667356673666737667386673966740667416674266743667446674566746667476674866749667506675166752667536675466755667566675766758667596676066761667626676366764667656676666767667686676966770667716677266773667746677566776667776677866779667806678166782667836678466785667866678766788667896679066791667926679366794667956679666797667986679966800668016680266803668046680566806668076680866809668106681166812668136681466815668166681766818668196682066821668226682366824668256682666827668286682966830668316683266833668346683566836668376683866839668406684166842668436684466845668466684766848668496685066851668526685366854668556685666857668586685966860668616686266863668646686566866668676686866869668706687166872668736687466875668766687766878668796688066881668826688366884668856688666887668886688966890668916689266893668946689566896668976689866899669006690166902669036690466905669066690766908669096691066911669126691366914669156691666917669186691966920669216692266923669246692566926669276692866929669306693166932669336693466935669366693766938669396694066941669426694366944669456694666947669486694966950669516695266953669546695566956669576695866959669606696166962669636696466965669666696766968669696697066971669726697366974669756697666977669786697966980669816698266983669846698566986669876698866989669906699166992669936699466995669966699766998669996700067001670026700367004670056700667007670086700967010670116701267013670146701567016670176701867019670206702167022670236702467025670266702767028670296703067031670326703367034670356703667037670386703967040670416704267043670446704567046670476704867049670506705167052670536705467055670566705767058670596706067061670626706367064670656706667067670686706967070670716707267073670746707567076670776707867079670806708167082670836708467085670866708767088670896709067091670926709367094670956709667097670986709967100671016710267103671046710567106671076710867109671106711167112671136711467115671166711767118671196712067121671226712367124671256712667127671286712967130671316713267133671346713567136671376713867139671406714167142671436714467145671466714767148671496715067151671526715367154671556715667157671586715967160671616716267163671646716567166671676716867169671706717167172671736717467175671766717767178671796718067181671826718367184671856718667187671886718967190671916719267193671946719567196671976719867199672006720167202672036720467205672066720767208672096721067211672126721367214672156721667217672186721967220672216722267223672246722567226672276722867229672306723167232672336723467235672366723767238672396724067241672426724367244672456724667247672486724967250672516725267253672546725567256672576725867259672606726167262672636726467265672666726767268672696727067271672726727367274672756727667277672786727967280672816728267283672846728567286672876728867289672906729167292672936729467295672966729767298672996730067301673026730367304673056730667307673086730967310673116731267313673146731567316673176731867319673206732167322673236732467325673266732767328673296733067331673326733367334673356733667337673386733967340673416734267343673446734567346673476734867349673506735167352673536735467355673566735767358673596736067361673626736367364673656736667367673686736967370673716737267373673746737567376673776737867379673806738167382673836738467385673866738767388673896739067391673926739367394673956739667397673986739967400674016740267403674046740567406674076740867409674106741167412674136741467415674166741767418674196742067421674226742367424674256742667427674286742967430674316743267433674346743567436674376743867439674406744167442674436744467445674466744767448674496745067451674526745367454674556745667457674586745967460674616746267463674646746567466674676746867469674706747167472674736747467475674766747767478674796748067481674826748367484674856748667487674886748967490674916749267493674946749567496674976749867499675006750167502675036750467505675066750767508675096751067511675126751367514675156751667517675186751967520675216752267523675246752567526675276752867529675306753167532675336753467535675366753767538675396754067541675426754367544675456754667547675486754967550675516755267553675546755567556675576755867559675606756167562675636756467565675666756767568675696757067571675726757367574675756757667577675786757967580675816758267583675846758567586675876758867589675906759167592675936759467595675966759767598675996760067601676026760367604676056760667607676086760967610676116761267613676146761567616676176761867619676206762167622676236762467625676266762767628676296763067631676326763367634676356763667637676386763967640676416764267643676446764567646676476764867649676506765167652676536765467655676566765767658676596766067661676626766367664676656766667667676686766967670676716767267673676746767567676676776767867679676806768167682676836768467685676866768767688676896769067691676926769367694676956769667697676986769967700677016770267703677046770567706677076770867709677106771167712677136771467715677166771767718677196772067721677226772367724677256772667727677286772967730677316773267733677346773567736677376773867739677406774167742677436774467745677466774767748677496775067751677526775367754677556775667757677586775967760677616776267763677646776567766677676776867769677706777167772677736777467775677766777767778677796778067781677826778367784677856778667787677886778967790677916779267793677946779567796677976779867799678006780167802678036780467805678066780767808678096781067811678126781367814678156781667817678186781967820678216782267823678246782567826678276782867829678306783167832678336783467835678366783767838678396784067841678426784367844678456784667847678486784967850678516785267853678546785567856678576785867859678606786167862678636786467865678666786767868678696787067871678726787367874678756787667877678786787967880678816788267883678846788567886678876788867889678906789167892678936789467895678966789767898678996790067901679026790367904679056790667907679086790967910679116791267913679146791567916679176791867919679206792167922679236792467925679266792767928679296793067931679326793367934679356793667937679386793967940679416794267943679446794567946679476794867949679506795167952679536795467955679566795767958679596796067961679626796367964679656796667967679686796967970679716797267973679746797567976679776797867979679806798167982679836798467985679866798767988679896799067991679926799367994679956799667997679986799968000680016800268003680046800568006680076800868009680106801168012680136801468015680166801768018680196802068021680226802368024680256802668027680286802968030680316803268033680346803568036680376803868039680406804168042680436804468045680466804768048680496805068051680526805368054680556805668057680586805968060680616806268063680646806568066680676806868069680706807168072680736807468075680766807768078680796808068081680826808368084680856808668087680886808968090680916809268093680946809568096680976809868099681006810168102681036810468105681066810768108681096811068111681126811368114681156811668117681186811968120681216812268123681246812568126681276812868129681306813168132681336813468135681366813768138681396814068141681426814368144681456814668147681486814968150681516815268153681546815568156681576815868159681606816168162681636816468165681666816768168681696817068171681726817368174681756817668177681786817968180681816818268183681846818568186681876818868189681906819168192681936819468195681966819768198681996820068201682026820368204682056820668207682086820968210682116821268213682146821568216682176821868219682206822168222682236822468225682266822768228682296823068231682326823368234682356823668237682386823968240682416824268243682446824568246682476824868249682506825168252682536825468255682566825768258682596826068261682626826368264682656826668267682686826968270682716827268273682746827568276682776827868279682806828168282682836828468285682866828768288682896829068291682926829368294682956829668297682986829968300683016830268303683046830568306683076830868309683106831168312683136831468315683166831768318683196832068321683226832368324683256832668327683286832968330683316833268333683346833568336683376833868339683406834168342683436834468345683466834768348683496835068351683526835368354683556835668357683586835968360683616836268363683646836568366683676836868369683706837168372683736837468375683766837768378683796838068381683826838368384683856838668387683886838968390683916839268393683946839568396683976839868399684006840168402684036840468405684066840768408684096841068411684126841368414684156841668417684186841968420684216842268423684246842568426684276842868429684306843168432684336843468435684366843768438684396844068441684426844368444684456844668447684486844968450684516845268453684546845568456684576845868459684606846168462684636846468465684666846768468684696847068471684726847368474684756847668477684786847968480684816848268483684846848568486684876848868489684906849168492684936849468495684966849768498684996850068501685026850368504685056850668507685086850968510685116851268513685146851568516685176851868519685206852168522685236852468525685266852768528685296853068531685326853368534685356853668537685386853968540685416854268543685446854568546685476854868549685506855168552685536855468555685566855768558685596856068561685626856368564685656856668567685686856968570685716857268573685746857568576685776857868579685806858168582685836858468585685866858768588685896859068591685926859368594685956859668597685986859968600686016860268603686046860568606686076860868609686106861168612686136861468615686166861768618686196862068621686226862368624686256862668627686286862968630686316863268633686346863568636686376863868639686406864168642686436864468645686466864768648686496865068651686526865368654686556865668657686586865968660686616866268663686646866568666686676866868669686706867168672686736867468675686766867768678686796868068681686826868368684686856868668687686886868968690686916869268693686946869568696686976869868699687006870168702687036870468705687066870768708687096871068711687126871368714687156871668717687186871968720687216872268723687246872568726687276872868729687306873168732687336873468735687366873768738687396874068741687426874368744687456874668747687486874968750687516875268753687546875568756687576875868759687606876168762687636876468765687666876768768687696877068771687726877368774687756877668777687786877968780687816878268783687846878568786687876878868789687906879168792687936879468795687966879768798687996880068801688026880368804688056880668807688086880968810688116881268813688146881568816688176881868819688206882168822688236882468825688266882768828688296883068831688326883368834688356883668837688386883968840688416884268843688446884568846688476884868849688506885168852688536885468855688566885768858688596886068861688626886368864688656886668867688686886968870688716887268873688746887568876688776887868879688806888168882688836888468885688866888768888688896889068891688926889368894688956889668897688986889968900689016890268903689046890568906689076890868909689106891168912689136891468915689166891768918689196892068921689226892368924689256892668927689286892968930689316893268933689346893568936689376893868939689406894168942689436894468945689466894768948689496895068951689526895368954689556895668957689586895968960689616896268963689646896568966689676896868969689706897168972689736897468975689766897768978689796898068981689826898368984689856898668987689886898968990689916899268993689946899568996689976899868999690006900169002690036900469005690066900769008690096901069011690126901369014690156901669017690186901969020690216902269023690246902569026690276902869029690306903169032690336903469035690366903769038690396904069041690426904369044690456904669047690486904969050690516905269053690546905569056690576905869059690606906169062690636906469065690666906769068690696907069071690726907369074690756907669077690786907969080690816908269083690846908569086690876908869089690906909169092690936909469095690966909769098690996910069101691026910369104691056910669107691086910969110691116911269113691146911569116691176911869119691206912169122691236912469125691266912769128691296913069131691326913369134691356913669137691386913969140691416914269143691446914569146691476914869149691506915169152691536915469155691566915769158691596916069161691626916369164691656916669167691686916969170691716917269173691746917569176691776917869179691806918169182691836918469185691866918769188691896919069191691926919369194691956919669197691986919969200692016920269203692046920569206692076920869209692106921169212692136921469215692166921769218692196922069221692226922369224692256922669227692286922969230692316923269233692346923569236692376923869239692406924169242692436924469245692466924769248692496925069251692526925369254692556925669257692586925969260692616926269263692646926569266692676926869269692706927169272692736927469275692766927769278692796928069281692826928369284692856928669287692886928969290692916929269293692946929569296692976929869299693006930169302693036930469305693066930769308693096931069311693126931369314693156931669317693186931969320693216932269323693246932569326693276932869329693306933169332693336933469335693366933769338693396934069341693426934369344693456934669347693486934969350693516935269353693546935569356693576935869359693606936169362693636936469365693666936769368693696937069371693726937369374693756937669377693786937969380693816938269383693846938569386693876938869389693906939169392693936939469395693966939769398693996940069401694026940369404694056940669407694086940969410694116941269413694146941569416694176941869419694206942169422694236942469425694266942769428694296943069431694326943369434694356943669437694386943969440694416944269443694446944569446694476944869449694506945169452694536945469455694566945769458694596946069461694626946369464694656946669467694686946969470694716947269473694746947569476694776947869479694806948169482694836948469485694866948769488694896949069491694926949369494694956949669497694986949969500695016950269503695046950569506695076950869509695106951169512695136951469515695166951769518695196952069521695226952369524695256952669527695286952969530695316953269533695346953569536695376953869539695406954169542695436954469545695466954769548695496955069551695526955369554695556955669557695586955969560695616956269563695646956569566695676956869569695706957169572695736957469575695766957769578695796958069581695826958369584695856958669587695886958969590695916959269593695946959569596695976959869599696006960169602696036960469605696066960769608696096961069611696126961369614696156961669617696186961969620696216962269623696246962569626696276962869629696306963169632696336963469635696366963769638696396964069641696426964369644696456964669647696486964969650696516965269653696546965569656696576965869659696606966169662696636966469665696666966769668696696967069671696726967369674696756967669677696786967969680696816968269683696846968569686696876968869689696906969169692696936969469695696966969769698696996970069701697026970369704697056970669707697086970969710697116971269713697146971569716697176971869719697206972169722697236972469725697266972769728697296973069731697326973369734697356973669737697386973969740697416974269743697446974569746697476974869749697506975169752697536975469755697566975769758697596976069761697626976369764697656976669767697686976969770697716977269773697746977569776697776977869779697806978169782697836978469785697866978769788697896979069791697926979369794697956979669797697986979969800698016980269803698046980569806698076980869809698106981169812698136981469815698166981769818698196982069821698226982369824698256982669827698286982969830698316983269833698346983569836698376983869839698406984169842698436984469845698466984769848698496985069851698526985369854698556985669857698586985969860698616986269863698646986569866698676986869869698706987169872698736987469875698766987769878698796988069881698826988369884698856988669887698886988969890698916989269893698946989569896698976989869899699006990169902699036990469905699066990769908699096991069911699126991369914699156991669917699186991969920699216992269923699246992569926699276992869929699306993169932699336993469935699366993769938699396994069941699426994369944699456994669947699486994969950699516995269953699546995569956699576995869959699606996169962699636996469965699666996769968699696997069971699726997369974699756997669977699786997969980699816998269983699846998569986699876998869989699906999169992699936999469995699966999769998699997000070001700027000370004700057000670007700087000970010700117001270013700147001570016700177001870019700207002170022700237002470025700267002770028700297003070031700327003370034700357003670037700387003970040700417004270043700447004570046700477004870049700507005170052700537005470055700567005770058700597006070061700627006370064700657006670067700687006970070700717007270073700747007570076700777007870079700807008170082700837008470085700867008770088700897009070091700927009370094700957009670097700987009970100701017010270103701047010570106701077010870109701107011170112701137011470115701167011770118701197012070121701227012370124701257012670127701287012970130701317013270133701347013570136701377013870139701407014170142701437014470145701467014770148701497015070151701527015370154701557015670157701587015970160701617016270163701647016570166701677016870169701707017170172701737017470175701767017770178701797018070181701827018370184701857018670187701887018970190701917019270193701947019570196701977019870199702007020170202702037020470205702067020770208702097021070211702127021370214702157021670217702187021970220702217022270223702247022570226702277022870229702307023170232702337023470235702367023770238702397024070241702427024370244702457024670247702487024970250702517025270253702547025570256702577025870259702607026170262702637026470265702667026770268702697027070271702727027370274702757027670277702787027970280702817028270283702847028570286702877028870289702907029170292702937029470295702967029770298702997030070301703027030370304703057030670307703087030970310703117031270313703147031570316703177031870319703207032170322703237032470325703267032770328703297033070331703327033370334703357033670337703387033970340703417034270343703447034570346703477034870349703507035170352703537035470355703567035770358703597036070361703627036370364703657036670367703687036970370703717037270373703747037570376703777037870379703807038170382703837038470385703867038770388703897039070391703927039370394703957039670397703987039970400704017040270403704047040570406704077040870409704107041170412704137041470415704167041770418704197042070421704227042370424704257042670427704287042970430704317043270433704347043570436704377043870439704407044170442704437044470445704467044770448704497045070451704527045370454704557045670457704587045970460704617046270463704647046570466704677046870469704707047170472704737047470475704767047770478704797048070481704827048370484704857048670487704887048970490704917049270493704947049570496704977049870499705007050170502705037050470505705067050770508705097051070511705127051370514705157051670517705187051970520705217052270523705247052570526705277052870529705307053170532705337053470535705367053770538705397054070541705427054370544705457054670547705487054970550705517055270553705547055570556705577055870559705607056170562705637056470565705667056770568705697057070571705727057370574705757057670577705787057970580705817058270583705847058570586705877058870589705907059170592705937059470595705967059770598705997060070601706027060370604706057060670607706087060970610706117061270613706147061570616706177061870619706207062170622706237062470625706267062770628706297063070631706327063370634706357063670637706387063970640706417064270643706447064570646706477064870649706507065170652706537065470655706567065770658706597066070661706627066370664706657066670667706687066970670706717067270673706747067570676706777067870679706807068170682706837068470685706867068770688706897069070691706927069370694706957069670697706987069970700707017070270703707047070570706707077070870709707107071170712707137071470715707167071770718707197072070721707227072370724707257072670727707287072970730707317073270733707347073570736707377073870739707407074170742707437074470745707467074770748707497075070751707527075370754707557075670757707587075970760707617076270763707647076570766707677076870769707707077170772707737077470775707767077770778707797078070781707827078370784707857078670787707887078970790707917079270793707947079570796707977079870799708007080170802708037080470805708067080770808708097081070811708127081370814708157081670817708187081970820708217082270823708247082570826708277082870829708307083170832708337083470835708367083770838708397084070841708427084370844708457084670847708487084970850708517085270853708547085570856708577085870859708607086170862708637086470865708667086770868708697087070871708727087370874708757087670877708787087970880708817088270883708847088570886708877088870889708907089170892708937089470895708967089770898708997090070901709027090370904709057090670907709087090970910709117091270913709147091570916709177091870919709207092170922709237092470925709267092770928709297093070931709327093370934709357093670937709387093970940709417094270943709447094570946709477094870949709507095170952709537095470955709567095770958709597096070961709627096370964709657096670967709687096970970709717097270973709747097570976709777097870979709807098170982709837098470985709867098770988709897099070991709927099370994709957099670997709987099971000710017100271003710047100571006710077100871009710107101171012710137101471015710167101771018710197102071021710227102371024710257102671027710287102971030710317103271033710347103571036710377103871039710407104171042710437104471045710467104771048710497105071051710527105371054710557105671057710587105971060710617106271063710647106571066710677106871069710707107171072710737107471075710767107771078710797108071081710827108371084710857108671087710887108971090710917109271093710947109571096710977109871099711007110171102711037110471105711067110771108711097111071111711127111371114711157111671117711187111971120711217112271123711247112571126711277112871129711307113171132711337113471135711367113771138711397114071141711427114371144711457114671147711487114971150711517115271153711547115571156711577115871159711607116171162711637116471165711667116771168711697117071171711727117371174711757117671177711787117971180711817118271183711847118571186711877118871189711907119171192711937119471195711967119771198711997120071201712027120371204712057120671207712087120971210712117121271213712147121571216712177121871219712207122171222712237122471225712267122771228712297123071231712327123371234712357123671237712387123971240712417124271243712447124571246712477124871249712507125171252712537125471255712567125771258712597126071261712627126371264712657126671267712687126971270712717127271273712747127571276712777127871279712807128171282712837128471285712867128771288712897129071291712927129371294712957129671297712987129971300713017130271303713047130571306713077130871309713107131171312713137131471315713167131771318713197132071321713227132371324713257132671327713287132971330713317133271333713347133571336713377133871339713407134171342713437134471345713467134771348713497135071351713527135371354713557135671357713587135971360713617136271363713647136571366713677136871369713707137171372713737137471375713767137771378713797138071381713827138371384713857138671387713887138971390713917139271393713947139571396713977139871399714007140171402714037140471405714067140771408714097141071411714127141371414714157141671417714187141971420714217142271423714247142571426714277142871429714307143171432714337143471435714367143771438714397144071441714427144371444714457144671447714487144971450714517145271453714547145571456714577145871459714607146171462714637146471465714667146771468714697147071471714727147371474714757147671477714787147971480714817148271483714847148571486714877148871489714907149171492714937149471495714967149771498714997150071501715027150371504715057150671507715087150971510715117151271513715147151571516715177151871519715207152171522715237152471525715267152771528715297153071531715327153371534715357153671537715387153971540715417154271543715447154571546715477154871549715507155171552715537155471555715567155771558715597156071561715627156371564715657156671567715687156971570715717157271573715747157571576715777157871579715807158171582715837158471585715867158771588715897159071591715927159371594715957159671597715987159971600716017160271603716047160571606716077160871609716107161171612716137161471615716167161771618716197162071621716227162371624716257162671627716287162971630716317163271633716347163571636716377163871639716407164171642716437164471645716467164771648716497165071651716527165371654716557165671657716587165971660716617166271663716647166571666716677166871669716707167171672716737167471675716767167771678716797168071681716827168371684716857168671687716887168971690716917169271693716947169571696716977169871699717007170171702717037170471705717067170771708717097171071711717127171371714717157171671717717187171971720717217172271723717247172571726717277172871729717307173171732717337173471735717367173771738717397174071741717427174371744717457174671747717487174971750717517175271753717547175571756717577175871759717607176171762717637176471765717667176771768717697177071771717727177371774717757177671777717787177971780717817178271783717847178571786717877178871789717907179171792717937179471795717967179771798717997180071801718027180371804718057180671807718087180971810718117181271813718147181571816718177181871819718207182171822718237182471825718267182771828718297183071831718327183371834718357183671837718387183971840718417184271843718447184571846718477184871849718507185171852718537185471855718567185771858718597186071861718627186371864718657186671867718687186971870718717187271873718747187571876718777187871879718807188171882718837188471885718867188771888718897189071891718927189371894718957189671897718987189971900719017190271903719047190571906719077190871909719107191171912719137191471915719167191771918719197192071921719227192371924719257192671927719287192971930719317193271933719347193571936719377193871939719407194171942719437194471945719467194771948719497195071951719527195371954719557195671957719587195971960719617196271963719647196571966719677196871969719707197171972719737197471975719767197771978719797198071981719827198371984719857198671987719887198971990719917199271993719947199571996719977199871999720007200172002720037200472005720067200772008720097201072011720127201372014720157201672017720187201972020720217202272023720247202572026720277202872029720307203172032720337203472035720367203772038720397204072041720427204372044720457204672047720487204972050720517205272053720547205572056720577205872059720607206172062720637206472065720667206772068720697207072071720727207372074720757207672077720787207972080720817208272083720847208572086720877208872089720907209172092720937209472095720967209772098720997210072101721027210372104721057210672107721087210972110721117211272113721147211572116721177211872119721207212172122721237212472125721267212772128721297213072131721327213372134721357213672137721387213972140721417214272143721447214572146721477214872149721507215172152721537215472155721567215772158721597216072161721627216372164721657216672167721687216972170721717217272173721747217572176721777217872179721807218172182721837218472185721867218772188721897219072191721927219372194721957219672197721987219972200722017220272203722047220572206722077220872209722107221172212722137221472215722167221772218722197222072221722227222372224722257222672227722287222972230722317223272233722347223572236722377223872239722407224172242722437224472245722467224772248722497225072251722527225372254722557225672257722587225972260722617226272263722647226572266722677226872269722707227172272722737227472275722767227772278722797228072281722827228372284722857228672287722887228972290722917229272293722947229572296722977229872299723007230172302723037230472305723067230772308723097231072311723127231372314723157231672317723187231972320723217232272323723247232572326723277232872329723307233172332723337233472335723367233772338723397234072341723427234372344723457234672347723487234972350723517235272353723547235572356723577235872359723607236172362723637236472365723667236772368723697237072371723727237372374723757237672377723787237972380723817238272383723847238572386723877238872389723907239172392723937239472395723967239772398723997240072401724027240372404724057240672407724087240972410724117241272413724147241572416724177241872419724207242172422724237242472425724267242772428724297243072431724327243372434724357243672437724387243972440724417244272443724447244572446724477244872449724507245172452724537245472455724567245772458724597246072461724627246372464724657246672467724687246972470724717247272473724747247572476724777247872479724807248172482724837248472485724867248772488724897249072491724927249372494724957249672497724987249972500725017250272503725047250572506725077250872509725107251172512725137251472515725167251772518725197252072521725227252372524725257252672527725287252972530725317253272533725347253572536725377253872539725407254172542725437254472545725467254772548725497255072551725527255372554725557255672557725587255972560725617256272563725647256572566725677256872569725707257172572725737257472575725767257772578725797258072581725827258372584725857258672587725887258972590725917259272593725947259572596725977259872599726007260172602726037260472605726067260772608726097261072611726127261372614726157261672617726187261972620726217262272623726247262572626726277262872629726307263172632726337263472635726367263772638726397264072641726427264372644726457264672647726487264972650726517265272653726547265572656726577265872659726607266172662726637266472665726667266772668726697267072671726727267372674726757267672677726787267972680726817268272683726847268572686726877268872689726907269172692726937269472695726967269772698726997270072701727027270372704727057270672707727087270972710727117271272713727147271572716727177271872719727207272172722727237272472725727267272772728727297273072731727327273372734727357273672737727387273972740727417274272743727447274572746727477274872749727507275172752727537275472755727567275772758727597276072761727627276372764727657276672767727687276972770727717277272773727747277572776727777277872779727807278172782727837278472785727867278772788727897279072791727927279372794727957279672797727987279972800728017280272803728047280572806728077280872809728107281172812728137281472815728167281772818728197282072821728227282372824728257282672827728287282972830728317283272833728347283572836728377283872839728407284172842728437284472845728467284772848728497285072851728527285372854728557285672857728587285972860728617286272863728647286572866728677286872869728707287172872728737287472875728767287772878728797288072881728827288372884728857288672887728887288972890728917289272893728947289572896728977289872899729007290172902729037290472905729067290772908729097291072911729127291372914729157291672917729187291972920729217292272923729247292572926729277292872929729307293172932729337293472935729367293772938729397294072941729427294372944729457294672947729487294972950729517295272953729547295572956729577295872959729607296172962729637296472965729667296772968729697297072971729727297372974729757297672977729787297972980729817298272983729847298572986729877298872989729907299172992729937299472995729967299772998729997300073001730027300373004730057300673007730087300973010730117301273013730147301573016730177301873019730207302173022730237302473025730267302773028730297303073031730327303373034730357303673037730387303973040730417304273043730447304573046730477304873049730507305173052730537305473055730567305773058730597306073061730627306373064730657306673067730687306973070730717307273073730747307573076730777307873079730807308173082730837308473085730867308773088730897309073091730927309373094730957309673097730987309973100731017310273103731047310573106731077310873109731107311173112731137311473115731167311773118731197312073121731227312373124731257312673127731287312973130731317313273133731347313573136731377313873139731407314173142731437314473145731467314773148731497315073151731527315373154731557315673157731587315973160731617316273163731647316573166731677316873169731707317173172731737317473175731767317773178731797318073181731827318373184731857318673187731887318973190731917319273193731947319573196731977319873199732007320173202732037320473205732067320773208732097321073211732127321373214732157321673217732187321973220732217322273223732247322573226732277322873229732307323173232732337323473235732367323773238732397324073241732427324373244732457324673247732487324973250732517325273253732547325573256732577325873259732607326173262732637326473265732667326773268732697327073271732727327373274732757327673277732787327973280732817328273283732847328573286732877328873289732907329173292732937329473295732967329773298732997330073301733027330373304733057330673307733087330973310733117331273313733147331573316733177331873319733207332173322733237332473325733267332773328733297333073331733327333373334733357333673337733387333973340733417334273343733447334573346733477334873349733507335173352733537335473355733567335773358733597336073361733627336373364733657336673367733687336973370733717337273373733747337573376733777337873379733807338173382733837338473385733867338773388733897339073391733927339373394733957339673397733987339973400734017340273403734047340573406734077340873409734107341173412734137341473415734167341773418734197342073421734227342373424734257342673427734287342973430734317343273433734347343573436734377343873439734407344173442734437344473445734467344773448734497345073451734527345373454734557345673457734587345973460734617346273463734647346573466734677346873469734707347173472734737347473475734767347773478734797348073481734827348373484734857348673487734887348973490734917349273493734947349573496734977349873499735007350173502735037350473505735067350773508735097351073511735127351373514735157351673517735187351973520735217352273523735247352573526735277352873529735307353173532735337353473535735367353773538735397354073541735427354373544735457354673547735487354973550735517355273553735547355573556735577355873559735607356173562735637356473565735667356773568735697357073571735727357373574735757357673577735787357973580735817358273583735847358573586735877358873589735907359173592735937359473595735967359773598735997360073601736027360373604736057360673607736087360973610736117361273613736147361573616736177361873619736207362173622736237362473625736267362773628736297363073631736327363373634736357363673637736387363973640736417364273643736447364573646736477364873649736507365173652736537365473655736567365773658736597366073661736627366373664736657366673667736687366973670736717367273673736747367573676736777367873679736807368173682736837368473685736867368773688736897369073691736927369373694736957369673697736987369973700737017370273703737047370573706737077370873709737107371173712737137371473715737167371773718737197372073721737227372373724737257372673727737287372973730737317373273733737347373573736737377373873739737407374173742737437374473745737467374773748737497375073751737527375373754737557375673757737587375973760737617376273763737647376573766737677376873769737707377173772737737377473775737767377773778737797378073781737827378373784737857378673787737887378973790737917379273793737947379573796737977379873799738007380173802738037380473805738067380773808738097381073811738127381373814738157381673817738187381973820738217382273823738247382573826738277382873829738307383173832738337383473835738367383773838738397384073841738427384373844738457384673847738487384973850738517385273853738547385573856738577385873859738607386173862738637386473865738667386773868738697387073871738727387373874738757387673877738787387973880738817388273883738847388573886738877388873889738907389173892738937389473895738967389773898738997390073901739027390373904739057390673907739087390973910739117391273913739147391573916739177391873919739207392173922739237392473925739267392773928739297393073931739327393373934739357393673937739387393973940739417394273943739447394573946739477394873949739507395173952739537395473955739567395773958739597396073961739627396373964739657396673967739687396973970739717397273973739747397573976739777397873979739807398173982739837398473985739867398773988739897399073991739927399373994739957399673997739987399974000740017400274003740047400574006740077400874009740107401174012740137401474015740167401774018740197402074021740227402374024740257402674027740287402974030740317403274033740347403574036740377403874039740407404174042740437404474045740467404774048740497405074051740527405374054740557405674057740587405974060740617406274063740647406574066740677406874069740707407174072740737407474075740767407774078740797408074081740827408374084740857408674087740887408974090740917409274093740947409574096740977409874099741007410174102741037410474105741067410774108741097411074111741127411374114741157411674117741187411974120741217412274123741247412574126741277412874129741307413174132741337413474135741367413774138741397414074141741427414374144741457414674147741487414974150741517415274153741547415574156741577415874159741607416174162741637416474165741667416774168741697417074171741727417374174741757417674177741787417974180741817418274183741847418574186741877418874189741907419174192741937419474195741967419774198741997420074201742027420374204742057420674207742087420974210742117421274213742147421574216742177421874219742207422174222742237422474225742267422774228742297423074231742327423374234742357423674237742387423974240742417424274243742447424574246742477424874249742507425174252742537425474255742567425774258742597426074261742627426374264742657426674267742687426974270742717427274273742747427574276742777427874279742807428174282742837428474285742867428774288742897429074291742927429374294742957429674297742987429974300743017430274303743047430574306743077430874309743107431174312743137431474315743167431774318743197432074321743227432374324743257432674327743287432974330743317433274333743347433574336743377433874339743407434174342743437434474345743467434774348743497435074351743527435374354743557435674357743587435974360743617436274363743647436574366743677436874369743707437174372743737437474375743767437774378743797438074381743827438374384743857438674387743887438974390743917439274393743947439574396743977439874399744007440174402744037440474405744067440774408744097441074411744127441374414744157441674417744187441974420744217442274423744247442574426744277442874429744307443174432744337443474435744367443774438744397444074441744427444374444744457444674447744487444974450744517445274453744547445574456744577445874459744607446174462744637446474465744667446774468744697447074471744727447374474744757447674477744787447974480744817448274483744847448574486744877448874489744907449174492744937449474495744967449774498744997450074501745027450374504745057450674507745087450974510745117451274513745147451574516745177451874519745207452174522745237452474525745267452774528745297453074531745327453374534745357453674537745387453974540745417454274543745447454574546745477454874549745507455174552745537455474555745567455774558745597456074561745627456374564745657456674567745687456974570745717457274573745747457574576745777457874579745807458174582745837458474585745867458774588745897459074591745927459374594745957459674597745987459974600746017460274603746047460574606746077460874609746107461174612746137461474615746167461774618746197462074621746227462374624746257462674627746287462974630746317463274633746347463574636746377463874639746407464174642746437464474645746467464774648746497465074651746527465374654746557465674657746587465974660746617466274663746647466574666746677466874669746707467174672746737467474675746767467774678746797468074681746827468374684746857468674687746887468974690746917469274693746947469574696746977469874699747007470174702747037470474705747067470774708747097471074711747127471374714747157471674717747187471974720747217472274723747247472574726747277472874729747307473174732747337473474735747367473774738747397474074741747427474374744747457474674747747487474974750747517475274753747547475574756747577475874759747607476174762747637476474765747667476774768747697477074771747727477374774747757477674777747787477974780747817478274783747847478574786747877478874789747907479174792747937479474795747967479774798747997480074801748027480374804748057480674807748087480974810748117481274813748147481574816748177481874819748207482174822748237482474825748267482774828748297483074831748327483374834748357483674837748387483974840748417484274843748447484574846748477484874849748507485174852748537485474855748567485774858748597486074861748627486374864748657486674867748687486974870748717487274873748747487574876748777487874879748807488174882748837488474885748867488774888748897489074891748927489374894748957489674897748987489974900749017490274903749047490574906749077490874909749107491174912749137491474915749167491774918749197492074921749227492374924749257492674927749287492974930749317493274933749347493574936749377493874939749407494174942749437494474945749467494774948749497495074951749527495374954749557495674957749587495974960749617496274963749647496574966749677496874969749707497174972749737497474975749767497774978749797498074981749827498374984749857498674987749887498974990749917499274993749947499574996749977499874999750007500175002750037500475005750067500775008750097501075011750127501375014750157501675017750187501975020750217502275023750247502575026750277502875029750307503175032750337503475035750367503775038750397504075041750427504375044750457504675047750487504975050750517505275053750547505575056750577505875059750607506175062750637506475065750667506775068750697507075071750727507375074750757507675077750787507975080750817508275083750847508575086750877508875089750907509175092750937509475095750967509775098750997510075101751027510375104751057510675107751087510975110751117511275113751147511575116751177511875119751207512175122751237512475125751267512775128751297513075131751327513375134751357513675137751387513975140751417514275143751447514575146751477514875149751507515175152751537515475155751567515775158751597516075161751627516375164751657516675167751687516975170751717517275173751747517575176751777517875179751807518175182751837518475185751867518775188751897519075191751927519375194751957519675197751987519975200752017520275203752047520575206752077520875209752107521175212752137521475215752167521775218752197522075221752227522375224752257522675227752287522975230752317523275233752347523575236752377523875239752407524175242752437524475245752467524775248752497525075251752527525375254752557525675257752587525975260752617526275263752647526575266752677526875269752707527175272752737527475275752767527775278752797528075281752827528375284752857528675287752887528975290752917529275293752947529575296752977529875299753007530175302753037530475305753067530775308753097531075311753127531375314753157531675317753187531975320753217532275323753247532575326753277532875329753307533175332753337533475335753367533775338753397534075341753427534375344753457534675347753487534975350753517535275353753547535575356753577535875359753607536175362753637536475365753667536775368753697537075371753727537375374753757537675377753787537975380753817538275383753847538575386753877538875389753907539175392753937539475395753967539775398753997540075401754027540375404754057540675407754087540975410754117541275413754147541575416754177541875419754207542175422754237542475425754267542775428754297543075431754327543375434754357543675437754387543975440754417544275443754447544575446754477544875449754507545175452754537545475455754567545775458754597546075461754627546375464754657546675467754687546975470754717547275473754747547575476754777547875479754807548175482754837548475485754867548775488754897549075491754927549375494754957549675497754987549975500755017550275503755047550575506755077550875509755107551175512755137551475515755167551775518755197552075521755227552375524755257552675527755287552975530755317553275533755347553575536755377553875539755407554175542755437554475545755467554775548755497555075551755527555375554755557555675557755587555975560755617556275563755647556575566755677556875569755707557175572755737557475575755767557775578755797558075581755827558375584755857558675587755887558975590755917559275593755947559575596755977559875599756007560175602756037560475605756067560775608756097561075611756127561375614756157561675617756187561975620756217562275623756247562575626756277562875629756307563175632756337563475635756367563775638756397564075641756427564375644756457564675647756487564975650756517565275653756547565575656756577565875659756607566175662756637566475665756667566775668756697567075671756727567375674756757567675677756787567975680756817568275683756847568575686756877568875689756907569175692756937569475695756967569775698756997570075701757027570375704757057570675707757087570975710757117571275713757147571575716757177571875719757207572175722757237572475725757267572775728757297573075731757327573375734757357573675737757387573975740757417574275743757447574575746757477574875749757507575175752757537575475755757567575775758757597576075761757627576375764757657576675767757687576975770757717577275773757747577575776757777577875779757807578175782757837578475785757867578775788757897579075791757927579375794757957579675797757987579975800758017580275803758047580575806758077580875809758107581175812758137581475815758167581775818758197582075821758227582375824758257582675827758287582975830758317583275833758347583575836758377583875839758407584175842758437584475845758467584775848758497585075851758527585375854758557585675857758587585975860758617586275863758647586575866758677586875869758707587175872758737587475875758767587775878758797588075881758827588375884758857588675887758887588975890758917589275893758947589575896758977589875899759007590175902759037590475905759067590775908759097591075911759127591375914759157591675917759187591975920759217592275923759247592575926759277592875929759307593175932759337593475935759367593775938759397594075941759427594375944759457594675947759487594975950759517595275953759547595575956759577595875959759607596175962759637596475965759667596775968759697597075971759727597375974759757597675977759787597975980759817598275983759847598575986759877598875989759907599175992759937599475995759967599775998759997600076001760027600376004760057600676007760087600976010760117601276013760147601576016760177601876019760207602176022760237602476025760267602776028760297603076031760327603376034760357603676037760387603976040760417604276043760447604576046760477604876049760507605176052760537605476055760567605776058760597606076061760627606376064760657606676067760687606976070760717607276073760747607576076760777607876079760807608176082760837608476085760867608776088760897609076091760927609376094760957609676097760987609976100761017610276103761047610576106761077610876109761107611176112761137611476115761167611776118761197612076121761227612376124761257612676127761287612976130761317613276133761347613576136761377613876139761407614176142761437614476145761467614776148761497615076151761527615376154761557615676157761587615976160761617616276163761647616576166761677616876169761707617176172761737617476175761767617776178761797618076181761827618376184761857618676187761887618976190761917619276193761947619576196761977619876199762007620176202762037620476205762067620776208762097621076211762127621376214762157621676217762187621976220762217622276223762247622576226762277622876229762307623176232762337623476235762367623776238762397624076241762427624376244762457624676247762487624976250762517625276253762547625576256762577625876259762607626176262762637626476265762667626776268762697627076271762727627376274762757627676277762787627976280762817628276283762847628576286762877628876289762907629176292762937629476295762967629776298762997630076301763027630376304763057630676307763087630976310763117631276313763147631576316763177631876319763207632176322763237632476325763267632776328763297633076331763327633376334763357633676337763387633976340763417634276343763447634576346763477634876349763507635176352763537635476355763567635776358763597636076361763627636376364763657636676367763687636976370763717637276373763747637576376763777637876379763807638176382763837638476385763867638776388763897639076391763927639376394763957639676397763987639976400764017640276403764047640576406764077640876409764107641176412764137641476415764167641776418764197642076421764227642376424764257642676427764287642976430764317643276433764347643576436764377643876439764407644176442764437644476445764467644776448764497645076451764527645376454764557645676457764587645976460764617646276463764647646576466764677646876469764707647176472764737647476475764767647776478764797648076481764827648376484764857648676487764887648976490764917649276493764947649576496764977649876499765007650176502765037650476505765067650776508765097651076511765127651376514765157651676517765187651976520765217652276523765247652576526765277652876529765307653176532765337653476535765367653776538765397654076541765427654376544765457654676547765487654976550765517655276553765547655576556765577655876559765607656176562765637656476565765667656776568765697657076571765727657376574765757657676577765787657976580765817658276583765847658576586765877658876589765907659176592765937659476595765967659776598765997660076601766027660376604766057660676607766087660976610766117661276613766147661576616766177661876619766207662176622766237662476625766267662776628766297663076631766327663376634766357663676637766387663976640766417664276643766447664576646766477664876649766507665176652766537665476655766567665776658766597666076661766627666376664766657666676667766687666976670766717667276673766747667576676766777667876679766807668176682766837668476685766867668776688766897669076691766927669376694766957669676697766987669976700767017670276703767047670576706767077670876709767107671176712767137671476715767167671776718767197672076721767227672376724767257672676727767287672976730767317673276733767347673576736767377673876739767407674176742767437674476745767467674776748767497675076751767527675376754767557675676757767587675976760767617676276763767647676576766767677676876769767707677176772767737677476775767767677776778767797678076781767827678376784767857678676787767887678976790767917679276793767947679576796767977679876799768007680176802768037680476805768067680776808768097681076811768127681376814768157681676817768187681976820768217682276823768247682576826768277682876829768307683176832768337683476835768367683776838768397684076841768427684376844768457684676847768487684976850768517685276853768547685576856768577685876859768607686176862768637686476865768667686776868768697687076871768727687376874768757687676877768787687976880768817688276883768847688576886768877688876889768907689176892768937689476895768967689776898768997690076901769027690376904769057690676907769087690976910769117691276913769147691576916769177691876919769207692176922769237692476925769267692776928769297693076931769327693376934769357693676937769387693976940769417694276943769447694576946769477694876949769507695176952769537695476955769567695776958769597696076961769627696376964769657696676967769687696976970769717697276973769747697576976769777697876979769807698176982769837698476985769867698776988769897699076991769927699376994769957699676997769987699977000770017700277003770047700577006770077700877009770107701177012770137701477015770167701777018770197702077021770227702377024770257702677027770287702977030770317703277033770347703577036770377703877039770407704177042770437704477045770467704777048770497705077051770527705377054770557705677057770587705977060770617706277063770647706577066770677706877069770707707177072770737707477075770767707777078770797708077081770827708377084770857708677087770887708977090770917709277093770947709577096770977709877099771007710177102771037710477105771067710777108771097711077111771127711377114771157711677117771187711977120771217712277123771247712577126771277712877129771307713177132771337713477135771367713777138771397714077141771427714377144771457714677147771487714977150771517715277153771547715577156771577715877159771607716177162771637716477165771667716777168771697717077171771727717377174771757717677177771787717977180771817718277183771847718577186771877718877189771907719177192771937719477195771967719777198771997720077201772027720377204772057720677207772087720977210772117721277213772147721577216772177721877219772207722177222772237722477225772267722777228772297723077231772327723377234772357723677237772387723977240772417724277243772447724577246772477724877249772507725177252772537725477255772567725777258772597726077261772627726377264772657726677267772687726977270772717727277273772747727577276772777727877279772807728177282772837728477285772867728777288772897729077291772927729377294772957729677297772987729977300773017730277303773047730577306773077730877309773107731177312773137731477315773167731777318773197732077321773227732377324773257732677327773287732977330773317733277333773347733577336773377733877339773407734177342773437734477345773467734777348773497735077351773527735377354773557735677357773587735977360773617736277363773647736577366773677736877369773707737177372773737737477375773767737777378773797738077381773827738377384773857738677387773887738977390773917739277393773947739577396773977739877399774007740177402774037740477405774067740777408774097741077411774127741377414774157741677417774187741977420774217742277423774247742577426774277742877429774307743177432774337743477435774367743777438774397744077441774427744377444774457744677447774487744977450774517745277453774547745577456774577745877459774607746177462774637746477465774667746777468774697747077471774727747377474774757747677477774787747977480774817748277483774847748577486774877748877489774907749177492774937749477495774967749777498774997750077501775027750377504775057750677507775087750977510775117751277513775147751577516775177751877519775207752177522775237752477525775267752777528775297753077531775327753377534775357753677537775387753977540775417754277543775447754577546775477754877549775507755177552775537755477555775567755777558775597756077561775627756377564775657756677567775687756977570775717757277573775747757577576775777757877579775807758177582775837758477585775867758777588775897759077591775927759377594775957759677597775987759977600776017760277603776047760577606776077760877609776107761177612776137761477615776167761777618776197762077621776227762377624776257762677627776287762977630776317763277633776347763577636776377763877639776407764177642776437764477645776467764777648776497765077651776527765377654776557765677657776587765977660776617766277663776647766577666776677766877669776707767177672776737767477675776767767777678776797768077681776827768377684776857768677687776887768977690776917769277693776947769577696776977769877699777007770177702777037770477705777067770777708777097771077711777127771377714777157771677717777187771977720777217772277723777247772577726777277772877729777307773177732777337773477735777367773777738777397774077741777427774377744777457774677747777487774977750777517775277753777547775577756777577775877759777607776177762777637776477765777667776777768777697777077771777727777377774777757777677777777787777977780777817778277783777847778577786777877778877789777907779177792777937779477795777967779777798777997780077801778027780377804778057780677807778087780977810778117781277813778147781577816778177781877819778207782177822778237782477825778267782777828778297783077831778327783377834778357783677837778387783977840778417784277843778447784577846778477784877849778507785177852778537785477855778567785777858778597786077861778627786377864778657786677867778687786977870778717787277873778747787577876778777787877879778807788177882778837788477885778867788777888778897789077891778927789377894778957789677897778987789977900779017790277903779047790577906779077790877909779107791177912779137791477915779167791777918779197792077921779227792377924779257792677927779287792977930779317793277933779347793577936779377793877939779407794177942779437794477945779467794777948779497795077951779527795377954779557795677957779587795977960779617796277963779647796577966779677796877969779707797177972779737797477975779767797777978779797798077981779827798377984779857798677987779887798977990779917799277993779947799577996779977799877999780007800178002780037800478005780067800778008780097801078011780127801378014780157801678017780187801978020780217802278023780247802578026780277802878029780307803178032780337803478035780367803778038780397804078041780427804378044780457804678047780487804978050780517805278053780547805578056780577805878059780607806178062780637806478065780667806778068780697807078071780727807378074780757807678077780787807978080780817808278083780847808578086780877808878089780907809178092780937809478095780967809778098780997810078101781027810378104781057810678107781087810978110781117811278113781147811578116781177811878119781207812178122781237812478125781267812778128781297813078131781327813378134781357813678137781387813978140781417814278143781447814578146781477814878149781507815178152781537815478155781567815778158781597816078161781627816378164781657816678167781687816978170781717817278173781747817578176781777817878179781807818178182781837818478185781867818778188781897819078191781927819378194781957819678197781987819978200782017820278203782047820578206782077820878209782107821178212782137821478215782167821778218782197822078221782227822378224782257822678227782287822978230782317823278233782347823578236782377823878239782407824178242782437824478245782467824778248782497825078251782527825378254782557825678257782587825978260782617826278263782647826578266782677826878269782707827178272782737827478275782767827778278782797828078281782827828378284782857828678287782887828978290782917829278293782947829578296782977829878299783007830178302783037830478305783067830778308783097831078311783127831378314783157831678317783187831978320783217832278323783247832578326783277832878329783307833178332783337833478335783367833778338783397834078341783427834378344783457834678347783487834978350783517835278353783547835578356783577835878359783607836178362783637836478365783667836778368783697837078371783727837378374783757837678377783787837978380783817838278383783847838578386783877838878389783907839178392783937839478395783967839778398783997840078401784027840378404784057840678407784087840978410784117841278413784147841578416784177841878419784207842178422784237842478425784267842778428784297843078431784327843378434784357843678437784387843978440784417844278443784447844578446784477844878449784507845178452784537845478455784567845778458784597846078461784627846378464784657846678467784687846978470784717847278473784747847578476784777847878479784807848178482784837848478485784867848778488784897849078491784927849378494784957849678497784987849978500785017850278503785047850578506785077850878509785107851178512785137851478515785167851778518785197852078521785227852378524785257852678527785287852978530785317853278533785347853578536785377853878539785407854178542785437854478545785467854778548785497855078551785527855378554785557855678557785587855978560785617856278563785647856578566785677856878569785707857178572785737857478575785767857778578785797858078581785827858378584785857858678587785887858978590785917859278593785947859578596785977859878599786007860178602786037860478605786067860778608786097861078611786127861378614786157861678617786187861978620786217862278623786247862578626786277862878629786307863178632786337863478635786367863778638786397864078641786427864378644786457864678647786487864978650786517865278653786547865578656786577865878659786607866178662786637866478665786667866778668786697867078671786727867378674786757867678677786787867978680786817868278683786847868578686786877868878689786907869178692786937869478695786967869778698786997870078701787027870378704787057870678707787087870978710787117871278713787147871578716787177871878719787207872178722787237872478725787267872778728787297873078731787327873378734787357873678737787387873978740787417874278743787447874578746787477874878749787507875178752787537875478755787567875778758787597876078761787627876378764787657876678767787687876978770787717877278773787747877578776787777877878779787807878178782787837878478785787867878778788787897879078791787927879378794787957879678797787987879978800788017880278803788047880578806788077880878809788107881178812788137881478815788167881778818788197882078821788227882378824788257882678827788287882978830788317883278833788347883578836788377883878839788407884178842788437884478845788467884778848788497885078851788527885378854788557885678857788587885978860788617886278863788647886578866788677886878869788707887178872788737887478875788767887778878788797888078881788827888378884788857888678887788887888978890788917889278893788947889578896788977889878899789007890178902789037890478905789067890778908789097891078911789127891378914789157891678917789187891978920789217892278923789247892578926789277892878929789307893178932789337893478935789367893778938789397894078941789427894378944789457894678947789487894978950789517895278953789547895578956789577895878959789607896178962789637896478965789667896778968789697897078971789727897378974789757897678977789787897978980789817898278983789847898578986789877898878989789907899178992789937899478995789967899778998789997900079001790027900379004790057900679007790087900979010790117901279013790147901579016790177901879019790207902179022790237902479025790267902779028790297903079031790327903379034790357903679037790387903979040790417904279043790447904579046790477904879049790507905179052790537905479055790567905779058790597906079061790627906379064790657906679067790687906979070790717907279073790747907579076790777907879079790807908179082790837908479085790867908779088790897909079091790927909379094790957909679097790987909979100791017910279103791047910579106791077910879109791107911179112791137911479115791167911779118791197912079121791227912379124791257912679127791287912979130791317913279133791347913579136791377913879139791407914179142791437914479145791467914779148791497915079151791527915379154791557915679157791587915979160791617916279163791647916579166791677916879169791707917179172791737917479175791767917779178791797918079181791827918379184791857918679187791887918979190791917919279193791947919579196791977919879199792007920179202792037920479205792067920779208792097921079211792127921379214792157921679217792187921979220792217922279223792247922579226792277922879229792307923179232792337923479235792367923779238792397924079241792427924379244792457924679247792487924979250792517925279253792547925579256792577925879259792607926179262792637926479265792667926779268792697927079271792727927379274792757927679277792787927979280792817928279283792847928579286792877928879289792907929179292792937929479295792967929779298792997930079301793027930379304793057930679307793087930979310793117931279313793147931579316793177931879319793207932179322793237932479325793267932779328793297933079331793327933379334793357933679337793387933979340793417934279343793447934579346793477934879349793507935179352793537935479355793567935779358793597936079361793627936379364793657936679367793687936979370793717937279373793747937579376793777937879379793807938179382793837938479385793867938779388793897939079391793927939379394793957939679397793987939979400794017940279403794047940579406794077940879409794107941179412794137941479415794167941779418794197942079421794227942379424794257942679427794287942979430794317943279433794347943579436794377943879439794407944179442794437944479445794467944779448794497945079451794527945379454794557945679457794587945979460794617946279463794647946579466794677946879469794707947179472794737947479475794767947779478794797948079481794827948379484794857948679487794887948979490794917949279493794947949579496794977949879499795007950179502795037950479505795067950779508795097951079511795127951379514795157951679517795187951979520795217952279523795247952579526795277952879529795307953179532795337953479535795367953779538795397954079541795427954379544795457954679547795487954979550795517955279553795547955579556795577955879559795607956179562795637956479565795667956779568795697957079571795727957379574795757957679577795787957979580795817958279583795847958579586795877958879589795907959179592795937959479595795967959779598795997960079601796027960379604796057960679607796087960979610796117961279613796147961579616796177961879619796207962179622796237962479625796267962779628796297963079631796327963379634796357963679637796387963979640796417964279643796447964579646796477964879649796507965179652796537965479655796567965779658796597966079661796627966379664796657966679667796687966979670796717967279673796747967579676796777967879679796807968179682796837968479685796867968779688796897969079691796927969379694796957969679697796987969979700797017970279703797047970579706797077970879709797107971179712797137971479715797167971779718797197972079721797227972379724797257972679727797287972979730797317973279733797347973579736797377973879739797407974179742797437974479745797467974779748797497975079751797527975379754797557975679757797587975979760797617976279763797647976579766797677976879769797707977179772797737977479775797767977779778797797978079781797827978379784797857978679787797887978979790797917979279793797947979579796797977979879799798007980179802798037980479805798067980779808798097981079811798127981379814798157981679817798187981979820798217982279823798247982579826798277982879829798307983179832798337983479835798367983779838798397984079841798427984379844798457984679847798487984979850798517985279853798547985579856798577985879859798607986179862798637986479865798667986779868798697987079871798727987379874798757987679877798787987979880798817988279883798847988579886798877988879889798907989179892798937989479895798967989779898798997990079901799027990379904799057990679907799087990979910799117991279913799147991579916799177991879919799207992179922799237992479925799267992779928799297993079931799327993379934799357993679937799387993979940799417994279943799447994579946799477994879949799507995179952799537995479955799567995779958799597996079961799627996379964799657996679967799687996979970799717997279973799747997579976799777997879979799807998179982799837998479985799867998779988799897999079991799927999379994799957999679997799987999980000800018000280003800048000580006800078000880009800108001180012800138001480015800168001780018800198002080021800228002380024800258002680027800288002980030800318003280033800348003580036800378003880039800408004180042800438004480045800468004780048800498005080051800528005380054
  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":227,"dayjs/plugin/customParseFormat":228,"dayjs/plugin/utc":229,"fast-csv":260,"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. // this bundle is built without polyfill leaving apps the freedom to add their own
  4671. var ExcelJS = {
  4672. Workbook: require('./doc/workbook')
  4673. }; // Object.assign mono-fill
  4674. var Enums = require('./doc/enums');
  4675. Object.keys(Enums).forEach(function (key) {
  4676. ExcelJS[key] = Enums[key];
  4677. });
  4678. module.exports = ExcelJS;
  4679. },{"./doc/enums":7,"./doc/workbook":13}],16:[function(require,module,exports){
  4680. "use strict";
  4681. // eslint-disable-next-line node/no-unsupported-features/node-builtins
  4682. var textDecoder = typeof TextDecoder === 'undefined' ? null : new TextDecoder('utf-8');
  4683. function bufferToString(chunk) {
  4684. if (typeof chunk === 'string') {
  4685. return chunk;
  4686. }
  4687. if (textDecoder) {
  4688. return textDecoder.decode(chunk);
  4689. }
  4690. return chunk.toString();
  4691. }
  4692. exports.bufferToString = bufferToString;
  4693. },{}],17:[function(require,module,exports){
  4694. "use strict";
  4695. // eslint-disable-next-line node/no-unsupported-features/node-builtins
  4696. var textEncoder = typeof TextEncoder === 'undefined' ? null : new TextEncoder('utf-8');
  4697. var _require = require('buffer'),
  4698. Buffer = _require.Buffer;
  4699. function stringToBuffer(str) {
  4700. if (typeof str !== 'string') {
  4701. return str;
  4702. }
  4703. if (textEncoder) {
  4704. return Buffer.from(textEncoder.encode(str).buffer);
  4705. }
  4706. return Buffer.from(str);
  4707. }
  4708. exports.stringToBuffer = stringToBuffer;
  4709. },{"buffer":216}],18:[function(require,module,exports){
  4710. "use strict";
  4711. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4712. 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); } }
  4713. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  4714. var _ = require('./under-dash');
  4715. var colCache = require('./col-cache');
  4716. var CellMatrix = /*#__PURE__*/function () {
  4717. function CellMatrix(template) {
  4718. _classCallCheck(this, CellMatrix);
  4719. this.template = template;
  4720. this.sheets = {};
  4721. }
  4722. _createClass(CellMatrix, [{
  4723. key: "addCell",
  4724. value: function addCell(addressStr) {
  4725. this.addCellEx(colCache.decodeEx(addressStr));
  4726. }
  4727. }, {
  4728. key: "getCell",
  4729. value: function getCell(addressStr) {
  4730. return this.findCellEx(colCache.decodeEx(addressStr), true);
  4731. }
  4732. }, {
  4733. key: "findCell",
  4734. value: function findCell(addressStr) {
  4735. return this.findCellEx(colCache.decodeEx(addressStr), false);
  4736. }
  4737. }, {
  4738. key: "findCellAt",
  4739. value: function findCellAt(sheetName, rowNumber, colNumber) {
  4740. var sheet = this.sheets[sheetName];
  4741. var row = sheet && sheet[rowNumber];
  4742. return row && row[colNumber];
  4743. }
  4744. }, {
  4745. key: "addCellEx",
  4746. value: function addCellEx(address) {
  4747. if (address.top) {
  4748. for (var row = address.top; row <= address.bottom; row++) {
  4749. for (var col = address.left; col <= address.right; col++) {
  4750. this.getCellAt(address.sheetName, row, col);
  4751. }
  4752. }
  4753. } else {
  4754. this.findCellEx(address, true);
  4755. }
  4756. }
  4757. }, {
  4758. key: "getCellEx",
  4759. value: function getCellEx(address) {
  4760. return this.findCellEx(address, true);
  4761. }
  4762. }, {
  4763. key: "findCellEx",
  4764. value: function findCellEx(address, create) {
  4765. var sheet = this.findSheet(address, create);
  4766. var row = this.findSheetRow(sheet, address, create);
  4767. return this.findRowCell(row, address, create);
  4768. }
  4769. }, {
  4770. key: "getCellAt",
  4771. value: function getCellAt(sheetName, rowNumber, colNumber) {
  4772. var sheet = this.sheets[sheetName] || (this.sheets[sheetName] = []);
  4773. var row = sheet[rowNumber] || (sheet[rowNumber] = []);
  4774. var cell = row[colNumber] || (row[colNumber] = {
  4775. sheetName: sheetName,
  4776. address: colCache.n2l(colNumber) + rowNumber,
  4777. row: rowNumber,
  4778. col: colNumber
  4779. });
  4780. return cell;
  4781. }
  4782. }, {
  4783. key: "removeCellEx",
  4784. value: function removeCellEx(address) {
  4785. var sheet = this.findSheet(address);
  4786. if (!sheet) {
  4787. return;
  4788. }
  4789. var row = this.findSheetRow(sheet, address);
  4790. if (!row) {
  4791. return;
  4792. }
  4793. delete row[address.col];
  4794. }
  4795. }, {
  4796. key: "forEachInSheet",
  4797. value: function forEachInSheet(sheetName, callback) {
  4798. var sheet = this.sheets[sheetName];
  4799. if (sheet) {
  4800. sheet.forEach(function (row, rowNumber) {
  4801. if (row) {
  4802. row.forEach(function (cell, colNumber) {
  4803. if (cell) {
  4804. callback(cell, rowNumber, colNumber);
  4805. }
  4806. });
  4807. }
  4808. });
  4809. }
  4810. }
  4811. }, {
  4812. key: "forEach",
  4813. value: function forEach(callback) {
  4814. var _this = this;
  4815. _.each(this.sheets, function (sheet, sheetName) {
  4816. _this.forEachInSheet(sheetName, callback);
  4817. });
  4818. }
  4819. }, {
  4820. key: "map",
  4821. value: function map(callback) {
  4822. var results = [];
  4823. this.forEach(function (cell) {
  4824. results.push(callback(cell));
  4825. });
  4826. return results;
  4827. }
  4828. }, {
  4829. key: "findSheet",
  4830. value: function findSheet(address, create) {
  4831. var name = address.sheetName;
  4832. if (this.sheets[name]) {
  4833. return this.sheets[name];
  4834. }
  4835. if (create) {
  4836. return this.sheets[name] = [];
  4837. }
  4838. return undefined;
  4839. }
  4840. }, {
  4841. key: "findSheetRow",
  4842. value: function findSheetRow(sheet, address, create) {
  4843. var row = address.row;
  4844. if (sheet && sheet[row]) {
  4845. return sheet[row];
  4846. }
  4847. if (create) {
  4848. return sheet[row] = [];
  4849. }
  4850. return undefined;
  4851. }
  4852. }, {
  4853. key: "findRowCell",
  4854. value: function findRowCell(row, address, create) {
  4855. var col = address.col;
  4856. if (row && row[col]) {
  4857. return row[col];
  4858. }
  4859. if (create) {
  4860. return row[col] = this.template ? Object.assign(address, JSON.parse(JSON.stringify(this.template))) : address;
  4861. }
  4862. return undefined;
  4863. }
  4864. }, {
  4865. key: "spliceRows",
  4866. value: function spliceRows(sheetName, start, numDelete, numInsert) {
  4867. var sheet = this.sheets[sheetName];
  4868. if (sheet) {
  4869. var inserts = [];
  4870. for (var i = 0; i < numInsert; i++) {
  4871. inserts.push([]);
  4872. }
  4873. sheet.splice.apply(sheet, [start, numDelete].concat(inserts));
  4874. }
  4875. }
  4876. }, {
  4877. key: "spliceColumns",
  4878. value: function spliceColumns(sheetName, start, numDelete, numInsert) {
  4879. var sheet = this.sheets[sheetName];
  4880. if (sheet) {
  4881. var inserts = [];
  4882. for (var i = 0; i < numInsert; i++) {
  4883. inserts.push(null);
  4884. }
  4885. _.each(sheet, function (row) {
  4886. row.splice.apply(row, [start, numDelete].concat(inserts));
  4887. });
  4888. }
  4889. }
  4890. }]);
  4891. return CellMatrix;
  4892. }();
  4893. module.exports = CellMatrix;
  4894. },{"./col-cache":19,"./under-dash":25}],19:[function(require,module,exports){
  4895. "use strict";
  4896. function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
  4897. 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."); }
  4898. 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); }
  4899. 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; }
  4900. 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; }
  4901. function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  4902. 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; }
  4903. 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; }
  4904. 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; }
  4905. var addressRegex = /^[A-Z]+\d+$/; // =========================================================================
  4906. // Column Letter to Number conversion
  4907. var colCache = {
  4908. _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'],
  4909. _l2nFill: 0,
  4910. _l2n: {},
  4911. _n2l: [],
  4912. _level: function _level(n) {
  4913. if (n <= 26) {
  4914. return 1;
  4915. }
  4916. if (n <= 26 * 26) {
  4917. return 2;
  4918. }
  4919. return 3;
  4920. },
  4921. _fill: function _fill(level) {
  4922. var c;
  4923. var v;
  4924. var l1;
  4925. var l2;
  4926. var l3;
  4927. var n = 1;
  4928. if (level >= 4) {
  4929. throw new Error('Out of bounds. Excel supports columns from 1 to 16384');
  4930. }
  4931. if (this._l2nFill < 1 && level >= 1) {
  4932. while (n <= 26) {
  4933. c = this._dictionary[n - 1];
  4934. this._n2l[n] = c;
  4935. this._l2n[c] = n;
  4936. n++;
  4937. }
  4938. this._l2nFill = 1;
  4939. }
  4940. if (this._l2nFill < 2 && level >= 2) {
  4941. n = 27;
  4942. while (n <= 26 + 26 * 26) {
  4943. v = n - (26 + 1);
  4944. l1 = v % 26;
  4945. l2 = Math.floor(v / 26);
  4946. c = this._dictionary[l2] + this._dictionary[l1];
  4947. this._n2l[n] = c;
  4948. this._l2n[c] = n;
  4949. n++;
  4950. }
  4951. this._l2nFill = 2;
  4952. }
  4953. if (this._l2nFill < 3 && level >= 3) {
  4954. n = 26 + 26 * 26 + 1;
  4955. while (n <= 16384) {
  4956. v = n - (26 * 26 + 26 + 1);
  4957. l1 = v % 26;
  4958. l2 = Math.floor(v / 26) % 26;
  4959. l3 = Math.floor(v / (26 * 26));
  4960. c = this._dictionary[l3] + this._dictionary[l2] + this._dictionary[l1];
  4961. this._n2l[n] = c;
  4962. this._l2n[c] = n;
  4963. n++;
  4964. }
  4965. this._l2nFill = 3;
  4966. }
  4967. },
  4968. l2n: function l2n(l) {
  4969. if (!this._l2n[l]) {
  4970. this._fill(l.length);
  4971. }
  4972. if (!this._l2n[l]) {
  4973. throw new Error("Out of bounds. Invalid column letter: ".concat(l));
  4974. }
  4975. return this._l2n[l];
  4976. },
  4977. n2l: function n2l(n) {
  4978. if (n < 1 || n > 16384) {
  4979. throw new Error("".concat(n, " is out of bounds. Excel supports columns from 1 to 16384"));
  4980. }
  4981. if (!this._n2l[n]) {
  4982. this._fill(this._level(n));
  4983. }
  4984. return this._n2l[n];
  4985. },
  4986. // =========================================================================
  4987. // Address processing
  4988. _hash: {},
  4989. // check if value looks like an address
  4990. validateAddress: function validateAddress(value) {
  4991. if (!addressRegex.test(value)) {
  4992. throw new Error("Invalid Address: ".concat(value));
  4993. }
  4994. return true;
  4995. },
  4996. // convert address string into structure
  4997. decodeAddress: function decodeAddress(value) {
  4998. var addr = value.length < 5 && this._hash[value];
  4999. if (addr) {
  5000. return addr;
  5001. }
  5002. var hasCol = false;
  5003. var col = '';
  5004. var colNumber = 0;
  5005. var hasRow = false;
  5006. var row = '';
  5007. var rowNumber = 0;
  5008. for (var i = 0, char; i < value.length; i++) {
  5009. char = value.charCodeAt(i); // col should before row
  5010. if (!hasRow && char >= 65 && char <= 90) {
  5011. // 65 = 'A'.charCodeAt(0)
  5012. // 90 = 'Z'.charCodeAt(0)
  5013. hasCol = true;
  5014. col += value[i]; // colNumber starts from 1
  5015. colNumber = colNumber * 26 + char - 64;
  5016. } else if (char >= 48 && char <= 57) {
  5017. // 48 = '0'.charCodeAt(0)
  5018. // 57 = '9'.charCodeAt(0)
  5019. hasRow = true;
  5020. row += value[i]; // rowNumber starts from 0
  5021. rowNumber = rowNumber * 10 + char - 48;
  5022. } else if (hasRow && hasCol && char !== 36) {
  5023. // 36 = '$'.charCodeAt(0)
  5024. break;
  5025. }
  5026. }
  5027. if (!hasCol) {
  5028. colNumber = undefined;
  5029. } else if (colNumber > 16384) {
  5030. throw new Error("Out of bounds. Invalid column letter: ".concat(col));
  5031. }
  5032. if (!hasRow) {
  5033. rowNumber = undefined;
  5034. } // in case $row$col
  5035. value = col + row;
  5036. var address = {
  5037. address: value,
  5038. col: colNumber,
  5039. row: rowNumber,
  5040. $col$row: "$".concat(col, "$").concat(row)
  5041. }; // mem fix - cache only the tl 100x100 square
  5042. if (colNumber <= 100 && rowNumber <= 100) {
  5043. this._hash[value] = address;
  5044. this._hash[address.$col$row] = address;
  5045. }
  5046. return address;
  5047. },
  5048. // convert r,c into structure (if only 1 arg, assume r is address string)
  5049. getAddress: function getAddress(r, c) {
  5050. if (c) {
  5051. var address = this.n2l(c) + r;
  5052. return this.decodeAddress(address);
  5053. }
  5054. return this.decodeAddress(r);
  5055. },
  5056. // convert [address], [tl:br] into address structures
  5057. decode: function decode(value) {
  5058. var parts = value.split(':');
  5059. if (parts.length === 2) {
  5060. var tl = this.decodeAddress(parts[0]);
  5061. var br = this.decodeAddress(parts[1]);
  5062. var result = {
  5063. top: Math.min(tl.row, br.row),
  5064. left: Math.min(tl.col, br.col),
  5065. bottom: Math.max(tl.row, br.row),
  5066. right: Math.max(tl.col, br.col)
  5067. }; // reconstruct tl, br and dimensions
  5068. result.tl = this.n2l(result.left) + result.top;
  5069. result.br = this.n2l(result.right) + result.bottom;
  5070. result.dimensions = "".concat(result.tl, ":").concat(result.br);
  5071. return result;
  5072. }
  5073. return this.decodeAddress(value);
  5074. },
  5075. // convert [sheetName!][$]col[$]row[[$]col[$]row] into address or range structures
  5076. decodeEx: function decodeEx(value) {
  5077. var groups = value.match(/(?:(?:(?:'((?:[^']|'')*)')|([^'^ !]*))!)?(.*)/);
  5078. var sheetName = groups[1] || groups[2]; // Qouted and unqouted groups
  5079. var reference = groups[3]; // Remaining address
  5080. var parts = reference.split(':');
  5081. if (parts.length > 1) {
  5082. var tl = this.decodeAddress(parts[0]);
  5083. var br = this.decodeAddress(parts[1]);
  5084. var top = Math.min(tl.row, br.row);
  5085. var left = Math.min(tl.col, br.col);
  5086. var bottom = Math.max(tl.row, br.row);
  5087. var right = Math.max(tl.col, br.col);
  5088. tl = this.n2l(left) + top;
  5089. br = this.n2l(right) + bottom;
  5090. return {
  5091. top: top,
  5092. left: left,
  5093. bottom: bottom,
  5094. right: right,
  5095. sheetName: sheetName,
  5096. tl: {
  5097. address: tl,
  5098. col: left,
  5099. row: top,
  5100. $col$row: "$".concat(this.n2l(left), "$").concat(top),
  5101. sheetName: sheetName
  5102. },
  5103. br: {
  5104. address: br,
  5105. col: right,
  5106. row: bottom,
  5107. $col$row: "$".concat(this.n2l(right), "$").concat(bottom),
  5108. sheetName: sheetName
  5109. },
  5110. dimensions: "".concat(tl, ":").concat(br)
  5111. };
  5112. }
  5113. if (reference.startsWith('#')) {
  5114. return sheetName ? {
  5115. sheetName: sheetName,
  5116. error: reference
  5117. } : {
  5118. error: reference
  5119. };
  5120. }
  5121. var address = this.decodeAddress(reference);
  5122. return sheetName ? _objectSpread({
  5123. sheetName: sheetName
  5124. }, address) : address;
  5125. },
  5126. // convert row,col into address string
  5127. encodeAddress: function encodeAddress(row, col) {
  5128. return colCache.n2l(col) + row;
  5129. },
  5130. // convert row,col into string address or t,l,b,r into range
  5131. encode: function encode() {
  5132. switch (arguments.length) {
  5133. case 2:
  5134. return colCache.encodeAddress(arguments[0], arguments[1]);
  5135. case 4:
  5136. return "".concat(colCache.encodeAddress(arguments[0], arguments[1]), ":").concat(colCache.encodeAddress(arguments[2], arguments[3]));
  5137. default:
  5138. throw new Error('Can only encode with 2 or 4 arguments');
  5139. }
  5140. },
  5141. // return true if address is contained within range
  5142. inRange: function inRange(range, address) {
  5143. var _range = _slicedToArray(range, 5),
  5144. left = _range[0],
  5145. top = _range[1],
  5146. right = _range[3],
  5147. bottom = _range[4];
  5148. var _address = _slicedToArray(address, 2),
  5149. col = _address[0],
  5150. row = _address[1];
  5151. return col >= left && col <= right && row >= top && row <= bottom;
  5152. }
  5153. };
  5154. module.exports = colCache;
  5155. },{}],20:[function(require,module,exports){
  5156. (function (Buffer){
  5157. 'use strict';
  5158. var crypto = require('crypto');
  5159. var Encryptor = {
  5160. /**
  5161. * Calculate a hash of the concatenated buffers with the given algorithm.
  5162. * @param {string} algorithm - The hash algorithm.
  5163. * @returns {Buffer} The hash
  5164. */
  5165. hash: function hash(algorithm) {
  5166. var hash = crypto.createHash(algorithm);
  5167. for (var _len = arguments.length, buffers = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  5168. buffers[_key - 1] = arguments[_key];
  5169. }
  5170. hash.update(Buffer.concat(buffers));
  5171. return hash.digest();
  5172. },
  5173. /**
  5174. * Convert a password into an encryption key
  5175. * @param {string} password - The password
  5176. * @param {string} hashAlgorithm - The hash algoritm
  5177. * @param {string} saltValue - The salt value
  5178. * @param {number} spinCount - The spin count
  5179. * @param {number} keyBits - The length of the key in bits
  5180. * @param {Buffer} blockKey - The block key
  5181. * @returns {Buffer} The encryption key
  5182. */
  5183. convertPasswordToHash: function convertPasswordToHash(password, hashAlgorithm, saltValue, spinCount) {
  5184. hashAlgorithm = hashAlgorithm.toLowerCase();
  5185. var hashes = crypto.getHashes();
  5186. if (hashes.indexOf(hashAlgorithm) < 0) {
  5187. throw new Error("Hash algorithm '".concat(hashAlgorithm, "' not supported!"));
  5188. } // Password must be in unicode buffer
  5189. var passwordBuffer = Buffer.from(password, 'utf16le'); // Generate the initial hash
  5190. var key = this.hash(hashAlgorithm, Buffer.from(saltValue, 'base64'), passwordBuffer); // Now regenerate until spin count
  5191. for (var i = 0; i < spinCount; i++) {
  5192. var iterator = Buffer.alloc(4); // this is the 'special' element of Excel password hashing
  5193. // that stops us from using crypto.pbkdf2()
  5194. iterator.writeUInt32LE(i, 0);
  5195. key = this.hash(hashAlgorithm, key, iterator);
  5196. }
  5197. return key.toString('base64');
  5198. },
  5199. /**
  5200. * Generates cryptographically strong pseudo-random data.
  5201. * @param size The size argument is a number indicating the number of bytes to generate.
  5202. */
  5203. randomBytes: function randomBytes(size) {
  5204. return crypto.randomBytes(size);
  5205. }
  5206. };
  5207. module.exports = Encryptor;
  5208. }).call(this,require("buffer").Buffer)
  5209. },{"buffer":216,"crypto":226}],21:[function(require,module,exports){
  5210. "use strict";
  5211. function _awaitAsyncGenerator(value) { return new _AwaitValue(value); }
  5212. function _wrapAsyncGenerator(fn) { return function () { return new _AsyncGenerator(fn.apply(this, arguments)); }; }
  5213. 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; } }
  5214. if (typeof Symbol === "function" && Symbol.asyncIterator) { _AsyncGenerator.prototype[Symbol.asyncIterator] = function () { return this; }; }
  5215. _AsyncGenerator.prototype.next = function (arg) { return this._invoke("next", arg); };
  5216. _AsyncGenerator.prototype.throw = function (arg) { return this._invoke("throw", arg); };
  5217. _AsyncGenerator.prototype.return = function (arg) { return this._invoke("return", arg); };
  5218. function _AwaitValue(value) { this.wrapped = value; }
  5219. 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"); }
  5220. var _require = require('saxes'),
  5221. SaxesParser = _require.SaxesParser;
  5222. var _require2 = require('readable-stream'),
  5223. PassThrough = _require2.PassThrough;
  5224. var _require3 = require('./browser-buffer-decode'),
  5225. bufferToString = _require3.bufferToString;
  5226. module.exports = /*#__PURE__*/function () {
  5227. var _ref = _wrapAsyncGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(iterable) {
  5228. var saxesParser, error, events, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk;
  5229. return regeneratorRuntime.wrap(function _callee$(_context) {
  5230. while (1) {
  5231. switch (_context.prev = _context.next) {
  5232. case 0:
  5233. // TODO: Remove once node v8 is deprecated
  5234. // Detect and upgrade old streams
  5235. if (iterable.pipe && !iterable[Symbol.asyncIterator]) {
  5236. iterable = iterable.pipe(new PassThrough());
  5237. }
  5238. saxesParser = new SaxesParser();
  5239. saxesParser.on('error', function (err) {
  5240. error = err;
  5241. });
  5242. events = [];
  5243. saxesParser.on('opentag', function (value) {
  5244. return events.push({
  5245. eventType: 'opentag',
  5246. value: value
  5247. });
  5248. });
  5249. saxesParser.on('text', function (value) {
  5250. return events.push({
  5251. eventType: 'text',
  5252. value: value
  5253. });
  5254. });
  5255. saxesParser.on('closetag', function (value) {
  5256. return events.push({
  5257. eventType: 'closetag',
  5258. value: value
  5259. });
  5260. });
  5261. _iteratorNormalCompletion = true;
  5262. _didIteratorError = false;
  5263. _context.prev = 9;
  5264. _iterator = _asyncIterator(iterable);
  5265. case 11:
  5266. _context.next = 13;
  5267. return _awaitAsyncGenerator(_iterator.next());
  5268. case 13:
  5269. _step = _context.sent;
  5270. _iteratorNormalCompletion = _step.done;
  5271. _context.next = 17;
  5272. return _awaitAsyncGenerator(_step.value);
  5273. case 17:
  5274. _value = _context.sent;
  5275. if (_iteratorNormalCompletion) {
  5276. _context.next = 29;
  5277. break;
  5278. }
  5279. chunk = _value;
  5280. saxesParser.write(bufferToString(chunk)); // saxesParser.write and saxesParser.on() are synchronous,
  5281. // so we can only reach the below line once all events have been emitted
  5282. if (!error) {
  5283. _context.next = 23;
  5284. break;
  5285. }
  5286. throw error;
  5287. case 23:
  5288. _context.next = 25;
  5289. return events;
  5290. case 25:
  5291. events = [];
  5292. case 26:
  5293. _iteratorNormalCompletion = true;
  5294. _context.next = 11;
  5295. break;
  5296. case 29:
  5297. _context.next = 35;
  5298. break;
  5299. case 31:
  5300. _context.prev = 31;
  5301. _context.t0 = _context["catch"](9);
  5302. _didIteratorError = true;
  5303. _iteratorError = _context.t0;
  5304. case 35:
  5305. _context.prev = 35;
  5306. _context.prev = 36;
  5307. if (!(!_iteratorNormalCompletion && _iterator.return != null)) {
  5308. _context.next = 40;
  5309. break;
  5310. }
  5311. _context.next = 40;
  5312. return _awaitAsyncGenerator(_iterator.return());
  5313. case 40:
  5314. _context.prev = 40;
  5315. if (!_didIteratorError) {
  5316. _context.next = 43;
  5317. break;
  5318. }
  5319. throw _iteratorError;
  5320. case 43:
  5321. return _context.finish(40);
  5322. case 44:
  5323. return _context.finish(35);
  5324. case 45:
  5325. case "end":
  5326. return _context.stop();
  5327. }
  5328. }
  5329. }, _callee, null, [[9, 31, 35, 45], [36,, 40, 44]]);
  5330. }));
  5331. return function (_x) {
  5332. return _ref.apply(this, arguments);
  5333. };
  5334. }();
  5335. },{"./browser-buffer-decode":16,"readable-stream":382,"saxes":386}],22:[function(require,module,exports){
  5336. "use strict";
  5337. var colCache = require('./col-cache'); // const cellRefRegex = /(([a-z_\-0-9]*)!)?[$]?([a-z]+)[$]?([1-9][0-9]*)/i;
  5338. var replacementCandidateRx = /(([a-z_\-0-9]*)!)?([a-z0-9_$]{2,})([(])?/gi;
  5339. var CRrx = /^([$])?([a-z]+)([$])?([1-9][0-9]*)$/i;
  5340. function slideFormula(formula, fromCell, toCell) {
  5341. var offset = colCache.decode(fromCell);
  5342. var to = colCache.decode(toCell);
  5343. return formula.replace(replacementCandidateRx, function (refMatch, sheet, sheetMaybe, addrPart, trailingParen) {
  5344. if (trailingParen) {
  5345. return refMatch;
  5346. }
  5347. var match = CRrx.exec(addrPart);
  5348. if (match) {
  5349. var colDollar = match[1];
  5350. var colStr = match[2].toUpperCase();
  5351. var rowDollar = match[3];
  5352. var rowStr = match[4];
  5353. if (colStr.length > 3 || colStr.length === 3 && colStr > 'XFD') {
  5354. // > XFD is the highest col number in excel 2007 and beyond, so this is a named range
  5355. return refMatch;
  5356. }
  5357. var col = colCache.l2n(colStr);
  5358. var row = parseInt(rowStr, 10);
  5359. if (!colDollar) {
  5360. col += to.col - offset.col;
  5361. }
  5362. if (!rowDollar) {
  5363. row += to.row - offset.row;
  5364. }
  5365. var res = (sheet || '') + (colDollar || '') + colCache.n2l(col) + (rowDollar || '') + row;
  5366. return res;
  5367. }
  5368. return refMatch;
  5369. });
  5370. }
  5371. module.exports = {
  5372. slideFormula: slideFormula
  5373. };
  5374. },{"./col-cache":19}],23:[function(require,module,exports){
  5375. (function (process,Buffer){
  5376. "use strict";
  5377. 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); } }
  5378. 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); }); }; }
  5379. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5380. 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); } }
  5381. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  5382. /* eslint-disable max-classes-per-file */
  5383. var Stream = require('readable-stream');
  5384. var utils = require('./utils');
  5385. var StringBuf = require('./string-buf'); // =============================================================================
  5386. // data chunks - encapsulating incoming data
  5387. var StringChunk = /*#__PURE__*/function () {
  5388. function StringChunk(data, encoding) {
  5389. _classCallCheck(this, StringChunk);
  5390. this._data = data;
  5391. this._encoding = encoding;
  5392. }
  5393. _createClass(StringChunk, [{
  5394. key: "copy",
  5395. // copy to target buffer
  5396. value: function copy(target, targetOffset, offset, length) {
  5397. return this.toBuffer().copy(target, targetOffset, offset, length);
  5398. }
  5399. }, {
  5400. key: "toBuffer",
  5401. value: function toBuffer() {
  5402. if (!this._buffer) {
  5403. this._buffer = Buffer.from(this._data, this._encoding);
  5404. }
  5405. return this._buffer;
  5406. }
  5407. }, {
  5408. key: "length",
  5409. get: function get() {
  5410. return this.toBuffer().length;
  5411. }
  5412. }]);
  5413. return StringChunk;
  5414. }();
  5415. var StringBufChunk = /*#__PURE__*/function () {
  5416. function StringBufChunk(data) {
  5417. _classCallCheck(this, StringBufChunk);
  5418. this._data = data;
  5419. }
  5420. _createClass(StringBufChunk, [{
  5421. key: "copy",
  5422. // copy to target buffer
  5423. value: function copy(target, targetOffset, offset, length) {
  5424. // eslint-disable-next-line no-underscore-dangle
  5425. return this._data._buf.copy(target, targetOffset, offset, length);
  5426. }
  5427. }, {
  5428. key: "toBuffer",
  5429. value: function toBuffer() {
  5430. return this._data.toBuffer();
  5431. }
  5432. }, {
  5433. key: "length",
  5434. get: function get() {
  5435. return this._data.length;
  5436. }
  5437. }]);
  5438. return StringBufChunk;
  5439. }();
  5440. var BufferChunk = /*#__PURE__*/function () {
  5441. function BufferChunk(data) {
  5442. _classCallCheck(this, BufferChunk);
  5443. this._data = data;
  5444. }
  5445. _createClass(BufferChunk, [{
  5446. key: "copy",
  5447. // copy to target buffer
  5448. value: function copy(target, targetOffset, offset, length) {
  5449. this._data.copy(target, targetOffset, offset, length);
  5450. }
  5451. }, {
  5452. key: "toBuffer",
  5453. value: function toBuffer() {
  5454. return this._data;
  5455. }
  5456. }, {
  5457. key: "length",
  5458. get: function get() {
  5459. return this._data.length;
  5460. }
  5461. }]);
  5462. return BufferChunk;
  5463. }(); // =============================================================================
  5464. // ReadWriteBuf - a single buffer supporting simple read-write
  5465. var ReadWriteBuf = /*#__PURE__*/function () {
  5466. function ReadWriteBuf(size) {
  5467. _classCallCheck(this, ReadWriteBuf);
  5468. this.size = size; // the buffer
  5469. this.buffer = Buffer.alloc(size); // read index
  5470. this.iRead = 0; // write index
  5471. this.iWrite = 0;
  5472. }
  5473. _createClass(ReadWriteBuf, [{
  5474. key: "toBuffer",
  5475. value: function toBuffer() {
  5476. if (this.iRead === 0 && this.iWrite === this.size) {
  5477. return this.buffer;
  5478. }
  5479. var buf = Buffer.alloc(this.iWrite - this.iRead);
  5480. this.buffer.copy(buf, 0, this.iRead, this.iWrite);
  5481. return buf;
  5482. }
  5483. }, {
  5484. key: "read",
  5485. value: function read(size) {
  5486. var buf; // read size bytes from buffer and return buffer
  5487. if (size === 0) {
  5488. // special case - return null if no data requested
  5489. return null;
  5490. }
  5491. if (size === undefined || size >= this.length) {
  5492. // if no size specified or size is at least what we have then return all of the bytes
  5493. buf = this.toBuffer();
  5494. this.iRead = this.iWrite;
  5495. return buf;
  5496. } // otherwise return a chunk
  5497. buf = Buffer.alloc(size);
  5498. this.buffer.copy(buf, 0, this.iRead, size);
  5499. this.iRead += size;
  5500. return buf;
  5501. }
  5502. }, {
  5503. key: "write",
  5504. value: function write(chunk, offset, length) {
  5505. // write as many bytes from data from optional source offset
  5506. // and return number of bytes written
  5507. var size = Math.min(length, this.size - this.iWrite);
  5508. chunk.copy(this.buffer, this.iWrite, offset, offset + size);
  5509. this.iWrite += size;
  5510. return size;
  5511. }
  5512. }, {
  5513. key: "length",
  5514. get: function get() {
  5515. return this.iWrite - this.iRead;
  5516. }
  5517. }, {
  5518. key: "eod",
  5519. get: function get() {
  5520. return this.iRead === this.iWrite;
  5521. }
  5522. }, {
  5523. key: "full",
  5524. get: function get() {
  5525. return this.iWrite === this.size;
  5526. }
  5527. }]);
  5528. return ReadWriteBuf;
  5529. }(); // =============================================================================
  5530. // StreamBuf - a multi-purpose read-write stream
  5531. // As MemBuf - write as much data as you like. Then call toBuffer() to consolidate
  5532. // As StreamHub - pipe to multiple writables
  5533. // As readable stream - feed data into the writable part and have some other code read from it.
  5534. // Note: Not sure why but StreamBuf does not like JS "class" sugar. It fails the
  5535. // integration tests
  5536. var StreamBuf = function StreamBuf(options) {
  5537. options = options || {};
  5538. this.bufSize = options.bufSize || 1024 * 1024;
  5539. this.buffers = []; // batch mode fills a buffer completely before passing the data on
  5540. // to pipes or 'readable' event listeners
  5541. this.batch = options.batch || false;
  5542. this.corked = false; // where in the current writable buffer we're up to
  5543. this.inPos = 0; // where in the current readable buffer we've read up to
  5544. this.outPos = 0; // consuming pipe streams go here
  5545. this.pipes = []; // controls emit('data')
  5546. this.paused = false;
  5547. this.encoding = null;
  5548. };
  5549. utils.inherits(StreamBuf, Stream.Duplex, {
  5550. toBuffer: function toBuffer() {
  5551. switch (this.buffers.length) {
  5552. case 0:
  5553. return null;
  5554. case 1:
  5555. return this.buffers[0].toBuffer();
  5556. default:
  5557. return Buffer.concat(this.buffers.map(function (rwBuf) {
  5558. return rwBuf.toBuffer();
  5559. }));
  5560. }
  5561. },
  5562. // writable
  5563. // event drain - if write returns false (which it won't), indicates when safe to write again.
  5564. // finish - end() has been called
  5565. // pipe(src) - pipe() has been called on readable
  5566. // unpipe(src) - unpipe() has been called on readable
  5567. // error - duh
  5568. _getWritableBuffer: function _getWritableBuffer() {
  5569. if (this.buffers.length) {
  5570. var last = this.buffers[this.buffers.length - 1];
  5571. if (!last.full) {
  5572. return last;
  5573. }
  5574. }
  5575. var buf = new ReadWriteBuf(this.bufSize);
  5576. this.buffers.push(buf);
  5577. return buf;
  5578. },
  5579. _pipe: function _pipe(chunk) {
  5580. var _this = this;
  5581. return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
  5582. var write;
  5583. return regeneratorRuntime.wrap(function _callee$(_context) {
  5584. while (1) {
  5585. switch (_context.prev = _context.next) {
  5586. case 0:
  5587. write = function write(pipe) {
  5588. return new Promise(function (resolve) {
  5589. pipe.write(chunk.toBuffer(), function () {
  5590. resolve();
  5591. });
  5592. });
  5593. };
  5594. _context.next = 3;
  5595. return Promise.all(_this.pipes.map(write));
  5596. case 3:
  5597. case "end":
  5598. return _context.stop();
  5599. }
  5600. }
  5601. }, _callee);
  5602. }))();
  5603. },
  5604. _writeToBuffers: function _writeToBuffers(chunk) {
  5605. var inPos = 0;
  5606. var inLen = chunk.length;
  5607. while (inPos < inLen) {
  5608. // find writable buffer
  5609. var buffer = this._getWritableBuffer(); // write some data
  5610. inPos += buffer.write(chunk, inPos, inLen - inPos);
  5611. }
  5612. },
  5613. write: function write(data, encoding, callback) {
  5614. var _this2 = this;
  5615. return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
  5616. var chunk;
  5617. return regeneratorRuntime.wrap(function _callee2$(_context2) {
  5618. while (1) {
  5619. switch (_context2.prev = _context2.next) {
  5620. case 0:
  5621. if (encoding instanceof Function) {
  5622. callback = encoding;
  5623. encoding = 'utf8';
  5624. }
  5625. callback = callback || utils.nop; // encapsulate data into a chunk
  5626. if (!(data instanceof StringBuf)) {
  5627. _context2.next = 6;
  5628. break;
  5629. }
  5630. chunk = new StringBufChunk(data);
  5631. _context2.next = 15;
  5632. break;
  5633. case 6:
  5634. if (!(data instanceof Buffer)) {
  5635. _context2.next = 10;
  5636. break;
  5637. }
  5638. chunk = new BufferChunk(data);
  5639. _context2.next = 15;
  5640. break;
  5641. case 10:
  5642. if (!(typeof data === 'string' || data instanceof String || data instanceof ArrayBuffer)) {
  5643. _context2.next = 14;
  5644. break;
  5645. }
  5646. chunk = new StringChunk(data, encoding);
  5647. _context2.next = 15;
  5648. break;
  5649. case 14:
  5650. throw new Error('Chunk must be one of type String, Buffer or StringBuf.');
  5651. case 15:
  5652. if (!_this2.pipes.length) {
  5653. _context2.next = 31;
  5654. break;
  5655. }
  5656. if (!_this2.batch) {
  5657. _context2.next = 21;
  5658. break;
  5659. }
  5660. _this2._writeToBuffers(chunk);
  5661. while (!_this2.corked && _this2.buffers.length > 1) {
  5662. _this2._pipe(_this2.buffers.shift());
  5663. }
  5664. _context2.next = 29;
  5665. break;
  5666. case 21:
  5667. if (_this2.corked) {
  5668. _context2.next = 27;
  5669. break;
  5670. }
  5671. _context2.next = 24;
  5672. return _this2._pipe(chunk);
  5673. case 24:
  5674. callback();
  5675. _context2.next = 29;
  5676. break;
  5677. case 27:
  5678. _this2._writeToBuffers(chunk);
  5679. process.nextTick(callback);
  5680. case 29:
  5681. _context2.next = 34;
  5682. break;
  5683. case 31:
  5684. if (!_this2.paused) {
  5685. _this2.emit('data', chunk.toBuffer());
  5686. }
  5687. _this2._writeToBuffers(chunk);
  5688. _this2.emit('readable');
  5689. case 34:
  5690. return _context2.abrupt("return", true);
  5691. case 35:
  5692. case "end":
  5693. return _context2.stop();
  5694. }
  5695. }
  5696. }, _callee2);
  5697. }))();
  5698. },
  5699. cork: function cork() {
  5700. this.corked = true;
  5701. },
  5702. _flush: function _flush()
  5703. /* destination */
  5704. {
  5705. // if we have comsumers...
  5706. if (this.pipes.length) {
  5707. // and there's stuff not written
  5708. while (this.buffers.length) {
  5709. this._pipe(this.buffers.shift());
  5710. }
  5711. }
  5712. },
  5713. uncork: function uncork() {
  5714. this.corked = false;
  5715. this._flush();
  5716. },
  5717. end: function end(chunk, encoding, callback) {
  5718. var _this3 = this;
  5719. var writeComplete = function writeComplete(error) {
  5720. if (error) {
  5721. callback(error);
  5722. } else {
  5723. _this3._flush();
  5724. _this3.pipes.forEach(function (pipe) {
  5725. pipe.end();
  5726. });
  5727. _this3.emit('finish');
  5728. }
  5729. };
  5730. if (chunk) {
  5731. this.write(chunk, encoding, writeComplete);
  5732. } else {
  5733. writeComplete();
  5734. }
  5735. },
  5736. // readable
  5737. // event readable - some data is now available
  5738. // event data - switch to flowing mode - feeds chunks to handler
  5739. // event end - no more data
  5740. // event close - optional, indicates upstream close
  5741. // event error - duh
  5742. read: function read(size) {
  5743. var buffers; // read min(buffer, size || infinity)
  5744. if (size) {
  5745. buffers = [];
  5746. while (size && this.buffers.length && !this.buffers[0].eod) {
  5747. var first = this.buffers[0];
  5748. var buffer = first.read(size);
  5749. size -= buffer.length;
  5750. buffers.push(buffer);
  5751. if (first.eod && first.full) {
  5752. this.buffers.shift();
  5753. }
  5754. }
  5755. return Buffer.concat(buffers);
  5756. }
  5757. buffers = this.buffers.map(function (buf) {
  5758. return buf.toBuffer();
  5759. }).filter(Boolean);
  5760. this.buffers = [];
  5761. return Buffer.concat(buffers);
  5762. },
  5763. setEncoding: function setEncoding(encoding) {
  5764. // causes stream.read or stream.on('data) to return strings of encoding instead of Buffer objects
  5765. this.encoding = encoding;
  5766. },
  5767. pause: function pause() {
  5768. this.paused = true;
  5769. },
  5770. resume: function resume() {
  5771. this.paused = false;
  5772. },
  5773. isPaused: function isPaused() {
  5774. return !!this.paused;
  5775. },
  5776. pipe: function pipe(destination) {
  5777. // add destination to pipe list & write current buffer
  5778. this.pipes.push(destination);
  5779. if (!this.paused && this.buffers.length) {
  5780. this.end();
  5781. }
  5782. },
  5783. unpipe: function unpipe(destination) {
  5784. // remove destination from pipe list
  5785. this.pipes = this.pipes.filter(function (pipe) {
  5786. return pipe !== destination;
  5787. });
  5788. },
  5789. unshift: function unshift()
  5790. /* chunk */
  5791. {
  5792. // some numpty has read some data that's not for them and they want to put it back!
  5793. // Might implement this some day
  5794. throw new Error('Not Implemented');
  5795. },
  5796. wrap: function wrap()
  5797. /* stream */
  5798. {
  5799. // not implemented
  5800. throw new Error('Not Implemented');
  5801. }
  5802. });
  5803. module.exports = StreamBuf;
  5804. }).call(this,require('_process'),require("buffer").Buffer)
  5805. },{"./string-buf":24,"./utils":26,"_process":358,"buffer":216,"readable-stream":382}],24:[function(require,module,exports){
  5806. (function (Buffer){
  5807. "use strict";
  5808. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5809. 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); } }
  5810. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  5811. // StringBuf - a way to keep string memory operations to a minimum
  5812. // while building the strings for the xml files
  5813. var StringBuf = /*#__PURE__*/function () {
  5814. function StringBuf(options) {
  5815. _classCallCheck(this, StringBuf);
  5816. this._buf = Buffer.alloc(options && options.size || 16384);
  5817. this._encoding = options && options.encoding || 'utf8'; // where in the buffer we are at
  5818. this._inPos = 0; // for use by toBuffer()
  5819. this._buffer = undefined;
  5820. }
  5821. _createClass(StringBuf, [{
  5822. key: "toBuffer",
  5823. value: function toBuffer() {
  5824. // return the current data as a single enclosing buffer
  5825. if (!this._buffer) {
  5826. this._buffer = Buffer.alloc(this.length);
  5827. this._buf.copy(this._buffer, 0, 0, this.length);
  5828. }
  5829. return this._buffer;
  5830. }
  5831. }, {
  5832. key: "reset",
  5833. value: function reset(position) {
  5834. position = position || 0;
  5835. this._buffer = undefined;
  5836. this._inPos = position;
  5837. }
  5838. }, {
  5839. key: "_grow",
  5840. value: function _grow(min) {
  5841. var size = this._buf.length * 2;
  5842. while (size < min) {
  5843. size *= 2;
  5844. }
  5845. var buf = Buffer.alloc(size);
  5846. this._buf.copy(buf, 0);
  5847. this._buf = buf;
  5848. }
  5849. }, {
  5850. key: "addText",
  5851. value: function addText(text) {
  5852. this._buffer = undefined;
  5853. var inPos = this._inPos + this._buf.write(text, this._inPos, this._encoding); // if we've hit (or nearing capacity), grow the buf
  5854. while (inPos >= this._buf.length - 4) {
  5855. this._grow(this._inPos + text.length); // keep trying to write until we've completely written the text
  5856. inPos = this._inPos + this._buf.write(text, this._inPos, this._encoding);
  5857. }
  5858. this._inPos = inPos;
  5859. }
  5860. }, {
  5861. key: "addStringBuf",
  5862. value: function addStringBuf(inBuf) {
  5863. if (inBuf.length) {
  5864. this._buffer = undefined;
  5865. if (this.length + inBuf.length > this.capacity) {
  5866. this._grow(this.length + inBuf.length);
  5867. } // eslint-disable-next-line no-underscore-dangle
  5868. inBuf._buf.copy(this._buf, this._inPos, 0, inBuf.length);
  5869. this._inPos += inBuf.length;
  5870. }
  5871. }
  5872. }, {
  5873. key: "length",
  5874. get: function get() {
  5875. return this._inPos;
  5876. }
  5877. }, {
  5878. key: "capacity",
  5879. get: function get() {
  5880. return this._buf.length;
  5881. }
  5882. }, {
  5883. key: "buffer",
  5884. get: function get() {
  5885. return this._buf;
  5886. }
  5887. }]);
  5888. return StringBuf;
  5889. }();
  5890. module.exports = StringBuf;
  5891. }).call(this,require("buffer").Buffer)
  5892. },{"buffer":216}],25:[function(require,module,exports){
  5893. "use strict";
  5894. 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); }
  5895. var toString = Object.prototype.toString;
  5896. var escapeHtmlRegex = /["&<>]/;
  5897. var _ = {
  5898. each: function each(obj, cb) {
  5899. if (obj) {
  5900. if (Array.isArray(obj)) {
  5901. obj.forEach(cb);
  5902. } else {
  5903. Object.keys(obj).forEach(function (key) {
  5904. cb(obj[key], key);
  5905. });
  5906. }
  5907. }
  5908. },
  5909. some: function some(obj, cb) {
  5910. if (obj) {
  5911. if (Array.isArray(obj)) {
  5912. return obj.some(cb);
  5913. }
  5914. return Object.keys(obj).some(function (key) {
  5915. return cb(obj[key], key);
  5916. });
  5917. }
  5918. return false;
  5919. },
  5920. every: function every(obj, cb) {
  5921. if (obj) {
  5922. if (Array.isArray(obj)) {
  5923. return obj.every(cb);
  5924. }
  5925. return Object.keys(obj).every(function (key) {
  5926. return cb(obj[key], key);
  5927. });
  5928. }
  5929. return true;
  5930. },
  5931. map: function map(obj, cb) {
  5932. if (obj) {
  5933. if (Array.isArray(obj)) {
  5934. return obj.map(cb);
  5935. }
  5936. return Object.keys(obj).map(function (key) {
  5937. return cb(obj[key], key);
  5938. });
  5939. }
  5940. return [];
  5941. },
  5942. keyBy: function keyBy(a, p) {
  5943. return a.reduce(function (o, v) {
  5944. o[v[p]] = v;
  5945. return o;
  5946. }, {});
  5947. },
  5948. isEqual: function isEqual(a, b) {
  5949. var aType = _typeof(a);
  5950. var bType = _typeof(b);
  5951. var aArray = Array.isArray(a);
  5952. var bArray = Array.isArray(b);
  5953. if (aType !== bType) {
  5954. return false;
  5955. }
  5956. switch (_typeof(a)) {
  5957. case 'object':
  5958. if (aArray || bArray) {
  5959. if (aArray && bArray) {
  5960. return a.length === b.length && a.every(function (aValue, index) {
  5961. var bValue = b[index];
  5962. return _.isEqual(aValue, bValue);
  5963. });
  5964. }
  5965. return false;
  5966. }
  5967. return _.every(a, function (aValue, key) {
  5968. var bValue = b[key];
  5969. return _.isEqual(aValue, bValue);
  5970. });
  5971. default:
  5972. return a === b;
  5973. }
  5974. },
  5975. escapeHtml: function escapeHtml(html) {
  5976. var regexResult = escapeHtmlRegex.exec(html);
  5977. if (!regexResult) return html;
  5978. var result = '';
  5979. var escape = '';
  5980. var lastIndex = 0;
  5981. var i = regexResult.index;
  5982. for (; i < html.length; i++) {
  5983. switch (html.charAt(i)) {
  5984. case '"':
  5985. escape = '&quot;';
  5986. break;
  5987. case '&':
  5988. escape = '&amp;';
  5989. break;
  5990. case '\'':
  5991. escape = '&apos;';
  5992. break;
  5993. case '<':
  5994. escape = '&lt;';
  5995. break;
  5996. case '>':
  5997. escape = '&gt;';
  5998. break;
  5999. default:
  6000. continue;
  6001. }
  6002. if (lastIndex !== i) result += html.substring(lastIndex, i);
  6003. lastIndex = i + 1;
  6004. result += escape;
  6005. }
  6006. if (lastIndex !== i) return result + html.substring(lastIndex, i);
  6007. return result;
  6008. },
  6009. strcmp: function strcmp(a, b) {
  6010. if (a < b) return -1;
  6011. if (a > b) return 1;
  6012. return 0;
  6013. },
  6014. isUndefined: function isUndefined(val) {
  6015. return toString.call(val) === '[object Undefined]';
  6016. },
  6017. isObject: function isObject(val) {
  6018. return toString.call(val) === '[object Object]';
  6019. },
  6020. deepMerge: function deepMerge() {
  6021. var target = arguments[0] || {};
  6022. var length = arguments.length; // eslint-disable-next-line one-var
  6023. var src, clone, copyIsArray;
  6024. function assignValue(val, key) {
  6025. src = target[key];
  6026. copyIsArray = Array.isArray(val);
  6027. if (_.isObject(val) || copyIsArray) {
  6028. if (copyIsArray) {
  6029. copyIsArray = false;
  6030. clone = src && Array.isArray(src) ? src : [];
  6031. } else {
  6032. clone = src && _.isObject(src) ? src : {};
  6033. }
  6034. target[key] = _.deepMerge(clone, val);
  6035. } else if (!_.isUndefined(val)) {
  6036. target[key] = val;
  6037. }
  6038. }
  6039. for (var i = 0; i < length; i++) {
  6040. _.each(arguments[i], assignValue);
  6041. }
  6042. return target;
  6043. }
  6044. };
  6045. module.exports = _;
  6046. },{}],26:[function(require,module,exports){
  6047. (function (global,setImmediate){
  6048. "use strict";
  6049. var fs = require('fs'); // useful stuff
  6050. var inherits = function inherits(cls, superCtor, statics, prototype) {
  6051. // eslint-disable-next-line no-underscore-dangle
  6052. cls.super_ = superCtor;
  6053. if (!prototype) {
  6054. prototype = statics;
  6055. statics = null;
  6056. }
  6057. if (statics) {
  6058. Object.keys(statics).forEach(function (i) {
  6059. Object.defineProperty(cls, i, Object.getOwnPropertyDescriptor(statics, i));
  6060. });
  6061. }
  6062. var properties = {
  6063. constructor: {
  6064. value: cls,
  6065. enumerable: false,
  6066. writable: false,
  6067. configurable: true
  6068. }
  6069. };
  6070. if (prototype) {
  6071. Object.keys(prototype).forEach(function (i) {
  6072. properties[i] = Object.getOwnPropertyDescriptor(prototype, i);
  6073. });
  6074. }
  6075. cls.prototype = Object.create(superCtor.prototype, properties);
  6076. }; // eslint-disable-next-line no-control-regex
  6077. var xmlDecodeRegex = /[<>&'"\x7F\x00-\x08\x0B-\x0C\x0E-\x1F]/;
  6078. var utils = {
  6079. nop: function nop() {},
  6080. promiseImmediate: function promiseImmediate(value) {
  6081. return new Promise(function (resolve) {
  6082. if (global.setImmediate) {
  6083. setImmediate(function () {
  6084. resolve(value);
  6085. });
  6086. } else {
  6087. // poorman's setImmediate - must wait at least 1ms
  6088. setTimeout(function () {
  6089. resolve(value);
  6090. }, 1);
  6091. }
  6092. });
  6093. },
  6094. inherits: inherits,
  6095. dateToExcel: function dateToExcel(d, date1904) {
  6096. return 25569 + d.getTime() / (24 * 3600 * 1000) - (date1904 ? 1462 : 0);
  6097. },
  6098. excelToDate: function excelToDate(v, date1904) {
  6099. var millisecondSinceEpoch = Math.round((v - 25569 + (date1904 ? 1462 : 0)) * 24 * 3600 * 1000);
  6100. return new Date(millisecondSinceEpoch);
  6101. },
  6102. parsePath: function parsePath(filepath) {
  6103. var last = filepath.lastIndexOf('/');
  6104. return {
  6105. path: filepath.substring(0, last),
  6106. name: filepath.substring(last + 1)
  6107. };
  6108. },
  6109. getRelsPath: function getRelsPath(filepath) {
  6110. var path = utils.parsePath(filepath);
  6111. return "".concat(path.path, "/_rels/").concat(path.name, ".rels");
  6112. },
  6113. xmlEncode: function xmlEncode(text) {
  6114. var regexResult = xmlDecodeRegex.exec(text);
  6115. if (!regexResult) return text;
  6116. var result = '';
  6117. var escape = '';
  6118. var lastIndex = 0;
  6119. var i = regexResult.index;
  6120. for (; i < text.length; i++) {
  6121. var charCode = text.charCodeAt(i);
  6122. switch (charCode) {
  6123. case 34:
  6124. // "
  6125. escape = '&quot;';
  6126. break;
  6127. case 38:
  6128. // &
  6129. escape = '&amp;';
  6130. break;
  6131. case 39:
  6132. // '
  6133. escape = '&apos;';
  6134. break;
  6135. case 60:
  6136. // <
  6137. escape = '&lt;';
  6138. break;
  6139. case 62:
  6140. // >
  6141. escape = '&gt;';
  6142. break;
  6143. case 127:
  6144. escape = '';
  6145. break;
  6146. default:
  6147. {
  6148. if (charCode <= 31 && (charCode <= 8 || charCode >= 11 && charCode !== 13)) {
  6149. escape = '';
  6150. break;
  6151. }
  6152. continue;
  6153. }
  6154. }
  6155. if (lastIndex !== i) result += text.substring(lastIndex, i);
  6156. lastIndex = i + 1;
  6157. if (escape) result += escape;
  6158. }
  6159. if (lastIndex !== i) return result + text.substring(lastIndex, i);
  6160. return result;
  6161. },
  6162. xmlDecode: function xmlDecode(text) {
  6163. return text.replace(/&([a-z]*);/g, function (c) {
  6164. switch (c) {
  6165. case '&lt;':
  6166. return '<';
  6167. case '&gt;':
  6168. return '>';
  6169. case '&amp;':
  6170. return '&';
  6171. case '&apos;':
  6172. return '\'';
  6173. case '&quot;':
  6174. return '"';
  6175. default:
  6176. return c;
  6177. }
  6178. });
  6179. },
  6180. validInt: function validInt(value) {
  6181. var i = parseInt(value, 10);
  6182. return !Number.isNaN(i) ? i : 0;
  6183. },
  6184. isDateFmt: function isDateFmt(fmt) {
  6185. if (!fmt) {
  6186. return false;
  6187. } // must remove all chars inside quotes and []
  6188. fmt = fmt.replace(/\[[^\]]*]/g, '');
  6189. fmt = fmt.replace(/"[^"]*"/g, ''); // then check for date formatting chars
  6190. var result = fmt.match(/[ymdhMsb]+/) !== null;
  6191. return result;
  6192. },
  6193. fs: {
  6194. exists: function exists(path) {
  6195. return new Promise(function (resolve) {
  6196. fs.access(path, fs.constants.F_OK, function (err) {
  6197. resolve(!err);
  6198. });
  6199. });
  6200. }
  6201. },
  6202. toIsoDateString: function toIsoDateString(dt) {
  6203. return dt.toIsoString().subsstr(0, 10);
  6204. }
  6205. };
  6206. module.exports = utils;
  6207. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("timers").setImmediate)
  6208. },{"fs":215,"timers":411}],27:[function(require,module,exports){
  6209. "use strict";
  6210. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6211. 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); } }
  6212. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  6213. var _ = require('./under-dash');
  6214. var utils = require('./utils'); // constants
  6215. var OPEN_ANGLE = '<';
  6216. var CLOSE_ANGLE = '>';
  6217. var OPEN_ANGLE_SLASH = '</';
  6218. var CLOSE_SLASH_ANGLE = '/>';
  6219. var EQUALS_QUOTE = '="';
  6220. var QUOTE = '"';
  6221. var SPACE = ' ';
  6222. function pushAttribute(xml, name, value) {
  6223. xml.push(SPACE);
  6224. xml.push(name);
  6225. xml.push(EQUALS_QUOTE);
  6226. xml.push(utils.xmlEncode(value.toString()));
  6227. xml.push(QUOTE);
  6228. }
  6229. function pushAttributes(xml, attributes) {
  6230. if (attributes) {
  6231. _.each(attributes, function (value, name) {
  6232. if (value !== undefined) {
  6233. pushAttribute(xml, name, value);
  6234. }
  6235. });
  6236. }
  6237. }
  6238. var XmlStream = /*#__PURE__*/function () {
  6239. function XmlStream() {
  6240. _classCallCheck(this, XmlStream);
  6241. this._xml = [];
  6242. this._stack = [];
  6243. this._rollbacks = [];
  6244. }
  6245. _createClass(XmlStream, [{
  6246. key: "openXml",
  6247. value: function openXml(docAttributes) {
  6248. var xml = this._xml; // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  6249. xml.push('<?xml');
  6250. pushAttributes(xml, docAttributes);
  6251. xml.push('?>\n');
  6252. }
  6253. }, {
  6254. key: "openNode",
  6255. value: function openNode(name, attributes) {
  6256. var parent = this.tos;
  6257. var xml = this._xml;
  6258. if (parent && this.open) {
  6259. xml.push(CLOSE_ANGLE);
  6260. }
  6261. this._stack.push(name); // start streaming node
  6262. xml.push(OPEN_ANGLE);
  6263. xml.push(name);
  6264. pushAttributes(xml, attributes);
  6265. this.leaf = true;
  6266. this.open = true;
  6267. }
  6268. }, {
  6269. key: "addAttribute",
  6270. value: function addAttribute(name, value) {
  6271. if (!this.open) {
  6272. throw new Error('Cannot write attributes to node if it is not open');
  6273. }
  6274. if (value !== undefined) {
  6275. pushAttribute(this._xml, name, value);
  6276. }
  6277. }
  6278. }, {
  6279. key: "addAttributes",
  6280. value: function addAttributes(attrs) {
  6281. if (!this.open) {
  6282. throw new Error('Cannot write attributes to node if it is not open');
  6283. }
  6284. pushAttributes(this._xml, attrs);
  6285. }
  6286. }, {
  6287. key: "writeText",
  6288. value: function writeText(text) {
  6289. var xml = this._xml;
  6290. if (this.open) {
  6291. xml.push(CLOSE_ANGLE);
  6292. this.open = false;
  6293. }
  6294. this.leaf = false;
  6295. xml.push(utils.xmlEncode(text.toString()));
  6296. }
  6297. }, {
  6298. key: "writeXml",
  6299. value: function writeXml(xml) {
  6300. if (this.open) {
  6301. this._xml.push(CLOSE_ANGLE);
  6302. this.open = false;
  6303. }
  6304. this.leaf = false;
  6305. this._xml.push(xml);
  6306. }
  6307. }, {
  6308. key: "closeNode",
  6309. value: function closeNode() {
  6310. var node = this._stack.pop();
  6311. var xml = this._xml;
  6312. if (this.leaf) {
  6313. xml.push(CLOSE_SLASH_ANGLE);
  6314. } else {
  6315. xml.push(OPEN_ANGLE_SLASH);
  6316. xml.push(node);
  6317. xml.push(CLOSE_ANGLE);
  6318. }
  6319. this.open = false;
  6320. this.leaf = false;
  6321. }
  6322. }, {
  6323. key: "leafNode",
  6324. value: function leafNode(name, attributes, text) {
  6325. this.openNode(name, attributes);
  6326. if (text !== undefined) {
  6327. // zeros need to be written
  6328. this.writeText(text);
  6329. }
  6330. this.closeNode();
  6331. }
  6332. }, {
  6333. key: "closeAll",
  6334. value: function closeAll() {
  6335. while (this._stack.length) {
  6336. this.closeNode();
  6337. }
  6338. }
  6339. }, {
  6340. key: "addRollback",
  6341. value: function addRollback() {
  6342. this._rollbacks.push({
  6343. xml: this._xml.length,
  6344. stack: this._stack.length,
  6345. leaf: this.leaf,
  6346. open: this.open
  6347. });
  6348. return this.cursor;
  6349. }
  6350. }, {
  6351. key: "commit",
  6352. value: function commit() {
  6353. this._rollbacks.pop();
  6354. }
  6355. }, {
  6356. key: "rollback",
  6357. value: function rollback() {
  6358. var r = this._rollbacks.pop();
  6359. if (this._xml.length > r.xml) {
  6360. this._xml.splice(r.xml, this._xml.length - r.xml);
  6361. }
  6362. if (this._stack.length > r.stack) {
  6363. this._stack.splice(r.stack, this._stack.length - r.stack);
  6364. }
  6365. this.leaf = r.leaf;
  6366. this.open = r.open;
  6367. }
  6368. }, {
  6369. key: "tos",
  6370. get: function get() {
  6371. return this._stack.length ? this._stack[this._stack.length - 1] : undefined;
  6372. }
  6373. }, {
  6374. key: "cursor",
  6375. get: function get() {
  6376. // handy way to track whether anything has been added
  6377. return this._xml.length;
  6378. }
  6379. }, {
  6380. key: "xml",
  6381. get: function get() {
  6382. this.closeAll();
  6383. return this._xml.join('');
  6384. }
  6385. }]);
  6386. return XmlStream;
  6387. }();
  6388. XmlStream.StdDocAttributes = {
  6389. version: '1.0',
  6390. encoding: 'UTF-8',
  6391. standalone: 'yes'
  6392. };
  6393. module.exports = XmlStream;
  6394. },{"./under-dash":25,"./utils":26}],28:[function(require,module,exports){
  6395. (function (process){
  6396. "use strict";
  6397. 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); }
  6398. 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); } }
  6399. 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); }); }; }
  6400. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6401. 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); } }
  6402. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  6403. 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); }
  6404. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  6405. 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); }; }
  6406. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  6407. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  6408. 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; } }
  6409. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  6410. var events = require('events');
  6411. var JSZip = require('jszip');
  6412. var StreamBuf = require('./stream-buf');
  6413. var _require = require('./browser-buffer-encode'),
  6414. stringToBuffer = _require.stringToBuffer; // =============================================================================
  6415. // The ZipWriter class
  6416. // Packs streamed data into an output zip stream
  6417. var ZipWriter = /*#__PURE__*/function (_events$EventEmitter) {
  6418. _inherits(ZipWriter, _events$EventEmitter);
  6419. var _super = _createSuper(ZipWriter);
  6420. function ZipWriter(options) {
  6421. var _this;
  6422. _classCallCheck(this, ZipWriter);
  6423. _this = _super.call(this);
  6424. _this.options = Object.assign({
  6425. type: 'nodebuffer',
  6426. compression: 'DEFLATE'
  6427. }, options);
  6428. _this.zip = new JSZip();
  6429. _this.stream = new StreamBuf();
  6430. return _this;
  6431. }
  6432. _createClass(ZipWriter, [{
  6433. key: "append",
  6434. value: function append(data, options) {
  6435. if (options.hasOwnProperty('base64') && options.base64) {
  6436. this.zip.file(options.name, data, {
  6437. base64: true
  6438. });
  6439. } else {
  6440. // https://www.npmjs.com/package/process
  6441. if (process.browser && typeof data === 'string') {
  6442. // use TextEncoder in browser
  6443. data = stringToBuffer(data);
  6444. }
  6445. this.zip.file(options.name, data);
  6446. }
  6447. }
  6448. }, {
  6449. key: "finalize",
  6450. value: function () {
  6451. var _finalize = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
  6452. var content;
  6453. return regeneratorRuntime.wrap(function _callee$(_context) {
  6454. while (1) {
  6455. switch (_context.prev = _context.next) {
  6456. case 0:
  6457. _context.next = 2;
  6458. return this.zip.generateAsync(this.options);
  6459. case 2:
  6460. content = _context.sent;
  6461. this.stream.end(content);
  6462. this.emit('finish');
  6463. case 5:
  6464. case "end":
  6465. return _context.stop();
  6466. }
  6467. }
  6468. }, _callee, this);
  6469. }));
  6470. function finalize() {
  6471. return _finalize.apply(this, arguments);
  6472. }
  6473. return finalize;
  6474. }() // ==========================================================================
  6475. // Stream.Readable interface
  6476. }, {
  6477. key: "read",
  6478. value: function read(size) {
  6479. return this.stream.read(size);
  6480. }
  6481. }, {
  6482. key: "setEncoding",
  6483. value: function setEncoding(encoding) {
  6484. return this.stream.setEncoding(encoding);
  6485. }
  6486. }, {
  6487. key: "pause",
  6488. value: function pause() {
  6489. return this.stream.pause();
  6490. }
  6491. }, {
  6492. key: "resume",
  6493. value: function resume() {
  6494. return this.stream.resume();
  6495. }
  6496. }, {
  6497. key: "isPaused",
  6498. value: function isPaused() {
  6499. return this.stream.isPaused();
  6500. }
  6501. }, {
  6502. key: "pipe",
  6503. value: function pipe(destination, options) {
  6504. return this.stream.pipe(destination, options);
  6505. }
  6506. }, {
  6507. key: "unpipe",
  6508. value: function unpipe(destination) {
  6509. return this.stream.unpipe(destination);
  6510. }
  6511. }, {
  6512. key: "unshift",
  6513. value: function unshift(chunk) {
  6514. return this.stream.unshift(chunk);
  6515. }
  6516. }, {
  6517. key: "wrap",
  6518. value: function wrap(stream) {
  6519. return this.stream.wrap(stream);
  6520. }
  6521. }]);
  6522. return ZipWriter;
  6523. }(events.EventEmitter); // =============================================================================
  6524. module.exports = {
  6525. ZipWriter: ZipWriter
  6526. };
  6527. }).call(this,require('_process'))
  6528. },{"./browser-buffer-encode":17,"./stream-buf":23,"_process":358,"events":258,"jszip":290}],29:[function(require,module,exports){
  6529. "use strict";
  6530. module.exports = {
  6531. 0: {
  6532. f: 'General'
  6533. },
  6534. 1: {
  6535. f: '0'
  6536. },
  6537. 2: {
  6538. f: '0.00'
  6539. },
  6540. 3: {
  6541. f: '#,##0'
  6542. },
  6543. 4: {
  6544. f: '#,##0.00'
  6545. },
  6546. 9: {
  6547. f: '0%'
  6548. },
  6549. 10: {
  6550. f: '0.00%'
  6551. },
  6552. 11: {
  6553. f: '0.00E+00'
  6554. },
  6555. 12: {
  6556. f: '# ?/?'
  6557. },
  6558. 13: {
  6559. f: '# ??/??'
  6560. },
  6561. 14: {
  6562. f: 'mm-dd-yy'
  6563. },
  6564. 15: {
  6565. f: 'd-mmm-yy'
  6566. },
  6567. 16: {
  6568. f: 'd-mmm'
  6569. },
  6570. 17: {
  6571. f: 'mmm-yy'
  6572. },
  6573. 18: {
  6574. f: 'h:mm AM/PM'
  6575. },
  6576. 19: {
  6577. f: 'h:mm:ss AM/PM'
  6578. },
  6579. 20: {
  6580. f: 'h:mm'
  6581. },
  6582. 21: {
  6583. f: 'h:mm:ss'
  6584. },
  6585. 22: {
  6586. f: 'm/d/yy "h":mm'
  6587. },
  6588. 27: {
  6589. 'zh-tw': '[$-404]e/m/d',
  6590. 'zh-cn': 'yyyy"年"m"月"',
  6591. 'ja-jp': '[$-411]ge.m.d',
  6592. 'ko-kr': 'yyyy"年" mm"月" dd"日"'
  6593. },
  6594. 28: {
  6595. 'zh-tw': '[$-404]e"年"m"月"d"日"',
  6596. 'zh-cn': 'm"月"d"日"',
  6597. 'ja-jp': '[$-411]ggge"年"m"月"d"日"',
  6598. 'ko-kr': 'mm-dd'
  6599. },
  6600. 29: {
  6601. 'zh-tw': '[$-404]e"年"m"月"d"日"',
  6602. 'zh-cn': 'm"月"d"日"',
  6603. 'ja-jp': '[$-411]ggge"年"m"月"d"日"',
  6604. 'ko-kr': 'mm-dd'
  6605. },
  6606. 30: {
  6607. 'zh-tw': 'm/d/yy ',
  6608. 'zh-cn': 'm-d-yy',
  6609. 'ja-jp': 'm/d/yy',
  6610. 'ko-kr': 'mm-dd-yy'
  6611. },
  6612. 31: {
  6613. 'zh-tw': 'yyyy"年"m"月"d"日"',
  6614. 'zh-cn': 'yyyy"年"m"月"d"日"',
  6615. 'ja-jp': 'yyyy"年"m"月"d"日"',
  6616. 'ko-kr': 'yyyy"년" mm"월" dd"일"'
  6617. },
  6618. 32: {
  6619. 'zh-tw': 'hh"時"mm"分"',
  6620. 'zh-cn': 'h"时"mm"分"',
  6621. 'ja-jp': 'h"時"mm"分"',
  6622. 'ko-kr': 'h"시" mm"분"'
  6623. },
  6624. 33: {
  6625. 'zh-tw': 'hh"時"mm"分"ss"秒"',
  6626. 'zh-cn': 'h"时"mm"分"ss"秒"',
  6627. 'ja-jp': 'h"時"mm"分"ss"秒"',
  6628. 'ko-kr': 'h"시" mm"분" ss"초"'
  6629. },
  6630. 34: {
  6631. 'zh-tw': '上午/下午 hh"時"mm"分"',
  6632. 'zh-cn': '上午/下午 h"时"mm"分"',
  6633. 'ja-jp': 'yyyy"年"m"月"',
  6634. 'ko-kr': 'yyyy-mm-dd'
  6635. },
  6636. 35: {
  6637. 'zh-tw': '上午/下午 hh"時"mm"分"ss"秒"',
  6638. 'zh-cn': '上午/下午 h"时"mm"分"ss"秒"',
  6639. 'ja-jp': 'm"月"d"日"',
  6640. 'ko-kr': 'yyyy-mm-dd'
  6641. },
  6642. 36: {
  6643. 'zh-tw': '[$-404]e/m/d',
  6644. 'zh-cn': 'yyyy"年"m"月"',
  6645. 'ja-jp': '[$-411]ge.m.d',
  6646. 'ko-kr': 'yyyy"年" mm"月" dd"日"'
  6647. },
  6648. 37: {
  6649. f: '#,##0 ;(#,##0)'
  6650. },
  6651. 38: {
  6652. f: '#,##0 ;[Red](#,##0)'
  6653. },
  6654. 39: {
  6655. f: '#,##0.00 ;(#,##0.00)'
  6656. },
  6657. 40: {
  6658. f: '#,##0.00 ;[Red](#,##0.00)'
  6659. },
  6660. 45: {
  6661. f: 'mm:ss'
  6662. },
  6663. 46: {
  6664. f: '[h]:mm:ss'
  6665. },
  6666. 47: {
  6667. f: 'mmss.0'
  6668. },
  6669. 48: {
  6670. f: '##0.0E+0'
  6671. },
  6672. 49: {
  6673. f: '@'
  6674. },
  6675. 50: {
  6676. 'zh-tw': '[$-404]e/m/d',
  6677. 'zh-cn': 'yyyy"年"m"月"',
  6678. 'ja-jp': '[$-411]ge.m.d',
  6679. 'ko-kr': 'yyyy"年" mm"月" dd"日"'
  6680. },
  6681. 51: {
  6682. 'zh-tw': '[$-404]e"年"m"月"d"日"',
  6683. 'zh-cn': 'm"月"d"日"',
  6684. 'ja-jp': '[$-411]ggge"年"m"月"d"日"',
  6685. 'ko-kr': 'mm-dd'
  6686. },
  6687. 52: {
  6688. 'zh-tw': '上午/下午 hh"時"mm"分"',
  6689. 'zh-cn': 'yyyy"年"m"月"',
  6690. 'ja-jp': 'yyyy"年"m"月"',
  6691. 'ko-kr': 'yyyy-mm-dd'
  6692. },
  6693. 53: {
  6694. 'zh-tw': '上午/下午 hh"時"mm"分"ss"秒"',
  6695. 'zh-cn': 'm"月"d"日"',
  6696. 'ja-jp': 'm"月"d"日"',
  6697. 'ko-kr': 'yyyy-mm-dd'
  6698. },
  6699. 54: {
  6700. 'zh-tw': '[$-404]e"年"m"月"d"日"',
  6701. 'zh-cn': 'm"月"d"日"',
  6702. 'ja-jp': '[$-411]ggge"年"m"月"d"日"',
  6703. 'ko-kr': 'mm-dd'
  6704. },
  6705. 55: {
  6706. 'zh-tw': '上午/下午 hh"時"mm"分"',
  6707. 'zh-cn': '上午/下午 h"时"mm"分"',
  6708. 'ja-jp': 'yyyy"年"m"月"',
  6709. 'ko-kr': 'yyyy-mm-dd'
  6710. },
  6711. 56: {
  6712. 'zh-tw': '上午/下午 hh"時"mm"分"ss"秒"',
  6713. 'zh-cn': '上午/下午 h"时"mm"分"ss"秒"',
  6714. 'ja-jp': 'm"月"d"日"',
  6715. 'ko-kr': 'yyyy-mm-dd'
  6716. },
  6717. 57: {
  6718. 'zh-tw': '[$-404]e/m/d',
  6719. 'zh-cn': 'yyyy"年"m"月"',
  6720. 'ja-jp': '[$-411]ge.m.d',
  6721. 'ko-kr': 'yyyy"年" mm"月" dd"日"'
  6722. },
  6723. 58: {
  6724. 'zh-tw': '[$-404]e"年"m"月"d"日"',
  6725. 'zh-cn': 'm"月"d"日"',
  6726. 'ja-jp': '[$-411]ggge"年"m"月"d"日"',
  6727. 'ko-kr': 'mm-dd'
  6728. },
  6729. 59: {
  6730. 'th-th': 't0'
  6731. },
  6732. 60: {
  6733. 'th-th': 't0.00'
  6734. },
  6735. 61: {
  6736. 'th-th': 't#,##0'
  6737. },
  6738. 62: {
  6739. 'th-th': 't#,##0.00'
  6740. },
  6741. 67: {
  6742. 'th-th': 't0%'
  6743. },
  6744. 68: {
  6745. 'th-th': 't0.00%'
  6746. },
  6747. 69: {
  6748. 'th-th': 't# ?/?'
  6749. },
  6750. 70: {
  6751. 'th-th': 't# ??/??'
  6752. },
  6753. 81: {
  6754. 'th-th': 'd/m/bb'
  6755. }
  6756. };
  6757. },{}],30:[function(require,module,exports){
  6758. 'use strict';
  6759. module.exports = {
  6760. OfficeDocument: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument',
  6761. Worksheet: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet',
  6762. CalcChain: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/calcChain',
  6763. SharedStrings: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings',
  6764. Styles: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles',
  6765. Theme: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme',
  6766. Hyperlink: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink',
  6767. Image: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image',
  6768. CoreProperties: 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties',
  6769. ExtenderProperties: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties',
  6770. Comments: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments',
  6771. VmlDrawing: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing',
  6772. Table: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/table'
  6773. };
  6774. },{}],31:[function(require,module,exports){
  6775. "use strict";
  6776. 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; } } }; }
  6777. 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); }
  6778. 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; }
  6779. 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); } }
  6780. 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); }); }; }
  6781. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6782. 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); } }
  6783. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  6784. 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"); }
  6785. var parseSax = require('../../utils/parse-sax');
  6786. var XmlStream = require('../../utils/xml-stream');
  6787. /* 'virtual' methods used as a form of documentation */
  6788. /* eslint-disable class-methods-use-this */
  6789. // Base class for Xforms
  6790. var BaseXform = /*#__PURE__*/function () {
  6791. function BaseXform() {
  6792. _classCallCheck(this, BaseXform);
  6793. }
  6794. _createClass(BaseXform, [{
  6795. key: "prepare",
  6796. // constructor(/* model, name */) {}
  6797. // ============================================================
  6798. // Virtual Interface
  6799. value: function prepare()
  6800. /* model, options */
  6801. {// optional preparation (mutation) of model so it is ready for write
  6802. }
  6803. }, {
  6804. key: "render",
  6805. value: function render()
  6806. /* xmlStream, model */
  6807. {// convert model to xml
  6808. }
  6809. }, {
  6810. key: "parseOpen",
  6811. value: function parseOpen(node) {// XML node opened
  6812. }
  6813. }, {
  6814. key: "parseText",
  6815. value: function parseText(text) {// chunk of text encountered for current node
  6816. }
  6817. }, {
  6818. key: "parseClose",
  6819. value: function parseClose(name) {// XML node closed
  6820. }
  6821. }, {
  6822. key: "reconcile",
  6823. value: function reconcile(model, options) {// optional post-parse step (opposite to prepare)
  6824. } // ============================================================
  6825. }, {
  6826. key: "reset",
  6827. value: function reset() {
  6828. // to make sure parses don't bleed to next iteration
  6829. this.model = null; // if we have a map - reset them too
  6830. if (this.map) {
  6831. Object.values(this.map).forEach(function (xform) {
  6832. if (xform instanceof BaseXform) {
  6833. xform.reset();
  6834. } else if (xform.xform) {
  6835. xform.xform.reset();
  6836. }
  6837. });
  6838. }
  6839. }
  6840. }, {
  6841. key: "mergeModel",
  6842. value: function mergeModel(obj) {
  6843. // set obj's props to this.model
  6844. this.model = Object.assign(this.model || {}, obj);
  6845. }
  6846. }, {
  6847. key: "parse",
  6848. value: function () {
  6849. var _parse = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(saxParser) {
  6850. var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, events, _iterator2, _step2, _step2$value, eventType, value;
  6851. return regeneratorRuntime.wrap(function _callee$(_context) {
  6852. while (1) {
  6853. switch (_context.prev = _context.next) {
  6854. case 0:
  6855. _iteratorNormalCompletion = true;
  6856. _didIteratorError = false;
  6857. _context.prev = 2;
  6858. _iterator = _asyncIterator(saxParser);
  6859. case 4:
  6860. _context.next = 6;
  6861. return _iterator.next();
  6862. case 6:
  6863. _step = _context.sent;
  6864. _iteratorNormalCompletion = _step.done;
  6865. _context.next = 10;
  6866. return _step.value;
  6867. case 10:
  6868. _value = _context.sent;
  6869. if (_iteratorNormalCompletion) {
  6870. _context.next = 42;
  6871. break;
  6872. }
  6873. events = _value;
  6874. _iterator2 = _createForOfIteratorHelper(events);
  6875. _context.prev = 14;
  6876. _iterator2.s();
  6877. case 16:
  6878. if ((_step2 = _iterator2.n()).done) {
  6879. _context.next = 31;
  6880. break;
  6881. }
  6882. _step2$value = _step2.value, eventType = _step2$value.eventType, value = _step2$value.value;
  6883. if (!(eventType === 'opentag')) {
  6884. _context.next = 22;
  6885. break;
  6886. }
  6887. this.parseOpen(value);
  6888. _context.next = 29;
  6889. break;
  6890. case 22:
  6891. if (!(eventType === 'text')) {
  6892. _context.next = 26;
  6893. break;
  6894. }
  6895. this.parseText(value);
  6896. _context.next = 29;
  6897. break;
  6898. case 26:
  6899. if (!(eventType === 'closetag')) {
  6900. _context.next = 29;
  6901. break;
  6902. }
  6903. if (this.parseClose(value.name)) {
  6904. _context.next = 29;
  6905. break;
  6906. }
  6907. return _context.abrupt("return", this.model);
  6908. case 29:
  6909. _context.next = 16;
  6910. break;
  6911. case 31:
  6912. _context.next = 36;
  6913. break;
  6914. case 33:
  6915. _context.prev = 33;
  6916. _context.t0 = _context["catch"](14);
  6917. _iterator2.e(_context.t0);
  6918. case 36:
  6919. _context.prev = 36;
  6920. _iterator2.f();
  6921. return _context.finish(36);
  6922. case 39:
  6923. _iteratorNormalCompletion = true;
  6924. _context.next = 4;
  6925. break;
  6926. case 42:
  6927. _context.next = 48;
  6928. break;
  6929. case 44:
  6930. _context.prev = 44;
  6931. _context.t1 = _context["catch"](2);
  6932. _didIteratorError = true;
  6933. _iteratorError = _context.t1;
  6934. case 48:
  6935. _context.prev = 48;
  6936. _context.prev = 49;
  6937. if (!(!_iteratorNormalCompletion && _iterator.return != null)) {
  6938. _context.next = 53;
  6939. break;
  6940. }
  6941. _context.next = 53;
  6942. return _iterator.return();
  6943. case 53:
  6944. _context.prev = 53;
  6945. if (!_didIteratorError) {
  6946. _context.next = 56;
  6947. break;
  6948. }
  6949. throw _iteratorError;
  6950. case 56:
  6951. return _context.finish(53);
  6952. case 57:
  6953. return _context.finish(48);
  6954. case 58:
  6955. return _context.abrupt("return", this.model);
  6956. case 59:
  6957. case "end":
  6958. return _context.stop();
  6959. }
  6960. }
  6961. }, _callee, this, [[2, 44, 48, 58], [14, 33, 36, 39], [49,, 53, 57]]);
  6962. }));
  6963. function parse(_x) {
  6964. return _parse.apply(this, arguments);
  6965. }
  6966. return parse;
  6967. }()
  6968. }, {
  6969. key: "parseStream",
  6970. value: function () {
  6971. var _parseStream = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(stream) {
  6972. return regeneratorRuntime.wrap(function _callee2$(_context2) {
  6973. while (1) {
  6974. switch (_context2.prev = _context2.next) {
  6975. case 0:
  6976. return _context2.abrupt("return", this.parse(parseSax(stream)));
  6977. case 1:
  6978. case "end":
  6979. return _context2.stop();
  6980. }
  6981. }
  6982. }, _callee2, this);
  6983. }));
  6984. function parseStream(_x2) {
  6985. return _parseStream.apply(this, arguments);
  6986. }
  6987. return parseStream;
  6988. }()
  6989. }, {
  6990. key: "toXml",
  6991. value: function toXml(model) {
  6992. var xmlStream = new XmlStream();
  6993. this.render(xmlStream, model);
  6994. return xmlStream.xml;
  6995. } // ============================================================
  6996. // Useful Utilities
  6997. }, {
  6998. key: "xml",
  6999. get: function get() {
  7000. // convenience function to get the xml of this.model
  7001. // useful for manager types that are built during the prepare phase
  7002. return this.toXml(this.model);
  7003. }
  7004. }], [{
  7005. key: "toAttribute",
  7006. value: function toAttribute(value, dflt) {
  7007. var always = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  7008. if (value === undefined) {
  7009. if (always) {
  7010. return dflt;
  7011. }
  7012. } else if (always || value !== dflt) {
  7013. return value.toString();
  7014. }
  7015. return undefined;
  7016. }
  7017. }, {
  7018. key: "toStringAttribute",
  7019. value: function toStringAttribute(value, dflt) {
  7020. var always = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  7021. return BaseXform.toAttribute(value, dflt, always);
  7022. }
  7023. }, {
  7024. key: "toStringValue",
  7025. value: function toStringValue(attr, dflt) {
  7026. return attr === undefined ? dflt : attr;
  7027. }
  7028. }, {
  7029. key: "toBoolAttribute",
  7030. value: function toBoolAttribute(value, dflt) {
  7031. var always = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  7032. if (value === undefined) {
  7033. if (always) {
  7034. return dflt;
  7035. }
  7036. } else if (always || value !== dflt) {
  7037. return value ? '1' : '0';
  7038. }
  7039. return undefined;
  7040. }
  7041. }, {
  7042. key: "toBoolValue",
  7043. value: function toBoolValue(attr, dflt) {
  7044. return attr === undefined ? dflt : attr === '1';
  7045. }
  7046. }, {
  7047. key: "toIntAttribute",
  7048. value: function toIntAttribute(value, dflt) {
  7049. var always = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  7050. return BaseXform.toAttribute(value, dflt, always);
  7051. }
  7052. }, {
  7053. key: "toIntValue",
  7054. value: function toIntValue(attr, dflt) {
  7055. return attr === undefined ? dflt : parseInt(attr, 10);
  7056. }
  7057. }, {
  7058. key: "toFloatAttribute",
  7059. value: function toFloatAttribute(value, dflt) {
  7060. var always = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  7061. return BaseXform.toAttribute(value, dflt, always);
  7062. }
  7063. }, {
  7064. key: "toFloatValue",
  7065. value: function toFloatValue(attr, dflt) {
  7066. return attr === undefined ? dflt : parseFloat(attr);
  7067. }
  7068. }]);
  7069. return BaseXform;
  7070. }();
  7071. module.exports = BaseXform;
  7072. },{"../../utils/parse-sax":21,"../../utils/xml-stream":27}],32:[function(require,module,exports){
  7073. "use strict";
  7074. 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); }
  7075. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7076. 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); } }
  7077. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7078. 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); }
  7079. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  7080. 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); }; }
  7081. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  7082. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  7083. 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; } }
  7084. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  7085. var BaseXform = require('../base-xform');
  7086. var colCache = require('../../../utils/col-cache');
  7087. var DefinedNamesXform = /*#__PURE__*/function (_BaseXform) {
  7088. _inherits(DefinedNamesXform, _BaseXform);
  7089. var _super = _createSuper(DefinedNamesXform);
  7090. function DefinedNamesXform() {
  7091. _classCallCheck(this, DefinedNamesXform);
  7092. return _super.apply(this, arguments);
  7093. }
  7094. _createClass(DefinedNamesXform, [{
  7095. key: "render",
  7096. value: function render(xmlStream, model) {
  7097. // <definedNames>
  7098. // <definedName name="name">name.ranges.join(',')</definedName>
  7099. // <definedName name="_xlnm.Print_Area" localSheetId="0">name.ranges.join(',')</definedName>
  7100. // </definedNames>
  7101. xmlStream.openNode('definedName', {
  7102. name: model.name,
  7103. localSheetId: model.localSheetId
  7104. });
  7105. xmlStream.writeText(model.ranges.join(','));
  7106. xmlStream.closeNode();
  7107. }
  7108. }, {
  7109. key: "parseOpen",
  7110. value: function parseOpen(node) {
  7111. switch (node.name) {
  7112. case 'definedName':
  7113. this._parsedName = node.attributes.name;
  7114. this._parsedLocalSheetId = node.attributes.localSheetId;
  7115. this._parsedText = [];
  7116. return true;
  7117. default:
  7118. return false;
  7119. }
  7120. }
  7121. }, {
  7122. key: "parseText",
  7123. value: function parseText(text) {
  7124. this._parsedText.push(text);
  7125. }
  7126. }, {
  7127. key: "parseClose",
  7128. value: function parseClose() {
  7129. this.model = {
  7130. name: this._parsedName,
  7131. ranges: extractRanges(this._parsedText.join(''))
  7132. };
  7133. if (this._parsedLocalSheetId !== undefined) {
  7134. this.model.localSheetId = parseInt(this._parsedLocalSheetId, 10);
  7135. }
  7136. return false;
  7137. }
  7138. }]);
  7139. return DefinedNamesXform;
  7140. }(BaseXform);
  7141. function isValidRange(range) {
  7142. try {
  7143. colCache.decodeEx(range);
  7144. return true;
  7145. } catch (err) {
  7146. return false;
  7147. }
  7148. }
  7149. function extractRanges(parsedText) {
  7150. var ranges = [];
  7151. var quotesOpened = false;
  7152. var last = '';
  7153. parsedText.split(',').forEach(function (item) {
  7154. if (!item) {
  7155. return;
  7156. }
  7157. var quotes = (item.match(/'/g) || []).length;
  7158. if (!quotes) {
  7159. if (quotesOpened) {
  7160. last += "".concat(item, ",");
  7161. } else if (isValidRange(item)) {
  7162. ranges.push(item);
  7163. }
  7164. return;
  7165. }
  7166. var quotesEven = quotes % 2 === 0;
  7167. if (!quotesOpened && quotesEven && isValidRange(item)) {
  7168. ranges.push(item);
  7169. } else if (quotesOpened && !quotesEven) {
  7170. quotesOpened = false;
  7171. if (isValidRange(last + item)) {
  7172. ranges.push(last + item);
  7173. }
  7174. last = '';
  7175. } else {
  7176. quotesOpened = true;
  7177. last += "".concat(item, ",");
  7178. }
  7179. });
  7180. return ranges;
  7181. }
  7182. module.exports = DefinedNamesXform;
  7183. },{"../../../utils/col-cache":19,"../base-xform":31}],33:[function(require,module,exports){
  7184. "use strict";
  7185. 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); }
  7186. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7187. 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); } }
  7188. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7189. 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); }
  7190. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  7191. 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); }; }
  7192. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  7193. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  7194. 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; } }
  7195. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  7196. var utils = require('../../../utils/utils');
  7197. var BaseXform = require('../base-xform');
  7198. var WorksheetXform = /*#__PURE__*/function (_BaseXform) {
  7199. _inherits(WorksheetXform, _BaseXform);
  7200. var _super = _createSuper(WorksheetXform);
  7201. function WorksheetXform() {
  7202. _classCallCheck(this, WorksheetXform);
  7203. return _super.apply(this, arguments);
  7204. }
  7205. _createClass(WorksheetXform, [{
  7206. key: "render",
  7207. value: function render(xmlStream, model) {
  7208. xmlStream.leafNode('sheet', {
  7209. sheetId: model.id,
  7210. name: model.name,
  7211. state: model.state,
  7212. 'r:id': model.rId
  7213. });
  7214. }
  7215. }, {
  7216. key: "parseOpen",
  7217. value: function parseOpen(node) {
  7218. if (node.name === 'sheet') {
  7219. this.model = {
  7220. name: utils.xmlDecode(node.attributes.name),
  7221. id: parseInt(node.attributes.sheetId, 10),
  7222. state: node.attributes.state,
  7223. rId: node.attributes['r:id']
  7224. };
  7225. return true;
  7226. }
  7227. return false;
  7228. }
  7229. }, {
  7230. key: "parseText",
  7231. value: function parseText() {}
  7232. }, {
  7233. key: "parseClose",
  7234. value: function parseClose() {
  7235. return false;
  7236. }
  7237. }]);
  7238. return WorksheetXform;
  7239. }(BaseXform);
  7240. module.exports = WorksheetXform;
  7241. },{"../../../utils/utils":26,"../base-xform":31}],34:[function(require,module,exports){
  7242. "use strict";
  7243. 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); }
  7244. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7245. 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); } }
  7246. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7247. 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); }
  7248. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  7249. 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); }; }
  7250. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  7251. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  7252. 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; } }
  7253. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  7254. var BaseXform = require('../base-xform');
  7255. var WorkbookCalcPropertiesXform = /*#__PURE__*/function (_BaseXform) {
  7256. _inherits(WorkbookCalcPropertiesXform, _BaseXform);
  7257. var _super = _createSuper(WorkbookCalcPropertiesXform);
  7258. function WorkbookCalcPropertiesXform() {
  7259. _classCallCheck(this, WorkbookCalcPropertiesXform);
  7260. return _super.apply(this, arguments);
  7261. }
  7262. _createClass(WorkbookCalcPropertiesXform, [{
  7263. key: "render",
  7264. value: function render(xmlStream, model) {
  7265. xmlStream.leafNode('calcPr', {
  7266. calcId: 171027,
  7267. fullCalcOnLoad: model.fullCalcOnLoad ? 1 : undefined
  7268. });
  7269. }
  7270. }, {
  7271. key: "parseOpen",
  7272. value: function parseOpen(node) {
  7273. if (node.name === 'calcPr') {
  7274. this.model = {};
  7275. return true;
  7276. }
  7277. return false;
  7278. }
  7279. }, {
  7280. key: "parseText",
  7281. value: function parseText() {}
  7282. }, {
  7283. key: "parseClose",
  7284. value: function parseClose() {
  7285. return false;
  7286. }
  7287. }]);
  7288. return WorkbookCalcPropertiesXform;
  7289. }(BaseXform);
  7290. module.exports = WorkbookCalcPropertiesXform;
  7291. },{"../base-xform":31}],35:[function(require,module,exports){
  7292. "use strict";
  7293. 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); }
  7294. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7295. 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); } }
  7296. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7297. 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); }
  7298. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  7299. 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); }; }
  7300. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  7301. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  7302. 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; } }
  7303. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  7304. var BaseXform = require('../base-xform');
  7305. var WorksheetPropertiesXform = /*#__PURE__*/function (_BaseXform) {
  7306. _inherits(WorksheetPropertiesXform, _BaseXform);
  7307. var _super = _createSuper(WorksheetPropertiesXform);
  7308. function WorksheetPropertiesXform() {
  7309. _classCallCheck(this, WorksheetPropertiesXform);
  7310. return _super.apply(this, arguments);
  7311. }
  7312. _createClass(WorksheetPropertiesXform, [{
  7313. key: "render",
  7314. value: function render(xmlStream, model) {
  7315. xmlStream.leafNode('workbookPr', {
  7316. date1904: model.date1904 ? 1 : undefined,
  7317. defaultThemeVersion: 164011,
  7318. filterPrivacy: 1
  7319. });
  7320. }
  7321. }, {
  7322. key: "parseOpen",
  7323. value: function parseOpen(node) {
  7324. if (node.name === 'workbookPr') {
  7325. this.model = {
  7326. date1904: node.attributes.date1904 === '1'
  7327. };
  7328. return true;
  7329. }
  7330. return false;
  7331. }
  7332. }, {
  7333. key: "parseText",
  7334. value: function parseText() {}
  7335. }, {
  7336. key: "parseClose",
  7337. value: function parseClose() {
  7338. return false;
  7339. }
  7340. }]);
  7341. return WorksheetPropertiesXform;
  7342. }(BaseXform);
  7343. module.exports = WorksheetPropertiesXform;
  7344. },{"../base-xform":31}],36:[function(require,module,exports){
  7345. "use strict";
  7346. 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); }
  7347. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7348. 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); } }
  7349. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7350. 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); }
  7351. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  7352. 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); }; }
  7353. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  7354. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  7355. 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; } }
  7356. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  7357. var BaseXform = require('../base-xform');
  7358. var WorkbookViewXform = /*#__PURE__*/function (_BaseXform) {
  7359. _inherits(WorkbookViewXform, _BaseXform);
  7360. var _super = _createSuper(WorkbookViewXform);
  7361. function WorkbookViewXform() {
  7362. _classCallCheck(this, WorkbookViewXform);
  7363. return _super.apply(this, arguments);
  7364. }
  7365. _createClass(WorkbookViewXform, [{
  7366. key: "render",
  7367. value: function render(xmlStream, model) {
  7368. var attributes = {
  7369. xWindow: model.x || 0,
  7370. yWindow: model.y || 0,
  7371. windowWidth: model.width || 12000,
  7372. windowHeight: model.height || 24000,
  7373. firstSheet: model.firstSheet,
  7374. activeTab: model.activeTab
  7375. };
  7376. if (model.visibility && model.visibility !== 'visible') {
  7377. attributes.visibility = model.visibility;
  7378. }
  7379. xmlStream.leafNode('workbookView', attributes);
  7380. }
  7381. }, {
  7382. key: "parseOpen",
  7383. value: function parseOpen(node) {
  7384. if (node.name === 'workbookView') {
  7385. var model = this.model = {};
  7386. var addS = function addS(name, value, dflt) {
  7387. var s = value !== undefined ? model[name] = value : dflt;
  7388. if (s !== undefined) {
  7389. model[name] = s;
  7390. }
  7391. };
  7392. var addN = function addN(name, value, dflt) {
  7393. var n = value !== undefined ? model[name] = parseInt(value, 10) : dflt;
  7394. if (n !== undefined) {
  7395. model[name] = n;
  7396. }
  7397. };
  7398. addN('x', node.attributes.xWindow, 0);
  7399. addN('y', node.attributes.yWindow, 0);
  7400. addN('width', node.attributes.windowWidth, 25000);
  7401. addN('height', node.attributes.windowHeight, 10000);
  7402. addS('visibility', node.attributes.visibility, 'visible');
  7403. addN('activeTab', node.attributes.activeTab, undefined);
  7404. addN('firstSheet', node.attributes.firstSheet, undefined);
  7405. return true;
  7406. }
  7407. return false;
  7408. }
  7409. }, {
  7410. key: "parseText",
  7411. value: function parseText() {}
  7412. }, {
  7413. key: "parseClose",
  7414. value: function parseClose() {
  7415. return false;
  7416. }
  7417. }]);
  7418. return WorkbookViewXform;
  7419. }(BaseXform);
  7420. module.exports = WorkbookViewXform;
  7421. },{"../base-xform":31}],37:[function(require,module,exports){
  7422. "use strict";
  7423. 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); }
  7424. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7425. 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); } }
  7426. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7427. 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); }
  7428. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  7429. 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); }; }
  7430. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  7431. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  7432. 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; } }
  7433. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  7434. var _ = require('../../../utils/under-dash');
  7435. var colCache = require('../../../utils/col-cache');
  7436. var XmlStream = require('../../../utils/xml-stream');
  7437. var BaseXform = require('../base-xform');
  7438. var StaticXform = require('../static-xform');
  7439. var ListXform = require('../list-xform');
  7440. var DefinedNameXform = require('./defined-name-xform');
  7441. var SheetXform = require('./sheet-xform');
  7442. var WorkbookViewXform = require('./workbook-view-xform');
  7443. var WorkbookPropertiesXform = require('./workbook-properties-xform');
  7444. var WorkbookCalcPropertiesXform = require('./workbook-calc-properties-xform');
  7445. var WorkbookXform = /*#__PURE__*/function (_BaseXform) {
  7446. _inherits(WorkbookXform, _BaseXform);
  7447. var _super = _createSuper(WorkbookXform);
  7448. function WorkbookXform() {
  7449. var _this;
  7450. _classCallCheck(this, WorkbookXform);
  7451. _this = _super.call(this);
  7452. _this.map = {
  7453. fileVersion: WorkbookXform.STATIC_XFORMS.fileVersion,
  7454. workbookPr: new WorkbookPropertiesXform(),
  7455. bookViews: new ListXform({
  7456. tag: 'bookViews',
  7457. count: false,
  7458. childXform: new WorkbookViewXform()
  7459. }),
  7460. sheets: new ListXform({
  7461. tag: 'sheets',
  7462. count: false,
  7463. childXform: new SheetXform()
  7464. }),
  7465. definedNames: new ListXform({
  7466. tag: 'definedNames',
  7467. count: false,
  7468. childXform: new DefinedNameXform()
  7469. }),
  7470. calcPr: new WorkbookCalcPropertiesXform()
  7471. };
  7472. return _this;
  7473. }
  7474. _createClass(WorkbookXform, [{
  7475. key: "prepare",
  7476. value: function prepare(model) {
  7477. model.sheets = model.worksheets; // collate all the print areas from all of the sheets and add them to the defined names
  7478. var printAreas = [];
  7479. var index = 0; // sheets is sparse array - calc index manually
  7480. model.sheets.forEach(function (sheet) {
  7481. if (sheet.pageSetup && sheet.pageSetup.printArea) {
  7482. sheet.pageSetup.printArea.split('&&').forEach(function (printArea) {
  7483. var printAreaComponents = printArea.split(':');
  7484. var definedName = {
  7485. name: '_xlnm.Print_Area',
  7486. ranges: ["'".concat(sheet.name, "'!$").concat(printAreaComponents[0], ":$").concat(printAreaComponents[1])],
  7487. localSheetId: index
  7488. };
  7489. printAreas.push(definedName);
  7490. });
  7491. }
  7492. if (sheet.pageSetup && (sheet.pageSetup.printTitlesRow || sheet.pageSetup.printTitlesColumn)) {
  7493. var ranges = [];
  7494. if (sheet.pageSetup.printTitlesColumn) {
  7495. var titlesColumns = sheet.pageSetup.printTitlesColumn.split(':');
  7496. ranges.push("'".concat(sheet.name, "'!$").concat(titlesColumns[0], ":$").concat(titlesColumns[1]));
  7497. }
  7498. if (sheet.pageSetup.printTitlesRow) {
  7499. var titlesRows = sheet.pageSetup.printTitlesRow.split(':');
  7500. ranges.push("'".concat(sheet.name, "'!$").concat(titlesRows[0], ":$").concat(titlesRows[1]));
  7501. }
  7502. var definedName = {
  7503. name: '_xlnm.Print_Titles',
  7504. ranges: ranges,
  7505. localSheetId: index
  7506. };
  7507. printAreas.push(definedName);
  7508. }
  7509. index++;
  7510. });
  7511. if (printAreas.length) {
  7512. model.definedNames = model.definedNames.concat(printAreas);
  7513. }
  7514. (model.media || []).forEach(function (medium, i) {
  7515. // assign name
  7516. medium.name = medium.type + (i + 1);
  7517. });
  7518. }
  7519. }, {
  7520. key: "render",
  7521. value: function render(xmlStream, model) {
  7522. xmlStream.openXml(XmlStream.StdDocAttributes);
  7523. xmlStream.openNode('workbook', WorkbookXform.WORKBOOK_ATTRIBUTES);
  7524. this.map.fileVersion.render(xmlStream);
  7525. this.map.workbookPr.render(xmlStream, model.properties);
  7526. this.map.bookViews.render(xmlStream, model.views);
  7527. this.map.sheets.render(xmlStream, model.sheets);
  7528. this.map.definedNames.render(xmlStream, model.definedNames);
  7529. this.map.calcPr.render(xmlStream, model.calcProperties);
  7530. xmlStream.closeNode();
  7531. }
  7532. }, {
  7533. key: "parseOpen",
  7534. value: function parseOpen(node) {
  7535. if (this.parser) {
  7536. this.parser.parseOpen(node);
  7537. return true;
  7538. }
  7539. switch (node.name) {
  7540. case 'workbook':
  7541. return true;
  7542. default:
  7543. this.parser = this.map[node.name];
  7544. if (this.parser) {
  7545. this.parser.parseOpen(node);
  7546. }
  7547. return true;
  7548. }
  7549. }
  7550. }, {
  7551. key: "parseText",
  7552. value: function parseText(text) {
  7553. if (this.parser) {
  7554. this.parser.parseText(text);
  7555. }
  7556. }
  7557. }, {
  7558. key: "parseClose",
  7559. value: function parseClose(name) {
  7560. if (this.parser) {
  7561. if (!this.parser.parseClose(name)) {
  7562. this.parser = undefined;
  7563. }
  7564. return true;
  7565. }
  7566. switch (name) {
  7567. case 'workbook':
  7568. this.model = {
  7569. sheets: this.map.sheets.model,
  7570. properties: this.map.workbookPr.model || {},
  7571. views: this.map.bookViews.model,
  7572. calcProperties: {}
  7573. };
  7574. if (this.map.definedNames.model) {
  7575. this.model.definedNames = this.map.definedNames.model;
  7576. }
  7577. return false;
  7578. default:
  7579. // not quite sure how we get here!
  7580. return true;
  7581. }
  7582. }
  7583. }, {
  7584. key: "reconcile",
  7585. value: function reconcile(model) {
  7586. var rels = (model.workbookRels || []).reduce(function (map, rel) {
  7587. map[rel.Id] = rel;
  7588. return map;
  7589. }, {}); // reconcile sheet ids, rIds and names
  7590. var worksheets = [];
  7591. var worksheet;
  7592. var index = 0;
  7593. (model.sheets || []).forEach(function (sheet) {
  7594. var rel = rels[sheet.rId];
  7595. if (!rel) {
  7596. return;
  7597. } // if rel.Target start with `[space]/xl/` or `/xl/` , then it will be replaced with `''` and spliced behind `xl/`,
  7598. // otherwise it will be spliced directly behind `xl/`. i.g.
  7599. worksheet = model.worksheetHash["xl/".concat(rel.Target.replace(/^(\s|\/xl\/)+/, ''))]; // If there are "chartsheets" in the file, rel.Target will
  7600. // come out as chartsheets/sheet1.xml or similar here, and
  7601. // that won't be in model.worksheetHash.
  7602. // As we don't have the infrastructure to support chartsheets,
  7603. // we will ignore them for now:
  7604. if (worksheet) {
  7605. worksheet.name = sheet.name;
  7606. worksheet.id = sheet.id;
  7607. worksheet.state = sheet.state;
  7608. worksheets[index++] = worksheet;
  7609. }
  7610. }); // reconcile print areas
  7611. var definedNames = [];
  7612. _.each(model.definedNames, function (definedName) {
  7613. if (definedName.name === '_xlnm.Print_Area') {
  7614. worksheet = worksheets[definedName.localSheetId];
  7615. if (worksheet) {
  7616. if (!worksheet.pageSetup) {
  7617. worksheet.pageSetup = {};
  7618. }
  7619. var range = colCache.decodeEx(definedName.ranges[0]);
  7620. worksheet.pageSetup.printArea = worksheet.pageSetup.printArea ? "".concat(worksheet.pageSetup.printArea, "&&").concat(range.dimensions) : range.dimensions;
  7621. }
  7622. } else if (definedName.name === '_xlnm.Print_Titles') {
  7623. worksheet = worksheets[definedName.localSheetId];
  7624. if (worksheet) {
  7625. if (!worksheet.pageSetup) {
  7626. worksheet.pageSetup = {};
  7627. }
  7628. var rangeString = definedName.ranges.join(',');
  7629. var dollarRegex = /\$/g;
  7630. var rowRangeRegex = /\$\d+:\$\d+/;
  7631. var rowRangeMatches = rangeString.match(rowRangeRegex);
  7632. if (rowRangeMatches && rowRangeMatches.length) {
  7633. var _range = rowRangeMatches[0];
  7634. worksheet.pageSetup.printTitlesRow = _range.replace(dollarRegex, '');
  7635. }
  7636. var columnRangeRegex = /\$[A-Z]+:\$[A-Z]+/;
  7637. var columnRangeMatches = rangeString.match(columnRangeRegex);
  7638. if (columnRangeMatches && columnRangeMatches.length) {
  7639. var _range2 = columnRangeMatches[0];
  7640. worksheet.pageSetup.printTitlesColumn = _range2.replace(dollarRegex, '');
  7641. }
  7642. }
  7643. } else {
  7644. definedNames.push(definedName);
  7645. }
  7646. });
  7647. model.definedNames = definedNames; // used by sheets to build their image models
  7648. model.media.forEach(function (media, i) {
  7649. media.index = i;
  7650. });
  7651. }
  7652. }]);
  7653. return WorkbookXform;
  7654. }(BaseXform);
  7655. WorkbookXform.WORKBOOK_ATTRIBUTES = {
  7656. xmlns: 'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
  7657. 'xmlns:r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
  7658. 'xmlns:mc': 'http://schemas.openxmlformats.org/markup-compatibility/2006',
  7659. 'mc:Ignorable': 'x15',
  7660. 'xmlns:x15': 'http://schemas.microsoft.com/office/spreadsheetml/2010/11/main'
  7661. };
  7662. WorkbookXform.STATIC_XFORMS = {
  7663. fileVersion: new StaticXform({
  7664. tag: 'fileVersion',
  7665. $: {
  7666. appName: 'xl',
  7667. lastEdited: 5,
  7668. lowestEdited: 5,
  7669. rupBuild: 9303
  7670. }
  7671. })
  7672. };
  7673. module.exports = WorkbookXform;
  7674. },{"../../../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){
  7675. "use strict";
  7676. 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; }
  7677. 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; }
  7678. 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; }
  7679. var RichTextXform = require('../strings/rich-text-xform');
  7680. var utils = require('../../../utils/utils');
  7681. var BaseXform = require('../base-xform');
  7682. /**
  7683. <comment ref="B1" authorId="0">
  7684. <text>
  7685. <r>
  7686. <rPr>
  7687. <b/>
  7688. <sz val="9"/>
  7689. <rFont val="宋体"/>
  7690. <charset val="134"/>
  7691. </rPr>
  7692. <t>51422:</t>
  7693. </r>
  7694. <r>
  7695. <rPr>
  7696. <sz val="9"/>
  7697. <rFont val="宋体"/>
  7698. <charset val="134"/>
  7699. </rPr>
  7700. <t xml:space="preserve">&#10;test</t>
  7701. </r>
  7702. </text>
  7703. </comment>
  7704. */
  7705. var CommentXform = module.exports = function (model) {
  7706. this.model = model;
  7707. };
  7708. utils.inherits(CommentXform, BaseXform, {
  7709. get tag() {
  7710. return 'r';
  7711. },
  7712. get richTextXform() {
  7713. if (!this._richTextXform) {
  7714. this._richTextXform = new RichTextXform();
  7715. }
  7716. return this._richTextXform;
  7717. },
  7718. render: function render(xmlStream, model) {
  7719. var _this = this;
  7720. model = model || this.model;
  7721. xmlStream.openNode('comment', {
  7722. ref: model.ref,
  7723. authorId: 0
  7724. });
  7725. xmlStream.openNode('text');
  7726. if (model && model.note && model.note.texts) {
  7727. model.note.texts.forEach(function (text) {
  7728. _this.richTextXform.render(xmlStream, text);
  7729. });
  7730. }
  7731. xmlStream.closeNode();
  7732. xmlStream.closeNode();
  7733. },
  7734. parseOpen: function parseOpen(node) {
  7735. if (this.parser) {
  7736. this.parser.parseOpen(node);
  7737. return true;
  7738. }
  7739. switch (node.name) {
  7740. case 'comment':
  7741. this.model = _objectSpread({
  7742. type: 'note',
  7743. note: {
  7744. texts: []
  7745. }
  7746. }, node.attributes);
  7747. return true;
  7748. case 'r':
  7749. this.parser = this.richTextXform;
  7750. this.parser.parseOpen(node);
  7751. return true;
  7752. default:
  7753. return false;
  7754. }
  7755. },
  7756. parseText: function parseText(text) {
  7757. if (this.parser) {
  7758. this.parser.parseText(text);
  7759. }
  7760. },
  7761. parseClose: function parseClose(name) {
  7762. switch (name) {
  7763. case 'comment':
  7764. return false;
  7765. case 'r':
  7766. this.model.note.texts.push(this.parser.model);
  7767. this.parser = undefined;
  7768. return true;
  7769. default:
  7770. if (this.parser) {
  7771. this.parser.parseClose(name);
  7772. }
  7773. return true;
  7774. }
  7775. }
  7776. });
  7777. },{"../../../utils/utils":26,"../base-xform":31,"../strings/rich-text-xform":121}],39:[function(require,module,exports){
  7778. "use strict";
  7779. var XmlStream = require('../../../utils/xml-stream');
  7780. var utils = require('../../../utils/utils');
  7781. var BaseXform = require('../base-xform');
  7782. var CommentXform = require('./comment-xform');
  7783. var CommentsXform = module.exports = function () {
  7784. this.map = {
  7785. comment: new CommentXform()
  7786. };
  7787. };
  7788. utils.inherits(CommentsXform, BaseXform, {
  7789. COMMENTS_ATTRIBUTES: {
  7790. xmlns: 'http://schemas.openxmlformats.org/spreadsheetml/2006/main'
  7791. }
  7792. }, {
  7793. render: function render(xmlStream, model) {
  7794. var _this = this;
  7795. model = model || this.model;
  7796. xmlStream.openXml(XmlStream.StdDocAttributes);
  7797. xmlStream.openNode('comments', CommentsXform.COMMENTS_ATTRIBUTES); // authors
  7798. // TODO: support authors properly
  7799. xmlStream.openNode('authors');
  7800. xmlStream.leafNode('author', null, 'Author');
  7801. xmlStream.closeNode(); // comments
  7802. xmlStream.openNode('commentList');
  7803. model.comments.forEach(function (comment) {
  7804. _this.map.comment.render(xmlStream, comment);
  7805. });
  7806. xmlStream.closeNode();
  7807. xmlStream.closeNode();
  7808. },
  7809. parseOpen: function parseOpen(node) {
  7810. if (this.parser) {
  7811. this.parser.parseOpen(node);
  7812. return true;
  7813. }
  7814. switch (node.name) {
  7815. case 'commentList':
  7816. this.model = {
  7817. comments: []
  7818. };
  7819. return true;
  7820. case 'comment':
  7821. this.parser = this.map.comment;
  7822. this.parser.parseOpen(node);
  7823. return true;
  7824. default:
  7825. return false;
  7826. }
  7827. },
  7828. parseText: function parseText(text) {
  7829. if (this.parser) {
  7830. this.parser.parseText(text);
  7831. }
  7832. },
  7833. parseClose: function parseClose(name) {
  7834. switch (name) {
  7835. case 'commentList':
  7836. return false;
  7837. case 'comment':
  7838. this.model.comments.push(this.parser.model);
  7839. this.parser = undefined;
  7840. return true;
  7841. default:
  7842. if (this.parser) {
  7843. this.parser.parseClose(name);
  7844. }
  7845. return true;
  7846. }
  7847. }
  7848. });
  7849. },{"../../../utils/utils":26,"../../../utils/xml-stream":27,"../base-xform":31,"./comment-xform":38}],40:[function(require,module,exports){
  7850. "use strict";
  7851. 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); }
  7852. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7853. 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); } }
  7854. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7855. 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); }
  7856. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  7857. 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); }; }
  7858. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  7859. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  7860. 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; } }
  7861. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  7862. var BaseXform = require('../../base-xform');
  7863. var VmlPositionXform = /*#__PURE__*/function (_BaseXform) {
  7864. _inherits(VmlPositionXform, _BaseXform);
  7865. var _super = _createSuper(VmlPositionXform);
  7866. function VmlPositionXform(model) {
  7867. var _this;
  7868. _classCallCheck(this, VmlPositionXform);
  7869. _this = _super.call(this);
  7870. _this._model = model;
  7871. return _this;
  7872. }
  7873. _createClass(VmlPositionXform, [{
  7874. key: "render",
  7875. value: function render(xmlStream, model, type) {
  7876. if (model === type[2]) {
  7877. xmlStream.leafNode(this.tag);
  7878. } else if (this.tag === 'x:SizeWithCells' && model === type[1]) {
  7879. xmlStream.leafNode(this.tag);
  7880. }
  7881. }
  7882. }, {
  7883. key: "parseOpen",
  7884. value: function parseOpen(node) {
  7885. switch (node.name) {
  7886. case this.tag:
  7887. this.model = {};
  7888. this.model[this.tag] = true;
  7889. return true;
  7890. default:
  7891. return false;
  7892. }
  7893. }
  7894. }, {
  7895. key: "parseText",
  7896. value: function parseText() {}
  7897. }, {
  7898. key: "parseClose",
  7899. value: function parseClose() {
  7900. return false;
  7901. }
  7902. }, {
  7903. key: "tag",
  7904. get: function get() {
  7905. return this._model && this._model.tag;
  7906. }
  7907. }]);
  7908. return VmlPositionXform;
  7909. }(BaseXform);
  7910. module.exports = VmlPositionXform;
  7911. },{"../../base-xform":31}],41:[function(require,module,exports){
  7912. "use strict";
  7913. 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); }
  7914. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7915. 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); } }
  7916. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7917. 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); }
  7918. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  7919. 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); }; }
  7920. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  7921. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  7922. 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; } }
  7923. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  7924. var BaseXform = require('../../base-xform');
  7925. var VmlProtectionXform = /*#__PURE__*/function (_BaseXform) {
  7926. _inherits(VmlProtectionXform, _BaseXform);
  7927. var _super = _createSuper(VmlProtectionXform);
  7928. function VmlProtectionXform(model) {
  7929. var _this;
  7930. _classCallCheck(this, VmlProtectionXform);
  7931. _this = _super.call(this);
  7932. _this._model = model;
  7933. return _this;
  7934. }
  7935. _createClass(VmlProtectionXform, [{
  7936. key: "render",
  7937. value: function render(xmlStream, model) {
  7938. xmlStream.leafNode(this.tag, null, model);
  7939. }
  7940. }, {
  7941. key: "parseOpen",
  7942. value: function parseOpen(node) {
  7943. switch (node.name) {
  7944. case this.tag:
  7945. this.text = '';
  7946. return true;
  7947. default:
  7948. return false;
  7949. }
  7950. }
  7951. }, {
  7952. key: "parseText",
  7953. value: function parseText(text) {
  7954. this.text = text;
  7955. }
  7956. }, {
  7957. key: "parseClose",
  7958. value: function parseClose() {
  7959. return false;
  7960. }
  7961. }, {
  7962. key: "tag",
  7963. get: function get() {
  7964. return this._model && this._model.tag;
  7965. }
  7966. }]);
  7967. return VmlProtectionXform;
  7968. }(BaseXform);
  7969. module.exports = VmlProtectionXform;
  7970. },{"../../base-xform":31}],42:[function(require,module,exports){
  7971. "use strict";
  7972. 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); }
  7973. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7974. 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); } }
  7975. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7976. 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); }
  7977. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  7978. 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); }; }
  7979. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  7980. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  7981. 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; } }
  7982. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  7983. var BaseXform = require('../base-xform'); // render the triangle in the cell for the comment
  7984. var VmlAnchorXform = /*#__PURE__*/function (_BaseXform) {
  7985. _inherits(VmlAnchorXform, _BaseXform);
  7986. var _super = _createSuper(VmlAnchorXform);
  7987. function VmlAnchorXform() {
  7988. _classCallCheck(this, VmlAnchorXform);
  7989. return _super.apply(this, arguments);
  7990. }
  7991. _createClass(VmlAnchorXform, [{
  7992. key: "getAnchorRect",
  7993. value: function getAnchorRect(anchor) {
  7994. var l = Math.floor(anchor.left);
  7995. var lf = Math.floor((anchor.left - l) * 68);
  7996. var t = Math.floor(anchor.top);
  7997. var tf = Math.floor((anchor.top - t) * 18);
  7998. var r = Math.floor(anchor.right);
  7999. var rf = Math.floor((anchor.right - r) * 68);
  8000. var b = Math.floor(anchor.bottom);
  8001. var bf = Math.floor((anchor.bottom - b) * 18);
  8002. return [l, lf, t, tf, r, rf, b, bf];
  8003. }
  8004. }, {
  8005. key: "getDefaultRect",
  8006. value: function getDefaultRect(ref) {
  8007. var l = ref.col;
  8008. var lf = 6;
  8009. var t = Math.max(ref.row - 2, 0);
  8010. var tf = 14;
  8011. var r = l + 2;
  8012. var rf = 2;
  8013. var b = t + 4;
  8014. var bf = 16;
  8015. return [l, lf, t, tf, r, rf, b, bf];
  8016. }
  8017. }, {
  8018. key: "render",
  8019. value: function render(xmlStream, model) {
  8020. var rect = model.anchor ? this.getAnchorRect(model.anchor) : this.getDefaultRect(model.refAddress);
  8021. xmlStream.leafNode('x:Anchor', null, rect.join(', '));
  8022. }
  8023. }, {
  8024. key: "parseOpen",
  8025. value: function parseOpen(node) {
  8026. switch (node.name) {
  8027. case this.tag:
  8028. this.text = '';
  8029. return true;
  8030. default:
  8031. return false;
  8032. }
  8033. }
  8034. }, {
  8035. key: "parseText",
  8036. value: function parseText(text) {
  8037. this.text = text;
  8038. }
  8039. }, {
  8040. key: "parseClose",
  8041. value: function parseClose() {
  8042. return false;
  8043. }
  8044. }, {
  8045. key: "tag",
  8046. get: function get() {
  8047. return 'x:Anchor';
  8048. }
  8049. }]);
  8050. return VmlAnchorXform;
  8051. }(BaseXform);
  8052. module.exports = VmlAnchorXform;
  8053. },{"../base-xform":31}],43:[function(require,module,exports){
  8054. "use strict";
  8055. 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); }
  8056. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8057. 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); } }
  8058. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8059. 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); }
  8060. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8061. 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); }; }
  8062. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  8063. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8064. 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; } }
  8065. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8066. var BaseXform = require('../base-xform');
  8067. var VmlAnchorXform = require('./vml-anchor-xform');
  8068. var VmlProtectionXform = require('./style/vml-protection-xform');
  8069. var VmlPositionXform = require('./style/vml-position-xform');
  8070. var POSITION_TYPE = ['twoCells', 'oneCells', 'absolute'];
  8071. var VmlClientDataXform = /*#__PURE__*/function (_BaseXform) {
  8072. _inherits(VmlClientDataXform, _BaseXform);
  8073. var _super = _createSuper(VmlClientDataXform);
  8074. function VmlClientDataXform() {
  8075. var _this;
  8076. _classCallCheck(this, VmlClientDataXform);
  8077. _this = _super.call(this);
  8078. _this.map = {
  8079. 'x:Anchor': new VmlAnchorXform(),
  8080. 'x:Locked': new VmlProtectionXform({
  8081. tag: 'x:Locked'
  8082. }),
  8083. 'x:LockText': new VmlProtectionXform({
  8084. tag: 'x:LockText'
  8085. }),
  8086. 'x:SizeWithCells': new VmlPositionXform({
  8087. tag: 'x:SizeWithCells'
  8088. }),
  8089. 'x:MoveWithCells': new VmlPositionXform({
  8090. tag: 'x:MoveWithCells'
  8091. })
  8092. };
  8093. return _this;
  8094. }
  8095. _createClass(VmlClientDataXform, [{
  8096. key: "render",
  8097. value: function render(xmlStream, model) {
  8098. var _model$note = model.note,
  8099. protection = _model$note.protection,
  8100. editAs = _model$note.editAs;
  8101. xmlStream.openNode(this.tag, {
  8102. ObjectType: 'Note'
  8103. });
  8104. this.map['x:MoveWithCells'].render(xmlStream, editAs, POSITION_TYPE);
  8105. this.map['x:SizeWithCells'].render(xmlStream, editAs, POSITION_TYPE);
  8106. this.map['x:Anchor'].render(xmlStream, model);
  8107. this.map['x:Locked'].render(xmlStream, protection.locked);
  8108. xmlStream.leafNode('x:AutoFill', null, 'False');
  8109. this.map['x:LockText'].render(xmlStream, protection.lockText);
  8110. xmlStream.leafNode('x:Row', null, model.refAddress.row - 1);
  8111. xmlStream.leafNode('x:Column', null, model.refAddress.col - 1);
  8112. xmlStream.closeNode();
  8113. }
  8114. }, {
  8115. key: "parseOpen",
  8116. value: function parseOpen(node) {
  8117. switch (node.name) {
  8118. case this.tag:
  8119. this.reset();
  8120. this.model = {
  8121. anchor: [],
  8122. protection: {},
  8123. editAs: ''
  8124. };
  8125. break;
  8126. default:
  8127. this.parser = this.map[node.name];
  8128. if (this.parser) {
  8129. this.parser.parseOpen(node);
  8130. }
  8131. break;
  8132. }
  8133. return true;
  8134. }
  8135. }, {
  8136. key: "parseText",
  8137. value: function parseText(text) {
  8138. if (this.parser) {
  8139. this.parser.parseText(text);
  8140. }
  8141. }
  8142. }, {
  8143. key: "parseClose",
  8144. value: function parseClose(name) {
  8145. if (this.parser) {
  8146. if (!this.parser.parseClose(name)) {
  8147. this.parser = undefined;
  8148. }
  8149. return true;
  8150. }
  8151. switch (name) {
  8152. case this.tag:
  8153. this.normalizeModel();
  8154. return false;
  8155. default:
  8156. return true;
  8157. }
  8158. }
  8159. }, {
  8160. key: "normalizeModel",
  8161. value: function normalizeModel() {
  8162. var position = Object.assign({}, this.map['x:MoveWithCells'].model, this.map['x:SizeWithCells'].model);
  8163. var len = Object.keys(position).length;
  8164. this.model.editAs = POSITION_TYPE[len];
  8165. this.model.anchor = this.map['x:Anchor'].text;
  8166. this.model.protection.locked = this.map['x:Locked'].text;
  8167. this.model.protection.lockText = this.map['x:LockText'].text;
  8168. }
  8169. }, {
  8170. key: "tag",
  8171. get: function get() {
  8172. return 'x:ClientData';
  8173. }
  8174. }]);
  8175. return VmlClientDataXform;
  8176. }(BaseXform);
  8177. module.exports = VmlClientDataXform;
  8178. },{"../base-xform":31,"./style/vml-position-xform":40,"./style/vml-protection-xform":41,"./vml-anchor-xform":42}],44:[function(require,module,exports){
  8179. "use strict";
  8180. 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); }
  8181. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8182. 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); } }
  8183. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8184. 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); }
  8185. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8186. 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); }; }
  8187. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  8188. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8189. 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; } }
  8190. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8191. var XmlStream = require('../../../utils/xml-stream');
  8192. var BaseXform = require('../base-xform');
  8193. var VmlShapeXform = require('./vml-shape-xform'); // This class is (currently) single purposed to insert the triangle
  8194. // drawing icons on commented cells
  8195. var VmlNotesXform = /*#__PURE__*/function (_BaseXform) {
  8196. _inherits(VmlNotesXform, _BaseXform);
  8197. var _super = _createSuper(VmlNotesXform);
  8198. function VmlNotesXform() {
  8199. var _this;
  8200. _classCallCheck(this, VmlNotesXform);
  8201. _this = _super.call(this);
  8202. _this.map = {
  8203. 'v:shape': new VmlShapeXform()
  8204. };
  8205. return _this;
  8206. }
  8207. _createClass(VmlNotesXform, [{
  8208. key: "render",
  8209. value: function render(xmlStream, model) {
  8210. var _this2 = this;
  8211. xmlStream.openXml(XmlStream.StdDocAttributes);
  8212. xmlStream.openNode(this.tag, VmlNotesXform.DRAWING_ATTRIBUTES);
  8213. xmlStream.openNode('o:shapelayout', {
  8214. 'v:ext': 'edit'
  8215. });
  8216. xmlStream.leafNode('o:idmap', {
  8217. 'v:ext': 'edit',
  8218. data: 1
  8219. });
  8220. xmlStream.closeNode();
  8221. xmlStream.openNode('v:shapetype', {
  8222. id: '_x0000_t202',
  8223. coordsize: '21600,21600',
  8224. 'o:spt': 202,
  8225. path: 'm,l,21600r21600,l21600,xe'
  8226. });
  8227. xmlStream.leafNode('v:stroke', {
  8228. joinstyle: 'miter'
  8229. });
  8230. xmlStream.leafNode('v:path', {
  8231. gradientshapeok: 't',
  8232. 'o:connecttype': 'rect'
  8233. });
  8234. xmlStream.closeNode();
  8235. model.comments.forEach(function (item, index) {
  8236. _this2.map['v:shape'].render(xmlStream, item, index);
  8237. });
  8238. xmlStream.closeNode();
  8239. }
  8240. }, {
  8241. key: "parseOpen",
  8242. value: function parseOpen(node) {
  8243. if (this.parser) {
  8244. this.parser.parseOpen(node);
  8245. return true;
  8246. }
  8247. switch (node.name) {
  8248. case this.tag:
  8249. this.reset();
  8250. this.model = {
  8251. comments: []
  8252. };
  8253. break;
  8254. default:
  8255. this.parser = this.map[node.name];
  8256. if (this.parser) {
  8257. this.parser.parseOpen(node);
  8258. }
  8259. break;
  8260. }
  8261. return true;
  8262. }
  8263. }, {
  8264. key: "parseText",
  8265. value: function parseText(text) {
  8266. if (this.parser) {
  8267. this.parser.parseText(text);
  8268. }
  8269. }
  8270. }, {
  8271. key: "parseClose",
  8272. value: function parseClose(name) {
  8273. if (this.parser) {
  8274. if (!this.parser.parseClose(name)) {
  8275. this.model.comments.push(this.parser.model);
  8276. this.parser = undefined;
  8277. }
  8278. return true;
  8279. }
  8280. switch (name) {
  8281. case this.tag:
  8282. return false;
  8283. default:
  8284. // could be some unrecognised tags
  8285. return true;
  8286. }
  8287. }
  8288. }, {
  8289. key: "reconcile",
  8290. value: function reconcile(model, options) {
  8291. var _this3 = this;
  8292. model.anchors.forEach(function (anchor) {
  8293. if (anchor.br) {
  8294. _this3.map['xdr:twoCellAnchor'].reconcile(anchor, options);
  8295. } else {
  8296. _this3.map['xdr:oneCellAnchor'].reconcile(anchor, options);
  8297. }
  8298. });
  8299. }
  8300. }, {
  8301. key: "tag",
  8302. get: function get() {
  8303. return 'xml';
  8304. }
  8305. }]);
  8306. return VmlNotesXform;
  8307. }(BaseXform);
  8308. VmlNotesXform.DRAWING_ATTRIBUTES = {
  8309. 'xmlns:v': 'urn:schemas-microsoft-com:vml',
  8310. 'xmlns:o': 'urn:schemas-microsoft-com:office:office',
  8311. 'xmlns:x': 'urn:schemas-microsoft-com:office:excel'
  8312. };
  8313. module.exports = VmlNotesXform;
  8314. },{"../../../utils/xml-stream":27,"../base-xform":31,"./vml-shape-xform":45}],45:[function(require,module,exports){
  8315. "use strict";
  8316. 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); }
  8317. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8318. 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); } }
  8319. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8320. 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); }
  8321. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8322. 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); }; }
  8323. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  8324. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8325. 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; } }
  8326. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8327. var BaseXform = require('../base-xform');
  8328. var VmlTextboxXform = require('./vml-textbox-xform');
  8329. var VmlClientDataXform = require('./vml-client-data-xform');
  8330. var VmlShapeXform = /*#__PURE__*/function (_BaseXform) {
  8331. _inherits(VmlShapeXform, _BaseXform);
  8332. var _super = _createSuper(VmlShapeXform);
  8333. function VmlShapeXform() {
  8334. var _this;
  8335. _classCallCheck(this, VmlShapeXform);
  8336. _this = _super.call(this);
  8337. _this.map = {
  8338. 'v:textbox': new VmlTextboxXform(),
  8339. 'x:ClientData': new VmlClientDataXform()
  8340. };
  8341. return _this;
  8342. }
  8343. _createClass(VmlShapeXform, [{
  8344. key: "render",
  8345. value: function render(xmlStream, model, index) {
  8346. xmlStream.openNode('v:shape', VmlShapeXform.V_SHAPE_ATTRIBUTES(model, index));
  8347. xmlStream.leafNode('v:fill', {
  8348. color2: 'infoBackground [80]'
  8349. });
  8350. xmlStream.leafNode('v:shadow', {
  8351. color: 'none [81]',
  8352. obscured: 't'
  8353. });
  8354. xmlStream.leafNode('v:path', {
  8355. 'o:connecttype': 'none'
  8356. });
  8357. this.map['v:textbox'].render(xmlStream, model);
  8358. this.map['x:ClientData'].render(xmlStream, model);
  8359. xmlStream.closeNode();
  8360. }
  8361. }, {
  8362. key: "parseOpen",
  8363. value: function parseOpen(node) {
  8364. if (this.parser) {
  8365. this.parser.parseOpen(node);
  8366. return true;
  8367. }
  8368. switch (node.name) {
  8369. case this.tag:
  8370. this.reset();
  8371. this.model = {
  8372. margins: {
  8373. insetmode: node.attributes['o:insetmode']
  8374. },
  8375. anchor: '',
  8376. editAs: '',
  8377. protection: {}
  8378. };
  8379. break;
  8380. default:
  8381. this.parser = this.map[node.name];
  8382. if (this.parser) {
  8383. this.parser.parseOpen(node);
  8384. }
  8385. break;
  8386. }
  8387. return true;
  8388. }
  8389. }, {
  8390. key: "parseText",
  8391. value: function parseText(text) {
  8392. if (this.parser) {
  8393. this.parser.parseText(text);
  8394. }
  8395. }
  8396. }, {
  8397. key: "parseClose",
  8398. value: function parseClose(name) {
  8399. if (this.parser) {
  8400. if (!this.parser.parseClose(name)) {
  8401. this.parser = undefined;
  8402. }
  8403. return true;
  8404. }
  8405. switch (name) {
  8406. case this.tag:
  8407. this.model.margins.inset = this.map['v:textbox'].model && this.map['v:textbox'].model.inset;
  8408. this.model.protection = this.map['x:ClientData'].model && this.map['x:ClientData'].model.protection;
  8409. this.model.anchor = this.map['x:ClientData'].model && this.map['x:ClientData'].model.anchor;
  8410. this.model.editAs = this.map['x:ClientData'].model && this.map['x:ClientData'].model.editAs;
  8411. return false;
  8412. default:
  8413. return true;
  8414. }
  8415. }
  8416. }, {
  8417. key: "tag",
  8418. get: function get() {
  8419. return 'v:shape';
  8420. }
  8421. }]);
  8422. return VmlShapeXform;
  8423. }(BaseXform);
  8424. VmlShapeXform.V_SHAPE_ATTRIBUTES = function (model, index) {
  8425. return {
  8426. id: "_x0000_s".concat(1025 + index),
  8427. type: '#_x0000_t202',
  8428. style: 'position:absolute; margin-left:105.3pt;margin-top:10.5pt;width:97.8pt;height:59.1pt;z-index:1;visibility:hidden',
  8429. fillcolor: 'infoBackground [80]',
  8430. strokecolor: 'none [81]',
  8431. 'o:insetmode': model.note.margins && model.note.margins.insetmode
  8432. };
  8433. };
  8434. module.exports = VmlShapeXform;
  8435. },{"../base-xform":31,"./vml-client-data-xform":43,"./vml-textbox-xform":46}],46:[function(require,module,exports){
  8436. "use strict";
  8437. 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); }
  8438. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8439. 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); } }
  8440. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8441. 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); }
  8442. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8443. 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); }; }
  8444. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  8445. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8446. 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; } }
  8447. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8448. var BaseXform = require('../base-xform');
  8449. var VmlTextboxXform = /*#__PURE__*/function (_BaseXform) {
  8450. _inherits(VmlTextboxXform, _BaseXform);
  8451. var _super = _createSuper(VmlTextboxXform);
  8452. function VmlTextboxXform() {
  8453. _classCallCheck(this, VmlTextboxXform);
  8454. return _super.apply(this, arguments);
  8455. }
  8456. _createClass(VmlTextboxXform, [{
  8457. key: "conversionUnit",
  8458. value: function conversionUnit(value, multiple, unit) {
  8459. return "".concat(parseFloat(value) * multiple.toFixed(2)).concat(unit);
  8460. }
  8461. }, {
  8462. key: "reverseConversionUnit",
  8463. value: function reverseConversionUnit(inset) {
  8464. var _this = this;
  8465. return (inset || '').split(',').map(function (margin) {
  8466. return Number(parseFloat(_this.conversionUnit(parseFloat(margin), 0.1, '')).toFixed(2));
  8467. });
  8468. }
  8469. }, {
  8470. key: "render",
  8471. value: function render(xmlStream, model) {
  8472. var _this2 = this;
  8473. var attributes = {
  8474. style: 'mso-direction-alt:auto'
  8475. };
  8476. if (model && model.note) {
  8477. var _ref = model.note && model.note.margins,
  8478. inset = _ref.inset;
  8479. if (Array.isArray(inset)) {
  8480. inset = inset.map(function (margin) {
  8481. return _this2.conversionUnit(margin, 10, 'mm');
  8482. }).join(',');
  8483. }
  8484. if (inset) {
  8485. attributes.inset = inset;
  8486. }
  8487. }
  8488. xmlStream.openNode('v:textbox', attributes);
  8489. xmlStream.leafNode('div', {
  8490. style: 'text-align:left'
  8491. });
  8492. xmlStream.closeNode();
  8493. }
  8494. }, {
  8495. key: "parseOpen",
  8496. value: function parseOpen(node) {
  8497. switch (node.name) {
  8498. case this.tag:
  8499. this.model = {
  8500. inset: this.reverseConversionUnit(node.attributes.inset)
  8501. };
  8502. return true;
  8503. default:
  8504. return true;
  8505. }
  8506. }
  8507. }, {
  8508. key: "parseText",
  8509. value: function parseText() {}
  8510. }, {
  8511. key: "parseClose",
  8512. value: function parseClose(name) {
  8513. switch (name) {
  8514. case this.tag:
  8515. return false;
  8516. default:
  8517. return true;
  8518. }
  8519. }
  8520. }, {
  8521. key: "tag",
  8522. get: function get() {
  8523. return 'v:textbox';
  8524. }
  8525. }]);
  8526. return VmlTextboxXform;
  8527. }(BaseXform);
  8528. module.exports = VmlTextboxXform;
  8529. },{"../base-xform":31}],47:[function(require,module,exports){
  8530. "use strict";
  8531. 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); }
  8532. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8533. 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); } }
  8534. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8535. 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); }
  8536. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8537. 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); }; }
  8538. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  8539. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8540. 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; } }
  8541. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8542. var BaseXform = require('./base-xform');
  8543. /* 'virtual' methods used as a form of documentation */
  8544. /* eslint-disable class-methods-use-this */
  8545. // base class for xforms that are composed of other xforms
  8546. // offers some default implementations
  8547. var CompositeXform = /*#__PURE__*/function (_BaseXform) {
  8548. _inherits(CompositeXform, _BaseXform);
  8549. var _super = _createSuper(CompositeXform);
  8550. function CompositeXform() {
  8551. _classCallCheck(this, CompositeXform);
  8552. return _super.apply(this, arguments);
  8553. }
  8554. _createClass(CompositeXform, [{
  8555. key: "createNewModel",
  8556. value: function createNewModel(node) {
  8557. return {};
  8558. }
  8559. }, {
  8560. key: "parseOpen",
  8561. value: function parseOpen(node) {
  8562. // Typical pattern for composite xform
  8563. this.parser = this.parser || this.map[node.name];
  8564. if (this.parser) {
  8565. this.parser.parseOpen(node);
  8566. return true;
  8567. }
  8568. if (node.name === this.tag) {
  8569. this.model = this.createNewModel(node);
  8570. return true;
  8571. }
  8572. return false;
  8573. }
  8574. }, {
  8575. key: "parseText",
  8576. value: function parseText(text) {
  8577. // Default implementation. Send text to child parser
  8578. if (this.parser) {
  8579. this.parser.parseText(text);
  8580. }
  8581. }
  8582. }, {
  8583. key: "onParserClose",
  8584. value: function onParserClose(name, parser) {
  8585. // parseClose has seen a child parser close
  8586. // now need to incorporate into this.model somehow
  8587. this.model[name] = parser.model;
  8588. }
  8589. }, {
  8590. key: "parseClose",
  8591. value: function parseClose(name) {
  8592. // Default implementation
  8593. if (this.parser) {
  8594. if (!this.parser.parseClose(name)) {
  8595. this.onParserClose(name, this.parser);
  8596. this.parser = undefined;
  8597. }
  8598. return true;
  8599. }
  8600. return name !== this.tag;
  8601. }
  8602. }]);
  8603. return CompositeXform;
  8604. }(BaseXform);
  8605. module.exports = CompositeXform;
  8606. },{"./base-xform":31}],48:[function(require,module,exports){
  8607. "use strict";
  8608. 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); }
  8609. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8610. 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); } }
  8611. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8612. 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); }
  8613. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8614. 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); }; }
  8615. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  8616. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8617. 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; } }
  8618. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8619. var BaseXform = require('../base-xform');
  8620. var AppHeadingPairsXform = /*#__PURE__*/function (_BaseXform) {
  8621. _inherits(AppHeadingPairsXform, _BaseXform);
  8622. var _super = _createSuper(AppHeadingPairsXform);
  8623. function AppHeadingPairsXform() {
  8624. _classCallCheck(this, AppHeadingPairsXform);
  8625. return _super.apply(this, arguments);
  8626. }
  8627. _createClass(AppHeadingPairsXform, [{
  8628. key: "render",
  8629. value: function render(xmlStream, model) {
  8630. xmlStream.openNode('HeadingPairs');
  8631. xmlStream.openNode('vt:vector', {
  8632. size: 2,
  8633. baseType: 'variant'
  8634. });
  8635. xmlStream.openNode('vt:variant');
  8636. xmlStream.leafNode('vt:lpstr', undefined, 'Worksheets');
  8637. xmlStream.closeNode();
  8638. xmlStream.openNode('vt:variant');
  8639. xmlStream.leafNode('vt:i4', undefined, model.length);
  8640. xmlStream.closeNode();
  8641. xmlStream.closeNode();
  8642. xmlStream.closeNode();
  8643. }
  8644. }, {
  8645. key: "parseOpen",
  8646. value: function parseOpen(node) {
  8647. // no parsing
  8648. return node.name === 'HeadingPairs';
  8649. }
  8650. }, {
  8651. key: "parseText",
  8652. value: function parseText() {}
  8653. }, {
  8654. key: "parseClose",
  8655. value: function parseClose(name) {
  8656. return name !== 'HeadingPairs';
  8657. }
  8658. }]);
  8659. return AppHeadingPairsXform;
  8660. }(BaseXform);
  8661. module.exports = AppHeadingPairsXform;
  8662. },{"../base-xform":31}],49:[function(require,module,exports){
  8663. "use strict";
  8664. 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); }
  8665. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8666. 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); } }
  8667. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8668. 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); }
  8669. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8670. 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); }; }
  8671. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  8672. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8673. 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; } }
  8674. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8675. var BaseXform = require('../base-xform');
  8676. var AppTitlesOfPartsXform = /*#__PURE__*/function (_BaseXform) {
  8677. _inherits(AppTitlesOfPartsXform, _BaseXform);
  8678. var _super = _createSuper(AppTitlesOfPartsXform);
  8679. function AppTitlesOfPartsXform() {
  8680. _classCallCheck(this, AppTitlesOfPartsXform);
  8681. return _super.apply(this, arguments);
  8682. }
  8683. _createClass(AppTitlesOfPartsXform, [{
  8684. key: "render",
  8685. value: function render(xmlStream, model) {
  8686. xmlStream.openNode('TitlesOfParts');
  8687. xmlStream.openNode('vt:vector', {
  8688. size: model.length,
  8689. baseType: 'lpstr'
  8690. });
  8691. model.forEach(function (sheet) {
  8692. xmlStream.leafNode('vt:lpstr', undefined, sheet.name);
  8693. });
  8694. xmlStream.closeNode();
  8695. xmlStream.closeNode();
  8696. }
  8697. }, {
  8698. key: "parseOpen",
  8699. value: function parseOpen(node) {
  8700. // no parsing
  8701. return node.name === 'TitlesOfParts';
  8702. }
  8703. }, {
  8704. key: "parseText",
  8705. value: function parseText() {}
  8706. }, {
  8707. key: "parseClose",
  8708. value: function parseClose(name) {
  8709. return name !== 'TitlesOfParts';
  8710. }
  8711. }]);
  8712. return AppTitlesOfPartsXform;
  8713. }(BaseXform);
  8714. module.exports = AppTitlesOfPartsXform;
  8715. },{"../base-xform":31}],50:[function(require,module,exports){
  8716. "use strict";
  8717. 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); }
  8718. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8719. 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); } }
  8720. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8721. 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); }
  8722. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8723. 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); }; }
  8724. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  8725. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8726. 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; } }
  8727. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8728. var XmlStream = require('../../../utils/xml-stream');
  8729. var BaseXform = require('../base-xform');
  8730. var StringXform = require('../simple/string-xform');
  8731. var AppHeadingPairsXform = require('./app-heading-pairs-xform');
  8732. var AppTitleOfPartsXform = require('./app-titles-of-parts-xform');
  8733. var AppXform = /*#__PURE__*/function (_BaseXform) {
  8734. _inherits(AppXform, _BaseXform);
  8735. var _super = _createSuper(AppXform);
  8736. function AppXform() {
  8737. var _this;
  8738. _classCallCheck(this, AppXform);
  8739. _this = _super.call(this);
  8740. _this.map = {
  8741. Company: new StringXform({
  8742. tag: 'Company'
  8743. }),
  8744. Manager: new StringXform({
  8745. tag: 'Manager'
  8746. }),
  8747. HeadingPairs: new AppHeadingPairsXform(),
  8748. TitleOfParts: new AppTitleOfPartsXform()
  8749. };
  8750. return _this;
  8751. }
  8752. _createClass(AppXform, [{
  8753. key: "render",
  8754. value: function render(xmlStream, model) {
  8755. xmlStream.openXml(XmlStream.StdDocAttributes);
  8756. xmlStream.openNode('Properties', AppXform.PROPERTY_ATTRIBUTES);
  8757. xmlStream.leafNode('Application', undefined, 'Microsoft Excel');
  8758. xmlStream.leafNode('DocSecurity', undefined, '0');
  8759. xmlStream.leafNode('ScaleCrop', undefined, 'false');
  8760. this.map.HeadingPairs.render(xmlStream, model.worksheets);
  8761. this.map.TitleOfParts.render(xmlStream, model.worksheets);
  8762. this.map.Company.render(xmlStream, model.company || '');
  8763. this.map.Manager.render(xmlStream, model.manager);
  8764. xmlStream.leafNode('LinksUpToDate', undefined, 'false');
  8765. xmlStream.leafNode('SharedDoc', undefined, 'false');
  8766. xmlStream.leafNode('HyperlinksChanged', undefined, 'false');
  8767. xmlStream.leafNode('AppVersion', undefined, '16.0300');
  8768. xmlStream.closeNode();
  8769. }
  8770. }, {
  8771. key: "parseOpen",
  8772. value: function parseOpen(node) {
  8773. if (this.parser) {
  8774. this.parser.parseOpen(node);
  8775. return true;
  8776. }
  8777. switch (node.name) {
  8778. case 'Properties':
  8779. return true;
  8780. default:
  8781. this.parser = this.map[node.name];
  8782. if (this.parser) {
  8783. this.parser.parseOpen(node);
  8784. return true;
  8785. } // there's a lot we don't bother to parse
  8786. return false;
  8787. }
  8788. }
  8789. }, {
  8790. key: "parseText",
  8791. value: function parseText(text) {
  8792. if (this.parser) {
  8793. this.parser.parseText(text);
  8794. }
  8795. }
  8796. }, {
  8797. key: "parseClose",
  8798. value: function parseClose(name) {
  8799. if (this.parser) {
  8800. if (!this.parser.parseClose(name)) {
  8801. this.parser = undefined;
  8802. }
  8803. return true;
  8804. }
  8805. switch (name) {
  8806. case 'Properties':
  8807. this.model = {
  8808. worksheets: this.map.TitleOfParts.model,
  8809. company: this.map.Company.model,
  8810. manager: this.map.Manager.model
  8811. };
  8812. return false;
  8813. default:
  8814. return true;
  8815. }
  8816. }
  8817. }]);
  8818. return AppXform;
  8819. }(BaseXform);
  8820. AppXform.DateFormat = function (dt) {
  8821. return dt.toISOString().replace(/[.]\d{3,6}/, '');
  8822. };
  8823. AppXform.DateAttrs = {
  8824. 'xsi:type': 'dcterms:W3CDTF'
  8825. };
  8826. AppXform.PROPERTY_ATTRIBUTES = {
  8827. xmlns: 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties',
  8828. 'xmlns:vt': 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes'
  8829. };
  8830. module.exports = AppXform;
  8831. },{"../../../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){
  8832. "use strict";
  8833. 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); }
  8834. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8835. 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); } }
  8836. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8837. 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); }
  8838. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8839. 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); }; }
  8840. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  8841. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8842. 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; } }
  8843. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8844. var XmlStream = require('../../../utils/xml-stream');
  8845. var BaseXform = require('../base-xform'); // used for rendering the [Content_Types].xml file
  8846. // not used for parsing
  8847. var ContentTypesXform = /*#__PURE__*/function (_BaseXform) {
  8848. _inherits(ContentTypesXform, _BaseXform);
  8849. var _super = _createSuper(ContentTypesXform);
  8850. function ContentTypesXform() {
  8851. _classCallCheck(this, ContentTypesXform);
  8852. return _super.apply(this, arguments);
  8853. }
  8854. _createClass(ContentTypesXform, [{
  8855. key: "render",
  8856. value: function render(xmlStream, model) {
  8857. xmlStream.openXml(XmlStream.StdDocAttributes);
  8858. xmlStream.openNode('Types', ContentTypesXform.PROPERTY_ATTRIBUTES);
  8859. var mediaHash = {};
  8860. (model.media || []).forEach(function (medium) {
  8861. if (medium.type === 'image') {
  8862. var imageType = medium.extension;
  8863. if (!mediaHash[imageType]) {
  8864. mediaHash[imageType] = true;
  8865. xmlStream.leafNode('Default', {
  8866. Extension: imageType,
  8867. ContentType: "image/".concat(imageType)
  8868. });
  8869. }
  8870. }
  8871. });
  8872. xmlStream.leafNode('Default', {
  8873. Extension: 'rels',
  8874. ContentType: 'application/vnd.openxmlformats-package.relationships+xml'
  8875. });
  8876. xmlStream.leafNode('Default', {
  8877. Extension: 'xml',
  8878. ContentType: 'application/xml'
  8879. });
  8880. xmlStream.leafNode('Override', {
  8881. PartName: '/xl/workbook.xml',
  8882. ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml'
  8883. });
  8884. model.worksheets.forEach(function (worksheet) {
  8885. var name = "/xl/worksheets/sheet".concat(worksheet.id, ".xml");
  8886. xmlStream.leafNode('Override', {
  8887. PartName: name,
  8888. ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml'
  8889. });
  8890. });
  8891. xmlStream.leafNode('Override', {
  8892. PartName: '/xl/theme/theme1.xml',
  8893. ContentType: 'application/vnd.openxmlformats-officedocument.theme+xml'
  8894. });
  8895. xmlStream.leafNode('Override', {
  8896. PartName: '/xl/styles.xml',
  8897. ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml'
  8898. });
  8899. var hasSharedStrings = model.sharedStrings && model.sharedStrings.count;
  8900. if (hasSharedStrings) {
  8901. xmlStream.leafNode('Override', {
  8902. PartName: '/xl/sharedStrings.xml',
  8903. ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml'
  8904. });
  8905. }
  8906. if (model.tables) {
  8907. model.tables.forEach(function (table) {
  8908. xmlStream.leafNode('Override', {
  8909. PartName: "/xl/tables/".concat(table.target),
  8910. ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml'
  8911. });
  8912. });
  8913. }
  8914. if (model.drawings) {
  8915. model.drawings.forEach(function (drawing) {
  8916. xmlStream.leafNode('Override', {
  8917. PartName: "/xl/drawings/".concat(drawing.name, ".xml"),
  8918. ContentType: 'application/vnd.openxmlformats-officedocument.drawing+xml'
  8919. });
  8920. });
  8921. }
  8922. if (model.commentRefs) {
  8923. xmlStream.leafNode('Default', {
  8924. Extension: 'vml',
  8925. ContentType: 'application/vnd.openxmlformats-officedocument.vmlDrawing'
  8926. });
  8927. model.commentRefs.forEach(function (_ref) {
  8928. var commentName = _ref.commentName;
  8929. xmlStream.leafNode('Override', {
  8930. PartName: "/xl/".concat(commentName, ".xml"),
  8931. ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml'
  8932. });
  8933. });
  8934. }
  8935. xmlStream.leafNode('Override', {
  8936. PartName: '/docProps/core.xml',
  8937. ContentType: 'application/vnd.openxmlformats-package.core-properties+xml'
  8938. });
  8939. xmlStream.leafNode('Override', {
  8940. PartName: '/docProps/app.xml',
  8941. ContentType: 'application/vnd.openxmlformats-officedocument.extended-properties+xml'
  8942. });
  8943. xmlStream.closeNode();
  8944. }
  8945. }, {
  8946. key: "parseOpen",
  8947. value: function parseOpen() {
  8948. return false;
  8949. }
  8950. }, {
  8951. key: "parseText",
  8952. value: function parseText() {}
  8953. }, {
  8954. key: "parseClose",
  8955. value: function parseClose() {
  8956. return false;
  8957. }
  8958. }]);
  8959. return ContentTypesXform;
  8960. }(BaseXform);
  8961. ContentTypesXform.PROPERTY_ATTRIBUTES = {
  8962. xmlns: 'http://schemas.openxmlformats.org/package/2006/content-types'
  8963. };
  8964. module.exports = ContentTypesXform;
  8965. },{"../../../utils/xml-stream":27,"../base-xform":31}],52:[function(require,module,exports){
  8966. "use strict";
  8967. 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); }
  8968. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8969. 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); } }
  8970. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8971. 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); }
  8972. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8973. 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); }; }
  8974. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  8975. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8976. 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; } }
  8977. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8978. var XmlStream = require('../../../utils/xml-stream');
  8979. var BaseXform = require('../base-xform');
  8980. var DateXform = require('../simple/date-xform');
  8981. var StringXform = require('../simple/string-xform');
  8982. var IntegerXform = require('../simple/integer-xform');
  8983. var CoreXform = /*#__PURE__*/function (_BaseXform) {
  8984. _inherits(CoreXform, _BaseXform);
  8985. var _super = _createSuper(CoreXform);
  8986. function CoreXform() {
  8987. var _this;
  8988. _classCallCheck(this, CoreXform);
  8989. _this = _super.call(this);
  8990. _this.map = {
  8991. 'dc:creator': new StringXform({
  8992. tag: 'dc:creator'
  8993. }),
  8994. 'dc:title': new StringXform({
  8995. tag: 'dc:title'
  8996. }),
  8997. 'dc:subject': new StringXform({
  8998. tag: 'dc:subject'
  8999. }),
  9000. 'dc:description': new StringXform({
  9001. tag: 'dc:description'
  9002. }),
  9003. 'dc:identifier': new StringXform({
  9004. tag: 'dc:identifier'
  9005. }),
  9006. 'dc:language': new StringXform({
  9007. tag: 'dc:language'
  9008. }),
  9009. 'cp:keywords': new StringXform({
  9010. tag: 'cp:keywords'
  9011. }),
  9012. 'cp:category': new StringXform({
  9013. tag: 'cp:category'
  9014. }),
  9015. 'cp:lastModifiedBy': new StringXform({
  9016. tag: 'cp:lastModifiedBy'
  9017. }),
  9018. 'cp:lastPrinted': new DateXform({
  9019. tag: 'cp:lastPrinted',
  9020. format: CoreXform.DateFormat
  9021. }),
  9022. 'cp:revision': new IntegerXform({
  9023. tag: 'cp:revision'
  9024. }),
  9025. 'cp:version': new StringXform({
  9026. tag: 'cp:version'
  9027. }),
  9028. 'cp:contentStatus': new StringXform({
  9029. tag: 'cp:contentStatus'
  9030. }),
  9031. 'cp:contentType': new StringXform({
  9032. tag: 'cp:contentType'
  9033. }),
  9034. 'dcterms:created': new DateXform({
  9035. tag: 'dcterms:created',
  9036. attrs: CoreXform.DateAttrs,
  9037. format: CoreXform.DateFormat
  9038. }),
  9039. 'dcterms:modified': new DateXform({
  9040. tag: 'dcterms:modified',
  9041. attrs: CoreXform.DateAttrs,
  9042. format: CoreXform.DateFormat
  9043. })
  9044. };
  9045. return _this;
  9046. }
  9047. _createClass(CoreXform, [{
  9048. key: "render",
  9049. value: function render(xmlStream, model) {
  9050. xmlStream.openXml(XmlStream.StdDocAttributes);
  9051. xmlStream.openNode('cp:coreProperties', CoreXform.CORE_PROPERTY_ATTRIBUTES);
  9052. this.map['dc:creator'].render(xmlStream, model.creator);
  9053. this.map['dc:title'].render(xmlStream, model.title);
  9054. this.map['dc:subject'].render(xmlStream, model.subject);
  9055. this.map['dc:description'].render(xmlStream, model.description);
  9056. this.map['dc:identifier'].render(xmlStream, model.identifier);
  9057. this.map['dc:language'].render(xmlStream, model.language);
  9058. this.map['cp:keywords'].render(xmlStream, model.keywords);
  9059. this.map['cp:category'].render(xmlStream, model.category);
  9060. this.map['cp:lastModifiedBy'].render(xmlStream, model.lastModifiedBy);
  9061. this.map['cp:lastPrinted'].render(xmlStream, model.lastPrinted);
  9062. this.map['cp:revision'].render(xmlStream, model.revision);
  9063. this.map['cp:version'].render(xmlStream, model.version);
  9064. this.map['cp:contentStatus'].render(xmlStream, model.contentStatus);
  9065. this.map['cp:contentType'].render(xmlStream, model.contentType);
  9066. this.map['dcterms:created'].render(xmlStream, model.created);
  9067. this.map['dcterms:modified'].render(xmlStream, model.modified);
  9068. xmlStream.closeNode();
  9069. }
  9070. }, {
  9071. key: "parseOpen",
  9072. value: function parseOpen(node) {
  9073. if (this.parser) {
  9074. this.parser.parseOpen(node);
  9075. return true;
  9076. }
  9077. switch (node.name) {
  9078. case 'cp:coreProperties':
  9079. case 'coreProperties':
  9080. return true;
  9081. default:
  9082. this.parser = this.map[node.name];
  9083. if (this.parser) {
  9084. this.parser.parseOpen(node);
  9085. return true;
  9086. }
  9087. throw new Error("Unexpected xml node in parseOpen: ".concat(JSON.stringify(node)));
  9088. }
  9089. }
  9090. }, {
  9091. key: "parseText",
  9092. value: function parseText(text) {
  9093. if (this.parser) {
  9094. this.parser.parseText(text);
  9095. }
  9096. }
  9097. }, {
  9098. key: "parseClose",
  9099. value: function parseClose(name) {
  9100. if (this.parser) {
  9101. if (!this.parser.parseClose(name)) {
  9102. this.parser = undefined;
  9103. }
  9104. return true;
  9105. }
  9106. switch (name) {
  9107. case 'cp:coreProperties':
  9108. case 'coreProperties':
  9109. this.model = {
  9110. creator: this.map['dc:creator'].model,
  9111. title: this.map['dc:title'].model,
  9112. subject: this.map['dc:subject'].model,
  9113. description: this.map['dc:description'].model,
  9114. identifier: this.map['dc:identifier'].model,
  9115. language: this.map['dc:language'].model,
  9116. keywords: this.map['cp:keywords'].model,
  9117. category: this.map['cp:category'].model,
  9118. lastModifiedBy: this.map['cp:lastModifiedBy'].model,
  9119. lastPrinted: this.map['cp:lastPrinted'].model,
  9120. revision: this.map['cp:revision'].model,
  9121. contentStatus: this.map['cp:contentStatus'].model,
  9122. contentType: this.map['cp:contentType'].model,
  9123. created: this.map['dcterms:created'].model,
  9124. modified: this.map['dcterms:modified'].model
  9125. };
  9126. return false;
  9127. default:
  9128. throw new Error("Unexpected xml node in parseClose: ".concat(name));
  9129. }
  9130. }
  9131. }]);
  9132. return CoreXform;
  9133. }(BaseXform);
  9134. CoreXform.DateFormat = function (dt) {
  9135. return dt.toISOString().replace(/[.]\d{3}/, '');
  9136. };
  9137. CoreXform.DateAttrs = {
  9138. 'xsi:type': 'dcterms:W3CDTF'
  9139. };
  9140. CoreXform.CORE_PROPERTY_ATTRIBUTES = {
  9141. 'xmlns:cp': 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties',
  9142. 'xmlns:dc': 'http://purl.org/dc/elements/1.1/',
  9143. 'xmlns:dcterms': 'http://purl.org/dc/terms/',
  9144. 'xmlns:dcmitype': 'http://purl.org/dc/dcmitype/',
  9145. 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance'
  9146. };
  9147. module.exports = CoreXform;
  9148. },{"../../../utils/xml-stream":27,"../base-xform":31,"../simple/date-xform":116,"../simple/integer-xform":117,"../simple/string-xform":118}],53:[function(require,module,exports){
  9149. "use strict";
  9150. 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); }
  9151. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9152. 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); } }
  9153. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9154. 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); }
  9155. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9156. 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); }; }
  9157. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  9158. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9159. 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; } }
  9160. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9161. var BaseXform = require('../base-xform');
  9162. var RelationshipXform = /*#__PURE__*/function (_BaseXform) {
  9163. _inherits(RelationshipXform, _BaseXform);
  9164. var _super = _createSuper(RelationshipXform);
  9165. function RelationshipXform() {
  9166. _classCallCheck(this, RelationshipXform);
  9167. return _super.apply(this, arguments);
  9168. }
  9169. _createClass(RelationshipXform, [{
  9170. key: "render",
  9171. value: function render(xmlStream, model) {
  9172. xmlStream.leafNode('Relationship', model);
  9173. }
  9174. }, {
  9175. key: "parseOpen",
  9176. value: function parseOpen(node) {
  9177. switch (node.name) {
  9178. case 'Relationship':
  9179. this.model = node.attributes;
  9180. return true;
  9181. default:
  9182. return false;
  9183. }
  9184. }
  9185. }, {
  9186. key: "parseText",
  9187. value: function parseText() {}
  9188. }, {
  9189. key: "parseClose",
  9190. value: function parseClose() {
  9191. return false;
  9192. }
  9193. }]);
  9194. return RelationshipXform;
  9195. }(BaseXform);
  9196. module.exports = RelationshipXform;
  9197. },{"../base-xform":31}],54:[function(require,module,exports){
  9198. "use strict";
  9199. 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); }
  9200. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9201. 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); } }
  9202. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9203. 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); }
  9204. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9205. 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); }; }
  9206. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  9207. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9208. 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; } }
  9209. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9210. var XmlStream = require('../../../utils/xml-stream');
  9211. var BaseXform = require('../base-xform');
  9212. var RelationshipXform = require('./relationship-xform');
  9213. var RelationshipsXform = /*#__PURE__*/function (_BaseXform) {
  9214. _inherits(RelationshipsXform, _BaseXform);
  9215. var _super = _createSuper(RelationshipsXform);
  9216. function RelationshipsXform() {
  9217. var _this;
  9218. _classCallCheck(this, RelationshipsXform);
  9219. _this = _super.call(this);
  9220. _this.map = {
  9221. Relationship: new RelationshipXform()
  9222. };
  9223. return _this;
  9224. }
  9225. _createClass(RelationshipsXform, [{
  9226. key: "render",
  9227. value: function render(xmlStream, model) {
  9228. var _this2 = this;
  9229. model = model || this._values;
  9230. xmlStream.openXml(XmlStream.StdDocAttributes);
  9231. xmlStream.openNode('Relationships', RelationshipsXform.RELATIONSHIPS_ATTRIBUTES);
  9232. model.forEach(function (relationship) {
  9233. _this2.map.Relationship.render(xmlStream, relationship);
  9234. });
  9235. xmlStream.closeNode();
  9236. }
  9237. }, {
  9238. key: "parseOpen",
  9239. value: function parseOpen(node) {
  9240. if (this.parser) {
  9241. this.parser.parseOpen(node);
  9242. return true;
  9243. }
  9244. switch (node.name) {
  9245. case 'Relationships':
  9246. this.model = [];
  9247. return true;
  9248. default:
  9249. this.parser = this.map[node.name];
  9250. if (this.parser) {
  9251. this.parser.parseOpen(node);
  9252. return true;
  9253. }
  9254. throw new Error("Unexpected xml node in parseOpen: ".concat(JSON.stringify(node)));
  9255. }
  9256. }
  9257. }, {
  9258. key: "parseText",
  9259. value: function parseText(text) {
  9260. if (this.parser) {
  9261. this.parser.parseText(text);
  9262. }
  9263. }
  9264. }, {
  9265. key: "parseClose",
  9266. value: function parseClose(name) {
  9267. if (this.parser) {
  9268. if (!this.parser.parseClose(name)) {
  9269. this.model.push(this.parser.model);
  9270. this.parser = undefined;
  9271. }
  9272. return true;
  9273. }
  9274. switch (name) {
  9275. case 'Relationships':
  9276. return false;
  9277. default:
  9278. throw new Error("Unexpected xml node in parseClose: ".concat(name));
  9279. }
  9280. }
  9281. }]);
  9282. return RelationshipsXform;
  9283. }(BaseXform);
  9284. RelationshipsXform.RELATIONSHIPS_ATTRIBUTES = {
  9285. xmlns: 'http://schemas.openxmlformats.org/package/2006/relationships'
  9286. };
  9287. module.exports = RelationshipsXform;
  9288. },{"../../../utils/xml-stream":27,"../base-xform":31,"./relationship-xform":53}],55:[function(require,module,exports){
  9289. "use strict";
  9290. 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); }
  9291. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9292. 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); } }
  9293. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9294. 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); }
  9295. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9296. 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); }; }
  9297. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  9298. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9299. 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; } }
  9300. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9301. var BaseXform = require('../base-xform');
  9302. var BaseCellAnchorXform = /*#__PURE__*/function (_BaseXform) {
  9303. _inherits(BaseCellAnchorXform, _BaseXform);
  9304. var _super = _createSuper(BaseCellAnchorXform);
  9305. function BaseCellAnchorXform() {
  9306. _classCallCheck(this, BaseCellAnchorXform);
  9307. return _super.apply(this, arguments);
  9308. }
  9309. _createClass(BaseCellAnchorXform, [{
  9310. key: "parseOpen",
  9311. value: function parseOpen(node) {
  9312. if (this.parser) {
  9313. this.parser.parseOpen(node);
  9314. return true;
  9315. }
  9316. switch (node.name) {
  9317. case this.tag:
  9318. this.reset();
  9319. this.model = {
  9320. range: {
  9321. editAs: node.attributes.editAs || 'oneCell'
  9322. }
  9323. };
  9324. break;
  9325. default:
  9326. this.parser = this.map[node.name];
  9327. if (this.parser) {
  9328. this.parser.parseOpen(node);
  9329. }
  9330. break;
  9331. }
  9332. return true;
  9333. }
  9334. }, {
  9335. key: "parseText",
  9336. value: function parseText(text) {
  9337. if (this.parser) {
  9338. this.parser.parseText(text);
  9339. }
  9340. }
  9341. }, {
  9342. key: "reconcilePicture",
  9343. value: function reconcilePicture(model, options) {
  9344. if (model && model.rId) {
  9345. var rel = options.rels[model.rId];
  9346. var match = rel.Target.match(/.*\/media\/(.+[.][a-zA-Z]{3,4})/);
  9347. if (match) {
  9348. var name = match[1];
  9349. var mediaId = options.mediaIndex[name];
  9350. return options.media[mediaId];
  9351. }
  9352. }
  9353. return undefined;
  9354. }
  9355. }]);
  9356. return BaseCellAnchorXform;
  9357. }(BaseXform);
  9358. module.exports = BaseCellAnchorXform;
  9359. },{"../base-xform":31}],56:[function(require,module,exports){
  9360. "use strict";
  9361. 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); }
  9362. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9363. 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); } }
  9364. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9365. 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); }
  9366. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9367. 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); }; }
  9368. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  9369. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9370. 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; } }
  9371. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9372. var BaseXform = require('../base-xform');
  9373. var BlipXform = require('./blip-xform');
  9374. var BlipFillXform = /*#__PURE__*/function (_BaseXform) {
  9375. _inherits(BlipFillXform, _BaseXform);
  9376. var _super = _createSuper(BlipFillXform);
  9377. function BlipFillXform() {
  9378. var _this;
  9379. _classCallCheck(this, BlipFillXform);
  9380. _this = _super.call(this);
  9381. _this.map = {
  9382. 'a:blip': new BlipXform()
  9383. };
  9384. return _this;
  9385. }
  9386. _createClass(BlipFillXform, [{
  9387. key: "render",
  9388. value: function render(xmlStream, model) {
  9389. xmlStream.openNode(this.tag);
  9390. this.map['a:blip'].render(xmlStream, model); // TODO: options for this + parsing
  9391. xmlStream.openNode('a:stretch');
  9392. xmlStream.leafNode('a:fillRect');
  9393. xmlStream.closeNode();
  9394. xmlStream.closeNode();
  9395. }
  9396. }, {
  9397. key: "parseOpen",
  9398. value: function parseOpen(node) {
  9399. if (this.parser) {
  9400. this.parser.parseOpen(node);
  9401. return true;
  9402. }
  9403. switch (node.name) {
  9404. case this.tag:
  9405. this.reset();
  9406. break;
  9407. default:
  9408. this.parser = this.map[node.name];
  9409. if (this.parser) {
  9410. this.parser.parseOpen(node);
  9411. }
  9412. break;
  9413. }
  9414. return true;
  9415. }
  9416. }, {
  9417. key: "parseText",
  9418. value: function parseText() {}
  9419. }, {
  9420. key: "parseClose",
  9421. value: function parseClose(name) {
  9422. if (this.parser) {
  9423. if (!this.parser.parseClose(name)) {
  9424. this.parser = undefined;
  9425. }
  9426. return true;
  9427. }
  9428. switch (name) {
  9429. case this.tag:
  9430. this.model = this.map['a:blip'].model;
  9431. return false;
  9432. default:
  9433. return true;
  9434. }
  9435. }
  9436. }, {
  9437. key: "tag",
  9438. get: function get() {
  9439. return 'xdr:blipFill';
  9440. }
  9441. }]);
  9442. return BlipFillXform;
  9443. }(BaseXform);
  9444. module.exports = BlipFillXform;
  9445. },{"../base-xform":31,"./blip-xform":57}],57:[function(require,module,exports){
  9446. "use strict";
  9447. 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); }
  9448. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9449. 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); } }
  9450. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9451. 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); }
  9452. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9453. 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); }; }
  9454. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  9455. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9456. 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; } }
  9457. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9458. var BaseXform = require('../base-xform');
  9459. var BlipXform = /*#__PURE__*/function (_BaseXform) {
  9460. _inherits(BlipXform, _BaseXform);
  9461. var _super = _createSuper(BlipXform);
  9462. function BlipXform() {
  9463. _classCallCheck(this, BlipXform);
  9464. return _super.apply(this, arguments);
  9465. }
  9466. _createClass(BlipXform, [{
  9467. key: "render",
  9468. value: function render(xmlStream, model) {
  9469. xmlStream.leafNode(this.tag, {
  9470. 'xmlns:r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
  9471. 'r:embed': model.rId,
  9472. cstate: 'print'
  9473. }); // TODO: handle children (e.g. a:extLst=>a:ext=>a14:useLocalDpi
  9474. }
  9475. }, {
  9476. key: "parseOpen",
  9477. value: function parseOpen(node) {
  9478. switch (node.name) {
  9479. case this.tag:
  9480. this.model = {
  9481. rId: node.attributes['r:embed']
  9482. };
  9483. return true;
  9484. default:
  9485. return true;
  9486. }
  9487. }
  9488. }, {
  9489. key: "parseText",
  9490. value: function parseText() {}
  9491. }, {
  9492. key: "parseClose",
  9493. value: function parseClose(name) {
  9494. switch (name) {
  9495. case this.tag:
  9496. return false;
  9497. default:
  9498. // unprocessed internal nodes
  9499. return true;
  9500. }
  9501. }
  9502. }, {
  9503. key: "tag",
  9504. get: function get() {
  9505. return 'a:blip';
  9506. }
  9507. }]);
  9508. return BlipXform;
  9509. }(BaseXform);
  9510. module.exports = BlipXform;
  9511. },{"../base-xform":31}],58:[function(require,module,exports){
  9512. "use strict";
  9513. 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); }
  9514. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9515. 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); } }
  9516. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9517. 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); }
  9518. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9519. 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); }; }
  9520. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  9521. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9522. 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; } }
  9523. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9524. var BaseXform = require('../base-xform');
  9525. var CNvPicPrXform = /*#__PURE__*/function (_BaseXform) {
  9526. _inherits(CNvPicPrXform, _BaseXform);
  9527. var _super = _createSuper(CNvPicPrXform);
  9528. function CNvPicPrXform() {
  9529. _classCallCheck(this, CNvPicPrXform);
  9530. return _super.apply(this, arguments);
  9531. }
  9532. _createClass(CNvPicPrXform, [{
  9533. key: "render",
  9534. value: function render(xmlStream) {
  9535. xmlStream.openNode(this.tag);
  9536. xmlStream.leafNode('a:picLocks', {
  9537. noChangeAspect: '1'
  9538. });
  9539. xmlStream.closeNode();
  9540. }
  9541. }, {
  9542. key: "parseOpen",
  9543. value: function parseOpen(node) {
  9544. switch (node.name) {
  9545. case this.tag:
  9546. return true;
  9547. default:
  9548. return true;
  9549. }
  9550. }
  9551. }, {
  9552. key: "parseText",
  9553. value: function parseText() {}
  9554. }, {
  9555. key: "parseClose",
  9556. value: function parseClose(name) {
  9557. switch (name) {
  9558. case this.tag:
  9559. return false;
  9560. default:
  9561. // unprocessed internal nodes
  9562. return true;
  9563. }
  9564. }
  9565. }, {
  9566. key: "tag",
  9567. get: function get() {
  9568. return 'xdr:cNvPicPr';
  9569. }
  9570. }]);
  9571. return CNvPicPrXform;
  9572. }(BaseXform);
  9573. module.exports = CNvPicPrXform;
  9574. },{"../base-xform":31}],59:[function(require,module,exports){
  9575. "use strict";
  9576. 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); }
  9577. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9578. 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); } }
  9579. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9580. 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); }
  9581. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9582. 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); }; }
  9583. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  9584. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9585. 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; } }
  9586. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9587. var BaseXform = require('../base-xform');
  9588. var HlickClickXform = require('./hlink-click-xform');
  9589. var ExtLstXform = require('./ext-lst-xform');
  9590. var CNvPrXform = /*#__PURE__*/function (_BaseXform) {
  9591. _inherits(CNvPrXform, _BaseXform);
  9592. var _super = _createSuper(CNvPrXform);
  9593. function CNvPrXform() {
  9594. var _this;
  9595. _classCallCheck(this, CNvPrXform);
  9596. _this = _super.call(this);
  9597. _this.map = {
  9598. 'a:hlinkClick': new HlickClickXform(),
  9599. 'a:extLst': new ExtLstXform()
  9600. };
  9601. return _this;
  9602. }
  9603. _createClass(CNvPrXform, [{
  9604. key: "render",
  9605. value: function render(xmlStream, model) {
  9606. xmlStream.openNode(this.tag, {
  9607. id: model.index,
  9608. name: "Picture ".concat(model.index)
  9609. });
  9610. this.map['a:hlinkClick'].render(xmlStream, model);
  9611. this.map['a:extLst'].render(xmlStream, model);
  9612. xmlStream.closeNode();
  9613. }
  9614. }, {
  9615. key: "parseOpen",
  9616. value: function parseOpen(node) {
  9617. if (this.parser) {
  9618. this.parser.parseOpen(node);
  9619. return true;
  9620. }
  9621. switch (node.name) {
  9622. case this.tag:
  9623. this.reset();
  9624. break;
  9625. default:
  9626. this.parser = this.map[node.name];
  9627. if (this.parser) {
  9628. this.parser.parseOpen(node);
  9629. }
  9630. break;
  9631. }
  9632. return true;
  9633. }
  9634. }, {
  9635. key: "parseText",
  9636. value: function parseText() {}
  9637. }, {
  9638. key: "parseClose",
  9639. value: function parseClose(name) {
  9640. if (this.parser) {
  9641. if (!this.parser.parseClose(name)) {
  9642. this.parser = undefined;
  9643. }
  9644. return true;
  9645. }
  9646. switch (name) {
  9647. case this.tag:
  9648. this.model = this.map['a:hlinkClick'].model;
  9649. return false;
  9650. default:
  9651. return true;
  9652. }
  9653. }
  9654. }, {
  9655. key: "tag",
  9656. get: function get() {
  9657. return 'xdr:cNvPr';
  9658. }
  9659. }]);
  9660. return CNvPrXform;
  9661. }(BaseXform);
  9662. module.exports = CNvPrXform;
  9663. },{"../base-xform":31,"./ext-lst-xform":62,"./hlink-click-xform":64}],60:[function(require,module,exports){
  9664. "use strict";
  9665. 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); }
  9666. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9667. 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); } }
  9668. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9669. 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); }
  9670. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9671. 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); }; }
  9672. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  9673. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9674. 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; } }
  9675. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9676. var BaseXform = require('../base-xform');
  9677. var IntegerXform = require('../simple/integer-xform');
  9678. var CellPositionXform = /*#__PURE__*/function (_BaseXform) {
  9679. _inherits(CellPositionXform, _BaseXform);
  9680. var _super = _createSuper(CellPositionXform);
  9681. function CellPositionXform(options) {
  9682. var _this;
  9683. _classCallCheck(this, CellPositionXform);
  9684. _this = _super.call(this);
  9685. _this.tag = options.tag;
  9686. _this.map = {
  9687. 'xdr:col': new IntegerXform({
  9688. tag: 'xdr:col',
  9689. zero: true
  9690. }),
  9691. 'xdr:colOff': new IntegerXform({
  9692. tag: 'xdr:colOff',
  9693. zero: true
  9694. }),
  9695. 'xdr:row': new IntegerXform({
  9696. tag: 'xdr:row',
  9697. zero: true
  9698. }),
  9699. 'xdr:rowOff': new IntegerXform({
  9700. tag: 'xdr:rowOff',
  9701. zero: true
  9702. })
  9703. };
  9704. return _this;
  9705. }
  9706. _createClass(CellPositionXform, [{
  9707. key: "render",
  9708. value: function render(xmlStream, model) {
  9709. xmlStream.openNode(this.tag);
  9710. this.map['xdr:col'].render(xmlStream, model.nativeCol);
  9711. this.map['xdr:colOff'].render(xmlStream, model.nativeColOff);
  9712. this.map['xdr:row'].render(xmlStream, model.nativeRow);
  9713. this.map['xdr:rowOff'].render(xmlStream, model.nativeRowOff);
  9714. xmlStream.closeNode();
  9715. }
  9716. }, {
  9717. key: "parseOpen",
  9718. value: function parseOpen(node) {
  9719. if (this.parser) {
  9720. this.parser.parseOpen(node);
  9721. return true;
  9722. }
  9723. switch (node.name) {
  9724. case this.tag:
  9725. this.reset();
  9726. break;
  9727. default:
  9728. this.parser = this.map[node.name];
  9729. if (this.parser) {
  9730. this.parser.parseOpen(node);
  9731. }
  9732. break;
  9733. }
  9734. return true;
  9735. }
  9736. }, {
  9737. key: "parseText",
  9738. value: function parseText(text) {
  9739. if (this.parser) {
  9740. this.parser.parseText(text);
  9741. }
  9742. }
  9743. }, {
  9744. key: "parseClose",
  9745. value: function parseClose(name) {
  9746. if (this.parser) {
  9747. if (!this.parser.parseClose(name)) {
  9748. this.parser = undefined;
  9749. }
  9750. return true;
  9751. }
  9752. switch (name) {
  9753. case this.tag:
  9754. this.model = {
  9755. nativeCol: this.map['xdr:col'].model,
  9756. nativeColOff: this.map['xdr:colOff'].model,
  9757. nativeRow: this.map['xdr:row'].model,
  9758. nativeRowOff: this.map['xdr:rowOff'].model
  9759. };
  9760. return false;
  9761. default:
  9762. // not quite sure how we get here!
  9763. return true;
  9764. }
  9765. }
  9766. }]);
  9767. return CellPositionXform;
  9768. }(BaseXform);
  9769. module.exports = CellPositionXform;
  9770. },{"../base-xform":31,"../simple/integer-xform":117}],61:[function(require,module,exports){
  9771. "use strict";
  9772. 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); }
  9773. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9774. 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); } }
  9775. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9776. 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); }
  9777. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9778. 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); }; }
  9779. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  9780. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9781. 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; } }
  9782. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9783. var colCache = require('../../../utils/col-cache');
  9784. var XmlStream = require('../../../utils/xml-stream');
  9785. var BaseXform = require('../base-xform');
  9786. var TwoCellAnchorXform = require('./two-cell-anchor-xform');
  9787. var OneCellAnchorXform = require('./one-cell-anchor-xform');
  9788. function getAnchorType(model) {
  9789. var range = typeof model.range === 'string' ? colCache.decode(model.range) : model.range;
  9790. return range.br ? 'xdr:twoCellAnchor' : 'xdr:oneCellAnchor';
  9791. }
  9792. var DrawingXform = /*#__PURE__*/function (_BaseXform) {
  9793. _inherits(DrawingXform, _BaseXform);
  9794. var _super = _createSuper(DrawingXform);
  9795. function DrawingXform() {
  9796. var _this;
  9797. _classCallCheck(this, DrawingXform);
  9798. _this = _super.call(this);
  9799. _this.map = {
  9800. 'xdr:twoCellAnchor': new TwoCellAnchorXform(),
  9801. 'xdr:oneCellAnchor': new OneCellAnchorXform()
  9802. };
  9803. return _this;
  9804. }
  9805. _createClass(DrawingXform, [{
  9806. key: "prepare",
  9807. value: function prepare(model) {
  9808. var _this2 = this;
  9809. model.anchors.forEach(function (item, index) {
  9810. item.anchorType = getAnchorType(item);
  9811. var anchor = _this2.map[item.anchorType];
  9812. anchor.prepare(item, {
  9813. index: index
  9814. });
  9815. });
  9816. }
  9817. }, {
  9818. key: "render",
  9819. value: function render(xmlStream, model) {
  9820. var _this3 = this;
  9821. xmlStream.openXml(XmlStream.StdDocAttributes);
  9822. xmlStream.openNode(this.tag, DrawingXform.DRAWING_ATTRIBUTES);
  9823. model.anchors.forEach(function (item) {
  9824. var anchor = _this3.map[item.anchorType];
  9825. anchor.render(xmlStream, item);
  9826. });
  9827. xmlStream.closeNode();
  9828. }
  9829. }, {
  9830. key: "parseOpen",
  9831. value: function parseOpen(node) {
  9832. if (this.parser) {
  9833. this.parser.parseOpen(node);
  9834. return true;
  9835. }
  9836. switch (node.name) {
  9837. case this.tag:
  9838. this.reset();
  9839. this.model = {
  9840. anchors: []
  9841. };
  9842. break;
  9843. default:
  9844. this.parser = this.map[node.name];
  9845. if (this.parser) {
  9846. this.parser.parseOpen(node);
  9847. }
  9848. break;
  9849. }
  9850. return true;
  9851. }
  9852. }, {
  9853. key: "parseText",
  9854. value: function parseText(text) {
  9855. if (this.parser) {
  9856. this.parser.parseText(text);
  9857. }
  9858. }
  9859. }, {
  9860. key: "parseClose",
  9861. value: function parseClose(name) {
  9862. if (this.parser) {
  9863. if (!this.parser.parseClose(name)) {
  9864. this.model.anchors.push(this.parser.model);
  9865. this.parser = undefined;
  9866. }
  9867. return true;
  9868. }
  9869. switch (name) {
  9870. case this.tag:
  9871. return false;
  9872. default:
  9873. // could be some unrecognised tags
  9874. return true;
  9875. }
  9876. }
  9877. }, {
  9878. key: "reconcile",
  9879. value: function reconcile(model, options) {
  9880. var _this4 = this;
  9881. model.anchors.forEach(function (anchor) {
  9882. if (anchor.br) {
  9883. _this4.map['xdr:twoCellAnchor'].reconcile(anchor, options);
  9884. } else {
  9885. _this4.map['xdr:oneCellAnchor'].reconcile(anchor, options);
  9886. }
  9887. });
  9888. }
  9889. }, {
  9890. key: "tag",
  9891. get: function get() {
  9892. return 'xdr:wsDr';
  9893. }
  9894. }]);
  9895. return DrawingXform;
  9896. }(BaseXform);
  9897. DrawingXform.DRAWING_ATTRIBUTES = {
  9898. 'xmlns:xdr': 'http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing',
  9899. 'xmlns:a': 'http://schemas.openxmlformats.org/drawingml/2006/main'
  9900. };
  9901. module.exports = DrawingXform;
  9902. },{"../../../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){
  9903. "use strict";
  9904. 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); }
  9905. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9906. 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); } }
  9907. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9908. 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); }
  9909. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9910. 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); }; }
  9911. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  9912. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9913. 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; } }
  9914. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9915. var BaseXform = require('../base-xform');
  9916. var ExtLstXform = /*#__PURE__*/function (_BaseXform) {
  9917. _inherits(ExtLstXform, _BaseXform);
  9918. var _super = _createSuper(ExtLstXform);
  9919. function ExtLstXform() {
  9920. _classCallCheck(this, ExtLstXform);
  9921. return _super.apply(this, arguments);
  9922. }
  9923. _createClass(ExtLstXform, [{
  9924. key: "render",
  9925. value: function render(xmlStream) {
  9926. xmlStream.openNode(this.tag);
  9927. xmlStream.openNode('a:ext', {
  9928. uri: '{FF2B5EF4-FFF2-40B4-BE49-F238E27FC236}'
  9929. });
  9930. xmlStream.leafNode('a16:creationId', {
  9931. 'xmlns:a16': 'http://schemas.microsoft.com/office/drawing/2014/main',
  9932. id: '{00000000-0008-0000-0000-000002000000}'
  9933. });
  9934. xmlStream.closeNode();
  9935. xmlStream.closeNode();
  9936. }
  9937. }, {
  9938. key: "parseOpen",
  9939. value: function parseOpen(node) {
  9940. switch (node.name) {
  9941. case this.tag:
  9942. return true;
  9943. default:
  9944. return true;
  9945. }
  9946. }
  9947. }, {
  9948. key: "parseText",
  9949. value: function parseText() {}
  9950. }, {
  9951. key: "parseClose",
  9952. value: function parseClose(name) {
  9953. switch (name) {
  9954. case this.tag:
  9955. return false;
  9956. default:
  9957. // unprocessed internal nodes
  9958. return true;
  9959. }
  9960. }
  9961. }, {
  9962. key: "tag",
  9963. get: function get() {
  9964. return 'a:extLst';
  9965. }
  9966. }]);
  9967. return ExtLstXform;
  9968. }(BaseXform);
  9969. module.exports = ExtLstXform;
  9970. },{"../base-xform":31}],63:[function(require,module,exports){
  9971. "use strict";
  9972. 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); }
  9973. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9974. 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); } }
  9975. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9976. 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); }
  9977. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9978. 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); }; }
  9979. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  9980. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9981. 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; } }
  9982. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9983. var BaseXform = require('../base-xform');
  9984. /** https://en.wikipedia.org/wiki/Office_Open_XML_file_formats#DrawingML */
  9985. var EMU_PER_PIXEL_AT_96_DPI = 9525;
  9986. var ExtXform = /*#__PURE__*/function (_BaseXform) {
  9987. _inherits(ExtXform, _BaseXform);
  9988. var _super = _createSuper(ExtXform);
  9989. function ExtXform(options) {
  9990. var _this;
  9991. _classCallCheck(this, ExtXform);
  9992. _this = _super.call(this);
  9993. _this.tag = options.tag;
  9994. _this.map = {};
  9995. return _this;
  9996. }
  9997. _createClass(ExtXform, [{
  9998. key: "render",
  9999. value: function render(xmlStream, model) {
  10000. xmlStream.openNode(this.tag);
  10001. var width = Math.floor(model.width * EMU_PER_PIXEL_AT_96_DPI);
  10002. var height = Math.floor(model.height * EMU_PER_PIXEL_AT_96_DPI);
  10003. xmlStream.addAttribute('cx', width);
  10004. xmlStream.addAttribute('cy', height);
  10005. xmlStream.closeNode();
  10006. }
  10007. }, {
  10008. key: "parseOpen",
  10009. value: function parseOpen(node) {
  10010. if (node.name === this.tag) {
  10011. this.model = {
  10012. width: parseInt(node.attributes.cx || '0', 10) / EMU_PER_PIXEL_AT_96_DPI,
  10013. height: parseInt(node.attributes.cy || '0', 10) / EMU_PER_PIXEL_AT_96_DPI
  10014. };
  10015. return true;
  10016. }
  10017. return false;
  10018. }
  10019. }, {
  10020. key: "parseText",
  10021. value: function parseText()
  10022. /* text */
  10023. {}
  10024. }, {
  10025. key: "parseClose",
  10026. value: function parseClose()
  10027. /* name */
  10028. {
  10029. return false;
  10030. }
  10031. }]);
  10032. return ExtXform;
  10033. }(BaseXform);
  10034. module.exports = ExtXform;
  10035. },{"../base-xform":31}],64:[function(require,module,exports){
  10036. "use strict";
  10037. 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); }
  10038. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10039. 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); } }
  10040. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  10041. 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); }
  10042. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  10043. 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); }; }
  10044. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  10045. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  10046. 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; } }
  10047. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  10048. var BaseXform = require('../base-xform');
  10049. var HLinkClickXform = /*#__PURE__*/function (_BaseXform) {
  10050. _inherits(HLinkClickXform, _BaseXform);
  10051. var _super = _createSuper(HLinkClickXform);
  10052. function HLinkClickXform() {
  10053. _classCallCheck(this, HLinkClickXform);
  10054. return _super.apply(this, arguments);
  10055. }
  10056. _createClass(HLinkClickXform, [{
  10057. key: "render",
  10058. value: function render(xmlStream, model) {
  10059. if (!(model.hyperlinks && model.hyperlinks.rId)) {
  10060. return;
  10061. }
  10062. xmlStream.leafNode(this.tag, {
  10063. 'xmlns:r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
  10064. 'r:id': model.hyperlinks.rId,
  10065. tooltip: model.hyperlinks.tooltip
  10066. });
  10067. }
  10068. }, {
  10069. key: "parseOpen",
  10070. value: function parseOpen(node) {
  10071. switch (node.name) {
  10072. case this.tag:
  10073. this.model = {
  10074. hyperlinks: {
  10075. rId: node.attributes['r:id'],
  10076. tooltip: node.attributes.tooltip
  10077. }
  10078. };
  10079. return true;
  10080. default:
  10081. return true;
  10082. }
  10083. }
  10084. }, {
  10085. key: "parseText",
  10086. value: function parseText() {}
  10087. }, {
  10088. key: "parseClose",
  10089. value: function parseClose() {
  10090. return false;
  10091. }
  10092. }, {
  10093. key: "tag",
  10094. get: function get() {
  10095. return 'a:hlinkClick';
  10096. }
  10097. }]);
  10098. return HLinkClickXform;
  10099. }(BaseXform);
  10100. module.exports = HLinkClickXform;
  10101. },{"../base-xform":31}],65:[function(require,module,exports){
  10102. "use strict";
  10103. 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); }
  10104. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10105. 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); } }
  10106. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  10107. 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); }
  10108. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  10109. 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); }; }
  10110. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  10111. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  10112. 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; } }
  10113. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  10114. var BaseXform = require('../base-xform');
  10115. var CNvPrXform = require('./c-nv-pr-xform');
  10116. var CNvPicPrXform = require('./c-nv-pic-pr-xform');
  10117. var NvPicPrXform = /*#__PURE__*/function (_BaseXform) {
  10118. _inherits(NvPicPrXform, _BaseXform);
  10119. var _super = _createSuper(NvPicPrXform);
  10120. function NvPicPrXform() {
  10121. var _this;
  10122. _classCallCheck(this, NvPicPrXform);
  10123. _this = _super.call(this);
  10124. _this.map = {
  10125. 'xdr:cNvPr': new CNvPrXform(),
  10126. 'xdr:cNvPicPr': new CNvPicPrXform()
  10127. };
  10128. return _this;
  10129. }
  10130. _createClass(NvPicPrXform, [{
  10131. key: "render",
  10132. value: function render(xmlStream, model) {
  10133. xmlStream.openNode(this.tag);
  10134. this.map['xdr:cNvPr'].render(xmlStream, model);
  10135. this.map['xdr:cNvPicPr'].render(xmlStream, model);
  10136. xmlStream.closeNode();
  10137. }
  10138. }, {
  10139. key: "parseOpen",
  10140. value: function parseOpen(node) {
  10141. if (this.parser) {
  10142. this.parser.parseOpen(node);
  10143. return true;
  10144. }
  10145. switch (node.name) {
  10146. case this.tag:
  10147. this.reset();
  10148. break;
  10149. default:
  10150. this.parser = this.map[node.name];
  10151. if (this.parser) {
  10152. this.parser.parseOpen(node);
  10153. }
  10154. break;
  10155. }
  10156. return true;
  10157. }
  10158. }, {
  10159. key: "parseText",
  10160. value: function parseText() {}
  10161. }, {
  10162. key: "parseClose",
  10163. value: function parseClose(name) {
  10164. if (this.parser) {
  10165. if (!this.parser.parseClose(name)) {
  10166. this.parser = undefined;
  10167. }
  10168. return true;
  10169. }
  10170. switch (name) {
  10171. case this.tag:
  10172. this.model = this.map['xdr:cNvPr'].model;
  10173. return false;
  10174. default:
  10175. return true;
  10176. }
  10177. }
  10178. }, {
  10179. key: "tag",
  10180. get: function get() {
  10181. return 'xdr:nvPicPr';
  10182. }
  10183. }]);
  10184. return NvPicPrXform;
  10185. }(BaseXform);
  10186. module.exports = NvPicPrXform;
  10187. },{"../base-xform":31,"./c-nv-pic-pr-xform":58,"./c-nv-pr-xform":59}],66:[function(require,module,exports){
  10188. "use strict";
  10189. 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); }
  10190. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10191. 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); } }
  10192. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  10193. 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); }
  10194. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  10195. 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); }; }
  10196. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  10197. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  10198. 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; } }
  10199. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  10200. var BaseCellAnchorXform = require('./base-cell-anchor-xform');
  10201. var StaticXform = require('../static-xform');
  10202. var CellPositionXform = require('./cell-position-xform');
  10203. var ExtXform = require('./ext-xform');
  10204. var PicXform = require('./pic-xform');
  10205. var OneCellAnchorXform = /*#__PURE__*/function (_BaseCellAnchorXform) {
  10206. _inherits(OneCellAnchorXform, _BaseCellAnchorXform);
  10207. var _super = _createSuper(OneCellAnchorXform);
  10208. function OneCellAnchorXform() {
  10209. var _this;
  10210. _classCallCheck(this, OneCellAnchorXform);
  10211. _this = _super.call(this);
  10212. _this.map = {
  10213. 'xdr:from': new CellPositionXform({
  10214. tag: 'xdr:from'
  10215. }),
  10216. 'xdr:ext': new ExtXform({
  10217. tag: 'xdr:ext'
  10218. }),
  10219. 'xdr:pic': new PicXform(),
  10220. 'xdr:clientData': new StaticXform({
  10221. tag: 'xdr:clientData'
  10222. })
  10223. };
  10224. return _this;
  10225. }
  10226. _createClass(OneCellAnchorXform, [{
  10227. key: "prepare",
  10228. value: function prepare(model, options) {
  10229. this.map['xdr:pic'].prepare(model.picture, options);
  10230. }
  10231. }, {
  10232. key: "render",
  10233. value: function render(xmlStream, model) {
  10234. xmlStream.openNode(this.tag, {
  10235. editAs: model.range.editAs || 'oneCell'
  10236. });
  10237. this.map['xdr:from'].render(xmlStream, model.range.tl);
  10238. this.map['xdr:ext'].render(xmlStream, model.range.ext);
  10239. this.map['xdr:pic'].render(xmlStream, model.picture);
  10240. this.map['xdr:clientData'].render(xmlStream, {});
  10241. xmlStream.closeNode();
  10242. }
  10243. }, {
  10244. key: "parseClose",
  10245. value: function parseClose(name) {
  10246. if (this.parser) {
  10247. if (!this.parser.parseClose(name)) {
  10248. this.parser = undefined;
  10249. }
  10250. return true;
  10251. }
  10252. switch (name) {
  10253. case this.tag:
  10254. this.model.range.tl = this.map['xdr:from'].model;
  10255. this.model.range.ext = this.map['xdr:ext'].model;
  10256. this.model.picture = this.map['xdr:pic'].model;
  10257. return false;
  10258. default:
  10259. // could be some unrecognised tags
  10260. return true;
  10261. }
  10262. }
  10263. }, {
  10264. key: "reconcile",
  10265. value: function reconcile(model, options) {
  10266. model.medium = this.reconcilePicture(model.picture, options);
  10267. }
  10268. }, {
  10269. key: "tag",
  10270. get: function get() {
  10271. return 'xdr:oneCellAnchor';
  10272. }
  10273. }]);
  10274. return OneCellAnchorXform;
  10275. }(BaseCellAnchorXform);
  10276. module.exports = OneCellAnchorXform;
  10277. },{"../static-xform":119,"./base-cell-anchor-xform":55,"./cell-position-xform":60,"./ext-xform":63,"./pic-xform":67}],67:[function(require,module,exports){
  10278. "use strict";
  10279. 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); }
  10280. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10281. 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); } }
  10282. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  10283. 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); }
  10284. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  10285. 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); }; }
  10286. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  10287. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  10288. 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; } }
  10289. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  10290. var BaseXform = require('../base-xform');
  10291. var StaticXform = require('../static-xform');
  10292. var BlipFillXform = require('./blip-fill-xform');
  10293. var NvPicPrXform = require('./nv-pic-pr-xform');
  10294. var spPrJSON = require('./sp-pr');
  10295. var PicXform = /*#__PURE__*/function (_BaseXform) {
  10296. _inherits(PicXform, _BaseXform);
  10297. var _super = _createSuper(PicXform);
  10298. function PicXform() {
  10299. var _this;
  10300. _classCallCheck(this, PicXform);
  10301. _this = _super.call(this);
  10302. _this.map = {
  10303. 'xdr:nvPicPr': new NvPicPrXform(),
  10304. 'xdr:blipFill': new BlipFillXform(),
  10305. 'xdr:spPr': new StaticXform(spPrJSON)
  10306. };
  10307. return _this;
  10308. }
  10309. _createClass(PicXform, [{
  10310. key: "prepare",
  10311. value: function prepare(model, options) {
  10312. model.index = options.index + 1;
  10313. }
  10314. }, {
  10315. key: "render",
  10316. value: function render(xmlStream, model) {
  10317. xmlStream.openNode(this.tag);
  10318. this.map['xdr:nvPicPr'].render(xmlStream, model);
  10319. this.map['xdr:blipFill'].render(xmlStream, model);
  10320. this.map['xdr:spPr'].render(xmlStream, model);
  10321. xmlStream.closeNode();
  10322. }
  10323. }, {
  10324. key: "parseOpen",
  10325. value: function parseOpen(node) {
  10326. if (this.parser) {
  10327. this.parser.parseOpen(node);
  10328. return true;
  10329. }
  10330. switch (node.name) {
  10331. case this.tag:
  10332. this.reset();
  10333. break;
  10334. default:
  10335. this.parser = this.map[node.name];
  10336. if (this.parser) {
  10337. this.parser.parseOpen(node);
  10338. }
  10339. break;
  10340. }
  10341. return true;
  10342. }
  10343. }, {
  10344. key: "parseText",
  10345. value: function parseText() {}
  10346. }, {
  10347. key: "parseClose",
  10348. value: function parseClose(name) {
  10349. if (this.parser) {
  10350. if (!this.parser.parseClose(name)) {
  10351. this.mergeModel(this.parser.model);
  10352. this.parser = undefined;
  10353. }
  10354. return true;
  10355. }
  10356. switch (name) {
  10357. case this.tag:
  10358. return false;
  10359. default:
  10360. // not quite sure how we get here!
  10361. return true;
  10362. }
  10363. }
  10364. }, {
  10365. key: "tag",
  10366. get: function get() {
  10367. return 'xdr:pic';
  10368. }
  10369. }]);
  10370. return PicXform;
  10371. }(BaseXform);
  10372. module.exports = PicXform;
  10373. },{"../base-xform":31,"../static-xform":119,"./blip-fill-xform":56,"./nv-pic-pr-xform":65,"./sp-pr":68}],68:[function(require,module,exports){
  10374. "use strict";
  10375. module.exports = {
  10376. tag: 'xdr:spPr',
  10377. c: [{
  10378. tag: 'a:xfrm',
  10379. c: [{
  10380. tag: 'a:off',
  10381. $: {
  10382. x: '0',
  10383. y: '0'
  10384. }
  10385. }, {
  10386. tag: 'a:ext',
  10387. $: {
  10388. cx: '0',
  10389. cy: '0'
  10390. }
  10391. }]
  10392. }, {
  10393. tag: 'a:prstGeom',
  10394. $: {
  10395. prst: 'rect'
  10396. },
  10397. c: [{
  10398. tag: 'a:avLst'
  10399. }]
  10400. }]
  10401. };
  10402. },{}],69:[function(require,module,exports){
  10403. "use strict";
  10404. 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); }
  10405. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10406. 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); } }
  10407. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  10408. 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); }
  10409. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  10410. 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); }; }
  10411. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  10412. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  10413. 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; } }
  10414. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  10415. var BaseCellAnchorXform = require('./base-cell-anchor-xform');
  10416. var StaticXform = require('../static-xform');
  10417. var CellPositionXform = require('./cell-position-xform');
  10418. var PicXform = require('./pic-xform');
  10419. var TwoCellAnchorXform = /*#__PURE__*/function (_BaseCellAnchorXform) {
  10420. _inherits(TwoCellAnchorXform, _BaseCellAnchorXform);
  10421. var _super = _createSuper(TwoCellAnchorXform);
  10422. function TwoCellAnchorXform() {
  10423. var _this;
  10424. _classCallCheck(this, TwoCellAnchorXform);
  10425. _this = _super.call(this);
  10426. _this.map = {
  10427. 'xdr:from': new CellPositionXform({
  10428. tag: 'xdr:from'
  10429. }),
  10430. 'xdr:to': new CellPositionXform({
  10431. tag: 'xdr:to'
  10432. }),
  10433. 'xdr:pic': new PicXform(),
  10434. 'xdr:clientData': new StaticXform({
  10435. tag: 'xdr:clientData'
  10436. })
  10437. };
  10438. return _this;
  10439. }
  10440. _createClass(TwoCellAnchorXform, [{
  10441. key: "prepare",
  10442. value: function prepare(model, options) {
  10443. this.map['xdr:pic'].prepare(model.picture, options);
  10444. }
  10445. }, {
  10446. key: "render",
  10447. value: function render(xmlStream, model) {
  10448. xmlStream.openNode(this.tag, {
  10449. editAs: model.range.editAs || 'oneCell'
  10450. });
  10451. this.map['xdr:from'].render(xmlStream, model.range.tl);
  10452. this.map['xdr:to'].render(xmlStream, model.range.br);
  10453. this.map['xdr:pic'].render(xmlStream, model.picture);
  10454. this.map['xdr:clientData'].render(xmlStream, {});
  10455. xmlStream.closeNode();
  10456. }
  10457. }, {
  10458. key: "parseClose",
  10459. value: function parseClose(name) {
  10460. if (this.parser) {
  10461. if (!this.parser.parseClose(name)) {
  10462. this.parser = undefined;
  10463. }
  10464. return true;
  10465. }
  10466. switch (name) {
  10467. case this.tag:
  10468. this.model.range.tl = this.map['xdr:from'].model;
  10469. this.model.range.br = this.map['xdr:to'].model;
  10470. this.model.picture = this.map['xdr:pic'].model;
  10471. return false;
  10472. default:
  10473. // could be some unrecognised tags
  10474. return true;
  10475. }
  10476. }
  10477. }, {
  10478. key: "reconcile",
  10479. value: function reconcile(model, options) {
  10480. model.medium = this.reconcilePicture(model.picture, options);
  10481. }
  10482. }, {
  10483. key: "tag",
  10484. get: function get() {
  10485. return 'xdr:twoCellAnchor';
  10486. }
  10487. }]);
  10488. return TwoCellAnchorXform;
  10489. }(BaseCellAnchorXform);
  10490. module.exports = TwoCellAnchorXform;
  10491. },{"../static-xform":119,"./base-cell-anchor-xform":55,"./cell-position-xform":60,"./pic-xform":67}],70:[function(require,module,exports){
  10492. "use strict";
  10493. 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); }
  10494. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10495. 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); } }
  10496. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  10497. 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); }
  10498. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  10499. 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); }; }
  10500. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  10501. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  10502. 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; } }
  10503. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  10504. var BaseXform = require('./base-xform');
  10505. var ListXform = /*#__PURE__*/function (_BaseXform) {
  10506. _inherits(ListXform, _BaseXform);
  10507. var _super = _createSuper(ListXform);
  10508. function ListXform(options) {
  10509. var _this;
  10510. _classCallCheck(this, ListXform);
  10511. _this = _super.call(this);
  10512. _this.tag = options.tag;
  10513. _this.always = !!options.always;
  10514. _this.count = options.count;
  10515. _this.empty = options.empty;
  10516. _this.$count = options.$count || 'count';
  10517. _this.$ = options.$;
  10518. _this.childXform = options.childXform;
  10519. _this.maxItems = options.maxItems;
  10520. return _this;
  10521. }
  10522. _createClass(ListXform, [{
  10523. key: "prepare",
  10524. value: function prepare(model, options) {
  10525. var childXform = this.childXform;
  10526. if (model) {
  10527. model.forEach(function (childModel, index) {
  10528. options.index = index;
  10529. childXform.prepare(childModel, options);
  10530. });
  10531. }
  10532. }
  10533. }, {
  10534. key: "render",
  10535. value: function render(xmlStream, model) {
  10536. if (this.always || model && model.length) {
  10537. xmlStream.openNode(this.tag, this.$);
  10538. if (this.count) {
  10539. xmlStream.addAttribute(this.$count, model && model.length || 0);
  10540. }
  10541. var childXform = this.childXform;
  10542. (model || []).forEach(function (childModel, index) {
  10543. childXform.render(xmlStream, childModel, index);
  10544. });
  10545. xmlStream.closeNode();
  10546. } else if (this.empty) {
  10547. xmlStream.leafNode(this.tag);
  10548. }
  10549. }
  10550. }, {
  10551. key: "parseOpen",
  10552. value: function parseOpen(node) {
  10553. if (this.parser) {
  10554. this.parser.parseOpen(node);
  10555. return true;
  10556. }
  10557. switch (node.name) {
  10558. case this.tag:
  10559. this.model = [];
  10560. return true;
  10561. default:
  10562. if (this.childXform.parseOpen(node)) {
  10563. this.parser = this.childXform;
  10564. return true;
  10565. }
  10566. return false;
  10567. }
  10568. }
  10569. }, {
  10570. key: "parseText",
  10571. value: function parseText(text) {
  10572. if (this.parser) {
  10573. this.parser.parseText(text);
  10574. }
  10575. }
  10576. }, {
  10577. key: "parseClose",
  10578. value: function parseClose(name) {
  10579. if (this.parser) {
  10580. if (!this.parser.parseClose(name)) {
  10581. this.model.push(this.parser.model);
  10582. this.parser = undefined;
  10583. if (this.maxItems && this.model.length > this.maxItems) {
  10584. throw new Error("Max ".concat(this.childXform.tag, " count (").concat(this.maxItems, ") exceeded"));
  10585. }
  10586. }
  10587. return true;
  10588. }
  10589. return false;
  10590. }
  10591. }, {
  10592. key: "reconcile",
  10593. value: function reconcile(model, options) {
  10594. if (model) {
  10595. var childXform = this.childXform;
  10596. model.forEach(function (childModel) {
  10597. childXform.reconcile(childModel, options);
  10598. });
  10599. }
  10600. }
  10601. }]);
  10602. return ListXform;
  10603. }(BaseXform);
  10604. module.exports = ListXform;
  10605. },{"./base-xform":31}],71:[function(require,module,exports){
  10606. "use strict";
  10607. 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); }
  10608. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10609. 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); } }
  10610. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  10611. 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); }
  10612. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  10613. 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); }; }
  10614. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  10615. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  10616. 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; } }
  10617. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  10618. var colCache = require('../../../utils/col-cache');
  10619. var BaseXform = require('../base-xform');
  10620. var AutoFilterXform = /*#__PURE__*/function (_BaseXform) {
  10621. _inherits(AutoFilterXform, _BaseXform);
  10622. var _super = _createSuper(AutoFilterXform);
  10623. function AutoFilterXform() {
  10624. _classCallCheck(this, AutoFilterXform);
  10625. return _super.apply(this, arguments);
  10626. }
  10627. _createClass(AutoFilterXform, [{
  10628. key: "render",
  10629. value: function render(xmlStream, model) {
  10630. if (model) {
  10631. if (typeof model === 'string') {
  10632. // assume range
  10633. xmlStream.leafNode('autoFilter', {
  10634. ref: model
  10635. });
  10636. } else {
  10637. var getAddress = function getAddress(addr) {
  10638. if (typeof addr === 'string') {
  10639. return addr;
  10640. }
  10641. return colCache.getAddress(addr.row, addr.column).address;
  10642. };
  10643. var firstAddress = getAddress(model.from);
  10644. var secondAddress = getAddress(model.to);
  10645. if (firstAddress && secondAddress) {
  10646. xmlStream.leafNode('autoFilter', {
  10647. ref: "".concat(firstAddress, ":").concat(secondAddress)
  10648. });
  10649. }
  10650. }
  10651. }
  10652. }
  10653. }, {
  10654. key: "parseOpen",
  10655. value: function parseOpen(node) {
  10656. if (node.name === 'autoFilter') {
  10657. this.model = node.attributes.ref;
  10658. }
  10659. }
  10660. }, {
  10661. key: "tag",
  10662. get: function get() {
  10663. return 'autoFilter';
  10664. }
  10665. }]);
  10666. return AutoFilterXform;
  10667. }(BaseXform);
  10668. module.exports = AutoFilterXform;
  10669. },{"../../../utils/col-cache":19,"../base-xform":31}],72:[function(require,module,exports){
  10670. "use strict";
  10671. 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); }
  10672. 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; }
  10673. 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; }
  10674. 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; }
  10675. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10676. 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); } }
  10677. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  10678. 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); }
  10679. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  10680. 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); }; }
  10681. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  10682. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  10683. 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; } }
  10684. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  10685. var utils = require('../../../utils/utils');
  10686. var BaseXform = require('../base-xform');
  10687. var Range = require('../../../doc/range');
  10688. var Enums = require('../../../doc/enums');
  10689. var RichTextXform = require('../strings/rich-text-xform');
  10690. function getValueType(v) {
  10691. if (v === null || v === undefined) {
  10692. return Enums.ValueType.Null;
  10693. }
  10694. if (v instanceof String || typeof v === 'string') {
  10695. return Enums.ValueType.String;
  10696. }
  10697. if (typeof v === 'number') {
  10698. return Enums.ValueType.Number;
  10699. }
  10700. if (typeof v === 'boolean') {
  10701. return Enums.ValueType.Boolean;
  10702. }
  10703. if (v instanceof Date) {
  10704. return Enums.ValueType.Date;
  10705. }
  10706. if (v.text && v.hyperlink) {
  10707. return Enums.ValueType.Hyperlink;
  10708. }
  10709. if (v.formula) {
  10710. return Enums.ValueType.Formula;
  10711. }
  10712. if (v.error) {
  10713. return Enums.ValueType.Error;
  10714. }
  10715. throw new Error('I could not understand type of value');
  10716. }
  10717. function getEffectiveCellType(cell) {
  10718. switch (cell.type) {
  10719. case Enums.ValueType.Formula:
  10720. return getValueType(cell.result);
  10721. default:
  10722. return cell.type;
  10723. }
  10724. }
  10725. var CellXform = /*#__PURE__*/function (_BaseXform) {
  10726. _inherits(CellXform, _BaseXform);
  10727. var _super = _createSuper(CellXform);
  10728. function CellXform() {
  10729. var _this;
  10730. _classCallCheck(this, CellXform);
  10731. _this = _super.call(this);
  10732. _this.richTextXForm = new RichTextXform();
  10733. return _this;
  10734. }
  10735. _createClass(CellXform, [{
  10736. key: "prepare",
  10737. value: function prepare(model, options) {
  10738. var styleId = options.styles.addStyleModel(model.style || {}, getEffectiveCellType(model));
  10739. if (styleId) {
  10740. model.styleId = styleId;
  10741. }
  10742. if (model.comment) {
  10743. options.comments.push(_objectSpread(_objectSpread({}, model.comment), {}, {
  10744. ref: model.address
  10745. }));
  10746. }
  10747. switch (model.type) {
  10748. case Enums.ValueType.String:
  10749. case Enums.ValueType.RichText:
  10750. if (options.sharedStrings) {
  10751. model.ssId = options.sharedStrings.add(model.value);
  10752. }
  10753. break;
  10754. case Enums.ValueType.Date:
  10755. if (options.date1904) {
  10756. model.date1904 = true;
  10757. }
  10758. break;
  10759. case Enums.ValueType.Hyperlink:
  10760. if (options.sharedStrings && model.text !== undefined && model.text !== null) {
  10761. model.ssId = options.sharedStrings.add(model.text);
  10762. }
  10763. options.hyperlinks.push({
  10764. address: model.address,
  10765. target: model.hyperlink,
  10766. tooltip: model.tooltip
  10767. });
  10768. break;
  10769. case Enums.ValueType.Merge:
  10770. options.merges.add(model);
  10771. break;
  10772. case Enums.ValueType.Formula:
  10773. if (options.date1904) {
  10774. // in case valueType is date
  10775. model.date1904 = true;
  10776. }
  10777. if (model.shareType === 'shared') {
  10778. model.si = options.siFormulae++;
  10779. }
  10780. if (model.formula) {
  10781. options.formulae[model.address] = model;
  10782. } else if (model.sharedFormula) {
  10783. var master = options.formulae[model.sharedFormula];
  10784. if (!master) {
  10785. throw new Error("Shared Formula master must exist above and or left of clone for cell ".concat(model.address));
  10786. }
  10787. if (master.si === undefined) {
  10788. master.shareType = 'shared';
  10789. master.si = options.siFormulae++;
  10790. master.range = new Range(master.address, model.address);
  10791. } else if (master.range) {
  10792. master.range.expandToAddress(model.address);
  10793. }
  10794. model.si = master.si;
  10795. }
  10796. break;
  10797. default:
  10798. break;
  10799. }
  10800. }
  10801. }, {
  10802. key: "renderFormula",
  10803. value: function renderFormula(xmlStream, model) {
  10804. var attrs = null;
  10805. switch (model.shareType) {
  10806. case 'shared':
  10807. attrs = {
  10808. t: 'shared',
  10809. ref: model.ref || model.range.range,
  10810. si: model.si
  10811. };
  10812. break;
  10813. case 'array':
  10814. attrs = {
  10815. t: 'array',
  10816. ref: model.ref
  10817. };
  10818. break;
  10819. default:
  10820. if (model.si !== undefined) {
  10821. attrs = {
  10822. t: 'shared',
  10823. si: model.si
  10824. };
  10825. }
  10826. break;
  10827. }
  10828. switch (getValueType(model.result)) {
  10829. case Enums.ValueType.Null:
  10830. // ?
  10831. xmlStream.leafNode('f', attrs, model.formula);
  10832. break;
  10833. case Enums.ValueType.String:
  10834. // oddly, formula results don't ever use shared strings
  10835. xmlStream.addAttribute('t', 'str');
  10836. xmlStream.leafNode('f', attrs, model.formula);
  10837. xmlStream.leafNode('v', null, model.result);
  10838. break;
  10839. case Enums.ValueType.Number:
  10840. xmlStream.leafNode('f', attrs, model.formula);
  10841. xmlStream.leafNode('v', null, model.result);
  10842. break;
  10843. case Enums.ValueType.Boolean:
  10844. xmlStream.addAttribute('t', 'b');
  10845. xmlStream.leafNode('f', attrs, model.formula);
  10846. xmlStream.leafNode('v', null, model.result ? 1 : 0);
  10847. break;
  10848. case Enums.ValueType.Error:
  10849. xmlStream.addAttribute('t', 'e');
  10850. xmlStream.leafNode('f', attrs, model.formula);
  10851. xmlStream.leafNode('v', null, model.result.error);
  10852. break;
  10853. case Enums.ValueType.Date:
  10854. xmlStream.leafNode('f', attrs, model.formula);
  10855. xmlStream.leafNode('v', null, utils.dateToExcel(model.result, model.date1904));
  10856. break;
  10857. // case Enums.ValueType.Hyperlink: // ??
  10858. // case Enums.ValueType.Formula:
  10859. default:
  10860. throw new Error('I could not understand type of value');
  10861. }
  10862. }
  10863. }, {
  10864. key: "render",
  10865. value: function render(xmlStream, model) {
  10866. var _this2 = this;
  10867. if (model.type === Enums.ValueType.Null && !model.styleId) {
  10868. // if null and no style, exit
  10869. return;
  10870. }
  10871. xmlStream.openNode('c');
  10872. xmlStream.addAttribute('r', model.address);
  10873. if (model.styleId) {
  10874. xmlStream.addAttribute('s', model.styleId);
  10875. }
  10876. switch (model.type) {
  10877. case Enums.ValueType.Null:
  10878. break;
  10879. case Enums.ValueType.Number:
  10880. xmlStream.leafNode('v', null, model.value);
  10881. break;
  10882. case Enums.ValueType.Boolean:
  10883. xmlStream.addAttribute('t', 'b');
  10884. xmlStream.leafNode('v', null, model.value ? '1' : '0');
  10885. break;
  10886. case Enums.ValueType.Error:
  10887. xmlStream.addAttribute('t', 'e');
  10888. xmlStream.leafNode('v', null, model.value.error);
  10889. break;
  10890. case Enums.ValueType.String:
  10891. case Enums.ValueType.RichText:
  10892. if (model.ssId !== undefined) {
  10893. xmlStream.addAttribute('t', 's');
  10894. xmlStream.leafNode('v', null, model.ssId);
  10895. } else if (model.value && model.value.richText) {
  10896. xmlStream.addAttribute('t', 'inlineStr');
  10897. xmlStream.openNode('is');
  10898. model.value.richText.forEach(function (text) {
  10899. _this2.richTextXForm.render(xmlStream, text);
  10900. });
  10901. xmlStream.closeNode('is');
  10902. } else {
  10903. xmlStream.addAttribute('t', 'str');
  10904. xmlStream.leafNode('v', null, model.value);
  10905. }
  10906. break;
  10907. case Enums.ValueType.Date:
  10908. xmlStream.leafNode('v', null, utils.dateToExcel(model.value, model.date1904));
  10909. break;
  10910. case Enums.ValueType.Hyperlink:
  10911. if (model.ssId !== undefined) {
  10912. xmlStream.addAttribute('t', 's');
  10913. xmlStream.leafNode('v', null, model.ssId);
  10914. } else {
  10915. xmlStream.addAttribute('t', 'str');
  10916. xmlStream.leafNode('v', null, model.text);
  10917. }
  10918. break;
  10919. case Enums.ValueType.Formula:
  10920. this.renderFormula(xmlStream, model);
  10921. break;
  10922. case Enums.ValueType.Merge:
  10923. // nothing to add
  10924. break;
  10925. default:
  10926. break;
  10927. }
  10928. xmlStream.closeNode(); // </c>
  10929. }
  10930. }, {
  10931. key: "parseOpen",
  10932. value: function parseOpen(node) {
  10933. if (this.parser) {
  10934. this.parser.parseOpen(node);
  10935. return true;
  10936. }
  10937. switch (node.name) {
  10938. case 'c':
  10939. // const address = colCache.decodeAddress(node.attributes.r);
  10940. this.model = {
  10941. address: node.attributes.r
  10942. };
  10943. this.t = node.attributes.t;
  10944. if (node.attributes.s) {
  10945. this.model.styleId = parseInt(node.attributes.s, 10);
  10946. }
  10947. return true;
  10948. case 'f':
  10949. this.currentNode = 'f';
  10950. this.model.si = node.attributes.si;
  10951. this.model.shareType = node.attributes.t;
  10952. this.model.ref = node.attributes.ref;
  10953. return true;
  10954. case 'v':
  10955. this.currentNode = 'v';
  10956. return true;
  10957. case 't':
  10958. this.currentNode = 't';
  10959. return true;
  10960. case 'r':
  10961. this.parser = this.richTextXForm;
  10962. this.parser.parseOpen(node);
  10963. return true;
  10964. default:
  10965. return false;
  10966. }
  10967. }
  10968. }, {
  10969. key: "parseText",
  10970. value: function parseText(text) {
  10971. if (this.parser) {
  10972. this.parser.parseText(text);
  10973. return;
  10974. }
  10975. switch (this.currentNode) {
  10976. case 'f':
  10977. this.model.formula = this.model.formula ? this.model.formula + text : text;
  10978. break;
  10979. case 'v':
  10980. case 't':
  10981. if (this.model.value && this.model.value.richText) {
  10982. this.model.value.richText.text = this.model.value.richText.text ? this.model.value.richText.text + text : text;
  10983. } else {
  10984. this.model.value = this.model.value ? this.model.value + text : text;
  10985. }
  10986. break;
  10987. default:
  10988. break;
  10989. }
  10990. }
  10991. }, {
  10992. key: "parseClose",
  10993. value: function parseClose(name) {
  10994. switch (name) {
  10995. case 'c':
  10996. {
  10997. var model = this.model; // first guess on cell type
  10998. if (model.formula || model.shareType) {
  10999. model.type = Enums.ValueType.Formula;
  11000. if (model.value) {
  11001. if (this.t === 'str') {
  11002. model.result = utils.xmlDecode(model.value);
  11003. } else if (this.t === 'b') {
  11004. model.result = parseInt(model.value, 10) !== 0;
  11005. } else if (this.t === 'e') {
  11006. model.result = {
  11007. error: model.value
  11008. };
  11009. } else {
  11010. model.result = parseFloat(model.value);
  11011. }
  11012. model.value = undefined;
  11013. }
  11014. } else if (model.value !== undefined) {
  11015. switch (this.t) {
  11016. case 's':
  11017. model.type = Enums.ValueType.String;
  11018. model.value = parseInt(model.value, 10);
  11019. break;
  11020. case 'str':
  11021. model.type = Enums.ValueType.String;
  11022. model.value = utils.xmlDecode(model.value);
  11023. break;
  11024. case 'inlineStr':
  11025. model.type = Enums.ValueType.String;
  11026. break;
  11027. case 'b':
  11028. model.type = Enums.ValueType.Boolean;
  11029. model.value = parseInt(model.value, 10) !== 0;
  11030. break;
  11031. case 'e':
  11032. model.type = Enums.ValueType.Error;
  11033. model.value = {
  11034. error: model.value
  11035. };
  11036. break;
  11037. default:
  11038. model.type = Enums.ValueType.Number;
  11039. model.value = parseFloat(model.value);
  11040. break;
  11041. }
  11042. } else if (model.styleId) {
  11043. model.type = Enums.ValueType.Null;
  11044. } else {
  11045. model.type = Enums.ValueType.Merge;
  11046. }
  11047. return false;
  11048. }
  11049. case 'f':
  11050. case 'v':
  11051. case 'is':
  11052. this.currentNode = undefined;
  11053. return true;
  11054. case 't':
  11055. if (this.parser) {
  11056. this.parser.parseClose(name);
  11057. return true;
  11058. }
  11059. this.currentNode = undefined;
  11060. return true;
  11061. case 'r':
  11062. this.model.value = this.model.value || {};
  11063. this.model.value.richText = this.model.value.richText || [];
  11064. this.model.value.richText.push(this.parser.model);
  11065. this.parser = undefined;
  11066. this.currentNode = undefined;
  11067. return true;
  11068. default:
  11069. if (this.parser) {
  11070. this.parser.parseClose(name);
  11071. return true;
  11072. }
  11073. return false;
  11074. }
  11075. }
  11076. }, {
  11077. key: "reconcile",
  11078. value: function reconcile(model, options) {
  11079. var style = model.styleId && options.styles && options.styles.getStyleModel(model.styleId);
  11080. if (style) {
  11081. model.style = style;
  11082. }
  11083. if (model.styleId !== undefined) {
  11084. model.styleId = undefined;
  11085. }
  11086. switch (model.type) {
  11087. case Enums.ValueType.String:
  11088. if (typeof model.value === 'number') {
  11089. if (options.sharedStrings) {
  11090. model.value = options.sharedStrings.getString(model.value);
  11091. }
  11092. }
  11093. if (model.value.richText) {
  11094. model.type = Enums.ValueType.RichText;
  11095. }
  11096. break;
  11097. case Enums.ValueType.Number:
  11098. if (style && utils.isDateFmt(style.numFmt)) {
  11099. model.type = Enums.ValueType.Date;
  11100. model.value = utils.excelToDate(model.value, options.date1904);
  11101. }
  11102. break;
  11103. case Enums.ValueType.Formula:
  11104. if (model.result !== undefined && style && utils.isDateFmt(style.numFmt)) {
  11105. model.result = utils.excelToDate(model.result, options.date1904);
  11106. }
  11107. if (model.shareType === 'shared') {
  11108. if (model.ref) {
  11109. // master
  11110. options.formulae[model.si] = model.address;
  11111. } else {
  11112. // slave
  11113. model.sharedFormula = options.formulae[model.si];
  11114. delete model.shareType;
  11115. }
  11116. delete model.si;
  11117. }
  11118. break;
  11119. default:
  11120. break;
  11121. } // look for hyperlink
  11122. var hyperlink = options.hyperlinkMap[model.address];
  11123. if (hyperlink) {
  11124. if (model.type === Enums.ValueType.Formula) {
  11125. model.text = model.result;
  11126. model.result = undefined;
  11127. } else {
  11128. model.text = model.value;
  11129. model.value = undefined;
  11130. }
  11131. model.type = Enums.ValueType.Hyperlink;
  11132. model.hyperlink = hyperlink;
  11133. }
  11134. var comment = options.commentsMap && options.commentsMap[model.address];
  11135. if (comment) {
  11136. model.comment = comment;
  11137. }
  11138. }
  11139. }, {
  11140. key: "tag",
  11141. get: function get() {
  11142. return 'c';
  11143. }
  11144. }]);
  11145. return CellXform;
  11146. }(BaseXform);
  11147. module.exports = CellXform;
  11148. },{"../../../doc/enums":7,"../../../doc/range":10,"../../../utils/utils":26,"../base-xform":31,"../strings/rich-text-xform":121}],73:[function(require,module,exports){
  11149. "use strict";
  11150. 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); }
  11151. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11152. 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); } }
  11153. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11154. 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); }
  11155. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11156. 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); }; }
  11157. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  11158. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11159. 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; } }
  11160. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  11161. var BaseXform = require('../../base-xform');
  11162. var CfIconExtXform = /*#__PURE__*/function (_BaseXform) {
  11163. _inherits(CfIconExtXform, _BaseXform);
  11164. var _super = _createSuper(CfIconExtXform);
  11165. function CfIconExtXform() {
  11166. _classCallCheck(this, CfIconExtXform);
  11167. return _super.apply(this, arguments);
  11168. }
  11169. _createClass(CfIconExtXform, [{
  11170. key: "render",
  11171. value: function render(xmlStream, model) {
  11172. xmlStream.leafNode(this.tag, {
  11173. iconSet: model.iconSet,
  11174. iconId: model.iconId
  11175. });
  11176. }
  11177. }, {
  11178. key: "parseOpen",
  11179. value: function parseOpen(_ref) {
  11180. var attributes = _ref.attributes;
  11181. this.model = {
  11182. iconSet: attributes.iconSet,
  11183. iconId: BaseXform.toIntValue(attributes.iconId)
  11184. };
  11185. }
  11186. }, {
  11187. key: "parseClose",
  11188. value: function parseClose(name) {
  11189. return name !== this.tag;
  11190. }
  11191. }, {
  11192. key: "tag",
  11193. get: function get() {
  11194. return 'x14:cfIcon';
  11195. }
  11196. }]);
  11197. return CfIconExtXform;
  11198. }(BaseXform);
  11199. module.exports = CfIconExtXform;
  11200. },{"../../base-xform":31}],74:[function(require,module,exports){
  11201. "use strict";
  11202. 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); }
  11203. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11204. 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); } }
  11205. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11206. 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); }
  11207. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11208. 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); }; }
  11209. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  11210. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11211. 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; } }
  11212. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  11213. var _require = require('uuid'),
  11214. uuidv4 = _require.v4;
  11215. var BaseXform = require('../../base-xform');
  11216. var CompositeXform = require('../../composite-xform');
  11217. var DatabarExtXform = require('./databar-ext-xform');
  11218. var IconSetExtXform = require('./icon-set-ext-xform');
  11219. var extIcons = {
  11220. '3Triangles': true,
  11221. '3Stars': true,
  11222. '5Boxes': true
  11223. };
  11224. var CfRuleExtXform = /*#__PURE__*/function (_CompositeXform) {
  11225. _inherits(CfRuleExtXform, _CompositeXform);
  11226. var _super = _createSuper(CfRuleExtXform);
  11227. function CfRuleExtXform() {
  11228. var _this;
  11229. _classCallCheck(this, CfRuleExtXform);
  11230. _this = _super.call(this);
  11231. _this.map = {
  11232. 'x14:dataBar': _this.databarXform = new DatabarExtXform(),
  11233. 'x14:iconSet': _this.iconSetXform = new IconSetExtXform()
  11234. };
  11235. return _this;
  11236. }
  11237. _createClass(CfRuleExtXform, [{
  11238. key: "prepare",
  11239. value: function prepare(model) {
  11240. if (CfRuleExtXform.isExt(model)) {
  11241. model.x14Id = "{".concat(uuidv4(), "}").toUpperCase();
  11242. }
  11243. }
  11244. }, {
  11245. key: "render",
  11246. value: function render(xmlStream, model) {
  11247. if (!CfRuleExtXform.isExt(model)) {
  11248. return;
  11249. }
  11250. switch (model.type) {
  11251. case 'dataBar':
  11252. this.renderDataBar(xmlStream, model);
  11253. break;
  11254. case 'iconSet':
  11255. this.renderIconSet(xmlStream, model);
  11256. break;
  11257. }
  11258. }
  11259. }, {
  11260. key: "renderDataBar",
  11261. value: function renderDataBar(xmlStream, model) {
  11262. xmlStream.openNode(this.tag, {
  11263. type: 'dataBar',
  11264. id: model.x14Id
  11265. });
  11266. this.databarXform.render(xmlStream, model);
  11267. xmlStream.closeNode();
  11268. }
  11269. }, {
  11270. key: "renderIconSet",
  11271. value: function renderIconSet(xmlStream, model) {
  11272. xmlStream.openNode(this.tag, {
  11273. type: 'iconSet',
  11274. priority: model.priority,
  11275. id: model.x14Id || "{".concat(uuidv4(), "}")
  11276. });
  11277. this.iconSetXform.render(xmlStream, model);
  11278. xmlStream.closeNode();
  11279. }
  11280. }, {
  11281. key: "createNewModel",
  11282. value: function createNewModel(_ref) {
  11283. var attributes = _ref.attributes;
  11284. return {
  11285. type: attributes.type,
  11286. x14Id: attributes.id,
  11287. priority: BaseXform.toIntValue(attributes.priority)
  11288. };
  11289. }
  11290. }, {
  11291. key: "onParserClose",
  11292. value: function onParserClose(name, parser) {
  11293. Object.assign(this.model, parser.model);
  11294. }
  11295. }, {
  11296. key: "tag",
  11297. get: function get() {
  11298. return 'x14:cfRule';
  11299. }
  11300. }], [{
  11301. key: "isExt",
  11302. value: function isExt(rule) {
  11303. // is this rule primitive?
  11304. if (rule.type === 'dataBar') {
  11305. return DatabarExtXform.isExt(rule);
  11306. }
  11307. if (rule.type === 'iconSet') {
  11308. if (rule.custom || extIcons[rule.iconSet]) {
  11309. return true;
  11310. }
  11311. }
  11312. return false;
  11313. }
  11314. }]);
  11315. return CfRuleExtXform;
  11316. }(CompositeXform);
  11317. module.exports = CfRuleExtXform;
  11318. },{"../../base-xform":31,"../../composite-xform":47,"./databar-ext-xform":78,"./icon-set-ext-xform":80,"uuid":416}],75:[function(require,module,exports){
  11319. "use strict";
  11320. 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); }
  11321. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11322. 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); } }
  11323. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11324. 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); }
  11325. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11326. 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); }; }
  11327. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  11328. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11329. 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; } }
  11330. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  11331. var CompositeXform = require('../../composite-xform');
  11332. var FExtXform = require('./f-ext-xform');
  11333. var CfvoExtXform = /*#__PURE__*/function (_CompositeXform) {
  11334. _inherits(CfvoExtXform, _CompositeXform);
  11335. var _super = _createSuper(CfvoExtXform);
  11336. function CfvoExtXform() {
  11337. var _this;
  11338. _classCallCheck(this, CfvoExtXform);
  11339. _this = _super.call(this);
  11340. _this.map = {
  11341. 'xm:f': _this.fExtXform = new FExtXform()
  11342. };
  11343. return _this;
  11344. }
  11345. _createClass(CfvoExtXform, [{
  11346. key: "render",
  11347. value: function render(xmlStream, model) {
  11348. xmlStream.openNode(this.tag, {
  11349. type: model.type
  11350. });
  11351. if (model.value !== undefined) {
  11352. this.fExtXform.render(xmlStream, model.value);
  11353. }
  11354. xmlStream.closeNode();
  11355. }
  11356. }, {
  11357. key: "createNewModel",
  11358. value: function createNewModel(node) {
  11359. return {
  11360. type: node.attributes.type
  11361. };
  11362. }
  11363. }, {
  11364. key: "onParserClose",
  11365. value: function onParserClose(name, parser) {
  11366. switch (name) {
  11367. case 'xm:f':
  11368. this.model.value = parser.model ? parseFloat(parser.model) : 0;
  11369. break;
  11370. }
  11371. }
  11372. }, {
  11373. key: "tag",
  11374. get: function get() {
  11375. return 'x14:cfvo';
  11376. }
  11377. }]);
  11378. return CfvoExtXform;
  11379. }(CompositeXform);
  11380. module.exports = CfvoExtXform;
  11381. },{"../../composite-xform":47,"./f-ext-xform":79}],76:[function(require,module,exports){
  11382. "use strict";
  11383. 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); }
  11384. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11385. 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); } }
  11386. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11387. 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); }
  11388. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11389. 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); }; }
  11390. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  11391. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11392. 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; } }
  11393. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  11394. var CompositeXform = require('../../composite-xform');
  11395. var SqRefExtXform = require('./sqref-ext-xform');
  11396. var CfRuleExtXform = require('./cf-rule-ext-xform');
  11397. var ConditionalFormattingExtXform = /*#__PURE__*/function (_CompositeXform) {
  11398. _inherits(ConditionalFormattingExtXform, _CompositeXform);
  11399. var _super = _createSuper(ConditionalFormattingExtXform);
  11400. function ConditionalFormattingExtXform() {
  11401. var _this;
  11402. _classCallCheck(this, ConditionalFormattingExtXform);
  11403. _this = _super.call(this);
  11404. _this.map = {
  11405. 'xm:sqref': _this.sqRef = new SqRefExtXform(),
  11406. 'x14:cfRule': _this.cfRule = new CfRuleExtXform()
  11407. };
  11408. return _this;
  11409. }
  11410. _createClass(ConditionalFormattingExtXform, [{
  11411. key: "prepare",
  11412. value: function prepare(model, options) {
  11413. var _this2 = this;
  11414. model.rules.forEach(function (rule) {
  11415. _this2.cfRule.prepare(rule, options);
  11416. });
  11417. }
  11418. }, {
  11419. key: "render",
  11420. value: function render(xmlStream, model) {
  11421. var _this3 = this;
  11422. if (!model.rules.some(CfRuleExtXform.isExt)) {
  11423. return;
  11424. }
  11425. xmlStream.openNode(this.tag, {
  11426. 'xmlns:xm': 'http://schemas.microsoft.com/office/excel/2006/main'
  11427. });
  11428. model.rules.filter(CfRuleExtXform.isExt).forEach(function (rule) {
  11429. return _this3.cfRule.render(xmlStream, rule);
  11430. }); // for some odd reason, Excel needs the <xm:sqref> node to be after the rules
  11431. this.sqRef.render(xmlStream, model.ref);
  11432. xmlStream.closeNode();
  11433. }
  11434. }, {
  11435. key: "createNewModel",
  11436. value: function createNewModel() {
  11437. return {
  11438. rules: []
  11439. };
  11440. }
  11441. }, {
  11442. key: "onParserClose",
  11443. value: function onParserClose(name, parser) {
  11444. switch (name) {
  11445. case 'xm:sqref':
  11446. this.model.ref = parser.model;
  11447. break;
  11448. case 'x14:cfRule':
  11449. this.model.rules.push(parser.model);
  11450. break;
  11451. }
  11452. }
  11453. }, {
  11454. key: "tag",
  11455. get: function get() {
  11456. return 'x14:conditionalFormatting';
  11457. }
  11458. }]);
  11459. return ConditionalFormattingExtXform;
  11460. }(CompositeXform);
  11461. module.exports = ConditionalFormattingExtXform;
  11462. },{"../../composite-xform":47,"./cf-rule-ext-xform":74,"./sqref-ext-xform":81}],77:[function(require,module,exports){
  11463. "use strict";
  11464. 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); }
  11465. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11466. 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); } }
  11467. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11468. 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); }
  11469. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11470. 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); }; }
  11471. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  11472. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11473. 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; } }
  11474. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  11475. var CompositeXform = require('../../composite-xform');
  11476. var CfRuleExtXform = require('./cf-rule-ext-xform');
  11477. var ConditionalFormattingExtXform = require('./conditional-formatting-ext-xform');
  11478. var ConditionalFormattingsExtXform = /*#__PURE__*/function (_CompositeXform) {
  11479. _inherits(ConditionalFormattingsExtXform, _CompositeXform);
  11480. var _super = _createSuper(ConditionalFormattingsExtXform);
  11481. function ConditionalFormattingsExtXform() {
  11482. var _this;
  11483. _classCallCheck(this, ConditionalFormattingsExtXform);
  11484. _this = _super.call(this);
  11485. _this.map = {
  11486. 'x14:conditionalFormatting': _this.cfXform = new ConditionalFormattingExtXform()
  11487. };
  11488. return _this;
  11489. }
  11490. _createClass(ConditionalFormattingsExtXform, [{
  11491. key: "hasContent",
  11492. value: function hasContent(model) {
  11493. if (model.hasExtContent === undefined) {
  11494. model.hasExtContent = model.some(function (cf) {
  11495. return cf.rules.some(CfRuleExtXform.isExt);
  11496. });
  11497. }
  11498. return model.hasExtContent;
  11499. }
  11500. }, {
  11501. key: "prepare",
  11502. value: function prepare(model, options) {
  11503. var _this2 = this;
  11504. model.forEach(function (cf) {
  11505. _this2.cfXform.prepare(cf, options);
  11506. });
  11507. }
  11508. }, {
  11509. key: "render",
  11510. value: function render(xmlStream, model) {
  11511. var _this3 = this;
  11512. if (this.hasContent(model)) {
  11513. xmlStream.openNode(this.tag);
  11514. model.forEach(function (cf) {
  11515. return _this3.cfXform.render(xmlStream, cf);
  11516. });
  11517. xmlStream.closeNode();
  11518. }
  11519. }
  11520. }, {
  11521. key: "createNewModel",
  11522. value: function createNewModel() {
  11523. return [];
  11524. }
  11525. }, {
  11526. key: "onParserClose",
  11527. value: function onParserClose(name, parser) {
  11528. // model is array of conditional formatting objects
  11529. this.model.push(parser.model);
  11530. }
  11531. }, {
  11532. key: "tag",
  11533. get: function get() {
  11534. return 'x14:conditionalFormattings';
  11535. }
  11536. }]);
  11537. return ConditionalFormattingsExtXform;
  11538. }(CompositeXform);
  11539. module.exports = ConditionalFormattingsExtXform;
  11540. },{"../../composite-xform":47,"./cf-rule-ext-xform":74,"./conditional-formatting-ext-xform":76}],78:[function(require,module,exports){
  11541. "use strict";
  11542. 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); }
  11543. function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
  11544. 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."); }
  11545. 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); }
  11546. 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; }
  11547. 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; }
  11548. function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  11549. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11550. 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); } }
  11551. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11552. 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); }
  11553. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11554. 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); }; }
  11555. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  11556. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11557. 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; } }
  11558. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  11559. var BaseXform = require('../../base-xform');
  11560. var CompositeXform = require('../../composite-xform');
  11561. var ColorXform = require('../../style/color-xform');
  11562. var CfvoExtXform = require('./cfvo-ext-xform');
  11563. var DatabarExtXform = /*#__PURE__*/function (_CompositeXform) {
  11564. _inherits(DatabarExtXform, _CompositeXform);
  11565. var _super = _createSuper(DatabarExtXform);
  11566. function DatabarExtXform() {
  11567. var _this;
  11568. _classCallCheck(this, DatabarExtXform);
  11569. _this = _super.call(this);
  11570. _this.map = {
  11571. 'x14:cfvo': _this.cfvoXform = new CfvoExtXform(),
  11572. 'x14:borderColor': _this.borderColorXform = new ColorXform('x14:borderColor'),
  11573. 'x14:negativeBorderColor': _this.negativeBorderColorXform = new ColorXform('x14:negativeBorderColor'),
  11574. 'x14:negativeFillColor': _this.negativeFillColorXform = new ColorXform('x14:negativeFillColor'),
  11575. 'x14:axisColor': _this.axisColorXform = new ColorXform('x14:axisColor')
  11576. };
  11577. return _this;
  11578. }
  11579. _createClass(DatabarExtXform, [{
  11580. key: "render",
  11581. value: function render(xmlStream, model) {
  11582. var _this2 = this;
  11583. xmlStream.openNode(this.tag, {
  11584. minLength: BaseXform.toIntAttribute(model.minLength, 0, true),
  11585. maxLength: BaseXform.toIntAttribute(model.maxLength, 100, true),
  11586. border: BaseXform.toBoolAttribute(model.border, false),
  11587. gradient: BaseXform.toBoolAttribute(model.gradient, true),
  11588. negativeBarColorSameAsPositive: BaseXform.toBoolAttribute(model.negativeBarColorSameAsPositive, true),
  11589. negativeBarBorderColorSameAsPositive: BaseXform.toBoolAttribute(model.negativeBarBorderColorSameAsPositive, true),
  11590. axisPosition: BaseXform.toAttribute(model.axisPosition, 'auto'),
  11591. direction: BaseXform.toAttribute(model.direction, 'leftToRight')
  11592. });
  11593. model.cfvo.forEach(function (cfvo) {
  11594. _this2.cfvoXform.render(xmlStream, cfvo);
  11595. });
  11596. this.borderColorXform.render(xmlStream, model.borderColor);
  11597. this.negativeBorderColorXform.render(xmlStream, model.negativeBorderColor);
  11598. this.negativeFillColorXform.render(xmlStream, model.negativeFillColor);
  11599. this.axisColorXform.render(xmlStream, model.axisColor);
  11600. xmlStream.closeNode();
  11601. }
  11602. }, {
  11603. key: "createNewModel",
  11604. value: function createNewModel(_ref) {
  11605. var attributes = _ref.attributes;
  11606. return {
  11607. cfvo: [],
  11608. minLength: BaseXform.toIntValue(attributes.minLength, 0),
  11609. maxLength: BaseXform.toIntValue(attributes.maxLength, 100),
  11610. border: BaseXform.toBoolValue(attributes.border, false),
  11611. gradient: BaseXform.toBoolValue(attributes.gradient, true),
  11612. negativeBarColorSameAsPositive: BaseXform.toBoolValue(attributes.negativeBarColorSameAsPositive, true),
  11613. negativeBarBorderColorSameAsPositive: BaseXform.toBoolValue(attributes.negativeBarBorderColorSameAsPositive, true),
  11614. axisPosition: BaseXform.toStringValue(attributes.axisPosition, 'auto'),
  11615. direction: BaseXform.toStringValue(attributes.direction, 'leftToRight')
  11616. };
  11617. }
  11618. }, {
  11619. key: "onParserClose",
  11620. value: function onParserClose(name, parser) {
  11621. var _name$split = name.split(':'),
  11622. _name$split2 = _slicedToArray(_name$split, 2),
  11623. prop = _name$split2[1];
  11624. switch (prop) {
  11625. case 'cfvo':
  11626. this.model.cfvo.push(parser.model);
  11627. break;
  11628. default:
  11629. this.model[prop] = parser.model;
  11630. break;
  11631. }
  11632. }
  11633. }, {
  11634. key: "tag",
  11635. get: function get() {
  11636. return 'x14:dataBar';
  11637. }
  11638. }], [{
  11639. key: "isExt",
  11640. value: function isExt(rule) {
  11641. // not all databars need ext
  11642. // TODO: refine this
  11643. return !rule.gradient;
  11644. }
  11645. }]);
  11646. return DatabarExtXform;
  11647. }(CompositeXform);
  11648. module.exports = DatabarExtXform;
  11649. },{"../../base-xform":31,"../../composite-xform":47,"../../style/color-xform":127,"./cfvo-ext-xform":75}],79:[function(require,module,exports){
  11650. "use strict";
  11651. 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); }
  11652. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11653. 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); } }
  11654. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11655. 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); }
  11656. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11657. 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); }; }
  11658. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  11659. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11660. 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; } }
  11661. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  11662. var BaseXform = require('../../base-xform');
  11663. var FExtXform = /*#__PURE__*/function (_BaseXform) {
  11664. _inherits(FExtXform, _BaseXform);
  11665. var _super = _createSuper(FExtXform);
  11666. function FExtXform() {
  11667. _classCallCheck(this, FExtXform);
  11668. return _super.apply(this, arguments);
  11669. }
  11670. _createClass(FExtXform, [{
  11671. key: "render",
  11672. value: function render(xmlStream, model) {
  11673. xmlStream.leafNode(this.tag, null, model);
  11674. }
  11675. }, {
  11676. key: "parseOpen",
  11677. value: function parseOpen() {
  11678. this.model = '';
  11679. }
  11680. }, {
  11681. key: "parseText",
  11682. value: function parseText(text) {
  11683. this.model += text;
  11684. }
  11685. }, {
  11686. key: "parseClose",
  11687. value: function parseClose(name) {
  11688. return name !== this.tag;
  11689. }
  11690. }, {
  11691. key: "tag",
  11692. get: function get() {
  11693. return 'xm:f';
  11694. }
  11695. }]);
  11696. return FExtXform;
  11697. }(BaseXform);
  11698. module.exports = FExtXform;
  11699. },{"../../base-xform":31}],80:[function(require,module,exports){
  11700. "use strict";
  11701. 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); }
  11702. function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
  11703. 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."); }
  11704. 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); }
  11705. 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; }
  11706. 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; }
  11707. function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  11708. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11709. 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); } }
  11710. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11711. 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); }
  11712. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11713. 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); }; }
  11714. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  11715. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11716. 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; } }
  11717. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  11718. var BaseXform = require('../../base-xform');
  11719. var CompositeXform = require('../../composite-xform');
  11720. var CfvoExtXform = require('./cfvo-ext-xform');
  11721. var CfIconExtXform = require('./cf-icon-ext-xform');
  11722. var IconSetExtXform = /*#__PURE__*/function (_CompositeXform) {
  11723. _inherits(IconSetExtXform, _CompositeXform);
  11724. var _super = _createSuper(IconSetExtXform);
  11725. function IconSetExtXform() {
  11726. var _this;
  11727. _classCallCheck(this, IconSetExtXform);
  11728. _this = _super.call(this);
  11729. _this.map = {
  11730. 'x14:cfvo': _this.cfvoXform = new CfvoExtXform(),
  11731. 'x14:cfIcon': _this.cfIconXform = new CfIconExtXform()
  11732. };
  11733. return _this;
  11734. }
  11735. _createClass(IconSetExtXform, [{
  11736. key: "render",
  11737. value: function render(xmlStream, model) {
  11738. var _this2 = this;
  11739. xmlStream.openNode(this.tag, {
  11740. iconSet: BaseXform.toStringAttribute(model.iconSet),
  11741. reverse: BaseXform.toBoolAttribute(model.reverse, false),
  11742. showValue: BaseXform.toBoolAttribute(model.showValue, true),
  11743. custom: BaseXform.toBoolAttribute(model.icons, false)
  11744. });
  11745. model.cfvo.forEach(function (cfvo) {
  11746. _this2.cfvoXform.render(xmlStream, cfvo);
  11747. });
  11748. if (model.icons) {
  11749. model.icons.forEach(function (icon, i) {
  11750. icon.iconId = i;
  11751. _this2.cfIconXform.render(xmlStream, icon);
  11752. });
  11753. }
  11754. xmlStream.closeNode();
  11755. }
  11756. }, {
  11757. key: "createNewModel",
  11758. value: function createNewModel(_ref) {
  11759. var attributes = _ref.attributes;
  11760. return {
  11761. cfvo: [],
  11762. iconSet: BaseXform.toStringValue(attributes.iconSet, '3TrafficLights'),
  11763. reverse: BaseXform.toBoolValue(attributes.reverse, false),
  11764. showValue: BaseXform.toBoolValue(attributes.showValue, true)
  11765. };
  11766. }
  11767. }, {
  11768. key: "onParserClose",
  11769. value: function onParserClose(name, parser) {
  11770. var _name$split = name.split(':'),
  11771. _name$split2 = _slicedToArray(_name$split, 2),
  11772. prop = _name$split2[1];
  11773. switch (prop) {
  11774. case 'cfvo':
  11775. this.model.cfvo.push(parser.model);
  11776. break;
  11777. case 'cfIcon':
  11778. if (!this.model.icons) {
  11779. this.model.icons = [];
  11780. }
  11781. this.model.icons.push(parser.model);
  11782. break;
  11783. default:
  11784. this.model[prop] = parser.model;
  11785. break;
  11786. }
  11787. }
  11788. }, {
  11789. key: "tag",
  11790. get: function get() {
  11791. return 'x14:iconSet';
  11792. }
  11793. }]);
  11794. return IconSetExtXform;
  11795. }(CompositeXform);
  11796. module.exports = IconSetExtXform;
  11797. },{"../../base-xform":31,"../../composite-xform":47,"./cf-icon-ext-xform":73,"./cfvo-ext-xform":75}],81:[function(require,module,exports){
  11798. "use strict";
  11799. 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); }
  11800. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11801. 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); } }
  11802. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11803. 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); }
  11804. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11805. 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); }; }
  11806. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  11807. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11808. 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; } }
  11809. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  11810. var BaseXform = require('../../base-xform');
  11811. var SqrefExtXform = /*#__PURE__*/function (_BaseXform) {
  11812. _inherits(SqrefExtXform, _BaseXform);
  11813. var _super = _createSuper(SqrefExtXform);
  11814. function SqrefExtXform() {
  11815. _classCallCheck(this, SqrefExtXform);
  11816. return _super.apply(this, arguments);
  11817. }
  11818. _createClass(SqrefExtXform, [{
  11819. key: "render",
  11820. value: function render(xmlStream, model) {
  11821. xmlStream.leafNode(this.tag, null, model);
  11822. }
  11823. }, {
  11824. key: "parseOpen",
  11825. value: function parseOpen() {
  11826. this.model = '';
  11827. }
  11828. }, {
  11829. key: "parseText",
  11830. value: function parseText(text) {
  11831. this.model += text;
  11832. }
  11833. }, {
  11834. key: "parseClose",
  11835. value: function parseClose(name) {
  11836. return name !== this.tag;
  11837. }
  11838. }, {
  11839. key: "tag",
  11840. get: function get() {
  11841. return 'xm:sqref';
  11842. }
  11843. }]);
  11844. return SqrefExtXform;
  11845. }(BaseXform);
  11846. module.exports = SqrefExtXform;
  11847. },{"../../base-xform":31}],82:[function(require,module,exports){
  11848. "use strict";
  11849. 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); }
  11850. 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; }
  11851. 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; }
  11852. 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; }
  11853. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11854. 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); } }
  11855. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11856. 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); }
  11857. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11858. 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); }; }
  11859. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  11860. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11861. 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; } }
  11862. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  11863. var BaseXform = require('../../base-xform');
  11864. var CompositeXform = require('../../composite-xform');
  11865. var Range = require('../../../../doc/range');
  11866. var DatabarXform = require('./databar-xform');
  11867. var ExtLstRefXform = require('./ext-lst-ref-xform');
  11868. var FormulaXform = require('./formula-xform');
  11869. var ColorScaleXform = require('./color-scale-xform');
  11870. var IconSetXform = require('./icon-set-xform');
  11871. var extIcons = {
  11872. '3Triangles': true,
  11873. '3Stars': true,
  11874. '5Boxes': true
  11875. };
  11876. var getTextFormula = function getTextFormula(model) {
  11877. if (model.formulae && model.formulae[0]) {
  11878. return model.formulae[0];
  11879. }
  11880. var range = new Range(model.ref);
  11881. var tl = range.tl;
  11882. switch (model.operator) {
  11883. case 'containsText':
  11884. return "NOT(ISERROR(SEARCH(\"".concat(model.text, "\",").concat(tl, ")))");
  11885. case 'containsBlanks':
  11886. return "LEN(TRIM(".concat(tl, "))=0");
  11887. case 'notContainsBlanks':
  11888. return "LEN(TRIM(".concat(tl, "))>0");
  11889. case 'containsErrors':
  11890. return "ISERROR(".concat(tl, ")");
  11891. case 'notContainsErrors':
  11892. return "NOT(ISERROR(".concat(tl, "))");
  11893. default:
  11894. return undefined;
  11895. }
  11896. };
  11897. var getTimePeriodFormula = function getTimePeriodFormula(model) {
  11898. if (model.formulae && model.formulae[0]) {
  11899. return model.formulae[0];
  11900. }
  11901. var range = new Range(model.ref);
  11902. var tl = range.tl;
  11903. switch (model.timePeriod) {
  11904. case 'thisWeek':
  11905. return "AND(TODAY()-ROUNDDOWN(".concat(tl, ",0)<=WEEKDAY(TODAY())-1,ROUNDDOWN(").concat(tl, ",0)-TODAY()<=7-WEEKDAY(TODAY()))");
  11906. case 'lastWeek':
  11907. return "AND(TODAY()-ROUNDDOWN(".concat(tl, ",0)>=(WEEKDAY(TODAY())),TODAY()-ROUNDDOWN(").concat(tl, ",0)<(WEEKDAY(TODAY())+7))");
  11908. case 'nextWeek':
  11909. return "AND(ROUNDDOWN(".concat(tl, ",0)-TODAY()>(7-WEEKDAY(TODAY())),ROUNDDOWN(").concat(tl, ",0)-TODAY()<(15-WEEKDAY(TODAY())))");
  11910. case 'yesterday':
  11911. return "FLOOR(".concat(tl, ",1)=TODAY()-1");
  11912. case 'today':
  11913. return "FLOOR(".concat(tl, ",1)=TODAY()");
  11914. case 'tomorrow':
  11915. return "FLOOR(".concat(tl, ",1)=TODAY()+1");
  11916. case 'last7Days':
  11917. return "AND(TODAY()-FLOOR(".concat(tl, ",1)<=6,FLOOR(").concat(tl, ",1)<=TODAY())");
  11918. case 'lastMonth':
  11919. return "AND(MONTH(".concat(tl, ")=MONTH(EDATE(TODAY(),0-1)),YEAR(").concat(tl, ")=YEAR(EDATE(TODAY(),0-1)))");
  11920. case 'thisMonth':
  11921. return "AND(MONTH(".concat(tl, ")=MONTH(TODAY()),YEAR(").concat(tl, ")=YEAR(TODAY()))");
  11922. case 'nextMonth':
  11923. return "AND(MONTH(".concat(tl, ")=MONTH(EDATE(TODAY(),0+1)),YEAR(").concat(tl, ")=YEAR(EDATE(TODAY(),0+1)))");
  11924. default:
  11925. return undefined;
  11926. }
  11927. };
  11928. var opType = function opType(attributes) {
  11929. var type = attributes.type,
  11930. operator = attributes.operator;
  11931. switch (type) {
  11932. case 'containsText':
  11933. case 'containsBlanks':
  11934. case 'notContainsBlanks':
  11935. case 'containsErrors':
  11936. case 'notContainsErrors':
  11937. return {
  11938. type: 'containsText',
  11939. operator: type
  11940. };
  11941. default:
  11942. return {
  11943. type: type,
  11944. operator: operator
  11945. };
  11946. }
  11947. };
  11948. var CfRuleXform = /*#__PURE__*/function (_CompositeXform) {
  11949. _inherits(CfRuleXform, _CompositeXform);
  11950. var _super = _createSuper(CfRuleXform);
  11951. function CfRuleXform() {
  11952. var _this;
  11953. _classCallCheck(this, CfRuleXform);
  11954. _this = _super.call(this);
  11955. _this.map = {
  11956. dataBar: _this.databarXform = new DatabarXform(),
  11957. extLst: _this.extLstRefXform = new ExtLstRefXform(),
  11958. formula: _this.formulaXform = new FormulaXform(),
  11959. colorScale: _this.colorScaleXform = new ColorScaleXform(),
  11960. iconSet: _this.iconSetXform = new IconSetXform()
  11961. };
  11962. return _this;
  11963. }
  11964. _createClass(CfRuleXform, [{
  11965. key: "render",
  11966. value: function render(xmlStream, model) {
  11967. switch (model.type) {
  11968. case 'expression':
  11969. this.renderExpression(xmlStream, model);
  11970. break;
  11971. case 'cellIs':
  11972. this.renderCellIs(xmlStream, model);
  11973. break;
  11974. case 'top10':
  11975. this.renderTop10(xmlStream, model);
  11976. break;
  11977. case 'aboveAverage':
  11978. this.renderAboveAverage(xmlStream, model);
  11979. break;
  11980. case 'dataBar':
  11981. this.renderDataBar(xmlStream, model);
  11982. break;
  11983. case 'colorScale':
  11984. this.renderColorScale(xmlStream, model);
  11985. break;
  11986. case 'iconSet':
  11987. this.renderIconSet(xmlStream, model);
  11988. break;
  11989. case 'containsText':
  11990. this.renderText(xmlStream, model);
  11991. break;
  11992. case 'timePeriod':
  11993. this.renderTimePeriod(xmlStream, model);
  11994. break;
  11995. }
  11996. }
  11997. }, {
  11998. key: "renderExpression",
  11999. value: function renderExpression(xmlStream, model) {
  12000. xmlStream.openNode(this.tag, {
  12001. type: 'expression',
  12002. dxfId: model.dxfId,
  12003. priority: model.priority
  12004. });
  12005. this.formulaXform.render(xmlStream, model.formulae[0]);
  12006. xmlStream.closeNode();
  12007. }
  12008. }, {
  12009. key: "renderCellIs",
  12010. value: function renderCellIs(xmlStream, model) {
  12011. var _this2 = this;
  12012. xmlStream.openNode(this.tag, {
  12013. type: 'cellIs',
  12014. dxfId: model.dxfId,
  12015. priority: model.priority,
  12016. operator: model.operator
  12017. });
  12018. model.formulae.forEach(function (formula) {
  12019. _this2.formulaXform.render(xmlStream, formula);
  12020. });
  12021. xmlStream.closeNode();
  12022. }
  12023. }, {
  12024. key: "renderTop10",
  12025. value: function renderTop10(xmlStream, model) {
  12026. xmlStream.leafNode(this.tag, {
  12027. type: 'top10',
  12028. dxfId: model.dxfId,
  12029. priority: model.priority,
  12030. percent: BaseXform.toBoolAttribute(model.percent, false),
  12031. bottom: BaseXform.toBoolAttribute(model.bottom, false),
  12032. rank: BaseXform.toIntValue(model.rank, 10, true)
  12033. });
  12034. }
  12035. }, {
  12036. key: "renderAboveAverage",
  12037. value: function renderAboveAverage(xmlStream, model) {
  12038. xmlStream.leafNode(this.tag, {
  12039. type: 'aboveAverage',
  12040. dxfId: model.dxfId,
  12041. priority: model.priority,
  12042. aboveAverage: BaseXform.toBoolAttribute(model.aboveAverage, true)
  12043. });
  12044. }
  12045. }, {
  12046. key: "renderDataBar",
  12047. value: function renderDataBar(xmlStream, model) {
  12048. xmlStream.openNode(this.tag, {
  12049. type: 'dataBar',
  12050. priority: model.priority
  12051. });
  12052. this.databarXform.render(xmlStream, model);
  12053. this.extLstRefXform.render(xmlStream, model);
  12054. xmlStream.closeNode();
  12055. }
  12056. }, {
  12057. key: "renderColorScale",
  12058. value: function renderColorScale(xmlStream, model) {
  12059. xmlStream.openNode(this.tag, {
  12060. type: 'colorScale',
  12061. priority: model.priority
  12062. });
  12063. this.colorScaleXform.render(xmlStream, model);
  12064. xmlStream.closeNode();
  12065. }
  12066. }, {
  12067. key: "renderIconSet",
  12068. value: function renderIconSet(xmlStream, model) {
  12069. // iconset is all primitive or all extLst
  12070. if (!CfRuleXform.isPrimitive(model)) {
  12071. return;
  12072. }
  12073. xmlStream.openNode(this.tag, {
  12074. type: 'iconSet',
  12075. priority: model.priority
  12076. });
  12077. this.iconSetXform.render(xmlStream, model);
  12078. xmlStream.closeNode();
  12079. }
  12080. }, {
  12081. key: "renderText",
  12082. value: function renderText(xmlStream, model) {
  12083. xmlStream.openNode(this.tag, {
  12084. type: model.operator,
  12085. dxfId: model.dxfId,
  12086. priority: model.priority,
  12087. operator: BaseXform.toStringAttribute(model.operator, 'containsText')
  12088. });
  12089. var formula = getTextFormula(model);
  12090. if (formula) {
  12091. this.formulaXform.render(xmlStream, formula);
  12092. }
  12093. xmlStream.closeNode();
  12094. }
  12095. }, {
  12096. key: "renderTimePeriod",
  12097. value: function renderTimePeriod(xmlStream, model) {
  12098. xmlStream.openNode(this.tag, {
  12099. type: 'timePeriod',
  12100. dxfId: model.dxfId,
  12101. priority: model.priority,
  12102. timePeriod: model.timePeriod
  12103. });
  12104. var formula = getTimePeriodFormula(model);
  12105. if (formula) {
  12106. this.formulaXform.render(xmlStream, formula);
  12107. }
  12108. xmlStream.closeNode();
  12109. }
  12110. }, {
  12111. key: "createNewModel",
  12112. value: function createNewModel(_ref) {
  12113. var attributes = _ref.attributes;
  12114. return _objectSpread(_objectSpread({}, opType(attributes)), {}, {
  12115. dxfId: BaseXform.toIntValue(attributes.dxfId),
  12116. priority: BaseXform.toIntValue(attributes.priority),
  12117. timePeriod: attributes.timePeriod,
  12118. percent: BaseXform.toBoolValue(attributes.percent),
  12119. bottom: BaseXform.toBoolValue(attributes.bottom),
  12120. rank: BaseXform.toIntValue(attributes.rank),
  12121. aboveAverage: BaseXform.toBoolValue(attributes.aboveAverage)
  12122. });
  12123. }
  12124. }, {
  12125. key: "onParserClose",
  12126. value: function onParserClose(name, parser) {
  12127. switch (name) {
  12128. case 'dataBar':
  12129. case 'extLst':
  12130. case 'colorScale':
  12131. case 'iconSet':
  12132. // merge parser model with ours
  12133. Object.assign(this.model, parser.model);
  12134. break;
  12135. case 'formula':
  12136. // except - formula is a string and appends to formulae
  12137. this.model.formulae = this.model.formulae || [];
  12138. this.model.formulae.push(parser.model);
  12139. break;
  12140. }
  12141. }
  12142. }, {
  12143. key: "tag",
  12144. get: function get() {
  12145. return 'cfRule';
  12146. }
  12147. }], [{
  12148. key: "isPrimitive",
  12149. value: function isPrimitive(rule) {
  12150. // is this rule primitive?
  12151. if (rule.type === 'iconSet') {
  12152. if (rule.custom || extIcons[rule.iconSet]) {
  12153. return false;
  12154. }
  12155. }
  12156. return true;
  12157. }
  12158. }]);
  12159. return CfRuleXform;
  12160. }(CompositeXform);
  12161. module.exports = CfRuleXform;
  12162. },{"../../../../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){
  12163. "use strict";
  12164. 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); }
  12165. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12166. 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); } }
  12167. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  12168. 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); }
  12169. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  12170. 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); }; }
  12171. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  12172. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  12173. 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; } }
  12174. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  12175. var BaseXform = require('../../base-xform');
  12176. var CfvoXform = /*#__PURE__*/function (_BaseXform) {
  12177. _inherits(CfvoXform, _BaseXform);
  12178. var _super = _createSuper(CfvoXform);
  12179. function CfvoXform() {
  12180. _classCallCheck(this, CfvoXform);
  12181. return _super.apply(this, arguments);
  12182. }
  12183. _createClass(CfvoXform, [{
  12184. key: "render",
  12185. value: function render(xmlStream, model) {
  12186. xmlStream.leafNode(this.tag, {
  12187. type: model.type,
  12188. val: model.value
  12189. });
  12190. }
  12191. }, {
  12192. key: "parseOpen",
  12193. value: function parseOpen(node) {
  12194. this.model = {
  12195. type: node.attributes.type,
  12196. value: BaseXform.toFloatValue(node.attributes.val)
  12197. };
  12198. }
  12199. }, {
  12200. key: "parseClose",
  12201. value: function parseClose(name) {
  12202. return name !== this.tag;
  12203. }
  12204. }, {
  12205. key: "tag",
  12206. get: function get() {
  12207. return 'cfvo';
  12208. }
  12209. }]);
  12210. return CfvoXform;
  12211. }(BaseXform);
  12212. module.exports = CfvoXform;
  12213. },{"../../base-xform":31}],84:[function(require,module,exports){
  12214. "use strict";
  12215. 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); }
  12216. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12217. 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); } }
  12218. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  12219. 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); }
  12220. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  12221. 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); }; }
  12222. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  12223. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  12224. 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; } }
  12225. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  12226. var CompositeXform = require('../../composite-xform');
  12227. var ColorXform = require('../../style/color-xform');
  12228. var CfvoXform = require('./cfvo-xform');
  12229. var ColorScaleXform = /*#__PURE__*/function (_CompositeXform) {
  12230. _inherits(ColorScaleXform, _CompositeXform);
  12231. var _super = _createSuper(ColorScaleXform);
  12232. function ColorScaleXform() {
  12233. var _this;
  12234. _classCallCheck(this, ColorScaleXform);
  12235. _this = _super.call(this);
  12236. _this.map = {
  12237. cfvo: _this.cfvoXform = new CfvoXform(),
  12238. color: _this.colorXform = new ColorXform()
  12239. };
  12240. return _this;
  12241. }
  12242. _createClass(ColorScaleXform, [{
  12243. key: "render",
  12244. value: function render(xmlStream, model) {
  12245. var _this2 = this;
  12246. xmlStream.openNode(this.tag);
  12247. model.cfvo.forEach(function (cfvo) {
  12248. _this2.cfvoXform.render(xmlStream, cfvo);
  12249. });
  12250. model.color.forEach(function (color) {
  12251. _this2.colorXform.render(xmlStream, color);
  12252. });
  12253. xmlStream.closeNode();
  12254. }
  12255. }, {
  12256. key: "createNewModel",
  12257. value: function createNewModel(node) {
  12258. return {
  12259. cfvo: [],
  12260. color: []
  12261. };
  12262. }
  12263. }, {
  12264. key: "onParserClose",
  12265. value: function onParserClose(name, parser) {
  12266. this.model[name].push(parser.model);
  12267. }
  12268. }, {
  12269. key: "tag",
  12270. get: function get() {
  12271. return 'colorScale';
  12272. }
  12273. }]);
  12274. return ColorScaleXform;
  12275. }(CompositeXform);
  12276. module.exports = ColorScaleXform;
  12277. },{"../../composite-xform":47,"../../style/color-xform":127,"./cfvo-xform":83}],85:[function(require,module,exports){
  12278. "use strict";
  12279. 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); }
  12280. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12281. 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); } }
  12282. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  12283. 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); }
  12284. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  12285. 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); }; }
  12286. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  12287. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  12288. 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; } }
  12289. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  12290. var CompositeXform = require('../../composite-xform');
  12291. var CfRuleXform = require('./cf-rule-xform');
  12292. var ConditionalFormattingXform = /*#__PURE__*/function (_CompositeXform) {
  12293. _inherits(ConditionalFormattingXform, _CompositeXform);
  12294. var _super = _createSuper(ConditionalFormattingXform);
  12295. function ConditionalFormattingXform() {
  12296. var _this;
  12297. _classCallCheck(this, ConditionalFormattingXform);
  12298. _this = _super.call(this);
  12299. _this.map = {
  12300. cfRule: new CfRuleXform()
  12301. };
  12302. return _this;
  12303. }
  12304. _createClass(ConditionalFormattingXform, [{
  12305. key: "render",
  12306. value: function render(xmlStream, model) {
  12307. var _this2 = this;
  12308. // if there are no primitive rules, exit now
  12309. if (!model.rules.some(CfRuleXform.isPrimitive)) {
  12310. return;
  12311. }
  12312. xmlStream.openNode(this.tag, {
  12313. sqref: model.ref
  12314. });
  12315. model.rules.forEach(function (rule) {
  12316. if (CfRuleXform.isPrimitive(rule)) {
  12317. rule.ref = model.ref;
  12318. _this2.map.cfRule.render(xmlStream, rule);
  12319. }
  12320. });
  12321. xmlStream.closeNode();
  12322. }
  12323. }, {
  12324. key: "createNewModel",
  12325. value: function createNewModel(_ref) {
  12326. var attributes = _ref.attributes;
  12327. return {
  12328. ref: attributes.sqref,
  12329. rules: []
  12330. };
  12331. }
  12332. }, {
  12333. key: "onParserClose",
  12334. value: function onParserClose(name, parser) {
  12335. this.model.rules.push(parser.model);
  12336. }
  12337. }, {
  12338. key: "tag",
  12339. get: function get() {
  12340. return 'conditionalFormatting';
  12341. }
  12342. }]);
  12343. return ConditionalFormattingXform;
  12344. }(CompositeXform);
  12345. module.exports = ConditionalFormattingXform;
  12346. },{"../../composite-xform":47,"./cf-rule-xform":82}],86:[function(require,module,exports){
  12347. "use strict";
  12348. 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); }
  12349. function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
  12350. 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."); }
  12351. 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); }
  12352. function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
  12353. function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
  12354. 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; }
  12355. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12356. 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); } }
  12357. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  12358. 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); }
  12359. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  12360. 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); }; }
  12361. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  12362. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  12363. 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; } }
  12364. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  12365. var BaseXform = require('../../base-xform');
  12366. var ConditionalFormattingXform = require('./conditional-formatting-xform');
  12367. var ConditionalFormattingsXform = /*#__PURE__*/function (_BaseXform) {
  12368. _inherits(ConditionalFormattingsXform, _BaseXform);
  12369. var _super = _createSuper(ConditionalFormattingsXform);
  12370. function ConditionalFormattingsXform() {
  12371. var _this;
  12372. _classCallCheck(this, ConditionalFormattingsXform);
  12373. _this = _super.call(this);
  12374. _this.cfXform = new ConditionalFormattingXform();
  12375. return _this;
  12376. }
  12377. _createClass(ConditionalFormattingsXform, [{
  12378. key: "reset",
  12379. value: function reset() {
  12380. this.model = [];
  12381. }
  12382. }, {
  12383. key: "prepare",
  12384. value: function prepare(model, options) {
  12385. // ensure each rule has a priority value
  12386. var nextPriority = model.reduce(function (p, cf) {
  12387. return Math.max.apply(Math, [p].concat(_toConsumableArray(cf.rules.map(function (rule) {
  12388. return rule.priority || 0;
  12389. }))));
  12390. }, 1);
  12391. model.forEach(function (cf) {
  12392. cf.rules.forEach(function (rule) {
  12393. if (!rule.priority) {
  12394. rule.priority = nextPriority++;
  12395. }
  12396. if (rule.style) {
  12397. rule.dxfId = options.styles.addDxfStyle(rule.style);
  12398. }
  12399. });
  12400. });
  12401. }
  12402. }, {
  12403. key: "render",
  12404. value: function render(xmlStream, model) {
  12405. var _this2 = this;
  12406. model.forEach(function (cf) {
  12407. _this2.cfXform.render(xmlStream, cf);
  12408. });
  12409. }
  12410. }, {
  12411. key: "parseOpen",
  12412. value: function parseOpen(node) {
  12413. if (this.parser) {
  12414. this.parser.parseOpen(node);
  12415. return true;
  12416. }
  12417. switch (node.name) {
  12418. case 'conditionalFormatting':
  12419. this.parser = this.cfXform;
  12420. this.parser.parseOpen(node);
  12421. return true;
  12422. default:
  12423. return false;
  12424. }
  12425. }
  12426. }, {
  12427. key: "parseText",
  12428. value: function parseText(text) {
  12429. if (this.parser) {
  12430. this.parser.parseText(text);
  12431. }
  12432. }
  12433. }, {
  12434. key: "parseClose",
  12435. value: function parseClose(name) {
  12436. if (this.parser) {
  12437. if (!this.parser.parseClose(name)) {
  12438. this.model.push(this.parser.model);
  12439. this.parser = undefined;
  12440. return false;
  12441. }
  12442. return true;
  12443. }
  12444. return false;
  12445. }
  12446. }, {
  12447. key: "reconcile",
  12448. value: function reconcile(model, options) {
  12449. model.forEach(function (cf) {
  12450. cf.rules.forEach(function (rule) {
  12451. if (rule.dxfId !== undefined) {
  12452. rule.style = options.styles.getDxfStyle(rule.dxfId);
  12453. delete rule.dxfId;
  12454. }
  12455. });
  12456. });
  12457. }
  12458. }, {
  12459. key: "tag",
  12460. get: function get() {
  12461. return 'conditionalFormatting';
  12462. }
  12463. }]);
  12464. return ConditionalFormattingsXform;
  12465. }(BaseXform);
  12466. module.exports = ConditionalFormattingsXform;
  12467. },{"../../base-xform":31,"./conditional-formatting-xform":85}],87:[function(require,module,exports){
  12468. "use strict";
  12469. 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); }
  12470. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12471. 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); } }
  12472. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  12473. 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); }
  12474. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  12475. 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); }; }
  12476. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  12477. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  12478. 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; } }
  12479. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  12480. var CompositeXform = require('../../composite-xform');
  12481. var ColorXform = require('../../style/color-xform');
  12482. var CfvoXform = require('./cfvo-xform');
  12483. var DatabarXform = /*#__PURE__*/function (_CompositeXform) {
  12484. _inherits(DatabarXform, _CompositeXform);
  12485. var _super = _createSuper(DatabarXform);
  12486. function DatabarXform() {
  12487. var _this;
  12488. _classCallCheck(this, DatabarXform);
  12489. _this = _super.call(this);
  12490. _this.map = {
  12491. cfvo: _this.cfvoXform = new CfvoXform(),
  12492. color: _this.colorXform = new ColorXform()
  12493. };
  12494. return _this;
  12495. }
  12496. _createClass(DatabarXform, [{
  12497. key: "render",
  12498. value: function render(xmlStream, model) {
  12499. var _this2 = this;
  12500. xmlStream.openNode(this.tag);
  12501. model.cfvo.forEach(function (cfvo) {
  12502. _this2.cfvoXform.render(xmlStream, cfvo);
  12503. });
  12504. this.colorXform.render(xmlStream, model.color);
  12505. xmlStream.closeNode();
  12506. }
  12507. }, {
  12508. key: "createNewModel",
  12509. value: function createNewModel() {
  12510. return {
  12511. cfvo: []
  12512. };
  12513. }
  12514. }, {
  12515. key: "onParserClose",
  12516. value: function onParserClose(name, parser) {
  12517. switch (name) {
  12518. case 'cfvo':
  12519. this.model.cfvo.push(parser.model);
  12520. break;
  12521. case 'color':
  12522. this.model.color = parser.model;
  12523. break;
  12524. }
  12525. }
  12526. }, {
  12527. key: "tag",
  12528. get: function get() {
  12529. return 'dataBar';
  12530. }
  12531. }]);
  12532. return DatabarXform;
  12533. }(CompositeXform);
  12534. module.exports = DatabarXform;
  12535. },{"../../composite-xform":47,"../../style/color-xform":127,"./cfvo-xform":83}],88:[function(require,module,exports){
  12536. "use strict";
  12537. 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); }
  12538. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12539. 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); } }
  12540. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  12541. 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); }
  12542. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  12543. 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); }; }
  12544. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  12545. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  12546. 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; } }
  12547. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  12548. /* eslint-disable max-classes-per-file */
  12549. var BaseXform = require('../../base-xform');
  12550. var CompositeXform = require('../../composite-xform');
  12551. var X14IdXform = /*#__PURE__*/function (_BaseXform) {
  12552. _inherits(X14IdXform, _BaseXform);
  12553. var _super = _createSuper(X14IdXform);
  12554. function X14IdXform() {
  12555. _classCallCheck(this, X14IdXform);
  12556. return _super.apply(this, arguments);
  12557. }
  12558. _createClass(X14IdXform, [{
  12559. key: "render",
  12560. value: function render(xmlStream, model) {
  12561. xmlStream.leafNode(this.tag, null, model);
  12562. }
  12563. }, {
  12564. key: "parseOpen",
  12565. value: function parseOpen() {
  12566. this.model = '';
  12567. }
  12568. }, {
  12569. key: "parseText",
  12570. value: function parseText(text) {
  12571. this.model += text;
  12572. }
  12573. }, {
  12574. key: "parseClose",
  12575. value: function parseClose(name) {
  12576. return name !== this.tag;
  12577. }
  12578. }, {
  12579. key: "tag",
  12580. get: function get() {
  12581. return 'x14:id';
  12582. }
  12583. }]);
  12584. return X14IdXform;
  12585. }(BaseXform);
  12586. var ExtXform = /*#__PURE__*/function (_CompositeXform) {
  12587. _inherits(ExtXform, _CompositeXform);
  12588. var _super2 = _createSuper(ExtXform);
  12589. function ExtXform() {
  12590. var _this;
  12591. _classCallCheck(this, ExtXform);
  12592. _this = _super2.call(this);
  12593. _this.map = {
  12594. 'x14:id': _this.idXform = new X14IdXform()
  12595. };
  12596. return _this;
  12597. }
  12598. _createClass(ExtXform, [{
  12599. key: "render",
  12600. value: function render(xmlStream, model) {
  12601. xmlStream.openNode(this.tag, {
  12602. uri: '{B025F937-C7B1-47D3-B67F-A62EFF666E3E}',
  12603. 'xmlns:x14': 'http://schemas.microsoft.com/office/spreadsheetml/2009/9/main'
  12604. });
  12605. this.idXform.render(xmlStream, model.x14Id);
  12606. xmlStream.closeNode();
  12607. }
  12608. }, {
  12609. key: "createNewModel",
  12610. value: function createNewModel() {
  12611. return {};
  12612. }
  12613. }, {
  12614. key: "onParserClose",
  12615. value: function onParserClose(name, parser) {
  12616. this.model.x14Id = parser.model;
  12617. }
  12618. }, {
  12619. key: "tag",
  12620. get: function get() {
  12621. return 'ext';
  12622. }
  12623. }]);
  12624. return ExtXform;
  12625. }(CompositeXform);
  12626. var ExtLstRefXform = /*#__PURE__*/function (_CompositeXform2) {
  12627. _inherits(ExtLstRefXform, _CompositeXform2);
  12628. var _super3 = _createSuper(ExtLstRefXform);
  12629. function ExtLstRefXform() {
  12630. var _this2;
  12631. _classCallCheck(this, ExtLstRefXform);
  12632. _this2 = _super3.call(this);
  12633. _this2.map = {
  12634. ext: new ExtXform()
  12635. };
  12636. return _this2;
  12637. }
  12638. _createClass(ExtLstRefXform, [{
  12639. key: "render",
  12640. value: function render(xmlStream, model) {
  12641. xmlStream.openNode(this.tag);
  12642. this.map.ext.render(xmlStream, model);
  12643. xmlStream.closeNode();
  12644. }
  12645. }, {
  12646. key: "createNewModel",
  12647. value: function createNewModel() {
  12648. return {};
  12649. }
  12650. }, {
  12651. key: "onParserClose",
  12652. value: function onParserClose(name, parser) {
  12653. Object.assign(this.model, parser.model);
  12654. }
  12655. }, {
  12656. key: "tag",
  12657. get: function get() {
  12658. return 'extLst';
  12659. }
  12660. }]);
  12661. return ExtLstRefXform;
  12662. }(CompositeXform);
  12663. module.exports = ExtLstRefXform;
  12664. },{"../../base-xform":31,"../../composite-xform":47}],89:[function(require,module,exports){
  12665. "use strict";
  12666. 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); }
  12667. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12668. 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); } }
  12669. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  12670. 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); }
  12671. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  12672. 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); }; }
  12673. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  12674. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  12675. 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; } }
  12676. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  12677. var BaseXform = require('../../base-xform');
  12678. var FormulaXform = /*#__PURE__*/function (_BaseXform) {
  12679. _inherits(FormulaXform, _BaseXform);
  12680. var _super = _createSuper(FormulaXform);
  12681. function FormulaXform() {
  12682. _classCallCheck(this, FormulaXform);
  12683. return _super.apply(this, arguments);
  12684. }
  12685. _createClass(FormulaXform, [{
  12686. key: "render",
  12687. value: function render(xmlStream, model) {
  12688. xmlStream.leafNode(this.tag, null, model);
  12689. }
  12690. }, {
  12691. key: "parseOpen",
  12692. value: function parseOpen() {
  12693. this.model = '';
  12694. }
  12695. }, {
  12696. key: "parseText",
  12697. value: function parseText(text) {
  12698. this.model += text;
  12699. }
  12700. }, {
  12701. key: "parseClose",
  12702. value: function parseClose(name) {
  12703. return name !== this.tag;
  12704. }
  12705. }, {
  12706. key: "tag",
  12707. get: function get() {
  12708. return 'formula';
  12709. }
  12710. }]);
  12711. return FormulaXform;
  12712. }(BaseXform);
  12713. module.exports = FormulaXform;
  12714. },{"../../base-xform":31}],90:[function(require,module,exports){
  12715. "use strict";
  12716. 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); }
  12717. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12718. 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); } }
  12719. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  12720. 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); }
  12721. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  12722. 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); }; }
  12723. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  12724. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  12725. 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; } }
  12726. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  12727. var BaseXform = require('../../base-xform');
  12728. var CompositeXform = require('../../composite-xform');
  12729. var CfvoXform = require('./cfvo-xform');
  12730. var IconSetXform = /*#__PURE__*/function (_CompositeXform) {
  12731. _inherits(IconSetXform, _CompositeXform);
  12732. var _super = _createSuper(IconSetXform);
  12733. function IconSetXform() {
  12734. var _this;
  12735. _classCallCheck(this, IconSetXform);
  12736. _this = _super.call(this);
  12737. _this.map = {
  12738. cfvo: _this.cfvoXform = new CfvoXform()
  12739. };
  12740. return _this;
  12741. }
  12742. _createClass(IconSetXform, [{
  12743. key: "render",
  12744. value: function render(xmlStream, model) {
  12745. var _this2 = this;
  12746. xmlStream.openNode(this.tag, {
  12747. iconSet: BaseXform.toStringAttribute(model.iconSet, '3TrafficLights'),
  12748. reverse: BaseXform.toBoolAttribute(model.reverse, false),
  12749. showValue: BaseXform.toBoolAttribute(model.showValue, true)
  12750. });
  12751. model.cfvo.forEach(function (cfvo) {
  12752. _this2.cfvoXform.render(xmlStream, cfvo);
  12753. });
  12754. xmlStream.closeNode();
  12755. }
  12756. }, {
  12757. key: "createNewModel",
  12758. value: function createNewModel(_ref) {
  12759. var attributes = _ref.attributes;
  12760. return {
  12761. iconSet: BaseXform.toStringValue(attributes.iconSet, '3TrafficLights'),
  12762. reverse: BaseXform.toBoolValue(attributes.reverse),
  12763. showValue: BaseXform.toBoolValue(attributes.showValue),
  12764. cfvo: []
  12765. };
  12766. }
  12767. }, {
  12768. key: "onParserClose",
  12769. value: function onParserClose(name, parser) {
  12770. this.model[name].push(parser.model);
  12771. }
  12772. }, {
  12773. key: "tag",
  12774. get: function get() {
  12775. return 'iconSet';
  12776. }
  12777. }]);
  12778. return IconSetXform;
  12779. }(CompositeXform);
  12780. module.exports = IconSetXform;
  12781. },{"../../base-xform":31,"../../composite-xform":47,"./cfvo-xform":83}],91:[function(require,module,exports){
  12782. "use strict";
  12783. 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); }
  12784. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12785. 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); } }
  12786. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  12787. 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); }
  12788. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  12789. 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); }; }
  12790. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  12791. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  12792. 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; } }
  12793. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  12794. var BaseXform = require('../base-xform');
  12795. var ColXform = /*#__PURE__*/function (_BaseXform) {
  12796. _inherits(ColXform, _BaseXform);
  12797. var _super = _createSuper(ColXform);
  12798. function ColXform() {
  12799. _classCallCheck(this, ColXform);
  12800. return _super.apply(this, arguments);
  12801. }
  12802. _createClass(ColXform, [{
  12803. key: "prepare",
  12804. value: function prepare(model, options) {
  12805. var styleId = options.styles.addStyleModel(model.style || {});
  12806. if (styleId) {
  12807. model.styleId = styleId;
  12808. }
  12809. }
  12810. }, {
  12811. key: "render",
  12812. value: function render(xmlStream, model) {
  12813. xmlStream.openNode('col');
  12814. xmlStream.addAttribute('min', model.min);
  12815. xmlStream.addAttribute('max', model.max);
  12816. if (model.width) {
  12817. xmlStream.addAttribute('width', model.width);
  12818. }
  12819. if (model.styleId) {
  12820. xmlStream.addAttribute('style', model.styleId);
  12821. }
  12822. if (model.hidden) {
  12823. xmlStream.addAttribute('hidden', '1');
  12824. }
  12825. if (model.bestFit) {
  12826. xmlStream.addAttribute('bestFit', '1');
  12827. }
  12828. if (model.outlineLevel) {
  12829. xmlStream.addAttribute('outlineLevel', model.outlineLevel);
  12830. }
  12831. if (model.collapsed) {
  12832. xmlStream.addAttribute('collapsed', '1');
  12833. }
  12834. xmlStream.addAttribute('customWidth', '1');
  12835. xmlStream.closeNode();
  12836. }
  12837. }, {
  12838. key: "parseOpen",
  12839. value: function parseOpen(node) {
  12840. if (node.name === 'col') {
  12841. var model = this.model = {
  12842. min: parseInt(node.attributes.min || '0', 10),
  12843. max: parseInt(node.attributes.max || '0', 10),
  12844. width: node.attributes.width === undefined ? undefined : parseFloat(node.attributes.width || '0')
  12845. };
  12846. if (node.attributes.style) {
  12847. model.styleId = parseInt(node.attributes.style, 10);
  12848. }
  12849. if (node.attributes.hidden === true || node.attributes.hidden === 'true' || node.attributes.hidden === 1 || node.attributes.hidden === '1') {
  12850. model.hidden = true;
  12851. }
  12852. if (node.attributes.bestFit) {
  12853. model.bestFit = true;
  12854. }
  12855. if (node.attributes.outlineLevel) {
  12856. model.outlineLevel = parseInt(node.attributes.outlineLevel, 10);
  12857. }
  12858. if (node.attributes.collapsed) {
  12859. model.collapsed = true;
  12860. }
  12861. return true;
  12862. }
  12863. return false;
  12864. }
  12865. }, {
  12866. key: "parseText",
  12867. value: function parseText() {}
  12868. }, {
  12869. key: "parseClose",
  12870. value: function parseClose() {
  12871. return false;
  12872. }
  12873. }, {
  12874. key: "reconcile",
  12875. value: function reconcile(model, options) {
  12876. // reconcile column styles
  12877. if (model.styleId) {
  12878. model.style = options.styles.getStyleModel(model.styleId);
  12879. }
  12880. }
  12881. }, {
  12882. key: "tag",
  12883. get: function get() {
  12884. return 'col';
  12885. }
  12886. }]);
  12887. return ColXform;
  12888. }(BaseXform);
  12889. module.exports = ColXform;
  12890. },{"../base-xform":31}],92:[function(require,module,exports){
  12891. "use strict";
  12892. 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); }
  12893. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12894. 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); } }
  12895. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  12896. 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); }
  12897. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  12898. 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); }; }
  12899. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  12900. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  12901. 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; } }
  12902. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  12903. 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; }
  12904. 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; }
  12905. 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; }
  12906. var _ = require('../../../utils/under-dash');
  12907. var utils = require('../../../utils/utils');
  12908. var colCache = require('../../../utils/col-cache');
  12909. var BaseXform = require('../base-xform');
  12910. var Range = require('../../../doc/range');
  12911. function assign(definedName, attributes, name, defaultValue) {
  12912. var value = attributes[name];
  12913. if (value !== undefined) {
  12914. definedName[name] = value;
  12915. } else if (defaultValue !== undefined) {
  12916. definedName[name] = defaultValue;
  12917. }
  12918. }
  12919. function parseBool(value) {
  12920. switch (value) {
  12921. case '1':
  12922. case 'true':
  12923. return true;
  12924. default:
  12925. return false;
  12926. }
  12927. }
  12928. function assignBool(definedName, attributes, name, defaultValue) {
  12929. var value = attributes[name];
  12930. if (value !== undefined) {
  12931. definedName[name] = parseBool(value);
  12932. } else if (defaultValue !== undefined) {
  12933. definedName[name] = defaultValue;
  12934. }
  12935. }
  12936. function optimiseDataValidations(model) {
  12937. // Squeeze alike data validations together into rectangular ranges
  12938. // to reduce file size and speed up Excel load time
  12939. var dvList = _.map(model, function (dataValidation, address) {
  12940. return {
  12941. address: address,
  12942. dataValidation: dataValidation,
  12943. marked: false
  12944. };
  12945. }).sort(function (a, b) {
  12946. return _.strcmp(a.address, b.address);
  12947. });
  12948. var dvMap = _.keyBy(dvList, 'address');
  12949. var matchCol = function matchCol(addr, height, col) {
  12950. for (var i = 0; i < height; i++) {
  12951. var otherAddress = colCache.encodeAddress(addr.row + i, col);
  12952. if (!model[otherAddress] || !_.isEqual(model[addr.address], model[otherAddress])) {
  12953. return false;
  12954. }
  12955. }
  12956. return true;
  12957. };
  12958. return dvList.map(function (dv) {
  12959. if (!dv.marked) {
  12960. var addr = colCache.decodeEx(dv.address);
  12961. if (addr.dimensions) {
  12962. dvMap[addr.dimensions].marked = true;
  12963. return _objectSpread(_objectSpread({}, dv.dataValidation), {}, {
  12964. sqref: dv.address
  12965. });
  12966. } // iterate downwards - finding matching cells
  12967. var height = 1;
  12968. var otherAddress = colCache.encodeAddress(addr.row + height, addr.col);
  12969. while (model[otherAddress] && _.isEqual(dv.dataValidation, model[otherAddress])) {
  12970. height++;
  12971. otherAddress = colCache.encodeAddress(addr.row + height, addr.col);
  12972. } // iterate rightwards...
  12973. var width = 1;
  12974. while (matchCol(addr, height, addr.col + width)) {
  12975. width++;
  12976. } // mark all included addresses
  12977. for (var i = 0; i < height; i++) {
  12978. for (var j = 0; j < width; j++) {
  12979. otherAddress = colCache.encodeAddress(addr.row + i, addr.col + j);
  12980. dvMap[otherAddress].marked = true;
  12981. }
  12982. }
  12983. if (height > 1 || width > 1) {
  12984. var bottom = addr.row + (height - 1);
  12985. var right = addr.col + (width - 1);
  12986. return _objectSpread(_objectSpread({}, dv.dataValidation), {}, {
  12987. sqref: "".concat(dv.address, ":").concat(colCache.encodeAddress(bottom, right))
  12988. });
  12989. }
  12990. return _objectSpread(_objectSpread({}, dv.dataValidation), {}, {
  12991. sqref: dv.address
  12992. });
  12993. }
  12994. return null;
  12995. }).filter(Boolean);
  12996. }
  12997. var DataValidationsXform = /*#__PURE__*/function (_BaseXform) {
  12998. _inherits(DataValidationsXform, _BaseXform);
  12999. var _super = _createSuper(DataValidationsXform);
  13000. function DataValidationsXform() {
  13001. _classCallCheck(this, DataValidationsXform);
  13002. return _super.apply(this, arguments);
  13003. }
  13004. _createClass(DataValidationsXform, [{
  13005. key: "render",
  13006. value: function render(xmlStream, model) {
  13007. var optimizedModel = optimiseDataValidations(model);
  13008. if (optimizedModel.length) {
  13009. xmlStream.openNode('dataValidations', {
  13010. count: optimizedModel.length
  13011. });
  13012. optimizedModel.forEach(function (value) {
  13013. xmlStream.openNode('dataValidation');
  13014. if (value.type !== 'any') {
  13015. xmlStream.addAttribute('type', value.type);
  13016. if (value.operator && value.type !== 'list' && value.operator !== 'between') {
  13017. xmlStream.addAttribute('operator', value.operator);
  13018. }
  13019. if (value.allowBlank) {
  13020. xmlStream.addAttribute('allowBlank', '1');
  13021. }
  13022. }
  13023. if (value.showInputMessage) {
  13024. xmlStream.addAttribute('showInputMessage', '1');
  13025. }
  13026. if (value.promptTitle) {
  13027. xmlStream.addAttribute('promptTitle', value.promptTitle);
  13028. }
  13029. if (value.prompt) {
  13030. xmlStream.addAttribute('prompt', value.prompt);
  13031. }
  13032. if (value.showErrorMessage) {
  13033. xmlStream.addAttribute('showErrorMessage', '1');
  13034. }
  13035. if (value.errorStyle) {
  13036. xmlStream.addAttribute('errorStyle', value.errorStyle);
  13037. }
  13038. if (value.errorTitle) {
  13039. xmlStream.addAttribute('errorTitle', value.errorTitle);
  13040. }
  13041. if (value.error) {
  13042. xmlStream.addAttribute('error', value.error);
  13043. }
  13044. xmlStream.addAttribute('sqref', value.sqref);
  13045. (value.formulae || []).forEach(function (formula, index) {
  13046. xmlStream.openNode("formula".concat(index + 1));
  13047. if (value.type === 'date') {
  13048. xmlStream.writeText(utils.dateToExcel(new Date(formula)));
  13049. } else {
  13050. xmlStream.writeText(formula);
  13051. }
  13052. xmlStream.closeNode();
  13053. });
  13054. xmlStream.closeNode();
  13055. });
  13056. xmlStream.closeNode();
  13057. }
  13058. }
  13059. }, {
  13060. key: "parseOpen",
  13061. value: function parseOpen(node) {
  13062. switch (node.name) {
  13063. case 'dataValidations':
  13064. this.model = {};
  13065. return true;
  13066. case 'dataValidation':
  13067. {
  13068. this._address = node.attributes.sqref;
  13069. var dataValidation = {
  13070. type: node.attributes.type || 'any',
  13071. formulae: []
  13072. };
  13073. if (node.attributes.type) {
  13074. assignBool(dataValidation, node.attributes, 'allowBlank');
  13075. }
  13076. assignBool(dataValidation, node.attributes, 'showInputMessage');
  13077. assignBool(dataValidation, node.attributes, 'showErrorMessage');
  13078. switch (dataValidation.type) {
  13079. case 'any':
  13080. case 'list':
  13081. case 'custom':
  13082. break;
  13083. default:
  13084. assign(dataValidation, node.attributes, 'operator', 'between');
  13085. break;
  13086. }
  13087. assign(dataValidation, node.attributes, 'promptTitle');
  13088. assign(dataValidation, node.attributes, 'prompt');
  13089. assign(dataValidation, node.attributes, 'errorStyle');
  13090. assign(dataValidation, node.attributes, 'errorTitle');
  13091. assign(dataValidation, node.attributes, 'error');
  13092. this._dataValidation = dataValidation;
  13093. return true;
  13094. }
  13095. case 'formula1':
  13096. case 'formula2':
  13097. this._formula = [];
  13098. return true;
  13099. default:
  13100. return false;
  13101. }
  13102. }
  13103. }, {
  13104. key: "parseText",
  13105. value: function parseText(text) {
  13106. if (this._formula) {
  13107. this._formula.push(text);
  13108. }
  13109. }
  13110. }, {
  13111. key: "parseClose",
  13112. value: function parseClose(name) {
  13113. var _this = this;
  13114. switch (name) {
  13115. case 'dataValidations':
  13116. return false;
  13117. case 'dataValidation':
  13118. {
  13119. if (!this._dataValidation.formulae || !this._dataValidation.formulae.length) {
  13120. delete this._dataValidation.formulae;
  13121. delete this._dataValidation.operator;
  13122. } // The four known cases: 1. E4:L9 N4:U9 2.E4 L9 3. N4:U9 4. E4
  13123. var list = this._address.split(/\s+/g) || [];
  13124. list.forEach(function (addr) {
  13125. if (addr.includes(':')) {
  13126. var range = new Range(addr);
  13127. range.forEachAddress(function (address) {
  13128. _this.model[address] = _this._dataValidation;
  13129. });
  13130. } else {
  13131. _this.model[addr] = _this._dataValidation;
  13132. }
  13133. });
  13134. return true;
  13135. }
  13136. case 'formula1':
  13137. case 'formula2':
  13138. {
  13139. var formula = this._formula.join('');
  13140. switch (this._dataValidation.type) {
  13141. case 'whole':
  13142. case 'textLength':
  13143. formula = parseInt(formula, 10);
  13144. break;
  13145. case 'decimal':
  13146. formula = parseFloat(formula);
  13147. break;
  13148. case 'date':
  13149. formula = utils.excelToDate(parseFloat(formula));
  13150. break;
  13151. default:
  13152. break;
  13153. }
  13154. this._dataValidation.formulae.push(formula);
  13155. this._formula = undefined;
  13156. return true;
  13157. }
  13158. default:
  13159. return true;
  13160. }
  13161. }
  13162. }, {
  13163. key: "tag",
  13164. get: function get() {
  13165. return 'dataValidations';
  13166. }
  13167. }]);
  13168. return DataValidationsXform;
  13169. }(BaseXform);
  13170. module.exports = DataValidationsXform;
  13171. },{"../../../doc/range":10,"../../../utils/col-cache":19,"../../../utils/under-dash":25,"../../../utils/utils":26,"../base-xform":31}],93:[function(require,module,exports){
  13172. "use strict";
  13173. 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); }
  13174. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13175. 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); } }
  13176. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13177. 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); }
  13178. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13179. 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); }; }
  13180. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13181. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13182. 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; } }
  13183. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13184. var BaseXform = require('../base-xform');
  13185. var DimensionXform = /*#__PURE__*/function (_BaseXform) {
  13186. _inherits(DimensionXform, _BaseXform);
  13187. var _super = _createSuper(DimensionXform);
  13188. function DimensionXform() {
  13189. _classCallCheck(this, DimensionXform);
  13190. return _super.apply(this, arguments);
  13191. }
  13192. _createClass(DimensionXform, [{
  13193. key: "render",
  13194. value: function render(xmlStream, model) {
  13195. if (model) {
  13196. xmlStream.leafNode('dimension', {
  13197. ref: model
  13198. });
  13199. }
  13200. }
  13201. }, {
  13202. key: "parseOpen",
  13203. value: function parseOpen(node) {
  13204. if (node.name === 'dimension') {
  13205. this.model = node.attributes.ref;
  13206. return true;
  13207. }
  13208. return false;
  13209. }
  13210. }, {
  13211. key: "parseText",
  13212. value: function parseText() {}
  13213. }, {
  13214. key: "parseClose",
  13215. value: function parseClose() {
  13216. return false;
  13217. }
  13218. }, {
  13219. key: "tag",
  13220. get: function get() {
  13221. return 'dimension';
  13222. }
  13223. }]);
  13224. return DimensionXform;
  13225. }(BaseXform);
  13226. module.exports = DimensionXform;
  13227. },{"../base-xform":31}],94:[function(require,module,exports){
  13228. "use strict";
  13229. 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); }
  13230. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13231. 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); } }
  13232. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13233. 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); }
  13234. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13235. 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); }; }
  13236. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13237. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13238. 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; } }
  13239. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13240. var BaseXform = require('../base-xform');
  13241. var DrawingXform = /*#__PURE__*/function (_BaseXform) {
  13242. _inherits(DrawingXform, _BaseXform);
  13243. var _super = _createSuper(DrawingXform);
  13244. function DrawingXform() {
  13245. _classCallCheck(this, DrawingXform);
  13246. return _super.apply(this, arguments);
  13247. }
  13248. _createClass(DrawingXform, [{
  13249. key: "render",
  13250. value: function render(xmlStream, model) {
  13251. if (model) {
  13252. xmlStream.leafNode(this.tag, {
  13253. 'r:id': model.rId
  13254. });
  13255. }
  13256. }
  13257. }, {
  13258. key: "parseOpen",
  13259. value: function parseOpen(node) {
  13260. switch (node.name) {
  13261. case this.tag:
  13262. this.model = {
  13263. rId: node.attributes['r:id']
  13264. };
  13265. return true;
  13266. default:
  13267. return false;
  13268. }
  13269. }
  13270. }, {
  13271. key: "parseText",
  13272. value: function parseText() {}
  13273. }, {
  13274. key: "parseClose",
  13275. value: function parseClose() {
  13276. return false;
  13277. }
  13278. }, {
  13279. key: "tag",
  13280. get: function get() {
  13281. return 'drawing';
  13282. }
  13283. }]);
  13284. return DrawingXform;
  13285. }(BaseXform);
  13286. module.exports = DrawingXform;
  13287. },{"../base-xform":31}],95:[function(require,module,exports){
  13288. "use strict";
  13289. 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); }
  13290. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13291. 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); } }
  13292. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13293. 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); }
  13294. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13295. 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); }; }
  13296. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13297. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13298. 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; } }
  13299. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13300. /* eslint-disable max-classes-per-file */
  13301. var CompositeXform = require('../composite-xform');
  13302. var ConditionalFormattingsExt = require('./cf-ext/conditional-formattings-ext-xform');
  13303. var ExtXform = /*#__PURE__*/function (_CompositeXform) {
  13304. _inherits(ExtXform, _CompositeXform);
  13305. var _super = _createSuper(ExtXform);
  13306. function ExtXform() {
  13307. var _this;
  13308. _classCallCheck(this, ExtXform);
  13309. _this = _super.call(this);
  13310. _this.map = {
  13311. 'x14:conditionalFormattings': _this.conditionalFormattings = new ConditionalFormattingsExt()
  13312. };
  13313. return _this;
  13314. }
  13315. _createClass(ExtXform, [{
  13316. key: "hasContent",
  13317. value: function hasContent(model) {
  13318. return this.conditionalFormattings.hasContent(model.conditionalFormattings);
  13319. }
  13320. }, {
  13321. key: "prepare",
  13322. value: function prepare(model, options) {
  13323. this.conditionalFormattings.prepare(model.conditionalFormattings, options);
  13324. }
  13325. }, {
  13326. key: "render",
  13327. value: function render(xmlStream, model) {
  13328. xmlStream.openNode('ext', {
  13329. uri: '{78C0D931-6437-407d-A8EE-F0AAD7539E65}',
  13330. 'xmlns:x14': 'http://schemas.microsoft.com/office/spreadsheetml/2009/9/main'
  13331. });
  13332. this.conditionalFormattings.render(xmlStream, model.conditionalFormattings);
  13333. xmlStream.closeNode();
  13334. }
  13335. }, {
  13336. key: "createNewModel",
  13337. value: function createNewModel() {
  13338. return {};
  13339. }
  13340. }, {
  13341. key: "onParserClose",
  13342. value: function onParserClose(name, parser) {
  13343. this.model[name] = parser.model;
  13344. }
  13345. }, {
  13346. key: "tag",
  13347. get: function get() {
  13348. return 'ext';
  13349. }
  13350. }]);
  13351. return ExtXform;
  13352. }(CompositeXform);
  13353. var ExtLstXform = /*#__PURE__*/function (_CompositeXform2) {
  13354. _inherits(ExtLstXform, _CompositeXform2);
  13355. var _super2 = _createSuper(ExtLstXform);
  13356. function ExtLstXform() {
  13357. var _this2;
  13358. _classCallCheck(this, ExtLstXform);
  13359. _this2 = _super2.call(this);
  13360. _this2.map = {
  13361. ext: _this2.ext = new ExtXform()
  13362. };
  13363. return _this2;
  13364. }
  13365. _createClass(ExtLstXform, [{
  13366. key: "prepare",
  13367. value: function prepare(model, options) {
  13368. this.ext.prepare(model, options);
  13369. }
  13370. }, {
  13371. key: "hasContent",
  13372. value: function hasContent(model) {
  13373. return this.ext.hasContent(model);
  13374. }
  13375. }, {
  13376. key: "render",
  13377. value: function render(xmlStream, model) {
  13378. if (!this.hasContent(model)) {
  13379. return;
  13380. }
  13381. xmlStream.openNode('extLst');
  13382. this.ext.render(xmlStream, model);
  13383. xmlStream.closeNode();
  13384. }
  13385. }, {
  13386. key: "createNewModel",
  13387. value: function createNewModel() {
  13388. return {};
  13389. }
  13390. }, {
  13391. key: "onParserClose",
  13392. value: function onParserClose(name, parser) {
  13393. Object.assign(this.model, parser.model);
  13394. }
  13395. }, {
  13396. key: "tag",
  13397. get: function get() {
  13398. return 'extLst';
  13399. }
  13400. }]);
  13401. return ExtLstXform;
  13402. }(CompositeXform);
  13403. module.exports = ExtLstXform;
  13404. },{"../composite-xform":47,"./cf-ext/conditional-formattings-ext-xform":77}],96:[function(require,module,exports){
  13405. "use strict";
  13406. 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); }
  13407. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13408. 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); } }
  13409. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13410. 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); }
  13411. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13412. 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); }; }
  13413. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13414. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13415. 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; } }
  13416. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13417. var BaseXform = require('../base-xform');
  13418. var HeaderFooterXform = /*#__PURE__*/function (_BaseXform) {
  13419. _inherits(HeaderFooterXform, _BaseXform);
  13420. var _super = _createSuper(HeaderFooterXform);
  13421. function HeaderFooterXform() {
  13422. _classCallCheck(this, HeaderFooterXform);
  13423. return _super.apply(this, arguments);
  13424. }
  13425. _createClass(HeaderFooterXform, [{
  13426. key: "render",
  13427. value: function render(xmlStream, model) {
  13428. if (model) {
  13429. xmlStream.addRollback();
  13430. var createTag = false;
  13431. xmlStream.openNode('headerFooter');
  13432. if (model.differentFirst) {
  13433. xmlStream.addAttribute('differentFirst', '1');
  13434. createTag = true;
  13435. }
  13436. if (model.differentOddEven) {
  13437. xmlStream.addAttribute('differentOddEven', '1');
  13438. createTag = true;
  13439. }
  13440. if (model.oddHeader && typeof model.oddHeader === 'string') {
  13441. xmlStream.leafNode('oddHeader', null, model.oddHeader);
  13442. createTag = true;
  13443. }
  13444. if (model.oddFooter && typeof model.oddFooter === 'string') {
  13445. xmlStream.leafNode('oddFooter', null, model.oddFooter);
  13446. createTag = true;
  13447. }
  13448. if (model.evenHeader && typeof model.evenHeader === 'string') {
  13449. xmlStream.leafNode('evenHeader', null, model.evenHeader);
  13450. createTag = true;
  13451. }
  13452. if (model.evenFooter && typeof model.evenFooter === 'string') {
  13453. xmlStream.leafNode('evenFooter', null, model.evenFooter);
  13454. createTag = true;
  13455. }
  13456. if (model.firstHeader && typeof model.firstHeader === 'string') {
  13457. xmlStream.leafNode('firstHeader', null, model.firstHeader);
  13458. createTag = true;
  13459. }
  13460. if (model.firstFooter && typeof model.firstFooter === 'string') {
  13461. xmlStream.leafNode('firstFooter', null, model.firstFooter);
  13462. createTag = true;
  13463. }
  13464. if (createTag) {
  13465. xmlStream.closeNode();
  13466. xmlStream.commit();
  13467. } else {
  13468. xmlStream.rollback();
  13469. }
  13470. }
  13471. }
  13472. }, {
  13473. key: "parseOpen",
  13474. value: function parseOpen(node) {
  13475. switch (node.name) {
  13476. case 'headerFooter':
  13477. this.model = {};
  13478. if (node.attributes.differentFirst) {
  13479. this.model.differentFirst = parseInt(node.attributes.differentFirst, 0) === 1;
  13480. }
  13481. if (node.attributes.differentOddEven) {
  13482. this.model.differentOddEven = parseInt(node.attributes.differentOddEven, 0) === 1;
  13483. }
  13484. return true;
  13485. case 'oddHeader':
  13486. this.currentNode = 'oddHeader';
  13487. return true;
  13488. case 'oddFooter':
  13489. this.currentNode = 'oddFooter';
  13490. return true;
  13491. case 'evenHeader':
  13492. this.currentNode = 'evenHeader';
  13493. return true;
  13494. case 'evenFooter':
  13495. this.currentNode = 'evenFooter';
  13496. return true;
  13497. case 'firstHeader':
  13498. this.currentNode = 'firstHeader';
  13499. return true;
  13500. case 'firstFooter':
  13501. this.currentNode = 'firstFooter';
  13502. return true;
  13503. default:
  13504. return false;
  13505. }
  13506. }
  13507. }, {
  13508. key: "parseText",
  13509. value: function parseText(text) {
  13510. switch (this.currentNode) {
  13511. case 'oddHeader':
  13512. this.model.oddHeader = text;
  13513. break;
  13514. case 'oddFooter':
  13515. this.model.oddFooter = text;
  13516. break;
  13517. case 'evenHeader':
  13518. this.model.evenHeader = text;
  13519. break;
  13520. case 'evenFooter':
  13521. this.model.evenFooter = text;
  13522. break;
  13523. case 'firstHeader':
  13524. this.model.firstHeader = text;
  13525. break;
  13526. case 'firstFooter':
  13527. this.model.firstFooter = text;
  13528. break;
  13529. default:
  13530. break;
  13531. }
  13532. }
  13533. }, {
  13534. key: "parseClose",
  13535. value: function parseClose() {
  13536. switch (this.currentNode) {
  13537. case 'oddHeader':
  13538. case 'oddFooter':
  13539. case 'evenHeader':
  13540. case 'evenFooter':
  13541. case 'firstHeader':
  13542. case 'firstFooter':
  13543. this.currentNode = undefined;
  13544. return true;
  13545. default:
  13546. return false;
  13547. }
  13548. }
  13549. }, {
  13550. key: "tag",
  13551. get: function get() {
  13552. return 'headerFooter';
  13553. }
  13554. }]);
  13555. return HeaderFooterXform;
  13556. }(BaseXform);
  13557. module.exports = HeaderFooterXform;
  13558. },{"../base-xform":31}],97:[function(require,module,exports){
  13559. "use strict";
  13560. 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); }
  13561. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13562. 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); } }
  13563. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13564. 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); }
  13565. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13566. 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); }; }
  13567. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13568. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13569. 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; } }
  13570. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13571. var BaseXform = require('../base-xform');
  13572. var HyperlinkXform = /*#__PURE__*/function (_BaseXform) {
  13573. _inherits(HyperlinkXform, _BaseXform);
  13574. var _super = _createSuper(HyperlinkXform);
  13575. function HyperlinkXform() {
  13576. _classCallCheck(this, HyperlinkXform);
  13577. return _super.apply(this, arguments);
  13578. }
  13579. _createClass(HyperlinkXform, [{
  13580. key: "render",
  13581. value: function render(xmlStream, model) {
  13582. xmlStream.leafNode('hyperlink', {
  13583. ref: model.address,
  13584. 'r:id': model.rId,
  13585. tooltip: model.tooltip
  13586. });
  13587. }
  13588. }, {
  13589. key: "parseOpen",
  13590. value: function parseOpen(node) {
  13591. if (node.name === 'hyperlink') {
  13592. this.model = {
  13593. address: node.attributes.ref,
  13594. rId: node.attributes['r:id'],
  13595. tooltip: node.attributes.tooltip
  13596. };
  13597. return true;
  13598. }
  13599. return false;
  13600. }
  13601. }, {
  13602. key: "parseText",
  13603. value: function parseText() {}
  13604. }, {
  13605. key: "parseClose",
  13606. value: function parseClose() {
  13607. return false;
  13608. }
  13609. }, {
  13610. key: "tag",
  13611. get: function get() {
  13612. return 'hyperlink';
  13613. }
  13614. }]);
  13615. return HyperlinkXform;
  13616. }(BaseXform);
  13617. module.exports = HyperlinkXform;
  13618. },{"../base-xform":31}],98:[function(require,module,exports){
  13619. "use strict";
  13620. 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); }
  13621. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13622. 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); } }
  13623. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13624. 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); }
  13625. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13626. 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); }; }
  13627. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13628. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13629. 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; } }
  13630. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13631. var BaseXform = require('../base-xform');
  13632. var MergeCellXform = /*#__PURE__*/function (_BaseXform) {
  13633. _inherits(MergeCellXform, _BaseXform);
  13634. var _super = _createSuper(MergeCellXform);
  13635. function MergeCellXform() {
  13636. _classCallCheck(this, MergeCellXform);
  13637. return _super.apply(this, arguments);
  13638. }
  13639. _createClass(MergeCellXform, [{
  13640. key: "render",
  13641. value: function render(xmlStream, model) {
  13642. xmlStream.leafNode('mergeCell', {
  13643. ref: model
  13644. });
  13645. }
  13646. }, {
  13647. key: "parseOpen",
  13648. value: function parseOpen(node) {
  13649. if (node.name === 'mergeCell') {
  13650. this.model = node.attributes.ref;
  13651. return true;
  13652. }
  13653. return false;
  13654. }
  13655. }, {
  13656. key: "parseText",
  13657. value: function parseText() {}
  13658. }, {
  13659. key: "parseClose",
  13660. value: function parseClose() {
  13661. return false;
  13662. }
  13663. }, {
  13664. key: "tag",
  13665. get: function get() {
  13666. return 'mergeCell';
  13667. }
  13668. }]);
  13669. return MergeCellXform;
  13670. }(BaseXform);
  13671. module.exports = MergeCellXform;
  13672. },{"../base-xform":31}],99:[function(require,module,exports){
  13673. "use strict";
  13674. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13675. 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); } }
  13676. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13677. var _ = require('../../../utils/under-dash');
  13678. var Range = require('../../../doc/range');
  13679. var colCache = require('../../../utils/col-cache');
  13680. var Enums = require('../../../doc/enums');
  13681. var Merges = /*#__PURE__*/function () {
  13682. function Merges() {
  13683. _classCallCheck(this, Merges);
  13684. // optional mergeCells is array of ranges (like the xml)
  13685. this.merges = {};
  13686. }
  13687. _createClass(Merges, [{
  13688. key: "add",
  13689. value: function add(merge) {
  13690. // merge is {address, master}
  13691. if (this.merges[merge.master]) {
  13692. this.merges[merge.master].expandToAddress(merge.address);
  13693. } else {
  13694. var range = "".concat(merge.master, ":").concat(merge.address);
  13695. this.merges[merge.master] = new Range(range);
  13696. }
  13697. }
  13698. }, {
  13699. key: "reconcile",
  13700. value: function reconcile(mergeCells, rows) {
  13701. // reconcile merge list with merge cells
  13702. _.each(mergeCells, function (merge) {
  13703. var dimensions = colCache.decode(merge);
  13704. for (var i = dimensions.top; i <= dimensions.bottom; i++) {
  13705. var row = rows[i - 1];
  13706. for (var j = dimensions.left; j <= dimensions.right; j++) {
  13707. var cell = row.cells[j - 1];
  13708. if (!cell) {
  13709. // nulls are not included in document - so if master cell has no value - add a null one here
  13710. row.cells[j] = {
  13711. type: Enums.ValueType.Null,
  13712. address: colCache.encodeAddress(i, j)
  13713. };
  13714. } else if (cell.type === Enums.ValueType.Merge) {
  13715. cell.master = dimensions.tl;
  13716. }
  13717. }
  13718. }
  13719. });
  13720. }
  13721. }, {
  13722. key: "getMasterAddress",
  13723. value: function getMasterAddress(address) {
  13724. // if address has been merged, return its master's address. Assumes reconcile has been called
  13725. var range = this.hash[address];
  13726. return range && range.tl;
  13727. }
  13728. }, {
  13729. key: "mergeCells",
  13730. get: function get() {
  13731. return _.map(this.merges, function (merge) {
  13732. return merge.range;
  13733. });
  13734. }
  13735. }]);
  13736. return Merges;
  13737. }();
  13738. module.exports = Merges;
  13739. },{"../../../doc/enums":7,"../../../doc/range":10,"../../../utils/col-cache":19,"../../../utils/under-dash":25}],100:[function(require,module,exports){
  13740. "use strict";
  13741. 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); }
  13742. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13743. 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); } }
  13744. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13745. 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); }
  13746. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13747. 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); }; }
  13748. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13749. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13750. 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; } }
  13751. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13752. var BaseXform = require('../base-xform');
  13753. var isDefined = function isDefined(attr) {
  13754. return typeof attr !== 'undefined';
  13755. };
  13756. var OutlinePropertiesXform = /*#__PURE__*/function (_BaseXform) {
  13757. _inherits(OutlinePropertiesXform, _BaseXform);
  13758. var _super = _createSuper(OutlinePropertiesXform);
  13759. function OutlinePropertiesXform() {
  13760. _classCallCheck(this, OutlinePropertiesXform);
  13761. return _super.apply(this, arguments);
  13762. }
  13763. _createClass(OutlinePropertiesXform, [{
  13764. key: "render",
  13765. value: function render(xmlStream, model) {
  13766. if (model && (isDefined(model.summaryBelow) || isDefined(model.summaryRight))) {
  13767. xmlStream.leafNode(this.tag, {
  13768. summaryBelow: isDefined(model.summaryBelow) ? Number(model.summaryBelow) : undefined,
  13769. summaryRight: isDefined(model.summaryRight) ? Number(model.summaryRight) : undefined
  13770. });
  13771. return true;
  13772. }
  13773. return false;
  13774. }
  13775. }, {
  13776. key: "parseOpen",
  13777. value: function parseOpen(node) {
  13778. if (node.name === this.tag) {
  13779. this.model = {
  13780. summaryBelow: isDefined(node.attributes.summaryBelow) ? Boolean(Number(node.attributes.summaryBelow)) : undefined,
  13781. summaryRight: isDefined(node.attributes.summaryRight) ? Boolean(Number(node.attributes.summaryRight)) : undefined
  13782. };
  13783. return true;
  13784. }
  13785. return false;
  13786. }
  13787. }, {
  13788. key: "parseText",
  13789. value: function parseText() {}
  13790. }, {
  13791. key: "parseClose",
  13792. value: function parseClose() {
  13793. return false;
  13794. }
  13795. }, {
  13796. key: "tag",
  13797. get: function get() {
  13798. return 'outlinePr';
  13799. }
  13800. }]);
  13801. return OutlinePropertiesXform;
  13802. }(BaseXform);
  13803. module.exports = OutlinePropertiesXform;
  13804. },{"../base-xform":31}],101:[function(require,module,exports){
  13805. "use strict";
  13806. 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); }
  13807. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13808. 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); } }
  13809. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13810. 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); }
  13811. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13812. 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); }; }
  13813. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13814. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13815. 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; } }
  13816. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13817. var BaseXform = require('../base-xform');
  13818. var PageBreaksXform = /*#__PURE__*/function (_BaseXform) {
  13819. _inherits(PageBreaksXform, _BaseXform);
  13820. var _super = _createSuper(PageBreaksXform);
  13821. function PageBreaksXform() {
  13822. _classCallCheck(this, PageBreaksXform);
  13823. return _super.apply(this, arguments);
  13824. }
  13825. _createClass(PageBreaksXform, [{
  13826. key: "render",
  13827. value: function render(xmlStream, model) {
  13828. xmlStream.leafNode('brk', model);
  13829. }
  13830. }, {
  13831. key: "parseOpen",
  13832. value: function parseOpen(node) {
  13833. if (node.name === 'brk') {
  13834. this.model = node.attributes.ref;
  13835. return true;
  13836. }
  13837. return false;
  13838. }
  13839. }, {
  13840. key: "parseText",
  13841. value: function parseText() {}
  13842. }, {
  13843. key: "parseClose",
  13844. value: function parseClose() {
  13845. return false;
  13846. }
  13847. }, {
  13848. key: "tag",
  13849. get: function get() {
  13850. return 'brk';
  13851. }
  13852. }]);
  13853. return PageBreaksXform;
  13854. }(BaseXform);
  13855. module.exports = PageBreaksXform;
  13856. },{"../base-xform":31}],102:[function(require,module,exports){
  13857. "use strict";
  13858. 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); }
  13859. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13860. 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); } }
  13861. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13862. 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); }
  13863. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13864. 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); }; }
  13865. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13866. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13867. 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; } }
  13868. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13869. var _ = require('../../../utils/under-dash');
  13870. var BaseXform = require('../base-xform');
  13871. var PageMarginsXform = /*#__PURE__*/function (_BaseXform) {
  13872. _inherits(PageMarginsXform, _BaseXform);
  13873. var _super = _createSuper(PageMarginsXform);
  13874. function PageMarginsXform() {
  13875. _classCallCheck(this, PageMarginsXform);
  13876. return _super.apply(this, arguments);
  13877. }
  13878. _createClass(PageMarginsXform, [{
  13879. key: "render",
  13880. value: function render(xmlStream, model) {
  13881. if (model) {
  13882. var attributes = {
  13883. left: model.left,
  13884. right: model.right,
  13885. top: model.top,
  13886. bottom: model.bottom,
  13887. header: model.header,
  13888. footer: model.footer
  13889. };
  13890. if (_.some(attributes, function (value) {
  13891. return value !== undefined;
  13892. })) {
  13893. xmlStream.leafNode(this.tag, attributes);
  13894. }
  13895. }
  13896. }
  13897. }, {
  13898. key: "parseOpen",
  13899. value: function parseOpen(node) {
  13900. switch (node.name) {
  13901. case this.tag:
  13902. this.model = {
  13903. left: parseFloat(node.attributes.left || 0.7),
  13904. right: parseFloat(node.attributes.right || 0.7),
  13905. top: parseFloat(node.attributes.top || 0.75),
  13906. bottom: parseFloat(node.attributes.bottom || 0.75),
  13907. header: parseFloat(node.attributes.header || 0.3),
  13908. footer: parseFloat(node.attributes.footer || 0.3)
  13909. };
  13910. return true;
  13911. default:
  13912. return false;
  13913. }
  13914. }
  13915. }, {
  13916. key: "parseText",
  13917. value: function parseText() {}
  13918. }, {
  13919. key: "parseClose",
  13920. value: function parseClose() {
  13921. return false;
  13922. }
  13923. }, {
  13924. key: "tag",
  13925. get: function get() {
  13926. return 'pageMargins';
  13927. }
  13928. }]);
  13929. return PageMarginsXform;
  13930. }(BaseXform);
  13931. module.exports = PageMarginsXform;
  13932. },{"../../../utils/under-dash":25,"../base-xform":31}],103:[function(require,module,exports){
  13933. "use strict";
  13934. 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); }
  13935. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13936. 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); } }
  13937. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13938. 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); }
  13939. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13940. 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); }; }
  13941. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13942. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13943. 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; } }
  13944. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13945. var BaseXform = require('../base-xform');
  13946. var PageSetupPropertiesXform = /*#__PURE__*/function (_BaseXform) {
  13947. _inherits(PageSetupPropertiesXform, _BaseXform);
  13948. var _super = _createSuper(PageSetupPropertiesXform);
  13949. function PageSetupPropertiesXform() {
  13950. _classCallCheck(this, PageSetupPropertiesXform);
  13951. return _super.apply(this, arguments);
  13952. }
  13953. _createClass(PageSetupPropertiesXform, [{
  13954. key: "render",
  13955. value: function render(xmlStream, model) {
  13956. if (model && model.fitToPage) {
  13957. xmlStream.leafNode(this.tag, {
  13958. fitToPage: model.fitToPage ? '1' : undefined
  13959. });
  13960. return true;
  13961. }
  13962. return false;
  13963. }
  13964. }, {
  13965. key: "parseOpen",
  13966. value: function parseOpen(node) {
  13967. if (node.name === this.tag) {
  13968. this.model = {
  13969. fitToPage: node.attributes.fitToPage === '1'
  13970. };
  13971. return true;
  13972. }
  13973. return false;
  13974. }
  13975. }, {
  13976. key: "parseText",
  13977. value: function parseText() {}
  13978. }, {
  13979. key: "parseClose",
  13980. value: function parseClose() {
  13981. return false;
  13982. }
  13983. }, {
  13984. key: "tag",
  13985. get: function get() {
  13986. return 'pageSetUpPr';
  13987. }
  13988. }]);
  13989. return PageSetupPropertiesXform;
  13990. }(BaseXform);
  13991. module.exports = PageSetupPropertiesXform;
  13992. },{"../base-xform":31}],104:[function(require,module,exports){
  13993. "use strict";
  13994. 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); }
  13995. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13996. 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); } }
  13997. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13998. 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); }
  13999. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  14000. 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); }; }
  14001. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  14002. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  14003. 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; } }
  14004. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  14005. var _ = require('../../../utils/under-dash');
  14006. var BaseXform = require('../base-xform');
  14007. function booleanToXml(model) {
  14008. return model ? '1' : undefined;
  14009. }
  14010. function pageOrderToXml(model) {
  14011. switch (model) {
  14012. case 'overThenDown':
  14013. return model;
  14014. default:
  14015. return undefined;
  14016. }
  14017. }
  14018. function cellCommentsToXml(model) {
  14019. switch (model) {
  14020. case 'atEnd':
  14021. case 'asDisplyed':
  14022. return model;
  14023. default:
  14024. return undefined;
  14025. }
  14026. }
  14027. function errorsToXml(model) {
  14028. switch (model) {
  14029. case 'dash':
  14030. case 'blank':
  14031. case 'NA':
  14032. return model;
  14033. default:
  14034. return undefined;
  14035. }
  14036. }
  14037. function pageSizeToModel(value) {
  14038. return value !== undefined ? parseInt(value, 10) : undefined;
  14039. }
  14040. var PageSetupXform = /*#__PURE__*/function (_BaseXform) {
  14041. _inherits(PageSetupXform, _BaseXform);
  14042. var _super = _createSuper(PageSetupXform);
  14043. function PageSetupXform() {
  14044. _classCallCheck(this, PageSetupXform);
  14045. return _super.apply(this, arguments);
  14046. }
  14047. _createClass(PageSetupXform, [{
  14048. key: "render",
  14049. value: function render(xmlStream, model) {
  14050. if (model) {
  14051. var attributes = {
  14052. paperSize: model.paperSize,
  14053. orientation: model.orientation,
  14054. horizontalDpi: model.horizontalDpi,
  14055. verticalDpi: model.verticalDpi,
  14056. pageOrder: pageOrderToXml(model.pageOrder),
  14057. blackAndWhite: booleanToXml(model.blackAndWhite),
  14058. draft: booleanToXml(model.draft),
  14059. cellComments: cellCommentsToXml(model.cellComments),
  14060. errors: errorsToXml(model.errors),
  14061. scale: model.scale,
  14062. fitToWidth: model.fitToWidth,
  14063. fitToHeight: model.fitToHeight,
  14064. firstPageNumber: model.firstPageNumber,
  14065. useFirstPageNumber: booleanToXml(model.firstPageNumber),
  14066. usePrinterDefaults: booleanToXml(model.usePrinterDefaults),
  14067. copies: model.copies
  14068. };
  14069. if (_.some(attributes, function (value) {
  14070. return value !== undefined;
  14071. })) {
  14072. xmlStream.leafNode(this.tag, attributes);
  14073. }
  14074. }
  14075. }
  14076. }, {
  14077. key: "parseOpen",
  14078. value: function parseOpen(node) {
  14079. switch (node.name) {
  14080. case this.tag:
  14081. this.model = {
  14082. paperSize: pageSizeToModel(node.attributes.paperSize),
  14083. orientation: node.attributes.orientation || 'portrait',
  14084. horizontalDpi: parseInt(node.attributes.horizontalDpi || '4294967295', 10),
  14085. verticalDpi: parseInt(node.attributes.verticalDpi || '4294967295', 10),
  14086. pageOrder: node.attributes.pageOrder || 'downThenOver',
  14087. blackAndWhite: node.attributes.blackAndWhite === '1',
  14088. draft: node.attributes.draft === '1',
  14089. cellComments: node.attributes.cellComments || 'None',
  14090. errors: node.attributes.errors || 'displayed',
  14091. scale: parseInt(node.attributes.scale || '100', 10),
  14092. fitToWidth: parseInt(node.attributes.fitToWidth || '1', 10),
  14093. fitToHeight: parseInt(node.attributes.fitToHeight || '1', 10),
  14094. firstPageNumber: parseInt(node.attributes.firstPageNumber || '1', 10),
  14095. useFirstPageNumber: node.attributes.useFirstPageNumber === '1',
  14096. usePrinterDefaults: node.attributes.usePrinterDefaults === '1',
  14097. copies: parseInt(node.attributes.copies || '1', 10)
  14098. };
  14099. return true;
  14100. default:
  14101. return false;
  14102. }
  14103. }
  14104. }, {
  14105. key: "parseText",
  14106. value: function parseText() {}
  14107. }, {
  14108. key: "parseClose",
  14109. value: function parseClose() {
  14110. return false;
  14111. }
  14112. }, {
  14113. key: "tag",
  14114. get: function get() {
  14115. return 'pageSetup';
  14116. }
  14117. }]);
  14118. return PageSetupXform;
  14119. }(BaseXform);
  14120. module.exports = PageSetupXform;
  14121. },{"../../../utils/under-dash":25,"../base-xform":31}],105:[function(require,module,exports){
  14122. "use strict";
  14123. 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); }
  14124. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14125. 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); } }
  14126. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  14127. 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); }
  14128. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  14129. 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); }; }
  14130. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  14131. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  14132. 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; } }
  14133. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  14134. var BaseXform = require('../base-xform');
  14135. var PictureXform = /*#__PURE__*/function (_BaseXform) {
  14136. _inherits(PictureXform, _BaseXform);
  14137. var _super = _createSuper(PictureXform);
  14138. function PictureXform() {
  14139. _classCallCheck(this, PictureXform);
  14140. return _super.apply(this, arguments);
  14141. }
  14142. _createClass(PictureXform, [{
  14143. key: "render",
  14144. value: function render(xmlStream, model) {
  14145. if (model) {
  14146. xmlStream.leafNode(this.tag, {
  14147. 'r:id': model.rId
  14148. });
  14149. }
  14150. }
  14151. }, {
  14152. key: "parseOpen",
  14153. value: function parseOpen(node) {
  14154. switch (node.name) {
  14155. case this.tag:
  14156. this.model = {
  14157. rId: node.attributes['r:id']
  14158. };
  14159. return true;
  14160. default:
  14161. return false;
  14162. }
  14163. }
  14164. }, {
  14165. key: "parseText",
  14166. value: function parseText() {}
  14167. }, {
  14168. key: "parseClose",
  14169. value: function parseClose() {
  14170. return false;
  14171. }
  14172. }, {
  14173. key: "tag",
  14174. get: function get() {
  14175. return 'picture';
  14176. }
  14177. }]);
  14178. return PictureXform;
  14179. }(BaseXform);
  14180. module.exports = PictureXform;
  14181. },{"../base-xform":31}],106:[function(require,module,exports){
  14182. "use strict";
  14183. 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); }
  14184. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14185. 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); } }
  14186. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  14187. 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); }
  14188. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  14189. 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); }; }
  14190. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  14191. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  14192. 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; } }
  14193. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  14194. var _ = require('../../../utils/under-dash');
  14195. var BaseXform = require('../base-xform');
  14196. function booleanToXml(model) {
  14197. return model ? '1' : undefined;
  14198. }
  14199. var PrintOptionsXform = /*#__PURE__*/function (_BaseXform) {
  14200. _inherits(PrintOptionsXform, _BaseXform);
  14201. var _super = _createSuper(PrintOptionsXform);
  14202. function PrintOptionsXform() {
  14203. _classCallCheck(this, PrintOptionsXform);
  14204. return _super.apply(this, arguments);
  14205. }
  14206. _createClass(PrintOptionsXform, [{
  14207. key: "render",
  14208. value: function render(xmlStream, model) {
  14209. if (model) {
  14210. var attributes = {
  14211. headings: booleanToXml(model.showRowColHeaders),
  14212. gridLines: booleanToXml(model.showGridLines),
  14213. horizontalCentered: booleanToXml(model.horizontalCentered),
  14214. verticalCentered: booleanToXml(model.verticalCentered)
  14215. };
  14216. if (_.some(attributes, function (value) {
  14217. return value !== undefined;
  14218. })) {
  14219. xmlStream.leafNode(this.tag, attributes);
  14220. }
  14221. }
  14222. }
  14223. }, {
  14224. key: "parseOpen",
  14225. value: function parseOpen(node) {
  14226. switch (node.name) {
  14227. case this.tag:
  14228. this.model = {
  14229. showRowColHeaders: node.attributes.headings === '1',
  14230. showGridLines: node.attributes.gridLines === '1',
  14231. horizontalCentered: node.attributes.horizontalCentered === '1',
  14232. verticalCentered: node.attributes.verticalCentered === '1'
  14233. };
  14234. return true;
  14235. default:
  14236. return false;
  14237. }
  14238. }
  14239. }, {
  14240. key: "parseText",
  14241. value: function parseText() {}
  14242. }, {
  14243. key: "parseClose",
  14244. value: function parseClose() {
  14245. return false;
  14246. }
  14247. }, {
  14248. key: "tag",
  14249. get: function get() {
  14250. return 'printOptions';
  14251. }
  14252. }]);
  14253. return PrintOptionsXform;
  14254. }(BaseXform);
  14255. module.exports = PrintOptionsXform;
  14256. },{"../../../utils/under-dash":25,"../base-xform":31}],107:[function(require,module,exports){
  14257. 'use strict';
  14258. 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); }
  14259. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14260. 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); } }
  14261. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  14262. 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); }
  14263. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  14264. 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); }; }
  14265. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  14266. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  14267. 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; } }
  14268. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  14269. var PageBreaksXform = require('./page-breaks-xform');
  14270. var ListXform = require('../list-xform');
  14271. var RowBreaksXform = /*#__PURE__*/function (_ListXform) {
  14272. _inherits(RowBreaksXform, _ListXform);
  14273. var _super = _createSuper(RowBreaksXform);
  14274. function RowBreaksXform() {
  14275. _classCallCheck(this, RowBreaksXform);
  14276. var options = {
  14277. tag: 'rowBreaks',
  14278. count: true,
  14279. childXform: new PageBreaksXform()
  14280. };
  14281. return _super.call(this, options);
  14282. } // get tag() { return 'rowBreaks'; }
  14283. _createClass(RowBreaksXform, [{
  14284. key: "render",
  14285. value: function render(xmlStream, model) {
  14286. if (model && model.length) {
  14287. xmlStream.openNode(this.tag, this.$);
  14288. if (this.count) {
  14289. xmlStream.addAttribute(this.$count, model.length);
  14290. xmlStream.addAttribute('manualBreakCount', model.length);
  14291. }
  14292. var childXform = this.childXform;
  14293. model.forEach(function (childModel) {
  14294. childXform.render(xmlStream, childModel);
  14295. });
  14296. xmlStream.closeNode();
  14297. } else if (this.empty) {
  14298. xmlStream.leafNode(this.tag);
  14299. }
  14300. }
  14301. }]);
  14302. return RowBreaksXform;
  14303. }(ListXform);
  14304. module.exports = RowBreaksXform;
  14305. },{"../list-xform":70,"./page-breaks-xform":101}],108:[function(require,module,exports){
  14306. "use strict";
  14307. 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); }
  14308. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14309. 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); } }
  14310. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  14311. 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); }
  14312. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  14313. 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); }; }
  14314. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  14315. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  14316. 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; } }
  14317. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  14318. var BaseXform = require('../base-xform');
  14319. var CellXform = require('./cell-xform');
  14320. var RowXform = /*#__PURE__*/function (_BaseXform) {
  14321. _inherits(RowXform, _BaseXform);
  14322. var _super = _createSuper(RowXform);
  14323. function RowXform(options) {
  14324. var _this;
  14325. _classCallCheck(this, RowXform);
  14326. _this = _super.call(this);
  14327. _this.maxItems = options && options.maxItems;
  14328. _this.map = {
  14329. c: new CellXform()
  14330. };
  14331. return _this;
  14332. }
  14333. _createClass(RowXform, [{
  14334. key: "prepare",
  14335. value: function prepare(model, options) {
  14336. var styleId = options.styles.addStyleModel(model.style);
  14337. if (styleId) {
  14338. model.styleId = styleId;
  14339. }
  14340. var cellXform = this.map.c;
  14341. model.cells.forEach(function (cellModel) {
  14342. cellXform.prepare(cellModel, options);
  14343. });
  14344. }
  14345. }, {
  14346. key: "render",
  14347. value: function render(xmlStream, model, options) {
  14348. xmlStream.openNode('row');
  14349. xmlStream.addAttribute('r', model.number);
  14350. if (model.height) {
  14351. xmlStream.addAttribute('ht', model.height);
  14352. xmlStream.addAttribute('customHeight', '1');
  14353. }
  14354. if (model.hidden) {
  14355. xmlStream.addAttribute('hidden', '1');
  14356. }
  14357. if (model.min > 0 && model.max > 0 && model.min <= model.max) {
  14358. xmlStream.addAttribute('spans', "".concat(model.min, ":").concat(model.max));
  14359. }
  14360. if (model.styleId) {
  14361. xmlStream.addAttribute('s', model.styleId);
  14362. xmlStream.addAttribute('customFormat', '1');
  14363. }
  14364. xmlStream.addAttribute('x14ac:dyDescent', '0.25');
  14365. if (model.outlineLevel) {
  14366. xmlStream.addAttribute('outlineLevel', model.outlineLevel);
  14367. }
  14368. if (model.collapsed) {
  14369. xmlStream.addAttribute('collapsed', '1');
  14370. }
  14371. var cellXform = this.map.c;
  14372. model.cells.forEach(function (cellModel) {
  14373. cellXform.render(xmlStream, cellModel, options);
  14374. });
  14375. xmlStream.closeNode();
  14376. }
  14377. }, {
  14378. key: "parseOpen",
  14379. value: function parseOpen(node) {
  14380. if (this.parser) {
  14381. this.parser.parseOpen(node);
  14382. return true;
  14383. }
  14384. if (node.name === 'row') {
  14385. this.numRowsSeen += 1;
  14386. var spans = node.attributes.spans ? node.attributes.spans.split(':').map(function (span) {
  14387. return parseInt(span, 10);
  14388. }) : [undefined, undefined];
  14389. var model = this.model = {
  14390. number: parseInt(node.attributes.r, 10),
  14391. min: spans[0],
  14392. max: spans[1],
  14393. cells: []
  14394. };
  14395. if (node.attributes.s) {
  14396. model.styleId = parseInt(node.attributes.s, 10);
  14397. }
  14398. if (node.attributes.hidden === true || node.attributes.hidden === 'true' || node.attributes.hidden === 1 || node.attributes.hidden === '1') {
  14399. model.hidden = true;
  14400. }
  14401. if (node.attributes.bestFit) {
  14402. model.bestFit = true;
  14403. }
  14404. if (node.attributes.ht) {
  14405. model.height = parseFloat(node.attributes.ht);
  14406. }
  14407. if (node.attributes.outlineLevel) {
  14408. model.outlineLevel = parseInt(node.attributes.outlineLevel, 10);
  14409. }
  14410. if (node.attributes.collapsed) {
  14411. model.collapsed = true;
  14412. }
  14413. return true;
  14414. }
  14415. this.parser = this.map[node.name];
  14416. if (this.parser) {
  14417. this.parser.parseOpen(node);
  14418. return true;
  14419. }
  14420. return false;
  14421. }
  14422. }, {
  14423. key: "parseText",
  14424. value: function parseText(text) {
  14425. if (this.parser) {
  14426. this.parser.parseText(text);
  14427. }
  14428. }
  14429. }, {
  14430. key: "parseClose",
  14431. value: function parseClose(name) {
  14432. if (this.parser) {
  14433. if (!this.parser.parseClose(name)) {
  14434. this.model.cells.push(this.parser.model);
  14435. if (this.maxItems && this.model.cells.length > this.maxItems) {
  14436. throw new Error("Max column count (".concat(this.maxItems, ") exceeded"));
  14437. }
  14438. this.parser = undefined;
  14439. }
  14440. return true;
  14441. }
  14442. return false;
  14443. }
  14444. }, {
  14445. key: "reconcile",
  14446. value: function reconcile(model, options) {
  14447. model.style = model.styleId ? options.styles.getStyleModel(model.styleId) : {};
  14448. if (model.styleId !== undefined) {
  14449. model.styleId = undefined;
  14450. }
  14451. var cellXform = this.map.c;
  14452. model.cells.forEach(function (cellModel) {
  14453. cellXform.reconcile(cellModel, options);
  14454. });
  14455. }
  14456. }, {
  14457. key: "tag",
  14458. get: function get() {
  14459. return 'row';
  14460. }
  14461. }]);
  14462. return RowXform;
  14463. }(BaseXform);
  14464. module.exports = RowXform;
  14465. },{"../base-xform":31,"./cell-xform":72}],109:[function(require,module,exports){
  14466. "use strict";
  14467. 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); }
  14468. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14469. 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); } }
  14470. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  14471. 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); }
  14472. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  14473. 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); }; }
  14474. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  14475. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  14476. 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; } }
  14477. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  14478. var _ = require('../../../utils/under-dash');
  14479. var BaseXform = require('../base-xform');
  14480. var SheetFormatPropertiesXform = /*#__PURE__*/function (_BaseXform) {
  14481. _inherits(SheetFormatPropertiesXform, _BaseXform);
  14482. var _super = _createSuper(SheetFormatPropertiesXform);
  14483. function SheetFormatPropertiesXform() {
  14484. _classCallCheck(this, SheetFormatPropertiesXform);
  14485. return _super.apply(this, arguments);
  14486. }
  14487. _createClass(SheetFormatPropertiesXform, [{
  14488. key: "render",
  14489. value: function render(xmlStream, model) {
  14490. if (model) {
  14491. var attributes = {
  14492. defaultRowHeight: model.defaultRowHeight,
  14493. outlineLevelRow: model.outlineLevelRow,
  14494. outlineLevelCol: model.outlineLevelCol,
  14495. 'x14ac:dyDescent': model.dyDescent
  14496. };
  14497. if (model.defaultColWidth) {
  14498. attributes.defaultColWidth = model.defaultColWidth;
  14499. } // default value for 'defaultRowHeight' is 15, this should not be 'custom'
  14500. if (!model.defaultRowHeight || model.defaultRowHeight !== 15) {
  14501. attributes.customHeight = '1';
  14502. }
  14503. if (_.some(attributes, function (value) {
  14504. return value !== undefined;
  14505. })) {
  14506. xmlStream.leafNode('sheetFormatPr', attributes);
  14507. }
  14508. }
  14509. }
  14510. }, {
  14511. key: "parseOpen",
  14512. value: function parseOpen(node) {
  14513. if (node.name === 'sheetFormatPr') {
  14514. this.model = {
  14515. defaultRowHeight: parseFloat(node.attributes.defaultRowHeight || '0'),
  14516. dyDescent: parseFloat(node.attributes['x14ac:dyDescent'] || '0'),
  14517. outlineLevelRow: parseInt(node.attributes.outlineLevelRow || '0', 10),
  14518. outlineLevelCol: parseInt(node.attributes.outlineLevelCol || '0', 10)
  14519. };
  14520. if (node.attributes.defaultColWidth) {
  14521. this.model.defaultColWidth = parseFloat(node.attributes.defaultColWidth);
  14522. }
  14523. return true;
  14524. }
  14525. return false;
  14526. }
  14527. }, {
  14528. key: "parseText",
  14529. value: function parseText() {}
  14530. }, {
  14531. key: "parseClose",
  14532. value: function parseClose() {
  14533. return false;
  14534. }
  14535. }, {
  14536. key: "tag",
  14537. get: function get() {
  14538. return 'sheetFormatPr';
  14539. }
  14540. }]);
  14541. return SheetFormatPropertiesXform;
  14542. }(BaseXform);
  14543. module.exports = SheetFormatPropertiesXform;
  14544. },{"../../../utils/under-dash":25,"../base-xform":31}],110:[function(require,module,exports){
  14545. "use strict";
  14546. 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); }
  14547. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14548. 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); } }
  14549. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  14550. 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); }
  14551. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  14552. 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); }; }
  14553. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  14554. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  14555. 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; } }
  14556. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  14557. var BaseXform = require('../base-xform');
  14558. var ColorXform = require('../style/color-xform');
  14559. var PageSetupPropertiesXform = require('./page-setup-properties-xform');
  14560. var OutlinePropertiesXform = require('./outline-properties-xform');
  14561. var SheetPropertiesXform = /*#__PURE__*/function (_BaseXform) {
  14562. _inherits(SheetPropertiesXform, _BaseXform);
  14563. var _super = _createSuper(SheetPropertiesXform);
  14564. function SheetPropertiesXform() {
  14565. var _this;
  14566. _classCallCheck(this, SheetPropertiesXform);
  14567. _this = _super.call(this);
  14568. _this.map = {
  14569. tabColor: new ColorXform('tabColor'),
  14570. pageSetUpPr: new PageSetupPropertiesXform(),
  14571. outlinePr: new OutlinePropertiesXform()
  14572. };
  14573. return _this;
  14574. }
  14575. _createClass(SheetPropertiesXform, [{
  14576. key: "render",
  14577. value: function render(xmlStream, model) {
  14578. if (model) {
  14579. xmlStream.addRollback();
  14580. xmlStream.openNode('sheetPr');
  14581. var inner = false;
  14582. inner = this.map.tabColor.render(xmlStream, model.tabColor) || inner;
  14583. inner = this.map.pageSetUpPr.render(xmlStream, model.pageSetup) || inner;
  14584. inner = this.map.outlinePr.render(xmlStream, model.outlineProperties) || inner;
  14585. if (inner) {
  14586. xmlStream.closeNode();
  14587. xmlStream.commit();
  14588. } else {
  14589. xmlStream.rollback();
  14590. }
  14591. }
  14592. }
  14593. }, {
  14594. key: "parseOpen",
  14595. value: function parseOpen(node) {
  14596. if (this.parser) {
  14597. this.parser.parseOpen(node);
  14598. return true;
  14599. }
  14600. if (node.name === this.tag) {
  14601. this.reset();
  14602. return true;
  14603. }
  14604. if (this.map[node.name]) {
  14605. this.parser = this.map[node.name];
  14606. this.parser.parseOpen(node);
  14607. return true;
  14608. }
  14609. return false;
  14610. }
  14611. }, {
  14612. key: "parseText",
  14613. value: function parseText(text) {
  14614. if (this.parser) {
  14615. this.parser.parseText(text);
  14616. return true;
  14617. }
  14618. return false;
  14619. }
  14620. }, {
  14621. key: "parseClose",
  14622. value: function parseClose(name) {
  14623. if (this.parser) {
  14624. if (!this.parser.parseClose(name)) {
  14625. this.parser = undefined;
  14626. }
  14627. return true;
  14628. }
  14629. if (this.map.tabColor.model || this.map.pageSetUpPr.model || this.map.outlinePr.model) {
  14630. this.model = {};
  14631. if (this.map.tabColor.model) {
  14632. this.model.tabColor = this.map.tabColor.model;
  14633. }
  14634. if (this.map.pageSetUpPr.model) {
  14635. this.model.pageSetup = this.map.pageSetUpPr.model;
  14636. }
  14637. if (this.map.outlinePr.model) {
  14638. this.model.outlineProperties = this.map.outlinePr.model;
  14639. }
  14640. } else {
  14641. this.model = null;
  14642. }
  14643. return false;
  14644. }
  14645. }, {
  14646. key: "tag",
  14647. get: function get() {
  14648. return 'sheetPr';
  14649. }
  14650. }]);
  14651. return SheetPropertiesXform;
  14652. }(BaseXform);
  14653. module.exports = SheetPropertiesXform;
  14654. },{"../base-xform":31,"../style/color-xform":127,"./outline-properties-xform":100,"./page-setup-properties-xform":103}],111:[function(require,module,exports){
  14655. "use strict";
  14656. 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); }
  14657. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14658. 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); } }
  14659. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  14660. 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); }
  14661. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  14662. 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); }; }
  14663. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  14664. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  14665. 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; } }
  14666. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  14667. var _ = require('../../../utils/under-dash');
  14668. var BaseXform = require('../base-xform');
  14669. function booleanToXml(model, value) {
  14670. return model ? value : undefined;
  14671. }
  14672. function xmlToBoolean(value, equals) {
  14673. return value === equals ? true : undefined;
  14674. }
  14675. var SheetProtectionXform = /*#__PURE__*/function (_BaseXform) {
  14676. _inherits(SheetProtectionXform, _BaseXform);
  14677. var _super = _createSuper(SheetProtectionXform);
  14678. function SheetProtectionXform() {
  14679. _classCallCheck(this, SheetProtectionXform);
  14680. return _super.apply(this, arguments);
  14681. }
  14682. _createClass(SheetProtectionXform, [{
  14683. key: "render",
  14684. value: function render(xmlStream, model) {
  14685. if (model) {
  14686. var attributes = {
  14687. sheet: booleanToXml(model.sheet, '1'),
  14688. selectLockedCells: model.selectLockedCells === false ? '1' : undefined,
  14689. selectUnlockedCells: model.selectUnlockedCells === false ? '1' : undefined,
  14690. formatCells: booleanToXml(model.formatCells, '0'),
  14691. formatColumns: booleanToXml(model.formatColumns, '0'),
  14692. formatRows: booleanToXml(model.formatRows, '0'),
  14693. insertColumns: booleanToXml(model.insertColumns, '0'),
  14694. insertRows: booleanToXml(model.insertRows, '0'),
  14695. insertHyperlinks: booleanToXml(model.insertHyperlinks, '0'),
  14696. deleteColumns: booleanToXml(model.deleteColumns, '0'),
  14697. deleteRows: booleanToXml(model.deleteRows, '0'),
  14698. sort: booleanToXml(model.sort, '0'),
  14699. autoFilter: booleanToXml(model.autoFilter, '0'),
  14700. pivotTables: booleanToXml(model.pivotTables, '0')
  14701. };
  14702. if (model.sheet) {
  14703. attributes.algorithmName = model.algorithmName;
  14704. attributes.hashValue = model.hashValue;
  14705. attributes.saltValue = model.saltValue;
  14706. attributes.spinCount = model.spinCount;
  14707. attributes.objects = booleanToXml(model.objects === false, '1');
  14708. attributes.scenarios = booleanToXml(model.scenarios === false, '1');
  14709. }
  14710. if (_.some(attributes, function (value) {
  14711. return value !== undefined;
  14712. })) {
  14713. xmlStream.leafNode(this.tag, attributes);
  14714. }
  14715. }
  14716. }
  14717. }, {
  14718. key: "parseOpen",
  14719. value: function parseOpen(node) {
  14720. switch (node.name) {
  14721. case this.tag:
  14722. this.model = {
  14723. sheet: xmlToBoolean(node.attributes.sheet, '1'),
  14724. objects: node.attributes.objects === '1' ? false : undefined,
  14725. scenarios: node.attributes.scenarios === '1' ? false : undefined,
  14726. selectLockedCells: node.attributes.selectLockedCells === '1' ? false : undefined,
  14727. selectUnlockedCells: node.attributes.selectUnlockedCells === '1' ? false : undefined,
  14728. formatCells: xmlToBoolean(node.attributes.formatCells, '0'),
  14729. formatColumns: xmlToBoolean(node.attributes.formatColumns, '0'),
  14730. formatRows: xmlToBoolean(node.attributes.formatRows, '0'),
  14731. insertColumns: xmlToBoolean(node.attributes.insertColumns, '0'),
  14732. insertRows: xmlToBoolean(node.attributes.insertRows, '0'),
  14733. insertHyperlinks: xmlToBoolean(node.attributes.insertHyperlinks, '0'),
  14734. deleteColumns: xmlToBoolean(node.attributes.deleteColumns, '0'),
  14735. deleteRows: xmlToBoolean(node.attributes.deleteRows, '0'),
  14736. sort: xmlToBoolean(node.attributes.sort, '0'),
  14737. autoFilter: xmlToBoolean(node.attributes.autoFilter, '0'),
  14738. pivotTables: xmlToBoolean(node.attributes.pivotTables, '0')
  14739. };
  14740. if (node.attributes.algorithmName) {
  14741. this.model.algorithmName = node.attributes.algorithmName;
  14742. this.model.hashValue = node.attributes.hashValue;
  14743. this.model.saltValue = node.attributes.saltValue;
  14744. this.model.spinCount = parseInt(node.attributes.spinCount, 10);
  14745. }
  14746. return true;
  14747. default:
  14748. return false;
  14749. }
  14750. }
  14751. }, {
  14752. key: "parseText",
  14753. value: function parseText() {}
  14754. }, {
  14755. key: "parseClose",
  14756. value: function parseClose() {
  14757. return false;
  14758. }
  14759. }, {
  14760. key: "tag",
  14761. get: function get() {
  14762. return 'sheetProtection';
  14763. }
  14764. }]);
  14765. return SheetProtectionXform;
  14766. }(BaseXform);
  14767. module.exports = SheetProtectionXform;
  14768. },{"../../../utils/under-dash":25,"../base-xform":31}],112:[function(require,module,exports){
  14769. "use strict";
  14770. 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); }
  14771. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14772. 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); } }
  14773. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  14774. 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); }
  14775. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  14776. 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); }; }
  14777. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  14778. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  14779. 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; } }
  14780. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  14781. var colCache = require('../../../utils/col-cache');
  14782. var BaseXform = require('../base-xform');
  14783. var VIEW_STATES = {
  14784. frozen: 'frozen',
  14785. frozenSplit: 'frozen',
  14786. split: 'split'
  14787. };
  14788. var SheetViewXform = /*#__PURE__*/function (_BaseXform) {
  14789. _inherits(SheetViewXform, _BaseXform);
  14790. var _super = _createSuper(SheetViewXform);
  14791. function SheetViewXform() {
  14792. _classCallCheck(this, SheetViewXform);
  14793. return _super.apply(this, arguments);
  14794. }
  14795. _createClass(SheetViewXform, [{
  14796. key: "prepare",
  14797. value: function prepare(model) {
  14798. switch (model.state) {
  14799. case 'frozen':
  14800. case 'split':
  14801. break;
  14802. default:
  14803. model.state = 'normal';
  14804. break;
  14805. }
  14806. }
  14807. }, {
  14808. key: "render",
  14809. value: function render(xmlStream, model) {
  14810. xmlStream.openNode('sheetView', {
  14811. workbookViewId: model.workbookViewId || 0
  14812. });
  14813. var add = function add(name, value, included) {
  14814. if (included) {
  14815. xmlStream.addAttribute(name, value);
  14816. }
  14817. };
  14818. add('rightToLeft', '1', model.rightToLeft === true);
  14819. add('tabSelected', '1', model.tabSelected);
  14820. add('showRuler', '0', model.showRuler === false);
  14821. add('showRowColHeaders', '0', model.showRowColHeaders === false);
  14822. add('showGridLines', '0', model.showGridLines === false);
  14823. add('zoomScale', model.zoomScale, model.zoomScale);
  14824. add('zoomScaleNormal', model.zoomScaleNormal, model.zoomScaleNormal);
  14825. add('view', model.style, model.style);
  14826. var topLeftCell;
  14827. var xSplit;
  14828. var ySplit;
  14829. var activePane;
  14830. switch (model.state) {
  14831. case 'frozen':
  14832. xSplit = model.xSplit || 0;
  14833. ySplit = model.ySplit || 0;
  14834. topLeftCell = model.topLeftCell || colCache.getAddress(ySplit + 1, xSplit + 1).address;
  14835. activePane = model.xSplit && model.ySplit && 'bottomRight' || model.xSplit && 'topRight' || 'bottomLeft';
  14836. xmlStream.leafNode('pane', {
  14837. xSplit: model.xSplit || undefined,
  14838. ySplit: model.ySplit || undefined,
  14839. topLeftCell: topLeftCell,
  14840. activePane: activePane,
  14841. state: 'frozen'
  14842. });
  14843. xmlStream.leafNode('selection', {
  14844. pane: activePane,
  14845. activeCell: model.activeCell,
  14846. sqref: model.activeCell
  14847. });
  14848. break;
  14849. case 'split':
  14850. if (model.activePane === 'topLeft') {
  14851. model.activePane = undefined;
  14852. }
  14853. xmlStream.leafNode('pane', {
  14854. xSplit: model.xSplit || undefined,
  14855. ySplit: model.ySplit || undefined,
  14856. topLeftCell: model.topLeftCell,
  14857. activePane: model.activePane
  14858. });
  14859. xmlStream.leafNode('selection', {
  14860. pane: model.activePane,
  14861. activeCell: model.activeCell,
  14862. sqref: model.activeCell
  14863. });
  14864. break;
  14865. case 'normal':
  14866. if (model.activeCell) {
  14867. xmlStream.leafNode('selection', {
  14868. activeCell: model.activeCell,
  14869. sqref: model.activeCell
  14870. });
  14871. }
  14872. break;
  14873. default:
  14874. break;
  14875. }
  14876. xmlStream.closeNode();
  14877. }
  14878. }, {
  14879. key: "parseOpen",
  14880. value: function parseOpen(node) {
  14881. switch (node.name) {
  14882. case 'sheetView':
  14883. this.sheetView = {
  14884. workbookViewId: parseInt(node.attributes.workbookViewId, 10),
  14885. rightToLeft: node.attributes.rightToLeft === '1',
  14886. tabSelected: node.attributes.tabSelected === '1',
  14887. showRuler: !(node.attributes.showRuler === '0'),
  14888. showRowColHeaders: !(node.attributes.showRowColHeaders === '0'),
  14889. showGridLines: !(node.attributes.showGridLines === '0'),
  14890. zoomScale: parseInt(node.attributes.zoomScale || '100', 10),
  14891. zoomScaleNormal: parseInt(node.attributes.zoomScaleNormal || '100', 10),
  14892. style: node.attributes.view
  14893. };
  14894. this.pane = undefined;
  14895. this.selections = {};
  14896. return true;
  14897. case 'pane':
  14898. this.pane = {
  14899. xSplit: parseInt(node.attributes.xSplit || '0', 10),
  14900. ySplit: parseInt(node.attributes.ySplit || '0', 10),
  14901. topLeftCell: node.attributes.topLeftCell,
  14902. activePane: node.attributes.activePane || 'topLeft',
  14903. state: node.attributes.state
  14904. };
  14905. return true;
  14906. case 'selection':
  14907. {
  14908. var name = node.attributes.pane || 'topLeft';
  14909. this.selections[name] = {
  14910. pane: name,
  14911. activeCell: node.attributes.activeCell
  14912. };
  14913. return true;
  14914. }
  14915. default:
  14916. return false;
  14917. }
  14918. }
  14919. }, {
  14920. key: "parseText",
  14921. value: function parseText() {}
  14922. }, {
  14923. key: "parseClose",
  14924. value: function parseClose(name) {
  14925. var model;
  14926. var selection;
  14927. switch (name) {
  14928. case 'sheetView':
  14929. if (this.sheetView && this.pane) {
  14930. model = this.model = {
  14931. workbookViewId: this.sheetView.workbookViewId,
  14932. rightToLeft: this.sheetView.rightToLeft,
  14933. state: VIEW_STATES[this.pane.state] || 'split',
  14934. // split is default
  14935. xSplit: this.pane.xSplit,
  14936. ySplit: this.pane.ySplit,
  14937. topLeftCell: this.pane.topLeftCell,
  14938. showRuler: this.sheetView.showRuler,
  14939. showRowColHeaders: this.sheetView.showRowColHeaders,
  14940. showGridLines: this.sheetView.showGridLines,
  14941. zoomScale: this.sheetView.zoomScale,
  14942. zoomScaleNormal: this.sheetView.zoomScaleNormal
  14943. };
  14944. if (this.model.state === 'split') {
  14945. model.activePane = this.pane.activePane;
  14946. }
  14947. selection = this.selections[this.pane.activePane];
  14948. if (selection && selection.activeCell) {
  14949. model.activeCell = selection.activeCell;
  14950. }
  14951. if (this.sheetView.style) {
  14952. model.style = this.sheetView.style;
  14953. }
  14954. } else {
  14955. model = this.model = {
  14956. workbookViewId: this.sheetView.workbookViewId,
  14957. rightToLeft: this.sheetView.rightToLeft,
  14958. state: 'normal',
  14959. showRuler: this.sheetView.showRuler,
  14960. showRowColHeaders: this.sheetView.showRowColHeaders,
  14961. showGridLines: this.sheetView.showGridLines,
  14962. zoomScale: this.sheetView.zoomScale,
  14963. zoomScaleNormal: this.sheetView.zoomScaleNormal
  14964. };
  14965. selection = this.selections.topLeft;
  14966. if (selection && selection.activeCell) {
  14967. model.activeCell = selection.activeCell;
  14968. }
  14969. if (this.sheetView.style) {
  14970. model.style = this.sheetView.style;
  14971. }
  14972. }
  14973. return false;
  14974. default:
  14975. return true;
  14976. }
  14977. }
  14978. }, {
  14979. key: "reconcile",
  14980. value: function reconcile() {}
  14981. }, {
  14982. key: "tag",
  14983. get: function get() {
  14984. return 'sheetView';
  14985. }
  14986. }]);
  14987. return SheetViewXform;
  14988. }(BaseXform);
  14989. module.exports = SheetViewXform;
  14990. },{"../../../utils/col-cache":19,"../base-xform":31}],113:[function(require,module,exports){
  14991. "use strict";
  14992. 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); }
  14993. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14994. 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); } }
  14995. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  14996. 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); }
  14997. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  14998. 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); }; }
  14999. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  15000. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  15001. 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; } }
  15002. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  15003. var BaseXform = require('../base-xform');
  15004. var TablePartXform = /*#__PURE__*/function (_BaseXform) {
  15005. _inherits(TablePartXform, _BaseXform);
  15006. var _super = _createSuper(TablePartXform);
  15007. function TablePartXform() {
  15008. _classCallCheck(this, TablePartXform);
  15009. return _super.apply(this, arguments);
  15010. }
  15011. _createClass(TablePartXform, [{
  15012. key: "render",
  15013. value: function render(xmlStream, model) {
  15014. if (model) {
  15015. xmlStream.leafNode(this.tag, {
  15016. 'r:id': model.rId
  15017. });
  15018. }
  15019. }
  15020. }, {
  15021. key: "parseOpen",
  15022. value: function parseOpen(node) {
  15023. switch (node.name) {
  15024. case this.tag:
  15025. this.model = {
  15026. rId: node.attributes['r:id']
  15027. };
  15028. return true;
  15029. default:
  15030. return false;
  15031. }
  15032. }
  15033. }, {
  15034. key: "parseText",
  15035. value: function parseText() {}
  15036. }, {
  15037. key: "parseClose",
  15038. value: function parseClose() {
  15039. return false;
  15040. }
  15041. }, {
  15042. key: "tag",
  15043. get: function get() {
  15044. return 'tablePart';
  15045. }
  15046. }]);
  15047. return TablePartXform;
  15048. }(BaseXform);
  15049. module.exports = TablePartXform;
  15050. },{"../base-xform":31}],114:[function(require,module,exports){
  15051. "use strict";
  15052. 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); }
  15053. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  15054. 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); } }
  15055. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  15056. 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); }
  15057. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  15058. 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); }; }
  15059. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  15060. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  15061. 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; } }
  15062. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  15063. var _ = require('../../../utils/under-dash');
  15064. var colCache = require('../../../utils/col-cache');
  15065. var XmlStream = require('../../../utils/xml-stream');
  15066. var RelType = require('../../rel-type');
  15067. var Merges = require('./merges');
  15068. var BaseXform = require('../base-xform');
  15069. var ListXform = require('../list-xform');
  15070. var RowXform = require('./row-xform');
  15071. var ColXform = require('./col-xform');
  15072. var DimensionXform = require('./dimension-xform');
  15073. var HyperlinkXform = require('./hyperlink-xform');
  15074. var MergeCellXform = require('./merge-cell-xform');
  15075. var DataValidationsXform = require('./data-validations-xform');
  15076. var SheetPropertiesXform = require('./sheet-properties-xform');
  15077. var SheetFormatPropertiesXform = require('./sheet-format-properties-xform');
  15078. var SheetViewXform = require('./sheet-view-xform');
  15079. var SheetProtectionXform = require('./sheet-protection-xform');
  15080. var PageMarginsXform = require('./page-margins-xform');
  15081. var PageSetupXform = require('./page-setup-xform');
  15082. var PrintOptionsXform = require('./print-options-xform');
  15083. var AutoFilterXform = require('./auto-filter-xform');
  15084. var PictureXform = require('./picture-xform');
  15085. var DrawingXform = require('./drawing-xform');
  15086. var TablePartXform = require('./table-part-xform');
  15087. var RowBreaksXform = require('./row-breaks-xform');
  15088. var HeaderFooterXform = require('./header-footer-xform');
  15089. var ConditionalFormattingsXform = require('./cf/conditional-formattings-xform');
  15090. var ExtListXform = require('./ext-lst-xform');
  15091. var mergeRule = function mergeRule(rule, extRule) {
  15092. Object.keys(extRule).forEach(function (key) {
  15093. var value = rule[key];
  15094. var extValue = extRule[key];
  15095. if (value === undefined && extValue !== undefined) {
  15096. rule[key] = extValue;
  15097. }
  15098. });
  15099. };
  15100. var mergeConditionalFormattings = function mergeConditionalFormattings(model, extModel) {
  15101. // conditional formattings are rendered in worksheet.conditionalFormatting and also in
  15102. // worksheet.extLst.ext.x14:conditionalFormattings
  15103. // some (e.g. dataBar) are even spread across both!
  15104. if (!extModel || !extModel.length) {
  15105. return model;
  15106. }
  15107. if (!model || !model.length) {
  15108. return extModel;
  15109. } // index model rules by x14Id
  15110. var cfMap = {};
  15111. var ruleMap = {};
  15112. model.forEach(function (cf) {
  15113. cfMap[cf.ref] = cf;
  15114. cf.rules.forEach(function (rule) {
  15115. var x14Id = rule.x14Id;
  15116. if (x14Id) {
  15117. ruleMap[x14Id] = rule;
  15118. }
  15119. });
  15120. });
  15121. extModel.forEach(function (extCf) {
  15122. extCf.rules.forEach(function (extRule) {
  15123. var rule = ruleMap[extRule.x14Id];
  15124. if (rule) {
  15125. // merge with matching rule
  15126. mergeRule(rule, extRule);
  15127. } else if (cfMap[extCf.ref]) {
  15128. // reuse existing cf ref
  15129. cfMap[extCf.ref].rules.push(extRule);
  15130. } else {
  15131. // create new cf
  15132. model.push({
  15133. ref: extCf.ref,
  15134. rules: [extRule]
  15135. });
  15136. }
  15137. });
  15138. }); // need to cope with rules in extModel that don't exist in model
  15139. return model;
  15140. };
  15141. var WorkSheetXform = /*#__PURE__*/function (_BaseXform) {
  15142. _inherits(WorkSheetXform, _BaseXform);
  15143. var _super = _createSuper(WorkSheetXform);
  15144. function WorkSheetXform(options) {
  15145. var _this;
  15146. _classCallCheck(this, WorkSheetXform);
  15147. _this = _super.call(this);
  15148. var _ref = options || {},
  15149. maxRows = _ref.maxRows,
  15150. maxCols = _ref.maxCols;
  15151. _this.map = {
  15152. sheetPr: new SheetPropertiesXform(),
  15153. dimension: new DimensionXform(),
  15154. sheetViews: new ListXform({
  15155. tag: 'sheetViews',
  15156. count: false,
  15157. childXform: new SheetViewXform()
  15158. }),
  15159. sheetFormatPr: new SheetFormatPropertiesXform(),
  15160. cols: new ListXform({
  15161. tag: 'cols',
  15162. count: false,
  15163. childXform: new ColXform()
  15164. }),
  15165. sheetData: new ListXform({
  15166. tag: 'sheetData',
  15167. count: false,
  15168. empty: true,
  15169. childXform: new RowXform({
  15170. maxItems: maxCols
  15171. }),
  15172. maxItems: maxRows
  15173. }),
  15174. autoFilter: new AutoFilterXform(),
  15175. mergeCells: new ListXform({
  15176. tag: 'mergeCells',
  15177. count: true,
  15178. childXform: new MergeCellXform()
  15179. }),
  15180. rowBreaks: new RowBreaksXform(),
  15181. hyperlinks: new ListXform({
  15182. tag: 'hyperlinks',
  15183. count: false,
  15184. childXform: new HyperlinkXform()
  15185. }),
  15186. pageMargins: new PageMarginsXform(),
  15187. dataValidations: new DataValidationsXform(),
  15188. pageSetup: new PageSetupXform(),
  15189. headerFooter: new HeaderFooterXform(),
  15190. printOptions: new PrintOptionsXform(),
  15191. picture: new PictureXform(),
  15192. drawing: new DrawingXform(),
  15193. sheetProtection: new SheetProtectionXform(),
  15194. tableParts: new ListXform({
  15195. tag: 'tableParts',
  15196. count: true,
  15197. childXform: new TablePartXform()
  15198. }),
  15199. conditionalFormatting: new ConditionalFormattingsXform(),
  15200. extLst: new ExtListXform()
  15201. };
  15202. return _this;
  15203. }
  15204. _createClass(WorkSheetXform, [{
  15205. key: "prepare",
  15206. value: function prepare(model, options) {
  15207. var _this2 = this;
  15208. options.merges = new Merges();
  15209. model.hyperlinks = options.hyperlinks = [];
  15210. model.comments = options.comments = [];
  15211. options.formulae = {};
  15212. options.siFormulae = 0;
  15213. this.map.cols.prepare(model.cols, options);
  15214. this.map.sheetData.prepare(model.rows, options);
  15215. this.map.conditionalFormatting.prepare(model.conditionalFormattings, options);
  15216. model.mergeCells = options.merges.mergeCells; // prepare relationships
  15217. var rels = model.rels = [];
  15218. function nextRid(r) {
  15219. return "rId".concat(r.length + 1);
  15220. }
  15221. model.hyperlinks.forEach(function (hyperlink) {
  15222. var rId = nextRid(rels);
  15223. hyperlink.rId = rId;
  15224. rels.push({
  15225. Id: rId,
  15226. Type: RelType.Hyperlink,
  15227. Target: hyperlink.target,
  15228. TargetMode: 'External'
  15229. });
  15230. }); // prepare comment relationships
  15231. if (model.comments.length > 0) {
  15232. var comment = {
  15233. Id: nextRid(rels),
  15234. Type: RelType.Comments,
  15235. Target: "../comments".concat(model.id, ".xml")
  15236. };
  15237. rels.push(comment);
  15238. var vmlDrawing = {
  15239. Id: nextRid(rels),
  15240. Type: RelType.VmlDrawing,
  15241. Target: "../drawings/vmlDrawing".concat(model.id, ".vml")
  15242. };
  15243. rels.push(vmlDrawing);
  15244. model.comments.forEach(function (item) {
  15245. item.refAddress = colCache.decodeAddress(item.ref);
  15246. });
  15247. options.commentRefs.push({
  15248. commentName: "comments".concat(model.id),
  15249. vmlDrawing: "vmlDrawing".concat(model.id)
  15250. });
  15251. }
  15252. var drawingRelsHash = [];
  15253. var bookImage;
  15254. model.media.forEach(function (medium) {
  15255. if (medium.type === 'background') {
  15256. var rId = nextRid(rels);
  15257. bookImage = options.media[medium.imageId];
  15258. rels.push({
  15259. Id: rId,
  15260. Type: RelType.Image,
  15261. Target: "../media/".concat(bookImage.name, ".").concat(bookImage.extension)
  15262. });
  15263. model.background = {
  15264. rId: rId
  15265. };
  15266. model.image = options.media[medium.imageId];
  15267. } else if (medium.type === 'image') {
  15268. var drawing = model.drawing;
  15269. bookImage = options.media[medium.imageId];
  15270. if (!drawing) {
  15271. drawing = model.drawing = {
  15272. rId: nextRid(rels),
  15273. name: "drawing".concat(++options.drawingsCount),
  15274. anchors: [],
  15275. rels: []
  15276. };
  15277. options.drawings.push(drawing);
  15278. rels.push({
  15279. Id: drawing.rId,
  15280. Type: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing',
  15281. Target: "../drawings/".concat(drawing.name, ".xml")
  15282. });
  15283. }
  15284. var rIdImage = _this2.preImageId === medium.imageId ? drawingRelsHash[medium.imageId] : drawingRelsHash[drawing.rels.length];
  15285. if (!rIdImage) {
  15286. rIdImage = nextRid(drawing.rels);
  15287. drawingRelsHash[drawing.rels.length] = rIdImage;
  15288. drawing.rels.push({
  15289. Id: rIdImage,
  15290. Type: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image',
  15291. Target: "../media/".concat(bookImage.name, ".").concat(bookImage.extension)
  15292. });
  15293. }
  15294. var anchor = {
  15295. picture: {
  15296. rId: rIdImage
  15297. },
  15298. range: medium.range
  15299. };
  15300. if (medium.hyperlinks && medium.hyperlinks.hyperlink) {
  15301. var rIdHyperLink = nextRid(drawing.rels);
  15302. drawingRelsHash[drawing.rels.length] = rIdHyperLink;
  15303. anchor.picture.hyperlinks = {
  15304. tooltip: medium.hyperlinks.tooltip,
  15305. rId: rIdHyperLink
  15306. };
  15307. drawing.rels.push({
  15308. Id: rIdHyperLink,
  15309. Type: RelType.Hyperlink,
  15310. Target: medium.hyperlinks.hyperlink,
  15311. TargetMode: 'External'
  15312. });
  15313. }
  15314. _this2.preImageId = medium.imageId;
  15315. drawing.anchors.push(anchor);
  15316. }
  15317. }); // prepare tables
  15318. model.tables.forEach(function (table) {
  15319. // relationships
  15320. var rId = nextRid(rels);
  15321. table.rId = rId;
  15322. rels.push({
  15323. Id: rId,
  15324. Type: RelType.Table,
  15325. Target: "../tables/".concat(table.target)
  15326. }); // dynamic styles
  15327. table.columns.forEach(function (column) {
  15328. var style = column.style;
  15329. if (style) {
  15330. column.dxfId = options.styles.addDxfStyle(style);
  15331. }
  15332. });
  15333. }); // prepare ext items
  15334. this.map.extLst.prepare(model, options);
  15335. }
  15336. }, {
  15337. key: "render",
  15338. value: function render(xmlStream, model) {
  15339. xmlStream.openXml(XmlStream.StdDocAttributes);
  15340. xmlStream.openNode('worksheet', WorkSheetXform.WORKSHEET_ATTRIBUTES);
  15341. var sheetFormatPropertiesModel = model.properties ? {
  15342. defaultRowHeight: model.properties.defaultRowHeight,
  15343. dyDescent: model.properties.dyDescent,
  15344. outlineLevelCol: model.properties.outlineLevelCol,
  15345. outlineLevelRow: model.properties.outlineLevelRow
  15346. } : undefined;
  15347. if (model.properties && model.properties.defaultColWidth) {
  15348. sheetFormatPropertiesModel.defaultColWidth = model.properties.defaultColWidth;
  15349. }
  15350. var sheetPropertiesModel = {
  15351. outlineProperties: model.properties && model.properties.outlineProperties,
  15352. tabColor: model.properties && model.properties.tabColor,
  15353. pageSetup: model.pageSetup && model.pageSetup.fitToPage ? {
  15354. fitToPage: model.pageSetup.fitToPage
  15355. } : undefined
  15356. };
  15357. var pageMarginsModel = model.pageSetup && model.pageSetup.margins;
  15358. var printOptionsModel = {
  15359. showRowColHeaders: model.pageSetup && model.pageSetup.showRowColHeaders,
  15360. showGridLines: model.pageSetup && model.pageSetup.showGridLines,
  15361. horizontalCentered: model.pageSetup && model.pageSetup.horizontalCentered,
  15362. verticalCentered: model.pageSetup && model.pageSetup.verticalCentered
  15363. };
  15364. var sheetProtectionModel = model.sheetProtection;
  15365. this.map.sheetPr.render(xmlStream, sheetPropertiesModel);
  15366. this.map.dimension.render(xmlStream, model.dimensions);
  15367. this.map.sheetViews.render(xmlStream, model.views);
  15368. this.map.sheetFormatPr.render(xmlStream, sheetFormatPropertiesModel);
  15369. this.map.cols.render(xmlStream, model.cols);
  15370. this.map.sheetData.render(xmlStream, model.rows);
  15371. this.map.sheetProtection.render(xmlStream, sheetProtectionModel); // Note: must be after sheetData and before autoFilter
  15372. this.map.autoFilter.render(xmlStream, model.autoFilter);
  15373. this.map.mergeCells.render(xmlStream, model.mergeCells);
  15374. this.map.conditionalFormatting.render(xmlStream, model.conditionalFormattings); // Note: must be before dataValidations
  15375. this.map.dataValidations.render(xmlStream, model.dataValidations); // For some reason hyperlinks have to be after the data validations
  15376. this.map.hyperlinks.render(xmlStream, model.hyperlinks);
  15377. this.map.printOptions.render(xmlStream, printOptionsModel); // Note: must be before pageMargins
  15378. this.map.pageMargins.render(xmlStream, pageMarginsModel);
  15379. this.map.pageSetup.render(xmlStream, model.pageSetup);
  15380. this.map.headerFooter.render(xmlStream, model.headerFooter);
  15381. this.map.rowBreaks.render(xmlStream, model.rowBreaks);
  15382. this.map.drawing.render(xmlStream, model.drawing); // Note: must be after rowBreaks
  15383. this.map.picture.render(xmlStream, model.background); // Note: must be after drawing
  15384. this.map.tableParts.render(xmlStream, model.tables);
  15385. this.map.extLst.render(xmlStream, model);
  15386. if (model.rels) {
  15387. // add a <legacyDrawing /> node for each comment
  15388. model.rels.forEach(function (rel) {
  15389. if (rel.Type === RelType.VmlDrawing) {
  15390. xmlStream.leafNode('legacyDrawing', {
  15391. 'r:id': rel.Id
  15392. });
  15393. }
  15394. });
  15395. }
  15396. xmlStream.closeNode();
  15397. }
  15398. }, {
  15399. key: "parseOpen",
  15400. value: function parseOpen(node) {
  15401. if (this.parser) {
  15402. this.parser.parseOpen(node);
  15403. return true;
  15404. }
  15405. if (node.name === 'worksheet') {
  15406. _.each(this.map, function (xform) {
  15407. xform.reset();
  15408. });
  15409. return true;
  15410. }
  15411. this.parser = this.map[node.name];
  15412. if (this.parser) {
  15413. this.parser.parseOpen(node);
  15414. }
  15415. return true;
  15416. }
  15417. }, {
  15418. key: "parseText",
  15419. value: function parseText(text) {
  15420. if (this.parser) {
  15421. this.parser.parseText(text);
  15422. }
  15423. }
  15424. }, {
  15425. key: "parseClose",
  15426. value: function parseClose(name) {
  15427. if (this.parser) {
  15428. if (!this.parser.parseClose(name)) {
  15429. this.parser = undefined;
  15430. }
  15431. return true;
  15432. }
  15433. switch (name) {
  15434. case 'worksheet':
  15435. {
  15436. var properties = this.map.sheetFormatPr.model || {};
  15437. if (this.map.sheetPr.model && this.map.sheetPr.model.tabColor) {
  15438. properties.tabColor = this.map.sheetPr.model.tabColor;
  15439. }
  15440. if (this.map.sheetPr.model && this.map.sheetPr.model.outlineProperties) {
  15441. properties.outlineProperties = this.map.sheetPr.model.outlineProperties;
  15442. }
  15443. var sheetProperties = {
  15444. fitToPage: this.map.sheetPr.model && this.map.sheetPr.model.pageSetup && this.map.sheetPr.model.pageSetup.fitToPage || false,
  15445. margins: this.map.pageMargins.model
  15446. };
  15447. var pageSetup = Object.assign(sheetProperties, this.map.pageSetup.model, this.map.printOptions.model);
  15448. var conditionalFormattings = mergeConditionalFormattings(this.map.conditionalFormatting.model, this.map.extLst.model && this.map.extLst.model['x14:conditionalFormattings']);
  15449. this.model = {
  15450. dimensions: this.map.dimension.model,
  15451. cols: this.map.cols.model,
  15452. rows: this.map.sheetData.model,
  15453. mergeCells: this.map.mergeCells.model,
  15454. hyperlinks: this.map.hyperlinks.model,
  15455. dataValidations: this.map.dataValidations.model,
  15456. properties: properties,
  15457. views: this.map.sheetViews.model,
  15458. pageSetup: pageSetup,
  15459. headerFooter: this.map.headerFooter.model,
  15460. background: this.map.picture.model,
  15461. drawing: this.map.drawing.model,
  15462. tables: this.map.tableParts.model,
  15463. conditionalFormattings: conditionalFormattings
  15464. };
  15465. if (this.map.autoFilter.model) {
  15466. this.model.autoFilter = this.map.autoFilter.model;
  15467. }
  15468. if (this.map.sheetProtection.model) {
  15469. this.model.sheetProtection = this.map.sheetProtection.model;
  15470. }
  15471. return false;
  15472. }
  15473. default:
  15474. // not quite sure how we get here!
  15475. return true;
  15476. }
  15477. }
  15478. }, {
  15479. key: "reconcile",
  15480. value: function reconcile(model, options) {
  15481. // options.merges = new Merges();
  15482. // options.merges.reconcile(model.mergeCells, model.rows);
  15483. var rels = (model.relationships || []).reduce(function (h, rel) {
  15484. h[rel.Id] = rel;
  15485. if (rel.Type === RelType.Comments) {
  15486. model.comments = options.comments[rel.Target].comments;
  15487. }
  15488. if (rel.Type === RelType.VmlDrawing && model.comments && model.comments.length) {
  15489. var vmlComment = options.vmlDrawings[rel.Target].comments;
  15490. model.comments.forEach(function (comment, index) {
  15491. comment.note = Object.assign({}, comment.note, vmlComment[index]);
  15492. });
  15493. }
  15494. return h;
  15495. }, {});
  15496. options.commentsMap = (model.comments || []).reduce(function (h, comment) {
  15497. if (comment.ref) {
  15498. h[comment.ref] = comment;
  15499. }
  15500. return h;
  15501. }, {});
  15502. options.hyperlinkMap = (model.hyperlinks || []).reduce(function (h, hyperlink) {
  15503. if (hyperlink.rId) {
  15504. h[hyperlink.address] = rels[hyperlink.rId].Target;
  15505. }
  15506. return h;
  15507. }, {});
  15508. options.formulae = {}; // compact the rows and cells
  15509. model.rows = model.rows && model.rows.filter(Boolean) || [];
  15510. model.rows.forEach(function (row) {
  15511. row.cells = row.cells && row.cells.filter(Boolean) || [];
  15512. });
  15513. this.map.cols.reconcile(model.cols, options);
  15514. this.map.sheetData.reconcile(model.rows, options);
  15515. this.map.conditionalFormatting.reconcile(model.conditionalFormattings, options);
  15516. model.media = [];
  15517. if (model.drawing) {
  15518. var drawingRel = rels[model.drawing.rId];
  15519. var match = drawingRel.Target.match(/\/drawings\/([a-zA-Z0-9]+)[.][a-zA-Z]{3,4}$/);
  15520. if (match) {
  15521. var drawingName = match[1];
  15522. var drawing = options.drawings[drawingName];
  15523. drawing.anchors.forEach(function (anchor) {
  15524. if (anchor.medium) {
  15525. var image = {
  15526. type: 'image',
  15527. imageId: anchor.medium.index,
  15528. range: anchor.range,
  15529. hyperlinks: anchor.picture.hyperlinks
  15530. };
  15531. model.media.push(image);
  15532. }
  15533. });
  15534. }
  15535. }
  15536. var backgroundRel = model.background && rels[model.background.rId];
  15537. if (backgroundRel) {
  15538. var target = backgroundRel.Target.split('/media/')[1];
  15539. var imageId = options.mediaIndex && options.mediaIndex[target];
  15540. if (imageId !== undefined) {
  15541. model.media.push({
  15542. type: 'background',
  15543. imageId: imageId
  15544. });
  15545. }
  15546. }
  15547. model.tables = (model.tables || []).map(function (tablePart) {
  15548. var rel = rels[tablePart.rId];
  15549. return options.tables[rel.Target];
  15550. });
  15551. delete model.relationships;
  15552. delete model.hyperlinks;
  15553. delete model.comments;
  15554. }
  15555. }]);
  15556. return WorkSheetXform;
  15557. }(BaseXform);
  15558. WorkSheetXform.WORKSHEET_ATTRIBUTES = {
  15559. xmlns: 'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
  15560. 'xmlns:r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
  15561. 'xmlns:mc': 'http://schemas.openxmlformats.org/markup-compatibility/2006',
  15562. 'mc:Ignorable': 'x14ac',
  15563. 'xmlns:x14ac': 'http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac'
  15564. };
  15565. module.exports = WorkSheetXform;
  15566. },{"../../../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){
  15567. "use strict";
  15568. 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); }
  15569. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  15570. 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); } }
  15571. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  15572. 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); }
  15573. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  15574. 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); }; }
  15575. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  15576. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  15577. 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; } }
  15578. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  15579. var BaseXform = require('../base-xform');
  15580. var BooleanXform = /*#__PURE__*/function (_BaseXform) {
  15581. _inherits(BooleanXform, _BaseXform);
  15582. var _super = _createSuper(BooleanXform);
  15583. function BooleanXform(options) {
  15584. var _this;
  15585. _classCallCheck(this, BooleanXform);
  15586. _this = _super.call(this);
  15587. _this.tag = options.tag;
  15588. _this.attr = options.attr;
  15589. return _this;
  15590. }
  15591. _createClass(BooleanXform, [{
  15592. key: "render",
  15593. value: function render(xmlStream, model) {
  15594. if (model) {
  15595. xmlStream.openNode(this.tag);
  15596. xmlStream.closeNode();
  15597. }
  15598. }
  15599. }, {
  15600. key: "parseOpen",
  15601. value: function parseOpen(node) {
  15602. if (node.name === this.tag) {
  15603. this.model = true;
  15604. }
  15605. }
  15606. }, {
  15607. key: "parseText",
  15608. value: function parseText() {}
  15609. }, {
  15610. key: "parseClose",
  15611. value: function parseClose() {
  15612. return false;
  15613. }
  15614. }]);
  15615. return BooleanXform;
  15616. }(BaseXform);
  15617. module.exports = BooleanXform;
  15618. },{"../base-xform":31}],116:[function(require,module,exports){
  15619. "use strict";
  15620. 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); }
  15621. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  15622. 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); } }
  15623. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  15624. 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); }
  15625. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  15626. 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); }; }
  15627. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  15628. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  15629. 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; } }
  15630. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  15631. var BaseXform = require('../base-xform');
  15632. var DateXform = /*#__PURE__*/function (_BaseXform) {
  15633. _inherits(DateXform, _BaseXform);
  15634. var _super = _createSuper(DateXform);
  15635. function DateXform(options) {
  15636. var _this;
  15637. _classCallCheck(this, DateXform);
  15638. _this = _super.call(this);
  15639. _this.tag = options.tag;
  15640. _this.attr = options.attr;
  15641. _this.attrs = options.attrs;
  15642. _this._format = options.format || function (dt) {
  15643. try {
  15644. if (Number.isNaN(dt.getTime())) return '';
  15645. return dt.toISOString();
  15646. } catch (e) {
  15647. return '';
  15648. }
  15649. };
  15650. _this._parse = options.parse || function (str) {
  15651. return new Date(str);
  15652. };
  15653. return _this;
  15654. }
  15655. _createClass(DateXform, [{
  15656. key: "render",
  15657. value: function render(xmlStream, model) {
  15658. if (model) {
  15659. xmlStream.openNode(this.tag);
  15660. if (this.attrs) {
  15661. xmlStream.addAttributes(this.attrs);
  15662. }
  15663. if (this.attr) {
  15664. xmlStream.addAttribute(this.attr, this._format(model));
  15665. } else {
  15666. xmlStream.writeText(this._format(model));
  15667. }
  15668. xmlStream.closeNode();
  15669. }
  15670. }
  15671. }, {
  15672. key: "parseOpen",
  15673. value: function parseOpen(node) {
  15674. if (node.name === this.tag) {
  15675. if (this.attr) {
  15676. this.model = this._parse(node.attributes[this.attr]);
  15677. } else {
  15678. this.text = [];
  15679. }
  15680. }
  15681. }
  15682. }, {
  15683. key: "parseText",
  15684. value: function parseText(text) {
  15685. if (!this.attr) {
  15686. this.text.push(text);
  15687. }
  15688. }
  15689. }, {
  15690. key: "parseClose",
  15691. value: function parseClose() {
  15692. if (!this.attr) {
  15693. this.model = this._parse(this.text.join(''));
  15694. }
  15695. return false;
  15696. }
  15697. }]);
  15698. return DateXform;
  15699. }(BaseXform);
  15700. module.exports = DateXform;
  15701. },{"../base-xform":31}],117:[function(require,module,exports){
  15702. "use strict";
  15703. 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); }
  15704. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  15705. 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); } }
  15706. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  15707. 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); }
  15708. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  15709. 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); }; }
  15710. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  15711. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  15712. 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; } }
  15713. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  15714. var BaseXform = require('../base-xform');
  15715. var IntegerXform = /*#__PURE__*/function (_BaseXform) {
  15716. _inherits(IntegerXform, _BaseXform);
  15717. var _super = _createSuper(IntegerXform);
  15718. function IntegerXform(options) {
  15719. var _this;
  15720. _classCallCheck(this, IntegerXform);
  15721. _this = _super.call(this);
  15722. _this.tag = options.tag;
  15723. _this.attr = options.attr;
  15724. _this.attrs = options.attrs; // option to render zero
  15725. _this.zero = options.zero;
  15726. return _this;
  15727. }
  15728. _createClass(IntegerXform, [{
  15729. key: "render",
  15730. value: function render(xmlStream, model) {
  15731. // int is different to float in that zero is not rendered
  15732. if (model || this.zero) {
  15733. xmlStream.openNode(this.tag);
  15734. if (this.attrs) {
  15735. xmlStream.addAttributes(this.attrs);
  15736. }
  15737. if (this.attr) {
  15738. xmlStream.addAttribute(this.attr, model);
  15739. } else {
  15740. xmlStream.writeText(model);
  15741. }
  15742. xmlStream.closeNode();
  15743. }
  15744. }
  15745. }, {
  15746. key: "parseOpen",
  15747. value: function parseOpen(node) {
  15748. if (node.name === this.tag) {
  15749. if (this.attr) {
  15750. this.model = parseInt(node.attributes[this.attr], 10);
  15751. } else {
  15752. this.text = [];
  15753. }
  15754. return true;
  15755. }
  15756. return false;
  15757. }
  15758. }, {
  15759. key: "parseText",
  15760. value: function parseText(text) {
  15761. if (!this.attr) {
  15762. this.text.push(text);
  15763. }
  15764. }
  15765. }, {
  15766. key: "parseClose",
  15767. value: function parseClose() {
  15768. if (!this.attr) {
  15769. this.model = parseInt(this.text.join('') || 0, 10);
  15770. }
  15771. return false;
  15772. }
  15773. }]);
  15774. return IntegerXform;
  15775. }(BaseXform);
  15776. module.exports = IntegerXform;
  15777. },{"../base-xform":31}],118:[function(require,module,exports){
  15778. "use strict";
  15779. 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); }
  15780. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  15781. 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); } }
  15782. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  15783. 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); }
  15784. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  15785. 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); }; }
  15786. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  15787. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  15788. 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; } }
  15789. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  15790. var BaseXform = require('../base-xform');
  15791. var StringXform = /*#__PURE__*/function (_BaseXform) {
  15792. _inherits(StringXform, _BaseXform);
  15793. var _super = _createSuper(StringXform);
  15794. function StringXform(options) {
  15795. var _this;
  15796. _classCallCheck(this, StringXform);
  15797. _this = _super.call(this);
  15798. _this.tag = options.tag;
  15799. _this.attr = options.attr;
  15800. _this.attrs = options.attrs;
  15801. return _this;
  15802. }
  15803. _createClass(StringXform, [{
  15804. key: "render",
  15805. value: function render(xmlStream, model) {
  15806. if (model !== undefined) {
  15807. xmlStream.openNode(this.tag);
  15808. if (this.attrs) {
  15809. xmlStream.addAttributes(this.attrs);
  15810. }
  15811. if (this.attr) {
  15812. xmlStream.addAttribute(this.attr, model);
  15813. } else {
  15814. xmlStream.writeText(model);
  15815. }
  15816. xmlStream.closeNode();
  15817. }
  15818. }
  15819. }, {
  15820. key: "parseOpen",
  15821. value: function parseOpen(node) {
  15822. if (node.name === this.tag) {
  15823. if (this.attr) {
  15824. this.model = node.attributes[this.attr];
  15825. } else {
  15826. this.text = [];
  15827. }
  15828. }
  15829. }
  15830. }, {
  15831. key: "parseText",
  15832. value: function parseText(text) {
  15833. if (!this.attr) {
  15834. this.text.push(text);
  15835. }
  15836. }
  15837. }, {
  15838. key: "parseClose",
  15839. value: function parseClose() {
  15840. if (!this.attr) {
  15841. this.model = this.text.join('');
  15842. }
  15843. return false;
  15844. }
  15845. }]);
  15846. return StringXform;
  15847. }(BaseXform);
  15848. module.exports = StringXform;
  15849. },{"../base-xform":31}],119:[function(require,module,exports){
  15850. "use strict";
  15851. 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); }
  15852. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  15853. 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); } }
  15854. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  15855. 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); }
  15856. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  15857. 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); }; }
  15858. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  15859. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  15860. 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; } }
  15861. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  15862. var BaseXform = require('./base-xform');
  15863. var XmlStream = require('../../utils/xml-stream'); // const model = {
  15864. // tag: 'name',
  15865. // $: {attr: 'value'},
  15866. // c: [
  15867. // { tag: 'child' }
  15868. // ],
  15869. // t: 'some text'
  15870. // };
  15871. function build(xmlStream, model) {
  15872. xmlStream.openNode(model.tag, model.$);
  15873. if (model.c) {
  15874. model.c.forEach(function (child) {
  15875. build(xmlStream, child);
  15876. });
  15877. }
  15878. if (model.t) {
  15879. xmlStream.writeText(model.t);
  15880. }
  15881. xmlStream.closeNode();
  15882. }
  15883. var StaticXform = /*#__PURE__*/function (_BaseXform) {
  15884. _inherits(StaticXform, _BaseXform);
  15885. var _super = _createSuper(StaticXform);
  15886. function StaticXform(model) {
  15887. var _this;
  15888. _classCallCheck(this, StaticXform);
  15889. _this = _super.call(this); // This class is an optimisation for static (unimportant and unchanging) xml
  15890. // It is stateless - apart from its static model and so can be used as a singleton
  15891. // Being stateless - it will only track entry to and exit from it's root xml tag during parsing and nothing else
  15892. // Known issues:
  15893. // since stateless - parseOpen always returns true. Parent xform must know when to start using this xform
  15894. // if the root tag is recursive, the parsing will behave unpredictably
  15895. _this._model = model;
  15896. return _this;
  15897. }
  15898. _createClass(StaticXform, [{
  15899. key: "render",
  15900. value: function render(xmlStream) {
  15901. if (!this._xml) {
  15902. var stream = new XmlStream();
  15903. build(stream, this._model);
  15904. this._xml = stream.xml;
  15905. }
  15906. xmlStream.writeXml(this._xml);
  15907. }
  15908. }, {
  15909. key: "parseOpen",
  15910. value: function parseOpen() {
  15911. return true;
  15912. }
  15913. }, {
  15914. key: "parseText",
  15915. value: function parseText() {}
  15916. }, {
  15917. key: "parseClose",
  15918. value: function parseClose(name) {
  15919. switch (name) {
  15920. case this._model.tag:
  15921. return false;
  15922. default:
  15923. return true;
  15924. }
  15925. }
  15926. }]);
  15927. return StaticXform;
  15928. }(BaseXform);
  15929. module.exports = StaticXform;
  15930. },{"../../utils/xml-stream":27,"./base-xform":31}],120:[function(require,module,exports){
  15931. "use strict";
  15932. 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); }
  15933. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  15934. 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); } }
  15935. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  15936. 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); }
  15937. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  15938. 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); }; }
  15939. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  15940. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  15941. 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; } }
  15942. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  15943. var TextXform = require('./text-xform');
  15944. var RichTextXform = require('./rich-text-xform');
  15945. var BaseXform = require('../base-xform'); // <rPh sb="0" eb="1">
  15946. // <t>(its pronounciation in KATAKANA)</t>
  15947. // </rPh>
  15948. var PhoneticTextXform = /*#__PURE__*/function (_BaseXform) {
  15949. _inherits(PhoneticTextXform, _BaseXform);
  15950. var _super = _createSuper(PhoneticTextXform);
  15951. function PhoneticTextXform() {
  15952. var _this;
  15953. _classCallCheck(this, PhoneticTextXform);
  15954. _this = _super.call(this);
  15955. _this.map = {
  15956. r: new RichTextXform(),
  15957. t: new TextXform()
  15958. };
  15959. return _this;
  15960. }
  15961. _createClass(PhoneticTextXform, [{
  15962. key: "render",
  15963. value: function render(xmlStream, model) {
  15964. xmlStream.openNode(this.tag, {
  15965. sb: model.sb || 0,
  15966. eb: model.eb || 0
  15967. });
  15968. if (model && model.hasOwnProperty('richText') && model.richText) {
  15969. var r = this.map.r;
  15970. model.richText.forEach(function (text) {
  15971. r.render(xmlStream, text);
  15972. });
  15973. } else if (model) {
  15974. this.map.t.render(xmlStream, model.text);
  15975. }
  15976. xmlStream.closeNode();
  15977. }
  15978. }, {
  15979. key: "parseOpen",
  15980. value: function parseOpen(node) {
  15981. var name = node.name;
  15982. if (this.parser) {
  15983. this.parser.parseOpen(node);
  15984. return true;
  15985. }
  15986. if (name === this.tag) {
  15987. this.model = {
  15988. sb: parseInt(node.attributes.sb, 10),
  15989. eb: parseInt(node.attributes.eb, 10)
  15990. };
  15991. return true;
  15992. }
  15993. this.parser = this.map[name];
  15994. if (this.parser) {
  15995. this.parser.parseOpen(node);
  15996. return true;
  15997. }
  15998. return false;
  15999. }
  16000. }, {
  16001. key: "parseText",
  16002. value: function parseText(text) {
  16003. if (this.parser) {
  16004. this.parser.parseText(text);
  16005. }
  16006. }
  16007. }, {
  16008. key: "parseClose",
  16009. value: function parseClose(name) {
  16010. if (this.parser) {
  16011. if (!this.parser.parseClose(name)) {
  16012. switch (name) {
  16013. case 'r':
  16014. {
  16015. var rt = this.model.richText;
  16016. if (!rt) {
  16017. rt = this.model.richText = [];
  16018. }
  16019. rt.push(this.parser.model);
  16020. break;
  16021. }
  16022. case 't':
  16023. this.model.text = this.parser.model;
  16024. break;
  16025. default:
  16026. break;
  16027. }
  16028. this.parser = undefined;
  16029. }
  16030. return true;
  16031. }
  16032. switch (name) {
  16033. case this.tag:
  16034. return false;
  16035. default:
  16036. return true;
  16037. }
  16038. }
  16039. }, {
  16040. key: "tag",
  16041. get: function get() {
  16042. return 'rPh';
  16043. }
  16044. }]);
  16045. return PhoneticTextXform;
  16046. }(BaseXform);
  16047. module.exports = PhoneticTextXform;
  16048. },{"../base-xform":31,"./rich-text-xform":121,"./text-xform":124}],121:[function(require,module,exports){
  16049. "use strict";
  16050. 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); }
  16051. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16052. 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); } }
  16053. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  16054. 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); }
  16055. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  16056. 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); }; }
  16057. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  16058. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  16059. 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; } }
  16060. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  16061. var TextXform = require('./text-xform');
  16062. var FontXform = require('../style/font-xform');
  16063. var BaseXform = require('../base-xform'); // <r>
  16064. // <rPr>
  16065. // <sz val="11"/>
  16066. // <color theme="1" tint="5"/>
  16067. // <rFont val="Calibri"/>
  16068. // <family val="2"/>
  16069. // <scheme val="minor"/>
  16070. // </rPr>
  16071. // <t xml:space="preserve"> is </t>
  16072. // </r>
  16073. var RichTextXform = /*#__PURE__*/function (_BaseXform) {
  16074. _inherits(RichTextXform, _BaseXform);
  16075. var _super = _createSuper(RichTextXform);
  16076. function RichTextXform(model) {
  16077. var _this;
  16078. _classCallCheck(this, RichTextXform);
  16079. _this = _super.call(this);
  16080. _this.model = model;
  16081. return _this;
  16082. }
  16083. _createClass(RichTextXform, [{
  16084. key: "render",
  16085. value: function render(xmlStream, model) {
  16086. model = model || this.model;
  16087. xmlStream.openNode('r');
  16088. if (model.font) {
  16089. this.fontXform.render(xmlStream, model.font);
  16090. }
  16091. this.textXform.render(xmlStream, model.text);
  16092. xmlStream.closeNode();
  16093. }
  16094. }, {
  16095. key: "parseOpen",
  16096. value: function parseOpen(node) {
  16097. if (this.parser) {
  16098. this.parser.parseOpen(node);
  16099. return true;
  16100. }
  16101. switch (node.name) {
  16102. case 'r':
  16103. this.model = {};
  16104. return true;
  16105. case 't':
  16106. this.parser = this.textXform;
  16107. this.parser.parseOpen(node);
  16108. return true;
  16109. case 'rPr':
  16110. this.parser = this.fontXform;
  16111. this.parser.parseOpen(node);
  16112. return true;
  16113. default:
  16114. return false;
  16115. }
  16116. }
  16117. }, {
  16118. key: "parseText",
  16119. value: function parseText(text) {
  16120. if (this.parser) {
  16121. this.parser.parseText(text);
  16122. }
  16123. }
  16124. }, {
  16125. key: "parseClose",
  16126. value: function parseClose(name) {
  16127. switch (name) {
  16128. case 'r':
  16129. return false;
  16130. case 't':
  16131. this.model.text = this.parser.model;
  16132. this.parser = undefined;
  16133. return true;
  16134. case 'rPr':
  16135. this.model.font = this.parser.model;
  16136. this.parser = undefined;
  16137. return true;
  16138. default:
  16139. if (this.parser) {
  16140. this.parser.parseClose(name);
  16141. }
  16142. return true;
  16143. }
  16144. }
  16145. }, {
  16146. key: "tag",
  16147. get: function get() {
  16148. return 'r';
  16149. }
  16150. }, {
  16151. key: "textXform",
  16152. get: function get() {
  16153. return this._textXform || (this._textXform = new TextXform());
  16154. }
  16155. }, {
  16156. key: "fontXform",
  16157. get: function get() {
  16158. return this._fontXform || (this._fontXform = new FontXform(RichTextXform.FONT_OPTIONS));
  16159. }
  16160. }]);
  16161. return RichTextXform;
  16162. }(BaseXform);
  16163. RichTextXform.FONT_OPTIONS = {
  16164. tagName: 'rPr',
  16165. fontNameTag: 'rFont'
  16166. };
  16167. module.exports = RichTextXform;
  16168. },{"../base-xform":31,"../style/font-xform":130,"./text-xform":124}],122:[function(require,module,exports){
  16169. "use strict";
  16170. 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); }
  16171. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16172. 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); } }
  16173. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  16174. 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); }
  16175. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  16176. 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); }; }
  16177. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  16178. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  16179. 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; } }
  16180. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  16181. var TextXform = require('./text-xform');
  16182. var RichTextXform = require('./rich-text-xform');
  16183. var PhoneticTextXform = require('./phonetic-text-xform');
  16184. var BaseXform = require('../base-xform'); // <si>
  16185. // <r></r><r></r>...
  16186. // </si>
  16187. // <si>
  16188. // <t></t>
  16189. // </si>
  16190. var SharedStringXform = /*#__PURE__*/function (_BaseXform) {
  16191. _inherits(SharedStringXform, _BaseXform);
  16192. var _super = _createSuper(SharedStringXform);
  16193. function SharedStringXform(model) {
  16194. var _this;
  16195. _classCallCheck(this, SharedStringXform);
  16196. _this = _super.call(this);
  16197. _this.model = model;
  16198. _this.map = {
  16199. r: new RichTextXform(),
  16200. t: new TextXform(),
  16201. rPh: new PhoneticTextXform()
  16202. };
  16203. return _this;
  16204. }
  16205. _createClass(SharedStringXform, [{
  16206. key: "render",
  16207. value: function render(xmlStream, model) {
  16208. var _this2 = this;
  16209. xmlStream.openNode(this.tag);
  16210. if (model && model.hasOwnProperty('richText') && model.richText) {
  16211. if (model.richText.length) {
  16212. model.richText.forEach(function (text) {
  16213. _this2.map.r.render(xmlStream, text);
  16214. });
  16215. } else {
  16216. this.map.t.render(xmlStream, '');
  16217. }
  16218. } else if (model !== undefined && model !== null) {
  16219. this.map.t.render(xmlStream, model);
  16220. }
  16221. xmlStream.closeNode();
  16222. }
  16223. }, {
  16224. key: "parseOpen",
  16225. value: function parseOpen(node) {
  16226. var name = node.name;
  16227. if (this.parser) {
  16228. this.parser.parseOpen(node);
  16229. return true;
  16230. }
  16231. if (name === this.tag) {
  16232. this.model = {};
  16233. return true;
  16234. }
  16235. this.parser = this.map[name];
  16236. if (this.parser) {
  16237. this.parser.parseOpen(node);
  16238. return true;
  16239. }
  16240. return false;
  16241. }
  16242. }, {
  16243. key: "parseText",
  16244. value: function parseText(text) {
  16245. if (this.parser) {
  16246. this.parser.parseText(text);
  16247. }
  16248. }
  16249. }, {
  16250. key: "parseClose",
  16251. value: function parseClose(name) {
  16252. if (this.parser) {
  16253. if (!this.parser.parseClose(name)) {
  16254. switch (name) {
  16255. case 'r':
  16256. {
  16257. var rt = this.model.richText;
  16258. if (!rt) {
  16259. rt = this.model.richText = [];
  16260. }
  16261. rt.push(this.parser.model);
  16262. break;
  16263. }
  16264. case 't':
  16265. this.model = this.parser.model;
  16266. break;
  16267. default:
  16268. break;
  16269. }
  16270. this.parser = undefined;
  16271. }
  16272. return true;
  16273. }
  16274. switch (name) {
  16275. case this.tag:
  16276. return false;
  16277. default:
  16278. return true;
  16279. }
  16280. }
  16281. }, {
  16282. key: "tag",
  16283. get: function get() {
  16284. return 'si';
  16285. }
  16286. }]);
  16287. return SharedStringXform;
  16288. }(BaseXform);
  16289. module.exports = SharedStringXform;
  16290. },{"../base-xform":31,"./phonetic-text-xform":120,"./rich-text-xform":121,"./text-xform":124}],123:[function(require,module,exports){
  16291. "use strict";
  16292. 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); }
  16293. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16294. 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); } }
  16295. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  16296. 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); }
  16297. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  16298. 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); }; }
  16299. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  16300. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  16301. 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; } }
  16302. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  16303. var XmlStream = require('../../../utils/xml-stream');
  16304. var BaseXform = require('../base-xform');
  16305. var SharedStringXform = require('./shared-string-xform');
  16306. var SharedStringsXform = /*#__PURE__*/function (_BaseXform) {
  16307. _inherits(SharedStringsXform, _BaseXform);
  16308. var _super = _createSuper(SharedStringsXform);
  16309. function SharedStringsXform(model) {
  16310. var _this;
  16311. _classCallCheck(this, SharedStringsXform);
  16312. _this = _super.call(this);
  16313. _this.model = model || {
  16314. values: [],
  16315. count: 0
  16316. };
  16317. _this.hash = Object.create(null);
  16318. _this.rich = Object.create(null);
  16319. return _this;
  16320. }
  16321. _createClass(SharedStringsXform, [{
  16322. key: "getString",
  16323. value: function getString(index) {
  16324. return this.model.values[index];
  16325. }
  16326. }, {
  16327. key: "add",
  16328. value: function add(value) {
  16329. return value.richText ? this.addRichText(value) : this.addText(value);
  16330. }
  16331. }, {
  16332. key: "addText",
  16333. value: function addText(value) {
  16334. var index = this.hash[value];
  16335. if (index === undefined) {
  16336. index = this.hash[value] = this.model.values.length;
  16337. this.model.values.push(value);
  16338. }
  16339. this.model.count++;
  16340. return index;
  16341. }
  16342. }, {
  16343. key: "addRichText",
  16344. value: function addRichText(value) {
  16345. // TODO: add WeakMap here
  16346. var xml = this.sharedStringXform.toXml(value);
  16347. var index = this.rich[xml];
  16348. if (index === undefined) {
  16349. index = this.rich[xml] = this.model.values.length;
  16350. this.model.values.push(value);
  16351. }
  16352. this.model.count++;
  16353. return index;
  16354. } // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  16355. // <sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="<%=totalRefs%>" uniqueCount="<%=count%>">
  16356. // <si><t><%=text%></t></si>
  16357. // <si><r><rPr></rPr><t></t></r></si>
  16358. // </sst>
  16359. }, {
  16360. key: "render",
  16361. value: function render(xmlStream, model) {
  16362. model = model || this._values;
  16363. xmlStream.openXml(XmlStream.StdDocAttributes);
  16364. xmlStream.openNode('sst', {
  16365. xmlns: 'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
  16366. count: model.count,
  16367. uniqueCount: model.values.length
  16368. });
  16369. var sx = this.sharedStringXform;
  16370. model.values.forEach(function (sharedString) {
  16371. sx.render(xmlStream, sharedString);
  16372. });
  16373. xmlStream.closeNode();
  16374. }
  16375. }, {
  16376. key: "parseOpen",
  16377. value: function parseOpen(node) {
  16378. if (this.parser) {
  16379. this.parser.parseOpen(node);
  16380. return true;
  16381. }
  16382. switch (node.name) {
  16383. case 'sst':
  16384. return true;
  16385. case 'si':
  16386. this.parser = this.sharedStringXform;
  16387. this.parser.parseOpen(node);
  16388. return true;
  16389. default:
  16390. throw new Error("Unexpected xml node in parseOpen: ".concat(JSON.stringify(node)));
  16391. }
  16392. }
  16393. }, {
  16394. key: "parseText",
  16395. value: function parseText(text) {
  16396. if (this.parser) {
  16397. this.parser.parseText(text);
  16398. }
  16399. }
  16400. }, {
  16401. key: "parseClose",
  16402. value: function parseClose(name) {
  16403. if (this.parser) {
  16404. if (!this.parser.parseClose(name)) {
  16405. this.model.values.push(this.parser.model);
  16406. this.model.count++;
  16407. this.parser = undefined;
  16408. }
  16409. return true;
  16410. }
  16411. switch (name) {
  16412. case 'sst':
  16413. return false;
  16414. default:
  16415. throw new Error("Unexpected xml node in parseClose: ".concat(name));
  16416. }
  16417. }
  16418. }, {
  16419. key: "sharedStringXform",
  16420. get: function get() {
  16421. return this._sharedStringXform || (this._sharedStringXform = new SharedStringXform());
  16422. }
  16423. }, {
  16424. key: "values",
  16425. get: function get() {
  16426. return this.model.values;
  16427. }
  16428. }, {
  16429. key: "uniqueCount",
  16430. get: function get() {
  16431. return this.model.values.length;
  16432. }
  16433. }, {
  16434. key: "count",
  16435. get: function get() {
  16436. return this.model.count;
  16437. }
  16438. }]);
  16439. return SharedStringsXform;
  16440. }(BaseXform);
  16441. module.exports = SharedStringsXform;
  16442. },{"../../../utils/xml-stream":27,"../base-xform":31,"./shared-string-xform":122}],124:[function(require,module,exports){
  16443. "use strict";
  16444. 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); }
  16445. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16446. 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); } }
  16447. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  16448. 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); }
  16449. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  16450. 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); }; }
  16451. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  16452. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  16453. 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; } }
  16454. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  16455. var BaseXform = require('../base-xform'); // <t xml:space="preserve"> is </t>
  16456. var TextXform = /*#__PURE__*/function (_BaseXform) {
  16457. _inherits(TextXform, _BaseXform);
  16458. var _super = _createSuper(TextXform);
  16459. function TextXform() {
  16460. _classCallCheck(this, TextXform);
  16461. return _super.apply(this, arguments);
  16462. }
  16463. _createClass(TextXform, [{
  16464. key: "render",
  16465. value: function render(xmlStream, model) {
  16466. xmlStream.openNode('t');
  16467. if (/^\s|\n|\s$/.test(model)) {
  16468. xmlStream.addAttribute('xml:space', 'preserve');
  16469. }
  16470. xmlStream.writeText(model);
  16471. xmlStream.closeNode();
  16472. }
  16473. }, {
  16474. key: "parseOpen",
  16475. value: function parseOpen(node) {
  16476. switch (node.name) {
  16477. case 't':
  16478. this._text = [];
  16479. return true;
  16480. default:
  16481. return false;
  16482. }
  16483. }
  16484. }, {
  16485. key: "parseText",
  16486. value: function parseText(text) {
  16487. this._text.push(text);
  16488. }
  16489. }, {
  16490. key: "parseClose",
  16491. value: function parseClose() {
  16492. return false;
  16493. }
  16494. }, {
  16495. key: "tag",
  16496. get: function get() {
  16497. return 't';
  16498. }
  16499. }, {
  16500. key: "model",
  16501. get: function get() {
  16502. return this._text.join('').replace(/_x([0-9A-F]{4})_/g, function ($0, $1) {
  16503. return String.fromCharCode(parseInt($1, 16));
  16504. });
  16505. }
  16506. }]);
  16507. return TextXform;
  16508. }(BaseXform);
  16509. module.exports = TextXform;
  16510. },{"../base-xform":31}],125:[function(require,module,exports){
  16511. "use strict";
  16512. 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); }
  16513. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16514. 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); } }
  16515. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  16516. 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); }
  16517. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  16518. 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); }; }
  16519. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  16520. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  16521. 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; } }
  16522. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  16523. var Enums = require('../../../doc/enums');
  16524. var utils = require('../../../utils/utils');
  16525. var BaseXform = require('../base-xform');
  16526. var validation = {
  16527. horizontalValues: ['left', 'center', 'right', 'fill', 'centerContinuous', 'distributed', 'justify'].reduce(function (p, v) {
  16528. p[v] = true;
  16529. return p;
  16530. }, {}),
  16531. horizontal: function horizontal(value) {
  16532. return this.horizontalValues[value] ? value : undefined;
  16533. },
  16534. verticalValues: ['top', 'middle', 'bottom', 'distributed', 'justify'].reduce(function (p, v) {
  16535. p[v] = true;
  16536. return p;
  16537. }, {}),
  16538. vertical: function vertical(value) {
  16539. if (value === 'middle') return 'center';
  16540. return this.verticalValues[value] ? value : undefined;
  16541. },
  16542. wrapText: function wrapText(value) {
  16543. return value ? true : undefined;
  16544. },
  16545. shrinkToFit: function shrinkToFit(value) {
  16546. return value ? true : undefined;
  16547. },
  16548. textRotation: function textRotation(value) {
  16549. switch (value) {
  16550. case 'vertical':
  16551. return value;
  16552. default:
  16553. value = utils.validInt(value);
  16554. return value >= -90 && value <= 90 ? value : undefined;
  16555. }
  16556. },
  16557. indent: function indent(value) {
  16558. value = utils.validInt(value);
  16559. return Math.max(0, value);
  16560. },
  16561. readingOrder: function readingOrder(value) {
  16562. switch (value) {
  16563. case 'ltr':
  16564. return Enums.ReadingOrder.LeftToRight;
  16565. case 'rtl':
  16566. return Enums.ReadingOrder.RightToLeft;
  16567. default:
  16568. return undefined;
  16569. }
  16570. }
  16571. };
  16572. var textRotationXform = {
  16573. toXml: function toXml(textRotation) {
  16574. textRotation = validation.textRotation(textRotation);
  16575. if (textRotation) {
  16576. if (textRotation === 'vertical') {
  16577. return 255;
  16578. }
  16579. var tr = Math.round(textRotation);
  16580. if (tr >= 0 && tr <= 90) {
  16581. return tr;
  16582. }
  16583. if (tr < 0 && tr >= -90) {
  16584. return 90 - tr;
  16585. }
  16586. }
  16587. return undefined;
  16588. },
  16589. toModel: function toModel(textRotation) {
  16590. var tr = utils.validInt(textRotation);
  16591. if (tr !== undefined) {
  16592. if (tr === 255) {
  16593. return 'vertical';
  16594. }
  16595. if (tr >= 0 && tr <= 90) {
  16596. return tr;
  16597. }
  16598. if (tr > 90 && tr <= 180) {
  16599. return 90 - tr;
  16600. }
  16601. }
  16602. return undefined;
  16603. }
  16604. }; // Alignment encapsulates translation from style.alignment model to/from xlsx
  16605. var AlignmentXform = /*#__PURE__*/function (_BaseXform) {
  16606. _inherits(AlignmentXform, _BaseXform);
  16607. var _super = _createSuper(AlignmentXform);
  16608. function AlignmentXform() {
  16609. _classCallCheck(this, AlignmentXform);
  16610. return _super.apply(this, arguments);
  16611. }
  16612. _createClass(AlignmentXform, [{
  16613. key: "render",
  16614. value: function render(xmlStream, model) {
  16615. xmlStream.addRollback();
  16616. xmlStream.openNode('alignment');
  16617. var isValid = false;
  16618. function add(name, value) {
  16619. if (value) {
  16620. xmlStream.addAttribute(name, value);
  16621. isValid = true;
  16622. }
  16623. }
  16624. add('horizontal', validation.horizontal(model.horizontal));
  16625. add('vertical', validation.vertical(model.vertical));
  16626. add('wrapText', validation.wrapText(model.wrapText) ? '1' : false);
  16627. add('shrinkToFit', validation.shrinkToFit(model.shrinkToFit) ? '1' : false);
  16628. add('indent', validation.indent(model.indent));
  16629. add('textRotation', textRotationXform.toXml(model.textRotation));
  16630. add('readingOrder', validation.readingOrder(model.readingOrder));
  16631. xmlStream.closeNode();
  16632. if (isValid) {
  16633. xmlStream.commit();
  16634. } else {
  16635. xmlStream.rollback();
  16636. }
  16637. }
  16638. }, {
  16639. key: "parseOpen",
  16640. value: function parseOpen(node) {
  16641. var model = {};
  16642. var valid = false;
  16643. function add(truthy, name, value) {
  16644. if (truthy) {
  16645. model[name] = value;
  16646. valid = true;
  16647. }
  16648. }
  16649. add(node.attributes.horizontal, 'horizontal', node.attributes.horizontal);
  16650. add(node.attributes.vertical, 'vertical', node.attributes.vertical === 'center' ? 'middle' : node.attributes.vertical);
  16651. add(node.attributes.wrapText, 'wrapText', !!node.attributes.wrapText);
  16652. add(node.attributes.shrinkToFit, 'shrinkToFit', !!node.attributes.shrinkToFit);
  16653. add(node.attributes.indent, 'indent', parseInt(node.attributes.indent, 10));
  16654. add(node.attributes.textRotation, 'textRotation', textRotationXform.toModel(node.attributes.textRotation));
  16655. add(node.attributes.readingOrder, 'readingOrder', node.attributes.readingOrder === '2' ? 'rtl' : 'ltr');
  16656. this.model = valid ? model : null;
  16657. }
  16658. }, {
  16659. key: "parseText",
  16660. value: function parseText() {}
  16661. }, {
  16662. key: "parseClose",
  16663. value: function parseClose() {
  16664. return false;
  16665. }
  16666. }, {
  16667. key: "tag",
  16668. get: function get() {
  16669. return 'alignment';
  16670. }
  16671. }]);
  16672. return AlignmentXform;
  16673. }(BaseXform);
  16674. module.exports = AlignmentXform;
  16675. },{"../../../doc/enums":7,"../../../utils/utils":26,"../base-xform":31}],126:[function(require,module,exports){
  16676. "use strict";
  16677. 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; }
  16678. 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; }
  16679. 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; }
  16680. 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); }
  16681. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16682. 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); } }
  16683. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  16684. 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); }
  16685. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  16686. 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); }; }
  16687. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  16688. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  16689. 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; } }
  16690. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  16691. /* eslint-disable max-classes-per-file */
  16692. var BaseXform = require('../base-xform');
  16693. var ColorXform = require('./color-xform');
  16694. var EdgeXform = /*#__PURE__*/function (_BaseXform) {
  16695. _inherits(EdgeXform, _BaseXform);
  16696. var _super = _createSuper(EdgeXform);
  16697. function EdgeXform(name) {
  16698. var _this;
  16699. _classCallCheck(this, EdgeXform);
  16700. _this = _super.call(this);
  16701. _this.name = name;
  16702. _this.map = {
  16703. color: new ColorXform()
  16704. };
  16705. return _this;
  16706. }
  16707. _createClass(EdgeXform, [{
  16708. key: "render",
  16709. value: function render(xmlStream, model, defaultColor) {
  16710. var color = model && model.color || defaultColor || this.defaultColor;
  16711. xmlStream.openNode(this.name);
  16712. if (model && model.style) {
  16713. xmlStream.addAttribute('style', model.style);
  16714. if (color) {
  16715. this.map.color.render(xmlStream, color);
  16716. }
  16717. }
  16718. xmlStream.closeNode();
  16719. }
  16720. }, {
  16721. key: "parseOpen",
  16722. value: function parseOpen(node) {
  16723. if (this.parser) {
  16724. this.parser.parseOpen(node);
  16725. return true;
  16726. }
  16727. switch (node.name) {
  16728. case this.name:
  16729. {
  16730. var style = node.attributes.style;
  16731. if (style) {
  16732. this.model = {
  16733. style: style
  16734. };
  16735. } else {
  16736. this.model = undefined;
  16737. }
  16738. return true;
  16739. }
  16740. case 'color':
  16741. this.parser = this.map.color;
  16742. this.parser.parseOpen(node);
  16743. return true;
  16744. default:
  16745. return false;
  16746. }
  16747. }
  16748. }, {
  16749. key: "parseText",
  16750. value: function parseText(text) {
  16751. if (this.parser) {
  16752. this.parser.parseText(text);
  16753. }
  16754. }
  16755. }, {
  16756. key: "parseClose",
  16757. value: function parseClose(name) {
  16758. if (this.parser) {
  16759. if (!this.parser.parseClose(name)) {
  16760. this.parser = undefined;
  16761. }
  16762. return true;
  16763. }
  16764. if (name === this.name) {
  16765. if (this.map.color.model) {
  16766. if (!this.model) {
  16767. this.model = {};
  16768. }
  16769. this.model.color = this.map.color.model;
  16770. }
  16771. }
  16772. return false;
  16773. }
  16774. }, {
  16775. key: "validStyle",
  16776. value: function validStyle(value) {
  16777. return EdgeXform.validStyleValues[value];
  16778. }
  16779. }, {
  16780. key: "tag",
  16781. get: function get() {
  16782. return this.name;
  16783. }
  16784. }]);
  16785. return EdgeXform;
  16786. }(BaseXform);
  16787. EdgeXform.validStyleValues = ['thin', 'dotted', 'dashDot', 'hair', 'dashDotDot', 'slantDashDot', 'mediumDashed', 'mediumDashDotDot', 'mediumDashDot', 'medium', 'double', 'thick'].reduce(function (p, v) {
  16788. p[v] = true;
  16789. return p;
  16790. }, {}); // Border encapsulates translation from border model to/from xlsx
  16791. var BorderXform = /*#__PURE__*/function (_BaseXform2) {
  16792. _inherits(BorderXform, _BaseXform2);
  16793. var _super2 = _createSuper(BorderXform);
  16794. function BorderXform() {
  16795. var _this2;
  16796. _classCallCheck(this, BorderXform);
  16797. _this2 = _super2.call(this);
  16798. _this2.map = {
  16799. top: new EdgeXform('top'),
  16800. left: new EdgeXform('left'),
  16801. bottom: new EdgeXform('bottom'),
  16802. right: new EdgeXform('right'),
  16803. diagonal: new EdgeXform('diagonal')
  16804. };
  16805. return _this2;
  16806. }
  16807. _createClass(BorderXform, [{
  16808. key: "render",
  16809. value: function render(xmlStream, model) {
  16810. var color = model.color;
  16811. xmlStream.openNode('border');
  16812. if (model.diagonal && model.diagonal.style) {
  16813. if (model.diagonal.up) {
  16814. xmlStream.addAttribute('diagonalUp', '1');
  16815. }
  16816. if (model.diagonal.down) {
  16817. xmlStream.addAttribute('diagonalDown', '1');
  16818. }
  16819. }
  16820. function add(edgeModel, edgeXform) {
  16821. if (edgeModel && !edgeModel.color && model.color) {
  16822. // don't mess with incoming models
  16823. edgeModel = _objectSpread(_objectSpread({}, edgeModel), {}, {
  16824. color: model.color
  16825. });
  16826. }
  16827. edgeXform.render(xmlStream, edgeModel, color);
  16828. }
  16829. add(model.left, this.map.left);
  16830. add(model.right, this.map.right);
  16831. add(model.top, this.map.top);
  16832. add(model.bottom, this.map.bottom);
  16833. add(model.diagonal, this.map.diagonal);
  16834. xmlStream.closeNode();
  16835. }
  16836. }, {
  16837. key: "parseOpen",
  16838. value: function parseOpen(node) {
  16839. if (this.parser) {
  16840. this.parser.parseOpen(node);
  16841. return true;
  16842. }
  16843. switch (node.name) {
  16844. case 'border':
  16845. this.reset();
  16846. this.diagonalUp = !!node.attributes.diagonalUp;
  16847. this.diagonalDown = !!node.attributes.diagonalDown;
  16848. return true;
  16849. default:
  16850. this.parser = this.map[node.name];
  16851. if (this.parser) {
  16852. this.parser.parseOpen(node);
  16853. return true;
  16854. }
  16855. return false;
  16856. }
  16857. }
  16858. }, {
  16859. key: "parseText",
  16860. value: function parseText(text) {
  16861. if (this.parser) {
  16862. this.parser.parseText(text);
  16863. }
  16864. }
  16865. }, {
  16866. key: "parseClose",
  16867. value: function parseClose(name) {
  16868. if (this.parser) {
  16869. if (!this.parser.parseClose(name)) {
  16870. this.parser = undefined;
  16871. }
  16872. return true;
  16873. }
  16874. if (name === 'border') {
  16875. var model = this.model = {};
  16876. var add = function add(key, edgeModel, extensions) {
  16877. if (edgeModel) {
  16878. if (extensions) {
  16879. Object.assign(edgeModel, extensions);
  16880. }
  16881. model[key] = edgeModel;
  16882. }
  16883. };
  16884. add('left', this.map.left.model);
  16885. add('right', this.map.right.model);
  16886. add('top', this.map.top.model);
  16887. add('bottom', this.map.bottom.model);
  16888. add('diagonal', this.map.diagonal.model, {
  16889. up: this.diagonalUp,
  16890. down: this.diagonalDown
  16891. });
  16892. }
  16893. return false;
  16894. }
  16895. }]);
  16896. return BorderXform;
  16897. }(BaseXform);
  16898. module.exports = BorderXform;
  16899. },{"../base-xform":31,"./color-xform":127}],127:[function(require,module,exports){
  16900. "use strict";
  16901. 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); }
  16902. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16903. 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); } }
  16904. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  16905. 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); }
  16906. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  16907. 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); }; }
  16908. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  16909. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  16910. 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; } }
  16911. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  16912. var BaseXform = require('../base-xform'); // Color encapsulates translation from color model to/from xlsx
  16913. var ColorXform = /*#__PURE__*/function (_BaseXform) {
  16914. _inherits(ColorXform, _BaseXform);
  16915. var _super = _createSuper(ColorXform);
  16916. function ColorXform(name) {
  16917. var _this;
  16918. _classCallCheck(this, ColorXform);
  16919. _this = _super.call(this); // this.name controls the xm node name
  16920. _this.name = name || 'color';
  16921. return _this;
  16922. }
  16923. _createClass(ColorXform, [{
  16924. key: "render",
  16925. value: function render(xmlStream, model) {
  16926. if (model) {
  16927. xmlStream.openNode(this.name);
  16928. if (model.argb) {
  16929. xmlStream.addAttribute('rgb', model.argb);
  16930. } else if (model.theme !== undefined) {
  16931. xmlStream.addAttribute('theme', model.theme);
  16932. if (model.tint !== undefined) {
  16933. xmlStream.addAttribute('tint', model.tint);
  16934. }
  16935. } else if (model.indexed !== undefined) {
  16936. xmlStream.addAttribute('indexed', model.indexed);
  16937. } else {
  16938. xmlStream.addAttribute('auto', '1');
  16939. }
  16940. xmlStream.closeNode();
  16941. return true;
  16942. }
  16943. return false;
  16944. }
  16945. }, {
  16946. key: "parseOpen",
  16947. value: function parseOpen(node) {
  16948. if (node.name === this.name) {
  16949. if (node.attributes.rgb) {
  16950. this.model = {
  16951. argb: node.attributes.rgb
  16952. };
  16953. } else if (node.attributes.theme) {
  16954. this.model = {
  16955. theme: parseInt(node.attributes.theme, 10)
  16956. };
  16957. if (node.attributes.tint) {
  16958. this.model.tint = parseFloat(node.attributes.tint);
  16959. }
  16960. } else if (node.attributes.indexed) {
  16961. this.model = {
  16962. indexed: parseInt(node.attributes.indexed, 10)
  16963. };
  16964. } else {
  16965. this.model = undefined;
  16966. }
  16967. return true;
  16968. }
  16969. return false;
  16970. }
  16971. }, {
  16972. key: "parseText",
  16973. value: function parseText() {}
  16974. }, {
  16975. key: "parseClose",
  16976. value: function parseClose() {
  16977. return false;
  16978. }
  16979. }, {
  16980. key: "tag",
  16981. get: function get() {
  16982. return this.name;
  16983. }
  16984. }]);
  16985. return ColorXform;
  16986. }(BaseXform);
  16987. module.exports = ColorXform;
  16988. },{"../base-xform":31}],128:[function(require,module,exports){
  16989. "use strict";
  16990. 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); }
  16991. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16992. 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); } }
  16993. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  16994. 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); }
  16995. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  16996. 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); }; }
  16997. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  16998. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  16999. 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; } }
  17000. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  17001. var BaseXform = require('../base-xform');
  17002. var AlignmentXform = require('./alignment-xform');
  17003. var BorderXform = require('./border-xform');
  17004. var FillXform = require('./fill-xform');
  17005. var FontXform = require('./font-xform');
  17006. var NumFmtXform = require('./numfmt-xform');
  17007. var ProtectionXform = require('./protection-xform'); // <xf numFmtId="[numFmtId]" fontId="[fontId]" fillId="[fillId]" borderId="[xf.borderId]" xfId="[xfId]">
  17008. // Optional <alignment>
  17009. // Optional <protection>
  17010. // </xf>
  17011. // Style assists translation from style model to/from xlsx
  17012. var DxfXform = /*#__PURE__*/function (_BaseXform) {
  17013. _inherits(DxfXform, _BaseXform);
  17014. var _super = _createSuper(DxfXform);
  17015. function DxfXform() {
  17016. var _this;
  17017. _classCallCheck(this, DxfXform);
  17018. _this = _super.call(this);
  17019. _this.map = {
  17020. alignment: new AlignmentXform(),
  17021. border: new BorderXform(),
  17022. fill: new FillXform(),
  17023. font: new FontXform(),
  17024. numFmt: new NumFmtXform(),
  17025. protection: new ProtectionXform()
  17026. };
  17027. return _this;
  17028. }
  17029. _createClass(DxfXform, [{
  17030. key: "render",
  17031. // how do we generate dxfid?
  17032. value: function render(xmlStream, model) {
  17033. xmlStream.openNode(this.tag);
  17034. if (model.font) {
  17035. this.map.font.render(xmlStream, model.font);
  17036. }
  17037. if (model.numFmt) {
  17038. this.map.numFmt.render(xmlStream, model.numFmt);
  17039. }
  17040. if (model.fill) {
  17041. this.map.fill.render(xmlStream, model.fill);
  17042. }
  17043. if (model.alignment) {
  17044. this.map.alignment.render(xmlStream, model.alignment);
  17045. }
  17046. if (model.border) {
  17047. this.map.border.render(xmlStream, model.border);
  17048. }
  17049. if (model.protection) {
  17050. this.map.protection.render(xmlStream, model.protection);
  17051. }
  17052. xmlStream.closeNode();
  17053. }
  17054. }, {
  17055. key: "parseOpen",
  17056. value: function parseOpen(node) {
  17057. if (this.parser) {
  17058. this.parser.parseOpen(node);
  17059. return true;
  17060. }
  17061. switch (node.name) {
  17062. case this.tag:
  17063. // this node is often repeated. Need to reset children
  17064. this.reset();
  17065. return true;
  17066. default:
  17067. this.parser = this.map[node.name];
  17068. if (this.parser) {
  17069. this.parser.parseOpen(node);
  17070. }
  17071. return true;
  17072. }
  17073. }
  17074. }, {
  17075. key: "parseText",
  17076. value: function parseText(text) {
  17077. if (this.parser) {
  17078. this.parser.parseText(text);
  17079. }
  17080. }
  17081. }, {
  17082. key: "parseClose",
  17083. value: function parseClose(name) {
  17084. if (this.parser) {
  17085. if (!this.parser.parseClose(name)) {
  17086. this.parser = undefined;
  17087. }
  17088. return true;
  17089. }
  17090. if (name === this.tag) {
  17091. this.model = {
  17092. alignment: this.map.alignment.model,
  17093. border: this.map.border.model,
  17094. fill: this.map.fill.model,
  17095. font: this.map.font.model,
  17096. numFmt: this.map.numFmt.model,
  17097. protection: this.map.protection.model
  17098. };
  17099. return false;
  17100. }
  17101. return true;
  17102. }
  17103. }, {
  17104. key: "tag",
  17105. get: function get() {
  17106. return 'dxf';
  17107. }
  17108. }]);
  17109. return DxfXform;
  17110. }(BaseXform);
  17111. module.exports = DxfXform;
  17112. },{"../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){
  17113. "use strict";
  17114. 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); }
  17115. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17116. 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); } }
  17117. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  17118. 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); }
  17119. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  17120. 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); }; }
  17121. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  17122. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  17123. 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; } }
  17124. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  17125. /* eslint-disable max-classes-per-file */
  17126. var BaseXform = require('../base-xform');
  17127. var ColorXform = require('./color-xform');
  17128. var StopXform = /*#__PURE__*/function (_BaseXform) {
  17129. _inherits(StopXform, _BaseXform);
  17130. var _super = _createSuper(StopXform);
  17131. function StopXform() {
  17132. var _this;
  17133. _classCallCheck(this, StopXform);
  17134. _this = _super.call(this);
  17135. _this.map = {
  17136. color: new ColorXform()
  17137. };
  17138. return _this;
  17139. }
  17140. _createClass(StopXform, [{
  17141. key: "render",
  17142. value: function render(xmlStream, model) {
  17143. xmlStream.openNode('stop');
  17144. xmlStream.addAttribute('position', model.position);
  17145. this.map.color.render(xmlStream, model.color);
  17146. xmlStream.closeNode();
  17147. }
  17148. }, {
  17149. key: "parseOpen",
  17150. value: function parseOpen(node) {
  17151. if (this.parser) {
  17152. this.parser.parseOpen(node);
  17153. return true;
  17154. }
  17155. switch (node.name) {
  17156. case 'stop':
  17157. this.model = {
  17158. position: parseFloat(node.attributes.position)
  17159. };
  17160. return true;
  17161. case 'color':
  17162. this.parser = this.map.color;
  17163. this.parser.parseOpen(node);
  17164. return true;
  17165. default:
  17166. return false;
  17167. }
  17168. }
  17169. }, {
  17170. key: "parseText",
  17171. value: function parseText() {}
  17172. }, {
  17173. key: "parseClose",
  17174. value: function parseClose(name) {
  17175. if (this.parser) {
  17176. if (!this.parser.parseClose(name)) {
  17177. this.model.color = this.parser.model;
  17178. this.parser = undefined;
  17179. }
  17180. return true;
  17181. }
  17182. return false;
  17183. }
  17184. }, {
  17185. key: "tag",
  17186. get: function get() {
  17187. return 'stop';
  17188. }
  17189. }]);
  17190. return StopXform;
  17191. }(BaseXform);
  17192. var PatternFillXform = /*#__PURE__*/function (_BaseXform2) {
  17193. _inherits(PatternFillXform, _BaseXform2);
  17194. var _super2 = _createSuper(PatternFillXform);
  17195. function PatternFillXform() {
  17196. var _this2;
  17197. _classCallCheck(this, PatternFillXform);
  17198. _this2 = _super2.call(this);
  17199. _this2.map = {
  17200. fgColor: new ColorXform('fgColor'),
  17201. bgColor: new ColorXform('bgColor')
  17202. };
  17203. return _this2;
  17204. }
  17205. _createClass(PatternFillXform, [{
  17206. key: "render",
  17207. value: function render(xmlStream, model) {
  17208. xmlStream.openNode('patternFill');
  17209. xmlStream.addAttribute('patternType', model.pattern);
  17210. if (model.fgColor) {
  17211. this.map.fgColor.render(xmlStream, model.fgColor);
  17212. }
  17213. if (model.bgColor) {
  17214. this.map.bgColor.render(xmlStream, model.bgColor);
  17215. }
  17216. xmlStream.closeNode();
  17217. }
  17218. }, {
  17219. key: "parseOpen",
  17220. value: function parseOpen(node) {
  17221. if (this.parser) {
  17222. this.parser.parseOpen(node);
  17223. return true;
  17224. }
  17225. switch (node.name) {
  17226. case 'patternFill':
  17227. this.model = {
  17228. type: 'pattern',
  17229. pattern: node.attributes.patternType
  17230. };
  17231. return true;
  17232. default:
  17233. this.parser = this.map[node.name];
  17234. if (this.parser) {
  17235. this.parser.parseOpen(node);
  17236. return true;
  17237. }
  17238. return false;
  17239. }
  17240. }
  17241. }, {
  17242. key: "parseText",
  17243. value: function parseText(text) {
  17244. if (this.parser) {
  17245. this.parser.parseText(text);
  17246. }
  17247. }
  17248. }, {
  17249. key: "parseClose",
  17250. value: function parseClose(name) {
  17251. if (this.parser) {
  17252. if (!this.parser.parseClose(name)) {
  17253. if (this.parser.model) {
  17254. this.model[name] = this.parser.model;
  17255. }
  17256. this.parser = undefined;
  17257. }
  17258. return true;
  17259. }
  17260. return false;
  17261. }
  17262. }, {
  17263. key: "name",
  17264. get: function get() {
  17265. return 'pattern';
  17266. }
  17267. }, {
  17268. key: "tag",
  17269. get: function get() {
  17270. return 'patternFill';
  17271. }
  17272. }]);
  17273. return PatternFillXform;
  17274. }(BaseXform);
  17275. var GradientFillXform = /*#__PURE__*/function (_BaseXform3) {
  17276. _inherits(GradientFillXform, _BaseXform3);
  17277. var _super3 = _createSuper(GradientFillXform);
  17278. function GradientFillXform() {
  17279. var _this3;
  17280. _classCallCheck(this, GradientFillXform);
  17281. _this3 = _super3.call(this);
  17282. _this3.map = {
  17283. stop: new StopXform()
  17284. }; // if (model) {
  17285. // this.gradient = model.gradient;
  17286. // if (model.center) {
  17287. // this.center = model.center;
  17288. // }
  17289. // if (model.degree !== undefined) {
  17290. // this.degree = model.degree;
  17291. // }
  17292. // this.stops = model.stops.map(function(stop) { return new StopXform(stop); });
  17293. // } else {
  17294. // this.stops = [];
  17295. // }
  17296. return _this3;
  17297. }
  17298. _createClass(GradientFillXform, [{
  17299. key: "render",
  17300. value: function render(xmlStream, model) {
  17301. xmlStream.openNode('gradientFill');
  17302. switch (model.gradient) {
  17303. case 'angle':
  17304. xmlStream.addAttribute('degree', model.degree);
  17305. break;
  17306. case 'path':
  17307. xmlStream.addAttribute('type', 'path');
  17308. if (model.center.left) {
  17309. xmlStream.addAttribute('left', model.center.left);
  17310. if (model.center.right === undefined) {
  17311. xmlStream.addAttribute('right', model.center.left);
  17312. }
  17313. }
  17314. if (model.center.right) {
  17315. xmlStream.addAttribute('right', model.center.right);
  17316. }
  17317. if (model.center.top) {
  17318. xmlStream.addAttribute('top', model.center.top);
  17319. if (model.center.bottom === undefined) {
  17320. xmlStream.addAttribute('bottom', model.center.top);
  17321. }
  17322. }
  17323. if (model.center.bottom) {
  17324. xmlStream.addAttribute('bottom', model.center.bottom);
  17325. }
  17326. break;
  17327. default:
  17328. break;
  17329. }
  17330. var stopXform = this.map.stop;
  17331. model.stops.forEach(function (stopModel) {
  17332. stopXform.render(xmlStream, stopModel);
  17333. });
  17334. xmlStream.closeNode();
  17335. }
  17336. }, {
  17337. key: "parseOpen",
  17338. value: function parseOpen(node) {
  17339. if (this.parser) {
  17340. this.parser.parseOpen(node);
  17341. return true;
  17342. }
  17343. switch (node.name) {
  17344. case 'gradientFill':
  17345. {
  17346. var model = this.model = {
  17347. stops: []
  17348. };
  17349. if (node.attributes.degree) {
  17350. model.gradient = 'angle';
  17351. model.degree = parseInt(node.attributes.degree, 10);
  17352. } else if (node.attributes.type === 'path') {
  17353. model.gradient = 'path';
  17354. model.center = {
  17355. left: node.attributes.left ? parseFloat(node.attributes.left) : 0,
  17356. top: node.attributes.top ? parseFloat(node.attributes.top) : 0
  17357. };
  17358. if (node.attributes.right !== node.attributes.left) {
  17359. model.center.right = node.attributes.right ? parseFloat(node.attributes.right) : 0;
  17360. }
  17361. if (node.attributes.bottom !== node.attributes.top) {
  17362. model.center.bottom = node.attributes.bottom ? parseFloat(node.attributes.bottom) : 0;
  17363. }
  17364. }
  17365. return true;
  17366. }
  17367. case 'stop':
  17368. this.parser = this.map.stop;
  17369. this.parser.parseOpen(node);
  17370. return true;
  17371. default:
  17372. return false;
  17373. }
  17374. }
  17375. }, {
  17376. key: "parseText",
  17377. value: function parseText(text) {
  17378. if (this.parser) {
  17379. this.parser.parseText(text);
  17380. }
  17381. }
  17382. }, {
  17383. key: "parseClose",
  17384. value: function parseClose(name) {
  17385. if (this.parser) {
  17386. if (!this.parser.parseClose(name)) {
  17387. this.model.stops.push(this.parser.model);
  17388. this.parser = undefined;
  17389. }
  17390. return true;
  17391. }
  17392. return false;
  17393. }
  17394. }, {
  17395. key: "name",
  17396. get: function get() {
  17397. return 'gradient';
  17398. }
  17399. }, {
  17400. key: "tag",
  17401. get: function get() {
  17402. return 'gradientFill';
  17403. }
  17404. }]);
  17405. return GradientFillXform;
  17406. }(BaseXform); // Fill encapsulates translation from fill model to/from xlsx
  17407. var FillXform = /*#__PURE__*/function (_BaseXform4) {
  17408. _inherits(FillXform, _BaseXform4);
  17409. var _super4 = _createSuper(FillXform);
  17410. function FillXform() {
  17411. var _this4;
  17412. _classCallCheck(this, FillXform);
  17413. _this4 = _super4.call(this);
  17414. _this4.map = {
  17415. patternFill: new PatternFillXform(),
  17416. gradientFill: new GradientFillXform()
  17417. };
  17418. return _this4;
  17419. }
  17420. _createClass(FillXform, [{
  17421. key: "render",
  17422. value: function render(xmlStream, model) {
  17423. xmlStream.addRollback();
  17424. xmlStream.openNode('fill');
  17425. switch (model.type) {
  17426. case 'pattern':
  17427. this.map.patternFill.render(xmlStream, model);
  17428. break;
  17429. case 'gradient':
  17430. this.map.gradientFill.render(xmlStream, model);
  17431. break;
  17432. default:
  17433. xmlStream.rollback();
  17434. return;
  17435. }
  17436. xmlStream.closeNode();
  17437. xmlStream.commit();
  17438. }
  17439. }, {
  17440. key: "parseOpen",
  17441. value: function parseOpen(node) {
  17442. if (this.parser) {
  17443. this.parser.parseOpen(node);
  17444. return true;
  17445. }
  17446. switch (node.name) {
  17447. case 'fill':
  17448. this.model = {};
  17449. return true;
  17450. default:
  17451. this.parser = this.map[node.name];
  17452. if (this.parser) {
  17453. this.parser.parseOpen(node);
  17454. return true;
  17455. }
  17456. return false;
  17457. }
  17458. }
  17459. }, {
  17460. key: "parseText",
  17461. value: function parseText(text) {
  17462. if (this.parser) {
  17463. this.parser.parseText(text);
  17464. }
  17465. }
  17466. }, {
  17467. key: "parseClose",
  17468. value: function parseClose(name) {
  17469. if (this.parser) {
  17470. if (!this.parser.parseClose(name)) {
  17471. this.model = this.parser.model;
  17472. this.model.type = this.parser.name;
  17473. this.parser = undefined;
  17474. }
  17475. return true;
  17476. }
  17477. return false;
  17478. }
  17479. }, {
  17480. key: "validStyle",
  17481. value: function validStyle(value) {
  17482. return FillXform.validPatternValues[value];
  17483. }
  17484. }, {
  17485. key: "tag",
  17486. get: function get() {
  17487. return 'fill';
  17488. }
  17489. }]);
  17490. return FillXform;
  17491. }(BaseXform);
  17492. 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) {
  17493. p[v] = true;
  17494. return p;
  17495. }, {});
  17496. FillXform.StopXform = StopXform;
  17497. FillXform.PatternFillXform = PatternFillXform;
  17498. FillXform.GradientFillXform = GradientFillXform;
  17499. module.exports = FillXform;
  17500. },{"../base-xform":31,"./color-xform":127}],130:[function(require,module,exports){
  17501. 'use strict';
  17502. 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); }
  17503. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17504. 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); } }
  17505. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  17506. 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); }
  17507. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  17508. 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); }; }
  17509. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  17510. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  17511. 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; } }
  17512. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  17513. var ColorXform = require('./color-xform');
  17514. var BooleanXform = require('../simple/boolean-xform');
  17515. var IntegerXform = require('../simple/integer-xform');
  17516. var StringXform = require('../simple/string-xform');
  17517. var UnderlineXform = require('./underline-xform');
  17518. var _ = require('../../../utils/under-dash');
  17519. var BaseXform = require('../base-xform'); // Font encapsulates translation from font model to xlsx
  17520. var FontXform = /*#__PURE__*/function (_BaseXform) {
  17521. _inherits(FontXform, _BaseXform);
  17522. var _super = _createSuper(FontXform);
  17523. function FontXform(options) {
  17524. var _this;
  17525. _classCallCheck(this, FontXform);
  17526. _this = _super.call(this);
  17527. _this.options = options || FontXform.OPTIONS;
  17528. _this.map = {
  17529. b: {
  17530. prop: 'bold',
  17531. xform: new BooleanXform({
  17532. tag: 'b',
  17533. attr: 'val'
  17534. })
  17535. },
  17536. i: {
  17537. prop: 'italic',
  17538. xform: new BooleanXform({
  17539. tag: 'i',
  17540. attr: 'val'
  17541. })
  17542. },
  17543. u: {
  17544. prop: 'underline',
  17545. xform: new UnderlineXform()
  17546. },
  17547. charset: {
  17548. prop: 'charset',
  17549. xform: new IntegerXform({
  17550. tag: 'charset',
  17551. attr: 'val'
  17552. })
  17553. },
  17554. color: {
  17555. prop: 'color',
  17556. xform: new ColorXform()
  17557. },
  17558. condense: {
  17559. prop: 'condense',
  17560. xform: new BooleanXform({
  17561. tag: 'condense',
  17562. attr: 'val'
  17563. })
  17564. },
  17565. extend: {
  17566. prop: 'extend',
  17567. xform: new BooleanXform({
  17568. tag: 'extend',
  17569. attr: 'val'
  17570. })
  17571. },
  17572. family: {
  17573. prop: 'family',
  17574. xform: new IntegerXform({
  17575. tag: 'family',
  17576. attr: 'val'
  17577. })
  17578. },
  17579. outline: {
  17580. prop: 'outline',
  17581. xform: new BooleanXform({
  17582. tag: 'outline',
  17583. attr: 'val'
  17584. })
  17585. },
  17586. vertAlign: {
  17587. prop: 'vertAlign',
  17588. xform: new StringXform({
  17589. tag: 'vertAlign',
  17590. attr: 'val'
  17591. })
  17592. },
  17593. scheme: {
  17594. prop: 'scheme',
  17595. xform: new StringXform({
  17596. tag: 'scheme',
  17597. attr: 'val'
  17598. })
  17599. },
  17600. shadow: {
  17601. prop: 'shadow',
  17602. xform: new BooleanXform({
  17603. tag: 'shadow',
  17604. attr: 'val'
  17605. })
  17606. },
  17607. strike: {
  17608. prop: 'strike',
  17609. xform: new BooleanXform({
  17610. tag: 'strike',
  17611. attr: 'val'
  17612. })
  17613. },
  17614. sz: {
  17615. prop: 'size',
  17616. xform: new IntegerXform({
  17617. tag: 'sz',
  17618. attr: 'val'
  17619. })
  17620. }
  17621. };
  17622. _this.map[_this.options.fontNameTag] = {
  17623. prop: 'name',
  17624. xform: new StringXform({
  17625. tag: _this.options.fontNameTag,
  17626. attr: 'val'
  17627. })
  17628. };
  17629. return _this;
  17630. }
  17631. _createClass(FontXform, [{
  17632. key: "render",
  17633. value: function render(xmlStream, model) {
  17634. var map = this.map;
  17635. xmlStream.openNode(this.options.tagName);
  17636. _.each(this.map, function (defn, tag) {
  17637. map[tag].xform.render(xmlStream, model[defn.prop]);
  17638. });
  17639. xmlStream.closeNode();
  17640. }
  17641. }, {
  17642. key: "parseOpen",
  17643. value: function parseOpen(node) {
  17644. if (this.parser) {
  17645. this.parser.parseOpen(node);
  17646. return true;
  17647. }
  17648. if (this.map[node.name]) {
  17649. this.parser = this.map[node.name].xform;
  17650. return this.parser.parseOpen(node);
  17651. }
  17652. switch (node.name) {
  17653. case this.options.tagName:
  17654. this.model = {};
  17655. return true;
  17656. default:
  17657. return false;
  17658. }
  17659. }
  17660. }, {
  17661. key: "parseText",
  17662. value: function parseText(text) {
  17663. if (this.parser) {
  17664. this.parser.parseText(text);
  17665. }
  17666. }
  17667. }, {
  17668. key: "parseClose",
  17669. value: function parseClose(name) {
  17670. if (this.parser && !this.parser.parseClose(name)) {
  17671. var item = this.map[name];
  17672. if (this.parser.model) {
  17673. this.model[item.prop] = this.parser.model;
  17674. }
  17675. this.parser = undefined;
  17676. return true;
  17677. }
  17678. switch (name) {
  17679. case this.options.tagName:
  17680. return false;
  17681. default:
  17682. return true;
  17683. }
  17684. }
  17685. }, {
  17686. key: "tag",
  17687. get: function get() {
  17688. return this.options.tagName;
  17689. }
  17690. }]);
  17691. return FontXform;
  17692. }(BaseXform);
  17693. FontXform.OPTIONS = {
  17694. tagName: 'font',
  17695. fontNameTag: 'name'
  17696. };
  17697. module.exports = FontXform;
  17698. },{"../../../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){
  17699. "use strict";
  17700. 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); }
  17701. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17702. 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); } }
  17703. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  17704. 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); }
  17705. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  17706. 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); }; }
  17707. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  17708. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  17709. 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; } }
  17710. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  17711. var _ = require('../../../utils/under-dash');
  17712. var defaultNumFormats = require('../../defaultnumformats');
  17713. var BaseXform = require('../base-xform');
  17714. function hashDefaultFormats() {
  17715. var hash = {};
  17716. _.each(defaultNumFormats, function (dnf, id) {
  17717. if (dnf.f) {
  17718. hash[dnf.f] = parseInt(id, 10);
  17719. } // at some point, add the other cultures here...
  17720. });
  17721. return hash;
  17722. }
  17723. var defaultFmtHash = hashDefaultFormats(); // NumFmt encapsulates translation between number format and xlsx
  17724. var NumFmtXform = /*#__PURE__*/function (_BaseXform) {
  17725. _inherits(NumFmtXform, _BaseXform);
  17726. var _super = _createSuper(NumFmtXform);
  17727. function NumFmtXform(id, formatCode) {
  17728. var _this;
  17729. _classCallCheck(this, NumFmtXform);
  17730. _this = _super.call(this);
  17731. _this.id = id;
  17732. _this.formatCode = formatCode;
  17733. return _this;
  17734. }
  17735. _createClass(NumFmtXform, [{
  17736. key: "render",
  17737. value: function render(xmlStream, model) {
  17738. xmlStream.leafNode('numFmt', {
  17739. numFmtId: model.id,
  17740. formatCode: model.formatCode
  17741. });
  17742. }
  17743. }, {
  17744. key: "parseOpen",
  17745. value: function parseOpen(node) {
  17746. switch (node.name) {
  17747. case 'numFmt':
  17748. this.model = {
  17749. id: parseInt(node.attributes.numFmtId, 10),
  17750. formatCode: node.attributes.formatCode.replace(/[\\](.)/g, '$1')
  17751. };
  17752. return true;
  17753. default:
  17754. return false;
  17755. }
  17756. }
  17757. }, {
  17758. key: "parseText",
  17759. value: function parseText() {}
  17760. }, {
  17761. key: "parseClose",
  17762. value: function parseClose() {
  17763. return false;
  17764. }
  17765. }, {
  17766. key: "tag",
  17767. get: function get() {
  17768. return 'numFmt';
  17769. }
  17770. }]);
  17771. return NumFmtXform;
  17772. }(BaseXform);
  17773. NumFmtXform.getDefaultFmtId = function getDefaultFmtId(formatCode) {
  17774. return defaultFmtHash[formatCode];
  17775. };
  17776. NumFmtXform.getDefaultFmtCode = function getDefaultFmtCode(numFmtId) {
  17777. return defaultNumFormats[numFmtId] && defaultNumFormats[numFmtId].f;
  17778. };
  17779. module.exports = NumFmtXform;
  17780. },{"../../../utils/under-dash":25,"../../defaultnumformats":29,"../base-xform":31}],132:[function(require,module,exports){
  17781. "use strict";
  17782. 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); }
  17783. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17784. 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); } }
  17785. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  17786. 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); }
  17787. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  17788. 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); }; }
  17789. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  17790. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  17791. 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; } }
  17792. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  17793. var BaseXform = require('../base-xform');
  17794. var validation = {
  17795. boolean: function boolean(value, dflt) {
  17796. if (value === undefined) {
  17797. return dflt;
  17798. }
  17799. return value;
  17800. }
  17801. }; // Protection encapsulates translation from style.protection model to/from xlsx
  17802. var ProtectionXform = /*#__PURE__*/function (_BaseXform) {
  17803. _inherits(ProtectionXform, _BaseXform);
  17804. var _super = _createSuper(ProtectionXform);
  17805. function ProtectionXform() {
  17806. _classCallCheck(this, ProtectionXform);
  17807. return _super.apply(this, arguments);
  17808. }
  17809. _createClass(ProtectionXform, [{
  17810. key: "render",
  17811. value: function render(xmlStream, model) {
  17812. xmlStream.addRollback();
  17813. xmlStream.openNode('protection');
  17814. var isValid = false;
  17815. function add(name, value) {
  17816. if (value !== undefined) {
  17817. xmlStream.addAttribute(name, value);
  17818. isValid = true;
  17819. }
  17820. }
  17821. add('locked', validation.boolean(model.locked, true) ? undefined : '0');
  17822. add('hidden', validation.boolean(model.hidden, false) ? '1' : undefined);
  17823. xmlStream.closeNode();
  17824. if (isValid) {
  17825. xmlStream.commit();
  17826. } else {
  17827. xmlStream.rollback();
  17828. }
  17829. }
  17830. }, {
  17831. key: "parseOpen",
  17832. value: function parseOpen(node) {
  17833. var model = {
  17834. locked: !(node.attributes.locked === '0'),
  17835. hidden: node.attributes.hidden === '1'
  17836. }; // only want to record models that differ from defaults
  17837. var isSignificant = !model.locked || model.hidden;
  17838. this.model = isSignificant ? model : null;
  17839. }
  17840. }, {
  17841. key: "parseText",
  17842. value: function parseText() {}
  17843. }, {
  17844. key: "parseClose",
  17845. value: function parseClose() {
  17846. return false;
  17847. }
  17848. }, {
  17849. key: "tag",
  17850. get: function get() {
  17851. return 'protection';
  17852. }
  17853. }]);
  17854. return ProtectionXform;
  17855. }(BaseXform);
  17856. module.exports = ProtectionXform;
  17857. },{"../base-xform":31}],133:[function(require,module,exports){
  17858. "use strict";
  17859. 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); }
  17860. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17861. 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); } }
  17862. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  17863. 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); }
  17864. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  17865. 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); }; }
  17866. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  17867. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  17868. 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; } }
  17869. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  17870. var BaseXform = require('../base-xform');
  17871. var AlignmentXform = require('./alignment-xform');
  17872. var ProtectionXform = require('./protection-xform'); // <xf numFmtId="[numFmtId]" fontId="[fontId]" fillId="[fillId]" borderId="[xf.borderId]" xfId="[xfId]">
  17873. // Optional <alignment>
  17874. // Optional <protection>
  17875. // </xf>
  17876. // Style assists translation from style model to/from xlsx
  17877. var StyleXform = /*#__PURE__*/function (_BaseXform) {
  17878. _inherits(StyleXform, _BaseXform);
  17879. var _super = _createSuper(StyleXform);
  17880. function StyleXform(options) {
  17881. var _this;
  17882. _classCallCheck(this, StyleXform);
  17883. _this = _super.call(this);
  17884. _this.xfId = !!(options && options.xfId);
  17885. _this.map = {
  17886. alignment: new AlignmentXform(),
  17887. protection: new ProtectionXform()
  17888. };
  17889. return _this;
  17890. }
  17891. _createClass(StyleXform, [{
  17892. key: "render",
  17893. value: function render(xmlStream, model) {
  17894. xmlStream.openNode('xf', {
  17895. numFmtId: model.numFmtId || 0,
  17896. fontId: model.fontId || 0,
  17897. fillId: model.fillId || 0,
  17898. borderId: model.borderId || 0
  17899. });
  17900. if (this.xfId) {
  17901. xmlStream.addAttribute('xfId', model.xfId || 0);
  17902. }
  17903. if (model.numFmtId) {
  17904. xmlStream.addAttribute('applyNumberFormat', '1');
  17905. }
  17906. if (model.fontId) {
  17907. xmlStream.addAttribute('applyFont', '1');
  17908. }
  17909. if (model.fillId) {
  17910. xmlStream.addAttribute('applyFill', '1');
  17911. }
  17912. if (model.borderId) {
  17913. xmlStream.addAttribute('applyBorder', '1');
  17914. }
  17915. if (model.alignment) {
  17916. xmlStream.addAttribute('applyAlignment', '1');
  17917. }
  17918. if (model.protection) {
  17919. xmlStream.addAttribute('applyProtection', '1');
  17920. }
  17921. /**
  17922. * Rendering tags causes close of XML stream.
  17923. * Therefore adding attributes must be done before rendering tags.
  17924. */
  17925. if (model.alignment) {
  17926. this.map.alignment.render(xmlStream, model.alignment);
  17927. }
  17928. if (model.protection) {
  17929. this.map.protection.render(xmlStream, model.protection);
  17930. }
  17931. xmlStream.closeNode();
  17932. }
  17933. }, {
  17934. key: "parseOpen",
  17935. value: function parseOpen(node) {
  17936. if (this.parser) {
  17937. this.parser.parseOpen(node);
  17938. return true;
  17939. } // used during sax parsing of xml to build font object
  17940. switch (node.name) {
  17941. case 'xf':
  17942. this.model = {
  17943. numFmtId: parseInt(node.attributes.numFmtId, 10),
  17944. fontId: parseInt(node.attributes.fontId, 10),
  17945. fillId: parseInt(node.attributes.fillId, 10),
  17946. borderId: parseInt(node.attributes.borderId, 10)
  17947. };
  17948. if (this.xfId) {
  17949. this.model.xfId = parseInt(node.attributes.xfId, 10);
  17950. }
  17951. return true;
  17952. case 'alignment':
  17953. this.parser = this.map.alignment;
  17954. this.parser.parseOpen(node);
  17955. return true;
  17956. case 'protection':
  17957. this.parser = this.map.protection;
  17958. this.parser.parseOpen(node);
  17959. return true;
  17960. default:
  17961. return false;
  17962. }
  17963. }
  17964. }, {
  17965. key: "parseText",
  17966. value: function parseText(text) {
  17967. if (this.parser) {
  17968. this.parser.parseText(text);
  17969. }
  17970. }
  17971. }, {
  17972. key: "parseClose",
  17973. value: function parseClose(name) {
  17974. if (this.parser) {
  17975. if (!this.parser.parseClose(name)) {
  17976. if (this.map.protection === this.parser) {
  17977. this.model.protection = this.parser.model;
  17978. } else {
  17979. this.model.alignment = this.parser.model;
  17980. }
  17981. this.parser = undefined;
  17982. }
  17983. return true;
  17984. }
  17985. return name !== 'xf';
  17986. }
  17987. }, {
  17988. key: "tag",
  17989. get: function get() {
  17990. return 'xf';
  17991. }
  17992. }]);
  17993. return StyleXform;
  17994. }(BaseXform);
  17995. module.exports = StyleXform;
  17996. },{"../base-xform":31,"./alignment-xform":125,"./protection-xform":132}],134:[function(require,module,exports){
  17997. "use strict";
  17998. 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); }
  17999. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  18000. 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); } }
  18001. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  18002. 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); }
  18003. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  18004. 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); }; }
  18005. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  18006. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  18007. 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; } }
  18008. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  18009. /* eslint-disable max-classes-per-file */
  18010. var Enums = require('../../../doc/enums');
  18011. var XmlStream = require('../../../utils/xml-stream');
  18012. var BaseXform = require('../base-xform');
  18013. var StaticXform = require('../static-xform');
  18014. var ListXform = require('../list-xform');
  18015. var FontXform = require('./font-xform');
  18016. var FillXform = require('./fill-xform');
  18017. var BorderXform = require('./border-xform');
  18018. var NumFmtXform = require('./numfmt-xform');
  18019. var StyleXform = require('./style-xform');
  18020. var DxfXform = require('./dxf-xform'); // custom numfmt ids start here
  18021. var NUMFMT_BASE = 164; // =============================================================================
  18022. // StylesXform is used to generate and parse the styles.xml file
  18023. // it manages the collections of fonts, number formats, alignments, etc
  18024. var StylesXform = /*#__PURE__*/function (_BaseXform) {
  18025. _inherits(StylesXform, _BaseXform);
  18026. var _super = _createSuper(StylesXform);
  18027. function StylesXform(initialise) {
  18028. var _this;
  18029. _classCallCheck(this, StylesXform);
  18030. _this = _super.call(this);
  18031. _this.map = {
  18032. numFmts: new ListXform({
  18033. tag: 'numFmts',
  18034. count: true,
  18035. childXform: new NumFmtXform()
  18036. }),
  18037. fonts: new ListXform({
  18038. tag: 'fonts',
  18039. count: true,
  18040. childXform: new FontXform(),
  18041. $: {
  18042. 'x14ac:knownFonts': 1
  18043. }
  18044. }),
  18045. fills: new ListXform({
  18046. tag: 'fills',
  18047. count: true,
  18048. childXform: new FillXform()
  18049. }),
  18050. borders: new ListXform({
  18051. tag: 'borders',
  18052. count: true,
  18053. childXform: new BorderXform()
  18054. }),
  18055. cellStyleXfs: new ListXform({
  18056. tag: 'cellStyleXfs',
  18057. count: true,
  18058. childXform: new StyleXform()
  18059. }),
  18060. cellXfs: new ListXform({
  18061. tag: 'cellXfs',
  18062. count: true,
  18063. childXform: new StyleXform({
  18064. xfId: true
  18065. })
  18066. }),
  18067. dxfs: new ListXform({
  18068. tag: 'dxfs',
  18069. always: true,
  18070. count: true,
  18071. childXform: new DxfXform()
  18072. }),
  18073. // for style manager
  18074. numFmt: new NumFmtXform(),
  18075. font: new FontXform(),
  18076. fill: new FillXform(),
  18077. border: new BorderXform(),
  18078. style: new StyleXform({
  18079. xfId: true
  18080. }),
  18081. cellStyles: StylesXform.STATIC_XFORMS.cellStyles,
  18082. tableStyles: StylesXform.STATIC_XFORMS.tableStyles,
  18083. extLst: StylesXform.STATIC_XFORMS.extLst
  18084. };
  18085. if (initialise) {
  18086. // StylesXform also acts as style manager and is used to build up styles-model during worksheet processing
  18087. _this.init();
  18088. }
  18089. return _this;
  18090. }
  18091. _createClass(StylesXform, [{
  18092. key: "initIndex",
  18093. value: function initIndex() {
  18094. this.index = {
  18095. style: {},
  18096. numFmt: {},
  18097. numFmtNextId: 164,
  18098. // start custom format ids here
  18099. font: {},
  18100. border: {},
  18101. fill: {}
  18102. };
  18103. }
  18104. }, {
  18105. key: "init",
  18106. value: function init() {
  18107. // Prepare for Style Manager role
  18108. this.model = {
  18109. styles: [],
  18110. numFmts: [],
  18111. fonts: [],
  18112. borders: [],
  18113. fills: [],
  18114. dxfs: []
  18115. };
  18116. this.initIndex(); // default (zero) border
  18117. this._addBorder({}); // add default (all zero) style
  18118. this._addStyle({
  18119. numFmtId: 0,
  18120. fontId: 0,
  18121. fillId: 0,
  18122. borderId: 0,
  18123. xfId: 0
  18124. }); // add default fills
  18125. this._addFill({
  18126. type: 'pattern',
  18127. pattern: 'none'
  18128. });
  18129. this._addFill({
  18130. type: 'pattern',
  18131. pattern: 'gray125'
  18132. });
  18133. this.weakMap = new WeakMap();
  18134. }
  18135. }, {
  18136. key: "render",
  18137. value: function render(xmlStream, model) {
  18138. model = model || this.model; //
  18139. // <fonts count="2" x14ac:knownFonts="1">
  18140. xmlStream.openXml(XmlStream.StdDocAttributes);
  18141. xmlStream.openNode('styleSheet', StylesXform.STYLESHEET_ATTRIBUTES);
  18142. if (this.index) {
  18143. // model has been built by style manager role (contains xml)
  18144. if (model.numFmts && model.numFmts.length) {
  18145. xmlStream.openNode('numFmts', {
  18146. count: model.numFmts.length
  18147. });
  18148. model.numFmts.forEach(function (numFmtXml) {
  18149. xmlStream.writeXml(numFmtXml);
  18150. });
  18151. xmlStream.closeNode();
  18152. }
  18153. if (!model.fonts.length) {
  18154. // default (zero) font
  18155. this._addFont({
  18156. size: 11,
  18157. color: {
  18158. theme: 1
  18159. },
  18160. name: 'Calibri',
  18161. family: 2,
  18162. scheme: 'minor'
  18163. });
  18164. }
  18165. xmlStream.openNode('fonts', {
  18166. count: model.fonts.length,
  18167. 'x14ac:knownFonts': 1
  18168. });
  18169. model.fonts.forEach(function (fontXml) {
  18170. xmlStream.writeXml(fontXml);
  18171. });
  18172. xmlStream.closeNode();
  18173. xmlStream.openNode('fills', {
  18174. count: model.fills.length
  18175. });
  18176. model.fills.forEach(function (fillXml) {
  18177. xmlStream.writeXml(fillXml);
  18178. });
  18179. xmlStream.closeNode();
  18180. xmlStream.openNode('borders', {
  18181. count: model.borders.length
  18182. });
  18183. model.borders.forEach(function (borderXml) {
  18184. xmlStream.writeXml(borderXml);
  18185. });
  18186. xmlStream.closeNode();
  18187. this.map.cellStyleXfs.render(xmlStream, [{
  18188. numFmtId: 0,
  18189. fontId: 0,
  18190. fillId: 0,
  18191. borderId: 0,
  18192. xfId: 0
  18193. }]);
  18194. xmlStream.openNode('cellXfs', {
  18195. count: model.styles.length
  18196. });
  18197. model.styles.forEach(function (styleXml) {
  18198. xmlStream.writeXml(styleXml);
  18199. });
  18200. xmlStream.closeNode();
  18201. } else {
  18202. // model is plain JSON and needs to be xformed
  18203. this.map.numFmts.render(xmlStream, model.numFmts);
  18204. this.map.fonts.render(xmlStream, model.fonts);
  18205. this.map.fills.render(xmlStream, model.fills);
  18206. this.map.borders.render(xmlStream, model.borders);
  18207. this.map.cellStyleXfs.render(xmlStream, [{
  18208. numFmtId: 0,
  18209. fontId: 0,
  18210. fillId: 0,
  18211. borderId: 0,
  18212. xfId: 0
  18213. }]);
  18214. this.map.cellXfs.render(xmlStream, model.styles);
  18215. }
  18216. StylesXform.STATIC_XFORMS.cellStyles.render(xmlStream);
  18217. this.map.dxfs.render(xmlStream, model.dxfs);
  18218. StylesXform.STATIC_XFORMS.tableStyles.render(xmlStream);
  18219. StylesXform.STATIC_XFORMS.extLst.render(xmlStream);
  18220. xmlStream.closeNode();
  18221. }
  18222. }, {
  18223. key: "parseOpen",
  18224. value: function parseOpen(node) {
  18225. if (this.parser) {
  18226. this.parser.parseOpen(node);
  18227. return true;
  18228. }
  18229. switch (node.name) {
  18230. case 'styleSheet':
  18231. this.initIndex();
  18232. return true;
  18233. default:
  18234. this.parser = this.map[node.name];
  18235. if (this.parser) {
  18236. this.parser.parseOpen(node);
  18237. }
  18238. return true;
  18239. }
  18240. }
  18241. }, {
  18242. key: "parseText",
  18243. value: function parseText(text) {
  18244. if (this.parser) {
  18245. this.parser.parseText(text);
  18246. }
  18247. }
  18248. }, {
  18249. key: "parseClose",
  18250. value: function parseClose(name) {
  18251. var _this2 = this;
  18252. if (this.parser) {
  18253. if (!this.parser.parseClose(name)) {
  18254. this.parser = undefined;
  18255. }
  18256. return true;
  18257. }
  18258. switch (name) {
  18259. case 'styleSheet':
  18260. {
  18261. this.model = {};
  18262. var add = function add(propName, xform) {
  18263. if (xform.model && xform.model.length) {
  18264. _this2.model[propName] = xform.model;
  18265. }
  18266. };
  18267. add('numFmts', this.map.numFmts);
  18268. add('fonts', this.map.fonts);
  18269. add('fills', this.map.fills);
  18270. add('borders', this.map.borders);
  18271. add('styles', this.map.cellXfs);
  18272. add('dxfs', this.map.dxfs); // index numFmts
  18273. this.index = {
  18274. model: [],
  18275. numFmt: []
  18276. };
  18277. if (this.model.numFmts) {
  18278. var numFmtIndex = this.index.numFmt;
  18279. this.model.numFmts.forEach(function (numFmt) {
  18280. numFmtIndex[numFmt.id] = numFmt.formatCode;
  18281. });
  18282. }
  18283. return false;
  18284. }
  18285. default:
  18286. // not quite sure how we get here!
  18287. return true;
  18288. }
  18289. } // add a cell's style model to the collection
  18290. // each style property is processed and cross-referenced, etc.
  18291. // the styleId is returned. Note: cellType is used when numFmt not defined
  18292. }, {
  18293. key: "addStyleModel",
  18294. value: function addStyleModel(model, cellType) {
  18295. if (!model) {
  18296. return 0;
  18297. } // if we have no default font, add it here now
  18298. if (!this.model.fonts.length) {
  18299. // default (zero) font
  18300. this._addFont({
  18301. size: 11,
  18302. color: {
  18303. theme: 1
  18304. },
  18305. name: 'Calibri',
  18306. family: 2,
  18307. scheme: 'minor'
  18308. });
  18309. } // if we have seen this style object before, assume it has the same styleId
  18310. if (this.weakMap && this.weakMap.has(model)) {
  18311. return this.weakMap.get(model);
  18312. }
  18313. var style = {};
  18314. cellType = cellType || Enums.ValueType.Number;
  18315. if (model.numFmt) {
  18316. style.numFmtId = this._addNumFmtStr(model.numFmt);
  18317. } else {
  18318. switch (cellType) {
  18319. case Enums.ValueType.Number:
  18320. style.numFmtId = this._addNumFmtStr('General');
  18321. break;
  18322. case Enums.ValueType.Date:
  18323. style.numFmtId = this._addNumFmtStr('mm-dd-yy');
  18324. break;
  18325. default:
  18326. break;
  18327. }
  18328. }
  18329. if (model.font) {
  18330. style.fontId = this._addFont(model.font);
  18331. }
  18332. if (model.border) {
  18333. style.borderId = this._addBorder(model.border);
  18334. }
  18335. if (model.fill) {
  18336. style.fillId = this._addFill(model.fill);
  18337. }
  18338. if (model.alignment) {
  18339. style.alignment = model.alignment;
  18340. }
  18341. if (model.protection) {
  18342. style.protection = model.protection;
  18343. }
  18344. var styleId = this._addStyle(style);
  18345. if (this.weakMap) {
  18346. this.weakMap.set(model, styleId);
  18347. }
  18348. return styleId;
  18349. } // given a styleId (i.e. s="n"), get the cell's style model
  18350. // objects are shared where possible.
  18351. }, {
  18352. key: "getStyleModel",
  18353. value: function getStyleModel(id) {
  18354. // if the style doesn't exist return null
  18355. var style = this.model.styles[id];
  18356. if (!style) return null; // have we built this model before?
  18357. var model = this.index.model[id];
  18358. if (model) return model; // build a new model
  18359. model = this.index.model[id] = {}; // -------------------------------------------------------
  18360. // number format
  18361. if (style.numFmtId) {
  18362. var numFmt = this.index.numFmt[style.numFmtId] || NumFmtXform.getDefaultFmtCode(style.numFmtId);
  18363. if (numFmt) {
  18364. model.numFmt = numFmt;
  18365. }
  18366. }
  18367. function addStyle(name, group, styleId) {
  18368. if (styleId || styleId === 0) {
  18369. var part = group[styleId];
  18370. if (part) {
  18371. model[name] = part;
  18372. }
  18373. }
  18374. }
  18375. addStyle('font', this.model.fonts, style.fontId);
  18376. addStyle('border', this.model.borders, style.borderId);
  18377. addStyle('fill', this.model.fills, style.fillId); // -------------------------------------------------------
  18378. // alignment
  18379. if (style.alignment) {
  18380. model.alignment = style.alignment;
  18381. } // -------------------------------------------------------
  18382. // protection
  18383. if (style.protection) {
  18384. model.protection = style.protection;
  18385. }
  18386. return model;
  18387. }
  18388. }, {
  18389. key: "addDxfStyle",
  18390. value: function addDxfStyle(style) {
  18391. this.model.dxfs.push(style);
  18392. return this.model.dxfs.length - 1;
  18393. }
  18394. }, {
  18395. key: "getDxfStyle",
  18396. value: function getDxfStyle(id) {
  18397. return this.model.dxfs[id];
  18398. } // =========================================================================
  18399. // Private Interface
  18400. }, {
  18401. key: "_addStyle",
  18402. value: function _addStyle(style) {
  18403. var xml = this.map.style.toXml(style);
  18404. var index = this.index.style[xml];
  18405. if (index === undefined) {
  18406. index = this.index.style[xml] = this.model.styles.length;
  18407. this.model.styles.push(xml);
  18408. }
  18409. return index;
  18410. } // =========================================================================
  18411. // Number Formats
  18412. }, {
  18413. key: "_addNumFmtStr",
  18414. value: function _addNumFmtStr(formatCode) {
  18415. // check if default format
  18416. var index = NumFmtXform.getDefaultFmtId(formatCode);
  18417. if (index !== undefined) return index; // check if already in
  18418. index = this.index.numFmt[formatCode];
  18419. if (index !== undefined) return index;
  18420. index = this.index.numFmt[formatCode] = NUMFMT_BASE + this.model.numFmts.length;
  18421. var xml = this.map.numFmt.toXml({
  18422. id: index,
  18423. formatCode: formatCode
  18424. });
  18425. this.model.numFmts.push(xml);
  18426. return index;
  18427. } // =========================================================================
  18428. // Fonts
  18429. }, {
  18430. key: "_addFont",
  18431. value: function _addFont(font) {
  18432. var xml = this.map.font.toXml(font);
  18433. var index = this.index.font[xml];
  18434. if (index === undefined) {
  18435. index = this.index.font[xml] = this.model.fonts.length;
  18436. this.model.fonts.push(xml);
  18437. }
  18438. return index;
  18439. } // =========================================================================
  18440. // Borders
  18441. }, {
  18442. key: "_addBorder",
  18443. value: function _addBorder(border) {
  18444. var xml = this.map.border.toXml(border);
  18445. var index = this.index.border[xml];
  18446. if (index === undefined) {
  18447. index = this.index.border[xml] = this.model.borders.length;
  18448. this.model.borders.push(xml);
  18449. }
  18450. return index;
  18451. } // =========================================================================
  18452. // Fills
  18453. }, {
  18454. key: "_addFill",
  18455. value: function _addFill(fill) {
  18456. var xml = this.map.fill.toXml(fill);
  18457. var index = this.index.fill[xml];
  18458. if (index === undefined) {
  18459. index = this.index.fill[xml] = this.model.fills.length;
  18460. this.model.fills.push(xml);
  18461. }
  18462. return index;
  18463. } // =========================================================================
  18464. }]);
  18465. return StylesXform;
  18466. }(BaseXform);
  18467. StylesXform.STYLESHEET_ATTRIBUTES = {
  18468. xmlns: 'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
  18469. 'xmlns:mc': 'http://schemas.openxmlformats.org/markup-compatibility/2006',
  18470. 'mc:Ignorable': 'x14ac x16r2',
  18471. 'xmlns:x14ac': 'http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac',
  18472. 'xmlns:x16r2': 'http://schemas.microsoft.com/office/spreadsheetml/2015/02/main'
  18473. };
  18474. StylesXform.STATIC_XFORMS = {
  18475. cellStyles: new StaticXform({
  18476. tag: 'cellStyles',
  18477. $: {
  18478. count: 1
  18479. },
  18480. c: [{
  18481. tag: 'cellStyle',
  18482. $: {
  18483. name: 'Normal',
  18484. xfId: 0,
  18485. builtinId: 0
  18486. }
  18487. }]
  18488. }),
  18489. dxfs: new StaticXform({
  18490. tag: 'dxfs',
  18491. $: {
  18492. count: 0
  18493. }
  18494. }),
  18495. tableStyles: new StaticXform({
  18496. tag: 'tableStyles',
  18497. $: {
  18498. count: 0,
  18499. defaultTableStyle: 'TableStyleMedium2',
  18500. defaultPivotStyle: 'PivotStyleLight16'
  18501. }
  18502. }),
  18503. extLst: new StaticXform({
  18504. tag: 'extLst',
  18505. c: [{
  18506. tag: 'ext',
  18507. $: {
  18508. uri: '{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}',
  18509. 'xmlns:x14': 'http://schemas.microsoft.com/office/spreadsheetml/2009/9/main'
  18510. },
  18511. c: [{
  18512. tag: 'x14:slicerStyles',
  18513. $: {
  18514. defaultSlicerStyle: 'SlicerStyleLight1'
  18515. }
  18516. }]
  18517. }, {
  18518. tag: 'ext',
  18519. $: {
  18520. uri: '{9260A510-F301-46a8-8635-F512D64BE5F5}',
  18521. 'xmlns:x15': 'http://schemas.microsoft.com/office/spreadsheetml/2010/11/main'
  18522. },
  18523. c: [{
  18524. tag: 'x15:timelineStyles',
  18525. $: {
  18526. defaultTimelineStyle: 'TimeSlicerStyleLight1'
  18527. }
  18528. }]
  18529. }]
  18530. })
  18531. }; // the stylemanager mock acts like StyleManager except that it always returns 0 or {}
  18532. var StylesXformMock = /*#__PURE__*/function (_StylesXform) {
  18533. _inherits(StylesXformMock, _StylesXform);
  18534. var _super2 = _createSuper(StylesXformMock);
  18535. function StylesXformMock() {
  18536. var _this3;
  18537. _classCallCheck(this, StylesXformMock);
  18538. _this3 = _super2.call(this);
  18539. _this3.model = {
  18540. styles: [{
  18541. numFmtId: 0,
  18542. fontId: 0,
  18543. fillId: 0,
  18544. borderId: 0,
  18545. xfId: 0
  18546. }],
  18547. numFmts: [],
  18548. fonts: [{
  18549. size: 11,
  18550. color: {
  18551. theme: 1
  18552. },
  18553. name: 'Calibri',
  18554. family: 2,
  18555. scheme: 'minor'
  18556. }],
  18557. borders: [{}],
  18558. fills: [{
  18559. type: 'pattern',
  18560. pattern: 'none'
  18561. }, {
  18562. type: 'pattern',
  18563. pattern: 'gray125'
  18564. }]
  18565. };
  18566. return _this3;
  18567. } // =========================================================================
  18568. // Style Manager Interface
  18569. // override normal behaviour - consume and dispose
  18570. _createClass(StylesXformMock, [{
  18571. key: "parseStream",
  18572. value: function parseStream(stream) {
  18573. stream.autodrain();
  18574. return Promise.resolve();
  18575. } // add a cell's style model to the collection
  18576. // each style property is processed and cross-referenced, etc.
  18577. // the styleId is returned. Note: cellType is used when numFmt not defined
  18578. }, {
  18579. key: "addStyleModel",
  18580. value: function addStyleModel(model, cellType) {
  18581. switch (cellType) {
  18582. case Enums.ValueType.Date:
  18583. return this.dateStyleId;
  18584. default:
  18585. return 0;
  18586. }
  18587. }
  18588. }, {
  18589. key: "getStyleModel",
  18590. // given a styleId (i.e. s="n"), get the cell's style model
  18591. // objects are shared where possible.
  18592. value: function getStyleModel()
  18593. /* id */
  18594. {
  18595. return {};
  18596. }
  18597. }, {
  18598. key: "dateStyleId",
  18599. get: function get() {
  18600. if (!this._dateStyleId) {
  18601. var dateStyle = {
  18602. numFmtId: NumFmtXform.getDefaultFmtId('mm-dd-yy')
  18603. };
  18604. this._dateStyleId = this.model.styles.length;
  18605. this.model.styles.push(dateStyle);
  18606. }
  18607. return this._dateStyleId;
  18608. }
  18609. }]);
  18610. return StylesXformMock;
  18611. }(StylesXform);
  18612. StylesXform.Mock = StylesXformMock;
  18613. module.exports = StylesXform;
  18614. },{"../../../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){
  18615. "use strict";
  18616. 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); }
  18617. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  18618. 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); } }
  18619. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  18620. 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); }
  18621. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  18622. 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); }; }
  18623. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  18624. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  18625. 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; } }
  18626. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  18627. var BaseXform = require('../base-xform');
  18628. var UnderlineXform = /*#__PURE__*/function (_BaseXform) {
  18629. _inherits(UnderlineXform, _BaseXform);
  18630. var _super = _createSuper(UnderlineXform);
  18631. function UnderlineXform(model) {
  18632. var _this;
  18633. _classCallCheck(this, UnderlineXform);
  18634. _this = _super.call(this);
  18635. _this.model = model;
  18636. return _this;
  18637. }
  18638. _createClass(UnderlineXform, [{
  18639. key: "render",
  18640. value: function render(xmlStream, model) {
  18641. model = model || this.model;
  18642. if (model === true) {
  18643. xmlStream.leafNode('u');
  18644. } else {
  18645. var attr = UnderlineXform.Attributes[model];
  18646. if (attr) {
  18647. xmlStream.leafNode('u', attr);
  18648. }
  18649. }
  18650. }
  18651. }, {
  18652. key: "parseOpen",
  18653. value: function parseOpen(node) {
  18654. if (node.name === 'u') {
  18655. this.model = node.attributes.val || true;
  18656. }
  18657. }
  18658. }, {
  18659. key: "parseText",
  18660. value: function parseText() {}
  18661. }, {
  18662. key: "parseClose",
  18663. value: function parseClose() {
  18664. return false;
  18665. }
  18666. }, {
  18667. key: "tag",
  18668. get: function get() {
  18669. return 'u';
  18670. }
  18671. }]);
  18672. return UnderlineXform;
  18673. }(BaseXform);
  18674. UnderlineXform.Attributes = {
  18675. single: {},
  18676. double: {
  18677. val: 'double'
  18678. },
  18679. singleAccounting: {
  18680. val: 'singleAccounting'
  18681. },
  18682. doubleAccounting: {
  18683. val: 'doubleAccounting'
  18684. }
  18685. };
  18686. module.exports = UnderlineXform;
  18687. },{"../base-xform":31}],136:[function(require,module,exports){
  18688. "use strict";
  18689. 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); }
  18690. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  18691. 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); } }
  18692. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  18693. 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); }
  18694. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  18695. 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); }; }
  18696. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  18697. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  18698. 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; } }
  18699. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  18700. var BaseXform = require('../base-xform');
  18701. var FilterColumnXform = require('./filter-column-xform');
  18702. var AutoFilterXform = /*#__PURE__*/function (_BaseXform) {
  18703. _inherits(AutoFilterXform, _BaseXform);
  18704. var _super = _createSuper(AutoFilterXform);
  18705. function AutoFilterXform() {
  18706. var _this;
  18707. _classCallCheck(this, AutoFilterXform);
  18708. _this = _super.call(this);
  18709. _this.map = {
  18710. filterColumn: new FilterColumnXform()
  18711. };
  18712. return _this;
  18713. }
  18714. _createClass(AutoFilterXform, [{
  18715. key: "prepare",
  18716. value: function prepare(model) {
  18717. var _this2 = this;
  18718. model.columns.forEach(function (column, index) {
  18719. _this2.map.filterColumn.prepare(column, {
  18720. index: index
  18721. });
  18722. });
  18723. }
  18724. }, {
  18725. key: "render",
  18726. value: function render(xmlStream, model) {
  18727. var _this3 = this;
  18728. xmlStream.openNode(this.tag, {
  18729. ref: model.autoFilterRef
  18730. });
  18731. model.columns.forEach(function (column) {
  18732. _this3.map.filterColumn.render(xmlStream, column);
  18733. });
  18734. xmlStream.closeNode();
  18735. return true;
  18736. }
  18737. }, {
  18738. key: "parseOpen",
  18739. value: function parseOpen(node) {
  18740. if (this.parser) {
  18741. this.parser.parseOpen(node);
  18742. return true;
  18743. }
  18744. switch (node.name) {
  18745. case this.tag:
  18746. this.model = {
  18747. autoFilterRef: node.attributes.ref,
  18748. columns: []
  18749. };
  18750. return true;
  18751. default:
  18752. this.parser = this.map[node.name];
  18753. if (this.parser) {
  18754. this.parseOpen(node);
  18755. return true;
  18756. }
  18757. throw new Error("Unexpected xml node in parseOpen: ".concat(JSON.stringify(node)));
  18758. }
  18759. }
  18760. }, {
  18761. key: "parseText",
  18762. value: function parseText(text) {
  18763. if (this.parser) {
  18764. this.parser.parseText(text);
  18765. }
  18766. }
  18767. }, {
  18768. key: "parseClose",
  18769. value: function parseClose(name) {
  18770. if (this.parser) {
  18771. if (!this.parser.parseClose(name)) {
  18772. this.model.columns.push(this.parser.model);
  18773. this.parser = undefined;
  18774. }
  18775. return true;
  18776. }
  18777. switch (name) {
  18778. case this.tag:
  18779. return false;
  18780. default:
  18781. throw new Error("Unexpected xml node in parseClose: ".concat(name));
  18782. }
  18783. }
  18784. }, {
  18785. key: "tag",
  18786. get: function get() {
  18787. return 'autoFilter';
  18788. }
  18789. }]);
  18790. return AutoFilterXform;
  18791. }(BaseXform);
  18792. module.exports = AutoFilterXform;
  18793. },{"../base-xform":31,"./filter-column-xform":137}],137:[function(require,module,exports){
  18794. "use strict";
  18795. 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); }
  18796. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  18797. 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); } }
  18798. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  18799. 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); }
  18800. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  18801. 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); }; }
  18802. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  18803. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  18804. 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; } }
  18805. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  18806. var BaseXform = require('../base-xform');
  18807. var FilterColumnXform = /*#__PURE__*/function (_BaseXform) {
  18808. _inherits(FilterColumnXform, _BaseXform);
  18809. var _super = _createSuper(FilterColumnXform);
  18810. function FilterColumnXform() {
  18811. _classCallCheck(this, FilterColumnXform);
  18812. return _super.apply(this, arguments);
  18813. }
  18814. _createClass(FilterColumnXform, [{
  18815. key: "prepare",
  18816. value: function prepare(model, options) {
  18817. model.colId = options.index.toString();
  18818. }
  18819. }, {
  18820. key: "render",
  18821. value: function render(xmlStream, model) {
  18822. xmlStream.leafNode(this.tag, {
  18823. colId: model.colId,
  18824. hiddenButton: model.filterButton ? '0' : '1'
  18825. });
  18826. return true;
  18827. }
  18828. }, {
  18829. key: "parseOpen",
  18830. value: function parseOpen(node) {
  18831. if (node.name === this.tag) {
  18832. var attributes = node.attributes;
  18833. this.model = {
  18834. filterButton: attributes.hiddenButton === '0'
  18835. };
  18836. return true;
  18837. }
  18838. return false;
  18839. }
  18840. }, {
  18841. key: "parseText",
  18842. value: function parseText() {}
  18843. }, {
  18844. key: "parseClose",
  18845. value: function parseClose() {
  18846. return false;
  18847. }
  18848. }, {
  18849. key: "tag",
  18850. get: function get() {
  18851. return 'filterColumn';
  18852. }
  18853. }]);
  18854. return FilterColumnXform;
  18855. }(BaseXform);
  18856. module.exports = FilterColumnXform;
  18857. },{"../base-xform":31}],138:[function(require,module,exports){
  18858. "use strict";
  18859. 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); }
  18860. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  18861. 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); } }
  18862. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  18863. 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); }
  18864. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  18865. 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); }; }
  18866. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  18867. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  18868. 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; } }
  18869. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  18870. var BaseXform = require('../base-xform');
  18871. var TableColumnXform = /*#__PURE__*/function (_BaseXform) {
  18872. _inherits(TableColumnXform, _BaseXform);
  18873. var _super = _createSuper(TableColumnXform);
  18874. function TableColumnXform() {
  18875. _classCallCheck(this, TableColumnXform);
  18876. return _super.apply(this, arguments);
  18877. }
  18878. _createClass(TableColumnXform, [{
  18879. key: "prepare",
  18880. value: function prepare(model, options) {
  18881. model.id = options.index + 1;
  18882. }
  18883. }, {
  18884. key: "render",
  18885. value: function render(xmlStream, model) {
  18886. xmlStream.leafNode(this.tag, {
  18887. id: model.id.toString(),
  18888. name: model.name,
  18889. totalsRowLabel: model.totalsRowLabel,
  18890. totalsRowFunction: model.totalsRowFunction,
  18891. dxfId: model.dxfId
  18892. });
  18893. return true;
  18894. }
  18895. }, {
  18896. key: "parseOpen",
  18897. value: function parseOpen(node) {
  18898. if (node.name === this.tag) {
  18899. var attributes = node.attributes;
  18900. this.model = {
  18901. name: attributes.name,
  18902. totalsRowLabel: attributes.totalsRowLabel,
  18903. totalsRowFunction: attributes.totalsRowFunction,
  18904. dxfId: attributes.dxfId
  18905. };
  18906. return true;
  18907. }
  18908. return false;
  18909. }
  18910. }, {
  18911. key: "parseText",
  18912. value: function parseText() {}
  18913. }, {
  18914. key: "parseClose",
  18915. value: function parseClose() {
  18916. return false;
  18917. }
  18918. }, {
  18919. key: "tag",
  18920. get: function get() {
  18921. return 'tableColumn';
  18922. }
  18923. }]);
  18924. return TableColumnXform;
  18925. }(BaseXform);
  18926. module.exports = TableColumnXform;
  18927. },{"../base-xform":31}],139:[function(require,module,exports){
  18928. "use strict";
  18929. 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); }
  18930. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  18931. 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); } }
  18932. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  18933. 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); }
  18934. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  18935. 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); }; }
  18936. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  18937. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  18938. 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; } }
  18939. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  18940. var BaseXform = require('../base-xform');
  18941. var TableStyleInfoXform = /*#__PURE__*/function (_BaseXform) {
  18942. _inherits(TableStyleInfoXform, _BaseXform);
  18943. var _super = _createSuper(TableStyleInfoXform);
  18944. function TableStyleInfoXform() {
  18945. _classCallCheck(this, TableStyleInfoXform);
  18946. return _super.apply(this, arguments);
  18947. }
  18948. _createClass(TableStyleInfoXform, [{
  18949. key: "render",
  18950. value: function render(xmlStream, model) {
  18951. xmlStream.leafNode(this.tag, {
  18952. name: model.theme ? model.theme : undefined,
  18953. showFirstColumn: model.showFirstColumn ? '1' : '0',
  18954. showLastColumn: model.showLastColumn ? '1' : '0',
  18955. showRowStripes: model.showRowStripes ? '1' : '0',
  18956. showColumnStripes: model.showColumnStripes ? '1' : '0'
  18957. });
  18958. return true;
  18959. }
  18960. }, {
  18961. key: "parseOpen",
  18962. value: function parseOpen(node) {
  18963. if (node.name === this.tag) {
  18964. var attributes = node.attributes;
  18965. this.model = {
  18966. theme: attributes.name ? attributes.name : null,
  18967. showFirstColumn: attributes.showFirstColumn === '1',
  18968. showLastColumn: attributes.showLastColumn === '1',
  18969. showRowStripes: attributes.showRowStripes === '1',
  18970. showColumnStripes: attributes.showColumnStripes === '1'
  18971. };
  18972. return true;
  18973. }
  18974. return false;
  18975. }
  18976. }, {
  18977. key: "parseText",
  18978. value: function parseText() {}
  18979. }, {
  18980. key: "parseClose",
  18981. value: function parseClose() {
  18982. return false;
  18983. }
  18984. }, {
  18985. key: "tag",
  18986. get: function get() {
  18987. return 'tableStyleInfo';
  18988. }
  18989. }]);
  18990. return TableStyleInfoXform;
  18991. }(BaseXform);
  18992. module.exports = TableStyleInfoXform;
  18993. },{"../base-xform":31}],140:[function(require,module,exports){
  18994. "use strict";
  18995. 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); }
  18996. 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; }
  18997. 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; }
  18998. 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; }
  18999. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  19000. 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); } }
  19001. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  19002. 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); }
  19003. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  19004. 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); }; }
  19005. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  19006. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  19007. 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; } }
  19008. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  19009. var XmlStream = require('../../../utils/xml-stream');
  19010. var BaseXform = require('../base-xform');
  19011. var ListXform = require('../list-xform');
  19012. var AutoFilterXform = require('./auto-filter-xform');
  19013. var TableColumnXform = require('./table-column-xform');
  19014. var TableStyleInfoXform = require('./table-style-info-xform');
  19015. var TableXform = /*#__PURE__*/function (_BaseXform) {
  19016. _inherits(TableXform, _BaseXform);
  19017. var _super = _createSuper(TableXform);
  19018. function TableXform() {
  19019. var _this;
  19020. _classCallCheck(this, TableXform);
  19021. _this = _super.call(this);
  19022. _this.map = {
  19023. autoFilter: new AutoFilterXform(),
  19024. tableColumns: new ListXform({
  19025. tag: 'tableColumns',
  19026. count: true,
  19027. empty: true,
  19028. childXform: new TableColumnXform()
  19029. }),
  19030. tableStyleInfo: new TableStyleInfoXform()
  19031. };
  19032. return _this;
  19033. }
  19034. _createClass(TableXform, [{
  19035. key: "prepare",
  19036. value: function prepare(model, options) {
  19037. this.map.autoFilter.prepare(model);
  19038. this.map.tableColumns.prepare(model.columns, options);
  19039. }
  19040. }, {
  19041. key: "render",
  19042. value: function render(xmlStream, model) {
  19043. xmlStream.openXml(XmlStream.StdDocAttributes);
  19044. xmlStream.openNode(this.tag, _objectSpread(_objectSpread({}, TableXform.TABLE_ATTRIBUTES), {}, {
  19045. id: model.id,
  19046. name: model.name,
  19047. displayName: model.displayName || model.name,
  19048. ref: model.tableRef,
  19049. totalsRowCount: model.totalsRow ? '1' : undefined,
  19050. totalsRowShown: model.totalsRow ? undefined : '1',
  19051. headerRowCount: model.headerRow ? '1' : '0'
  19052. }));
  19053. this.map.autoFilter.render(xmlStream, model);
  19054. this.map.tableColumns.render(xmlStream, model.columns);
  19055. this.map.tableStyleInfo.render(xmlStream, model.style);
  19056. xmlStream.closeNode();
  19057. }
  19058. }, {
  19059. key: "parseOpen",
  19060. value: function parseOpen(node) {
  19061. if (this.parser) {
  19062. this.parser.parseOpen(node);
  19063. return true;
  19064. }
  19065. var name = node.name,
  19066. attributes = node.attributes;
  19067. switch (name) {
  19068. case this.tag:
  19069. this.reset();
  19070. this.model = {
  19071. name: attributes.name,
  19072. displayName: attributes.displayName || attributes.name,
  19073. tableRef: attributes.ref,
  19074. totalsRow: attributes.totalsRowCount === '1',
  19075. headerRow: attributes.headerRowCount === '1'
  19076. };
  19077. break;
  19078. default:
  19079. this.parser = this.map[node.name];
  19080. if (this.parser) {
  19081. this.parser.parseOpen(node);
  19082. }
  19083. break;
  19084. }
  19085. return true;
  19086. }
  19087. }, {
  19088. key: "parseText",
  19089. value: function parseText(text) {
  19090. if (this.parser) {
  19091. this.parser.parseText(text);
  19092. }
  19093. }
  19094. }, {
  19095. key: "parseClose",
  19096. value: function parseClose(name) {
  19097. var _this2 = this;
  19098. if (this.parser) {
  19099. if (!this.parser.parseClose(name)) {
  19100. this.parser = undefined;
  19101. }
  19102. return true;
  19103. }
  19104. switch (name) {
  19105. case this.tag:
  19106. this.model.columns = this.map.tableColumns.model;
  19107. if (this.map.autoFilter.model) {
  19108. this.model.autoFilterRef = this.map.autoFilter.model.autoFilterRef;
  19109. this.map.autoFilter.model.columns.forEach(function (column, index) {
  19110. _this2.model.columns[index].filterButton = column.filterButton;
  19111. });
  19112. }
  19113. this.model.style = this.map.tableStyleInfo.model;
  19114. return false;
  19115. default:
  19116. // could be some unrecognised tags
  19117. return true;
  19118. }
  19119. }
  19120. }, {
  19121. key: "reconcile",
  19122. value: function reconcile(model, options) {
  19123. // fetch the dfxs from styles
  19124. model.columns.forEach(function (column) {
  19125. if (column.dxfId !== undefined) {
  19126. column.style = options.styles.getDxfStyle(column.dxfId);
  19127. }
  19128. });
  19129. }
  19130. }, {
  19131. key: "tag",
  19132. get: function get() {
  19133. return 'table';
  19134. }
  19135. }]);
  19136. return TableXform;
  19137. }(BaseXform);
  19138. TableXform.TABLE_ATTRIBUTES = {
  19139. xmlns: 'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
  19140. 'xmlns:mc': 'http://schemas.openxmlformats.org/markup-compatibility/2006',
  19141. 'mc:Ignorable': 'xr xr3',
  19142. 'xmlns:xr': 'http://schemas.microsoft.com/office/spreadsheetml/2014/revision',
  19143. 'xmlns:xr3': 'http://schemas.microsoft.com/office/spreadsheetml/2016/revision3' // 'xr:uid': '{00000000-000C-0000-FFFF-FFFF00000000}',
  19144. };
  19145. module.exports = TableXform;
  19146. },{"../../../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){
  19147. (function (process,Buffer){
  19148. "use strict";
  19149. 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); } }
  19150. 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); }); }; }
  19151. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  19152. 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); } }
  19153. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  19154. 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"); }
  19155. var fs = require('fs');
  19156. var JSZip = require('jszip');
  19157. var _require = require('readable-stream'),
  19158. PassThrough = _require.PassThrough;
  19159. var ZipStream = require('../utils/zip-stream');
  19160. var StreamBuf = require('../utils/stream-buf');
  19161. var utils = require('../utils/utils');
  19162. var XmlStream = require('../utils/xml-stream');
  19163. var _require2 = require('../utils/browser-buffer-decode'),
  19164. bufferToString = _require2.bufferToString;
  19165. var StylesXform = require('./xform/style/styles-xform');
  19166. var CoreXform = require('./xform/core/core-xform');
  19167. var SharedStringsXform = require('./xform/strings/shared-strings-xform');
  19168. var RelationshipsXform = require('./xform/core/relationships-xform');
  19169. var ContentTypesXform = require('./xform/core/content-types-xform');
  19170. var AppXform = require('./xform/core/app-xform');
  19171. var WorkbookXform = require('./xform/book/workbook-xform');
  19172. var WorksheetXform = require('./xform/sheet/worksheet-xform');
  19173. var DrawingXform = require('./xform/drawing/drawing-xform');
  19174. var TableXform = require('./xform/table/table-xform');
  19175. var CommentsXform = require('./xform/comment/comments-xform');
  19176. var VmlNotesXform = require('./xform/comment/vml-notes-xform');
  19177. var theme1Xml = require('./xml/theme1.js');
  19178. function fsReadFileAsync(filename, options) {
  19179. return new Promise(function (resolve, reject) {
  19180. fs.readFile(filename, options, function (error, data) {
  19181. if (error) {
  19182. reject(error);
  19183. } else {
  19184. resolve(data);
  19185. }
  19186. });
  19187. });
  19188. }
  19189. var XLSX = /*#__PURE__*/function () {
  19190. function XLSX(workbook) {
  19191. _classCallCheck(this, XLSX);
  19192. this.workbook = workbook;
  19193. } // ===============================================================================
  19194. // Workbook
  19195. // =========================================================================
  19196. // Read
  19197. _createClass(XLSX, [{
  19198. key: "readFile",
  19199. value: function () {
  19200. var _readFile = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(filename, options) {
  19201. var stream, workbook;
  19202. return regeneratorRuntime.wrap(function _callee$(_context) {
  19203. while (1) {
  19204. switch (_context.prev = _context.next) {
  19205. case 0:
  19206. _context.next = 2;
  19207. return utils.fs.exists(filename);
  19208. case 2:
  19209. if (_context.sent) {
  19210. _context.next = 4;
  19211. break;
  19212. }
  19213. throw new Error("File not found: ".concat(filename));
  19214. case 4:
  19215. stream = fs.createReadStream(filename);
  19216. _context.prev = 5;
  19217. _context.next = 8;
  19218. return this.read(stream, options);
  19219. case 8:
  19220. workbook = _context.sent;
  19221. stream.close();
  19222. return _context.abrupt("return", workbook);
  19223. case 13:
  19224. _context.prev = 13;
  19225. _context.t0 = _context["catch"](5);
  19226. stream.close();
  19227. throw _context.t0;
  19228. case 17:
  19229. case "end":
  19230. return _context.stop();
  19231. }
  19232. }
  19233. }, _callee, this, [[5, 13]]);
  19234. }));
  19235. function readFile(_x, _x2) {
  19236. return _readFile.apply(this, arguments);
  19237. }
  19238. return readFile;
  19239. }()
  19240. }, {
  19241. key: "parseRels",
  19242. value: function parseRels(stream) {
  19243. var xform = new RelationshipsXform();
  19244. return xform.parseStream(stream);
  19245. }
  19246. }, {
  19247. key: "parseWorkbook",
  19248. value: function parseWorkbook(stream) {
  19249. var xform = new WorkbookXform();
  19250. return xform.parseStream(stream);
  19251. }
  19252. }, {
  19253. key: "parseSharedStrings",
  19254. value: function parseSharedStrings(stream) {
  19255. var xform = new SharedStringsXform();
  19256. return xform.parseStream(stream);
  19257. }
  19258. }, {
  19259. key: "reconcile",
  19260. value: function reconcile(model, options) {
  19261. var workbookXform = new WorkbookXform();
  19262. var worksheetXform = new WorksheetXform(options);
  19263. var drawingXform = new DrawingXform();
  19264. var tableXform = new TableXform();
  19265. workbookXform.reconcile(model); // reconcile drawings with their rels
  19266. var drawingOptions = {
  19267. media: model.media,
  19268. mediaIndex: model.mediaIndex
  19269. };
  19270. Object.keys(model.drawings).forEach(function (name) {
  19271. var drawing = model.drawings[name];
  19272. var drawingRel = model.drawingRels[name];
  19273. if (drawingRel) {
  19274. drawingOptions.rels = drawingRel.reduce(function (o, rel) {
  19275. o[rel.Id] = rel;
  19276. return o;
  19277. }, {});
  19278. (drawing.anchors || []).forEach(function (anchor) {
  19279. var hyperlinks = anchor.picture && anchor.picture.hyperlinks;
  19280. if (hyperlinks && drawingOptions.rels[hyperlinks.rId]) {
  19281. hyperlinks.hyperlink = drawingOptions.rels[hyperlinks.rId].Target;
  19282. delete hyperlinks.rId;
  19283. }
  19284. });
  19285. drawingXform.reconcile(drawing, drawingOptions);
  19286. }
  19287. }); // reconcile tables with the default styles
  19288. var tableOptions = {
  19289. styles: model.styles
  19290. };
  19291. Object.values(model.tables).forEach(function (table) {
  19292. tableXform.reconcile(table, tableOptions);
  19293. });
  19294. var sheetOptions = {
  19295. styles: model.styles,
  19296. sharedStrings: model.sharedStrings,
  19297. media: model.media,
  19298. mediaIndex: model.mediaIndex,
  19299. date1904: model.properties && model.properties.date1904,
  19300. drawings: model.drawings,
  19301. comments: model.comments,
  19302. tables: model.tables,
  19303. vmlDrawings: model.vmlDrawings
  19304. };
  19305. model.worksheets.forEach(function (worksheet) {
  19306. worksheet.relationships = model.worksheetRels[worksheet.sheetNo];
  19307. worksheetXform.reconcile(worksheet, sheetOptions);
  19308. }); // delete unnecessary parts
  19309. delete model.worksheetHash;
  19310. delete model.worksheetRels;
  19311. delete model.globalRels;
  19312. delete model.sharedStrings;
  19313. delete model.workbookRels;
  19314. delete model.sheetDefs;
  19315. delete model.styles;
  19316. delete model.mediaIndex;
  19317. delete model.drawings;
  19318. delete model.drawingRels;
  19319. delete model.vmlDrawings;
  19320. }
  19321. }, {
  19322. key: "_processWorksheetEntry",
  19323. value: function () {
  19324. var _processWorksheetEntry2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(stream, model, sheetNo, options, path) {
  19325. var xform, worksheet;
  19326. return regeneratorRuntime.wrap(function _callee2$(_context2) {
  19327. while (1) {
  19328. switch (_context2.prev = _context2.next) {
  19329. case 0:
  19330. xform = new WorksheetXform(options);
  19331. _context2.next = 3;
  19332. return xform.parseStream(stream);
  19333. case 3:
  19334. worksheet = _context2.sent;
  19335. worksheet.sheetNo = sheetNo;
  19336. model.worksheetHash[path] = worksheet;
  19337. model.worksheets.push(worksheet);
  19338. case 7:
  19339. case "end":
  19340. return _context2.stop();
  19341. }
  19342. }
  19343. }, _callee2);
  19344. }));
  19345. function _processWorksheetEntry(_x3, _x4, _x5, _x6, _x7) {
  19346. return _processWorksheetEntry2.apply(this, arguments);
  19347. }
  19348. return _processWorksheetEntry;
  19349. }()
  19350. }, {
  19351. key: "_processCommentEntry",
  19352. value: function () {
  19353. var _processCommentEntry2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(stream, model, name) {
  19354. var xform, comments;
  19355. return regeneratorRuntime.wrap(function _callee3$(_context3) {
  19356. while (1) {
  19357. switch (_context3.prev = _context3.next) {
  19358. case 0:
  19359. xform = new CommentsXform();
  19360. _context3.next = 3;
  19361. return xform.parseStream(stream);
  19362. case 3:
  19363. comments = _context3.sent;
  19364. model.comments["../".concat(name, ".xml")] = comments;
  19365. case 5:
  19366. case "end":
  19367. return _context3.stop();
  19368. }
  19369. }
  19370. }, _callee3);
  19371. }));
  19372. function _processCommentEntry(_x8, _x9, _x10) {
  19373. return _processCommentEntry2.apply(this, arguments);
  19374. }
  19375. return _processCommentEntry;
  19376. }()
  19377. }, {
  19378. key: "_processTableEntry",
  19379. value: function () {
  19380. var _processTableEntry2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(stream, model, name) {
  19381. var xform, table;
  19382. return regeneratorRuntime.wrap(function _callee4$(_context4) {
  19383. while (1) {
  19384. switch (_context4.prev = _context4.next) {
  19385. case 0:
  19386. xform = new TableXform();
  19387. _context4.next = 3;
  19388. return xform.parseStream(stream);
  19389. case 3:
  19390. table = _context4.sent;
  19391. model.tables["../tables/".concat(name, ".xml")] = table;
  19392. case 5:
  19393. case "end":
  19394. return _context4.stop();
  19395. }
  19396. }
  19397. }, _callee4);
  19398. }));
  19399. function _processTableEntry(_x11, _x12, _x13) {
  19400. return _processTableEntry2.apply(this, arguments);
  19401. }
  19402. return _processTableEntry;
  19403. }()
  19404. }, {
  19405. key: "_processWorksheetRelsEntry",
  19406. value: function () {
  19407. var _processWorksheetRelsEntry2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(stream, model, sheetNo) {
  19408. var xform, relationships;
  19409. return regeneratorRuntime.wrap(function _callee5$(_context5) {
  19410. while (1) {
  19411. switch (_context5.prev = _context5.next) {
  19412. case 0:
  19413. xform = new RelationshipsXform();
  19414. _context5.next = 3;
  19415. return xform.parseStream(stream);
  19416. case 3:
  19417. relationships = _context5.sent;
  19418. model.worksheetRels[sheetNo] = relationships;
  19419. case 5:
  19420. case "end":
  19421. return _context5.stop();
  19422. }
  19423. }
  19424. }, _callee5);
  19425. }));
  19426. function _processWorksheetRelsEntry(_x14, _x15, _x16) {
  19427. return _processWorksheetRelsEntry2.apply(this, arguments);
  19428. }
  19429. return _processWorksheetRelsEntry;
  19430. }()
  19431. }, {
  19432. key: "_processMediaEntry",
  19433. value: function () {
  19434. var _processMediaEntry2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(entry, model, filename) {
  19435. var lastDot, extension, name;
  19436. return regeneratorRuntime.wrap(function _callee6$(_context6) {
  19437. while (1) {
  19438. switch (_context6.prev = _context6.next) {
  19439. case 0:
  19440. lastDot = filename.lastIndexOf('.'); // if we can't determine extension, ignore it
  19441. if (!(lastDot >= 1)) {
  19442. _context6.next = 6;
  19443. break;
  19444. }
  19445. extension = filename.substr(lastDot + 1);
  19446. name = filename.substr(0, lastDot);
  19447. _context6.next = 6;
  19448. return new Promise(function (resolve, reject) {
  19449. var streamBuf = new StreamBuf();
  19450. streamBuf.on('finish', function () {
  19451. model.mediaIndex[filename] = model.media.length;
  19452. model.mediaIndex[name] = model.media.length;
  19453. var medium = {
  19454. type: 'image',
  19455. name: name,
  19456. extension: extension,
  19457. buffer: streamBuf.toBuffer()
  19458. };
  19459. model.media.push(medium);
  19460. resolve();
  19461. });
  19462. entry.on('error', function (error) {
  19463. reject(error);
  19464. });
  19465. entry.pipe(streamBuf);
  19466. });
  19467. case 6:
  19468. case "end":
  19469. return _context6.stop();
  19470. }
  19471. }
  19472. }, _callee6);
  19473. }));
  19474. function _processMediaEntry(_x17, _x18, _x19) {
  19475. return _processMediaEntry2.apply(this, arguments);
  19476. }
  19477. return _processMediaEntry;
  19478. }()
  19479. }, {
  19480. key: "_processDrawingEntry",
  19481. value: function () {
  19482. var _processDrawingEntry2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7(entry, model, name) {
  19483. var xform, drawing;
  19484. return regeneratorRuntime.wrap(function _callee7$(_context7) {
  19485. while (1) {
  19486. switch (_context7.prev = _context7.next) {
  19487. case 0:
  19488. xform = new DrawingXform();
  19489. _context7.next = 3;
  19490. return xform.parseStream(entry);
  19491. case 3:
  19492. drawing = _context7.sent;
  19493. model.drawings[name] = drawing;
  19494. case 5:
  19495. case "end":
  19496. return _context7.stop();
  19497. }
  19498. }
  19499. }, _callee7);
  19500. }));
  19501. function _processDrawingEntry(_x20, _x21, _x22) {
  19502. return _processDrawingEntry2.apply(this, arguments);
  19503. }
  19504. return _processDrawingEntry;
  19505. }()
  19506. }, {
  19507. key: "_processDrawingRelsEntry",
  19508. value: function () {
  19509. var _processDrawingRelsEntry2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8(entry, model, name) {
  19510. var xform, relationships;
  19511. return regeneratorRuntime.wrap(function _callee8$(_context8) {
  19512. while (1) {
  19513. switch (_context8.prev = _context8.next) {
  19514. case 0:
  19515. xform = new RelationshipsXform();
  19516. _context8.next = 3;
  19517. return xform.parseStream(entry);
  19518. case 3:
  19519. relationships = _context8.sent;
  19520. model.drawingRels[name] = relationships;
  19521. case 5:
  19522. case "end":
  19523. return _context8.stop();
  19524. }
  19525. }
  19526. }, _callee8);
  19527. }));
  19528. function _processDrawingRelsEntry(_x23, _x24, _x25) {
  19529. return _processDrawingRelsEntry2.apply(this, arguments);
  19530. }
  19531. return _processDrawingRelsEntry;
  19532. }()
  19533. }, {
  19534. key: "_processVmlDrawingEntry",
  19535. value: function () {
  19536. var _processVmlDrawingEntry2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9(entry, model, name) {
  19537. var xform, vmlDrawing;
  19538. return regeneratorRuntime.wrap(function _callee9$(_context9) {
  19539. while (1) {
  19540. switch (_context9.prev = _context9.next) {
  19541. case 0:
  19542. xform = new VmlNotesXform();
  19543. _context9.next = 3;
  19544. return xform.parseStream(entry);
  19545. case 3:
  19546. vmlDrawing = _context9.sent;
  19547. model.vmlDrawings["../drawings/".concat(name, ".vml")] = vmlDrawing;
  19548. case 5:
  19549. case "end":
  19550. return _context9.stop();
  19551. }
  19552. }
  19553. }, _callee9);
  19554. }));
  19555. function _processVmlDrawingEntry(_x26, _x27, _x28) {
  19556. return _processVmlDrawingEntry2.apply(this, arguments);
  19557. }
  19558. return _processVmlDrawingEntry;
  19559. }()
  19560. }, {
  19561. key: "_processThemeEntry",
  19562. value: function () {
  19563. var _processThemeEntry2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10(entry, model, name) {
  19564. return regeneratorRuntime.wrap(function _callee10$(_context10) {
  19565. while (1) {
  19566. switch (_context10.prev = _context10.next) {
  19567. case 0:
  19568. _context10.next = 2;
  19569. return new Promise(function (resolve, reject) {
  19570. // TODO: stream entry into buffer and store the xml in the model.themes[]
  19571. var stream = new StreamBuf();
  19572. entry.on('error', reject);
  19573. stream.on('error', reject);
  19574. stream.on('finish', function () {
  19575. model.themes[name] = stream.read().toString();
  19576. resolve();
  19577. });
  19578. entry.pipe(stream);
  19579. });
  19580. case 2:
  19581. case "end":
  19582. return _context10.stop();
  19583. }
  19584. }
  19585. }, _callee10);
  19586. }));
  19587. function _processThemeEntry(_x29, _x30, _x31) {
  19588. return _processThemeEntry2.apply(this, arguments);
  19589. }
  19590. return _processThemeEntry;
  19591. }()
  19592. /**
  19593. * @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
  19594. */
  19595. }, {
  19596. key: "createInputStream",
  19597. value: function createInputStream() {
  19598. 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');
  19599. }
  19600. }, {
  19601. key: "read",
  19602. value: function () {
  19603. var _read = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11(stream, options) {
  19604. var chunks, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk;
  19605. return regeneratorRuntime.wrap(function _callee11$(_context11) {
  19606. while (1) {
  19607. switch (_context11.prev = _context11.next) {
  19608. case 0:
  19609. // TODO: Remove once node v8 is deprecated
  19610. // Detect and upgrade old streams
  19611. if (!stream[Symbol.asyncIterator] && stream.pipe) {
  19612. stream = stream.pipe(new PassThrough());
  19613. }
  19614. chunks = [];
  19615. _iteratorNormalCompletion = true;
  19616. _didIteratorError = false;
  19617. _context11.prev = 4;
  19618. _iterator = _asyncIterator(stream);
  19619. case 6:
  19620. _context11.next = 8;
  19621. return _iterator.next();
  19622. case 8:
  19623. _step = _context11.sent;
  19624. _iteratorNormalCompletion = _step.done;
  19625. _context11.next = 12;
  19626. return _step.value;
  19627. case 12:
  19628. _value = _context11.sent;
  19629. if (_iteratorNormalCompletion) {
  19630. _context11.next = 19;
  19631. break;
  19632. }
  19633. chunk = _value;
  19634. chunks.push(chunk);
  19635. case 16:
  19636. _iteratorNormalCompletion = true;
  19637. _context11.next = 6;
  19638. break;
  19639. case 19:
  19640. _context11.next = 25;
  19641. break;
  19642. case 21:
  19643. _context11.prev = 21;
  19644. _context11.t0 = _context11["catch"](4);
  19645. _didIteratorError = true;
  19646. _iteratorError = _context11.t0;
  19647. case 25:
  19648. _context11.prev = 25;
  19649. _context11.prev = 26;
  19650. if (!(!_iteratorNormalCompletion && _iterator.return != null)) {
  19651. _context11.next = 30;
  19652. break;
  19653. }
  19654. _context11.next = 30;
  19655. return _iterator.return();
  19656. case 30:
  19657. _context11.prev = 30;
  19658. if (!_didIteratorError) {
  19659. _context11.next = 33;
  19660. break;
  19661. }
  19662. throw _iteratorError;
  19663. case 33:
  19664. return _context11.finish(30);
  19665. case 34:
  19666. return _context11.finish(25);
  19667. case 35:
  19668. return _context11.abrupt("return", this.load(Buffer.concat(chunks), options));
  19669. case 36:
  19670. case "end":
  19671. return _context11.stop();
  19672. }
  19673. }
  19674. }, _callee11, this, [[4, 21, 25, 35], [26,, 30, 34]]);
  19675. }));
  19676. function read(_x32, _x33) {
  19677. return _read.apply(this, arguments);
  19678. }
  19679. return read;
  19680. }()
  19681. }, {
  19682. key: "load",
  19683. value: function () {
  19684. var _load = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee12(data, options) {
  19685. var buffer, model, zip, _i, _Object$values, entry, entryName, stream, content, chunkSize, i, workbook, appXform, appProperties, coreXform, coreProperties, match;
  19686. return regeneratorRuntime.wrap(function _callee12$(_context12) {
  19687. while (1) {
  19688. switch (_context12.prev = _context12.next) {
  19689. case 0:
  19690. if (options && options.base64) {
  19691. buffer = Buffer.from(data.toString(), 'base64');
  19692. } else {
  19693. buffer = data;
  19694. }
  19695. model = {
  19696. worksheets: [],
  19697. worksheetHash: {},
  19698. worksheetRels: [],
  19699. themes: {},
  19700. media: [],
  19701. mediaIndex: {},
  19702. drawings: {},
  19703. drawingRels: {},
  19704. comments: {},
  19705. tables: {},
  19706. vmlDrawings: {}
  19707. };
  19708. _context12.next = 4;
  19709. return JSZip.loadAsync(buffer);
  19710. case 4:
  19711. zip = _context12.sent;
  19712. _i = 0, _Object$values = Object.values(zip.files);
  19713. case 6:
  19714. if (!(_i < _Object$values.length)) {
  19715. _context12.next = 126;
  19716. break;
  19717. }
  19718. entry = _Object$values[_i];
  19719. if (entry.dir) {
  19720. _context12.next = 123;
  19721. break;
  19722. }
  19723. entryName = entry.name;
  19724. if (entryName[0] === '/') {
  19725. entryName = entryName.substr(1);
  19726. }
  19727. stream = void 0;
  19728. if (!(entryName.match(/xl\/media\//) || // themes are not parsed as stream
  19729. entryName.match(/xl\/theme\/([a-zA-Z0-9]+)[.]xml/))) {
  19730. _context12.next = 21;
  19731. break;
  19732. }
  19733. stream = new PassThrough();
  19734. _context12.t0 = stream;
  19735. _context12.next = 17;
  19736. return entry.async('nodebuffer');
  19737. case 17:
  19738. _context12.t1 = _context12.sent;
  19739. _context12.t0.write.call(_context12.t0, _context12.t1);
  19740. _context12.next = 36;
  19741. break;
  19742. case 21:
  19743. // use object mode to avoid buffer-string convention
  19744. stream = new PassThrough({
  19745. writableObjectMode: true,
  19746. readableObjectMode: true
  19747. });
  19748. content = void 0; // https://www.npmjs.com/package/process
  19749. if (!process.browser) {
  19750. _context12.next = 31;
  19751. break;
  19752. }
  19753. _context12.t2 = bufferToString;
  19754. _context12.next = 27;
  19755. return entry.async('nodebuffer');
  19756. case 27:
  19757. _context12.t3 = _context12.sent;
  19758. content = (0, _context12.t2)(_context12.t3);
  19759. _context12.next = 34;
  19760. break;
  19761. case 31:
  19762. _context12.next = 33;
  19763. return entry.async('string');
  19764. case 33:
  19765. content = _context12.sent;
  19766. case 34:
  19767. chunkSize = 16 * 1024;
  19768. for (i = 0; i < content.length; i += chunkSize) {
  19769. stream.write(content.substring(i, i + chunkSize));
  19770. }
  19771. case 36:
  19772. stream.end();
  19773. _context12.t4 = entryName;
  19774. _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;
  19775. break;
  19776. case 40:
  19777. _context12.next = 42;
  19778. return this.parseRels(stream);
  19779. case 42:
  19780. model.globalRels = _context12.sent;
  19781. return _context12.abrupt("break", 123);
  19782. case 44:
  19783. _context12.next = 46;
  19784. return this.parseWorkbook(stream);
  19785. case 46:
  19786. workbook = _context12.sent;
  19787. model.sheets = workbook.sheets;
  19788. model.definedNames = workbook.definedNames;
  19789. model.views = workbook.views;
  19790. model.properties = workbook.properties;
  19791. model.calcProperties = workbook.calcProperties;
  19792. return _context12.abrupt("break", 123);
  19793. case 53:
  19794. _context12.next = 55;
  19795. return this.parseRels(stream);
  19796. case 55:
  19797. model.workbookRels = _context12.sent;
  19798. return _context12.abrupt("break", 123);
  19799. case 57:
  19800. model.sharedStrings = new SharedStringsXform();
  19801. _context12.next = 60;
  19802. return model.sharedStrings.parseStream(stream);
  19803. case 60:
  19804. return _context12.abrupt("break", 123);
  19805. case 61:
  19806. model.styles = new StylesXform();
  19807. _context12.next = 64;
  19808. return model.styles.parseStream(stream);
  19809. case 64:
  19810. return _context12.abrupt("break", 123);
  19811. case 65:
  19812. appXform = new AppXform();
  19813. _context12.next = 68;
  19814. return appXform.parseStream(stream);
  19815. case 68:
  19816. appProperties = _context12.sent;
  19817. model.company = appProperties.company;
  19818. model.manager = appProperties.manager;
  19819. return _context12.abrupt("break", 123);
  19820. case 72:
  19821. coreXform = new CoreXform();
  19822. _context12.next = 75;
  19823. return coreXform.parseStream(stream);
  19824. case 75:
  19825. coreProperties = _context12.sent;
  19826. Object.assign(model, coreProperties);
  19827. return _context12.abrupt("break", 123);
  19828. case 78:
  19829. match = entryName.match(/xl\/worksheets\/sheet(\d+)[.]xml/);
  19830. if (!match) {
  19831. _context12.next = 83;
  19832. break;
  19833. }
  19834. _context12.next = 82;
  19835. return this._processWorksheetEntry(stream, model, match[1], options, entryName);
  19836. case 82:
  19837. return _context12.abrupt("break", 123);
  19838. case 83:
  19839. match = entryName.match(/xl\/worksheets\/_rels\/sheet(\d+)[.]xml.rels/);
  19840. if (!match) {
  19841. _context12.next = 88;
  19842. break;
  19843. }
  19844. _context12.next = 87;
  19845. return this._processWorksheetRelsEntry(stream, model, match[1]);
  19846. case 87:
  19847. return _context12.abrupt("break", 123);
  19848. case 88:
  19849. match = entryName.match(/xl\/theme\/([a-zA-Z0-9]+)[.]xml/);
  19850. if (!match) {
  19851. _context12.next = 93;
  19852. break;
  19853. }
  19854. _context12.next = 92;
  19855. return this._processThemeEntry(stream, model, match[1]);
  19856. case 92:
  19857. return _context12.abrupt("break", 123);
  19858. case 93:
  19859. match = entryName.match(/xl\/media\/([a-zA-Z0-9]+[.][a-zA-Z0-9]{3,4})$/);
  19860. if (!match) {
  19861. _context12.next = 98;
  19862. break;
  19863. }
  19864. _context12.next = 97;
  19865. return this._processMediaEntry(stream, model, match[1]);
  19866. case 97:
  19867. return _context12.abrupt("break", 123);
  19868. case 98:
  19869. match = entryName.match(/xl\/drawings\/([a-zA-Z0-9]+)[.]xml/);
  19870. if (!match) {
  19871. _context12.next = 103;
  19872. break;
  19873. }
  19874. _context12.next = 102;
  19875. return this._processDrawingEntry(stream, model, match[1]);
  19876. case 102:
  19877. return _context12.abrupt("break", 123);
  19878. case 103:
  19879. match = entryName.match(/xl\/(comments\d+)[.]xml/);
  19880. if (!match) {
  19881. _context12.next = 108;
  19882. break;
  19883. }
  19884. _context12.next = 107;
  19885. return this._processCommentEntry(stream, model, match[1]);
  19886. case 107:
  19887. return _context12.abrupt("break", 123);
  19888. case 108:
  19889. match = entryName.match(/xl\/tables\/(table\d+)[.]xml/);
  19890. if (!match) {
  19891. _context12.next = 113;
  19892. break;
  19893. }
  19894. _context12.next = 112;
  19895. return this._processTableEntry(stream, model, match[1]);
  19896. case 112:
  19897. return _context12.abrupt("break", 123);
  19898. case 113:
  19899. match = entryName.match(/xl\/drawings\/_rels\/([a-zA-Z0-9]+)[.]xml[.]rels/);
  19900. if (!match) {
  19901. _context12.next = 118;
  19902. break;
  19903. }
  19904. _context12.next = 117;
  19905. return this._processDrawingRelsEntry(stream, model, match[1]);
  19906. case 117:
  19907. return _context12.abrupt("break", 123);
  19908. case 118:
  19909. match = entryName.match(/xl\/drawings\/(vmlDrawing\d+)[.]vml/);
  19910. if (!match) {
  19911. _context12.next = 123;
  19912. break;
  19913. }
  19914. _context12.next = 122;
  19915. return this._processVmlDrawingEntry(stream, model, match[1]);
  19916. case 122:
  19917. return _context12.abrupt("break", 123);
  19918. case 123:
  19919. _i++;
  19920. _context12.next = 6;
  19921. break;
  19922. case 126:
  19923. this.reconcile(model, options); // apply model
  19924. this.workbook.model = model;
  19925. return _context12.abrupt("return", this.workbook);
  19926. case 129:
  19927. case "end":
  19928. return _context12.stop();
  19929. }
  19930. }
  19931. }, _callee12, this);
  19932. }));
  19933. function load(_x34, _x35) {
  19934. return _load.apply(this, arguments);
  19935. }
  19936. return load;
  19937. }() // =========================================================================
  19938. // Write
  19939. }, {
  19940. key: "addMedia",
  19941. value: function () {
  19942. var _addMedia = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee14(zip, model) {
  19943. return regeneratorRuntime.wrap(function _callee14$(_context14) {
  19944. while (1) {
  19945. switch (_context14.prev = _context14.next) {
  19946. case 0:
  19947. _context14.next = 2;
  19948. return Promise.all(model.media.map( /*#__PURE__*/function () {
  19949. var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee13(medium) {
  19950. var filename, data, dataimg64, content;
  19951. return regeneratorRuntime.wrap(function _callee13$(_context13) {
  19952. while (1) {
  19953. switch (_context13.prev = _context13.next) {
  19954. case 0:
  19955. if (!(medium.type === 'image')) {
  19956. _context13.next = 13;
  19957. break;
  19958. }
  19959. filename = "xl/media/".concat(medium.name, ".").concat(medium.extension);
  19960. if (!medium.filename) {
  19961. _context13.next = 7;
  19962. break;
  19963. }
  19964. _context13.next = 5;
  19965. return fsReadFileAsync(medium.filename);
  19966. case 5:
  19967. data = _context13.sent;
  19968. return _context13.abrupt("return", zip.append(data, {
  19969. name: filename
  19970. }));
  19971. case 7:
  19972. if (!medium.buffer) {
  19973. _context13.next = 9;
  19974. break;
  19975. }
  19976. return _context13.abrupt("return", zip.append(medium.buffer, {
  19977. name: filename
  19978. }));
  19979. case 9:
  19980. if (!medium.base64) {
  19981. _context13.next = 13;
  19982. break;
  19983. }
  19984. dataimg64 = medium.base64;
  19985. content = dataimg64.substring(dataimg64.indexOf(',') + 1);
  19986. return _context13.abrupt("return", zip.append(content, {
  19987. name: filename,
  19988. base64: true
  19989. }));
  19990. case 13:
  19991. throw new Error('Unsupported media');
  19992. case 14:
  19993. case "end":
  19994. return _context13.stop();
  19995. }
  19996. }
  19997. }, _callee13);
  19998. }));
  19999. return function (_x38) {
  20000. return _ref.apply(this, arguments);
  20001. };
  20002. }()));
  20003. case 2:
  20004. case "end":
  20005. return _context14.stop();
  20006. }
  20007. }
  20008. }, _callee14);
  20009. }));
  20010. function addMedia(_x36, _x37) {
  20011. return _addMedia.apply(this, arguments);
  20012. }
  20013. return addMedia;
  20014. }()
  20015. }, {
  20016. key: "addDrawings",
  20017. value: function addDrawings(zip, model) {
  20018. var drawingXform = new DrawingXform();
  20019. var relsXform = new RelationshipsXform();
  20020. model.worksheets.forEach(function (worksheet) {
  20021. var drawing = worksheet.drawing;
  20022. if (drawing) {
  20023. drawingXform.prepare(drawing, {});
  20024. var xml = drawingXform.toXml(drawing);
  20025. zip.append(xml, {
  20026. name: "xl/drawings/".concat(drawing.name, ".xml")
  20027. });
  20028. xml = relsXform.toXml(drawing.rels);
  20029. zip.append(xml, {
  20030. name: "xl/drawings/_rels/".concat(drawing.name, ".xml.rels")
  20031. });
  20032. }
  20033. });
  20034. }
  20035. }, {
  20036. key: "addTables",
  20037. value: function addTables(zip, model) {
  20038. var tableXform = new TableXform();
  20039. model.worksheets.forEach(function (worksheet) {
  20040. var tables = worksheet.tables;
  20041. tables.forEach(function (table) {
  20042. tableXform.prepare(table, {});
  20043. var tableXml = tableXform.toXml(table);
  20044. zip.append(tableXml, {
  20045. name: "xl/tables/".concat(table.target)
  20046. });
  20047. });
  20048. });
  20049. }
  20050. }, {
  20051. key: "addContentTypes",
  20052. value: function () {
  20053. var _addContentTypes = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee15(zip, model) {
  20054. var xform, xml;
  20055. return regeneratorRuntime.wrap(function _callee15$(_context15) {
  20056. while (1) {
  20057. switch (_context15.prev = _context15.next) {
  20058. case 0:
  20059. xform = new ContentTypesXform();
  20060. xml = xform.toXml(model);
  20061. zip.append(xml, {
  20062. name: '[Content_Types].xml'
  20063. });
  20064. case 3:
  20065. case "end":
  20066. return _context15.stop();
  20067. }
  20068. }
  20069. }, _callee15);
  20070. }));
  20071. function addContentTypes(_x39, _x40) {
  20072. return _addContentTypes.apply(this, arguments);
  20073. }
  20074. return addContentTypes;
  20075. }()
  20076. }, {
  20077. key: "addApp",
  20078. value: function () {
  20079. var _addApp = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee16(zip, model) {
  20080. var xform, xml;
  20081. return regeneratorRuntime.wrap(function _callee16$(_context16) {
  20082. while (1) {
  20083. switch (_context16.prev = _context16.next) {
  20084. case 0:
  20085. xform = new AppXform();
  20086. xml = xform.toXml(model);
  20087. zip.append(xml, {
  20088. name: 'docProps/app.xml'
  20089. });
  20090. case 3:
  20091. case "end":
  20092. return _context16.stop();
  20093. }
  20094. }
  20095. }, _callee16);
  20096. }));
  20097. function addApp(_x41, _x42) {
  20098. return _addApp.apply(this, arguments);
  20099. }
  20100. return addApp;
  20101. }()
  20102. }, {
  20103. key: "addCore",
  20104. value: function () {
  20105. var _addCore = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee17(zip, model) {
  20106. var coreXform;
  20107. return regeneratorRuntime.wrap(function _callee17$(_context17) {
  20108. while (1) {
  20109. switch (_context17.prev = _context17.next) {
  20110. case 0:
  20111. coreXform = new CoreXform();
  20112. zip.append(coreXform.toXml(model), {
  20113. name: 'docProps/core.xml'
  20114. });
  20115. case 2:
  20116. case "end":
  20117. return _context17.stop();
  20118. }
  20119. }
  20120. }, _callee17);
  20121. }));
  20122. function addCore(_x43, _x44) {
  20123. return _addCore.apply(this, arguments);
  20124. }
  20125. return addCore;
  20126. }()
  20127. }, {
  20128. key: "addThemes",
  20129. value: function () {
  20130. var _addThemes = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee18(zip, model) {
  20131. var themes;
  20132. return regeneratorRuntime.wrap(function _callee18$(_context18) {
  20133. while (1) {
  20134. switch (_context18.prev = _context18.next) {
  20135. case 0:
  20136. themes = model.themes || {
  20137. theme1: theme1Xml
  20138. };
  20139. Object.keys(themes).forEach(function (name) {
  20140. var xml = themes[name];
  20141. var path = "xl/theme/".concat(name, ".xml");
  20142. zip.append(xml, {
  20143. name: path
  20144. });
  20145. });
  20146. case 2:
  20147. case "end":
  20148. return _context18.stop();
  20149. }
  20150. }
  20151. }, _callee18);
  20152. }));
  20153. function addThemes(_x45, _x46) {
  20154. return _addThemes.apply(this, arguments);
  20155. }
  20156. return addThemes;
  20157. }()
  20158. }, {
  20159. key: "addOfficeRels",
  20160. value: function () {
  20161. var _addOfficeRels = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee19(zip) {
  20162. var xform, xml;
  20163. return regeneratorRuntime.wrap(function _callee19$(_context19) {
  20164. while (1) {
  20165. switch (_context19.prev = _context19.next) {
  20166. case 0:
  20167. xform = new RelationshipsXform();
  20168. xml = xform.toXml([{
  20169. Id: 'rId1',
  20170. Type: XLSX.RelType.OfficeDocument,
  20171. Target: 'xl/workbook.xml'
  20172. }, {
  20173. Id: 'rId2',
  20174. Type: XLSX.RelType.CoreProperties,
  20175. Target: 'docProps/core.xml'
  20176. }, {
  20177. Id: 'rId3',
  20178. Type: XLSX.RelType.ExtenderProperties,
  20179. Target: 'docProps/app.xml'
  20180. }]);
  20181. zip.append(xml, {
  20182. name: '_rels/.rels'
  20183. });
  20184. case 3:
  20185. case "end":
  20186. return _context19.stop();
  20187. }
  20188. }
  20189. }, _callee19);
  20190. }));
  20191. function addOfficeRels(_x47) {
  20192. return _addOfficeRels.apply(this, arguments);
  20193. }
  20194. return addOfficeRels;
  20195. }()
  20196. }, {
  20197. key: "addWorkbookRels",
  20198. value: function () {
  20199. var _addWorkbookRels = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee20(zip, model) {
  20200. var count, relationships, xform, xml;
  20201. return regeneratorRuntime.wrap(function _callee20$(_context20) {
  20202. while (1) {
  20203. switch (_context20.prev = _context20.next) {
  20204. case 0:
  20205. count = 1;
  20206. relationships = [{
  20207. Id: "rId".concat(count++),
  20208. Type: XLSX.RelType.Styles,
  20209. Target: 'styles.xml'
  20210. }, {
  20211. Id: "rId".concat(count++),
  20212. Type: XLSX.RelType.Theme,
  20213. Target: 'theme/theme1.xml'
  20214. }];
  20215. if (model.sharedStrings.count) {
  20216. relationships.push({
  20217. Id: "rId".concat(count++),
  20218. Type: XLSX.RelType.SharedStrings,
  20219. Target: 'sharedStrings.xml'
  20220. });
  20221. }
  20222. model.worksheets.forEach(function (worksheet) {
  20223. worksheet.rId = "rId".concat(count++);
  20224. relationships.push({
  20225. Id: worksheet.rId,
  20226. Type: XLSX.RelType.Worksheet,
  20227. Target: "worksheets/sheet".concat(worksheet.id, ".xml")
  20228. });
  20229. });
  20230. xform = new RelationshipsXform();
  20231. xml = xform.toXml(relationships);
  20232. zip.append(xml, {
  20233. name: 'xl/_rels/workbook.xml.rels'
  20234. });
  20235. case 7:
  20236. case "end":
  20237. return _context20.stop();
  20238. }
  20239. }
  20240. }, _callee20);
  20241. }));
  20242. function addWorkbookRels(_x48, _x49) {
  20243. return _addWorkbookRels.apply(this, arguments);
  20244. }
  20245. return addWorkbookRels;
  20246. }()
  20247. }, {
  20248. key: "addSharedStrings",
  20249. value: function () {
  20250. var _addSharedStrings = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee21(zip, model) {
  20251. return regeneratorRuntime.wrap(function _callee21$(_context21) {
  20252. while (1) {
  20253. switch (_context21.prev = _context21.next) {
  20254. case 0:
  20255. if (model.sharedStrings && model.sharedStrings.count) {
  20256. zip.append(model.sharedStrings.xml, {
  20257. name: 'xl/sharedStrings.xml'
  20258. });
  20259. }
  20260. case 1:
  20261. case "end":
  20262. return _context21.stop();
  20263. }
  20264. }
  20265. }, _callee21);
  20266. }));
  20267. function addSharedStrings(_x50, _x51) {
  20268. return _addSharedStrings.apply(this, arguments);
  20269. }
  20270. return addSharedStrings;
  20271. }()
  20272. }, {
  20273. key: "addStyles",
  20274. value: function () {
  20275. var _addStyles = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee22(zip, model) {
  20276. var xml;
  20277. return regeneratorRuntime.wrap(function _callee22$(_context22) {
  20278. while (1) {
  20279. switch (_context22.prev = _context22.next) {
  20280. case 0:
  20281. xml = model.styles.xml;
  20282. if (xml) {
  20283. zip.append(xml, {
  20284. name: 'xl/styles.xml'
  20285. });
  20286. }
  20287. case 2:
  20288. case "end":
  20289. return _context22.stop();
  20290. }
  20291. }
  20292. }, _callee22);
  20293. }));
  20294. function addStyles(_x52, _x53) {
  20295. return _addStyles.apply(this, arguments);
  20296. }
  20297. return addStyles;
  20298. }()
  20299. }, {
  20300. key: "addWorkbook",
  20301. value: function () {
  20302. var _addWorkbook = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee23(zip, model) {
  20303. var xform;
  20304. return regeneratorRuntime.wrap(function _callee23$(_context23) {
  20305. while (1) {
  20306. switch (_context23.prev = _context23.next) {
  20307. case 0:
  20308. xform = new WorkbookXform();
  20309. zip.append(xform.toXml(model), {
  20310. name: 'xl/workbook.xml'
  20311. });
  20312. case 2:
  20313. case "end":
  20314. return _context23.stop();
  20315. }
  20316. }
  20317. }, _callee23);
  20318. }));
  20319. function addWorkbook(_x54, _x55) {
  20320. return _addWorkbook.apply(this, arguments);
  20321. }
  20322. return addWorkbook;
  20323. }()
  20324. }, {
  20325. key: "addWorksheets",
  20326. value: function () {
  20327. var _addWorksheets = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee24(zip, model) {
  20328. var worksheetXform, relationshipsXform, commentsXform, vmlNotesXform;
  20329. return regeneratorRuntime.wrap(function _callee24$(_context24) {
  20330. while (1) {
  20331. switch (_context24.prev = _context24.next) {
  20332. case 0:
  20333. // preparation phase
  20334. worksheetXform = new WorksheetXform();
  20335. relationshipsXform = new RelationshipsXform();
  20336. commentsXform = new CommentsXform();
  20337. vmlNotesXform = new VmlNotesXform(); // write sheets
  20338. model.worksheets.forEach(function (worksheet) {
  20339. var xmlStream = new XmlStream();
  20340. worksheetXform.render(xmlStream, worksheet);
  20341. zip.append(xmlStream.xml, {
  20342. name: "xl/worksheets/sheet".concat(worksheet.id, ".xml")
  20343. });
  20344. if (worksheet.rels && worksheet.rels.length) {
  20345. xmlStream = new XmlStream();
  20346. relationshipsXform.render(xmlStream, worksheet.rels);
  20347. zip.append(xmlStream.xml, {
  20348. name: "xl/worksheets/_rels/sheet".concat(worksheet.id, ".xml.rels")
  20349. });
  20350. }
  20351. if (worksheet.comments.length > 0) {
  20352. xmlStream = new XmlStream();
  20353. commentsXform.render(xmlStream, worksheet);
  20354. zip.append(xmlStream.xml, {
  20355. name: "xl/comments".concat(worksheet.id, ".xml")
  20356. });
  20357. xmlStream = new XmlStream();
  20358. vmlNotesXform.render(xmlStream, worksheet);
  20359. zip.append(xmlStream.xml, {
  20360. name: "xl/drawings/vmlDrawing".concat(worksheet.id, ".vml")
  20361. });
  20362. }
  20363. });
  20364. case 5:
  20365. case "end":
  20366. return _context24.stop();
  20367. }
  20368. }
  20369. }, _callee24);
  20370. }));
  20371. function addWorksheets(_x56, _x57) {
  20372. return _addWorksheets.apply(this, arguments);
  20373. }
  20374. return addWorksheets;
  20375. }()
  20376. }, {
  20377. key: "_finalize",
  20378. value: function _finalize(zip) {
  20379. var _this = this;
  20380. return new Promise(function (resolve, reject) {
  20381. zip.on('finish', function () {
  20382. resolve(_this);
  20383. });
  20384. zip.on('error', reject);
  20385. zip.finalize();
  20386. });
  20387. }
  20388. }, {
  20389. key: "prepareModel",
  20390. value: function prepareModel(model, options) {
  20391. // ensure following properties have sane values
  20392. model.creator = model.creator || 'ExcelJS';
  20393. model.lastModifiedBy = model.lastModifiedBy || 'ExcelJS';
  20394. model.created = model.created || new Date();
  20395. model.modified = model.modified || new Date();
  20396. model.useSharedStrings = options.useSharedStrings !== undefined ? options.useSharedStrings : true;
  20397. model.useStyles = options.useStyles !== undefined ? options.useStyles : true; // Manage the shared strings
  20398. model.sharedStrings = new SharedStringsXform(); // add a style manager to handle cell formats, fonts, etc.
  20399. model.styles = model.useStyles ? new StylesXform(true) : new StylesXform.Mock(); // prepare all of the things before the render
  20400. var workbookXform = new WorkbookXform();
  20401. var worksheetXform = new WorksheetXform();
  20402. workbookXform.prepare(model);
  20403. var worksheetOptions = {
  20404. sharedStrings: model.sharedStrings,
  20405. styles: model.styles,
  20406. date1904: model.properties.date1904,
  20407. drawingsCount: 0,
  20408. media: model.media
  20409. };
  20410. worksheetOptions.drawings = model.drawings = [];
  20411. worksheetOptions.commentRefs = model.commentRefs = [];
  20412. var tableCount = 0;
  20413. model.tables = [];
  20414. model.worksheets.forEach(function (worksheet) {
  20415. // assign unique filenames to tables
  20416. worksheet.tables.forEach(function (table) {
  20417. tableCount++;
  20418. table.target = "table".concat(tableCount, ".xml");
  20419. table.id = tableCount;
  20420. model.tables.push(table);
  20421. });
  20422. worksheetXform.prepare(worksheet, worksheetOptions);
  20423. }); // TODO: workbook drawing list
  20424. }
  20425. }, {
  20426. key: "write",
  20427. value: function () {
  20428. var _write = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee25(stream, options) {
  20429. var model, zip;
  20430. return regeneratorRuntime.wrap(function _callee25$(_context25) {
  20431. while (1) {
  20432. switch (_context25.prev = _context25.next) {
  20433. case 0:
  20434. options = options || {};
  20435. model = this.workbook.model;
  20436. zip = new ZipStream.ZipWriter(options.zip);
  20437. zip.pipe(stream);
  20438. this.prepareModel(model, options); // render
  20439. _context25.next = 7;
  20440. return this.addContentTypes(zip, model);
  20441. case 7:
  20442. _context25.next = 9;
  20443. return this.addOfficeRels(zip, model);
  20444. case 9:
  20445. _context25.next = 11;
  20446. return this.addWorkbookRels(zip, model);
  20447. case 11:
  20448. _context25.next = 13;
  20449. return this.addWorksheets(zip, model);
  20450. case 13:
  20451. _context25.next = 15;
  20452. return this.addSharedStrings(zip, model);
  20453. case 15:
  20454. _context25.next = 17;
  20455. return this.addDrawings(zip, model);
  20456. case 17:
  20457. _context25.next = 19;
  20458. return this.addTables(zip, model);
  20459. case 19:
  20460. _context25.next = 21;
  20461. return Promise.all([this.addThemes(zip, model), this.addStyles(zip, model)]);
  20462. case 21:
  20463. _context25.next = 23;
  20464. return this.addMedia(zip, model);
  20465. case 23:
  20466. _context25.next = 25;
  20467. return Promise.all([this.addApp(zip, model), this.addCore(zip, model)]);
  20468. case 25:
  20469. _context25.next = 27;
  20470. return this.addWorkbook(zip, model);
  20471. case 27:
  20472. return _context25.abrupt("return", this._finalize(zip));
  20473. case 28:
  20474. case "end":
  20475. return _context25.stop();
  20476. }
  20477. }
  20478. }, _callee25, this);
  20479. }));
  20480. function write(_x58, _x59) {
  20481. return _write.apply(this, arguments);
  20482. }
  20483. return write;
  20484. }()
  20485. }, {
  20486. key: "writeFile",
  20487. value: function writeFile(filename, options) {
  20488. var _this2 = this;
  20489. var stream = fs.createWriteStream(filename);
  20490. return new Promise(function (resolve, reject) {
  20491. stream.on('finish', function () {
  20492. resolve();
  20493. });
  20494. stream.on('error', function (error) {
  20495. reject(error);
  20496. });
  20497. _this2.write(stream, options).then(function () {
  20498. stream.end();
  20499. });
  20500. });
  20501. }
  20502. }, {
  20503. key: "writeBuffer",
  20504. value: function () {
  20505. var _writeBuffer = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee26(options) {
  20506. var stream;
  20507. return regeneratorRuntime.wrap(function _callee26$(_context26) {
  20508. while (1) {
  20509. switch (_context26.prev = _context26.next) {
  20510. case 0:
  20511. stream = new StreamBuf();
  20512. _context26.next = 3;
  20513. return this.write(stream, options);
  20514. case 3:
  20515. return _context26.abrupt("return", stream.read());
  20516. case 4:
  20517. case "end":
  20518. return _context26.stop();
  20519. }
  20520. }
  20521. }, _callee26, this);
  20522. }));
  20523. function writeBuffer(_x60) {
  20524. return _writeBuffer.apply(this, arguments);
  20525. }
  20526. return writeBuffer;
  20527. }()
  20528. }]);
  20529. return XLSX;
  20530. }();
  20531. XLSX.RelType = require('./rel-type');
  20532. module.exports = XLSX;
  20533. }).call(this,require('_process'),require("buffer").Buffer)
  20534. },{"../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":358,"buffer":216,"fs":215,"jszip":290,"readable-stream":382}],142:[function(require,module,exports){
  20535. "use strict";
  20536. /* eslint-disable */
  20537. 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>';
  20538. },{}],143:[function(require,module,exports){
  20539. (function (Buffer){
  20540. "use strict";
  20541. 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); }
  20542. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  20543. 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); } }
  20544. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  20545. 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); }
  20546. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  20547. 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); }; }
  20548. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  20549. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  20550. 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; } }
  20551. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  20552. Object.defineProperty(exports, "__esModule", {
  20553. value: true
  20554. });
  20555. exports.CsvFormatterStream = void 0;
  20556. var stream_1 = require("stream");
  20557. var formatter_1 = require("./formatter");
  20558. var CsvFormatterStream = /*#__PURE__*/function (_stream_1$Transform) {
  20559. _inherits(CsvFormatterStream, _stream_1$Transform);
  20560. var _super = _createSuper(CsvFormatterStream);
  20561. function CsvFormatterStream(formatterOptions) {
  20562. var _this;
  20563. _classCallCheck(this, CsvFormatterStream);
  20564. _this = _super.call(this, {
  20565. writableObjectMode: formatterOptions.objectMode
  20566. });
  20567. _this.hasWrittenBOM = false;
  20568. _this.formatterOptions = formatterOptions;
  20569. _this.rowFormatter = new formatter_1.RowFormatter(formatterOptions); // if writeBOM is false then set to true
  20570. // if writeBOM is true then set to false by default so it is written out
  20571. _this.hasWrittenBOM = !formatterOptions.writeBOM;
  20572. return _this;
  20573. }
  20574. _createClass(CsvFormatterStream, [{
  20575. key: "transform",
  20576. value: function transform(transformFunction) {
  20577. this.rowFormatter.rowTransform = transformFunction;
  20578. return this;
  20579. }
  20580. }, {
  20581. key: "_transform",
  20582. value: function _transform(row, encoding, cb) {
  20583. var _this2 = this;
  20584. var cbCalled = false;
  20585. try {
  20586. if (!this.hasWrittenBOM) {
  20587. this.push(this.formatterOptions.BOM);
  20588. this.hasWrittenBOM = true;
  20589. }
  20590. this.rowFormatter.format(row, function (err, rows) {
  20591. if (err) {
  20592. cbCalled = true;
  20593. return cb(err);
  20594. }
  20595. if (rows) {
  20596. rows.forEach(function (r) {
  20597. _this2.push(Buffer.from(r, 'utf8'));
  20598. });
  20599. }
  20600. cbCalled = true;
  20601. return cb();
  20602. });
  20603. } catch (e) {
  20604. if (cbCalled) {
  20605. throw e;
  20606. }
  20607. cb(e);
  20608. }
  20609. }
  20610. }, {
  20611. key: "_flush",
  20612. value: function _flush(cb) {
  20613. var _this3 = this;
  20614. this.rowFormatter.finish(function (err, rows) {
  20615. if (err) {
  20616. return cb(err);
  20617. }
  20618. if (rows) {
  20619. rows.forEach(function (r) {
  20620. _this3.push(Buffer.from(r, 'utf8'));
  20621. });
  20622. }
  20623. return cb();
  20624. });
  20625. }
  20626. }]);
  20627. return CsvFormatterStream;
  20628. }(stream_1.Transform);
  20629. exports.CsvFormatterStream = CsvFormatterStream;
  20630. }).call(this,require("buffer").Buffer)
  20631. },{"./formatter":147,"buffer":216,"stream":396}],144:[function(require,module,exports){
  20632. "use strict";
  20633. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  20634. Object.defineProperty(exports, "__esModule", {
  20635. value: true
  20636. });
  20637. exports.FormatterOptions = void 0;
  20638. var FormatterOptions = function FormatterOptions() {
  20639. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  20640. _classCallCheck(this, FormatterOptions);
  20641. var _a;
  20642. this.objectMode = true;
  20643. this.delimiter = ',';
  20644. this.rowDelimiter = '\n';
  20645. this.quote = '"';
  20646. this.escape = this.quote;
  20647. this.quoteColumns = false;
  20648. this.quoteHeaders = this.quoteColumns;
  20649. this.headers = null;
  20650. this.includeEndRowDelimiter = false;
  20651. this.writeBOM = false;
  20652. this.BOM = "\uFEFF";
  20653. this.alwaysWriteHeaders = false;
  20654. Object.assign(this, opts || {});
  20655. if (typeof (opts === null || opts === void 0 ? void 0 : opts.quoteHeaders) === 'undefined') {
  20656. this.quoteHeaders = this.quoteColumns;
  20657. }
  20658. if ((opts === null || opts === void 0 ? void 0 : opts.quote) === true) {
  20659. this.quote = '"';
  20660. } else if ((opts === null || opts === void 0 ? void 0 : opts.quote) === false) {
  20661. this.quote = '';
  20662. }
  20663. if (typeof (opts === null || opts === void 0 ? void 0 : opts.escape) !== 'string') {
  20664. this.escape = this.quote;
  20665. }
  20666. this.shouldWriteHeaders = !!this.headers && ((_a = opts.writeHeaders) !== null && _a !== void 0 ? _a : true);
  20667. this.headers = Array.isArray(this.headers) ? this.headers : null;
  20668. this.escapedQuote = "".concat(this.escape).concat(this.quote);
  20669. };
  20670. exports.FormatterOptions = FormatterOptions;
  20671. },{}],145:[function(require,module,exports){
  20672. "use strict";
  20673. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  20674. 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); } }
  20675. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  20676. var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
  20677. return mod && mod.__esModule ? mod : {
  20678. "default": mod
  20679. };
  20680. };
  20681. Object.defineProperty(exports, "__esModule", {
  20682. value: true
  20683. });
  20684. exports.FieldFormatter = void 0;
  20685. var lodash_isboolean_1 = __importDefault(require("lodash.isboolean"));
  20686. var lodash_isnil_1 = __importDefault(require("lodash.isnil"));
  20687. var lodash_escaperegexp_1 = __importDefault(require("lodash.escaperegexp"));
  20688. var FieldFormatter = /*#__PURE__*/function () {
  20689. function FieldFormatter(formatterOptions) {
  20690. _classCallCheck(this, FieldFormatter);
  20691. this._headers = null;
  20692. this.formatterOptions = formatterOptions;
  20693. if (formatterOptions.headers !== null) {
  20694. this.headers = formatterOptions.headers;
  20695. }
  20696. this.REPLACE_REGEXP = new RegExp(formatterOptions.quote, 'g');
  20697. var escapePattern = "[".concat(formatterOptions.delimiter).concat(lodash_escaperegexp_1.default(formatterOptions.rowDelimiter), "|\r|\n']");
  20698. this.ESCAPE_REGEXP = new RegExp(escapePattern);
  20699. }
  20700. _createClass(FieldFormatter, [{
  20701. key: "shouldQuote",
  20702. value: function shouldQuote(fieldIndex, isHeader) {
  20703. var quoteConfig = isHeader ? this.formatterOptions.quoteHeaders : this.formatterOptions.quoteColumns;
  20704. if (lodash_isboolean_1.default(quoteConfig)) {
  20705. return quoteConfig;
  20706. }
  20707. if (Array.isArray(quoteConfig)) {
  20708. return quoteConfig[fieldIndex];
  20709. }
  20710. if (this._headers !== null) {
  20711. return quoteConfig[this._headers[fieldIndex]];
  20712. }
  20713. return false;
  20714. }
  20715. }, {
  20716. key: "format",
  20717. value: function format(field, fieldIndex, isHeader) {
  20718. var preparedField = "".concat(lodash_isnil_1.default(field) ? '' : field).replace(/\0/g, '');
  20719. var formatterOptions = this.formatterOptions;
  20720. if (formatterOptions.quote !== '') {
  20721. var shouldEscape = preparedField.indexOf(formatterOptions.quote) !== -1;
  20722. if (shouldEscape) {
  20723. return this.quoteField(preparedField.replace(this.REPLACE_REGEXP, formatterOptions.escapedQuote));
  20724. }
  20725. }
  20726. var hasEscapeCharacters = preparedField.search(this.ESCAPE_REGEXP) !== -1;
  20727. if (hasEscapeCharacters || this.shouldQuote(fieldIndex, isHeader)) {
  20728. return this.quoteField(preparedField);
  20729. }
  20730. return preparedField;
  20731. }
  20732. }, {
  20733. key: "quoteField",
  20734. value: function quoteField(field) {
  20735. var quote = this.formatterOptions.quote;
  20736. return "".concat(quote).concat(field).concat(quote);
  20737. }
  20738. }, {
  20739. key: "headers",
  20740. set: function set(headers) {
  20741. this._headers = headers;
  20742. }
  20743. }]);
  20744. return FieldFormatter;
  20745. }();
  20746. exports.FieldFormatter = FieldFormatter;
  20747. },{"lodash.escaperegexp":317,"lodash.isboolean":319,"lodash.isnil":322}],146:[function(require,module,exports){
  20748. "use strict";
  20749. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  20750. 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); } }
  20751. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  20752. var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
  20753. return mod && mod.__esModule ? mod : {
  20754. "default": mod
  20755. };
  20756. };
  20757. Object.defineProperty(exports, "__esModule", {
  20758. value: true
  20759. });
  20760. exports.RowFormatter = void 0;
  20761. var lodash_isfunction_1 = __importDefault(require("lodash.isfunction"));
  20762. var lodash_isequal_1 = __importDefault(require("lodash.isequal"));
  20763. var FieldFormatter_1 = require("./FieldFormatter");
  20764. var types_1 = require("../types");
  20765. var RowFormatter = /*#__PURE__*/function () {
  20766. function RowFormatter(formatterOptions) {
  20767. _classCallCheck(this, RowFormatter);
  20768. this.rowCount = 0;
  20769. this.formatterOptions = formatterOptions;
  20770. this.fieldFormatter = new FieldFormatter_1.FieldFormatter(formatterOptions);
  20771. this.headers = formatterOptions.headers;
  20772. this.shouldWriteHeaders = formatterOptions.shouldWriteHeaders;
  20773. this.hasWrittenHeaders = false;
  20774. if (this.headers !== null) {
  20775. this.fieldFormatter.headers = this.headers;
  20776. }
  20777. if (formatterOptions.transform) {
  20778. this.rowTransform = formatterOptions.transform;
  20779. }
  20780. }
  20781. _createClass(RowFormatter, [{
  20782. key: "format",
  20783. value: function format(row, cb) {
  20784. var _this = this;
  20785. this.callTransformer(row, function (err, transformedRow) {
  20786. if (err) {
  20787. return cb(err);
  20788. }
  20789. if (!row) {
  20790. return cb(null);
  20791. }
  20792. var rows = [];
  20793. if (transformedRow) {
  20794. var _this$checkHeaders = _this.checkHeaders(transformedRow),
  20795. shouldFormatColumns = _this$checkHeaders.shouldFormatColumns,
  20796. headers = _this$checkHeaders.headers;
  20797. if (_this.shouldWriteHeaders && headers && !_this.hasWrittenHeaders) {
  20798. rows.push(_this.formatColumns(headers, true));
  20799. _this.hasWrittenHeaders = true;
  20800. }
  20801. if (shouldFormatColumns) {
  20802. var columns = _this.gatherColumns(transformedRow);
  20803. rows.push(_this.formatColumns(columns, false));
  20804. }
  20805. }
  20806. return cb(null, rows);
  20807. });
  20808. }
  20809. }, {
  20810. key: "finish",
  20811. value: function finish(cb) {
  20812. var rows = []; // check if we should write headers and we didnt get any rows
  20813. if (this.formatterOptions.alwaysWriteHeaders && this.rowCount === 0) {
  20814. if (!this.headers) {
  20815. return cb(new Error('`alwaysWriteHeaders` option is set to true but `headers` option not provided.'));
  20816. }
  20817. rows.push(this.formatColumns(this.headers, true));
  20818. }
  20819. if (this.formatterOptions.includeEndRowDelimiter) {
  20820. rows.push(this.formatterOptions.rowDelimiter);
  20821. }
  20822. return cb(null, rows);
  20823. } // check if we need to write header return true if we should also write a row
  20824. // could be false if headers is true and the header row(first item) is passed in
  20825. }, {
  20826. key: "checkHeaders",
  20827. value: function checkHeaders(row) {
  20828. if (this.headers) {
  20829. // either the headers were provided by the user or we have already gathered them.
  20830. return {
  20831. shouldFormatColumns: true,
  20832. headers: this.headers
  20833. };
  20834. }
  20835. var headers = RowFormatter.gatherHeaders(row);
  20836. this.headers = headers;
  20837. this.fieldFormatter.headers = headers;
  20838. if (!this.shouldWriteHeaders) {
  20839. // if we are not supposed to write the headers then
  20840. // always format the columns
  20841. return {
  20842. shouldFormatColumns: true,
  20843. headers: null
  20844. };
  20845. } // if the row is equal to headers dont format
  20846. return {
  20847. shouldFormatColumns: !lodash_isequal_1.default(headers, row),
  20848. headers: headers
  20849. };
  20850. } // todo change this method to unknown[]
  20851. }, {
  20852. key: "gatherColumns",
  20853. value: function gatherColumns(row) {
  20854. if (this.headers === null) {
  20855. throw new Error('Headers is currently null');
  20856. }
  20857. if (!Array.isArray(row)) {
  20858. return this.headers.map(function (header) {
  20859. return row[header];
  20860. });
  20861. }
  20862. if (RowFormatter.isHashArray(row)) {
  20863. return this.headers.map(function (header, i) {
  20864. var col = row[i];
  20865. if (col) {
  20866. return col[1];
  20867. }
  20868. return '';
  20869. });
  20870. }
  20871. return this.headers.map(function (header, i) {
  20872. return row[i];
  20873. });
  20874. }
  20875. }, {
  20876. key: "callTransformer",
  20877. value: function callTransformer(row, cb) {
  20878. if (!this._rowTransform) {
  20879. return cb(null, row);
  20880. }
  20881. return this._rowTransform(row, cb);
  20882. }
  20883. }, {
  20884. key: "formatColumns",
  20885. value: function formatColumns(columns, isHeadersRow) {
  20886. var _this2 = this;
  20887. var formattedCols = columns.map(function (field, i) {
  20888. return _this2.fieldFormatter.format(field, i, isHeadersRow);
  20889. }).join(this.formatterOptions.delimiter);
  20890. var rowCount = this.rowCount;
  20891. this.rowCount += 1;
  20892. if (rowCount) {
  20893. return [this.formatterOptions.rowDelimiter, formattedCols].join('');
  20894. }
  20895. return formattedCols;
  20896. }
  20897. }, {
  20898. key: "rowTransform",
  20899. set: function set(transformFunction) {
  20900. if (!lodash_isfunction_1.default(transformFunction)) {
  20901. throw new TypeError('The transform should be a function');
  20902. }
  20903. this._rowTransform = RowFormatter.createTransform(transformFunction);
  20904. }
  20905. }], [{
  20906. key: "isHashArray",
  20907. value: function isHashArray(row) {
  20908. if (Array.isArray(row)) {
  20909. return Array.isArray(row[0]) && row[0].length === 2;
  20910. }
  20911. return false;
  20912. } // get headers from a row item
  20913. }, {
  20914. key: "gatherHeaders",
  20915. value: function gatherHeaders(row) {
  20916. if (RowFormatter.isHashArray(row)) {
  20917. // lets assume a multi-dimesional array with item 0 being the header
  20918. return row.map(function (it) {
  20919. return it[0];
  20920. });
  20921. }
  20922. if (Array.isArray(row)) {
  20923. return row;
  20924. }
  20925. return Object.keys(row);
  20926. }
  20927. }, {
  20928. key: "createTransform",
  20929. value: function createTransform(transformFunction) {
  20930. if (types_1.isSyncTransform(transformFunction)) {
  20931. return function (row, cb) {
  20932. var transformedRow = null;
  20933. try {
  20934. transformedRow = transformFunction(row);
  20935. } catch (e) {
  20936. return cb(e);
  20937. }
  20938. return cb(null, transformedRow);
  20939. };
  20940. }
  20941. return function (row, cb) {
  20942. transformFunction(row, cb);
  20943. };
  20944. }
  20945. }]);
  20946. return RowFormatter;
  20947. }();
  20948. exports.RowFormatter = RowFormatter;
  20949. },{"../types":149,"./FieldFormatter":145,"lodash.isequal":320,"lodash.isfunction":321}],147:[function(require,module,exports){
  20950. "use strict";
  20951. Object.defineProperty(exports, "__esModule", {
  20952. value: true
  20953. });
  20954. var RowFormatter_1 = require("./RowFormatter");
  20955. Object.defineProperty(exports, "RowFormatter", {
  20956. enumerable: true,
  20957. get: function get() {
  20958. return RowFormatter_1.RowFormatter;
  20959. }
  20960. });
  20961. var FieldFormatter_1 = require("./FieldFormatter");
  20962. Object.defineProperty(exports, "FieldFormatter", {
  20963. enumerable: true,
  20964. get: function get() {
  20965. return FieldFormatter_1.FieldFormatter;
  20966. }
  20967. });
  20968. },{"./FieldFormatter":145,"./RowFormatter":146}],148:[function(require,module,exports){
  20969. (function (Buffer){
  20970. "use strict";
  20971. var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
  20972. if (k2 === undefined) k2 = k;
  20973. Object.defineProperty(o, k2, {
  20974. enumerable: true,
  20975. get: function get() {
  20976. return m[k];
  20977. }
  20978. });
  20979. } : function (o, m, k, k2) {
  20980. if (k2 === undefined) k2 = k;
  20981. o[k2] = m[k];
  20982. });
  20983. var __setModuleDefault = void 0 && (void 0).__setModuleDefault || (Object.create ? function (o, v) {
  20984. Object.defineProperty(o, "default", {
  20985. enumerable: true,
  20986. value: v
  20987. });
  20988. } : function (o, v) {
  20989. o["default"] = v;
  20990. });
  20991. var __importStar = void 0 && (void 0).__importStar || function (mod) {
  20992. if (mod && mod.__esModule) return mod;
  20993. var result = {};
  20994. if (mod != null) for (var k in mod) {
  20995. if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  20996. }
  20997. __setModuleDefault(result, mod);
  20998. return result;
  20999. };
  21000. var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
  21001. for (var p in m) {
  21002. if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
  21003. }
  21004. };
  21005. Object.defineProperty(exports, "__esModule", {
  21006. value: true
  21007. });
  21008. exports.writeToPath = exports.writeToString = exports.writeToBuffer = exports.writeToStream = exports.write = exports.format = void 0;
  21009. var util_1 = require("util");
  21010. var stream_1 = require("stream");
  21011. var fs = __importStar(require("fs"));
  21012. var FormatterOptions_1 = require("./FormatterOptions");
  21013. var CsvFormatterStream_1 = require("./CsvFormatterStream");
  21014. __exportStar(require("./types"), exports);
  21015. var CsvFormatterStream_2 = require("./CsvFormatterStream");
  21016. Object.defineProperty(exports, "CsvFormatterStream", {
  21017. enumerable: true,
  21018. get: function get() {
  21019. return CsvFormatterStream_2.CsvFormatterStream;
  21020. }
  21021. });
  21022. var FormatterOptions_2 = require("./FormatterOptions");
  21023. Object.defineProperty(exports, "FormatterOptions", {
  21024. enumerable: true,
  21025. get: function get() {
  21026. return FormatterOptions_2.FormatterOptions;
  21027. }
  21028. });
  21029. exports.format = function (options) {
  21030. return new CsvFormatterStream_1.CsvFormatterStream(new FormatterOptions_1.FormatterOptions(options));
  21031. };
  21032. exports.write = function (rows, options) {
  21033. var csvStream = exports.format(options);
  21034. var promiseWrite = util_1.promisify(function (row, cb) {
  21035. csvStream.write(row, undefined, cb);
  21036. });
  21037. rows.reduce(function (prev, row) {
  21038. return prev.then(function () {
  21039. return promiseWrite(row);
  21040. });
  21041. }, Promise.resolve()).then(function () {
  21042. return csvStream.end();
  21043. }).catch(function (err) {
  21044. csvStream.emit('error', err);
  21045. });
  21046. return csvStream;
  21047. };
  21048. exports.writeToStream = function (ws, rows, options) {
  21049. return exports.write(rows, options).pipe(ws);
  21050. };
  21051. exports.writeToBuffer = function (rows) {
  21052. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  21053. var buffers = [];
  21054. var ws = new stream_1.Writable({
  21055. write: function write(data, enc, writeCb) {
  21056. buffers.push(data);
  21057. writeCb();
  21058. }
  21059. });
  21060. return new Promise(function (res, rej) {
  21061. ws.on('error', rej).on('finish', function () {
  21062. return res(Buffer.concat(buffers));
  21063. });
  21064. exports.write(rows, opts).pipe(ws);
  21065. });
  21066. };
  21067. exports.writeToString = function (rows, options) {
  21068. return exports.writeToBuffer(rows, options).then(function (buffer) {
  21069. return buffer.toString();
  21070. });
  21071. };
  21072. exports.writeToPath = function (path, rows, options) {
  21073. var stream = fs.createWriteStream(path, {
  21074. encoding: 'utf8'
  21075. });
  21076. return exports.write(rows, options).pipe(stream);
  21077. };
  21078. }).call(this,require("buffer").Buffer)
  21079. },{"./CsvFormatterStream":143,"./FormatterOptions":144,"./types":149,"buffer":216,"fs":215,"stream":396,"util":415}],149:[function(require,module,exports){
  21080. "use strict";
  21081. /* eslint-disable @typescript-eslint/no-explicit-any */
  21082. Object.defineProperty(exports, "__esModule", {
  21083. value: true
  21084. });
  21085. exports.isSyncTransform = void 0;
  21086. exports.isSyncTransform = function (transform) {
  21087. return transform.length === 1;
  21088. };
  21089. },{}],150:[function(require,module,exports){
  21090. (function (setImmediate){
  21091. "use strict";
  21092. 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); }
  21093. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21094. 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); } }
  21095. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  21096. 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); }
  21097. function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
  21098. 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); }
  21099. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  21100. 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); }; }
  21101. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  21102. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  21103. 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; } }
  21104. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  21105. Object.defineProperty(exports, "__esModule", {
  21106. value: true
  21107. });
  21108. exports.CsvParserStream = void 0;
  21109. var string_decoder_1 = require("string_decoder");
  21110. var stream_1 = require("stream");
  21111. var transforms_1 = require("./transforms");
  21112. var parser_1 = require("./parser");
  21113. var CsvParserStream = /*#__PURE__*/function (_stream_1$Transform) {
  21114. _inherits(CsvParserStream, _stream_1$Transform);
  21115. var _super = _createSuper(CsvParserStream);
  21116. function CsvParserStream(parserOptions) {
  21117. var _this;
  21118. _classCallCheck(this, CsvParserStream);
  21119. _this = _super.call(this, {
  21120. objectMode: parserOptions.objectMode
  21121. });
  21122. _this.lines = '';
  21123. _this.rowCount = 0;
  21124. _this.parsedRowCount = 0;
  21125. _this.parsedLineCount = 0;
  21126. _this.endEmitted = false;
  21127. _this.headersEmitted = false;
  21128. _this.parserOptions = parserOptions;
  21129. _this.parser = new parser_1.Parser(parserOptions);
  21130. _this.headerTransformer = new transforms_1.HeaderTransformer(parserOptions);
  21131. _this.decoder = new string_decoder_1.StringDecoder(parserOptions.encoding);
  21132. _this.rowTransformerValidator = new transforms_1.RowTransformerValidator();
  21133. return _this;
  21134. }
  21135. _createClass(CsvParserStream, [{
  21136. key: "transform",
  21137. value: function transform(transformFunction) {
  21138. this.rowTransformerValidator.rowTransform = transformFunction;
  21139. return this;
  21140. }
  21141. }, {
  21142. key: "validate",
  21143. value: function validate(validateFunction) {
  21144. this.rowTransformerValidator.rowValidator = validateFunction;
  21145. return this;
  21146. } // eslint-disable-next-line @typescript-eslint/no-explicit-any
  21147. }, {
  21148. key: "emit",
  21149. value: function emit(event) {
  21150. var _get2;
  21151. if (event === 'end') {
  21152. if (!this.endEmitted) {
  21153. this.endEmitted = true;
  21154. _get(_getPrototypeOf(CsvParserStream.prototype), "emit", this).call(this, 'end', this.rowCount);
  21155. }
  21156. return false;
  21157. }
  21158. for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  21159. rest[_key - 1] = arguments[_key];
  21160. }
  21161. return (_get2 = _get(_getPrototypeOf(CsvParserStream.prototype), "emit", this)).call.apply(_get2, [this, event].concat(rest));
  21162. }
  21163. }, {
  21164. key: "_transform",
  21165. value: function _transform(data, encoding, done) {
  21166. // if we have hit our maxRows parsing limit then skip parsing
  21167. if (this.hasHitRowLimit) {
  21168. return done();
  21169. }
  21170. try {
  21171. var lines = this.lines;
  21172. var newLine = lines + this.decoder.write(data);
  21173. var rows = this.parse(newLine, true);
  21174. return this.processRows(rows, done);
  21175. } catch (e) {
  21176. return done(e);
  21177. }
  21178. }
  21179. }, {
  21180. key: "_flush",
  21181. value: function _flush(done) {
  21182. // if we have hit our maxRows parsing limit then skip parsing
  21183. if (this.hasHitRowLimit) {
  21184. return done();
  21185. }
  21186. try {
  21187. var newLine = this.lines + this.decoder.end();
  21188. var rows = this.parse(newLine, false);
  21189. return this.processRows(rows, done);
  21190. } catch (e) {
  21191. return done(e);
  21192. }
  21193. }
  21194. }, {
  21195. key: "parse",
  21196. value: function parse(data, hasMoreData) {
  21197. if (!data) {
  21198. return [];
  21199. }
  21200. var _this$parser$parse = this.parser.parse(data, hasMoreData),
  21201. line = _this$parser$parse.line,
  21202. rows = _this$parser$parse.rows;
  21203. this.lines = line;
  21204. return rows;
  21205. }
  21206. }, {
  21207. key: "processRows",
  21208. value: function processRows(rows, cb) {
  21209. var _this2 = this;
  21210. var rowsLength = rows.length;
  21211. var iterate = function iterate(i) {
  21212. var callNext = function callNext(err) {
  21213. if (err) {
  21214. return cb(err);
  21215. }
  21216. if (i % 100 === 0) {
  21217. // incase the transform are sync insert a next tick to prevent stack overflow
  21218. setImmediate(function () {
  21219. return iterate(i + 1);
  21220. });
  21221. return undefined;
  21222. }
  21223. return iterate(i + 1);
  21224. };
  21225. _this2.checkAndEmitHeaders(); // if we have emitted all rows or we have hit the maxRows limit option
  21226. // then end
  21227. if (i >= rowsLength || _this2.hasHitRowLimit) {
  21228. return cb();
  21229. }
  21230. _this2.parsedLineCount += 1;
  21231. if (_this2.shouldSkipLine) {
  21232. return callNext();
  21233. }
  21234. var row = rows[i];
  21235. _this2.rowCount += 1;
  21236. _this2.parsedRowCount += 1;
  21237. var nextRowCount = _this2.rowCount;
  21238. return _this2.transformRow(row, function (err, transformResult) {
  21239. if (err) {
  21240. _this2.rowCount -= 1;
  21241. return callNext(err);
  21242. }
  21243. if (!transformResult) {
  21244. return callNext(new Error('expected transform result'));
  21245. }
  21246. if (!transformResult.isValid) {
  21247. _this2.emit('data-invalid', transformResult.row, nextRowCount, transformResult.reason);
  21248. } else if (transformResult.row) {
  21249. return _this2.pushRow(transformResult.row, callNext);
  21250. }
  21251. return callNext();
  21252. });
  21253. };
  21254. iterate(0);
  21255. }
  21256. }, {
  21257. key: "transformRow",
  21258. value: function transformRow(parsedRow, cb) {
  21259. var _this3 = this;
  21260. try {
  21261. this.headerTransformer.transform(parsedRow, function (err, withHeaders) {
  21262. if (err) {
  21263. return cb(err);
  21264. }
  21265. if (!withHeaders) {
  21266. return cb(new Error('Expected result from header transform'));
  21267. }
  21268. if (!withHeaders.isValid) {
  21269. if (_this3.shouldEmitRows) {
  21270. return cb(null, {
  21271. isValid: false,
  21272. row: parsedRow
  21273. });
  21274. } // skipped because of skipRows option remove from total row count
  21275. return _this3.skipRow(cb);
  21276. }
  21277. if (withHeaders.row) {
  21278. if (_this3.shouldEmitRows) {
  21279. return _this3.rowTransformerValidator.transformAndValidate(withHeaders.row, cb);
  21280. } // skipped because of skipRows option remove from total row count
  21281. return _this3.skipRow(cb);
  21282. } // this is a header row dont include in the rowCount or parsedRowCount
  21283. _this3.rowCount -= 1;
  21284. _this3.parsedRowCount -= 1;
  21285. return cb(null, {
  21286. row: null,
  21287. isValid: true
  21288. });
  21289. });
  21290. } catch (e) {
  21291. cb(e);
  21292. }
  21293. }
  21294. }, {
  21295. key: "checkAndEmitHeaders",
  21296. value: function checkAndEmitHeaders() {
  21297. if (!this.headersEmitted && this.headerTransformer.headers) {
  21298. this.headersEmitted = true;
  21299. this.emit('headers', this.headerTransformer.headers);
  21300. }
  21301. }
  21302. }, {
  21303. key: "skipRow",
  21304. value: function skipRow(cb) {
  21305. // skipped because of skipRows option remove from total row count
  21306. this.rowCount -= 1;
  21307. return cb(null, {
  21308. row: null,
  21309. isValid: true
  21310. });
  21311. }
  21312. }, {
  21313. key: "pushRow",
  21314. value: function pushRow(row, cb) {
  21315. try {
  21316. if (!this.parserOptions.objectMode) {
  21317. this.push(JSON.stringify(row));
  21318. } else {
  21319. this.push(row);
  21320. }
  21321. cb();
  21322. } catch (e) {
  21323. cb(e);
  21324. }
  21325. }
  21326. }, {
  21327. key: "hasHitRowLimit",
  21328. get: function get() {
  21329. return this.parserOptions.limitRows && this.rowCount >= this.parserOptions.maxRows;
  21330. }
  21331. }, {
  21332. key: "shouldEmitRows",
  21333. get: function get() {
  21334. return this.parsedRowCount > this.parserOptions.skipRows;
  21335. }
  21336. }, {
  21337. key: "shouldSkipLine",
  21338. get: function get() {
  21339. return this.parsedLineCount <= this.parserOptions.skipLines;
  21340. }
  21341. }]);
  21342. return CsvParserStream;
  21343. }(stream_1.Transform);
  21344. exports.CsvParserStream = CsvParserStream;
  21345. }).call(this,require("timers").setImmediate)
  21346. },{"./parser":162,"./transforms":165,"stream":396,"string_decoder":410,"timers":411}],151:[function(require,module,exports){
  21347. "use strict";
  21348. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21349. var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
  21350. return mod && mod.__esModule ? mod : {
  21351. "default": mod
  21352. };
  21353. };
  21354. Object.defineProperty(exports, "__esModule", {
  21355. value: true
  21356. });
  21357. exports.ParserOptions = void 0;
  21358. var lodash_escaperegexp_1 = __importDefault(require("lodash.escaperegexp"));
  21359. var lodash_isnil_1 = __importDefault(require("lodash.isnil"));
  21360. var ParserOptions = function ParserOptions(opts) {
  21361. _classCallCheck(this, ParserOptions);
  21362. var _a;
  21363. this.objectMode = true;
  21364. this.delimiter = ',';
  21365. this.ignoreEmpty = false;
  21366. this.quote = '"';
  21367. this.escape = null;
  21368. this.escapeChar = this.quote;
  21369. this.comment = null;
  21370. this.supportsComments = false;
  21371. this.ltrim = false;
  21372. this.rtrim = false;
  21373. this.trim = false;
  21374. this.headers = null;
  21375. this.renameHeaders = false;
  21376. this.strictColumnHandling = false;
  21377. this.discardUnmappedColumns = false;
  21378. this.carriageReturn = '\r';
  21379. this.encoding = 'utf8';
  21380. this.limitRows = false;
  21381. this.maxRows = 0;
  21382. this.skipLines = 0;
  21383. this.skipRows = 0;
  21384. Object.assign(this, opts || {});
  21385. if (this.delimiter.length > 1) {
  21386. throw new Error('delimiter option must be one character long');
  21387. }
  21388. this.escapedDelimiter = lodash_escaperegexp_1.default(this.delimiter);
  21389. this.escapeChar = (_a = this.escape) !== null && _a !== void 0 ? _a : this.quote;
  21390. this.supportsComments = !lodash_isnil_1.default(this.comment);
  21391. this.NEXT_TOKEN_REGEXP = new RegExp("([^\\s]|\\r\\n|\\n|\\r|".concat(this.escapedDelimiter, ")"));
  21392. if (this.maxRows > 0) {
  21393. this.limitRows = true;
  21394. }
  21395. };
  21396. exports.ParserOptions = ParserOptions;
  21397. },{"lodash.escaperegexp":317,"lodash.isnil":322}],152:[function(require,module,exports){
  21398. "use strict";
  21399. var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
  21400. if (k2 === undefined) k2 = k;
  21401. Object.defineProperty(o, k2, {
  21402. enumerable: true,
  21403. get: function get() {
  21404. return m[k];
  21405. }
  21406. });
  21407. } : function (o, m, k, k2) {
  21408. if (k2 === undefined) k2 = k;
  21409. o[k2] = m[k];
  21410. });
  21411. var __setModuleDefault = void 0 && (void 0).__setModuleDefault || (Object.create ? function (o, v) {
  21412. Object.defineProperty(o, "default", {
  21413. enumerable: true,
  21414. value: v
  21415. });
  21416. } : function (o, v) {
  21417. o["default"] = v;
  21418. });
  21419. var __importStar = void 0 && (void 0).__importStar || function (mod) {
  21420. if (mod && mod.__esModule) return mod;
  21421. var result = {};
  21422. if (mod != null) for (var k in mod) {
  21423. if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  21424. }
  21425. __setModuleDefault(result, mod);
  21426. return result;
  21427. };
  21428. var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
  21429. for (var p in m) {
  21430. if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
  21431. }
  21432. };
  21433. Object.defineProperty(exports, "__esModule", {
  21434. value: true
  21435. });
  21436. exports.parseString = exports.parseFile = exports.parseStream = exports.parse = void 0;
  21437. var fs = __importStar(require("fs"));
  21438. var stream_1 = require("stream");
  21439. var ParserOptions_1 = require("./ParserOptions");
  21440. var CsvParserStream_1 = require("./CsvParserStream");
  21441. __exportStar(require("./types"), exports);
  21442. var CsvParserStream_2 = require("./CsvParserStream");
  21443. Object.defineProperty(exports, "CsvParserStream", {
  21444. enumerable: true,
  21445. get: function get() {
  21446. return CsvParserStream_2.CsvParserStream;
  21447. }
  21448. });
  21449. var ParserOptions_2 = require("./ParserOptions");
  21450. Object.defineProperty(exports, "ParserOptions", {
  21451. enumerable: true,
  21452. get: function get() {
  21453. return ParserOptions_2.ParserOptions;
  21454. }
  21455. });
  21456. exports.parse = function (args) {
  21457. return new CsvParserStream_1.CsvParserStream(new ParserOptions_1.ParserOptions(args));
  21458. };
  21459. exports.parseStream = function (stream, options) {
  21460. return stream.pipe(new CsvParserStream_1.CsvParserStream(new ParserOptions_1.ParserOptions(options)));
  21461. };
  21462. exports.parseFile = function (location) {
  21463. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  21464. return fs.createReadStream(location).pipe(new CsvParserStream_1.CsvParserStream(new ParserOptions_1.ParserOptions(options)));
  21465. };
  21466. exports.parseString = function (string, options) {
  21467. var rs = new stream_1.Readable();
  21468. rs.push(string);
  21469. rs.push(null);
  21470. return rs.pipe(new CsvParserStream_1.CsvParserStream(new ParserOptions_1.ParserOptions(options)));
  21471. };
  21472. },{"./CsvParserStream":150,"./ParserOptions":151,"./types":166,"fs":215,"stream":396}],153:[function(require,module,exports){
  21473. "use strict";
  21474. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21475. 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); } }
  21476. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  21477. Object.defineProperty(exports, "__esModule", {
  21478. value: true
  21479. });
  21480. exports.Parser = void 0;
  21481. var Scanner_1 = require("./Scanner");
  21482. var RowParser_1 = require("./RowParser");
  21483. var Token_1 = require("./Token");
  21484. var EMPTY_ROW_REGEXP = /^\s*(?:''|"")?\s*(?:,\s*(?:''|"")?\s*)*$/;
  21485. var Parser = /*#__PURE__*/function () {
  21486. function Parser(parserOptions) {
  21487. _classCallCheck(this, Parser);
  21488. this.parserOptions = parserOptions;
  21489. this.rowParser = new RowParser_1.RowParser(this.parserOptions);
  21490. }
  21491. _createClass(Parser, [{
  21492. key: "parse",
  21493. value: function parse(line, hasMoreData) {
  21494. var scanner = new Scanner_1.Scanner({
  21495. line: Parser.removeBOM(line),
  21496. parserOptions: this.parserOptions,
  21497. hasMoreData: hasMoreData
  21498. });
  21499. if (this.parserOptions.supportsComments) {
  21500. return this.parseWithComments(scanner);
  21501. }
  21502. return this.parseWithoutComments(scanner);
  21503. }
  21504. }, {
  21505. key: "parseWithoutComments",
  21506. value: function parseWithoutComments(scanner) {
  21507. var rows = [];
  21508. var shouldContinue = true;
  21509. while (shouldContinue) {
  21510. shouldContinue = this.parseRow(scanner, rows);
  21511. }
  21512. return {
  21513. line: scanner.line,
  21514. rows: rows
  21515. };
  21516. }
  21517. }, {
  21518. key: "parseWithComments",
  21519. value: function parseWithComments(scanner) {
  21520. var parserOptions = this.parserOptions;
  21521. var rows = [];
  21522. for (var nextToken = scanner.nextCharacterToken; nextToken !== null; nextToken = scanner.nextCharacterToken) {
  21523. if (Token_1.Token.isTokenComment(nextToken, parserOptions)) {
  21524. var cursor = scanner.advancePastLine();
  21525. if (cursor === null) {
  21526. return {
  21527. line: scanner.lineFromCursor,
  21528. rows: rows
  21529. };
  21530. }
  21531. if (!scanner.hasMoreCharacters) {
  21532. return {
  21533. line: scanner.lineFromCursor,
  21534. rows: rows
  21535. };
  21536. }
  21537. scanner.truncateToCursor();
  21538. } else if (!this.parseRow(scanner, rows)) {
  21539. break;
  21540. }
  21541. }
  21542. return {
  21543. line: scanner.line,
  21544. rows: rows
  21545. };
  21546. }
  21547. }, {
  21548. key: "parseRow",
  21549. value: function parseRow(scanner, rows) {
  21550. var nextToken = scanner.nextNonSpaceToken;
  21551. if (!nextToken) {
  21552. return false;
  21553. }
  21554. var row = this.rowParser.parse(scanner);
  21555. if (row === null) {
  21556. return false;
  21557. }
  21558. if (this.parserOptions.ignoreEmpty && EMPTY_ROW_REGEXP.test(row.join(''))) {
  21559. return true;
  21560. }
  21561. rows.push(row);
  21562. return true;
  21563. }
  21564. }], [{
  21565. key: "removeBOM",
  21566. value: function removeBOM(line) {
  21567. // Catches EFBBBF (UTF-8 BOM) because the buffer-to-string
  21568. // conversion translates it to FEFF (UTF-16 BOM)
  21569. if (line && line.charCodeAt(0) === 0xfeff) {
  21570. return line.slice(1);
  21571. }
  21572. return line;
  21573. }
  21574. }]);
  21575. return Parser;
  21576. }();
  21577. exports.Parser = Parser;
  21578. },{"./RowParser":154,"./Scanner":155,"./Token":156}],154:[function(require,module,exports){
  21579. "use strict";
  21580. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21581. 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); } }
  21582. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  21583. Object.defineProperty(exports, "__esModule", {
  21584. value: true
  21585. });
  21586. exports.RowParser = void 0;
  21587. var column_1 = require("./column");
  21588. var Token_1 = require("./Token");
  21589. var _Token_1$Token = Token_1.Token,
  21590. isTokenRowDelimiter = _Token_1$Token.isTokenRowDelimiter,
  21591. isTokenCarriageReturn = _Token_1$Token.isTokenCarriageReturn,
  21592. isTokenDelimiter = _Token_1$Token.isTokenDelimiter;
  21593. var RowParser = /*#__PURE__*/function () {
  21594. function RowParser(parserOptions) {
  21595. _classCallCheck(this, RowParser);
  21596. this.parserOptions = parserOptions;
  21597. this.columnParser = new column_1.ColumnParser(parserOptions);
  21598. }
  21599. _createClass(RowParser, [{
  21600. key: "parse",
  21601. value: function parse(scanner) {
  21602. var parserOptions = this.parserOptions;
  21603. var hasMoreData = scanner.hasMoreData;
  21604. var currentScanner = scanner;
  21605. var columns = [];
  21606. var currentToken = this.getStartToken(currentScanner, columns);
  21607. while (currentToken) {
  21608. if (isTokenRowDelimiter(currentToken)) {
  21609. currentScanner.advancePastToken(currentToken); // if ends with CR and there is more data, keep unparsed due to possible
  21610. // coming LF in CRLF
  21611. if (!currentScanner.hasMoreCharacters && isTokenCarriageReturn(currentToken, parserOptions) && hasMoreData) {
  21612. return null;
  21613. }
  21614. currentScanner.truncateToCursor();
  21615. return columns;
  21616. }
  21617. if (!this.shouldSkipColumnParse(currentScanner, currentToken, columns)) {
  21618. var item = this.columnParser.parse(currentScanner);
  21619. if (item === null) {
  21620. return null;
  21621. }
  21622. columns.push(item);
  21623. }
  21624. currentToken = currentScanner.nextNonSpaceToken;
  21625. }
  21626. if (!hasMoreData) {
  21627. currentScanner.truncateToCursor();
  21628. return columns;
  21629. }
  21630. return null;
  21631. }
  21632. }, {
  21633. key: "getStartToken",
  21634. value: function getStartToken(scanner, columns) {
  21635. var currentToken = scanner.nextNonSpaceToken;
  21636. if (currentToken !== null && isTokenDelimiter(currentToken, this.parserOptions)) {
  21637. columns.push('');
  21638. return scanner.nextNonSpaceToken;
  21639. }
  21640. return currentToken;
  21641. }
  21642. }, {
  21643. key: "shouldSkipColumnParse",
  21644. value: function shouldSkipColumnParse(scanner, currentToken, columns) {
  21645. var parserOptions = this.parserOptions;
  21646. if (isTokenDelimiter(currentToken, parserOptions)) {
  21647. scanner.advancePastToken(currentToken); // if the delimiter is at the end of a line
  21648. var nextToken = scanner.nextCharacterToken;
  21649. if (!scanner.hasMoreCharacters || nextToken !== null && isTokenRowDelimiter(nextToken)) {
  21650. columns.push('');
  21651. return true;
  21652. }
  21653. if (nextToken !== null && isTokenDelimiter(nextToken, parserOptions)) {
  21654. columns.push('');
  21655. return true;
  21656. }
  21657. }
  21658. return false;
  21659. }
  21660. }]);
  21661. return RowParser;
  21662. }();
  21663. exports.RowParser = RowParser;
  21664. },{"./Token":156,"./column":161}],155:[function(require,module,exports){
  21665. "use strict";
  21666. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21667. 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); } }
  21668. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  21669. Object.defineProperty(exports, "__esModule", {
  21670. value: true
  21671. });
  21672. exports.Scanner = void 0;
  21673. var Token_1 = require("./Token");
  21674. var ROW_DELIMITER = /((?:\r\n)|\n|\r)/;
  21675. var Scanner = /*#__PURE__*/function () {
  21676. function Scanner(args) {
  21677. _classCallCheck(this, Scanner);
  21678. this.cursor = 0;
  21679. this.line = args.line;
  21680. this.lineLength = this.line.length;
  21681. this.parserOptions = args.parserOptions;
  21682. this.hasMoreData = args.hasMoreData;
  21683. this.cursor = args.cursor || 0;
  21684. }
  21685. _createClass(Scanner, [{
  21686. key: "advancePastLine",
  21687. value: function advancePastLine() {
  21688. var match = ROW_DELIMITER.exec(this.lineFromCursor);
  21689. if (!match) {
  21690. if (this.hasMoreData) {
  21691. return null;
  21692. }
  21693. this.cursor = this.lineLength;
  21694. return this;
  21695. }
  21696. this.cursor += (match.index || 0) + match[0].length;
  21697. return this;
  21698. }
  21699. }, {
  21700. key: "advanceTo",
  21701. value: function advanceTo(cursor) {
  21702. this.cursor = cursor;
  21703. return this;
  21704. }
  21705. }, {
  21706. key: "advanceToToken",
  21707. value: function advanceToToken(token) {
  21708. this.cursor = token.startCursor;
  21709. return this;
  21710. }
  21711. }, {
  21712. key: "advancePastToken",
  21713. value: function advancePastToken(token) {
  21714. this.cursor = token.endCursor + 1;
  21715. return this;
  21716. }
  21717. }, {
  21718. key: "truncateToCursor",
  21719. value: function truncateToCursor() {
  21720. this.line = this.lineFromCursor;
  21721. this.lineLength = this.line.length;
  21722. this.cursor = 0;
  21723. return this;
  21724. }
  21725. }, {
  21726. key: "hasMoreCharacters",
  21727. get: function get() {
  21728. return this.lineLength > this.cursor;
  21729. }
  21730. }, {
  21731. key: "nextNonSpaceToken",
  21732. get: function get() {
  21733. var lineFromCursor = this.lineFromCursor;
  21734. var regex = this.parserOptions.NEXT_TOKEN_REGEXP;
  21735. if (lineFromCursor.search(regex) === -1) {
  21736. return null;
  21737. }
  21738. var match = regex.exec(lineFromCursor);
  21739. if (match == null) {
  21740. return null;
  21741. }
  21742. var token = match[1];
  21743. var startCursor = this.cursor + (match.index || 0);
  21744. return new Token_1.Token({
  21745. token: token,
  21746. startCursor: startCursor,
  21747. endCursor: startCursor + token.length - 1
  21748. });
  21749. }
  21750. }, {
  21751. key: "nextCharacterToken",
  21752. get: function get() {
  21753. var cursor = this.cursor,
  21754. lineLength = this.lineLength;
  21755. if (lineLength <= cursor) {
  21756. return null;
  21757. }
  21758. return new Token_1.Token({
  21759. token: this.line[cursor],
  21760. startCursor: cursor,
  21761. endCursor: cursor
  21762. });
  21763. }
  21764. }, {
  21765. key: "lineFromCursor",
  21766. get: function get() {
  21767. return this.line.substr(this.cursor);
  21768. }
  21769. }]);
  21770. return Scanner;
  21771. }();
  21772. exports.Scanner = Scanner;
  21773. },{"./Token":156}],156:[function(require,module,exports){
  21774. "use strict";
  21775. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21776. 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); } }
  21777. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  21778. Object.defineProperty(exports, "__esModule", {
  21779. value: true
  21780. });
  21781. exports.Token = void 0;
  21782. var Token = /*#__PURE__*/function () {
  21783. function Token(tokenArgs) {
  21784. _classCallCheck(this, Token);
  21785. this.token = tokenArgs.token;
  21786. this.startCursor = tokenArgs.startCursor;
  21787. this.endCursor = tokenArgs.endCursor;
  21788. }
  21789. _createClass(Token, null, [{
  21790. key: "isTokenRowDelimiter",
  21791. value: function isTokenRowDelimiter(token) {
  21792. var content = token.token;
  21793. return content === '\r' || content === '\n' || content === '\r\n';
  21794. }
  21795. }, {
  21796. key: "isTokenCarriageReturn",
  21797. value: function isTokenCarriageReturn(token, parserOptions) {
  21798. return token.token === parserOptions.carriageReturn;
  21799. }
  21800. }, {
  21801. key: "isTokenComment",
  21802. value: function isTokenComment(token, parserOptions) {
  21803. return parserOptions.supportsComments && !!token && token.token === parserOptions.comment;
  21804. }
  21805. }, {
  21806. key: "isTokenEscapeCharacter",
  21807. value: function isTokenEscapeCharacter(token, parserOptions) {
  21808. return token.token === parserOptions.escapeChar;
  21809. }
  21810. }, {
  21811. key: "isTokenQuote",
  21812. value: function isTokenQuote(token, parserOptions) {
  21813. return token.token === parserOptions.quote;
  21814. }
  21815. }, {
  21816. key: "isTokenDelimiter",
  21817. value: function isTokenDelimiter(token, parserOptions) {
  21818. return token.token === parserOptions.delimiter;
  21819. }
  21820. }]);
  21821. return Token;
  21822. }();
  21823. exports.Token = Token;
  21824. },{}],157:[function(require,module,exports){
  21825. "use strict";
  21826. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21827. Object.defineProperty(exports, "__esModule", {
  21828. value: true
  21829. });
  21830. exports.ColumnFormatter = void 0;
  21831. var ColumnFormatter = function ColumnFormatter(parserOptions) {
  21832. _classCallCheck(this, ColumnFormatter);
  21833. if (parserOptions.trim) {
  21834. this.format = function (col) {
  21835. return col.trim();
  21836. };
  21837. } else if (parserOptions.ltrim) {
  21838. this.format = function (col) {
  21839. return col.trimLeft();
  21840. };
  21841. } else if (parserOptions.rtrim) {
  21842. this.format = function (col) {
  21843. return col.trimRight();
  21844. };
  21845. } else {
  21846. this.format = function (col) {
  21847. return col;
  21848. };
  21849. }
  21850. };
  21851. exports.ColumnFormatter = ColumnFormatter;
  21852. },{}],158:[function(require,module,exports){
  21853. "use strict";
  21854. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21855. 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); } }
  21856. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  21857. Object.defineProperty(exports, "__esModule", {
  21858. value: true
  21859. });
  21860. exports.ColumnParser = void 0;
  21861. var NonQuotedColumnParser_1 = require("./NonQuotedColumnParser");
  21862. var QuotedColumnParser_1 = require("./QuotedColumnParser");
  21863. var Token_1 = require("../Token");
  21864. var ColumnParser = /*#__PURE__*/function () {
  21865. function ColumnParser(parserOptions) {
  21866. _classCallCheck(this, ColumnParser);
  21867. this.parserOptions = parserOptions;
  21868. this.quotedColumnParser = new QuotedColumnParser_1.QuotedColumnParser(parserOptions);
  21869. this.nonQuotedColumnParser = new NonQuotedColumnParser_1.NonQuotedColumnParser(parserOptions);
  21870. }
  21871. _createClass(ColumnParser, [{
  21872. key: "parse",
  21873. value: function parse(scanner) {
  21874. var nextNonSpaceToken = scanner.nextNonSpaceToken;
  21875. if (nextNonSpaceToken !== null && Token_1.Token.isTokenQuote(nextNonSpaceToken, this.parserOptions)) {
  21876. scanner.advanceToToken(nextNonSpaceToken);
  21877. return this.quotedColumnParser.parse(scanner);
  21878. }
  21879. return this.nonQuotedColumnParser.parse(scanner);
  21880. }
  21881. }]);
  21882. return ColumnParser;
  21883. }();
  21884. exports.ColumnParser = ColumnParser;
  21885. },{"../Token":156,"./NonQuotedColumnParser":159,"./QuotedColumnParser":160}],159:[function(require,module,exports){
  21886. "use strict";
  21887. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21888. 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); } }
  21889. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  21890. Object.defineProperty(exports, "__esModule", {
  21891. value: true
  21892. });
  21893. exports.NonQuotedColumnParser = void 0;
  21894. var ColumnFormatter_1 = require("./ColumnFormatter");
  21895. var Token_1 = require("../Token");
  21896. var _Token_1$Token = Token_1.Token,
  21897. isTokenDelimiter = _Token_1$Token.isTokenDelimiter,
  21898. isTokenRowDelimiter = _Token_1$Token.isTokenRowDelimiter;
  21899. var NonQuotedColumnParser = /*#__PURE__*/function () {
  21900. function NonQuotedColumnParser(parserOptions) {
  21901. _classCallCheck(this, NonQuotedColumnParser);
  21902. this.parserOptions = parserOptions;
  21903. this.columnFormatter = new ColumnFormatter_1.ColumnFormatter(parserOptions);
  21904. }
  21905. _createClass(NonQuotedColumnParser, [{
  21906. key: "parse",
  21907. value: function parse(scanner) {
  21908. if (!scanner.hasMoreCharacters) {
  21909. return null;
  21910. }
  21911. var parserOptions = this.parserOptions;
  21912. var characters = [];
  21913. var nextToken = scanner.nextCharacterToken;
  21914. for (; nextToken; nextToken = scanner.nextCharacterToken) {
  21915. if (isTokenDelimiter(nextToken, parserOptions) || isTokenRowDelimiter(nextToken)) {
  21916. break;
  21917. }
  21918. characters.push(nextToken.token);
  21919. scanner.advancePastToken(nextToken);
  21920. }
  21921. return this.columnFormatter.format(characters.join(''));
  21922. }
  21923. }]);
  21924. return NonQuotedColumnParser;
  21925. }();
  21926. exports.NonQuotedColumnParser = NonQuotedColumnParser;
  21927. },{"../Token":156,"./ColumnFormatter":157}],160:[function(require,module,exports){
  21928. "use strict";
  21929. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21930. 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); } }
  21931. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  21932. Object.defineProperty(exports, "__esModule", {
  21933. value: true
  21934. });
  21935. exports.QuotedColumnParser = void 0;
  21936. var ColumnFormatter_1 = require("./ColumnFormatter");
  21937. var Token_1 = require("../Token");
  21938. var _Token_1$Token = Token_1.Token,
  21939. isTokenDelimiter = _Token_1$Token.isTokenDelimiter,
  21940. isTokenRowDelimiter = _Token_1$Token.isTokenRowDelimiter,
  21941. isTokenEscapeCharacter = _Token_1$Token.isTokenEscapeCharacter,
  21942. isTokenQuote = _Token_1$Token.isTokenQuote;
  21943. var QuotedColumnParser = /*#__PURE__*/function () {
  21944. function QuotedColumnParser(parserOptions) {
  21945. _classCallCheck(this, QuotedColumnParser);
  21946. this.parserOptions = parserOptions;
  21947. this.columnFormatter = new ColumnFormatter_1.ColumnFormatter(parserOptions);
  21948. }
  21949. _createClass(QuotedColumnParser, [{
  21950. key: "parse",
  21951. value: function parse(scanner) {
  21952. if (!scanner.hasMoreCharacters) {
  21953. return null;
  21954. }
  21955. var originalCursor = scanner.cursor;
  21956. var _this$gatherDataBetwe = this.gatherDataBetweenQuotes(scanner),
  21957. foundClosingQuote = _this$gatherDataBetwe.foundClosingQuote,
  21958. col = _this$gatherDataBetwe.col;
  21959. if (!foundClosingQuote) {
  21960. // reset the cursor to the original
  21961. scanner.advanceTo(originalCursor); // if we didnt find a closing quote but we potentially have more data then skip the parsing
  21962. // and return the original scanner.
  21963. if (!scanner.hasMoreData) {
  21964. throw new Error("Parse Error: missing closing: '".concat(this.parserOptions.quote || '', "' in line: at '").concat(scanner.lineFromCursor.replace(/[\r\n]/g, "\\n'"), "'"));
  21965. }
  21966. return null;
  21967. }
  21968. this.checkForMalformedColumn(scanner);
  21969. return col;
  21970. }
  21971. }, {
  21972. key: "gatherDataBetweenQuotes",
  21973. value: function gatherDataBetweenQuotes(scanner) {
  21974. var parserOptions = this.parserOptions;
  21975. var foundStartingQuote = false;
  21976. var foundClosingQuote = false;
  21977. var characters = [];
  21978. var nextToken = scanner.nextCharacterToken;
  21979. for (; !foundClosingQuote && nextToken !== null; nextToken = scanner.nextCharacterToken) {
  21980. var isQuote = isTokenQuote(nextToken, parserOptions); // ignore first quote
  21981. if (!foundStartingQuote && isQuote) {
  21982. foundStartingQuote = true;
  21983. } else if (foundStartingQuote) {
  21984. if (isTokenEscapeCharacter(nextToken, parserOptions)) {
  21985. // advance past the escape character so we can get the next one in line
  21986. scanner.advancePastToken(nextToken);
  21987. var tokenFollowingEscape = scanner.nextCharacterToken; // if the character following the escape is a quote character then just add
  21988. // the quote and advance to that character
  21989. if (tokenFollowingEscape !== null && (isTokenQuote(tokenFollowingEscape, parserOptions) || isTokenEscapeCharacter(tokenFollowingEscape, parserOptions))) {
  21990. characters.push(tokenFollowingEscape.token);
  21991. nextToken = tokenFollowingEscape;
  21992. } else if (isQuote) {
  21993. // if the escape is also a quote then we found our closing quote and finish early
  21994. foundClosingQuote = true;
  21995. } else {
  21996. // other wise add the escape token to the characters since it wast escaping anything
  21997. characters.push(nextToken.token);
  21998. }
  21999. } else if (isQuote) {
  22000. // we found our closing quote!
  22001. foundClosingQuote = true;
  22002. } else {
  22003. // add the token to the characters
  22004. characters.push(nextToken.token);
  22005. }
  22006. }
  22007. scanner.advancePastToken(nextToken);
  22008. }
  22009. return {
  22010. col: this.columnFormatter.format(characters.join('')),
  22011. foundClosingQuote: foundClosingQuote
  22012. };
  22013. }
  22014. }, {
  22015. key: "checkForMalformedColumn",
  22016. value: function checkForMalformedColumn(scanner) {
  22017. var parserOptions = this.parserOptions;
  22018. var nextNonSpaceToken = scanner.nextNonSpaceToken;
  22019. if (nextNonSpaceToken) {
  22020. var isNextTokenADelimiter = isTokenDelimiter(nextNonSpaceToken, parserOptions);
  22021. var isNextTokenARowDelimiter = isTokenRowDelimiter(nextNonSpaceToken);
  22022. if (!(isNextTokenADelimiter || isNextTokenARowDelimiter)) {
  22023. // if the final quote was NOT followed by a column (,) or row(\n) delimiter then its a bad column
  22024. // tldr: only part of the column was quoted
  22025. var linePreview = scanner.lineFromCursor.substr(0, 10).replace(/[\r\n]/g, "\\n'");
  22026. throw new Error("Parse Error: expected: '".concat(parserOptions.escapedDelimiter, "' OR new line got: '").concat(nextNonSpaceToken.token, "'. at '").concat(linePreview));
  22027. }
  22028. scanner.advanceToToken(nextNonSpaceToken);
  22029. } else if (!scanner.hasMoreData) {
  22030. scanner.advancePastLine();
  22031. }
  22032. }
  22033. }]);
  22034. return QuotedColumnParser;
  22035. }();
  22036. exports.QuotedColumnParser = QuotedColumnParser;
  22037. },{"../Token":156,"./ColumnFormatter":157}],161:[function(require,module,exports){
  22038. "use strict";
  22039. Object.defineProperty(exports, "__esModule", {
  22040. value: true
  22041. });
  22042. var ColumnParser_1 = require("./ColumnParser");
  22043. Object.defineProperty(exports, "ColumnParser", {
  22044. enumerable: true,
  22045. get: function get() {
  22046. return ColumnParser_1.ColumnParser;
  22047. }
  22048. });
  22049. var NonQuotedColumnParser_1 = require("./NonQuotedColumnParser");
  22050. Object.defineProperty(exports, "NonQuotedColumnParser", {
  22051. enumerable: true,
  22052. get: function get() {
  22053. return NonQuotedColumnParser_1.NonQuotedColumnParser;
  22054. }
  22055. });
  22056. var QuotedColumnParser_1 = require("./QuotedColumnParser");
  22057. Object.defineProperty(exports, "QuotedColumnParser", {
  22058. enumerable: true,
  22059. get: function get() {
  22060. return QuotedColumnParser_1.QuotedColumnParser;
  22061. }
  22062. });
  22063. var ColumnFormatter_1 = require("./ColumnFormatter");
  22064. Object.defineProperty(exports, "ColumnFormatter", {
  22065. enumerable: true,
  22066. get: function get() {
  22067. return ColumnFormatter_1.ColumnFormatter;
  22068. }
  22069. });
  22070. },{"./ColumnFormatter":157,"./ColumnParser":158,"./NonQuotedColumnParser":159,"./QuotedColumnParser":160}],162:[function(require,module,exports){
  22071. "use strict";
  22072. Object.defineProperty(exports, "__esModule", {
  22073. value: true
  22074. });
  22075. var Parser_1 = require("./Parser");
  22076. Object.defineProperty(exports, "Parser", {
  22077. enumerable: true,
  22078. get: function get() {
  22079. return Parser_1.Parser;
  22080. }
  22081. });
  22082. var RowParser_1 = require("./RowParser");
  22083. Object.defineProperty(exports, "RowParser", {
  22084. enumerable: true,
  22085. get: function get() {
  22086. return RowParser_1.RowParser;
  22087. }
  22088. });
  22089. var Scanner_1 = require("./Scanner");
  22090. Object.defineProperty(exports, "Scanner", {
  22091. enumerable: true,
  22092. get: function get() {
  22093. return Scanner_1.Scanner;
  22094. }
  22095. });
  22096. var Token_1 = require("./Token");
  22097. Object.defineProperty(exports, "Token", {
  22098. enumerable: true,
  22099. get: function get() {
  22100. return Token_1.Token;
  22101. }
  22102. });
  22103. var column_1 = require("./column");
  22104. Object.defineProperty(exports, "ColumnParser", {
  22105. enumerable: true,
  22106. get: function get() {
  22107. return column_1.ColumnParser;
  22108. }
  22109. });
  22110. Object.defineProperty(exports, "NonQuotedColumnParser", {
  22111. enumerable: true,
  22112. get: function get() {
  22113. return column_1.NonQuotedColumnParser;
  22114. }
  22115. });
  22116. Object.defineProperty(exports, "QuotedColumnParser", {
  22117. enumerable: true,
  22118. get: function get() {
  22119. return column_1.QuotedColumnParser;
  22120. }
  22121. });
  22122. },{"./Parser":153,"./RowParser":154,"./Scanner":155,"./Token":156,"./column":161}],163:[function(require,module,exports){
  22123. "use strict";
  22124. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  22125. 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); } }
  22126. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  22127. var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
  22128. return mod && mod.__esModule ? mod : {
  22129. "default": mod
  22130. };
  22131. };
  22132. Object.defineProperty(exports, "__esModule", {
  22133. value: true
  22134. });
  22135. exports.HeaderTransformer = void 0;
  22136. var lodash_isundefined_1 = __importDefault(require("lodash.isundefined"));
  22137. var lodash_isfunction_1 = __importDefault(require("lodash.isfunction"));
  22138. var lodash_uniq_1 = __importDefault(require("lodash.uniq"));
  22139. var lodash_groupby_1 = __importDefault(require("lodash.groupby"));
  22140. var HeaderTransformer = /*#__PURE__*/function () {
  22141. function HeaderTransformer(parserOptions) {
  22142. _classCallCheck(this, HeaderTransformer);
  22143. this.headers = null;
  22144. this.receivedHeaders = false;
  22145. this.shouldUseFirstRow = false;
  22146. this.processedFirstRow = false;
  22147. this.headersLength = 0;
  22148. this.parserOptions = parserOptions;
  22149. if (parserOptions.headers === true) {
  22150. this.shouldUseFirstRow = true;
  22151. } else if (Array.isArray(parserOptions.headers)) {
  22152. this.setHeaders(parserOptions.headers);
  22153. } else if (lodash_isfunction_1.default(parserOptions.headers)) {
  22154. this.headersTransform = parserOptions.headers;
  22155. }
  22156. }
  22157. _createClass(HeaderTransformer, [{
  22158. key: "transform",
  22159. value: function transform(row, cb) {
  22160. if (!this.shouldMapRow(row)) {
  22161. return cb(null, {
  22162. row: null,
  22163. isValid: true
  22164. });
  22165. }
  22166. return cb(null, this.processRow(row));
  22167. }
  22168. }, {
  22169. key: "shouldMapRow",
  22170. value: function shouldMapRow(row) {
  22171. var parserOptions = this.parserOptions;
  22172. if (!this.headersTransform && parserOptions.renameHeaders && !this.processedFirstRow) {
  22173. if (!this.receivedHeaders) {
  22174. throw new Error('Error renaming headers: new headers must be provided in an array');
  22175. }
  22176. this.processedFirstRow = true;
  22177. return false;
  22178. }
  22179. if (!this.receivedHeaders && Array.isArray(row)) {
  22180. if (this.headersTransform) {
  22181. this.setHeaders(this.headersTransform(row));
  22182. } else if (this.shouldUseFirstRow) {
  22183. this.setHeaders(row);
  22184. } else {
  22185. // dont do anything with the headers if we didnt receive a transform or shouldnt use the first row.
  22186. return true;
  22187. }
  22188. return false;
  22189. }
  22190. return true;
  22191. }
  22192. }, {
  22193. key: "processRow",
  22194. value: function processRow(row) {
  22195. if (!this.headers) {
  22196. return {
  22197. row: row,
  22198. isValid: true
  22199. };
  22200. }
  22201. var parserOptions = this.parserOptions;
  22202. if (!parserOptions.discardUnmappedColumns && row.length > this.headersLength) {
  22203. if (!parserOptions.strictColumnHandling) {
  22204. throw new Error("Unexpected Error: column header mismatch expected: ".concat(this.headersLength, " columns got: ").concat(row.length));
  22205. }
  22206. return {
  22207. row: row,
  22208. isValid: false,
  22209. reason: "Column header mismatch expected: ".concat(this.headersLength, " columns got: ").concat(row.length)
  22210. };
  22211. }
  22212. if (parserOptions.strictColumnHandling && row.length < this.headersLength) {
  22213. return {
  22214. row: row,
  22215. isValid: false,
  22216. reason: "Column header mismatch expected: ".concat(this.headersLength, " columns got: ").concat(row.length)
  22217. };
  22218. }
  22219. return {
  22220. row: this.mapHeaders(row),
  22221. isValid: true
  22222. };
  22223. }
  22224. }, {
  22225. key: "mapHeaders",
  22226. value: function mapHeaders(row) {
  22227. var rowMap = {};
  22228. var headers = this.headers,
  22229. headersLength = this.headersLength;
  22230. for (var i = 0; i < headersLength; i += 1) {
  22231. var header = headers[i];
  22232. if (!lodash_isundefined_1.default(header)) {
  22233. var val = row[i]; // eslint-disable-next-line no-param-reassign
  22234. if (lodash_isundefined_1.default(val)) {
  22235. rowMap[header] = '';
  22236. } else {
  22237. rowMap[header] = val;
  22238. }
  22239. }
  22240. }
  22241. return rowMap;
  22242. }
  22243. }, {
  22244. key: "setHeaders",
  22245. value: function setHeaders(headers) {
  22246. var _a;
  22247. var filteredHeaders = headers.filter(function (h) {
  22248. return !!h;
  22249. });
  22250. if (lodash_uniq_1.default(filteredHeaders).length !== filteredHeaders.length) {
  22251. var grouped = lodash_groupby_1.default(filteredHeaders);
  22252. var duplicates = Object.keys(grouped).filter(function (dup) {
  22253. return grouped[dup].length > 1;
  22254. });
  22255. throw new Error("Duplicate headers found ".concat(JSON.stringify(duplicates)));
  22256. }
  22257. this.headers = headers;
  22258. this.receivedHeaders = true;
  22259. this.headersLength = ((_a = this.headers) === null || _a === void 0 ? void 0 : _a.length) || 0;
  22260. }
  22261. }]);
  22262. return HeaderTransformer;
  22263. }();
  22264. exports.HeaderTransformer = HeaderTransformer;
  22265. },{"lodash.groupby":318,"lodash.isfunction":321,"lodash.isundefined":323,"lodash.uniq":324}],164:[function(require,module,exports){
  22266. "use strict";
  22267. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  22268. 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); } }
  22269. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  22270. var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
  22271. return mod && mod.__esModule ? mod : {
  22272. "default": mod
  22273. };
  22274. };
  22275. Object.defineProperty(exports, "__esModule", {
  22276. value: true
  22277. });
  22278. exports.RowTransformerValidator = void 0;
  22279. var lodash_isfunction_1 = __importDefault(require("lodash.isfunction"));
  22280. var types_1 = require("../types");
  22281. var RowTransformerValidator = /*#__PURE__*/function () {
  22282. function RowTransformerValidator() {
  22283. _classCallCheck(this, RowTransformerValidator);
  22284. this._rowTransform = null;
  22285. this._rowValidator = null;
  22286. }
  22287. _createClass(RowTransformerValidator, [{
  22288. key: "transformAndValidate",
  22289. value: function transformAndValidate(row, cb) {
  22290. var _this = this;
  22291. return this.callTransformer(row, function (transformErr, transformedRow) {
  22292. if (transformErr) {
  22293. return cb(transformErr);
  22294. }
  22295. if (!transformedRow) {
  22296. return cb(null, {
  22297. row: null,
  22298. isValid: true
  22299. });
  22300. }
  22301. return _this.callValidator(transformedRow, function (validateErr, validationResult) {
  22302. if (validateErr) {
  22303. return cb(validateErr);
  22304. }
  22305. if (validationResult && !validationResult.isValid) {
  22306. return cb(null, {
  22307. row: transformedRow,
  22308. isValid: false,
  22309. reason: validationResult.reason
  22310. });
  22311. }
  22312. return cb(null, {
  22313. row: transformedRow,
  22314. isValid: true
  22315. });
  22316. });
  22317. });
  22318. }
  22319. }, {
  22320. key: "callTransformer",
  22321. value: function callTransformer(row, cb) {
  22322. if (!this._rowTransform) {
  22323. return cb(null, row);
  22324. }
  22325. return this._rowTransform(row, cb);
  22326. }
  22327. }, {
  22328. key: "callValidator",
  22329. value: function callValidator(row, cb) {
  22330. if (!this._rowValidator) {
  22331. return cb(null, {
  22332. row: row,
  22333. isValid: true
  22334. });
  22335. }
  22336. return this._rowValidator(row, cb);
  22337. }
  22338. }, {
  22339. key: "rowTransform",
  22340. set: function set(transformFunction) {
  22341. if (!lodash_isfunction_1.default(transformFunction)) {
  22342. throw new TypeError('The transform should be a function');
  22343. }
  22344. this._rowTransform = RowTransformerValidator.createTransform(transformFunction);
  22345. }
  22346. }, {
  22347. key: "rowValidator",
  22348. set: function set(validateFunction) {
  22349. if (!lodash_isfunction_1.default(validateFunction)) {
  22350. throw new TypeError('The validate should be a function');
  22351. }
  22352. this._rowValidator = RowTransformerValidator.createValidator(validateFunction);
  22353. }
  22354. }], [{
  22355. key: "createTransform",
  22356. value: function createTransform(transformFunction) {
  22357. if (types_1.isSyncTransform(transformFunction)) {
  22358. return function (row, cb) {
  22359. var transformed = null;
  22360. try {
  22361. transformed = transformFunction(row);
  22362. } catch (e) {
  22363. return cb(e);
  22364. }
  22365. return cb(null, transformed);
  22366. };
  22367. }
  22368. return transformFunction;
  22369. }
  22370. }, {
  22371. key: "createValidator",
  22372. value: function createValidator(validateFunction) {
  22373. if (types_1.isSyncValidate(validateFunction)) {
  22374. return function (row, cb) {
  22375. cb(null, {
  22376. row: row,
  22377. isValid: validateFunction(row)
  22378. });
  22379. };
  22380. }
  22381. return function (row, cb) {
  22382. validateFunction(row, function (err, isValid, reason) {
  22383. if (err) {
  22384. return cb(err);
  22385. }
  22386. if (isValid) {
  22387. return cb(null, {
  22388. row: row,
  22389. isValid: isValid,
  22390. reason: reason
  22391. });
  22392. }
  22393. return cb(null, {
  22394. row: row,
  22395. isValid: false,
  22396. reason: reason
  22397. });
  22398. });
  22399. };
  22400. }
  22401. }]);
  22402. return RowTransformerValidator;
  22403. }();
  22404. exports.RowTransformerValidator = RowTransformerValidator;
  22405. },{"../types":166,"lodash.isfunction":321}],165:[function(require,module,exports){
  22406. "use strict";
  22407. Object.defineProperty(exports, "__esModule", {
  22408. value: true
  22409. });
  22410. var RowTransformerValidator_1 = require("./RowTransformerValidator");
  22411. Object.defineProperty(exports, "RowTransformerValidator", {
  22412. enumerable: true,
  22413. get: function get() {
  22414. return RowTransformerValidator_1.RowTransformerValidator;
  22415. }
  22416. });
  22417. var HeaderTransformer_1 = require("./HeaderTransformer");
  22418. Object.defineProperty(exports, "HeaderTransformer", {
  22419. enumerable: true,
  22420. get: function get() {
  22421. return HeaderTransformer_1.HeaderTransformer;
  22422. }
  22423. });
  22424. },{"./HeaderTransformer":163,"./RowTransformerValidator":164}],166:[function(require,module,exports){
  22425. "use strict";
  22426. Object.defineProperty(exports, "__esModule", {
  22427. value: true
  22428. });
  22429. exports.isSyncValidate = exports.isSyncTransform = void 0;
  22430. exports.isSyncTransform = function (transform) {
  22431. return transform.length === 1;
  22432. };
  22433. exports.isSyncValidate = function (validate) {
  22434. return validate.length === 1;
  22435. };
  22436. },{}],167:[function(require,module,exports){
  22437. 'use strict';
  22438. var asn1 = exports;
  22439. asn1.bignum = require('bn.js');
  22440. asn1.define = require('./asn1/api').define;
  22441. asn1.base = require('./asn1/base');
  22442. asn1.constants = require('./asn1/constants');
  22443. asn1.decoders = require('./asn1/decoders');
  22444. asn1.encoders = require('./asn1/encoders');
  22445. },{"./asn1/api":168,"./asn1/base":170,"./asn1/constants":174,"./asn1/decoders":176,"./asn1/encoders":179,"bn.js":181}],168:[function(require,module,exports){
  22446. 'use strict';
  22447. var encoders = require('./encoders');
  22448. var decoders = require('./decoders');
  22449. var inherits = require('inherits');
  22450. var api = exports;
  22451. api.define = function define(name, body) {
  22452. return new Entity(name, body);
  22453. };
  22454. function Entity(name, body) {
  22455. this.name = name;
  22456. this.body = body;
  22457. this.decoders = {};
  22458. this.encoders = {};
  22459. }
  22460. Entity.prototype._createNamed = function createNamed(Base) {
  22461. var name = this.name;
  22462. function Generated(entity) {
  22463. this._initNamed(entity, name);
  22464. }
  22465. inherits(Generated, Base);
  22466. Generated.prototype._initNamed = function _initNamed(entity, name) {
  22467. Base.call(this, entity, name);
  22468. };
  22469. return new Generated(this);
  22470. };
  22471. Entity.prototype._getDecoder = function _getDecoder(enc) {
  22472. enc = enc || 'der'; // Lazily create decoder
  22473. if (!this.decoders.hasOwnProperty(enc)) this.decoders[enc] = this._createNamed(decoders[enc]);
  22474. return this.decoders[enc];
  22475. };
  22476. Entity.prototype.decode = function decode(data, enc, options) {
  22477. return this._getDecoder(enc).decode(data, options);
  22478. };
  22479. Entity.prototype._getEncoder = function _getEncoder(enc) {
  22480. enc = enc || 'der'; // Lazily create encoder
  22481. if (!this.encoders.hasOwnProperty(enc)) this.encoders[enc] = this._createNamed(encoders[enc]);
  22482. return this.encoders[enc];
  22483. };
  22484. Entity.prototype.encode = function encode(data, enc,
  22485. /* internal */
  22486. reporter) {
  22487. return this._getEncoder(enc).encode(data, reporter);
  22488. };
  22489. },{"./decoders":176,"./encoders":179,"inherits":278}],169:[function(require,module,exports){
  22490. 'use strict';
  22491. 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); }
  22492. var inherits = require('inherits');
  22493. var Reporter = require('../base/reporter').Reporter;
  22494. var Buffer = require('safer-buffer').Buffer;
  22495. function DecoderBuffer(base, options) {
  22496. Reporter.call(this, options);
  22497. if (!Buffer.isBuffer(base)) {
  22498. this.error('Input not Buffer');
  22499. return;
  22500. }
  22501. this.base = base;
  22502. this.offset = 0;
  22503. this.length = base.length;
  22504. }
  22505. inherits(DecoderBuffer, Reporter);
  22506. exports.DecoderBuffer = DecoderBuffer;
  22507. DecoderBuffer.isDecoderBuffer = function isDecoderBuffer(data) {
  22508. if (data instanceof DecoderBuffer) {
  22509. return true;
  22510. } // Or accept compatible API
  22511. 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';
  22512. return isCompatible;
  22513. };
  22514. DecoderBuffer.prototype.save = function save() {
  22515. return {
  22516. offset: this.offset,
  22517. reporter: Reporter.prototype.save.call(this)
  22518. };
  22519. };
  22520. DecoderBuffer.prototype.restore = function restore(save) {
  22521. // Return skipped data
  22522. var res = new DecoderBuffer(this.base);
  22523. res.offset = save.offset;
  22524. res.length = this.offset;
  22525. this.offset = save.offset;
  22526. Reporter.prototype.restore.call(this, save.reporter);
  22527. return res;
  22528. };
  22529. DecoderBuffer.prototype.isEmpty = function isEmpty() {
  22530. return this.offset === this.length;
  22531. };
  22532. DecoderBuffer.prototype.readUInt8 = function readUInt8(fail) {
  22533. if (this.offset + 1 <= this.length) return this.base.readUInt8(this.offset++, true);else return this.error(fail || 'DecoderBuffer overrun');
  22534. };
  22535. DecoderBuffer.prototype.skip = function skip(bytes, fail) {
  22536. if (!(this.offset + bytes <= this.length)) return this.error(fail || 'DecoderBuffer overrun');
  22537. var res = new DecoderBuffer(this.base); // Share reporter state
  22538. res._reporterState = this._reporterState;
  22539. res.offset = this.offset;
  22540. res.length = this.offset + bytes;
  22541. this.offset += bytes;
  22542. return res;
  22543. };
  22544. DecoderBuffer.prototype.raw = function raw(save) {
  22545. return this.base.slice(save ? save.offset : this.offset, this.length);
  22546. };
  22547. function EncoderBuffer(value, reporter) {
  22548. if (Array.isArray(value)) {
  22549. this.length = 0;
  22550. this.value = value.map(function (item) {
  22551. if (!EncoderBuffer.isEncoderBuffer(item)) item = new EncoderBuffer(item, reporter);
  22552. this.length += item.length;
  22553. return item;
  22554. }, this);
  22555. } else if (typeof value === 'number') {
  22556. if (!(0 <= value && value <= 0xff)) return reporter.error('non-byte EncoderBuffer value');
  22557. this.value = value;
  22558. this.length = 1;
  22559. } else if (typeof value === 'string') {
  22560. this.value = value;
  22561. this.length = Buffer.byteLength(value);
  22562. } else if (Buffer.isBuffer(value)) {
  22563. this.value = value;
  22564. this.length = value.length;
  22565. } else {
  22566. return reporter.error('Unsupported type: ' + _typeof(value));
  22567. }
  22568. }
  22569. exports.EncoderBuffer = EncoderBuffer;
  22570. EncoderBuffer.isEncoderBuffer = function isEncoderBuffer(data) {
  22571. if (data instanceof EncoderBuffer) {
  22572. return true;
  22573. } // Or accept compatible API
  22574. var isCompatible = _typeof(data) === 'object' && data.constructor.name === 'EncoderBuffer' && typeof data.length === 'number' && typeof data.join === 'function';
  22575. return isCompatible;
  22576. };
  22577. EncoderBuffer.prototype.join = function join(out, offset) {
  22578. if (!out) out = Buffer.alloc(this.length);
  22579. if (!offset) offset = 0;
  22580. if (this.length === 0) return out;
  22581. if (Array.isArray(this.value)) {
  22582. this.value.forEach(function (item) {
  22583. item.join(out, offset);
  22584. offset += item.length;
  22585. });
  22586. } else {
  22587. 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);
  22588. offset += this.length;
  22589. }
  22590. return out;
  22591. };
  22592. },{"../base/reporter":172,"inherits":278,"safer-buffer":385}],170:[function(require,module,exports){
  22593. 'use strict';
  22594. var base = exports;
  22595. base.Reporter = require('./reporter').Reporter;
  22596. base.DecoderBuffer = require('./buffer').DecoderBuffer;
  22597. base.EncoderBuffer = require('./buffer').EncoderBuffer;
  22598. base.Node = require('./node');
  22599. },{"./buffer":169,"./node":171,"./reporter":172}],171:[function(require,module,exports){
  22600. 'use strict';
  22601. 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); }
  22602. var Reporter = require('../base/reporter').Reporter;
  22603. var EncoderBuffer = require('../base/buffer').EncoderBuffer;
  22604. var DecoderBuffer = require('../base/buffer').DecoderBuffer;
  22605. var assert = require('minimalistic-assert'); // Supported tags
  22606. 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
  22607. var methods = ['key', 'obj', 'use', 'optional', 'explicit', 'implicit', 'def', 'choice', 'any', 'contains'].concat(tags); // Overrided methods list
  22608. var overrided = ['_peekTag', '_decodeTag', '_use', '_decodeStr', '_decodeObjid', '_decodeTime', '_decodeNull', '_decodeInt', '_decodeBool', '_decodeList', '_encodeComposite', '_encodeStr', '_encodeObjid', '_encodeTime', '_encodeNull', '_encodeInt', '_encodeBool'];
  22609. function Node(enc, parent, name) {
  22610. var state = {};
  22611. this._baseState = state;
  22612. state.name = name;
  22613. state.enc = enc;
  22614. state.parent = parent || null;
  22615. state.children = null; // State
  22616. state.tag = null;
  22617. state.args = null;
  22618. state.reverseArgs = null;
  22619. state.choice = null;
  22620. state.optional = false;
  22621. state.any = false;
  22622. state.obj = false;
  22623. state.use = null;
  22624. state.useDecoder = null;
  22625. state.key = null;
  22626. state['default'] = null;
  22627. state.explicit = null;
  22628. state.implicit = null;
  22629. state.contains = null; // Should create new instance on each method
  22630. if (!state.parent) {
  22631. state.children = [];
  22632. this._wrap();
  22633. }
  22634. }
  22635. module.exports = Node;
  22636. var stateProps = ['enc', 'parent', 'children', 'tag', 'args', 'reverseArgs', 'choice', 'optional', 'any', 'obj', 'use', 'alteredUse', 'key', 'default', 'explicit', 'implicit', 'contains'];
  22637. Node.prototype.clone = function clone() {
  22638. var state = this._baseState;
  22639. var cstate = {};
  22640. stateProps.forEach(function (prop) {
  22641. cstate[prop] = state[prop];
  22642. });
  22643. var res = new this.constructor(cstate.parent);
  22644. res._baseState = cstate;
  22645. return res;
  22646. };
  22647. Node.prototype._wrap = function wrap() {
  22648. var state = this._baseState;
  22649. methods.forEach(function (method) {
  22650. this[method] = function _wrappedMethod() {
  22651. var clone = new this.constructor(this);
  22652. state.children.push(clone);
  22653. return clone[method].apply(clone, arguments);
  22654. };
  22655. }, this);
  22656. };
  22657. Node.prototype._init = function init(body) {
  22658. var state = this._baseState;
  22659. assert(state.parent === null);
  22660. body.call(this); // Filter children
  22661. state.children = state.children.filter(function (child) {
  22662. return child._baseState.parent === this;
  22663. }, this);
  22664. assert.equal(state.children.length, 1, 'Root node can have only one child');
  22665. };
  22666. Node.prototype._useArgs = function useArgs(args) {
  22667. var state = this._baseState; // Filter children and args
  22668. var children = args.filter(function (arg) {
  22669. return arg instanceof this.constructor;
  22670. }, this);
  22671. args = args.filter(function (arg) {
  22672. return !(arg instanceof this.constructor);
  22673. }, this);
  22674. if (children.length !== 0) {
  22675. assert(state.children === null);
  22676. state.children = children; // Replace parent to maintain backward link
  22677. children.forEach(function (child) {
  22678. child._baseState.parent = this;
  22679. }, this);
  22680. }
  22681. if (args.length !== 0) {
  22682. assert(state.args === null);
  22683. state.args = args;
  22684. state.reverseArgs = args.map(function (arg) {
  22685. if (_typeof(arg) !== 'object' || arg.constructor !== Object) return arg;
  22686. var res = {};
  22687. Object.keys(arg).forEach(function (key) {
  22688. if (key == (key | 0)) key |= 0;
  22689. var value = arg[key];
  22690. res[value] = key;
  22691. });
  22692. return res;
  22693. });
  22694. }
  22695. }; //
  22696. // Overrided methods
  22697. //
  22698. overrided.forEach(function (method) {
  22699. Node.prototype[method] = function _overrided() {
  22700. var state = this._baseState;
  22701. throw new Error(method + ' not implemented for encoding: ' + state.enc);
  22702. };
  22703. }); //
  22704. // Public methods
  22705. //
  22706. tags.forEach(function (tag) {
  22707. Node.prototype[tag] = function _tagMethod() {
  22708. var state = this._baseState;
  22709. var args = Array.prototype.slice.call(arguments);
  22710. assert(state.tag === null);
  22711. state.tag = tag;
  22712. this._useArgs(args);
  22713. return this;
  22714. };
  22715. });
  22716. Node.prototype.use = function use(item) {
  22717. assert(item);
  22718. var state = this._baseState;
  22719. assert(state.use === null);
  22720. state.use = item;
  22721. return this;
  22722. };
  22723. Node.prototype.optional = function optional() {
  22724. var state = this._baseState;
  22725. state.optional = true;
  22726. return this;
  22727. };
  22728. Node.prototype.def = function def(val) {
  22729. var state = this._baseState;
  22730. assert(state['default'] === null);
  22731. state['default'] = val;
  22732. state.optional = true;
  22733. return this;
  22734. };
  22735. Node.prototype.explicit = function explicit(num) {
  22736. var state = this._baseState;
  22737. assert(state.explicit === null && state.implicit === null);
  22738. state.explicit = num;
  22739. return this;
  22740. };
  22741. Node.prototype.implicit = function implicit(num) {
  22742. var state = this._baseState;
  22743. assert(state.explicit === null && state.implicit === null);
  22744. state.implicit = num;
  22745. return this;
  22746. };
  22747. Node.prototype.obj = function obj() {
  22748. var state = this._baseState;
  22749. var args = Array.prototype.slice.call(arguments);
  22750. state.obj = true;
  22751. if (args.length !== 0) this._useArgs(args);
  22752. return this;
  22753. };
  22754. Node.prototype.key = function key(newKey) {
  22755. var state = this._baseState;
  22756. assert(state.key === null);
  22757. state.key = newKey;
  22758. return this;
  22759. };
  22760. Node.prototype.any = function any() {
  22761. var state = this._baseState;
  22762. state.any = true;
  22763. return this;
  22764. };
  22765. Node.prototype.choice = function choice(obj) {
  22766. var state = this._baseState;
  22767. assert(state.choice === null);
  22768. state.choice = obj;
  22769. this._useArgs(Object.keys(obj).map(function (key) {
  22770. return obj[key];
  22771. }));
  22772. return this;
  22773. };
  22774. Node.prototype.contains = function contains(item) {
  22775. var state = this._baseState;
  22776. assert(state.use === null);
  22777. state.contains = item;
  22778. return this;
  22779. }; //
  22780. // Decoding
  22781. //
  22782. Node.prototype._decode = function decode(input, options) {
  22783. var state = this._baseState; // Decode root node
  22784. if (state.parent === null) return input.wrapResult(state.children[0]._decode(input, options));
  22785. var result = state['default'];
  22786. var present = true;
  22787. var prevKey = null;
  22788. if (state.key !== null) prevKey = input.enterKey(state.key); // Check if tag is there
  22789. if (state.optional) {
  22790. var tag = null;
  22791. if (state.explicit !== null) tag = state.explicit;else if (state.implicit !== null) tag = state.implicit;else if (state.tag !== null) tag = state.tag;
  22792. if (tag === null && !state.any) {
  22793. // Trial and Error
  22794. var save = input.save();
  22795. try {
  22796. if (state.choice === null) this._decodeGeneric(state.tag, input, options);else this._decodeChoice(input, options);
  22797. present = true;
  22798. } catch (e) {
  22799. present = false;
  22800. }
  22801. input.restore(save);
  22802. } else {
  22803. present = this._peekTag(input, tag, state.any);
  22804. if (input.isError(present)) return present;
  22805. }
  22806. } // Push object on stack
  22807. var prevObj;
  22808. if (state.obj && present) prevObj = input.enterObject();
  22809. if (present) {
  22810. // Unwrap explicit values
  22811. if (state.explicit !== null) {
  22812. var explicit = this._decodeTag(input, state.explicit);
  22813. if (input.isError(explicit)) return explicit;
  22814. input = explicit;
  22815. }
  22816. var start = input.offset; // Unwrap implicit and normal values
  22817. if (state.use === null && state.choice === null) {
  22818. var _save;
  22819. if (state.any) _save = input.save();
  22820. var body = this._decodeTag(input, state.implicit !== null ? state.implicit : state.tag, state.any);
  22821. if (input.isError(body)) return body;
  22822. if (state.any) result = input.raw(_save);else input = body;
  22823. }
  22824. if (options && options.track && state.tag !== null) options.track(input.path(), start, input.length, 'tagged');
  22825. if (options && options.track && state.tag !== null) options.track(input.path(), input.offset, input.length, 'content'); // Select proper method for tag
  22826. if (state.any) {// no-op
  22827. } else if (state.choice === null) {
  22828. result = this._decodeGeneric(state.tag, input, options);
  22829. } else {
  22830. result = this._decodeChoice(input, options);
  22831. }
  22832. if (input.isError(result)) return result; // Decode children
  22833. if (!state.any && state.choice === null && state.children !== null) {
  22834. state.children.forEach(function decodeChildren(child) {
  22835. // NOTE: We are ignoring errors here, to let parser continue with other
  22836. // parts of encoded data
  22837. child._decode(input, options);
  22838. });
  22839. } // Decode contained/encoded by schema, only in bit or octet strings
  22840. if (state.contains && (state.tag === 'octstr' || state.tag === 'bitstr')) {
  22841. var data = new DecoderBuffer(result);
  22842. result = this._getUse(state.contains, input._reporterState.obj)._decode(data, options);
  22843. }
  22844. } // Pop object
  22845. if (state.obj && present) result = input.leaveObject(prevObj); // Set key
  22846. if (state.key !== null && (result !== null || present === true)) input.leaveKey(prevKey, state.key, result);else if (prevKey !== null) input.exitKey(prevKey);
  22847. return result;
  22848. };
  22849. Node.prototype._decodeGeneric = function decodeGeneric(tag, input, options) {
  22850. var state = this._baseState;
  22851. if (tag === 'seq' || tag === 'set') return null;
  22852. 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);
  22853. if (state.use !== null) {
  22854. return this._getUse(state.use, input._reporterState.obj)._decode(input, options);
  22855. } else {
  22856. return input.error('unknown tag: ' + tag);
  22857. }
  22858. };
  22859. Node.prototype._getUse = function _getUse(entity, obj) {
  22860. var state = this._baseState; // Create altered use decoder if implicit is set
  22861. state.useDecoder = this._use(entity, obj);
  22862. assert(state.useDecoder._baseState.parent === null);
  22863. state.useDecoder = state.useDecoder._baseState.children[0];
  22864. if (state.implicit !== state.useDecoder._baseState.implicit) {
  22865. state.useDecoder = state.useDecoder.clone();
  22866. state.useDecoder._baseState.implicit = state.implicit;
  22867. }
  22868. return state.useDecoder;
  22869. };
  22870. Node.prototype._decodeChoice = function decodeChoice(input, options) {
  22871. var state = this._baseState;
  22872. var result = null;
  22873. var match = false;
  22874. Object.keys(state.choice).some(function (key) {
  22875. var save = input.save();
  22876. var node = state.choice[key];
  22877. try {
  22878. var value = node._decode(input, options);
  22879. if (input.isError(value)) return false;
  22880. result = {
  22881. type: key,
  22882. value: value
  22883. };
  22884. match = true;
  22885. } catch (e) {
  22886. input.restore(save);
  22887. return false;
  22888. }
  22889. return true;
  22890. }, this);
  22891. if (!match) return input.error('Choice not matched');
  22892. return result;
  22893. }; //
  22894. // Encoding
  22895. //
  22896. Node.prototype._createEncoderBuffer = function createEncoderBuffer(data) {
  22897. return new EncoderBuffer(data, this.reporter);
  22898. };
  22899. Node.prototype._encode = function encode(data, reporter, parent) {
  22900. var state = this._baseState;
  22901. if (state['default'] !== null && state['default'] === data) return;
  22902. var result = this._encodeValue(data, reporter, parent);
  22903. if (result === undefined) return;
  22904. if (this._skipDefault(result, reporter, parent)) return;
  22905. return result;
  22906. };
  22907. Node.prototype._encodeValue = function encode(data, reporter, parent) {
  22908. var state = this._baseState; // Decode root node
  22909. if (state.parent === null) return state.children[0]._encode(data, reporter || new Reporter());
  22910. var result = null; // Set reporter to share it with a child class
  22911. this.reporter = reporter; // Check if data is there
  22912. if (state.optional && data === undefined) {
  22913. if (state['default'] !== null) data = state['default'];else return;
  22914. } // Encode children first
  22915. var content = null;
  22916. var primitive = false;
  22917. if (state.any) {
  22918. // Anything that was given is translated to buffer
  22919. result = this._createEncoderBuffer(data);
  22920. } else if (state.choice) {
  22921. result = this._encodeChoice(data, reporter);
  22922. } else if (state.contains) {
  22923. content = this._getUse(state.contains, parent)._encode(data, reporter);
  22924. primitive = true;
  22925. } else if (state.children) {
  22926. content = state.children.map(function (child) {
  22927. if (child._baseState.tag === 'null_') return child._encode(null, reporter, data);
  22928. if (child._baseState.key === null) return reporter.error('Child should have a key');
  22929. var prevKey = reporter.enterKey(child._baseState.key);
  22930. if (_typeof(data) !== 'object') return reporter.error('Child expected, but input is not object');
  22931. var res = child._encode(data[child._baseState.key], reporter, data);
  22932. reporter.leaveKey(prevKey);
  22933. return res;
  22934. }, this).filter(function (child) {
  22935. return child;
  22936. });
  22937. content = this._createEncoderBuffer(content);
  22938. } else {
  22939. if (state.tag === 'seqof' || state.tag === 'setof') {
  22940. // TODO(indutny): this should be thrown on DSL level
  22941. if (!(state.args && state.args.length === 1)) return reporter.error('Too many args for : ' + state.tag);
  22942. if (!Array.isArray(data)) return reporter.error('seqof/setof, but data is not Array');
  22943. var child = this.clone();
  22944. child._baseState.implicit = null;
  22945. content = this._createEncoderBuffer(data.map(function (item) {
  22946. var state = this._baseState;
  22947. return this._getUse(state.args[0], data)._encode(item, reporter);
  22948. }, child));
  22949. } else if (state.use !== null) {
  22950. result = this._getUse(state.use, parent)._encode(data, reporter);
  22951. } else {
  22952. content = this._encodePrimitive(state.tag, data);
  22953. primitive = true;
  22954. }
  22955. } // Encode data itself
  22956. if (!state.any && state.choice === null) {
  22957. var tag = state.implicit !== null ? state.implicit : state.tag;
  22958. var cls = state.implicit === null ? 'universal' : 'context';
  22959. if (tag === null) {
  22960. if (state.use === null) reporter.error('Tag could be omitted only for .use()');
  22961. } else {
  22962. if (state.use === null) result = this._encodeComposite(tag, primitive, cls, content);
  22963. }
  22964. } // Wrap in explicit
  22965. if (state.explicit !== null) result = this._encodeComposite(state.explicit, false, 'context', result);
  22966. return result;
  22967. };
  22968. Node.prototype._encodeChoice = function encodeChoice(data, reporter) {
  22969. var state = this._baseState;
  22970. var node = state.choice[data.type];
  22971. if (!node) {
  22972. assert(false, data.type + ' not found in ' + JSON.stringify(Object.keys(state.choice)));
  22973. }
  22974. return node._encode(data.value, reporter);
  22975. };
  22976. Node.prototype._encodePrimitive = function encodePrimitive(tag, data) {
  22977. var state = this._baseState;
  22978. 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);
  22979. };
  22980. Node.prototype._isNumstr = function isNumstr(str) {
  22981. return /^[0-9 ]*$/.test(str);
  22982. };
  22983. Node.prototype._isPrintstr = function isPrintstr(str) {
  22984. return /^[A-Za-z0-9 '()+,-./:=?]*$/.test(str);
  22985. };
  22986. },{"../base/buffer":169,"../base/reporter":172,"minimalistic-assert":328}],172:[function(require,module,exports){
  22987. 'use strict';
  22988. var inherits = require('inherits');
  22989. function Reporter(options) {
  22990. this._reporterState = {
  22991. obj: null,
  22992. path: [],
  22993. options: options || {},
  22994. errors: []
  22995. };
  22996. }
  22997. exports.Reporter = Reporter;
  22998. Reporter.prototype.isError = function isError(obj) {
  22999. return obj instanceof ReporterError;
  23000. };
  23001. Reporter.prototype.save = function save() {
  23002. var state = this._reporterState;
  23003. return {
  23004. obj: state.obj,
  23005. pathLen: state.path.length
  23006. };
  23007. };
  23008. Reporter.prototype.restore = function restore(data) {
  23009. var state = this._reporterState;
  23010. state.obj = data.obj;
  23011. state.path = state.path.slice(0, data.pathLen);
  23012. };
  23013. Reporter.prototype.enterKey = function enterKey(key) {
  23014. return this._reporterState.path.push(key);
  23015. };
  23016. Reporter.prototype.exitKey = function exitKey(index) {
  23017. var state = this._reporterState;
  23018. state.path = state.path.slice(0, index - 1);
  23019. };
  23020. Reporter.prototype.leaveKey = function leaveKey(index, key, value) {
  23021. var state = this._reporterState;
  23022. this.exitKey(index);
  23023. if (state.obj !== null) state.obj[key] = value;
  23024. };
  23025. Reporter.prototype.path = function path() {
  23026. return this._reporterState.path.join('/');
  23027. };
  23028. Reporter.prototype.enterObject = function enterObject() {
  23029. var state = this._reporterState;
  23030. var prev = state.obj;
  23031. state.obj = {};
  23032. return prev;
  23033. };
  23034. Reporter.prototype.leaveObject = function leaveObject(prev) {
  23035. var state = this._reporterState;
  23036. var now = state.obj;
  23037. state.obj = prev;
  23038. return now;
  23039. };
  23040. Reporter.prototype.error = function error(msg) {
  23041. var err;
  23042. var state = this._reporterState;
  23043. var inherited = msg instanceof ReporterError;
  23044. if (inherited) {
  23045. err = msg;
  23046. } else {
  23047. err = new ReporterError(state.path.map(function (elem) {
  23048. return '[' + JSON.stringify(elem) + ']';
  23049. }).join(''), msg.message || msg, msg.stack);
  23050. }
  23051. if (!state.options.partial) throw err;
  23052. if (!inherited) state.errors.push(err);
  23053. return err;
  23054. };
  23055. Reporter.prototype.wrapResult = function wrapResult(result) {
  23056. var state = this._reporterState;
  23057. if (!state.options.partial) return result;
  23058. return {
  23059. result: this.isError(result) ? null : result,
  23060. errors: state.errors
  23061. };
  23062. };
  23063. function ReporterError(path, msg) {
  23064. this.path = path;
  23065. this.rethrow(msg);
  23066. }
  23067. inherits(ReporterError, Error);
  23068. ReporterError.prototype.rethrow = function rethrow(msg) {
  23069. this.message = msg + ' at: ' + (this.path || '(shallow)');
  23070. if (Error.captureStackTrace) Error.captureStackTrace(this, ReporterError);
  23071. if (!this.stack) {
  23072. try {
  23073. // IE only adds stack when thrown
  23074. throw new Error(this.message);
  23075. } catch (e) {
  23076. this.stack = e.stack;
  23077. }
  23078. }
  23079. return this;
  23080. };
  23081. },{"inherits":278}],173:[function(require,module,exports){
  23082. 'use strict'; // Helper
  23083. function reverse(map) {
  23084. var res = {};
  23085. Object.keys(map).forEach(function (key) {
  23086. // Convert key to integer if it is stringified
  23087. if ((key | 0) == key) key = key | 0;
  23088. var value = map[key];
  23089. res[value] = key;
  23090. });
  23091. return res;
  23092. }
  23093. exports.tagClass = {
  23094. 0: 'universal',
  23095. 1: 'application',
  23096. 2: 'context',
  23097. 3: 'private'
  23098. };
  23099. exports.tagClassByName = reverse(exports.tagClass);
  23100. exports.tag = {
  23101. 0x00: 'end',
  23102. 0x01: 'bool',
  23103. 0x02: 'int',
  23104. 0x03: 'bitstr',
  23105. 0x04: 'octstr',
  23106. 0x05: 'null_',
  23107. 0x06: 'objid',
  23108. 0x07: 'objDesc',
  23109. 0x08: 'external',
  23110. 0x09: 'real',
  23111. 0x0a: 'enum',
  23112. 0x0b: 'embed',
  23113. 0x0c: 'utf8str',
  23114. 0x0d: 'relativeOid',
  23115. 0x10: 'seq',
  23116. 0x11: 'set',
  23117. 0x12: 'numstr',
  23118. 0x13: 'printstr',
  23119. 0x14: 't61str',
  23120. 0x15: 'videostr',
  23121. 0x16: 'ia5str',
  23122. 0x17: 'utctime',
  23123. 0x18: 'gentime',
  23124. 0x19: 'graphstr',
  23125. 0x1a: 'iso646str',
  23126. 0x1b: 'genstr',
  23127. 0x1c: 'unistr',
  23128. 0x1d: 'charstr',
  23129. 0x1e: 'bmpstr'
  23130. };
  23131. exports.tagByName = reverse(exports.tag);
  23132. },{}],174:[function(require,module,exports){
  23133. 'use strict';
  23134. var constants = exports; // Helper
  23135. constants._reverse = function reverse(map) {
  23136. var res = {};
  23137. Object.keys(map).forEach(function (key) {
  23138. // Convert key to integer if it is stringified
  23139. if ((key | 0) == key) key = key | 0;
  23140. var value = map[key];
  23141. res[value] = key;
  23142. });
  23143. return res;
  23144. };
  23145. constants.der = require('./der');
  23146. },{"./der":173}],175:[function(require,module,exports){
  23147. 'use strict';
  23148. var inherits = require('inherits');
  23149. var bignum = require('bn.js');
  23150. var DecoderBuffer = require('../base/buffer').DecoderBuffer;
  23151. var Node = require('../base/node'); // Import DER constants
  23152. var der = require('../constants/der');
  23153. function DERDecoder(entity) {
  23154. this.enc = 'der';
  23155. this.name = entity.name;
  23156. this.entity = entity; // Construct base tree
  23157. this.tree = new DERNode();
  23158. this.tree._init(entity.body);
  23159. }
  23160. module.exports = DERDecoder;
  23161. DERDecoder.prototype.decode = function decode(data, options) {
  23162. if (!DecoderBuffer.isDecoderBuffer(data)) {
  23163. data = new DecoderBuffer(data, options);
  23164. }
  23165. return this.tree._decode(data, options);
  23166. }; // Tree methods
  23167. function DERNode(parent) {
  23168. Node.call(this, 'der', parent);
  23169. }
  23170. inherits(DERNode, Node);
  23171. DERNode.prototype._peekTag = function peekTag(buffer, tag, any) {
  23172. if (buffer.isEmpty()) return false;
  23173. var state = buffer.save();
  23174. var decodedTag = derDecodeTag(buffer, 'Failed to peek tag: "' + tag + '"');
  23175. if (buffer.isError(decodedTag)) return decodedTag;
  23176. buffer.restore(state);
  23177. return decodedTag.tag === tag || decodedTag.tagStr === tag || decodedTag.tagStr + 'of' === tag || any;
  23178. };
  23179. DERNode.prototype._decodeTag = function decodeTag(buffer, tag, any) {
  23180. var decodedTag = derDecodeTag(buffer, 'Failed to decode tag of "' + tag + '"');
  23181. if (buffer.isError(decodedTag)) return decodedTag;
  23182. var len = derDecodeLen(buffer, decodedTag.primitive, 'Failed to get length of "' + tag + '"'); // Failure
  23183. if (buffer.isError(len)) return len;
  23184. if (!any && decodedTag.tag !== tag && decodedTag.tagStr !== tag && decodedTag.tagStr + 'of' !== tag) {
  23185. return buffer.error('Failed to match tag: "' + tag + '"');
  23186. }
  23187. if (decodedTag.primitive || len !== null) return buffer.skip(len, 'Failed to match body of: "' + tag + '"'); // Indefinite length... find END tag
  23188. var state = buffer.save();
  23189. var res = this._skipUntilEnd(buffer, 'Failed to skip indefinite length body: "' + this.tag + '"');
  23190. if (buffer.isError(res)) return res;
  23191. len = buffer.offset - state.offset;
  23192. buffer.restore(state);
  23193. return buffer.skip(len, 'Failed to match body of: "' + tag + '"');
  23194. };
  23195. DERNode.prototype._skipUntilEnd = function skipUntilEnd(buffer, fail) {
  23196. for (;;) {
  23197. var tag = derDecodeTag(buffer, fail);
  23198. if (buffer.isError(tag)) return tag;
  23199. var len = derDecodeLen(buffer, tag.primitive, fail);
  23200. if (buffer.isError(len)) return len;
  23201. var res = void 0;
  23202. if (tag.primitive || len !== null) res = buffer.skip(len);else res = this._skipUntilEnd(buffer, fail); // Failure
  23203. if (buffer.isError(res)) return res;
  23204. if (tag.tagStr === 'end') break;
  23205. }
  23206. };
  23207. DERNode.prototype._decodeList = function decodeList(buffer, tag, decoder, options) {
  23208. var result = [];
  23209. while (!buffer.isEmpty()) {
  23210. var possibleEnd = this._peekTag(buffer, 'end');
  23211. if (buffer.isError(possibleEnd)) return possibleEnd;
  23212. var res = decoder.decode(buffer, 'der', options);
  23213. if (buffer.isError(res) && possibleEnd) break;
  23214. result.push(res);
  23215. }
  23216. return result;
  23217. };
  23218. DERNode.prototype._decodeStr = function decodeStr(buffer, tag) {
  23219. if (tag === 'bitstr') {
  23220. var unused = buffer.readUInt8();
  23221. if (buffer.isError(unused)) return unused;
  23222. return {
  23223. unused: unused,
  23224. data: buffer.raw()
  23225. };
  23226. } else if (tag === 'bmpstr') {
  23227. var raw = buffer.raw();
  23228. if (raw.length % 2 === 1) return buffer.error('Decoding of string type: bmpstr length mismatch');
  23229. var str = '';
  23230. for (var i = 0; i < raw.length / 2; i++) {
  23231. str += String.fromCharCode(raw.readUInt16BE(i * 2));
  23232. }
  23233. return str;
  23234. } else if (tag === 'numstr') {
  23235. var numstr = buffer.raw().toString('ascii');
  23236. if (!this._isNumstr(numstr)) {
  23237. return buffer.error('Decoding of string type: ' + 'numstr unsupported characters');
  23238. }
  23239. return numstr;
  23240. } else if (tag === 'octstr') {
  23241. return buffer.raw();
  23242. } else if (tag === 'objDesc') {
  23243. return buffer.raw();
  23244. } else if (tag === 'printstr') {
  23245. var printstr = buffer.raw().toString('ascii');
  23246. if (!this._isPrintstr(printstr)) {
  23247. return buffer.error('Decoding of string type: ' + 'printstr unsupported characters');
  23248. }
  23249. return printstr;
  23250. } else if (/str$/.test(tag)) {
  23251. return buffer.raw().toString();
  23252. } else {
  23253. return buffer.error('Decoding of string type: ' + tag + ' unsupported');
  23254. }
  23255. };
  23256. DERNode.prototype._decodeObjid = function decodeObjid(buffer, values, relative) {
  23257. var result;
  23258. var identifiers = [];
  23259. var ident = 0;
  23260. var subident = 0;
  23261. while (!buffer.isEmpty()) {
  23262. subident = buffer.readUInt8();
  23263. ident <<= 7;
  23264. ident |= subident & 0x7f;
  23265. if ((subident & 0x80) === 0) {
  23266. identifiers.push(ident);
  23267. ident = 0;
  23268. }
  23269. }
  23270. if (subident & 0x80) identifiers.push(ident);
  23271. var first = identifiers[0] / 40 | 0;
  23272. var second = identifiers[0] % 40;
  23273. if (relative) result = identifiers;else result = [first, second].concat(identifiers.slice(1));
  23274. if (values) {
  23275. var tmp = values[result.join(' ')];
  23276. if (tmp === undefined) tmp = values[result.join('.')];
  23277. if (tmp !== undefined) result = tmp;
  23278. }
  23279. return result;
  23280. };
  23281. DERNode.prototype._decodeTime = function decodeTime(buffer, tag) {
  23282. var str = buffer.raw().toString();
  23283. var year;
  23284. var mon;
  23285. var day;
  23286. var hour;
  23287. var min;
  23288. var sec;
  23289. if (tag === 'gentime') {
  23290. year = str.slice(0, 4) | 0;
  23291. mon = str.slice(4, 6) | 0;
  23292. day = str.slice(6, 8) | 0;
  23293. hour = str.slice(8, 10) | 0;
  23294. min = str.slice(10, 12) | 0;
  23295. sec = str.slice(12, 14) | 0;
  23296. } else if (tag === 'utctime') {
  23297. year = str.slice(0, 2) | 0;
  23298. mon = str.slice(2, 4) | 0;
  23299. day = str.slice(4, 6) | 0;
  23300. hour = str.slice(6, 8) | 0;
  23301. min = str.slice(8, 10) | 0;
  23302. sec = str.slice(10, 12) | 0;
  23303. if (year < 70) year = 2000 + year;else year = 1900 + year;
  23304. } else {
  23305. return buffer.error('Decoding ' + tag + ' time is not supported yet');
  23306. }
  23307. return Date.UTC(year, mon - 1, day, hour, min, sec, 0);
  23308. };
  23309. DERNode.prototype._decodeNull = function decodeNull() {
  23310. return null;
  23311. };
  23312. DERNode.prototype._decodeBool = function decodeBool(buffer) {
  23313. var res = buffer.readUInt8();
  23314. if (buffer.isError(res)) return res;else return res !== 0;
  23315. };
  23316. DERNode.prototype._decodeInt = function decodeInt(buffer, values) {
  23317. // Bigint, return as it is (assume big endian)
  23318. var raw = buffer.raw();
  23319. var res = new bignum(raw);
  23320. if (values) res = values[res.toString(10)] || res;
  23321. return res;
  23322. };
  23323. DERNode.prototype._use = function use(entity, obj) {
  23324. if (typeof entity === 'function') entity = entity(obj);
  23325. return entity._getDecoder('der').tree;
  23326. }; // Utility methods
  23327. function derDecodeTag(buf, fail) {
  23328. var tag = buf.readUInt8(fail);
  23329. if (buf.isError(tag)) return tag;
  23330. var cls = der.tagClass[tag >> 6];
  23331. var primitive = (tag & 0x20) === 0; // Multi-octet tag - load
  23332. if ((tag & 0x1f) === 0x1f) {
  23333. var oct = tag;
  23334. tag = 0;
  23335. while ((oct & 0x80) === 0x80) {
  23336. oct = buf.readUInt8(fail);
  23337. if (buf.isError(oct)) return oct;
  23338. tag <<= 7;
  23339. tag |= oct & 0x7f;
  23340. }
  23341. } else {
  23342. tag &= 0x1f;
  23343. }
  23344. var tagStr = der.tag[tag];
  23345. return {
  23346. cls: cls,
  23347. primitive: primitive,
  23348. tag: tag,
  23349. tagStr: tagStr
  23350. };
  23351. }
  23352. function derDecodeLen(buf, primitive, fail) {
  23353. var len = buf.readUInt8(fail);
  23354. if (buf.isError(len)) return len; // Indefinite form
  23355. if (!primitive && len === 0x80) return null; // Definite form
  23356. if ((len & 0x80) === 0) {
  23357. // Short form
  23358. return len;
  23359. } // Long form
  23360. var num = len & 0x7f;
  23361. if (num > 4) return buf.error('length octect is too long');
  23362. len = 0;
  23363. for (var i = 0; i < num; i++) {
  23364. len <<= 8;
  23365. var j = buf.readUInt8(fail);
  23366. if (buf.isError(j)) return j;
  23367. len |= j;
  23368. }
  23369. return len;
  23370. }
  23371. },{"../base/buffer":169,"../base/node":171,"../constants/der":173,"bn.js":181,"inherits":278}],176:[function(require,module,exports){
  23372. 'use strict';
  23373. var decoders = exports;
  23374. decoders.der = require('./der');
  23375. decoders.pem = require('./pem');
  23376. },{"./der":175,"./pem":177}],177:[function(require,module,exports){
  23377. 'use strict';
  23378. var inherits = require('inherits');
  23379. var Buffer = require('safer-buffer').Buffer;
  23380. var DERDecoder = require('./der');
  23381. function PEMDecoder(entity) {
  23382. DERDecoder.call(this, entity);
  23383. this.enc = 'pem';
  23384. }
  23385. inherits(PEMDecoder, DERDecoder);
  23386. module.exports = PEMDecoder;
  23387. PEMDecoder.prototype.decode = function decode(data, options) {
  23388. var lines = data.toString().split(/[\r\n]+/g);
  23389. var label = options.label.toUpperCase();
  23390. var re = /^-----(BEGIN|END) ([^-]+)-----$/;
  23391. var start = -1;
  23392. var end = -1;
  23393. for (var i = 0; i < lines.length; i++) {
  23394. var match = lines[i].match(re);
  23395. if (match === null) continue;
  23396. if (match[2] !== label) continue;
  23397. if (start === -1) {
  23398. if (match[1] !== 'BEGIN') break;
  23399. start = i;
  23400. } else {
  23401. if (match[1] !== 'END') break;
  23402. end = i;
  23403. break;
  23404. }
  23405. }
  23406. if (start === -1 || end === -1) throw new Error('PEM section not found for: ' + label);
  23407. var base64 = lines.slice(start + 1, end).join(''); // Remove excessive symbols
  23408. base64.replace(/[^a-z0-9+/=]+/gi, '');
  23409. var input = Buffer.from(base64, 'base64');
  23410. return DERDecoder.prototype.decode.call(this, input, options);
  23411. };
  23412. },{"./der":175,"inherits":278,"safer-buffer":385}],178:[function(require,module,exports){
  23413. 'use strict';
  23414. var inherits = require('inherits');
  23415. var Buffer = require('safer-buffer').Buffer;
  23416. var Node = require('../base/node'); // Import DER constants
  23417. var der = require('../constants/der');
  23418. function DEREncoder(entity) {
  23419. this.enc = 'der';
  23420. this.name = entity.name;
  23421. this.entity = entity; // Construct base tree
  23422. this.tree = new DERNode();
  23423. this.tree._init(entity.body);
  23424. }
  23425. module.exports = DEREncoder;
  23426. DEREncoder.prototype.encode = function encode(data, reporter) {
  23427. return this.tree._encode(data, reporter).join();
  23428. }; // Tree methods
  23429. function DERNode(parent) {
  23430. Node.call(this, 'der', parent);
  23431. }
  23432. inherits(DERNode, Node);
  23433. DERNode.prototype._encodeComposite = function encodeComposite(tag, primitive, cls, content) {
  23434. var encodedTag = encodeTag(tag, primitive, cls, this.reporter); // Short form
  23435. if (content.length < 0x80) {
  23436. var _header = Buffer.alloc(2);
  23437. _header[0] = encodedTag;
  23438. _header[1] = content.length;
  23439. return this._createEncoderBuffer([_header, content]);
  23440. } // Long form
  23441. // Count octets required to store length
  23442. var lenOctets = 1;
  23443. for (var i = content.length; i >= 0x100; i >>= 8) {
  23444. lenOctets++;
  23445. }
  23446. var header = Buffer.alloc(1 + 1 + lenOctets);
  23447. header[0] = encodedTag;
  23448. header[1] = 0x80 | lenOctets;
  23449. for (var _i = 1 + lenOctets, j = content.length; j > 0; _i--, j >>= 8) {
  23450. header[_i] = j & 0xff;
  23451. }
  23452. return this._createEncoderBuffer([header, content]);
  23453. };
  23454. DERNode.prototype._encodeStr = function encodeStr(str, tag) {
  23455. if (tag === 'bitstr') {
  23456. return this._createEncoderBuffer([str.unused | 0, str.data]);
  23457. } else if (tag === 'bmpstr') {
  23458. var buf = Buffer.alloc(str.length * 2);
  23459. for (var i = 0; i < str.length; i++) {
  23460. buf.writeUInt16BE(str.charCodeAt(i), i * 2);
  23461. }
  23462. return this._createEncoderBuffer(buf);
  23463. } else if (tag === 'numstr') {
  23464. if (!this._isNumstr(str)) {
  23465. return this.reporter.error('Encoding of string type: numstr supports ' + 'only digits and space');
  23466. }
  23467. return this._createEncoderBuffer(str);
  23468. } else if (tag === 'printstr') {
  23469. if (!this._isPrintstr(str)) {
  23470. 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');
  23471. }
  23472. return this._createEncoderBuffer(str);
  23473. } else if (/str$/.test(tag)) {
  23474. return this._createEncoderBuffer(str);
  23475. } else if (tag === 'objDesc') {
  23476. return this._createEncoderBuffer(str);
  23477. } else {
  23478. return this.reporter.error('Encoding of string type: ' + tag + ' unsupported');
  23479. }
  23480. };
  23481. DERNode.prototype._encodeObjid = function encodeObjid(id, values, relative) {
  23482. if (typeof id === 'string') {
  23483. if (!values) return this.reporter.error('string objid given, but no values map found');
  23484. if (!values.hasOwnProperty(id)) return this.reporter.error('objid not found in values map');
  23485. id = values[id].split(/[\s.]+/g);
  23486. for (var i = 0; i < id.length; i++) {
  23487. id[i] |= 0;
  23488. }
  23489. } else if (Array.isArray(id)) {
  23490. id = id.slice();
  23491. for (var _i2 = 0; _i2 < id.length; _i2++) {
  23492. id[_i2] |= 0;
  23493. }
  23494. }
  23495. if (!Array.isArray(id)) {
  23496. return this.reporter.error('objid() should be either array or string, ' + 'got: ' + JSON.stringify(id));
  23497. }
  23498. if (!relative) {
  23499. if (id[1] >= 40) return this.reporter.error('Second objid identifier OOB');
  23500. id.splice(0, 2, id[0] * 40 + id[1]);
  23501. } // Count number of octets
  23502. var size = 0;
  23503. for (var _i3 = 0; _i3 < id.length; _i3++) {
  23504. var ident = id[_i3];
  23505. for (size++; ident >= 0x80; ident >>= 7) {
  23506. size++;
  23507. }
  23508. }
  23509. var objid = Buffer.alloc(size);
  23510. var offset = objid.length - 1;
  23511. for (var _i4 = id.length - 1; _i4 >= 0; _i4--) {
  23512. var _ident = id[_i4];
  23513. objid[offset--] = _ident & 0x7f;
  23514. while ((_ident >>= 7) > 0) {
  23515. objid[offset--] = 0x80 | _ident & 0x7f;
  23516. }
  23517. }
  23518. return this._createEncoderBuffer(objid);
  23519. };
  23520. function two(num) {
  23521. if (num < 10) return '0' + num;else return num;
  23522. }
  23523. DERNode.prototype._encodeTime = function encodeTime(time, tag) {
  23524. var str;
  23525. var date = new Date(time);
  23526. if (tag === 'gentime') {
  23527. str = [two(date.getUTCFullYear()), two(date.getUTCMonth() + 1), two(date.getUTCDate()), two(date.getUTCHours()), two(date.getUTCMinutes()), two(date.getUTCSeconds()), 'Z'].join('');
  23528. } else if (tag === 'utctime') {
  23529. str = [two(date.getUTCFullYear() % 100), two(date.getUTCMonth() + 1), two(date.getUTCDate()), two(date.getUTCHours()), two(date.getUTCMinutes()), two(date.getUTCSeconds()), 'Z'].join('');
  23530. } else {
  23531. this.reporter.error('Encoding ' + tag + ' time is not supported yet');
  23532. }
  23533. return this._encodeStr(str, 'octstr');
  23534. };
  23535. DERNode.prototype._encodeNull = function encodeNull() {
  23536. return this._createEncoderBuffer('');
  23537. };
  23538. DERNode.prototype._encodeInt = function encodeInt(num, values) {
  23539. if (typeof num === 'string') {
  23540. if (!values) return this.reporter.error('String int or enum given, but no values map');
  23541. if (!values.hasOwnProperty(num)) {
  23542. return this.reporter.error('Values map doesn\'t contain: ' + JSON.stringify(num));
  23543. }
  23544. num = values[num];
  23545. } // Bignum, assume big endian
  23546. if (typeof num !== 'number' && !Buffer.isBuffer(num)) {
  23547. var numArray = num.toArray();
  23548. if (!num.sign && numArray[0] & 0x80) {
  23549. numArray.unshift(0);
  23550. }
  23551. num = Buffer.from(numArray);
  23552. }
  23553. if (Buffer.isBuffer(num)) {
  23554. var _size = num.length;
  23555. if (num.length === 0) _size++;
  23556. var _out = Buffer.alloc(_size);
  23557. num.copy(_out);
  23558. if (num.length === 0) _out[0] = 0;
  23559. return this._createEncoderBuffer(_out);
  23560. }
  23561. if (num < 0x80) return this._createEncoderBuffer(num);
  23562. if (num < 0x100) return this._createEncoderBuffer([0, num]);
  23563. var size = 1;
  23564. for (var i = num; i >= 0x100; i >>= 8) {
  23565. size++;
  23566. }
  23567. var out = new Array(size);
  23568. for (var _i5 = out.length - 1; _i5 >= 0; _i5--) {
  23569. out[_i5] = num & 0xff;
  23570. num >>= 8;
  23571. }
  23572. if (out[0] & 0x80) {
  23573. out.unshift(0);
  23574. }
  23575. return this._createEncoderBuffer(Buffer.from(out));
  23576. };
  23577. DERNode.prototype._encodeBool = function encodeBool(value) {
  23578. return this._createEncoderBuffer(value ? 0xff : 0);
  23579. };
  23580. DERNode.prototype._use = function use(entity, obj) {
  23581. if (typeof entity === 'function') entity = entity(obj);
  23582. return entity._getEncoder('der').tree;
  23583. };
  23584. DERNode.prototype._skipDefault = function skipDefault(dataBuffer, reporter, parent) {
  23585. var state = this._baseState;
  23586. var i;
  23587. if (state['default'] === null) return false;
  23588. var data = dataBuffer.join();
  23589. if (state.defaultBuffer === undefined) state.defaultBuffer = this._encodeValue(state['default'], reporter, parent).join();
  23590. if (data.length !== state.defaultBuffer.length) return false;
  23591. for (i = 0; i < data.length; i++) {
  23592. if (data[i] !== state.defaultBuffer[i]) return false;
  23593. }
  23594. return true;
  23595. }; // Utility methods
  23596. function encodeTag(tag, primitive, cls, reporter) {
  23597. var res;
  23598. if (tag === 'seqof') tag = 'seq';else if (tag === 'setof') tag = 'set';
  23599. 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);
  23600. if (res >= 0x1f) return reporter.error('Multi-octet tag encoding unsupported');
  23601. if (!primitive) res |= 0x20;
  23602. res |= der.tagClassByName[cls || 'universal'] << 6;
  23603. return res;
  23604. }
  23605. },{"../base/node":171,"../constants/der":173,"inherits":278,"safer-buffer":385}],179:[function(require,module,exports){
  23606. 'use strict';
  23607. var encoders = exports;
  23608. encoders.der = require('./der');
  23609. encoders.pem = require('./pem');
  23610. },{"./der":178,"./pem":180}],180:[function(require,module,exports){
  23611. 'use strict';
  23612. var inherits = require('inherits');
  23613. var DEREncoder = require('./der');
  23614. function PEMEncoder(entity) {
  23615. DEREncoder.call(this, entity);
  23616. this.enc = 'pem';
  23617. }
  23618. inherits(PEMEncoder, DEREncoder);
  23619. module.exports = PEMEncoder;
  23620. PEMEncoder.prototype.encode = function encode(data, options) {
  23621. var buf = DEREncoder.prototype.encode.call(this, data);
  23622. var p = buf.toString('base64');
  23623. var out = ['-----BEGIN ' + options.label + '-----'];
  23624. for (var i = 0; i < p.length; i += 64) {
  23625. out.push(p.slice(i, i + 64));
  23626. }
  23627. out.push('-----END ' + options.label + '-----');
  23628. return out.join('\n');
  23629. };
  23630. },{"./der":178,"inherits":278}],181:[function(require,module,exports){
  23631. "use strict";
  23632. 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); }
  23633. (function (module, exports) {
  23634. 'use strict'; // Utils
  23635. function assert(val, msg) {
  23636. if (!val) throw new Error(msg || 'Assertion failed');
  23637. } // Could use `inherits` module, but don't want to move from single file
  23638. // architecture yet.
  23639. function inherits(ctor, superCtor) {
  23640. ctor.super_ = superCtor;
  23641. var TempCtor = function TempCtor() {};
  23642. TempCtor.prototype = superCtor.prototype;
  23643. ctor.prototype = new TempCtor();
  23644. ctor.prototype.constructor = ctor;
  23645. } // BN
  23646. function BN(number, base, endian) {
  23647. if (BN.isBN(number)) {
  23648. return number;
  23649. }
  23650. this.negative = 0;
  23651. this.words = null;
  23652. this.length = 0; // Reduction context
  23653. this.red = null;
  23654. if (number !== null) {
  23655. if (base === 'le' || base === 'be') {
  23656. endian = base;
  23657. base = 10;
  23658. }
  23659. this._init(number || 0, base || 10, endian || 'be');
  23660. }
  23661. }
  23662. if (_typeof(module) === 'object') {
  23663. module.exports = BN;
  23664. } else {
  23665. exports.BN = BN;
  23666. }
  23667. BN.BN = BN;
  23668. BN.wordSize = 26;
  23669. var Buffer;
  23670. try {
  23671. Buffer = require('buffer').Buffer;
  23672. } catch (e) {}
  23673. BN.isBN = function isBN(num) {
  23674. if (num instanceof BN) {
  23675. return true;
  23676. }
  23677. return num !== null && _typeof(num) === 'object' && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
  23678. };
  23679. BN.max = function max(left, right) {
  23680. if (left.cmp(right) > 0) return left;
  23681. return right;
  23682. };
  23683. BN.min = function min(left, right) {
  23684. if (left.cmp(right) < 0) return left;
  23685. return right;
  23686. };
  23687. BN.prototype._init = function init(number, base, endian) {
  23688. if (typeof number === 'number') {
  23689. return this._initNumber(number, base, endian);
  23690. }
  23691. if (_typeof(number) === 'object') {
  23692. return this._initArray(number, base, endian);
  23693. }
  23694. if (base === 'hex') {
  23695. base = 16;
  23696. }
  23697. assert(base === (base | 0) && base >= 2 && base <= 36);
  23698. number = number.toString().replace(/\s+/g, '');
  23699. var start = 0;
  23700. if (number[0] === '-') {
  23701. start++;
  23702. }
  23703. if (base === 16) {
  23704. this._parseHex(number, start);
  23705. } else {
  23706. this._parseBase(number, base, start);
  23707. }
  23708. if (number[0] === '-') {
  23709. this.negative = 1;
  23710. }
  23711. this.strip();
  23712. if (endian !== 'le') return;
  23713. this._initArray(this.toArray(), base, endian);
  23714. };
  23715. BN.prototype._initNumber = function _initNumber(number, base, endian) {
  23716. if (number < 0) {
  23717. this.negative = 1;
  23718. number = -number;
  23719. }
  23720. if (number < 0x4000000) {
  23721. this.words = [number & 0x3ffffff];
  23722. this.length = 1;
  23723. } else if (number < 0x10000000000000) {
  23724. this.words = [number & 0x3ffffff, number / 0x4000000 & 0x3ffffff];
  23725. this.length = 2;
  23726. } else {
  23727. assert(number < 0x20000000000000); // 2 ^ 53 (unsafe)
  23728. this.words = [number & 0x3ffffff, number / 0x4000000 & 0x3ffffff, 1];
  23729. this.length = 3;
  23730. }
  23731. if (endian !== 'le') return; // Reverse the bytes
  23732. this._initArray(this.toArray(), base, endian);
  23733. };
  23734. BN.prototype._initArray = function _initArray(number, base, endian) {
  23735. // Perhaps a Uint8Array
  23736. assert(typeof number.length === 'number');
  23737. if (number.length <= 0) {
  23738. this.words = [0];
  23739. this.length = 1;
  23740. return this;
  23741. }
  23742. this.length = Math.ceil(number.length / 3);
  23743. this.words = new Array(this.length);
  23744. for (var i = 0; i < this.length; i++) {
  23745. this.words[i] = 0;
  23746. }
  23747. var j, w;
  23748. var off = 0;
  23749. if (endian === 'be') {
  23750. for (i = number.length - 1, j = 0; i >= 0; i -= 3) {
  23751. w = number[i] | number[i - 1] << 8 | number[i - 2] << 16;
  23752. this.words[j] |= w << off & 0x3ffffff;
  23753. this.words[j + 1] = w >>> 26 - off & 0x3ffffff;
  23754. off += 24;
  23755. if (off >= 26) {
  23756. off -= 26;
  23757. j++;
  23758. }
  23759. }
  23760. } else if (endian === 'le') {
  23761. for (i = 0, j = 0; i < number.length; i += 3) {
  23762. w = number[i] | number[i + 1] << 8 | number[i + 2] << 16;
  23763. this.words[j] |= w << off & 0x3ffffff;
  23764. this.words[j + 1] = w >>> 26 - off & 0x3ffffff;
  23765. off += 24;
  23766. if (off >= 26) {
  23767. off -= 26;
  23768. j++;
  23769. }
  23770. }
  23771. }
  23772. return this.strip();
  23773. };
  23774. function parseHex(str, start, end) {
  23775. var r = 0;
  23776. var len = Math.min(str.length, end);
  23777. for (var i = start; i < len; i++) {
  23778. var c = str.charCodeAt(i) - 48;
  23779. r <<= 4; // 'a' - 'f'
  23780. if (c >= 49 && c <= 54) {
  23781. r |= c - 49 + 0xa; // 'A' - 'F'
  23782. } else if (c >= 17 && c <= 22) {
  23783. r |= c - 17 + 0xa; // '0' - '9'
  23784. } else {
  23785. r |= c & 0xf;
  23786. }
  23787. }
  23788. return r;
  23789. }
  23790. BN.prototype._parseHex = function _parseHex(number, start) {
  23791. // Create possibly bigger array to ensure that it fits the number
  23792. this.length = Math.ceil((number.length - start) / 6);
  23793. this.words = new Array(this.length);
  23794. for (var i = 0; i < this.length; i++) {
  23795. this.words[i] = 0;
  23796. }
  23797. var j, w; // Scan 24-bit chunks and add them to the number
  23798. var off = 0;
  23799. for (i = number.length - 6, j = 0; i >= start; i -= 6) {
  23800. w = parseHex(number, i, i + 6);
  23801. this.words[j] |= w << off & 0x3ffffff; // NOTE: `0x3fffff` is intentional here, 26bits max shift + 24bit hex limb
  23802. this.words[j + 1] |= w >>> 26 - off & 0x3fffff;
  23803. off += 24;
  23804. if (off >= 26) {
  23805. off -= 26;
  23806. j++;
  23807. }
  23808. }
  23809. if (i + 6 !== start) {
  23810. w = parseHex(number, start, i + 6);
  23811. this.words[j] |= w << off & 0x3ffffff;
  23812. this.words[j + 1] |= w >>> 26 - off & 0x3fffff;
  23813. }
  23814. this.strip();
  23815. };
  23816. function parseBase(str, start, end, mul) {
  23817. var r = 0;
  23818. var len = Math.min(str.length, end);
  23819. for (var i = start; i < len; i++) {
  23820. var c = str.charCodeAt(i) - 48;
  23821. r *= mul; // 'a'
  23822. if (c >= 49) {
  23823. r += c - 49 + 0xa; // 'A'
  23824. } else if (c >= 17) {
  23825. r += c - 17 + 0xa; // '0' - '9'
  23826. } else {
  23827. r += c;
  23828. }
  23829. }
  23830. return r;
  23831. }
  23832. BN.prototype._parseBase = function _parseBase(number, base, start) {
  23833. // Initialize as zero
  23834. this.words = [0];
  23835. this.length = 1; // Find length of limb in base
  23836. for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) {
  23837. limbLen++;
  23838. }
  23839. limbLen--;
  23840. limbPow = limbPow / base | 0;
  23841. var total = number.length - start;
  23842. var mod = total % limbLen;
  23843. var end = Math.min(total, total - mod) + start;
  23844. var word = 0;
  23845. for (var i = start; i < end; i += limbLen) {
  23846. word = parseBase(number, i, i + limbLen, base);
  23847. this.imuln(limbPow);
  23848. if (this.words[0] + word < 0x4000000) {
  23849. this.words[0] += word;
  23850. } else {
  23851. this._iaddn(word);
  23852. }
  23853. }
  23854. if (mod !== 0) {
  23855. var pow = 1;
  23856. word = parseBase(number, i, number.length, base);
  23857. for (i = 0; i < mod; i++) {
  23858. pow *= base;
  23859. }
  23860. this.imuln(pow);
  23861. if (this.words[0] + word < 0x4000000) {
  23862. this.words[0] += word;
  23863. } else {
  23864. this._iaddn(word);
  23865. }
  23866. }
  23867. };
  23868. BN.prototype.copy = function copy(dest) {
  23869. dest.words = new Array(this.length);
  23870. for (var i = 0; i < this.length; i++) {
  23871. dest.words[i] = this.words[i];
  23872. }
  23873. dest.length = this.length;
  23874. dest.negative = this.negative;
  23875. dest.red = this.red;
  23876. };
  23877. BN.prototype.clone = function clone() {
  23878. var r = new BN(null);
  23879. this.copy(r);
  23880. return r;
  23881. };
  23882. BN.prototype._expand = function _expand(size) {
  23883. while (this.length < size) {
  23884. this.words[this.length++] = 0;
  23885. }
  23886. return this;
  23887. }; // Remove leading `0` from `this`
  23888. BN.prototype.strip = function strip() {
  23889. while (this.length > 1 && this.words[this.length - 1] === 0) {
  23890. this.length--;
  23891. }
  23892. return this._normSign();
  23893. };
  23894. BN.prototype._normSign = function _normSign() {
  23895. // -0 = 0
  23896. if (this.length === 1 && this.words[0] === 0) {
  23897. this.negative = 0;
  23898. }
  23899. return this;
  23900. };
  23901. BN.prototype.inspect = function inspect() {
  23902. return (this.red ? '<BN-R: ' : '<BN: ') + this.toString(16) + '>';
  23903. };
  23904. /*
  23905. var zeros = [];
  23906. var groupSizes = [];
  23907. var groupBases = [];
  23908. var s = '';
  23909. var i = -1;
  23910. while (++i < BN.wordSize) {
  23911. zeros[i] = s;
  23912. s += '0';
  23913. }
  23914. groupSizes[0] = 0;
  23915. groupSizes[1] = 0;
  23916. groupBases[0] = 0;
  23917. groupBases[1] = 0;
  23918. var base = 2 - 1;
  23919. while (++base < 36 + 1) {
  23920. var groupSize = 0;
  23921. var groupBase = 1;
  23922. while (groupBase < (1 << BN.wordSize) / base) {
  23923. groupBase *= base;
  23924. groupSize += 1;
  23925. }
  23926. groupSizes[base] = groupSize;
  23927. groupBases[base] = groupBase;
  23928. }
  23929. */
  23930. 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'];
  23931. 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];
  23932. 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];
  23933. BN.prototype.toString = function toString(base, padding) {
  23934. base = base || 10;
  23935. padding = padding | 0 || 1;
  23936. var out;
  23937. if (base === 16 || base === 'hex') {
  23938. out = '';
  23939. var off = 0;
  23940. var carry = 0;
  23941. for (var i = 0; i < this.length; i++) {
  23942. var w = this.words[i];
  23943. var word = ((w << off | carry) & 0xffffff).toString(16);
  23944. carry = w >>> 24 - off & 0xffffff;
  23945. if (carry !== 0 || i !== this.length - 1) {
  23946. out = zeros[6 - word.length] + word + out;
  23947. } else {
  23948. out = word + out;
  23949. }
  23950. off += 2;
  23951. if (off >= 26) {
  23952. off -= 26;
  23953. i--;
  23954. }
  23955. }
  23956. if (carry !== 0) {
  23957. out = carry.toString(16) + out;
  23958. }
  23959. while (out.length % padding !== 0) {
  23960. out = '0' + out;
  23961. }
  23962. if (this.negative !== 0) {
  23963. out = '-' + out;
  23964. }
  23965. return out;
  23966. }
  23967. if (base === (base | 0) && base >= 2 && base <= 36) {
  23968. // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base));
  23969. var groupSize = groupSizes[base]; // var groupBase = Math.pow(base, groupSize);
  23970. var groupBase = groupBases[base];
  23971. out = '';
  23972. var c = this.clone();
  23973. c.negative = 0;
  23974. while (!c.isZero()) {
  23975. var r = c.modn(groupBase).toString(base);
  23976. c = c.idivn(groupBase);
  23977. if (!c.isZero()) {
  23978. out = zeros[groupSize - r.length] + r + out;
  23979. } else {
  23980. out = r + out;
  23981. }
  23982. }
  23983. if (this.isZero()) {
  23984. out = '0' + out;
  23985. }
  23986. while (out.length % padding !== 0) {
  23987. out = '0' + out;
  23988. }
  23989. if (this.negative !== 0) {
  23990. out = '-' + out;
  23991. }
  23992. return out;
  23993. }
  23994. assert(false, 'Base should be between 2 and 36');
  23995. };
  23996. BN.prototype.toNumber = function toNumber() {
  23997. var ret = this.words[0];
  23998. if (this.length === 2) {
  23999. ret += this.words[1] * 0x4000000;
  24000. } else if (this.length === 3 && this.words[2] === 0x01) {
  24001. // NOTE: at this stage it is known that the top bit is set
  24002. ret += 0x10000000000000 + this.words[1] * 0x4000000;
  24003. } else if (this.length > 2) {
  24004. assert(false, 'Number can only safely store up to 53 bits');
  24005. }
  24006. return this.negative !== 0 ? -ret : ret;
  24007. };
  24008. BN.prototype.toJSON = function toJSON() {
  24009. return this.toString(16);
  24010. };
  24011. BN.prototype.toBuffer = function toBuffer(endian, length) {
  24012. assert(typeof Buffer !== 'undefined');
  24013. return this.toArrayLike(Buffer, endian, length);
  24014. };
  24015. BN.prototype.toArray = function toArray(endian, length) {
  24016. return this.toArrayLike(Array, endian, length);
  24017. };
  24018. BN.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) {
  24019. var byteLength = this.byteLength();
  24020. var reqLength = length || Math.max(1, byteLength);
  24021. assert(byteLength <= reqLength, 'byte array longer than desired length');
  24022. assert(reqLength > 0, 'Requested array length <= 0');
  24023. this.strip();
  24024. var littleEndian = endian === 'le';
  24025. var res = new ArrayType(reqLength);
  24026. var b, i;
  24027. var q = this.clone();
  24028. if (!littleEndian) {
  24029. // Assume big-endian
  24030. for (i = 0; i < reqLength - byteLength; i++) {
  24031. res[i] = 0;
  24032. }
  24033. for (i = 0; !q.isZero(); i++) {
  24034. b = q.andln(0xff);
  24035. q.iushrn(8);
  24036. res[reqLength - i - 1] = b;
  24037. }
  24038. } else {
  24039. for (i = 0; !q.isZero(); i++) {
  24040. b = q.andln(0xff);
  24041. q.iushrn(8);
  24042. res[i] = b;
  24043. }
  24044. for (; i < reqLength; i++) {
  24045. res[i] = 0;
  24046. }
  24047. }
  24048. return res;
  24049. };
  24050. if (Math.clz32) {
  24051. BN.prototype._countBits = function _countBits(w) {
  24052. return 32 - Math.clz32(w);
  24053. };
  24054. } else {
  24055. BN.prototype._countBits = function _countBits(w) {
  24056. var t = w;
  24057. var r = 0;
  24058. if (t >= 0x1000) {
  24059. r += 13;
  24060. t >>>= 13;
  24061. }
  24062. if (t >= 0x40) {
  24063. r += 7;
  24064. t >>>= 7;
  24065. }
  24066. if (t >= 0x8) {
  24067. r += 4;
  24068. t >>>= 4;
  24069. }
  24070. if (t >= 0x02) {
  24071. r += 2;
  24072. t >>>= 2;
  24073. }
  24074. return r + t;
  24075. };
  24076. }
  24077. BN.prototype._zeroBits = function _zeroBits(w) {
  24078. // Short-cut
  24079. if (w === 0) return 26;
  24080. var t = w;
  24081. var r = 0;
  24082. if ((t & 0x1fff) === 0) {
  24083. r += 13;
  24084. t >>>= 13;
  24085. }
  24086. if ((t & 0x7f) === 0) {
  24087. r += 7;
  24088. t >>>= 7;
  24089. }
  24090. if ((t & 0xf) === 0) {
  24091. r += 4;
  24092. t >>>= 4;
  24093. }
  24094. if ((t & 0x3) === 0) {
  24095. r += 2;
  24096. t >>>= 2;
  24097. }
  24098. if ((t & 0x1) === 0) {
  24099. r++;
  24100. }
  24101. return r;
  24102. }; // Return number of used bits in a BN
  24103. BN.prototype.bitLength = function bitLength() {
  24104. var w = this.words[this.length - 1];
  24105. var hi = this._countBits(w);
  24106. return (this.length - 1) * 26 + hi;
  24107. };
  24108. function toBitArray(num) {
  24109. var w = new Array(num.bitLength());
  24110. for (var bit = 0; bit < w.length; bit++) {
  24111. var off = bit / 26 | 0;
  24112. var wbit = bit % 26;
  24113. w[bit] = (num.words[off] & 1 << wbit) >>> wbit;
  24114. }
  24115. return w;
  24116. } // Number of trailing zero bits
  24117. BN.prototype.zeroBits = function zeroBits() {
  24118. if (this.isZero()) return 0;
  24119. var r = 0;
  24120. for (var i = 0; i < this.length; i++) {
  24121. var b = this._zeroBits(this.words[i]);
  24122. r += b;
  24123. if (b !== 26) break;
  24124. }
  24125. return r;
  24126. };
  24127. BN.prototype.byteLength = function byteLength() {
  24128. return Math.ceil(this.bitLength() / 8);
  24129. };
  24130. BN.prototype.toTwos = function toTwos(width) {
  24131. if (this.negative !== 0) {
  24132. return this.abs().inotn(width).iaddn(1);
  24133. }
  24134. return this.clone();
  24135. };
  24136. BN.prototype.fromTwos = function fromTwos(width) {
  24137. if (this.testn(width - 1)) {
  24138. return this.notn(width).iaddn(1).ineg();
  24139. }
  24140. return this.clone();
  24141. };
  24142. BN.prototype.isNeg = function isNeg() {
  24143. return this.negative !== 0;
  24144. }; // Return negative clone of `this`
  24145. BN.prototype.neg = function neg() {
  24146. return this.clone().ineg();
  24147. };
  24148. BN.prototype.ineg = function ineg() {
  24149. if (!this.isZero()) {
  24150. this.negative ^= 1;
  24151. }
  24152. return this;
  24153. }; // Or `num` with `this` in-place
  24154. BN.prototype.iuor = function iuor(num) {
  24155. while (this.length < num.length) {
  24156. this.words[this.length++] = 0;
  24157. }
  24158. for (var i = 0; i < num.length; i++) {
  24159. this.words[i] = this.words[i] | num.words[i];
  24160. }
  24161. return this.strip();
  24162. };
  24163. BN.prototype.ior = function ior(num) {
  24164. assert((this.negative | num.negative) === 0);
  24165. return this.iuor(num);
  24166. }; // Or `num` with `this`
  24167. BN.prototype.or = function or(num) {
  24168. if (this.length > num.length) return this.clone().ior(num);
  24169. return num.clone().ior(this);
  24170. };
  24171. BN.prototype.uor = function uor(num) {
  24172. if (this.length > num.length) return this.clone().iuor(num);
  24173. return num.clone().iuor(this);
  24174. }; // And `num` with `this` in-place
  24175. BN.prototype.iuand = function iuand(num) {
  24176. // b = min-length(num, this)
  24177. var b;
  24178. if (this.length > num.length) {
  24179. b = num;
  24180. } else {
  24181. b = this;
  24182. }
  24183. for (var i = 0; i < b.length; i++) {
  24184. this.words[i] = this.words[i] & num.words[i];
  24185. }
  24186. this.length = b.length;
  24187. return this.strip();
  24188. };
  24189. BN.prototype.iand = function iand(num) {
  24190. assert((this.negative | num.negative) === 0);
  24191. return this.iuand(num);
  24192. }; // And `num` with `this`
  24193. BN.prototype.and = function and(num) {
  24194. if (this.length > num.length) return this.clone().iand(num);
  24195. return num.clone().iand(this);
  24196. };
  24197. BN.prototype.uand = function uand(num) {
  24198. if (this.length > num.length) return this.clone().iuand(num);
  24199. return num.clone().iuand(this);
  24200. }; // Xor `num` with `this` in-place
  24201. BN.prototype.iuxor = function iuxor(num) {
  24202. // a.length > b.length
  24203. var a;
  24204. var b;
  24205. if (this.length > num.length) {
  24206. a = this;
  24207. b = num;
  24208. } else {
  24209. a = num;
  24210. b = this;
  24211. }
  24212. for (var i = 0; i < b.length; i++) {
  24213. this.words[i] = a.words[i] ^ b.words[i];
  24214. }
  24215. if (this !== a) {
  24216. for (; i < a.length; i++) {
  24217. this.words[i] = a.words[i];
  24218. }
  24219. }
  24220. this.length = a.length;
  24221. return this.strip();
  24222. };
  24223. BN.prototype.ixor = function ixor(num) {
  24224. assert((this.negative | num.negative) === 0);
  24225. return this.iuxor(num);
  24226. }; // Xor `num` with `this`
  24227. BN.prototype.xor = function xor(num) {
  24228. if (this.length > num.length) return this.clone().ixor(num);
  24229. return num.clone().ixor(this);
  24230. };
  24231. BN.prototype.uxor = function uxor(num) {
  24232. if (this.length > num.length) return this.clone().iuxor(num);
  24233. return num.clone().iuxor(this);
  24234. }; // Not ``this`` with ``width`` bitwidth
  24235. BN.prototype.inotn = function inotn(width) {
  24236. assert(typeof width === 'number' && width >= 0);
  24237. var bytesNeeded = Math.ceil(width / 26) | 0;
  24238. var bitsLeft = width % 26; // Extend the buffer with leading zeroes
  24239. this._expand(bytesNeeded);
  24240. if (bitsLeft > 0) {
  24241. bytesNeeded--;
  24242. } // Handle complete words
  24243. for (var i = 0; i < bytesNeeded; i++) {
  24244. this.words[i] = ~this.words[i] & 0x3ffffff;
  24245. } // Handle the residue
  24246. if (bitsLeft > 0) {
  24247. this.words[i] = ~this.words[i] & 0x3ffffff >> 26 - bitsLeft;
  24248. } // And remove leading zeroes
  24249. return this.strip();
  24250. };
  24251. BN.prototype.notn = function notn(width) {
  24252. return this.clone().inotn(width);
  24253. }; // Set `bit` of `this`
  24254. BN.prototype.setn = function setn(bit, val) {
  24255. assert(typeof bit === 'number' && bit >= 0);
  24256. var off = bit / 26 | 0;
  24257. var wbit = bit % 26;
  24258. this._expand(off + 1);
  24259. if (val) {
  24260. this.words[off] = this.words[off] | 1 << wbit;
  24261. } else {
  24262. this.words[off] = this.words[off] & ~(1 << wbit);
  24263. }
  24264. return this.strip();
  24265. }; // Add `num` to `this` in-place
  24266. BN.prototype.iadd = function iadd(num) {
  24267. var r; // negative + positive
  24268. if (this.negative !== 0 && num.negative === 0) {
  24269. this.negative = 0;
  24270. r = this.isub(num);
  24271. this.negative ^= 1;
  24272. return this._normSign(); // positive + negative
  24273. } else if (this.negative === 0 && num.negative !== 0) {
  24274. num.negative = 0;
  24275. r = this.isub(num);
  24276. num.negative = 1;
  24277. return r._normSign();
  24278. } // a.length > b.length
  24279. var a, b;
  24280. if (this.length > num.length) {
  24281. a = this;
  24282. b = num;
  24283. } else {
  24284. a = num;
  24285. b = this;
  24286. }
  24287. var carry = 0;
  24288. for (var i = 0; i < b.length; i++) {
  24289. r = (a.words[i] | 0) + (b.words[i] | 0) + carry;
  24290. this.words[i] = r & 0x3ffffff;
  24291. carry = r >>> 26;
  24292. }
  24293. for (; carry !== 0 && i < a.length; i++) {
  24294. r = (a.words[i] | 0) + carry;
  24295. this.words[i] = r & 0x3ffffff;
  24296. carry = r >>> 26;
  24297. }
  24298. this.length = a.length;
  24299. if (carry !== 0) {
  24300. this.words[this.length] = carry;
  24301. this.length++; // Copy the rest of the words
  24302. } else if (a !== this) {
  24303. for (; i < a.length; i++) {
  24304. this.words[i] = a.words[i];
  24305. }
  24306. }
  24307. return this;
  24308. }; // Add `num` to `this`
  24309. BN.prototype.add = function add(num) {
  24310. var res;
  24311. if (num.negative !== 0 && this.negative === 0) {
  24312. num.negative = 0;
  24313. res = this.sub(num);
  24314. num.negative ^= 1;
  24315. return res;
  24316. } else if (num.negative === 0 && this.negative !== 0) {
  24317. this.negative = 0;
  24318. res = num.sub(this);
  24319. this.negative = 1;
  24320. return res;
  24321. }
  24322. if (this.length > num.length) return this.clone().iadd(num);
  24323. return num.clone().iadd(this);
  24324. }; // Subtract `num` from `this` in-place
  24325. BN.prototype.isub = function isub(num) {
  24326. // this - (-num) = this + num
  24327. if (num.negative !== 0) {
  24328. num.negative = 0;
  24329. var r = this.iadd(num);
  24330. num.negative = 1;
  24331. return r._normSign(); // -this - num = -(this + num)
  24332. } else if (this.negative !== 0) {
  24333. this.negative = 0;
  24334. this.iadd(num);
  24335. this.negative = 1;
  24336. return this._normSign();
  24337. } // At this point both numbers are positive
  24338. var cmp = this.cmp(num); // Optimization - zeroify
  24339. if (cmp === 0) {
  24340. this.negative = 0;
  24341. this.length = 1;
  24342. this.words[0] = 0;
  24343. return this;
  24344. } // a > b
  24345. var a, b;
  24346. if (cmp > 0) {
  24347. a = this;
  24348. b = num;
  24349. } else {
  24350. a = num;
  24351. b = this;
  24352. }
  24353. var carry = 0;
  24354. for (var i = 0; i < b.length; i++) {
  24355. r = (a.words[i] | 0) - (b.words[i] | 0) + carry;
  24356. carry = r >> 26;
  24357. this.words[i] = r & 0x3ffffff;
  24358. }
  24359. for (; carry !== 0 && i < a.length; i++) {
  24360. r = (a.words[i] | 0) + carry;
  24361. carry = r >> 26;
  24362. this.words[i] = r & 0x3ffffff;
  24363. } // Copy rest of the words
  24364. if (carry === 0 && i < a.length && a !== this) {
  24365. for (; i < a.length; i++) {
  24366. this.words[i] = a.words[i];
  24367. }
  24368. }
  24369. this.length = Math.max(this.length, i);
  24370. if (a !== this) {
  24371. this.negative = 1;
  24372. }
  24373. return this.strip();
  24374. }; // Subtract `num` from `this`
  24375. BN.prototype.sub = function sub(num) {
  24376. return this.clone().isub(num);
  24377. };
  24378. function smallMulTo(self, num, out) {
  24379. out.negative = num.negative ^ self.negative;
  24380. var len = self.length + num.length | 0;
  24381. out.length = len;
  24382. len = len - 1 | 0; // Peel one iteration (compiler can't do it, because of code complexity)
  24383. var a = self.words[0] | 0;
  24384. var b = num.words[0] | 0;
  24385. var r = a * b;
  24386. var lo = r & 0x3ffffff;
  24387. var carry = r / 0x4000000 | 0;
  24388. out.words[0] = lo;
  24389. for (var k = 1; k < len; k++) {
  24390. // Sum all words with the same `i + j = k` and accumulate `ncarry`,
  24391. // note that ncarry could be >= 0x3ffffff
  24392. var ncarry = carry >>> 26;
  24393. var rword = carry & 0x3ffffff;
  24394. var maxJ = Math.min(k, num.length - 1);
  24395. for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
  24396. var i = k - j | 0;
  24397. a = self.words[i] | 0;
  24398. b = num.words[j] | 0;
  24399. r = a * b + rword;
  24400. ncarry += r / 0x4000000 | 0;
  24401. rword = r & 0x3ffffff;
  24402. }
  24403. out.words[k] = rword | 0;
  24404. carry = ncarry | 0;
  24405. }
  24406. if (carry !== 0) {
  24407. out.words[k] = carry | 0;
  24408. } else {
  24409. out.length--;
  24410. }
  24411. return out.strip();
  24412. } // TODO(indutny): it may be reasonable to omit it for users who don't need
  24413. // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit
  24414. // multiplication (like elliptic secp256k1).
  24415. var comb10MulTo = function comb10MulTo(self, num, out) {
  24416. var a = self.words;
  24417. var b = num.words;
  24418. var o = out.words;
  24419. var c = 0;
  24420. var lo;
  24421. var mid;
  24422. var hi;
  24423. var a0 = a[0] | 0;
  24424. var al0 = a0 & 0x1fff;
  24425. var ah0 = a0 >>> 13;
  24426. var a1 = a[1] | 0;
  24427. var al1 = a1 & 0x1fff;
  24428. var ah1 = a1 >>> 13;
  24429. var a2 = a[2] | 0;
  24430. var al2 = a2 & 0x1fff;
  24431. var ah2 = a2 >>> 13;
  24432. var a3 = a[3] | 0;
  24433. var al3 = a3 & 0x1fff;
  24434. var ah3 = a3 >>> 13;
  24435. var a4 = a[4] | 0;
  24436. var al4 = a4 & 0x1fff;
  24437. var ah4 = a4 >>> 13;
  24438. var a5 = a[5] | 0;
  24439. var al5 = a5 & 0x1fff;
  24440. var ah5 = a5 >>> 13;
  24441. var a6 = a[6] | 0;
  24442. var al6 = a6 & 0x1fff;
  24443. var ah6 = a6 >>> 13;
  24444. var a7 = a[7] | 0;
  24445. var al7 = a7 & 0x1fff;
  24446. var ah7 = a7 >>> 13;
  24447. var a8 = a[8] | 0;
  24448. var al8 = a8 & 0x1fff;
  24449. var ah8 = a8 >>> 13;
  24450. var a9 = a[9] | 0;
  24451. var al9 = a9 & 0x1fff;
  24452. var ah9 = a9 >>> 13;
  24453. var b0 = b[0] | 0;
  24454. var bl0 = b0 & 0x1fff;
  24455. var bh0 = b0 >>> 13;
  24456. var b1 = b[1] | 0;
  24457. var bl1 = b1 & 0x1fff;
  24458. var bh1 = b1 >>> 13;
  24459. var b2 = b[2] | 0;
  24460. var bl2 = b2 & 0x1fff;
  24461. var bh2 = b2 >>> 13;
  24462. var b3 = b[3] | 0;
  24463. var bl3 = b3 & 0x1fff;
  24464. var bh3 = b3 >>> 13;
  24465. var b4 = b[4] | 0;
  24466. var bl4 = b4 & 0x1fff;
  24467. var bh4 = b4 >>> 13;
  24468. var b5 = b[5] | 0;
  24469. var bl5 = b5 & 0x1fff;
  24470. var bh5 = b5 >>> 13;
  24471. var b6 = b[6] | 0;
  24472. var bl6 = b6 & 0x1fff;
  24473. var bh6 = b6 >>> 13;
  24474. var b7 = b[7] | 0;
  24475. var bl7 = b7 & 0x1fff;
  24476. var bh7 = b7 >>> 13;
  24477. var b8 = b[8] | 0;
  24478. var bl8 = b8 & 0x1fff;
  24479. var bh8 = b8 >>> 13;
  24480. var b9 = b[9] | 0;
  24481. var bl9 = b9 & 0x1fff;
  24482. var bh9 = b9 >>> 13;
  24483. out.negative = self.negative ^ num.negative;
  24484. out.length = 19;
  24485. /* k = 0 */
  24486. lo = Math.imul(al0, bl0);
  24487. mid = Math.imul(al0, bh0);
  24488. mid = mid + Math.imul(ah0, bl0) | 0;
  24489. hi = Math.imul(ah0, bh0);
  24490. var w0 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24491. c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0;
  24492. w0 &= 0x3ffffff;
  24493. /* k = 1 */
  24494. lo = Math.imul(al1, bl0);
  24495. mid = Math.imul(al1, bh0);
  24496. mid = mid + Math.imul(ah1, bl0) | 0;
  24497. hi = Math.imul(ah1, bh0);
  24498. lo = lo + Math.imul(al0, bl1) | 0;
  24499. mid = mid + Math.imul(al0, bh1) | 0;
  24500. mid = mid + Math.imul(ah0, bl1) | 0;
  24501. hi = hi + Math.imul(ah0, bh1) | 0;
  24502. var w1 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24503. c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0;
  24504. w1 &= 0x3ffffff;
  24505. /* k = 2 */
  24506. lo = Math.imul(al2, bl0);
  24507. mid = Math.imul(al2, bh0);
  24508. mid = mid + Math.imul(ah2, bl0) | 0;
  24509. hi = Math.imul(ah2, bh0);
  24510. lo = lo + Math.imul(al1, bl1) | 0;
  24511. mid = mid + Math.imul(al1, bh1) | 0;
  24512. mid = mid + Math.imul(ah1, bl1) | 0;
  24513. hi = hi + Math.imul(ah1, bh1) | 0;
  24514. lo = lo + Math.imul(al0, bl2) | 0;
  24515. mid = mid + Math.imul(al0, bh2) | 0;
  24516. mid = mid + Math.imul(ah0, bl2) | 0;
  24517. hi = hi + Math.imul(ah0, bh2) | 0;
  24518. var w2 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24519. c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0;
  24520. w2 &= 0x3ffffff;
  24521. /* k = 3 */
  24522. lo = Math.imul(al3, bl0);
  24523. mid = Math.imul(al3, bh0);
  24524. mid = mid + Math.imul(ah3, bl0) | 0;
  24525. hi = Math.imul(ah3, bh0);
  24526. lo = lo + Math.imul(al2, bl1) | 0;
  24527. mid = mid + Math.imul(al2, bh1) | 0;
  24528. mid = mid + Math.imul(ah2, bl1) | 0;
  24529. hi = hi + Math.imul(ah2, bh1) | 0;
  24530. lo = lo + Math.imul(al1, bl2) | 0;
  24531. mid = mid + Math.imul(al1, bh2) | 0;
  24532. mid = mid + Math.imul(ah1, bl2) | 0;
  24533. hi = hi + Math.imul(ah1, bh2) | 0;
  24534. lo = lo + Math.imul(al0, bl3) | 0;
  24535. mid = mid + Math.imul(al0, bh3) | 0;
  24536. mid = mid + Math.imul(ah0, bl3) | 0;
  24537. hi = hi + Math.imul(ah0, bh3) | 0;
  24538. var w3 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24539. c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0;
  24540. w3 &= 0x3ffffff;
  24541. /* k = 4 */
  24542. lo = Math.imul(al4, bl0);
  24543. mid = Math.imul(al4, bh0);
  24544. mid = mid + Math.imul(ah4, bl0) | 0;
  24545. hi = Math.imul(ah4, bh0);
  24546. lo = lo + Math.imul(al3, bl1) | 0;
  24547. mid = mid + Math.imul(al3, bh1) | 0;
  24548. mid = mid + Math.imul(ah3, bl1) | 0;
  24549. hi = hi + Math.imul(ah3, bh1) | 0;
  24550. lo = lo + Math.imul(al2, bl2) | 0;
  24551. mid = mid + Math.imul(al2, bh2) | 0;
  24552. mid = mid + Math.imul(ah2, bl2) | 0;
  24553. hi = hi + Math.imul(ah2, bh2) | 0;
  24554. lo = lo + Math.imul(al1, bl3) | 0;
  24555. mid = mid + Math.imul(al1, bh3) | 0;
  24556. mid = mid + Math.imul(ah1, bl3) | 0;
  24557. hi = hi + Math.imul(ah1, bh3) | 0;
  24558. lo = lo + Math.imul(al0, bl4) | 0;
  24559. mid = mid + Math.imul(al0, bh4) | 0;
  24560. mid = mid + Math.imul(ah0, bl4) | 0;
  24561. hi = hi + Math.imul(ah0, bh4) | 0;
  24562. var w4 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24563. c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0;
  24564. w4 &= 0x3ffffff;
  24565. /* k = 5 */
  24566. lo = Math.imul(al5, bl0);
  24567. mid = Math.imul(al5, bh0);
  24568. mid = mid + Math.imul(ah5, bl0) | 0;
  24569. hi = Math.imul(ah5, bh0);
  24570. lo = lo + Math.imul(al4, bl1) | 0;
  24571. mid = mid + Math.imul(al4, bh1) | 0;
  24572. mid = mid + Math.imul(ah4, bl1) | 0;
  24573. hi = hi + Math.imul(ah4, bh1) | 0;
  24574. lo = lo + Math.imul(al3, bl2) | 0;
  24575. mid = mid + Math.imul(al3, bh2) | 0;
  24576. mid = mid + Math.imul(ah3, bl2) | 0;
  24577. hi = hi + Math.imul(ah3, bh2) | 0;
  24578. lo = lo + Math.imul(al2, bl3) | 0;
  24579. mid = mid + Math.imul(al2, bh3) | 0;
  24580. mid = mid + Math.imul(ah2, bl3) | 0;
  24581. hi = hi + Math.imul(ah2, bh3) | 0;
  24582. lo = lo + Math.imul(al1, bl4) | 0;
  24583. mid = mid + Math.imul(al1, bh4) | 0;
  24584. mid = mid + Math.imul(ah1, bl4) | 0;
  24585. hi = hi + Math.imul(ah1, bh4) | 0;
  24586. lo = lo + Math.imul(al0, bl5) | 0;
  24587. mid = mid + Math.imul(al0, bh5) | 0;
  24588. mid = mid + Math.imul(ah0, bl5) | 0;
  24589. hi = hi + Math.imul(ah0, bh5) | 0;
  24590. var w5 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24591. c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0;
  24592. w5 &= 0x3ffffff;
  24593. /* k = 6 */
  24594. lo = Math.imul(al6, bl0);
  24595. mid = Math.imul(al6, bh0);
  24596. mid = mid + Math.imul(ah6, bl0) | 0;
  24597. hi = Math.imul(ah6, bh0);
  24598. lo = lo + Math.imul(al5, bl1) | 0;
  24599. mid = mid + Math.imul(al5, bh1) | 0;
  24600. mid = mid + Math.imul(ah5, bl1) | 0;
  24601. hi = hi + Math.imul(ah5, bh1) | 0;
  24602. lo = lo + Math.imul(al4, bl2) | 0;
  24603. mid = mid + Math.imul(al4, bh2) | 0;
  24604. mid = mid + Math.imul(ah4, bl2) | 0;
  24605. hi = hi + Math.imul(ah4, bh2) | 0;
  24606. lo = lo + Math.imul(al3, bl3) | 0;
  24607. mid = mid + Math.imul(al3, bh3) | 0;
  24608. mid = mid + Math.imul(ah3, bl3) | 0;
  24609. hi = hi + Math.imul(ah3, bh3) | 0;
  24610. lo = lo + Math.imul(al2, bl4) | 0;
  24611. mid = mid + Math.imul(al2, bh4) | 0;
  24612. mid = mid + Math.imul(ah2, bl4) | 0;
  24613. hi = hi + Math.imul(ah2, bh4) | 0;
  24614. lo = lo + Math.imul(al1, bl5) | 0;
  24615. mid = mid + Math.imul(al1, bh5) | 0;
  24616. mid = mid + Math.imul(ah1, bl5) | 0;
  24617. hi = hi + Math.imul(ah1, bh5) | 0;
  24618. lo = lo + Math.imul(al0, bl6) | 0;
  24619. mid = mid + Math.imul(al0, bh6) | 0;
  24620. mid = mid + Math.imul(ah0, bl6) | 0;
  24621. hi = hi + Math.imul(ah0, bh6) | 0;
  24622. var w6 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24623. c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0;
  24624. w6 &= 0x3ffffff;
  24625. /* k = 7 */
  24626. lo = Math.imul(al7, bl0);
  24627. mid = Math.imul(al7, bh0);
  24628. mid = mid + Math.imul(ah7, bl0) | 0;
  24629. hi = Math.imul(ah7, bh0);
  24630. lo = lo + Math.imul(al6, bl1) | 0;
  24631. mid = mid + Math.imul(al6, bh1) | 0;
  24632. mid = mid + Math.imul(ah6, bl1) | 0;
  24633. hi = hi + Math.imul(ah6, bh1) | 0;
  24634. lo = lo + Math.imul(al5, bl2) | 0;
  24635. mid = mid + Math.imul(al5, bh2) | 0;
  24636. mid = mid + Math.imul(ah5, bl2) | 0;
  24637. hi = hi + Math.imul(ah5, bh2) | 0;
  24638. lo = lo + Math.imul(al4, bl3) | 0;
  24639. mid = mid + Math.imul(al4, bh3) | 0;
  24640. mid = mid + Math.imul(ah4, bl3) | 0;
  24641. hi = hi + Math.imul(ah4, bh3) | 0;
  24642. lo = lo + Math.imul(al3, bl4) | 0;
  24643. mid = mid + Math.imul(al3, bh4) | 0;
  24644. mid = mid + Math.imul(ah3, bl4) | 0;
  24645. hi = hi + Math.imul(ah3, bh4) | 0;
  24646. lo = lo + Math.imul(al2, bl5) | 0;
  24647. mid = mid + Math.imul(al2, bh5) | 0;
  24648. mid = mid + Math.imul(ah2, bl5) | 0;
  24649. hi = hi + Math.imul(ah2, bh5) | 0;
  24650. lo = lo + Math.imul(al1, bl6) | 0;
  24651. mid = mid + Math.imul(al1, bh6) | 0;
  24652. mid = mid + Math.imul(ah1, bl6) | 0;
  24653. hi = hi + Math.imul(ah1, bh6) | 0;
  24654. lo = lo + Math.imul(al0, bl7) | 0;
  24655. mid = mid + Math.imul(al0, bh7) | 0;
  24656. mid = mid + Math.imul(ah0, bl7) | 0;
  24657. hi = hi + Math.imul(ah0, bh7) | 0;
  24658. var w7 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24659. c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0;
  24660. w7 &= 0x3ffffff;
  24661. /* k = 8 */
  24662. lo = Math.imul(al8, bl0);
  24663. mid = Math.imul(al8, bh0);
  24664. mid = mid + Math.imul(ah8, bl0) | 0;
  24665. hi = Math.imul(ah8, bh0);
  24666. lo = lo + Math.imul(al7, bl1) | 0;
  24667. mid = mid + Math.imul(al7, bh1) | 0;
  24668. mid = mid + Math.imul(ah7, bl1) | 0;
  24669. hi = hi + Math.imul(ah7, bh1) | 0;
  24670. lo = lo + Math.imul(al6, bl2) | 0;
  24671. mid = mid + Math.imul(al6, bh2) | 0;
  24672. mid = mid + Math.imul(ah6, bl2) | 0;
  24673. hi = hi + Math.imul(ah6, bh2) | 0;
  24674. lo = lo + Math.imul(al5, bl3) | 0;
  24675. mid = mid + Math.imul(al5, bh3) | 0;
  24676. mid = mid + Math.imul(ah5, bl3) | 0;
  24677. hi = hi + Math.imul(ah5, bh3) | 0;
  24678. lo = lo + Math.imul(al4, bl4) | 0;
  24679. mid = mid + Math.imul(al4, bh4) | 0;
  24680. mid = mid + Math.imul(ah4, bl4) | 0;
  24681. hi = hi + Math.imul(ah4, bh4) | 0;
  24682. lo = lo + Math.imul(al3, bl5) | 0;
  24683. mid = mid + Math.imul(al3, bh5) | 0;
  24684. mid = mid + Math.imul(ah3, bl5) | 0;
  24685. hi = hi + Math.imul(ah3, bh5) | 0;
  24686. lo = lo + Math.imul(al2, bl6) | 0;
  24687. mid = mid + Math.imul(al2, bh6) | 0;
  24688. mid = mid + Math.imul(ah2, bl6) | 0;
  24689. hi = hi + Math.imul(ah2, bh6) | 0;
  24690. lo = lo + Math.imul(al1, bl7) | 0;
  24691. mid = mid + Math.imul(al1, bh7) | 0;
  24692. mid = mid + Math.imul(ah1, bl7) | 0;
  24693. hi = hi + Math.imul(ah1, bh7) | 0;
  24694. lo = lo + Math.imul(al0, bl8) | 0;
  24695. mid = mid + Math.imul(al0, bh8) | 0;
  24696. mid = mid + Math.imul(ah0, bl8) | 0;
  24697. hi = hi + Math.imul(ah0, bh8) | 0;
  24698. var w8 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24699. c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0;
  24700. w8 &= 0x3ffffff;
  24701. /* k = 9 */
  24702. lo = Math.imul(al9, bl0);
  24703. mid = Math.imul(al9, bh0);
  24704. mid = mid + Math.imul(ah9, bl0) | 0;
  24705. hi = Math.imul(ah9, bh0);
  24706. lo = lo + Math.imul(al8, bl1) | 0;
  24707. mid = mid + Math.imul(al8, bh1) | 0;
  24708. mid = mid + Math.imul(ah8, bl1) | 0;
  24709. hi = hi + Math.imul(ah8, bh1) | 0;
  24710. lo = lo + Math.imul(al7, bl2) | 0;
  24711. mid = mid + Math.imul(al7, bh2) | 0;
  24712. mid = mid + Math.imul(ah7, bl2) | 0;
  24713. hi = hi + Math.imul(ah7, bh2) | 0;
  24714. lo = lo + Math.imul(al6, bl3) | 0;
  24715. mid = mid + Math.imul(al6, bh3) | 0;
  24716. mid = mid + Math.imul(ah6, bl3) | 0;
  24717. hi = hi + Math.imul(ah6, bh3) | 0;
  24718. lo = lo + Math.imul(al5, bl4) | 0;
  24719. mid = mid + Math.imul(al5, bh4) | 0;
  24720. mid = mid + Math.imul(ah5, bl4) | 0;
  24721. hi = hi + Math.imul(ah5, bh4) | 0;
  24722. lo = lo + Math.imul(al4, bl5) | 0;
  24723. mid = mid + Math.imul(al4, bh5) | 0;
  24724. mid = mid + Math.imul(ah4, bl5) | 0;
  24725. hi = hi + Math.imul(ah4, bh5) | 0;
  24726. lo = lo + Math.imul(al3, bl6) | 0;
  24727. mid = mid + Math.imul(al3, bh6) | 0;
  24728. mid = mid + Math.imul(ah3, bl6) | 0;
  24729. hi = hi + Math.imul(ah3, bh6) | 0;
  24730. lo = lo + Math.imul(al2, bl7) | 0;
  24731. mid = mid + Math.imul(al2, bh7) | 0;
  24732. mid = mid + Math.imul(ah2, bl7) | 0;
  24733. hi = hi + Math.imul(ah2, bh7) | 0;
  24734. lo = lo + Math.imul(al1, bl8) | 0;
  24735. mid = mid + Math.imul(al1, bh8) | 0;
  24736. mid = mid + Math.imul(ah1, bl8) | 0;
  24737. hi = hi + Math.imul(ah1, bh8) | 0;
  24738. lo = lo + Math.imul(al0, bl9) | 0;
  24739. mid = mid + Math.imul(al0, bh9) | 0;
  24740. mid = mid + Math.imul(ah0, bl9) | 0;
  24741. hi = hi + Math.imul(ah0, bh9) | 0;
  24742. var w9 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24743. c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0;
  24744. w9 &= 0x3ffffff;
  24745. /* k = 10 */
  24746. lo = Math.imul(al9, bl1);
  24747. mid = Math.imul(al9, bh1);
  24748. mid = mid + Math.imul(ah9, bl1) | 0;
  24749. hi = Math.imul(ah9, bh1);
  24750. lo = lo + Math.imul(al8, bl2) | 0;
  24751. mid = mid + Math.imul(al8, bh2) | 0;
  24752. mid = mid + Math.imul(ah8, bl2) | 0;
  24753. hi = hi + Math.imul(ah8, bh2) | 0;
  24754. lo = lo + Math.imul(al7, bl3) | 0;
  24755. mid = mid + Math.imul(al7, bh3) | 0;
  24756. mid = mid + Math.imul(ah7, bl3) | 0;
  24757. hi = hi + Math.imul(ah7, bh3) | 0;
  24758. lo = lo + Math.imul(al6, bl4) | 0;
  24759. mid = mid + Math.imul(al6, bh4) | 0;
  24760. mid = mid + Math.imul(ah6, bl4) | 0;
  24761. hi = hi + Math.imul(ah6, bh4) | 0;
  24762. lo = lo + Math.imul(al5, bl5) | 0;
  24763. mid = mid + Math.imul(al5, bh5) | 0;
  24764. mid = mid + Math.imul(ah5, bl5) | 0;
  24765. hi = hi + Math.imul(ah5, bh5) | 0;
  24766. lo = lo + Math.imul(al4, bl6) | 0;
  24767. mid = mid + Math.imul(al4, bh6) | 0;
  24768. mid = mid + Math.imul(ah4, bl6) | 0;
  24769. hi = hi + Math.imul(ah4, bh6) | 0;
  24770. lo = lo + Math.imul(al3, bl7) | 0;
  24771. mid = mid + Math.imul(al3, bh7) | 0;
  24772. mid = mid + Math.imul(ah3, bl7) | 0;
  24773. hi = hi + Math.imul(ah3, bh7) | 0;
  24774. lo = lo + Math.imul(al2, bl8) | 0;
  24775. mid = mid + Math.imul(al2, bh8) | 0;
  24776. mid = mid + Math.imul(ah2, bl8) | 0;
  24777. hi = hi + Math.imul(ah2, bh8) | 0;
  24778. lo = lo + Math.imul(al1, bl9) | 0;
  24779. mid = mid + Math.imul(al1, bh9) | 0;
  24780. mid = mid + Math.imul(ah1, bl9) | 0;
  24781. hi = hi + Math.imul(ah1, bh9) | 0;
  24782. var w10 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24783. c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0;
  24784. w10 &= 0x3ffffff;
  24785. /* k = 11 */
  24786. lo = Math.imul(al9, bl2);
  24787. mid = Math.imul(al9, bh2);
  24788. mid = mid + Math.imul(ah9, bl2) | 0;
  24789. hi = Math.imul(ah9, bh2);
  24790. lo = lo + Math.imul(al8, bl3) | 0;
  24791. mid = mid + Math.imul(al8, bh3) | 0;
  24792. mid = mid + Math.imul(ah8, bl3) | 0;
  24793. hi = hi + Math.imul(ah8, bh3) | 0;
  24794. lo = lo + Math.imul(al7, bl4) | 0;
  24795. mid = mid + Math.imul(al7, bh4) | 0;
  24796. mid = mid + Math.imul(ah7, bl4) | 0;
  24797. hi = hi + Math.imul(ah7, bh4) | 0;
  24798. lo = lo + Math.imul(al6, bl5) | 0;
  24799. mid = mid + Math.imul(al6, bh5) | 0;
  24800. mid = mid + Math.imul(ah6, bl5) | 0;
  24801. hi = hi + Math.imul(ah6, bh5) | 0;
  24802. lo = lo + Math.imul(al5, bl6) | 0;
  24803. mid = mid + Math.imul(al5, bh6) | 0;
  24804. mid = mid + Math.imul(ah5, bl6) | 0;
  24805. hi = hi + Math.imul(ah5, bh6) | 0;
  24806. lo = lo + Math.imul(al4, bl7) | 0;
  24807. mid = mid + Math.imul(al4, bh7) | 0;
  24808. mid = mid + Math.imul(ah4, bl7) | 0;
  24809. hi = hi + Math.imul(ah4, bh7) | 0;
  24810. lo = lo + Math.imul(al3, bl8) | 0;
  24811. mid = mid + Math.imul(al3, bh8) | 0;
  24812. mid = mid + Math.imul(ah3, bl8) | 0;
  24813. hi = hi + Math.imul(ah3, bh8) | 0;
  24814. lo = lo + Math.imul(al2, bl9) | 0;
  24815. mid = mid + Math.imul(al2, bh9) | 0;
  24816. mid = mid + Math.imul(ah2, bl9) | 0;
  24817. hi = hi + Math.imul(ah2, bh9) | 0;
  24818. var w11 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24819. c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0;
  24820. w11 &= 0x3ffffff;
  24821. /* k = 12 */
  24822. lo = Math.imul(al9, bl3);
  24823. mid = Math.imul(al9, bh3);
  24824. mid = mid + Math.imul(ah9, bl3) | 0;
  24825. hi = Math.imul(ah9, bh3);
  24826. lo = lo + Math.imul(al8, bl4) | 0;
  24827. mid = mid + Math.imul(al8, bh4) | 0;
  24828. mid = mid + Math.imul(ah8, bl4) | 0;
  24829. hi = hi + Math.imul(ah8, bh4) | 0;
  24830. lo = lo + Math.imul(al7, bl5) | 0;
  24831. mid = mid + Math.imul(al7, bh5) | 0;
  24832. mid = mid + Math.imul(ah7, bl5) | 0;
  24833. hi = hi + Math.imul(ah7, bh5) | 0;
  24834. lo = lo + Math.imul(al6, bl6) | 0;
  24835. mid = mid + Math.imul(al6, bh6) | 0;
  24836. mid = mid + Math.imul(ah6, bl6) | 0;
  24837. hi = hi + Math.imul(ah6, bh6) | 0;
  24838. lo = lo + Math.imul(al5, bl7) | 0;
  24839. mid = mid + Math.imul(al5, bh7) | 0;
  24840. mid = mid + Math.imul(ah5, bl7) | 0;
  24841. hi = hi + Math.imul(ah5, bh7) | 0;
  24842. lo = lo + Math.imul(al4, bl8) | 0;
  24843. mid = mid + Math.imul(al4, bh8) | 0;
  24844. mid = mid + Math.imul(ah4, bl8) | 0;
  24845. hi = hi + Math.imul(ah4, bh8) | 0;
  24846. lo = lo + Math.imul(al3, bl9) | 0;
  24847. mid = mid + Math.imul(al3, bh9) | 0;
  24848. mid = mid + Math.imul(ah3, bl9) | 0;
  24849. hi = hi + Math.imul(ah3, bh9) | 0;
  24850. var w12 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24851. c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0;
  24852. w12 &= 0x3ffffff;
  24853. /* k = 13 */
  24854. lo = Math.imul(al9, bl4);
  24855. mid = Math.imul(al9, bh4);
  24856. mid = mid + Math.imul(ah9, bl4) | 0;
  24857. hi = Math.imul(ah9, bh4);
  24858. lo = lo + Math.imul(al8, bl5) | 0;
  24859. mid = mid + Math.imul(al8, bh5) | 0;
  24860. mid = mid + Math.imul(ah8, bl5) | 0;
  24861. hi = hi + Math.imul(ah8, bh5) | 0;
  24862. lo = lo + Math.imul(al7, bl6) | 0;
  24863. mid = mid + Math.imul(al7, bh6) | 0;
  24864. mid = mid + Math.imul(ah7, bl6) | 0;
  24865. hi = hi + Math.imul(ah7, bh6) | 0;
  24866. lo = lo + Math.imul(al6, bl7) | 0;
  24867. mid = mid + Math.imul(al6, bh7) | 0;
  24868. mid = mid + Math.imul(ah6, bl7) | 0;
  24869. hi = hi + Math.imul(ah6, bh7) | 0;
  24870. lo = lo + Math.imul(al5, bl8) | 0;
  24871. mid = mid + Math.imul(al5, bh8) | 0;
  24872. mid = mid + Math.imul(ah5, bl8) | 0;
  24873. hi = hi + Math.imul(ah5, bh8) | 0;
  24874. lo = lo + Math.imul(al4, bl9) | 0;
  24875. mid = mid + Math.imul(al4, bh9) | 0;
  24876. mid = mid + Math.imul(ah4, bl9) | 0;
  24877. hi = hi + Math.imul(ah4, bh9) | 0;
  24878. var w13 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24879. c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0;
  24880. w13 &= 0x3ffffff;
  24881. /* k = 14 */
  24882. lo = Math.imul(al9, bl5);
  24883. mid = Math.imul(al9, bh5);
  24884. mid = mid + Math.imul(ah9, bl5) | 0;
  24885. hi = Math.imul(ah9, bh5);
  24886. lo = lo + Math.imul(al8, bl6) | 0;
  24887. mid = mid + Math.imul(al8, bh6) | 0;
  24888. mid = mid + Math.imul(ah8, bl6) | 0;
  24889. hi = hi + Math.imul(ah8, bh6) | 0;
  24890. lo = lo + Math.imul(al7, bl7) | 0;
  24891. mid = mid + Math.imul(al7, bh7) | 0;
  24892. mid = mid + Math.imul(ah7, bl7) | 0;
  24893. hi = hi + Math.imul(ah7, bh7) | 0;
  24894. lo = lo + Math.imul(al6, bl8) | 0;
  24895. mid = mid + Math.imul(al6, bh8) | 0;
  24896. mid = mid + Math.imul(ah6, bl8) | 0;
  24897. hi = hi + Math.imul(ah6, bh8) | 0;
  24898. lo = lo + Math.imul(al5, bl9) | 0;
  24899. mid = mid + Math.imul(al5, bh9) | 0;
  24900. mid = mid + Math.imul(ah5, bl9) | 0;
  24901. hi = hi + Math.imul(ah5, bh9) | 0;
  24902. var w14 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24903. c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0;
  24904. w14 &= 0x3ffffff;
  24905. /* k = 15 */
  24906. lo = Math.imul(al9, bl6);
  24907. mid = Math.imul(al9, bh6);
  24908. mid = mid + Math.imul(ah9, bl6) | 0;
  24909. hi = Math.imul(ah9, bh6);
  24910. lo = lo + Math.imul(al8, bl7) | 0;
  24911. mid = mid + Math.imul(al8, bh7) | 0;
  24912. mid = mid + Math.imul(ah8, bl7) | 0;
  24913. hi = hi + Math.imul(ah8, bh7) | 0;
  24914. lo = lo + Math.imul(al7, bl8) | 0;
  24915. mid = mid + Math.imul(al7, bh8) | 0;
  24916. mid = mid + Math.imul(ah7, bl8) | 0;
  24917. hi = hi + Math.imul(ah7, bh8) | 0;
  24918. lo = lo + Math.imul(al6, bl9) | 0;
  24919. mid = mid + Math.imul(al6, bh9) | 0;
  24920. mid = mid + Math.imul(ah6, bl9) | 0;
  24921. hi = hi + Math.imul(ah6, bh9) | 0;
  24922. var w15 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24923. c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0;
  24924. w15 &= 0x3ffffff;
  24925. /* k = 16 */
  24926. lo = Math.imul(al9, bl7);
  24927. mid = Math.imul(al9, bh7);
  24928. mid = mid + Math.imul(ah9, bl7) | 0;
  24929. hi = Math.imul(ah9, bh7);
  24930. lo = lo + Math.imul(al8, bl8) | 0;
  24931. mid = mid + Math.imul(al8, bh8) | 0;
  24932. mid = mid + Math.imul(ah8, bl8) | 0;
  24933. hi = hi + Math.imul(ah8, bh8) | 0;
  24934. lo = lo + Math.imul(al7, bl9) | 0;
  24935. mid = mid + Math.imul(al7, bh9) | 0;
  24936. mid = mid + Math.imul(ah7, bl9) | 0;
  24937. hi = hi + Math.imul(ah7, bh9) | 0;
  24938. var w16 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24939. c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0;
  24940. w16 &= 0x3ffffff;
  24941. /* k = 17 */
  24942. lo = Math.imul(al9, bl8);
  24943. mid = Math.imul(al9, bh8);
  24944. mid = mid + Math.imul(ah9, bl8) | 0;
  24945. hi = Math.imul(ah9, bh8);
  24946. lo = lo + Math.imul(al8, bl9) | 0;
  24947. mid = mid + Math.imul(al8, bh9) | 0;
  24948. mid = mid + Math.imul(ah8, bl9) | 0;
  24949. hi = hi + Math.imul(ah8, bh9) | 0;
  24950. var w17 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24951. c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0;
  24952. w17 &= 0x3ffffff;
  24953. /* k = 18 */
  24954. lo = Math.imul(al9, bl9);
  24955. mid = Math.imul(al9, bh9);
  24956. mid = mid + Math.imul(ah9, bl9) | 0;
  24957. hi = Math.imul(ah9, bh9);
  24958. var w18 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  24959. c = (hi + (mid >>> 13) | 0) + (w18 >>> 26) | 0;
  24960. w18 &= 0x3ffffff;
  24961. o[0] = w0;
  24962. o[1] = w1;
  24963. o[2] = w2;
  24964. o[3] = w3;
  24965. o[4] = w4;
  24966. o[5] = w5;
  24967. o[6] = w6;
  24968. o[7] = w7;
  24969. o[8] = w8;
  24970. o[9] = w9;
  24971. o[10] = w10;
  24972. o[11] = w11;
  24973. o[12] = w12;
  24974. o[13] = w13;
  24975. o[14] = w14;
  24976. o[15] = w15;
  24977. o[16] = w16;
  24978. o[17] = w17;
  24979. o[18] = w18;
  24980. if (c !== 0) {
  24981. o[19] = c;
  24982. out.length++;
  24983. }
  24984. return out;
  24985. }; // Polyfill comb
  24986. if (!Math.imul) {
  24987. comb10MulTo = smallMulTo;
  24988. }
  24989. function bigMulTo(self, num, out) {
  24990. out.negative = num.negative ^ self.negative;
  24991. out.length = self.length + num.length;
  24992. var carry = 0;
  24993. var hncarry = 0;
  24994. for (var k = 0; k < out.length - 1; k++) {
  24995. // Sum all words with the same `i + j = k` and accumulate `ncarry`,
  24996. // note that ncarry could be >= 0x3ffffff
  24997. var ncarry = hncarry;
  24998. hncarry = 0;
  24999. var rword = carry & 0x3ffffff;
  25000. var maxJ = Math.min(k, num.length - 1);
  25001. for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
  25002. var i = k - j;
  25003. var a = self.words[i] | 0;
  25004. var b = num.words[j] | 0;
  25005. var r = a * b;
  25006. var lo = r & 0x3ffffff;
  25007. ncarry = ncarry + (r / 0x4000000 | 0) | 0;
  25008. lo = lo + rword | 0;
  25009. rword = lo & 0x3ffffff;
  25010. ncarry = ncarry + (lo >>> 26) | 0;
  25011. hncarry += ncarry >>> 26;
  25012. ncarry &= 0x3ffffff;
  25013. }
  25014. out.words[k] = rword;
  25015. carry = ncarry;
  25016. ncarry = hncarry;
  25017. }
  25018. if (carry !== 0) {
  25019. out.words[k] = carry;
  25020. } else {
  25021. out.length--;
  25022. }
  25023. return out.strip();
  25024. }
  25025. function jumboMulTo(self, num, out) {
  25026. var fftm = new FFTM();
  25027. return fftm.mulp(self, num, out);
  25028. }
  25029. BN.prototype.mulTo = function mulTo(num, out) {
  25030. var res;
  25031. var len = this.length + num.length;
  25032. if (this.length === 10 && num.length === 10) {
  25033. res = comb10MulTo(this, num, out);
  25034. } else if (len < 63) {
  25035. res = smallMulTo(this, num, out);
  25036. } else if (len < 1024) {
  25037. res = bigMulTo(this, num, out);
  25038. } else {
  25039. res = jumboMulTo(this, num, out);
  25040. }
  25041. return res;
  25042. }; // Cooley-Tukey algorithm for FFT
  25043. // slightly revisited to rely on looping instead of recursion
  25044. function FFTM(x, y) {
  25045. this.x = x;
  25046. this.y = y;
  25047. }
  25048. FFTM.prototype.makeRBT = function makeRBT(N) {
  25049. var t = new Array(N);
  25050. var l = BN.prototype._countBits(N) - 1;
  25051. for (var i = 0; i < N; i++) {
  25052. t[i] = this.revBin(i, l, N);
  25053. }
  25054. return t;
  25055. }; // Returns binary-reversed representation of `x`
  25056. FFTM.prototype.revBin = function revBin(x, l, N) {
  25057. if (x === 0 || x === N - 1) return x;
  25058. var rb = 0;
  25059. for (var i = 0; i < l; i++) {
  25060. rb |= (x & 1) << l - i - 1;
  25061. x >>= 1;
  25062. }
  25063. return rb;
  25064. }; // Performs "tweedling" phase, therefore 'emulating'
  25065. // behaviour of the recursive algorithm
  25066. FFTM.prototype.permute = function permute(rbt, rws, iws, rtws, itws, N) {
  25067. for (var i = 0; i < N; i++) {
  25068. rtws[i] = rws[rbt[i]];
  25069. itws[i] = iws[rbt[i]];
  25070. }
  25071. };
  25072. FFTM.prototype.transform = function transform(rws, iws, rtws, itws, N, rbt) {
  25073. this.permute(rbt, rws, iws, rtws, itws, N);
  25074. for (var s = 1; s < N; s <<= 1) {
  25075. var l = s << 1;
  25076. var rtwdf = Math.cos(2 * Math.PI / l);
  25077. var itwdf = Math.sin(2 * Math.PI / l);
  25078. for (var p = 0; p < N; p += l) {
  25079. var rtwdf_ = rtwdf;
  25080. var itwdf_ = itwdf;
  25081. for (var j = 0; j < s; j++) {
  25082. var re = rtws[p + j];
  25083. var ie = itws[p + j];
  25084. var ro = rtws[p + j + s];
  25085. var io = itws[p + j + s];
  25086. var rx = rtwdf_ * ro - itwdf_ * io;
  25087. io = rtwdf_ * io + itwdf_ * ro;
  25088. ro = rx;
  25089. rtws[p + j] = re + ro;
  25090. itws[p + j] = ie + io;
  25091. rtws[p + j + s] = re - ro;
  25092. itws[p + j + s] = ie - io;
  25093. /* jshint maxdepth : false */
  25094. if (j !== l) {
  25095. rx = rtwdf * rtwdf_ - itwdf * itwdf_;
  25096. itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_;
  25097. rtwdf_ = rx;
  25098. }
  25099. }
  25100. }
  25101. }
  25102. };
  25103. FFTM.prototype.guessLen13b = function guessLen13b(n, m) {
  25104. var N = Math.max(m, n) | 1;
  25105. var odd = N & 1;
  25106. var i = 0;
  25107. for (N = N / 2 | 0; N; N = N >>> 1) {
  25108. i++;
  25109. }
  25110. return 1 << i + 1 + odd;
  25111. };
  25112. FFTM.prototype.conjugate = function conjugate(rws, iws, N) {
  25113. if (N <= 1) return;
  25114. for (var i = 0; i < N / 2; i++) {
  25115. var t = rws[i];
  25116. rws[i] = rws[N - i - 1];
  25117. rws[N - i - 1] = t;
  25118. t = iws[i];
  25119. iws[i] = -iws[N - i - 1];
  25120. iws[N - i - 1] = -t;
  25121. }
  25122. };
  25123. FFTM.prototype.normalize13b = function normalize13b(ws, N) {
  25124. var carry = 0;
  25125. for (var i = 0; i < N / 2; i++) {
  25126. var w = Math.round(ws[2 * i + 1] / N) * 0x2000 + Math.round(ws[2 * i] / N) + carry;
  25127. ws[i] = w & 0x3ffffff;
  25128. if (w < 0x4000000) {
  25129. carry = 0;
  25130. } else {
  25131. carry = w / 0x4000000 | 0;
  25132. }
  25133. }
  25134. return ws;
  25135. };
  25136. FFTM.prototype.convert13b = function convert13b(ws, len, rws, N) {
  25137. var carry = 0;
  25138. for (var i = 0; i < len; i++) {
  25139. carry = carry + (ws[i] | 0);
  25140. rws[2 * i] = carry & 0x1fff;
  25141. carry = carry >>> 13;
  25142. rws[2 * i + 1] = carry & 0x1fff;
  25143. carry = carry >>> 13;
  25144. } // Pad with zeroes
  25145. for (i = 2 * len; i < N; ++i) {
  25146. rws[i] = 0;
  25147. }
  25148. assert(carry === 0);
  25149. assert((carry & ~0x1fff) === 0);
  25150. };
  25151. FFTM.prototype.stub = function stub(N) {
  25152. var ph = new Array(N);
  25153. for (var i = 0; i < N; i++) {
  25154. ph[i] = 0;
  25155. }
  25156. return ph;
  25157. };
  25158. FFTM.prototype.mulp = function mulp(x, y, out) {
  25159. var N = 2 * this.guessLen13b(x.length, y.length);
  25160. var rbt = this.makeRBT(N);
  25161. var _ = this.stub(N);
  25162. var rws = new Array(N);
  25163. var rwst = new Array(N);
  25164. var iwst = new Array(N);
  25165. var nrws = new Array(N);
  25166. var nrwst = new Array(N);
  25167. var niwst = new Array(N);
  25168. var rmws = out.words;
  25169. rmws.length = N;
  25170. this.convert13b(x.words, x.length, rws, N);
  25171. this.convert13b(y.words, y.length, nrws, N);
  25172. this.transform(rws, _, rwst, iwst, N, rbt);
  25173. this.transform(nrws, _, nrwst, niwst, N, rbt);
  25174. for (var i = 0; i < N; i++) {
  25175. var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
  25176. iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i];
  25177. rwst[i] = rx;
  25178. }
  25179. this.conjugate(rwst, iwst, N);
  25180. this.transform(rwst, iwst, rmws, _, N, rbt);
  25181. this.conjugate(rmws, _, N);
  25182. this.normalize13b(rmws, N);
  25183. out.negative = x.negative ^ y.negative;
  25184. out.length = x.length + y.length;
  25185. return out.strip();
  25186. }; // Multiply `this` by `num`
  25187. BN.prototype.mul = function mul(num) {
  25188. var out = new BN(null);
  25189. out.words = new Array(this.length + num.length);
  25190. return this.mulTo(num, out);
  25191. }; // Multiply employing FFT
  25192. BN.prototype.mulf = function mulf(num) {
  25193. var out = new BN(null);
  25194. out.words = new Array(this.length + num.length);
  25195. return jumboMulTo(this, num, out);
  25196. }; // In-place Multiplication
  25197. BN.prototype.imul = function imul(num) {
  25198. return this.clone().mulTo(num, this);
  25199. };
  25200. BN.prototype.imuln = function imuln(num) {
  25201. assert(typeof num === 'number');
  25202. assert(num < 0x4000000); // Carry
  25203. var carry = 0;
  25204. for (var i = 0; i < this.length; i++) {
  25205. var w = (this.words[i] | 0) * num;
  25206. var lo = (w & 0x3ffffff) + (carry & 0x3ffffff);
  25207. carry >>= 26;
  25208. carry += w / 0x4000000 | 0; // NOTE: lo is 27bit maximum
  25209. carry += lo >>> 26;
  25210. this.words[i] = lo & 0x3ffffff;
  25211. }
  25212. if (carry !== 0) {
  25213. this.words[i] = carry;
  25214. this.length++;
  25215. }
  25216. return this;
  25217. };
  25218. BN.prototype.muln = function muln(num) {
  25219. return this.clone().imuln(num);
  25220. }; // `this` * `this`
  25221. BN.prototype.sqr = function sqr() {
  25222. return this.mul(this);
  25223. }; // `this` * `this` in-place
  25224. BN.prototype.isqr = function isqr() {
  25225. return this.imul(this.clone());
  25226. }; // Math.pow(`this`, `num`)
  25227. BN.prototype.pow = function pow(num) {
  25228. var w = toBitArray(num);
  25229. if (w.length === 0) return new BN(1); // Skip leading zeroes
  25230. var res = this;
  25231. for (var i = 0; i < w.length; i++, res = res.sqr()) {
  25232. if (w[i] !== 0) break;
  25233. }
  25234. if (++i < w.length) {
  25235. for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) {
  25236. if (w[i] === 0) continue;
  25237. res = res.mul(q);
  25238. }
  25239. }
  25240. return res;
  25241. }; // Shift-left in-place
  25242. BN.prototype.iushln = function iushln(bits) {
  25243. assert(typeof bits === 'number' && bits >= 0);
  25244. var r = bits % 26;
  25245. var s = (bits - r) / 26;
  25246. var carryMask = 0x3ffffff >>> 26 - r << 26 - r;
  25247. var i;
  25248. if (r !== 0) {
  25249. var carry = 0;
  25250. for (i = 0; i < this.length; i++) {
  25251. var newCarry = this.words[i] & carryMask;
  25252. var c = (this.words[i] | 0) - newCarry << r;
  25253. this.words[i] = c | carry;
  25254. carry = newCarry >>> 26 - r;
  25255. }
  25256. if (carry) {
  25257. this.words[i] = carry;
  25258. this.length++;
  25259. }
  25260. }
  25261. if (s !== 0) {
  25262. for (i = this.length - 1; i >= 0; i--) {
  25263. this.words[i + s] = this.words[i];
  25264. }
  25265. for (i = 0; i < s; i++) {
  25266. this.words[i] = 0;
  25267. }
  25268. this.length += s;
  25269. }
  25270. return this.strip();
  25271. };
  25272. BN.prototype.ishln = function ishln(bits) {
  25273. // TODO(indutny): implement me
  25274. assert(this.negative === 0);
  25275. return this.iushln(bits);
  25276. }; // Shift-right in-place
  25277. // NOTE: `hint` is a lowest bit before trailing zeroes
  25278. // NOTE: if `extended` is present - it will be filled with destroyed bits
  25279. BN.prototype.iushrn = function iushrn(bits, hint, extended) {
  25280. assert(typeof bits === 'number' && bits >= 0);
  25281. var h;
  25282. if (hint) {
  25283. h = (hint - hint % 26) / 26;
  25284. } else {
  25285. h = 0;
  25286. }
  25287. var r = bits % 26;
  25288. var s = Math.min((bits - r) / 26, this.length);
  25289. var mask = 0x3ffffff ^ 0x3ffffff >>> r << r;
  25290. var maskedWords = extended;
  25291. h -= s;
  25292. h = Math.max(0, h); // Extended mode, copy masked part
  25293. if (maskedWords) {
  25294. for (var i = 0; i < s; i++) {
  25295. maskedWords.words[i] = this.words[i];
  25296. }
  25297. maskedWords.length = s;
  25298. }
  25299. if (s === 0) {// No-op, we should not move anything at all
  25300. } else if (this.length > s) {
  25301. this.length -= s;
  25302. for (i = 0; i < this.length; i++) {
  25303. this.words[i] = this.words[i + s];
  25304. }
  25305. } else {
  25306. this.words[0] = 0;
  25307. this.length = 1;
  25308. }
  25309. var carry = 0;
  25310. for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
  25311. var word = this.words[i] | 0;
  25312. this.words[i] = carry << 26 - r | word >>> r;
  25313. carry = word & mask;
  25314. } // Push carried bits as a mask
  25315. if (maskedWords && carry !== 0) {
  25316. maskedWords.words[maskedWords.length++] = carry;
  25317. }
  25318. if (this.length === 0) {
  25319. this.words[0] = 0;
  25320. this.length = 1;
  25321. }
  25322. return this.strip();
  25323. };
  25324. BN.prototype.ishrn = function ishrn(bits, hint, extended) {
  25325. // TODO(indutny): implement me
  25326. assert(this.negative === 0);
  25327. return this.iushrn(bits, hint, extended);
  25328. }; // Shift-left
  25329. BN.prototype.shln = function shln(bits) {
  25330. return this.clone().ishln(bits);
  25331. };
  25332. BN.prototype.ushln = function ushln(bits) {
  25333. return this.clone().iushln(bits);
  25334. }; // Shift-right
  25335. BN.prototype.shrn = function shrn(bits) {
  25336. return this.clone().ishrn(bits);
  25337. };
  25338. BN.prototype.ushrn = function ushrn(bits) {
  25339. return this.clone().iushrn(bits);
  25340. }; // Test if n bit is set
  25341. BN.prototype.testn = function testn(bit) {
  25342. assert(typeof bit === 'number' && bit >= 0);
  25343. var r = bit % 26;
  25344. var s = (bit - r) / 26;
  25345. var q = 1 << r; // Fast case: bit is much higher than all existing words
  25346. if (this.length <= s) return false; // Check bit and return
  25347. var w = this.words[s];
  25348. return !!(w & q);
  25349. }; // Return only lowers bits of number (in-place)
  25350. BN.prototype.imaskn = function imaskn(bits) {
  25351. assert(typeof bits === 'number' && bits >= 0);
  25352. var r = bits % 26;
  25353. var s = (bits - r) / 26;
  25354. assert(this.negative === 0, 'imaskn works only with positive numbers');
  25355. if (this.length <= s) {
  25356. return this;
  25357. }
  25358. if (r !== 0) {
  25359. s++;
  25360. }
  25361. this.length = Math.min(s, this.length);
  25362. if (r !== 0) {
  25363. var mask = 0x3ffffff ^ 0x3ffffff >>> r << r;
  25364. this.words[this.length - 1] &= mask;
  25365. }
  25366. return this.strip();
  25367. }; // Return only lowers bits of number
  25368. BN.prototype.maskn = function maskn(bits) {
  25369. return this.clone().imaskn(bits);
  25370. }; // Add plain number `num` to `this`
  25371. BN.prototype.iaddn = function iaddn(num) {
  25372. assert(typeof num === 'number');
  25373. assert(num < 0x4000000);
  25374. if (num < 0) return this.isubn(-num); // Possible sign change
  25375. if (this.negative !== 0) {
  25376. if (this.length === 1 && (this.words[0] | 0) < num) {
  25377. this.words[0] = num - (this.words[0] | 0);
  25378. this.negative = 0;
  25379. return this;
  25380. }
  25381. this.negative = 0;
  25382. this.isubn(num);
  25383. this.negative = 1;
  25384. return this;
  25385. } // Add without checks
  25386. return this._iaddn(num);
  25387. };
  25388. BN.prototype._iaddn = function _iaddn(num) {
  25389. this.words[0] += num; // Carry
  25390. for (var i = 0; i < this.length && this.words[i] >= 0x4000000; i++) {
  25391. this.words[i] -= 0x4000000;
  25392. if (i === this.length - 1) {
  25393. this.words[i + 1] = 1;
  25394. } else {
  25395. this.words[i + 1]++;
  25396. }
  25397. }
  25398. this.length = Math.max(this.length, i + 1);
  25399. return this;
  25400. }; // Subtract plain number `num` from `this`
  25401. BN.prototype.isubn = function isubn(num) {
  25402. assert(typeof num === 'number');
  25403. assert(num < 0x4000000);
  25404. if (num < 0) return this.iaddn(-num);
  25405. if (this.negative !== 0) {
  25406. this.negative = 0;
  25407. this.iaddn(num);
  25408. this.negative = 1;
  25409. return this;
  25410. }
  25411. this.words[0] -= num;
  25412. if (this.length === 1 && this.words[0] < 0) {
  25413. this.words[0] = -this.words[0];
  25414. this.negative = 1;
  25415. } else {
  25416. // Carry
  25417. for (var i = 0; i < this.length && this.words[i] < 0; i++) {
  25418. this.words[i] += 0x4000000;
  25419. this.words[i + 1] -= 1;
  25420. }
  25421. }
  25422. return this.strip();
  25423. };
  25424. BN.prototype.addn = function addn(num) {
  25425. return this.clone().iaddn(num);
  25426. };
  25427. BN.prototype.subn = function subn(num) {
  25428. return this.clone().isubn(num);
  25429. };
  25430. BN.prototype.iabs = function iabs() {
  25431. this.negative = 0;
  25432. return this;
  25433. };
  25434. BN.prototype.abs = function abs() {
  25435. return this.clone().iabs();
  25436. };
  25437. BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) {
  25438. var len = num.length + shift;
  25439. var i;
  25440. this._expand(len);
  25441. var w;
  25442. var carry = 0;
  25443. for (i = 0; i < num.length; i++) {
  25444. w = (this.words[i + shift] | 0) + carry;
  25445. var right = (num.words[i] | 0) * mul;
  25446. w -= right & 0x3ffffff;
  25447. carry = (w >> 26) - (right / 0x4000000 | 0);
  25448. this.words[i + shift] = w & 0x3ffffff;
  25449. }
  25450. for (; i < this.length - shift; i++) {
  25451. w = (this.words[i + shift] | 0) + carry;
  25452. carry = w >> 26;
  25453. this.words[i + shift] = w & 0x3ffffff;
  25454. }
  25455. if (carry === 0) return this.strip(); // Subtraction overflow
  25456. assert(carry === -1);
  25457. carry = 0;
  25458. for (i = 0; i < this.length; i++) {
  25459. w = -(this.words[i] | 0) + carry;
  25460. carry = w >> 26;
  25461. this.words[i] = w & 0x3ffffff;
  25462. }
  25463. this.negative = 1;
  25464. return this.strip();
  25465. };
  25466. BN.prototype._wordDiv = function _wordDiv(num, mode) {
  25467. var shift = this.length - num.length;
  25468. var a = this.clone();
  25469. var b = num; // Normalize
  25470. var bhi = b.words[b.length - 1] | 0;
  25471. var bhiBits = this._countBits(bhi);
  25472. shift = 26 - bhiBits;
  25473. if (shift !== 0) {
  25474. b = b.ushln(shift);
  25475. a.iushln(shift);
  25476. bhi = b.words[b.length - 1] | 0;
  25477. } // Initialize quotient
  25478. var m = a.length - b.length;
  25479. var q;
  25480. if (mode !== 'mod') {
  25481. q = new BN(null);
  25482. q.length = m + 1;
  25483. q.words = new Array(q.length);
  25484. for (var i = 0; i < q.length; i++) {
  25485. q.words[i] = 0;
  25486. }
  25487. }
  25488. var diff = a.clone()._ishlnsubmul(b, 1, m);
  25489. if (diff.negative === 0) {
  25490. a = diff;
  25491. if (q) {
  25492. q.words[m] = 1;
  25493. }
  25494. }
  25495. for (var j = m - 1; j >= 0; j--) {
  25496. 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
  25497. // (0x7ffffff)
  25498. qj = Math.min(qj / bhi | 0, 0x3ffffff);
  25499. a._ishlnsubmul(b, qj, j);
  25500. while (a.negative !== 0) {
  25501. qj--;
  25502. a.negative = 0;
  25503. a._ishlnsubmul(b, 1, j);
  25504. if (!a.isZero()) {
  25505. a.negative ^= 1;
  25506. }
  25507. }
  25508. if (q) {
  25509. q.words[j] = qj;
  25510. }
  25511. }
  25512. if (q) {
  25513. q.strip();
  25514. }
  25515. a.strip(); // Denormalize
  25516. if (mode !== 'div' && shift !== 0) {
  25517. a.iushrn(shift);
  25518. }
  25519. return {
  25520. div: q || null,
  25521. mod: a
  25522. };
  25523. }; // NOTE: 1) `mode` can be set to `mod` to request mod only,
  25524. // to `div` to request div only, or be absent to
  25525. // request both div & mod
  25526. // 2) `positive` is true if unsigned mod is requested
  25527. BN.prototype.divmod = function divmod(num, mode, positive) {
  25528. assert(!num.isZero());
  25529. if (this.isZero()) {
  25530. return {
  25531. div: new BN(0),
  25532. mod: new BN(0)
  25533. };
  25534. }
  25535. var div, mod, res;
  25536. if (this.negative !== 0 && num.negative === 0) {
  25537. res = this.neg().divmod(num, mode);
  25538. if (mode !== 'mod') {
  25539. div = res.div.neg();
  25540. }
  25541. if (mode !== 'div') {
  25542. mod = res.mod.neg();
  25543. if (positive && mod.negative !== 0) {
  25544. mod.iadd(num);
  25545. }
  25546. }
  25547. return {
  25548. div: div,
  25549. mod: mod
  25550. };
  25551. }
  25552. if (this.negative === 0 && num.negative !== 0) {
  25553. res = this.divmod(num.neg(), mode);
  25554. if (mode !== 'mod') {
  25555. div = res.div.neg();
  25556. }
  25557. return {
  25558. div: div,
  25559. mod: res.mod
  25560. };
  25561. }
  25562. if ((this.negative & num.negative) !== 0) {
  25563. res = this.neg().divmod(num.neg(), mode);
  25564. if (mode !== 'div') {
  25565. mod = res.mod.neg();
  25566. if (positive && mod.negative !== 0) {
  25567. mod.isub(num);
  25568. }
  25569. }
  25570. return {
  25571. div: res.div,
  25572. mod: mod
  25573. };
  25574. } // Both numbers are positive at this point
  25575. // Strip both numbers to approximate shift value
  25576. if (num.length > this.length || this.cmp(num) < 0) {
  25577. return {
  25578. div: new BN(0),
  25579. mod: this
  25580. };
  25581. } // Very short reduction
  25582. if (num.length === 1) {
  25583. if (mode === 'div') {
  25584. return {
  25585. div: this.divn(num.words[0]),
  25586. mod: null
  25587. };
  25588. }
  25589. if (mode === 'mod') {
  25590. return {
  25591. div: null,
  25592. mod: new BN(this.modn(num.words[0]))
  25593. };
  25594. }
  25595. return {
  25596. div: this.divn(num.words[0]),
  25597. mod: new BN(this.modn(num.words[0]))
  25598. };
  25599. }
  25600. return this._wordDiv(num, mode);
  25601. }; // Find `this` / `num`
  25602. BN.prototype.div = function div(num) {
  25603. return this.divmod(num, 'div', false).div;
  25604. }; // Find `this` % `num`
  25605. BN.prototype.mod = function mod(num) {
  25606. return this.divmod(num, 'mod', false).mod;
  25607. };
  25608. BN.prototype.umod = function umod(num) {
  25609. return this.divmod(num, 'mod', true).mod;
  25610. }; // Find Round(`this` / `num`)
  25611. BN.prototype.divRound = function divRound(num) {
  25612. var dm = this.divmod(num); // Fast case - exact division
  25613. if (dm.mod.isZero()) return dm.div;
  25614. var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
  25615. var half = num.ushrn(1);
  25616. var r2 = num.andln(1);
  25617. var cmp = mod.cmp(half); // Round down
  25618. if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; // Round up
  25619. return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
  25620. };
  25621. BN.prototype.modn = function modn(num) {
  25622. assert(num <= 0x3ffffff);
  25623. var p = (1 << 26) % num;
  25624. var acc = 0;
  25625. for (var i = this.length - 1; i >= 0; i--) {
  25626. acc = (p * acc + (this.words[i] | 0)) % num;
  25627. }
  25628. return acc;
  25629. }; // In-place division by number
  25630. BN.prototype.idivn = function idivn(num) {
  25631. assert(num <= 0x3ffffff);
  25632. var carry = 0;
  25633. for (var i = this.length - 1; i >= 0; i--) {
  25634. var w = (this.words[i] | 0) + carry * 0x4000000;
  25635. this.words[i] = w / num | 0;
  25636. carry = w % num;
  25637. }
  25638. return this.strip();
  25639. };
  25640. BN.prototype.divn = function divn(num) {
  25641. return this.clone().idivn(num);
  25642. };
  25643. BN.prototype.egcd = function egcd(p) {
  25644. assert(p.negative === 0);
  25645. assert(!p.isZero());
  25646. var x = this;
  25647. var y = p.clone();
  25648. if (x.negative !== 0) {
  25649. x = x.umod(p);
  25650. } else {
  25651. x = x.clone();
  25652. } // A * x + B * y = x
  25653. var A = new BN(1);
  25654. var B = new BN(0); // C * x + D * y = y
  25655. var C = new BN(0);
  25656. var D = new BN(1);
  25657. var g = 0;
  25658. while (x.isEven() && y.isEven()) {
  25659. x.iushrn(1);
  25660. y.iushrn(1);
  25661. ++g;
  25662. }
  25663. var yp = y.clone();
  25664. var xp = x.clone();
  25665. while (!x.isZero()) {
  25666. for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1) {
  25667. ;
  25668. }
  25669. if (i > 0) {
  25670. x.iushrn(i);
  25671. while (i-- > 0) {
  25672. if (A.isOdd() || B.isOdd()) {
  25673. A.iadd(yp);
  25674. B.isub(xp);
  25675. }
  25676. A.iushrn(1);
  25677. B.iushrn(1);
  25678. }
  25679. }
  25680. for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1) {
  25681. ;
  25682. }
  25683. if (j > 0) {
  25684. y.iushrn(j);
  25685. while (j-- > 0) {
  25686. if (C.isOdd() || D.isOdd()) {
  25687. C.iadd(yp);
  25688. D.isub(xp);
  25689. }
  25690. C.iushrn(1);
  25691. D.iushrn(1);
  25692. }
  25693. }
  25694. if (x.cmp(y) >= 0) {
  25695. x.isub(y);
  25696. A.isub(C);
  25697. B.isub(D);
  25698. } else {
  25699. y.isub(x);
  25700. C.isub(A);
  25701. D.isub(B);
  25702. }
  25703. }
  25704. return {
  25705. a: C,
  25706. b: D,
  25707. gcd: y.iushln(g)
  25708. };
  25709. }; // This is reduced incarnation of the binary EEA
  25710. // above, designated to invert members of the
  25711. // _prime_ fields F(p) at a maximal speed
  25712. BN.prototype._invmp = function _invmp(p) {
  25713. assert(p.negative === 0);
  25714. assert(!p.isZero());
  25715. var a = this;
  25716. var b = p.clone();
  25717. if (a.negative !== 0) {
  25718. a = a.umod(p);
  25719. } else {
  25720. a = a.clone();
  25721. }
  25722. var x1 = new BN(1);
  25723. var x2 = new BN(0);
  25724. var delta = b.clone();
  25725. while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
  25726. for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1) {
  25727. ;
  25728. }
  25729. if (i > 0) {
  25730. a.iushrn(i);
  25731. while (i-- > 0) {
  25732. if (x1.isOdd()) {
  25733. x1.iadd(delta);
  25734. }
  25735. x1.iushrn(1);
  25736. }
  25737. }
  25738. for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1) {
  25739. ;
  25740. }
  25741. if (j > 0) {
  25742. b.iushrn(j);
  25743. while (j-- > 0) {
  25744. if (x2.isOdd()) {
  25745. x2.iadd(delta);
  25746. }
  25747. x2.iushrn(1);
  25748. }
  25749. }
  25750. if (a.cmp(b) >= 0) {
  25751. a.isub(b);
  25752. x1.isub(x2);
  25753. } else {
  25754. b.isub(a);
  25755. x2.isub(x1);
  25756. }
  25757. }
  25758. var res;
  25759. if (a.cmpn(1) === 0) {
  25760. res = x1;
  25761. } else {
  25762. res = x2;
  25763. }
  25764. if (res.cmpn(0) < 0) {
  25765. res.iadd(p);
  25766. }
  25767. return res;
  25768. };
  25769. BN.prototype.gcd = function gcd(num) {
  25770. if (this.isZero()) return num.abs();
  25771. if (num.isZero()) return this.abs();
  25772. var a = this.clone();
  25773. var b = num.clone();
  25774. a.negative = 0;
  25775. b.negative = 0; // Remove common factor of two
  25776. for (var shift = 0; a.isEven() && b.isEven(); shift++) {
  25777. a.iushrn(1);
  25778. b.iushrn(1);
  25779. }
  25780. do {
  25781. while (a.isEven()) {
  25782. a.iushrn(1);
  25783. }
  25784. while (b.isEven()) {
  25785. b.iushrn(1);
  25786. }
  25787. var r = a.cmp(b);
  25788. if (r < 0) {
  25789. // Swap `a` and `b` to make `a` always bigger than `b`
  25790. var t = a;
  25791. a = b;
  25792. b = t;
  25793. } else if (r === 0 || b.cmpn(1) === 0) {
  25794. break;
  25795. }
  25796. a.isub(b);
  25797. } while (true);
  25798. return b.iushln(shift);
  25799. }; // Invert number in the field F(num)
  25800. BN.prototype.invm = function invm(num) {
  25801. return this.egcd(num).a.umod(num);
  25802. };
  25803. BN.prototype.isEven = function isEven() {
  25804. return (this.words[0] & 1) === 0;
  25805. };
  25806. BN.prototype.isOdd = function isOdd() {
  25807. return (this.words[0] & 1) === 1;
  25808. }; // And first word and num
  25809. BN.prototype.andln = function andln(num) {
  25810. return this.words[0] & num;
  25811. }; // Increment at the bit position in-line
  25812. BN.prototype.bincn = function bincn(bit) {
  25813. assert(typeof bit === 'number');
  25814. var r = bit % 26;
  25815. var s = (bit - r) / 26;
  25816. var q = 1 << r; // Fast case: bit is much higher than all existing words
  25817. if (this.length <= s) {
  25818. this._expand(s + 1);
  25819. this.words[s] |= q;
  25820. return this;
  25821. } // Add bit and propagate, if needed
  25822. var carry = q;
  25823. for (var i = s; carry !== 0 && i < this.length; i++) {
  25824. var w = this.words[i] | 0;
  25825. w += carry;
  25826. carry = w >>> 26;
  25827. w &= 0x3ffffff;
  25828. this.words[i] = w;
  25829. }
  25830. if (carry !== 0) {
  25831. this.words[i] = carry;
  25832. this.length++;
  25833. }
  25834. return this;
  25835. };
  25836. BN.prototype.isZero = function isZero() {
  25837. return this.length === 1 && this.words[0] === 0;
  25838. };
  25839. BN.prototype.cmpn = function cmpn(num) {
  25840. var negative = num < 0;
  25841. if (this.negative !== 0 && !negative) return -1;
  25842. if (this.negative === 0 && negative) return 1;
  25843. this.strip();
  25844. var res;
  25845. if (this.length > 1) {
  25846. res = 1;
  25847. } else {
  25848. if (negative) {
  25849. num = -num;
  25850. }
  25851. assert(num <= 0x3ffffff, 'Number is too big');
  25852. var w = this.words[0] | 0;
  25853. res = w === num ? 0 : w < num ? -1 : 1;
  25854. }
  25855. if (this.negative !== 0) return -res | 0;
  25856. return res;
  25857. }; // Compare two numbers and return:
  25858. // 1 - if `this` > `num`
  25859. // 0 - if `this` == `num`
  25860. // -1 - if `this` < `num`
  25861. BN.prototype.cmp = function cmp(num) {
  25862. if (this.negative !== 0 && num.negative === 0) return -1;
  25863. if (this.negative === 0 && num.negative !== 0) return 1;
  25864. var res = this.ucmp(num);
  25865. if (this.negative !== 0) return -res | 0;
  25866. return res;
  25867. }; // Unsigned comparison
  25868. BN.prototype.ucmp = function ucmp(num) {
  25869. // At this point both numbers have the same sign
  25870. if (this.length > num.length) return 1;
  25871. if (this.length < num.length) return -1;
  25872. var res = 0;
  25873. for (var i = this.length - 1; i >= 0; i--) {
  25874. var a = this.words[i] | 0;
  25875. var b = num.words[i] | 0;
  25876. if (a === b) continue;
  25877. if (a < b) {
  25878. res = -1;
  25879. } else if (a > b) {
  25880. res = 1;
  25881. }
  25882. break;
  25883. }
  25884. return res;
  25885. };
  25886. BN.prototype.gtn = function gtn(num) {
  25887. return this.cmpn(num) === 1;
  25888. };
  25889. BN.prototype.gt = function gt(num) {
  25890. return this.cmp(num) === 1;
  25891. };
  25892. BN.prototype.gten = function gten(num) {
  25893. return this.cmpn(num) >= 0;
  25894. };
  25895. BN.prototype.gte = function gte(num) {
  25896. return this.cmp(num) >= 0;
  25897. };
  25898. BN.prototype.ltn = function ltn(num) {
  25899. return this.cmpn(num) === -1;
  25900. };
  25901. BN.prototype.lt = function lt(num) {
  25902. return this.cmp(num) === -1;
  25903. };
  25904. BN.prototype.lten = function lten(num) {
  25905. return this.cmpn(num) <= 0;
  25906. };
  25907. BN.prototype.lte = function lte(num) {
  25908. return this.cmp(num) <= 0;
  25909. };
  25910. BN.prototype.eqn = function eqn(num) {
  25911. return this.cmpn(num) === 0;
  25912. };
  25913. BN.prototype.eq = function eq(num) {
  25914. return this.cmp(num) === 0;
  25915. }; //
  25916. // A reduce context, could be using montgomery or something better, depending
  25917. // on the `m` itself.
  25918. //
  25919. BN.red = function red(num) {
  25920. return new Red(num);
  25921. };
  25922. BN.prototype.toRed = function toRed(ctx) {
  25923. assert(!this.red, 'Already a number in reduction context');
  25924. assert(this.negative === 0, 'red works only with positives');
  25925. return ctx.convertTo(this)._forceRed(ctx);
  25926. };
  25927. BN.prototype.fromRed = function fromRed() {
  25928. assert(this.red, 'fromRed works only with numbers in reduction context');
  25929. return this.red.convertFrom(this);
  25930. };
  25931. BN.prototype._forceRed = function _forceRed(ctx) {
  25932. this.red = ctx;
  25933. return this;
  25934. };
  25935. BN.prototype.forceRed = function forceRed(ctx) {
  25936. assert(!this.red, 'Already a number in reduction context');
  25937. return this._forceRed(ctx);
  25938. };
  25939. BN.prototype.redAdd = function redAdd(num) {
  25940. assert(this.red, 'redAdd works only with red numbers');
  25941. return this.red.add(this, num);
  25942. };
  25943. BN.prototype.redIAdd = function redIAdd(num) {
  25944. assert(this.red, 'redIAdd works only with red numbers');
  25945. return this.red.iadd(this, num);
  25946. };
  25947. BN.prototype.redSub = function redSub(num) {
  25948. assert(this.red, 'redSub works only with red numbers');
  25949. return this.red.sub(this, num);
  25950. };
  25951. BN.prototype.redISub = function redISub(num) {
  25952. assert(this.red, 'redISub works only with red numbers');
  25953. return this.red.isub(this, num);
  25954. };
  25955. BN.prototype.redShl = function redShl(num) {
  25956. assert(this.red, 'redShl works only with red numbers');
  25957. return this.red.shl(this, num);
  25958. };
  25959. BN.prototype.redMul = function redMul(num) {
  25960. assert(this.red, 'redMul works only with red numbers');
  25961. this.red._verify2(this, num);
  25962. return this.red.mul(this, num);
  25963. };
  25964. BN.prototype.redIMul = function redIMul(num) {
  25965. assert(this.red, 'redMul works only with red numbers');
  25966. this.red._verify2(this, num);
  25967. return this.red.imul(this, num);
  25968. };
  25969. BN.prototype.redSqr = function redSqr() {
  25970. assert(this.red, 'redSqr works only with red numbers');
  25971. this.red._verify1(this);
  25972. return this.red.sqr(this);
  25973. };
  25974. BN.prototype.redISqr = function redISqr() {
  25975. assert(this.red, 'redISqr works only with red numbers');
  25976. this.red._verify1(this);
  25977. return this.red.isqr(this);
  25978. }; // Square root over p
  25979. BN.prototype.redSqrt = function redSqrt() {
  25980. assert(this.red, 'redSqrt works only with red numbers');
  25981. this.red._verify1(this);
  25982. return this.red.sqrt(this);
  25983. };
  25984. BN.prototype.redInvm = function redInvm() {
  25985. assert(this.red, 'redInvm works only with red numbers');
  25986. this.red._verify1(this);
  25987. return this.red.invm(this);
  25988. }; // Return negative clone of `this` % `red modulo`
  25989. BN.prototype.redNeg = function redNeg() {
  25990. assert(this.red, 'redNeg works only with red numbers');
  25991. this.red._verify1(this);
  25992. return this.red.neg(this);
  25993. };
  25994. BN.prototype.redPow = function redPow(num) {
  25995. assert(this.red && !num.red, 'redPow(normalNum)');
  25996. this.red._verify1(this);
  25997. return this.red.pow(this, num);
  25998. }; // Prime numbers with efficient reduction
  25999. var primes = {
  26000. k256: null,
  26001. p224: null,
  26002. p192: null,
  26003. p25519: null
  26004. }; // Pseudo-Mersenne prime
  26005. function MPrime(name, p) {
  26006. // P = 2 ^ N - K
  26007. this.name = name;
  26008. this.p = new BN(p, 16);
  26009. this.n = this.p.bitLength();
  26010. this.k = new BN(1).iushln(this.n).isub(this.p);
  26011. this.tmp = this._tmp();
  26012. }
  26013. MPrime.prototype._tmp = function _tmp() {
  26014. var tmp = new BN(null);
  26015. tmp.words = new Array(Math.ceil(this.n / 13));
  26016. return tmp;
  26017. };
  26018. MPrime.prototype.ireduce = function ireduce(num) {
  26019. // Assumes that `num` is less than `P^2`
  26020. // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P)
  26021. var r = num;
  26022. var rlen;
  26023. do {
  26024. this.split(r, this.tmp);
  26025. r = this.imulK(r);
  26026. r = r.iadd(this.tmp);
  26027. rlen = r.bitLength();
  26028. } while (rlen > this.n);
  26029. var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
  26030. if (cmp === 0) {
  26031. r.words[0] = 0;
  26032. r.length = 1;
  26033. } else if (cmp > 0) {
  26034. r.isub(this.p);
  26035. } else {
  26036. if (r.strip !== undefined) {
  26037. // r is BN v4 instance
  26038. r.strip();
  26039. } else {
  26040. // r is BN v5 instance
  26041. r._strip();
  26042. }
  26043. }
  26044. return r;
  26045. };
  26046. MPrime.prototype.split = function split(input, out) {
  26047. input.iushrn(this.n, 0, out);
  26048. };
  26049. MPrime.prototype.imulK = function imulK(num) {
  26050. return num.imul(this.k);
  26051. };
  26052. function K256() {
  26053. MPrime.call(this, 'k256', 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f');
  26054. }
  26055. inherits(K256, MPrime);
  26056. K256.prototype.split = function split(input, output) {
  26057. // 256 = 9 * 26 + 22
  26058. var mask = 0x3fffff;
  26059. var outLen = Math.min(input.length, 9);
  26060. for (var i = 0; i < outLen; i++) {
  26061. output.words[i] = input.words[i];
  26062. }
  26063. output.length = outLen;
  26064. if (input.length <= 9) {
  26065. input.words[0] = 0;
  26066. input.length = 1;
  26067. return;
  26068. } // Shift by 9 limbs
  26069. var prev = input.words[9];
  26070. output.words[output.length++] = prev & mask;
  26071. for (i = 10; i < input.length; i++) {
  26072. var next = input.words[i] | 0;
  26073. input.words[i - 10] = (next & mask) << 4 | prev >>> 22;
  26074. prev = next;
  26075. }
  26076. prev >>>= 22;
  26077. input.words[i - 10] = prev;
  26078. if (prev === 0 && input.length > 10) {
  26079. input.length -= 10;
  26080. } else {
  26081. input.length -= 9;
  26082. }
  26083. };
  26084. K256.prototype.imulK = function imulK(num) {
  26085. // K = 0x1000003d1 = [ 0x40, 0x3d1 ]
  26086. num.words[num.length] = 0;
  26087. num.words[num.length + 1] = 0;
  26088. num.length += 2; // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390
  26089. var lo = 0;
  26090. for (var i = 0; i < num.length; i++) {
  26091. var w = num.words[i] | 0;
  26092. lo += w * 0x3d1;
  26093. num.words[i] = lo & 0x3ffffff;
  26094. lo = w * 0x40 + (lo / 0x4000000 | 0);
  26095. } // Fast length reduction
  26096. if (num.words[num.length - 1] === 0) {
  26097. num.length--;
  26098. if (num.words[num.length - 1] === 0) {
  26099. num.length--;
  26100. }
  26101. }
  26102. return num;
  26103. };
  26104. function P224() {
  26105. MPrime.call(this, 'p224', 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001');
  26106. }
  26107. inherits(P224, MPrime);
  26108. function P192() {
  26109. MPrime.call(this, 'p192', 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff');
  26110. }
  26111. inherits(P192, MPrime);
  26112. function P25519() {
  26113. // 2 ^ 255 - 19
  26114. MPrime.call(this, '25519', '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed');
  26115. }
  26116. inherits(P25519, MPrime);
  26117. P25519.prototype.imulK = function imulK(num) {
  26118. // K = 0x13
  26119. var carry = 0;
  26120. for (var i = 0; i < num.length; i++) {
  26121. var hi = (num.words[i] | 0) * 0x13 + carry;
  26122. var lo = hi & 0x3ffffff;
  26123. hi >>>= 26;
  26124. num.words[i] = lo;
  26125. carry = hi;
  26126. }
  26127. if (carry !== 0) {
  26128. num.words[num.length++] = carry;
  26129. }
  26130. return num;
  26131. }; // Exported mostly for testing purposes, use plain name instead
  26132. BN._prime = function prime(name) {
  26133. // Cached version of prime
  26134. if (primes[name]) return primes[name];
  26135. var prime;
  26136. if (name === 'k256') {
  26137. prime = new K256();
  26138. } else if (name === 'p224') {
  26139. prime = new P224();
  26140. } else if (name === 'p192') {
  26141. prime = new P192();
  26142. } else if (name === 'p25519') {
  26143. prime = new P25519();
  26144. } else {
  26145. throw new Error('Unknown prime ' + name);
  26146. }
  26147. primes[name] = prime;
  26148. return prime;
  26149. }; //
  26150. // Base reduction engine
  26151. //
  26152. function Red(m) {
  26153. if (typeof m === 'string') {
  26154. var prime = BN._prime(m);
  26155. this.m = prime.p;
  26156. this.prime = prime;
  26157. } else {
  26158. assert(m.gtn(1), 'modulus must be greater than 1');
  26159. this.m = m;
  26160. this.prime = null;
  26161. }
  26162. }
  26163. Red.prototype._verify1 = function _verify1(a) {
  26164. assert(a.negative === 0, 'red works only with positives');
  26165. assert(a.red, 'red works only with red numbers');
  26166. };
  26167. Red.prototype._verify2 = function _verify2(a, b) {
  26168. assert((a.negative | b.negative) === 0, 'red works only with positives');
  26169. assert(a.red && a.red === b.red, 'red works only with red numbers');
  26170. };
  26171. Red.prototype.imod = function imod(a) {
  26172. if (this.prime) return this.prime.ireduce(a)._forceRed(this);
  26173. return a.umod(this.m)._forceRed(this);
  26174. };
  26175. Red.prototype.neg = function neg(a) {
  26176. if (a.isZero()) {
  26177. return a.clone();
  26178. }
  26179. return this.m.sub(a)._forceRed(this);
  26180. };
  26181. Red.prototype.add = function add(a, b) {
  26182. this._verify2(a, b);
  26183. var res = a.add(b);
  26184. if (res.cmp(this.m) >= 0) {
  26185. res.isub(this.m);
  26186. }
  26187. return res._forceRed(this);
  26188. };
  26189. Red.prototype.iadd = function iadd(a, b) {
  26190. this._verify2(a, b);
  26191. var res = a.iadd(b);
  26192. if (res.cmp(this.m) >= 0) {
  26193. res.isub(this.m);
  26194. }
  26195. return res;
  26196. };
  26197. Red.prototype.sub = function sub(a, b) {
  26198. this._verify2(a, b);
  26199. var res = a.sub(b);
  26200. if (res.cmpn(0) < 0) {
  26201. res.iadd(this.m);
  26202. }
  26203. return res._forceRed(this);
  26204. };
  26205. Red.prototype.isub = function isub(a, b) {
  26206. this._verify2(a, b);
  26207. var res = a.isub(b);
  26208. if (res.cmpn(0) < 0) {
  26209. res.iadd(this.m);
  26210. }
  26211. return res;
  26212. };
  26213. Red.prototype.shl = function shl(a, num) {
  26214. this._verify1(a);
  26215. return this.imod(a.ushln(num));
  26216. };
  26217. Red.prototype.imul = function imul(a, b) {
  26218. this._verify2(a, b);
  26219. return this.imod(a.imul(b));
  26220. };
  26221. Red.prototype.mul = function mul(a, b) {
  26222. this._verify2(a, b);
  26223. return this.imod(a.mul(b));
  26224. };
  26225. Red.prototype.isqr = function isqr(a) {
  26226. return this.imul(a, a.clone());
  26227. };
  26228. Red.prototype.sqr = function sqr(a) {
  26229. return this.mul(a, a);
  26230. };
  26231. Red.prototype.sqrt = function sqrt(a) {
  26232. if (a.isZero()) return a.clone();
  26233. var mod3 = this.m.andln(3);
  26234. assert(mod3 % 2 === 1); // Fast case
  26235. if (mod3 === 3) {
  26236. var pow = this.m.add(new BN(1)).iushrn(2);
  26237. return this.pow(a, pow);
  26238. } // Tonelli-Shanks algorithm (Totally unoptimized and slow)
  26239. //
  26240. // Find Q and S, that Q * 2 ^ S = (P - 1)
  26241. var q = this.m.subn(1);
  26242. var s = 0;
  26243. while (!q.isZero() && q.andln(1) === 0) {
  26244. s++;
  26245. q.iushrn(1);
  26246. }
  26247. assert(!q.isZero());
  26248. var one = new BN(1).toRed(this);
  26249. var nOne = one.redNeg(); // Find quadratic non-residue
  26250. // NOTE: Max is such because of generalized Riemann hypothesis.
  26251. var lpow = this.m.subn(1).iushrn(1);
  26252. var z = this.m.bitLength();
  26253. z = new BN(2 * z * z).toRed(this);
  26254. while (this.pow(z, lpow).cmp(nOne) !== 0) {
  26255. z.redIAdd(nOne);
  26256. }
  26257. var c = this.pow(z, q);
  26258. var r = this.pow(a, q.addn(1).iushrn(1));
  26259. var t = this.pow(a, q);
  26260. var m = s;
  26261. while (t.cmp(one) !== 0) {
  26262. var tmp = t;
  26263. for (var i = 0; tmp.cmp(one) !== 0; i++) {
  26264. tmp = tmp.redSqr();
  26265. }
  26266. assert(i < m);
  26267. var b = this.pow(c, new BN(1).iushln(m - i - 1));
  26268. r = r.redMul(b);
  26269. c = b.redSqr();
  26270. t = t.redMul(c);
  26271. m = i;
  26272. }
  26273. return r;
  26274. };
  26275. Red.prototype.invm = function invm(a) {
  26276. var inv = a._invmp(this.m);
  26277. if (inv.negative !== 0) {
  26278. inv.negative = 0;
  26279. return this.imod(inv).redNeg();
  26280. } else {
  26281. return this.imod(inv);
  26282. }
  26283. };
  26284. Red.prototype.pow = function pow(a, num) {
  26285. if (num.isZero()) return new BN(1).toRed(this);
  26286. if (num.cmpn(1) === 0) return a.clone();
  26287. var windowSize = 4;
  26288. var wnd = new Array(1 << windowSize);
  26289. wnd[0] = new BN(1).toRed(this);
  26290. wnd[1] = a;
  26291. for (var i = 2; i < wnd.length; i++) {
  26292. wnd[i] = this.mul(wnd[i - 1], a);
  26293. }
  26294. var res = wnd[0];
  26295. var current = 0;
  26296. var currentLen = 0;
  26297. var start = num.bitLength() % 26;
  26298. if (start === 0) {
  26299. start = 26;
  26300. }
  26301. for (i = num.length - 1; i >= 0; i--) {
  26302. var word = num.words[i];
  26303. for (var j = start - 1; j >= 0; j--) {
  26304. var bit = word >> j & 1;
  26305. if (res !== wnd[0]) {
  26306. res = this.sqr(res);
  26307. }
  26308. if (bit === 0 && current === 0) {
  26309. currentLen = 0;
  26310. continue;
  26311. }
  26312. current <<= 1;
  26313. current |= bit;
  26314. currentLen++;
  26315. if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue;
  26316. res = this.mul(res, wnd[current]);
  26317. currentLen = 0;
  26318. current = 0;
  26319. }
  26320. start = 26;
  26321. }
  26322. return res;
  26323. };
  26324. Red.prototype.convertTo = function convertTo(num) {
  26325. var r = num.umod(this.m);
  26326. return r === num ? r.clone() : r;
  26327. };
  26328. Red.prototype.convertFrom = function convertFrom(num) {
  26329. var res = num.clone();
  26330. res.red = null;
  26331. return res;
  26332. }; //
  26333. // Montgomery method engine
  26334. //
  26335. BN.mont = function mont(num) {
  26336. return new Mont(num);
  26337. };
  26338. function Mont(m) {
  26339. Red.call(this, m);
  26340. this.shift = this.m.bitLength();
  26341. if (this.shift % 26 !== 0) {
  26342. this.shift += 26 - this.shift % 26;
  26343. }
  26344. this.r = new BN(1).iushln(this.shift);
  26345. this.r2 = this.imod(this.r.sqr());
  26346. this.rinv = this.r._invmp(this.m);
  26347. this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
  26348. this.minv = this.minv.umod(this.r);
  26349. this.minv = this.r.sub(this.minv);
  26350. }
  26351. inherits(Mont, Red);
  26352. Mont.prototype.convertTo = function convertTo(num) {
  26353. return this.imod(num.ushln(this.shift));
  26354. };
  26355. Mont.prototype.convertFrom = function convertFrom(num) {
  26356. var r = this.imod(num.mul(this.rinv));
  26357. r.red = null;
  26358. return r;
  26359. };
  26360. Mont.prototype.imul = function imul(a, b) {
  26361. if (a.isZero() || b.isZero()) {
  26362. a.words[0] = 0;
  26363. a.length = 1;
  26364. return a;
  26365. }
  26366. var t = a.imul(b);
  26367. var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
  26368. var u = t.isub(c).iushrn(this.shift);
  26369. var res = u;
  26370. if (u.cmp(this.m) >= 0) {
  26371. res = u.isub(this.m);
  26372. } else if (u.cmpn(0) < 0) {
  26373. res = u.iadd(this.m);
  26374. }
  26375. return res._forceRed(this);
  26376. };
  26377. Mont.prototype.mul = function mul(a, b) {
  26378. if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
  26379. var t = a.mul(b);
  26380. var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
  26381. var u = t.isub(c).iushrn(this.shift);
  26382. var res = u;
  26383. if (u.cmp(this.m) >= 0) {
  26384. res = u.isub(this.m);
  26385. } else if (u.cmpn(0) < 0) {
  26386. res = u.iadd(this.m);
  26387. }
  26388. return res._forceRed(this);
  26389. };
  26390. Mont.prototype.invm = function invm(a) {
  26391. // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R
  26392. var res = this.imod(a._invmp(this.m).mul(this.r2));
  26393. return res._forceRed(this);
  26394. };
  26395. })(typeof module === 'undefined' || module, void 0);
  26396. },{"buffer":185}],182:[function(require,module,exports){
  26397. 'use strict';
  26398. exports.byteLength = byteLength;
  26399. exports.toByteArray = toByteArray;
  26400. exports.fromByteArray = fromByteArray;
  26401. var lookup = [];
  26402. var revLookup = [];
  26403. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
  26404. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  26405. for (var i = 0, len = code.length; i < len; ++i) {
  26406. lookup[i] = code[i];
  26407. revLookup[code.charCodeAt(i)] = i;
  26408. } // Support decoding URL-safe base64 strings, as Node.js does.
  26409. // See: https://en.wikipedia.org/wiki/Base64#URL_applications
  26410. revLookup['-'.charCodeAt(0)] = 62;
  26411. revLookup['_'.charCodeAt(0)] = 63;
  26412. function getLens(b64) {
  26413. var len = b64.length;
  26414. if (len % 4 > 0) {
  26415. throw new Error('Invalid string. Length must be a multiple of 4');
  26416. } // Trim off extra bytes after placeholder bytes are found
  26417. // See: https://github.com/beatgammit/base64-js/issues/42
  26418. var validLen = b64.indexOf('=');
  26419. if (validLen === -1) validLen = len;
  26420. var placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4;
  26421. return [validLen, placeHoldersLen];
  26422. } // base64 is 4/3 + up to two characters of the original data
  26423. function byteLength(b64) {
  26424. var lens = getLens(b64);
  26425. var validLen = lens[0];
  26426. var placeHoldersLen = lens[1];
  26427. return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
  26428. }
  26429. function _byteLength(b64, validLen, placeHoldersLen) {
  26430. return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
  26431. }
  26432. function toByteArray(b64) {
  26433. var tmp;
  26434. var lens = getLens(b64);
  26435. var validLen = lens[0];
  26436. var placeHoldersLen = lens[1];
  26437. var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
  26438. var curByte = 0; // if there are placeholders, only get up to the last complete 4 chars
  26439. var len = placeHoldersLen > 0 ? validLen - 4 : validLen;
  26440. var i;
  26441. for (i = 0; i < len; i += 4) {
  26442. tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)];
  26443. arr[curByte++] = tmp >> 16 & 0xFF;
  26444. arr[curByte++] = tmp >> 8 & 0xFF;
  26445. arr[curByte++] = tmp & 0xFF;
  26446. }
  26447. if (placeHoldersLen === 2) {
  26448. tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4;
  26449. arr[curByte++] = tmp & 0xFF;
  26450. }
  26451. if (placeHoldersLen === 1) {
  26452. tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2;
  26453. arr[curByte++] = tmp >> 8 & 0xFF;
  26454. arr[curByte++] = tmp & 0xFF;
  26455. }
  26456. return arr;
  26457. }
  26458. function tripletToBase64(num) {
  26459. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F];
  26460. }
  26461. function encodeChunk(uint8, start, end) {
  26462. var tmp;
  26463. var output = [];
  26464. for (var i = start; i < end; i += 3) {
  26465. tmp = (uint8[i] << 16 & 0xFF0000) + (uint8[i + 1] << 8 & 0xFF00) + (uint8[i + 2] & 0xFF);
  26466. output.push(tripletToBase64(tmp));
  26467. }
  26468. return output.join('');
  26469. }
  26470. function fromByteArray(uint8) {
  26471. var tmp;
  26472. var len = uint8.length;
  26473. var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
  26474. var parts = [];
  26475. var maxChunkLength = 16383; // must be multiple of 3
  26476. // go through the array every three bytes, we'll deal with trailing stuff later
  26477. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  26478. parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength));
  26479. } // pad the end with zeros, but make sure to not forget the extra bytes
  26480. if (extraBytes === 1) {
  26481. tmp = uint8[len - 1];
  26482. parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 0x3F] + '==');
  26483. } else if (extraBytes === 2) {
  26484. tmp = (uint8[len - 2] << 8) + uint8[len - 1];
  26485. parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 0x3F] + lookup[tmp << 2 & 0x3F] + '=');
  26486. }
  26487. return parts.join('');
  26488. }
  26489. },{}],183:[function(require,module,exports){
  26490. "use strict";
  26491. 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); }
  26492. (function (module, exports) {
  26493. 'use strict'; // Utils
  26494. function assert(val, msg) {
  26495. if (!val) throw new Error(msg || 'Assertion failed');
  26496. } // Could use `inherits` module, but don't want to move from single file
  26497. // architecture yet.
  26498. function inherits(ctor, superCtor) {
  26499. ctor.super_ = superCtor;
  26500. var TempCtor = function TempCtor() {};
  26501. TempCtor.prototype = superCtor.prototype;
  26502. ctor.prototype = new TempCtor();
  26503. ctor.prototype.constructor = ctor;
  26504. } // BN
  26505. function BN(number, base, endian) {
  26506. if (BN.isBN(number)) {
  26507. return number;
  26508. }
  26509. this.negative = 0;
  26510. this.words = null;
  26511. this.length = 0; // Reduction context
  26512. this.red = null;
  26513. if (number !== null) {
  26514. if (base === 'le' || base === 'be') {
  26515. endian = base;
  26516. base = 10;
  26517. }
  26518. this._init(number || 0, base || 10, endian || 'be');
  26519. }
  26520. }
  26521. if (_typeof(module) === 'object') {
  26522. module.exports = BN;
  26523. } else {
  26524. exports.BN = BN;
  26525. }
  26526. BN.BN = BN;
  26527. BN.wordSize = 26;
  26528. var Buffer;
  26529. try {
  26530. Buffer = require('buffer').Buffer;
  26531. } catch (e) {}
  26532. BN.isBN = function isBN(num) {
  26533. if (num instanceof BN) {
  26534. return true;
  26535. }
  26536. return num !== null && _typeof(num) === 'object' && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
  26537. };
  26538. BN.max = function max(left, right) {
  26539. if (left.cmp(right) > 0) return left;
  26540. return right;
  26541. };
  26542. BN.min = function min(left, right) {
  26543. if (left.cmp(right) < 0) return left;
  26544. return right;
  26545. };
  26546. BN.prototype._init = function init(number, base, endian) {
  26547. if (typeof number === 'number') {
  26548. return this._initNumber(number, base, endian);
  26549. }
  26550. if (_typeof(number) === 'object') {
  26551. return this._initArray(number, base, endian);
  26552. }
  26553. if (base === 'hex') {
  26554. base = 16;
  26555. }
  26556. assert(base === (base | 0) && base >= 2 && base <= 36);
  26557. number = number.toString().replace(/\s+/g, '');
  26558. var start = 0;
  26559. if (number[0] === '-') {
  26560. start++;
  26561. }
  26562. if (base === 16) {
  26563. this._parseHex(number, start);
  26564. } else {
  26565. this._parseBase(number, base, start);
  26566. }
  26567. if (number[0] === '-') {
  26568. this.negative = 1;
  26569. }
  26570. this._strip();
  26571. if (endian !== 'le') return;
  26572. this._initArray(this.toArray(), base, endian);
  26573. };
  26574. BN.prototype._initNumber = function _initNumber(number, base, endian) {
  26575. if (number < 0) {
  26576. this.negative = 1;
  26577. number = -number;
  26578. }
  26579. if (number < 0x4000000) {
  26580. this.words = [number & 0x3ffffff];
  26581. this.length = 1;
  26582. } else if (number < 0x10000000000000) {
  26583. this.words = [number & 0x3ffffff, number / 0x4000000 & 0x3ffffff];
  26584. this.length = 2;
  26585. } else {
  26586. assert(number < 0x20000000000000); // 2 ^ 53 (unsafe)
  26587. this.words = [number & 0x3ffffff, number / 0x4000000 & 0x3ffffff, 1];
  26588. this.length = 3;
  26589. }
  26590. if (endian !== 'le') return; // Reverse the bytes
  26591. this._initArray(this.toArray(), base, endian);
  26592. };
  26593. BN.prototype._initArray = function _initArray(number, base, endian) {
  26594. // Perhaps a Uint8Array
  26595. assert(typeof number.length === 'number');
  26596. if (number.length <= 0) {
  26597. this.words = [0];
  26598. this.length = 1;
  26599. return this;
  26600. }
  26601. this.length = Math.ceil(number.length / 3);
  26602. this.words = new Array(this.length);
  26603. for (var i = 0; i < this.length; i++) {
  26604. this.words[i] = 0;
  26605. }
  26606. var j, w;
  26607. var off = 0;
  26608. if (endian === 'be') {
  26609. for (i = number.length - 1, j = 0; i >= 0; i -= 3) {
  26610. w = number[i] | number[i - 1] << 8 | number[i - 2] << 16;
  26611. this.words[j] |= w << off & 0x3ffffff;
  26612. this.words[j + 1] = w >>> 26 - off & 0x3ffffff;
  26613. off += 24;
  26614. if (off >= 26) {
  26615. off -= 26;
  26616. j++;
  26617. }
  26618. }
  26619. } else if (endian === 'le') {
  26620. for (i = 0, j = 0; i < number.length; i += 3) {
  26621. w = number[i] | number[i + 1] << 8 | number[i + 2] << 16;
  26622. this.words[j] |= w << off & 0x3ffffff;
  26623. this.words[j + 1] = w >>> 26 - off & 0x3ffffff;
  26624. off += 24;
  26625. if (off >= 26) {
  26626. off -= 26;
  26627. j++;
  26628. }
  26629. }
  26630. }
  26631. return this._strip();
  26632. };
  26633. function parseHex(str, start, end) {
  26634. var r = 0;
  26635. var len = Math.min(str.length, end);
  26636. var z = 0;
  26637. for (var i = start; i < len; i++) {
  26638. var c = str.charCodeAt(i) - 48;
  26639. r <<= 4;
  26640. var b; // 'a' - 'f'
  26641. if (c >= 49 && c <= 54) {
  26642. b = c - 49 + 0xa; // 'A' - 'F'
  26643. } else if (c >= 17 && c <= 22) {
  26644. b = c - 17 + 0xa; // '0' - '9'
  26645. } else {
  26646. b = c;
  26647. }
  26648. r |= b;
  26649. z |= b;
  26650. }
  26651. assert(!(z & 0xf0), 'Invalid character in ' + str);
  26652. return r;
  26653. }
  26654. BN.prototype._parseHex = function _parseHex(number, start) {
  26655. // Create possibly bigger array to ensure that it fits the number
  26656. this.length = Math.ceil((number.length - start) / 6);
  26657. this.words = new Array(this.length);
  26658. for (var i = 0; i < this.length; i++) {
  26659. this.words[i] = 0;
  26660. }
  26661. var j, w; // Scan 24-bit chunks and add them to the number
  26662. var off = 0;
  26663. for (i = number.length - 6, j = 0; i >= start; i -= 6) {
  26664. w = parseHex(number, i, i + 6);
  26665. this.words[j] |= w << off & 0x3ffffff; // NOTE: `0x3fffff` is intentional here, 26bits max shift + 24bit hex limb
  26666. this.words[j + 1] |= w >>> 26 - off & 0x3fffff;
  26667. off += 24;
  26668. if (off >= 26) {
  26669. off -= 26;
  26670. j++;
  26671. }
  26672. }
  26673. if (i + 6 !== start) {
  26674. w = parseHex(number, start, i + 6);
  26675. this.words[j] |= w << off & 0x3ffffff;
  26676. this.words[j + 1] |= w >>> 26 - off & 0x3fffff;
  26677. }
  26678. this._strip();
  26679. };
  26680. function parseBase(str, start, end, mul) {
  26681. var r = 0;
  26682. var b = 0;
  26683. var len = Math.min(str.length, end);
  26684. for (var i = start; i < len; i++) {
  26685. var c = str.charCodeAt(i) - 48;
  26686. r *= mul; // 'a'
  26687. if (c >= 49) {
  26688. b = c - 49 + 0xa; // 'A'
  26689. } else if (c >= 17) {
  26690. b = c - 17 + 0xa; // '0' - '9'
  26691. } else {
  26692. b = c;
  26693. }
  26694. assert(c >= 0 && b < mul, 'Invalid character');
  26695. r += b;
  26696. }
  26697. return r;
  26698. }
  26699. BN.prototype._parseBase = function _parseBase(number, base, start) {
  26700. // Initialize as zero
  26701. this.words = [0];
  26702. this.length = 1; // Find length of limb in base
  26703. for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) {
  26704. limbLen++;
  26705. }
  26706. limbLen--;
  26707. limbPow = limbPow / base | 0;
  26708. var total = number.length - start;
  26709. var mod = total % limbLen;
  26710. var end = Math.min(total, total - mod) + start;
  26711. var word = 0;
  26712. for (var i = start; i < end; i += limbLen) {
  26713. word = parseBase(number, i, i + limbLen, base);
  26714. this.imuln(limbPow);
  26715. if (this.words[0] + word < 0x4000000) {
  26716. this.words[0] += word;
  26717. } else {
  26718. this._iaddn(word);
  26719. }
  26720. }
  26721. if (mod !== 0) {
  26722. var pow = 1;
  26723. word = parseBase(number, i, number.length, base);
  26724. for (i = 0; i < mod; i++) {
  26725. pow *= base;
  26726. }
  26727. this.imuln(pow);
  26728. if (this.words[0] + word < 0x4000000) {
  26729. this.words[0] += word;
  26730. } else {
  26731. this._iaddn(word);
  26732. }
  26733. }
  26734. };
  26735. BN.prototype.copy = function copy(dest) {
  26736. dest.words = new Array(this.length);
  26737. for (var i = 0; i < this.length; i++) {
  26738. dest.words[i] = this.words[i];
  26739. }
  26740. dest.length = this.length;
  26741. dest.negative = this.negative;
  26742. dest.red = this.red;
  26743. };
  26744. function move(dest, src) {
  26745. dest.words = src.words;
  26746. dest.length = src.length;
  26747. dest.negative = src.negative;
  26748. dest.red = src.red;
  26749. }
  26750. BN.prototype._move = function _move(dest) {
  26751. move(dest, this);
  26752. };
  26753. BN.prototype.clone = function clone() {
  26754. var r = new BN(null);
  26755. this.copy(r);
  26756. return r;
  26757. };
  26758. BN.prototype._expand = function _expand(size) {
  26759. while (this.length < size) {
  26760. this.words[this.length++] = 0;
  26761. }
  26762. return this;
  26763. }; // Remove leading `0` from `this`
  26764. BN.prototype._strip = function strip() {
  26765. while (this.length > 1 && this.words[this.length - 1] === 0) {
  26766. this.length--;
  26767. }
  26768. return this._normSign();
  26769. };
  26770. BN.prototype._normSign = function _normSign() {
  26771. // -0 = 0
  26772. if (this.length === 1 && this.words[0] === 0) {
  26773. this.negative = 0;
  26774. }
  26775. return this;
  26776. }; // Check Symbol.for because not everywhere where Symbol defined
  26777. // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol#Browser_compatibility
  26778. if (typeof Symbol !== 'undefined' && typeof Symbol.for === 'function') {
  26779. try {
  26780. BN.prototype[Symbol.for('nodejs.util.inspect.custom')] = inspect;
  26781. } catch (e) {
  26782. BN.prototype.inspect = inspect;
  26783. }
  26784. } else {
  26785. BN.prototype.inspect = inspect;
  26786. }
  26787. function inspect() {
  26788. return (this.red ? '<BN-R: ' : '<BN: ') + this.toString(16) + '>';
  26789. }
  26790. /*
  26791. var zeros = [];
  26792. var groupSizes = [];
  26793. var groupBases = [];
  26794. var s = '';
  26795. var i = -1;
  26796. while (++i < BN.wordSize) {
  26797. zeros[i] = s;
  26798. s += '0';
  26799. }
  26800. groupSizes[0] = 0;
  26801. groupSizes[1] = 0;
  26802. groupBases[0] = 0;
  26803. groupBases[1] = 0;
  26804. var base = 2 - 1;
  26805. while (++base < 36 + 1) {
  26806. var groupSize = 0;
  26807. var groupBase = 1;
  26808. while (groupBase < (1 << BN.wordSize) / base) {
  26809. groupBase *= base;
  26810. groupSize += 1;
  26811. }
  26812. groupSizes[base] = groupSize;
  26813. groupBases[base] = groupBase;
  26814. }
  26815. */
  26816. 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'];
  26817. 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];
  26818. 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];
  26819. BN.prototype.toString = function toString(base, padding) {
  26820. base = base || 10;
  26821. padding = padding | 0 || 1;
  26822. var out;
  26823. if (base === 16 || base === 'hex') {
  26824. out = '';
  26825. var off = 0;
  26826. var carry = 0;
  26827. for (var i = 0; i < this.length; i++) {
  26828. var w = this.words[i];
  26829. var word = ((w << off | carry) & 0xffffff).toString(16);
  26830. carry = w >>> 24 - off & 0xffffff;
  26831. if (carry !== 0 || i !== this.length - 1) {
  26832. out = zeros[6 - word.length] + word + out;
  26833. } else {
  26834. out = word + out;
  26835. }
  26836. off += 2;
  26837. if (off >= 26) {
  26838. off -= 26;
  26839. i--;
  26840. }
  26841. }
  26842. if (carry !== 0) {
  26843. out = carry.toString(16) + out;
  26844. }
  26845. while (out.length % padding !== 0) {
  26846. out = '0' + out;
  26847. }
  26848. if (this.negative !== 0) {
  26849. out = '-' + out;
  26850. }
  26851. return out;
  26852. }
  26853. if (base === (base | 0) && base >= 2 && base <= 36) {
  26854. // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base));
  26855. var groupSize = groupSizes[base]; // var groupBase = Math.pow(base, groupSize);
  26856. var groupBase = groupBases[base];
  26857. out = '';
  26858. var c = this.clone();
  26859. c.negative = 0;
  26860. while (!c.isZero()) {
  26861. var r = c.modrn(groupBase).toString(base);
  26862. c = c.idivn(groupBase);
  26863. if (!c.isZero()) {
  26864. out = zeros[groupSize - r.length] + r + out;
  26865. } else {
  26866. out = r + out;
  26867. }
  26868. }
  26869. if (this.isZero()) {
  26870. out = '0' + out;
  26871. }
  26872. while (out.length % padding !== 0) {
  26873. out = '0' + out;
  26874. }
  26875. if (this.negative !== 0) {
  26876. out = '-' + out;
  26877. }
  26878. return out;
  26879. }
  26880. assert(false, 'Base should be between 2 and 36');
  26881. };
  26882. BN.prototype.toNumber = function toNumber() {
  26883. var ret = this.words[0];
  26884. if (this.length === 2) {
  26885. ret += this.words[1] * 0x4000000;
  26886. } else if (this.length === 3 && this.words[2] === 0x01) {
  26887. // NOTE: at this stage it is known that the top bit is set
  26888. ret += 0x10000000000000 + this.words[1] * 0x4000000;
  26889. } else if (this.length > 2) {
  26890. assert(false, 'Number can only safely store up to 53 bits');
  26891. }
  26892. return this.negative !== 0 ? -ret : ret;
  26893. };
  26894. BN.prototype.toJSON = function toJSON() {
  26895. return this.toString(16, 2);
  26896. };
  26897. if (Buffer) {
  26898. BN.prototype.toBuffer = function toBuffer(endian, length) {
  26899. return this.toArrayLike(Buffer, endian, length);
  26900. };
  26901. }
  26902. BN.prototype.toArray = function toArray(endian, length) {
  26903. return this.toArrayLike(Array, endian, length);
  26904. };
  26905. var allocate = function allocate(ArrayType, size) {
  26906. if (ArrayType.allocUnsafe) {
  26907. return ArrayType.allocUnsafe(size);
  26908. }
  26909. return new ArrayType(size);
  26910. };
  26911. BN.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) {
  26912. this._strip();
  26913. var byteLength = this.byteLength();
  26914. var reqLength = length || Math.max(1, byteLength);
  26915. assert(byteLength <= reqLength, 'byte array longer than desired length');
  26916. assert(reqLength > 0, 'Requested array length <= 0');
  26917. var res = allocate(ArrayType, reqLength);
  26918. var postfix = endian === 'le' ? 'LE' : 'BE';
  26919. this['_toArrayLike' + postfix](res, byteLength);
  26920. return res;
  26921. };
  26922. BN.prototype._toArrayLikeLE = function _toArrayLikeLE(res, byteLength) {
  26923. var position = 0;
  26924. var carry = 0;
  26925. for (var i = 0, shift = 0; i < this.length; i++) {
  26926. var word = this.words[i] << shift | carry;
  26927. res[position++] = word & 0xff;
  26928. if (position < res.length) {
  26929. res[position++] = word >> 8 & 0xff;
  26930. }
  26931. if (position < res.length) {
  26932. res[position++] = word >> 16 & 0xff;
  26933. }
  26934. if (shift === 6) {
  26935. if (position < res.length) {
  26936. res[position++] = word >> 24 & 0xff;
  26937. }
  26938. carry = 0;
  26939. shift = 0;
  26940. } else {
  26941. carry = word >>> 24;
  26942. shift += 2;
  26943. }
  26944. }
  26945. if (position < res.length) {
  26946. res[position++] = carry;
  26947. while (position < res.length) {
  26948. res[position++] = 0;
  26949. }
  26950. }
  26951. };
  26952. BN.prototype._toArrayLikeBE = function _toArrayLikeBE(res, byteLength) {
  26953. var position = res.length - 1;
  26954. var carry = 0;
  26955. for (var i = 0, shift = 0; i < this.length; i++) {
  26956. var word = this.words[i] << shift | carry;
  26957. res[position--] = word & 0xff;
  26958. if (position >= 0) {
  26959. res[position--] = word >> 8 & 0xff;
  26960. }
  26961. if (position >= 0) {
  26962. res[position--] = word >> 16 & 0xff;
  26963. }
  26964. if (shift === 6) {
  26965. if (position >= 0) {
  26966. res[position--] = word >> 24 & 0xff;
  26967. }
  26968. carry = 0;
  26969. shift = 0;
  26970. } else {
  26971. carry = word >>> 24;
  26972. shift += 2;
  26973. }
  26974. }
  26975. if (position >= 0) {
  26976. res[position--] = carry;
  26977. while (position >= 0) {
  26978. res[position--] = 0;
  26979. }
  26980. }
  26981. };
  26982. if (Math.clz32) {
  26983. BN.prototype._countBits = function _countBits(w) {
  26984. return 32 - Math.clz32(w);
  26985. };
  26986. } else {
  26987. BN.prototype._countBits = function _countBits(w) {
  26988. var t = w;
  26989. var r = 0;
  26990. if (t >= 0x1000) {
  26991. r += 13;
  26992. t >>>= 13;
  26993. }
  26994. if (t >= 0x40) {
  26995. r += 7;
  26996. t >>>= 7;
  26997. }
  26998. if (t >= 0x8) {
  26999. r += 4;
  27000. t >>>= 4;
  27001. }
  27002. if (t >= 0x02) {
  27003. r += 2;
  27004. t >>>= 2;
  27005. }
  27006. return r + t;
  27007. };
  27008. }
  27009. BN.prototype._zeroBits = function _zeroBits(w) {
  27010. // Short-cut
  27011. if (w === 0) return 26;
  27012. var t = w;
  27013. var r = 0;
  27014. if ((t & 0x1fff) === 0) {
  27015. r += 13;
  27016. t >>>= 13;
  27017. }
  27018. if ((t & 0x7f) === 0) {
  27019. r += 7;
  27020. t >>>= 7;
  27021. }
  27022. if ((t & 0xf) === 0) {
  27023. r += 4;
  27024. t >>>= 4;
  27025. }
  27026. if ((t & 0x3) === 0) {
  27027. r += 2;
  27028. t >>>= 2;
  27029. }
  27030. if ((t & 0x1) === 0) {
  27031. r++;
  27032. }
  27033. return r;
  27034. }; // Return number of used bits in a BN
  27035. BN.prototype.bitLength = function bitLength() {
  27036. var w = this.words[this.length - 1];
  27037. var hi = this._countBits(w);
  27038. return (this.length - 1) * 26 + hi;
  27039. };
  27040. function toBitArray(num) {
  27041. var w = new Array(num.bitLength());
  27042. for (var bit = 0; bit < w.length; bit++) {
  27043. var off = bit / 26 | 0;
  27044. var wbit = bit % 26;
  27045. w[bit] = num.words[off] >>> wbit & 0x01;
  27046. }
  27047. return w;
  27048. } // Number of trailing zero bits
  27049. BN.prototype.zeroBits = function zeroBits() {
  27050. if (this.isZero()) return 0;
  27051. var r = 0;
  27052. for (var i = 0; i < this.length; i++) {
  27053. var b = this._zeroBits(this.words[i]);
  27054. r += b;
  27055. if (b !== 26) break;
  27056. }
  27057. return r;
  27058. };
  27059. BN.prototype.byteLength = function byteLength() {
  27060. return Math.ceil(this.bitLength() / 8);
  27061. };
  27062. BN.prototype.toTwos = function toTwos(width) {
  27063. if (this.negative !== 0) {
  27064. return this.abs().inotn(width).iaddn(1);
  27065. }
  27066. return this.clone();
  27067. };
  27068. BN.prototype.fromTwos = function fromTwos(width) {
  27069. if (this.testn(width - 1)) {
  27070. return this.notn(width).iaddn(1).ineg();
  27071. }
  27072. return this.clone();
  27073. };
  27074. BN.prototype.isNeg = function isNeg() {
  27075. return this.negative !== 0;
  27076. }; // Return negative clone of `this`
  27077. BN.prototype.neg = function neg() {
  27078. return this.clone().ineg();
  27079. };
  27080. BN.prototype.ineg = function ineg() {
  27081. if (!this.isZero()) {
  27082. this.negative ^= 1;
  27083. }
  27084. return this;
  27085. }; // Or `num` with `this` in-place
  27086. BN.prototype.iuor = function iuor(num) {
  27087. while (this.length < num.length) {
  27088. this.words[this.length++] = 0;
  27089. }
  27090. for (var i = 0; i < num.length; i++) {
  27091. this.words[i] = this.words[i] | num.words[i];
  27092. }
  27093. return this._strip();
  27094. };
  27095. BN.prototype.ior = function ior(num) {
  27096. assert((this.negative | num.negative) === 0);
  27097. return this.iuor(num);
  27098. }; // Or `num` with `this`
  27099. BN.prototype.or = function or(num) {
  27100. if (this.length > num.length) return this.clone().ior(num);
  27101. return num.clone().ior(this);
  27102. };
  27103. BN.prototype.uor = function uor(num) {
  27104. if (this.length > num.length) return this.clone().iuor(num);
  27105. return num.clone().iuor(this);
  27106. }; // And `num` with `this` in-place
  27107. BN.prototype.iuand = function iuand(num) {
  27108. // b = min-length(num, this)
  27109. var b;
  27110. if (this.length > num.length) {
  27111. b = num;
  27112. } else {
  27113. b = this;
  27114. }
  27115. for (var i = 0; i < b.length; i++) {
  27116. this.words[i] = this.words[i] & num.words[i];
  27117. }
  27118. this.length = b.length;
  27119. return this._strip();
  27120. };
  27121. BN.prototype.iand = function iand(num) {
  27122. assert((this.negative | num.negative) === 0);
  27123. return this.iuand(num);
  27124. }; // And `num` with `this`
  27125. BN.prototype.and = function and(num) {
  27126. if (this.length > num.length) return this.clone().iand(num);
  27127. return num.clone().iand(this);
  27128. };
  27129. BN.prototype.uand = function uand(num) {
  27130. if (this.length > num.length) return this.clone().iuand(num);
  27131. return num.clone().iuand(this);
  27132. }; // Xor `num` with `this` in-place
  27133. BN.prototype.iuxor = function iuxor(num) {
  27134. // a.length > b.length
  27135. var a;
  27136. var b;
  27137. if (this.length > num.length) {
  27138. a = this;
  27139. b = num;
  27140. } else {
  27141. a = num;
  27142. b = this;
  27143. }
  27144. for (var i = 0; i < b.length; i++) {
  27145. this.words[i] = a.words[i] ^ b.words[i];
  27146. }
  27147. if (this !== a) {
  27148. for (; i < a.length; i++) {
  27149. this.words[i] = a.words[i];
  27150. }
  27151. }
  27152. this.length = a.length;
  27153. return this._strip();
  27154. };
  27155. BN.prototype.ixor = function ixor(num) {
  27156. assert((this.negative | num.negative) === 0);
  27157. return this.iuxor(num);
  27158. }; // Xor `num` with `this`
  27159. BN.prototype.xor = function xor(num) {
  27160. if (this.length > num.length) return this.clone().ixor(num);
  27161. return num.clone().ixor(this);
  27162. };
  27163. BN.prototype.uxor = function uxor(num) {
  27164. if (this.length > num.length) return this.clone().iuxor(num);
  27165. return num.clone().iuxor(this);
  27166. }; // Not ``this`` with ``width`` bitwidth
  27167. BN.prototype.inotn = function inotn(width) {
  27168. assert(typeof width === 'number' && width >= 0);
  27169. var bytesNeeded = Math.ceil(width / 26) | 0;
  27170. var bitsLeft = width % 26; // Extend the buffer with leading zeroes
  27171. this._expand(bytesNeeded);
  27172. if (bitsLeft > 0) {
  27173. bytesNeeded--;
  27174. } // Handle complete words
  27175. for (var i = 0; i < bytesNeeded; i++) {
  27176. this.words[i] = ~this.words[i] & 0x3ffffff;
  27177. } // Handle the residue
  27178. if (bitsLeft > 0) {
  27179. this.words[i] = ~this.words[i] & 0x3ffffff >> 26 - bitsLeft;
  27180. } // And remove leading zeroes
  27181. return this._strip();
  27182. };
  27183. BN.prototype.notn = function notn(width) {
  27184. return this.clone().inotn(width);
  27185. }; // Set `bit` of `this`
  27186. BN.prototype.setn = function setn(bit, val) {
  27187. assert(typeof bit === 'number' && bit >= 0);
  27188. var off = bit / 26 | 0;
  27189. var wbit = bit % 26;
  27190. this._expand(off + 1);
  27191. if (val) {
  27192. this.words[off] = this.words[off] | 1 << wbit;
  27193. } else {
  27194. this.words[off] = this.words[off] & ~(1 << wbit);
  27195. }
  27196. return this._strip();
  27197. }; // Add `num` to `this` in-place
  27198. BN.prototype.iadd = function iadd(num) {
  27199. var r; // negative + positive
  27200. if (this.negative !== 0 && num.negative === 0) {
  27201. this.negative = 0;
  27202. r = this.isub(num);
  27203. this.negative ^= 1;
  27204. return this._normSign(); // positive + negative
  27205. } else if (this.negative === 0 && num.negative !== 0) {
  27206. num.negative = 0;
  27207. r = this.isub(num);
  27208. num.negative = 1;
  27209. return r._normSign();
  27210. } // a.length > b.length
  27211. var a, b;
  27212. if (this.length > num.length) {
  27213. a = this;
  27214. b = num;
  27215. } else {
  27216. a = num;
  27217. b = this;
  27218. }
  27219. var carry = 0;
  27220. for (var i = 0; i < b.length; i++) {
  27221. r = (a.words[i] | 0) + (b.words[i] | 0) + carry;
  27222. this.words[i] = r & 0x3ffffff;
  27223. carry = r >>> 26;
  27224. }
  27225. for (; carry !== 0 && i < a.length; i++) {
  27226. r = (a.words[i] | 0) + carry;
  27227. this.words[i] = r & 0x3ffffff;
  27228. carry = r >>> 26;
  27229. }
  27230. this.length = a.length;
  27231. if (carry !== 0) {
  27232. this.words[this.length] = carry;
  27233. this.length++; // Copy the rest of the words
  27234. } else if (a !== this) {
  27235. for (; i < a.length; i++) {
  27236. this.words[i] = a.words[i];
  27237. }
  27238. }
  27239. return this;
  27240. }; // Add `num` to `this`
  27241. BN.prototype.add = function add(num) {
  27242. var res;
  27243. if (num.negative !== 0 && this.negative === 0) {
  27244. num.negative = 0;
  27245. res = this.sub(num);
  27246. num.negative ^= 1;
  27247. return res;
  27248. } else if (num.negative === 0 && this.negative !== 0) {
  27249. this.negative = 0;
  27250. res = num.sub(this);
  27251. this.negative = 1;
  27252. return res;
  27253. }
  27254. if (this.length > num.length) return this.clone().iadd(num);
  27255. return num.clone().iadd(this);
  27256. }; // Subtract `num` from `this` in-place
  27257. BN.prototype.isub = function isub(num) {
  27258. // this - (-num) = this + num
  27259. if (num.negative !== 0) {
  27260. num.negative = 0;
  27261. var r = this.iadd(num);
  27262. num.negative = 1;
  27263. return r._normSign(); // -this - num = -(this + num)
  27264. } else if (this.negative !== 0) {
  27265. this.negative = 0;
  27266. this.iadd(num);
  27267. this.negative = 1;
  27268. return this._normSign();
  27269. } // At this point both numbers are positive
  27270. var cmp = this.cmp(num); // Optimization - zeroify
  27271. if (cmp === 0) {
  27272. this.negative = 0;
  27273. this.length = 1;
  27274. this.words[0] = 0;
  27275. return this;
  27276. } // a > b
  27277. var a, b;
  27278. if (cmp > 0) {
  27279. a = this;
  27280. b = num;
  27281. } else {
  27282. a = num;
  27283. b = this;
  27284. }
  27285. var carry = 0;
  27286. for (var i = 0; i < b.length; i++) {
  27287. r = (a.words[i] | 0) - (b.words[i] | 0) + carry;
  27288. carry = r >> 26;
  27289. this.words[i] = r & 0x3ffffff;
  27290. }
  27291. for (; carry !== 0 && i < a.length; i++) {
  27292. r = (a.words[i] | 0) + carry;
  27293. carry = r >> 26;
  27294. this.words[i] = r & 0x3ffffff;
  27295. } // Copy rest of the words
  27296. if (carry === 0 && i < a.length && a !== this) {
  27297. for (; i < a.length; i++) {
  27298. this.words[i] = a.words[i];
  27299. }
  27300. }
  27301. this.length = Math.max(this.length, i);
  27302. if (a !== this) {
  27303. this.negative = 1;
  27304. }
  27305. return this._strip();
  27306. }; // Subtract `num` from `this`
  27307. BN.prototype.sub = function sub(num) {
  27308. return this.clone().isub(num);
  27309. };
  27310. function smallMulTo(self, num, out) {
  27311. out.negative = num.negative ^ self.negative;
  27312. var len = self.length + num.length | 0;
  27313. out.length = len;
  27314. len = len - 1 | 0; // Peel one iteration (compiler can't do it, because of code complexity)
  27315. var a = self.words[0] | 0;
  27316. var b = num.words[0] | 0;
  27317. var r = a * b;
  27318. var lo = r & 0x3ffffff;
  27319. var carry = r / 0x4000000 | 0;
  27320. out.words[0] = lo;
  27321. for (var k = 1; k < len; k++) {
  27322. // Sum all words with the same `i + j = k` and accumulate `ncarry`,
  27323. // note that ncarry could be >= 0x3ffffff
  27324. var ncarry = carry >>> 26;
  27325. var rword = carry & 0x3ffffff;
  27326. var maxJ = Math.min(k, num.length - 1);
  27327. for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
  27328. var i = k - j | 0;
  27329. a = self.words[i] | 0;
  27330. b = num.words[j] | 0;
  27331. r = a * b + rword;
  27332. ncarry += r / 0x4000000 | 0;
  27333. rword = r & 0x3ffffff;
  27334. }
  27335. out.words[k] = rword | 0;
  27336. carry = ncarry | 0;
  27337. }
  27338. if (carry !== 0) {
  27339. out.words[k] = carry | 0;
  27340. } else {
  27341. out.length--;
  27342. }
  27343. return out._strip();
  27344. } // TODO(indutny): it may be reasonable to omit it for users who don't need
  27345. // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit
  27346. // multiplication (like elliptic secp256k1).
  27347. var comb10MulTo = function comb10MulTo(self, num, out) {
  27348. var a = self.words;
  27349. var b = num.words;
  27350. var o = out.words;
  27351. var c = 0;
  27352. var lo;
  27353. var mid;
  27354. var hi;
  27355. var a0 = a[0] | 0;
  27356. var al0 = a0 & 0x1fff;
  27357. var ah0 = a0 >>> 13;
  27358. var a1 = a[1] | 0;
  27359. var al1 = a1 & 0x1fff;
  27360. var ah1 = a1 >>> 13;
  27361. var a2 = a[2] | 0;
  27362. var al2 = a2 & 0x1fff;
  27363. var ah2 = a2 >>> 13;
  27364. var a3 = a[3] | 0;
  27365. var al3 = a3 & 0x1fff;
  27366. var ah3 = a3 >>> 13;
  27367. var a4 = a[4] | 0;
  27368. var al4 = a4 & 0x1fff;
  27369. var ah4 = a4 >>> 13;
  27370. var a5 = a[5] | 0;
  27371. var al5 = a5 & 0x1fff;
  27372. var ah5 = a5 >>> 13;
  27373. var a6 = a[6] | 0;
  27374. var al6 = a6 & 0x1fff;
  27375. var ah6 = a6 >>> 13;
  27376. var a7 = a[7] | 0;
  27377. var al7 = a7 & 0x1fff;
  27378. var ah7 = a7 >>> 13;
  27379. var a8 = a[8] | 0;
  27380. var al8 = a8 & 0x1fff;
  27381. var ah8 = a8 >>> 13;
  27382. var a9 = a[9] | 0;
  27383. var al9 = a9 & 0x1fff;
  27384. var ah9 = a9 >>> 13;
  27385. var b0 = b[0] | 0;
  27386. var bl0 = b0 & 0x1fff;
  27387. var bh0 = b0 >>> 13;
  27388. var b1 = b[1] | 0;
  27389. var bl1 = b1 & 0x1fff;
  27390. var bh1 = b1 >>> 13;
  27391. var b2 = b[2] | 0;
  27392. var bl2 = b2 & 0x1fff;
  27393. var bh2 = b2 >>> 13;
  27394. var b3 = b[3] | 0;
  27395. var bl3 = b3 & 0x1fff;
  27396. var bh3 = b3 >>> 13;
  27397. var b4 = b[4] | 0;
  27398. var bl4 = b4 & 0x1fff;
  27399. var bh4 = b4 >>> 13;
  27400. var b5 = b[5] | 0;
  27401. var bl5 = b5 & 0x1fff;
  27402. var bh5 = b5 >>> 13;
  27403. var b6 = b[6] | 0;
  27404. var bl6 = b6 & 0x1fff;
  27405. var bh6 = b6 >>> 13;
  27406. var b7 = b[7] | 0;
  27407. var bl7 = b7 & 0x1fff;
  27408. var bh7 = b7 >>> 13;
  27409. var b8 = b[8] | 0;
  27410. var bl8 = b8 & 0x1fff;
  27411. var bh8 = b8 >>> 13;
  27412. var b9 = b[9] | 0;
  27413. var bl9 = b9 & 0x1fff;
  27414. var bh9 = b9 >>> 13;
  27415. out.negative = self.negative ^ num.negative;
  27416. out.length = 19;
  27417. /* k = 0 */
  27418. lo = Math.imul(al0, bl0);
  27419. mid = Math.imul(al0, bh0);
  27420. mid = mid + Math.imul(ah0, bl0) | 0;
  27421. hi = Math.imul(ah0, bh0);
  27422. var w0 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27423. c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0;
  27424. w0 &= 0x3ffffff;
  27425. /* k = 1 */
  27426. lo = Math.imul(al1, bl0);
  27427. mid = Math.imul(al1, bh0);
  27428. mid = mid + Math.imul(ah1, bl0) | 0;
  27429. hi = Math.imul(ah1, bh0);
  27430. lo = lo + Math.imul(al0, bl1) | 0;
  27431. mid = mid + Math.imul(al0, bh1) | 0;
  27432. mid = mid + Math.imul(ah0, bl1) | 0;
  27433. hi = hi + Math.imul(ah0, bh1) | 0;
  27434. var w1 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27435. c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0;
  27436. w1 &= 0x3ffffff;
  27437. /* k = 2 */
  27438. lo = Math.imul(al2, bl0);
  27439. mid = Math.imul(al2, bh0);
  27440. mid = mid + Math.imul(ah2, bl0) | 0;
  27441. hi = Math.imul(ah2, bh0);
  27442. lo = lo + Math.imul(al1, bl1) | 0;
  27443. mid = mid + Math.imul(al1, bh1) | 0;
  27444. mid = mid + Math.imul(ah1, bl1) | 0;
  27445. hi = hi + Math.imul(ah1, bh1) | 0;
  27446. lo = lo + Math.imul(al0, bl2) | 0;
  27447. mid = mid + Math.imul(al0, bh2) | 0;
  27448. mid = mid + Math.imul(ah0, bl2) | 0;
  27449. hi = hi + Math.imul(ah0, bh2) | 0;
  27450. var w2 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27451. c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0;
  27452. w2 &= 0x3ffffff;
  27453. /* k = 3 */
  27454. lo = Math.imul(al3, bl0);
  27455. mid = Math.imul(al3, bh0);
  27456. mid = mid + Math.imul(ah3, bl0) | 0;
  27457. hi = Math.imul(ah3, bh0);
  27458. lo = lo + Math.imul(al2, bl1) | 0;
  27459. mid = mid + Math.imul(al2, bh1) | 0;
  27460. mid = mid + Math.imul(ah2, bl1) | 0;
  27461. hi = hi + Math.imul(ah2, bh1) | 0;
  27462. lo = lo + Math.imul(al1, bl2) | 0;
  27463. mid = mid + Math.imul(al1, bh2) | 0;
  27464. mid = mid + Math.imul(ah1, bl2) | 0;
  27465. hi = hi + Math.imul(ah1, bh2) | 0;
  27466. lo = lo + Math.imul(al0, bl3) | 0;
  27467. mid = mid + Math.imul(al0, bh3) | 0;
  27468. mid = mid + Math.imul(ah0, bl3) | 0;
  27469. hi = hi + Math.imul(ah0, bh3) | 0;
  27470. var w3 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27471. c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0;
  27472. w3 &= 0x3ffffff;
  27473. /* k = 4 */
  27474. lo = Math.imul(al4, bl0);
  27475. mid = Math.imul(al4, bh0);
  27476. mid = mid + Math.imul(ah4, bl0) | 0;
  27477. hi = Math.imul(ah4, bh0);
  27478. lo = lo + Math.imul(al3, bl1) | 0;
  27479. mid = mid + Math.imul(al3, bh1) | 0;
  27480. mid = mid + Math.imul(ah3, bl1) | 0;
  27481. hi = hi + Math.imul(ah3, bh1) | 0;
  27482. lo = lo + Math.imul(al2, bl2) | 0;
  27483. mid = mid + Math.imul(al2, bh2) | 0;
  27484. mid = mid + Math.imul(ah2, bl2) | 0;
  27485. hi = hi + Math.imul(ah2, bh2) | 0;
  27486. lo = lo + Math.imul(al1, bl3) | 0;
  27487. mid = mid + Math.imul(al1, bh3) | 0;
  27488. mid = mid + Math.imul(ah1, bl3) | 0;
  27489. hi = hi + Math.imul(ah1, bh3) | 0;
  27490. lo = lo + Math.imul(al0, bl4) | 0;
  27491. mid = mid + Math.imul(al0, bh4) | 0;
  27492. mid = mid + Math.imul(ah0, bl4) | 0;
  27493. hi = hi + Math.imul(ah0, bh4) | 0;
  27494. var w4 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27495. c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0;
  27496. w4 &= 0x3ffffff;
  27497. /* k = 5 */
  27498. lo = Math.imul(al5, bl0);
  27499. mid = Math.imul(al5, bh0);
  27500. mid = mid + Math.imul(ah5, bl0) | 0;
  27501. hi = Math.imul(ah5, bh0);
  27502. lo = lo + Math.imul(al4, bl1) | 0;
  27503. mid = mid + Math.imul(al4, bh1) | 0;
  27504. mid = mid + Math.imul(ah4, bl1) | 0;
  27505. hi = hi + Math.imul(ah4, bh1) | 0;
  27506. lo = lo + Math.imul(al3, bl2) | 0;
  27507. mid = mid + Math.imul(al3, bh2) | 0;
  27508. mid = mid + Math.imul(ah3, bl2) | 0;
  27509. hi = hi + Math.imul(ah3, bh2) | 0;
  27510. lo = lo + Math.imul(al2, bl3) | 0;
  27511. mid = mid + Math.imul(al2, bh3) | 0;
  27512. mid = mid + Math.imul(ah2, bl3) | 0;
  27513. hi = hi + Math.imul(ah2, bh3) | 0;
  27514. lo = lo + Math.imul(al1, bl4) | 0;
  27515. mid = mid + Math.imul(al1, bh4) | 0;
  27516. mid = mid + Math.imul(ah1, bl4) | 0;
  27517. hi = hi + Math.imul(ah1, bh4) | 0;
  27518. lo = lo + Math.imul(al0, bl5) | 0;
  27519. mid = mid + Math.imul(al0, bh5) | 0;
  27520. mid = mid + Math.imul(ah0, bl5) | 0;
  27521. hi = hi + Math.imul(ah0, bh5) | 0;
  27522. var w5 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27523. c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0;
  27524. w5 &= 0x3ffffff;
  27525. /* k = 6 */
  27526. lo = Math.imul(al6, bl0);
  27527. mid = Math.imul(al6, bh0);
  27528. mid = mid + Math.imul(ah6, bl0) | 0;
  27529. hi = Math.imul(ah6, bh0);
  27530. lo = lo + Math.imul(al5, bl1) | 0;
  27531. mid = mid + Math.imul(al5, bh1) | 0;
  27532. mid = mid + Math.imul(ah5, bl1) | 0;
  27533. hi = hi + Math.imul(ah5, bh1) | 0;
  27534. lo = lo + Math.imul(al4, bl2) | 0;
  27535. mid = mid + Math.imul(al4, bh2) | 0;
  27536. mid = mid + Math.imul(ah4, bl2) | 0;
  27537. hi = hi + Math.imul(ah4, bh2) | 0;
  27538. lo = lo + Math.imul(al3, bl3) | 0;
  27539. mid = mid + Math.imul(al3, bh3) | 0;
  27540. mid = mid + Math.imul(ah3, bl3) | 0;
  27541. hi = hi + Math.imul(ah3, bh3) | 0;
  27542. lo = lo + Math.imul(al2, bl4) | 0;
  27543. mid = mid + Math.imul(al2, bh4) | 0;
  27544. mid = mid + Math.imul(ah2, bl4) | 0;
  27545. hi = hi + Math.imul(ah2, bh4) | 0;
  27546. lo = lo + Math.imul(al1, bl5) | 0;
  27547. mid = mid + Math.imul(al1, bh5) | 0;
  27548. mid = mid + Math.imul(ah1, bl5) | 0;
  27549. hi = hi + Math.imul(ah1, bh5) | 0;
  27550. lo = lo + Math.imul(al0, bl6) | 0;
  27551. mid = mid + Math.imul(al0, bh6) | 0;
  27552. mid = mid + Math.imul(ah0, bl6) | 0;
  27553. hi = hi + Math.imul(ah0, bh6) | 0;
  27554. var w6 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27555. c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0;
  27556. w6 &= 0x3ffffff;
  27557. /* k = 7 */
  27558. lo = Math.imul(al7, bl0);
  27559. mid = Math.imul(al7, bh0);
  27560. mid = mid + Math.imul(ah7, bl0) | 0;
  27561. hi = Math.imul(ah7, bh0);
  27562. lo = lo + Math.imul(al6, bl1) | 0;
  27563. mid = mid + Math.imul(al6, bh1) | 0;
  27564. mid = mid + Math.imul(ah6, bl1) | 0;
  27565. hi = hi + Math.imul(ah6, bh1) | 0;
  27566. lo = lo + Math.imul(al5, bl2) | 0;
  27567. mid = mid + Math.imul(al5, bh2) | 0;
  27568. mid = mid + Math.imul(ah5, bl2) | 0;
  27569. hi = hi + Math.imul(ah5, bh2) | 0;
  27570. lo = lo + Math.imul(al4, bl3) | 0;
  27571. mid = mid + Math.imul(al4, bh3) | 0;
  27572. mid = mid + Math.imul(ah4, bl3) | 0;
  27573. hi = hi + Math.imul(ah4, bh3) | 0;
  27574. lo = lo + Math.imul(al3, bl4) | 0;
  27575. mid = mid + Math.imul(al3, bh4) | 0;
  27576. mid = mid + Math.imul(ah3, bl4) | 0;
  27577. hi = hi + Math.imul(ah3, bh4) | 0;
  27578. lo = lo + Math.imul(al2, bl5) | 0;
  27579. mid = mid + Math.imul(al2, bh5) | 0;
  27580. mid = mid + Math.imul(ah2, bl5) | 0;
  27581. hi = hi + Math.imul(ah2, bh5) | 0;
  27582. lo = lo + Math.imul(al1, bl6) | 0;
  27583. mid = mid + Math.imul(al1, bh6) | 0;
  27584. mid = mid + Math.imul(ah1, bl6) | 0;
  27585. hi = hi + Math.imul(ah1, bh6) | 0;
  27586. lo = lo + Math.imul(al0, bl7) | 0;
  27587. mid = mid + Math.imul(al0, bh7) | 0;
  27588. mid = mid + Math.imul(ah0, bl7) | 0;
  27589. hi = hi + Math.imul(ah0, bh7) | 0;
  27590. var w7 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27591. c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0;
  27592. w7 &= 0x3ffffff;
  27593. /* k = 8 */
  27594. lo = Math.imul(al8, bl0);
  27595. mid = Math.imul(al8, bh0);
  27596. mid = mid + Math.imul(ah8, bl0) | 0;
  27597. hi = Math.imul(ah8, bh0);
  27598. lo = lo + Math.imul(al7, bl1) | 0;
  27599. mid = mid + Math.imul(al7, bh1) | 0;
  27600. mid = mid + Math.imul(ah7, bl1) | 0;
  27601. hi = hi + Math.imul(ah7, bh1) | 0;
  27602. lo = lo + Math.imul(al6, bl2) | 0;
  27603. mid = mid + Math.imul(al6, bh2) | 0;
  27604. mid = mid + Math.imul(ah6, bl2) | 0;
  27605. hi = hi + Math.imul(ah6, bh2) | 0;
  27606. lo = lo + Math.imul(al5, bl3) | 0;
  27607. mid = mid + Math.imul(al5, bh3) | 0;
  27608. mid = mid + Math.imul(ah5, bl3) | 0;
  27609. hi = hi + Math.imul(ah5, bh3) | 0;
  27610. lo = lo + Math.imul(al4, bl4) | 0;
  27611. mid = mid + Math.imul(al4, bh4) | 0;
  27612. mid = mid + Math.imul(ah4, bl4) | 0;
  27613. hi = hi + Math.imul(ah4, bh4) | 0;
  27614. lo = lo + Math.imul(al3, bl5) | 0;
  27615. mid = mid + Math.imul(al3, bh5) | 0;
  27616. mid = mid + Math.imul(ah3, bl5) | 0;
  27617. hi = hi + Math.imul(ah3, bh5) | 0;
  27618. lo = lo + Math.imul(al2, bl6) | 0;
  27619. mid = mid + Math.imul(al2, bh6) | 0;
  27620. mid = mid + Math.imul(ah2, bl6) | 0;
  27621. hi = hi + Math.imul(ah2, bh6) | 0;
  27622. lo = lo + Math.imul(al1, bl7) | 0;
  27623. mid = mid + Math.imul(al1, bh7) | 0;
  27624. mid = mid + Math.imul(ah1, bl7) | 0;
  27625. hi = hi + Math.imul(ah1, bh7) | 0;
  27626. lo = lo + Math.imul(al0, bl8) | 0;
  27627. mid = mid + Math.imul(al0, bh8) | 0;
  27628. mid = mid + Math.imul(ah0, bl8) | 0;
  27629. hi = hi + Math.imul(ah0, bh8) | 0;
  27630. var w8 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27631. c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0;
  27632. w8 &= 0x3ffffff;
  27633. /* k = 9 */
  27634. lo = Math.imul(al9, bl0);
  27635. mid = Math.imul(al9, bh0);
  27636. mid = mid + Math.imul(ah9, bl0) | 0;
  27637. hi = Math.imul(ah9, bh0);
  27638. lo = lo + Math.imul(al8, bl1) | 0;
  27639. mid = mid + Math.imul(al8, bh1) | 0;
  27640. mid = mid + Math.imul(ah8, bl1) | 0;
  27641. hi = hi + Math.imul(ah8, bh1) | 0;
  27642. lo = lo + Math.imul(al7, bl2) | 0;
  27643. mid = mid + Math.imul(al7, bh2) | 0;
  27644. mid = mid + Math.imul(ah7, bl2) | 0;
  27645. hi = hi + Math.imul(ah7, bh2) | 0;
  27646. lo = lo + Math.imul(al6, bl3) | 0;
  27647. mid = mid + Math.imul(al6, bh3) | 0;
  27648. mid = mid + Math.imul(ah6, bl3) | 0;
  27649. hi = hi + Math.imul(ah6, bh3) | 0;
  27650. lo = lo + Math.imul(al5, bl4) | 0;
  27651. mid = mid + Math.imul(al5, bh4) | 0;
  27652. mid = mid + Math.imul(ah5, bl4) | 0;
  27653. hi = hi + Math.imul(ah5, bh4) | 0;
  27654. lo = lo + Math.imul(al4, bl5) | 0;
  27655. mid = mid + Math.imul(al4, bh5) | 0;
  27656. mid = mid + Math.imul(ah4, bl5) | 0;
  27657. hi = hi + Math.imul(ah4, bh5) | 0;
  27658. lo = lo + Math.imul(al3, bl6) | 0;
  27659. mid = mid + Math.imul(al3, bh6) | 0;
  27660. mid = mid + Math.imul(ah3, bl6) | 0;
  27661. hi = hi + Math.imul(ah3, bh6) | 0;
  27662. lo = lo + Math.imul(al2, bl7) | 0;
  27663. mid = mid + Math.imul(al2, bh7) | 0;
  27664. mid = mid + Math.imul(ah2, bl7) | 0;
  27665. hi = hi + Math.imul(ah2, bh7) | 0;
  27666. lo = lo + Math.imul(al1, bl8) | 0;
  27667. mid = mid + Math.imul(al1, bh8) | 0;
  27668. mid = mid + Math.imul(ah1, bl8) | 0;
  27669. hi = hi + Math.imul(ah1, bh8) | 0;
  27670. lo = lo + Math.imul(al0, bl9) | 0;
  27671. mid = mid + Math.imul(al0, bh9) | 0;
  27672. mid = mid + Math.imul(ah0, bl9) | 0;
  27673. hi = hi + Math.imul(ah0, bh9) | 0;
  27674. var w9 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27675. c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0;
  27676. w9 &= 0x3ffffff;
  27677. /* k = 10 */
  27678. lo = Math.imul(al9, bl1);
  27679. mid = Math.imul(al9, bh1);
  27680. mid = mid + Math.imul(ah9, bl1) | 0;
  27681. hi = Math.imul(ah9, bh1);
  27682. lo = lo + Math.imul(al8, bl2) | 0;
  27683. mid = mid + Math.imul(al8, bh2) | 0;
  27684. mid = mid + Math.imul(ah8, bl2) | 0;
  27685. hi = hi + Math.imul(ah8, bh2) | 0;
  27686. lo = lo + Math.imul(al7, bl3) | 0;
  27687. mid = mid + Math.imul(al7, bh3) | 0;
  27688. mid = mid + Math.imul(ah7, bl3) | 0;
  27689. hi = hi + Math.imul(ah7, bh3) | 0;
  27690. lo = lo + Math.imul(al6, bl4) | 0;
  27691. mid = mid + Math.imul(al6, bh4) | 0;
  27692. mid = mid + Math.imul(ah6, bl4) | 0;
  27693. hi = hi + Math.imul(ah6, bh4) | 0;
  27694. lo = lo + Math.imul(al5, bl5) | 0;
  27695. mid = mid + Math.imul(al5, bh5) | 0;
  27696. mid = mid + Math.imul(ah5, bl5) | 0;
  27697. hi = hi + Math.imul(ah5, bh5) | 0;
  27698. lo = lo + Math.imul(al4, bl6) | 0;
  27699. mid = mid + Math.imul(al4, bh6) | 0;
  27700. mid = mid + Math.imul(ah4, bl6) | 0;
  27701. hi = hi + Math.imul(ah4, bh6) | 0;
  27702. lo = lo + Math.imul(al3, bl7) | 0;
  27703. mid = mid + Math.imul(al3, bh7) | 0;
  27704. mid = mid + Math.imul(ah3, bl7) | 0;
  27705. hi = hi + Math.imul(ah3, bh7) | 0;
  27706. lo = lo + Math.imul(al2, bl8) | 0;
  27707. mid = mid + Math.imul(al2, bh8) | 0;
  27708. mid = mid + Math.imul(ah2, bl8) | 0;
  27709. hi = hi + Math.imul(ah2, bh8) | 0;
  27710. lo = lo + Math.imul(al1, bl9) | 0;
  27711. mid = mid + Math.imul(al1, bh9) | 0;
  27712. mid = mid + Math.imul(ah1, bl9) | 0;
  27713. hi = hi + Math.imul(ah1, bh9) | 0;
  27714. var w10 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27715. c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0;
  27716. w10 &= 0x3ffffff;
  27717. /* k = 11 */
  27718. lo = Math.imul(al9, bl2);
  27719. mid = Math.imul(al9, bh2);
  27720. mid = mid + Math.imul(ah9, bl2) | 0;
  27721. hi = Math.imul(ah9, bh2);
  27722. lo = lo + Math.imul(al8, bl3) | 0;
  27723. mid = mid + Math.imul(al8, bh3) | 0;
  27724. mid = mid + Math.imul(ah8, bl3) | 0;
  27725. hi = hi + Math.imul(ah8, bh3) | 0;
  27726. lo = lo + Math.imul(al7, bl4) | 0;
  27727. mid = mid + Math.imul(al7, bh4) | 0;
  27728. mid = mid + Math.imul(ah7, bl4) | 0;
  27729. hi = hi + Math.imul(ah7, bh4) | 0;
  27730. lo = lo + Math.imul(al6, bl5) | 0;
  27731. mid = mid + Math.imul(al6, bh5) | 0;
  27732. mid = mid + Math.imul(ah6, bl5) | 0;
  27733. hi = hi + Math.imul(ah6, bh5) | 0;
  27734. lo = lo + Math.imul(al5, bl6) | 0;
  27735. mid = mid + Math.imul(al5, bh6) | 0;
  27736. mid = mid + Math.imul(ah5, bl6) | 0;
  27737. hi = hi + Math.imul(ah5, bh6) | 0;
  27738. lo = lo + Math.imul(al4, bl7) | 0;
  27739. mid = mid + Math.imul(al4, bh7) | 0;
  27740. mid = mid + Math.imul(ah4, bl7) | 0;
  27741. hi = hi + Math.imul(ah4, bh7) | 0;
  27742. lo = lo + Math.imul(al3, bl8) | 0;
  27743. mid = mid + Math.imul(al3, bh8) | 0;
  27744. mid = mid + Math.imul(ah3, bl8) | 0;
  27745. hi = hi + Math.imul(ah3, bh8) | 0;
  27746. lo = lo + Math.imul(al2, bl9) | 0;
  27747. mid = mid + Math.imul(al2, bh9) | 0;
  27748. mid = mid + Math.imul(ah2, bl9) | 0;
  27749. hi = hi + Math.imul(ah2, bh9) | 0;
  27750. var w11 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27751. c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0;
  27752. w11 &= 0x3ffffff;
  27753. /* k = 12 */
  27754. lo = Math.imul(al9, bl3);
  27755. mid = Math.imul(al9, bh3);
  27756. mid = mid + Math.imul(ah9, bl3) | 0;
  27757. hi = Math.imul(ah9, bh3);
  27758. lo = lo + Math.imul(al8, bl4) | 0;
  27759. mid = mid + Math.imul(al8, bh4) | 0;
  27760. mid = mid + Math.imul(ah8, bl4) | 0;
  27761. hi = hi + Math.imul(ah8, bh4) | 0;
  27762. lo = lo + Math.imul(al7, bl5) | 0;
  27763. mid = mid + Math.imul(al7, bh5) | 0;
  27764. mid = mid + Math.imul(ah7, bl5) | 0;
  27765. hi = hi + Math.imul(ah7, bh5) | 0;
  27766. lo = lo + Math.imul(al6, bl6) | 0;
  27767. mid = mid + Math.imul(al6, bh6) | 0;
  27768. mid = mid + Math.imul(ah6, bl6) | 0;
  27769. hi = hi + Math.imul(ah6, bh6) | 0;
  27770. lo = lo + Math.imul(al5, bl7) | 0;
  27771. mid = mid + Math.imul(al5, bh7) | 0;
  27772. mid = mid + Math.imul(ah5, bl7) | 0;
  27773. hi = hi + Math.imul(ah5, bh7) | 0;
  27774. lo = lo + Math.imul(al4, bl8) | 0;
  27775. mid = mid + Math.imul(al4, bh8) | 0;
  27776. mid = mid + Math.imul(ah4, bl8) | 0;
  27777. hi = hi + Math.imul(ah4, bh8) | 0;
  27778. lo = lo + Math.imul(al3, bl9) | 0;
  27779. mid = mid + Math.imul(al3, bh9) | 0;
  27780. mid = mid + Math.imul(ah3, bl9) | 0;
  27781. hi = hi + Math.imul(ah3, bh9) | 0;
  27782. var w12 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27783. c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0;
  27784. w12 &= 0x3ffffff;
  27785. /* k = 13 */
  27786. lo = Math.imul(al9, bl4);
  27787. mid = Math.imul(al9, bh4);
  27788. mid = mid + Math.imul(ah9, bl4) | 0;
  27789. hi = Math.imul(ah9, bh4);
  27790. lo = lo + Math.imul(al8, bl5) | 0;
  27791. mid = mid + Math.imul(al8, bh5) | 0;
  27792. mid = mid + Math.imul(ah8, bl5) | 0;
  27793. hi = hi + Math.imul(ah8, bh5) | 0;
  27794. lo = lo + Math.imul(al7, bl6) | 0;
  27795. mid = mid + Math.imul(al7, bh6) | 0;
  27796. mid = mid + Math.imul(ah7, bl6) | 0;
  27797. hi = hi + Math.imul(ah7, bh6) | 0;
  27798. lo = lo + Math.imul(al6, bl7) | 0;
  27799. mid = mid + Math.imul(al6, bh7) | 0;
  27800. mid = mid + Math.imul(ah6, bl7) | 0;
  27801. hi = hi + Math.imul(ah6, bh7) | 0;
  27802. lo = lo + Math.imul(al5, bl8) | 0;
  27803. mid = mid + Math.imul(al5, bh8) | 0;
  27804. mid = mid + Math.imul(ah5, bl8) | 0;
  27805. hi = hi + Math.imul(ah5, bh8) | 0;
  27806. lo = lo + Math.imul(al4, bl9) | 0;
  27807. mid = mid + Math.imul(al4, bh9) | 0;
  27808. mid = mid + Math.imul(ah4, bl9) | 0;
  27809. hi = hi + Math.imul(ah4, bh9) | 0;
  27810. var w13 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27811. c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0;
  27812. w13 &= 0x3ffffff;
  27813. /* k = 14 */
  27814. lo = Math.imul(al9, bl5);
  27815. mid = Math.imul(al9, bh5);
  27816. mid = mid + Math.imul(ah9, bl5) | 0;
  27817. hi = Math.imul(ah9, bh5);
  27818. lo = lo + Math.imul(al8, bl6) | 0;
  27819. mid = mid + Math.imul(al8, bh6) | 0;
  27820. mid = mid + Math.imul(ah8, bl6) | 0;
  27821. hi = hi + Math.imul(ah8, bh6) | 0;
  27822. lo = lo + Math.imul(al7, bl7) | 0;
  27823. mid = mid + Math.imul(al7, bh7) | 0;
  27824. mid = mid + Math.imul(ah7, bl7) | 0;
  27825. hi = hi + Math.imul(ah7, bh7) | 0;
  27826. lo = lo + Math.imul(al6, bl8) | 0;
  27827. mid = mid + Math.imul(al6, bh8) | 0;
  27828. mid = mid + Math.imul(ah6, bl8) | 0;
  27829. hi = hi + Math.imul(ah6, bh8) | 0;
  27830. lo = lo + Math.imul(al5, bl9) | 0;
  27831. mid = mid + Math.imul(al5, bh9) | 0;
  27832. mid = mid + Math.imul(ah5, bl9) | 0;
  27833. hi = hi + Math.imul(ah5, bh9) | 0;
  27834. var w14 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27835. c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0;
  27836. w14 &= 0x3ffffff;
  27837. /* k = 15 */
  27838. lo = Math.imul(al9, bl6);
  27839. mid = Math.imul(al9, bh6);
  27840. mid = mid + Math.imul(ah9, bl6) | 0;
  27841. hi = Math.imul(ah9, bh6);
  27842. lo = lo + Math.imul(al8, bl7) | 0;
  27843. mid = mid + Math.imul(al8, bh7) | 0;
  27844. mid = mid + Math.imul(ah8, bl7) | 0;
  27845. hi = hi + Math.imul(ah8, bh7) | 0;
  27846. lo = lo + Math.imul(al7, bl8) | 0;
  27847. mid = mid + Math.imul(al7, bh8) | 0;
  27848. mid = mid + Math.imul(ah7, bl8) | 0;
  27849. hi = hi + Math.imul(ah7, bh8) | 0;
  27850. lo = lo + Math.imul(al6, bl9) | 0;
  27851. mid = mid + Math.imul(al6, bh9) | 0;
  27852. mid = mid + Math.imul(ah6, bl9) | 0;
  27853. hi = hi + Math.imul(ah6, bh9) | 0;
  27854. var w15 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27855. c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0;
  27856. w15 &= 0x3ffffff;
  27857. /* k = 16 */
  27858. lo = Math.imul(al9, bl7);
  27859. mid = Math.imul(al9, bh7);
  27860. mid = mid + Math.imul(ah9, bl7) | 0;
  27861. hi = Math.imul(ah9, bh7);
  27862. lo = lo + Math.imul(al8, bl8) | 0;
  27863. mid = mid + Math.imul(al8, bh8) | 0;
  27864. mid = mid + Math.imul(ah8, bl8) | 0;
  27865. hi = hi + Math.imul(ah8, bh8) | 0;
  27866. lo = lo + Math.imul(al7, bl9) | 0;
  27867. mid = mid + Math.imul(al7, bh9) | 0;
  27868. mid = mid + Math.imul(ah7, bl9) | 0;
  27869. hi = hi + Math.imul(ah7, bh9) | 0;
  27870. var w16 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27871. c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0;
  27872. w16 &= 0x3ffffff;
  27873. /* k = 17 */
  27874. lo = Math.imul(al9, bl8);
  27875. mid = Math.imul(al9, bh8);
  27876. mid = mid + Math.imul(ah9, bl8) | 0;
  27877. hi = Math.imul(ah9, bh8);
  27878. lo = lo + Math.imul(al8, bl9) | 0;
  27879. mid = mid + Math.imul(al8, bh9) | 0;
  27880. mid = mid + Math.imul(ah8, bl9) | 0;
  27881. hi = hi + Math.imul(ah8, bh9) | 0;
  27882. var w17 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27883. c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0;
  27884. w17 &= 0x3ffffff;
  27885. /* k = 18 */
  27886. lo = Math.imul(al9, bl9);
  27887. mid = Math.imul(al9, bh9);
  27888. mid = mid + Math.imul(ah9, bl9) | 0;
  27889. hi = Math.imul(ah9, bh9);
  27890. var w18 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  27891. c = (hi + (mid >>> 13) | 0) + (w18 >>> 26) | 0;
  27892. w18 &= 0x3ffffff;
  27893. o[0] = w0;
  27894. o[1] = w1;
  27895. o[2] = w2;
  27896. o[3] = w3;
  27897. o[4] = w4;
  27898. o[5] = w5;
  27899. o[6] = w6;
  27900. o[7] = w7;
  27901. o[8] = w8;
  27902. o[9] = w9;
  27903. o[10] = w10;
  27904. o[11] = w11;
  27905. o[12] = w12;
  27906. o[13] = w13;
  27907. o[14] = w14;
  27908. o[15] = w15;
  27909. o[16] = w16;
  27910. o[17] = w17;
  27911. o[18] = w18;
  27912. if (c !== 0) {
  27913. o[19] = c;
  27914. out.length++;
  27915. }
  27916. return out;
  27917. }; // Polyfill comb
  27918. if (!Math.imul) {
  27919. comb10MulTo = smallMulTo;
  27920. }
  27921. function bigMulTo(self, num, out) {
  27922. out.negative = num.negative ^ self.negative;
  27923. out.length = self.length + num.length;
  27924. var carry = 0;
  27925. var hncarry = 0;
  27926. for (var k = 0; k < out.length - 1; k++) {
  27927. // Sum all words with the same `i + j = k` and accumulate `ncarry`,
  27928. // note that ncarry could be >= 0x3ffffff
  27929. var ncarry = hncarry;
  27930. hncarry = 0;
  27931. var rword = carry & 0x3ffffff;
  27932. var maxJ = Math.min(k, num.length - 1);
  27933. for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
  27934. var i = k - j;
  27935. var a = self.words[i] | 0;
  27936. var b = num.words[j] | 0;
  27937. var r = a * b;
  27938. var lo = r & 0x3ffffff;
  27939. ncarry = ncarry + (r / 0x4000000 | 0) | 0;
  27940. lo = lo + rword | 0;
  27941. rword = lo & 0x3ffffff;
  27942. ncarry = ncarry + (lo >>> 26) | 0;
  27943. hncarry += ncarry >>> 26;
  27944. ncarry &= 0x3ffffff;
  27945. }
  27946. out.words[k] = rword;
  27947. carry = ncarry;
  27948. ncarry = hncarry;
  27949. }
  27950. if (carry !== 0) {
  27951. out.words[k] = carry;
  27952. } else {
  27953. out.length--;
  27954. }
  27955. return out._strip();
  27956. }
  27957. function jumboMulTo(self, num, out) {
  27958. // Temporary disable, see https://github.com/indutny/bn.js/issues/211
  27959. // var fftm = new FFTM();
  27960. // return fftm.mulp(self, num, out);
  27961. return bigMulTo(self, num, out);
  27962. }
  27963. BN.prototype.mulTo = function mulTo(num, out) {
  27964. var res;
  27965. var len = this.length + num.length;
  27966. if (this.length === 10 && num.length === 10) {
  27967. res = comb10MulTo(this, num, out);
  27968. } else if (len < 63) {
  27969. res = smallMulTo(this, num, out);
  27970. } else if (len < 1024) {
  27971. res = bigMulTo(this, num, out);
  27972. } else {
  27973. res = jumboMulTo(this, num, out);
  27974. }
  27975. return res;
  27976. }; // Cooley-Tukey algorithm for FFT
  27977. // slightly revisited to rely on looping instead of recursion
  27978. function FFTM(x, y) {
  27979. this.x = x;
  27980. this.y = y;
  27981. }
  27982. FFTM.prototype.makeRBT = function makeRBT(N) {
  27983. var t = new Array(N);
  27984. var l = BN.prototype._countBits(N) - 1;
  27985. for (var i = 0; i < N; i++) {
  27986. t[i] = this.revBin(i, l, N);
  27987. }
  27988. return t;
  27989. }; // Returns binary-reversed representation of `x`
  27990. FFTM.prototype.revBin = function revBin(x, l, N) {
  27991. if (x === 0 || x === N - 1) return x;
  27992. var rb = 0;
  27993. for (var i = 0; i < l; i++) {
  27994. rb |= (x & 1) << l - i - 1;
  27995. x >>= 1;
  27996. }
  27997. return rb;
  27998. }; // Performs "tweedling" phase, therefore 'emulating'
  27999. // behaviour of the recursive algorithm
  28000. FFTM.prototype.permute = function permute(rbt, rws, iws, rtws, itws, N) {
  28001. for (var i = 0; i < N; i++) {
  28002. rtws[i] = rws[rbt[i]];
  28003. itws[i] = iws[rbt[i]];
  28004. }
  28005. };
  28006. FFTM.prototype.transform = function transform(rws, iws, rtws, itws, N, rbt) {
  28007. this.permute(rbt, rws, iws, rtws, itws, N);
  28008. for (var s = 1; s < N; s <<= 1) {
  28009. var l = s << 1;
  28010. var rtwdf = Math.cos(2 * Math.PI / l);
  28011. var itwdf = Math.sin(2 * Math.PI / l);
  28012. for (var p = 0; p < N; p += l) {
  28013. var rtwdf_ = rtwdf;
  28014. var itwdf_ = itwdf;
  28015. for (var j = 0; j < s; j++) {
  28016. var re = rtws[p + j];
  28017. var ie = itws[p + j];
  28018. var ro = rtws[p + j + s];
  28019. var io = itws[p + j + s];
  28020. var rx = rtwdf_ * ro - itwdf_ * io;
  28021. io = rtwdf_ * io + itwdf_ * ro;
  28022. ro = rx;
  28023. rtws[p + j] = re + ro;
  28024. itws[p + j] = ie + io;
  28025. rtws[p + j + s] = re - ro;
  28026. itws[p + j + s] = ie - io;
  28027. /* jshint maxdepth : false */
  28028. if (j !== l) {
  28029. rx = rtwdf * rtwdf_ - itwdf * itwdf_;
  28030. itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_;
  28031. rtwdf_ = rx;
  28032. }
  28033. }
  28034. }
  28035. }
  28036. };
  28037. FFTM.prototype.guessLen13b = function guessLen13b(n, m) {
  28038. var N = Math.max(m, n) | 1;
  28039. var odd = N & 1;
  28040. var i = 0;
  28041. for (N = N / 2 | 0; N; N = N >>> 1) {
  28042. i++;
  28043. }
  28044. return 1 << i + 1 + odd;
  28045. };
  28046. FFTM.prototype.conjugate = function conjugate(rws, iws, N) {
  28047. if (N <= 1) return;
  28048. for (var i = 0; i < N / 2; i++) {
  28049. var t = rws[i];
  28050. rws[i] = rws[N - i - 1];
  28051. rws[N - i - 1] = t;
  28052. t = iws[i];
  28053. iws[i] = -iws[N - i - 1];
  28054. iws[N - i - 1] = -t;
  28055. }
  28056. };
  28057. FFTM.prototype.normalize13b = function normalize13b(ws, N) {
  28058. var carry = 0;
  28059. for (var i = 0; i < N / 2; i++) {
  28060. var w = Math.round(ws[2 * i + 1] / N) * 0x2000 + Math.round(ws[2 * i] / N) + carry;
  28061. ws[i] = w & 0x3ffffff;
  28062. if (w < 0x4000000) {
  28063. carry = 0;
  28064. } else {
  28065. carry = w / 0x4000000 | 0;
  28066. }
  28067. }
  28068. return ws;
  28069. };
  28070. FFTM.prototype.convert13b = function convert13b(ws, len, rws, N) {
  28071. var carry = 0;
  28072. for (var i = 0; i < len; i++) {
  28073. carry = carry + (ws[i] | 0);
  28074. rws[2 * i] = carry & 0x1fff;
  28075. carry = carry >>> 13;
  28076. rws[2 * i + 1] = carry & 0x1fff;
  28077. carry = carry >>> 13;
  28078. } // Pad with zeroes
  28079. for (i = 2 * len; i < N; ++i) {
  28080. rws[i] = 0;
  28081. }
  28082. assert(carry === 0);
  28083. assert((carry & ~0x1fff) === 0);
  28084. };
  28085. FFTM.prototype.stub = function stub(N) {
  28086. var ph = new Array(N);
  28087. for (var i = 0; i < N; i++) {
  28088. ph[i] = 0;
  28089. }
  28090. return ph;
  28091. };
  28092. FFTM.prototype.mulp = function mulp(x, y, out) {
  28093. var N = 2 * this.guessLen13b(x.length, y.length);
  28094. var rbt = this.makeRBT(N);
  28095. var _ = this.stub(N);
  28096. var rws = new Array(N);
  28097. var rwst = new Array(N);
  28098. var iwst = new Array(N);
  28099. var nrws = new Array(N);
  28100. var nrwst = new Array(N);
  28101. var niwst = new Array(N);
  28102. var rmws = out.words;
  28103. rmws.length = N;
  28104. this.convert13b(x.words, x.length, rws, N);
  28105. this.convert13b(y.words, y.length, nrws, N);
  28106. this.transform(rws, _, rwst, iwst, N, rbt);
  28107. this.transform(nrws, _, nrwst, niwst, N, rbt);
  28108. for (var i = 0; i < N; i++) {
  28109. var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
  28110. iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i];
  28111. rwst[i] = rx;
  28112. }
  28113. this.conjugate(rwst, iwst, N);
  28114. this.transform(rwst, iwst, rmws, _, N, rbt);
  28115. this.conjugate(rmws, _, N);
  28116. this.normalize13b(rmws, N);
  28117. out.negative = x.negative ^ y.negative;
  28118. out.length = x.length + y.length;
  28119. return out._strip();
  28120. }; // Multiply `this` by `num`
  28121. BN.prototype.mul = function mul(num) {
  28122. var out = new BN(null);
  28123. out.words = new Array(this.length + num.length);
  28124. return this.mulTo(num, out);
  28125. }; // Multiply employing FFT
  28126. BN.prototype.mulf = function mulf(num) {
  28127. var out = new BN(null);
  28128. out.words = new Array(this.length + num.length);
  28129. return jumboMulTo(this, num, out);
  28130. }; // In-place Multiplication
  28131. BN.prototype.imul = function imul(num) {
  28132. return this.clone().mulTo(num, this);
  28133. };
  28134. BN.prototype.imuln = function imuln(num) {
  28135. var isNegNum = num < 0;
  28136. if (isNegNum) num = -num;
  28137. assert(typeof num === 'number');
  28138. assert(num < 0x4000000); // Carry
  28139. var carry = 0;
  28140. for (var i = 0; i < this.length; i++) {
  28141. var w = (this.words[i] | 0) * num;
  28142. var lo = (w & 0x3ffffff) + (carry & 0x3ffffff);
  28143. carry >>= 26;
  28144. carry += w / 0x4000000 | 0; // NOTE: lo is 27bit maximum
  28145. carry += lo >>> 26;
  28146. this.words[i] = lo & 0x3ffffff;
  28147. }
  28148. if (carry !== 0) {
  28149. this.words[i] = carry;
  28150. this.length++;
  28151. }
  28152. return isNegNum ? this.ineg() : this;
  28153. };
  28154. BN.prototype.muln = function muln(num) {
  28155. return this.clone().imuln(num);
  28156. }; // `this` * `this`
  28157. BN.prototype.sqr = function sqr() {
  28158. return this.mul(this);
  28159. }; // `this` * `this` in-place
  28160. BN.prototype.isqr = function isqr() {
  28161. return this.imul(this.clone());
  28162. }; // Math.pow(`this`, `num`)
  28163. BN.prototype.pow = function pow(num) {
  28164. var w = toBitArray(num);
  28165. if (w.length === 0) return new BN(1); // Skip leading zeroes
  28166. var res = this;
  28167. for (var i = 0; i < w.length; i++, res = res.sqr()) {
  28168. if (w[i] !== 0) break;
  28169. }
  28170. if (++i < w.length) {
  28171. for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) {
  28172. if (w[i] === 0) continue;
  28173. res = res.mul(q);
  28174. }
  28175. }
  28176. return res;
  28177. }; // Shift-left in-place
  28178. BN.prototype.iushln = function iushln(bits) {
  28179. assert(typeof bits === 'number' && bits >= 0);
  28180. var r = bits % 26;
  28181. var s = (bits - r) / 26;
  28182. var carryMask = 0x3ffffff >>> 26 - r << 26 - r;
  28183. var i;
  28184. if (r !== 0) {
  28185. var carry = 0;
  28186. for (i = 0; i < this.length; i++) {
  28187. var newCarry = this.words[i] & carryMask;
  28188. var c = (this.words[i] | 0) - newCarry << r;
  28189. this.words[i] = c | carry;
  28190. carry = newCarry >>> 26 - r;
  28191. }
  28192. if (carry) {
  28193. this.words[i] = carry;
  28194. this.length++;
  28195. }
  28196. }
  28197. if (s !== 0) {
  28198. for (i = this.length - 1; i >= 0; i--) {
  28199. this.words[i + s] = this.words[i];
  28200. }
  28201. for (i = 0; i < s; i++) {
  28202. this.words[i] = 0;
  28203. }
  28204. this.length += s;
  28205. }
  28206. return this._strip();
  28207. };
  28208. BN.prototype.ishln = function ishln(bits) {
  28209. // TODO(indutny): implement me
  28210. assert(this.negative === 0);
  28211. return this.iushln(bits);
  28212. }; // Shift-right in-place
  28213. // NOTE: `hint` is a lowest bit before trailing zeroes
  28214. // NOTE: if `extended` is present - it will be filled with destroyed bits
  28215. BN.prototype.iushrn = function iushrn(bits, hint, extended) {
  28216. assert(typeof bits === 'number' && bits >= 0);
  28217. var h;
  28218. if (hint) {
  28219. h = (hint - hint % 26) / 26;
  28220. } else {
  28221. h = 0;
  28222. }
  28223. var r = bits % 26;
  28224. var s = Math.min((bits - r) / 26, this.length);
  28225. var mask = 0x3ffffff ^ 0x3ffffff >>> r << r;
  28226. var maskedWords = extended;
  28227. h -= s;
  28228. h = Math.max(0, h); // Extended mode, copy masked part
  28229. if (maskedWords) {
  28230. for (var i = 0; i < s; i++) {
  28231. maskedWords.words[i] = this.words[i];
  28232. }
  28233. maskedWords.length = s;
  28234. }
  28235. if (s === 0) {// No-op, we should not move anything at all
  28236. } else if (this.length > s) {
  28237. this.length -= s;
  28238. for (i = 0; i < this.length; i++) {
  28239. this.words[i] = this.words[i + s];
  28240. }
  28241. } else {
  28242. this.words[0] = 0;
  28243. this.length = 1;
  28244. }
  28245. var carry = 0;
  28246. for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
  28247. var word = this.words[i] | 0;
  28248. this.words[i] = carry << 26 - r | word >>> r;
  28249. carry = word & mask;
  28250. } // Push carried bits as a mask
  28251. if (maskedWords && carry !== 0) {
  28252. maskedWords.words[maskedWords.length++] = carry;
  28253. }
  28254. if (this.length === 0) {
  28255. this.words[0] = 0;
  28256. this.length = 1;
  28257. }
  28258. return this._strip();
  28259. };
  28260. BN.prototype.ishrn = function ishrn(bits, hint, extended) {
  28261. // TODO(indutny): implement me
  28262. assert(this.negative === 0);
  28263. return this.iushrn(bits, hint, extended);
  28264. }; // Shift-left
  28265. BN.prototype.shln = function shln(bits) {
  28266. return this.clone().ishln(bits);
  28267. };
  28268. BN.prototype.ushln = function ushln(bits) {
  28269. return this.clone().iushln(bits);
  28270. }; // Shift-right
  28271. BN.prototype.shrn = function shrn(bits) {
  28272. return this.clone().ishrn(bits);
  28273. };
  28274. BN.prototype.ushrn = function ushrn(bits) {
  28275. return this.clone().iushrn(bits);
  28276. }; // Test if n bit is set
  28277. BN.prototype.testn = function testn(bit) {
  28278. assert(typeof bit === 'number' && bit >= 0);
  28279. var r = bit % 26;
  28280. var s = (bit - r) / 26;
  28281. var q = 1 << r; // Fast case: bit is much higher than all existing words
  28282. if (this.length <= s) return false; // Check bit and return
  28283. var w = this.words[s];
  28284. return !!(w & q);
  28285. }; // Return only lowers bits of number (in-place)
  28286. BN.prototype.imaskn = function imaskn(bits) {
  28287. assert(typeof bits === 'number' && bits >= 0);
  28288. var r = bits % 26;
  28289. var s = (bits - r) / 26;
  28290. assert(this.negative === 0, 'imaskn works only with positive numbers');
  28291. if (this.length <= s) {
  28292. return this;
  28293. }
  28294. if (r !== 0) {
  28295. s++;
  28296. }
  28297. this.length = Math.min(s, this.length);
  28298. if (r !== 0) {
  28299. var mask = 0x3ffffff ^ 0x3ffffff >>> r << r;
  28300. this.words[this.length - 1] &= mask;
  28301. }
  28302. return this._strip();
  28303. }; // Return only lowers bits of number
  28304. BN.prototype.maskn = function maskn(bits) {
  28305. return this.clone().imaskn(bits);
  28306. }; // Add plain number `num` to `this`
  28307. BN.prototype.iaddn = function iaddn(num) {
  28308. assert(typeof num === 'number');
  28309. assert(num < 0x4000000);
  28310. if (num < 0) return this.isubn(-num); // Possible sign change
  28311. if (this.negative !== 0) {
  28312. if (this.length === 1 && (this.words[0] | 0) <= num) {
  28313. this.words[0] = num - (this.words[0] | 0);
  28314. this.negative = 0;
  28315. return this;
  28316. }
  28317. this.negative = 0;
  28318. this.isubn(num);
  28319. this.negative = 1;
  28320. return this;
  28321. } // Add without checks
  28322. return this._iaddn(num);
  28323. };
  28324. BN.prototype._iaddn = function _iaddn(num) {
  28325. this.words[0] += num; // Carry
  28326. for (var i = 0; i < this.length && this.words[i] >= 0x4000000; i++) {
  28327. this.words[i] -= 0x4000000;
  28328. if (i === this.length - 1) {
  28329. this.words[i + 1] = 1;
  28330. } else {
  28331. this.words[i + 1]++;
  28332. }
  28333. }
  28334. this.length = Math.max(this.length, i + 1);
  28335. return this;
  28336. }; // Subtract plain number `num` from `this`
  28337. BN.prototype.isubn = function isubn(num) {
  28338. assert(typeof num === 'number');
  28339. assert(num < 0x4000000);
  28340. if (num < 0) return this.iaddn(-num);
  28341. if (this.negative !== 0) {
  28342. this.negative = 0;
  28343. this.iaddn(num);
  28344. this.negative = 1;
  28345. return this;
  28346. }
  28347. this.words[0] -= num;
  28348. if (this.length === 1 && this.words[0] < 0) {
  28349. this.words[0] = -this.words[0];
  28350. this.negative = 1;
  28351. } else {
  28352. // Carry
  28353. for (var i = 0; i < this.length && this.words[i] < 0; i++) {
  28354. this.words[i] += 0x4000000;
  28355. this.words[i + 1] -= 1;
  28356. }
  28357. }
  28358. return this._strip();
  28359. };
  28360. BN.prototype.addn = function addn(num) {
  28361. return this.clone().iaddn(num);
  28362. };
  28363. BN.prototype.subn = function subn(num) {
  28364. return this.clone().isubn(num);
  28365. };
  28366. BN.prototype.iabs = function iabs() {
  28367. this.negative = 0;
  28368. return this;
  28369. };
  28370. BN.prototype.abs = function abs() {
  28371. return this.clone().iabs();
  28372. };
  28373. BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) {
  28374. var len = num.length + shift;
  28375. var i;
  28376. this._expand(len);
  28377. var w;
  28378. var carry = 0;
  28379. for (i = 0; i < num.length; i++) {
  28380. w = (this.words[i + shift] | 0) + carry;
  28381. var right = (num.words[i] | 0) * mul;
  28382. w -= right & 0x3ffffff;
  28383. carry = (w >> 26) - (right / 0x4000000 | 0);
  28384. this.words[i + shift] = w & 0x3ffffff;
  28385. }
  28386. for (; i < this.length - shift; i++) {
  28387. w = (this.words[i + shift] | 0) + carry;
  28388. carry = w >> 26;
  28389. this.words[i + shift] = w & 0x3ffffff;
  28390. }
  28391. if (carry === 0) return this._strip(); // Subtraction overflow
  28392. assert(carry === -1);
  28393. carry = 0;
  28394. for (i = 0; i < this.length; i++) {
  28395. w = -(this.words[i] | 0) + carry;
  28396. carry = w >> 26;
  28397. this.words[i] = w & 0x3ffffff;
  28398. }
  28399. this.negative = 1;
  28400. return this._strip();
  28401. };
  28402. BN.prototype._wordDiv = function _wordDiv(num, mode) {
  28403. var shift = this.length - num.length;
  28404. var a = this.clone();
  28405. var b = num; // Normalize
  28406. var bhi = b.words[b.length - 1] | 0;
  28407. var bhiBits = this._countBits(bhi);
  28408. shift = 26 - bhiBits;
  28409. if (shift !== 0) {
  28410. b = b.ushln(shift);
  28411. a.iushln(shift);
  28412. bhi = b.words[b.length - 1] | 0;
  28413. } // Initialize quotient
  28414. var m = a.length - b.length;
  28415. var q;
  28416. if (mode !== 'mod') {
  28417. q = new BN(null);
  28418. q.length = m + 1;
  28419. q.words = new Array(q.length);
  28420. for (var i = 0; i < q.length; i++) {
  28421. q.words[i] = 0;
  28422. }
  28423. }
  28424. var diff = a.clone()._ishlnsubmul(b, 1, m);
  28425. if (diff.negative === 0) {
  28426. a = diff;
  28427. if (q) {
  28428. q.words[m] = 1;
  28429. }
  28430. }
  28431. for (var j = m - 1; j >= 0; j--) {
  28432. 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
  28433. // (0x7ffffff)
  28434. qj = Math.min(qj / bhi | 0, 0x3ffffff);
  28435. a._ishlnsubmul(b, qj, j);
  28436. while (a.negative !== 0) {
  28437. qj--;
  28438. a.negative = 0;
  28439. a._ishlnsubmul(b, 1, j);
  28440. if (!a.isZero()) {
  28441. a.negative ^= 1;
  28442. }
  28443. }
  28444. if (q) {
  28445. q.words[j] = qj;
  28446. }
  28447. }
  28448. if (q) {
  28449. q._strip();
  28450. }
  28451. a._strip(); // Denormalize
  28452. if (mode !== 'div' && shift !== 0) {
  28453. a.iushrn(shift);
  28454. }
  28455. return {
  28456. div: q || null,
  28457. mod: a
  28458. };
  28459. }; // NOTE: 1) `mode` can be set to `mod` to request mod only,
  28460. // to `div` to request div only, or be absent to
  28461. // request both div & mod
  28462. // 2) `positive` is true if unsigned mod is requested
  28463. BN.prototype.divmod = function divmod(num, mode, positive) {
  28464. assert(!num.isZero());
  28465. if (this.isZero()) {
  28466. return {
  28467. div: new BN(0),
  28468. mod: new BN(0)
  28469. };
  28470. }
  28471. var div, mod, res;
  28472. if (this.negative !== 0 && num.negative === 0) {
  28473. res = this.neg().divmod(num, mode);
  28474. if (mode !== 'mod') {
  28475. div = res.div.neg();
  28476. }
  28477. if (mode !== 'div') {
  28478. mod = res.mod.neg();
  28479. if (positive && mod.negative !== 0) {
  28480. mod.iadd(num);
  28481. }
  28482. }
  28483. return {
  28484. div: div,
  28485. mod: mod
  28486. };
  28487. }
  28488. if (this.negative === 0 && num.negative !== 0) {
  28489. res = this.divmod(num.neg(), mode);
  28490. if (mode !== 'mod') {
  28491. div = res.div.neg();
  28492. }
  28493. return {
  28494. div: div,
  28495. mod: res.mod
  28496. };
  28497. }
  28498. if ((this.negative & num.negative) !== 0) {
  28499. res = this.neg().divmod(num.neg(), mode);
  28500. if (mode !== 'div') {
  28501. mod = res.mod.neg();
  28502. if (positive && mod.negative !== 0) {
  28503. mod.isub(num);
  28504. }
  28505. }
  28506. return {
  28507. div: res.div,
  28508. mod: mod
  28509. };
  28510. } // Both numbers are positive at this point
  28511. // Strip both numbers to approximate shift value
  28512. if (num.length > this.length || this.cmp(num) < 0) {
  28513. return {
  28514. div: new BN(0),
  28515. mod: this
  28516. };
  28517. } // Very short reduction
  28518. if (num.length === 1) {
  28519. if (mode === 'div') {
  28520. return {
  28521. div: this.divn(num.words[0]),
  28522. mod: null
  28523. };
  28524. }
  28525. if (mode === 'mod') {
  28526. return {
  28527. div: null,
  28528. mod: new BN(this.modrn(num.words[0]))
  28529. };
  28530. }
  28531. return {
  28532. div: this.divn(num.words[0]),
  28533. mod: new BN(this.modrn(num.words[0]))
  28534. };
  28535. }
  28536. return this._wordDiv(num, mode);
  28537. }; // Find `this` / `num`
  28538. BN.prototype.div = function div(num) {
  28539. return this.divmod(num, 'div', false).div;
  28540. }; // Find `this` % `num`
  28541. BN.prototype.mod = function mod(num) {
  28542. return this.divmod(num, 'mod', false).mod;
  28543. };
  28544. BN.prototype.umod = function umod(num) {
  28545. return this.divmod(num, 'mod', true).mod;
  28546. }; // Find Round(`this` / `num`)
  28547. BN.prototype.divRound = function divRound(num) {
  28548. var dm = this.divmod(num); // Fast case - exact division
  28549. if (dm.mod.isZero()) return dm.div;
  28550. var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
  28551. var half = num.ushrn(1);
  28552. var r2 = num.andln(1);
  28553. var cmp = mod.cmp(half); // Round down
  28554. if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; // Round up
  28555. return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
  28556. };
  28557. BN.prototype.modrn = function modrn(num) {
  28558. var isNegNum = num < 0;
  28559. if (isNegNum) num = -num;
  28560. assert(num <= 0x3ffffff);
  28561. var p = (1 << 26) % num;
  28562. var acc = 0;
  28563. for (var i = this.length - 1; i >= 0; i--) {
  28564. acc = (p * acc + (this.words[i] | 0)) % num;
  28565. }
  28566. return isNegNum ? -acc : acc;
  28567. }; // WARNING: DEPRECATED
  28568. BN.prototype.modn = function modn(num) {
  28569. return this.modrn(num);
  28570. }; // In-place division by number
  28571. BN.prototype.idivn = function idivn(num) {
  28572. var isNegNum = num < 0;
  28573. if (isNegNum) num = -num;
  28574. assert(num <= 0x3ffffff);
  28575. var carry = 0;
  28576. for (var i = this.length - 1; i >= 0; i--) {
  28577. var w = (this.words[i] | 0) + carry * 0x4000000;
  28578. this.words[i] = w / num | 0;
  28579. carry = w % num;
  28580. }
  28581. this._strip();
  28582. return isNegNum ? this.ineg() : this;
  28583. };
  28584. BN.prototype.divn = function divn(num) {
  28585. return this.clone().idivn(num);
  28586. };
  28587. BN.prototype.egcd = function egcd(p) {
  28588. assert(p.negative === 0);
  28589. assert(!p.isZero());
  28590. var x = this;
  28591. var y = p.clone();
  28592. if (x.negative !== 0) {
  28593. x = x.umod(p);
  28594. } else {
  28595. x = x.clone();
  28596. } // A * x + B * y = x
  28597. var A = new BN(1);
  28598. var B = new BN(0); // C * x + D * y = y
  28599. var C = new BN(0);
  28600. var D = new BN(1);
  28601. var g = 0;
  28602. while (x.isEven() && y.isEven()) {
  28603. x.iushrn(1);
  28604. y.iushrn(1);
  28605. ++g;
  28606. }
  28607. var yp = y.clone();
  28608. var xp = x.clone();
  28609. while (!x.isZero()) {
  28610. for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1) {
  28611. ;
  28612. }
  28613. if (i > 0) {
  28614. x.iushrn(i);
  28615. while (i-- > 0) {
  28616. if (A.isOdd() || B.isOdd()) {
  28617. A.iadd(yp);
  28618. B.isub(xp);
  28619. }
  28620. A.iushrn(1);
  28621. B.iushrn(1);
  28622. }
  28623. }
  28624. for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1) {
  28625. ;
  28626. }
  28627. if (j > 0) {
  28628. y.iushrn(j);
  28629. while (j-- > 0) {
  28630. if (C.isOdd() || D.isOdd()) {
  28631. C.iadd(yp);
  28632. D.isub(xp);
  28633. }
  28634. C.iushrn(1);
  28635. D.iushrn(1);
  28636. }
  28637. }
  28638. if (x.cmp(y) >= 0) {
  28639. x.isub(y);
  28640. A.isub(C);
  28641. B.isub(D);
  28642. } else {
  28643. y.isub(x);
  28644. C.isub(A);
  28645. D.isub(B);
  28646. }
  28647. }
  28648. return {
  28649. a: C,
  28650. b: D,
  28651. gcd: y.iushln(g)
  28652. };
  28653. }; // This is reduced incarnation of the binary EEA
  28654. // above, designated to invert members of the
  28655. // _prime_ fields F(p) at a maximal speed
  28656. BN.prototype._invmp = function _invmp(p) {
  28657. assert(p.negative === 0);
  28658. assert(!p.isZero());
  28659. var a = this;
  28660. var b = p.clone();
  28661. if (a.negative !== 0) {
  28662. a = a.umod(p);
  28663. } else {
  28664. a = a.clone();
  28665. }
  28666. var x1 = new BN(1);
  28667. var x2 = new BN(0);
  28668. var delta = b.clone();
  28669. while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
  28670. for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1) {
  28671. ;
  28672. }
  28673. if (i > 0) {
  28674. a.iushrn(i);
  28675. while (i-- > 0) {
  28676. if (x1.isOdd()) {
  28677. x1.iadd(delta);
  28678. }
  28679. x1.iushrn(1);
  28680. }
  28681. }
  28682. for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1) {
  28683. ;
  28684. }
  28685. if (j > 0) {
  28686. b.iushrn(j);
  28687. while (j-- > 0) {
  28688. if (x2.isOdd()) {
  28689. x2.iadd(delta);
  28690. }
  28691. x2.iushrn(1);
  28692. }
  28693. }
  28694. if (a.cmp(b) >= 0) {
  28695. a.isub(b);
  28696. x1.isub(x2);
  28697. } else {
  28698. b.isub(a);
  28699. x2.isub(x1);
  28700. }
  28701. }
  28702. var res;
  28703. if (a.cmpn(1) === 0) {
  28704. res = x1;
  28705. } else {
  28706. res = x2;
  28707. }
  28708. if (res.cmpn(0) < 0) {
  28709. res.iadd(p);
  28710. }
  28711. return res;
  28712. };
  28713. BN.prototype.gcd = function gcd(num) {
  28714. if (this.isZero()) return num.abs();
  28715. if (num.isZero()) return this.abs();
  28716. var a = this.clone();
  28717. var b = num.clone();
  28718. a.negative = 0;
  28719. b.negative = 0; // Remove common factor of two
  28720. for (var shift = 0; a.isEven() && b.isEven(); shift++) {
  28721. a.iushrn(1);
  28722. b.iushrn(1);
  28723. }
  28724. do {
  28725. while (a.isEven()) {
  28726. a.iushrn(1);
  28727. }
  28728. while (b.isEven()) {
  28729. b.iushrn(1);
  28730. }
  28731. var r = a.cmp(b);
  28732. if (r < 0) {
  28733. // Swap `a` and `b` to make `a` always bigger than `b`
  28734. var t = a;
  28735. a = b;
  28736. b = t;
  28737. } else if (r === 0 || b.cmpn(1) === 0) {
  28738. break;
  28739. }
  28740. a.isub(b);
  28741. } while (true);
  28742. return b.iushln(shift);
  28743. }; // Invert number in the field F(num)
  28744. BN.prototype.invm = function invm(num) {
  28745. return this.egcd(num).a.umod(num);
  28746. };
  28747. BN.prototype.isEven = function isEven() {
  28748. return (this.words[0] & 1) === 0;
  28749. };
  28750. BN.prototype.isOdd = function isOdd() {
  28751. return (this.words[0] & 1) === 1;
  28752. }; // And first word and num
  28753. BN.prototype.andln = function andln(num) {
  28754. return this.words[0] & num;
  28755. }; // Increment at the bit position in-line
  28756. BN.prototype.bincn = function bincn(bit) {
  28757. assert(typeof bit === 'number');
  28758. var r = bit % 26;
  28759. var s = (bit - r) / 26;
  28760. var q = 1 << r; // Fast case: bit is much higher than all existing words
  28761. if (this.length <= s) {
  28762. this._expand(s + 1);
  28763. this.words[s] |= q;
  28764. return this;
  28765. } // Add bit and propagate, if needed
  28766. var carry = q;
  28767. for (var i = s; carry !== 0 && i < this.length; i++) {
  28768. var w = this.words[i] | 0;
  28769. w += carry;
  28770. carry = w >>> 26;
  28771. w &= 0x3ffffff;
  28772. this.words[i] = w;
  28773. }
  28774. if (carry !== 0) {
  28775. this.words[i] = carry;
  28776. this.length++;
  28777. }
  28778. return this;
  28779. };
  28780. BN.prototype.isZero = function isZero() {
  28781. return this.length === 1 && this.words[0] === 0;
  28782. };
  28783. BN.prototype.cmpn = function cmpn(num) {
  28784. var negative = num < 0;
  28785. if (this.negative !== 0 && !negative) return -1;
  28786. if (this.negative === 0 && negative) return 1;
  28787. this._strip();
  28788. var res;
  28789. if (this.length > 1) {
  28790. res = 1;
  28791. } else {
  28792. if (negative) {
  28793. num = -num;
  28794. }
  28795. assert(num <= 0x3ffffff, 'Number is too big');
  28796. var w = this.words[0] | 0;
  28797. res = w === num ? 0 : w < num ? -1 : 1;
  28798. }
  28799. if (this.negative !== 0) return -res | 0;
  28800. return res;
  28801. }; // Compare two numbers and return:
  28802. // 1 - if `this` > `num`
  28803. // 0 - if `this` == `num`
  28804. // -1 - if `this` < `num`
  28805. BN.prototype.cmp = function cmp(num) {
  28806. if (this.negative !== 0 && num.negative === 0) return -1;
  28807. if (this.negative === 0 && num.negative !== 0) return 1;
  28808. var res = this.ucmp(num);
  28809. if (this.negative !== 0) return -res | 0;
  28810. return res;
  28811. }; // Unsigned comparison
  28812. BN.prototype.ucmp = function ucmp(num) {
  28813. // At this point both numbers have the same sign
  28814. if (this.length > num.length) return 1;
  28815. if (this.length < num.length) return -1;
  28816. var res = 0;
  28817. for (var i = this.length - 1; i >= 0; i--) {
  28818. var a = this.words[i] | 0;
  28819. var b = num.words[i] | 0;
  28820. if (a === b) continue;
  28821. if (a < b) {
  28822. res = -1;
  28823. } else if (a > b) {
  28824. res = 1;
  28825. }
  28826. break;
  28827. }
  28828. return res;
  28829. };
  28830. BN.prototype.gtn = function gtn(num) {
  28831. return this.cmpn(num) === 1;
  28832. };
  28833. BN.prototype.gt = function gt(num) {
  28834. return this.cmp(num) === 1;
  28835. };
  28836. BN.prototype.gten = function gten(num) {
  28837. return this.cmpn(num) >= 0;
  28838. };
  28839. BN.prototype.gte = function gte(num) {
  28840. return this.cmp(num) >= 0;
  28841. };
  28842. BN.prototype.ltn = function ltn(num) {
  28843. return this.cmpn(num) === -1;
  28844. };
  28845. BN.prototype.lt = function lt(num) {
  28846. return this.cmp(num) === -1;
  28847. };
  28848. BN.prototype.lten = function lten(num) {
  28849. return this.cmpn(num) <= 0;
  28850. };
  28851. BN.prototype.lte = function lte(num) {
  28852. return this.cmp(num) <= 0;
  28853. };
  28854. BN.prototype.eqn = function eqn(num) {
  28855. return this.cmpn(num) === 0;
  28856. };
  28857. BN.prototype.eq = function eq(num) {
  28858. return this.cmp(num) === 0;
  28859. }; //
  28860. // A reduce context, could be using montgomery or something better, depending
  28861. // on the `m` itself.
  28862. //
  28863. BN.red = function red(num) {
  28864. return new Red(num);
  28865. };
  28866. BN.prototype.toRed = function toRed(ctx) {
  28867. assert(!this.red, 'Already a number in reduction context');
  28868. assert(this.negative === 0, 'red works only with positives');
  28869. return ctx.convertTo(this)._forceRed(ctx);
  28870. };
  28871. BN.prototype.fromRed = function fromRed() {
  28872. assert(this.red, 'fromRed works only with numbers in reduction context');
  28873. return this.red.convertFrom(this);
  28874. };
  28875. BN.prototype._forceRed = function _forceRed(ctx) {
  28876. this.red = ctx;
  28877. return this;
  28878. };
  28879. BN.prototype.forceRed = function forceRed(ctx) {
  28880. assert(!this.red, 'Already a number in reduction context');
  28881. return this._forceRed(ctx);
  28882. };
  28883. BN.prototype.redAdd = function redAdd(num) {
  28884. assert(this.red, 'redAdd works only with red numbers');
  28885. return this.red.add(this, num);
  28886. };
  28887. BN.prototype.redIAdd = function redIAdd(num) {
  28888. assert(this.red, 'redIAdd works only with red numbers');
  28889. return this.red.iadd(this, num);
  28890. };
  28891. BN.prototype.redSub = function redSub(num) {
  28892. assert(this.red, 'redSub works only with red numbers');
  28893. return this.red.sub(this, num);
  28894. };
  28895. BN.prototype.redISub = function redISub(num) {
  28896. assert(this.red, 'redISub works only with red numbers');
  28897. return this.red.isub(this, num);
  28898. };
  28899. BN.prototype.redShl = function redShl(num) {
  28900. assert(this.red, 'redShl works only with red numbers');
  28901. return this.red.shl(this, num);
  28902. };
  28903. BN.prototype.redMul = function redMul(num) {
  28904. assert(this.red, 'redMul works only with red numbers');
  28905. this.red._verify2(this, num);
  28906. return this.red.mul(this, num);
  28907. };
  28908. BN.prototype.redIMul = function redIMul(num) {
  28909. assert(this.red, 'redMul works only with red numbers');
  28910. this.red._verify2(this, num);
  28911. return this.red.imul(this, num);
  28912. };
  28913. BN.prototype.redSqr = function redSqr() {
  28914. assert(this.red, 'redSqr works only with red numbers');
  28915. this.red._verify1(this);
  28916. return this.red.sqr(this);
  28917. };
  28918. BN.prototype.redISqr = function redISqr() {
  28919. assert(this.red, 'redISqr works only with red numbers');
  28920. this.red._verify1(this);
  28921. return this.red.isqr(this);
  28922. }; // Square root over p
  28923. BN.prototype.redSqrt = function redSqrt() {
  28924. assert(this.red, 'redSqrt works only with red numbers');
  28925. this.red._verify1(this);
  28926. return this.red.sqrt(this);
  28927. };
  28928. BN.prototype.redInvm = function redInvm() {
  28929. assert(this.red, 'redInvm works only with red numbers');
  28930. this.red._verify1(this);
  28931. return this.red.invm(this);
  28932. }; // Return negative clone of `this` % `red modulo`
  28933. BN.prototype.redNeg = function redNeg() {
  28934. assert(this.red, 'redNeg works only with red numbers');
  28935. this.red._verify1(this);
  28936. return this.red.neg(this);
  28937. };
  28938. BN.prototype.redPow = function redPow(num) {
  28939. assert(this.red && !num.red, 'redPow(normalNum)');
  28940. this.red._verify1(this);
  28941. return this.red.pow(this, num);
  28942. }; // Prime numbers with efficient reduction
  28943. var primes = {
  28944. k256: null,
  28945. p224: null,
  28946. p192: null,
  28947. p25519: null
  28948. }; // Pseudo-Mersenne prime
  28949. function MPrime(name, p) {
  28950. // P = 2 ^ N - K
  28951. this.name = name;
  28952. this.p = new BN(p, 16);
  28953. this.n = this.p.bitLength();
  28954. this.k = new BN(1).iushln(this.n).isub(this.p);
  28955. this.tmp = this._tmp();
  28956. }
  28957. MPrime.prototype._tmp = function _tmp() {
  28958. var tmp = new BN(null);
  28959. tmp.words = new Array(Math.ceil(this.n / 13));
  28960. return tmp;
  28961. };
  28962. MPrime.prototype.ireduce = function ireduce(num) {
  28963. // Assumes that `num` is less than `P^2`
  28964. // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P)
  28965. var r = num;
  28966. var rlen;
  28967. do {
  28968. this.split(r, this.tmp);
  28969. r = this.imulK(r);
  28970. r = r.iadd(this.tmp);
  28971. rlen = r.bitLength();
  28972. } while (rlen > this.n);
  28973. var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
  28974. if (cmp === 0) {
  28975. r.words[0] = 0;
  28976. r.length = 1;
  28977. } else if (cmp > 0) {
  28978. r.isub(this.p);
  28979. } else {
  28980. if (r.strip !== undefined) {
  28981. // r is a BN v4 instance
  28982. r.strip();
  28983. } else {
  28984. // r is a BN v5 instance
  28985. r._strip();
  28986. }
  28987. }
  28988. return r;
  28989. };
  28990. MPrime.prototype.split = function split(input, out) {
  28991. input.iushrn(this.n, 0, out);
  28992. };
  28993. MPrime.prototype.imulK = function imulK(num) {
  28994. return num.imul(this.k);
  28995. };
  28996. function K256() {
  28997. MPrime.call(this, 'k256', 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f');
  28998. }
  28999. inherits(K256, MPrime);
  29000. K256.prototype.split = function split(input, output) {
  29001. // 256 = 9 * 26 + 22
  29002. var mask = 0x3fffff;
  29003. var outLen = Math.min(input.length, 9);
  29004. for (var i = 0; i < outLen; i++) {
  29005. output.words[i] = input.words[i];
  29006. }
  29007. output.length = outLen;
  29008. if (input.length <= 9) {
  29009. input.words[0] = 0;
  29010. input.length = 1;
  29011. return;
  29012. } // Shift by 9 limbs
  29013. var prev = input.words[9];
  29014. output.words[output.length++] = prev & mask;
  29015. for (i = 10; i < input.length; i++) {
  29016. var next = input.words[i] | 0;
  29017. input.words[i - 10] = (next & mask) << 4 | prev >>> 22;
  29018. prev = next;
  29019. }
  29020. prev >>>= 22;
  29021. input.words[i - 10] = prev;
  29022. if (prev === 0 && input.length > 10) {
  29023. input.length -= 10;
  29024. } else {
  29025. input.length -= 9;
  29026. }
  29027. };
  29028. K256.prototype.imulK = function imulK(num) {
  29029. // K = 0x1000003d1 = [ 0x40, 0x3d1 ]
  29030. num.words[num.length] = 0;
  29031. num.words[num.length + 1] = 0;
  29032. num.length += 2; // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390
  29033. var lo = 0;
  29034. for (var i = 0; i < num.length; i++) {
  29035. var w = num.words[i] | 0;
  29036. lo += w * 0x3d1;
  29037. num.words[i] = lo & 0x3ffffff;
  29038. lo = w * 0x40 + (lo / 0x4000000 | 0);
  29039. } // Fast length reduction
  29040. if (num.words[num.length - 1] === 0) {
  29041. num.length--;
  29042. if (num.words[num.length - 1] === 0) {
  29043. num.length--;
  29044. }
  29045. }
  29046. return num;
  29047. };
  29048. function P224() {
  29049. MPrime.call(this, 'p224', 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001');
  29050. }
  29051. inherits(P224, MPrime);
  29052. function P192() {
  29053. MPrime.call(this, 'p192', 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff');
  29054. }
  29055. inherits(P192, MPrime);
  29056. function P25519() {
  29057. // 2 ^ 255 - 19
  29058. MPrime.call(this, '25519', '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed');
  29059. }
  29060. inherits(P25519, MPrime);
  29061. P25519.prototype.imulK = function imulK(num) {
  29062. // K = 0x13
  29063. var carry = 0;
  29064. for (var i = 0; i < num.length; i++) {
  29065. var hi = (num.words[i] | 0) * 0x13 + carry;
  29066. var lo = hi & 0x3ffffff;
  29067. hi >>>= 26;
  29068. num.words[i] = lo;
  29069. carry = hi;
  29070. }
  29071. if (carry !== 0) {
  29072. num.words[num.length++] = carry;
  29073. }
  29074. return num;
  29075. }; // Exported mostly for testing purposes, use plain name instead
  29076. BN._prime = function prime(name) {
  29077. // Cached version of prime
  29078. if (primes[name]) return primes[name];
  29079. var prime;
  29080. if (name === 'k256') {
  29081. prime = new K256();
  29082. } else if (name === 'p224') {
  29083. prime = new P224();
  29084. } else if (name === 'p192') {
  29085. prime = new P192();
  29086. } else if (name === 'p25519') {
  29087. prime = new P25519();
  29088. } else {
  29089. throw new Error('Unknown prime ' + name);
  29090. }
  29091. primes[name] = prime;
  29092. return prime;
  29093. }; //
  29094. // Base reduction engine
  29095. //
  29096. function Red(m) {
  29097. if (typeof m === 'string') {
  29098. var prime = BN._prime(m);
  29099. this.m = prime.p;
  29100. this.prime = prime;
  29101. } else {
  29102. assert(m.gtn(1), 'modulus must be greater than 1');
  29103. this.m = m;
  29104. this.prime = null;
  29105. }
  29106. }
  29107. Red.prototype._verify1 = function _verify1(a) {
  29108. assert(a.negative === 0, 'red works only with positives');
  29109. assert(a.red, 'red works only with red numbers');
  29110. };
  29111. Red.prototype._verify2 = function _verify2(a, b) {
  29112. assert((a.negative | b.negative) === 0, 'red works only with positives');
  29113. assert(a.red && a.red === b.red, 'red works only with red numbers');
  29114. };
  29115. Red.prototype.imod = function imod(a) {
  29116. if (this.prime) return this.prime.ireduce(a)._forceRed(this);
  29117. move(a, a.umod(this.m)._forceRed(this));
  29118. return a;
  29119. };
  29120. Red.prototype.neg = function neg(a) {
  29121. if (a.isZero()) {
  29122. return a.clone();
  29123. }
  29124. return this.m.sub(a)._forceRed(this);
  29125. };
  29126. Red.prototype.add = function add(a, b) {
  29127. this._verify2(a, b);
  29128. var res = a.add(b);
  29129. if (res.cmp(this.m) >= 0) {
  29130. res.isub(this.m);
  29131. }
  29132. return res._forceRed(this);
  29133. };
  29134. Red.prototype.iadd = function iadd(a, b) {
  29135. this._verify2(a, b);
  29136. var res = a.iadd(b);
  29137. if (res.cmp(this.m) >= 0) {
  29138. res.isub(this.m);
  29139. }
  29140. return res;
  29141. };
  29142. Red.prototype.sub = function sub(a, b) {
  29143. this._verify2(a, b);
  29144. var res = a.sub(b);
  29145. if (res.cmpn(0) < 0) {
  29146. res.iadd(this.m);
  29147. }
  29148. return res._forceRed(this);
  29149. };
  29150. Red.prototype.isub = function isub(a, b) {
  29151. this._verify2(a, b);
  29152. var res = a.isub(b);
  29153. if (res.cmpn(0) < 0) {
  29154. res.iadd(this.m);
  29155. }
  29156. return res;
  29157. };
  29158. Red.prototype.shl = function shl(a, num) {
  29159. this._verify1(a);
  29160. return this.imod(a.ushln(num));
  29161. };
  29162. Red.prototype.imul = function imul(a, b) {
  29163. this._verify2(a, b);
  29164. return this.imod(a.imul(b));
  29165. };
  29166. Red.prototype.mul = function mul(a, b) {
  29167. this._verify2(a, b);
  29168. return this.imod(a.mul(b));
  29169. };
  29170. Red.prototype.isqr = function isqr(a) {
  29171. return this.imul(a, a.clone());
  29172. };
  29173. Red.prototype.sqr = function sqr(a) {
  29174. return this.mul(a, a);
  29175. };
  29176. Red.prototype.sqrt = function sqrt(a) {
  29177. if (a.isZero()) return a.clone();
  29178. var mod3 = this.m.andln(3);
  29179. assert(mod3 % 2 === 1); // Fast case
  29180. if (mod3 === 3) {
  29181. var pow = this.m.add(new BN(1)).iushrn(2);
  29182. return this.pow(a, pow);
  29183. } // Tonelli-Shanks algorithm (Totally unoptimized and slow)
  29184. //
  29185. // Find Q and S, that Q * 2 ^ S = (P - 1)
  29186. var q = this.m.subn(1);
  29187. var s = 0;
  29188. while (!q.isZero() && q.andln(1) === 0) {
  29189. s++;
  29190. q.iushrn(1);
  29191. }
  29192. assert(!q.isZero());
  29193. var one = new BN(1).toRed(this);
  29194. var nOne = one.redNeg(); // Find quadratic non-residue
  29195. // NOTE: Max is such because of generalized Riemann hypothesis.
  29196. var lpow = this.m.subn(1).iushrn(1);
  29197. var z = this.m.bitLength();
  29198. z = new BN(2 * z * z).toRed(this);
  29199. while (this.pow(z, lpow).cmp(nOne) !== 0) {
  29200. z.redIAdd(nOne);
  29201. }
  29202. var c = this.pow(z, q);
  29203. var r = this.pow(a, q.addn(1).iushrn(1));
  29204. var t = this.pow(a, q);
  29205. var m = s;
  29206. while (t.cmp(one) !== 0) {
  29207. var tmp = t;
  29208. for (var i = 0; tmp.cmp(one) !== 0; i++) {
  29209. tmp = tmp.redSqr();
  29210. }
  29211. assert(i < m);
  29212. var b = this.pow(c, new BN(1).iushln(m - i - 1));
  29213. r = r.redMul(b);
  29214. c = b.redSqr();
  29215. t = t.redMul(c);
  29216. m = i;
  29217. }
  29218. return r;
  29219. };
  29220. Red.prototype.invm = function invm(a) {
  29221. var inv = a._invmp(this.m);
  29222. if (inv.negative !== 0) {
  29223. inv.negative = 0;
  29224. return this.imod(inv).redNeg();
  29225. } else {
  29226. return this.imod(inv);
  29227. }
  29228. };
  29229. Red.prototype.pow = function pow(a, num) {
  29230. if (num.isZero()) return new BN(1).toRed(this);
  29231. if (num.cmpn(1) === 0) return a.clone();
  29232. var windowSize = 4;
  29233. var wnd = new Array(1 << windowSize);
  29234. wnd[0] = new BN(1).toRed(this);
  29235. wnd[1] = a;
  29236. for (var i = 2; i < wnd.length; i++) {
  29237. wnd[i] = this.mul(wnd[i - 1], a);
  29238. }
  29239. var res = wnd[0];
  29240. var current = 0;
  29241. var currentLen = 0;
  29242. var start = num.bitLength() % 26;
  29243. if (start === 0) {
  29244. start = 26;
  29245. }
  29246. for (i = num.length - 1; i >= 0; i--) {
  29247. var word = num.words[i];
  29248. for (var j = start - 1; j >= 0; j--) {
  29249. var bit = word >> j & 1;
  29250. if (res !== wnd[0]) {
  29251. res = this.sqr(res);
  29252. }
  29253. if (bit === 0 && current === 0) {
  29254. currentLen = 0;
  29255. continue;
  29256. }
  29257. current <<= 1;
  29258. current |= bit;
  29259. currentLen++;
  29260. if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue;
  29261. res = this.mul(res, wnd[current]);
  29262. currentLen = 0;
  29263. current = 0;
  29264. }
  29265. start = 26;
  29266. }
  29267. return res;
  29268. };
  29269. Red.prototype.convertTo = function convertTo(num) {
  29270. var r = num.umod(this.m);
  29271. return r === num ? r.clone() : r;
  29272. };
  29273. Red.prototype.convertFrom = function convertFrom(num) {
  29274. var res = num.clone();
  29275. res.red = null;
  29276. return res;
  29277. }; //
  29278. // Montgomery method engine
  29279. //
  29280. BN.mont = function mont(num) {
  29281. return new Mont(num);
  29282. };
  29283. function Mont(m) {
  29284. Red.call(this, m);
  29285. this.shift = this.m.bitLength();
  29286. if (this.shift % 26 !== 0) {
  29287. this.shift += 26 - this.shift % 26;
  29288. }
  29289. this.r = new BN(1).iushln(this.shift);
  29290. this.r2 = this.imod(this.r.sqr());
  29291. this.rinv = this.r._invmp(this.m);
  29292. this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
  29293. this.minv = this.minv.umod(this.r);
  29294. this.minv = this.r.sub(this.minv);
  29295. }
  29296. inherits(Mont, Red);
  29297. Mont.prototype.convertTo = function convertTo(num) {
  29298. return this.imod(num.ushln(this.shift));
  29299. };
  29300. Mont.prototype.convertFrom = function convertFrom(num) {
  29301. var r = this.imod(num.mul(this.rinv));
  29302. r.red = null;
  29303. return r;
  29304. };
  29305. Mont.prototype.imul = function imul(a, b) {
  29306. if (a.isZero() || b.isZero()) {
  29307. a.words[0] = 0;
  29308. a.length = 1;
  29309. return a;
  29310. }
  29311. var t = a.imul(b);
  29312. var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
  29313. var u = t.isub(c).iushrn(this.shift);
  29314. var res = u;
  29315. if (u.cmp(this.m) >= 0) {
  29316. res = u.isub(this.m);
  29317. } else if (u.cmpn(0) < 0) {
  29318. res = u.iadd(this.m);
  29319. }
  29320. return res._forceRed(this);
  29321. };
  29322. Mont.prototype.mul = function mul(a, b) {
  29323. if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
  29324. var t = a.mul(b);
  29325. var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
  29326. var u = t.isub(c).iushrn(this.shift);
  29327. var res = u;
  29328. if (u.cmp(this.m) >= 0) {
  29329. res = u.isub(this.m);
  29330. } else if (u.cmpn(0) < 0) {
  29331. res = u.iadd(this.m);
  29332. }
  29333. return res._forceRed(this);
  29334. };
  29335. Mont.prototype.invm = function invm(a) {
  29336. // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R
  29337. var res = this.imod(a._invmp(this.m).mul(this.r2));
  29338. return res._forceRed(this);
  29339. };
  29340. })(typeof module === 'undefined' || module, void 0);
  29341. },{"buffer":185}],184:[function(require,module,exports){
  29342. "use strict";
  29343. 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); }
  29344. var r;
  29345. module.exports = function rand(len) {
  29346. if (!r) r = new Rand(null);
  29347. return r.generate(len);
  29348. };
  29349. function Rand(rand) {
  29350. this.rand = rand;
  29351. }
  29352. module.exports.Rand = Rand;
  29353. Rand.prototype.generate = function generate(len) {
  29354. return this._rand(len);
  29355. }; // Emulate crypto API using randy
  29356. Rand.prototype._rand = function _rand(n) {
  29357. if (this.rand.getBytes) return this.rand.getBytes(n);
  29358. var res = new Uint8Array(n);
  29359. for (var i = 0; i < res.length; i++) {
  29360. res[i] = this.rand.getByte();
  29361. }
  29362. return res;
  29363. };
  29364. if ((typeof self === "undefined" ? "undefined" : _typeof(self)) === 'object') {
  29365. if (self.crypto && self.crypto.getRandomValues) {
  29366. // Modern browsers
  29367. Rand.prototype._rand = function _rand(n) {
  29368. var arr = new Uint8Array(n);
  29369. self.crypto.getRandomValues(arr);
  29370. return arr;
  29371. };
  29372. } else if (self.msCrypto && self.msCrypto.getRandomValues) {
  29373. // IE
  29374. Rand.prototype._rand = function _rand(n) {
  29375. var arr = new Uint8Array(n);
  29376. self.msCrypto.getRandomValues(arr);
  29377. return arr;
  29378. }; // Safari's WebWorkers do not have `crypto`
  29379. } else if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object') {
  29380. // Old junk
  29381. Rand.prototype._rand = function () {
  29382. throw new Error('Not implemented yet');
  29383. };
  29384. }
  29385. } else {
  29386. // Node.js or Web worker with no crypto support
  29387. try {
  29388. var crypto = require('crypto');
  29389. if (typeof crypto.randomBytes !== 'function') throw new Error('Not supported');
  29390. Rand.prototype._rand = function _rand(n) {
  29391. return crypto.randomBytes(n);
  29392. };
  29393. } catch (e) {}
  29394. }
  29395. },{"crypto":185}],185:[function(require,module,exports){
  29396. "use strict";
  29397. },{}],186:[function(require,module,exports){
  29398. "use strict";
  29399. // based on the aes implimentation in triple sec
  29400. // https://github.com/keybase/triplesec
  29401. // which is in turn based on the one from crypto-js
  29402. // https://code.google.com/p/crypto-js/
  29403. var Buffer = require('safe-buffer').Buffer;
  29404. function asUInt32Array(buf) {
  29405. if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf);
  29406. var len = buf.length / 4 | 0;
  29407. var out = new Array(len);
  29408. for (var i = 0; i < len; i++) {
  29409. out[i] = buf.readUInt32BE(i * 4);
  29410. }
  29411. return out;
  29412. }
  29413. function scrubVec(v) {
  29414. for (var i = 0; i < v.length; v++) {
  29415. v[i] = 0;
  29416. }
  29417. }
  29418. function cryptBlock(M, keySchedule, SUB_MIX, SBOX, nRounds) {
  29419. var SUB_MIX0 = SUB_MIX[0];
  29420. var SUB_MIX1 = SUB_MIX[1];
  29421. var SUB_MIX2 = SUB_MIX[2];
  29422. var SUB_MIX3 = SUB_MIX[3];
  29423. var s0 = M[0] ^ keySchedule[0];
  29424. var s1 = M[1] ^ keySchedule[1];
  29425. var s2 = M[2] ^ keySchedule[2];
  29426. var s3 = M[3] ^ keySchedule[3];
  29427. var t0, t1, t2, t3;
  29428. var ksRow = 4;
  29429. for (var round = 1; round < nRounds; round++) {
  29430. t0 = SUB_MIX0[s0 >>> 24] ^ SUB_MIX1[s1 >>> 16 & 0xff] ^ SUB_MIX2[s2 >>> 8 & 0xff] ^ SUB_MIX3[s3 & 0xff] ^ keySchedule[ksRow++];
  29431. t1 = SUB_MIX0[s1 >>> 24] ^ SUB_MIX1[s2 >>> 16 & 0xff] ^ SUB_MIX2[s3 >>> 8 & 0xff] ^ SUB_MIX3[s0 & 0xff] ^ keySchedule[ksRow++];
  29432. t2 = SUB_MIX0[s2 >>> 24] ^ SUB_MIX1[s3 >>> 16 & 0xff] ^ SUB_MIX2[s0 >>> 8 & 0xff] ^ SUB_MIX3[s1 & 0xff] ^ keySchedule[ksRow++];
  29433. t3 = SUB_MIX0[s3 >>> 24] ^ SUB_MIX1[s0 >>> 16 & 0xff] ^ SUB_MIX2[s1 >>> 8 & 0xff] ^ SUB_MIX3[s2 & 0xff] ^ keySchedule[ksRow++];
  29434. s0 = t0;
  29435. s1 = t1;
  29436. s2 = t2;
  29437. s3 = t3;
  29438. }
  29439. t0 = (SBOX[s0 >>> 24] << 24 | SBOX[s1 >>> 16 & 0xff] << 16 | SBOX[s2 >>> 8 & 0xff] << 8 | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++];
  29440. t1 = (SBOX[s1 >>> 24] << 24 | SBOX[s2 >>> 16 & 0xff] << 16 | SBOX[s3 >>> 8 & 0xff] << 8 | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++];
  29441. t2 = (SBOX[s2 >>> 24] << 24 | SBOX[s3 >>> 16 & 0xff] << 16 | SBOX[s0 >>> 8 & 0xff] << 8 | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++];
  29442. t3 = (SBOX[s3 >>> 24] << 24 | SBOX[s0 >>> 16 & 0xff] << 16 | SBOX[s1 >>> 8 & 0xff] << 8 | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++];
  29443. t0 = t0 >>> 0;
  29444. t1 = t1 >>> 0;
  29445. t2 = t2 >>> 0;
  29446. t3 = t3 >>> 0;
  29447. return [t0, t1, t2, t3];
  29448. } // AES constants
  29449. var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
  29450. var G = function () {
  29451. // Compute double table
  29452. var d = new Array(256);
  29453. for (var j = 0; j < 256; j++) {
  29454. if (j < 128) {
  29455. d[j] = j << 1;
  29456. } else {
  29457. d[j] = j << 1 ^ 0x11b;
  29458. }
  29459. }
  29460. var SBOX = [];
  29461. var INV_SBOX = [];
  29462. var SUB_MIX = [[], [], [], []];
  29463. var INV_SUB_MIX = [[], [], [], []]; // Walk GF(2^8)
  29464. var x = 0;
  29465. var xi = 0;
  29466. for (var i = 0; i < 256; ++i) {
  29467. // Compute sbox
  29468. var sx = xi ^ xi << 1 ^ xi << 2 ^ xi << 3 ^ xi << 4;
  29469. sx = sx >>> 8 ^ sx & 0xff ^ 0x63;
  29470. SBOX[x] = sx;
  29471. INV_SBOX[sx] = x; // Compute multiplication
  29472. var x2 = d[x];
  29473. var x4 = d[x2];
  29474. var x8 = d[x4]; // Compute sub bytes, mix columns tables
  29475. var t = d[sx] * 0x101 ^ sx * 0x1010100;
  29476. SUB_MIX[0][x] = t << 24 | t >>> 8;
  29477. SUB_MIX[1][x] = t << 16 | t >>> 16;
  29478. SUB_MIX[2][x] = t << 8 | t >>> 24;
  29479. SUB_MIX[3][x] = t; // Compute inv sub bytes, inv mix columns tables
  29480. t = x8 * 0x1010101 ^ x4 * 0x10001 ^ x2 * 0x101 ^ x * 0x1010100;
  29481. INV_SUB_MIX[0][sx] = t << 24 | t >>> 8;
  29482. INV_SUB_MIX[1][sx] = t << 16 | t >>> 16;
  29483. INV_SUB_MIX[2][sx] = t << 8 | t >>> 24;
  29484. INV_SUB_MIX[3][sx] = t;
  29485. if (x === 0) {
  29486. x = xi = 1;
  29487. } else {
  29488. x = x2 ^ d[d[d[x8 ^ x2]]];
  29489. xi ^= d[d[xi]];
  29490. }
  29491. }
  29492. return {
  29493. SBOX: SBOX,
  29494. INV_SBOX: INV_SBOX,
  29495. SUB_MIX: SUB_MIX,
  29496. INV_SUB_MIX: INV_SUB_MIX
  29497. };
  29498. }();
  29499. function AES(key) {
  29500. this._key = asUInt32Array(key);
  29501. this._reset();
  29502. }
  29503. AES.blockSize = 4 * 4;
  29504. AES.keySize = 256 / 8;
  29505. AES.prototype.blockSize = AES.blockSize;
  29506. AES.prototype.keySize = AES.keySize;
  29507. AES.prototype._reset = function () {
  29508. var keyWords = this._key;
  29509. var keySize = keyWords.length;
  29510. var nRounds = keySize + 6;
  29511. var ksRows = (nRounds + 1) * 4;
  29512. var keySchedule = [];
  29513. for (var k = 0; k < keySize; k++) {
  29514. keySchedule[k] = keyWords[k];
  29515. }
  29516. for (k = keySize; k < ksRows; k++) {
  29517. var t = keySchedule[k - 1];
  29518. if (k % keySize === 0) {
  29519. t = t << 8 | t >>> 24;
  29520. t = G.SBOX[t >>> 24] << 24 | G.SBOX[t >>> 16 & 0xff] << 16 | G.SBOX[t >>> 8 & 0xff] << 8 | G.SBOX[t & 0xff];
  29521. t ^= RCON[k / keySize | 0] << 24;
  29522. } else if (keySize > 6 && k % keySize === 4) {
  29523. t = G.SBOX[t >>> 24] << 24 | G.SBOX[t >>> 16 & 0xff] << 16 | G.SBOX[t >>> 8 & 0xff] << 8 | G.SBOX[t & 0xff];
  29524. }
  29525. keySchedule[k] = keySchedule[k - keySize] ^ t;
  29526. }
  29527. var invKeySchedule = [];
  29528. for (var ik = 0; ik < ksRows; ik++) {
  29529. var ksR = ksRows - ik;
  29530. var tt = keySchedule[ksR - (ik % 4 ? 0 : 4)];
  29531. if (ik < 4 || ksR <= 4) {
  29532. invKeySchedule[ik] = tt;
  29533. } else {
  29534. 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]];
  29535. }
  29536. }
  29537. this._nRounds = nRounds;
  29538. this._keySchedule = keySchedule;
  29539. this._invKeySchedule = invKeySchedule;
  29540. };
  29541. AES.prototype.encryptBlockRaw = function (M) {
  29542. M = asUInt32Array(M);
  29543. return cryptBlock(M, this._keySchedule, G.SUB_MIX, G.SBOX, this._nRounds);
  29544. };
  29545. AES.prototype.encryptBlock = function (M) {
  29546. var out = this.encryptBlockRaw(M);
  29547. var buf = Buffer.allocUnsafe(16);
  29548. buf.writeUInt32BE(out[0], 0);
  29549. buf.writeUInt32BE(out[1], 4);
  29550. buf.writeUInt32BE(out[2], 8);
  29551. buf.writeUInt32BE(out[3], 12);
  29552. return buf;
  29553. };
  29554. AES.prototype.decryptBlock = function (M) {
  29555. M = asUInt32Array(M); // swap
  29556. var m1 = M[1];
  29557. M[1] = M[3];
  29558. M[3] = m1;
  29559. var out = cryptBlock(M, this._invKeySchedule, G.INV_SUB_MIX, G.INV_SBOX, this._nRounds);
  29560. var buf = Buffer.allocUnsafe(16);
  29561. buf.writeUInt32BE(out[0], 0);
  29562. buf.writeUInt32BE(out[3], 4);
  29563. buf.writeUInt32BE(out[2], 8);
  29564. buf.writeUInt32BE(out[1], 12);
  29565. return buf;
  29566. };
  29567. AES.prototype.scrub = function () {
  29568. scrubVec(this._keySchedule);
  29569. scrubVec(this._invKeySchedule);
  29570. scrubVec(this._key);
  29571. };
  29572. module.exports.AES = AES;
  29573. },{"safe-buffer":384}],187:[function(require,module,exports){
  29574. "use strict";
  29575. var aes = require('./aes');
  29576. var Buffer = require('safe-buffer').Buffer;
  29577. var Transform = require('cipher-base');
  29578. var inherits = require('inherits');
  29579. var GHASH = require('./ghash');
  29580. var xor = require('buffer-xor');
  29581. var incr32 = require('./incr32');
  29582. function xorTest(a, b) {
  29583. var out = 0;
  29584. if (a.length !== b.length) out++;
  29585. var len = Math.min(a.length, b.length);
  29586. for (var i = 0; i < len; ++i) {
  29587. out += a[i] ^ b[i];
  29588. }
  29589. return out;
  29590. }
  29591. function calcIv(self, iv, ck) {
  29592. if (iv.length === 12) {
  29593. self._finID = Buffer.concat([iv, Buffer.from([0, 0, 0, 1])]);
  29594. return Buffer.concat([iv, Buffer.from([0, 0, 0, 2])]);
  29595. }
  29596. var ghash = new GHASH(ck);
  29597. var len = iv.length;
  29598. var toPad = len % 16;
  29599. ghash.update(iv);
  29600. if (toPad) {
  29601. toPad = 16 - toPad;
  29602. ghash.update(Buffer.alloc(toPad, 0));
  29603. }
  29604. ghash.update(Buffer.alloc(8, 0));
  29605. var ivBits = len * 8;
  29606. var tail = Buffer.alloc(8);
  29607. tail.writeUIntBE(ivBits, 0, 8);
  29608. ghash.update(tail);
  29609. self._finID = ghash.state;
  29610. var out = Buffer.from(self._finID);
  29611. incr32(out);
  29612. return out;
  29613. }
  29614. function StreamCipher(mode, key, iv, decrypt) {
  29615. Transform.call(this);
  29616. var h = Buffer.alloc(4, 0);
  29617. this._cipher = new aes.AES(key);
  29618. var ck = this._cipher.encryptBlock(h);
  29619. this._ghash = new GHASH(ck);
  29620. iv = calcIv(this, iv, ck);
  29621. this._prev = Buffer.from(iv);
  29622. this._cache = Buffer.allocUnsafe(0);
  29623. this._secCache = Buffer.allocUnsafe(0);
  29624. this._decrypt = decrypt;
  29625. this._alen = 0;
  29626. this._len = 0;
  29627. this._mode = mode;
  29628. this._authTag = null;
  29629. this._called = false;
  29630. }
  29631. inherits(StreamCipher, Transform);
  29632. StreamCipher.prototype._update = function (chunk) {
  29633. if (!this._called && this._alen) {
  29634. var rump = 16 - this._alen % 16;
  29635. if (rump < 16) {
  29636. rump = Buffer.alloc(rump, 0);
  29637. this._ghash.update(rump);
  29638. }
  29639. }
  29640. this._called = true;
  29641. var out = this._mode.encrypt(this, chunk);
  29642. if (this._decrypt) {
  29643. this._ghash.update(chunk);
  29644. } else {
  29645. this._ghash.update(out);
  29646. }
  29647. this._len += chunk.length;
  29648. return out;
  29649. };
  29650. StreamCipher.prototype._final = function () {
  29651. if (this._decrypt && !this._authTag) throw new Error('Unsupported state or unable to authenticate data');
  29652. var tag = xor(this._ghash.final(this._alen * 8, this._len * 8), this._cipher.encryptBlock(this._finID));
  29653. if (this._decrypt && xorTest(tag, this._authTag)) throw new Error('Unsupported state or unable to authenticate data');
  29654. this._authTag = tag;
  29655. this._cipher.scrub();
  29656. };
  29657. StreamCipher.prototype.getAuthTag = function getAuthTag() {
  29658. if (this._decrypt || !Buffer.isBuffer(this._authTag)) throw new Error('Attempting to get auth tag in unsupported state');
  29659. return this._authTag;
  29660. };
  29661. StreamCipher.prototype.setAuthTag = function setAuthTag(tag) {
  29662. if (!this._decrypt) throw new Error('Attempting to set auth tag in unsupported state');
  29663. this._authTag = tag;
  29664. };
  29665. StreamCipher.prototype.setAAD = function setAAD(buf) {
  29666. if (this._called) throw new Error('Attempting to set AAD in unsupported state');
  29667. this._ghash.update(buf);
  29668. this._alen += buf.length;
  29669. };
  29670. module.exports = StreamCipher;
  29671. },{"./aes":186,"./ghash":191,"./incr32":192,"buffer-xor":217,"cipher-base":218,"inherits":278,"safe-buffer":384}],188:[function(require,module,exports){
  29672. "use strict";
  29673. var ciphers = require('./encrypter');
  29674. var deciphers = require('./decrypter');
  29675. var modes = require('./modes/list.json');
  29676. function getCiphers() {
  29677. return Object.keys(modes);
  29678. }
  29679. exports.createCipher = exports.Cipher = ciphers.createCipher;
  29680. exports.createCipheriv = exports.Cipheriv = ciphers.createCipheriv;
  29681. exports.createDecipher = exports.Decipher = deciphers.createDecipher;
  29682. exports.createDecipheriv = exports.Decipheriv = deciphers.createDecipheriv;
  29683. exports.listCiphers = exports.getCiphers = getCiphers;
  29684. },{"./decrypter":189,"./encrypter":190,"./modes/list.json":200}],189:[function(require,module,exports){
  29685. "use strict";
  29686. var AuthCipher = require('./authCipher');
  29687. var Buffer = require('safe-buffer').Buffer;
  29688. var MODES = require('./modes');
  29689. var StreamCipher = require('./streamCipher');
  29690. var Transform = require('cipher-base');
  29691. var aes = require('./aes');
  29692. var ebtk = require('evp_bytestokey');
  29693. var inherits = require('inherits');
  29694. function Decipher(mode, key, iv) {
  29695. Transform.call(this);
  29696. this._cache = new Splitter();
  29697. this._last = void 0;
  29698. this._cipher = new aes.AES(key);
  29699. this._prev = Buffer.from(iv);
  29700. this._mode = mode;
  29701. this._autopadding = true;
  29702. }
  29703. inherits(Decipher, Transform);
  29704. Decipher.prototype._update = function (data) {
  29705. this._cache.add(data);
  29706. var chunk;
  29707. var thing;
  29708. var out = [];
  29709. while (chunk = this._cache.get(this._autopadding)) {
  29710. thing = this._mode.decrypt(this, chunk);
  29711. out.push(thing);
  29712. }
  29713. return Buffer.concat(out);
  29714. };
  29715. Decipher.prototype._final = function () {
  29716. var chunk = this._cache.flush();
  29717. if (this._autopadding) {
  29718. return unpad(this._mode.decrypt(this, chunk));
  29719. } else if (chunk) {
  29720. throw new Error('data not multiple of block length');
  29721. }
  29722. };
  29723. Decipher.prototype.setAutoPadding = function (setTo) {
  29724. this._autopadding = !!setTo;
  29725. return this;
  29726. };
  29727. function Splitter() {
  29728. this.cache = Buffer.allocUnsafe(0);
  29729. }
  29730. Splitter.prototype.add = function (data) {
  29731. this.cache = Buffer.concat([this.cache, data]);
  29732. };
  29733. Splitter.prototype.get = function (autoPadding) {
  29734. var out;
  29735. if (autoPadding) {
  29736. if (this.cache.length > 16) {
  29737. out = this.cache.slice(0, 16);
  29738. this.cache = this.cache.slice(16);
  29739. return out;
  29740. }
  29741. } else {
  29742. if (this.cache.length >= 16) {
  29743. out = this.cache.slice(0, 16);
  29744. this.cache = this.cache.slice(16);
  29745. return out;
  29746. }
  29747. }
  29748. return null;
  29749. };
  29750. Splitter.prototype.flush = function () {
  29751. if (this.cache.length) return this.cache;
  29752. };
  29753. function unpad(last) {
  29754. var padded = last[15];
  29755. if (padded < 1 || padded > 16) {
  29756. throw new Error('unable to decrypt data');
  29757. }
  29758. var i = -1;
  29759. while (++i < padded) {
  29760. if (last[i + (16 - padded)] !== padded) {
  29761. throw new Error('unable to decrypt data');
  29762. }
  29763. }
  29764. if (padded === 16) return;
  29765. return last.slice(0, 16 - padded);
  29766. }
  29767. function createDecipheriv(suite, password, iv) {
  29768. var config = MODES[suite.toLowerCase()];
  29769. if (!config) throw new TypeError('invalid suite type');
  29770. if (typeof iv === 'string') iv = Buffer.from(iv);
  29771. if (config.mode !== 'GCM' && iv.length !== config.iv) throw new TypeError('invalid iv length ' + iv.length);
  29772. if (typeof password === 'string') password = Buffer.from(password);
  29773. if (password.length !== config.key / 8) throw new TypeError('invalid key length ' + password.length);
  29774. if (config.type === 'stream') {
  29775. return new StreamCipher(config.module, password, iv, true);
  29776. } else if (config.type === 'auth') {
  29777. return new AuthCipher(config.module, password, iv, true);
  29778. }
  29779. return new Decipher(config.module, password, iv);
  29780. }
  29781. function createDecipher(suite, password) {
  29782. var config = MODES[suite.toLowerCase()];
  29783. if (!config) throw new TypeError('invalid suite type');
  29784. var keys = ebtk(password, false, config.key, config.iv);
  29785. return createDecipheriv(suite, keys.key, keys.iv);
  29786. }
  29787. exports.createDecipher = createDecipher;
  29788. exports.createDecipheriv = createDecipheriv;
  29789. },{"./aes":186,"./authCipher":187,"./modes":199,"./streamCipher":202,"cipher-base":218,"evp_bytestokey":259,"inherits":278,"safe-buffer":384}],190:[function(require,module,exports){
  29790. "use strict";
  29791. var MODES = require('./modes');
  29792. var AuthCipher = require('./authCipher');
  29793. var Buffer = require('safe-buffer').Buffer;
  29794. var StreamCipher = require('./streamCipher');
  29795. var Transform = require('cipher-base');
  29796. var aes = require('./aes');
  29797. var ebtk = require('evp_bytestokey');
  29798. var inherits = require('inherits');
  29799. function Cipher(mode, key, iv) {
  29800. Transform.call(this);
  29801. this._cache = new Splitter();
  29802. this._cipher = new aes.AES(key);
  29803. this._prev = Buffer.from(iv);
  29804. this._mode = mode;
  29805. this._autopadding = true;
  29806. }
  29807. inherits(Cipher, Transform);
  29808. Cipher.prototype._update = function (data) {
  29809. this._cache.add(data);
  29810. var chunk;
  29811. var thing;
  29812. var out = [];
  29813. while (chunk = this._cache.get()) {
  29814. thing = this._mode.encrypt(this, chunk);
  29815. out.push(thing);
  29816. }
  29817. return Buffer.concat(out);
  29818. };
  29819. var PADDING = Buffer.alloc(16, 0x10);
  29820. Cipher.prototype._final = function () {
  29821. var chunk = this._cache.flush();
  29822. if (this._autopadding) {
  29823. chunk = this._mode.encrypt(this, chunk);
  29824. this._cipher.scrub();
  29825. return chunk;
  29826. }
  29827. if (!chunk.equals(PADDING)) {
  29828. this._cipher.scrub();
  29829. throw new Error('data not multiple of block length');
  29830. }
  29831. };
  29832. Cipher.prototype.setAutoPadding = function (setTo) {
  29833. this._autopadding = !!setTo;
  29834. return this;
  29835. };
  29836. function Splitter() {
  29837. this.cache = Buffer.allocUnsafe(0);
  29838. }
  29839. Splitter.prototype.add = function (data) {
  29840. this.cache = Buffer.concat([this.cache, data]);
  29841. };
  29842. Splitter.prototype.get = function () {
  29843. if (this.cache.length > 15) {
  29844. var out = this.cache.slice(0, 16);
  29845. this.cache = this.cache.slice(16);
  29846. return out;
  29847. }
  29848. return null;
  29849. };
  29850. Splitter.prototype.flush = function () {
  29851. var len = 16 - this.cache.length;
  29852. var padBuff = Buffer.allocUnsafe(len);
  29853. var i = -1;
  29854. while (++i < len) {
  29855. padBuff.writeUInt8(len, i);
  29856. }
  29857. return Buffer.concat([this.cache, padBuff]);
  29858. };
  29859. function createCipheriv(suite, password, iv) {
  29860. var config = MODES[suite.toLowerCase()];
  29861. if (!config) throw new TypeError('invalid suite type');
  29862. if (typeof password === 'string') password = Buffer.from(password);
  29863. if (password.length !== config.key / 8) throw new TypeError('invalid key length ' + password.length);
  29864. if (typeof iv === 'string') iv = Buffer.from(iv);
  29865. if (config.mode !== 'GCM' && iv.length !== config.iv) throw new TypeError('invalid iv length ' + iv.length);
  29866. if (config.type === 'stream') {
  29867. return new StreamCipher(config.module, password, iv);
  29868. } else if (config.type === 'auth') {
  29869. return new AuthCipher(config.module, password, iv);
  29870. }
  29871. return new Cipher(config.module, password, iv);
  29872. }
  29873. function createCipher(suite, password) {
  29874. var config = MODES[suite.toLowerCase()];
  29875. if (!config) throw new TypeError('invalid suite type');
  29876. var keys = ebtk(password, false, config.key, config.iv);
  29877. return createCipheriv(suite, keys.key, keys.iv);
  29878. }
  29879. exports.createCipheriv = createCipheriv;
  29880. exports.createCipher = createCipher;
  29881. },{"./aes":186,"./authCipher":187,"./modes":199,"./streamCipher":202,"cipher-base":218,"evp_bytestokey":259,"inherits":278,"safe-buffer":384}],191:[function(require,module,exports){
  29882. "use strict";
  29883. var Buffer = require('safe-buffer').Buffer;
  29884. var ZEROES = Buffer.alloc(16, 0);
  29885. function toArray(buf) {
  29886. return [buf.readUInt32BE(0), buf.readUInt32BE(4), buf.readUInt32BE(8), buf.readUInt32BE(12)];
  29887. }
  29888. function fromArray(out) {
  29889. var buf = Buffer.allocUnsafe(16);
  29890. buf.writeUInt32BE(out[0] >>> 0, 0);
  29891. buf.writeUInt32BE(out[1] >>> 0, 4);
  29892. buf.writeUInt32BE(out[2] >>> 0, 8);
  29893. buf.writeUInt32BE(out[3] >>> 0, 12);
  29894. return buf;
  29895. }
  29896. function GHASH(key) {
  29897. this.h = key;
  29898. this.state = Buffer.alloc(16, 0);
  29899. this.cache = Buffer.allocUnsafe(0);
  29900. } // from http://bitwiseshiftleft.github.io/sjcl/doc/symbols/src/core_gcm.js.html
  29901. // by Juho Vähä-Herttua
  29902. GHASH.prototype.ghash = function (block) {
  29903. var i = -1;
  29904. while (++i < block.length) {
  29905. this.state[i] ^= block[i];
  29906. }
  29907. this._multiply();
  29908. };
  29909. GHASH.prototype._multiply = function () {
  29910. var Vi = toArray(this.h);
  29911. var Zi = [0, 0, 0, 0];
  29912. var j, xi, lsbVi;
  29913. var i = -1;
  29914. while (++i < 128) {
  29915. xi = (this.state[~~(i / 8)] & 1 << 7 - i % 8) !== 0;
  29916. if (xi) {
  29917. // Z_i+1 = Z_i ^ V_i
  29918. Zi[0] ^= Vi[0];
  29919. Zi[1] ^= Vi[1];
  29920. Zi[2] ^= Vi[2];
  29921. Zi[3] ^= Vi[3];
  29922. } // Store the value of LSB(V_i)
  29923. lsbVi = (Vi[3] & 1) !== 0; // V_i+1 = V_i >> 1
  29924. for (j = 3; j > 0; j--) {
  29925. Vi[j] = Vi[j] >>> 1 | (Vi[j - 1] & 1) << 31;
  29926. }
  29927. Vi[0] = Vi[0] >>> 1; // If LSB(V_i) is 1, V_i+1 = (V_i >> 1) ^ R
  29928. if (lsbVi) {
  29929. Vi[0] = Vi[0] ^ 0xe1 << 24;
  29930. }
  29931. }
  29932. this.state = fromArray(Zi);
  29933. };
  29934. GHASH.prototype.update = function (buf) {
  29935. this.cache = Buffer.concat([this.cache, buf]);
  29936. var chunk;
  29937. while (this.cache.length >= 16) {
  29938. chunk = this.cache.slice(0, 16);
  29939. this.cache = this.cache.slice(16);
  29940. this.ghash(chunk);
  29941. }
  29942. };
  29943. GHASH.prototype.final = function (abl, bl) {
  29944. if (this.cache.length) {
  29945. this.ghash(Buffer.concat([this.cache, ZEROES], 16));
  29946. }
  29947. this.ghash(fromArray([0, abl, 0, bl]));
  29948. return this.state;
  29949. };
  29950. module.exports = GHASH;
  29951. },{"safe-buffer":384}],192:[function(require,module,exports){
  29952. "use strict";
  29953. function incr32(iv) {
  29954. var len = iv.length;
  29955. var item;
  29956. while (len--) {
  29957. item = iv.readUInt8(len);
  29958. if (item === 255) {
  29959. iv.writeUInt8(0, len);
  29960. } else {
  29961. item++;
  29962. iv.writeUInt8(item, len);
  29963. break;
  29964. }
  29965. }
  29966. }
  29967. module.exports = incr32;
  29968. },{}],193:[function(require,module,exports){
  29969. "use strict";
  29970. var xor = require('buffer-xor');
  29971. exports.encrypt = function (self, block) {
  29972. var data = xor(block, self._prev);
  29973. self._prev = self._cipher.encryptBlock(data);
  29974. return self._prev;
  29975. };
  29976. exports.decrypt = function (self, block) {
  29977. var pad = self._prev;
  29978. self._prev = block;
  29979. var out = self._cipher.decryptBlock(block);
  29980. return xor(out, pad);
  29981. };
  29982. },{"buffer-xor":217}],194:[function(require,module,exports){
  29983. "use strict";
  29984. var Buffer = require('safe-buffer').Buffer;
  29985. var xor = require('buffer-xor');
  29986. function encryptStart(self, data, decrypt) {
  29987. var len = data.length;
  29988. var out = xor(data, self._cache);
  29989. self._cache = self._cache.slice(len);
  29990. self._prev = Buffer.concat([self._prev, decrypt ? data : out]);
  29991. return out;
  29992. }
  29993. exports.encrypt = function (self, data, decrypt) {
  29994. var out = Buffer.allocUnsafe(0);
  29995. var len;
  29996. while (data.length) {
  29997. if (self._cache.length === 0) {
  29998. self._cache = self._cipher.encryptBlock(self._prev);
  29999. self._prev = Buffer.allocUnsafe(0);
  30000. }
  30001. if (self._cache.length <= data.length) {
  30002. len = self._cache.length;
  30003. out = Buffer.concat([out, encryptStart(self, data.slice(0, len), decrypt)]);
  30004. data = data.slice(len);
  30005. } else {
  30006. out = Buffer.concat([out, encryptStart(self, data, decrypt)]);
  30007. break;
  30008. }
  30009. }
  30010. return out;
  30011. };
  30012. },{"buffer-xor":217,"safe-buffer":384}],195:[function(require,module,exports){
  30013. "use strict";
  30014. var Buffer = require('safe-buffer').Buffer;
  30015. function encryptByte(self, byteParam, decrypt) {
  30016. var pad;
  30017. var i = -1;
  30018. var len = 8;
  30019. var out = 0;
  30020. var bit, value;
  30021. while (++i < len) {
  30022. pad = self._cipher.encryptBlock(self._prev);
  30023. bit = byteParam & 1 << 7 - i ? 0x80 : 0;
  30024. value = pad[0] ^ bit;
  30025. out += (value & 0x80) >> i % 8;
  30026. self._prev = shiftIn(self._prev, decrypt ? bit : value);
  30027. }
  30028. return out;
  30029. }
  30030. function shiftIn(buffer, value) {
  30031. var len = buffer.length;
  30032. var i = -1;
  30033. var out = Buffer.allocUnsafe(buffer.length);
  30034. buffer = Buffer.concat([buffer, Buffer.from([value])]);
  30035. while (++i < len) {
  30036. out[i] = buffer[i] << 1 | buffer[i + 1] >> 7;
  30037. }
  30038. return out;
  30039. }
  30040. exports.encrypt = function (self, chunk, decrypt) {
  30041. var len = chunk.length;
  30042. var out = Buffer.allocUnsafe(len);
  30043. var i = -1;
  30044. while (++i < len) {
  30045. out[i] = encryptByte(self, chunk[i], decrypt);
  30046. }
  30047. return out;
  30048. };
  30049. },{"safe-buffer":384}],196:[function(require,module,exports){
  30050. "use strict";
  30051. var Buffer = require('safe-buffer').Buffer;
  30052. function encryptByte(self, byteParam, decrypt) {
  30053. var pad = self._cipher.encryptBlock(self._prev);
  30054. var out = pad[0] ^ byteParam;
  30055. self._prev = Buffer.concat([self._prev.slice(1), Buffer.from([decrypt ? byteParam : out])]);
  30056. return out;
  30057. }
  30058. exports.encrypt = function (self, chunk, decrypt) {
  30059. var len = chunk.length;
  30060. var out = Buffer.allocUnsafe(len);
  30061. var i = -1;
  30062. while (++i < len) {
  30063. out[i] = encryptByte(self, chunk[i], decrypt);
  30064. }
  30065. return out;
  30066. };
  30067. },{"safe-buffer":384}],197:[function(require,module,exports){
  30068. "use strict";
  30069. var xor = require('buffer-xor');
  30070. var Buffer = require('safe-buffer').Buffer;
  30071. var incr32 = require('../incr32');
  30072. function getBlock(self) {
  30073. var out = self._cipher.encryptBlockRaw(self._prev);
  30074. incr32(self._prev);
  30075. return out;
  30076. }
  30077. var blockSize = 16;
  30078. exports.encrypt = function (self, chunk) {
  30079. var chunkNum = Math.ceil(chunk.length / blockSize);
  30080. var start = self._cache.length;
  30081. self._cache = Buffer.concat([self._cache, Buffer.allocUnsafe(chunkNum * blockSize)]);
  30082. for (var i = 0; i < chunkNum; i++) {
  30083. var out = getBlock(self);
  30084. var offset = start + i * blockSize;
  30085. self._cache.writeUInt32BE(out[0], offset + 0);
  30086. self._cache.writeUInt32BE(out[1], offset + 4);
  30087. self._cache.writeUInt32BE(out[2], offset + 8);
  30088. self._cache.writeUInt32BE(out[3], offset + 12);
  30089. }
  30090. var pad = self._cache.slice(0, chunk.length);
  30091. self._cache = self._cache.slice(chunk.length);
  30092. return xor(chunk, pad);
  30093. };
  30094. },{"../incr32":192,"buffer-xor":217,"safe-buffer":384}],198:[function(require,module,exports){
  30095. "use strict";
  30096. exports.encrypt = function (self, block) {
  30097. return self._cipher.encryptBlock(block);
  30098. };
  30099. exports.decrypt = function (self, block) {
  30100. return self._cipher.decryptBlock(block);
  30101. };
  30102. },{}],199:[function(require,module,exports){
  30103. "use strict";
  30104. var modeModules = {
  30105. ECB: require('./ecb'),
  30106. CBC: require('./cbc'),
  30107. CFB: require('./cfb'),
  30108. CFB8: require('./cfb8'),
  30109. CFB1: require('./cfb1'),
  30110. OFB: require('./ofb'),
  30111. CTR: require('./ctr'),
  30112. GCM: require('./ctr')
  30113. };
  30114. var modes = require('./list.json');
  30115. for (var key in modes) {
  30116. modes[key].module = modeModules[modes[key].mode];
  30117. }
  30118. module.exports = modes;
  30119. },{"./cbc":193,"./cfb":194,"./cfb1":195,"./cfb8":196,"./ctr":197,"./ecb":198,"./list.json":200,"./ofb":201}],200:[function(require,module,exports){
  30120. module.exports={
  30121. "aes-128-ecb": {
  30122. "cipher": "AES",
  30123. "key": 128,
  30124. "iv": 0,
  30125. "mode": "ECB",
  30126. "type": "block"
  30127. },
  30128. "aes-192-ecb": {
  30129. "cipher": "AES",
  30130. "key": 192,
  30131. "iv": 0,
  30132. "mode": "ECB",
  30133. "type": "block"
  30134. },
  30135. "aes-256-ecb": {
  30136. "cipher": "AES",
  30137. "key": 256,
  30138. "iv": 0,
  30139. "mode": "ECB",
  30140. "type": "block"
  30141. },
  30142. "aes-128-cbc": {
  30143. "cipher": "AES",
  30144. "key": 128,
  30145. "iv": 16,
  30146. "mode": "CBC",
  30147. "type": "block"
  30148. },
  30149. "aes-192-cbc": {
  30150. "cipher": "AES",
  30151. "key": 192,
  30152. "iv": 16,
  30153. "mode": "CBC",
  30154. "type": "block"
  30155. },
  30156. "aes-256-cbc": {
  30157. "cipher": "AES",
  30158. "key": 256,
  30159. "iv": 16,
  30160. "mode": "CBC",
  30161. "type": "block"
  30162. },
  30163. "aes128": {
  30164. "cipher": "AES",
  30165. "key": 128,
  30166. "iv": 16,
  30167. "mode": "CBC",
  30168. "type": "block"
  30169. },
  30170. "aes192": {
  30171. "cipher": "AES",
  30172. "key": 192,
  30173. "iv": 16,
  30174. "mode": "CBC",
  30175. "type": "block"
  30176. },
  30177. "aes256": {
  30178. "cipher": "AES",
  30179. "key": 256,
  30180. "iv": 16,
  30181. "mode": "CBC",
  30182. "type": "block"
  30183. },
  30184. "aes-128-cfb": {
  30185. "cipher": "AES",
  30186. "key": 128,
  30187. "iv": 16,
  30188. "mode": "CFB",
  30189. "type": "stream"
  30190. },
  30191. "aes-192-cfb": {
  30192. "cipher": "AES",
  30193. "key": 192,
  30194. "iv": 16,
  30195. "mode": "CFB",
  30196. "type": "stream"
  30197. },
  30198. "aes-256-cfb": {
  30199. "cipher": "AES",
  30200. "key": 256,
  30201. "iv": 16,
  30202. "mode": "CFB",
  30203. "type": "stream"
  30204. },
  30205. "aes-128-cfb8": {
  30206. "cipher": "AES",
  30207. "key": 128,
  30208. "iv": 16,
  30209. "mode": "CFB8",
  30210. "type": "stream"
  30211. },
  30212. "aes-192-cfb8": {
  30213. "cipher": "AES",
  30214. "key": 192,
  30215. "iv": 16,
  30216. "mode": "CFB8",
  30217. "type": "stream"
  30218. },
  30219. "aes-256-cfb8": {
  30220. "cipher": "AES",
  30221. "key": 256,
  30222. "iv": 16,
  30223. "mode": "CFB8",
  30224. "type": "stream"
  30225. },
  30226. "aes-128-cfb1": {
  30227. "cipher": "AES",
  30228. "key": 128,
  30229. "iv": 16,
  30230. "mode": "CFB1",
  30231. "type": "stream"
  30232. },
  30233. "aes-192-cfb1": {
  30234. "cipher": "AES",
  30235. "key": 192,
  30236. "iv": 16,
  30237. "mode": "CFB1",
  30238. "type": "stream"
  30239. },
  30240. "aes-256-cfb1": {
  30241. "cipher": "AES",
  30242. "key": 256,
  30243. "iv": 16,
  30244. "mode": "CFB1",
  30245. "type": "stream"
  30246. },
  30247. "aes-128-ofb": {
  30248. "cipher": "AES",
  30249. "key": 128,
  30250. "iv": 16,
  30251. "mode": "OFB",
  30252. "type": "stream"
  30253. },
  30254. "aes-192-ofb": {
  30255. "cipher": "AES",
  30256. "key": 192,
  30257. "iv": 16,
  30258. "mode": "OFB",
  30259. "type": "stream"
  30260. },
  30261. "aes-256-ofb": {
  30262. "cipher": "AES",
  30263. "key": 256,
  30264. "iv": 16,
  30265. "mode": "OFB",
  30266. "type": "stream"
  30267. },
  30268. "aes-128-ctr": {
  30269. "cipher": "AES",
  30270. "key": 128,
  30271. "iv": 16,
  30272. "mode": "CTR",
  30273. "type": "stream"
  30274. },
  30275. "aes-192-ctr": {
  30276. "cipher": "AES",
  30277. "key": 192,
  30278. "iv": 16,
  30279. "mode": "CTR",
  30280. "type": "stream"
  30281. },
  30282. "aes-256-ctr": {
  30283. "cipher": "AES",
  30284. "key": 256,
  30285. "iv": 16,
  30286. "mode": "CTR",
  30287. "type": "stream"
  30288. },
  30289. "aes-128-gcm": {
  30290. "cipher": "AES",
  30291. "key": 128,
  30292. "iv": 12,
  30293. "mode": "GCM",
  30294. "type": "auth"
  30295. },
  30296. "aes-192-gcm": {
  30297. "cipher": "AES",
  30298. "key": 192,
  30299. "iv": 12,
  30300. "mode": "GCM",
  30301. "type": "auth"
  30302. },
  30303. "aes-256-gcm": {
  30304. "cipher": "AES",
  30305. "key": 256,
  30306. "iv": 12,
  30307. "mode": "GCM",
  30308. "type": "auth"
  30309. }
  30310. }
  30311. },{}],201:[function(require,module,exports){
  30312. (function (Buffer){
  30313. "use strict";
  30314. var xor = require('buffer-xor');
  30315. function getBlock(self) {
  30316. self._prev = self._cipher.encryptBlock(self._prev);
  30317. return self._prev;
  30318. }
  30319. exports.encrypt = function (self, chunk) {
  30320. while (self._cache.length < chunk.length) {
  30321. self._cache = Buffer.concat([self._cache, getBlock(self)]);
  30322. }
  30323. var pad = self._cache.slice(0, chunk.length);
  30324. self._cache = self._cache.slice(chunk.length);
  30325. return xor(chunk, pad);
  30326. };
  30327. }).call(this,require("buffer").Buffer)
  30328. },{"buffer":216,"buffer-xor":217}],202:[function(require,module,exports){
  30329. "use strict";
  30330. var aes = require('./aes');
  30331. var Buffer = require('safe-buffer').Buffer;
  30332. var Transform = require('cipher-base');
  30333. var inherits = require('inherits');
  30334. function StreamCipher(mode, key, iv, decrypt) {
  30335. Transform.call(this);
  30336. this._cipher = new aes.AES(key);
  30337. this._prev = Buffer.from(iv);
  30338. this._cache = Buffer.allocUnsafe(0);
  30339. this._secCache = Buffer.allocUnsafe(0);
  30340. this._decrypt = decrypt;
  30341. this._mode = mode;
  30342. }
  30343. inherits(StreamCipher, Transform);
  30344. StreamCipher.prototype._update = function (chunk) {
  30345. return this._mode.encrypt(this, chunk, this._decrypt);
  30346. };
  30347. StreamCipher.prototype._final = function () {
  30348. this._cipher.scrub();
  30349. };
  30350. module.exports = StreamCipher;
  30351. },{"./aes":186,"cipher-base":218,"inherits":278,"safe-buffer":384}],203:[function(require,module,exports){
  30352. "use strict";
  30353. var DES = require('browserify-des');
  30354. var aes = require('browserify-aes/browser');
  30355. var aesModes = require('browserify-aes/modes');
  30356. var desModes = require('browserify-des/modes');
  30357. var ebtk = require('evp_bytestokey');
  30358. function createCipher(suite, password) {
  30359. suite = suite.toLowerCase();
  30360. var keyLen, ivLen;
  30361. if (aesModes[suite]) {
  30362. keyLen = aesModes[suite].key;
  30363. ivLen = aesModes[suite].iv;
  30364. } else if (desModes[suite]) {
  30365. keyLen = desModes[suite].key * 8;
  30366. ivLen = desModes[suite].iv;
  30367. } else {
  30368. throw new TypeError('invalid suite type');
  30369. }
  30370. var keys = ebtk(password, false, keyLen, ivLen);
  30371. return createCipheriv(suite, keys.key, keys.iv);
  30372. }
  30373. function createDecipher(suite, password) {
  30374. suite = suite.toLowerCase();
  30375. var keyLen, ivLen;
  30376. if (aesModes[suite]) {
  30377. keyLen = aesModes[suite].key;
  30378. ivLen = aesModes[suite].iv;
  30379. } else if (desModes[suite]) {
  30380. keyLen = desModes[suite].key * 8;
  30381. ivLen = desModes[suite].iv;
  30382. } else {
  30383. throw new TypeError('invalid suite type');
  30384. }
  30385. var keys = ebtk(password, false, keyLen, ivLen);
  30386. return createDecipheriv(suite, keys.key, keys.iv);
  30387. }
  30388. function createCipheriv(suite, key, iv) {
  30389. suite = suite.toLowerCase();
  30390. if (aesModes[suite]) return aes.createCipheriv(suite, key, iv);
  30391. if (desModes[suite]) return new DES({
  30392. key: key,
  30393. iv: iv,
  30394. mode: suite
  30395. });
  30396. throw new TypeError('invalid suite type');
  30397. }
  30398. function createDecipheriv(suite, key, iv) {
  30399. suite = suite.toLowerCase();
  30400. if (aesModes[suite]) return aes.createDecipheriv(suite, key, iv);
  30401. if (desModes[suite]) return new DES({
  30402. key: key,
  30403. iv: iv,
  30404. mode: suite,
  30405. decrypt: true
  30406. });
  30407. throw new TypeError('invalid suite type');
  30408. }
  30409. function getCiphers() {
  30410. return Object.keys(desModes).concat(aes.getCiphers());
  30411. }
  30412. exports.createCipher = exports.Cipher = createCipher;
  30413. exports.createCipheriv = exports.Cipheriv = createCipheriv;
  30414. exports.createDecipher = exports.Decipher = createDecipher;
  30415. exports.createDecipheriv = exports.Decipheriv = createDecipheriv;
  30416. exports.listCiphers = exports.getCiphers = getCiphers;
  30417. },{"browserify-aes/browser":188,"browserify-aes/modes":199,"browserify-des":204,"browserify-des/modes":205,"evp_bytestokey":259}],204:[function(require,module,exports){
  30418. "use strict";
  30419. var CipherBase = require('cipher-base');
  30420. var des = require('des.js');
  30421. var inherits = require('inherits');
  30422. var Buffer = require('safe-buffer').Buffer;
  30423. var modes = {
  30424. 'des-ede3-cbc': des.CBC.instantiate(des.EDE),
  30425. 'des-ede3': des.EDE,
  30426. 'des-ede-cbc': des.CBC.instantiate(des.EDE),
  30427. 'des-ede': des.EDE,
  30428. 'des-cbc': des.CBC.instantiate(des.DES),
  30429. 'des-ecb': des.DES
  30430. };
  30431. modes.des = modes['des-cbc'];
  30432. modes.des3 = modes['des-ede3-cbc'];
  30433. module.exports = DES;
  30434. inherits(DES, CipherBase);
  30435. function DES(opts) {
  30436. CipherBase.call(this);
  30437. var modeName = opts.mode.toLowerCase();
  30438. var mode = modes[modeName];
  30439. var type;
  30440. if (opts.decrypt) {
  30441. type = 'decrypt';
  30442. } else {
  30443. type = 'encrypt';
  30444. }
  30445. var key = opts.key;
  30446. if (!Buffer.isBuffer(key)) {
  30447. key = Buffer.from(key);
  30448. }
  30449. if (modeName === 'des-ede' || modeName === 'des-ede-cbc') {
  30450. key = Buffer.concat([key, key.slice(0, 8)]);
  30451. }
  30452. var iv = opts.iv;
  30453. if (!Buffer.isBuffer(iv)) {
  30454. iv = Buffer.from(iv);
  30455. }
  30456. this._des = mode.create({
  30457. key: key,
  30458. iv: iv,
  30459. type: type
  30460. });
  30461. }
  30462. DES.prototype._update = function (data) {
  30463. return Buffer.from(this._des.update(data));
  30464. };
  30465. DES.prototype._final = function () {
  30466. return Buffer.from(this._des.final());
  30467. };
  30468. },{"cipher-base":218,"des.js":230,"inherits":278,"safe-buffer":384}],205:[function(require,module,exports){
  30469. "use strict";
  30470. exports['des-ecb'] = {
  30471. key: 8,
  30472. iv: 0
  30473. };
  30474. exports['des-cbc'] = exports.des = {
  30475. key: 8,
  30476. iv: 8
  30477. };
  30478. exports['des-ede3-cbc'] = exports.des3 = {
  30479. key: 24,
  30480. iv: 8
  30481. };
  30482. exports['des-ede3'] = {
  30483. key: 24,
  30484. iv: 0
  30485. };
  30486. exports['des-ede-cbc'] = {
  30487. key: 16,
  30488. iv: 8
  30489. };
  30490. exports['des-ede'] = {
  30491. key: 16,
  30492. iv: 0
  30493. };
  30494. },{}],206:[function(require,module,exports){
  30495. (function (Buffer){
  30496. "use strict";
  30497. var bn = require('bn.js');
  30498. var randomBytes = require('randombytes');
  30499. module.exports = crt;
  30500. function blind(priv) {
  30501. var r = getr(priv);
  30502. var blinder = r.toRed(bn.mont(priv.modulus)).redPow(new bn(priv.publicExponent)).fromRed();
  30503. return {
  30504. blinder: blinder,
  30505. unblinder: r.invm(priv.modulus)
  30506. };
  30507. }
  30508. function crt(msg, priv) {
  30509. var blinds = blind(priv);
  30510. var len = priv.modulus.byteLength();
  30511. var mod = bn.mont(priv.modulus);
  30512. var blinded = new bn(msg).mul(blinds.blinder).umod(priv.modulus);
  30513. var c1 = blinded.toRed(bn.mont(priv.prime1));
  30514. var c2 = blinded.toRed(bn.mont(priv.prime2));
  30515. var qinv = priv.coefficient;
  30516. var p = priv.prime1;
  30517. var q = priv.prime2;
  30518. var m1 = c1.redPow(priv.exponent1);
  30519. var m2 = c2.redPow(priv.exponent2);
  30520. m1 = m1.fromRed();
  30521. m2 = m2.fromRed();
  30522. var h = m1.isub(m2).imul(qinv).umod(p);
  30523. h.imul(q);
  30524. m2.iadd(h);
  30525. return new Buffer(m2.imul(blinds.unblinder).umod(priv.modulus).toArray(false, len));
  30526. }
  30527. crt.getr = getr;
  30528. function getr(priv) {
  30529. var len = priv.modulus.byteLength();
  30530. var r = new bn(randomBytes(len));
  30531. while (r.cmp(priv.modulus) >= 0 || !r.umod(priv.prime1) || !r.umod(priv.prime2)) {
  30532. r = new bn(randomBytes(len));
  30533. }
  30534. return r;
  30535. }
  30536. }).call(this,require("buffer").Buffer)
  30537. },{"bn.js":207,"buffer":216,"randombytes":366}],207:[function(require,module,exports){
  30538. arguments[4][181][0].apply(exports,arguments)
  30539. },{"buffer":185,"dup":181}],208:[function(require,module,exports){
  30540. "use strict";
  30541. module.exports = require('./browser/algorithms.json');
  30542. },{"./browser/algorithms.json":209}],209:[function(require,module,exports){
  30543. module.exports={
  30544. "sha224WithRSAEncryption": {
  30545. "sign": "rsa",
  30546. "hash": "sha224",
  30547. "id": "302d300d06096086480165030402040500041c"
  30548. },
  30549. "RSA-SHA224": {
  30550. "sign": "ecdsa/rsa",
  30551. "hash": "sha224",
  30552. "id": "302d300d06096086480165030402040500041c"
  30553. },
  30554. "sha256WithRSAEncryption": {
  30555. "sign": "rsa",
  30556. "hash": "sha256",
  30557. "id": "3031300d060960864801650304020105000420"
  30558. },
  30559. "RSA-SHA256": {
  30560. "sign": "ecdsa/rsa",
  30561. "hash": "sha256",
  30562. "id": "3031300d060960864801650304020105000420"
  30563. },
  30564. "sha384WithRSAEncryption": {
  30565. "sign": "rsa",
  30566. "hash": "sha384",
  30567. "id": "3041300d060960864801650304020205000430"
  30568. },
  30569. "RSA-SHA384": {
  30570. "sign": "ecdsa/rsa",
  30571. "hash": "sha384",
  30572. "id": "3041300d060960864801650304020205000430"
  30573. },
  30574. "sha512WithRSAEncryption": {
  30575. "sign": "rsa",
  30576. "hash": "sha512",
  30577. "id": "3051300d060960864801650304020305000440"
  30578. },
  30579. "RSA-SHA512": {
  30580. "sign": "ecdsa/rsa",
  30581. "hash": "sha512",
  30582. "id": "3051300d060960864801650304020305000440"
  30583. },
  30584. "RSA-SHA1": {
  30585. "sign": "rsa",
  30586. "hash": "sha1",
  30587. "id": "3021300906052b0e03021a05000414"
  30588. },
  30589. "ecdsa-with-SHA1": {
  30590. "sign": "ecdsa",
  30591. "hash": "sha1",
  30592. "id": ""
  30593. },
  30594. "sha256": {
  30595. "sign": "ecdsa",
  30596. "hash": "sha256",
  30597. "id": ""
  30598. },
  30599. "sha224": {
  30600. "sign": "ecdsa",
  30601. "hash": "sha224",
  30602. "id": ""
  30603. },
  30604. "sha384": {
  30605. "sign": "ecdsa",
  30606. "hash": "sha384",
  30607. "id": ""
  30608. },
  30609. "sha512": {
  30610. "sign": "ecdsa",
  30611. "hash": "sha512",
  30612. "id": ""
  30613. },
  30614. "DSA-SHA": {
  30615. "sign": "dsa",
  30616. "hash": "sha1",
  30617. "id": ""
  30618. },
  30619. "DSA-SHA1": {
  30620. "sign": "dsa",
  30621. "hash": "sha1",
  30622. "id": ""
  30623. },
  30624. "DSA": {
  30625. "sign": "dsa",
  30626. "hash": "sha1",
  30627. "id": ""
  30628. },
  30629. "DSA-WITH-SHA224": {
  30630. "sign": "dsa",
  30631. "hash": "sha224",
  30632. "id": ""
  30633. },
  30634. "DSA-SHA224": {
  30635. "sign": "dsa",
  30636. "hash": "sha224",
  30637. "id": ""
  30638. },
  30639. "DSA-WITH-SHA256": {
  30640. "sign": "dsa",
  30641. "hash": "sha256",
  30642. "id": ""
  30643. },
  30644. "DSA-SHA256": {
  30645. "sign": "dsa",
  30646. "hash": "sha256",
  30647. "id": ""
  30648. },
  30649. "DSA-WITH-SHA384": {
  30650. "sign": "dsa",
  30651. "hash": "sha384",
  30652. "id": ""
  30653. },
  30654. "DSA-SHA384": {
  30655. "sign": "dsa",
  30656. "hash": "sha384",
  30657. "id": ""
  30658. },
  30659. "DSA-WITH-SHA512": {
  30660. "sign": "dsa",
  30661. "hash": "sha512",
  30662. "id": ""
  30663. },
  30664. "DSA-SHA512": {
  30665. "sign": "dsa",
  30666. "hash": "sha512",
  30667. "id": ""
  30668. },
  30669. "DSA-RIPEMD160": {
  30670. "sign": "dsa",
  30671. "hash": "rmd160",
  30672. "id": ""
  30673. },
  30674. "ripemd160WithRSA": {
  30675. "sign": "rsa",
  30676. "hash": "rmd160",
  30677. "id": "3021300906052b2403020105000414"
  30678. },
  30679. "RSA-RIPEMD160": {
  30680. "sign": "rsa",
  30681. "hash": "rmd160",
  30682. "id": "3021300906052b2403020105000414"
  30683. },
  30684. "md5WithRSAEncryption": {
  30685. "sign": "rsa",
  30686. "hash": "md5",
  30687. "id": "3020300c06082a864886f70d020505000410"
  30688. },
  30689. "RSA-MD5": {
  30690. "sign": "rsa",
  30691. "hash": "md5",
  30692. "id": "3020300c06082a864886f70d020505000410"
  30693. }
  30694. }
  30695. },{}],210:[function(require,module,exports){
  30696. module.exports={
  30697. "1.3.132.0.10": "secp256k1",
  30698. "1.3.132.0.33": "p224",
  30699. "1.2.840.10045.3.1.1": "p192",
  30700. "1.2.840.10045.3.1.7": "p256",
  30701. "1.3.132.0.34": "p384",
  30702. "1.3.132.0.35": "p521"
  30703. }
  30704. },{}],211:[function(require,module,exports){
  30705. "use strict";
  30706. var Buffer = require('safe-buffer').Buffer;
  30707. var createHash = require('create-hash');
  30708. var stream = require('readable-stream');
  30709. var inherits = require('inherits');
  30710. var sign = require('./sign');
  30711. var verify = require('./verify');
  30712. var algorithms = require('./algorithms.json');
  30713. Object.keys(algorithms).forEach(function (key) {
  30714. algorithms[key].id = Buffer.from(algorithms[key].id, 'hex');
  30715. algorithms[key.toLowerCase()] = algorithms[key];
  30716. });
  30717. function Sign(algorithm) {
  30718. stream.Writable.call(this);
  30719. var data = algorithms[algorithm];
  30720. if (!data) throw new Error('Unknown message digest');
  30721. this._hashType = data.hash;
  30722. this._hash = createHash(data.hash);
  30723. this._tag = data.id;
  30724. this._signType = data.sign;
  30725. }
  30726. inherits(Sign, stream.Writable);
  30727. Sign.prototype._write = function _write(data, _, done) {
  30728. this._hash.update(data);
  30729. done();
  30730. };
  30731. Sign.prototype.update = function update(data, enc) {
  30732. if (typeof data === 'string') data = Buffer.from(data, enc);
  30733. this._hash.update(data);
  30734. return this;
  30735. };
  30736. Sign.prototype.sign = function signMethod(key, enc) {
  30737. this.end();
  30738. var hash = this._hash.digest();
  30739. var sig = sign(hash, key, this._hashType, this._signType, this._tag);
  30740. return enc ? sig.toString(enc) : sig;
  30741. };
  30742. function Verify(algorithm) {
  30743. stream.Writable.call(this);
  30744. var data = algorithms[algorithm];
  30745. if (!data) throw new Error('Unknown message digest');
  30746. this._hash = createHash(data.hash);
  30747. this._tag = data.id;
  30748. this._signType = data.sign;
  30749. }
  30750. inherits(Verify, stream.Writable);
  30751. Verify.prototype._write = function _write(data, _, done) {
  30752. this._hash.update(data);
  30753. done();
  30754. };
  30755. Verify.prototype.update = function update(data, enc) {
  30756. if (typeof data === 'string') data = Buffer.from(data, enc);
  30757. this._hash.update(data);
  30758. return this;
  30759. };
  30760. Verify.prototype.verify = function verifyMethod(key, sig, enc) {
  30761. if (typeof sig === 'string') sig = Buffer.from(sig, enc);
  30762. this.end();
  30763. var hash = this._hash.digest();
  30764. return verify(sig, hash, key, this._signType, this._tag);
  30765. };
  30766. function createSign(algorithm) {
  30767. return new Sign(algorithm);
  30768. }
  30769. function createVerify(algorithm) {
  30770. return new Verify(algorithm);
  30771. }
  30772. module.exports = {
  30773. Sign: createSign,
  30774. Verify: createVerify,
  30775. createSign: createSign,
  30776. createVerify: createVerify
  30777. };
  30778. },{"./algorithms.json":209,"./sign":212,"./verify":213,"create-hash":222,"inherits":278,"readable-stream":382,"safe-buffer":214}],212:[function(require,module,exports){
  30779. "use strict";
  30780. // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js
  30781. var Buffer = require('safe-buffer').Buffer;
  30782. var createHmac = require('create-hmac');
  30783. var crt = require('browserify-rsa');
  30784. var EC = require('elliptic').ec;
  30785. var BN = require('bn.js');
  30786. var parseKeys = require('parse-asn1');
  30787. var curves = require('./curves.json');
  30788. function sign(hash, key, hashType, signType, tag) {
  30789. var priv = parseKeys(key);
  30790. if (priv.curve) {
  30791. // rsa keys can be interpreted as ecdsa ones in openssl
  30792. if (signType !== 'ecdsa' && signType !== 'ecdsa/rsa') throw new Error('wrong private key type');
  30793. return ecSign(hash, priv);
  30794. } else if (priv.type === 'dsa') {
  30795. if (signType !== 'dsa') throw new Error('wrong private key type');
  30796. return dsaSign(hash, priv, hashType);
  30797. } else {
  30798. if (signType !== 'rsa' && signType !== 'ecdsa/rsa') throw new Error('wrong private key type');
  30799. }
  30800. hash = Buffer.concat([tag, hash]);
  30801. var len = priv.modulus.byteLength();
  30802. var pad = [0, 1];
  30803. while (hash.length + pad.length + 1 < len) {
  30804. pad.push(0xff);
  30805. }
  30806. pad.push(0x00);
  30807. var i = -1;
  30808. while (++i < hash.length) {
  30809. pad.push(hash[i]);
  30810. }
  30811. var out = crt(pad, priv);
  30812. return out;
  30813. }
  30814. function ecSign(hash, priv) {
  30815. var curveId = curves[priv.curve.join('.')];
  30816. if (!curveId) throw new Error('unknown curve ' + priv.curve.join('.'));
  30817. var curve = new EC(curveId);
  30818. var key = curve.keyFromPrivate(priv.privateKey);
  30819. var out = key.sign(hash);
  30820. return Buffer.from(out.toDER());
  30821. }
  30822. function dsaSign(hash, priv, algo) {
  30823. var x = priv.params.priv_key;
  30824. var p = priv.params.p;
  30825. var q = priv.params.q;
  30826. var g = priv.params.g;
  30827. var r = new BN(0);
  30828. var k;
  30829. var H = bits2int(hash, q).mod(q);
  30830. var s = false;
  30831. var kv = getKey(x, q, hash, algo);
  30832. while (s === false) {
  30833. k = makeKey(q, kv, algo);
  30834. r = makeR(g, k, p, q);
  30835. s = k.invm(q).imul(H.add(x.mul(r))).mod(q);
  30836. if (s.cmpn(0) === 0) {
  30837. s = false;
  30838. r = new BN(0);
  30839. }
  30840. }
  30841. return toDER(r, s);
  30842. }
  30843. function toDER(r, s) {
  30844. r = r.toArray();
  30845. s = s.toArray(); // Pad values
  30846. if (r[0] & 0x80) r = [0].concat(r);
  30847. if (s[0] & 0x80) s = [0].concat(s);
  30848. var total = r.length + s.length + 4;
  30849. var res = [0x30, total, 0x02, r.length];
  30850. res = res.concat(r, [0x02, s.length], s);
  30851. return Buffer.from(res);
  30852. }
  30853. function getKey(x, q, hash, algo) {
  30854. x = Buffer.from(x.toArray());
  30855. if (x.length < q.byteLength()) {
  30856. var zeros = Buffer.alloc(q.byteLength() - x.length);
  30857. x = Buffer.concat([zeros, x]);
  30858. }
  30859. var hlen = hash.length;
  30860. var hbits = bits2octets(hash, q);
  30861. var v = Buffer.alloc(hlen);
  30862. v.fill(1);
  30863. var k = Buffer.alloc(hlen);
  30864. k = createHmac(algo, k).update(v).update(Buffer.from([0])).update(x).update(hbits).digest();
  30865. v = createHmac(algo, k).update(v).digest();
  30866. k = createHmac(algo, k).update(v).update(Buffer.from([1])).update(x).update(hbits).digest();
  30867. v = createHmac(algo, k).update(v).digest();
  30868. return {
  30869. k: k,
  30870. v: v
  30871. };
  30872. }
  30873. function bits2int(obits, q) {
  30874. var bits = new BN(obits);
  30875. var shift = (obits.length << 3) - q.bitLength();
  30876. if (shift > 0) bits.ishrn(shift);
  30877. return bits;
  30878. }
  30879. function bits2octets(bits, q) {
  30880. bits = bits2int(bits, q);
  30881. bits = bits.mod(q);
  30882. var out = Buffer.from(bits.toArray());
  30883. if (out.length < q.byteLength()) {
  30884. var zeros = Buffer.alloc(q.byteLength() - out.length);
  30885. out = Buffer.concat([zeros, out]);
  30886. }
  30887. return out;
  30888. }
  30889. function makeKey(q, kv, algo) {
  30890. var t;
  30891. var k;
  30892. do {
  30893. t = Buffer.alloc(0);
  30894. while (t.length * 8 < q.bitLength()) {
  30895. kv.v = createHmac(algo, kv.k).update(kv.v).digest();
  30896. t = Buffer.concat([t, kv.v]);
  30897. }
  30898. k = bits2int(t, q);
  30899. kv.k = createHmac(algo, kv.k).update(kv.v).update(Buffer.from([0])).digest();
  30900. kv.v = createHmac(algo, kv.k).update(kv.v).digest();
  30901. } while (k.cmp(q) !== -1);
  30902. return k;
  30903. }
  30904. function makeR(g, k, p, q) {
  30905. return g.toRed(BN.mont(p)).redPow(k).fromRed().mod(q);
  30906. }
  30907. module.exports = sign;
  30908. module.exports.getKey = getKey;
  30909. module.exports.makeKey = makeKey;
  30910. },{"./curves.json":210,"bn.js":183,"browserify-rsa":206,"create-hmac":224,"elliptic":241,"parse-asn1":350,"safe-buffer":214}],213:[function(require,module,exports){
  30911. "use strict";
  30912. // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js
  30913. var Buffer = require('safe-buffer').Buffer;
  30914. var BN = require('bn.js');
  30915. var EC = require('elliptic').ec;
  30916. var parseKeys = require('parse-asn1');
  30917. var curves = require('./curves.json');
  30918. function verify(sig, hash, key, signType, tag) {
  30919. var pub = parseKeys(key);
  30920. if (pub.type === 'ec') {
  30921. // rsa keys can be interpreted as ecdsa ones in openssl
  30922. if (signType !== 'ecdsa' && signType !== 'ecdsa/rsa') throw new Error('wrong public key type');
  30923. return ecVerify(sig, hash, pub);
  30924. } else if (pub.type === 'dsa') {
  30925. if (signType !== 'dsa') throw new Error('wrong public key type');
  30926. return dsaVerify(sig, hash, pub);
  30927. } else {
  30928. if (signType !== 'rsa' && signType !== 'ecdsa/rsa') throw new Error('wrong public key type');
  30929. }
  30930. hash = Buffer.concat([tag, hash]);
  30931. var len = pub.modulus.byteLength();
  30932. var pad = [1];
  30933. var padNum = 0;
  30934. while (hash.length + pad.length + 2 < len) {
  30935. pad.push(0xff);
  30936. padNum++;
  30937. }
  30938. pad.push(0x00);
  30939. var i = -1;
  30940. while (++i < hash.length) {
  30941. pad.push(hash[i]);
  30942. }
  30943. pad = Buffer.from(pad);
  30944. var red = BN.mont(pub.modulus);
  30945. sig = new BN(sig).toRed(red);
  30946. sig = sig.redPow(new BN(pub.publicExponent));
  30947. sig = Buffer.from(sig.fromRed().toArray());
  30948. var out = padNum < 8 ? 1 : 0;
  30949. len = Math.min(sig.length, pad.length);
  30950. if (sig.length !== pad.length) out = 1;
  30951. i = -1;
  30952. while (++i < len) {
  30953. out |= sig[i] ^ pad[i];
  30954. }
  30955. return out === 0;
  30956. }
  30957. function ecVerify(sig, hash, pub) {
  30958. var curveId = curves[pub.data.algorithm.curve.join('.')];
  30959. if (!curveId) throw new Error('unknown curve ' + pub.data.algorithm.curve.join('.'));
  30960. var curve = new EC(curveId);
  30961. var pubkey = pub.data.subjectPrivateKey.data;
  30962. return curve.verify(hash, sig, pubkey);
  30963. }
  30964. function dsaVerify(sig, hash, pub) {
  30965. var p = pub.data.p;
  30966. var q = pub.data.q;
  30967. var g = pub.data.g;
  30968. var y = pub.data.pub_key;
  30969. var unpacked = parseKeys.signature.decode(sig, 'der');
  30970. var s = unpacked.s;
  30971. var r = unpacked.r;
  30972. checkValue(s, q);
  30973. checkValue(r, q);
  30974. var montp = BN.mont(p);
  30975. var w = s.invm(q);
  30976. 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);
  30977. return v.cmp(r) === 0;
  30978. }
  30979. function checkValue(b, q) {
  30980. if (b.cmpn(0) <= 0) throw new Error('invalid sig');
  30981. if (b.cmp(q) >= q) throw new Error('invalid sig');
  30982. }
  30983. module.exports = verify;
  30984. },{"./curves.json":210,"bn.js":183,"elliptic":241,"parse-asn1":350,"safe-buffer":214}],214:[function(require,module,exports){
  30985. "use strict";
  30986. /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
  30987. /* eslint-disable node/no-deprecated-api */
  30988. var buffer = require('buffer');
  30989. var Buffer = buffer.Buffer; // alternative to using Object.keys for old browsers
  30990. function copyProps(src, dst) {
  30991. for (var key in src) {
  30992. dst[key] = src[key];
  30993. }
  30994. }
  30995. if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
  30996. module.exports = buffer;
  30997. } else {
  30998. // Copy properties from require('buffer')
  30999. copyProps(buffer, exports);
  31000. exports.Buffer = SafeBuffer;
  31001. }
  31002. function SafeBuffer(arg, encodingOrOffset, length) {
  31003. return Buffer(arg, encodingOrOffset, length);
  31004. }
  31005. SafeBuffer.prototype = Object.create(Buffer.prototype); // Copy static methods from Buffer
  31006. copyProps(Buffer, SafeBuffer);
  31007. SafeBuffer.from = function (arg, encodingOrOffset, length) {
  31008. if (typeof arg === 'number') {
  31009. throw new TypeError('Argument must not be a number');
  31010. }
  31011. return Buffer(arg, encodingOrOffset, length);
  31012. };
  31013. SafeBuffer.alloc = function (size, fill, encoding) {
  31014. if (typeof size !== 'number') {
  31015. throw new TypeError('Argument must be a number');
  31016. }
  31017. var buf = Buffer(size);
  31018. if (fill !== undefined) {
  31019. if (typeof encoding === 'string') {
  31020. buf.fill(fill, encoding);
  31021. } else {
  31022. buf.fill(fill);
  31023. }
  31024. } else {
  31025. buf.fill(0);
  31026. }
  31027. return buf;
  31028. };
  31029. SafeBuffer.allocUnsafe = function (size) {
  31030. if (typeof size !== 'number') {
  31031. throw new TypeError('Argument must be a number');
  31032. }
  31033. return Buffer(size);
  31034. };
  31035. SafeBuffer.allocUnsafeSlow = function (size) {
  31036. if (typeof size !== 'number') {
  31037. throw new TypeError('Argument must be a number');
  31038. }
  31039. return buffer.SlowBuffer(size);
  31040. };
  31041. },{"buffer":216}],215:[function(require,module,exports){
  31042. arguments[4][185][0].apply(exports,arguments)
  31043. },{"dup":185}],216:[function(require,module,exports){
  31044. (function (Buffer){
  31045. /*!
  31046. * The buffer module from node.js, for the browser.
  31047. *
  31048. * @author Feross Aboukhadijeh <https://feross.org>
  31049. * @license MIT
  31050. */
  31051. /* eslint-disable no-proto */
  31052. 'use strict';
  31053. 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); }
  31054. var base64 = require('base64-js');
  31055. var ieee754 = require('ieee754');
  31056. exports.Buffer = Buffer;
  31057. exports.SlowBuffer = SlowBuffer;
  31058. exports.INSPECT_MAX_BYTES = 50;
  31059. var K_MAX_LENGTH = 0x7fffffff;
  31060. exports.kMaxLength = K_MAX_LENGTH;
  31061. /**
  31062. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  31063. * === true Use Uint8Array implementation (fastest)
  31064. * === false Print warning and recommend using `buffer` v4.x which has an Object
  31065. * implementation (most compatible, even IE6)
  31066. *
  31067. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  31068. * Opera 11.6+, iOS 4.2+.
  31069. *
  31070. * We report that the browser does not support typed arrays if the are not subclassable
  31071. * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
  31072. * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
  31073. * for __proto__ and has a buggy typed array implementation.
  31074. */
  31075. Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
  31076. if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && typeof console.error === 'function') {
  31077. 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.');
  31078. }
  31079. function typedArraySupport() {
  31080. // Can typed array instances can be augmented?
  31081. try {
  31082. var arr = new Uint8Array(1);
  31083. arr.__proto__ = {
  31084. __proto__: Uint8Array.prototype,
  31085. foo: function foo() {
  31086. return 42;
  31087. }
  31088. };
  31089. return arr.foo() === 42;
  31090. } catch (e) {
  31091. return false;
  31092. }
  31093. }
  31094. Object.defineProperty(Buffer.prototype, 'parent', {
  31095. enumerable: true,
  31096. get: function get() {
  31097. if (!Buffer.isBuffer(this)) return undefined;
  31098. return this.buffer;
  31099. }
  31100. });
  31101. Object.defineProperty(Buffer.prototype, 'offset', {
  31102. enumerable: true,
  31103. get: function get() {
  31104. if (!Buffer.isBuffer(this)) return undefined;
  31105. return this.byteOffset;
  31106. }
  31107. });
  31108. function createBuffer(length) {
  31109. if (length > K_MAX_LENGTH) {
  31110. throw new RangeError('The value "' + length + '" is invalid for option "size"');
  31111. } // Return an augmented `Uint8Array` instance
  31112. var buf = new Uint8Array(length);
  31113. buf.__proto__ = Buffer.prototype;
  31114. return buf;
  31115. }
  31116. /**
  31117. * The Buffer constructor returns instances of `Uint8Array` that have their
  31118. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  31119. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  31120. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  31121. * returns a single octet.
  31122. *
  31123. * The `Uint8Array` prototype remains unmodified.
  31124. */
  31125. function Buffer(arg, encodingOrOffset, length) {
  31126. // Common case.
  31127. if (typeof arg === 'number') {
  31128. if (typeof encodingOrOffset === 'string') {
  31129. throw new TypeError('The "string" argument must be of type string. Received type number');
  31130. }
  31131. return allocUnsafe(arg);
  31132. }
  31133. return from(arg, encodingOrOffset, length);
  31134. } // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  31135. if (typeof Symbol !== 'undefined' && Symbol.species != null && Buffer[Symbol.species] === Buffer) {
  31136. Object.defineProperty(Buffer, Symbol.species, {
  31137. value: null,
  31138. configurable: true,
  31139. enumerable: false,
  31140. writable: false
  31141. });
  31142. }
  31143. Buffer.poolSize = 8192; // not used by this implementation
  31144. function from(value, encodingOrOffset, length) {
  31145. if (typeof value === 'string') {
  31146. return fromString(value, encodingOrOffset);
  31147. }
  31148. if (ArrayBuffer.isView(value)) {
  31149. return fromArrayLike(value);
  31150. }
  31151. if (value == null) {
  31152. throw TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + 'or Array-like Object. Received type ' + _typeof(value));
  31153. }
  31154. if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) {
  31155. return fromArrayBuffer(value, encodingOrOffset, length);
  31156. }
  31157. if (typeof value === 'number') {
  31158. throw new TypeError('The "value" argument must not be of type number. Received type number');
  31159. }
  31160. var valueOf = value.valueOf && value.valueOf();
  31161. if (valueOf != null && valueOf !== value) {
  31162. return Buffer.from(valueOf, encodingOrOffset, length);
  31163. }
  31164. var b = fromObject(value);
  31165. if (b) return b;
  31166. if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === 'function') {
  31167. return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length);
  31168. }
  31169. throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + 'or Array-like Object. Received type ' + _typeof(value));
  31170. }
  31171. /**
  31172. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  31173. * if value is a number.
  31174. * Buffer.from(str[, encoding])
  31175. * Buffer.from(array)
  31176. * Buffer.from(buffer)
  31177. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  31178. **/
  31179. Buffer.from = function (value, encodingOrOffset, length) {
  31180. return from(value, encodingOrOffset, length);
  31181. }; // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
  31182. // https://github.com/feross/buffer/pull/148
  31183. Buffer.prototype.__proto__ = Uint8Array.prototype;
  31184. Buffer.__proto__ = Uint8Array;
  31185. function assertSize(size) {
  31186. if (typeof size !== 'number') {
  31187. throw new TypeError('"size" argument must be of type number');
  31188. } else if (size < 0) {
  31189. throw new RangeError('The value "' + size + '" is invalid for option "size"');
  31190. }
  31191. }
  31192. function alloc(size, fill, encoding) {
  31193. assertSize(size);
  31194. if (size <= 0) {
  31195. return createBuffer(size);
  31196. }
  31197. if (fill !== undefined) {
  31198. // Only pay attention to encoding if it's a string. This
  31199. // prevents accidentally sending in a number that would
  31200. // be interpretted as a start offset.
  31201. return typeof encoding === 'string' ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill);
  31202. }
  31203. return createBuffer(size);
  31204. }
  31205. /**
  31206. * Creates a new filled Buffer instance.
  31207. * alloc(size[, fill[, encoding]])
  31208. **/
  31209. Buffer.alloc = function (size, fill, encoding) {
  31210. return alloc(size, fill, encoding);
  31211. };
  31212. function allocUnsafe(size) {
  31213. assertSize(size);
  31214. return createBuffer(size < 0 ? 0 : checked(size) | 0);
  31215. }
  31216. /**
  31217. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  31218. * */
  31219. Buffer.allocUnsafe = function (size) {
  31220. return allocUnsafe(size);
  31221. };
  31222. /**
  31223. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  31224. */
  31225. Buffer.allocUnsafeSlow = function (size) {
  31226. return allocUnsafe(size);
  31227. };
  31228. function fromString(string, encoding) {
  31229. if (typeof encoding !== 'string' || encoding === '') {
  31230. encoding = 'utf8';
  31231. }
  31232. if (!Buffer.isEncoding(encoding)) {
  31233. throw new TypeError('Unknown encoding: ' + encoding);
  31234. }
  31235. var length = byteLength(string, encoding) | 0;
  31236. var buf = createBuffer(length);
  31237. var actual = buf.write(string, encoding);
  31238. if (actual !== length) {
  31239. // Writing a hex string, for example, that contains invalid characters will
  31240. // cause everything after the first invalid character to be ignored. (e.g.
  31241. // 'abxxcd' will be treated as 'ab')
  31242. buf = buf.slice(0, actual);
  31243. }
  31244. return buf;
  31245. }
  31246. function fromArrayLike(array) {
  31247. var length = array.length < 0 ? 0 : checked(array.length) | 0;
  31248. var buf = createBuffer(length);
  31249. for (var i = 0; i < length; i += 1) {
  31250. buf[i] = array[i] & 255;
  31251. }
  31252. return buf;
  31253. }
  31254. function fromArrayBuffer(array, byteOffset, length) {
  31255. if (byteOffset < 0 || array.byteLength < byteOffset) {
  31256. throw new RangeError('"offset" is outside of buffer bounds');
  31257. }
  31258. if (array.byteLength < byteOffset + (length || 0)) {
  31259. throw new RangeError('"length" is outside of buffer bounds');
  31260. }
  31261. var buf;
  31262. if (byteOffset === undefined && length === undefined) {
  31263. buf = new Uint8Array(array);
  31264. } else if (length === undefined) {
  31265. buf = new Uint8Array(array, byteOffset);
  31266. } else {
  31267. buf = new Uint8Array(array, byteOffset, length);
  31268. } // Return an augmented `Uint8Array` instance
  31269. buf.__proto__ = Buffer.prototype;
  31270. return buf;
  31271. }
  31272. function fromObject(obj) {
  31273. if (Buffer.isBuffer(obj)) {
  31274. var len = checked(obj.length) | 0;
  31275. var buf = createBuffer(len);
  31276. if (buf.length === 0) {
  31277. return buf;
  31278. }
  31279. obj.copy(buf, 0, 0, len);
  31280. return buf;
  31281. }
  31282. if (obj.length !== undefined) {
  31283. if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
  31284. return createBuffer(0);
  31285. }
  31286. return fromArrayLike(obj);
  31287. }
  31288. if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
  31289. return fromArrayLike(obj.data);
  31290. }
  31291. }
  31292. function checked(length) {
  31293. // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
  31294. // length is NaN (which is otherwise coerced to zero.)
  31295. if (length >= K_MAX_LENGTH) {
  31296. throw new RangeError('Attempt to allocate Buffer larger than maximum ' + 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes');
  31297. }
  31298. return length | 0;
  31299. }
  31300. function SlowBuffer(length) {
  31301. if (+length != length) {
  31302. // eslint-disable-line eqeqeq
  31303. length = 0;
  31304. }
  31305. return Buffer.alloc(+length);
  31306. }
  31307. Buffer.isBuffer = function isBuffer(b) {
  31308. return b != null && b._isBuffer === true && b !== Buffer.prototype; // so Buffer.isBuffer(Buffer.prototype) will be false
  31309. };
  31310. Buffer.compare = function compare(a, b) {
  31311. if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength);
  31312. if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength);
  31313. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  31314. throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');
  31315. }
  31316. if (a === b) return 0;
  31317. var x = a.length;
  31318. var y = b.length;
  31319. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  31320. if (a[i] !== b[i]) {
  31321. x = a[i];
  31322. y = b[i];
  31323. break;
  31324. }
  31325. }
  31326. if (x < y) return -1;
  31327. if (y < x) return 1;
  31328. return 0;
  31329. };
  31330. Buffer.isEncoding = function isEncoding(encoding) {
  31331. switch (String(encoding).toLowerCase()) {
  31332. case 'hex':
  31333. case 'utf8':
  31334. case 'utf-8':
  31335. case 'ascii':
  31336. case 'latin1':
  31337. case 'binary':
  31338. case 'base64':
  31339. case 'ucs2':
  31340. case 'ucs-2':
  31341. case 'utf16le':
  31342. case 'utf-16le':
  31343. return true;
  31344. default:
  31345. return false;
  31346. }
  31347. };
  31348. Buffer.concat = function concat(list, length) {
  31349. if (!Array.isArray(list)) {
  31350. throw new TypeError('"list" argument must be an Array of Buffers');
  31351. }
  31352. if (list.length === 0) {
  31353. return Buffer.alloc(0);
  31354. }
  31355. var i;
  31356. if (length === undefined) {
  31357. length = 0;
  31358. for (i = 0; i < list.length; ++i) {
  31359. length += list[i].length;
  31360. }
  31361. }
  31362. var buffer = Buffer.allocUnsafe(length);
  31363. var pos = 0;
  31364. for (i = 0; i < list.length; ++i) {
  31365. var buf = list[i];
  31366. if (isInstance(buf, Uint8Array)) {
  31367. buf = Buffer.from(buf);
  31368. }
  31369. if (!Buffer.isBuffer(buf)) {
  31370. throw new TypeError('"list" argument must be an Array of Buffers');
  31371. }
  31372. buf.copy(buffer, pos);
  31373. pos += buf.length;
  31374. }
  31375. return buffer;
  31376. };
  31377. function byteLength(string, encoding) {
  31378. if (Buffer.isBuffer(string)) {
  31379. return string.length;
  31380. }
  31381. if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
  31382. return string.byteLength;
  31383. }
  31384. if (typeof string !== 'string') {
  31385. throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' + 'Received type ' + _typeof(string));
  31386. }
  31387. var len = string.length;
  31388. var mustMatch = arguments.length > 2 && arguments[2] === true;
  31389. if (!mustMatch && len === 0) return 0; // Use a for loop to avoid recursion
  31390. var loweredCase = false;
  31391. for (;;) {
  31392. switch (encoding) {
  31393. case 'ascii':
  31394. case 'latin1':
  31395. case 'binary':
  31396. return len;
  31397. case 'utf8':
  31398. case 'utf-8':
  31399. return utf8ToBytes(string).length;
  31400. case 'ucs2':
  31401. case 'ucs-2':
  31402. case 'utf16le':
  31403. case 'utf-16le':
  31404. return len * 2;
  31405. case 'hex':
  31406. return len >>> 1;
  31407. case 'base64':
  31408. return base64ToBytes(string).length;
  31409. default:
  31410. if (loweredCase) {
  31411. return mustMatch ? -1 : utf8ToBytes(string).length; // assume utf8
  31412. }
  31413. encoding = ('' + encoding).toLowerCase();
  31414. loweredCase = true;
  31415. }
  31416. }
  31417. }
  31418. Buffer.byteLength = byteLength;
  31419. function slowToString(encoding, start, end) {
  31420. var loweredCase = false; // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  31421. // property of a typed array.
  31422. // This behaves neither like String nor Uint8Array in that we set start/end
  31423. // to their upper/lower bounds if the value passed is out of range.
  31424. // undefined is handled specially as per ECMA-262 6th Edition,
  31425. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  31426. if (start === undefined || start < 0) {
  31427. start = 0;
  31428. } // Return early if start > this.length. Done here to prevent potential uint32
  31429. // coercion fail below.
  31430. if (start > this.length) {
  31431. return '';
  31432. }
  31433. if (end === undefined || end > this.length) {
  31434. end = this.length;
  31435. }
  31436. if (end <= 0) {
  31437. return '';
  31438. } // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  31439. end >>>= 0;
  31440. start >>>= 0;
  31441. if (end <= start) {
  31442. return '';
  31443. }
  31444. if (!encoding) encoding = 'utf8';
  31445. while (true) {
  31446. switch (encoding) {
  31447. case 'hex':
  31448. return hexSlice(this, start, end);
  31449. case 'utf8':
  31450. case 'utf-8':
  31451. return utf8Slice(this, start, end);
  31452. case 'ascii':
  31453. return asciiSlice(this, start, end);
  31454. case 'latin1':
  31455. case 'binary':
  31456. return latin1Slice(this, start, end);
  31457. case 'base64':
  31458. return base64Slice(this, start, end);
  31459. case 'ucs2':
  31460. case 'ucs-2':
  31461. case 'utf16le':
  31462. case 'utf-16le':
  31463. return utf16leSlice(this, start, end);
  31464. default:
  31465. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding);
  31466. encoding = (encoding + '').toLowerCase();
  31467. loweredCase = true;
  31468. }
  31469. }
  31470. } // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
  31471. // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
  31472. // reliably in a browserify context because there could be multiple different
  31473. // copies of the 'buffer' package in use. This method works even for Buffer
  31474. // instances that were created from another copy of the `buffer` package.
  31475. // See: https://github.com/feross/buffer/issues/154
  31476. Buffer.prototype._isBuffer = true;
  31477. function swap(b, n, m) {
  31478. var i = b[n];
  31479. b[n] = b[m];
  31480. b[m] = i;
  31481. }
  31482. Buffer.prototype.swap16 = function swap16() {
  31483. var len = this.length;
  31484. if (len % 2 !== 0) {
  31485. throw new RangeError('Buffer size must be a multiple of 16-bits');
  31486. }
  31487. for (var i = 0; i < len; i += 2) {
  31488. swap(this, i, i + 1);
  31489. }
  31490. return this;
  31491. };
  31492. Buffer.prototype.swap32 = function swap32() {
  31493. var len = this.length;
  31494. if (len % 4 !== 0) {
  31495. throw new RangeError('Buffer size must be a multiple of 32-bits');
  31496. }
  31497. for (var i = 0; i < len; i += 4) {
  31498. swap(this, i, i + 3);
  31499. swap(this, i + 1, i + 2);
  31500. }
  31501. return this;
  31502. };
  31503. Buffer.prototype.swap64 = function swap64() {
  31504. var len = this.length;
  31505. if (len % 8 !== 0) {
  31506. throw new RangeError('Buffer size must be a multiple of 64-bits');
  31507. }
  31508. for (var i = 0; i < len; i += 8) {
  31509. swap(this, i, i + 7);
  31510. swap(this, i + 1, i + 6);
  31511. swap(this, i + 2, i + 5);
  31512. swap(this, i + 3, i + 4);
  31513. }
  31514. return this;
  31515. };
  31516. Buffer.prototype.toString = function toString() {
  31517. var length = this.length;
  31518. if (length === 0) return '';
  31519. if (arguments.length === 0) return utf8Slice(this, 0, length);
  31520. return slowToString.apply(this, arguments);
  31521. };
  31522. Buffer.prototype.toLocaleString = Buffer.prototype.toString;
  31523. Buffer.prototype.equals = function equals(b) {
  31524. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer');
  31525. if (this === b) return true;
  31526. return Buffer.compare(this, b) === 0;
  31527. };
  31528. Buffer.prototype.inspect = function inspect() {
  31529. var str = '';
  31530. var max = exports.INSPECT_MAX_BYTES;
  31531. str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
  31532. if (this.length > max) str += ' ... ';
  31533. return '<Buffer ' + str + '>';
  31534. };
  31535. Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
  31536. if (isInstance(target, Uint8Array)) {
  31537. target = Buffer.from(target, target.offset, target.byteLength);
  31538. }
  31539. if (!Buffer.isBuffer(target)) {
  31540. throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. ' + 'Received type ' + _typeof(target));
  31541. }
  31542. if (start === undefined) {
  31543. start = 0;
  31544. }
  31545. if (end === undefined) {
  31546. end = target ? target.length : 0;
  31547. }
  31548. if (thisStart === undefined) {
  31549. thisStart = 0;
  31550. }
  31551. if (thisEnd === undefined) {
  31552. thisEnd = this.length;
  31553. }
  31554. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  31555. throw new RangeError('out of range index');
  31556. }
  31557. if (thisStart >= thisEnd && start >= end) {
  31558. return 0;
  31559. }
  31560. if (thisStart >= thisEnd) {
  31561. return -1;
  31562. }
  31563. if (start >= end) {
  31564. return 1;
  31565. }
  31566. start >>>= 0;
  31567. end >>>= 0;
  31568. thisStart >>>= 0;
  31569. thisEnd >>>= 0;
  31570. if (this === target) return 0;
  31571. var x = thisEnd - thisStart;
  31572. var y = end - start;
  31573. var len = Math.min(x, y);
  31574. var thisCopy = this.slice(thisStart, thisEnd);
  31575. var targetCopy = target.slice(start, end);
  31576. for (var i = 0; i < len; ++i) {
  31577. if (thisCopy[i] !== targetCopy[i]) {
  31578. x = thisCopy[i];
  31579. y = targetCopy[i];
  31580. break;
  31581. }
  31582. }
  31583. if (x < y) return -1;
  31584. if (y < x) return 1;
  31585. return 0;
  31586. }; // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  31587. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  31588. //
  31589. // Arguments:
  31590. // - buffer - a Buffer to search
  31591. // - val - a string, Buffer, or number
  31592. // - byteOffset - an index into `buffer`; will be clamped to an int32
  31593. // - encoding - an optional encoding, relevant is val is a string
  31594. // - dir - true for indexOf, false for lastIndexOf
  31595. function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
  31596. // Empty buffer means no match
  31597. if (buffer.length === 0) return -1; // Normalize byteOffset
  31598. if (typeof byteOffset === 'string') {
  31599. encoding = byteOffset;
  31600. byteOffset = 0;
  31601. } else if (byteOffset > 0x7fffffff) {
  31602. byteOffset = 0x7fffffff;
  31603. } else if (byteOffset < -0x80000000) {
  31604. byteOffset = -0x80000000;
  31605. }
  31606. byteOffset = +byteOffset; // Coerce to Number.
  31607. if (numberIsNaN(byteOffset)) {
  31608. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  31609. byteOffset = dir ? 0 : buffer.length - 1;
  31610. } // Normalize byteOffset: negative offsets start from the end of the buffer
  31611. if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
  31612. if (byteOffset >= buffer.length) {
  31613. if (dir) return -1;else byteOffset = buffer.length - 1;
  31614. } else if (byteOffset < 0) {
  31615. if (dir) byteOffset = 0;else return -1;
  31616. } // Normalize val
  31617. if (typeof val === 'string') {
  31618. val = Buffer.from(val, encoding);
  31619. } // Finally, search either indexOf (if dir is true) or lastIndexOf
  31620. if (Buffer.isBuffer(val)) {
  31621. // Special case: looking for empty string/buffer always fails
  31622. if (val.length === 0) {
  31623. return -1;
  31624. }
  31625. return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
  31626. } else if (typeof val === 'number') {
  31627. val = val & 0xFF; // Search for a byte value [0-255]
  31628. if (typeof Uint8Array.prototype.indexOf === 'function') {
  31629. if (dir) {
  31630. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
  31631. } else {
  31632. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
  31633. }
  31634. }
  31635. return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
  31636. }
  31637. throw new TypeError('val must be string, number or Buffer');
  31638. }
  31639. function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
  31640. var indexSize = 1;
  31641. var arrLength = arr.length;
  31642. var valLength = val.length;
  31643. if (encoding !== undefined) {
  31644. encoding = String(encoding).toLowerCase();
  31645. if (encoding === 'ucs2' || encoding === 'ucs-2' || encoding === 'utf16le' || encoding === 'utf-16le') {
  31646. if (arr.length < 2 || val.length < 2) {
  31647. return -1;
  31648. }
  31649. indexSize = 2;
  31650. arrLength /= 2;
  31651. valLength /= 2;
  31652. byteOffset /= 2;
  31653. }
  31654. }
  31655. function read(buf, i) {
  31656. if (indexSize === 1) {
  31657. return buf[i];
  31658. } else {
  31659. return buf.readUInt16BE(i * indexSize);
  31660. }
  31661. }
  31662. var i;
  31663. if (dir) {
  31664. var foundIndex = -1;
  31665. for (i = byteOffset; i < arrLength; i++) {
  31666. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  31667. if (foundIndex === -1) foundIndex = i;
  31668. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;
  31669. } else {
  31670. if (foundIndex !== -1) i -= i - foundIndex;
  31671. foundIndex = -1;
  31672. }
  31673. }
  31674. } else {
  31675. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
  31676. for (i = byteOffset; i >= 0; i--) {
  31677. var found = true;
  31678. for (var j = 0; j < valLength; j++) {
  31679. if (read(arr, i + j) !== read(val, j)) {
  31680. found = false;
  31681. break;
  31682. }
  31683. }
  31684. if (found) return i;
  31685. }
  31686. }
  31687. return -1;
  31688. }
  31689. Buffer.prototype.includes = function includes(val, byteOffset, encoding) {
  31690. return this.indexOf(val, byteOffset, encoding) !== -1;
  31691. };
  31692. Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
  31693. return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
  31694. };
  31695. Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
  31696. return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
  31697. };
  31698. function hexWrite(buf, string, offset, length) {
  31699. offset = Number(offset) || 0;
  31700. var remaining = buf.length - offset;
  31701. if (!length) {
  31702. length = remaining;
  31703. } else {
  31704. length = Number(length);
  31705. if (length > remaining) {
  31706. length = remaining;
  31707. }
  31708. }
  31709. var strLen = string.length;
  31710. if (length > strLen / 2) {
  31711. length = strLen / 2;
  31712. }
  31713. for (var i = 0; i < length; ++i) {
  31714. var parsed = parseInt(string.substr(i * 2, 2), 16);
  31715. if (numberIsNaN(parsed)) return i;
  31716. buf[offset + i] = parsed;
  31717. }
  31718. return i;
  31719. }
  31720. function utf8Write(buf, string, offset, length) {
  31721. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
  31722. }
  31723. function asciiWrite(buf, string, offset, length) {
  31724. return blitBuffer(asciiToBytes(string), buf, offset, length);
  31725. }
  31726. function latin1Write(buf, string, offset, length) {
  31727. return asciiWrite(buf, string, offset, length);
  31728. }
  31729. function base64Write(buf, string, offset, length) {
  31730. return blitBuffer(base64ToBytes(string), buf, offset, length);
  31731. }
  31732. function ucs2Write(buf, string, offset, length) {
  31733. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
  31734. }
  31735. Buffer.prototype.write = function write(string, offset, length, encoding) {
  31736. // Buffer#write(string)
  31737. if (offset === undefined) {
  31738. encoding = 'utf8';
  31739. length = this.length;
  31740. offset = 0; // Buffer#write(string, encoding)
  31741. } else if (length === undefined && typeof offset === 'string') {
  31742. encoding = offset;
  31743. length = this.length;
  31744. offset = 0; // Buffer#write(string, offset[, length][, encoding])
  31745. } else if (isFinite(offset)) {
  31746. offset = offset >>> 0;
  31747. if (isFinite(length)) {
  31748. length = length >>> 0;
  31749. if (encoding === undefined) encoding = 'utf8';
  31750. } else {
  31751. encoding = length;
  31752. length = undefined;
  31753. }
  31754. } else {
  31755. throw new Error('Buffer.write(string, encoding, offset[, length]) is no longer supported');
  31756. }
  31757. var remaining = this.length - offset;
  31758. if (length === undefined || length > remaining) length = remaining;
  31759. if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {
  31760. throw new RangeError('Attempt to write outside buffer bounds');
  31761. }
  31762. if (!encoding) encoding = 'utf8';
  31763. var loweredCase = false;
  31764. for (;;) {
  31765. switch (encoding) {
  31766. case 'hex':
  31767. return hexWrite(this, string, offset, length);
  31768. case 'utf8':
  31769. case 'utf-8':
  31770. return utf8Write(this, string, offset, length);
  31771. case 'ascii':
  31772. return asciiWrite(this, string, offset, length);
  31773. case 'latin1':
  31774. case 'binary':
  31775. return latin1Write(this, string, offset, length);
  31776. case 'base64':
  31777. // Warning: maxLength not taken into account in base64Write
  31778. return base64Write(this, string, offset, length);
  31779. case 'ucs2':
  31780. case 'ucs-2':
  31781. case 'utf16le':
  31782. case 'utf-16le':
  31783. return ucs2Write(this, string, offset, length);
  31784. default:
  31785. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding);
  31786. encoding = ('' + encoding).toLowerCase();
  31787. loweredCase = true;
  31788. }
  31789. }
  31790. };
  31791. Buffer.prototype.toJSON = function toJSON() {
  31792. return {
  31793. type: 'Buffer',
  31794. data: Array.prototype.slice.call(this._arr || this, 0)
  31795. };
  31796. };
  31797. function base64Slice(buf, start, end) {
  31798. if (start === 0 && end === buf.length) {
  31799. return base64.fromByteArray(buf);
  31800. } else {
  31801. return base64.fromByteArray(buf.slice(start, end));
  31802. }
  31803. }
  31804. function utf8Slice(buf, start, end) {
  31805. end = Math.min(buf.length, end);
  31806. var res = [];
  31807. var i = start;
  31808. while (i < end) {
  31809. var firstByte = buf[i];
  31810. var codePoint = null;
  31811. var bytesPerSequence = firstByte > 0xEF ? 4 : firstByte > 0xDF ? 3 : firstByte > 0xBF ? 2 : 1;
  31812. if (i + bytesPerSequence <= end) {
  31813. var secondByte, thirdByte, fourthByte, tempCodePoint;
  31814. switch (bytesPerSequence) {
  31815. case 1:
  31816. if (firstByte < 0x80) {
  31817. codePoint = firstByte;
  31818. }
  31819. break;
  31820. case 2:
  31821. secondByte = buf[i + 1];
  31822. if ((secondByte & 0xC0) === 0x80) {
  31823. tempCodePoint = (firstByte & 0x1F) << 0x6 | secondByte & 0x3F;
  31824. if (tempCodePoint > 0x7F) {
  31825. codePoint = tempCodePoint;
  31826. }
  31827. }
  31828. break;
  31829. case 3:
  31830. secondByte = buf[i + 1];
  31831. thirdByte = buf[i + 2];
  31832. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  31833. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | thirdByte & 0x3F;
  31834. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  31835. codePoint = tempCodePoint;
  31836. }
  31837. }
  31838. break;
  31839. case 4:
  31840. secondByte = buf[i + 1];
  31841. thirdByte = buf[i + 2];
  31842. fourthByte = buf[i + 3];
  31843. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  31844. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | fourthByte & 0x3F;
  31845. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  31846. codePoint = tempCodePoint;
  31847. }
  31848. }
  31849. }
  31850. }
  31851. if (codePoint === null) {
  31852. // we did not generate a valid codePoint so insert a
  31853. // replacement char (U+FFFD) and advance only 1 byte
  31854. codePoint = 0xFFFD;
  31855. bytesPerSequence = 1;
  31856. } else if (codePoint > 0xFFFF) {
  31857. // encode to utf16 (surrogate pair dance)
  31858. codePoint -= 0x10000;
  31859. res.push(codePoint >>> 10 & 0x3FF | 0xD800);
  31860. codePoint = 0xDC00 | codePoint & 0x3FF;
  31861. }
  31862. res.push(codePoint);
  31863. i += bytesPerSequence;
  31864. }
  31865. return decodeCodePointsArray(res);
  31866. } // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  31867. // the lowest limit is Chrome, with 0x10000 args.
  31868. // We go 1 magnitude less, for safety
  31869. var MAX_ARGUMENTS_LENGTH = 0x1000;
  31870. function decodeCodePointsArray(codePoints) {
  31871. var len = codePoints.length;
  31872. if (len <= MAX_ARGUMENTS_LENGTH) {
  31873. return String.fromCharCode.apply(String, codePoints); // avoid extra slice()
  31874. } // Decode in chunks to avoid "call stack size exceeded".
  31875. var res = '';
  31876. var i = 0;
  31877. while (i < len) {
  31878. res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH));
  31879. }
  31880. return res;
  31881. }
  31882. function asciiSlice(buf, start, end) {
  31883. var ret = '';
  31884. end = Math.min(buf.length, end);
  31885. for (var i = start; i < end; ++i) {
  31886. ret += String.fromCharCode(buf[i] & 0x7F);
  31887. }
  31888. return ret;
  31889. }
  31890. function latin1Slice(buf, start, end) {
  31891. var ret = '';
  31892. end = Math.min(buf.length, end);
  31893. for (var i = start; i < end; ++i) {
  31894. ret += String.fromCharCode(buf[i]);
  31895. }
  31896. return ret;
  31897. }
  31898. function hexSlice(buf, start, end) {
  31899. var len = buf.length;
  31900. if (!start || start < 0) start = 0;
  31901. if (!end || end < 0 || end > len) end = len;
  31902. var out = '';
  31903. for (var i = start; i < end; ++i) {
  31904. out += toHex(buf[i]);
  31905. }
  31906. return out;
  31907. }
  31908. function utf16leSlice(buf, start, end) {
  31909. var bytes = buf.slice(start, end);
  31910. var res = '';
  31911. for (var i = 0; i < bytes.length; i += 2) {
  31912. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
  31913. }
  31914. return res;
  31915. }
  31916. Buffer.prototype.slice = function slice(start, end) {
  31917. var len = this.length;
  31918. start = ~~start;
  31919. end = end === undefined ? len : ~~end;
  31920. if (start < 0) {
  31921. start += len;
  31922. if (start < 0) start = 0;
  31923. } else if (start > len) {
  31924. start = len;
  31925. }
  31926. if (end < 0) {
  31927. end += len;
  31928. if (end < 0) end = 0;
  31929. } else if (end > len) {
  31930. end = len;
  31931. }
  31932. if (end < start) end = start;
  31933. var newBuf = this.subarray(start, end); // Return an augmented `Uint8Array` instance
  31934. newBuf.__proto__ = Buffer.prototype;
  31935. return newBuf;
  31936. };
  31937. /*
  31938. * Need to make sure that buffer isn't trying to write out of bounds.
  31939. */
  31940. function checkOffset(offset, ext, length) {
  31941. if (offset % 1 !== 0 || offset < 0) throw new RangeError('offset is not uint');
  31942. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length');
  31943. }
  31944. Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) {
  31945. offset = offset >>> 0;
  31946. byteLength = byteLength >>> 0;
  31947. if (!noAssert) checkOffset(offset, byteLength, this.length);
  31948. var val = this[offset];
  31949. var mul = 1;
  31950. var i = 0;
  31951. while (++i < byteLength && (mul *= 0x100)) {
  31952. val += this[offset + i] * mul;
  31953. }
  31954. return val;
  31955. };
  31956. Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) {
  31957. offset = offset >>> 0;
  31958. byteLength = byteLength >>> 0;
  31959. if (!noAssert) {
  31960. checkOffset(offset, byteLength, this.length);
  31961. }
  31962. var val = this[offset + --byteLength];
  31963. var mul = 1;
  31964. while (byteLength > 0 && (mul *= 0x100)) {
  31965. val += this[offset + --byteLength] * mul;
  31966. }
  31967. return val;
  31968. };
  31969. Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) {
  31970. offset = offset >>> 0;
  31971. if (!noAssert) checkOffset(offset, 1, this.length);
  31972. return this[offset];
  31973. };
  31974. Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
  31975. offset = offset >>> 0;
  31976. if (!noAssert) checkOffset(offset, 2, this.length);
  31977. return this[offset] | this[offset + 1] << 8;
  31978. };
  31979. Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
  31980. offset = offset >>> 0;
  31981. if (!noAssert) checkOffset(offset, 2, this.length);
  31982. return this[offset] << 8 | this[offset + 1];
  31983. };
  31984. Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
  31985. offset = offset >>> 0;
  31986. if (!noAssert) checkOffset(offset, 4, this.length);
  31987. return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 0x1000000;
  31988. };
  31989. Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
  31990. offset = offset >>> 0;
  31991. if (!noAssert) checkOffset(offset, 4, this.length);
  31992. return this[offset] * 0x1000000 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
  31993. };
  31994. Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) {
  31995. offset = offset >>> 0;
  31996. byteLength = byteLength >>> 0;
  31997. if (!noAssert) checkOffset(offset, byteLength, this.length);
  31998. var val = this[offset];
  31999. var mul = 1;
  32000. var i = 0;
  32001. while (++i < byteLength && (mul *= 0x100)) {
  32002. val += this[offset + i] * mul;
  32003. }
  32004. mul *= 0x80;
  32005. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  32006. return val;
  32007. };
  32008. Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) {
  32009. offset = offset >>> 0;
  32010. byteLength = byteLength >>> 0;
  32011. if (!noAssert) checkOffset(offset, byteLength, this.length);
  32012. var i = byteLength;
  32013. var mul = 1;
  32014. var val = this[offset + --i];
  32015. while (i > 0 && (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.readInt8 = function readInt8(offset, noAssert) {
  32023. offset = offset >>> 0;
  32024. if (!noAssert) checkOffset(offset, 1, this.length);
  32025. if (!(this[offset] & 0x80)) return this[offset];
  32026. return (0xff - this[offset] + 1) * -1;
  32027. };
  32028. Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
  32029. offset = offset >>> 0;
  32030. if (!noAssert) checkOffset(offset, 2, this.length);
  32031. var val = this[offset] | this[offset + 1] << 8;
  32032. return val & 0x8000 ? val | 0xFFFF0000 : val;
  32033. };
  32034. Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
  32035. offset = offset >>> 0;
  32036. if (!noAssert) checkOffset(offset, 2, this.length);
  32037. var val = this[offset + 1] | this[offset] << 8;
  32038. return val & 0x8000 ? val | 0xFFFF0000 : val;
  32039. };
  32040. Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
  32041. offset = offset >>> 0;
  32042. if (!noAssert) checkOffset(offset, 4, this.length);
  32043. return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
  32044. };
  32045. Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
  32046. offset = offset >>> 0;
  32047. if (!noAssert) checkOffset(offset, 4, this.length);
  32048. return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
  32049. };
  32050. Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
  32051. offset = offset >>> 0;
  32052. if (!noAssert) checkOffset(offset, 4, this.length);
  32053. return ieee754.read(this, offset, true, 23, 4);
  32054. };
  32055. Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
  32056. offset = offset >>> 0;
  32057. if (!noAssert) checkOffset(offset, 4, this.length);
  32058. return ieee754.read(this, offset, false, 23, 4);
  32059. };
  32060. Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
  32061. offset = offset >>> 0;
  32062. if (!noAssert) checkOffset(offset, 8, this.length);
  32063. return ieee754.read(this, offset, true, 52, 8);
  32064. };
  32065. Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
  32066. offset = offset >>> 0;
  32067. if (!noAssert) checkOffset(offset, 8, this.length);
  32068. return ieee754.read(this, offset, false, 52, 8);
  32069. };
  32070. function checkInt(buf, value, offset, ext, max, min) {
  32071. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance');
  32072. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds');
  32073. if (offset + ext > buf.length) throw new RangeError('Index out of range');
  32074. }
  32075. Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) {
  32076. value = +value;
  32077. offset = offset >>> 0;
  32078. byteLength = byteLength >>> 0;
  32079. if (!noAssert) {
  32080. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  32081. checkInt(this, value, offset, byteLength, maxBytes, 0);
  32082. }
  32083. var mul = 1;
  32084. var i = 0;
  32085. this[offset] = value & 0xFF;
  32086. while (++i < byteLength && (mul *= 0x100)) {
  32087. this[offset + i] = value / mul & 0xFF;
  32088. }
  32089. return offset + byteLength;
  32090. };
  32091. Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) {
  32092. value = +value;
  32093. offset = offset >>> 0;
  32094. byteLength = byteLength >>> 0;
  32095. if (!noAssert) {
  32096. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  32097. checkInt(this, value, offset, byteLength, maxBytes, 0);
  32098. }
  32099. var i = byteLength - 1;
  32100. var mul = 1;
  32101. this[offset + i] = value & 0xFF;
  32102. while (--i >= 0 && (mul *= 0x100)) {
  32103. this[offset + i] = value / mul & 0xFF;
  32104. }
  32105. return offset + byteLength;
  32106. };
  32107. Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
  32108. value = +value;
  32109. offset = offset >>> 0;
  32110. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
  32111. this[offset] = value & 0xff;
  32112. return offset + 1;
  32113. };
  32114. Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
  32115. value = +value;
  32116. offset = offset >>> 0;
  32117. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  32118. this[offset] = value & 0xff;
  32119. this[offset + 1] = value >>> 8;
  32120. return offset + 2;
  32121. };
  32122. Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
  32123. value = +value;
  32124. offset = offset >>> 0;
  32125. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  32126. this[offset] = value >>> 8;
  32127. this[offset + 1] = value & 0xff;
  32128. return offset + 2;
  32129. };
  32130. Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
  32131. value = +value;
  32132. offset = offset >>> 0;
  32133. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  32134. this[offset + 3] = value >>> 24;
  32135. this[offset + 2] = value >>> 16;
  32136. this[offset + 1] = value >>> 8;
  32137. this[offset] = value & 0xff;
  32138. return offset + 4;
  32139. };
  32140. Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
  32141. value = +value;
  32142. offset = offset >>> 0;
  32143. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  32144. this[offset] = value >>> 24;
  32145. this[offset + 1] = value >>> 16;
  32146. this[offset + 2] = value >>> 8;
  32147. this[offset + 3] = value & 0xff;
  32148. return offset + 4;
  32149. };
  32150. Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) {
  32151. value = +value;
  32152. offset = offset >>> 0;
  32153. if (!noAssert) {
  32154. var limit = Math.pow(2, 8 * byteLength - 1);
  32155. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  32156. }
  32157. var i = 0;
  32158. var mul = 1;
  32159. var sub = 0;
  32160. this[offset] = value & 0xFF;
  32161. while (++i < byteLength && (mul *= 0x100)) {
  32162. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  32163. sub = 1;
  32164. }
  32165. this[offset + i] = (value / mul >> 0) - sub & 0xFF;
  32166. }
  32167. return offset + byteLength;
  32168. };
  32169. Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) {
  32170. value = +value;
  32171. offset = offset >>> 0;
  32172. if (!noAssert) {
  32173. var limit = Math.pow(2, 8 * byteLength - 1);
  32174. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  32175. }
  32176. var i = byteLength - 1;
  32177. var mul = 1;
  32178. var sub = 0;
  32179. this[offset + i] = value & 0xFF;
  32180. while (--i >= 0 && (mul *= 0x100)) {
  32181. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  32182. sub = 1;
  32183. }
  32184. this[offset + i] = (value / mul >> 0) - sub & 0xFF;
  32185. }
  32186. return offset + byteLength;
  32187. };
  32188. Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
  32189. value = +value;
  32190. offset = offset >>> 0;
  32191. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
  32192. if (value < 0) value = 0xff + value + 1;
  32193. this[offset] = value & 0xff;
  32194. return offset + 1;
  32195. };
  32196. Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
  32197. value = +value;
  32198. offset = offset >>> 0;
  32199. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  32200. this[offset] = value & 0xff;
  32201. this[offset + 1] = value >>> 8;
  32202. return offset + 2;
  32203. };
  32204. Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
  32205. value = +value;
  32206. offset = offset >>> 0;
  32207. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  32208. this[offset] = value >>> 8;
  32209. this[offset + 1] = value & 0xff;
  32210. return offset + 2;
  32211. };
  32212. Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
  32213. value = +value;
  32214. offset = offset >>> 0;
  32215. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  32216. this[offset] = value & 0xff;
  32217. this[offset + 1] = value >>> 8;
  32218. this[offset + 2] = value >>> 16;
  32219. this[offset + 3] = value >>> 24;
  32220. return offset + 4;
  32221. };
  32222. Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
  32223. value = +value;
  32224. offset = offset >>> 0;
  32225. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  32226. if (value < 0) value = 0xffffffff + value + 1;
  32227. this[offset] = value >>> 24;
  32228. this[offset + 1] = value >>> 16;
  32229. this[offset + 2] = value >>> 8;
  32230. this[offset + 3] = value & 0xff;
  32231. return offset + 4;
  32232. };
  32233. function checkIEEE754(buf, value, offset, ext, max, min) {
  32234. if (offset + ext > buf.length) throw new RangeError('Index out of range');
  32235. if (offset < 0) throw new RangeError('Index out of range');
  32236. }
  32237. function writeFloat(buf, value, offset, littleEndian, noAssert) {
  32238. value = +value;
  32239. offset = offset >>> 0;
  32240. if (!noAssert) {
  32241. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38);
  32242. }
  32243. ieee754.write(buf, value, offset, littleEndian, 23, 4);
  32244. return offset + 4;
  32245. }
  32246. Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
  32247. return writeFloat(this, value, offset, true, noAssert);
  32248. };
  32249. Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
  32250. return writeFloat(this, value, offset, false, noAssert);
  32251. };
  32252. function writeDouble(buf, value, offset, littleEndian, noAssert) {
  32253. value = +value;
  32254. offset = offset >>> 0;
  32255. if (!noAssert) {
  32256. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308);
  32257. }
  32258. ieee754.write(buf, value, offset, littleEndian, 52, 8);
  32259. return offset + 8;
  32260. }
  32261. Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
  32262. return writeDouble(this, value, offset, true, noAssert);
  32263. };
  32264. Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
  32265. return writeDouble(this, value, offset, false, noAssert);
  32266. }; // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  32267. Buffer.prototype.copy = function copy(target, targetStart, start, end) {
  32268. if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer');
  32269. if (!start) start = 0;
  32270. if (!end && end !== 0) end = this.length;
  32271. if (targetStart >= target.length) targetStart = target.length;
  32272. if (!targetStart) targetStart = 0;
  32273. if (end > 0 && end < start) end = start; // Copy 0 bytes; we're done
  32274. if (end === start) return 0;
  32275. if (target.length === 0 || this.length === 0) return 0; // Fatal error conditions
  32276. if (targetStart < 0) {
  32277. throw new RangeError('targetStart out of bounds');
  32278. }
  32279. if (start < 0 || start >= this.length) throw new RangeError('Index out of range');
  32280. if (end < 0) throw new RangeError('sourceEnd out of bounds'); // Are we oob?
  32281. if (end > this.length) end = this.length;
  32282. if (target.length - targetStart < end - start) {
  32283. end = target.length - targetStart + start;
  32284. }
  32285. var len = end - start;
  32286. if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
  32287. // Use built-in when available, missing from IE11
  32288. this.copyWithin(targetStart, start, end);
  32289. } else if (this === target && start < targetStart && targetStart < end) {
  32290. // descending copy from end
  32291. for (var i = len - 1; i >= 0; --i) {
  32292. target[i + targetStart] = this[i + start];
  32293. }
  32294. } else {
  32295. Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart);
  32296. }
  32297. return len;
  32298. }; // Usage:
  32299. // buffer.fill(number[, offset[, end]])
  32300. // buffer.fill(buffer[, offset[, end]])
  32301. // buffer.fill(string[, offset[, end]][, encoding])
  32302. Buffer.prototype.fill = function fill(val, start, end, encoding) {
  32303. // Handle string cases:
  32304. if (typeof val === 'string') {
  32305. if (typeof start === 'string') {
  32306. encoding = start;
  32307. start = 0;
  32308. end = this.length;
  32309. } else if (typeof end === 'string') {
  32310. encoding = end;
  32311. end = this.length;
  32312. }
  32313. if (encoding !== undefined && typeof encoding !== 'string') {
  32314. throw new TypeError('encoding must be a string');
  32315. }
  32316. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  32317. throw new TypeError('Unknown encoding: ' + encoding);
  32318. }
  32319. if (val.length === 1) {
  32320. var code = val.charCodeAt(0);
  32321. if (encoding === 'utf8' && code < 128 || encoding === 'latin1') {
  32322. // Fast path: If `val` fits into a single byte, use that numeric value.
  32323. val = code;
  32324. }
  32325. }
  32326. } else if (typeof val === 'number') {
  32327. val = val & 255;
  32328. } // Invalid ranges are not set to a default, so can range check early.
  32329. if (start < 0 || this.length < start || this.length < end) {
  32330. throw new RangeError('Out of range index');
  32331. }
  32332. if (end <= start) {
  32333. return this;
  32334. }
  32335. start = start >>> 0;
  32336. end = end === undefined ? this.length : end >>> 0;
  32337. if (!val) val = 0;
  32338. var i;
  32339. if (typeof val === 'number') {
  32340. for (i = start; i < end; ++i) {
  32341. this[i] = val;
  32342. }
  32343. } else {
  32344. var bytes = Buffer.isBuffer(val) ? val : Buffer.from(val, encoding);
  32345. var len = bytes.length;
  32346. if (len === 0) {
  32347. throw new TypeError('The value "' + val + '" is invalid for argument "value"');
  32348. }
  32349. for (i = 0; i < end - start; ++i) {
  32350. this[i + start] = bytes[i % len];
  32351. }
  32352. }
  32353. return this;
  32354. }; // HELPER FUNCTIONS
  32355. // ================
  32356. var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
  32357. function base64clean(str) {
  32358. // Node takes equal signs as end of the Base64 encoding
  32359. str = str.split('=')[0]; // Node strips out invalid characters like \n and \t from the string, base64-js does not
  32360. str = str.trim().replace(INVALID_BASE64_RE, ''); // Node converts strings with length < 2 to ''
  32361. if (str.length < 2) return ''; // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  32362. while (str.length % 4 !== 0) {
  32363. str = str + '=';
  32364. }
  32365. return str;
  32366. }
  32367. function toHex(n) {
  32368. if (n < 16) return '0' + n.toString(16);
  32369. return n.toString(16);
  32370. }
  32371. function utf8ToBytes(string, units) {
  32372. units = units || Infinity;
  32373. var codePoint;
  32374. var length = string.length;
  32375. var leadSurrogate = null;
  32376. var bytes = [];
  32377. for (var i = 0; i < length; ++i) {
  32378. codePoint = string.charCodeAt(i); // is surrogate component
  32379. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  32380. // last char was a lead
  32381. if (!leadSurrogate) {
  32382. // no lead yet
  32383. if (codePoint > 0xDBFF) {
  32384. // unexpected trail
  32385. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  32386. continue;
  32387. } else if (i + 1 === length) {
  32388. // unpaired lead
  32389. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  32390. continue;
  32391. } // valid lead
  32392. leadSurrogate = codePoint;
  32393. continue;
  32394. } // 2 leads in a row
  32395. if (codePoint < 0xDC00) {
  32396. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  32397. leadSurrogate = codePoint;
  32398. continue;
  32399. } // valid surrogate pair
  32400. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
  32401. } else if (leadSurrogate) {
  32402. // valid bmp char, but last char was a lead
  32403. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  32404. }
  32405. leadSurrogate = null; // encode utf8
  32406. if (codePoint < 0x80) {
  32407. if ((units -= 1) < 0) break;
  32408. bytes.push(codePoint);
  32409. } else if (codePoint < 0x800) {
  32410. if ((units -= 2) < 0) break;
  32411. bytes.push(codePoint >> 0x6 | 0xC0, codePoint & 0x3F | 0x80);
  32412. } else if (codePoint < 0x10000) {
  32413. if ((units -= 3) < 0) break;
  32414. bytes.push(codePoint >> 0xC | 0xE0, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80);
  32415. } else if (codePoint < 0x110000) {
  32416. if ((units -= 4) < 0) break;
  32417. bytes.push(codePoint >> 0x12 | 0xF0, codePoint >> 0xC & 0x3F | 0x80, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80);
  32418. } else {
  32419. throw new Error('Invalid code point');
  32420. }
  32421. }
  32422. return bytes;
  32423. }
  32424. function asciiToBytes(str) {
  32425. var byteArray = [];
  32426. for (var i = 0; i < str.length; ++i) {
  32427. // Node's code seems to be doing this and not & 0x7F..
  32428. byteArray.push(str.charCodeAt(i) & 0xFF);
  32429. }
  32430. return byteArray;
  32431. }
  32432. function utf16leToBytes(str, units) {
  32433. var c, hi, lo;
  32434. var byteArray = [];
  32435. for (var i = 0; i < str.length; ++i) {
  32436. if ((units -= 2) < 0) break;
  32437. c = str.charCodeAt(i);
  32438. hi = c >> 8;
  32439. lo = c % 256;
  32440. byteArray.push(lo);
  32441. byteArray.push(hi);
  32442. }
  32443. return byteArray;
  32444. }
  32445. function base64ToBytes(str) {
  32446. return base64.toByteArray(base64clean(str));
  32447. }
  32448. function blitBuffer(src, dst, offset, length) {
  32449. for (var i = 0; i < length; ++i) {
  32450. if (i + offset >= dst.length || i >= src.length) break;
  32451. dst[i + offset] = src[i];
  32452. }
  32453. return i;
  32454. } // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
  32455. // the `instanceof` check but they should be treated as of that type.
  32456. // See: https://github.com/feross/buffer/issues/166
  32457. function isInstance(obj, type) {
  32458. return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name;
  32459. }
  32460. function numberIsNaN(obj) {
  32461. // For IE11 support
  32462. return obj !== obj; // eslint-disable-line no-self-compare
  32463. }
  32464. }).call(this,require("buffer").Buffer)
  32465. },{"base64-js":182,"buffer":216,"ieee754":276}],217:[function(require,module,exports){
  32466. (function (Buffer){
  32467. "use strict";
  32468. module.exports = function xor(a, b) {
  32469. var length = Math.min(a.length, b.length);
  32470. var buffer = new Buffer(length);
  32471. for (var i = 0; i < length; ++i) {
  32472. buffer[i] = a[i] ^ b[i];
  32473. }
  32474. return buffer;
  32475. };
  32476. }).call(this,require("buffer").Buffer)
  32477. },{"buffer":216}],218:[function(require,module,exports){
  32478. "use strict";
  32479. var Buffer = require('safe-buffer').Buffer;
  32480. var Transform = require('stream').Transform;
  32481. var StringDecoder = require('string_decoder').StringDecoder;
  32482. var inherits = require('inherits');
  32483. function CipherBase(hashMode) {
  32484. Transform.call(this);
  32485. this.hashMode = typeof hashMode === 'string';
  32486. if (this.hashMode) {
  32487. this[hashMode] = this._finalOrDigest;
  32488. } else {
  32489. this.final = this._finalOrDigest;
  32490. }
  32491. if (this._final) {
  32492. this.__final = this._final;
  32493. this._final = null;
  32494. }
  32495. this._decoder = null;
  32496. this._encoding = null;
  32497. }
  32498. inherits(CipherBase, Transform);
  32499. CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
  32500. if (typeof data === 'string') {
  32501. data = Buffer.from(data, inputEnc);
  32502. }
  32503. var outData = this._update(data);
  32504. if (this.hashMode) return this;
  32505. if (outputEnc) {
  32506. outData = this._toString(outData, outputEnc);
  32507. }
  32508. return outData;
  32509. };
  32510. CipherBase.prototype.setAutoPadding = function () {};
  32511. CipherBase.prototype.getAuthTag = function () {
  32512. throw new Error('trying to get auth tag in unsupported state');
  32513. };
  32514. CipherBase.prototype.setAuthTag = function () {
  32515. throw new Error('trying to set auth tag in unsupported state');
  32516. };
  32517. CipherBase.prototype.setAAD = function () {
  32518. throw new Error('trying to set aad in unsupported state');
  32519. };
  32520. CipherBase.prototype._transform = function (data, _, next) {
  32521. var err;
  32522. try {
  32523. if (this.hashMode) {
  32524. this._update(data);
  32525. } else {
  32526. this.push(this._update(data));
  32527. }
  32528. } catch (e) {
  32529. err = e;
  32530. } finally {
  32531. next(err);
  32532. }
  32533. };
  32534. CipherBase.prototype._flush = function (done) {
  32535. var err;
  32536. try {
  32537. this.push(this.__final());
  32538. } catch (e) {
  32539. err = e;
  32540. }
  32541. done(err);
  32542. };
  32543. CipherBase.prototype._finalOrDigest = function (outputEnc) {
  32544. var outData = this.__final() || Buffer.alloc(0);
  32545. if (outputEnc) {
  32546. outData = this._toString(outData, outputEnc, true);
  32547. }
  32548. return outData;
  32549. };
  32550. CipherBase.prototype._toString = function (value, enc, fin) {
  32551. if (!this._decoder) {
  32552. this._decoder = new StringDecoder(enc);
  32553. this._encoding = enc;
  32554. }
  32555. if (this._encoding !== enc) throw new Error('can\'t switch encodings');
  32556. var out = this._decoder.write(value);
  32557. if (fin) {
  32558. out += this._decoder.end();
  32559. }
  32560. return out;
  32561. };
  32562. module.exports = CipherBase;
  32563. },{"inherits":278,"safe-buffer":384,"stream":396,"string_decoder":410}],219:[function(require,module,exports){
  32564. (function (Buffer){
  32565. "use strict";
  32566. 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); }
  32567. // Copyright Joyent, Inc. and other Node contributors.
  32568. //
  32569. // Permission is hereby granted, free of charge, to any person obtaining a
  32570. // copy of this software and associated documentation files (the
  32571. // "Software"), to deal in the Software without restriction, including
  32572. // without limitation the rights to use, copy, modify, merge, publish,
  32573. // distribute, sublicense, and/or sell copies of the Software, and to permit
  32574. // persons to whom the Software is furnished to do so, subject to the
  32575. // following conditions:
  32576. //
  32577. // The above copyright notice and this permission notice shall be included
  32578. // in all copies or substantial portions of the Software.
  32579. //
  32580. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  32581. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  32582. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  32583. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  32584. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  32585. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  32586. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  32587. // NOTE: These type checking functions intentionally don't use `instanceof`
  32588. // because it is fragile and can be easily faked with `Object.create()`.
  32589. function isArray(arg) {
  32590. if (Array.isArray) {
  32591. return Array.isArray(arg);
  32592. }
  32593. return objectToString(arg) === '[object Array]';
  32594. }
  32595. exports.isArray = isArray;
  32596. function isBoolean(arg) {
  32597. return typeof arg === 'boolean';
  32598. }
  32599. exports.isBoolean = isBoolean;
  32600. function isNull(arg) {
  32601. return arg === null;
  32602. }
  32603. exports.isNull = isNull;
  32604. function isNullOrUndefined(arg) {
  32605. return arg == null;
  32606. }
  32607. exports.isNullOrUndefined = isNullOrUndefined;
  32608. function isNumber(arg) {
  32609. return typeof arg === 'number';
  32610. }
  32611. exports.isNumber = isNumber;
  32612. function isString(arg) {
  32613. return typeof arg === 'string';
  32614. }
  32615. exports.isString = isString;
  32616. function isSymbol(arg) {
  32617. return _typeof(arg) === 'symbol';
  32618. }
  32619. exports.isSymbol = isSymbol;
  32620. function isUndefined(arg) {
  32621. return arg === void 0;
  32622. }
  32623. exports.isUndefined = isUndefined;
  32624. function isRegExp(re) {
  32625. return objectToString(re) === '[object RegExp]';
  32626. }
  32627. exports.isRegExp = isRegExp;
  32628. function isObject(arg) {
  32629. return _typeof(arg) === 'object' && arg !== null;
  32630. }
  32631. exports.isObject = isObject;
  32632. function isDate(d) {
  32633. return objectToString(d) === '[object Date]';
  32634. }
  32635. exports.isDate = isDate;
  32636. function isError(e) {
  32637. return objectToString(e) === '[object Error]' || e instanceof Error;
  32638. }
  32639. exports.isError = isError;
  32640. function isFunction(arg) {
  32641. return typeof arg === 'function';
  32642. }
  32643. exports.isFunction = isFunction;
  32644. function isPrimitive(arg) {
  32645. return arg === null || typeof arg === 'boolean' || typeof arg === 'number' || typeof arg === 'string' || _typeof(arg) === 'symbol' || // ES6 symbol
  32646. typeof arg === 'undefined';
  32647. }
  32648. exports.isPrimitive = isPrimitive;
  32649. exports.isBuffer = Buffer.isBuffer;
  32650. function objectToString(o) {
  32651. return Object.prototype.toString.call(o);
  32652. }
  32653. }).call(this,{"isBuffer":require("../../is-buffer/index.js")})
  32654. },{"../../is-buffer/index.js":279}],220:[function(require,module,exports){
  32655. (function (Buffer){
  32656. "use strict";
  32657. var elliptic = require('elliptic');
  32658. var BN = require('bn.js');
  32659. module.exports = function createECDH(curve) {
  32660. return new ECDH(curve);
  32661. };
  32662. var aliases = {
  32663. secp256k1: {
  32664. name: 'secp256k1',
  32665. byteLength: 32
  32666. },
  32667. secp224r1: {
  32668. name: 'p224',
  32669. byteLength: 28
  32670. },
  32671. prime256v1: {
  32672. name: 'p256',
  32673. byteLength: 32
  32674. },
  32675. prime192v1: {
  32676. name: 'p192',
  32677. byteLength: 24
  32678. },
  32679. ed25519: {
  32680. name: 'ed25519',
  32681. byteLength: 32
  32682. },
  32683. secp384r1: {
  32684. name: 'p384',
  32685. byteLength: 48
  32686. },
  32687. secp521r1: {
  32688. name: 'p521',
  32689. byteLength: 66
  32690. }
  32691. };
  32692. aliases.p224 = aliases.secp224r1;
  32693. aliases.p256 = aliases.secp256r1 = aliases.prime256v1;
  32694. aliases.p192 = aliases.secp192r1 = aliases.prime192v1;
  32695. aliases.p384 = aliases.secp384r1;
  32696. aliases.p521 = aliases.secp521r1;
  32697. function ECDH(curve) {
  32698. this.curveType = aliases[curve];
  32699. if (!this.curveType) {
  32700. this.curveType = {
  32701. name: curve
  32702. };
  32703. }
  32704. this.curve = new elliptic.ec(this.curveType.name); // eslint-disable-line new-cap
  32705. this.keys = void 0;
  32706. }
  32707. ECDH.prototype.generateKeys = function (enc, format) {
  32708. this.keys = this.curve.genKeyPair();
  32709. return this.getPublicKey(enc, format);
  32710. };
  32711. ECDH.prototype.computeSecret = function (other, inenc, enc) {
  32712. inenc = inenc || 'utf8';
  32713. if (!Buffer.isBuffer(other)) {
  32714. other = new Buffer(other, inenc);
  32715. }
  32716. var otherPub = this.curve.keyFromPublic(other).getPublic();
  32717. var out = otherPub.mul(this.keys.getPrivate()).getX();
  32718. return formatReturnValue(out, enc, this.curveType.byteLength);
  32719. };
  32720. ECDH.prototype.getPublicKey = function (enc, format) {
  32721. var key = this.keys.getPublic(format === 'compressed', true);
  32722. if (format === 'hybrid') {
  32723. if (key[key.length - 1] % 2) {
  32724. key[0] = 7;
  32725. } else {
  32726. key[0] = 6;
  32727. }
  32728. }
  32729. return formatReturnValue(key, enc);
  32730. };
  32731. ECDH.prototype.getPrivateKey = function (enc) {
  32732. return formatReturnValue(this.keys.getPrivate(), enc);
  32733. };
  32734. ECDH.prototype.setPublicKey = function (pub, enc) {
  32735. enc = enc || 'utf8';
  32736. if (!Buffer.isBuffer(pub)) {
  32737. pub = new Buffer(pub, enc);
  32738. }
  32739. this.keys._importPublic(pub);
  32740. return this;
  32741. };
  32742. ECDH.prototype.setPrivateKey = function (priv, enc) {
  32743. enc = enc || 'utf8';
  32744. if (!Buffer.isBuffer(priv)) {
  32745. priv = new Buffer(priv, enc);
  32746. }
  32747. var _priv = new BN(priv);
  32748. _priv = _priv.toString(16);
  32749. this.keys = this.curve.genKeyPair();
  32750. this.keys._importPrivate(_priv);
  32751. return this;
  32752. };
  32753. function formatReturnValue(bn, enc, len) {
  32754. if (!Array.isArray(bn)) {
  32755. bn = bn.toArray();
  32756. }
  32757. var buf = new Buffer(bn);
  32758. if (len && buf.length < len) {
  32759. var zeros = new Buffer(len - buf.length);
  32760. zeros.fill(0);
  32761. buf = Buffer.concat([zeros, buf]);
  32762. }
  32763. if (!enc) {
  32764. return buf;
  32765. } else {
  32766. return buf.toString(enc);
  32767. }
  32768. }
  32769. }).call(this,require("buffer").Buffer)
  32770. },{"bn.js":221,"buffer":216,"elliptic":241}],221:[function(require,module,exports){
  32771. arguments[4][181][0].apply(exports,arguments)
  32772. },{"buffer":185,"dup":181}],222:[function(require,module,exports){
  32773. 'use strict';
  32774. var inherits = require('inherits');
  32775. var MD5 = require('md5.js');
  32776. var RIPEMD160 = require('ripemd160');
  32777. var sha = require('sha.js');
  32778. var Base = require('cipher-base');
  32779. function Hash(hash) {
  32780. Base.call(this, 'digest');
  32781. this._hash = hash;
  32782. }
  32783. inherits(Hash, Base);
  32784. Hash.prototype._update = function (data) {
  32785. this._hash.update(data);
  32786. };
  32787. Hash.prototype._final = function () {
  32788. return this._hash.digest();
  32789. };
  32790. module.exports = function createHash(alg) {
  32791. alg = alg.toLowerCase();
  32792. if (alg === 'md5') return new MD5();
  32793. if (alg === 'rmd160' || alg === 'ripemd160') return new RIPEMD160();
  32794. return new Hash(sha(alg));
  32795. };
  32796. },{"cipher-base":218,"inherits":278,"md5.js":325,"ripemd160":383,"sha.js":389}],223:[function(require,module,exports){
  32797. "use strict";
  32798. var MD5 = require('md5.js');
  32799. module.exports = function (buffer) {
  32800. return new MD5().update(buffer).digest();
  32801. };
  32802. },{"md5.js":325}],224:[function(require,module,exports){
  32803. 'use strict';
  32804. var inherits = require('inherits');
  32805. var Legacy = require('./legacy');
  32806. var Base = require('cipher-base');
  32807. var Buffer = require('safe-buffer').Buffer;
  32808. var md5 = require('create-hash/md5');
  32809. var RIPEMD160 = require('ripemd160');
  32810. var sha = require('sha.js');
  32811. var ZEROS = Buffer.alloc(128);
  32812. function Hmac(alg, key) {
  32813. Base.call(this, 'digest');
  32814. if (typeof key === 'string') {
  32815. key = Buffer.from(key);
  32816. }
  32817. var blocksize = alg === 'sha512' || alg === 'sha384' ? 128 : 64;
  32818. this._alg = alg;
  32819. this._key = key;
  32820. if (key.length > blocksize) {
  32821. var hash = alg === 'rmd160' ? new RIPEMD160() : sha(alg);
  32822. key = hash.update(key).digest();
  32823. } else if (key.length < blocksize) {
  32824. key = Buffer.concat([key, ZEROS], blocksize);
  32825. }
  32826. var ipad = this._ipad = Buffer.allocUnsafe(blocksize);
  32827. var opad = this._opad = Buffer.allocUnsafe(blocksize);
  32828. for (var i = 0; i < blocksize; i++) {
  32829. ipad[i] = key[i] ^ 0x36;
  32830. opad[i] = key[i] ^ 0x5C;
  32831. }
  32832. this._hash = alg === 'rmd160' ? new RIPEMD160() : sha(alg);
  32833. this._hash.update(ipad);
  32834. }
  32835. inherits(Hmac, Base);
  32836. Hmac.prototype._update = function (data) {
  32837. this._hash.update(data);
  32838. };
  32839. Hmac.prototype._final = function () {
  32840. var h = this._hash.digest();
  32841. var hash = this._alg === 'rmd160' ? new RIPEMD160() : sha(this._alg);
  32842. return hash.update(this._opad).update(h).digest();
  32843. };
  32844. module.exports = function createHmac(alg, key) {
  32845. alg = alg.toLowerCase();
  32846. if (alg === 'rmd160' || alg === 'ripemd160') {
  32847. return new Hmac('rmd160', key);
  32848. }
  32849. if (alg === 'md5') {
  32850. return new Legacy(md5, key);
  32851. }
  32852. return new Hmac(alg, key);
  32853. };
  32854. },{"./legacy":225,"cipher-base":218,"create-hash/md5":223,"inherits":278,"ripemd160":383,"safe-buffer":384,"sha.js":389}],225:[function(require,module,exports){
  32855. 'use strict';
  32856. var inherits = require('inherits');
  32857. var Buffer = require('safe-buffer').Buffer;
  32858. var Base = require('cipher-base');
  32859. var ZEROS = Buffer.alloc(128);
  32860. var blocksize = 64;
  32861. function Hmac(alg, key) {
  32862. Base.call(this, 'digest');
  32863. if (typeof key === 'string') {
  32864. key = Buffer.from(key);
  32865. }
  32866. this._alg = alg;
  32867. this._key = key;
  32868. if (key.length > blocksize) {
  32869. key = alg(key);
  32870. } else if (key.length < blocksize) {
  32871. key = Buffer.concat([key, ZEROS], blocksize);
  32872. }
  32873. var ipad = this._ipad = Buffer.allocUnsafe(blocksize);
  32874. var opad = this._opad = Buffer.allocUnsafe(blocksize);
  32875. for (var i = 0; i < blocksize; i++) {
  32876. ipad[i] = key[i] ^ 0x36;
  32877. opad[i] = key[i] ^ 0x5C;
  32878. }
  32879. this._hash = [ipad];
  32880. }
  32881. inherits(Hmac, Base);
  32882. Hmac.prototype._update = function (data) {
  32883. this._hash.push(data);
  32884. };
  32885. Hmac.prototype._final = function () {
  32886. var h = this._alg(Buffer.concat(this._hash));
  32887. return this._alg(Buffer.concat([this._opad, h]));
  32888. };
  32889. module.exports = Hmac;
  32890. },{"cipher-base":218,"inherits":278,"safe-buffer":384}],226:[function(require,module,exports){
  32891. 'use strict';
  32892. exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = require('randombytes');
  32893. exports.createHash = exports.Hash = require('create-hash');
  32894. exports.createHmac = exports.Hmac = require('create-hmac');
  32895. var algos = require('browserify-sign/algos');
  32896. var algoKeys = Object.keys(algos);
  32897. var hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(algoKeys);
  32898. exports.getHashes = function () {
  32899. return hashes;
  32900. };
  32901. var p = require('pbkdf2');
  32902. exports.pbkdf2 = p.pbkdf2;
  32903. exports.pbkdf2Sync = p.pbkdf2Sync;
  32904. var aes = require('browserify-cipher');
  32905. exports.Cipher = aes.Cipher;
  32906. exports.createCipher = aes.createCipher;
  32907. exports.Cipheriv = aes.Cipheriv;
  32908. exports.createCipheriv = aes.createCipheriv;
  32909. exports.Decipher = aes.Decipher;
  32910. exports.createDecipher = aes.createDecipher;
  32911. exports.Decipheriv = aes.Decipheriv;
  32912. exports.createDecipheriv = aes.createDecipheriv;
  32913. exports.getCiphers = aes.getCiphers;
  32914. exports.listCiphers = aes.listCiphers;
  32915. var dh = require('diffie-hellman');
  32916. exports.DiffieHellmanGroup = dh.DiffieHellmanGroup;
  32917. exports.createDiffieHellmanGroup = dh.createDiffieHellmanGroup;
  32918. exports.getDiffieHellman = dh.getDiffieHellman;
  32919. exports.createDiffieHellman = dh.createDiffieHellman;
  32920. exports.DiffieHellman = dh.DiffieHellman;
  32921. var sign = require('browserify-sign');
  32922. exports.createSign = sign.createSign;
  32923. exports.Sign = sign.Sign;
  32924. exports.createVerify = sign.createVerify;
  32925. exports.Verify = sign.Verify;
  32926. exports.createECDH = require('create-ecdh');
  32927. var publicEncrypt = require('public-encrypt');
  32928. exports.publicEncrypt = publicEncrypt.publicEncrypt;
  32929. exports.privateEncrypt = publicEncrypt.privateEncrypt;
  32930. exports.publicDecrypt = publicEncrypt.publicDecrypt;
  32931. exports.privateDecrypt = publicEncrypt.privateDecrypt; // the least I can do is make error messages for the rest of the node.js/crypto api.
  32932. // ;[
  32933. // 'createCredentials'
  32934. // ].forEach(function (name) {
  32935. // exports[name] = function () {
  32936. // throw new Error([
  32937. // 'sorry, ' + name + ' is not implemented yet',
  32938. // 'we accept pull requests',
  32939. // 'https://github.com/crypto-browserify/crypto-browserify'
  32940. // ].join('\n'))
  32941. // }
  32942. // })
  32943. var rf = require('randomfill');
  32944. exports.randomFill = rf.randomFill;
  32945. exports.randomFillSync = rf.randomFillSync;
  32946. exports.createCredentials = function () {
  32947. throw new Error(['sorry, createCredentials is not implemented yet', 'we accept pull requests', 'https://github.com/crypto-browserify/crypto-browserify'].join('\n'));
  32948. };
  32949. exports.constants = {
  32950. 'DH_CHECK_P_NOT_SAFE_PRIME': 2,
  32951. 'DH_CHECK_P_NOT_PRIME': 1,
  32952. 'DH_UNABLE_TO_CHECK_GENERATOR': 4,
  32953. 'DH_NOT_SUITABLE_GENERATOR': 8,
  32954. 'NPN_ENABLED': 1,
  32955. 'ALPN_ENABLED': 1,
  32956. 'RSA_PKCS1_PADDING': 1,
  32957. 'RSA_SSLV23_PADDING': 2,
  32958. 'RSA_NO_PADDING': 3,
  32959. 'RSA_PKCS1_OAEP_PADDING': 4,
  32960. 'RSA_X931_PADDING': 5,
  32961. 'RSA_PKCS1_PSS_PADDING': 6,
  32962. 'POINT_CONVERSION_COMPRESSED': 2,
  32963. 'POINT_CONVERSION_UNCOMPRESSED': 4,
  32964. 'POINT_CONVERSION_HYBRID': 6
  32965. };
  32966. },{"browserify-cipher":203,"browserify-sign":211,"browserify-sign/algos":208,"create-ecdh":220,"create-hash":222,"create-hmac":224,"diffie-hellman":236,"pbkdf2":351,"public-encrypt":359,"randombytes":366,"randomfill":367}],227:[function(require,module,exports){
  32967. "use strict";
  32968. 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); }
  32969. !function (t, e) {
  32970. "object" == (typeof exports === "undefined" ? "undefined" : _typeof(exports)) && "undefined" != typeof module ? module.exports = e() : "function" == typeof define && define.amd ? define(e) : t.dayjs = e();
  32971. }(void 0, function () {
  32972. "use strict";
  32973. var t = "millisecond",
  32974. e = "second",
  32975. n = "minute",
  32976. r = "hour",
  32977. i = "day",
  32978. s = "week",
  32979. u = "month",
  32980. a = "quarter",
  32981. o = "year",
  32982. f = "date",
  32983. h = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?.?(\d+)?$/,
  32984. 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,
  32985. d = function d(t, e, n) {
  32986. var r = String(t);
  32987. return !r || r.length >= e ? t : "" + Array(e + 1 - r.length).join(n) + t;
  32988. },
  32989. $ = {
  32990. s: d,
  32991. z: function z(t) {
  32992. var e = -t.utcOffset(),
  32993. n = Math.abs(e),
  32994. r = Math.floor(n / 60),
  32995. i = n % 60;
  32996. return (e <= 0 ? "+" : "-") + d(r, 2, "0") + ":" + d(i, 2, "0");
  32997. },
  32998. m: function t(e, n) {
  32999. if (e.date() < n.date()) return -t(n, e);
  33000. var r = 12 * (n.year() - e.year()) + (n.month() - e.month()),
  33001. i = e.add(r, u),
  33002. s = n - i < 0,
  33003. a = e.add(r + (s ? -1 : 1), u);
  33004. return +(-(r + (n - i) / (s ? i - a : a - i)) || 0);
  33005. },
  33006. a: function a(t) {
  33007. return t < 0 ? Math.ceil(t) || 0 : Math.floor(t);
  33008. },
  33009. p: function p(h) {
  33010. return {
  33011. M: u,
  33012. y: o,
  33013. w: s,
  33014. d: i,
  33015. D: f,
  33016. h: r,
  33017. m: n,
  33018. s: e,
  33019. ms: t,
  33020. Q: a
  33021. }[h] || String(h || "").toLowerCase().replace(/s$/, "");
  33022. },
  33023. u: function u(t) {
  33024. return void 0 === t;
  33025. }
  33026. },
  33027. l = {
  33028. name: "en",
  33029. weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),
  33030. months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_")
  33031. },
  33032. y = "en",
  33033. M = {};
  33034. M[y] = l;
  33035. var m = function m(t) {
  33036. return t instanceof S;
  33037. },
  33038. D = function D(t, e, n) {
  33039. var r;
  33040. if (!t) return y;
  33041. if ("string" == typeof t) M[t] && (r = t), e && (M[t] = e, r = t);else {
  33042. var i = t.name;
  33043. M[i] = t, r = i;
  33044. }
  33045. return !n && r && (y = r), r || !n && y;
  33046. },
  33047. v = function v(t, e) {
  33048. if (m(t)) return t.clone();
  33049. var n = "object" == _typeof(e) ? e : {};
  33050. return n.date = t, n.args = arguments, new S(n);
  33051. },
  33052. g = $;
  33053. g.l = D, g.i = m, g.w = function (t, e) {
  33054. return v(t, {
  33055. locale: e.$L,
  33056. utc: e.$u,
  33057. $offset: e.$offset
  33058. });
  33059. };
  33060. var S = function () {
  33061. function d(t) {
  33062. this.$L = this.$L || D(t.locale, null, !0), this.parse(t);
  33063. }
  33064. var $ = d.prototype;
  33065. return $.parse = function (t) {
  33066. this.$d = function (t) {
  33067. var e = t.date,
  33068. n = t.utc;
  33069. if (null === e) return new Date(NaN);
  33070. if (g.u(e)) return new Date();
  33071. if (e instanceof Date) return new Date(e);
  33072. if ("string" == typeof e && !/Z$/i.test(e)) {
  33073. var r = e.match(h);
  33074. if (r) {
  33075. var i = r[2] - 1 || 0,
  33076. s = (r[7] || "0").substring(0, 3);
  33077. 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);
  33078. }
  33079. }
  33080. return new Date(e);
  33081. }(t), this.init();
  33082. }, $.init = function () {
  33083. var t = this.$d;
  33084. 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();
  33085. }, $.$utils = function () {
  33086. return g;
  33087. }, $.isValid = function () {
  33088. return !("Invalid Date" === this.$d.toString());
  33089. }, $.isSame = function (t, e) {
  33090. var n = v(t);
  33091. return this.startOf(e) <= n && n <= this.endOf(e);
  33092. }, $.isAfter = function (t, e) {
  33093. return v(t) < this.startOf(e);
  33094. }, $.isBefore = function (t, e) {
  33095. return this.endOf(e) < v(t);
  33096. }, $.$g = function (t, e, n) {
  33097. return g.u(t) ? this[e] : this.set(n, t);
  33098. }, $.unix = function () {
  33099. return Math.floor(this.valueOf() / 1e3);
  33100. }, $.valueOf = function () {
  33101. return this.$d.getTime();
  33102. }, $.startOf = function (t, a) {
  33103. var h = this,
  33104. c = !!g.u(a) || a,
  33105. d = g.p(t),
  33106. $ = function $(t, e) {
  33107. var n = g.w(h.$u ? Date.UTC(h.$y, e, t) : new Date(h.$y, e, t), h);
  33108. return c ? n : n.endOf(i);
  33109. },
  33110. l = function l(t, e) {
  33111. return g.w(h.toDate()[t].apply(h.toDate("s"), (c ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(e)), h);
  33112. },
  33113. y = this.$W,
  33114. M = this.$M,
  33115. m = this.$D,
  33116. D = "set" + (this.$u ? "UTC" : "");
  33117. switch (d) {
  33118. case o:
  33119. return c ? $(1, 0) : $(31, 11);
  33120. case u:
  33121. return c ? $(1, M) : $(0, M + 1);
  33122. case s:
  33123. var v = this.$locale().weekStart || 0,
  33124. S = (y < v ? y + 7 : y) - v;
  33125. return $(c ? m - S : m + (6 - S), M);
  33126. case i:
  33127. case f:
  33128. return l(D + "Hours", 0);
  33129. case r:
  33130. return l(D + "Minutes", 1);
  33131. case n:
  33132. return l(D + "Seconds", 2);
  33133. case e:
  33134. return l(D + "Milliseconds", 3);
  33135. default:
  33136. return this.clone();
  33137. }
  33138. }, $.endOf = function (t) {
  33139. return this.startOf(t, !1);
  33140. }, $.$set = function (s, a) {
  33141. var h,
  33142. c = g.p(s),
  33143. d = "set" + (this.$u ? "UTC" : ""),
  33144. $ = (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],
  33145. l = c === i ? this.$D + (a - this.$W) : a;
  33146. if (c === u || c === o) {
  33147. var y = this.clone().set(f, 1);
  33148. y.$d[$](l), y.init(), this.$d = y.set(f, Math.min(this.$D, y.daysInMonth())).$d;
  33149. } else $ && this.$d[$](l);
  33150. return this.init(), this;
  33151. }, $.set = function (t, e) {
  33152. return this.clone().$set(t, e);
  33153. }, $.get = function (t) {
  33154. return this[g.p(t)]();
  33155. }, $.add = function (t, a) {
  33156. var f,
  33157. h = this;
  33158. t = Number(t);
  33159. var c = g.p(a),
  33160. d = function d(e) {
  33161. var n = v(h);
  33162. return g.w(n.date(n.date() + Math.round(e * t)), h);
  33163. };
  33164. if (c === u) return this.set(u, this.$M + t);
  33165. if (c === o) return this.set(o, this.$y + t);
  33166. if (c === i) return d(1);
  33167. if (c === s) return d(7);
  33168. var $ = (f = {}, f[n] = 6e4, f[r] = 36e5, f[e] = 1e3, f)[c] || 1,
  33169. l = this.$d.getTime() + t * $;
  33170. return g.w(l, this);
  33171. }, $.subtract = function (t, e) {
  33172. return this.add(-1 * t, e);
  33173. }, $.format = function (t) {
  33174. var e = this;
  33175. if (!this.isValid()) return "Invalid Date";
  33176. var n = t || "YYYY-MM-DDTHH:mm:ssZ",
  33177. r = g.z(this),
  33178. i = this.$locale(),
  33179. s = this.$H,
  33180. u = this.$m,
  33181. a = this.$M,
  33182. o = i.weekdays,
  33183. f = i.months,
  33184. h = function h(t, r, i, s) {
  33185. return t && (t[r] || t(e, n)) || i[r].substr(0, s);
  33186. },
  33187. d = function d(t) {
  33188. return g.s(s % 12 || 12, t, "0");
  33189. },
  33190. $ = i.meridiem || function (t, e, n) {
  33191. var r = t < 12 ? "AM" : "PM";
  33192. return n ? r.toLowerCase() : r;
  33193. },
  33194. l = {
  33195. YY: String(this.$y).slice(-2),
  33196. YYYY: this.$y,
  33197. M: a + 1,
  33198. MM: g.s(a + 1, 2, "0"),
  33199. MMM: h(i.monthsShort, a, f, 3),
  33200. MMMM: h(f, a),
  33201. D: this.$D,
  33202. DD: g.s(this.$D, 2, "0"),
  33203. d: String(this.$W),
  33204. dd: h(i.weekdaysMin, this.$W, o, 2),
  33205. ddd: h(i.weekdaysShort, this.$W, o, 3),
  33206. dddd: o[this.$W],
  33207. H: String(s),
  33208. HH: g.s(s, 2, "0"),
  33209. h: d(1),
  33210. hh: d(2),
  33211. a: $(s, u, !0),
  33212. A: $(s, u, !1),
  33213. m: String(u),
  33214. mm: g.s(u, 2, "0"),
  33215. s: String(this.$s),
  33216. ss: g.s(this.$s, 2, "0"),
  33217. SSS: g.s(this.$ms, 3, "0"),
  33218. Z: r
  33219. };
  33220. return n.replace(c, function (t, e) {
  33221. return e || l[t] || r.replace(":", "");
  33222. });
  33223. }, $.utcOffset = function () {
  33224. return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
  33225. }, $.diff = function (t, f, h) {
  33226. var c,
  33227. d = g.p(f),
  33228. $ = v(t),
  33229. l = 6e4 * ($.utcOffset() - this.utcOffset()),
  33230. y = this - $,
  33231. M = g.m(this, $);
  33232. 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);
  33233. }, $.daysInMonth = function () {
  33234. return this.endOf(u).$D;
  33235. }, $.$locale = function () {
  33236. return M[this.$L];
  33237. }, $.locale = function (t, e) {
  33238. if (!t) return this.$L;
  33239. var n = this.clone(),
  33240. r = D(t, e, !0);
  33241. return r && (n.$L = r), n;
  33242. }, $.clone = function () {
  33243. return g.w(this.$d, this);
  33244. }, $.toDate = function () {
  33245. return new Date(this.valueOf());
  33246. }, $.toJSON = function () {
  33247. return this.isValid() ? this.toISOString() : null;
  33248. }, $.toISOString = function () {
  33249. return this.$d.toISOString();
  33250. }, $.toString = function () {
  33251. return this.$d.toUTCString();
  33252. }, d;
  33253. }(),
  33254. p = S.prototype;
  33255. return v.prototype = p, [["$ms", t], ["$s", e], ["$m", n], ["$H", r], ["$W", i], ["$M", u], ["$y", o], ["$D", f]].forEach(function (t) {
  33256. p[t[1]] = function (e) {
  33257. return this.$g(e, t[0], t[1]);
  33258. };
  33259. }), v.extend = function (t, e) {
  33260. return t(e, S, v), v;
  33261. }, v.locale = D, v.isDayjs = m, v.unix = function (t) {
  33262. return v(1e3 * t);
  33263. }, v.en = M[y], v.Ls = M, v;
  33264. });
  33265. },{}],228:[function(require,module,exports){
  33266. "use strict";
  33267. 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); }
  33268. !function (t, e) {
  33269. "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();
  33270. }(void 0, function () {
  33271. "use strict";
  33272. var t,
  33273. e = /(\[[^[]*\])|([-:/.()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,
  33274. n = /\d\d/,
  33275. r = /\d\d?/,
  33276. o = /\d*[^\s\d-:/()]+/;
  33277. var i = function i(t) {
  33278. return function (e) {
  33279. this[t] = +e;
  33280. };
  33281. },
  33282. s = [/[+-]\d\d:?\d\d/, function (t) {
  33283. var e, n;
  33284. (this.zone || (this.zone = {})).offset = (e = t.match(/([+-]|\d\d)/g), 0 === (n = 60 * e[1] + +e[2]) ? 0 : "+" === e[0] ? -n : n);
  33285. }],
  33286. a = function a(e) {
  33287. var n = t[e];
  33288. return n && (n.indexOf ? n : n.s.concat(n.f));
  33289. },
  33290. h = {
  33291. A: [/[AP]M/, function (t) {
  33292. this.afternoon = "PM" === t;
  33293. }],
  33294. a: [/[ap]m/, function (t) {
  33295. this.afternoon = "pm" === t;
  33296. }],
  33297. S: [/\d/, function (t) {
  33298. this.milliseconds = 100 * +t;
  33299. }],
  33300. SS: [n, function (t) {
  33301. this.milliseconds = 10 * +t;
  33302. }],
  33303. SSS: [/\d{3}/, function (t) {
  33304. this.milliseconds = +t;
  33305. }],
  33306. s: [r, i("seconds")],
  33307. ss: [r, i("seconds")],
  33308. m: [r, i("minutes")],
  33309. mm: [r, i("minutes")],
  33310. H: [r, i("hours")],
  33311. h: [r, i("hours")],
  33312. HH: [r, i("hours")],
  33313. hh: [r, i("hours")],
  33314. D: [r, i("day")],
  33315. DD: [n, i("day")],
  33316. Do: [o, function (e) {
  33317. var n = t.ordinal,
  33318. r = e.match(/\d+/);
  33319. if (this.day = r[0], n) for (var o = 1; o <= 31; o += 1) {
  33320. n(o).replace(/\[|\]/g, "") === e && (this.day = o);
  33321. }
  33322. }],
  33323. M: [r, i("month")],
  33324. MM: [n, i("month")],
  33325. MMM: [o, function (t) {
  33326. var e = a("months"),
  33327. n = (a("monthsShort") || e.map(function (t) {
  33328. return t.substr(0, 3);
  33329. })).indexOf(t) + 1;
  33330. if (n < 1) throw new Error();
  33331. this.month = n % 12 || n;
  33332. }],
  33333. MMMM: [o, function (t) {
  33334. var e = a("months").indexOf(t) + 1;
  33335. if (e < 1) throw new Error();
  33336. this.month = e % 12 || e;
  33337. }],
  33338. Y: [/[+-]?\d+/, i("year")],
  33339. YY: [n, function (t) {
  33340. t = +t, this.year = t + (t > 68 ? 1900 : 2e3);
  33341. }],
  33342. YYYY: [/\d{4}/, i("year")],
  33343. Z: s,
  33344. ZZ: s
  33345. };
  33346. var f = function f(t, n, r) {
  33347. try {
  33348. var o = function (t) {
  33349. for (var n = t.match(e), r = n.length, o = 0; o < r; o += 1) {
  33350. var i = n[o],
  33351. s = h[i],
  33352. a = s && s[0],
  33353. f = s && s[1];
  33354. n[o] = f ? {
  33355. regex: a,
  33356. parser: f
  33357. } : i.replace(/^\[|\]$/g, "");
  33358. }
  33359. return function (t) {
  33360. for (var e = {}, o = 0, i = 0; o < r; o += 1) {
  33361. var s = n[o];
  33362. if ("string" == typeof s) i += s.length;else {
  33363. var a = s.regex,
  33364. h = s.parser,
  33365. f = t.substr(i),
  33366. u = a.exec(f)[0];
  33367. h.call(e, u), t = t.replace(u, "");
  33368. }
  33369. }
  33370. return function (t) {
  33371. var e = t.afternoon;
  33372. if (void 0 !== e) {
  33373. var n = t.hours;
  33374. e ? n < 12 && (t.hours += 12) : 12 === n && (t.hours = 0), delete t.afternoon;
  33375. }
  33376. }(e), e;
  33377. };
  33378. }(n)(t),
  33379. i = o.year,
  33380. s = o.month,
  33381. a = o.day,
  33382. f = o.hours,
  33383. u = o.minutes,
  33384. d = o.seconds,
  33385. c = o.milliseconds,
  33386. l = o.zone,
  33387. m = new Date(),
  33388. v = a || (i || s ? 1 : m.getDate()),
  33389. p = i || m.getFullYear(),
  33390. y = 0;
  33391. i && !s || (y = s > 0 ? s - 1 : m.getMonth());
  33392. var D = f || 0,
  33393. M = u || 0,
  33394. g = d || 0,
  33395. Y = c || 0;
  33396. 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);
  33397. } catch (t) {
  33398. return new Date("");
  33399. }
  33400. };
  33401. return function (e, n, r) {
  33402. var o = n.prototype,
  33403. i = o.parse;
  33404. o.parse = function (e) {
  33405. var n = e.date,
  33406. o = e.utc,
  33407. s = e.args;
  33408. this.$u = o;
  33409. var a = s[1];
  33410. if ("string" == typeof a) {
  33411. var h = !0 === s[2],
  33412. u = !0 === s[3],
  33413. d = h || u,
  33414. c = s[2];
  33415. 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(""));
  33416. } else if (a instanceof Array) for (var l = a.length, m = 1; m <= l; m += 1) {
  33417. s[1] = a[m - 1];
  33418. var v = r.apply(this, s);
  33419. if (v.isValid()) {
  33420. this.$d = v.$d, this.$L = v.$L, this.init();
  33421. break;
  33422. }
  33423. m === l && (this.$d = new Date(""));
  33424. } else i.call(this, e);
  33425. };
  33426. };
  33427. });
  33428. },{}],229:[function(require,module,exports){
  33429. "use strict";
  33430. 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); }
  33431. !function (t, i) {
  33432. "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();
  33433. }(void 0, function () {
  33434. "use strict";
  33435. return function (t, i, e) {
  33436. var s = new Date().getTimezoneOffset(),
  33437. n = i.prototype;
  33438. e.utc = function (t) {
  33439. return new i({
  33440. date: t,
  33441. utc: !0,
  33442. args: arguments
  33443. });
  33444. }, n.utc = function () {
  33445. return e(this.toDate(), {
  33446. locale: this.$L,
  33447. utc: !0
  33448. });
  33449. }, n.local = function () {
  33450. return e(this.toDate(), {
  33451. locale: this.$L,
  33452. utc: !1
  33453. });
  33454. };
  33455. var u = n.parse;
  33456. n.parse = function (t) {
  33457. t.utc && (this.$u = !0), this.$utils().u(t.$offset) || (this.$offset = t.$offset), u.call(this, t);
  33458. };
  33459. var o = n.init;
  33460. n.init = function () {
  33461. if (this.$u) {
  33462. var t = this.$d;
  33463. 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();
  33464. } else o.call(this);
  33465. };
  33466. var f = n.utcOffset;
  33467. n.utcOffset = function (t, i) {
  33468. var e = this.$utils().u;
  33469. if (e(t)) return this.$u ? 0 : e(this.$offset) ? f.call(this) : this.$offset;
  33470. var n = Math.abs(t) <= 16 ? 60 * t : t,
  33471. u = this;
  33472. 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);
  33473. };
  33474. var r = n.format;
  33475. n.format = function (t) {
  33476. var i = t || (this.$u ? "YYYY-MM-DDTHH:mm:ss[Z]" : "");
  33477. return r.call(this, i);
  33478. }, n.valueOf = function () {
  33479. var t = this.$utils().u(this.$offset) ? 0 : this.$offset + s;
  33480. return this.$d.valueOf() - 6e4 * t;
  33481. }, n.isUTC = function () {
  33482. return !!this.$u;
  33483. }, n.toISOString = function () {
  33484. return this.toDate().toISOString();
  33485. }, n.toString = function () {
  33486. return this.toDate().toUTCString();
  33487. };
  33488. var a = n.toDate;
  33489. n.toDate = function (t) {
  33490. return "s" === t && this.$offset ? e(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate() : a.call(this);
  33491. };
  33492. var c = n.diff;
  33493. n.diff = function (t, i, s) {
  33494. var n = this.local(),
  33495. u = e(t).local();
  33496. return c.call(n, u, i, s);
  33497. };
  33498. };
  33499. });
  33500. },{}],230:[function(require,module,exports){
  33501. 'use strict';
  33502. exports.utils = require('./des/utils');
  33503. exports.Cipher = require('./des/cipher');
  33504. exports.DES = require('./des/des');
  33505. exports.CBC = require('./des/cbc');
  33506. exports.EDE = require('./des/ede');
  33507. },{"./des/cbc":231,"./des/cipher":232,"./des/des":233,"./des/ede":234,"./des/utils":235}],231:[function(require,module,exports){
  33508. 'use strict';
  33509. var assert = require('minimalistic-assert');
  33510. var inherits = require('inherits');
  33511. var proto = {};
  33512. function CBCState(iv) {
  33513. assert.equal(iv.length, 8, 'Invalid IV length');
  33514. this.iv = new Array(8);
  33515. for (var i = 0; i < this.iv.length; i++) {
  33516. this.iv[i] = iv[i];
  33517. }
  33518. }
  33519. function instantiate(Base) {
  33520. function CBC(options) {
  33521. Base.call(this, options);
  33522. this._cbcInit();
  33523. }
  33524. inherits(CBC, Base);
  33525. var keys = Object.keys(proto);
  33526. for (var i = 0; i < keys.length; i++) {
  33527. var key = keys[i];
  33528. CBC.prototype[key] = proto[key];
  33529. }
  33530. CBC.create = function create(options) {
  33531. return new CBC(options);
  33532. };
  33533. return CBC;
  33534. }
  33535. exports.instantiate = instantiate;
  33536. proto._cbcInit = function _cbcInit() {
  33537. var state = new CBCState(this.options.iv);
  33538. this._cbcState = state;
  33539. };
  33540. proto._update = function _update(inp, inOff, out, outOff) {
  33541. var state = this._cbcState;
  33542. var superProto = this.constructor.super_.prototype;
  33543. var iv = state.iv;
  33544. if (this.type === 'encrypt') {
  33545. for (var i = 0; i < this.blockSize; i++) {
  33546. iv[i] ^= inp[inOff + i];
  33547. }
  33548. superProto._update.call(this, iv, 0, out, outOff);
  33549. for (var i = 0; i < this.blockSize; i++) {
  33550. iv[i] = out[outOff + i];
  33551. }
  33552. } else {
  33553. superProto._update.call(this, inp, inOff, out, outOff);
  33554. for (var i = 0; i < this.blockSize; i++) {
  33555. out[outOff + i] ^= iv[i];
  33556. }
  33557. for (var i = 0; i < this.blockSize; i++) {
  33558. iv[i] = inp[inOff + i];
  33559. }
  33560. }
  33561. };
  33562. },{"inherits":278,"minimalistic-assert":328}],232:[function(require,module,exports){
  33563. 'use strict';
  33564. var assert = require('minimalistic-assert');
  33565. function Cipher(options) {
  33566. this.options = options;
  33567. this.type = this.options.type;
  33568. this.blockSize = 8;
  33569. this._init();
  33570. this.buffer = new Array(this.blockSize);
  33571. this.bufferOff = 0;
  33572. }
  33573. module.exports = Cipher;
  33574. Cipher.prototype._init = function _init() {// Might be overrided
  33575. };
  33576. Cipher.prototype.update = function update(data) {
  33577. if (data.length === 0) return [];
  33578. if (this.type === 'decrypt') return this._updateDecrypt(data);else return this._updateEncrypt(data);
  33579. };
  33580. Cipher.prototype._buffer = function _buffer(data, off) {
  33581. // Append data to buffer
  33582. var min = Math.min(this.buffer.length - this.bufferOff, data.length - off);
  33583. for (var i = 0; i < min; i++) {
  33584. this.buffer[this.bufferOff + i] = data[off + i];
  33585. }
  33586. this.bufferOff += min; // Shift next
  33587. return min;
  33588. };
  33589. Cipher.prototype._flushBuffer = function _flushBuffer(out, off) {
  33590. this._update(this.buffer, 0, out, off);
  33591. this.bufferOff = 0;
  33592. return this.blockSize;
  33593. };
  33594. Cipher.prototype._updateEncrypt = function _updateEncrypt(data) {
  33595. var inputOff = 0;
  33596. var outputOff = 0;
  33597. var count = (this.bufferOff + data.length) / this.blockSize | 0;
  33598. var out = new Array(count * this.blockSize);
  33599. if (this.bufferOff !== 0) {
  33600. inputOff += this._buffer(data, inputOff);
  33601. if (this.bufferOff === this.buffer.length) outputOff += this._flushBuffer(out, outputOff);
  33602. } // Write blocks
  33603. var max = data.length - (data.length - inputOff) % this.blockSize;
  33604. for (; inputOff < max; inputOff += this.blockSize) {
  33605. this._update(data, inputOff, out, outputOff);
  33606. outputOff += this.blockSize;
  33607. } // Queue rest
  33608. for (; inputOff < data.length; inputOff++, this.bufferOff++) {
  33609. this.buffer[this.bufferOff] = data[inputOff];
  33610. }
  33611. return out;
  33612. };
  33613. Cipher.prototype._updateDecrypt = function _updateDecrypt(data) {
  33614. var inputOff = 0;
  33615. var outputOff = 0;
  33616. var count = Math.ceil((this.bufferOff + data.length) / this.blockSize) - 1;
  33617. var out = new Array(count * this.blockSize); // TODO(indutny): optimize it, this is far from optimal
  33618. for (; count > 0; count--) {
  33619. inputOff += this._buffer(data, inputOff);
  33620. outputOff += this._flushBuffer(out, outputOff);
  33621. } // Buffer rest of the input
  33622. inputOff += this._buffer(data, inputOff);
  33623. return out;
  33624. };
  33625. Cipher.prototype.final = function final(buffer) {
  33626. var first;
  33627. if (buffer) first = this.update(buffer);
  33628. var last;
  33629. if (this.type === 'encrypt') last = this._finalEncrypt();else last = this._finalDecrypt();
  33630. if (first) return first.concat(last);else return last;
  33631. };
  33632. Cipher.prototype._pad = function _pad(buffer, off) {
  33633. if (off === 0) return false;
  33634. while (off < buffer.length) {
  33635. buffer[off++] = 0;
  33636. }
  33637. return true;
  33638. };
  33639. Cipher.prototype._finalEncrypt = function _finalEncrypt() {
  33640. if (!this._pad(this.buffer, this.bufferOff)) return [];
  33641. var out = new Array(this.blockSize);
  33642. this._update(this.buffer, 0, out, 0);
  33643. return out;
  33644. };
  33645. Cipher.prototype._unpad = function _unpad(buffer) {
  33646. return buffer;
  33647. };
  33648. Cipher.prototype._finalDecrypt = function _finalDecrypt() {
  33649. assert.equal(this.bufferOff, this.blockSize, 'Not enough data to decrypt');
  33650. var out = new Array(this.blockSize);
  33651. this._flushBuffer(out, 0);
  33652. return this._unpad(out);
  33653. };
  33654. },{"minimalistic-assert":328}],233:[function(require,module,exports){
  33655. 'use strict';
  33656. var assert = require('minimalistic-assert');
  33657. var inherits = require('inherits');
  33658. var utils = require('./utils');
  33659. var Cipher = require('./cipher');
  33660. function DESState() {
  33661. this.tmp = new Array(2);
  33662. this.keys = null;
  33663. }
  33664. function DES(options) {
  33665. Cipher.call(this, options);
  33666. var state = new DESState();
  33667. this._desState = state;
  33668. this.deriveKeys(state, options.key);
  33669. }
  33670. inherits(DES, Cipher);
  33671. module.exports = DES;
  33672. DES.create = function create(options) {
  33673. return new DES(options);
  33674. };
  33675. var shiftTable = [1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1];
  33676. DES.prototype.deriveKeys = function deriveKeys(state, key) {
  33677. state.keys = new Array(16 * 2);
  33678. assert.equal(key.length, this.blockSize, 'Invalid key length');
  33679. var kL = utils.readUInt32BE(key, 0);
  33680. var kR = utils.readUInt32BE(key, 4);
  33681. utils.pc1(kL, kR, state.tmp, 0);
  33682. kL = state.tmp[0];
  33683. kR = state.tmp[1];
  33684. for (var i = 0; i < state.keys.length; i += 2) {
  33685. var shift = shiftTable[i >>> 1];
  33686. kL = utils.r28shl(kL, shift);
  33687. kR = utils.r28shl(kR, shift);
  33688. utils.pc2(kL, kR, state.keys, i);
  33689. }
  33690. };
  33691. DES.prototype._update = function _update(inp, inOff, out, outOff) {
  33692. var state = this._desState;
  33693. var l = utils.readUInt32BE(inp, inOff);
  33694. var r = utils.readUInt32BE(inp, inOff + 4); // Initial Permutation
  33695. utils.ip(l, r, state.tmp, 0);
  33696. l = state.tmp[0];
  33697. r = state.tmp[1];
  33698. if (this.type === 'encrypt') this._encrypt(state, l, r, state.tmp, 0);else this._decrypt(state, l, r, state.tmp, 0);
  33699. l = state.tmp[0];
  33700. r = state.tmp[1];
  33701. utils.writeUInt32BE(out, l, outOff);
  33702. utils.writeUInt32BE(out, r, outOff + 4);
  33703. };
  33704. DES.prototype._pad = function _pad(buffer, off) {
  33705. var value = buffer.length - off;
  33706. for (var i = off; i < buffer.length; i++) {
  33707. buffer[i] = value;
  33708. }
  33709. return true;
  33710. };
  33711. DES.prototype._unpad = function _unpad(buffer) {
  33712. var pad = buffer[buffer.length - 1];
  33713. for (var i = buffer.length - pad; i < buffer.length; i++) {
  33714. assert.equal(buffer[i], pad);
  33715. }
  33716. return buffer.slice(0, buffer.length - pad);
  33717. };
  33718. DES.prototype._encrypt = function _encrypt(state, lStart, rStart, out, off) {
  33719. var l = lStart;
  33720. var r = rStart; // Apply f() x16 times
  33721. for (var i = 0; i < state.keys.length; i += 2) {
  33722. var keyL = state.keys[i];
  33723. var keyR = state.keys[i + 1]; // f(r, k)
  33724. utils.expand(r, state.tmp, 0);
  33725. keyL ^= state.tmp[0];
  33726. keyR ^= state.tmp[1];
  33727. var s = utils.substitute(keyL, keyR);
  33728. var f = utils.permute(s);
  33729. var t = r;
  33730. r = (l ^ f) >>> 0;
  33731. l = t;
  33732. } // Reverse Initial Permutation
  33733. utils.rip(r, l, out, off);
  33734. };
  33735. DES.prototype._decrypt = function _decrypt(state, lStart, rStart, out, off) {
  33736. var l = rStart;
  33737. var r = lStart; // Apply f() x16 times
  33738. for (var i = state.keys.length - 2; i >= 0; i -= 2) {
  33739. var keyL = state.keys[i];
  33740. var keyR = state.keys[i + 1]; // f(r, k)
  33741. utils.expand(l, state.tmp, 0);
  33742. keyL ^= state.tmp[0];
  33743. keyR ^= state.tmp[1];
  33744. var s = utils.substitute(keyL, keyR);
  33745. var f = utils.permute(s);
  33746. var t = l;
  33747. l = (r ^ f) >>> 0;
  33748. r = t;
  33749. } // Reverse Initial Permutation
  33750. utils.rip(l, r, out, off);
  33751. };
  33752. },{"./cipher":232,"./utils":235,"inherits":278,"minimalistic-assert":328}],234:[function(require,module,exports){
  33753. 'use strict';
  33754. var assert = require('minimalistic-assert');
  33755. var inherits = require('inherits');
  33756. var Cipher = require('./cipher');
  33757. var DES = require('./des');
  33758. function EDEState(type, key) {
  33759. assert.equal(key.length, 24, 'Invalid key length');
  33760. var k1 = key.slice(0, 8);
  33761. var k2 = key.slice(8, 16);
  33762. var k3 = key.slice(16, 24);
  33763. if (type === 'encrypt') {
  33764. this.ciphers = [DES.create({
  33765. type: 'encrypt',
  33766. key: k1
  33767. }), DES.create({
  33768. type: 'decrypt',
  33769. key: k2
  33770. }), DES.create({
  33771. type: 'encrypt',
  33772. key: k3
  33773. })];
  33774. } else {
  33775. this.ciphers = [DES.create({
  33776. type: 'decrypt',
  33777. key: k3
  33778. }), DES.create({
  33779. type: 'encrypt',
  33780. key: k2
  33781. }), DES.create({
  33782. type: 'decrypt',
  33783. key: k1
  33784. })];
  33785. }
  33786. }
  33787. function EDE(options) {
  33788. Cipher.call(this, options);
  33789. var state = new EDEState(this.type, this.options.key);
  33790. this._edeState = state;
  33791. }
  33792. inherits(EDE, Cipher);
  33793. module.exports = EDE;
  33794. EDE.create = function create(options) {
  33795. return new EDE(options);
  33796. };
  33797. EDE.prototype._update = function _update(inp, inOff, out, outOff) {
  33798. var state = this._edeState;
  33799. state.ciphers[0]._update(inp, inOff, out, outOff);
  33800. state.ciphers[1]._update(out, outOff, out, outOff);
  33801. state.ciphers[2]._update(out, outOff, out, outOff);
  33802. };
  33803. EDE.prototype._pad = DES.prototype._pad;
  33804. EDE.prototype._unpad = DES.prototype._unpad;
  33805. },{"./cipher":232,"./des":233,"inherits":278,"minimalistic-assert":328}],235:[function(require,module,exports){
  33806. 'use strict';
  33807. exports.readUInt32BE = function readUInt32BE(bytes, off) {
  33808. var res = bytes[0 + off] << 24 | bytes[1 + off] << 16 | bytes[2 + off] << 8 | bytes[3 + off];
  33809. return res >>> 0;
  33810. };
  33811. exports.writeUInt32BE = function writeUInt32BE(bytes, value, off) {
  33812. bytes[0 + off] = value >>> 24;
  33813. bytes[1 + off] = value >>> 16 & 0xff;
  33814. bytes[2 + off] = value >>> 8 & 0xff;
  33815. bytes[3 + off] = value & 0xff;
  33816. };
  33817. exports.ip = function ip(inL, inR, out, off) {
  33818. var outL = 0;
  33819. var outR = 0;
  33820. for (var i = 6; i >= 0; i -= 2) {
  33821. for (var j = 0; j <= 24; j += 8) {
  33822. outL <<= 1;
  33823. outL |= inR >>> j + i & 1;
  33824. }
  33825. for (var j = 0; j <= 24; j += 8) {
  33826. outL <<= 1;
  33827. outL |= inL >>> j + i & 1;
  33828. }
  33829. }
  33830. for (var i = 6; i >= 0; i -= 2) {
  33831. for (var j = 1; j <= 25; j += 8) {
  33832. outR <<= 1;
  33833. outR |= inR >>> j + i & 1;
  33834. }
  33835. for (var j = 1; j <= 25; j += 8) {
  33836. outR <<= 1;
  33837. outR |= inL >>> j + i & 1;
  33838. }
  33839. }
  33840. out[off + 0] = outL >>> 0;
  33841. out[off + 1] = outR >>> 0;
  33842. };
  33843. exports.rip = function rip(inL, inR, out, off) {
  33844. var outL = 0;
  33845. var outR = 0;
  33846. for (var i = 0; i < 4; i++) {
  33847. for (var j = 24; j >= 0; j -= 8) {
  33848. outL <<= 1;
  33849. outL |= inR >>> j + i & 1;
  33850. outL <<= 1;
  33851. outL |= inL >>> j + i & 1;
  33852. }
  33853. }
  33854. for (var i = 4; i < 8; i++) {
  33855. for (var j = 24; j >= 0; j -= 8) {
  33856. outR <<= 1;
  33857. outR |= inR >>> j + i & 1;
  33858. outR <<= 1;
  33859. outR |= inL >>> j + i & 1;
  33860. }
  33861. }
  33862. out[off + 0] = outL >>> 0;
  33863. out[off + 1] = outR >>> 0;
  33864. };
  33865. exports.pc1 = function pc1(inL, inR, out, off) {
  33866. var outL = 0;
  33867. var outR = 0; // 7, 15, 23, 31, 39, 47, 55, 63
  33868. // 6, 14, 22, 30, 39, 47, 55, 63
  33869. // 5, 13, 21, 29, 39, 47, 55, 63
  33870. // 4, 12, 20, 28
  33871. for (var i = 7; i >= 5; i--) {
  33872. for (var j = 0; j <= 24; j += 8) {
  33873. outL <<= 1;
  33874. outL |= inR >> j + i & 1;
  33875. }
  33876. for (var j = 0; j <= 24; j += 8) {
  33877. outL <<= 1;
  33878. outL |= inL >> j + i & 1;
  33879. }
  33880. }
  33881. for (var j = 0; j <= 24; j += 8) {
  33882. outL <<= 1;
  33883. outL |= inR >> j + i & 1;
  33884. } // 1, 9, 17, 25, 33, 41, 49, 57
  33885. // 2, 10, 18, 26, 34, 42, 50, 58
  33886. // 3, 11, 19, 27, 35, 43, 51, 59
  33887. // 36, 44, 52, 60
  33888. for (var i = 1; i <= 3; i++) {
  33889. for (var j = 0; j <= 24; j += 8) {
  33890. outR <<= 1;
  33891. outR |= inR >> j + i & 1;
  33892. }
  33893. for (var j = 0; j <= 24; j += 8) {
  33894. outR <<= 1;
  33895. outR |= inL >> j + i & 1;
  33896. }
  33897. }
  33898. for (var j = 0; j <= 24; j += 8) {
  33899. outR <<= 1;
  33900. outR |= inL >> j + i & 1;
  33901. }
  33902. out[off + 0] = outL >>> 0;
  33903. out[off + 1] = outR >>> 0;
  33904. };
  33905. exports.r28shl = function r28shl(num, shift) {
  33906. return num << shift & 0xfffffff | num >>> 28 - shift;
  33907. };
  33908. var pc2table = [// inL => outL
  33909. 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
  33910. 15, 4, 25, 19, 9, 1, 26, 16, 5, 11, 23, 8, 12, 7, 17, 0, 22, 3, 10, 14, 6, 20, 27, 24];
  33911. exports.pc2 = function pc2(inL, inR, out, off) {
  33912. var outL = 0;
  33913. var outR = 0;
  33914. var len = pc2table.length >>> 1;
  33915. for (var i = 0; i < len; i++) {
  33916. outL <<= 1;
  33917. outL |= inL >>> pc2table[i] & 0x1;
  33918. }
  33919. for (var i = len; i < pc2table.length; i++) {
  33920. outR <<= 1;
  33921. outR |= inR >>> pc2table[i] & 0x1;
  33922. }
  33923. out[off + 0] = outL >>> 0;
  33924. out[off + 1] = outR >>> 0;
  33925. };
  33926. exports.expand = function expand(r, out, off) {
  33927. var outL = 0;
  33928. var outR = 0;
  33929. outL = (r & 1) << 5 | r >>> 27;
  33930. for (var i = 23; i >= 15; i -= 4) {
  33931. outL <<= 6;
  33932. outL |= r >>> i & 0x3f;
  33933. }
  33934. for (var i = 11; i >= 3; i -= 4) {
  33935. outR |= r >>> i & 0x3f;
  33936. outR <<= 6;
  33937. }
  33938. outR |= (r & 0x1f) << 1 | r >>> 31;
  33939. out[off + 0] = outL >>> 0;
  33940. out[off + 1] = outR >>> 0;
  33941. };
  33942. 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];
  33943. exports.substitute = function substitute(inL, inR) {
  33944. var out = 0;
  33945. for (var i = 0; i < 4; i++) {
  33946. var b = inL >>> 18 - i * 6 & 0x3f;
  33947. var sb = sTable[i * 0x40 + b];
  33948. out <<= 4;
  33949. out |= sb;
  33950. }
  33951. for (var i = 0; i < 4; i++) {
  33952. var b = inR >>> 18 - i * 6 & 0x3f;
  33953. var sb = sTable[4 * 0x40 + i * 0x40 + b];
  33954. out <<= 4;
  33955. out |= sb;
  33956. }
  33957. return out >>> 0;
  33958. };
  33959. 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];
  33960. exports.permute = function permute(num) {
  33961. var out = 0;
  33962. for (var i = 0; i < permuteTable.length; i++) {
  33963. out <<= 1;
  33964. out |= num >>> permuteTable[i] & 0x1;
  33965. }
  33966. return out >>> 0;
  33967. };
  33968. exports.padSplit = function padSplit(num, size, group) {
  33969. var str = num.toString(2);
  33970. while (str.length < size) {
  33971. str = '0' + str;
  33972. }
  33973. var out = [];
  33974. for (var i = 0; i < size; i += group) {
  33975. out.push(str.slice(i, i + group));
  33976. }
  33977. return out.join(' ');
  33978. };
  33979. },{}],236:[function(require,module,exports){
  33980. (function (Buffer){
  33981. "use strict";
  33982. var generatePrime = require('./lib/generatePrime');
  33983. var primes = require('./lib/primes.json');
  33984. var DH = require('./lib/dh');
  33985. function getDiffieHellman(mod) {
  33986. var prime = new Buffer(primes[mod].prime, 'hex');
  33987. var gen = new Buffer(primes[mod].gen, 'hex');
  33988. return new DH(prime, gen);
  33989. }
  33990. var ENCODINGS = {
  33991. 'binary': true,
  33992. 'hex': true,
  33993. 'base64': true
  33994. };
  33995. function createDiffieHellman(prime, enc, generator, genc) {
  33996. if (Buffer.isBuffer(enc) || ENCODINGS[enc] === undefined) {
  33997. return createDiffieHellman(prime, 'binary', enc, generator);
  33998. }
  33999. enc = enc || 'binary';
  34000. genc = genc || 'binary';
  34001. generator = generator || new Buffer([2]);
  34002. if (!Buffer.isBuffer(generator)) {
  34003. generator = new Buffer(generator, genc);
  34004. }
  34005. if (typeof prime === 'number') {
  34006. return new DH(generatePrime(prime, generator), generator, true);
  34007. }
  34008. if (!Buffer.isBuffer(prime)) {
  34009. prime = new Buffer(prime, enc);
  34010. }
  34011. return new DH(prime, generator, true);
  34012. }
  34013. exports.DiffieHellmanGroup = exports.createDiffieHellmanGroup = exports.getDiffieHellman = getDiffieHellman;
  34014. exports.createDiffieHellman = exports.DiffieHellman = createDiffieHellman;
  34015. }).call(this,require("buffer").Buffer)
  34016. },{"./lib/dh":237,"./lib/generatePrime":238,"./lib/primes.json":239,"buffer":216}],237:[function(require,module,exports){
  34017. (function (Buffer){
  34018. "use strict";
  34019. var BN = require('bn.js');
  34020. var MillerRabin = require('miller-rabin');
  34021. var millerRabin = new MillerRabin();
  34022. var TWENTYFOUR = new BN(24);
  34023. var ELEVEN = new BN(11);
  34024. var TEN = new BN(10);
  34025. var THREE = new BN(3);
  34026. var SEVEN = new BN(7);
  34027. var primes = require('./generatePrime');
  34028. var randomBytes = require('randombytes');
  34029. module.exports = DH;
  34030. function setPublicKey(pub, enc) {
  34031. enc = enc || 'utf8';
  34032. if (!Buffer.isBuffer(pub)) {
  34033. pub = new Buffer(pub, enc);
  34034. }
  34035. this._pub = new BN(pub);
  34036. return this;
  34037. }
  34038. function setPrivateKey(priv, enc) {
  34039. enc = enc || 'utf8';
  34040. if (!Buffer.isBuffer(priv)) {
  34041. priv = new Buffer(priv, enc);
  34042. }
  34043. this._priv = new BN(priv);
  34044. return this;
  34045. }
  34046. var primeCache = {};
  34047. function checkPrime(prime, generator) {
  34048. var gen = generator.toString('hex');
  34049. var hex = [gen, prime.toString(16)].join('_');
  34050. if (hex in primeCache) {
  34051. return primeCache[hex];
  34052. }
  34053. var error = 0;
  34054. if (prime.isEven() || !primes.simpleSieve || !primes.fermatTest(prime) || !millerRabin.test(prime)) {
  34055. //not a prime so +1
  34056. error += 1;
  34057. if (gen === '02' || gen === '05') {
  34058. // we'd be able to check the generator
  34059. // it would fail so +8
  34060. error += 8;
  34061. } else {
  34062. //we wouldn't be able to test the generator
  34063. // so +4
  34064. error += 4;
  34065. }
  34066. primeCache[hex] = error;
  34067. return error;
  34068. }
  34069. if (!millerRabin.test(prime.shrn(1))) {
  34070. //not a safe prime
  34071. error += 2;
  34072. }
  34073. var rem;
  34074. switch (gen) {
  34075. case '02':
  34076. if (prime.mod(TWENTYFOUR).cmp(ELEVEN)) {
  34077. // unsuidable generator
  34078. error += 8;
  34079. }
  34080. break;
  34081. case '05':
  34082. rem = prime.mod(TEN);
  34083. if (rem.cmp(THREE) && rem.cmp(SEVEN)) {
  34084. // prime mod 10 needs to equal 3 or 7
  34085. error += 8;
  34086. }
  34087. break;
  34088. default:
  34089. error += 4;
  34090. }
  34091. primeCache[hex] = error;
  34092. return error;
  34093. }
  34094. function DH(prime, generator, malleable) {
  34095. this.setGenerator(generator);
  34096. this.__prime = new BN(prime);
  34097. this._prime = BN.mont(this.__prime);
  34098. this._primeLen = prime.length;
  34099. this._pub = undefined;
  34100. this._priv = undefined;
  34101. this._primeCode = undefined;
  34102. if (malleable) {
  34103. this.setPublicKey = setPublicKey;
  34104. this.setPrivateKey = setPrivateKey;
  34105. } else {
  34106. this._primeCode = 8;
  34107. }
  34108. }
  34109. Object.defineProperty(DH.prototype, 'verifyError', {
  34110. enumerable: true,
  34111. get: function get() {
  34112. if (typeof this._primeCode !== 'number') {
  34113. this._primeCode = checkPrime(this.__prime, this.__gen);
  34114. }
  34115. return this._primeCode;
  34116. }
  34117. });
  34118. DH.prototype.generateKeys = function () {
  34119. if (!this._priv) {
  34120. this._priv = new BN(randomBytes(this._primeLen));
  34121. }
  34122. this._pub = this._gen.toRed(this._prime).redPow(this._priv).fromRed();
  34123. return this.getPublicKey();
  34124. };
  34125. DH.prototype.computeSecret = function (other) {
  34126. other = new BN(other);
  34127. other = other.toRed(this._prime);
  34128. var secret = other.redPow(this._priv).fromRed();
  34129. var out = new Buffer(secret.toArray());
  34130. var prime = this.getPrime();
  34131. if (out.length < prime.length) {
  34132. var front = new Buffer(prime.length - out.length);
  34133. front.fill(0);
  34134. out = Buffer.concat([front, out]);
  34135. }
  34136. return out;
  34137. };
  34138. DH.prototype.getPublicKey = function getPublicKey(enc) {
  34139. return formatReturnValue(this._pub, enc);
  34140. };
  34141. DH.prototype.getPrivateKey = function getPrivateKey(enc) {
  34142. return formatReturnValue(this._priv, enc);
  34143. };
  34144. DH.prototype.getPrime = function (enc) {
  34145. return formatReturnValue(this.__prime, enc);
  34146. };
  34147. DH.prototype.getGenerator = function (enc) {
  34148. return formatReturnValue(this._gen, enc);
  34149. };
  34150. DH.prototype.setGenerator = function (gen, enc) {
  34151. enc = enc || 'utf8';
  34152. if (!Buffer.isBuffer(gen)) {
  34153. gen = new Buffer(gen, enc);
  34154. }
  34155. this.__gen = gen;
  34156. this._gen = new BN(gen);
  34157. return this;
  34158. };
  34159. function formatReturnValue(bn, enc) {
  34160. var buf = new Buffer(bn.toArray());
  34161. if (!enc) {
  34162. return buf;
  34163. } else {
  34164. return buf.toString(enc);
  34165. }
  34166. }
  34167. }).call(this,require("buffer").Buffer)
  34168. },{"./generatePrime":238,"bn.js":240,"buffer":216,"miller-rabin":326,"randombytes":366}],238:[function(require,module,exports){
  34169. "use strict";
  34170. var randomBytes = require('randombytes');
  34171. module.exports = findPrime;
  34172. findPrime.simpleSieve = simpleSieve;
  34173. findPrime.fermatTest = fermatTest;
  34174. var BN = require('bn.js');
  34175. var TWENTYFOUR = new BN(24);
  34176. var MillerRabin = require('miller-rabin');
  34177. var millerRabin = new MillerRabin();
  34178. var ONE = new BN(1);
  34179. var TWO = new BN(2);
  34180. var FIVE = new BN(5);
  34181. var SIXTEEN = new BN(16);
  34182. var EIGHT = new BN(8);
  34183. var TEN = new BN(10);
  34184. var THREE = new BN(3);
  34185. var SEVEN = new BN(7);
  34186. var ELEVEN = new BN(11);
  34187. var FOUR = new BN(4);
  34188. var TWELVE = new BN(12);
  34189. var primes = null;
  34190. function _getPrimes() {
  34191. if (primes !== null) return primes;
  34192. var limit = 0x100000;
  34193. var res = [];
  34194. res[0] = 2;
  34195. for (var i = 1, k = 3; k < limit; k += 2) {
  34196. var sqrt = Math.ceil(Math.sqrt(k));
  34197. for (var j = 0; j < i && res[j] <= sqrt; j++) {
  34198. if (k % res[j] === 0) break;
  34199. }
  34200. if (i !== j && res[j] <= sqrt) continue;
  34201. res[i++] = k;
  34202. }
  34203. primes = res;
  34204. return res;
  34205. }
  34206. function simpleSieve(p) {
  34207. var primes = _getPrimes();
  34208. for (var i = 0; i < primes.length; i++) {
  34209. if (p.modn(primes[i]) === 0) {
  34210. if (p.cmpn(primes[i]) === 0) {
  34211. return true;
  34212. } else {
  34213. return false;
  34214. }
  34215. }
  34216. }
  34217. return true;
  34218. }
  34219. function fermatTest(p) {
  34220. var red = BN.mont(p);
  34221. return TWO.toRed(red).redPow(p.subn(1)).fromRed().cmpn(1) === 0;
  34222. }
  34223. function findPrime(bits, gen) {
  34224. if (bits < 16) {
  34225. // this is what openssl does
  34226. if (gen === 2 || gen === 5) {
  34227. return new BN([0x8c, 0x7b]);
  34228. } else {
  34229. return new BN([0x8c, 0x27]);
  34230. }
  34231. }
  34232. gen = new BN(gen);
  34233. var num, n2;
  34234. while (true) {
  34235. num = new BN(randomBytes(Math.ceil(bits / 8)));
  34236. while (num.bitLength() > bits) {
  34237. num.ishrn(1);
  34238. }
  34239. if (num.isEven()) {
  34240. num.iadd(ONE);
  34241. }
  34242. if (!num.testn(1)) {
  34243. num.iadd(TWO);
  34244. }
  34245. if (!gen.cmp(TWO)) {
  34246. while (num.mod(TWENTYFOUR).cmp(ELEVEN)) {
  34247. num.iadd(FOUR);
  34248. }
  34249. } else if (!gen.cmp(FIVE)) {
  34250. while (num.mod(TEN).cmp(THREE)) {
  34251. num.iadd(FOUR);
  34252. }
  34253. }
  34254. n2 = num.shrn(1);
  34255. if (simpleSieve(n2) && simpleSieve(num) && fermatTest(n2) && fermatTest(num) && millerRabin.test(n2) && millerRabin.test(num)) {
  34256. return num;
  34257. }
  34258. }
  34259. }
  34260. },{"bn.js":240,"miller-rabin":326,"randombytes":366}],239:[function(require,module,exports){
  34261. module.exports={
  34262. "modp1": {
  34263. "gen": "02",
  34264. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a63a3620ffffffffffffffff"
  34265. },
  34266. "modp2": {
  34267. "gen": "02",
  34268. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece65381ffffffffffffffff"
  34269. },
  34270. "modp5": {
  34271. "gen": "02",
  34272. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca237327ffffffffffffffff"
  34273. },
  34274. "modp14": {
  34275. "gen": "02",
  34276. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aacaa68ffffffffffffffff"
  34277. },
  34278. "modp15": {
  34279. "gen": "02",
  34280. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a93ad2caffffffffffffffff"
  34281. },
  34282. "modp16": {
  34283. "gen": "02",
  34284. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c934063199ffffffffffffffff"
  34285. },
  34286. "modp17": {
  34287. "gen": "02",
  34288. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dcc4024ffffffffffffffff"
  34289. },
  34290. "modp18": {
  34291. "gen": "02",
  34292. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dbe115974a3926f12fee5e438777cb6a932df8cd8bec4d073b931ba3bc832b68d9dd300741fa7bf8afc47ed2576f6936ba424663aab639c5ae4f5683423b4742bf1c978238f16cbe39d652de3fdb8befc848ad922222e04a4037c0713eb57a81a23f0c73473fc646cea306b4bcbc8862f8385ddfa9d4b7fa2c087e879683303ed5bdd3a062b3cf5b3a278a66d2a13f83f44f82ddf310ee074ab6a364597e899a0255dc164f31cc50846851df9ab48195ded7ea1b1d510bd7ee74d73faf36bc31ecfa268359046f4eb879f924009438b481c6cd7889a002ed5ee382bc9190da6fc026e479558e4475677e9aa9e3050e2765694dfc81f56e880b96e7160c980dd98edd3dfffffffffffffffff"
  34293. }
  34294. }
  34295. },{}],240:[function(require,module,exports){
  34296. arguments[4][181][0].apply(exports,arguments)
  34297. },{"buffer":185,"dup":181}],241:[function(require,module,exports){
  34298. 'use strict';
  34299. var elliptic = exports;
  34300. elliptic.version = require('../package.json').version;
  34301. elliptic.utils = require('./elliptic/utils');
  34302. elliptic.rand = require('brorand');
  34303. elliptic.curve = require('./elliptic/curve');
  34304. elliptic.curves = require('./elliptic/curves'); // Protocols
  34305. elliptic.ec = require('./elliptic/ec');
  34306. elliptic.eddsa = require('./elliptic/eddsa');
  34307. },{"../package.json":257,"./elliptic/curve":244,"./elliptic/curves":247,"./elliptic/ec":248,"./elliptic/eddsa":251,"./elliptic/utils":255,"brorand":184}],242:[function(require,module,exports){
  34308. 'use strict';
  34309. var BN = require('bn.js');
  34310. var utils = require('../utils');
  34311. var getNAF = utils.getNAF;
  34312. var getJSF = utils.getJSF;
  34313. var assert = utils.assert;
  34314. function BaseCurve(type, conf) {
  34315. this.type = type;
  34316. this.p = new BN(conf.p, 16); // Use Montgomery, when there is no fast reduction for the prime
  34317. this.red = conf.prime ? BN.red(conf.prime) : BN.mont(this.p); // Useful for many curves
  34318. this.zero = new BN(0).toRed(this.red);
  34319. this.one = new BN(1).toRed(this.red);
  34320. this.two = new BN(2).toRed(this.red); // Curve configuration, optional
  34321. this.n = conf.n && new BN(conf.n, 16);
  34322. this.g = conf.g && this.pointFromJSON(conf.g, conf.gRed); // Temporary arrays
  34323. this._wnafT1 = new Array(4);
  34324. this._wnafT2 = new Array(4);
  34325. this._wnafT3 = new Array(4);
  34326. this._wnafT4 = new Array(4);
  34327. this._bitLength = this.n ? this.n.bitLength() : 0; // Generalized Greg Maxwell's trick
  34328. var adjustCount = this.n && this.p.div(this.n);
  34329. if (!adjustCount || adjustCount.cmpn(100) > 0) {
  34330. this.redN = null;
  34331. } else {
  34332. this._maxwellTrick = true;
  34333. this.redN = this.n.toRed(this.red);
  34334. }
  34335. }
  34336. module.exports = BaseCurve;
  34337. BaseCurve.prototype.point = function point() {
  34338. throw new Error('Not implemented');
  34339. };
  34340. BaseCurve.prototype.validate = function validate() {
  34341. throw new Error('Not implemented');
  34342. };
  34343. BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) {
  34344. assert(p.precomputed);
  34345. var doubles = p._getDoubles();
  34346. var naf = getNAF(k, 1, this._bitLength);
  34347. var I = (1 << doubles.step + 1) - (doubles.step % 2 === 0 ? 2 : 1);
  34348. I /= 3; // Translate into more windowed form
  34349. var repr = [];
  34350. for (var j = 0; j < naf.length; j += doubles.step) {
  34351. var nafW = 0;
  34352. for (var k = j + doubles.step - 1; k >= j; k--) {
  34353. nafW = (nafW << 1) + naf[k];
  34354. }
  34355. repr.push(nafW);
  34356. }
  34357. var a = this.jpoint(null, null, null);
  34358. var b = this.jpoint(null, null, null);
  34359. for (var i = I; i > 0; i--) {
  34360. for (var j = 0; j < repr.length; j++) {
  34361. var nafW = repr[j];
  34362. if (nafW === i) b = b.mixedAdd(doubles.points[j]);else if (nafW === -i) b = b.mixedAdd(doubles.points[j].neg());
  34363. }
  34364. a = a.add(b);
  34365. }
  34366. return a.toP();
  34367. };
  34368. BaseCurve.prototype._wnafMul = function _wnafMul(p, k) {
  34369. var w = 4; // Precompute window
  34370. var nafPoints = p._getNAFPoints(w);
  34371. w = nafPoints.wnd;
  34372. var wnd = nafPoints.points; // Get NAF form
  34373. var naf = getNAF(k, w, this._bitLength); // Add `this`*(N+1) for every w-NAF index
  34374. var acc = this.jpoint(null, null, null);
  34375. for (var i = naf.length - 1; i >= 0; i--) {
  34376. // Count zeroes
  34377. for (var k = 0; i >= 0 && naf[i] === 0; i--) {
  34378. k++;
  34379. }
  34380. if (i >= 0) k++;
  34381. acc = acc.dblp(k);
  34382. if (i < 0) break;
  34383. var z = naf[i];
  34384. assert(z !== 0);
  34385. if (p.type === 'affine') {
  34386. // J +- P
  34387. if (z > 0) acc = acc.mixedAdd(wnd[z - 1 >> 1]);else acc = acc.mixedAdd(wnd[-z - 1 >> 1].neg());
  34388. } else {
  34389. // J +- J
  34390. if (z > 0) acc = acc.add(wnd[z - 1 >> 1]);else acc = acc.add(wnd[-z - 1 >> 1].neg());
  34391. }
  34392. }
  34393. return p.type === 'affine' ? acc.toP() : acc;
  34394. };
  34395. BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW, points, coeffs, len, jacobianResult) {
  34396. var wndWidth = this._wnafT1;
  34397. var wnd = this._wnafT2;
  34398. var naf = this._wnafT3; // Fill all arrays
  34399. var max = 0;
  34400. for (var i = 0; i < len; i++) {
  34401. var p = points[i];
  34402. var nafPoints = p._getNAFPoints(defW);
  34403. wndWidth[i] = nafPoints.wnd;
  34404. wnd[i] = nafPoints.points;
  34405. } // Comb small window NAFs
  34406. for (var i = len - 1; i >= 1; i -= 2) {
  34407. var a = i - 1;
  34408. var b = i;
  34409. if (wndWidth[a] !== 1 || wndWidth[b] !== 1) {
  34410. naf[a] = getNAF(coeffs[a], wndWidth[a], this._bitLength);
  34411. naf[b] = getNAF(coeffs[b], wndWidth[b], this._bitLength);
  34412. max = Math.max(naf[a].length, max);
  34413. max = Math.max(naf[b].length, max);
  34414. continue;
  34415. }
  34416. var comb = [points[a],
  34417. /* 1 */
  34418. null,
  34419. /* 3 */
  34420. null,
  34421. /* 5 */
  34422. points[b]
  34423. /* 7 */
  34424. ]; // Try to avoid Projective points, if possible
  34425. if (points[a].y.cmp(points[b].y) === 0) {
  34426. comb[1] = points[a].add(points[b]);
  34427. comb[2] = points[a].toJ().mixedAdd(points[b].neg());
  34428. } else if (points[a].y.cmp(points[b].y.redNeg()) === 0) {
  34429. comb[1] = points[a].toJ().mixedAdd(points[b]);
  34430. comb[2] = points[a].add(points[b].neg());
  34431. } else {
  34432. comb[1] = points[a].toJ().mixedAdd(points[b]);
  34433. comb[2] = points[a].toJ().mixedAdd(points[b].neg());
  34434. }
  34435. var index = [-3,
  34436. /* -1 -1 */
  34437. -1,
  34438. /* -1 0 */
  34439. -5,
  34440. /* -1 1 */
  34441. -7,
  34442. /* 0 -1 */
  34443. 0,
  34444. /* 0 0 */
  34445. 7,
  34446. /* 0 1 */
  34447. 5,
  34448. /* 1 -1 */
  34449. 1,
  34450. /* 1 0 */
  34451. 3
  34452. /* 1 1 */
  34453. ];
  34454. var jsf = getJSF(coeffs[a], coeffs[b]);
  34455. max = Math.max(jsf[0].length, max);
  34456. naf[a] = new Array(max);
  34457. naf[b] = new Array(max);
  34458. for (var j = 0; j < max; j++) {
  34459. var ja = jsf[0][j] | 0;
  34460. var jb = jsf[1][j] | 0;
  34461. naf[a][j] = index[(ja + 1) * 3 + (jb + 1)];
  34462. naf[b][j] = 0;
  34463. wnd[a] = comb;
  34464. }
  34465. }
  34466. var acc = this.jpoint(null, null, null);
  34467. var tmp = this._wnafT4;
  34468. for (var i = max; i >= 0; i--) {
  34469. var k = 0;
  34470. while (i >= 0) {
  34471. var zero = true;
  34472. for (var j = 0; j < len; j++) {
  34473. tmp[j] = naf[j][i] | 0;
  34474. if (tmp[j] !== 0) zero = false;
  34475. }
  34476. if (!zero) break;
  34477. k++;
  34478. i--;
  34479. }
  34480. if (i >= 0) k++;
  34481. acc = acc.dblp(k);
  34482. if (i < 0) break;
  34483. for (var j = 0; j < len; j++) {
  34484. var z = tmp[j];
  34485. var p;
  34486. 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();
  34487. if (p.type === 'affine') acc = acc.mixedAdd(p);else acc = acc.add(p);
  34488. }
  34489. } // Zeroify references
  34490. for (var i = 0; i < len; i++) {
  34491. wnd[i] = null;
  34492. }
  34493. if (jacobianResult) return acc;else return acc.toP();
  34494. };
  34495. function BasePoint(curve, type) {
  34496. this.curve = curve;
  34497. this.type = type;
  34498. this.precomputed = null;
  34499. }
  34500. BaseCurve.BasePoint = BasePoint;
  34501. BasePoint.prototype.eq = function eq()
  34502. /*other*/
  34503. {
  34504. throw new Error('Not implemented');
  34505. };
  34506. BasePoint.prototype.validate = function validate() {
  34507. return this.curve.validate(this);
  34508. };
  34509. BaseCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
  34510. bytes = utils.toArray(bytes, enc);
  34511. var len = this.p.byteLength(); // uncompressed, hybrid-odd, hybrid-even
  34512. if ((bytes[0] === 0x04 || bytes[0] === 0x06 || bytes[0] === 0x07) && bytes.length - 1 === 2 * len) {
  34513. if (bytes[0] === 0x06) assert(bytes[bytes.length - 1] % 2 === 0);else if (bytes[0] === 0x07) assert(bytes[bytes.length - 1] % 2 === 1);
  34514. var res = this.point(bytes.slice(1, 1 + len), bytes.slice(1 + len, 1 + 2 * len));
  34515. return res;
  34516. } else if ((bytes[0] === 0x02 || bytes[0] === 0x03) && bytes.length - 1 === len) {
  34517. return this.pointFromX(bytes.slice(1, 1 + len), bytes[0] === 0x03);
  34518. }
  34519. throw new Error('Unknown point format');
  34520. };
  34521. BasePoint.prototype.encodeCompressed = function encodeCompressed(enc) {
  34522. return this.encode(enc, true);
  34523. };
  34524. BasePoint.prototype._encode = function _encode(compact) {
  34525. var len = this.curve.p.byteLength();
  34526. var x = this.getX().toArray('be', len);
  34527. if (compact) return [this.getY().isEven() ? 0x02 : 0x03].concat(x);
  34528. return [0x04].concat(x, this.getY().toArray('be', len));
  34529. };
  34530. BasePoint.prototype.encode = function encode(enc, compact) {
  34531. return utils.encode(this._encode(compact), enc);
  34532. };
  34533. BasePoint.prototype.precompute = function precompute(power) {
  34534. if (this.precomputed) return this;
  34535. var precomputed = {
  34536. doubles: null,
  34537. naf: null,
  34538. beta: null
  34539. };
  34540. precomputed.naf = this._getNAFPoints(8);
  34541. precomputed.doubles = this._getDoubles(4, power);
  34542. precomputed.beta = this._getBeta();
  34543. this.precomputed = precomputed;
  34544. return this;
  34545. };
  34546. BasePoint.prototype._hasDoubles = function _hasDoubles(k) {
  34547. if (!this.precomputed) return false;
  34548. var doubles = this.precomputed.doubles;
  34549. if (!doubles) return false;
  34550. return doubles.points.length >= Math.ceil((k.bitLength() + 1) / doubles.step);
  34551. };
  34552. BasePoint.prototype._getDoubles = function _getDoubles(step, power) {
  34553. if (this.precomputed && this.precomputed.doubles) return this.precomputed.doubles;
  34554. var doubles = [this];
  34555. var acc = this;
  34556. for (var i = 0; i < power; i += step) {
  34557. for (var j = 0; j < step; j++) {
  34558. acc = acc.dbl();
  34559. }
  34560. doubles.push(acc);
  34561. }
  34562. return {
  34563. step: step,
  34564. points: doubles
  34565. };
  34566. };
  34567. BasePoint.prototype._getNAFPoints = function _getNAFPoints(wnd) {
  34568. if (this.precomputed && this.precomputed.naf) return this.precomputed.naf;
  34569. var res = [this];
  34570. var max = (1 << wnd) - 1;
  34571. var dbl = max === 1 ? null : this.dbl();
  34572. for (var i = 1; i < max; i++) {
  34573. res[i] = res[i - 1].add(dbl);
  34574. }
  34575. return {
  34576. wnd: wnd,
  34577. points: res
  34578. };
  34579. };
  34580. BasePoint.prototype._getBeta = function _getBeta() {
  34581. return null;
  34582. };
  34583. BasePoint.prototype.dblp = function dblp(k) {
  34584. var r = this;
  34585. for (var i = 0; i < k; i++) {
  34586. r = r.dbl();
  34587. }
  34588. return r;
  34589. };
  34590. },{"../utils":255,"bn.js":256}],243:[function(require,module,exports){
  34591. 'use strict';
  34592. var utils = require('../utils');
  34593. var BN = require('bn.js');
  34594. var inherits = require('inherits');
  34595. var Base = require('./base');
  34596. var assert = utils.assert;
  34597. function EdwardsCurve(conf) {
  34598. // NOTE: Important as we are creating point in Base.call()
  34599. this.twisted = (conf.a | 0) !== 1;
  34600. this.mOneA = this.twisted && (conf.a | 0) === -1;
  34601. this.extended = this.mOneA;
  34602. Base.call(this, 'edwards', conf);
  34603. this.a = new BN(conf.a, 16).umod(this.red.m);
  34604. this.a = this.a.toRed(this.red);
  34605. this.c = new BN(conf.c, 16).toRed(this.red);
  34606. this.c2 = this.c.redSqr();
  34607. this.d = new BN(conf.d, 16).toRed(this.red);
  34608. this.dd = this.d.redAdd(this.d);
  34609. assert(!this.twisted || this.c.fromRed().cmpn(1) === 0);
  34610. this.oneC = (conf.c | 0) === 1;
  34611. }
  34612. inherits(EdwardsCurve, Base);
  34613. module.exports = EdwardsCurve;
  34614. EdwardsCurve.prototype._mulA = function _mulA(num) {
  34615. if (this.mOneA) return num.redNeg();else return this.a.redMul(num);
  34616. };
  34617. EdwardsCurve.prototype._mulC = function _mulC(num) {
  34618. if (this.oneC) return num;else return this.c.redMul(num);
  34619. }; // Just for compatibility with Short curve
  34620. EdwardsCurve.prototype.jpoint = function jpoint(x, y, z, t) {
  34621. return this.point(x, y, z, t);
  34622. };
  34623. EdwardsCurve.prototype.pointFromX = function pointFromX(x, odd) {
  34624. x = new BN(x, 16);
  34625. if (!x.red) x = x.toRed(this.red);
  34626. var x2 = x.redSqr();
  34627. var rhs = this.c2.redSub(this.a.redMul(x2));
  34628. var lhs = this.one.redSub(this.c2.redMul(this.d).redMul(x2));
  34629. var y2 = rhs.redMul(lhs.redInvm());
  34630. var y = y2.redSqrt();
  34631. if (y.redSqr().redSub(y2).cmp(this.zero) !== 0) throw new Error('invalid point');
  34632. var isOdd = y.fromRed().isOdd();
  34633. if (odd && !isOdd || !odd && isOdd) y = y.redNeg();
  34634. return this.point(x, y);
  34635. };
  34636. EdwardsCurve.prototype.pointFromY = function pointFromY(y, odd) {
  34637. y = new BN(y, 16);
  34638. if (!y.red) y = y.toRed(this.red); // x^2 = (y^2 - c^2) / (c^2 d y^2 - a)
  34639. var y2 = y.redSqr();
  34640. var lhs = y2.redSub(this.c2);
  34641. var rhs = y2.redMul(this.d).redMul(this.c2).redSub(this.a);
  34642. var x2 = lhs.redMul(rhs.redInvm());
  34643. if (x2.cmp(this.zero) === 0) {
  34644. if (odd) throw new Error('invalid point');else return this.point(this.zero, y);
  34645. }
  34646. var x = x2.redSqrt();
  34647. if (x.redSqr().redSub(x2).cmp(this.zero) !== 0) throw new Error('invalid point');
  34648. if (x.fromRed().isOdd() !== odd) x = x.redNeg();
  34649. return this.point(x, y);
  34650. };
  34651. EdwardsCurve.prototype.validate = function validate(point) {
  34652. if (point.isInfinity()) return true; // Curve: A * X^2 + Y^2 = C^2 * (1 + D * X^2 * Y^2)
  34653. point.normalize();
  34654. var x2 = point.x.redSqr();
  34655. var y2 = point.y.redSqr();
  34656. var lhs = x2.redMul(this.a).redAdd(y2);
  34657. var rhs = this.c2.redMul(this.one.redAdd(this.d.redMul(x2).redMul(y2)));
  34658. return lhs.cmp(rhs) === 0;
  34659. };
  34660. function Point(curve, x, y, z, t) {
  34661. Base.BasePoint.call(this, curve, 'projective');
  34662. if (x === null && y === null && z === null) {
  34663. this.x = this.curve.zero;
  34664. this.y = this.curve.one;
  34665. this.z = this.curve.one;
  34666. this.t = this.curve.zero;
  34667. this.zOne = true;
  34668. } else {
  34669. this.x = new BN(x, 16);
  34670. this.y = new BN(y, 16);
  34671. this.z = z ? new BN(z, 16) : this.curve.one;
  34672. this.t = t && new BN(t, 16);
  34673. if (!this.x.red) this.x = this.x.toRed(this.curve.red);
  34674. if (!this.y.red) this.y = this.y.toRed(this.curve.red);
  34675. if (!this.z.red) this.z = this.z.toRed(this.curve.red);
  34676. if (this.t && !this.t.red) this.t = this.t.toRed(this.curve.red);
  34677. this.zOne = this.z === this.curve.one; // Use extended coordinates
  34678. if (this.curve.extended && !this.t) {
  34679. this.t = this.x.redMul(this.y);
  34680. if (!this.zOne) this.t = this.t.redMul(this.z.redInvm());
  34681. }
  34682. }
  34683. }
  34684. inherits(Point, Base.BasePoint);
  34685. EdwardsCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
  34686. return Point.fromJSON(this, obj);
  34687. };
  34688. EdwardsCurve.prototype.point = function point(x, y, z, t) {
  34689. return new Point(this, x, y, z, t);
  34690. };
  34691. Point.fromJSON = function fromJSON(curve, obj) {
  34692. return new Point(curve, obj[0], obj[1], obj[2]);
  34693. };
  34694. Point.prototype.inspect = function inspect() {
  34695. if (this.isInfinity()) return '<EC Point Infinity>';
  34696. return '<EC Point x: ' + this.x.fromRed().toString(16, 2) + ' y: ' + this.y.fromRed().toString(16, 2) + ' z: ' + this.z.fromRed().toString(16, 2) + '>';
  34697. };
  34698. Point.prototype.isInfinity = function isInfinity() {
  34699. // XXX This code assumes that zero is always zero in red
  34700. return this.x.cmpn(0) === 0 && (this.y.cmp(this.z) === 0 || this.zOne && this.y.cmp(this.curve.c) === 0);
  34701. };
  34702. Point.prototype._extDbl = function _extDbl() {
  34703. // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
  34704. // #doubling-dbl-2008-hwcd
  34705. // 4M + 4S
  34706. // A = X1^2
  34707. var a = this.x.redSqr(); // B = Y1^2
  34708. var b = this.y.redSqr(); // C = 2 * Z1^2
  34709. var c = this.z.redSqr();
  34710. c = c.redIAdd(c); // D = a * A
  34711. var d = this.curve._mulA(a); // E = (X1 + Y1)^2 - A - B
  34712. var e = this.x.redAdd(this.y).redSqr().redISub(a).redISub(b); // G = D + B
  34713. var g = d.redAdd(b); // F = G - C
  34714. var f = g.redSub(c); // H = D - B
  34715. var h = d.redSub(b); // X3 = E * F
  34716. var nx = e.redMul(f); // Y3 = G * H
  34717. var ny = g.redMul(h); // T3 = E * H
  34718. var nt = e.redMul(h); // Z3 = F * G
  34719. var nz = f.redMul(g);
  34720. return this.curve.point(nx, ny, nz, nt);
  34721. };
  34722. Point.prototype._projDbl = function _projDbl() {
  34723. // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
  34724. // #doubling-dbl-2008-bbjlp
  34725. // #doubling-dbl-2007-bl
  34726. // and others
  34727. // Generally 3M + 4S or 2M + 4S
  34728. // B = (X1 + Y1)^2
  34729. var b = this.x.redAdd(this.y).redSqr(); // C = X1^2
  34730. var c = this.x.redSqr(); // D = Y1^2
  34731. var d = this.y.redSqr();
  34732. var nx;
  34733. var ny;
  34734. var nz;
  34735. if (this.curve.twisted) {
  34736. // E = a * C
  34737. var e = this.curve._mulA(c); // F = E + D
  34738. var f = e.redAdd(d);
  34739. if (this.zOne) {
  34740. // X3 = (B - C - D) * (F - 2)
  34741. nx = b.redSub(c).redSub(d).redMul(f.redSub(this.curve.two)); // Y3 = F * (E - D)
  34742. ny = f.redMul(e.redSub(d)); // Z3 = F^2 - 2 * F
  34743. nz = f.redSqr().redSub(f).redSub(f);
  34744. } else {
  34745. // H = Z1^2
  34746. var h = this.z.redSqr(); // J = F - 2 * H
  34747. var j = f.redSub(h).redISub(h); // X3 = (B-C-D)*J
  34748. nx = b.redSub(c).redISub(d).redMul(j); // Y3 = F * (E - D)
  34749. ny = f.redMul(e.redSub(d)); // Z3 = F * J
  34750. nz = f.redMul(j);
  34751. }
  34752. } else {
  34753. // E = C + D
  34754. var e = c.redAdd(d); // H = (c * Z1)^2
  34755. var h = this.curve._mulC(this.z).redSqr(); // J = E - 2 * H
  34756. var j = e.redSub(h).redSub(h); // X3 = c * (B - E) * J
  34757. nx = this.curve._mulC(b.redISub(e)).redMul(j); // Y3 = c * E * (C - D)
  34758. ny = this.curve._mulC(e).redMul(c.redISub(d)); // Z3 = E * J
  34759. nz = e.redMul(j);
  34760. }
  34761. return this.curve.point(nx, ny, nz);
  34762. };
  34763. Point.prototype.dbl = function dbl() {
  34764. if (this.isInfinity()) return this; // Double in extended coordinates
  34765. if (this.curve.extended) return this._extDbl();else return this._projDbl();
  34766. };
  34767. Point.prototype._extAdd = function _extAdd(p) {
  34768. // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
  34769. // #addition-add-2008-hwcd-3
  34770. // 8M
  34771. // A = (Y1 - X1) * (Y2 - X2)
  34772. var a = this.y.redSub(this.x).redMul(p.y.redSub(p.x)); // B = (Y1 + X1) * (Y2 + X2)
  34773. var b = this.y.redAdd(this.x).redMul(p.y.redAdd(p.x)); // C = T1 * k * T2
  34774. var c = this.t.redMul(this.curve.dd).redMul(p.t); // D = Z1 * 2 * Z2
  34775. var d = this.z.redMul(p.z.redAdd(p.z)); // E = B - A
  34776. var e = b.redSub(a); // F = D - C
  34777. var f = d.redSub(c); // G = D + C
  34778. var g = d.redAdd(c); // H = B + A
  34779. var h = b.redAdd(a); // X3 = E * F
  34780. var nx = e.redMul(f); // Y3 = G * H
  34781. var ny = g.redMul(h); // T3 = E * H
  34782. var nt = e.redMul(h); // Z3 = F * G
  34783. var nz = f.redMul(g);
  34784. return this.curve.point(nx, ny, nz, nt);
  34785. };
  34786. Point.prototype._projAdd = function _projAdd(p) {
  34787. // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
  34788. // #addition-add-2008-bbjlp
  34789. // #addition-add-2007-bl
  34790. // 10M + 1S
  34791. // A = Z1 * Z2
  34792. var a = this.z.redMul(p.z); // B = A^2
  34793. var b = a.redSqr(); // C = X1 * X2
  34794. var c = this.x.redMul(p.x); // D = Y1 * Y2
  34795. var d = this.y.redMul(p.y); // E = d * C * D
  34796. var e = this.curve.d.redMul(c).redMul(d); // F = B - E
  34797. var f = b.redSub(e); // G = B + E
  34798. var g = b.redAdd(e); // X3 = A * F * ((X1 + Y1) * (X2 + Y2) - C - D)
  34799. var tmp = this.x.redAdd(this.y).redMul(p.x.redAdd(p.y)).redISub(c).redISub(d);
  34800. var nx = a.redMul(f).redMul(tmp);
  34801. var ny;
  34802. var nz;
  34803. if (this.curve.twisted) {
  34804. // Y3 = A * G * (D - a * C)
  34805. ny = a.redMul(g).redMul(d.redSub(this.curve._mulA(c))); // Z3 = F * G
  34806. nz = f.redMul(g);
  34807. } else {
  34808. // Y3 = A * G * (D - C)
  34809. ny = a.redMul(g).redMul(d.redSub(c)); // Z3 = c * F * G
  34810. nz = this.curve._mulC(f).redMul(g);
  34811. }
  34812. return this.curve.point(nx, ny, nz);
  34813. };
  34814. Point.prototype.add = function add(p) {
  34815. if (this.isInfinity()) return p;
  34816. if (p.isInfinity()) return this;
  34817. if (this.curve.extended) return this._extAdd(p);else return this._projAdd(p);
  34818. };
  34819. Point.prototype.mul = function mul(k) {
  34820. if (this._hasDoubles(k)) return this.curve._fixedNafMul(this, k);else return this.curve._wnafMul(this, k);
  34821. };
  34822. Point.prototype.mulAdd = function mulAdd(k1, p, k2) {
  34823. return this.curve._wnafMulAdd(1, [this, p], [k1, k2], 2, false);
  34824. };
  34825. Point.prototype.jmulAdd = function jmulAdd(k1, p, k2) {
  34826. return this.curve._wnafMulAdd(1, [this, p], [k1, k2], 2, true);
  34827. };
  34828. Point.prototype.normalize = function normalize() {
  34829. if (this.zOne) return this; // Normalize coordinates
  34830. var zi = this.z.redInvm();
  34831. this.x = this.x.redMul(zi);
  34832. this.y = this.y.redMul(zi);
  34833. if (this.t) this.t = this.t.redMul(zi);
  34834. this.z = this.curve.one;
  34835. this.zOne = true;
  34836. return this;
  34837. };
  34838. Point.prototype.neg = function neg() {
  34839. return this.curve.point(this.x.redNeg(), this.y, this.z, this.t && this.t.redNeg());
  34840. };
  34841. Point.prototype.getX = function getX() {
  34842. this.normalize();
  34843. return this.x.fromRed();
  34844. };
  34845. Point.prototype.getY = function getY() {
  34846. this.normalize();
  34847. return this.y.fromRed();
  34848. };
  34849. Point.prototype.eq = function eq(other) {
  34850. return this === other || this.getX().cmp(other.getX()) === 0 && this.getY().cmp(other.getY()) === 0;
  34851. };
  34852. Point.prototype.eqXToP = function eqXToP(x) {
  34853. var rx = x.toRed(this.curve.red).redMul(this.z);
  34854. if (this.x.cmp(rx) === 0) return true;
  34855. var xc = x.clone();
  34856. var t = this.curve.redN.redMul(this.z);
  34857. for (;;) {
  34858. xc.iadd(this.curve.n);
  34859. if (xc.cmp(this.curve.p) >= 0) return false;
  34860. rx.redIAdd(t);
  34861. if (this.x.cmp(rx) === 0) return true;
  34862. }
  34863. }; // Compatibility with BaseCurve
  34864. Point.prototype.toP = Point.prototype.normalize;
  34865. Point.prototype.mixedAdd = Point.prototype.add;
  34866. },{"../utils":255,"./base":242,"bn.js":256,"inherits":278}],244:[function(require,module,exports){
  34867. 'use strict';
  34868. var curve = exports;
  34869. curve.base = require('./base');
  34870. curve.short = require('./short');
  34871. curve.mont = require('./mont');
  34872. curve.edwards = require('./edwards');
  34873. },{"./base":242,"./edwards":243,"./mont":245,"./short":246}],245:[function(require,module,exports){
  34874. 'use strict';
  34875. var BN = require('bn.js');
  34876. var inherits = require('inherits');
  34877. var Base = require('./base');
  34878. var utils = require('../utils');
  34879. function MontCurve(conf) {
  34880. Base.call(this, 'mont', conf);
  34881. this.a = new BN(conf.a, 16).toRed(this.red);
  34882. this.b = new BN(conf.b, 16).toRed(this.red);
  34883. this.i4 = new BN(4).toRed(this.red).redInvm();
  34884. this.two = new BN(2).toRed(this.red);
  34885. this.a24 = this.i4.redMul(this.a.redAdd(this.two));
  34886. }
  34887. inherits(MontCurve, Base);
  34888. module.exports = MontCurve;
  34889. MontCurve.prototype.validate = function validate(point) {
  34890. var x = point.normalize().x;
  34891. var x2 = x.redSqr();
  34892. var rhs = x2.redMul(x).redAdd(x2.redMul(this.a)).redAdd(x);
  34893. var y = rhs.redSqrt();
  34894. return y.redSqr().cmp(rhs) === 0;
  34895. };
  34896. function Point(curve, x, z) {
  34897. Base.BasePoint.call(this, curve, 'projective');
  34898. if (x === null && z === null) {
  34899. this.x = this.curve.one;
  34900. this.z = this.curve.zero;
  34901. } else {
  34902. this.x = new BN(x, 16);
  34903. this.z = new BN(z, 16);
  34904. if (!this.x.red) this.x = this.x.toRed(this.curve.red);
  34905. if (!this.z.red) this.z = this.z.toRed(this.curve.red);
  34906. }
  34907. }
  34908. inherits(Point, Base.BasePoint);
  34909. MontCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
  34910. return this.point(utils.toArray(bytes, enc), 1);
  34911. };
  34912. MontCurve.prototype.point = function point(x, z) {
  34913. return new Point(this, x, z);
  34914. };
  34915. MontCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
  34916. return Point.fromJSON(this, obj);
  34917. };
  34918. Point.prototype.precompute = function precompute() {// No-op
  34919. };
  34920. Point.prototype._encode = function _encode() {
  34921. return this.getX().toArray('be', this.curve.p.byteLength());
  34922. };
  34923. Point.fromJSON = function fromJSON(curve, obj) {
  34924. return new Point(curve, obj[0], obj[1] || curve.one);
  34925. };
  34926. Point.prototype.inspect = function inspect() {
  34927. if (this.isInfinity()) return '<EC Point Infinity>';
  34928. return '<EC Point x: ' + this.x.fromRed().toString(16, 2) + ' z: ' + this.z.fromRed().toString(16, 2) + '>';
  34929. };
  34930. Point.prototype.isInfinity = function isInfinity() {
  34931. // XXX This code assumes that zero is always zero in red
  34932. return this.z.cmpn(0) === 0;
  34933. };
  34934. Point.prototype.dbl = function dbl() {
  34935. // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#doubling-dbl-1987-m-3
  34936. // 2M + 2S + 4A
  34937. // A = X1 + Z1
  34938. var a = this.x.redAdd(this.z); // AA = A^2
  34939. var aa = a.redSqr(); // B = X1 - Z1
  34940. var b = this.x.redSub(this.z); // BB = B^2
  34941. var bb = b.redSqr(); // C = AA - BB
  34942. var c = aa.redSub(bb); // X3 = AA * BB
  34943. var nx = aa.redMul(bb); // Z3 = C * (BB + A24 * C)
  34944. var nz = c.redMul(bb.redAdd(this.curve.a24.redMul(c)));
  34945. return this.curve.point(nx, nz);
  34946. };
  34947. Point.prototype.add = function add() {
  34948. throw new Error('Not supported on Montgomery curve');
  34949. };
  34950. Point.prototype.diffAdd = function diffAdd(p, diff) {
  34951. // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#diffadd-dadd-1987-m-3
  34952. // 4M + 2S + 6A
  34953. // A = X2 + Z2
  34954. var a = this.x.redAdd(this.z); // B = X2 - Z2
  34955. var b = this.x.redSub(this.z); // C = X3 + Z3
  34956. var c = p.x.redAdd(p.z); // D = X3 - Z3
  34957. var d = p.x.redSub(p.z); // DA = D * A
  34958. var da = d.redMul(a); // CB = C * B
  34959. var cb = c.redMul(b); // X5 = Z1 * (DA + CB)^2
  34960. var nx = diff.z.redMul(da.redAdd(cb).redSqr()); // Z5 = X1 * (DA - CB)^2
  34961. var nz = diff.x.redMul(da.redISub(cb).redSqr());
  34962. return this.curve.point(nx, nz);
  34963. };
  34964. Point.prototype.mul = function mul(k) {
  34965. var t = k.clone();
  34966. var a = this; // (N / 2) * Q + Q
  34967. var b = this.curve.point(null, null); // (N / 2) * Q
  34968. var c = this; // Q
  34969. for (var bits = []; t.cmpn(0) !== 0; t.iushrn(1)) {
  34970. bits.push(t.andln(1));
  34971. }
  34972. for (var i = bits.length - 1; i >= 0; i--) {
  34973. if (bits[i] === 0) {
  34974. // N * Q + Q = ((N / 2) * Q + Q)) + (N / 2) * Q
  34975. a = a.diffAdd(b, c); // N * Q = 2 * ((N / 2) * Q + Q))
  34976. b = b.dbl();
  34977. } else {
  34978. // N * Q = ((N / 2) * Q + Q) + ((N / 2) * Q)
  34979. b = a.diffAdd(b, c); // N * Q + Q = 2 * ((N / 2) * Q + Q)
  34980. a = a.dbl();
  34981. }
  34982. }
  34983. return b;
  34984. };
  34985. Point.prototype.mulAdd = function mulAdd() {
  34986. throw new Error('Not supported on Montgomery curve');
  34987. };
  34988. Point.prototype.jumlAdd = function jumlAdd() {
  34989. throw new Error('Not supported on Montgomery curve');
  34990. };
  34991. Point.prototype.eq = function eq(other) {
  34992. return this.getX().cmp(other.getX()) === 0;
  34993. };
  34994. Point.prototype.normalize = function normalize() {
  34995. this.x = this.x.redMul(this.z.redInvm());
  34996. this.z = this.curve.one;
  34997. return this;
  34998. };
  34999. Point.prototype.getX = function getX() {
  35000. // Normalize coordinates
  35001. this.normalize();
  35002. return this.x.fromRed();
  35003. };
  35004. },{"../utils":255,"./base":242,"bn.js":256,"inherits":278}],246:[function(require,module,exports){
  35005. 'use strict';
  35006. var utils = require('../utils');
  35007. var BN = require('bn.js');
  35008. var inherits = require('inherits');
  35009. var Base = require('./base');
  35010. var assert = utils.assert;
  35011. function ShortCurve(conf) {
  35012. Base.call(this, 'short', conf);
  35013. this.a = new BN(conf.a, 16).toRed(this.red);
  35014. this.b = new BN(conf.b, 16).toRed(this.red);
  35015. this.tinv = this.two.redInvm();
  35016. this.zeroA = this.a.fromRed().cmpn(0) === 0;
  35017. this.threeA = this.a.fromRed().sub(this.p).cmpn(-3) === 0; // If the curve is endomorphic, precalculate beta and lambda
  35018. this.endo = this._getEndomorphism(conf);
  35019. this._endoWnafT1 = new Array(4);
  35020. this._endoWnafT2 = new Array(4);
  35021. }
  35022. inherits(ShortCurve, Base);
  35023. module.exports = ShortCurve;
  35024. ShortCurve.prototype._getEndomorphism = function _getEndomorphism(conf) {
  35025. // No efficient endomorphism
  35026. if (!this.zeroA || !this.g || !this.n || this.p.modn(3) !== 1) return; // Compute beta and lambda, that lambda * P = (beta * Px; Py)
  35027. var beta;
  35028. var lambda;
  35029. if (conf.beta) {
  35030. beta = new BN(conf.beta, 16).toRed(this.red);
  35031. } else {
  35032. var betas = this._getEndoRoots(this.p); // Choose the smallest beta
  35033. beta = betas[0].cmp(betas[1]) < 0 ? betas[0] : betas[1];
  35034. beta = beta.toRed(this.red);
  35035. }
  35036. if (conf.lambda) {
  35037. lambda = new BN(conf.lambda, 16);
  35038. } else {
  35039. // Choose the lambda that is matching selected beta
  35040. var lambdas = this._getEndoRoots(this.n);
  35041. if (this.g.mul(lambdas[0]).x.cmp(this.g.x.redMul(beta)) === 0) {
  35042. lambda = lambdas[0];
  35043. } else {
  35044. lambda = lambdas[1];
  35045. assert(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta)) === 0);
  35046. }
  35047. } // Get basis vectors, used for balanced length-two representation
  35048. var basis;
  35049. if (conf.basis) {
  35050. basis = conf.basis.map(function (vec) {
  35051. return {
  35052. a: new BN(vec.a, 16),
  35053. b: new BN(vec.b, 16)
  35054. };
  35055. });
  35056. } else {
  35057. basis = this._getEndoBasis(lambda);
  35058. }
  35059. return {
  35060. beta: beta,
  35061. lambda: lambda,
  35062. basis: basis
  35063. };
  35064. };
  35065. ShortCurve.prototype._getEndoRoots = function _getEndoRoots(num) {
  35066. // Find roots of for x^2 + x + 1 in F
  35067. // Root = (-1 +- Sqrt(-3)) / 2
  35068. //
  35069. var red = num === this.p ? this.red : BN.mont(num);
  35070. var tinv = new BN(2).toRed(red).redInvm();
  35071. var ntinv = tinv.redNeg();
  35072. var s = new BN(3).toRed(red).redNeg().redSqrt().redMul(tinv);
  35073. var l1 = ntinv.redAdd(s).fromRed();
  35074. var l2 = ntinv.redSub(s).fromRed();
  35075. return [l1, l2];
  35076. };
  35077. ShortCurve.prototype._getEndoBasis = function _getEndoBasis(lambda) {
  35078. // aprxSqrt >= sqrt(this.n)
  35079. var aprxSqrt = this.n.ushrn(Math.floor(this.n.bitLength() / 2)); // 3.74
  35080. // Run EGCD, until r(L + 1) < aprxSqrt
  35081. var u = lambda;
  35082. var v = this.n.clone();
  35083. var x1 = new BN(1);
  35084. var y1 = new BN(0);
  35085. var x2 = new BN(0);
  35086. var y2 = new BN(1); // NOTE: all vectors are roots of: a + b * lambda = 0 (mod n)
  35087. var a0;
  35088. var b0; // First vector
  35089. var a1;
  35090. var b1; // Second vector
  35091. var a2;
  35092. var b2;
  35093. var prevR;
  35094. var i = 0;
  35095. var r;
  35096. var x;
  35097. while (u.cmpn(0) !== 0) {
  35098. var q = v.div(u);
  35099. r = v.sub(q.mul(u));
  35100. x = x2.sub(q.mul(x1));
  35101. var y = y2.sub(q.mul(y1));
  35102. if (!a1 && r.cmp(aprxSqrt) < 0) {
  35103. a0 = prevR.neg();
  35104. b0 = x1;
  35105. a1 = r.neg();
  35106. b1 = x;
  35107. } else if (a1 && ++i === 2) {
  35108. break;
  35109. }
  35110. prevR = r;
  35111. v = u;
  35112. u = r;
  35113. x2 = x1;
  35114. x1 = x;
  35115. y2 = y1;
  35116. y1 = y;
  35117. }
  35118. a2 = r.neg();
  35119. b2 = x;
  35120. var len1 = a1.sqr().add(b1.sqr());
  35121. var len2 = a2.sqr().add(b2.sqr());
  35122. if (len2.cmp(len1) >= 0) {
  35123. a2 = a0;
  35124. b2 = b0;
  35125. } // Normalize signs
  35126. if (a1.negative) {
  35127. a1 = a1.neg();
  35128. b1 = b1.neg();
  35129. }
  35130. if (a2.negative) {
  35131. a2 = a2.neg();
  35132. b2 = b2.neg();
  35133. }
  35134. return [{
  35135. a: a1,
  35136. b: b1
  35137. }, {
  35138. a: a2,
  35139. b: b2
  35140. }];
  35141. };
  35142. ShortCurve.prototype._endoSplit = function _endoSplit(k) {
  35143. var basis = this.endo.basis;
  35144. var v1 = basis[0];
  35145. var v2 = basis[1];
  35146. var c1 = v2.b.mul(k).divRound(this.n);
  35147. var c2 = v1.b.neg().mul(k).divRound(this.n);
  35148. var p1 = c1.mul(v1.a);
  35149. var p2 = c2.mul(v2.a);
  35150. var q1 = c1.mul(v1.b);
  35151. var q2 = c2.mul(v2.b); // Calculate answer
  35152. var k1 = k.sub(p1).sub(p2);
  35153. var k2 = q1.add(q2).neg();
  35154. return {
  35155. k1: k1,
  35156. k2: k2
  35157. };
  35158. };
  35159. ShortCurve.prototype.pointFromX = function pointFromX(x, odd) {
  35160. x = new BN(x, 16);
  35161. if (!x.red) x = x.toRed(this.red);
  35162. var y2 = x.redSqr().redMul(x).redIAdd(x.redMul(this.a)).redIAdd(this.b);
  35163. var y = y2.redSqrt();
  35164. 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
  35165. // to non-red form?
  35166. var isOdd = y.fromRed().isOdd();
  35167. if (odd && !isOdd || !odd && isOdd) y = y.redNeg();
  35168. return this.point(x, y);
  35169. };
  35170. ShortCurve.prototype.validate = function validate(point) {
  35171. if (point.inf) return true;
  35172. var x = point.x;
  35173. var y = point.y;
  35174. var ax = this.a.redMul(x);
  35175. var rhs = x.redSqr().redMul(x).redIAdd(ax).redIAdd(this.b);
  35176. return y.redSqr().redISub(rhs).cmpn(0) === 0;
  35177. };
  35178. ShortCurve.prototype._endoWnafMulAdd = function _endoWnafMulAdd(points, coeffs, jacobianResult) {
  35179. var npoints = this._endoWnafT1;
  35180. var ncoeffs = this._endoWnafT2;
  35181. for (var i = 0; i < points.length; i++) {
  35182. var split = this._endoSplit(coeffs[i]);
  35183. var p = points[i];
  35184. var beta = p._getBeta();
  35185. if (split.k1.negative) {
  35186. split.k1.ineg();
  35187. p = p.neg(true);
  35188. }
  35189. if (split.k2.negative) {
  35190. split.k2.ineg();
  35191. beta = beta.neg(true);
  35192. }
  35193. npoints[i * 2] = p;
  35194. npoints[i * 2 + 1] = beta;
  35195. ncoeffs[i * 2] = split.k1;
  35196. ncoeffs[i * 2 + 1] = split.k2;
  35197. }
  35198. var res = this._wnafMulAdd(1, npoints, ncoeffs, i * 2, jacobianResult); // Clean-up references to points and coefficients
  35199. for (var j = 0; j < i * 2; j++) {
  35200. npoints[j] = null;
  35201. ncoeffs[j] = null;
  35202. }
  35203. return res;
  35204. };
  35205. function Point(curve, x, y, isRed) {
  35206. Base.BasePoint.call(this, curve, 'affine');
  35207. if (x === null && y === null) {
  35208. this.x = null;
  35209. this.y = null;
  35210. this.inf = true;
  35211. } else {
  35212. this.x = new BN(x, 16);
  35213. this.y = new BN(y, 16); // Force redgomery representation when loading from JSON
  35214. if (isRed) {
  35215. this.x.forceRed(this.curve.red);
  35216. this.y.forceRed(this.curve.red);
  35217. }
  35218. if (!this.x.red) this.x = this.x.toRed(this.curve.red);
  35219. if (!this.y.red) this.y = this.y.toRed(this.curve.red);
  35220. this.inf = false;
  35221. }
  35222. }
  35223. inherits(Point, Base.BasePoint);
  35224. ShortCurve.prototype.point = function point(x, y, isRed) {
  35225. return new Point(this, x, y, isRed);
  35226. };
  35227. ShortCurve.prototype.pointFromJSON = function pointFromJSON(obj, red) {
  35228. return Point.fromJSON(this, obj, red);
  35229. };
  35230. Point.prototype._getBeta = function _getBeta() {
  35231. if (!this.curve.endo) return;
  35232. var pre = this.precomputed;
  35233. if (pre && pre.beta) return pre.beta;
  35234. var beta = this.curve.point(this.x.redMul(this.curve.endo.beta), this.y);
  35235. if (pre) {
  35236. var curve = this.curve;
  35237. var endoMul = function endoMul(p) {
  35238. return curve.point(p.x.redMul(curve.endo.beta), p.y);
  35239. };
  35240. pre.beta = beta;
  35241. beta.precomputed = {
  35242. beta: null,
  35243. naf: pre.naf && {
  35244. wnd: pre.naf.wnd,
  35245. points: pre.naf.points.map(endoMul)
  35246. },
  35247. doubles: pre.doubles && {
  35248. step: pre.doubles.step,
  35249. points: pre.doubles.points.map(endoMul)
  35250. }
  35251. };
  35252. }
  35253. return beta;
  35254. };
  35255. Point.prototype.toJSON = function toJSON() {
  35256. if (!this.precomputed) return [this.x, this.y];
  35257. return [this.x, this.y, this.precomputed && {
  35258. doubles: this.precomputed.doubles && {
  35259. step: this.precomputed.doubles.step,
  35260. points: this.precomputed.doubles.points.slice(1)
  35261. },
  35262. naf: this.precomputed.naf && {
  35263. wnd: this.precomputed.naf.wnd,
  35264. points: this.precomputed.naf.points.slice(1)
  35265. }
  35266. }];
  35267. };
  35268. Point.fromJSON = function fromJSON(curve, obj, red) {
  35269. if (typeof obj === 'string') obj = JSON.parse(obj);
  35270. var res = curve.point(obj[0], obj[1], red);
  35271. if (!obj[2]) return res;
  35272. function obj2point(obj) {
  35273. return curve.point(obj[0], obj[1], red);
  35274. }
  35275. var pre = obj[2];
  35276. res.precomputed = {
  35277. beta: null,
  35278. doubles: pre.doubles && {
  35279. step: pre.doubles.step,
  35280. points: [res].concat(pre.doubles.points.map(obj2point))
  35281. },
  35282. naf: pre.naf && {
  35283. wnd: pre.naf.wnd,
  35284. points: [res].concat(pre.naf.points.map(obj2point))
  35285. }
  35286. };
  35287. return res;
  35288. };
  35289. Point.prototype.inspect = function inspect() {
  35290. if (this.isInfinity()) return '<EC Point Infinity>';
  35291. return '<EC Point x: ' + this.x.fromRed().toString(16, 2) + ' y: ' + this.y.fromRed().toString(16, 2) + '>';
  35292. };
  35293. Point.prototype.isInfinity = function isInfinity() {
  35294. return this.inf;
  35295. };
  35296. Point.prototype.add = function add(p) {
  35297. // O + P = P
  35298. if (this.inf) return p; // P + O = P
  35299. if (p.inf) return this; // P + P = 2P
  35300. if (this.eq(p)) return this.dbl(); // P + (-P) = O
  35301. if (this.neg().eq(p)) return this.curve.point(null, null); // P + Q = O
  35302. if (this.x.cmp(p.x) === 0) return this.curve.point(null, null);
  35303. var c = this.y.redSub(p.y);
  35304. if (c.cmpn(0) !== 0) c = c.redMul(this.x.redSub(p.x).redInvm());
  35305. var nx = c.redSqr().redISub(this.x).redISub(p.x);
  35306. var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
  35307. return this.curve.point(nx, ny);
  35308. };
  35309. Point.prototype.dbl = function dbl() {
  35310. if (this.inf) return this; // 2P = O
  35311. var ys1 = this.y.redAdd(this.y);
  35312. if (ys1.cmpn(0) === 0) return this.curve.point(null, null);
  35313. var a = this.curve.a;
  35314. var x2 = this.x.redSqr();
  35315. var dyinv = ys1.redInvm();
  35316. var c = x2.redAdd(x2).redIAdd(x2).redIAdd(a).redMul(dyinv);
  35317. var nx = c.redSqr().redISub(this.x.redAdd(this.x));
  35318. var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
  35319. return this.curve.point(nx, ny);
  35320. };
  35321. Point.prototype.getX = function getX() {
  35322. return this.x.fromRed();
  35323. };
  35324. Point.prototype.getY = function getY() {
  35325. return this.y.fromRed();
  35326. };
  35327. Point.prototype.mul = function mul(k) {
  35328. k = new BN(k, 16);
  35329. 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);
  35330. };
  35331. Point.prototype.mulAdd = function mulAdd(k1, p2, k2) {
  35332. var points = [this, p2];
  35333. var coeffs = [k1, k2];
  35334. if (this.curve.endo) return this.curve._endoWnafMulAdd(points, coeffs);else return this.curve._wnafMulAdd(1, points, coeffs, 2);
  35335. };
  35336. Point.prototype.jmulAdd = function jmulAdd(k1, p2, k2) {
  35337. var points = [this, p2];
  35338. var coeffs = [k1, k2];
  35339. if (this.curve.endo) return this.curve._endoWnafMulAdd(points, coeffs, true);else return this.curve._wnafMulAdd(1, points, coeffs, 2, true);
  35340. };
  35341. Point.prototype.eq = function eq(p) {
  35342. return this === p || this.inf === p.inf && (this.inf || this.x.cmp(p.x) === 0 && this.y.cmp(p.y) === 0);
  35343. };
  35344. Point.prototype.neg = function neg(_precompute) {
  35345. if (this.inf) return this;
  35346. var res = this.curve.point(this.x, this.y.redNeg());
  35347. if (_precompute && this.precomputed) {
  35348. var pre = this.precomputed;
  35349. var negate = function negate(p) {
  35350. return p.neg();
  35351. };
  35352. res.precomputed = {
  35353. naf: pre.naf && {
  35354. wnd: pre.naf.wnd,
  35355. points: pre.naf.points.map(negate)
  35356. },
  35357. doubles: pre.doubles && {
  35358. step: pre.doubles.step,
  35359. points: pre.doubles.points.map(negate)
  35360. }
  35361. };
  35362. }
  35363. return res;
  35364. };
  35365. Point.prototype.toJ = function toJ() {
  35366. if (this.inf) return this.curve.jpoint(null, null, null);
  35367. var res = this.curve.jpoint(this.x, this.y, this.curve.one);
  35368. return res;
  35369. };
  35370. function JPoint(curve, x, y, z) {
  35371. Base.BasePoint.call(this, curve, 'jacobian');
  35372. if (x === null && y === null && z === null) {
  35373. this.x = this.curve.one;
  35374. this.y = this.curve.one;
  35375. this.z = new BN(0);
  35376. } else {
  35377. this.x = new BN(x, 16);
  35378. this.y = new BN(y, 16);
  35379. this.z = new BN(z, 16);
  35380. }
  35381. if (!this.x.red) this.x = this.x.toRed(this.curve.red);
  35382. if (!this.y.red) this.y = this.y.toRed(this.curve.red);
  35383. if (!this.z.red) this.z = this.z.toRed(this.curve.red);
  35384. this.zOne = this.z === this.curve.one;
  35385. }
  35386. inherits(JPoint, Base.BasePoint);
  35387. ShortCurve.prototype.jpoint = function jpoint(x, y, z) {
  35388. return new JPoint(this, x, y, z);
  35389. };
  35390. JPoint.prototype.toP = function toP() {
  35391. if (this.isInfinity()) return this.curve.point(null, null);
  35392. var zinv = this.z.redInvm();
  35393. var zinv2 = zinv.redSqr();
  35394. var ax = this.x.redMul(zinv2);
  35395. var ay = this.y.redMul(zinv2).redMul(zinv);
  35396. return this.curve.point(ax, ay);
  35397. };
  35398. JPoint.prototype.neg = function neg() {
  35399. return this.curve.jpoint(this.x, this.y.redNeg(), this.z);
  35400. };
  35401. JPoint.prototype.add = function add(p) {
  35402. // O + P = P
  35403. if (this.isInfinity()) return p; // P + O = P
  35404. if (p.isInfinity()) return this; // 12M + 4S + 7A
  35405. var pz2 = p.z.redSqr();
  35406. var z2 = this.z.redSqr();
  35407. var u1 = this.x.redMul(pz2);
  35408. var u2 = p.x.redMul(z2);
  35409. var s1 = this.y.redMul(pz2.redMul(p.z));
  35410. var s2 = p.y.redMul(z2.redMul(this.z));
  35411. var h = u1.redSub(u2);
  35412. var r = s1.redSub(s2);
  35413. if (h.cmpn(0) === 0) {
  35414. if (r.cmpn(0) !== 0) return this.curve.jpoint(null, null, null);else return this.dbl();
  35415. }
  35416. var h2 = h.redSqr();
  35417. var h3 = h2.redMul(h);
  35418. var v = u1.redMul(h2);
  35419. var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
  35420. var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
  35421. var nz = this.z.redMul(p.z).redMul(h);
  35422. return this.curve.jpoint(nx, ny, nz);
  35423. };
  35424. JPoint.prototype.mixedAdd = function mixedAdd(p) {
  35425. // O + P = P
  35426. if (this.isInfinity()) return p.toJ(); // P + O = P
  35427. if (p.isInfinity()) return this; // 8M + 3S + 7A
  35428. var z2 = this.z.redSqr();
  35429. var u1 = this.x;
  35430. var u2 = p.x.redMul(z2);
  35431. var s1 = this.y;
  35432. var s2 = p.y.redMul(z2).redMul(this.z);
  35433. var h = u1.redSub(u2);
  35434. var r = s1.redSub(s2);
  35435. if (h.cmpn(0) === 0) {
  35436. if (r.cmpn(0) !== 0) return this.curve.jpoint(null, null, null);else return this.dbl();
  35437. }
  35438. var h2 = h.redSqr();
  35439. var h3 = h2.redMul(h);
  35440. var v = u1.redMul(h2);
  35441. var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
  35442. var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
  35443. var nz = this.z.redMul(h);
  35444. return this.curve.jpoint(nx, ny, nz);
  35445. };
  35446. JPoint.prototype.dblp = function dblp(pow) {
  35447. if (pow === 0) return this;
  35448. if (this.isInfinity()) return this;
  35449. if (!pow) return this.dbl();
  35450. if (this.curve.zeroA || this.curve.threeA) {
  35451. var r = this;
  35452. for (var i = 0; i < pow; i++) {
  35453. r = r.dbl();
  35454. }
  35455. return r;
  35456. } // 1M + 2S + 1A + N * (4S + 5M + 8A)
  35457. // N = 1 => 6M + 6S + 9A
  35458. var a = this.curve.a;
  35459. var tinv = this.curve.tinv;
  35460. var jx = this.x;
  35461. var jy = this.y;
  35462. var jz = this.z;
  35463. var jz4 = jz.redSqr().redSqr(); // Reuse results
  35464. var jyd = jy.redAdd(jy);
  35465. for (var i = 0; i < pow; i++) {
  35466. var jx2 = jx.redSqr();
  35467. var jyd2 = jyd.redSqr();
  35468. var jyd4 = jyd2.redSqr();
  35469. var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
  35470. var t1 = jx.redMul(jyd2);
  35471. var nx = c.redSqr().redISub(t1.redAdd(t1));
  35472. var t2 = t1.redISub(nx);
  35473. var dny = c.redMul(t2);
  35474. dny = dny.redIAdd(dny).redISub(jyd4);
  35475. var nz = jyd.redMul(jz);
  35476. if (i + 1 < pow) jz4 = jz4.redMul(jyd4);
  35477. jx = nx;
  35478. jz = nz;
  35479. jyd = dny;
  35480. }
  35481. return this.curve.jpoint(jx, jyd.redMul(tinv), jz);
  35482. };
  35483. JPoint.prototype.dbl = function dbl() {
  35484. if (this.isInfinity()) return this;
  35485. if (this.curve.zeroA) return this._zeroDbl();else if (this.curve.threeA) return this._threeDbl();else return this._dbl();
  35486. };
  35487. JPoint.prototype._zeroDbl = function _zeroDbl() {
  35488. var nx;
  35489. var ny;
  35490. var nz; // Z = 1
  35491. if (this.zOne) {
  35492. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
  35493. // #doubling-mdbl-2007-bl
  35494. // 1M + 5S + 14A
  35495. // XX = X1^2
  35496. var xx = this.x.redSqr(); // YY = Y1^2
  35497. var yy = this.y.redSqr(); // YYYY = YY^2
  35498. var yyyy = yy.redSqr(); // S = 2 * ((X1 + YY)^2 - XX - YYYY)
  35499. var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
  35500. s = s.redIAdd(s); // M = 3 * XX + a; a = 0
  35501. var m = xx.redAdd(xx).redIAdd(xx); // T = M ^ 2 - 2*S
  35502. var t = m.redSqr().redISub(s).redISub(s); // 8 * YYYY
  35503. var yyyy8 = yyyy.redIAdd(yyyy);
  35504. yyyy8 = yyyy8.redIAdd(yyyy8);
  35505. yyyy8 = yyyy8.redIAdd(yyyy8); // X3 = T
  35506. nx = t; // Y3 = M * (S - T) - 8 * YYYY
  35507. ny = m.redMul(s.redISub(t)).redISub(yyyy8); // Z3 = 2*Y1
  35508. nz = this.y.redAdd(this.y);
  35509. } else {
  35510. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
  35511. // #doubling-dbl-2009-l
  35512. // 2M + 5S + 13A
  35513. // A = X1^2
  35514. var a = this.x.redSqr(); // B = Y1^2
  35515. var b = this.y.redSqr(); // C = B^2
  35516. var c = b.redSqr(); // D = 2 * ((X1 + B)^2 - A - C)
  35517. var d = this.x.redAdd(b).redSqr().redISub(a).redISub(c);
  35518. d = d.redIAdd(d); // E = 3 * A
  35519. var e = a.redAdd(a).redIAdd(a); // F = E^2
  35520. var f = e.redSqr(); // 8 * C
  35521. var c8 = c.redIAdd(c);
  35522. c8 = c8.redIAdd(c8);
  35523. c8 = c8.redIAdd(c8); // X3 = F - 2 * D
  35524. nx = f.redISub(d).redISub(d); // Y3 = E * (D - X3) - 8 * C
  35525. ny = e.redMul(d.redISub(nx)).redISub(c8); // Z3 = 2 * Y1 * Z1
  35526. nz = this.y.redMul(this.z);
  35527. nz = nz.redIAdd(nz);
  35528. }
  35529. return this.curve.jpoint(nx, ny, nz);
  35530. };
  35531. JPoint.prototype._threeDbl = function _threeDbl() {
  35532. var nx;
  35533. var ny;
  35534. var nz; // Z = 1
  35535. if (this.zOne) {
  35536. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html
  35537. // #doubling-mdbl-2007-bl
  35538. // 1M + 5S + 15A
  35539. // XX = X1^2
  35540. var xx = this.x.redSqr(); // YY = Y1^2
  35541. var yy = this.y.redSqr(); // YYYY = YY^2
  35542. var yyyy = yy.redSqr(); // S = 2 * ((X1 + YY)^2 - XX - YYYY)
  35543. var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
  35544. s = s.redIAdd(s); // M = 3 * XX + a
  35545. var m = xx.redAdd(xx).redIAdd(xx).redIAdd(this.curve.a); // T = M^2 - 2 * S
  35546. var t = m.redSqr().redISub(s).redISub(s); // X3 = T
  35547. nx = t; // Y3 = M * (S - T) - 8 * YYYY
  35548. var yyyy8 = yyyy.redIAdd(yyyy);
  35549. yyyy8 = yyyy8.redIAdd(yyyy8);
  35550. yyyy8 = yyyy8.redIAdd(yyyy8);
  35551. ny = m.redMul(s.redISub(t)).redISub(yyyy8); // Z3 = 2 * Y1
  35552. nz = this.y.redAdd(this.y);
  35553. } else {
  35554. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#doubling-dbl-2001-b
  35555. // 3M + 5S
  35556. // delta = Z1^2
  35557. var delta = this.z.redSqr(); // gamma = Y1^2
  35558. var gamma = this.y.redSqr(); // beta = X1 * gamma
  35559. var beta = this.x.redMul(gamma); // alpha = 3 * (X1 - delta) * (X1 + delta)
  35560. var alpha = this.x.redSub(delta).redMul(this.x.redAdd(delta));
  35561. alpha = alpha.redAdd(alpha).redIAdd(alpha); // X3 = alpha^2 - 8 * beta
  35562. var beta4 = beta.redIAdd(beta);
  35563. beta4 = beta4.redIAdd(beta4);
  35564. var beta8 = beta4.redAdd(beta4);
  35565. nx = alpha.redSqr().redISub(beta8); // Z3 = (Y1 + Z1)^2 - gamma - delta
  35566. nz = this.y.redAdd(this.z).redSqr().redISub(gamma).redISub(delta); // Y3 = alpha * (4 * beta - X3) - 8 * gamma^2
  35567. var ggamma8 = gamma.redSqr();
  35568. ggamma8 = ggamma8.redIAdd(ggamma8);
  35569. ggamma8 = ggamma8.redIAdd(ggamma8);
  35570. ggamma8 = ggamma8.redIAdd(ggamma8);
  35571. ny = alpha.redMul(beta4.redISub(nx)).redISub(ggamma8);
  35572. }
  35573. return this.curve.jpoint(nx, ny, nz);
  35574. };
  35575. JPoint.prototype._dbl = function _dbl() {
  35576. var a = this.curve.a; // 4M + 6S + 10A
  35577. var jx = this.x;
  35578. var jy = this.y;
  35579. var jz = this.z;
  35580. var jz4 = jz.redSqr().redSqr();
  35581. var jx2 = jx.redSqr();
  35582. var jy2 = jy.redSqr();
  35583. var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
  35584. var jxd4 = jx.redAdd(jx);
  35585. jxd4 = jxd4.redIAdd(jxd4);
  35586. var t1 = jxd4.redMul(jy2);
  35587. var nx = c.redSqr().redISub(t1.redAdd(t1));
  35588. var t2 = t1.redISub(nx);
  35589. var jyd8 = jy2.redSqr();
  35590. jyd8 = jyd8.redIAdd(jyd8);
  35591. jyd8 = jyd8.redIAdd(jyd8);
  35592. jyd8 = jyd8.redIAdd(jyd8);
  35593. var ny = c.redMul(t2).redISub(jyd8);
  35594. var nz = jy.redAdd(jy).redMul(jz);
  35595. return this.curve.jpoint(nx, ny, nz);
  35596. };
  35597. JPoint.prototype.trpl = function trpl() {
  35598. if (!this.curve.zeroA) return this.dbl().add(this); // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#tripling-tpl-2007-bl
  35599. // 5M + 10S + ...
  35600. // XX = X1^2
  35601. var xx = this.x.redSqr(); // YY = Y1^2
  35602. var yy = this.y.redSqr(); // ZZ = Z1^2
  35603. var zz = this.z.redSqr(); // YYYY = YY^2
  35604. var yyyy = yy.redSqr(); // M = 3 * XX + a * ZZ2; a = 0
  35605. var m = xx.redAdd(xx).redIAdd(xx); // MM = M^2
  35606. var mm = m.redSqr(); // E = 6 * ((X1 + YY)^2 - XX - YYYY) - MM
  35607. var e = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
  35608. e = e.redIAdd(e);
  35609. e = e.redAdd(e).redIAdd(e);
  35610. e = e.redISub(mm); // EE = E^2
  35611. var ee = e.redSqr(); // T = 16*YYYY
  35612. var t = yyyy.redIAdd(yyyy);
  35613. t = t.redIAdd(t);
  35614. t = t.redIAdd(t);
  35615. t = t.redIAdd(t); // U = (M + E)^2 - MM - EE - T
  35616. var u = m.redIAdd(e).redSqr().redISub(mm).redISub(ee).redISub(t); // X3 = 4 * (X1 * EE - 4 * YY * U)
  35617. var yyu4 = yy.redMul(u);
  35618. yyu4 = yyu4.redIAdd(yyu4);
  35619. yyu4 = yyu4.redIAdd(yyu4);
  35620. var nx = this.x.redMul(ee).redISub(yyu4);
  35621. nx = nx.redIAdd(nx);
  35622. nx = nx.redIAdd(nx); // Y3 = 8 * Y1 * (U * (T - U) - E * EE)
  35623. var ny = this.y.redMul(u.redMul(t.redISub(u)).redISub(e.redMul(ee)));
  35624. ny = ny.redIAdd(ny);
  35625. ny = ny.redIAdd(ny);
  35626. ny = ny.redIAdd(ny); // Z3 = (Z1 + E)^2 - ZZ - EE
  35627. var nz = this.z.redAdd(e).redSqr().redISub(zz).redISub(ee);
  35628. return this.curve.jpoint(nx, ny, nz);
  35629. };
  35630. JPoint.prototype.mul = function mul(k, kbase) {
  35631. k = new BN(k, kbase);
  35632. return this.curve._wnafMul(this, k);
  35633. };
  35634. JPoint.prototype.eq = function eq(p) {
  35635. if (p.type === 'affine') return this.eq(p.toJ());
  35636. if (this === p) return true; // x1 * z2^2 == x2 * z1^2
  35637. var z2 = this.z.redSqr();
  35638. var pz2 = p.z.redSqr();
  35639. if (this.x.redMul(pz2).redISub(p.x.redMul(z2)).cmpn(0) !== 0) return false; // y1 * z2^3 == y2 * z1^3
  35640. var z3 = z2.redMul(this.z);
  35641. var pz3 = pz2.redMul(p.z);
  35642. return this.y.redMul(pz3).redISub(p.y.redMul(z3)).cmpn(0) === 0;
  35643. };
  35644. JPoint.prototype.eqXToP = function eqXToP(x) {
  35645. var zs = this.z.redSqr();
  35646. var rx = x.toRed(this.curve.red).redMul(zs);
  35647. if (this.x.cmp(rx) === 0) return true;
  35648. var xc = x.clone();
  35649. var t = this.curve.redN.redMul(zs);
  35650. for (;;) {
  35651. xc.iadd(this.curve.n);
  35652. if (xc.cmp(this.curve.p) >= 0) return false;
  35653. rx.redIAdd(t);
  35654. if (this.x.cmp(rx) === 0) return true;
  35655. }
  35656. };
  35657. JPoint.prototype.inspect = function inspect() {
  35658. if (this.isInfinity()) return '<EC JPoint Infinity>';
  35659. return '<EC JPoint x: ' + this.x.toString(16, 2) + ' y: ' + this.y.toString(16, 2) + ' z: ' + this.z.toString(16, 2) + '>';
  35660. };
  35661. JPoint.prototype.isInfinity = function isInfinity() {
  35662. // XXX This code assumes that zero is always zero in red
  35663. return this.z.cmpn(0) === 0;
  35664. };
  35665. },{"../utils":255,"./base":242,"bn.js":256,"inherits":278}],247:[function(require,module,exports){
  35666. 'use strict';
  35667. var curves = exports;
  35668. var hash = require('hash.js');
  35669. var curve = require('./curve');
  35670. var utils = require('./utils');
  35671. var assert = utils.assert;
  35672. function PresetCurve(options) {
  35673. 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);
  35674. this.g = this.curve.g;
  35675. this.n = this.curve.n;
  35676. this.hash = options.hash;
  35677. assert(this.g.validate(), 'Invalid curve');
  35678. assert(this.g.mul(this.n).isInfinity(), 'Invalid curve, G*N != O');
  35679. }
  35680. curves.PresetCurve = PresetCurve;
  35681. function defineCurve(name, options) {
  35682. Object.defineProperty(curves, name, {
  35683. configurable: true,
  35684. enumerable: true,
  35685. get: function get() {
  35686. var curve = new PresetCurve(options);
  35687. Object.defineProperty(curves, name, {
  35688. configurable: true,
  35689. enumerable: true,
  35690. value: curve
  35691. });
  35692. return curve;
  35693. }
  35694. });
  35695. }
  35696. defineCurve('p192', {
  35697. type: 'short',
  35698. prime: 'p192',
  35699. p: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff',
  35700. a: 'ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc',
  35701. b: '64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1',
  35702. n: 'ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831',
  35703. hash: hash.sha256,
  35704. gRed: false,
  35705. g: ['188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012', '07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811']
  35706. });
  35707. defineCurve('p224', {
  35708. type: 'short',
  35709. prime: 'p224',
  35710. p: 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001',
  35711. a: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe',
  35712. b: 'b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4',
  35713. n: 'ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d',
  35714. hash: hash.sha256,
  35715. gRed: false,
  35716. g: ['b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21', 'bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34']
  35717. });
  35718. defineCurve('p256', {
  35719. type: 'short',
  35720. prime: null,
  35721. p: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff',
  35722. a: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc',
  35723. b: '5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b',
  35724. n: 'ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551',
  35725. hash: hash.sha256,
  35726. gRed: false,
  35727. g: ['6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296', '4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5']
  35728. });
  35729. defineCurve('p384', {
  35730. type: 'short',
  35731. prime: null,
  35732. p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'fffffffe ffffffff 00000000 00000000 ffffffff',
  35733. a: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'fffffffe ffffffff 00000000 00000000 fffffffc',
  35734. b: 'b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f ' + '5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef',
  35735. n: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 ' + 'f4372ddf 581a0db2 48b0a77a ecec196a ccc52973',
  35736. hash: hash.sha384,
  35737. gRed: false,
  35738. 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']
  35739. });
  35740. defineCurve('p521', {
  35741. type: 'short',
  35742. prime: null,
  35743. p: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'ffffffff ffffffff ffffffff ffffffff ffffffff',
  35744. a: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'ffffffff ffffffff ffffffff ffffffff fffffffc',
  35745. b: '00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b ' + '99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd ' + '3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00',
  35746. n: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 ' + 'f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409',
  35747. hash: hash.sha512,
  35748. gRed: false,
  35749. 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']
  35750. });
  35751. defineCurve('curve25519', {
  35752. type: 'mont',
  35753. prime: 'p25519',
  35754. p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
  35755. a: '76d06',
  35756. b: '1',
  35757. n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
  35758. hash: hash.sha256,
  35759. gRed: false,
  35760. g: ['9']
  35761. });
  35762. defineCurve('ed25519', {
  35763. type: 'edwards',
  35764. prime: 'p25519',
  35765. p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
  35766. a: '-1',
  35767. c: '1',
  35768. // -121665 * (121666^(-1)) (mod P)
  35769. d: '52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3',
  35770. n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
  35771. hash: hash.sha256,
  35772. gRed: false,
  35773. g: ['216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a', // 4/5
  35774. '6666666666666666666666666666666666666666666666666666666666666658']
  35775. });
  35776. var pre;
  35777. try {
  35778. pre = require('./precomputed/secp256k1');
  35779. } catch (e) {
  35780. pre = undefined;
  35781. }
  35782. defineCurve('secp256k1', {
  35783. type: 'short',
  35784. prime: 'k256',
  35785. p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f',
  35786. a: '0',
  35787. b: '7',
  35788. n: 'ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141',
  35789. h: '1',
  35790. hash: hash.sha256,
  35791. // Precomputed endomorphism
  35792. beta: '7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee',
  35793. lambda: '5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72',
  35794. basis: [{
  35795. a: '3086d221a7d46bcde86c90e49284eb15',
  35796. b: '-e4437ed6010e88286f547fa90abfe4c3'
  35797. }, {
  35798. a: '114ca50f7a8e2f3f657c1108d9d44cfd8',
  35799. b: '3086d221a7d46bcde86c90e49284eb15'
  35800. }],
  35801. gRed: false,
  35802. g: ['79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798', '483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8', pre]
  35803. });
  35804. },{"./curve":244,"./precomputed/secp256k1":254,"./utils":255,"hash.js":263}],248:[function(require,module,exports){
  35805. 'use strict';
  35806. 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); }
  35807. var BN = require('bn.js');
  35808. var HmacDRBG = require('hmac-drbg');
  35809. var utils = require('../utils');
  35810. var curves = require('../curves');
  35811. var rand = require('brorand');
  35812. var assert = utils.assert;
  35813. var KeyPair = require('./key');
  35814. var Signature = require('./signature');
  35815. function EC(options) {
  35816. if (!(this instanceof EC)) return new EC(options); // Shortcut `elliptic.ec(curve-name)`
  35817. if (typeof options === 'string') {
  35818. assert(curves.hasOwnProperty(options), 'Unknown curve ' + options);
  35819. options = curves[options];
  35820. } // Shortcut for `elliptic.ec(elliptic.curves.curveName)`
  35821. if (options instanceof curves.PresetCurve) options = {
  35822. curve: options
  35823. };
  35824. this.curve = options.curve.curve;
  35825. this.n = this.curve.n;
  35826. this.nh = this.n.ushrn(1);
  35827. this.g = this.curve.g; // Point on curve
  35828. this.g = options.curve.g;
  35829. this.g.precompute(options.curve.n.bitLength() + 1); // Hash for function for DRBG
  35830. this.hash = options.hash || options.curve.hash;
  35831. }
  35832. module.exports = EC;
  35833. EC.prototype.keyPair = function keyPair(options) {
  35834. return new KeyPair(this, options);
  35835. };
  35836. EC.prototype.keyFromPrivate = function keyFromPrivate(priv, enc) {
  35837. return KeyPair.fromPrivate(this, priv, enc);
  35838. };
  35839. EC.prototype.keyFromPublic = function keyFromPublic(pub, enc) {
  35840. return KeyPair.fromPublic(this, pub, enc);
  35841. };
  35842. EC.prototype.genKeyPair = function genKeyPair(options) {
  35843. if (!options) options = {}; // Instantiate Hmac_DRBG
  35844. var drbg = new HmacDRBG({
  35845. hash: this.hash,
  35846. pers: options.pers,
  35847. persEnc: options.persEnc || 'utf8',
  35848. entropy: options.entropy || rand(this.hash.hmacStrength),
  35849. entropyEnc: options.entropy && options.entropyEnc || 'utf8',
  35850. nonce: this.n.toArray()
  35851. });
  35852. var bytes = this.n.byteLength();
  35853. var ns2 = this.n.sub(new BN(2));
  35854. do {
  35855. var priv = new BN(drbg.generate(bytes));
  35856. if (priv.cmp(ns2) > 0) continue;
  35857. priv.iaddn(1);
  35858. return this.keyFromPrivate(priv);
  35859. } while (true);
  35860. };
  35861. EC.prototype._truncateToN = function truncateToN(msg, truncOnly) {
  35862. var delta = msg.byteLength() * 8 - this.n.bitLength();
  35863. if (delta > 0) msg = msg.ushrn(delta);
  35864. if (!truncOnly && msg.cmp(this.n) >= 0) return msg.sub(this.n);else return msg;
  35865. };
  35866. EC.prototype.sign = function sign(msg, key, enc, options) {
  35867. if (_typeof(enc) === 'object') {
  35868. options = enc;
  35869. enc = null;
  35870. }
  35871. if (!options) options = {};
  35872. key = this.keyFromPrivate(key, enc);
  35873. msg = this._truncateToN(new BN(msg, 16)); // Zero-extend key to provide enough entropy
  35874. var bytes = this.n.byteLength();
  35875. var bkey = key.getPrivate().toArray('be', bytes); // Zero-extend nonce to have the same byte size as N
  35876. var nonce = msg.toArray('be', bytes); // Instantiate Hmac_DRBG
  35877. var drbg = new HmacDRBG({
  35878. hash: this.hash,
  35879. entropy: bkey,
  35880. nonce: nonce,
  35881. pers: options.pers,
  35882. persEnc: options.persEnc || 'utf8'
  35883. }); // Number of bytes to generate
  35884. var ns1 = this.n.sub(new BN(1));
  35885. for (var iter = 0; true; iter++) {
  35886. var k = options.k ? options.k(iter) : new BN(drbg.generate(this.n.byteLength()));
  35887. k = this._truncateToN(k, true);
  35888. if (k.cmpn(1) <= 0 || k.cmp(ns1) >= 0) continue;
  35889. var kp = this.g.mul(k);
  35890. if (kp.isInfinity()) continue;
  35891. var kpX = kp.getX();
  35892. var r = kpX.umod(this.n);
  35893. if (r.cmpn(0) === 0) continue;
  35894. var s = k.invm(this.n).mul(r.mul(key.getPrivate()).iadd(msg));
  35895. s = s.umod(this.n);
  35896. if (s.cmpn(0) === 0) continue;
  35897. var recoveryParam = (kp.getY().isOdd() ? 1 : 0) | (kpX.cmp(r) !== 0 ? 2 : 0); // Use complement of `s`, if it is > `n / 2`
  35898. if (options.canonical && s.cmp(this.nh) > 0) {
  35899. s = this.n.sub(s);
  35900. recoveryParam ^= 1;
  35901. }
  35902. return new Signature({
  35903. r: r,
  35904. s: s,
  35905. recoveryParam: recoveryParam
  35906. });
  35907. }
  35908. };
  35909. EC.prototype.verify = function verify(msg, signature, key, enc) {
  35910. msg = this._truncateToN(new BN(msg, 16));
  35911. key = this.keyFromPublic(key, enc);
  35912. signature = new Signature(signature, 'hex'); // Perform primitive values validation
  35913. var r = signature.r;
  35914. var s = signature.s;
  35915. if (r.cmpn(1) < 0 || r.cmp(this.n) >= 0) return false;
  35916. if (s.cmpn(1) < 0 || s.cmp(this.n) >= 0) return false; // Validate signature
  35917. var sinv = s.invm(this.n);
  35918. var u1 = sinv.mul(msg).umod(this.n);
  35919. var u2 = sinv.mul(r).umod(this.n);
  35920. if (!this.curve._maxwellTrick) {
  35921. var p = this.g.mulAdd(u1, key.getPublic(), u2);
  35922. if (p.isInfinity()) return false;
  35923. return p.getX().umod(this.n).cmp(r) === 0;
  35924. } // NOTE: Greg Maxwell's trick, inspired by:
  35925. // https://git.io/vad3K
  35926. var p = this.g.jmulAdd(u1, key.getPublic(), u2);
  35927. if (p.isInfinity()) return false; // Compare `p.x` of Jacobian point with `r`,
  35928. // this will do `p.x == r * p.z^2` instead of multiplying `p.x` by the
  35929. // inverse of `p.z^2`
  35930. return p.eqXToP(r);
  35931. };
  35932. EC.prototype.recoverPubKey = function (msg, signature, j, enc) {
  35933. assert((3 & j) === j, 'The recovery param is more than two bits');
  35934. signature = new Signature(signature, enc);
  35935. var n = this.n;
  35936. var e = new BN(msg);
  35937. var r = signature.r;
  35938. var s = signature.s; // A set LSB signifies that the y-coordinate is odd
  35939. var isYOdd = j & 1;
  35940. var isSecondKey = j >> 1;
  35941. 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.
  35942. if (isSecondKey) r = this.curve.pointFromX(r.add(this.curve.n), isYOdd);else r = this.curve.pointFromX(r, isYOdd);
  35943. var rInv = signature.r.invm(n);
  35944. var s1 = n.sub(e).mul(rInv).umod(n);
  35945. var s2 = s.mul(rInv).umod(n); // 1.6.1 Compute Q = r^-1 (sR - eG)
  35946. // Q = r^-1 (sR + -eG)
  35947. return this.g.mulAdd(s1, r, s2);
  35948. };
  35949. EC.prototype.getKeyRecoveryParam = function (e, signature, Q, enc) {
  35950. signature = new Signature(signature, enc);
  35951. if (signature.recoveryParam !== null) return signature.recoveryParam;
  35952. for (var i = 0; i < 4; i++) {
  35953. var Qprime;
  35954. try {
  35955. Qprime = this.recoverPubKey(e, signature, i);
  35956. } catch (e) {
  35957. continue;
  35958. }
  35959. if (Qprime.eq(Q)) return i;
  35960. }
  35961. throw new Error('Unable to find valid recovery factor');
  35962. };
  35963. },{"../curves":247,"../utils":255,"./key":249,"./signature":250,"bn.js":256,"brorand":184,"hmac-drbg":275}],249:[function(require,module,exports){
  35964. 'use strict';
  35965. var BN = require('bn.js');
  35966. var utils = require('../utils');
  35967. var assert = utils.assert;
  35968. function KeyPair(ec, options) {
  35969. this.ec = ec;
  35970. this.priv = null;
  35971. this.pub = null; // KeyPair(ec, { priv: ..., pub: ... })
  35972. if (options.priv) this._importPrivate(options.priv, options.privEnc);
  35973. if (options.pub) this._importPublic(options.pub, options.pubEnc);
  35974. }
  35975. module.exports = KeyPair;
  35976. KeyPair.fromPublic = function fromPublic(ec, pub, enc) {
  35977. if (pub instanceof KeyPair) return pub;
  35978. return new KeyPair(ec, {
  35979. pub: pub,
  35980. pubEnc: enc
  35981. });
  35982. };
  35983. KeyPair.fromPrivate = function fromPrivate(ec, priv, enc) {
  35984. if (priv instanceof KeyPair) return priv;
  35985. return new KeyPair(ec, {
  35986. priv: priv,
  35987. privEnc: enc
  35988. });
  35989. };
  35990. KeyPair.prototype.validate = function validate() {
  35991. var pub = this.getPublic();
  35992. if (pub.isInfinity()) return {
  35993. result: false,
  35994. reason: 'Invalid public key'
  35995. };
  35996. if (!pub.validate()) return {
  35997. result: false,
  35998. reason: 'Public key is not a point'
  35999. };
  36000. if (!pub.mul(this.ec.curve.n).isInfinity()) return {
  36001. result: false,
  36002. reason: 'Public key * N != O'
  36003. };
  36004. return {
  36005. result: true,
  36006. reason: null
  36007. };
  36008. };
  36009. KeyPair.prototype.getPublic = function getPublic(compact, enc) {
  36010. // compact is optional argument
  36011. if (typeof compact === 'string') {
  36012. enc = compact;
  36013. compact = null;
  36014. }
  36015. if (!this.pub) this.pub = this.ec.g.mul(this.priv);
  36016. if (!enc) return this.pub;
  36017. return this.pub.encode(enc, compact);
  36018. };
  36019. KeyPair.prototype.getPrivate = function getPrivate(enc) {
  36020. if (enc === 'hex') return this.priv.toString(16, 2);else return this.priv;
  36021. };
  36022. KeyPair.prototype._importPrivate = function _importPrivate(key, enc) {
  36023. this.priv = new BN(key, enc || 16); // Ensure that the priv won't be bigger than n, otherwise we may fail
  36024. // in fixed multiplication method
  36025. this.priv = this.priv.umod(this.ec.curve.n);
  36026. };
  36027. KeyPair.prototype._importPublic = function _importPublic(key, enc) {
  36028. if (key.x || key.y) {
  36029. // Montgomery points only have an `x` coordinate.
  36030. // Weierstrass/Edwards points on the other hand have both `x` and
  36031. // `y` coordinates.
  36032. if (this.ec.curve.type === 'mont') {
  36033. assert(key.x, 'Need x coordinate');
  36034. } else if (this.ec.curve.type === 'short' || this.ec.curve.type === 'edwards') {
  36035. assert(key.x && key.y, 'Need both x and y coordinate');
  36036. }
  36037. this.pub = this.ec.curve.point(key.x, key.y);
  36038. return;
  36039. }
  36040. this.pub = this.ec.curve.decodePoint(key, enc);
  36041. }; // ECDH
  36042. KeyPair.prototype.derive = function derive(pub) {
  36043. return pub.mul(this.priv).getX();
  36044. }; // ECDSA
  36045. KeyPair.prototype.sign = function sign(msg, enc, options) {
  36046. return this.ec.sign(msg, this, enc, options);
  36047. };
  36048. KeyPair.prototype.verify = function verify(msg, signature) {
  36049. return this.ec.verify(msg, signature, this);
  36050. };
  36051. KeyPair.prototype.inspect = function inspect() {
  36052. return '<Key priv: ' + (this.priv && this.priv.toString(16, 2)) + ' pub: ' + (this.pub && this.pub.inspect()) + ' >';
  36053. };
  36054. },{"../utils":255,"bn.js":256}],250:[function(require,module,exports){
  36055. 'use strict';
  36056. var BN = require('bn.js');
  36057. var utils = require('../utils');
  36058. var assert = utils.assert;
  36059. function Signature(options, enc) {
  36060. if (options instanceof Signature) return options;
  36061. if (this._importDER(options, enc)) return;
  36062. assert(options.r && options.s, 'Signature without r or s');
  36063. this.r = new BN(options.r, 16);
  36064. this.s = new BN(options.s, 16);
  36065. if (options.recoveryParam === undefined) this.recoveryParam = null;else this.recoveryParam = options.recoveryParam;
  36066. }
  36067. module.exports = Signature;
  36068. function Position() {
  36069. this.place = 0;
  36070. }
  36071. function getLength(buf, p) {
  36072. var initial = buf[p.place++];
  36073. if (!(initial & 0x80)) {
  36074. return initial;
  36075. }
  36076. var octetLen = initial & 0xf; // Indefinite length or overflow
  36077. if (octetLen === 0 || octetLen > 4) {
  36078. return false;
  36079. }
  36080. var val = 0;
  36081. for (var i = 0, off = p.place; i < octetLen; i++, off++) {
  36082. val <<= 8;
  36083. val |= buf[off];
  36084. val >>>= 0;
  36085. } // Leading zeroes
  36086. if (val <= 0x7f) {
  36087. return false;
  36088. }
  36089. p.place = off;
  36090. return val;
  36091. }
  36092. function rmPadding(buf) {
  36093. var i = 0;
  36094. var len = buf.length - 1;
  36095. while (!buf[i] && !(buf[i + 1] & 0x80) && i < len) {
  36096. i++;
  36097. }
  36098. if (i === 0) {
  36099. return buf;
  36100. }
  36101. return buf.slice(i);
  36102. }
  36103. Signature.prototype._importDER = function _importDER(data, enc) {
  36104. data = utils.toArray(data, enc);
  36105. var p = new Position();
  36106. if (data[p.place++] !== 0x30) {
  36107. return false;
  36108. }
  36109. var len = getLength(data, p);
  36110. if (len === false) {
  36111. return false;
  36112. }
  36113. if (len + p.place !== data.length) {
  36114. return false;
  36115. }
  36116. if (data[p.place++] !== 0x02) {
  36117. return false;
  36118. }
  36119. var rlen = getLength(data, p);
  36120. if (rlen === false) {
  36121. return false;
  36122. }
  36123. var r = data.slice(p.place, rlen + p.place);
  36124. p.place += rlen;
  36125. if (data[p.place++] !== 0x02) {
  36126. return false;
  36127. }
  36128. var slen = getLength(data, p);
  36129. if (slen === false) {
  36130. return false;
  36131. }
  36132. if (data.length !== slen + p.place) {
  36133. return false;
  36134. }
  36135. var s = data.slice(p.place, slen + p.place);
  36136. if (r[0] === 0) {
  36137. if (r[1] & 0x80) {
  36138. r = r.slice(1);
  36139. } else {
  36140. // Leading zeroes
  36141. return false;
  36142. }
  36143. }
  36144. if (s[0] === 0) {
  36145. if (s[1] & 0x80) {
  36146. s = s.slice(1);
  36147. } else {
  36148. // Leading zeroes
  36149. return false;
  36150. }
  36151. }
  36152. this.r = new BN(r);
  36153. this.s = new BN(s);
  36154. this.recoveryParam = null;
  36155. return true;
  36156. };
  36157. function constructLength(arr, len) {
  36158. if (len < 0x80) {
  36159. arr.push(len);
  36160. return;
  36161. }
  36162. var octets = 1 + (Math.log(len) / Math.LN2 >>> 3);
  36163. arr.push(octets | 0x80);
  36164. while (--octets) {
  36165. arr.push(len >>> (octets << 3) & 0xff);
  36166. }
  36167. arr.push(len);
  36168. }
  36169. Signature.prototype.toDER = function toDER(enc) {
  36170. var r = this.r.toArray();
  36171. var s = this.s.toArray(); // Pad values
  36172. if (r[0] & 0x80) r = [0].concat(r); // Pad values
  36173. if (s[0] & 0x80) s = [0].concat(s);
  36174. r = rmPadding(r);
  36175. s = rmPadding(s);
  36176. while (!s[0] && !(s[1] & 0x80)) {
  36177. s = s.slice(1);
  36178. }
  36179. var arr = [0x02];
  36180. constructLength(arr, r.length);
  36181. arr = arr.concat(r);
  36182. arr.push(0x02);
  36183. constructLength(arr, s.length);
  36184. var backHalf = arr.concat(s);
  36185. var res = [0x30];
  36186. constructLength(res, backHalf.length);
  36187. res = res.concat(backHalf);
  36188. return utils.encode(res, enc);
  36189. };
  36190. },{"../utils":255,"bn.js":256}],251:[function(require,module,exports){
  36191. 'use strict';
  36192. var hash = require('hash.js');
  36193. var curves = require('../curves');
  36194. var utils = require('../utils');
  36195. var assert = utils.assert;
  36196. var parseBytes = utils.parseBytes;
  36197. var KeyPair = require('./key');
  36198. var Signature = require('./signature');
  36199. function EDDSA(curve) {
  36200. assert(curve === 'ed25519', 'only tested with ed25519 so far');
  36201. if (!(this instanceof EDDSA)) return new EDDSA(curve);
  36202. var curve = curves[curve].curve;
  36203. this.curve = curve;
  36204. this.g = curve.g;
  36205. this.g.precompute(curve.n.bitLength() + 1);
  36206. this.pointClass = curve.point().constructor;
  36207. this.encodingLength = Math.ceil(curve.n.bitLength() / 8);
  36208. this.hash = hash.sha512;
  36209. }
  36210. module.exports = EDDSA;
  36211. /**
  36212. * @param {Array|String} message - message bytes
  36213. * @param {Array|String|KeyPair} secret - secret bytes or a keypair
  36214. * @returns {Signature} - signature
  36215. */
  36216. EDDSA.prototype.sign = function sign(message, secret) {
  36217. message = parseBytes(message);
  36218. var key = this.keyFromSecret(secret);
  36219. var r = this.hashInt(key.messagePrefix(), message);
  36220. var R = this.g.mul(r);
  36221. var Rencoded = this.encodePoint(R);
  36222. var s_ = this.hashInt(Rencoded, key.pubBytes(), message).mul(key.priv());
  36223. var S = r.add(s_).umod(this.curve.n);
  36224. return this.makeSignature({
  36225. R: R,
  36226. S: S,
  36227. Rencoded: Rencoded
  36228. });
  36229. };
  36230. /**
  36231. * @param {Array} message - message bytes
  36232. * @param {Array|String|Signature} sig - sig bytes
  36233. * @param {Array|String|Point|KeyPair} pub - public key
  36234. * @returns {Boolean} - true if public key matches sig of message
  36235. */
  36236. EDDSA.prototype.verify = function verify(message, sig, pub) {
  36237. message = parseBytes(message);
  36238. sig = this.makeSignature(sig);
  36239. var key = this.keyFromPublic(pub);
  36240. var h = this.hashInt(sig.Rencoded(), key.pubBytes(), message);
  36241. var SG = this.g.mul(sig.S());
  36242. var RplusAh = sig.R().add(key.pub().mul(h));
  36243. return RplusAh.eq(SG);
  36244. };
  36245. EDDSA.prototype.hashInt = function hashInt() {
  36246. var hash = this.hash();
  36247. for (var i = 0; i < arguments.length; i++) {
  36248. hash.update(arguments[i]);
  36249. }
  36250. return utils.intFromLE(hash.digest()).umod(this.curve.n);
  36251. };
  36252. EDDSA.prototype.keyFromPublic = function keyFromPublic(pub) {
  36253. return KeyPair.fromPublic(this, pub);
  36254. };
  36255. EDDSA.prototype.keyFromSecret = function keyFromSecret(secret) {
  36256. return KeyPair.fromSecret(this, secret);
  36257. };
  36258. EDDSA.prototype.makeSignature = function makeSignature(sig) {
  36259. if (sig instanceof Signature) return sig;
  36260. return new Signature(this, sig);
  36261. };
  36262. /**
  36263. * * https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-03#section-5.2
  36264. *
  36265. * EDDSA defines methods for encoding and decoding points and integers. These are
  36266. * helper convenience methods, that pass along to utility functions implied
  36267. * parameters.
  36268. *
  36269. */
  36270. EDDSA.prototype.encodePoint = function encodePoint(point) {
  36271. var enc = point.getY().toArray('le', this.encodingLength);
  36272. enc[this.encodingLength - 1] |= point.getX().isOdd() ? 0x80 : 0;
  36273. return enc;
  36274. };
  36275. EDDSA.prototype.decodePoint = function decodePoint(bytes) {
  36276. bytes = utils.parseBytes(bytes);
  36277. var lastIx = bytes.length - 1;
  36278. var normed = bytes.slice(0, lastIx).concat(bytes[lastIx] & ~0x80);
  36279. var xIsOdd = (bytes[lastIx] & 0x80) !== 0;
  36280. var y = utils.intFromLE(normed);
  36281. return this.curve.pointFromY(y, xIsOdd);
  36282. };
  36283. EDDSA.prototype.encodeInt = function encodeInt(num) {
  36284. return num.toArray('le', this.encodingLength);
  36285. };
  36286. EDDSA.prototype.decodeInt = function decodeInt(bytes) {
  36287. return utils.intFromLE(bytes);
  36288. };
  36289. EDDSA.prototype.isPoint = function isPoint(val) {
  36290. return val instanceof this.pointClass;
  36291. };
  36292. },{"../curves":247,"../utils":255,"./key":252,"./signature":253,"hash.js":263}],252:[function(require,module,exports){
  36293. 'use strict';
  36294. var utils = require('../utils');
  36295. var assert = utils.assert;
  36296. var parseBytes = utils.parseBytes;
  36297. var cachedProperty = utils.cachedProperty;
  36298. /**
  36299. * @param {EDDSA} eddsa - instance
  36300. * @param {Object} params - public/private key parameters
  36301. *
  36302. * @param {Array<Byte>} [params.secret] - secret seed bytes
  36303. * @param {Point} [params.pub] - public key point (aka `A` in eddsa terms)
  36304. * @param {Array<Byte>} [params.pub] - public key point encoded as bytes
  36305. *
  36306. */
  36307. function KeyPair(eddsa, params) {
  36308. this.eddsa = eddsa;
  36309. this._secret = parseBytes(params.secret);
  36310. if (eddsa.isPoint(params.pub)) this._pub = params.pub;else this._pubBytes = parseBytes(params.pub);
  36311. }
  36312. KeyPair.fromPublic = function fromPublic(eddsa, pub) {
  36313. if (pub instanceof KeyPair) return pub;
  36314. return new KeyPair(eddsa, {
  36315. pub: pub
  36316. });
  36317. };
  36318. KeyPair.fromSecret = function fromSecret(eddsa, secret) {
  36319. if (secret instanceof KeyPair) return secret;
  36320. return new KeyPair(eddsa, {
  36321. secret: secret
  36322. });
  36323. };
  36324. KeyPair.prototype.secret = function secret() {
  36325. return this._secret;
  36326. };
  36327. cachedProperty(KeyPair, 'pubBytes', function pubBytes() {
  36328. return this.eddsa.encodePoint(this.pub());
  36329. });
  36330. cachedProperty(KeyPair, 'pub', function pub() {
  36331. if (this._pubBytes) return this.eddsa.decodePoint(this._pubBytes);
  36332. return this.eddsa.g.mul(this.priv());
  36333. });
  36334. cachedProperty(KeyPair, 'privBytes', function privBytes() {
  36335. var eddsa = this.eddsa;
  36336. var hash = this.hash();
  36337. var lastIx = eddsa.encodingLength - 1;
  36338. var a = hash.slice(0, eddsa.encodingLength);
  36339. a[0] &= 248;
  36340. a[lastIx] &= 127;
  36341. a[lastIx] |= 64;
  36342. return a;
  36343. });
  36344. cachedProperty(KeyPair, 'priv', function priv() {
  36345. return this.eddsa.decodeInt(this.privBytes());
  36346. });
  36347. cachedProperty(KeyPair, 'hash', function hash() {
  36348. return this.eddsa.hash().update(this.secret()).digest();
  36349. });
  36350. cachedProperty(KeyPair, 'messagePrefix', function messagePrefix() {
  36351. return this.hash().slice(this.eddsa.encodingLength);
  36352. });
  36353. KeyPair.prototype.sign = function sign(message) {
  36354. assert(this._secret, 'KeyPair can only verify');
  36355. return this.eddsa.sign(message, this);
  36356. };
  36357. KeyPair.prototype.verify = function verify(message, sig) {
  36358. return this.eddsa.verify(message, sig, this);
  36359. };
  36360. KeyPair.prototype.getSecret = function getSecret(enc) {
  36361. assert(this._secret, 'KeyPair is public only');
  36362. return utils.encode(this.secret(), enc);
  36363. };
  36364. KeyPair.prototype.getPublic = function getPublic(enc) {
  36365. return utils.encode(this.pubBytes(), enc);
  36366. };
  36367. module.exports = KeyPair;
  36368. },{"../utils":255}],253:[function(require,module,exports){
  36369. 'use strict';
  36370. 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); }
  36371. var BN = require('bn.js');
  36372. var utils = require('../utils');
  36373. var assert = utils.assert;
  36374. var cachedProperty = utils.cachedProperty;
  36375. var parseBytes = utils.parseBytes;
  36376. /**
  36377. * @param {EDDSA} eddsa - eddsa instance
  36378. * @param {Array<Bytes>|Object} sig -
  36379. * @param {Array<Bytes>|Point} [sig.R] - R point as Point or bytes
  36380. * @param {Array<Bytes>|bn} [sig.S] - S scalar as bn or bytes
  36381. * @param {Array<Bytes>} [sig.Rencoded] - R point encoded
  36382. * @param {Array<Bytes>} [sig.Sencoded] - S scalar encoded
  36383. */
  36384. function Signature(eddsa, sig) {
  36385. this.eddsa = eddsa;
  36386. if (_typeof(sig) !== 'object') sig = parseBytes(sig);
  36387. if (Array.isArray(sig)) {
  36388. sig = {
  36389. R: sig.slice(0, eddsa.encodingLength),
  36390. S: sig.slice(eddsa.encodingLength)
  36391. };
  36392. }
  36393. assert(sig.R && sig.S, 'Signature without R or S');
  36394. if (eddsa.isPoint(sig.R)) this._R = sig.R;
  36395. if (sig.S instanceof BN) this._S = sig.S;
  36396. this._Rencoded = Array.isArray(sig.R) ? sig.R : sig.Rencoded;
  36397. this._Sencoded = Array.isArray(sig.S) ? sig.S : sig.Sencoded;
  36398. }
  36399. cachedProperty(Signature, 'S', function S() {
  36400. return this.eddsa.decodeInt(this.Sencoded());
  36401. });
  36402. cachedProperty(Signature, 'R', function R() {
  36403. return this.eddsa.decodePoint(this.Rencoded());
  36404. });
  36405. cachedProperty(Signature, 'Rencoded', function Rencoded() {
  36406. return this.eddsa.encodePoint(this.R());
  36407. });
  36408. cachedProperty(Signature, 'Sencoded', function Sencoded() {
  36409. return this.eddsa.encodeInt(this.S());
  36410. });
  36411. Signature.prototype.toBytes = function toBytes() {
  36412. return this.Rencoded().concat(this.Sencoded());
  36413. };
  36414. Signature.prototype.toHex = function toHex() {
  36415. return utils.encode(this.toBytes(), 'hex').toUpperCase();
  36416. };
  36417. module.exports = Signature;
  36418. },{"../utils":255,"bn.js":256}],254:[function(require,module,exports){
  36419. "use strict";
  36420. module.exports = {
  36421. doubles: {
  36422. step: 4,
  36423. 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']]
  36424. },
  36425. naf: {
  36426. wnd: 7,
  36427. 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']]
  36428. }
  36429. };
  36430. },{}],255:[function(require,module,exports){
  36431. 'use strict';
  36432. var utils = exports;
  36433. var BN = require('bn.js');
  36434. var minAssert = require('minimalistic-assert');
  36435. var minUtils = require('minimalistic-crypto-utils');
  36436. utils.assert = minAssert;
  36437. utils.toArray = minUtils.toArray;
  36438. utils.zero2 = minUtils.zero2;
  36439. utils.toHex = minUtils.toHex;
  36440. utils.encode = minUtils.encode; // Represent num in a w-NAF form
  36441. function getNAF(num, w, bits) {
  36442. var naf = new Array(Math.max(num.bitLength(), bits) + 1);
  36443. naf.fill(0);
  36444. var ws = 1 << w + 1;
  36445. var k = num.clone();
  36446. for (var i = 0; i < naf.length; i++) {
  36447. var z;
  36448. var mod = k.andln(ws - 1);
  36449. if (k.isOdd()) {
  36450. if (mod > (ws >> 1) - 1) z = (ws >> 1) - mod;else z = mod;
  36451. k.isubn(z);
  36452. } else {
  36453. z = 0;
  36454. }
  36455. naf[i] = z;
  36456. k.iushrn(1);
  36457. }
  36458. return naf;
  36459. }
  36460. utils.getNAF = getNAF; // Represent k1, k2 in a Joint Sparse Form
  36461. function getJSF(k1, k2) {
  36462. var jsf = [[], []];
  36463. k1 = k1.clone();
  36464. k2 = k2.clone();
  36465. var d1 = 0;
  36466. var d2 = 0;
  36467. while (k1.cmpn(-d1) > 0 || k2.cmpn(-d2) > 0) {
  36468. // First phase
  36469. var m14 = k1.andln(3) + d1 & 3;
  36470. var m24 = k2.andln(3) + d2 & 3;
  36471. if (m14 === 3) m14 = -1;
  36472. if (m24 === 3) m24 = -1;
  36473. var u1;
  36474. if ((m14 & 1) === 0) {
  36475. u1 = 0;
  36476. } else {
  36477. var m8 = k1.andln(7) + d1 & 7;
  36478. if ((m8 === 3 || m8 === 5) && m24 === 2) u1 = -m14;else u1 = m14;
  36479. }
  36480. jsf[0].push(u1);
  36481. var u2;
  36482. if ((m24 & 1) === 0) {
  36483. u2 = 0;
  36484. } else {
  36485. var m8 = k2.andln(7) + d2 & 7;
  36486. if ((m8 === 3 || m8 === 5) && m14 === 2) u2 = -m24;else u2 = m24;
  36487. }
  36488. jsf[1].push(u2); // Second phase
  36489. if (2 * d1 === u1 + 1) d1 = 1 - d1;
  36490. if (2 * d2 === u2 + 1) d2 = 1 - d2;
  36491. k1.iushrn(1);
  36492. k2.iushrn(1);
  36493. }
  36494. return jsf;
  36495. }
  36496. utils.getJSF = getJSF;
  36497. function cachedProperty(obj, name, computer) {
  36498. var key = '_' + name;
  36499. obj.prototype[name] = function cachedProperty() {
  36500. return this[key] !== undefined ? this[key] : this[key] = computer.call(this);
  36501. };
  36502. }
  36503. utils.cachedProperty = cachedProperty;
  36504. function parseBytes(bytes) {
  36505. return typeof bytes === 'string' ? utils.toArray(bytes, 'hex') : bytes;
  36506. }
  36507. utils.parseBytes = parseBytes;
  36508. function intFromLE(bytes) {
  36509. return new BN(bytes, 'hex', 'le');
  36510. }
  36511. utils.intFromLE = intFromLE;
  36512. },{"bn.js":256,"minimalistic-assert":328,"minimalistic-crypto-utils":329}],256:[function(require,module,exports){
  36513. arguments[4][181][0].apply(exports,arguments)
  36514. },{"buffer":185,"dup":181}],257:[function(require,module,exports){
  36515. module.exports={
  36516. "_from": "elliptic@^6.5.3",
  36517. "_id": "elliptic@6.5.3",
  36518. "_inBundle": false,
  36519. "_integrity": "sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw==",
  36520. "_location": "/elliptic",
  36521. "_phantomChildren": {},
  36522. "_requested": {
  36523. "type": "range",
  36524. "registry": true,
  36525. "raw": "elliptic@^6.5.3",
  36526. "name": "elliptic",
  36527. "escapedName": "elliptic",
  36528. "rawSpec": "^6.5.3",
  36529. "saveSpec": null,
  36530. "fetchSpec": "^6.5.3"
  36531. },
  36532. "_requiredBy": [
  36533. "/browserify-sign",
  36534. "/create-ecdh"
  36535. ],
  36536. "_resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.3.tgz",
  36537. "_shasum": "cb59eb2efdaf73a0bd78ccd7015a62ad6e0f93d6",
  36538. "_spec": "elliptic@^6.5.3",
  36539. "_where": "/mnt/d/dev/git/exceljs/node_modules/browserify-sign",
  36540. "author": {
  36541. "name": "Fedor Indutny",
  36542. "email": "fedor@indutny.com"
  36543. },
  36544. "bugs": {
  36545. "url": "https://github.com/indutny/elliptic/issues"
  36546. },
  36547. "bundleDependencies": false,
  36548. "dependencies": {
  36549. "bn.js": "^4.4.0",
  36550. "brorand": "^1.0.1",
  36551. "hash.js": "^1.0.0",
  36552. "hmac-drbg": "^1.0.0",
  36553. "inherits": "^2.0.1",
  36554. "minimalistic-assert": "^1.0.0",
  36555. "minimalistic-crypto-utils": "^1.0.0"
  36556. },
  36557. "deprecated": false,
  36558. "description": "EC cryptography",
  36559. "devDependencies": {
  36560. "brfs": "^1.4.3",
  36561. "coveralls": "^3.0.8",
  36562. "grunt": "^1.0.4",
  36563. "grunt-browserify": "^5.0.0",
  36564. "grunt-cli": "^1.2.0",
  36565. "grunt-contrib-connect": "^1.0.0",
  36566. "grunt-contrib-copy": "^1.0.0",
  36567. "grunt-contrib-uglify": "^1.0.1",
  36568. "grunt-mocha-istanbul": "^3.0.1",
  36569. "grunt-saucelabs": "^9.0.1",
  36570. "istanbul": "^0.4.2",
  36571. "jscs": "^3.0.7",
  36572. "jshint": "^2.10.3",
  36573. "mocha": "^6.2.2"
  36574. },
  36575. "files": [
  36576. "lib"
  36577. ],
  36578. "homepage": "https://github.com/indutny/elliptic",
  36579. "keywords": [
  36580. "EC",
  36581. "Elliptic",
  36582. "curve",
  36583. "Cryptography"
  36584. ],
  36585. "license": "MIT",
  36586. "main": "lib/elliptic.js",
  36587. "name": "elliptic",
  36588. "repository": {
  36589. "type": "git",
  36590. "url": "git+ssh://git@github.com/indutny/elliptic.git"
  36591. },
  36592. "scripts": {
  36593. "jscs": "jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",
  36594. "jshint": "jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",
  36595. "lint": "npm run jscs && npm run jshint",
  36596. "test": "npm run lint && npm run unit",
  36597. "unit": "istanbul test _mocha --reporter=spec test/index.js",
  36598. "version": "grunt dist && git add dist/"
  36599. },
  36600. "version": "6.5.3"
  36601. }
  36602. },{}],258:[function(require,module,exports){
  36603. "use strict";
  36604. 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); }
  36605. // Copyright Joyent, Inc. and other Node contributors.
  36606. //
  36607. // Permission is hereby granted, free of charge, to any person obtaining a
  36608. // copy of this software and associated documentation files (the
  36609. // "Software"), to deal in the Software without restriction, including
  36610. // without limitation the rights to use, copy, modify, merge, publish,
  36611. // distribute, sublicense, and/or sell copies of the Software, and to permit
  36612. // persons to whom the Software is furnished to do so, subject to the
  36613. // following conditions:
  36614. //
  36615. // The above copyright notice and this permission notice shall be included
  36616. // in all copies or substantial portions of the Software.
  36617. //
  36618. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  36619. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  36620. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  36621. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  36622. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  36623. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  36624. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  36625. var objectCreate = Object.create || objectCreatePolyfill;
  36626. var objectKeys = Object.keys || objectKeysPolyfill;
  36627. var bind = Function.prototype.bind || functionBindPolyfill;
  36628. function EventEmitter() {
  36629. if (!this._events || !Object.prototype.hasOwnProperty.call(this, '_events')) {
  36630. this._events = objectCreate(null);
  36631. this._eventsCount = 0;
  36632. }
  36633. this._maxListeners = this._maxListeners || undefined;
  36634. }
  36635. module.exports = EventEmitter; // Backwards-compat with node 0.10.x
  36636. EventEmitter.EventEmitter = EventEmitter;
  36637. EventEmitter.prototype._events = undefined;
  36638. EventEmitter.prototype._maxListeners = undefined; // By default EventEmitters will print a warning if more than 10 listeners are
  36639. // added to it. This is a useful default which helps finding memory leaks.
  36640. var defaultMaxListeners = 10;
  36641. var hasDefineProperty;
  36642. try {
  36643. var o = {};
  36644. if (Object.defineProperty) Object.defineProperty(o, 'x', {
  36645. value: 0
  36646. });
  36647. hasDefineProperty = o.x === 0;
  36648. } catch (err) {
  36649. hasDefineProperty = false;
  36650. }
  36651. if (hasDefineProperty) {
  36652. Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
  36653. enumerable: true,
  36654. get: function get() {
  36655. return defaultMaxListeners;
  36656. },
  36657. set: function set(arg) {
  36658. // check whether the input is a positive number (whose value is zero or
  36659. // greater and not a NaN).
  36660. if (typeof arg !== 'number' || arg < 0 || arg !== arg) throw new TypeError('"defaultMaxListeners" must be a positive number');
  36661. defaultMaxListeners = arg;
  36662. }
  36663. });
  36664. } else {
  36665. EventEmitter.defaultMaxListeners = defaultMaxListeners;
  36666. } // Obviously not all Emitters should be limited to 10. This function allows
  36667. // that to be increased. Set to zero for unlimited.
  36668. EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
  36669. if (typeof n !== 'number' || n < 0 || isNaN(n)) throw new TypeError('"n" argument must be a positive number');
  36670. this._maxListeners = n;
  36671. return this;
  36672. };
  36673. function $getMaxListeners(that) {
  36674. if (that._maxListeners === undefined) return EventEmitter.defaultMaxListeners;
  36675. return that._maxListeners;
  36676. }
  36677. EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
  36678. return $getMaxListeners(this);
  36679. }; // These standalone emit* functions are used to optimize calling of event
  36680. // handlers for fast cases because emit() itself often has a variable number of
  36681. // arguments and can be deoptimized because of that. These functions always have
  36682. // the same number of arguments and thus do not get deoptimized, so the code
  36683. // inside them can execute faster.
  36684. function emitNone(handler, isFn, self) {
  36685. if (isFn) handler.call(self);else {
  36686. var len = handler.length;
  36687. var listeners = arrayClone(handler, len);
  36688. for (var i = 0; i < len; ++i) {
  36689. listeners[i].call(self);
  36690. }
  36691. }
  36692. }
  36693. function emitOne(handler, isFn, self, arg1) {
  36694. if (isFn) handler.call(self, arg1);else {
  36695. var len = handler.length;
  36696. var listeners = arrayClone(handler, len);
  36697. for (var i = 0; i < len; ++i) {
  36698. listeners[i].call(self, arg1);
  36699. }
  36700. }
  36701. }
  36702. function emitTwo(handler, isFn, self, arg1, arg2) {
  36703. if (isFn) handler.call(self, arg1, arg2);else {
  36704. var len = handler.length;
  36705. var listeners = arrayClone(handler, len);
  36706. for (var i = 0; i < len; ++i) {
  36707. listeners[i].call(self, arg1, arg2);
  36708. }
  36709. }
  36710. }
  36711. function emitThree(handler, isFn, self, arg1, arg2, arg3) {
  36712. if (isFn) handler.call(self, arg1, arg2, arg3);else {
  36713. var len = handler.length;
  36714. var listeners = arrayClone(handler, len);
  36715. for (var i = 0; i < len; ++i) {
  36716. listeners[i].call(self, arg1, arg2, arg3);
  36717. }
  36718. }
  36719. }
  36720. function emitMany(handler, isFn, self, args) {
  36721. if (isFn) handler.apply(self, args);else {
  36722. var len = handler.length;
  36723. var listeners = arrayClone(handler, len);
  36724. for (var i = 0; i < len; ++i) {
  36725. listeners[i].apply(self, args);
  36726. }
  36727. }
  36728. }
  36729. EventEmitter.prototype.emit = function emit(type) {
  36730. var er, handler, len, args, i, events;
  36731. var doError = type === 'error';
  36732. events = this._events;
  36733. if (events) doError = doError && events.error == null;else if (!doError) return false; // If there is no 'error' event listener then throw.
  36734. if (doError) {
  36735. if (arguments.length > 1) er = arguments[1];
  36736. if (er instanceof Error) {
  36737. throw er; // Unhandled 'error' event
  36738. } else {
  36739. // At least give some kind of context to the user
  36740. var err = new Error('Unhandled "error" event. (' + er + ')');
  36741. err.context = er;
  36742. throw err;
  36743. }
  36744. return false;
  36745. }
  36746. handler = events[type];
  36747. if (!handler) return false;
  36748. var isFn = typeof handler === 'function';
  36749. len = arguments.length;
  36750. switch (len) {
  36751. // fast cases
  36752. case 1:
  36753. emitNone(handler, isFn, this);
  36754. break;
  36755. case 2:
  36756. emitOne(handler, isFn, this, arguments[1]);
  36757. break;
  36758. case 3:
  36759. emitTwo(handler, isFn, this, arguments[1], arguments[2]);
  36760. break;
  36761. case 4:
  36762. emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);
  36763. break;
  36764. // slower
  36765. default:
  36766. args = new Array(len - 1);
  36767. for (i = 1; i < len; i++) {
  36768. args[i - 1] = arguments[i];
  36769. }
  36770. emitMany(handler, isFn, this, args);
  36771. }
  36772. return true;
  36773. };
  36774. function _addListener(target, type, listener, prepend) {
  36775. var m;
  36776. var events;
  36777. var existing;
  36778. if (typeof listener !== 'function') throw new TypeError('"listener" argument must be a function');
  36779. events = target._events;
  36780. if (!events) {
  36781. events = target._events = objectCreate(null);
  36782. target._eventsCount = 0;
  36783. } else {
  36784. // To avoid recursion in the case that type === "newListener"! Before
  36785. // adding it to the listeners, first emit "newListener".
  36786. if (events.newListener) {
  36787. target.emit('newListener', type, listener.listener ? listener.listener : listener); // Re-assign `events` because a newListener handler could have caused the
  36788. // this._events to be assigned to a new object
  36789. events = target._events;
  36790. }
  36791. existing = events[type];
  36792. }
  36793. if (!existing) {
  36794. // Optimize the case of one listener. Don't need the extra array object.
  36795. existing = events[type] = listener;
  36796. ++target._eventsCount;
  36797. } else {
  36798. if (typeof existing === 'function') {
  36799. // Adding the second element, need to change to array.
  36800. existing = events[type] = prepend ? [listener, existing] : [existing, listener];
  36801. } else {
  36802. // If we've already got an array, just append.
  36803. if (prepend) {
  36804. existing.unshift(listener);
  36805. } else {
  36806. existing.push(listener);
  36807. }
  36808. } // Check for listener leak
  36809. if (!existing.warned) {
  36810. m = $getMaxListeners(target);
  36811. if (m && m > 0 && existing.length > m) {
  36812. existing.warned = true;
  36813. var w = new Error('Possible EventEmitter memory leak detected. ' + existing.length + ' "' + String(type) + '" listeners ' + 'added. Use emitter.setMaxListeners() to ' + 'increase limit.');
  36814. w.name = 'MaxListenersExceededWarning';
  36815. w.emitter = target;
  36816. w.type = type;
  36817. w.count = existing.length;
  36818. if ((typeof console === "undefined" ? "undefined" : _typeof(console)) === 'object' && console.warn) {
  36819. console.warn('%s: %s', w.name, w.message);
  36820. }
  36821. }
  36822. }
  36823. }
  36824. return target;
  36825. }
  36826. EventEmitter.prototype.addListener = function addListener(type, listener) {
  36827. return _addListener(this, type, listener, false);
  36828. };
  36829. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  36830. EventEmitter.prototype.prependListener = function prependListener(type, listener) {
  36831. return _addListener(this, type, listener, true);
  36832. };
  36833. function onceWrapper() {
  36834. if (!this.fired) {
  36835. this.target.removeListener(this.type, this.wrapFn);
  36836. this.fired = true;
  36837. switch (arguments.length) {
  36838. case 0:
  36839. return this.listener.call(this.target);
  36840. case 1:
  36841. return this.listener.call(this.target, arguments[0]);
  36842. case 2:
  36843. return this.listener.call(this.target, arguments[0], arguments[1]);
  36844. case 3:
  36845. return this.listener.call(this.target, arguments[0], arguments[1], arguments[2]);
  36846. default:
  36847. var args = new Array(arguments.length);
  36848. for (var i = 0; i < args.length; ++i) {
  36849. args[i] = arguments[i];
  36850. }
  36851. this.listener.apply(this.target, args);
  36852. }
  36853. }
  36854. }
  36855. function _onceWrap(target, type, listener) {
  36856. var state = {
  36857. fired: false,
  36858. wrapFn: undefined,
  36859. target: target,
  36860. type: type,
  36861. listener: listener
  36862. };
  36863. var wrapped = bind.call(onceWrapper, state);
  36864. wrapped.listener = listener;
  36865. state.wrapFn = wrapped;
  36866. return wrapped;
  36867. }
  36868. EventEmitter.prototype.once = function once(type, listener) {
  36869. if (typeof listener !== 'function') throw new TypeError('"listener" argument must be a function');
  36870. this.on(type, _onceWrap(this, type, listener));
  36871. return this;
  36872. };
  36873. EventEmitter.prototype.prependOnceListener = function prependOnceListener(type, listener) {
  36874. if (typeof listener !== 'function') throw new TypeError('"listener" argument must be a function');
  36875. this.prependListener(type, _onceWrap(this, type, listener));
  36876. return this;
  36877. }; // Emits a 'removeListener' event if and only if the listener was removed.
  36878. EventEmitter.prototype.removeListener = function removeListener(type, listener) {
  36879. var list, events, position, i, originalListener;
  36880. if (typeof listener !== 'function') throw new TypeError('"listener" argument must be a function');
  36881. events = this._events;
  36882. if (!events) return this;
  36883. list = events[type];
  36884. if (!list) return this;
  36885. if (list === listener || list.listener === listener) {
  36886. if (--this._eventsCount === 0) this._events = objectCreate(null);else {
  36887. delete events[type];
  36888. if (events.removeListener) this.emit('removeListener', type, list.listener || listener);
  36889. }
  36890. } else if (typeof list !== 'function') {
  36891. position = -1;
  36892. for (i = list.length - 1; i >= 0; i--) {
  36893. if (list[i] === listener || list[i].listener === listener) {
  36894. originalListener = list[i].listener;
  36895. position = i;
  36896. break;
  36897. }
  36898. }
  36899. if (position < 0) return this;
  36900. if (position === 0) list.shift();else spliceOne(list, position);
  36901. if (list.length === 1) events[type] = list[0];
  36902. if (events.removeListener) this.emit('removeListener', type, originalListener || listener);
  36903. }
  36904. return this;
  36905. };
  36906. EventEmitter.prototype.removeAllListeners = function removeAllListeners(type) {
  36907. var listeners, events, i;
  36908. events = this._events;
  36909. if (!events) return this; // not listening for removeListener, no need to emit
  36910. if (!events.removeListener) {
  36911. if (arguments.length === 0) {
  36912. this._events = objectCreate(null);
  36913. this._eventsCount = 0;
  36914. } else if (events[type]) {
  36915. if (--this._eventsCount === 0) this._events = objectCreate(null);else delete events[type];
  36916. }
  36917. return this;
  36918. } // emit removeListener for all listeners on all events
  36919. if (arguments.length === 0) {
  36920. var keys = objectKeys(events);
  36921. var key;
  36922. for (i = 0; i < keys.length; ++i) {
  36923. key = keys[i];
  36924. if (key === 'removeListener') continue;
  36925. this.removeAllListeners(key);
  36926. }
  36927. this.removeAllListeners('removeListener');
  36928. this._events = objectCreate(null);
  36929. this._eventsCount = 0;
  36930. return this;
  36931. }
  36932. listeners = events[type];
  36933. if (typeof listeners === 'function') {
  36934. this.removeListener(type, listeners);
  36935. } else if (listeners) {
  36936. // LIFO order
  36937. for (i = listeners.length - 1; i >= 0; i--) {
  36938. this.removeListener(type, listeners[i]);
  36939. }
  36940. }
  36941. return this;
  36942. };
  36943. function _listeners(target, type, unwrap) {
  36944. var events = target._events;
  36945. if (!events) return [];
  36946. var evlistener = events[type];
  36947. if (!evlistener) return [];
  36948. if (typeof evlistener === 'function') return unwrap ? [evlistener.listener || evlistener] : [evlistener];
  36949. return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
  36950. }
  36951. EventEmitter.prototype.listeners = function listeners(type) {
  36952. return _listeners(this, type, true);
  36953. };
  36954. EventEmitter.prototype.rawListeners = function rawListeners(type) {
  36955. return _listeners(this, type, false);
  36956. };
  36957. EventEmitter.listenerCount = function (emitter, type) {
  36958. if (typeof emitter.listenerCount === 'function') {
  36959. return emitter.listenerCount(type);
  36960. } else {
  36961. return listenerCount.call(emitter, type);
  36962. }
  36963. };
  36964. EventEmitter.prototype.listenerCount = listenerCount;
  36965. function listenerCount(type) {
  36966. var events = this._events;
  36967. if (events) {
  36968. var evlistener = events[type];
  36969. if (typeof evlistener === 'function') {
  36970. return 1;
  36971. } else if (evlistener) {
  36972. return evlistener.length;
  36973. }
  36974. }
  36975. return 0;
  36976. }
  36977. EventEmitter.prototype.eventNames = function eventNames() {
  36978. return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
  36979. }; // About 1.5x faster than the two-arg version of Array#splice().
  36980. function spliceOne(list, index) {
  36981. for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1) {
  36982. list[i] = list[k];
  36983. }
  36984. list.pop();
  36985. }
  36986. function arrayClone(arr, n) {
  36987. var copy = new Array(n);
  36988. for (var i = 0; i < n; ++i) {
  36989. copy[i] = arr[i];
  36990. }
  36991. return copy;
  36992. }
  36993. function unwrapListeners(arr) {
  36994. var ret = new Array(arr.length);
  36995. for (var i = 0; i < ret.length; ++i) {
  36996. ret[i] = arr[i].listener || arr[i];
  36997. }
  36998. return ret;
  36999. }
  37000. function objectCreatePolyfill(proto) {
  37001. var F = function F() {};
  37002. F.prototype = proto;
  37003. return new F();
  37004. }
  37005. function objectKeysPolyfill(obj) {
  37006. var keys = [];
  37007. for (var k in obj) {
  37008. if (Object.prototype.hasOwnProperty.call(obj, k)) {
  37009. keys.push(k);
  37010. }
  37011. }
  37012. return k;
  37013. }
  37014. function functionBindPolyfill(context) {
  37015. var fn = this;
  37016. return function () {
  37017. return fn.apply(context, arguments);
  37018. };
  37019. }
  37020. },{}],259:[function(require,module,exports){
  37021. "use strict";
  37022. var Buffer = require('safe-buffer').Buffer;
  37023. var MD5 = require('md5.js');
  37024. /* eslint-disable camelcase */
  37025. function EVP_BytesToKey(password, salt, keyBits, ivLen) {
  37026. if (!Buffer.isBuffer(password)) password = Buffer.from(password, 'binary');
  37027. if (salt) {
  37028. if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, 'binary');
  37029. if (salt.length !== 8) throw new RangeError('salt should be Buffer with 8 byte length');
  37030. }
  37031. var keyLen = keyBits / 8;
  37032. var key = Buffer.alloc(keyLen);
  37033. var iv = Buffer.alloc(ivLen || 0);
  37034. var tmp = Buffer.alloc(0);
  37035. while (keyLen > 0 || ivLen > 0) {
  37036. var hash = new MD5();
  37037. hash.update(tmp);
  37038. hash.update(password);
  37039. if (salt) hash.update(salt);
  37040. tmp = hash.digest();
  37041. var used = 0;
  37042. if (keyLen > 0) {
  37043. var keyStart = key.length - keyLen;
  37044. used = Math.min(keyLen, tmp.length);
  37045. tmp.copy(key, keyStart, 0, used);
  37046. keyLen -= used;
  37047. }
  37048. if (used < tmp.length && ivLen > 0) {
  37049. var ivStart = iv.length - ivLen;
  37050. var length = Math.min(ivLen, tmp.length - used);
  37051. tmp.copy(iv, ivStart, used, used + length);
  37052. ivLen -= length;
  37053. }
  37054. }
  37055. tmp.fill(0);
  37056. return {
  37057. key: key,
  37058. iv: iv
  37059. };
  37060. }
  37061. module.exports = EVP_BytesToKey;
  37062. },{"md5.js":325,"safe-buffer":384}],260:[function(require,module,exports){
  37063. "use strict";
  37064. Object.defineProperty(exports, "__esModule", {
  37065. value: true
  37066. });
  37067. var format_1 = require("@fast-csv/format");
  37068. Object.defineProperty(exports, "format", {
  37069. enumerable: true,
  37070. get: function get() {
  37071. return format_1.format;
  37072. }
  37073. });
  37074. Object.defineProperty(exports, "write", {
  37075. enumerable: true,
  37076. get: function get() {
  37077. return format_1.write;
  37078. }
  37079. });
  37080. Object.defineProperty(exports, "writeToStream", {
  37081. enumerable: true,
  37082. get: function get() {
  37083. return format_1.writeToStream;
  37084. }
  37085. });
  37086. Object.defineProperty(exports, "writeToBuffer", {
  37087. enumerable: true,
  37088. get: function get() {
  37089. return format_1.writeToBuffer;
  37090. }
  37091. });
  37092. Object.defineProperty(exports, "writeToString", {
  37093. enumerable: true,
  37094. get: function get() {
  37095. return format_1.writeToString;
  37096. }
  37097. });
  37098. Object.defineProperty(exports, "writeToPath", {
  37099. enumerable: true,
  37100. get: function get() {
  37101. return format_1.writeToPath;
  37102. }
  37103. });
  37104. Object.defineProperty(exports, "CsvFormatterStream", {
  37105. enumerable: true,
  37106. get: function get() {
  37107. return format_1.CsvFormatterStream;
  37108. }
  37109. });
  37110. Object.defineProperty(exports, "FormatterOptions", {
  37111. enumerable: true,
  37112. get: function get() {
  37113. return format_1.FormatterOptions;
  37114. }
  37115. });
  37116. var parse_1 = require("@fast-csv/parse");
  37117. Object.defineProperty(exports, "parse", {
  37118. enumerable: true,
  37119. get: function get() {
  37120. return parse_1.parse;
  37121. }
  37122. });
  37123. Object.defineProperty(exports, "parseString", {
  37124. enumerable: true,
  37125. get: function get() {
  37126. return parse_1.parseString;
  37127. }
  37128. });
  37129. Object.defineProperty(exports, "parseStream", {
  37130. enumerable: true,
  37131. get: function get() {
  37132. return parse_1.parseStream;
  37133. }
  37134. });
  37135. Object.defineProperty(exports, "parseFile", {
  37136. enumerable: true,
  37137. get: function get() {
  37138. return parse_1.parseFile;
  37139. }
  37140. });
  37141. Object.defineProperty(exports, "ParserOptions", {
  37142. enumerable: true,
  37143. get: function get() {
  37144. return parse_1.ParserOptions;
  37145. }
  37146. });
  37147. Object.defineProperty(exports, "CsvParserStream", {
  37148. enumerable: true,
  37149. get: function get() {
  37150. return parse_1.CsvParserStream;
  37151. }
  37152. });
  37153. },{"@fast-csv/format":148,"@fast-csv/parse":152}],261:[function(require,module,exports){
  37154. 'use strict';
  37155. var Buffer = require('safe-buffer').Buffer;
  37156. var Transform = require('readable-stream').Transform;
  37157. var inherits = require('inherits');
  37158. function throwIfNotStringOrBuffer(val, prefix) {
  37159. if (!Buffer.isBuffer(val) && typeof val !== 'string') {
  37160. throw new TypeError(prefix + ' must be a string or a buffer');
  37161. }
  37162. }
  37163. function HashBase(blockSize) {
  37164. Transform.call(this);
  37165. this._block = Buffer.allocUnsafe(blockSize);
  37166. this._blockSize = blockSize;
  37167. this._blockOffset = 0;
  37168. this._length = [0, 0, 0, 0];
  37169. this._finalized = false;
  37170. }
  37171. inherits(HashBase, Transform);
  37172. HashBase.prototype._transform = function (chunk, encoding, callback) {
  37173. var error = null;
  37174. try {
  37175. this.update(chunk, encoding);
  37176. } catch (err) {
  37177. error = err;
  37178. }
  37179. callback(error);
  37180. };
  37181. HashBase.prototype._flush = function (callback) {
  37182. var error = null;
  37183. try {
  37184. this.push(this.digest());
  37185. } catch (err) {
  37186. error = err;
  37187. }
  37188. callback(error);
  37189. };
  37190. HashBase.prototype.update = function (data, encoding) {
  37191. throwIfNotStringOrBuffer(data, 'Data');
  37192. if (this._finalized) throw new Error('Digest already called');
  37193. if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding); // consume data
  37194. var block = this._block;
  37195. var offset = 0;
  37196. while (this._blockOffset + data.length - offset >= this._blockSize) {
  37197. for (var i = this._blockOffset; i < this._blockSize;) {
  37198. block[i++] = data[offset++];
  37199. }
  37200. this._update();
  37201. this._blockOffset = 0;
  37202. }
  37203. while (offset < data.length) {
  37204. block[this._blockOffset++] = data[offset++];
  37205. } // update length
  37206. for (var j = 0, carry = data.length * 8; carry > 0; ++j) {
  37207. this._length[j] += carry;
  37208. carry = this._length[j] / 0x0100000000 | 0;
  37209. if (carry > 0) this._length[j] -= 0x0100000000 * carry;
  37210. }
  37211. return this;
  37212. };
  37213. HashBase.prototype._update = function () {
  37214. throw new Error('_update is not implemented');
  37215. };
  37216. HashBase.prototype.digest = function (encoding) {
  37217. if (this._finalized) throw new Error('Digest already called');
  37218. this._finalized = true;
  37219. var digest = this._digest();
  37220. if (encoding !== undefined) digest = digest.toString(encoding); // reset state
  37221. this._block.fill(0);
  37222. this._blockOffset = 0;
  37223. for (var i = 0; i < 4; ++i) {
  37224. this._length[i] = 0;
  37225. }
  37226. return digest;
  37227. };
  37228. HashBase.prototype._digest = function () {
  37229. throw new Error('_digest is not implemented');
  37230. };
  37231. module.exports = HashBase;
  37232. },{"inherits":278,"readable-stream":382,"safe-buffer":262}],262:[function(require,module,exports){
  37233. arguments[4][214][0].apply(exports,arguments)
  37234. },{"buffer":216,"dup":214}],263:[function(require,module,exports){
  37235. "use strict";
  37236. var hash = exports;
  37237. hash.utils = require('./hash/utils');
  37238. hash.common = require('./hash/common');
  37239. hash.sha = require('./hash/sha');
  37240. hash.ripemd = require('./hash/ripemd');
  37241. hash.hmac = require('./hash/hmac'); // Proxy hash functions to the main object
  37242. hash.sha1 = hash.sha.sha1;
  37243. hash.sha256 = hash.sha.sha256;
  37244. hash.sha224 = hash.sha.sha224;
  37245. hash.sha384 = hash.sha.sha384;
  37246. hash.sha512 = hash.sha.sha512;
  37247. hash.ripemd160 = hash.ripemd.ripemd160;
  37248. },{"./hash/common":264,"./hash/hmac":265,"./hash/ripemd":266,"./hash/sha":267,"./hash/utils":274}],264:[function(require,module,exports){
  37249. 'use strict';
  37250. var utils = require('./utils');
  37251. var assert = require('minimalistic-assert');
  37252. function BlockHash() {
  37253. this.pending = null;
  37254. this.pendingTotal = 0;
  37255. this.blockSize = this.constructor.blockSize;
  37256. this.outSize = this.constructor.outSize;
  37257. this.hmacStrength = this.constructor.hmacStrength;
  37258. this.padLength = this.constructor.padLength / 8;
  37259. this.endian = 'big';
  37260. this._delta8 = this.blockSize / 8;
  37261. this._delta32 = this.blockSize / 32;
  37262. }
  37263. exports.BlockHash = BlockHash;
  37264. BlockHash.prototype.update = function update(msg, enc) {
  37265. // Convert message to array, pad it, and join into 32bit blocks
  37266. msg = utils.toArray(msg, enc);
  37267. if (!this.pending) this.pending = msg;else this.pending = this.pending.concat(msg);
  37268. this.pendingTotal += msg.length; // Enough data, try updating
  37269. if (this.pending.length >= this._delta8) {
  37270. msg = this.pending; // Process pending data in blocks
  37271. var r = msg.length % this._delta8;
  37272. this.pending = msg.slice(msg.length - r, msg.length);
  37273. if (this.pending.length === 0) this.pending = null;
  37274. msg = utils.join32(msg, 0, msg.length - r, this.endian);
  37275. for (var i = 0; i < msg.length; i += this._delta32) {
  37276. this._update(msg, i, i + this._delta32);
  37277. }
  37278. }
  37279. return this;
  37280. };
  37281. BlockHash.prototype.digest = function digest(enc) {
  37282. this.update(this._pad());
  37283. assert(this.pending === null);
  37284. return this._digest(enc);
  37285. };
  37286. BlockHash.prototype._pad = function pad() {
  37287. var len = this.pendingTotal;
  37288. var bytes = this._delta8;
  37289. var k = bytes - (len + this.padLength) % bytes;
  37290. var res = new Array(k + this.padLength);
  37291. res[0] = 0x80;
  37292. for (var i = 1; i < k; i++) {
  37293. res[i] = 0;
  37294. } // Append length
  37295. len <<= 3;
  37296. if (this.endian === 'big') {
  37297. for (var t = 8; t < this.padLength; t++) {
  37298. res[i++] = 0;
  37299. }
  37300. res[i++] = 0;
  37301. res[i++] = 0;
  37302. res[i++] = 0;
  37303. res[i++] = 0;
  37304. res[i++] = len >>> 24 & 0xff;
  37305. res[i++] = len >>> 16 & 0xff;
  37306. res[i++] = len >>> 8 & 0xff;
  37307. res[i++] = len & 0xff;
  37308. } else {
  37309. res[i++] = len & 0xff;
  37310. res[i++] = len >>> 8 & 0xff;
  37311. res[i++] = len >>> 16 & 0xff;
  37312. res[i++] = len >>> 24 & 0xff;
  37313. res[i++] = 0;
  37314. res[i++] = 0;
  37315. res[i++] = 0;
  37316. res[i++] = 0;
  37317. for (t = 8; t < this.padLength; t++) {
  37318. res[i++] = 0;
  37319. }
  37320. }
  37321. return res;
  37322. };
  37323. },{"./utils":274,"minimalistic-assert":328}],265:[function(require,module,exports){
  37324. 'use strict';
  37325. var utils = require('./utils');
  37326. var assert = require('minimalistic-assert');
  37327. function Hmac(hash, key, enc) {
  37328. if (!(this instanceof Hmac)) return new Hmac(hash, key, enc);
  37329. this.Hash = hash;
  37330. this.blockSize = hash.blockSize / 8;
  37331. this.outSize = hash.outSize / 8;
  37332. this.inner = null;
  37333. this.outer = null;
  37334. this._init(utils.toArray(key, enc));
  37335. }
  37336. module.exports = Hmac;
  37337. Hmac.prototype._init = function init(key) {
  37338. // Shorten key, if needed
  37339. if (key.length > this.blockSize) key = new this.Hash().update(key).digest();
  37340. assert(key.length <= this.blockSize); // Add padding to key
  37341. for (var i = key.length; i < this.blockSize; i++) {
  37342. key.push(0);
  37343. }
  37344. for (i = 0; i < key.length; i++) {
  37345. key[i] ^= 0x36;
  37346. }
  37347. this.inner = new this.Hash().update(key); // 0x36 ^ 0x5c = 0x6a
  37348. for (i = 0; i < key.length; i++) {
  37349. key[i] ^= 0x6a;
  37350. }
  37351. this.outer = new this.Hash().update(key);
  37352. };
  37353. Hmac.prototype.update = function update(msg, enc) {
  37354. this.inner.update(msg, enc);
  37355. return this;
  37356. };
  37357. Hmac.prototype.digest = function digest(enc) {
  37358. this.outer.update(this.inner.digest());
  37359. return this.outer.digest(enc);
  37360. };
  37361. },{"./utils":274,"minimalistic-assert":328}],266:[function(require,module,exports){
  37362. 'use strict';
  37363. var utils = require('./utils');
  37364. var common = require('./common');
  37365. var rotl32 = utils.rotl32;
  37366. var sum32 = utils.sum32;
  37367. var sum32_3 = utils.sum32_3;
  37368. var sum32_4 = utils.sum32_4;
  37369. var BlockHash = common.BlockHash;
  37370. function RIPEMD160() {
  37371. if (!(this instanceof RIPEMD160)) return new RIPEMD160();
  37372. BlockHash.call(this);
  37373. this.h = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
  37374. this.endian = 'little';
  37375. }
  37376. utils.inherits(RIPEMD160, BlockHash);
  37377. exports.ripemd160 = RIPEMD160;
  37378. RIPEMD160.blockSize = 512;
  37379. RIPEMD160.outSize = 160;
  37380. RIPEMD160.hmacStrength = 192;
  37381. RIPEMD160.padLength = 64;
  37382. RIPEMD160.prototype._update = function update(msg, start) {
  37383. var A = this.h[0];
  37384. var B = this.h[1];
  37385. var C = this.h[2];
  37386. var D = this.h[3];
  37387. var E = this.h[4];
  37388. var Ah = A;
  37389. var Bh = B;
  37390. var Ch = C;
  37391. var Dh = D;
  37392. var Eh = E;
  37393. for (var j = 0; j < 80; j++) {
  37394. var T = sum32(rotl32(sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)), s[j]), E);
  37395. A = E;
  37396. E = D;
  37397. D = rotl32(C, 10);
  37398. C = B;
  37399. B = T;
  37400. T = sum32(rotl32(sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)), sh[j]), Eh);
  37401. Ah = Eh;
  37402. Eh = Dh;
  37403. Dh = rotl32(Ch, 10);
  37404. Ch = Bh;
  37405. Bh = T;
  37406. }
  37407. T = sum32_3(this.h[1], C, Dh);
  37408. this.h[1] = sum32_3(this.h[2], D, Eh);
  37409. this.h[2] = sum32_3(this.h[3], E, Ah);
  37410. this.h[3] = sum32_3(this.h[4], A, Bh);
  37411. this.h[4] = sum32_3(this.h[0], B, Ch);
  37412. this.h[0] = T;
  37413. };
  37414. RIPEMD160.prototype._digest = function digest(enc) {
  37415. if (enc === 'hex') return utils.toHex32(this.h, 'little');else return utils.split32(this.h, 'little');
  37416. };
  37417. function f(j, x, y, z) {
  37418. 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);
  37419. }
  37420. function K(j) {
  37421. 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;
  37422. }
  37423. function Kh(j) {
  37424. 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;
  37425. }
  37426. 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];
  37427. 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];
  37428. 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];
  37429. 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];
  37430. },{"./common":264,"./utils":274}],267:[function(require,module,exports){
  37431. 'use strict';
  37432. exports.sha1 = require('./sha/1');
  37433. exports.sha224 = require('./sha/224');
  37434. exports.sha256 = require('./sha/256');
  37435. exports.sha384 = require('./sha/384');
  37436. exports.sha512 = require('./sha/512');
  37437. },{"./sha/1":268,"./sha/224":269,"./sha/256":270,"./sha/384":271,"./sha/512":272}],268:[function(require,module,exports){
  37438. 'use strict';
  37439. var utils = require('../utils');
  37440. var common = require('../common');
  37441. var shaCommon = require('./common');
  37442. var rotl32 = utils.rotl32;
  37443. var sum32 = utils.sum32;
  37444. var sum32_5 = utils.sum32_5;
  37445. var ft_1 = shaCommon.ft_1;
  37446. var BlockHash = common.BlockHash;
  37447. var sha1_K = [0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6];
  37448. function SHA1() {
  37449. if (!(this instanceof SHA1)) return new SHA1();
  37450. BlockHash.call(this);
  37451. this.h = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
  37452. this.W = new Array(80);
  37453. }
  37454. utils.inherits(SHA1, BlockHash);
  37455. module.exports = SHA1;
  37456. SHA1.blockSize = 512;
  37457. SHA1.outSize = 160;
  37458. SHA1.hmacStrength = 80;
  37459. SHA1.padLength = 64;
  37460. SHA1.prototype._update = function _update(msg, start) {
  37461. var W = this.W;
  37462. for (var i = 0; i < 16; i++) {
  37463. W[i] = msg[start + i];
  37464. }
  37465. for (; i < W.length; i++) {
  37466. W[i] = rotl32(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
  37467. }
  37468. var a = this.h[0];
  37469. var b = this.h[1];
  37470. var c = this.h[2];
  37471. var d = this.h[3];
  37472. var e = this.h[4];
  37473. for (i = 0; i < W.length; i++) {
  37474. var s = ~~(i / 20);
  37475. var t = sum32_5(rotl32(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]);
  37476. e = d;
  37477. d = c;
  37478. c = rotl32(b, 30);
  37479. b = a;
  37480. a = t;
  37481. }
  37482. this.h[0] = sum32(this.h[0], a);
  37483. this.h[1] = sum32(this.h[1], b);
  37484. this.h[2] = sum32(this.h[2], c);
  37485. this.h[3] = sum32(this.h[3], d);
  37486. this.h[4] = sum32(this.h[4], e);
  37487. };
  37488. SHA1.prototype._digest = function digest(enc) {
  37489. if (enc === 'hex') return utils.toHex32(this.h, 'big');else return utils.split32(this.h, 'big');
  37490. };
  37491. },{"../common":264,"../utils":274,"./common":273}],269:[function(require,module,exports){
  37492. 'use strict';
  37493. var utils = require('../utils');
  37494. var SHA256 = require('./256');
  37495. function SHA224() {
  37496. if (!(this instanceof SHA224)) return new SHA224();
  37497. SHA256.call(this);
  37498. this.h = [0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4];
  37499. }
  37500. utils.inherits(SHA224, SHA256);
  37501. module.exports = SHA224;
  37502. SHA224.blockSize = 512;
  37503. SHA224.outSize = 224;
  37504. SHA224.hmacStrength = 192;
  37505. SHA224.padLength = 64;
  37506. SHA224.prototype._digest = function digest(enc) {
  37507. // Just truncate output
  37508. if (enc === 'hex') return utils.toHex32(this.h.slice(0, 7), 'big');else return utils.split32(this.h.slice(0, 7), 'big');
  37509. };
  37510. },{"../utils":274,"./256":270}],270:[function(require,module,exports){
  37511. 'use strict';
  37512. var utils = require('../utils');
  37513. var common = require('../common');
  37514. var shaCommon = require('./common');
  37515. var assert = require('minimalistic-assert');
  37516. var sum32 = utils.sum32;
  37517. var sum32_4 = utils.sum32_4;
  37518. var sum32_5 = utils.sum32_5;
  37519. var ch32 = shaCommon.ch32;
  37520. var maj32 = shaCommon.maj32;
  37521. var s0_256 = shaCommon.s0_256;
  37522. var s1_256 = shaCommon.s1_256;
  37523. var g0_256 = shaCommon.g0_256;
  37524. var g1_256 = shaCommon.g1_256;
  37525. var BlockHash = common.BlockHash;
  37526. 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];
  37527. function SHA256() {
  37528. if (!(this instanceof SHA256)) return new SHA256();
  37529. BlockHash.call(this);
  37530. this.h = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];
  37531. this.k = sha256_K;
  37532. this.W = new Array(64);
  37533. }
  37534. utils.inherits(SHA256, BlockHash);
  37535. module.exports = SHA256;
  37536. SHA256.blockSize = 512;
  37537. SHA256.outSize = 256;
  37538. SHA256.hmacStrength = 192;
  37539. SHA256.padLength = 64;
  37540. SHA256.prototype._update = function _update(msg, start) {
  37541. var W = this.W;
  37542. for (var i = 0; i < 16; i++) {
  37543. W[i] = msg[start + i];
  37544. }
  37545. for (; i < W.length; i++) {
  37546. W[i] = sum32_4(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]);
  37547. }
  37548. var a = this.h[0];
  37549. var b = this.h[1];
  37550. var c = this.h[2];
  37551. var d = this.h[3];
  37552. var e = this.h[4];
  37553. var f = this.h[5];
  37554. var g = this.h[6];
  37555. var h = this.h[7];
  37556. assert(this.k.length === W.length);
  37557. for (i = 0; i < W.length; i++) {
  37558. var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]);
  37559. var T2 = sum32(s0_256(a), maj32(a, b, c));
  37560. h = g;
  37561. g = f;
  37562. f = e;
  37563. e = sum32(d, T1);
  37564. d = c;
  37565. c = b;
  37566. b = a;
  37567. a = sum32(T1, T2);
  37568. }
  37569. this.h[0] = sum32(this.h[0], a);
  37570. this.h[1] = sum32(this.h[1], b);
  37571. this.h[2] = sum32(this.h[2], c);
  37572. this.h[3] = sum32(this.h[3], d);
  37573. this.h[4] = sum32(this.h[4], e);
  37574. this.h[5] = sum32(this.h[5], f);
  37575. this.h[6] = sum32(this.h[6], g);
  37576. this.h[7] = sum32(this.h[7], h);
  37577. };
  37578. SHA256.prototype._digest = function digest(enc) {
  37579. if (enc === 'hex') return utils.toHex32(this.h, 'big');else return utils.split32(this.h, 'big');
  37580. };
  37581. },{"../common":264,"../utils":274,"./common":273,"minimalistic-assert":328}],271:[function(require,module,exports){
  37582. 'use strict';
  37583. var utils = require('../utils');
  37584. var SHA512 = require('./512');
  37585. function SHA384() {
  37586. if (!(this instanceof SHA384)) return new SHA384();
  37587. SHA512.call(this);
  37588. this.h = [0xcbbb9d5d, 0xc1059ed8, 0x629a292a, 0x367cd507, 0x9159015a, 0x3070dd17, 0x152fecd8, 0xf70e5939, 0x67332667, 0xffc00b31, 0x8eb44a87, 0x68581511, 0xdb0c2e0d, 0x64f98fa7, 0x47b5481d, 0xbefa4fa4];
  37589. }
  37590. utils.inherits(SHA384, SHA512);
  37591. module.exports = SHA384;
  37592. SHA384.blockSize = 1024;
  37593. SHA384.outSize = 384;
  37594. SHA384.hmacStrength = 192;
  37595. SHA384.padLength = 128;
  37596. SHA384.prototype._digest = function digest(enc) {
  37597. if (enc === 'hex') return utils.toHex32(this.h.slice(0, 12), 'big');else return utils.split32(this.h.slice(0, 12), 'big');
  37598. };
  37599. },{"../utils":274,"./512":272}],272:[function(require,module,exports){
  37600. 'use strict';
  37601. var utils = require('../utils');
  37602. var common = require('../common');
  37603. var assert = require('minimalistic-assert');
  37604. var rotr64_hi = utils.rotr64_hi;
  37605. var rotr64_lo = utils.rotr64_lo;
  37606. var shr64_hi = utils.shr64_hi;
  37607. var shr64_lo = utils.shr64_lo;
  37608. var sum64 = utils.sum64;
  37609. var sum64_hi = utils.sum64_hi;
  37610. var sum64_lo = utils.sum64_lo;
  37611. var sum64_4_hi = utils.sum64_4_hi;
  37612. var sum64_4_lo = utils.sum64_4_lo;
  37613. var sum64_5_hi = utils.sum64_5_hi;
  37614. var sum64_5_lo = utils.sum64_5_lo;
  37615. var BlockHash = common.BlockHash;
  37616. 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];
  37617. function SHA512() {
  37618. if (!(this instanceof SHA512)) return new SHA512();
  37619. BlockHash.call(this);
  37620. this.h = [0x6a09e667, 0xf3bcc908, 0xbb67ae85, 0x84caa73b, 0x3c6ef372, 0xfe94f82b, 0xa54ff53a, 0x5f1d36f1, 0x510e527f, 0xade682d1, 0x9b05688c, 0x2b3e6c1f, 0x1f83d9ab, 0xfb41bd6b, 0x5be0cd19, 0x137e2179];
  37621. this.k = sha512_K;
  37622. this.W = new Array(160);
  37623. }
  37624. utils.inherits(SHA512, BlockHash);
  37625. module.exports = SHA512;
  37626. SHA512.blockSize = 1024;
  37627. SHA512.outSize = 512;
  37628. SHA512.hmacStrength = 192;
  37629. SHA512.padLength = 128;
  37630. SHA512.prototype._prepareBlock = function _prepareBlock(msg, start) {
  37631. var W = this.W; // 32 x 32bit words
  37632. for (var i = 0; i < 32; i++) {
  37633. W[i] = msg[start + i];
  37634. }
  37635. for (; i < W.length; i += 2) {
  37636. var c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 2
  37637. var c0_lo = g1_512_lo(W[i - 4], W[i - 3]);
  37638. var c1_hi = W[i - 14]; // i - 7
  37639. var c1_lo = W[i - 13];
  37640. var c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 15
  37641. var c2_lo = g0_512_lo(W[i - 30], W[i - 29]);
  37642. var c3_hi = W[i - 32]; // i - 16
  37643. var c3_lo = W[i - 31];
  37644. W[i] = sum64_4_hi(c0_hi, c0_lo, c1_hi, c1_lo, c2_hi, c2_lo, c3_hi, c3_lo);
  37645. W[i + 1] = sum64_4_lo(c0_hi, c0_lo, c1_hi, c1_lo, c2_hi, c2_lo, c3_hi, c3_lo);
  37646. }
  37647. };
  37648. SHA512.prototype._update = function _update(msg, start) {
  37649. this._prepareBlock(msg, start);
  37650. var W = this.W;
  37651. var ah = this.h[0];
  37652. var al = this.h[1];
  37653. var bh = this.h[2];
  37654. var bl = this.h[3];
  37655. var ch = this.h[4];
  37656. var cl = this.h[5];
  37657. var dh = this.h[6];
  37658. var dl = this.h[7];
  37659. var eh = this.h[8];
  37660. var el = this.h[9];
  37661. var fh = this.h[10];
  37662. var fl = this.h[11];
  37663. var gh = this.h[12];
  37664. var gl = this.h[13];
  37665. var hh = this.h[14];
  37666. var hl = this.h[15];
  37667. assert(this.k.length === W.length);
  37668. for (var i = 0; i < W.length; i += 2) {
  37669. var c0_hi = hh;
  37670. var c0_lo = hl;
  37671. var c1_hi = s1_512_hi(eh, el);
  37672. var c1_lo = s1_512_lo(eh, el);
  37673. var c2_hi = ch64_hi(eh, el, fh, fl, gh, gl);
  37674. var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl);
  37675. var c3_hi = this.k[i];
  37676. var c3_lo = this.k[i + 1];
  37677. var c4_hi = W[i];
  37678. var c4_lo = W[i + 1];
  37679. 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);
  37680. 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);
  37681. c0_hi = s0_512_hi(ah, al);
  37682. c0_lo = s0_512_lo(ah, al);
  37683. c1_hi = maj64_hi(ah, al, bh, bl, ch, cl);
  37684. c1_lo = maj64_lo(ah, al, bh, bl, ch, cl);
  37685. var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo);
  37686. var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo);
  37687. hh = gh;
  37688. hl = gl;
  37689. gh = fh;
  37690. gl = fl;
  37691. fh = eh;
  37692. fl = el;
  37693. eh = sum64_hi(dh, dl, T1_hi, T1_lo);
  37694. el = sum64_lo(dl, dl, T1_hi, T1_lo);
  37695. dh = ch;
  37696. dl = cl;
  37697. ch = bh;
  37698. cl = bl;
  37699. bh = ah;
  37700. bl = al;
  37701. ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo);
  37702. al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo);
  37703. }
  37704. sum64(this.h, 0, ah, al);
  37705. sum64(this.h, 2, bh, bl);
  37706. sum64(this.h, 4, ch, cl);
  37707. sum64(this.h, 6, dh, dl);
  37708. sum64(this.h, 8, eh, el);
  37709. sum64(this.h, 10, fh, fl);
  37710. sum64(this.h, 12, gh, gl);
  37711. sum64(this.h, 14, hh, hl);
  37712. };
  37713. SHA512.prototype._digest = function digest(enc) {
  37714. if (enc === 'hex') return utils.toHex32(this.h, 'big');else return utils.split32(this.h, 'big');
  37715. };
  37716. function ch64_hi(xh, xl, yh, yl, zh) {
  37717. var r = xh & yh ^ ~xh & zh;
  37718. if (r < 0) r += 0x100000000;
  37719. return r;
  37720. }
  37721. function ch64_lo(xh, xl, yh, yl, zh, zl) {
  37722. var r = xl & yl ^ ~xl & zl;
  37723. if (r < 0) r += 0x100000000;
  37724. return r;
  37725. }
  37726. function maj64_hi(xh, xl, yh, yl, zh) {
  37727. var r = xh & yh ^ xh & zh ^ yh & zh;
  37728. if (r < 0) r += 0x100000000;
  37729. return r;
  37730. }
  37731. function maj64_lo(xh, xl, yh, yl, zh, zl) {
  37732. var r = xl & yl ^ xl & zl ^ yl & zl;
  37733. if (r < 0) r += 0x100000000;
  37734. return r;
  37735. }
  37736. function s0_512_hi(xh, xl) {
  37737. var c0_hi = rotr64_hi(xh, xl, 28);
  37738. var c1_hi = rotr64_hi(xl, xh, 2); // 34
  37739. var c2_hi = rotr64_hi(xl, xh, 7); // 39
  37740. var r = c0_hi ^ c1_hi ^ c2_hi;
  37741. if (r < 0) r += 0x100000000;
  37742. return r;
  37743. }
  37744. function s0_512_lo(xh, xl) {
  37745. var c0_lo = rotr64_lo(xh, xl, 28);
  37746. var c1_lo = rotr64_lo(xl, xh, 2); // 34
  37747. var c2_lo = rotr64_lo(xl, xh, 7); // 39
  37748. var r = c0_lo ^ c1_lo ^ c2_lo;
  37749. if (r < 0) r += 0x100000000;
  37750. return r;
  37751. }
  37752. function s1_512_hi(xh, xl) {
  37753. var c0_hi = rotr64_hi(xh, xl, 14);
  37754. var c1_hi = rotr64_hi(xh, xl, 18);
  37755. var c2_hi = rotr64_hi(xl, xh, 9); // 41
  37756. var r = c0_hi ^ c1_hi ^ c2_hi;
  37757. if (r < 0) r += 0x100000000;
  37758. return r;
  37759. }
  37760. function s1_512_lo(xh, xl) {
  37761. var c0_lo = rotr64_lo(xh, xl, 14);
  37762. var c1_lo = rotr64_lo(xh, xl, 18);
  37763. var c2_lo = rotr64_lo(xl, xh, 9); // 41
  37764. var r = c0_lo ^ c1_lo ^ c2_lo;
  37765. if (r < 0) r += 0x100000000;
  37766. return r;
  37767. }
  37768. function g0_512_hi(xh, xl) {
  37769. var c0_hi = rotr64_hi(xh, xl, 1);
  37770. var c1_hi = rotr64_hi(xh, xl, 8);
  37771. var c2_hi = shr64_hi(xh, xl, 7);
  37772. var r = c0_hi ^ c1_hi ^ c2_hi;
  37773. if (r < 0) r += 0x100000000;
  37774. return r;
  37775. }
  37776. function g0_512_lo(xh, xl) {
  37777. var c0_lo = rotr64_lo(xh, xl, 1);
  37778. var c1_lo = rotr64_lo(xh, xl, 8);
  37779. var c2_lo = shr64_lo(xh, xl, 7);
  37780. var r = c0_lo ^ c1_lo ^ c2_lo;
  37781. if (r < 0) r += 0x100000000;
  37782. return r;
  37783. }
  37784. function g1_512_hi(xh, xl) {
  37785. var c0_hi = rotr64_hi(xh, xl, 19);
  37786. var c1_hi = rotr64_hi(xl, xh, 29); // 61
  37787. var c2_hi = shr64_hi(xh, xl, 6);
  37788. var r = c0_hi ^ c1_hi ^ c2_hi;
  37789. if (r < 0) r += 0x100000000;
  37790. return r;
  37791. }
  37792. function g1_512_lo(xh, xl) {
  37793. var c0_lo = rotr64_lo(xh, xl, 19);
  37794. var c1_lo = rotr64_lo(xl, xh, 29); // 61
  37795. var c2_lo = shr64_lo(xh, xl, 6);
  37796. var r = c0_lo ^ c1_lo ^ c2_lo;
  37797. if (r < 0) r += 0x100000000;
  37798. return r;
  37799. }
  37800. },{"../common":264,"../utils":274,"minimalistic-assert":328}],273:[function(require,module,exports){
  37801. 'use strict';
  37802. var utils = require('../utils');
  37803. var rotr32 = utils.rotr32;
  37804. function ft_1(s, x, y, z) {
  37805. if (s === 0) return ch32(x, y, z);
  37806. if (s === 1 || s === 3) return p32(x, y, z);
  37807. if (s === 2) return maj32(x, y, z);
  37808. }
  37809. exports.ft_1 = ft_1;
  37810. function ch32(x, y, z) {
  37811. return x & y ^ ~x & z;
  37812. }
  37813. exports.ch32 = ch32;
  37814. function maj32(x, y, z) {
  37815. return x & y ^ x & z ^ y & z;
  37816. }
  37817. exports.maj32 = maj32;
  37818. function p32(x, y, z) {
  37819. return x ^ y ^ z;
  37820. }
  37821. exports.p32 = p32;
  37822. function s0_256(x) {
  37823. return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
  37824. }
  37825. exports.s0_256 = s0_256;
  37826. function s1_256(x) {
  37827. return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
  37828. }
  37829. exports.s1_256 = s1_256;
  37830. function g0_256(x) {
  37831. return rotr32(x, 7) ^ rotr32(x, 18) ^ x >>> 3;
  37832. }
  37833. exports.g0_256 = g0_256;
  37834. function g1_256(x) {
  37835. return rotr32(x, 17) ^ rotr32(x, 19) ^ x >>> 10;
  37836. }
  37837. exports.g1_256 = g1_256;
  37838. },{"../utils":274}],274:[function(require,module,exports){
  37839. 'use strict';
  37840. var assert = require('minimalistic-assert');
  37841. var inherits = require('inherits');
  37842. exports.inherits = inherits;
  37843. function isSurrogatePair(msg, i) {
  37844. if ((msg.charCodeAt(i) & 0xFC00) !== 0xD800) {
  37845. return false;
  37846. }
  37847. if (i < 0 || i + 1 >= msg.length) {
  37848. return false;
  37849. }
  37850. return (msg.charCodeAt(i + 1) & 0xFC00) === 0xDC00;
  37851. }
  37852. function toArray(msg, enc) {
  37853. if (Array.isArray(msg)) return msg.slice();
  37854. if (!msg) return [];
  37855. var res = [];
  37856. if (typeof msg === 'string') {
  37857. if (!enc) {
  37858. // Inspired by stringToUtf8ByteArray() in closure-library by Google
  37859. // https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143
  37860. // Apache License 2.0
  37861. // https://github.com/google/closure-library/blob/master/LICENSE
  37862. var p = 0;
  37863. for (var i = 0; i < msg.length; i++) {
  37864. var c = msg.charCodeAt(i);
  37865. if (c < 128) {
  37866. res[p++] = c;
  37867. } else if (c < 2048) {
  37868. res[p++] = c >> 6 | 192;
  37869. res[p++] = c & 63 | 128;
  37870. } else if (isSurrogatePair(msg, i)) {
  37871. c = 0x10000 + ((c & 0x03FF) << 10) + (msg.charCodeAt(++i) & 0x03FF);
  37872. res[p++] = c >> 18 | 240;
  37873. res[p++] = c >> 12 & 63 | 128;
  37874. res[p++] = c >> 6 & 63 | 128;
  37875. res[p++] = c & 63 | 128;
  37876. } else {
  37877. res[p++] = c >> 12 | 224;
  37878. res[p++] = c >> 6 & 63 | 128;
  37879. res[p++] = c & 63 | 128;
  37880. }
  37881. }
  37882. } else if (enc === 'hex') {
  37883. msg = msg.replace(/[^a-z0-9]+/ig, '');
  37884. if (msg.length % 2 !== 0) msg = '0' + msg;
  37885. for (i = 0; i < msg.length; i += 2) {
  37886. res.push(parseInt(msg[i] + msg[i + 1], 16));
  37887. }
  37888. }
  37889. } else {
  37890. for (i = 0; i < msg.length; i++) {
  37891. res[i] = msg[i] | 0;
  37892. }
  37893. }
  37894. return res;
  37895. }
  37896. exports.toArray = toArray;
  37897. function toHex(msg) {
  37898. var res = '';
  37899. for (var i = 0; i < msg.length; i++) {
  37900. res += zero2(msg[i].toString(16));
  37901. }
  37902. return res;
  37903. }
  37904. exports.toHex = toHex;
  37905. function htonl(w) {
  37906. var res = w >>> 24 | w >>> 8 & 0xff00 | w << 8 & 0xff0000 | (w & 0xff) << 24;
  37907. return res >>> 0;
  37908. }
  37909. exports.htonl = htonl;
  37910. function toHex32(msg, endian) {
  37911. var res = '';
  37912. for (var i = 0; i < msg.length; i++) {
  37913. var w = msg[i];
  37914. if (endian === 'little') w = htonl(w);
  37915. res += zero8(w.toString(16));
  37916. }
  37917. return res;
  37918. }
  37919. exports.toHex32 = toHex32;
  37920. function zero2(word) {
  37921. if (word.length === 1) return '0' + word;else return word;
  37922. }
  37923. exports.zero2 = zero2;
  37924. function zero8(word) {
  37925. 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;
  37926. }
  37927. exports.zero8 = zero8;
  37928. function join32(msg, start, end, endian) {
  37929. var len = end - start;
  37930. assert(len % 4 === 0);
  37931. var res = new Array(len / 4);
  37932. for (var i = 0, k = start; i < res.length; i++, k += 4) {
  37933. var w;
  37934. 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];
  37935. res[i] = w >>> 0;
  37936. }
  37937. return res;
  37938. }
  37939. exports.join32 = join32;
  37940. function split32(msg, endian) {
  37941. var res = new Array(msg.length * 4);
  37942. for (var i = 0, k = 0; i < msg.length; i++, k += 4) {
  37943. var m = msg[i];
  37944. if (endian === 'big') {
  37945. res[k] = m >>> 24;
  37946. res[k + 1] = m >>> 16 & 0xff;
  37947. res[k + 2] = m >>> 8 & 0xff;
  37948. res[k + 3] = m & 0xff;
  37949. } else {
  37950. res[k + 3] = m >>> 24;
  37951. res[k + 2] = m >>> 16 & 0xff;
  37952. res[k + 1] = m >>> 8 & 0xff;
  37953. res[k] = m & 0xff;
  37954. }
  37955. }
  37956. return res;
  37957. }
  37958. exports.split32 = split32;
  37959. function rotr32(w, b) {
  37960. return w >>> b | w << 32 - b;
  37961. }
  37962. exports.rotr32 = rotr32;
  37963. function rotl32(w, b) {
  37964. return w << b | w >>> 32 - b;
  37965. }
  37966. exports.rotl32 = rotl32;
  37967. function sum32(a, b) {
  37968. return a + b >>> 0;
  37969. }
  37970. exports.sum32 = sum32;
  37971. function sum32_3(a, b, c) {
  37972. return a + b + c >>> 0;
  37973. }
  37974. exports.sum32_3 = sum32_3;
  37975. function sum32_4(a, b, c, d) {
  37976. return a + b + c + d >>> 0;
  37977. }
  37978. exports.sum32_4 = sum32_4;
  37979. function sum32_5(a, b, c, d, e) {
  37980. return a + b + c + d + e >>> 0;
  37981. }
  37982. exports.sum32_5 = sum32_5;
  37983. function sum64(buf, pos, ah, al) {
  37984. var bh = buf[pos];
  37985. var bl = buf[pos + 1];
  37986. var lo = al + bl >>> 0;
  37987. var hi = (lo < al ? 1 : 0) + ah + bh;
  37988. buf[pos] = hi >>> 0;
  37989. buf[pos + 1] = lo;
  37990. }
  37991. exports.sum64 = sum64;
  37992. function sum64_hi(ah, al, bh, bl) {
  37993. var lo = al + bl >>> 0;
  37994. var hi = (lo < al ? 1 : 0) + ah + bh;
  37995. return hi >>> 0;
  37996. }
  37997. exports.sum64_hi = sum64_hi;
  37998. function sum64_lo(ah, al, bh, bl) {
  37999. var lo = al + bl;
  38000. return lo >>> 0;
  38001. }
  38002. exports.sum64_lo = sum64_lo;
  38003. function sum64_4_hi(ah, al, bh, bl, ch, cl, dh, dl) {
  38004. var carry = 0;
  38005. var lo = al;
  38006. lo = lo + bl >>> 0;
  38007. carry += lo < al ? 1 : 0;
  38008. lo = lo + cl >>> 0;
  38009. carry += lo < cl ? 1 : 0;
  38010. lo = lo + dl >>> 0;
  38011. carry += lo < dl ? 1 : 0;
  38012. var hi = ah + bh + ch + dh + carry;
  38013. return hi >>> 0;
  38014. }
  38015. exports.sum64_4_hi = sum64_4_hi;
  38016. function sum64_4_lo(ah, al, bh, bl, ch, cl, dh, dl) {
  38017. var lo = al + bl + cl + dl;
  38018. return lo >>> 0;
  38019. }
  38020. exports.sum64_4_lo = sum64_4_lo;
  38021. function sum64_5_hi(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
  38022. var carry = 0;
  38023. var lo = al;
  38024. lo = lo + bl >>> 0;
  38025. carry += lo < al ? 1 : 0;
  38026. lo = lo + cl >>> 0;
  38027. carry += lo < cl ? 1 : 0;
  38028. lo = lo + dl >>> 0;
  38029. carry += lo < dl ? 1 : 0;
  38030. lo = lo + el >>> 0;
  38031. carry += lo < el ? 1 : 0;
  38032. var hi = ah + bh + ch + dh + eh + carry;
  38033. return hi >>> 0;
  38034. }
  38035. exports.sum64_5_hi = sum64_5_hi;
  38036. function sum64_5_lo(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
  38037. var lo = al + bl + cl + dl + el;
  38038. return lo >>> 0;
  38039. }
  38040. exports.sum64_5_lo = sum64_5_lo;
  38041. function rotr64_hi(ah, al, num) {
  38042. var r = al << 32 - num | ah >>> num;
  38043. return r >>> 0;
  38044. }
  38045. exports.rotr64_hi = rotr64_hi;
  38046. function rotr64_lo(ah, al, num) {
  38047. var r = ah << 32 - num | al >>> num;
  38048. return r >>> 0;
  38049. }
  38050. exports.rotr64_lo = rotr64_lo;
  38051. function shr64_hi(ah, al, num) {
  38052. return ah >>> num;
  38053. }
  38054. exports.shr64_hi = shr64_hi;
  38055. function shr64_lo(ah, al, num) {
  38056. var r = ah << 32 - num | al >>> num;
  38057. return r >>> 0;
  38058. }
  38059. exports.shr64_lo = shr64_lo;
  38060. },{"inherits":278,"minimalistic-assert":328}],275:[function(require,module,exports){
  38061. 'use strict';
  38062. var hash = require('hash.js');
  38063. var utils = require('minimalistic-crypto-utils');
  38064. var assert = require('minimalistic-assert');
  38065. function HmacDRBG(options) {
  38066. if (!(this instanceof HmacDRBG)) return new HmacDRBG(options);
  38067. this.hash = options.hash;
  38068. this.predResist = !!options.predResist;
  38069. this.outLen = this.hash.outSize;
  38070. this.minEntropy = options.minEntropy || this.hash.hmacStrength;
  38071. this._reseed = null;
  38072. this.reseedInterval = null;
  38073. this.K = null;
  38074. this.V = null;
  38075. var entropy = utils.toArray(options.entropy, options.entropyEnc || 'hex');
  38076. var nonce = utils.toArray(options.nonce, options.nonceEnc || 'hex');
  38077. var pers = utils.toArray(options.pers, options.persEnc || 'hex');
  38078. assert(entropy.length >= this.minEntropy / 8, 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
  38079. this._init(entropy, nonce, pers);
  38080. }
  38081. module.exports = HmacDRBG;
  38082. HmacDRBG.prototype._init = function init(entropy, nonce, pers) {
  38083. var seed = entropy.concat(nonce).concat(pers);
  38084. this.K = new Array(this.outLen / 8);
  38085. this.V = new Array(this.outLen / 8);
  38086. for (var i = 0; i < this.V.length; i++) {
  38087. this.K[i] = 0x00;
  38088. this.V[i] = 0x01;
  38089. }
  38090. this._update(seed);
  38091. this._reseed = 1;
  38092. this.reseedInterval = 0x1000000000000; // 2^48
  38093. };
  38094. HmacDRBG.prototype._hmac = function hmac() {
  38095. return new hash.hmac(this.hash, this.K);
  38096. };
  38097. HmacDRBG.prototype._update = function update(seed) {
  38098. var kmac = this._hmac().update(this.V).update([0x00]);
  38099. if (seed) kmac = kmac.update(seed);
  38100. this.K = kmac.digest();
  38101. this.V = this._hmac().update(this.V).digest();
  38102. if (!seed) return;
  38103. this.K = this._hmac().update(this.V).update([0x01]).update(seed).digest();
  38104. this.V = this._hmac().update(this.V).digest();
  38105. };
  38106. HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc) {
  38107. // Optional entropy enc
  38108. if (typeof entropyEnc !== 'string') {
  38109. addEnc = add;
  38110. add = entropyEnc;
  38111. entropyEnc = null;
  38112. }
  38113. entropy = utils.toArray(entropy, entropyEnc);
  38114. add = utils.toArray(add, addEnc);
  38115. assert(entropy.length >= this.minEntropy / 8, 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
  38116. this._update(entropy.concat(add || []));
  38117. this._reseed = 1;
  38118. };
  38119. HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) {
  38120. if (this._reseed > this.reseedInterval) throw new Error('Reseed is required'); // Optional encoding
  38121. if (typeof enc !== 'string') {
  38122. addEnc = add;
  38123. add = enc;
  38124. enc = null;
  38125. } // Optional additional data
  38126. if (add) {
  38127. add = utils.toArray(add, addEnc || 'hex');
  38128. this._update(add);
  38129. }
  38130. var temp = [];
  38131. while (temp.length < len) {
  38132. this.V = this._hmac().update(this.V).digest();
  38133. temp = temp.concat(this.V);
  38134. }
  38135. var res = temp.slice(0, len);
  38136. this._update(add);
  38137. this._reseed++;
  38138. return utils.encode(res, enc);
  38139. };
  38140. },{"hash.js":263,"minimalistic-assert":328,"minimalistic-crypto-utils":329}],276:[function(require,module,exports){
  38141. "use strict";
  38142. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  38143. var e, m;
  38144. var eLen = nBytes * 8 - mLen - 1;
  38145. var eMax = (1 << eLen) - 1;
  38146. var eBias = eMax >> 1;
  38147. var nBits = -7;
  38148. var i = isLE ? nBytes - 1 : 0;
  38149. var d = isLE ? -1 : 1;
  38150. var s = buffer[offset + i];
  38151. i += d;
  38152. e = s & (1 << -nBits) - 1;
  38153. s >>= -nBits;
  38154. nBits += eLen;
  38155. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  38156. m = e & (1 << -nBits) - 1;
  38157. e >>= -nBits;
  38158. nBits += mLen;
  38159. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  38160. if (e === 0) {
  38161. e = 1 - eBias;
  38162. } else if (e === eMax) {
  38163. return m ? NaN : (s ? -1 : 1) * Infinity;
  38164. } else {
  38165. m = m + Math.pow(2, mLen);
  38166. e = e - eBias;
  38167. }
  38168. return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
  38169. };
  38170. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  38171. var e, m, c;
  38172. var eLen = nBytes * 8 - mLen - 1;
  38173. var eMax = (1 << eLen) - 1;
  38174. var eBias = eMax >> 1;
  38175. var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
  38176. var i = isLE ? 0 : nBytes - 1;
  38177. var d = isLE ? 1 : -1;
  38178. var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
  38179. value = Math.abs(value);
  38180. if (isNaN(value) || value === Infinity) {
  38181. m = isNaN(value) ? 1 : 0;
  38182. e = eMax;
  38183. } else {
  38184. e = Math.floor(Math.log(value) / Math.LN2);
  38185. if (value * (c = Math.pow(2, -e)) < 1) {
  38186. e--;
  38187. c *= 2;
  38188. }
  38189. if (e + eBias >= 1) {
  38190. value += rt / c;
  38191. } else {
  38192. value += rt * Math.pow(2, 1 - eBias);
  38193. }
  38194. if (value * c >= 2) {
  38195. e++;
  38196. c /= 2;
  38197. }
  38198. if (e + eBias >= eMax) {
  38199. m = 0;
  38200. e = eMax;
  38201. } else if (e + eBias >= 1) {
  38202. m = (value * c - 1) * Math.pow(2, mLen);
  38203. e = e + eBias;
  38204. } else {
  38205. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  38206. e = 0;
  38207. }
  38208. }
  38209. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  38210. e = e << mLen | m;
  38211. eLen += mLen;
  38212. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  38213. buffer[offset + i - d] |= s * 128;
  38214. };
  38215. },{}],277:[function(require,module,exports){
  38216. (function (global){
  38217. 'use strict';
  38218. var Mutation = global.MutationObserver || global.WebKitMutationObserver;
  38219. var scheduleDrain;
  38220. {
  38221. if (Mutation) {
  38222. var called = 0;
  38223. var observer = new Mutation(nextTick);
  38224. var element = global.document.createTextNode('');
  38225. observer.observe(element, {
  38226. characterData: true
  38227. });
  38228. scheduleDrain = function scheduleDrain() {
  38229. element.data = called = ++called % 2;
  38230. };
  38231. } else if (!global.setImmediate && typeof global.MessageChannel !== 'undefined') {
  38232. var channel = new global.MessageChannel();
  38233. channel.port1.onmessage = nextTick;
  38234. scheduleDrain = function scheduleDrain() {
  38235. channel.port2.postMessage(0);
  38236. };
  38237. } else if ('document' in global && 'onreadystatechange' in global.document.createElement('script')) {
  38238. scheduleDrain = function scheduleDrain() {
  38239. // Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
  38240. // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
  38241. var scriptEl = global.document.createElement('script');
  38242. scriptEl.onreadystatechange = function () {
  38243. nextTick();
  38244. scriptEl.onreadystatechange = null;
  38245. scriptEl.parentNode.removeChild(scriptEl);
  38246. scriptEl = null;
  38247. };
  38248. global.document.documentElement.appendChild(scriptEl);
  38249. };
  38250. } else {
  38251. scheduleDrain = function scheduleDrain() {
  38252. setTimeout(nextTick, 0);
  38253. };
  38254. }
  38255. }
  38256. var draining;
  38257. var queue = []; //named nextTick for less confusing stack traces
  38258. function nextTick() {
  38259. draining = true;
  38260. var i, oldQueue;
  38261. var len = queue.length;
  38262. while (len) {
  38263. oldQueue = queue;
  38264. queue = [];
  38265. i = -1;
  38266. while (++i < len) {
  38267. oldQueue[i]();
  38268. }
  38269. len = queue.length;
  38270. }
  38271. draining = false;
  38272. }
  38273. module.exports = immediate;
  38274. function immediate(task) {
  38275. if (queue.push(task) === 1 && !draining) {
  38276. scheduleDrain();
  38277. }
  38278. }
  38279. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  38280. },{}],278:[function(require,module,exports){
  38281. "use strict";
  38282. if (typeof Object.create === 'function') {
  38283. // implementation from standard node.js 'util' module
  38284. module.exports = function inherits(ctor, superCtor) {
  38285. if (superCtor) {
  38286. ctor.super_ = superCtor;
  38287. ctor.prototype = Object.create(superCtor.prototype, {
  38288. constructor: {
  38289. value: ctor,
  38290. enumerable: false,
  38291. writable: true,
  38292. configurable: true
  38293. }
  38294. });
  38295. }
  38296. };
  38297. } else {
  38298. // old school shim for old browsers
  38299. module.exports = function inherits(ctor, superCtor) {
  38300. if (superCtor) {
  38301. ctor.super_ = superCtor;
  38302. var TempCtor = function TempCtor() {};
  38303. TempCtor.prototype = superCtor.prototype;
  38304. ctor.prototype = new TempCtor();
  38305. ctor.prototype.constructor = ctor;
  38306. }
  38307. };
  38308. }
  38309. },{}],279:[function(require,module,exports){
  38310. "use strict";
  38311. /*!
  38312. * Determine if an object is a Buffer
  38313. *
  38314. * @author Feross Aboukhadijeh <https://feross.org>
  38315. * @license MIT
  38316. */
  38317. // The _isBuffer check is for Safari 5-7 support, because it's missing
  38318. // Object.prototype.constructor. Remove this eventually
  38319. module.exports = function (obj) {
  38320. return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer);
  38321. };
  38322. function isBuffer(obj) {
  38323. return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj);
  38324. } // For Node v0.10 support. Remove this eventually.
  38325. function isSlowBuffer(obj) {
  38326. return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0));
  38327. }
  38328. },{}],280:[function(require,module,exports){
  38329. "use strict";
  38330. var toString = {}.toString;
  38331. module.exports = Array.isArray || function (arr) {
  38332. return toString.call(arr) == '[object Array]';
  38333. };
  38334. },{}],281:[function(require,module,exports){
  38335. 'use strict';
  38336. var utils = require('./utils');
  38337. var support = require('./support'); // private property
  38338. var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; // public method for encoding
  38339. exports.encode = function (input) {
  38340. var output = [];
  38341. var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
  38342. var i = 0,
  38343. len = input.length,
  38344. remainingBytes = len;
  38345. var isArray = utils.getTypeOf(input) !== "string";
  38346. while (i < input.length) {
  38347. remainingBytes = len - i;
  38348. if (!isArray) {
  38349. chr1 = input.charCodeAt(i++);
  38350. chr2 = i < len ? input.charCodeAt(i++) : 0;
  38351. chr3 = i < len ? input.charCodeAt(i++) : 0;
  38352. } else {
  38353. chr1 = input[i++];
  38354. chr2 = i < len ? input[i++] : 0;
  38355. chr3 = i < len ? input[i++] : 0;
  38356. }
  38357. enc1 = chr1 >> 2;
  38358. enc2 = (chr1 & 3) << 4 | chr2 >> 4;
  38359. enc3 = remainingBytes > 1 ? (chr2 & 15) << 2 | chr3 >> 6 : 64;
  38360. enc4 = remainingBytes > 2 ? chr3 & 63 : 64;
  38361. output.push(_keyStr.charAt(enc1) + _keyStr.charAt(enc2) + _keyStr.charAt(enc3) + _keyStr.charAt(enc4));
  38362. }
  38363. return output.join("");
  38364. }; // public method for decoding
  38365. exports.decode = function (input) {
  38366. var chr1, chr2, chr3;
  38367. var enc1, enc2, enc3, enc4;
  38368. var i = 0,
  38369. resultIndex = 0;
  38370. var dataUrlPrefix = "data:";
  38371. if (input.substr(0, dataUrlPrefix.length) === dataUrlPrefix) {
  38372. // This is a common error: people give a data url
  38373. // (data:image/png;base64,iVBOR...) with a {base64: true} and
  38374. // wonders why things don't work.
  38375. // We can detect that the string input looks like a data url but we
  38376. // *can't* be sure it is one: removing everything up to the comma would
  38377. // be too dangerous.
  38378. throw new Error("Invalid base64 input, it looks like a data url.");
  38379. }
  38380. input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
  38381. var totalLength = input.length * 3 / 4;
  38382. if (input.charAt(input.length - 1) === _keyStr.charAt(64)) {
  38383. totalLength--;
  38384. }
  38385. if (input.charAt(input.length - 2) === _keyStr.charAt(64)) {
  38386. totalLength--;
  38387. }
  38388. if (totalLength % 1 !== 0) {
  38389. // totalLength is not an integer, the length does not match a valid
  38390. // base64 content. That can happen if:
  38391. // - the input is not a base64 content
  38392. // - the input is *almost* a base64 content, with a extra chars at the
  38393. // beginning or at the end
  38394. // - the input uses a base64 variant (base64url for example)
  38395. throw new Error("Invalid base64 input, bad content length.");
  38396. }
  38397. var output;
  38398. if (support.uint8array) {
  38399. output = new Uint8Array(totalLength | 0);
  38400. } else {
  38401. output = new Array(totalLength | 0);
  38402. }
  38403. while (i < input.length) {
  38404. enc1 = _keyStr.indexOf(input.charAt(i++));
  38405. enc2 = _keyStr.indexOf(input.charAt(i++));
  38406. enc3 = _keyStr.indexOf(input.charAt(i++));
  38407. enc4 = _keyStr.indexOf(input.charAt(i++));
  38408. chr1 = enc1 << 2 | enc2 >> 4;
  38409. chr2 = (enc2 & 15) << 4 | enc3 >> 2;
  38410. chr3 = (enc3 & 3) << 6 | enc4;
  38411. output[resultIndex++] = chr1;
  38412. if (enc3 !== 64) {
  38413. output[resultIndex++] = chr2;
  38414. }
  38415. if (enc4 !== 64) {
  38416. output[resultIndex++] = chr3;
  38417. }
  38418. }
  38419. return output;
  38420. };
  38421. },{"./support":310,"./utils":312}],282:[function(require,module,exports){
  38422. 'use strict';
  38423. var external = require("./external");
  38424. var DataWorker = require('./stream/DataWorker');
  38425. var DataLengthProbe = require('./stream/DataLengthProbe');
  38426. var Crc32Probe = require('./stream/Crc32Probe');
  38427. var DataLengthProbe = require('./stream/DataLengthProbe');
  38428. /**
  38429. * Represent a compressed object, with everything needed to decompress it.
  38430. * @constructor
  38431. * @param {number} compressedSize the size of the data compressed.
  38432. * @param {number} uncompressedSize the size of the data after decompression.
  38433. * @param {number} crc32 the crc32 of the decompressed file.
  38434. * @param {object} compression the type of compression, see lib/compressions.js.
  38435. * @param {String|ArrayBuffer|Uint8Array|Buffer} data the compressed data.
  38436. */
  38437. function CompressedObject(compressedSize, uncompressedSize, crc32, compression, data) {
  38438. this.compressedSize = compressedSize;
  38439. this.uncompressedSize = uncompressedSize;
  38440. this.crc32 = crc32;
  38441. this.compression = compression;
  38442. this.compressedContent = data;
  38443. }
  38444. CompressedObject.prototype = {
  38445. /**
  38446. * Create a worker to get the uncompressed content.
  38447. * @return {GenericWorker} the worker.
  38448. */
  38449. getContentWorker: function getContentWorker() {
  38450. var worker = new DataWorker(external.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new DataLengthProbe("data_length"));
  38451. var that = this;
  38452. worker.on("end", function () {
  38453. if (this.streamInfo['data_length'] !== that.uncompressedSize) {
  38454. throw new Error("Bug : uncompressed data size mismatch");
  38455. }
  38456. });
  38457. return worker;
  38458. },
  38459. /**
  38460. * Create a worker to get the compressed content.
  38461. * @return {GenericWorker} the worker.
  38462. */
  38463. getCompressedWorker: function getCompressedWorker() {
  38464. return new DataWorker(external.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize", this.compressedSize).withStreamInfo("uncompressedSize", this.uncompressedSize).withStreamInfo("crc32", this.crc32).withStreamInfo("compression", this.compression);
  38465. }
  38466. };
  38467. /**
  38468. * Chain the given worker with other workers to compress the content with the
  38469. * given compression.
  38470. * @param {GenericWorker} uncompressedWorker the worker to pipe.
  38471. * @param {Object} compression the compression object.
  38472. * @param {Object} compressionOptions the options to use when compressing.
  38473. * @return {GenericWorker} the new worker compressing the content.
  38474. */
  38475. CompressedObject.createWorkerFrom = function (uncompressedWorker, compression, compressionOptions) {
  38476. return uncompressedWorker.pipe(new Crc32Probe()).pipe(new DataLengthProbe("uncompressedSize")).pipe(compression.compressWorker(compressionOptions)).pipe(new DataLengthProbe("compressedSize")).withStreamInfo("compression", compression);
  38477. };
  38478. module.exports = CompressedObject;
  38479. },{"./external":286,"./stream/Crc32Probe":305,"./stream/DataLengthProbe":306,"./stream/DataWorker":307}],283:[function(require,module,exports){
  38480. 'use strict';
  38481. var GenericWorker = require("./stream/GenericWorker");
  38482. exports.STORE = {
  38483. magic: "\x00\x00",
  38484. compressWorker: function compressWorker(compressionOptions) {
  38485. return new GenericWorker("STORE compression");
  38486. },
  38487. uncompressWorker: function uncompressWorker() {
  38488. return new GenericWorker("STORE decompression");
  38489. }
  38490. };
  38491. exports.DEFLATE = require('./flate');
  38492. },{"./flate":287,"./stream/GenericWorker":308}],284:[function(require,module,exports){
  38493. 'use strict';
  38494. var utils = require('./utils');
  38495. /**
  38496. * The following functions come from pako, from pako/lib/zlib/crc32.js
  38497. * released under the MIT license, see pako https://github.com/nodeca/pako/
  38498. */
  38499. // Use ordinary array, since untyped makes no boost here
  38500. function makeTable() {
  38501. var c,
  38502. table = [];
  38503. for (var n = 0; n < 256; n++) {
  38504. c = n;
  38505. for (var k = 0; k < 8; k++) {
  38506. c = c & 1 ? 0xEDB88320 ^ c >>> 1 : c >>> 1;
  38507. }
  38508. table[n] = c;
  38509. }
  38510. return table;
  38511. } // Create table on load. Just 255 signed longs. Not a problem.
  38512. var crcTable = makeTable();
  38513. function crc32(crc, buf, len, pos) {
  38514. var t = crcTable,
  38515. end = pos + len;
  38516. crc = crc ^ -1;
  38517. for (var i = pos; i < end; i++) {
  38518. crc = crc >>> 8 ^ t[(crc ^ buf[i]) & 0xFF];
  38519. }
  38520. return crc ^ -1; // >>> 0;
  38521. } // That's all for the pako functions.
  38522. /**
  38523. * Compute the crc32 of a string.
  38524. * This is almost the same as the function crc32, but for strings. Using the
  38525. * same function for the two use cases leads to horrible performances.
  38526. * @param {Number} crc the starting value of the crc.
  38527. * @param {String} str the string to use.
  38528. * @param {Number} len the length of the string.
  38529. * @param {Number} pos the starting position for the crc32 computation.
  38530. * @return {Number} the computed crc32.
  38531. */
  38532. function crc32str(crc, str, len, pos) {
  38533. var t = crcTable,
  38534. end = pos + len;
  38535. crc = crc ^ -1;
  38536. for (var i = pos; i < end; i++) {
  38537. crc = crc >>> 8 ^ t[(crc ^ str.charCodeAt(i)) & 0xFF];
  38538. }
  38539. return crc ^ -1; // >>> 0;
  38540. }
  38541. module.exports = function crc32wrapper(input, crc) {
  38542. if (typeof input === "undefined" || !input.length) {
  38543. return 0;
  38544. }
  38545. var isArray = utils.getTypeOf(input) !== "string";
  38546. if (isArray) {
  38547. return crc32(crc | 0, input, input.length, 0);
  38548. } else {
  38549. return crc32str(crc | 0, input, input.length, 0);
  38550. }
  38551. };
  38552. },{"./utils":312}],285:[function(require,module,exports){
  38553. 'use strict';
  38554. exports.base64 = false;
  38555. exports.binary = false;
  38556. exports.dir = false;
  38557. exports.createFolders = true;
  38558. exports.date = null;
  38559. exports.compression = null;
  38560. exports.compressionOptions = null;
  38561. exports.comment = null;
  38562. exports.unixPermissions = null;
  38563. exports.dosPermissions = null;
  38564. },{}],286:[function(require,module,exports){
  38565. /* global Promise */
  38566. 'use strict'; // load the global object first:
  38567. // - it should be better integrated in the system (unhandledRejection in node)
  38568. // - the environment may have a custom Promise implementation (see zone.js)
  38569. var ES6Promise = null;
  38570. if (typeof Promise !== "undefined") {
  38571. ES6Promise = Promise;
  38572. } else {
  38573. ES6Promise = require("lie");
  38574. }
  38575. /**
  38576. * Let the user use/change some implementations.
  38577. */
  38578. module.exports = {
  38579. Promise: ES6Promise
  38580. };
  38581. },{"lie":316}],287:[function(require,module,exports){
  38582. 'use strict';
  38583. var USE_TYPEDARRAY = typeof Uint8Array !== 'undefined' && typeof Uint16Array !== 'undefined' && typeof Uint32Array !== 'undefined';
  38584. var pako = require("pako");
  38585. var utils = require("./utils");
  38586. var GenericWorker = require("./stream/GenericWorker");
  38587. var ARRAY_TYPE = USE_TYPEDARRAY ? "uint8array" : "array";
  38588. exports.magic = "\x08\x00";
  38589. /**
  38590. * Create a worker that uses pako to inflate/deflate.
  38591. * @constructor
  38592. * @param {String} action the name of the pako function to call : either "Deflate" or "Inflate".
  38593. * @param {Object} options the options to use when (de)compressing.
  38594. */
  38595. function FlateWorker(action, options) {
  38596. GenericWorker.call(this, "FlateWorker/" + action);
  38597. this._pako = null;
  38598. this._pakoAction = action;
  38599. this._pakoOptions = options; // the `meta` object from the last chunk received
  38600. // this allow this worker to pass around metadata
  38601. this.meta = {};
  38602. }
  38603. utils.inherits(FlateWorker, GenericWorker);
  38604. /**
  38605. * @see GenericWorker.processChunk
  38606. */
  38607. FlateWorker.prototype.processChunk = function (chunk) {
  38608. this.meta = chunk.meta;
  38609. if (this._pako === null) {
  38610. this._createPako();
  38611. }
  38612. this._pako.push(utils.transformTo(ARRAY_TYPE, chunk.data), false);
  38613. };
  38614. /**
  38615. * @see GenericWorker.flush
  38616. */
  38617. FlateWorker.prototype.flush = function () {
  38618. GenericWorker.prototype.flush.call(this);
  38619. if (this._pako === null) {
  38620. this._createPako();
  38621. }
  38622. this._pako.push([], true);
  38623. };
  38624. /**
  38625. * @see GenericWorker.cleanUp
  38626. */
  38627. FlateWorker.prototype.cleanUp = function () {
  38628. GenericWorker.prototype.cleanUp.call(this);
  38629. this._pako = null;
  38630. };
  38631. /**
  38632. * Create the _pako object.
  38633. * TODO: lazy-loading this object isn't the best solution but it's the
  38634. * quickest. The best solution is to lazy-load the worker list. See also the
  38635. * issue #446.
  38636. */
  38637. FlateWorker.prototype._createPako = function () {
  38638. this._pako = new pako[this._pakoAction]({
  38639. raw: true,
  38640. level: this._pakoOptions.level || -1 // default compression
  38641. });
  38642. var self = this;
  38643. this._pako.onData = function (data) {
  38644. self.push({
  38645. data: data,
  38646. meta: self.meta
  38647. });
  38648. };
  38649. };
  38650. exports.compressWorker = function (compressionOptions) {
  38651. return new FlateWorker("Deflate", compressionOptions);
  38652. };
  38653. exports.uncompressWorker = function () {
  38654. return new FlateWorker("Inflate", {});
  38655. };
  38656. },{"./stream/GenericWorker":308,"./utils":312,"pako":330}],288:[function(require,module,exports){
  38657. 'use strict';
  38658. var utils = require('../utils');
  38659. var GenericWorker = require('../stream/GenericWorker');
  38660. var utf8 = require('../utf8');
  38661. var crc32 = require('../crc32');
  38662. var signature = require('../signature');
  38663. /**
  38664. * Transform an integer into a string in hexadecimal.
  38665. * @private
  38666. * @param {number} dec the number to convert.
  38667. * @param {number} bytes the number of bytes to generate.
  38668. * @returns {string} the result.
  38669. */
  38670. var decToHex = function decToHex(dec, bytes) {
  38671. var hex = "",
  38672. i;
  38673. for (i = 0; i < bytes; i++) {
  38674. hex += String.fromCharCode(dec & 0xff);
  38675. dec = dec >>> 8;
  38676. }
  38677. return hex;
  38678. };
  38679. /**
  38680. * Generate the UNIX part of the external file attributes.
  38681. * @param {Object} unixPermissions the unix permissions or null.
  38682. * @param {Boolean} isDir true if the entry is a directory, false otherwise.
  38683. * @return {Number} a 32 bit integer.
  38684. *
  38685. * adapted from http://unix.stackexchange.com/questions/14705/the-zip-formats-external-file-attribute :
  38686. *
  38687. * TTTTsstrwxrwxrwx0000000000ADVSHR
  38688. * ^^^^____________________________ file type, see zipinfo.c (UNX_*)
  38689. * ^^^_________________________ setuid, setgid, sticky
  38690. * ^^^^^^^^^________________ permissions
  38691. * ^^^^^^^^^^______ not used ?
  38692. * ^^^^^^ DOS attribute bits : Archive, Directory, Volume label, System file, Hidden, Read only
  38693. */
  38694. var generateUnixExternalFileAttr = function generateUnixExternalFileAttr(unixPermissions, isDir) {
  38695. var result = unixPermissions;
  38696. if (!unixPermissions) {
  38697. // I can't use octal values in strict mode, hence the hexa.
  38698. // 040775 => 0x41fd
  38699. // 0100664 => 0x81b4
  38700. result = isDir ? 0x41fd : 0x81b4;
  38701. }
  38702. return (result & 0xFFFF) << 16;
  38703. };
  38704. /**
  38705. * Generate the DOS part of the external file attributes.
  38706. * @param {Object} dosPermissions the dos permissions or null.
  38707. * @param {Boolean} isDir true if the entry is a directory, false otherwise.
  38708. * @return {Number} a 32 bit integer.
  38709. *
  38710. * Bit 0 Read-Only
  38711. * Bit 1 Hidden
  38712. * Bit 2 System
  38713. * Bit 3 Volume Label
  38714. * Bit 4 Directory
  38715. * Bit 5 Archive
  38716. */
  38717. var generateDosExternalFileAttr = function generateDosExternalFileAttr(dosPermissions, isDir) {
  38718. // the dir flag is already set for compatibility
  38719. return (dosPermissions || 0) & 0x3F;
  38720. };
  38721. /**
  38722. * Generate the various parts used in the construction of the final zip file.
  38723. * @param {Object} streamInfo the hash with information about the compressed file.
  38724. * @param {Boolean} streamedContent is the content streamed ?
  38725. * @param {Boolean} streamingEnded is the stream finished ?
  38726. * @param {number} offset the current offset from the start of the zip file.
  38727. * @param {String} platform let's pretend we are this platform (change platform dependents fields)
  38728. * @param {Function} encodeFileName the function to encode the file name / comment.
  38729. * @return {Object} the zip parts.
  38730. */
  38731. var generateZipParts = function generateZipParts(streamInfo, streamedContent, streamingEnded, offset, platform, encodeFileName) {
  38732. var file = streamInfo['file'],
  38733. compression = streamInfo['compression'],
  38734. useCustomEncoding = encodeFileName !== utf8.utf8encode,
  38735. encodedFileName = utils.transformTo("string", encodeFileName(file.name)),
  38736. utfEncodedFileName = utils.transformTo("string", utf8.utf8encode(file.name)),
  38737. comment = file.comment,
  38738. encodedComment = utils.transformTo("string", encodeFileName(comment)),
  38739. utfEncodedComment = utils.transformTo("string", utf8.utf8encode(comment)),
  38740. useUTF8ForFileName = utfEncodedFileName.length !== file.name.length,
  38741. useUTF8ForComment = utfEncodedComment.length !== comment.length,
  38742. dosTime,
  38743. dosDate,
  38744. extraFields = "",
  38745. unicodePathExtraField = "",
  38746. unicodeCommentExtraField = "",
  38747. dir = file.dir,
  38748. date = file.date;
  38749. var dataInfo = {
  38750. crc32: 0,
  38751. compressedSize: 0,
  38752. uncompressedSize: 0
  38753. }; // if the content is streamed, the sizes/crc32 are only available AFTER
  38754. // the end of the stream.
  38755. if (!streamedContent || streamingEnded) {
  38756. dataInfo.crc32 = streamInfo['crc32'];
  38757. dataInfo.compressedSize = streamInfo['compressedSize'];
  38758. dataInfo.uncompressedSize = streamInfo['uncompressedSize'];
  38759. }
  38760. var bitflag = 0;
  38761. if (streamedContent) {
  38762. // Bit 3: the sizes/crc32 are set to zero in the local header.
  38763. // The correct values are put in the data descriptor immediately
  38764. // following the compressed data.
  38765. bitflag |= 0x0008;
  38766. }
  38767. if (!useCustomEncoding && (useUTF8ForFileName || useUTF8ForComment)) {
  38768. // Bit 11: Language encoding flag (EFS).
  38769. bitflag |= 0x0800;
  38770. }
  38771. var extFileAttr = 0;
  38772. var versionMadeBy = 0;
  38773. if (dir) {
  38774. // dos or unix, we set the dos dir flag
  38775. extFileAttr |= 0x00010;
  38776. }
  38777. if (platform === "UNIX") {
  38778. versionMadeBy = 0x031E; // UNIX, version 3.0
  38779. extFileAttr |= generateUnixExternalFileAttr(file.unixPermissions, dir);
  38780. } else {
  38781. // DOS or other, fallback to DOS
  38782. versionMadeBy = 0x0014; // DOS, version 2.0
  38783. extFileAttr |= generateDosExternalFileAttr(file.dosPermissions, dir);
  38784. } // date
  38785. // @see http://www.delorie.com/djgpp/doc/rbinter/it/52/13.html
  38786. // @see http://www.delorie.com/djgpp/doc/rbinter/it/65/16.html
  38787. // @see http://www.delorie.com/djgpp/doc/rbinter/it/66/16.html
  38788. dosTime = date.getUTCHours();
  38789. dosTime = dosTime << 6;
  38790. dosTime = dosTime | date.getUTCMinutes();
  38791. dosTime = dosTime << 5;
  38792. dosTime = dosTime | date.getUTCSeconds() / 2;
  38793. dosDate = date.getUTCFullYear() - 1980;
  38794. dosDate = dosDate << 4;
  38795. dosDate = dosDate | date.getUTCMonth() + 1;
  38796. dosDate = dosDate << 5;
  38797. dosDate = dosDate | date.getUTCDate();
  38798. if (useUTF8ForFileName) {
  38799. // set the unicode path extra field. unzip needs at least one extra
  38800. // field to correctly handle unicode path, so using the path is as good
  38801. // as any other information. This could improve the situation with
  38802. // other archive managers too.
  38803. // This field is usually used without the utf8 flag, with a non
  38804. // unicode path in the header (winrar, winzip). This helps (a bit)
  38805. // with the messy Windows' default compressed folders feature but
  38806. // breaks on p7zip which doesn't seek the unicode path extra field.
  38807. // So for now, UTF-8 everywhere !
  38808. unicodePathExtraField = // Version
  38809. decToHex(1, 1) + // NameCRC32
  38810. decToHex(crc32(encodedFileName), 4) + // UnicodeName
  38811. utfEncodedFileName;
  38812. extraFields += // Info-ZIP Unicode Path Extra Field
  38813. "\x75\x70" + // size
  38814. decToHex(unicodePathExtraField.length, 2) + // content
  38815. unicodePathExtraField;
  38816. }
  38817. if (useUTF8ForComment) {
  38818. unicodeCommentExtraField = // Version
  38819. decToHex(1, 1) + // CommentCRC32
  38820. decToHex(crc32(encodedComment), 4) + // UnicodeName
  38821. utfEncodedComment;
  38822. extraFields += // Info-ZIP Unicode Path Extra Field
  38823. "\x75\x63" + // size
  38824. decToHex(unicodeCommentExtraField.length, 2) + // content
  38825. unicodeCommentExtraField;
  38826. }
  38827. var header = ""; // version needed to extract
  38828. header += "\x0A\x00"; // general purpose bit flag
  38829. header += decToHex(bitflag, 2); // compression method
  38830. header += compression.magic; // last mod file time
  38831. header += decToHex(dosTime, 2); // last mod file date
  38832. header += decToHex(dosDate, 2); // crc-32
  38833. header += decToHex(dataInfo.crc32, 4); // compressed size
  38834. header += decToHex(dataInfo.compressedSize, 4); // uncompressed size
  38835. header += decToHex(dataInfo.uncompressedSize, 4); // file name length
  38836. header += decToHex(encodedFileName.length, 2); // extra field length
  38837. header += decToHex(extraFields.length, 2);
  38838. var fileRecord = signature.LOCAL_FILE_HEADER + header + encodedFileName + extraFields;
  38839. var dirRecord = signature.CENTRAL_FILE_HEADER + // version made by (00: DOS)
  38840. decToHex(versionMadeBy, 2) + // file header (common to file and central directory)
  38841. header + // file comment length
  38842. decToHex(encodedComment.length, 2) + // disk number start
  38843. "\x00\x00" + // internal file attributes TODO
  38844. "\x00\x00" + // external file attributes
  38845. decToHex(extFileAttr, 4) + // relative offset of local header
  38846. decToHex(offset, 4) + // file name
  38847. encodedFileName + // extra field
  38848. extraFields + // file comment
  38849. encodedComment;
  38850. return {
  38851. fileRecord: fileRecord,
  38852. dirRecord: dirRecord
  38853. };
  38854. };
  38855. /**
  38856. * Generate the EOCD record.
  38857. * @param {Number} entriesCount the number of entries in the zip file.
  38858. * @param {Number} centralDirLength the length (in bytes) of the central dir.
  38859. * @param {Number} localDirLength the length (in bytes) of the local dir.
  38860. * @param {String} comment the zip file comment as a binary string.
  38861. * @param {Function} encodeFileName the function to encode the comment.
  38862. * @return {String} the EOCD record.
  38863. */
  38864. var generateCentralDirectoryEnd = function generateCentralDirectoryEnd(entriesCount, centralDirLength, localDirLength, comment, encodeFileName) {
  38865. var dirEnd = "";
  38866. var encodedComment = utils.transformTo("string", encodeFileName(comment)); // end of central dir signature
  38867. dirEnd = signature.CENTRAL_DIRECTORY_END + // number of this disk
  38868. "\x00\x00" + // number of the disk with the start of the central directory
  38869. "\x00\x00" + // total number of entries in the central directory on this disk
  38870. decToHex(entriesCount, 2) + // total number of entries in the central directory
  38871. decToHex(entriesCount, 2) + // size of the central directory 4 bytes
  38872. decToHex(centralDirLength, 4) + // offset of start of central directory with respect to the starting disk number
  38873. decToHex(localDirLength, 4) + // .ZIP file comment length
  38874. decToHex(encodedComment.length, 2) + // .ZIP file comment
  38875. encodedComment;
  38876. return dirEnd;
  38877. };
  38878. /**
  38879. * Generate data descriptors for a file entry.
  38880. * @param {Object} streamInfo the hash generated by a worker, containing information
  38881. * on the file entry.
  38882. * @return {String} the data descriptors.
  38883. */
  38884. var generateDataDescriptors = function generateDataDescriptors(streamInfo) {
  38885. var descriptor = "";
  38886. descriptor = signature.DATA_DESCRIPTOR + // crc-32 4 bytes
  38887. decToHex(streamInfo['crc32'], 4) + // compressed size 4 bytes
  38888. decToHex(streamInfo['compressedSize'], 4) + // uncompressed size 4 bytes
  38889. decToHex(streamInfo['uncompressedSize'], 4);
  38890. return descriptor;
  38891. };
  38892. /**
  38893. * A worker to concatenate other workers to create a zip file.
  38894. * @param {Boolean} streamFiles `true` to stream the content of the files,
  38895. * `false` to accumulate it.
  38896. * @param {String} comment the comment to use.
  38897. * @param {String} platform the platform to use, "UNIX" or "DOS".
  38898. * @param {Function} encodeFileName the function to encode file names and comments.
  38899. */
  38900. function ZipFileWorker(streamFiles, comment, platform, encodeFileName) {
  38901. GenericWorker.call(this, "ZipFileWorker"); // The number of bytes written so far. This doesn't count accumulated chunks.
  38902. this.bytesWritten = 0; // The comment of the zip file
  38903. this.zipComment = comment; // The platform "generating" the zip file.
  38904. this.zipPlatform = platform; // the function to encode file names and comments.
  38905. this.encodeFileName = encodeFileName; // Should we stream the content of the files ?
  38906. this.streamFiles = streamFiles; // If `streamFiles` is false, we will need to accumulate the content of the
  38907. // files to calculate sizes / crc32 (and write them *before* the content).
  38908. // This boolean indicates if we are accumulating chunks (it will change a lot
  38909. // during the lifetime of this worker).
  38910. this.accumulate = false; // The buffer receiving chunks when accumulating content.
  38911. this.contentBuffer = []; // The list of generated directory records.
  38912. this.dirRecords = []; // The offset (in bytes) from the beginning of the zip file for the current source.
  38913. this.currentSourceOffset = 0; // The total number of entries in this zip file.
  38914. this.entriesCount = 0; // the name of the file currently being added, null when handling the end of the zip file.
  38915. // Used for the emitted metadata.
  38916. this.currentFile = null;
  38917. this._sources = [];
  38918. }
  38919. utils.inherits(ZipFileWorker, GenericWorker);
  38920. /**
  38921. * @see GenericWorker.push
  38922. */
  38923. ZipFileWorker.prototype.push = function (chunk) {
  38924. var currentFilePercent = chunk.meta.percent || 0;
  38925. var entriesCount = this.entriesCount;
  38926. var remainingFiles = this._sources.length;
  38927. if (this.accumulate) {
  38928. this.contentBuffer.push(chunk);
  38929. } else {
  38930. this.bytesWritten += chunk.data.length;
  38931. GenericWorker.prototype.push.call(this, {
  38932. data: chunk.data,
  38933. meta: {
  38934. currentFile: this.currentFile,
  38935. percent: entriesCount ? (currentFilePercent + 100 * (entriesCount - remainingFiles - 1)) / entriesCount : 100
  38936. }
  38937. });
  38938. }
  38939. };
  38940. /**
  38941. * The worker started a new source (an other worker).
  38942. * @param {Object} streamInfo the streamInfo object from the new source.
  38943. */
  38944. ZipFileWorker.prototype.openedSource = function (streamInfo) {
  38945. this.currentSourceOffset = this.bytesWritten;
  38946. this.currentFile = streamInfo['file'].name;
  38947. var streamedContent = this.streamFiles && !streamInfo['file'].dir; // don't stream folders (because they don't have any content)
  38948. if (streamedContent) {
  38949. var record = generateZipParts(streamInfo, streamedContent, false, this.currentSourceOffset, this.zipPlatform, this.encodeFileName);
  38950. this.push({
  38951. data: record.fileRecord,
  38952. meta: {
  38953. percent: 0
  38954. }
  38955. });
  38956. } else {
  38957. // we need to wait for the whole file before pushing anything
  38958. this.accumulate = true;
  38959. }
  38960. };
  38961. /**
  38962. * The worker finished a source (an other worker).
  38963. * @param {Object} streamInfo the streamInfo object from the finished source.
  38964. */
  38965. ZipFileWorker.prototype.closedSource = function (streamInfo) {
  38966. this.accumulate = false;
  38967. var streamedContent = this.streamFiles && !streamInfo['file'].dir;
  38968. var record = generateZipParts(streamInfo, streamedContent, true, this.currentSourceOffset, this.zipPlatform, this.encodeFileName);
  38969. this.dirRecords.push(record.dirRecord);
  38970. if (streamedContent) {
  38971. // after the streamed file, we put data descriptors
  38972. this.push({
  38973. data: generateDataDescriptors(streamInfo),
  38974. meta: {
  38975. percent: 100
  38976. }
  38977. });
  38978. } else {
  38979. // the content wasn't streamed, we need to push everything now
  38980. // first the file record, then the content
  38981. this.push({
  38982. data: record.fileRecord,
  38983. meta: {
  38984. percent: 0
  38985. }
  38986. });
  38987. while (this.contentBuffer.length) {
  38988. this.push(this.contentBuffer.shift());
  38989. }
  38990. }
  38991. this.currentFile = null;
  38992. };
  38993. /**
  38994. * @see GenericWorker.flush
  38995. */
  38996. ZipFileWorker.prototype.flush = function () {
  38997. var localDirLength = this.bytesWritten;
  38998. for (var i = 0; i < this.dirRecords.length; i++) {
  38999. this.push({
  39000. data: this.dirRecords[i],
  39001. meta: {
  39002. percent: 100
  39003. }
  39004. });
  39005. }
  39006. var centralDirLength = this.bytesWritten - localDirLength;
  39007. var dirEnd = generateCentralDirectoryEnd(this.dirRecords.length, centralDirLength, localDirLength, this.zipComment, this.encodeFileName);
  39008. this.push({
  39009. data: dirEnd,
  39010. meta: {
  39011. percent: 100
  39012. }
  39013. });
  39014. };
  39015. /**
  39016. * Prepare the next source to be read.
  39017. */
  39018. ZipFileWorker.prototype.prepareNextSource = function () {
  39019. this.previous = this._sources.shift();
  39020. this.openedSource(this.previous.streamInfo);
  39021. if (this.isPaused) {
  39022. this.previous.pause();
  39023. } else {
  39024. this.previous.resume();
  39025. }
  39026. };
  39027. /**
  39028. * @see GenericWorker.registerPrevious
  39029. */
  39030. ZipFileWorker.prototype.registerPrevious = function (previous) {
  39031. this._sources.push(previous);
  39032. var self = this;
  39033. previous.on('data', function (chunk) {
  39034. self.processChunk(chunk);
  39035. });
  39036. previous.on('end', function () {
  39037. self.closedSource(self.previous.streamInfo);
  39038. if (self._sources.length) {
  39039. self.prepareNextSource();
  39040. } else {
  39041. self.end();
  39042. }
  39043. });
  39044. previous.on('error', function (e) {
  39045. self.error(e);
  39046. });
  39047. return this;
  39048. };
  39049. /**
  39050. * @see GenericWorker.resume
  39051. */
  39052. ZipFileWorker.prototype.resume = function () {
  39053. if (!GenericWorker.prototype.resume.call(this)) {
  39054. return false;
  39055. }
  39056. if (!this.previous && this._sources.length) {
  39057. this.prepareNextSource();
  39058. return true;
  39059. }
  39060. if (!this.previous && !this._sources.length && !this.generatedError) {
  39061. this.end();
  39062. return true;
  39063. }
  39064. };
  39065. /**
  39066. * @see GenericWorker.error
  39067. */
  39068. ZipFileWorker.prototype.error = function (e) {
  39069. var sources = this._sources;
  39070. if (!GenericWorker.prototype.error.call(this, e)) {
  39071. return false;
  39072. }
  39073. for (var i = 0; i < sources.length; i++) {
  39074. try {
  39075. sources[i].error(e);
  39076. } catch (e) {// the `error` exploded, nothing to do
  39077. }
  39078. }
  39079. return true;
  39080. };
  39081. /**
  39082. * @see GenericWorker.lock
  39083. */
  39084. ZipFileWorker.prototype.lock = function () {
  39085. GenericWorker.prototype.lock.call(this);
  39086. var sources = this._sources;
  39087. for (var i = 0; i < sources.length; i++) {
  39088. sources[i].lock();
  39089. }
  39090. };
  39091. module.exports = ZipFileWorker;
  39092. },{"../crc32":284,"../signature":303,"../stream/GenericWorker":308,"../utf8":311,"../utils":312}],289:[function(require,module,exports){
  39093. 'use strict';
  39094. var compressions = require('../compressions');
  39095. var ZipFileWorker = require('./ZipFileWorker');
  39096. /**
  39097. * Find the compression to use.
  39098. * @param {String} fileCompression the compression defined at the file level, if any.
  39099. * @param {String} zipCompression the compression defined at the load() level.
  39100. * @return {Object} the compression object to use.
  39101. */
  39102. var getCompression = function getCompression(fileCompression, zipCompression) {
  39103. var compressionName = fileCompression || zipCompression;
  39104. var compression = compressions[compressionName];
  39105. if (!compression) {
  39106. throw new Error(compressionName + " is not a valid compression method !");
  39107. }
  39108. return compression;
  39109. };
  39110. /**
  39111. * Create a worker to generate a zip file.
  39112. * @param {JSZip} zip the JSZip instance at the right root level.
  39113. * @param {Object} options to generate the zip file.
  39114. * @param {String} comment the comment to use.
  39115. */
  39116. exports.generateWorker = function (zip, options, comment) {
  39117. var zipFileWorker = new ZipFileWorker(options.streamFiles, comment, options.platform, options.encodeFileName);
  39118. var entriesCount = 0;
  39119. try {
  39120. zip.forEach(function (relativePath, file) {
  39121. entriesCount++;
  39122. var compression = getCompression(file.options.compression, options.compression);
  39123. var compressionOptions = file.options.compressionOptions || options.compressionOptions || {};
  39124. var dir = file.dir,
  39125. date = file.date;
  39126. file._compressWorker(compression, compressionOptions).withStreamInfo("file", {
  39127. name: relativePath,
  39128. dir: dir,
  39129. date: date,
  39130. comment: file.comment || "",
  39131. unixPermissions: file.unixPermissions,
  39132. dosPermissions: file.dosPermissions
  39133. }).pipe(zipFileWorker);
  39134. });
  39135. zipFileWorker.entriesCount = entriesCount;
  39136. } catch (e) {
  39137. zipFileWorker.error(e);
  39138. }
  39139. return zipFileWorker;
  39140. };
  39141. },{"../compressions":283,"./ZipFileWorker":288}],290:[function(require,module,exports){
  39142. 'use strict';
  39143. /**
  39144. * Representation a of zip file in js
  39145. * @constructor
  39146. */
  39147. function JSZip() {
  39148. // if this constructor is used without `new`, it adds `new` before itself:
  39149. if (!(this instanceof JSZip)) {
  39150. return new JSZip();
  39151. }
  39152. if (arguments.length) {
  39153. throw new Error("The constructor with parameters has been removed in JSZip 3.0, please check the upgrade guide.");
  39154. } // object containing the files :
  39155. // {
  39156. // "folder/" : {...},
  39157. // "folder/data.txt" : {...}
  39158. // }
  39159. this.files = {};
  39160. this.comment = null; // Where we are in the hierarchy
  39161. this.root = "";
  39162. this.clone = function () {
  39163. var newObj = new JSZip();
  39164. for (var i in this) {
  39165. if (typeof this[i] !== "function") {
  39166. newObj[i] = this[i];
  39167. }
  39168. }
  39169. return newObj;
  39170. };
  39171. }
  39172. JSZip.prototype = require('./object');
  39173. JSZip.prototype.loadAsync = require('./load');
  39174. JSZip.support = require('./support');
  39175. JSZip.defaults = require('./defaults'); // TODO find a better way to handle this version,
  39176. // a require('package.json').version doesn't work with webpack, see #327
  39177. JSZip.version = "3.5.0";
  39178. JSZip.loadAsync = function (content, options) {
  39179. return new JSZip().loadAsync(content, options);
  39180. };
  39181. JSZip.external = require("./external");
  39182. module.exports = JSZip;
  39183. },{"./defaults":285,"./external":286,"./load":291,"./object":295,"./support":310}],291:[function(require,module,exports){
  39184. 'use strict';
  39185. var utils = require('./utils');
  39186. var external = require("./external");
  39187. var utf8 = require('./utf8');
  39188. var utils = require('./utils');
  39189. var ZipEntries = require('./zipEntries');
  39190. var Crc32Probe = require('./stream/Crc32Probe');
  39191. var nodejsUtils = require("./nodejsUtils");
  39192. /**
  39193. * Check the CRC32 of an entry.
  39194. * @param {ZipEntry} zipEntry the zip entry to check.
  39195. * @return {Promise} the result.
  39196. */
  39197. function checkEntryCRC32(zipEntry) {
  39198. return new external.Promise(function (resolve, reject) {
  39199. var worker = zipEntry.decompressed.getContentWorker().pipe(new Crc32Probe());
  39200. worker.on("error", function (e) {
  39201. reject(e);
  39202. }).on("end", function () {
  39203. if (worker.streamInfo.crc32 !== zipEntry.decompressed.crc32) {
  39204. reject(new Error("Corrupted zip : CRC32 mismatch"));
  39205. } else {
  39206. resolve();
  39207. }
  39208. }).resume();
  39209. });
  39210. }
  39211. module.exports = function (data, options) {
  39212. var zip = this;
  39213. options = utils.extend(options || {}, {
  39214. base64: false,
  39215. checkCRC32: false,
  39216. optimizedBinaryString: false,
  39217. createFolders: false,
  39218. decodeFileName: utf8.utf8decode
  39219. });
  39220. if (nodejsUtils.isNode && nodejsUtils.isStream(data)) {
  39221. return external.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file."));
  39222. }
  39223. return utils.prepareContent("the loaded zip file", data, true, options.optimizedBinaryString, options.base64).then(function (data) {
  39224. var zipEntries = new ZipEntries(options);
  39225. zipEntries.load(data);
  39226. return zipEntries;
  39227. }).then(function checkCRC32(zipEntries) {
  39228. var promises = [external.Promise.resolve(zipEntries)];
  39229. var files = zipEntries.files;
  39230. if (options.checkCRC32) {
  39231. for (var i = 0; i < files.length; i++) {
  39232. promises.push(checkEntryCRC32(files[i]));
  39233. }
  39234. }
  39235. return external.Promise.all(promises);
  39236. }).then(function addFiles(results) {
  39237. var zipEntries = results.shift();
  39238. var files = zipEntries.files;
  39239. for (var i = 0; i < files.length; i++) {
  39240. var input = files[i];
  39241. zip.file(input.fileNameStr, input.decompressed, {
  39242. binary: true,
  39243. optimizedBinaryString: true,
  39244. date: input.date,
  39245. dir: input.dir,
  39246. comment: input.fileCommentStr.length ? input.fileCommentStr : null,
  39247. unixPermissions: input.unixPermissions,
  39248. dosPermissions: input.dosPermissions,
  39249. createFolders: options.createFolders
  39250. });
  39251. }
  39252. if (zipEntries.zipComment.length) {
  39253. zip.comment = zipEntries.zipComment;
  39254. }
  39255. return zip;
  39256. });
  39257. };
  39258. },{"./external":286,"./nodejsUtils":294,"./stream/Crc32Probe":305,"./utf8":311,"./utils":312,"./zipEntries":313}],292:[function(require,module,exports){
  39259. "use strict";
  39260. var utils = require('../utils');
  39261. var GenericWorker = require('../stream/GenericWorker');
  39262. /**
  39263. * A worker that use a nodejs stream as source.
  39264. * @constructor
  39265. * @param {String} filename the name of the file entry for this stream.
  39266. * @param {Readable} stream the nodejs stream.
  39267. */
  39268. function NodejsStreamInputAdapter(filename, stream) {
  39269. GenericWorker.call(this, "Nodejs stream input adapter for " + filename);
  39270. this._upstreamEnded = false;
  39271. this._bindStream(stream);
  39272. }
  39273. utils.inherits(NodejsStreamInputAdapter, GenericWorker);
  39274. /**
  39275. * Prepare the stream and bind the callbacks on it.
  39276. * Do this ASAP on node 0.10 ! A lazy binding doesn't always work.
  39277. * @param {Stream} stream the nodejs stream to use.
  39278. */
  39279. NodejsStreamInputAdapter.prototype._bindStream = function (stream) {
  39280. var self = this;
  39281. this._stream = stream;
  39282. stream.pause();
  39283. stream.on("data", function (chunk) {
  39284. self.push({
  39285. data: chunk,
  39286. meta: {
  39287. percent: 0
  39288. }
  39289. });
  39290. }).on("error", function (e) {
  39291. if (self.isPaused) {
  39292. this.generatedError = e;
  39293. } else {
  39294. self.error(e);
  39295. }
  39296. }).on("end", function () {
  39297. if (self.isPaused) {
  39298. self._upstreamEnded = true;
  39299. } else {
  39300. self.end();
  39301. }
  39302. });
  39303. };
  39304. NodejsStreamInputAdapter.prototype.pause = function () {
  39305. if (!GenericWorker.prototype.pause.call(this)) {
  39306. return false;
  39307. }
  39308. this._stream.pause();
  39309. return true;
  39310. };
  39311. NodejsStreamInputAdapter.prototype.resume = function () {
  39312. if (!GenericWorker.prototype.resume.call(this)) {
  39313. return false;
  39314. }
  39315. if (this._upstreamEnded) {
  39316. this.end();
  39317. } else {
  39318. this._stream.resume();
  39319. }
  39320. return true;
  39321. };
  39322. module.exports = NodejsStreamInputAdapter;
  39323. },{"../stream/GenericWorker":308,"../utils":312}],293:[function(require,module,exports){
  39324. 'use strict';
  39325. var Readable = require('readable-stream').Readable;
  39326. var utils = require('../utils');
  39327. utils.inherits(NodejsStreamOutputAdapter, Readable);
  39328. /**
  39329. * A nodejs stream using a worker as source.
  39330. * @see the SourceWrapper in http://nodejs.org/api/stream.html
  39331. * @constructor
  39332. * @param {StreamHelper} helper the helper wrapping the worker
  39333. * @param {Object} options the nodejs stream options
  39334. * @param {Function} updateCb the update callback.
  39335. */
  39336. function NodejsStreamOutputAdapter(helper, options, updateCb) {
  39337. Readable.call(this, options);
  39338. this._helper = helper;
  39339. var self = this;
  39340. helper.on("data", function (data, meta) {
  39341. if (!self.push(data)) {
  39342. self._helper.pause();
  39343. }
  39344. if (updateCb) {
  39345. updateCb(meta);
  39346. }
  39347. }).on("error", function (e) {
  39348. self.emit('error', e);
  39349. }).on("end", function () {
  39350. self.push(null);
  39351. });
  39352. }
  39353. NodejsStreamOutputAdapter.prototype._read = function () {
  39354. this._helper.resume();
  39355. };
  39356. module.exports = NodejsStreamOutputAdapter;
  39357. },{"../utils":312,"readable-stream":296}],294:[function(require,module,exports){
  39358. (function (Buffer){
  39359. 'use strict';
  39360. module.exports = {
  39361. /**
  39362. * True if this is running in Nodejs, will be undefined in a browser.
  39363. * In a browser, browserify won't include this file and the whole module
  39364. * will be resolved an empty object.
  39365. */
  39366. isNode: typeof Buffer !== "undefined",
  39367. /**
  39368. * Create a new nodejs Buffer from an existing content.
  39369. * @param {Object} data the data to pass to the constructor.
  39370. * @param {String} encoding the encoding to use.
  39371. * @return {Buffer} a new Buffer.
  39372. */
  39373. newBufferFrom: function newBufferFrom(data, encoding) {
  39374. if (Buffer.from && Buffer.from !== Uint8Array.from) {
  39375. return Buffer.from(data, encoding);
  39376. } else {
  39377. if (typeof data === "number") {
  39378. // Safeguard for old Node.js versions. On newer versions,
  39379. // Buffer.from(number) / Buffer(number, encoding) already throw.
  39380. throw new Error("The \"data\" argument must not be a number");
  39381. }
  39382. return new Buffer(data, encoding);
  39383. }
  39384. },
  39385. /**
  39386. * Create a new nodejs Buffer with the specified size.
  39387. * @param {Integer} size the size of the buffer.
  39388. * @return {Buffer} a new Buffer.
  39389. */
  39390. allocBuffer: function allocBuffer(size) {
  39391. if (Buffer.alloc) {
  39392. return Buffer.alloc(size);
  39393. } else {
  39394. var buf = new Buffer(size);
  39395. buf.fill(0);
  39396. return buf;
  39397. }
  39398. },
  39399. /**
  39400. * Find out if an object is a Buffer.
  39401. * @param {Object} b the object to test.
  39402. * @return {Boolean} true if the object is a Buffer, false otherwise.
  39403. */
  39404. isBuffer: function isBuffer(b) {
  39405. return Buffer.isBuffer(b);
  39406. },
  39407. isStream: function isStream(obj) {
  39408. return obj && typeof obj.on === "function" && typeof obj.pause === "function" && typeof obj.resume === "function";
  39409. }
  39410. };
  39411. }).call(this,require("buffer").Buffer)
  39412. },{"buffer":216}],295:[function(require,module,exports){
  39413. 'use strict';
  39414. var utf8 = require('./utf8');
  39415. var utils = require('./utils');
  39416. var GenericWorker = require('./stream/GenericWorker');
  39417. var StreamHelper = require('./stream/StreamHelper');
  39418. var defaults = require('./defaults');
  39419. var CompressedObject = require('./compressedObject');
  39420. var ZipObject = require('./zipObject');
  39421. var generate = require("./generate");
  39422. var nodejsUtils = require("./nodejsUtils");
  39423. var NodejsStreamInputAdapter = require("./nodejs/NodejsStreamInputAdapter");
  39424. /**
  39425. * Add a file in the current folder.
  39426. * @private
  39427. * @param {string} name the name of the file
  39428. * @param {String|ArrayBuffer|Uint8Array|Buffer} data the data of the file
  39429. * @param {Object} originalOptions the options of the file
  39430. * @return {Object} the new file.
  39431. */
  39432. var fileAdd = function fileAdd(name, data, originalOptions) {
  39433. // be sure sub folders exist
  39434. var dataType = utils.getTypeOf(data),
  39435. parent;
  39436. /*
  39437. * Correct options.
  39438. */
  39439. var o = utils.extend(originalOptions || {}, defaults);
  39440. o.date = o.date || new Date();
  39441. if (o.compression !== null) {
  39442. o.compression = o.compression.toUpperCase();
  39443. }
  39444. if (typeof o.unixPermissions === "string") {
  39445. o.unixPermissions = parseInt(o.unixPermissions, 8);
  39446. } // UNX_IFDIR 0040000 see zipinfo.c
  39447. if (o.unixPermissions && o.unixPermissions & 0x4000) {
  39448. o.dir = true;
  39449. } // Bit 4 Directory
  39450. if (o.dosPermissions && o.dosPermissions & 0x0010) {
  39451. o.dir = true;
  39452. }
  39453. if (o.dir) {
  39454. name = forceTrailingSlash(name);
  39455. }
  39456. if (o.createFolders && (parent = parentFolder(name))) {
  39457. folderAdd.call(this, parent, true);
  39458. }
  39459. var isUnicodeString = dataType === "string" && o.binary === false && o.base64 === false;
  39460. if (!originalOptions || typeof originalOptions.binary === "undefined") {
  39461. o.binary = !isUnicodeString;
  39462. }
  39463. var isCompressedEmpty = data instanceof CompressedObject && data.uncompressedSize === 0;
  39464. if (isCompressedEmpty || o.dir || !data || data.length === 0) {
  39465. o.base64 = false;
  39466. o.binary = true;
  39467. data = "";
  39468. o.compression = "STORE";
  39469. dataType = "string";
  39470. }
  39471. /*
  39472. * Convert content to fit.
  39473. */
  39474. var zipObjectContent = null;
  39475. if (data instanceof CompressedObject || data instanceof GenericWorker) {
  39476. zipObjectContent = data;
  39477. } else if (nodejsUtils.isNode && nodejsUtils.isStream(data)) {
  39478. zipObjectContent = new NodejsStreamInputAdapter(name, data);
  39479. } else {
  39480. zipObjectContent = utils.prepareContent(name, data, o.binary, o.optimizedBinaryString, o.base64);
  39481. }
  39482. var object = new ZipObject(name, zipObjectContent, o);
  39483. this.files[name] = object;
  39484. /*
  39485. TODO: we can't throw an exception because we have async promises
  39486. (we can have a promise of a Date() for example) but returning a
  39487. promise is useless because file(name, data) returns the JSZip
  39488. object for chaining. Should we break that to allow the user
  39489. to catch the error ?
  39490. return external.Promise.resolve(zipObjectContent)
  39491. .then(function () {
  39492. return object;
  39493. });
  39494. */
  39495. };
  39496. /**
  39497. * Find the parent folder of the path.
  39498. * @private
  39499. * @param {string} path the path to use
  39500. * @return {string} the parent folder, or ""
  39501. */
  39502. var parentFolder = function parentFolder(path) {
  39503. if (path.slice(-1) === '/') {
  39504. path = path.substring(0, path.length - 1);
  39505. }
  39506. var lastSlash = path.lastIndexOf('/');
  39507. return lastSlash > 0 ? path.substring(0, lastSlash) : "";
  39508. };
  39509. /**
  39510. * Returns the path with a slash at the end.
  39511. * @private
  39512. * @param {String} path the path to check.
  39513. * @return {String} the path with a trailing slash.
  39514. */
  39515. var forceTrailingSlash = function forceTrailingSlash(path) {
  39516. // Check the name ends with a /
  39517. if (path.slice(-1) !== "/") {
  39518. path += "/"; // IE doesn't like substr(-1)
  39519. }
  39520. return path;
  39521. };
  39522. /**
  39523. * Add a (sub) folder in the current folder.
  39524. * @private
  39525. * @param {string} name the folder's name
  39526. * @param {boolean=} [createFolders] If true, automatically create sub
  39527. * folders. Defaults to false.
  39528. * @return {Object} the new folder.
  39529. */
  39530. var folderAdd = function folderAdd(name, createFolders) {
  39531. createFolders = typeof createFolders !== 'undefined' ? createFolders : defaults.createFolders;
  39532. name = forceTrailingSlash(name); // Does this folder already exist?
  39533. if (!this.files[name]) {
  39534. fileAdd.call(this, name, null, {
  39535. dir: true,
  39536. createFolders: createFolders
  39537. });
  39538. }
  39539. return this.files[name];
  39540. };
  39541. /**
  39542. * Cross-window, cross-Node-context regular expression detection
  39543. * @param {Object} object Anything
  39544. * @return {Boolean} true if the object is a regular expression,
  39545. * false otherwise
  39546. */
  39547. function isRegExp(object) {
  39548. return Object.prototype.toString.call(object) === "[object RegExp]";
  39549. } // return the actual prototype of JSZip
  39550. var out = {
  39551. /**
  39552. * @see loadAsync
  39553. */
  39554. load: function load() {
  39555. throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.");
  39556. },
  39557. /**
  39558. * Call a callback function for each entry at this folder level.
  39559. * @param {Function} cb the callback function:
  39560. * function (relativePath, file) {...}
  39561. * It takes 2 arguments : the relative path and the file.
  39562. */
  39563. forEach: function forEach(cb) {
  39564. var filename, relativePath, file;
  39565. for (filename in this.files) {
  39566. if (!this.files.hasOwnProperty(filename)) {
  39567. continue;
  39568. }
  39569. file = this.files[filename];
  39570. relativePath = filename.slice(this.root.length, filename.length);
  39571. if (relativePath && filename.slice(0, this.root.length) === this.root) {
  39572. // the file is in the current root
  39573. cb(relativePath, file); // TODO reverse the parameters ? need to be clean AND consistent with the filter search fn...
  39574. }
  39575. }
  39576. },
  39577. /**
  39578. * Filter nested files/folders with the specified function.
  39579. * @param {Function} search the predicate to use :
  39580. * function (relativePath, file) {...}
  39581. * It takes 2 arguments : the relative path and the file.
  39582. * @return {Array} An array of matching elements.
  39583. */
  39584. filter: function filter(search) {
  39585. var result = [];
  39586. this.forEach(function (relativePath, entry) {
  39587. if (search(relativePath, entry)) {
  39588. // the file matches the function
  39589. result.push(entry);
  39590. }
  39591. });
  39592. return result;
  39593. },
  39594. /**
  39595. * Add a file to the zip file, or search a file.
  39596. * @param {string|RegExp} name The name of the file to add (if data is defined),
  39597. * the name of the file to find (if no data) or a regex to match files.
  39598. * @param {String|ArrayBuffer|Uint8Array|Buffer} data The file data, either raw or base64 encoded
  39599. * @param {Object} o File options
  39600. * @return {JSZip|Object|Array} this JSZip object (when adding a file),
  39601. * a file (when searching by string) or an array of files (when searching by regex).
  39602. */
  39603. file: function file(name, data, o) {
  39604. if (arguments.length === 1) {
  39605. if (isRegExp(name)) {
  39606. var regexp = name;
  39607. return this.filter(function (relativePath, file) {
  39608. return !file.dir && regexp.test(relativePath);
  39609. });
  39610. } else {
  39611. // text
  39612. var obj = this.files[this.root + name];
  39613. if (obj && !obj.dir) {
  39614. return obj;
  39615. } else {
  39616. return null;
  39617. }
  39618. }
  39619. } else {
  39620. // more than one argument : we have data !
  39621. name = this.root + name;
  39622. fileAdd.call(this, name, data, o);
  39623. }
  39624. return this;
  39625. },
  39626. /**
  39627. * Add a directory to the zip file, or search.
  39628. * @param {String|RegExp} arg The name of the directory to add, or a regex to search folders.
  39629. * @return {JSZip} an object with the new directory as the root, or an array containing matching folders.
  39630. */
  39631. folder: function folder(arg) {
  39632. if (!arg) {
  39633. return this;
  39634. }
  39635. if (isRegExp(arg)) {
  39636. return this.filter(function (relativePath, file) {
  39637. return file.dir && arg.test(relativePath);
  39638. });
  39639. } // else, name is a new folder
  39640. var name = this.root + arg;
  39641. var newFolder = folderAdd.call(this, name); // Allow chaining by returning a new object with this folder as the root
  39642. var ret = this.clone();
  39643. ret.root = newFolder.name;
  39644. return ret;
  39645. },
  39646. /**
  39647. * Delete a file, or a directory and all sub-files, from the zip
  39648. * @param {string} name the name of the file to delete
  39649. * @return {JSZip} this JSZip object
  39650. */
  39651. remove: function remove(name) {
  39652. name = this.root + name;
  39653. var file = this.files[name];
  39654. if (!file) {
  39655. // Look for any folders
  39656. if (name.slice(-1) !== "/") {
  39657. name += "/";
  39658. }
  39659. file = this.files[name];
  39660. }
  39661. if (file && !file.dir) {
  39662. // file
  39663. delete this.files[name];
  39664. } else {
  39665. // maybe a folder, delete recursively
  39666. var kids = this.filter(function (relativePath, file) {
  39667. return file.name.slice(0, name.length) === name;
  39668. });
  39669. for (var i = 0; i < kids.length; i++) {
  39670. delete this.files[kids[i].name];
  39671. }
  39672. }
  39673. return this;
  39674. },
  39675. /**
  39676. * Generate the complete zip file
  39677. * @param {Object} options the options to generate the zip file :
  39678. * - compression, "STORE" by default.
  39679. * - type, "base64" by default. Values are : string, base64, uint8array, arraybuffer, blob.
  39680. * @return {String|Uint8Array|ArrayBuffer|Buffer|Blob} the zip file
  39681. */
  39682. generate: function generate(options) {
  39683. throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.");
  39684. },
  39685. /**
  39686. * Generate the complete zip file as an internal stream.
  39687. * @param {Object} options the options to generate the zip file :
  39688. * - compression, "STORE" by default.
  39689. * - type, "base64" by default. Values are : string, base64, uint8array, arraybuffer, blob.
  39690. * @return {StreamHelper} the streamed zip file.
  39691. */
  39692. generateInternalStream: function generateInternalStream(options) {
  39693. var worker,
  39694. opts = {};
  39695. try {
  39696. opts = utils.extend(options || {}, {
  39697. streamFiles: false,
  39698. compression: "STORE",
  39699. compressionOptions: null,
  39700. type: "",
  39701. platform: "DOS",
  39702. comment: null,
  39703. mimeType: 'application/zip',
  39704. encodeFileName: utf8.utf8encode
  39705. });
  39706. opts.type = opts.type.toLowerCase();
  39707. opts.compression = opts.compression.toUpperCase(); // "binarystring" is preferred but the internals use "string".
  39708. if (opts.type === "binarystring") {
  39709. opts.type = "string";
  39710. }
  39711. if (!opts.type) {
  39712. throw new Error("No output type specified.");
  39713. }
  39714. utils.checkSupport(opts.type); // accept nodejs `process.platform`
  39715. if (opts.platform === 'darwin' || opts.platform === 'freebsd' || opts.platform === 'linux' || opts.platform === 'sunos') {
  39716. opts.platform = "UNIX";
  39717. }
  39718. if (opts.platform === 'win32') {
  39719. opts.platform = "DOS";
  39720. }
  39721. var comment = opts.comment || this.comment || "";
  39722. worker = generate.generateWorker(this, opts, comment);
  39723. } catch (e) {
  39724. worker = new GenericWorker("error");
  39725. worker.error(e);
  39726. }
  39727. return new StreamHelper(worker, opts.type || "string", opts.mimeType);
  39728. },
  39729. /**
  39730. * Generate the complete zip file asynchronously.
  39731. * @see generateInternalStream
  39732. */
  39733. generateAsync: function generateAsync(options, onUpdate) {
  39734. return this.generateInternalStream(options).accumulate(onUpdate);
  39735. },
  39736. /**
  39737. * Generate the complete zip file asynchronously.
  39738. * @see generateInternalStream
  39739. */
  39740. generateNodeStream: function generateNodeStream(options, onUpdate) {
  39741. options = options || {};
  39742. if (!options.type) {
  39743. options.type = "nodebuffer";
  39744. }
  39745. return this.generateInternalStream(options).toNodejsStream(onUpdate);
  39746. }
  39747. };
  39748. module.exports = out;
  39749. },{"./compressedObject":282,"./defaults":285,"./generate":289,"./nodejs/NodejsStreamInputAdapter":292,"./nodejsUtils":294,"./stream/GenericWorker":308,"./stream/StreamHelper":309,"./utf8":311,"./utils":312,"./zipObject":315}],296:[function(require,module,exports){
  39750. "use strict";
  39751. /*
  39752. * This file is used by module bundlers (browserify/webpack/etc) when
  39753. * including a stream implementation. We use "readable-stream" to get a
  39754. * consistent behavior between nodejs versions but bundlers often have a shim
  39755. * for "stream". Using this shim greatly improve the compatibility and greatly
  39756. * reduce the final size of the bundle (only one stream implementation, not
  39757. * two).
  39758. */
  39759. module.exports = require("stream");
  39760. },{"stream":396}],297:[function(require,module,exports){
  39761. 'use strict';
  39762. var DataReader = require('./DataReader');
  39763. var utils = require('../utils');
  39764. function ArrayReader(data) {
  39765. DataReader.call(this, data);
  39766. for (var i = 0; i < this.data.length; i++) {
  39767. data[i] = data[i] & 0xFF;
  39768. }
  39769. }
  39770. utils.inherits(ArrayReader, DataReader);
  39771. /**
  39772. * @see DataReader.byteAt
  39773. */
  39774. ArrayReader.prototype.byteAt = function (i) {
  39775. return this.data[this.zero + i];
  39776. };
  39777. /**
  39778. * @see DataReader.lastIndexOfSignature
  39779. */
  39780. ArrayReader.prototype.lastIndexOfSignature = function (sig) {
  39781. var sig0 = sig.charCodeAt(0),
  39782. sig1 = sig.charCodeAt(1),
  39783. sig2 = sig.charCodeAt(2),
  39784. sig3 = sig.charCodeAt(3);
  39785. for (var i = this.length - 4; i >= 0; --i) {
  39786. if (this.data[i] === sig0 && this.data[i + 1] === sig1 && this.data[i + 2] === sig2 && this.data[i + 3] === sig3) {
  39787. return i - this.zero;
  39788. }
  39789. }
  39790. return -1;
  39791. };
  39792. /**
  39793. * @see DataReader.readAndCheckSignature
  39794. */
  39795. ArrayReader.prototype.readAndCheckSignature = function (sig) {
  39796. var sig0 = sig.charCodeAt(0),
  39797. sig1 = sig.charCodeAt(1),
  39798. sig2 = sig.charCodeAt(2),
  39799. sig3 = sig.charCodeAt(3),
  39800. data = this.readData(4);
  39801. return sig0 === data[0] && sig1 === data[1] && sig2 === data[2] && sig3 === data[3];
  39802. };
  39803. /**
  39804. * @see DataReader.readData
  39805. */
  39806. ArrayReader.prototype.readData = function (size) {
  39807. this.checkOffset(size);
  39808. if (size === 0) {
  39809. return [];
  39810. }
  39811. var result = this.data.slice(this.zero + this.index, this.zero + this.index + size);
  39812. this.index += size;
  39813. return result;
  39814. };
  39815. module.exports = ArrayReader;
  39816. },{"../utils":312,"./DataReader":298}],298:[function(require,module,exports){
  39817. 'use strict';
  39818. var utils = require('../utils');
  39819. function DataReader(data) {
  39820. this.data = data; // type : see implementation
  39821. this.length = data.length;
  39822. this.index = 0;
  39823. this.zero = 0;
  39824. }
  39825. DataReader.prototype = {
  39826. /**
  39827. * Check that the offset will not go too far.
  39828. * @param {string} offset the additional offset to check.
  39829. * @throws {Error} an Error if the offset is out of bounds.
  39830. */
  39831. checkOffset: function checkOffset(offset) {
  39832. this.checkIndex(this.index + offset);
  39833. },
  39834. /**
  39835. * Check that the specified index will not be too far.
  39836. * @param {string} newIndex the index to check.
  39837. * @throws {Error} an Error if the index is out of bounds.
  39838. */
  39839. checkIndex: function checkIndex(newIndex) {
  39840. if (this.length < this.zero + newIndex || newIndex < 0) {
  39841. throw new Error("End of data reached (data length = " + this.length + ", asked index = " + newIndex + "). Corrupted zip ?");
  39842. }
  39843. },
  39844. /**
  39845. * Change the index.
  39846. * @param {number} newIndex The new index.
  39847. * @throws {Error} if the new index is out of the data.
  39848. */
  39849. setIndex: function setIndex(newIndex) {
  39850. this.checkIndex(newIndex);
  39851. this.index = newIndex;
  39852. },
  39853. /**
  39854. * Skip the next n bytes.
  39855. * @param {number} n the number of bytes to skip.
  39856. * @throws {Error} if the new index is out of the data.
  39857. */
  39858. skip: function skip(n) {
  39859. this.setIndex(this.index + n);
  39860. },
  39861. /**
  39862. * Get the byte at the specified index.
  39863. * @param {number} i the index to use.
  39864. * @return {number} a byte.
  39865. */
  39866. byteAt: function byteAt(i) {// see implementations
  39867. },
  39868. /**
  39869. * Get the next number with a given byte size.
  39870. * @param {number} size the number of bytes to read.
  39871. * @return {number} the corresponding number.
  39872. */
  39873. readInt: function readInt(size) {
  39874. var result = 0,
  39875. i;
  39876. this.checkOffset(size);
  39877. for (i = this.index + size - 1; i >= this.index; i--) {
  39878. result = (result << 8) + this.byteAt(i);
  39879. }
  39880. this.index += size;
  39881. return result;
  39882. },
  39883. /**
  39884. * Get the next string with a given byte size.
  39885. * @param {number} size the number of bytes to read.
  39886. * @return {string} the corresponding string.
  39887. */
  39888. readString: function readString(size) {
  39889. return utils.transformTo("string", this.readData(size));
  39890. },
  39891. /**
  39892. * Get raw data without conversion, <size> bytes.
  39893. * @param {number} size the number of bytes to read.
  39894. * @return {Object} the raw data, implementation specific.
  39895. */
  39896. readData: function readData(size) {// see implementations
  39897. },
  39898. /**
  39899. * Find the last occurrence of a zip signature (4 bytes).
  39900. * @param {string} sig the signature to find.
  39901. * @return {number} the index of the last occurrence, -1 if not found.
  39902. */
  39903. lastIndexOfSignature: function lastIndexOfSignature(sig) {// see implementations
  39904. },
  39905. /**
  39906. * Read the signature (4 bytes) at the current position and compare it with sig.
  39907. * @param {string} sig the expected signature
  39908. * @return {boolean} true if the signature matches, false otherwise.
  39909. */
  39910. readAndCheckSignature: function readAndCheckSignature(sig) {// see implementations
  39911. },
  39912. /**
  39913. * Get the next date.
  39914. * @return {Date} the date.
  39915. */
  39916. readDate: function readDate() {
  39917. var dostime = this.readInt(4);
  39918. return new Date(Date.UTC((dostime >> 25 & 0x7f) + 1980, // year
  39919. (dostime >> 21 & 0x0f) - 1, // month
  39920. dostime >> 16 & 0x1f, // day
  39921. dostime >> 11 & 0x1f, // hour
  39922. dostime >> 5 & 0x3f, // minute
  39923. (dostime & 0x1f) << 1)); // second
  39924. }
  39925. };
  39926. module.exports = DataReader;
  39927. },{"../utils":312}],299:[function(require,module,exports){
  39928. 'use strict';
  39929. var Uint8ArrayReader = require('./Uint8ArrayReader');
  39930. var utils = require('../utils');
  39931. function NodeBufferReader(data) {
  39932. Uint8ArrayReader.call(this, data);
  39933. }
  39934. utils.inherits(NodeBufferReader, Uint8ArrayReader);
  39935. /**
  39936. * @see DataReader.readData
  39937. */
  39938. NodeBufferReader.prototype.readData = function (size) {
  39939. this.checkOffset(size);
  39940. var result = this.data.slice(this.zero + this.index, this.zero + this.index + size);
  39941. this.index += size;
  39942. return result;
  39943. };
  39944. module.exports = NodeBufferReader;
  39945. },{"../utils":312,"./Uint8ArrayReader":301}],300:[function(require,module,exports){
  39946. 'use strict';
  39947. var DataReader = require('./DataReader');
  39948. var utils = require('../utils');
  39949. function StringReader(data) {
  39950. DataReader.call(this, data);
  39951. }
  39952. utils.inherits(StringReader, DataReader);
  39953. /**
  39954. * @see DataReader.byteAt
  39955. */
  39956. StringReader.prototype.byteAt = function (i) {
  39957. return this.data.charCodeAt(this.zero + i);
  39958. };
  39959. /**
  39960. * @see DataReader.lastIndexOfSignature
  39961. */
  39962. StringReader.prototype.lastIndexOfSignature = function (sig) {
  39963. return this.data.lastIndexOf(sig) - this.zero;
  39964. };
  39965. /**
  39966. * @see DataReader.readAndCheckSignature
  39967. */
  39968. StringReader.prototype.readAndCheckSignature = function (sig) {
  39969. var data = this.readData(4);
  39970. return sig === data;
  39971. };
  39972. /**
  39973. * @see DataReader.readData
  39974. */
  39975. StringReader.prototype.readData = function (size) {
  39976. this.checkOffset(size); // this will work because the constructor applied the "& 0xff" mask.
  39977. var result = this.data.slice(this.zero + this.index, this.zero + this.index + size);
  39978. this.index += size;
  39979. return result;
  39980. };
  39981. module.exports = StringReader;
  39982. },{"../utils":312,"./DataReader":298}],301:[function(require,module,exports){
  39983. 'use strict';
  39984. var ArrayReader = require('./ArrayReader');
  39985. var utils = require('../utils');
  39986. function Uint8ArrayReader(data) {
  39987. ArrayReader.call(this, data);
  39988. }
  39989. utils.inherits(Uint8ArrayReader, ArrayReader);
  39990. /**
  39991. * @see DataReader.readData
  39992. */
  39993. Uint8ArrayReader.prototype.readData = function (size) {
  39994. this.checkOffset(size);
  39995. if (size === 0) {
  39996. // in IE10, when using subarray(idx, idx), we get the array [0x00] instead of [].
  39997. return new Uint8Array(0);
  39998. }
  39999. var result = this.data.subarray(this.zero + this.index, this.zero + this.index + size);
  40000. this.index += size;
  40001. return result;
  40002. };
  40003. module.exports = Uint8ArrayReader;
  40004. },{"../utils":312,"./ArrayReader":297}],302:[function(require,module,exports){
  40005. 'use strict';
  40006. var utils = require('../utils');
  40007. var support = require('../support');
  40008. var ArrayReader = require('./ArrayReader');
  40009. var StringReader = require('./StringReader');
  40010. var NodeBufferReader = require('./NodeBufferReader');
  40011. var Uint8ArrayReader = require('./Uint8ArrayReader');
  40012. /**
  40013. * Create a reader adapted to the data.
  40014. * @param {String|ArrayBuffer|Uint8Array|Buffer} data the data to read.
  40015. * @return {DataReader} the data reader.
  40016. */
  40017. module.exports = function (data) {
  40018. var type = utils.getTypeOf(data);
  40019. utils.checkSupport(type);
  40020. if (type === "string" && !support.uint8array) {
  40021. return new StringReader(data);
  40022. }
  40023. if (type === "nodebuffer") {
  40024. return new NodeBufferReader(data);
  40025. }
  40026. if (support.uint8array) {
  40027. return new Uint8ArrayReader(utils.transformTo("uint8array", data));
  40028. }
  40029. return new ArrayReader(utils.transformTo("array", data));
  40030. };
  40031. },{"../support":310,"../utils":312,"./ArrayReader":297,"./NodeBufferReader":299,"./StringReader":300,"./Uint8ArrayReader":301}],303:[function(require,module,exports){
  40032. 'use strict';
  40033. exports.LOCAL_FILE_HEADER = "PK\x03\x04";
  40034. exports.CENTRAL_FILE_HEADER = "PK\x01\x02";
  40035. exports.CENTRAL_DIRECTORY_END = "PK\x05\x06";
  40036. exports.ZIP64_CENTRAL_DIRECTORY_LOCATOR = "PK\x06\x07";
  40037. exports.ZIP64_CENTRAL_DIRECTORY_END = "PK\x06\x06";
  40038. exports.DATA_DESCRIPTOR = "PK\x07\x08";
  40039. },{}],304:[function(require,module,exports){
  40040. 'use strict';
  40041. var GenericWorker = require('./GenericWorker');
  40042. var utils = require('../utils');
  40043. /**
  40044. * A worker which convert chunks to a specified type.
  40045. * @constructor
  40046. * @param {String} destType the destination type.
  40047. */
  40048. function ConvertWorker(destType) {
  40049. GenericWorker.call(this, "ConvertWorker to " + destType);
  40050. this.destType = destType;
  40051. }
  40052. utils.inherits(ConvertWorker, GenericWorker);
  40053. /**
  40054. * @see GenericWorker.processChunk
  40055. */
  40056. ConvertWorker.prototype.processChunk = function (chunk) {
  40057. this.push({
  40058. data: utils.transformTo(this.destType, chunk.data),
  40059. meta: chunk.meta
  40060. });
  40061. };
  40062. module.exports = ConvertWorker;
  40063. },{"../utils":312,"./GenericWorker":308}],305:[function(require,module,exports){
  40064. 'use strict';
  40065. var GenericWorker = require('./GenericWorker');
  40066. var crc32 = require('../crc32');
  40067. var utils = require('../utils');
  40068. /**
  40069. * A worker which calculate the crc32 of the data flowing through.
  40070. * @constructor
  40071. */
  40072. function Crc32Probe() {
  40073. GenericWorker.call(this, "Crc32Probe");
  40074. this.withStreamInfo("crc32", 0);
  40075. }
  40076. utils.inherits(Crc32Probe, GenericWorker);
  40077. /**
  40078. * @see GenericWorker.processChunk
  40079. */
  40080. Crc32Probe.prototype.processChunk = function (chunk) {
  40081. this.streamInfo.crc32 = crc32(chunk.data, this.streamInfo.crc32 || 0);
  40082. this.push(chunk);
  40083. };
  40084. module.exports = Crc32Probe;
  40085. },{"../crc32":284,"../utils":312,"./GenericWorker":308}],306:[function(require,module,exports){
  40086. 'use strict';
  40087. var utils = require('../utils');
  40088. var GenericWorker = require('./GenericWorker');
  40089. /**
  40090. * A worker which calculate the total length of the data flowing through.
  40091. * @constructor
  40092. * @param {String} propName the name used to expose the length
  40093. */
  40094. function DataLengthProbe(propName) {
  40095. GenericWorker.call(this, "DataLengthProbe for " + propName);
  40096. this.propName = propName;
  40097. this.withStreamInfo(propName, 0);
  40098. }
  40099. utils.inherits(DataLengthProbe, GenericWorker);
  40100. /**
  40101. * @see GenericWorker.processChunk
  40102. */
  40103. DataLengthProbe.prototype.processChunk = function (chunk) {
  40104. if (chunk) {
  40105. var length = this.streamInfo[this.propName] || 0;
  40106. this.streamInfo[this.propName] = length + chunk.data.length;
  40107. }
  40108. GenericWorker.prototype.processChunk.call(this, chunk);
  40109. };
  40110. module.exports = DataLengthProbe;
  40111. },{"../utils":312,"./GenericWorker":308}],307:[function(require,module,exports){
  40112. 'use strict';
  40113. var utils = require('../utils');
  40114. var GenericWorker = require('./GenericWorker'); // the size of the generated chunks
  40115. // TODO expose this as a public variable
  40116. var DEFAULT_BLOCK_SIZE = 16 * 1024;
  40117. /**
  40118. * A worker that reads a content and emits chunks.
  40119. * @constructor
  40120. * @param {Promise} dataP the promise of the data to split
  40121. */
  40122. function DataWorker(dataP) {
  40123. GenericWorker.call(this, "DataWorker");
  40124. var self = this;
  40125. this.dataIsReady = false;
  40126. this.index = 0;
  40127. this.max = 0;
  40128. this.data = null;
  40129. this.type = "";
  40130. this._tickScheduled = false;
  40131. dataP.then(function (data) {
  40132. self.dataIsReady = true;
  40133. self.data = data;
  40134. self.max = data && data.length || 0;
  40135. self.type = utils.getTypeOf(data);
  40136. if (!self.isPaused) {
  40137. self._tickAndRepeat();
  40138. }
  40139. }, function (e) {
  40140. self.error(e);
  40141. });
  40142. }
  40143. utils.inherits(DataWorker, GenericWorker);
  40144. /**
  40145. * @see GenericWorker.cleanUp
  40146. */
  40147. DataWorker.prototype.cleanUp = function () {
  40148. GenericWorker.prototype.cleanUp.call(this);
  40149. this.data = null;
  40150. };
  40151. /**
  40152. * @see GenericWorker.resume
  40153. */
  40154. DataWorker.prototype.resume = function () {
  40155. if (!GenericWorker.prototype.resume.call(this)) {
  40156. return false;
  40157. }
  40158. if (!this._tickScheduled && this.dataIsReady) {
  40159. this._tickScheduled = true;
  40160. utils.delay(this._tickAndRepeat, [], this);
  40161. }
  40162. return true;
  40163. };
  40164. /**
  40165. * Trigger a tick a schedule an other call to this function.
  40166. */
  40167. DataWorker.prototype._tickAndRepeat = function () {
  40168. this._tickScheduled = false;
  40169. if (this.isPaused || this.isFinished) {
  40170. return;
  40171. }
  40172. this._tick();
  40173. if (!this.isFinished) {
  40174. utils.delay(this._tickAndRepeat, [], this);
  40175. this._tickScheduled = true;
  40176. }
  40177. };
  40178. /**
  40179. * Read and push a chunk.
  40180. */
  40181. DataWorker.prototype._tick = function () {
  40182. if (this.isPaused || this.isFinished) {
  40183. return false;
  40184. }
  40185. var size = DEFAULT_BLOCK_SIZE;
  40186. var data = null,
  40187. nextIndex = Math.min(this.max, this.index + size);
  40188. if (this.index >= this.max) {
  40189. // EOF
  40190. return this.end();
  40191. } else {
  40192. switch (this.type) {
  40193. case "string":
  40194. data = this.data.substring(this.index, nextIndex);
  40195. break;
  40196. case "uint8array":
  40197. data = this.data.subarray(this.index, nextIndex);
  40198. break;
  40199. case "array":
  40200. case "nodebuffer":
  40201. data = this.data.slice(this.index, nextIndex);
  40202. break;
  40203. }
  40204. this.index = nextIndex;
  40205. return this.push({
  40206. data: data,
  40207. meta: {
  40208. percent: this.max ? this.index / this.max * 100 : 0
  40209. }
  40210. });
  40211. }
  40212. };
  40213. module.exports = DataWorker;
  40214. },{"../utils":312,"./GenericWorker":308}],308:[function(require,module,exports){
  40215. 'use strict';
  40216. /**
  40217. * A worker that does nothing but passing chunks to the next one. This is like
  40218. * a nodejs stream but with some differences. On the good side :
  40219. * - it works on IE 6-9 without any issue / polyfill
  40220. * - it weights less than the full dependencies bundled with browserify
  40221. * - it forwards errors (no need to declare an error handler EVERYWHERE)
  40222. *
  40223. * A chunk is an object with 2 attributes : `meta` and `data`. The former is an
  40224. * object containing anything (`percent` for example), see each worker for more
  40225. * details. The latter is the real data (String, Uint8Array, etc).
  40226. *
  40227. * @constructor
  40228. * @param {String} name the name of the stream (mainly used for debugging purposes)
  40229. */
  40230. function GenericWorker(name) {
  40231. // the name of the worker
  40232. this.name = name || "default"; // an object containing metadata about the workers chain
  40233. this.streamInfo = {}; // an error which happened when the worker was paused
  40234. this.generatedError = null; // an object containing metadata to be merged by this worker into the general metadata
  40235. this.extraStreamInfo = {}; // true if the stream is paused (and should not do anything), false otherwise
  40236. this.isPaused = true; // true if the stream is finished (and should not do anything), false otherwise
  40237. this.isFinished = false; // true if the stream is locked to prevent further structure updates (pipe), false otherwise
  40238. this.isLocked = false; // the event listeners
  40239. this._listeners = {
  40240. 'data': [],
  40241. 'end': [],
  40242. 'error': []
  40243. }; // the previous worker, if any
  40244. this.previous = null;
  40245. }
  40246. GenericWorker.prototype = {
  40247. /**
  40248. * Push a chunk to the next workers.
  40249. * @param {Object} chunk the chunk to push
  40250. */
  40251. push: function push(chunk) {
  40252. this.emit("data", chunk);
  40253. },
  40254. /**
  40255. * End the stream.
  40256. * @return {Boolean} true if this call ended the worker, false otherwise.
  40257. */
  40258. end: function end() {
  40259. if (this.isFinished) {
  40260. return false;
  40261. }
  40262. this.flush();
  40263. try {
  40264. this.emit("end");
  40265. this.cleanUp();
  40266. this.isFinished = true;
  40267. } catch (e) {
  40268. this.emit("error", e);
  40269. }
  40270. return true;
  40271. },
  40272. /**
  40273. * End the stream with an error.
  40274. * @param {Error} e the error which caused the premature end.
  40275. * @return {Boolean} true if this call ended the worker with an error, false otherwise.
  40276. */
  40277. error: function error(e) {
  40278. if (this.isFinished) {
  40279. return false;
  40280. }
  40281. if (this.isPaused) {
  40282. this.generatedError = e;
  40283. } else {
  40284. this.isFinished = true;
  40285. this.emit("error", e); // in the workers chain exploded in the middle of the chain,
  40286. // the error event will go downward but we also need to notify
  40287. // workers upward that there has been an error.
  40288. if (this.previous) {
  40289. this.previous.error(e);
  40290. }
  40291. this.cleanUp();
  40292. }
  40293. return true;
  40294. },
  40295. /**
  40296. * Add a callback on an event.
  40297. * @param {String} name the name of the event (data, end, error)
  40298. * @param {Function} listener the function to call when the event is triggered
  40299. * @return {GenericWorker} the current object for chainability
  40300. */
  40301. on: function on(name, listener) {
  40302. this._listeners[name].push(listener);
  40303. return this;
  40304. },
  40305. /**
  40306. * Clean any references when a worker is ending.
  40307. */
  40308. cleanUp: function cleanUp() {
  40309. this.streamInfo = this.generatedError = this.extraStreamInfo = null;
  40310. this._listeners = [];
  40311. },
  40312. /**
  40313. * Trigger an event. This will call registered callback with the provided arg.
  40314. * @param {String} name the name of the event (data, end, error)
  40315. * @param {Object} arg the argument to call the callback with.
  40316. */
  40317. emit: function emit(name, arg) {
  40318. if (this._listeners[name]) {
  40319. for (var i = 0; i < this._listeners[name].length; i++) {
  40320. this._listeners[name][i].call(this, arg);
  40321. }
  40322. }
  40323. },
  40324. /**
  40325. * Chain a worker with an other.
  40326. * @param {Worker} next the worker receiving events from the current one.
  40327. * @return {worker} the next worker for chainability
  40328. */
  40329. pipe: function pipe(next) {
  40330. return next.registerPrevious(this);
  40331. },
  40332. /**
  40333. * Same as `pipe` in the other direction.
  40334. * Using an API with `pipe(next)` is very easy.
  40335. * Implementing the API with the point of view of the next one registering
  40336. * a source is easier, see the ZipFileWorker.
  40337. * @param {Worker} previous the previous worker, sending events to this one
  40338. * @return {Worker} the current worker for chainability
  40339. */
  40340. registerPrevious: function registerPrevious(previous) {
  40341. if (this.isLocked) {
  40342. throw new Error("The stream '" + this + "' has already been used.");
  40343. } // sharing the streamInfo...
  40344. this.streamInfo = previous.streamInfo; // ... and adding our own bits
  40345. this.mergeStreamInfo();
  40346. this.previous = previous;
  40347. var self = this;
  40348. previous.on('data', function (chunk) {
  40349. self.processChunk(chunk);
  40350. });
  40351. previous.on('end', function () {
  40352. self.end();
  40353. });
  40354. previous.on('error', function (e) {
  40355. self.error(e);
  40356. });
  40357. return this;
  40358. },
  40359. /**
  40360. * Pause the stream so it doesn't send events anymore.
  40361. * @return {Boolean} true if this call paused the worker, false otherwise.
  40362. */
  40363. pause: function pause() {
  40364. if (this.isPaused || this.isFinished) {
  40365. return false;
  40366. }
  40367. this.isPaused = true;
  40368. if (this.previous) {
  40369. this.previous.pause();
  40370. }
  40371. return true;
  40372. },
  40373. /**
  40374. * Resume a paused stream.
  40375. * @return {Boolean} true if this call resumed the worker, false otherwise.
  40376. */
  40377. resume: function resume() {
  40378. if (!this.isPaused || this.isFinished) {
  40379. return false;
  40380. }
  40381. this.isPaused = false; // if true, the worker tried to resume but failed
  40382. var withError = false;
  40383. if (this.generatedError) {
  40384. this.error(this.generatedError);
  40385. withError = true;
  40386. }
  40387. if (this.previous) {
  40388. this.previous.resume();
  40389. }
  40390. return !withError;
  40391. },
  40392. /**
  40393. * Flush any remaining bytes as the stream is ending.
  40394. */
  40395. flush: function flush() {},
  40396. /**
  40397. * Process a chunk. This is usually the method overridden.
  40398. * @param {Object} chunk the chunk to process.
  40399. */
  40400. processChunk: function processChunk(chunk) {
  40401. this.push(chunk);
  40402. },
  40403. /**
  40404. * Add a key/value to be added in the workers chain streamInfo once activated.
  40405. * @param {String} key the key to use
  40406. * @param {Object} value the associated value
  40407. * @return {Worker} the current worker for chainability
  40408. */
  40409. withStreamInfo: function withStreamInfo(key, value) {
  40410. this.extraStreamInfo[key] = value;
  40411. this.mergeStreamInfo();
  40412. return this;
  40413. },
  40414. /**
  40415. * Merge this worker's streamInfo into the chain's streamInfo.
  40416. */
  40417. mergeStreamInfo: function mergeStreamInfo() {
  40418. for (var key in this.extraStreamInfo) {
  40419. if (!this.extraStreamInfo.hasOwnProperty(key)) {
  40420. continue;
  40421. }
  40422. this.streamInfo[key] = this.extraStreamInfo[key];
  40423. }
  40424. },
  40425. /**
  40426. * Lock the stream to prevent further updates on the workers chain.
  40427. * After calling this method, all calls to pipe will fail.
  40428. */
  40429. lock: function lock() {
  40430. if (this.isLocked) {
  40431. throw new Error("The stream '" + this + "' has already been used.");
  40432. }
  40433. this.isLocked = true;
  40434. if (this.previous) {
  40435. this.previous.lock();
  40436. }
  40437. },
  40438. /**
  40439. *
  40440. * Pretty print the workers chain.
  40441. */
  40442. toString: function toString() {
  40443. var me = "Worker " + this.name;
  40444. if (this.previous) {
  40445. return this.previous + " -> " + me;
  40446. } else {
  40447. return me;
  40448. }
  40449. }
  40450. };
  40451. module.exports = GenericWorker;
  40452. },{}],309:[function(require,module,exports){
  40453. (function (Buffer){
  40454. 'use strict';
  40455. var utils = require('../utils');
  40456. var ConvertWorker = require('./ConvertWorker');
  40457. var GenericWorker = require('./GenericWorker');
  40458. var base64 = require('../base64');
  40459. var support = require("../support");
  40460. var external = require("../external");
  40461. var NodejsStreamOutputAdapter = null;
  40462. if (support.nodestream) {
  40463. try {
  40464. NodejsStreamOutputAdapter = require('../nodejs/NodejsStreamOutputAdapter');
  40465. } catch (e) {}
  40466. }
  40467. /**
  40468. * Apply the final transformation of the data. If the user wants a Blob for
  40469. * example, it's easier to work with an U8intArray and finally do the
  40470. * ArrayBuffer/Blob conversion.
  40471. * @param {String} type the name of the final type
  40472. * @param {String|Uint8Array|Buffer} content the content to transform
  40473. * @param {String} mimeType the mime type of the content, if applicable.
  40474. * @return {String|Uint8Array|ArrayBuffer|Buffer|Blob} the content in the right format.
  40475. */
  40476. function transformZipOutput(type, content, mimeType) {
  40477. switch (type) {
  40478. case "blob":
  40479. return utils.newBlob(utils.transformTo("arraybuffer", content), mimeType);
  40480. case "base64":
  40481. return base64.encode(content);
  40482. default:
  40483. return utils.transformTo(type, content);
  40484. }
  40485. }
  40486. /**
  40487. * Concatenate an array of data of the given type.
  40488. * @param {String} type the type of the data in the given array.
  40489. * @param {Array} dataArray the array containing the data chunks to concatenate
  40490. * @return {String|Uint8Array|Buffer} the concatenated data
  40491. * @throws Error if the asked type is unsupported
  40492. */
  40493. function concat(type, dataArray) {
  40494. var i,
  40495. index = 0,
  40496. res = null,
  40497. totalLength = 0;
  40498. for (i = 0; i < dataArray.length; i++) {
  40499. totalLength += dataArray[i].length;
  40500. }
  40501. switch (type) {
  40502. case "string":
  40503. return dataArray.join("");
  40504. case "array":
  40505. return Array.prototype.concat.apply([], dataArray);
  40506. case "uint8array":
  40507. res = new Uint8Array(totalLength);
  40508. for (i = 0; i < dataArray.length; i++) {
  40509. res.set(dataArray[i], index);
  40510. index += dataArray[i].length;
  40511. }
  40512. return res;
  40513. case "nodebuffer":
  40514. return Buffer.concat(dataArray);
  40515. default:
  40516. throw new Error("concat : unsupported type '" + type + "'");
  40517. }
  40518. }
  40519. /**
  40520. * Listen a StreamHelper, accumulate its content and concatenate it into a
  40521. * complete block.
  40522. * @param {StreamHelper} helper the helper to use.
  40523. * @param {Function} updateCallback a callback called on each update. Called
  40524. * with one arg :
  40525. * - the metadata linked to the update received.
  40526. * @return Promise the promise for the accumulation.
  40527. */
  40528. function _accumulate(helper, updateCallback) {
  40529. return new external.Promise(function (resolve, reject) {
  40530. var dataArray = [];
  40531. var chunkType = helper._internalType,
  40532. resultType = helper._outputType,
  40533. mimeType = helper._mimeType;
  40534. helper.on('data', function (data, meta) {
  40535. dataArray.push(data);
  40536. if (updateCallback) {
  40537. updateCallback(meta);
  40538. }
  40539. }).on('error', function (err) {
  40540. dataArray = [];
  40541. reject(err);
  40542. }).on('end', function () {
  40543. try {
  40544. var result = transformZipOutput(resultType, concat(chunkType, dataArray), mimeType);
  40545. resolve(result);
  40546. } catch (e) {
  40547. reject(e);
  40548. }
  40549. dataArray = [];
  40550. }).resume();
  40551. });
  40552. }
  40553. /**
  40554. * An helper to easily use workers outside of JSZip.
  40555. * @constructor
  40556. * @param {Worker} worker the worker to wrap
  40557. * @param {String} outputType the type of data expected by the use
  40558. * @param {String} mimeType the mime type of the content, if applicable.
  40559. */
  40560. function StreamHelper(worker, outputType, mimeType) {
  40561. var internalType = outputType;
  40562. switch (outputType) {
  40563. case "blob":
  40564. case "arraybuffer":
  40565. internalType = "uint8array";
  40566. break;
  40567. case "base64":
  40568. internalType = "string";
  40569. break;
  40570. }
  40571. try {
  40572. // the type used internally
  40573. this._internalType = internalType; // the type used to output results
  40574. this._outputType = outputType; // the mime type
  40575. this._mimeType = mimeType;
  40576. utils.checkSupport(internalType);
  40577. this._worker = worker.pipe(new ConvertWorker(internalType)); // the last workers can be rewired without issues but we need to
  40578. // prevent any updates on previous workers.
  40579. worker.lock();
  40580. } catch (e) {
  40581. this._worker = new GenericWorker("error");
  40582. this._worker.error(e);
  40583. }
  40584. }
  40585. StreamHelper.prototype = {
  40586. /**
  40587. * Listen a StreamHelper, accumulate its content and concatenate it into a
  40588. * complete block.
  40589. * @param {Function} updateCb the update callback.
  40590. * @return Promise the promise for the accumulation.
  40591. */
  40592. accumulate: function accumulate(updateCb) {
  40593. return _accumulate(this, updateCb);
  40594. },
  40595. /**
  40596. * Add a listener on an event triggered on a stream.
  40597. * @param {String} evt the name of the event
  40598. * @param {Function} fn the listener
  40599. * @return {StreamHelper} the current helper.
  40600. */
  40601. on: function on(evt, fn) {
  40602. var self = this;
  40603. if (evt === "data") {
  40604. this._worker.on(evt, function (chunk) {
  40605. fn.call(self, chunk.data, chunk.meta);
  40606. });
  40607. } else {
  40608. this._worker.on(evt, function () {
  40609. utils.delay(fn, arguments, self);
  40610. });
  40611. }
  40612. return this;
  40613. },
  40614. /**
  40615. * Resume the flow of chunks.
  40616. * @return {StreamHelper} the current helper.
  40617. */
  40618. resume: function resume() {
  40619. utils.delay(this._worker.resume, [], this._worker);
  40620. return this;
  40621. },
  40622. /**
  40623. * Pause the flow of chunks.
  40624. * @return {StreamHelper} the current helper.
  40625. */
  40626. pause: function pause() {
  40627. this._worker.pause();
  40628. return this;
  40629. },
  40630. /**
  40631. * Return a nodejs stream for this helper.
  40632. * @param {Function} updateCb the update callback.
  40633. * @return {NodejsStreamOutputAdapter} the nodejs stream.
  40634. */
  40635. toNodejsStream: function toNodejsStream(updateCb) {
  40636. utils.checkSupport("nodestream");
  40637. if (this._outputType !== "nodebuffer") {
  40638. // an object stream containing blob/arraybuffer/uint8array/string
  40639. // is strange and I don't know if it would be useful.
  40640. // I you find this comment and have a good usecase, please open a
  40641. // bug report !
  40642. throw new Error(this._outputType + " is not supported by this method");
  40643. }
  40644. return new NodejsStreamOutputAdapter(this, {
  40645. objectMode: this._outputType !== "nodebuffer"
  40646. }, updateCb);
  40647. }
  40648. };
  40649. module.exports = StreamHelper;
  40650. }).call(this,require("buffer").Buffer)
  40651. },{"../base64":281,"../external":286,"../nodejs/NodejsStreamOutputAdapter":293,"../support":310,"../utils":312,"./ConvertWorker":304,"./GenericWorker":308,"buffer":216}],310:[function(require,module,exports){
  40652. (function (Buffer){
  40653. 'use strict';
  40654. exports.base64 = true;
  40655. exports.array = true;
  40656. exports.string = true;
  40657. exports.arraybuffer = typeof ArrayBuffer !== "undefined" && typeof Uint8Array !== "undefined";
  40658. exports.nodebuffer = typeof Buffer !== "undefined"; // contains true if JSZip can read/generate Uint8Array, false otherwise.
  40659. exports.uint8array = typeof Uint8Array !== "undefined";
  40660. if (typeof ArrayBuffer === "undefined") {
  40661. exports.blob = false;
  40662. } else {
  40663. var buffer = new ArrayBuffer(0);
  40664. try {
  40665. exports.blob = new Blob([buffer], {
  40666. type: "application/zip"
  40667. }).size === 0;
  40668. } catch (e) {
  40669. try {
  40670. var Builder = self.BlobBuilder || self.WebKitBlobBuilder || self.MozBlobBuilder || self.MSBlobBuilder;
  40671. var builder = new Builder();
  40672. builder.append(buffer);
  40673. exports.blob = builder.getBlob('application/zip').size === 0;
  40674. } catch (e) {
  40675. exports.blob = false;
  40676. }
  40677. }
  40678. }
  40679. try {
  40680. exports.nodestream = !!require('readable-stream').Readable;
  40681. } catch (e) {
  40682. exports.nodestream = false;
  40683. }
  40684. }).call(this,require("buffer").Buffer)
  40685. },{"buffer":216,"readable-stream":296}],311:[function(require,module,exports){
  40686. 'use strict';
  40687. var utils = require('./utils');
  40688. var support = require('./support');
  40689. var nodejsUtils = require('./nodejsUtils');
  40690. var GenericWorker = require('./stream/GenericWorker');
  40691. /**
  40692. * The following functions come from pako, from pako/lib/utils/strings
  40693. * released under the MIT license, see pako https://github.com/nodeca/pako/
  40694. */
  40695. // Table with utf8 lengths (calculated by first byte of sequence)
  40696. // Note, that 5 & 6-byte values and some 4-byte values can not be represented in JS,
  40697. // because max possible codepoint is 0x10ffff
  40698. var _utf8len = new Array(256);
  40699. for (var i = 0; i < 256; i++) {
  40700. _utf8len[i] = i >= 252 ? 6 : i >= 248 ? 5 : i >= 240 ? 4 : i >= 224 ? 3 : i >= 192 ? 2 : 1;
  40701. }
  40702. _utf8len[254] = _utf8len[254] = 1; // Invalid sequence start
  40703. // convert string to array (typed, when possible)
  40704. var string2buf = function string2buf(str) {
  40705. var buf,
  40706. c,
  40707. c2,
  40708. m_pos,
  40709. i,
  40710. str_len = str.length,
  40711. buf_len = 0; // count binary size
  40712. for (m_pos = 0; m_pos < str_len; m_pos++) {
  40713. c = str.charCodeAt(m_pos);
  40714. if ((c & 0xfc00) === 0xd800 && m_pos + 1 < str_len) {
  40715. c2 = str.charCodeAt(m_pos + 1);
  40716. if ((c2 & 0xfc00) === 0xdc00) {
  40717. c = 0x10000 + (c - 0xd800 << 10) + (c2 - 0xdc00);
  40718. m_pos++;
  40719. }
  40720. }
  40721. buf_len += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4;
  40722. } // allocate buffer
  40723. if (support.uint8array) {
  40724. buf = new Uint8Array(buf_len);
  40725. } else {
  40726. buf = new Array(buf_len);
  40727. } // convert
  40728. for (i = 0, m_pos = 0; i < buf_len; m_pos++) {
  40729. c = str.charCodeAt(m_pos);
  40730. if ((c & 0xfc00) === 0xd800 && m_pos + 1 < str_len) {
  40731. c2 = str.charCodeAt(m_pos + 1);
  40732. if ((c2 & 0xfc00) === 0xdc00) {
  40733. c = 0x10000 + (c - 0xd800 << 10) + (c2 - 0xdc00);
  40734. m_pos++;
  40735. }
  40736. }
  40737. if (c < 0x80) {
  40738. /* one byte */
  40739. buf[i++] = c;
  40740. } else if (c < 0x800) {
  40741. /* two bytes */
  40742. buf[i++] = 0xC0 | c >>> 6;
  40743. buf[i++] = 0x80 | c & 0x3f;
  40744. } else if (c < 0x10000) {
  40745. /* three bytes */
  40746. buf[i++] = 0xE0 | c >>> 12;
  40747. buf[i++] = 0x80 | c >>> 6 & 0x3f;
  40748. buf[i++] = 0x80 | c & 0x3f;
  40749. } else {
  40750. /* four bytes */
  40751. buf[i++] = 0xf0 | c >>> 18;
  40752. buf[i++] = 0x80 | c >>> 12 & 0x3f;
  40753. buf[i++] = 0x80 | c >>> 6 & 0x3f;
  40754. buf[i++] = 0x80 | c & 0x3f;
  40755. }
  40756. }
  40757. return buf;
  40758. }; // Calculate max possible position in utf8 buffer,
  40759. // that will not break sequence. If that's not possible
  40760. // - (very small limits) return max size as is.
  40761. //
  40762. // buf[] - utf8 bytes array
  40763. // max - length limit (mandatory);
  40764. var utf8border = function utf8border(buf, max) {
  40765. var pos;
  40766. max = max || buf.length;
  40767. if (max > buf.length) {
  40768. max = buf.length;
  40769. } // go back from last position, until start of sequence found
  40770. pos = max - 1;
  40771. while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) {
  40772. pos--;
  40773. } // Fuckup - very small and broken sequence,
  40774. // return max, because we should return something anyway.
  40775. if (pos < 0) {
  40776. return max;
  40777. } // If we came to start of buffer - that means vuffer is too small,
  40778. // return max too.
  40779. if (pos === 0) {
  40780. return max;
  40781. }
  40782. return pos + _utf8len[buf[pos]] > max ? pos : max;
  40783. }; // convert array to string
  40784. var buf2string = function buf2string(buf) {
  40785. var str, i, out, c, c_len;
  40786. var len = buf.length; // Reserve max possible length (2 words per char)
  40787. // NB: by unknown reasons, Array is significantly faster for
  40788. // String.fromCharCode.apply than Uint16Array.
  40789. var utf16buf = new Array(len * 2);
  40790. for (out = 0, i = 0; i < len;) {
  40791. c = buf[i++]; // quick process ascii
  40792. if (c < 0x80) {
  40793. utf16buf[out++] = c;
  40794. continue;
  40795. }
  40796. c_len = _utf8len[c]; // skip 5 & 6 byte codes
  40797. if (c_len > 4) {
  40798. utf16buf[out++] = 0xfffd;
  40799. i += c_len - 1;
  40800. continue;
  40801. } // apply mask on first byte
  40802. c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07; // join the rest
  40803. while (c_len > 1 && i < len) {
  40804. c = c << 6 | buf[i++] & 0x3f;
  40805. c_len--;
  40806. } // terminated by end of string?
  40807. if (c_len > 1) {
  40808. utf16buf[out++] = 0xfffd;
  40809. continue;
  40810. }
  40811. if (c < 0x10000) {
  40812. utf16buf[out++] = c;
  40813. } else {
  40814. c -= 0x10000;
  40815. utf16buf[out++] = 0xd800 | c >> 10 & 0x3ff;
  40816. utf16buf[out++] = 0xdc00 | c & 0x3ff;
  40817. }
  40818. } // shrinkBuf(utf16buf, out)
  40819. if (utf16buf.length !== out) {
  40820. if (utf16buf.subarray) {
  40821. utf16buf = utf16buf.subarray(0, out);
  40822. } else {
  40823. utf16buf.length = out;
  40824. }
  40825. } // return String.fromCharCode.apply(null, utf16buf);
  40826. return utils.applyFromCharCode(utf16buf);
  40827. }; // That's all for the pako functions.
  40828. /**
  40829. * Transform a javascript string into an array (typed if possible) of bytes,
  40830. * UTF-8 encoded.
  40831. * @param {String} str the string to encode
  40832. * @return {Array|Uint8Array|Buffer} the UTF-8 encoded string.
  40833. */
  40834. exports.utf8encode = function utf8encode(str) {
  40835. if (support.nodebuffer) {
  40836. return nodejsUtils.newBufferFrom(str, "utf-8");
  40837. }
  40838. return string2buf(str);
  40839. };
  40840. /**
  40841. * Transform a bytes array (or a representation) representing an UTF-8 encoded
  40842. * string into a javascript string.
  40843. * @param {Array|Uint8Array|Buffer} buf the data de decode
  40844. * @return {String} the decoded string.
  40845. */
  40846. exports.utf8decode = function utf8decode(buf) {
  40847. if (support.nodebuffer) {
  40848. return utils.transformTo("nodebuffer", buf).toString("utf-8");
  40849. }
  40850. buf = utils.transformTo(support.uint8array ? "uint8array" : "array", buf);
  40851. return buf2string(buf);
  40852. };
  40853. /**
  40854. * A worker to decode utf8 encoded binary chunks into string chunks.
  40855. * @constructor
  40856. */
  40857. function Utf8DecodeWorker() {
  40858. GenericWorker.call(this, "utf-8 decode"); // the last bytes if a chunk didn't end with a complete codepoint.
  40859. this.leftOver = null;
  40860. }
  40861. utils.inherits(Utf8DecodeWorker, GenericWorker);
  40862. /**
  40863. * @see GenericWorker.processChunk
  40864. */
  40865. Utf8DecodeWorker.prototype.processChunk = function (chunk) {
  40866. var data = utils.transformTo(support.uint8array ? "uint8array" : "array", chunk.data); // 1st step, re-use what's left of the previous chunk
  40867. if (this.leftOver && this.leftOver.length) {
  40868. if (support.uint8array) {
  40869. var previousData = data;
  40870. data = new Uint8Array(previousData.length + this.leftOver.length);
  40871. data.set(this.leftOver, 0);
  40872. data.set(previousData, this.leftOver.length);
  40873. } else {
  40874. data = this.leftOver.concat(data);
  40875. }
  40876. this.leftOver = null;
  40877. }
  40878. var nextBoundary = utf8border(data);
  40879. var usableData = data;
  40880. if (nextBoundary !== data.length) {
  40881. if (support.uint8array) {
  40882. usableData = data.subarray(0, nextBoundary);
  40883. this.leftOver = data.subarray(nextBoundary, data.length);
  40884. } else {
  40885. usableData = data.slice(0, nextBoundary);
  40886. this.leftOver = data.slice(nextBoundary, data.length);
  40887. }
  40888. }
  40889. this.push({
  40890. data: exports.utf8decode(usableData),
  40891. meta: chunk.meta
  40892. });
  40893. };
  40894. /**
  40895. * @see GenericWorker.flush
  40896. */
  40897. Utf8DecodeWorker.prototype.flush = function () {
  40898. if (this.leftOver && this.leftOver.length) {
  40899. this.push({
  40900. data: exports.utf8decode(this.leftOver),
  40901. meta: {}
  40902. });
  40903. this.leftOver = null;
  40904. }
  40905. };
  40906. exports.Utf8DecodeWorker = Utf8DecodeWorker;
  40907. /**
  40908. * A worker to endcode string chunks into utf8 encoded binary chunks.
  40909. * @constructor
  40910. */
  40911. function Utf8EncodeWorker() {
  40912. GenericWorker.call(this, "utf-8 encode");
  40913. }
  40914. utils.inherits(Utf8EncodeWorker, GenericWorker);
  40915. /**
  40916. * @see GenericWorker.processChunk
  40917. */
  40918. Utf8EncodeWorker.prototype.processChunk = function (chunk) {
  40919. this.push({
  40920. data: exports.utf8encode(chunk.data),
  40921. meta: chunk.meta
  40922. });
  40923. };
  40924. exports.Utf8EncodeWorker = Utf8EncodeWorker;
  40925. },{"./nodejsUtils":294,"./stream/GenericWorker":308,"./support":310,"./utils":312}],312:[function(require,module,exports){
  40926. 'use strict';
  40927. var support = require('./support');
  40928. var base64 = require('./base64');
  40929. var nodejsUtils = require('./nodejsUtils');
  40930. var setImmediate = require('set-immediate-shim');
  40931. var external = require("./external");
  40932. /**
  40933. * Convert a string that pass as a "binary string": it should represent a byte
  40934. * array but may have > 255 char codes. Be sure to take only the first byte
  40935. * and returns the byte array.
  40936. * @param {String} str the string to transform.
  40937. * @return {Array|Uint8Array} the string in a binary format.
  40938. */
  40939. function string2binary(str) {
  40940. var result = null;
  40941. if (support.uint8array) {
  40942. result = new Uint8Array(str.length);
  40943. } else {
  40944. result = new Array(str.length);
  40945. }
  40946. return stringToArrayLike(str, result);
  40947. }
  40948. /**
  40949. * Create a new blob with the given content and the given type.
  40950. * @param {String|ArrayBuffer} part the content to put in the blob. DO NOT use
  40951. * an Uint8Array because the stock browser of android 4 won't accept it (it
  40952. * will be silently converted to a string, "[object Uint8Array]").
  40953. *
  40954. * Use only ONE part to build the blob to avoid a memory leak in IE11 / Edge:
  40955. * when a large amount of Array is used to create the Blob, the amount of
  40956. * memory consumed is nearly 100 times the original data amount.
  40957. *
  40958. * @param {String} type the mime type of the blob.
  40959. * @return {Blob} the created blob.
  40960. */
  40961. exports.newBlob = function (part, type) {
  40962. exports.checkSupport("blob");
  40963. try {
  40964. // Blob constructor
  40965. return new Blob([part], {
  40966. type: type
  40967. });
  40968. } catch (e) {
  40969. try {
  40970. // deprecated, browser only, old way
  40971. var Builder = self.BlobBuilder || self.WebKitBlobBuilder || self.MozBlobBuilder || self.MSBlobBuilder;
  40972. var builder = new Builder();
  40973. builder.append(part);
  40974. return builder.getBlob(type);
  40975. } catch (e) {
  40976. // well, fuck ?!
  40977. throw new Error("Bug : can't construct the Blob.");
  40978. }
  40979. }
  40980. };
  40981. /**
  40982. * The identity function.
  40983. * @param {Object} input the input.
  40984. * @return {Object} the same input.
  40985. */
  40986. function identity(input) {
  40987. return input;
  40988. }
  40989. /**
  40990. * Fill in an array with a string.
  40991. * @param {String} str the string to use.
  40992. * @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to fill in (will be mutated).
  40993. * @return {Array|ArrayBuffer|Uint8Array|Buffer} the updated array.
  40994. */
  40995. function stringToArrayLike(str, array) {
  40996. for (var i = 0; i < str.length; ++i) {
  40997. array[i] = str.charCodeAt(i) & 0xFF;
  40998. }
  40999. return array;
  41000. }
  41001. /**
  41002. * An helper for the function arrayLikeToString.
  41003. * This contains static information and functions that
  41004. * can be optimized by the browser JIT compiler.
  41005. */
  41006. var arrayToStringHelper = {
  41007. /**
  41008. * Transform an array of int into a string, chunk by chunk.
  41009. * See the performances notes on arrayLikeToString.
  41010. * @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to transform.
  41011. * @param {String} type the type of the array.
  41012. * @param {Integer} chunk the chunk size.
  41013. * @return {String} the resulting string.
  41014. * @throws Error if the chunk is too big for the stack.
  41015. */
  41016. stringifyByChunk: function stringifyByChunk(array, type, chunk) {
  41017. var result = [],
  41018. k = 0,
  41019. len = array.length; // shortcut
  41020. if (len <= chunk) {
  41021. return String.fromCharCode.apply(null, array);
  41022. }
  41023. while (k < len) {
  41024. if (type === "array" || type === "nodebuffer") {
  41025. result.push(String.fromCharCode.apply(null, array.slice(k, Math.min(k + chunk, len))));
  41026. } else {
  41027. result.push(String.fromCharCode.apply(null, array.subarray(k, Math.min(k + chunk, len))));
  41028. }
  41029. k += chunk;
  41030. }
  41031. return result.join("");
  41032. },
  41033. /**
  41034. * Call String.fromCharCode on every item in the array.
  41035. * This is the naive implementation, which generate A LOT of intermediate string.
  41036. * This should be used when everything else fail.
  41037. * @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to transform.
  41038. * @return {String} the result.
  41039. */
  41040. stringifyByChar: function stringifyByChar(array) {
  41041. var resultStr = "";
  41042. for (var i = 0; i < array.length; i++) {
  41043. resultStr += String.fromCharCode(array[i]);
  41044. }
  41045. return resultStr;
  41046. },
  41047. applyCanBeUsed: {
  41048. /**
  41049. * true if the browser accepts to use String.fromCharCode on Uint8Array
  41050. */
  41051. uint8array: function () {
  41052. try {
  41053. return support.uint8array && String.fromCharCode.apply(null, new Uint8Array(1)).length === 1;
  41054. } catch (e) {
  41055. return false;
  41056. }
  41057. }(),
  41058. /**
  41059. * true if the browser accepts to use String.fromCharCode on nodejs Buffer.
  41060. */
  41061. nodebuffer: function () {
  41062. try {
  41063. return support.nodebuffer && String.fromCharCode.apply(null, nodejsUtils.allocBuffer(1)).length === 1;
  41064. } catch (e) {
  41065. return false;
  41066. }
  41067. }()
  41068. }
  41069. };
  41070. /**
  41071. * Transform an array-like object to a string.
  41072. * @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to transform.
  41073. * @return {String} the result.
  41074. */
  41075. function arrayLikeToString(array) {
  41076. // Performances notes :
  41077. // --------------------
  41078. // String.fromCharCode.apply(null, array) is the fastest, see
  41079. // see http://jsperf.com/converting-a-uint8array-to-a-string/2
  41080. // but the stack is limited (and we can get huge arrays !).
  41081. //
  41082. // result += String.fromCharCode(array[i]); generate too many strings !
  41083. //
  41084. // This code is inspired by http://jsperf.com/arraybuffer-to-string-apply-performance/2
  41085. // TODO : we now have workers that split the work. Do we still need that ?
  41086. var chunk = 65536,
  41087. type = exports.getTypeOf(array),
  41088. canUseApply = true;
  41089. if (type === "uint8array") {
  41090. canUseApply = arrayToStringHelper.applyCanBeUsed.uint8array;
  41091. } else if (type === "nodebuffer") {
  41092. canUseApply = arrayToStringHelper.applyCanBeUsed.nodebuffer;
  41093. }
  41094. if (canUseApply) {
  41095. while (chunk > 1) {
  41096. try {
  41097. return arrayToStringHelper.stringifyByChunk(array, type, chunk);
  41098. } catch (e) {
  41099. chunk = Math.floor(chunk / 2);
  41100. }
  41101. }
  41102. } // no apply or chunk error : slow and painful algorithm
  41103. // default browser on android 4.*
  41104. return arrayToStringHelper.stringifyByChar(array);
  41105. }
  41106. exports.applyFromCharCode = arrayLikeToString;
  41107. /**
  41108. * Copy the data from an array-like to an other array-like.
  41109. * @param {Array|ArrayBuffer|Uint8Array|Buffer} arrayFrom the origin array.
  41110. * @param {Array|ArrayBuffer|Uint8Array|Buffer} arrayTo the destination array which will be mutated.
  41111. * @return {Array|ArrayBuffer|Uint8Array|Buffer} the updated destination array.
  41112. */
  41113. function arrayLikeToArrayLike(arrayFrom, arrayTo) {
  41114. for (var i = 0; i < arrayFrom.length; i++) {
  41115. arrayTo[i] = arrayFrom[i];
  41116. }
  41117. return arrayTo;
  41118. } // a matrix containing functions to transform everything into everything.
  41119. var transform = {}; // string to ?
  41120. transform["string"] = {
  41121. "string": identity,
  41122. "array": function array(input) {
  41123. return stringToArrayLike(input, new Array(input.length));
  41124. },
  41125. "arraybuffer": function arraybuffer(input) {
  41126. return transform["string"]["uint8array"](input).buffer;
  41127. },
  41128. "uint8array": function uint8array(input) {
  41129. return stringToArrayLike(input, new Uint8Array(input.length));
  41130. },
  41131. "nodebuffer": function nodebuffer(input) {
  41132. return stringToArrayLike(input, nodejsUtils.allocBuffer(input.length));
  41133. }
  41134. }; // array to ?
  41135. transform["array"] = {
  41136. "string": arrayLikeToString,
  41137. "array": identity,
  41138. "arraybuffer": function arraybuffer(input) {
  41139. return new Uint8Array(input).buffer;
  41140. },
  41141. "uint8array": function uint8array(input) {
  41142. return new Uint8Array(input);
  41143. },
  41144. "nodebuffer": function nodebuffer(input) {
  41145. return nodejsUtils.newBufferFrom(input);
  41146. }
  41147. }; // arraybuffer to ?
  41148. transform["arraybuffer"] = {
  41149. "string": function string(input) {
  41150. return arrayLikeToString(new Uint8Array(input));
  41151. },
  41152. "array": function array(input) {
  41153. return arrayLikeToArrayLike(new Uint8Array(input), new Array(input.byteLength));
  41154. },
  41155. "arraybuffer": identity,
  41156. "uint8array": function uint8array(input) {
  41157. return new Uint8Array(input);
  41158. },
  41159. "nodebuffer": function nodebuffer(input) {
  41160. return nodejsUtils.newBufferFrom(new Uint8Array(input));
  41161. }
  41162. }; // uint8array to ?
  41163. transform["uint8array"] = {
  41164. "string": arrayLikeToString,
  41165. "array": function array(input) {
  41166. return arrayLikeToArrayLike(input, new Array(input.length));
  41167. },
  41168. "arraybuffer": function arraybuffer(input) {
  41169. return input.buffer;
  41170. },
  41171. "uint8array": identity,
  41172. "nodebuffer": function nodebuffer(input) {
  41173. return nodejsUtils.newBufferFrom(input);
  41174. }
  41175. }; // nodebuffer to ?
  41176. transform["nodebuffer"] = {
  41177. "string": arrayLikeToString,
  41178. "array": function array(input) {
  41179. return arrayLikeToArrayLike(input, new Array(input.length));
  41180. },
  41181. "arraybuffer": function arraybuffer(input) {
  41182. return transform["nodebuffer"]["uint8array"](input).buffer;
  41183. },
  41184. "uint8array": function uint8array(input) {
  41185. return arrayLikeToArrayLike(input, new Uint8Array(input.length));
  41186. },
  41187. "nodebuffer": identity
  41188. };
  41189. /**
  41190. * Transform an input into any type.
  41191. * The supported output type are : string, array, uint8array, arraybuffer, nodebuffer.
  41192. * If no output type is specified, the unmodified input will be returned.
  41193. * @param {String} outputType the output type.
  41194. * @param {String|Array|ArrayBuffer|Uint8Array|Buffer} input the input to convert.
  41195. * @throws {Error} an Error if the browser doesn't support the requested output type.
  41196. */
  41197. exports.transformTo = function (outputType, input) {
  41198. if (!input) {
  41199. // undefined, null, etc
  41200. // an empty string won't harm.
  41201. input = "";
  41202. }
  41203. if (!outputType) {
  41204. return input;
  41205. }
  41206. exports.checkSupport(outputType);
  41207. var inputType = exports.getTypeOf(input);
  41208. var result = transform[inputType][outputType](input);
  41209. return result;
  41210. };
  41211. /**
  41212. * Return the type of the input.
  41213. * The type will be in a format valid for JSZip.utils.transformTo : string, array, uint8array, arraybuffer.
  41214. * @param {Object} input the input to identify.
  41215. * @return {String} the (lowercase) type of the input.
  41216. */
  41217. exports.getTypeOf = function (input) {
  41218. if (typeof input === "string") {
  41219. return "string";
  41220. }
  41221. if (Object.prototype.toString.call(input) === "[object Array]") {
  41222. return "array";
  41223. }
  41224. if (support.nodebuffer && nodejsUtils.isBuffer(input)) {
  41225. return "nodebuffer";
  41226. }
  41227. if (support.uint8array && input instanceof Uint8Array) {
  41228. return "uint8array";
  41229. }
  41230. if (support.arraybuffer && input instanceof ArrayBuffer) {
  41231. return "arraybuffer";
  41232. }
  41233. };
  41234. /**
  41235. * Throw an exception if the type is not supported.
  41236. * @param {String} type the type to check.
  41237. * @throws {Error} an Error if the browser doesn't support the requested type.
  41238. */
  41239. exports.checkSupport = function (type) {
  41240. var supported = support[type.toLowerCase()];
  41241. if (!supported) {
  41242. throw new Error(type + " is not supported by this platform");
  41243. }
  41244. };
  41245. exports.MAX_VALUE_16BITS = 65535;
  41246. exports.MAX_VALUE_32BITS = -1; // well, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" is parsed as -1
  41247. /**
  41248. * Prettify a string read as binary.
  41249. * @param {string} str the string to prettify.
  41250. * @return {string} a pretty string.
  41251. */
  41252. exports.pretty = function (str) {
  41253. var res = '',
  41254. code,
  41255. i;
  41256. for (i = 0; i < (str || "").length; i++) {
  41257. code = str.charCodeAt(i);
  41258. res += '\\x' + (code < 16 ? "0" : "") + code.toString(16).toUpperCase();
  41259. }
  41260. return res;
  41261. };
  41262. /**
  41263. * Defer the call of a function.
  41264. * @param {Function} callback the function to call asynchronously.
  41265. * @param {Array} args the arguments to give to the callback.
  41266. */
  41267. exports.delay = function (callback, args, self) {
  41268. setImmediate(function () {
  41269. callback.apply(self || null, args || []);
  41270. });
  41271. };
  41272. /**
  41273. * Extends a prototype with an other, without calling a constructor with
  41274. * side effects. Inspired by nodejs' `utils.inherits`
  41275. * @param {Function} ctor the constructor to augment
  41276. * @param {Function} superCtor the parent constructor to use
  41277. */
  41278. exports.inherits = function (ctor, superCtor) {
  41279. var Obj = function Obj() {};
  41280. Obj.prototype = superCtor.prototype;
  41281. ctor.prototype = new Obj();
  41282. };
  41283. /**
  41284. * Merge the objects passed as parameters into a new one.
  41285. * @private
  41286. * @param {...Object} var_args All objects to merge.
  41287. * @return {Object} a new object with the data of the others.
  41288. */
  41289. exports.extend = function () {
  41290. var result = {},
  41291. i,
  41292. attr;
  41293. for (i = 0; i < arguments.length; i++) {
  41294. // arguments is not enumerable in some browsers
  41295. for (attr in arguments[i]) {
  41296. if (arguments[i].hasOwnProperty(attr) && typeof result[attr] === "undefined") {
  41297. result[attr] = arguments[i][attr];
  41298. }
  41299. }
  41300. }
  41301. return result;
  41302. };
  41303. /**
  41304. * Transform arbitrary content into a Promise.
  41305. * @param {String} name a name for the content being processed.
  41306. * @param {Object} inputData the content to process.
  41307. * @param {Boolean} isBinary true if the content is not an unicode string
  41308. * @param {Boolean} isOptimizedBinaryString true if the string content only has one byte per character.
  41309. * @param {Boolean} isBase64 true if the string content is encoded with base64.
  41310. * @return {Promise} a promise in a format usable by JSZip.
  41311. */
  41312. exports.prepareContent = function (name, inputData, isBinary, isOptimizedBinaryString, isBase64) {
  41313. // if inputData is already a promise, this flatten it.
  41314. var promise = external.Promise.resolve(inputData).then(function (data) {
  41315. var isBlob = support.blob && (data instanceof Blob || ['[object File]', '[object Blob]'].indexOf(Object.prototype.toString.call(data)) !== -1);
  41316. if (isBlob && typeof FileReader !== "undefined") {
  41317. return new external.Promise(function (resolve, reject) {
  41318. var reader = new FileReader();
  41319. reader.onload = function (e) {
  41320. resolve(e.target.result);
  41321. };
  41322. reader.onerror = function (e) {
  41323. reject(e.target.error);
  41324. };
  41325. reader.readAsArrayBuffer(data);
  41326. });
  41327. } else {
  41328. return data;
  41329. }
  41330. });
  41331. return promise.then(function (data) {
  41332. var dataType = exports.getTypeOf(data);
  41333. if (!dataType) {
  41334. return external.Promise.reject(new Error("Can't read the data of '" + name + "'. Is it " + "in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?"));
  41335. } // special case : it's way easier to work with Uint8Array than with ArrayBuffer
  41336. if (dataType === "arraybuffer") {
  41337. data = exports.transformTo("uint8array", data);
  41338. } else if (dataType === "string") {
  41339. if (isBase64) {
  41340. data = base64.decode(data);
  41341. } else if (isBinary) {
  41342. // optimizedBinaryString === true means that the file has already been filtered with a 0xFF mask
  41343. if (isOptimizedBinaryString !== true) {
  41344. // this is a string, not in a base64 format.
  41345. // Be sure that this is a correct "binary string"
  41346. data = string2binary(data);
  41347. }
  41348. }
  41349. }
  41350. return data;
  41351. });
  41352. };
  41353. },{"./base64":281,"./external":286,"./nodejsUtils":294,"./support":310,"set-immediate-shim":387}],313:[function(require,module,exports){
  41354. 'use strict';
  41355. var readerFor = require('./reader/readerFor');
  41356. var utils = require('./utils');
  41357. var sig = require('./signature');
  41358. var ZipEntry = require('./zipEntry');
  41359. var utf8 = require('./utf8');
  41360. var support = require('./support'); // class ZipEntries {{{
  41361. /**
  41362. * All the entries in the zip file.
  41363. * @constructor
  41364. * @param {Object} loadOptions Options for loading the stream.
  41365. */
  41366. function ZipEntries(loadOptions) {
  41367. this.files = [];
  41368. this.loadOptions = loadOptions;
  41369. }
  41370. ZipEntries.prototype = {
  41371. /**
  41372. * Check that the reader is on the specified signature.
  41373. * @param {string} expectedSignature the expected signature.
  41374. * @throws {Error} if it is an other signature.
  41375. */
  41376. checkSignature: function checkSignature(expectedSignature) {
  41377. if (!this.reader.readAndCheckSignature(expectedSignature)) {
  41378. this.reader.index -= 4;
  41379. var signature = this.reader.readString(4);
  41380. throw new Error("Corrupted zip or bug: unexpected signature " + "(" + utils.pretty(signature) + ", expected " + utils.pretty(expectedSignature) + ")");
  41381. }
  41382. },
  41383. /**
  41384. * Check if the given signature is at the given index.
  41385. * @param {number} askedIndex the index to check.
  41386. * @param {string} expectedSignature the signature to expect.
  41387. * @return {boolean} true if the signature is here, false otherwise.
  41388. */
  41389. isSignature: function isSignature(askedIndex, expectedSignature) {
  41390. var currentIndex = this.reader.index;
  41391. this.reader.setIndex(askedIndex);
  41392. var signature = this.reader.readString(4);
  41393. var result = signature === expectedSignature;
  41394. this.reader.setIndex(currentIndex);
  41395. return result;
  41396. },
  41397. /**
  41398. * Read the end of the central directory.
  41399. */
  41400. readBlockEndOfCentral: function readBlockEndOfCentral() {
  41401. this.diskNumber = this.reader.readInt(2);
  41402. this.diskWithCentralDirStart = this.reader.readInt(2);
  41403. this.centralDirRecordsOnThisDisk = this.reader.readInt(2);
  41404. this.centralDirRecords = this.reader.readInt(2);
  41405. this.centralDirSize = this.reader.readInt(4);
  41406. this.centralDirOffset = this.reader.readInt(4);
  41407. this.zipCommentLength = this.reader.readInt(2); // warning : the encoding depends of the system locale
  41408. // On a linux machine with LANG=en_US.utf8, this field is utf8 encoded.
  41409. // On a windows machine, this field is encoded with the localized windows code page.
  41410. var zipComment = this.reader.readData(this.zipCommentLength);
  41411. var decodeParamType = support.uint8array ? "uint8array" : "array"; // To get consistent behavior with the generation part, we will assume that
  41412. // this is utf8 encoded unless specified otherwise.
  41413. var decodeContent = utils.transformTo(decodeParamType, zipComment);
  41414. this.zipComment = this.loadOptions.decodeFileName(decodeContent);
  41415. },
  41416. /**
  41417. * Read the end of the Zip 64 central directory.
  41418. * Not merged with the method readEndOfCentral :
  41419. * The end of central can coexist with its Zip64 brother,
  41420. * I don't want to read the wrong number of bytes !
  41421. */
  41422. readBlockZip64EndOfCentral: function readBlockZip64EndOfCentral() {
  41423. this.zip64EndOfCentralSize = this.reader.readInt(8);
  41424. this.reader.skip(4); // this.versionMadeBy = this.reader.readString(2);
  41425. // this.versionNeeded = this.reader.readInt(2);
  41426. this.diskNumber = this.reader.readInt(4);
  41427. this.diskWithCentralDirStart = this.reader.readInt(4);
  41428. this.centralDirRecordsOnThisDisk = this.reader.readInt(8);
  41429. this.centralDirRecords = this.reader.readInt(8);
  41430. this.centralDirSize = this.reader.readInt(8);
  41431. this.centralDirOffset = this.reader.readInt(8);
  41432. this.zip64ExtensibleData = {};
  41433. var extraDataSize = this.zip64EndOfCentralSize - 44,
  41434. index = 0,
  41435. extraFieldId,
  41436. extraFieldLength,
  41437. extraFieldValue;
  41438. while (index < extraDataSize) {
  41439. extraFieldId = this.reader.readInt(2);
  41440. extraFieldLength = this.reader.readInt(4);
  41441. extraFieldValue = this.reader.readData(extraFieldLength);
  41442. this.zip64ExtensibleData[extraFieldId] = {
  41443. id: extraFieldId,
  41444. length: extraFieldLength,
  41445. value: extraFieldValue
  41446. };
  41447. }
  41448. },
  41449. /**
  41450. * Read the end of the Zip 64 central directory locator.
  41451. */
  41452. readBlockZip64EndOfCentralLocator: function readBlockZip64EndOfCentralLocator() {
  41453. this.diskWithZip64CentralDirStart = this.reader.readInt(4);
  41454. this.relativeOffsetEndOfZip64CentralDir = this.reader.readInt(8);
  41455. this.disksCount = this.reader.readInt(4);
  41456. if (this.disksCount > 1) {
  41457. throw new Error("Multi-volumes zip are not supported");
  41458. }
  41459. },
  41460. /**
  41461. * Read the local files, based on the offset read in the central part.
  41462. */
  41463. readLocalFiles: function readLocalFiles() {
  41464. var i, file;
  41465. for (i = 0; i < this.files.length; i++) {
  41466. file = this.files[i];
  41467. this.reader.setIndex(file.localHeaderOffset);
  41468. this.checkSignature(sig.LOCAL_FILE_HEADER);
  41469. file.readLocalPart(this.reader);
  41470. file.handleUTF8();
  41471. file.processAttributes();
  41472. }
  41473. },
  41474. /**
  41475. * Read the central directory.
  41476. */
  41477. readCentralDir: function readCentralDir() {
  41478. var file;
  41479. this.reader.setIndex(this.centralDirOffset);
  41480. while (this.reader.readAndCheckSignature(sig.CENTRAL_FILE_HEADER)) {
  41481. file = new ZipEntry({
  41482. zip64: this.zip64
  41483. }, this.loadOptions);
  41484. file.readCentralPart(this.reader);
  41485. this.files.push(file);
  41486. }
  41487. if (this.centralDirRecords !== this.files.length) {
  41488. if (this.centralDirRecords !== 0 && this.files.length === 0) {
  41489. // We expected some records but couldn't find ANY.
  41490. // This is really suspicious, as if something went wrong.
  41491. throw new Error("Corrupted zip or bug: expected " + this.centralDirRecords + " records in central dir, got " + this.files.length);
  41492. } else {// We found some records but not all.
  41493. // Something is wrong but we got something for the user: no error here.
  41494. // console.warn("expected", this.centralDirRecords, "records in central dir, got", this.files.length);
  41495. }
  41496. }
  41497. },
  41498. /**
  41499. * Read the end of central directory.
  41500. */
  41501. readEndOfCentral: function readEndOfCentral() {
  41502. var offset = this.reader.lastIndexOfSignature(sig.CENTRAL_DIRECTORY_END);
  41503. if (offset < 0) {
  41504. // Check if the content is a truncated zip or complete garbage.
  41505. // A "LOCAL_FILE_HEADER" is not required at the beginning (auto
  41506. // extractible zip for example) but it can give a good hint.
  41507. // If an ajax request was used without responseType, we will also
  41508. // get unreadable data.
  41509. var isGarbage = !this.isSignature(0, sig.LOCAL_FILE_HEADER);
  41510. if (isGarbage) {
  41511. 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");
  41512. } else {
  41513. throw new Error("Corrupted zip: can't find end of central directory");
  41514. }
  41515. }
  41516. this.reader.setIndex(offset);
  41517. var endOfCentralDirOffset = offset;
  41518. this.checkSignature(sig.CENTRAL_DIRECTORY_END);
  41519. this.readBlockEndOfCentral();
  41520. /* extract from the zip spec :
  41521. 4) If one of the fields in the end of central directory
  41522. record is too small to hold required data, the field
  41523. should be set to -1 (0xFFFF or 0xFFFFFFFF) and the
  41524. ZIP64 format record should be created.
  41525. 5) The end of central directory record and the
  41526. Zip64 end of central directory locator record must
  41527. reside on the same disk when splitting or spanning
  41528. an archive.
  41529. */
  41530. 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) {
  41531. this.zip64 = true;
  41532. /*
  41533. Warning : the zip64 extension is supported, but ONLY if the 64bits integer read from
  41534. the zip file can fit into a 32bits integer. This cannot be solved : JavaScript represents
  41535. all numbers as 64-bit double precision IEEE 754 floating point numbers.
  41536. So, we have 53bits for integers and bitwise operations treat everything as 32bits.
  41537. see https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/Bitwise_Operators
  41538. and http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf section 8.5
  41539. */
  41540. // should look for a zip64 EOCD locator
  41541. offset = this.reader.lastIndexOfSignature(sig.ZIP64_CENTRAL_DIRECTORY_LOCATOR);
  41542. if (offset < 0) {
  41543. throw new Error("Corrupted zip: can't find the ZIP64 end of central directory locator");
  41544. }
  41545. this.reader.setIndex(offset);
  41546. this.checkSignature(sig.ZIP64_CENTRAL_DIRECTORY_LOCATOR);
  41547. this.readBlockZip64EndOfCentralLocator(); // now the zip64 EOCD record
  41548. if (!this.isSignature(this.relativeOffsetEndOfZip64CentralDir, sig.ZIP64_CENTRAL_DIRECTORY_END)) {
  41549. // console.warn("ZIP64 end of central directory not where expected.");
  41550. this.relativeOffsetEndOfZip64CentralDir = this.reader.lastIndexOfSignature(sig.ZIP64_CENTRAL_DIRECTORY_END);
  41551. if (this.relativeOffsetEndOfZip64CentralDir < 0) {
  41552. throw new Error("Corrupted zip: can't find the ZIP64 end of central directory");
  41553. }
  41554. }
  41555. this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir);
  41556. this.checkSignature(sig.ZIP64_CENTRAL_DIRECTORY_END);
  41557. this.readBlockZip64EndOfCentral();
  41558. }
  41559. var expectedEndOfCentralDirOffset = this.centralDirOffset + this.centralDirSize;
  41560. if (this.zip64) {
  41561. expectedEndOfCentralDirOffset += 20; // end of central dir 64 locator
  41562. expectedEndOfCentralDirOffset += 12
  41563. /* should not include the leading 12 bytes */
  41564. + this.zip64EndOfCentralSize;
  41565. }
  41566. var extraBytes = endOfCentralDirOffset - expectedEndOfCentralDirOffset;
  41567. if (extraBytes > 0) {
  41568. // console.warn(extraBytes, "extra bytes at beginning or within zipfile");
  41569. if (this.isSignature(endOfCentralDirOffset, sig.CENTRAL_FILE_HEADER)) {// The offsets seem wrong, but we have something at the specified offset.
  41570. // So… we keep it.
  41571. } else {
  41572. // the offset is wrong, update the "zero" of the reader
  41573. // this happens if data has been prepended (crx files for example)
  41574. this.reader.zero = extraBytes;
  41575. }
  41576. } else if (extraBytes < 0) {
  41577. throw new Error("Corrupted zip: missing " + Math.abs(extraBytes) + " bytes.");
  41578. }
  41579. },
  41580. prepareReader: function prepareReader(data) {
  41581. this.reader = readerFor(data);
  41582. },
  41583. /**
  41584. * Read a zip file and create ZipEntries.
  41585. * @param {String|ArrayBuffer|Uint8Array|Buffer} data the binary string representing a zip file.
  41586. */
  41587. load: function load(data) {
  41588. this.prepareReader(data);
  41589. this.readEndOfCentral();
  41590. this.readCentralDir();
  41591. this.readLocalFiles();
  41592. }
  41593. }; // }}} end of ZipEntries
  41594. module.exports = ZipEntries;
  41595. },{"./reader/readerFor":302,"./signature":303,"./support":310,"./utf8":311,"./utils":312,"./zipEntry":314}],314:[function(require,module,exports){
  41596. 'use strict';
  41597. var readerFor = require('./reader/readerFor');
  41598. var utils = require('./utils');
  41599. var CompressedObject = require('./compressedObject');
  41600. var crc32fn = require('./crc32');
  41601. var utf8 = require('./utf8');
  41602. var compressions = require('./compressions');
  41603. var support = require('./support');
  41604. var MADE_BY_DOS = 0x00;
  41605. var MADE_BY_UNIX = 0x03;
  41606. /**
  41607. * Find a compression registered in JSZip.
  41608. * @param {string} compressionMethod the method magic to find.
  41609. * @return {Object|null} the JSZip compression object, null if none found.
  41610. */
  41611. var findCompression = function findCompression(compressionMethod) {
  41612. for (var method in compressions) {
  41613. if (!compressions.hasOwnProperty(method)) {
  41614. continue;
  41615. }
  41616. if (compressions[method].magic === compressionMethod) {
  41617. return compressions[method];
  41618. }
  41619. }
  41620. return null;
  41621. }; // class ZipEntry {{{
  41622. /**
  41623. * An entry in the zip file.
  41624. * @constructor
  41625. * @param {Object} options Options of the current file.
  41626. * @param {Object} loadOptions Options for loading the stream.
  41627. */
  41628. function ZipEntry(options, loadOptions) {
  41629. this.options = options;
  41630. this.loadOptions = loadOptions;
  41631. }
  41632. ZipEntry.prototype = {
  41633. /**
  41634. * say if the file is encrypted.
  41635. * @return {boolean} true if the file is encrypted, false otherwise.
  41636. */
  41637. isEncrypted: function isEncrypted() {
  41638. // bit 1 is set
  41639. return (this.bitFlag & 0x0001) === 0x0001;
  41640. },
  41641. /**
  41642. * say if the file has utf-8 filename/comment.
  41643. * @return {boolean} true if the filename/comment is in utf-8, false otherwise.
  41644. */
  41645. useUTF8: function useUTF8() {
  41646. // bit 11 is set
  41647. return (this.bitFlag & 0x0800) === 0x0800;
  41648. },
  41649. /**
  41650. * Read the local part of a zip file and add the info in this object.
  41651. * @param {DataReader} reader the reader to use.
  41652. */
  41653. readLocalPart: function readLocalPart(reader) {
  41654. var compression, localExtraFieldsLength; // we already know everything from the central dir !
  41655. // If the central dir data are false, we are doomed.
  41656. // On the bright side, the local part is scary : zip64, data descriptors, both, etc.
  41657. // The less data we get here, the more reliable this should be.
  41658. // Let's skip the whole header and dash to the data !
  41659. reader.skip(22); // in some zip created on windows, the filename stored in the central dir contains \ instead of /.
  41660. // Strangely, the filename here is OK.
  41661. // I would love to treat these zip files as corrupted (see http://www.info-zip.org/FAQ.html#backslashes
  41662. // or APPNOTE#4.4.17.1, "All slashes MUST be forward slashes '/'") but there are a lot of bad zip generators...
  41663. // Search "unzip mismatching "local" filename continuing with "central" filename version" on
  41664. // the internet.
  41665. //
  41666. // I think I see the logic here : the central directory is used to display
  41667. // content and the local directory is used to extract the files. Mixing / and \
  41668. // may be used to display \ to windows users and use / when extracting the files.
  41669. // Unfortunately, this lead also to some issues : http://seclists.org/fulldisclosure/2009/Sep/394
  41670. this.fileNameLength = reader.readInt(2);
  41671. localExtraFieldsLength = reader.readInt(2); // can't be sure this will be the same as the central dir
  41672. // the fileName is stored as binary data, the handleUTF8 method will take care of the encoding.
  41673. this.fileName = reader.readData(this.fileNameLength);
  41674. reader.skip(localExtraFieldsLength);
  41675. if (this.compressedSize === -1 || this.uncompressedSize === -1) {
  41676. throw new Error("Bug or corrupted zip : didn't get enough information from the central directory " + "(compressedSize === -1 || uncompressedSize === -1)");
  41677. }
  41678. compression = findCompression(this.compressionMethod);
  41679. if (compression === null) {
  41680. // no compression found
  41681. throw new Error("Corrupted zip : compression " + utils.pretty(this.compressionMethod) + " unknown (inner file : " + utils.transformTo("string", this.fileName) + ")");
  41682. }
  41683. this.decompressed = new CompressedObject(this.compressedSize, this.uncompressedSize, this.crc32, compression, reader.readData(this.compressedSize));
  41684. },
  41685. /**
  41686. * Read the central part of a zip file and add the info in this object.
  41687. * @param {DataReader} reader the reader to use.
  41688. */
  41689. readCentralPart: function readCentralPart(reader) {
  41690. this.versionMadeBy = reader.readInt(2);
  41691. reader.skip(2); // this.versionNeeded = reader.readInt(2);
  41692. this.bitFlag = reader.readInt(2);
  41693. this.compressionMethod = reader.readString(2);
  41694. this.date = reader.readDate();
  41695. this.crc32 = reader.readInt(4);
  41696. this.compressedSize = reader.readInt(4);
  41697. this.uncompressedSize = reader.readInt(4);
  41698. var fileNameLength = reader.readInt(2);
  41699. this.extraFieldsLength = reader.readInt(2);
  41700. this.fileCommentLength = reader.readInt(2);
  41701. this.diskNumberStart = reader.readInt(2);
  41702. this.internalFileAttributes = reader.readInt(2);
  41703. this.externalFileAttributes = reader.readInt(4);
  41704. this.localHeaderOffset = reader.readInt(4);
  41705. if (this.isEncrypted()) {
  41706. throw new Error("Encrypted zip are not supported");
  41707. } // will be read in the local part, see the comments there
  41708. reader.skip(fileNameLength);
  41709. this.readExtraFields(reader);
  41710. this.parseZIP64ExtraField(reader);
  41711. this.fileComment = reader.readData(this.fileCommentLength);
  41712. },
  41713. /**
  41714. * Parse the external file attributes and get the unix/dos permissions.
  41715. */
  41716. processAttributes: function processAttributes() {
  41717. this.unixPermissions = null;
  41718. this.dosPermissions = null;
  41719. var madeBy = this.versionMadeBy >> 8; // Check if we have the DOS directory flag set.
  41720. // We look for it in the DOS and UNIX permissions
  41721. // but some unknown platform could set it as a compatibility flag.
  41722. this.dir = this.externalFileAttributes & 0x0010 ? true : false;
  41723. if (madeBy === MADE_BY_DOS) {
  41724. // first 6 bits (0 to 5)
  41725. this.dosPermissions = this.externalFileAttributes & 0x3F;
  41726. }
  41727. if (madeBy === MADE_BY_UNIX) {
  41728. this.unixPermissions = this.externalFileAttributes >> 16 & 0xFFFF; // the octal permissions are in (this.unixPermissions & 0x01FF).toString(8);
  41729. } // fail safe : if the name ends with a / it probably means a folder
  41730. if (!this.dir && this.fileNameStr.slice(-1) === '/') {
  41731. this.dir = true;
  41732. }
  41733. },
  41734. /**
  41735. * Parse the ZIP64 extra field and merge the info in the current ZipEntry.
  41736. * @param {DataReader} reader the reader to use.
  41737. */
  41738. parseZIP64ExtraField: function parseZIP64ExtraField(reader) {
  41739. if (!this.extraFields[0x0001]) {
  41740. return;
  41741. } // should be something, preparing the extra reader
  41742. var extraReader = readerFor(this.extraFields[0x0001].value); // I really hope that these 64bits integer can fit in 32 bits integer, because js
  41743. // won't let us have more.
  41744. if (this.uncompressedSize === utils.MAX_VALUE_32BITS) {
  41745. this.uncompressedSize = extraReader.readInt(8);
  41746. }
  41747. if (this.compressedSize === utils.MAX_VALUE_32BITS) {
  41748. this.compressedSize = extraReader.readInt(8);
  41749. }
  41750. if (this.localHeaderOffset === utils.MAX_VALUE_32BITS) {
  41751. this.localHeaderOffset = extraReader.readInt(8);
  41752. }
  41753. if (this.diskNumberStart === utils.MAX_VALUE_32BITS) {
  41754. this.diskNumberStart = extraReader.readInt(4);
  41755. }
  41756. },
  41757. /**
  41758. * Read the central part of a zip file and add the info in this object.
  41759. * @param {DataReader} reader the reader to use.
  41760. */
  41761. readExtraFields: function readExtraFields(reader) {
  41762. var end = reader.index + this.extraFieldsLength,
  41763. extraFieldId,
  41764. extraFieldLength,
  41765. extraFieldValue;
  41766. if (!this.extraFields) {
  41767. this.extraFields = {};
  41768. }
  41769. while (reader.index + 4 < end) {
  41770. extraFieldId = reader.readInt(2);
  41771. extraFieldLength = reader.readInt(2);
  41772. extraFieldValue = reader.readData(extraFieldLength);
  41773. this.extraFields[extraFieldId] = {
  41774. id: extraFieldId,
  41775. length: extraFieldLength,
  41776. value: extraFieldValue
  41777. };
  41778. }
  41779. reader.setIndex(end);
  41780. },
  41781. /**
  41782. * Apply an UTF8 transformation if needed.
  41783. */
  41784. handleUTF8: function handleUTF8() {
  41785. var decodeParamType = support.uint8array ? "uint8array" : "array";
  41786. if (this.useUTF8()) {
  41787. this.fileNameStr = utf8.utf8decode(this.fileName);
  41788. this.fileCommentStr = utf8.utf8decode(this.fileComment);
  41789. } else {
  41790. var upath = this.findExtraFieldUnicodePath();
  41791. if (upath !== null) {
  41792. this.fileNameStr = upath;
  41793. } else {
  41794. // ASCII text or unsupported code page
  41795. var fileNameByteArray = utils.transformTo(decodeParamType, this.fileName);
  41796. this.fileNameStr = this.loadOptions.decodeFileName(fileNameByteArray);
  41797. }
  41798. var ucomment = this.findExtraFieldUnicodeComment();
  41799. if (ucomment !== null) {
  41800. this.fileCommentStr = ucomment;
  41801. } else {
  41802. // ASCII text or unsupported code page
  41803. var commentByteArray = utils.transformTo(decodeParamType, this.fileComment);
  41804. this.fileCommentStr = this.loadOptions.decodeFileName(commentByteArray);
  41805. }
  41806. }
  41807. },
  41808. /**
  41809. * Find the unicode path declared in the extra field, if any.
  41810. * @return {String} the unicode path, null otherwise.
  41811. */
  41812. findExtraFieldUnicodePath: function findExtraFieldUnicodePath() {
  41813. var upathField = this.extraFields[0x7075];
  41814. if (upathField) {
  41815. var extraReader = readerFor(upathField.value); // wrong version
  41816. if (extraReader.readInt(1) !== 1) {
  41817. return null;
  41818. } // the crc of the filename changed, this field is out of date.
  41819. if (crc32fn(this.fileName) !== extraReader.readInt(4)) {
  41820. return null;
  41821. }
  41822. return utf8.utf8decode(extraReader.readData(upathField.length - 5));
  41823. }
  41824. return null;
  41825. },
  41826. /**
  41827. * Find the unicode comment declared in the extra field, if any.
  41828. * @return {String} the unicode comment, null otherwise.
  41829. */
  41830. findExtraFieldUnicodeComment: function findExtraFieldUnicodeComment() {
  41831. var ucommentField = this.extraFields[0x6375];
  41832. if (ucommentField) {
  41833. var extraReader = readerFor(ucommentField.value); // wrong version
  41834. if (extraReader.readInt(1) !== 1) {
  41835. return null;
  41836. } // the crc of the comment changed, this field is out of date.
  41837. if (crc32fn(this.fileComment) !== extraReader.readInt(4)) {
  41838. return null;
  41839. }
  41840. return utf8.utf8decode(extraReader.readData(ucommentField.length - 5));
  41841. }
  41842. return null;
  41843. }
  41844. };
  41845. module.exports = ZipEntry;
  41846. },{"./compressedObject":282,"./compressions":283,"./crc32":284,"./reader/readerFor":302,"./support":310,"./utf8":311,"./utils":312}],315:[function(require,module,exports){
  41847. 'use strict';
  41848. var StreamHelper = require('./stream/StreamHelper');
  41849. var DataWorker = require('./stream/DataWorker');
  41850. var utf8 = require('./utf8');
  41851. var CompressedObject = require('./compressedObject');
  41852. var GenericWorker = require('./stream/GenericWorker');
  41853. /**
  41854. * A simple object representing a file in the zip file.
  41855. * @constructor
  41856. * @param {string} name the name of the file
  41857. * @param {String|ArrayBuffer|Uint8Array|Buffer} data the data
  41858. * @param {Object} options the options of the file
  41859. */
  41860. var ZipObject = function ZipObject(name, data, options) {
  41861. this.name = name;
  41862. this.dir = options.dir;
  41863. this.date = options.date;
  41864. this.comment = options.comment;
  41865. this.unixPermissions = options.unixPermissions;
  41866. this.dosPermissions = options.dosPermissions;
  41867. this._data = data;
  41868. this._dataBinary = options.binary; // keep only the compression
  41869. this.options = {
  41870. compression: options.compression,
  41871. compressionOptions: options.compressionOptions
  41872. };
  41873. };
  41874. ZipObject.prototype = {
  41875. /**
  41876. * Create an internal stream for the content of this object.
  41877. * @param {String} type the type of each chunk.
  41878. * @return StreamHelper the stream.
  41879. */
  41880. internalStream: function internalStream(type) {
  41881. var result = null,
  41882. outputType = "string";
  41883. try {
  41884. if (!type) {
  41885. throw new Error("No output type specified.");
  41886. }
  41887. outputType = type.toLowerCase();
  41888. var askUnicodeString = outputType === "string" || outputType === "text";
  41889. if (outputType === "binarystring" || outputType === "text") {
  41890. outputType = "string";
  41891. }
  41892. result = this._decompressWorker();
  41893. var isUnicodeString = !this._dataBinary;
  41894. if (isUnicodeString && !askUnicodeString) {
  41895. result = result.pipe(new utf8.Utf8EncodeWorker());
  41896. }
  41897. if (!isUnicodeString && askUnicodeString) {
  41898. result = result.pipe(new utf8.Utf8DecodeWorker());
  41899. }
  41900. } catch (e) {
  41901. result = new GenericWorker("error");
  41902. result.error(e);
  41903. }
  41904. return new StreamHelper(result, outputType, "");
  41905. },
  41906. /**
  41907. * Prepare the content in the asked type.
  41908. * @param {String} type the type of the result.
  41909. * @param {Function} onUpdate a function to call on each internal update.
  41910. * @return Promise the promise of the result.
  41911. */
  41912. async: function async(type, onUpdate) {
  41913. return this.internalStream(type).accumulate(onUpdate);
  41914. },
  41915. /**
  41916. * Prepare the content as a nodejs stream.
  41917. * @param {String} type the type of each chunk.
  41918. * @param {Function} onUpdate a function to call on each internal update.
  41919. * @return Stream the stream.
  41920. */
  41921. nodeStream: function nodeStream(type, onUpdate) {
  41922. return this.internalStream(type || "nodebuffer").toNodejsStream(onUpdate);
  41923. },
  41924. /**
  41925. * Return a worker for the compressed content.
  41926. * @private
  41927. * @param {Object} compression the compression object to use.
  41928. * @param {Object} compressionOptions the options to use when compressing.
  41929. * @return Worker the worker.
  41930. */
  41931. _compressWorker: function _compressWorker(compression, compressionOptions) {
  41932. if (this._data instanceof CompressedObject && this._data.compression.magic === compression.magic) {
  41933. return this._data.getCompressedWorker();
  41934. } else {
  41935. var result = this._decompressWorker();
  41936. if (!this._dataBinary) {
  41937. result = result.pipe(new utf8.Utf8EncodeWorker());
  41938. }
  41939. return CompressedObject.createWorkerFrom(result, compression, compressionOptions);
  41940. }
  41941. },
  41942. /**
  41943. * Return a worker for the decompressed content.
  41944. * @private
  41945. * @return Worker the worker.
  41946. */
  41947. _decompressWorker: function _decompressWorker() {
  41948. if (this._data instanceof CompressedObject) {
  41949. return this._data.getContentWorker();
  41950. } else if (this._data instanceof GenericWorker) {
  41951. return this._data;
  41952. } else {
  41953. return new DataWorker(this._data);
  41954. }
  41955. }
  41956. };
  41957. var removedMethods = ["asText", "asBinary", "asNodeBuffer", "asUint8Array", "asArrayBuffer"];
  41958. var removedFn = function removedFn() {
  41959. throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.");
  41960. };
  41961. for (var i = 0; i < removedMethods.length; i++) {
  41962. ZipObject.prototype[removedMethods[i]] = removedFn;
  41963. }
  41964. module.exports = ZipObject;
  41965. },{"./compressedObject":282,"./stream/DataWorker":307,"./stream/GenericWorker":308,"./stream/StreamHelper":309,"./utf8":311}],316:[function(require,module,exports){
  41966. 'use strict';
  41967. 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); }
  41968. var immediate = require('immediate');
  41969. /* istanbul ignore next */
  41970. function INTERNAL() {}
  41971. var handlers = {};
  41972. var REJECTED = ['REJECTED'];
  41973. var FULFILLED = ['FULFILLED'];
  41974. var PENDING = ['PENDING'];
  41975. module.exports = Promise;
  41976. function Promise(resolver) {
  41977. if (typeof resolver !== 'function') {
  41978. throw new TypeError('resolver must be a function');
  41979. }
  41980. this.state = PENDING;
  41981. this.queue = [];
  41982. this.outcome = void 0;
  41983. if (resolver !== INTERNAL) {
  41984. safelyResolveThenable(this, resolver);
  41985. }
  41986. }
  41987. Promise.prototype["finally"] = function (callback) {
  41988. if (typeof callback !== 'function') {
  41989. return this;
  41990. }
  41991. var p = this.constructor;
  41992. return this.then(resolve, reject);
  41993. function resolve(value) {
  41994. function yes() {
  41995. return value;
  41996. }
  41997. return p.resolve(callback()).then(yes);
  41998. }
  41999. function reject(reason) {
  42000. function no() {
  42001. throw reason;
  42002. }
  42003. return p.resolve(callback()).then(no);
  42004. }
  42005. };
  42006. Promise.prototype["catch"] = function (onRejected) {
  42007. return this.then(null, onRejected);
  42008. };
  42009. Promise.prototype.then = function (onFulfilled, onRejected) {
  42010. if (typeof onFulfilled !== 'function' && this.state === FULFILLED || typeof onRejected !== 'function' && this.state === REJECTED) {
  42011. return this;
  42012. }
  42013. var promise = new this.constructor(INTERNAL);
  42014. if (this.state !== PENDING) {
  42015. var resolver = this.state === FULFILLED ? onFulfilled : onRejected;
  42016. unwrap(promise, resolver, this.outcome);
  42017. } else {
  42018. this.queue.push(new QueueItem(promise, onFulfilled, onRejected));
  42019. }
  42020. return promise;
  42021. };
  42022. function QueueItem(promise, onFulfilled, onRejected) {
  42023. this.promise = promise;
  42024. if (typeof onFulfilled === 'function') {
  42025. this.onFulfilled = onFulfilled;
  42026. this.callFulfilled = this.otherCallFulfilled;
  42027. }
  42028. if (typeof onRejected === 'function') {
  42029. this.onRejected = onRejected;
  42030. this.callRejected = this.otherCallRejected;
  42031. }
  42032. }
  42033. QueueItem.prototype.callFulfilled = function (value) {
  42034. handlers.resolve(this.promise, value);
  42035. };
  42036. QueueItem.prototype.otherCallFulfilled = function (value) {
  42037. unwrap(this.promise, this.onFulfilled, value);
  42038. };
  42039. QueueItem.prototype.callRejected = function (value) {
  42040. handlers.reject(this.promise, value);
  42041. };
  42042. QueueItem.prototype.otherCallRejected = function (value) {
  42043. unwrap(this.promise, this.onRejected, value);
  42044. };
  42045. function unwrap(promise, func, value) {
  42046. immediate(function () {
  42047. var returnValue;
  42048. try {
  42049. returnValue = func(value);
  42050. } catch (e) {
  42051. return handlers.reject(promise, e);
  42052. }
  42053. if (returnValue === promise) {
  42054. handlers.reject(promise, new TypeError('Cannot resolve promise with itself'));
  42055. } else {
  42056. handlers.resolve(promise, returnValue);
  42057. }
  42058. });
  42059. }
  42060. handlers.resolve = function (self, value) {
  42061. var result = tryCatch(getThen, value);
  42062. if (result.status === 'error') {
  42063. return handlers.reject(self, result.value);
  42064. }
  42065. var thenable = result.value;
  42066. if (thenable) {
  42067. safelyResolveThenable(self, thenable);
  42068. } else {
  42069. self.state = FULFILLED;
  42070. self.outcome = value;
  42071. var i = -1;
  42072. var len = self.queue.length;
  42073. while (++i < len) {
  42074. self.queue[i].callFulfilled(value);
  42075. }
  42076. }
  42077. return self;
  42078. };
  42079. handlers.reject = function (self, error) {
  42080. self.state = REJECTED;
  42081. self.outcome = error;
  42082. var i = -1;
  42083. var len = self.queue.length;
  42084. while (++i < len) {
  42085. self.queue[i].callRejected(error);
  42086. }
  42087. return self;
  42088. };
  42089. function getThen(obj) {
  42090. // Make sure we only access the accessor once as required by the spec
  42091. var then = obj && obj.then;
  42092. if (obj && (_typeof(obj) === 'object' || typeof obj === 'function') && typeof then === 'function') {
  42093. return function appyThen() {
  42094. then.apply(obj, arguments);
  42095. };
  42096. }
  42097. }
  42098. function safelyResolveThenable(self, thenable) {
  42099. // Either fulfill, reject or reject with error
  42100. var called = false;
  42101. function onError(value) {
  42102. if (called) {
  42103. return;
  42104. }
  42105. called = true;
  42106. handlers.reject(self, value);
  42107. }
  42108. function onSuccess(value) {
  42109. if (called) {
  42110. return;
  42111. }
  42112. called = true;
  42113. handlers.resolve(self, value);
  42114. }
  42115. function tryToUnwrap() {
  42116. thenable(onSuccess, onError);
  42117. }
  42118. var result = tryCatch(tryToUnwrap);
  42119. if (result.status === 'error') {
  42120. onError(result.value);
  42121. }
  42122. }
  42123. function tryCatch(func, value) {
  42124. var out = {};
  42125. try {
  42126. out.value = func(value);
  42127. out.status = 'success';
  42128. } catch (e) {
  42129. out.status = 'error';
  42130. out.value = e;
  42131. }
  42132. return out;
  42133. }
  42134. Promise.resolve = resolve;
  42135. function resolve(value) {
  42136. if (value instanceof this) {
  42137. return value;
  42138. }
  42139. return handlers.resolve(new this(INTERNAL), value);
  42140. }
  42141. Promise.reject = reject;
  42142. function reject(reason) {
  42143. var promise = new this(INTERNAL);
  42144. return handlers.reject(promise, reason);
  42145. }
  42146. Promise.all = all;
  42147. function all(iterable) {
  42148. var self = this;
  42149. if (Object.prototype.toString.call(iterable) !== '[object Array]') {
  42150. return this.reject(new TypeError('must be an array'));
  42151. }
  42152. var len = iterable.length;
  42153. var called = false;
  42154. if (!len) {
  42155. return this.resolve([]);
  42156. }
  42157. var values = new Array(len);
  42158. var resolved = 0;
  42159. var i = -1;
  42160. var promise = new this(INTERNAL);
  42161. while (++i < len) {
  42162. allResolver(iterable[i], i);
  42163. }
  42164. return promise;
  42165. function allResolver(value, i) {
  42166. self.resolve(value).then(resolveFromAll, function (error) {
  42167. if (!called) {
  42168. called = true;
  42169. handlers.reject(promise, error);
  42170. }
  42171. });
  42172. function resolveFromAll(outValue) {
  42173. values[i] = outValue;
  42174. if (++resolved === len && !called) {
  42175. called = true;
  42176. handlers.resolve(promise, values);
  42177. }
  42178. }
  42179. }
  42180. }
  42181. Promise.race = race;
  42182. function race(iterable) {
  42183. var self = this;
  42184. if (Object.prototype.toString.call(iterable) !== '[object Array]') {
  42185. return this.reject(new TypeError('must be an array'));
  42186. }
  42187. var len = iterable.length;
  42188. var called = false;
  42189. if (!len) {
  42190. return this.resolve([]);
  42191. }
  42192. var i = -1;
  42193. var promise = new this(INTERNAL);
  42194. while (++i < len) {
  42195. resolver(iterable[i]);
  42196. }
  42197. return promise;
  42198. function resolver(value) {
  42199. self.resolve(value).then(function (response) {
  42200. if (!called) {
  42201. called = true;
  42202. handlers.resolve(promise, response);
  42203. }
  42204. }, function (error) {
  42205. if (!called) {
  42206. called = true;
  42207. handlers.reject(promise, error);
  42208. }
  42209. });
  42210. }
  42211. }
  42212. },{"immediate":277}],317:[function(require,module,exports){
  42213. (function (global){
  42214. "use strict";
  42215. 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); }
  42216. /**
  42217. * lodash (Custom Build) <https://lodash.com/>
  42218. * Build: `lodash modularize exports="npm" -o ./`
  42219. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  42220. * Released under MIT license <https://lodash.com/license>
  42221. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  42222. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  42223. */
  42224. /** Used as references for various `Number` constants. */
  42225. var INFINITY = 1 / 0;
  42226. /** `Object#toString` result references. */
  42227. var symbolTag = '[object Symbol]';
  42228. /**
  42229. * Used to match `RegExp`
  42230. * [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns).
  42231. */
  42232. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  42233. reHasRegExpChar = RegExp(reRegExpChar.source);
  42234. /** Detect free variable `global` from Node.js. */
  42235. var freeGlobal = (typeof global === "undefined" ? "undefined" : _typeof(global)) == 'object' && global && global.Object === Object && global;
  42236. /** Detect free variable `self`. */
  42237. var freeSelf = (typeof self === "undefined" ? "undefined" : _typeof(self)) == 'object' && self && self.Object === Object && self;
  42238. /** Used as a reference to the global object. */
  42239. var root = freeGlobal || freeSelf || Function('return this')();
  42240. /** Used for built-in method references. */
  42241. var objectProto = Object.prototype;
  42242. /**
  42243. * Used to resolve the
  42244. * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  42245. * of values.
  42246. */
  42247. var objectToString = objectProto.toString;
  42248. /** Built-in value references. */
  42249. var _Symbol = root.Symbol;
  42250. /** Used to convert symbols to primitives and strings. */
  42251. var symbolProto = _Symbol ? _Symbol.prototype : undefined,
  42252. symbolToString = symbolProto ? symbolProto.toString : undefined;
  42253. /**
  42254. * The base implementation of `_.toString` which doesn't convert nullish
  42255. * values to empty strings.
  42256. *
  42257. * @private
  42258. * @param {*} value The value to process.
  42259. * @returns {string} Returns the string.
  42260. */
  42261. function baseToString(value) {
  42262. // Exit early for strings to avoid a performance hit in some environments.
  42263. if (typeof value == 'string') {
  42264. return value;
  42265. }
  42266. if (isSymbol(value)) {
  42267. return symbolToString ? symbolToString.call(value) : '';
  42268. }
  42269. var result = value + '';
  42270. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  42271. }
  42272. /**
  42273. * Checks if `value` is object-like. A value is object-like if it's not `null`
  42274. * and has a `typeof` result of "object".
  42275. *
  42276. * @static
  42277. * @memberOf _
  42278. * @since 4.0.0
  42279. * @category Lang
  42280. * @param {*} value The value to check.
  42281. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  42282. * @example
  42283. *
  42284. * _.isObjectLike({});
  42285. * // => true
  42286. *
  42287. * _.isObjectLike([1, 2, 3]);
  42288. * // => true
  42289. *
  42290. * _.isObjectLike(_.noop);
  42291. * // => false
  42292. *
  42293. * _.isObjectLike(null);
  42294. * // => false
  42295. */
  42296. function isObjectLike(value) {
  42297. return !!value && _typeof(value) == 'object';
  42298. }
  42299. /**
  42300. * Checks if `value` is classified as a `Symbol` primitive or object.
  42301. *
  42302. * @static
  42303. * @memberOf _
  42304. * @since 4.0.0
  42305. * @category Lang
  42306. * @param {*} value The value to check.
  42307. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  42308. * @example
  42309. *
  42310. * _.isSymbol(Symbol.iterator);
  42311. * // => true
  42312. *
  42313. * _.isSymbol('abc');
  42314. * // => false
  42315. */
  42316. function isSymbol(value) {
  42317. return _typeof(value) == 'symbol' || isObjectLike(value) && objectToString.call(value) == symbolTag;
  42318. }
  42319. /**
  42320. * Converts `value` to a string. An empty string is returned for `null`
  42321. * and `undefined` values. The sign of `-0` is preserved.
  42322. *
  42323. * @static
  42324. * @memberOf _
  42325. * @since 4.0.0
  42326. * @category Lang
  42327. * @param {*} value The value to process.
  42328. * @returns {string} Returns the string.
  42329. * @example
  42330. *
  42331. * _.toString(null);
  42332. * // => ''
  42333. *
  42334. * _.toString(-0);
  42335. * // => '-0'
  42336. *
  42337. * _.toString([1, 2, 3]);
  42338. * // => '1,2,3'
  42339. */
  42340. function toString(value) {
  42341. return value == null ? '' : baseToString(value);
  42342. }
  42343. /**
  42344. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  42345. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  42346. *
  42347. * @static
  42348. * @memberOf _
  42349. * @since 3.0.0
  42350. * @category String
  42351. * @param {string} [string=''] The string to escape.
  42352. * @returns {string} Returns the escaped string.
  42353. * @example
  42354. *
  42355. * _.escapeRegExp('[lodash](https://lodash.com/)');
  42356. * // => '\[lodash\]\(https://lodash\.com/\)'
  42357. */
  42358. function escapeRegExp(string) {
  42359. string = toString(string);
  42360. return string && reHasRegExpChar.test(string) ? string.replace(reRegExpChar, '\\$&') : string;
  42361. }
  42362. module.exports = escapeRegExp;
  42363. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  42364. },{}],318:[function(require,module,exports){
  42365. (function (global){
  42366. "use strict";
  42367. 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); }
  42368. /**
  42369. * lodash (Custom Build) <https://lodash.com/>
  42370. * Build: `lodash modularize exports="npm" -o ./`
  42371. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  42372. * Released under MIT license <https://lodash.com/license>
  42373. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  42374. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  42375. */
  42376. /** Used as the size to enable large array optimizations. */
  42377. var LARGE_ARRAY_SIZE = 200;
  42378. /** Used as the `TypeError` message for "Functions" methods. */
  42379. var FUNC_ERROR_TEXT = 'Expected a function';
  42380. /** Used to stand-in for `undefined` hash values. */
  42381. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  42382. /** Used to compose bitmasks for comparison styles. */
  42383. var UNORDERED_COMPARE_FLAG = 1,
  42384. PARTIAL_COMPARE_FLAG = 2;
  42385. /** Used as references for various `Number` constants. */
  42386. var INFINITY = 1 / 0,
  42387. MAX_SAFE_INTEGER = 9007199254740991;
  42388. /** `Object#toString` result references. */
  42389. var argsTag = '[object Arguments]',
  42390. arrayTag = '[object Array]',
  42391. boolTag = '[object Boolean]',
  42392. dateTag = '[object Date]',
  42393. errorTag = '[object Error]',
  42394. funcTag = '[object Function]',
  42395. genTag = '[object GeneratorFunction]',
  42396. mapTag = '[object Map]',
  42397. numberTag = '[object Number]',
  42398. objectTag = '[object Object]',
  42399. promiseTag = '[object Promise]',
  42400. regexpTag = '[object RegExp]',
  42401. setTag = '[object Set]',
  42402. stringTag = '[object String]',
  42403. symbolTag = '[object Symbol]',
  42404. weakMapTag = '[object WeakMap]';
  42405. var arrayBufferTag = '[object ArrayBuffer]',
  42406. dataViewTag = '[object DataView]',
  42407. float32Tag = '[object Float32Array]',
  42408. float64Tag = '[object Float64Array]',
  42409. int8Tag = '[object Int8Array]',
  42410. int16Tag = '[object Int16Array]',
  42411. int32Tag = '[object Int32Array]',
  42412. uint8Tag = '[object Uint8Array]',
  42413. uint8ClampedTag = '[object Uint8ClampedArray]',
  42414. uint16Tag = '[object Uint16Array]',
  42415. uint32Tag = '[object Uint32Array]';
  42416. /** Used to match property names within property paths. */
  42417. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  42418. reIsPlainProp = /^\w*$/,
  42419. reLeadingDot = /^\./,
  42420. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  42421. /**
  42422. * Used to match `RegExp`
  42423. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  42424. */
  42425. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  42426. /** Used to match backslashes in property paths. */
  42427. var reEscapeChar = /\\(\\)?/g;
  42428. /** Used to detect host constructors (Safari). */
  42429. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  42430. /** Used to detect unsigned integer values. */
  42431. var reIsUint = /^(?:0|[1-9]\d*)$/;
  42432. /** Used to identify `toStringTag` values of typed arrays. */
  42433. var typedArrayTags = {};
  42434. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = typedArrayTags[uint32Tag] = true;
  42435. 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;
  42436. /** Detect free variable `global` from Node.js. */
  42437. var freeGlobal = (typeof global === "undefined" ? "undefined" : _typeof(global)) == 'object' && global && global.Object === Object && global;
  42438. /** Detect free variable `self`. */
  42439. var freeSelf = (typeof self === "undefined" ? "undefined" : _typeof(self)) == 'object' && self && self.Object === Object && self;
  42440. /** Used as a reference to the global object. */
  42441. var root = freeGlobal || freeSelf || Function('return this')();
  42442. /** Detect free variable `exports`. */
  42443. var freeExports = (typeof exports === "undefined" ? "undefined" : _typeof(exports)) == 'object' && exports && !exports.nodeType && exports;
  42444. /** Detect free variable `module`. */
  42445. var freeModule = freeExports && (typeof module === "undefined" ? "undefined" : _typeof(module)) == 'object' && module && !module.nodeType && module;
  42446. /** Detect the popular CommonJS extension `module.exports`. */
  42447. var moduleExports = freeModule && freeModule.exports === freeExports;
  42448. /** Detect free variable `process` from Node.js. */
  42449. var freeProcess = moduleExports && freeGlobal.process;
  42450. /** Used to access faster Node.js helpers. */
  42451. var nodeUtil = function () {
  42452. try {
  42453. return freeProcess && freeProcess.binding('util');
  42454. } catch (e) {}
  42455. }();
  42456. /* Node.js helper references. */
  42457. var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  42458. /**
  42459. * A specialized version of `baseAggregator` for arrays.
  42460. *
  42461. * @private
  42462. * @param {Array} [array] The array to iterate over.
  42463. * @param {Function} setter The function to set `accumulator` values.
  42464. * @param {Function} iteratee The iteratee to transform keys.
  42465. * @param {Object} accumulator The initial aggregated object.
  42466. * @returns {Function} Returns `accumulator`.
  42467. */
  42468. function arrayAggregator(array, setter, iteratee, accumulator) {
  42469. var index = -1,
  42470. length = array ? array.length : 0;
  42471. while (++index < length) {
  42472. var value = array[index];
  42473. setter(accumulator, value, iteratee(value), array);
  42474. }
  42475. return accumulator;
  42476. }
  42477. /**
  42478. * A specialized version of `_.some` for arrays without support for iteratee
  42479. * shorthands.
  42480. *
  42481. * @private
  42482. * @param {Array} [array] The array to iterate over.
  42483. * @param {Function} predicate The function invoked per iteration.
  42484. * @returns {boolean} Returns `true` if any element passes the predicate check,
  42485. * else `false`.
  42486. */
  42487. function arraySome(array, predicate) {
  42488. var index = -1,
  42489. length = array ? array.length : 0;
  42490. while (++index < length) {
  42491. if (predicate(array[index], index, array)) {
  42492. return true;
  42493. }
  42494. }
  42495. return false;
  42496. }
  42497. /**
  42498. * The base implementation of `_.property` without support for deep paths.
  42499. *
  42500. * @private
  42501. * @param {string} key The key of the property to get.
  42502. * @returns {Function} Returns the new accessor function.
  42503. */
  42504. function baseProperty(key) {
  42505. return function (object) {
  42506. return object == null ? undefined : object[key];
  42507. };
  42508. }
  42509. /**
  42510. * The base implementation of `_.times` without support for iteratee shorthands
  42511. * or max array length checks.
  42512. *
  42513. * @private
  42514. * @param {number} n The number of times to invoke `iteratee`.
  42515. * @param {Function} iteratee The function invoked per iteration.
  42516. * @returns {Array} Returns the array of results.
  42517. */
  42518. function baseTimes(n, iteratee) {
  42519. var index = -1,
  42520. result = Array(n);
  42521. while (++index < n) {
  42522. result[index] = iteratee(index);
  42523. }
  42524. return result;
  42525. }
  42526. /**
  42527. * The base implementation of `_.unary` without support for storing metadata.
  42528. *
  42529. * @private
  42530. * @param {Function} func The function to cap arguments for.
  42531. * @returns {Function} Returns the new capped function.
  42532. */
  42533. function baseUnary(func) {
  42534. return function (value) {
  42535. return func(value);
  42536. };
  42537. }
  42538. /**
  42539. * Gets the value at `key` of `object`.
  42540. *
  42541. * @private
  42542. * @param {Object} [object] The object to query.
  42543. * @param {string} key The key of the property to get.
  42544. * @returns {*} Returns the property value.
  42545. */
  42546. function getValue(object, key) {
  42547. return object == null ? undefined : object[key];
  42548. }
  42549. /**
  42550. * Checks if `value` is a host object in IE < 9.
  42551. *
  42552. * @private
  42553. * @param {*} value The value to check.
  42554. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  42555. */
  42556. function isHostObject(value) {
  42557. // Many host objects are `Object` objects that can coerce to strings
  42558. // despite having improperly defined `toString` methods.
  42559. var result = false;
  42560. if (value != null && typeof value.toString != 'function') {
  42561. try {
  42562. result = !!(value + '');
  42563. } catch (e) {}
  42564. }
  42565. return result;
  42566. }
  42567. /**
  42568. * Converts `map` to its key-value pairs.
  42569. *
  42570. * @private
  42571. * @param {Object} map The map to convert.
  42572. * @returns {Array} Returns the key-value pairs.
  42573. */
  42574. function mapToArray(map) {
  42575. var index = -1,
  42576. result = Array(map.size);
  42577. map.forEach(function (value, key) {
  42578. result[++index] = [key, value];
  42579. });
  42580. return result;
  42581. }
  42582. /**
  42583. * Creates a unary function that invokes `func` with its argument transformed.
  42584. *
  42585. * @private
  42586. * @param {Function} func The function to wrap.
  42587. * @param {Function} transform The argument transform.
  42588. * @returns {Function} Returns the new function.
  42589. */
  42590. function overArg(func, transform) {
  42591. return function (arg) {
  42592. return func(transform(arg));
  42593. };
  42594. }
  42595. /**
  42596. * Converts `set` to an array of its values.
  42597. *
  42598. * @private
  42599. * @param {Object} set The set to convert.
  42600. * @returns {Array} Returns the values.
  42601. */
  42602. function setToArray(set) {
  42603. var index = -1,
  42604. result = Array(set.size);
  42605. set.forEach(function (value) {
  42606. result[++index] = value;
  42607. });
  42608. return result;
  42609. }
  42610. /** Used for built-in method references. */
  42611. var arrayProto = Array.prototype,
  42612. funcProto = Function.prototype,
  42613. objectProto = Object.prototype;
  42614. /** Used to detect overreaching core-js shims. */
  42615. var coreJsData = root['__core-js_shared__'];
  42616. /** Used to detect methods masquerading as native. */
  42617. var maskSrcKey = function () {
  42618. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  42619. return uid ? 'Symbol(src)_1.' + uid : '';
  42620. }();
  42621. /** Used to resolve the decompiled source of functions. */
  42622. var funcToString = funcProto.toString;
  42623. /** Used to check objects for own properties. */
  42624. var hasOwnProperty = objectProto.hasOwnProperty;
  42625. /**
  42626. * Used to resolve the
  42627. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  42628. * of values.
  42629. */
  42630. var objectToString = objectProto.toString;
  42631. /** Used to detect if a method is native. */
  42632. var reIsNative = RegExp('^' + funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
  42633. /** Built-in value references. */
  42634. var _Symbol = root.Symbol,
  42635. Uint8Array = root.Uint8Array,
  42636. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  42637. splice = arrayProto.splice;
  42638. /* Built-in method references for those with the same name as other `lodash` methods. */
  42639. var nativeKeys = overArg(Object.keys, Object);
  42640. /* Built-in method references that are verified to be native. */
  42641. var DataView = getNative(root, 'DataView'),
  42642. Map = getNative(root, 'Map'),
  42643. Promise = getNative(root, 'Promise'),
  42644. Set = getNative(root, 'Set'),
  42645. WeakMap = getNative(root, 'WeakMap'),
  42646. nativeCreate = getNative(Object, 'create');
  42647. /** Used to detect maps, sets, and weakmaps. */
  42648. var dataViewCtorString = toSource(DataView),
  42649. mapCtorString = toSource(Map),
  42650. promiseCtorString = toSource(Promise),
  42651. setCtorString = toSource(Set),
  42652. weakMapCtorString = toSource(WeakMap);
  42653. /** Used to convert symbols to primitives and strings. */
  42654. var symbolProto = _Symbol ? _Symbol.prototype : undefined,
  42655. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  42656. symbolToString = symbolProto ? symbolProto.toString : undefined;
  42657. /**
  42658. * Creates a hash object.
  42659. *
  42660. * @private
  42661. * @constructor
  42662. * @param {Array} [entries] The key-value pairs to cache.
  42663. */
  42664. function Hash(entries) {
  42665. var index = -1,
  42666. length = entries ? entries.length : 0;
  42667. this.clear();
  42668. while (++index < length) {
  42669. var entry = entries[index];
  42670. this.set(entry[0], entry[1]);
  42671. }
  42672. }
  42673. /**
  42674. * Removes all key-value entries from the hash.
  42675. *
  42676. * @private
  42677. * @name clear
  42678. * @memberOf Hash
  42679. */
  42680. function hashClear() {
  42681. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  42682. }
  42683. /**
  42684. * Removes `key` and its value from the hash.
  42685. *
  42686. * @private
  42687. * @name delete
  42688. * @memberOf Hash
  42689. * @param {Object} hash The hash to modify.
  42690. * @param {string} key The key of the value to remove.
  42691. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  42692. */
  42693. function hashDelete(key) {
  42694. return this.has(key) && delete this.__data__[key];
  42695. }
  42696. /**
  42697. * Gets the hash value for `key`.
  42698. *
  42699. * @private
  42700. * @name get
  42701. * @memberOf Hash
  42702. * @param {string} key The key of the value to get.
  42703. * @returns {*} Returns the entry value.
  42704. */
  42705. function hashGet(key) {
  42706. var data = this.__data__;
  42707. if (nativeCreate) {
  42708. var result = data[key];
  42709. return result === HASH_UNDEFINED ? undefined : result;
  42710. }
  42711. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  42712. }
  42713. /**
  42714. * Checks if a hash value for `key` exists.
  42715. *
  42716. * @private
  42717. * @name has
  42718. * @memberOf Hash
  42719. * @param {string} key The key of the entry to check.
  42720. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  42721. */
  42722. function hashHas(key) {
  42723. var data = this.__data__;
  42724. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  42725. }
  42726. /**
  42727. * Sets the hash `key` to `value`.
  42728. *
  42729. * @private
  42730. * @name set
  42731. * @memberOf Hash
  42732. * @param {string} key The key of the value to set.
  42733. * @param {*} value The value to set.
  42734. * @returns {Object} Returns the hash instance.
  42735. */
  42736. function hashSet(key, value) {
  42737. var data = this.__data__;
  42738. data[key] = nativeCreate && value === undefined ? HASH_UNDEFINED : value;
  42739. return this;
  42740. } // Add methods to `Hash`.
  42741. Hash.prototype.clear = hashClear;
  42742. Hash.prototype['delete'] = hashDelete;
  42743. Hash.prototype.get = hashGet;
  42744. Hash.prototype.has = hashHas;
  42745. Hash.prototype.set = hashSet;
  42746. /**
  42747. * Creates an list cache object.
  42748. *
  42749. * @private
  42750. * @constructor
  42751. * @param {Array} [entries] The key-value pairs to cache.
  42752. */
  42753. function ListCache(entries) {
  42754. var index = -1,
  42755. length = entries ? entries.length : 0;
  42756. this.clear();
  42757. while (++index < length) {
  42758. var entry = entries[index];
  42759. this.set(entry[0], entry[1]);
  42760. }
  42761. }
  42762. /**
  42763. * Removes all key-value entries from the list cache.
  42764. *
  42765. * @private
  42766. * @name clear
  42767. * @memberOf ListCache
  42768. */
  42769. function listCacheClear() {
  42770. this.__data__ = [];
  42771. }
  42772. /**
  42773. * Removes `key` and its value from the list cache.
  42774. *
  42775. * @private
  42776. * @name delete
  42777. * @memberOf ListCache
  42778. * @param {string} key The key of the value to remove.
  42779. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  42780. */
  42781. function listCacheDelete(key) {
  42782. var data = this.__data__,
  42783. index = assocIndexOf(data, key);
  42784. if (index < 0) {
  42785. return false;
  42786. }
  42787. var lastIndex = data.length - 1;
  42788. if (index == lastIndex) {
  42789. data.pop();
  42790. } else {
  42791. splice.call(data, index, 1);
  42792. }
  42793. return true;
  42794. }
  42795. /**
  42796. * Gets the list cache value for `key`.
  42797. *
  42798. * @private
  42799. * @name get
  42800. * @memberOf ListCache
  42801. * @param {string} key The key of the value to get.
  42802. * @returns {*} Returns the entry value.
  42803. */
  42804. function listCacheGet(key) {
  42805. var data = this.__data__,
  42806. index = assocIndexOf(data, key);
  42807. return index < 0 ? undefined : data[index][1];
  42808. }
  42809. /**
  42810. * Checks if a list cache value for `key` exists.
  42811. *
  42812. * @private
  42813. * @name has
  42814. * @memberOf ListCache
  42815. * @param {string} key The key of the entry to check.
  42816. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  42817. */
  42818. function listCacheHas(key) {
  42819. return assocIndexOf(this.__data__, key) > -1;
  42820. }
  42821. /**
  42822. * Sets the list cache `key` to `value`.
  42823. *
  42824. * @private
  42825. * @name set
  42826. * @memberOf ListCache
  42827. * @param {string} key The key of the value to set.
  42828. * @param {*} value The value to set.
  42829. * @returns {Object} Returns the list cache instance.
  42830. */
  42831. function listCacheSet(key, value) {
  42832. var data = this.__data__,
  42833. index = assocIndexOf(data, key);
  42834. if (index < 0) {
  42835. data.push([key, value]);
  42836. } else {
  42837. data[index][1] = value;
  42838. }
  42839. return this;
  42840. } // Add methods to `ListCache`.
  42841. ListCache.prototype.clear = listCacheClear;
  42842. ListCache.prototype['delete'] = listCacheDelete;
  42843. ListCache.prototype.get = listCacheGet;
  42844. ListCache.prototype.has = listCacheHas;
  42845. ListCache.prototype.set = listCacheSet;
  42846. /**
  42847. * Creates a map cache object to store key-value pairs.
  42848. *
  42849. * @private
  42850. * @constructor
  42851. * @param {Array} [entries] The key-value pairs to cache.
  42852. */
  42853. function MapCache(entries) {
  42854. var index = -1,
  42855. length = entries ? entries.length : 0;
  42856. this.clear();
  42857. while (++index < length) {
  42858. var entry = entries[index];
  42859. this.set(entry[0], entry[1]);
  42860. }
  42861. }
  42862. /**
  42863. * Removes all key-value entries from the map.
  42864. *
  42865. * @private
  42866. * @name clear
  42867. * @memberOf MapCache
  42868. */
  42869. function mapCacheClear() {
  42870. this.__data__ = {
  42871. 'hash': new Hash(),
  42872. 'map': new (Map || ListCache)(),
  42873. 'string': new Hash()
  42874. };
  42875. }
  42876. /**
  42877. * Removes `key` and its value from the map.
  42878. *
  42879. * @private
  42880. * @name delete
  42881. * @memberOf MapCache
  42882. * @param {string} key The key of the value to remove.
  42883. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  42884. */
  42885. function mapCacheDelete(key) {
  42886. return getMapData(this, key)['delete'](key);
  42887. }
  42888. /**
  42889. * Gets the map value for `key`.
  42890. *
  42891. * @private
  42892. * @name get
  42893. * @memberOf MapCache
  42894. * @param {string} key The key of the value to get.
  42895. * @returns {*} Returns the entry value.
  42896. */
  42897. function mapCacheGet(key) {
  42898. return getMapData(this, key).get(key);
  42899. }
  42900. /**
  42901. * Checks if a map value for `key` exists.
  42902. *
  42903. * @private
  42904. * @name has
  42905. * @memberOf MapCache
  42906. * @param {string} key The key of the entry to check.
  42907. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  42908. */
  42909. function mapCacheHas(key) {
  42910. return getMapData(this, key).has(key);
  42911. }
  42912. /**
  42913. * Sets the map `key` to `value`.
  42914. *
  42915. * @private
  42916. * @name set
  42917. * @memberOf MapCache
  42918. * @param {string} key The key of the value to set.
  42919. * @param {*} value The value to set.
  42920. * @returns {Object} Returns the map cache instance.
  42921. */
  42922. function mapCacheSet(key, value) {
  42923. getMapData(this, key).set(key, value);
  42924. return this;
  42925. } // Add methods to `MapCache`.
  42926. MapCache.prototype.clear = mapCacheClear;
  42927. MapCache.prototype['delete'] = mapCacheDelete;
  42928. MapCache.prototype.get = mapCacheGet;
  42929. MapCache.prototype.has = mapCacheHas;
  42930. MapCache.prototype.set = mapCacheSet;
  42931. /**
  42932. *
  42933. * Creates an array cache object to store unique values.
  42934. *
  42935. * @private
  42936. * @constructor
  42937. * @param {Array} [values] The values to cache.
  42938. */
  42939. function SetCache(values) {
  42940. var index = -1,
  42941. length = values ? values.length : 0;
  42942. this.__data__ = new MapCache();
  42943. while (++index < length) {
  42944. this.add(values[index]);
  42945. }
  42946. }
  42947. /**
  42948. * Adds `value` to the array cache.
  42949. *
  42950. * @private
  42951. * @name add
  42952. * @memberOf SetCache
  42953. * @alias push
  42954. * @param {*} value The value to cache.
  42955. * @returns {Object} Returns the cache instance.
  42956. */
  42957. function setCacheAdd(value) {
  42958. this.__data__.set(value, HASH_UNDEFINED);
  42959. return this;
  42960. }
  42961. /**
  42962. * Checks if `value` is in the array cache.
  42963. *
  42964. * @private
  42965. * @name has
  42966. * @memberOf SetCache
  42967. * @param {*} value The value to search for.
  42968. * @returns {number} Returns `true` if `value` is found, else `false`.
  42969. */
  42970. function setCacheHas(value) {
  42971. return this.__data__.has(value);
  42972. } // Add methods to `SetCache`.
  42973. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  42974. SetCache.prototype.has = setCacheHas;
  42975. /**
  42976. * Creates a stack cache object to store key-value pairs.
  42977. *
  42978. * @private
  42979. * @constructor
  42980. * @param {Array} [entries] The key-value pairs to cache.
  42981. */
  42982. function Stack(entries) {
  42983. this.__data__ = new ListCache(entries);
  42984. }
  42985. /**
  42986. * Removes all key-value entries from the stack.
  42987. *
  42988. * @private
  42989. * @name clear
  42990. * @memberOf Stack
  42991. */
  42992. function stackClear() {
  42993. this.__data__ = new ListCache();
  42994. }
  42995. /**
  42996. * Removes `key` and its value from the stack.
  42997. *
  42998. * @private
  42999. * @name delete
  43000. * @memberOf Stack
  43001. * @param {string} key The key of the value to remove.
  43002. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  43003. */
  43004. function stackDelete(key) {
  43005. return this.__data__['delete'](key);
  43006. }
  43007. /**
  43008. * Gets the stack value for `key`.
  43009. *
  43010. * @private
  43011. * @name get
  43012. * @memberOf Stack
  43013. * @param {string} key The key of the value to get.
  43014. * @returns {*} Returns the entry value.
  43015. */
  43016. function stackGet(key) {
  43017. return this.__data__.get(key);
  43018. }
  43019. /**
  43020. * Checks if a stack value for `key` exists.
  43021. *
  43022. * @private
  43023. * @name has
  43024. * @memberOf Stack
  43025. * @param {string} key The key of the entry to check.
  43026. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  43027. */
  43028. function stackHas(key) {
  43029. return this.__data__.has(key);
  43030. }
  43031. /**
  43032. * Sets the stack `key` to `value`.
  43033. *
  43034. * @private
  43035. * @name set
  43036. * @memberOf Stack
  43037. * @param {string} key The key of the value to set.
  43038. * @param {*} value The value to set.
  43039. * @returns {Object} Returns the stack cache instance.
  43040. */
  43041. function stackSet(key, value) {
  43042. var cache = this.__data__;
  43043. if (cache instanceof ListCache) {
  43044. var pairs = cache.__data__;
  43045. if (!Map || pairs.length < LARGE_ARRAY_SIZE - 1) {
  43046. pairs.push([key, value]);
  43047. return this;
  43048. }
  43049. cache = this.__data__ = new MapCache(pairs);
  43050. }
  43051. cache.set(key, value);
  43052. return this;
  43053. } // Add methods to `Stack`.
  43054. Stack.prototype.clear = stackClear;
  43055. Stack.prototype['delete'] = stackDelete;
  43056. Stack.prototype.get = stackGet;
  43057. Stack.prototype.has = stackHas;
  43058. Stack.prototype.set = stackSet;
  43059. /**
  43060. * Creates an array of the enumerable property names of the array-like `value`.
  43061. *
  43062. * @private
  43063. * @param {*} value The value to query.
  43064. * @param {boolean} inherited Specify returning inherited property names.
  43065. * @returns {Array} Returns the array of property names.
  43066. */
  43067. function arrayLikeKeys(value, inherited) {
  43068. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  43069. // Safari 9 makes `arguments.length` enumerable in strict mode.
  43070. var result = isArray(value) || isArguments(value) ? baseTimes(value.length, String) : [];
  43071. var length = result.length,
  43072. skipIndexes = !!length;
  43073. for (var key in value) {
  43074. if ((inherited || hasOwnProperty.call(value, key)) && !(skipIndexes && (key == 'length' || isIndex(key, length)))) {
  43075. result.push(key);
  43076. }
  43077. }
  43078. return result;
  43079. }
  43080. /**
  43081. * Gets the index at which the `key` is found in `array` of key-value pairs.
  43082. *
  43083. * @private
  43084. * @param {Array} array The array to inspect.
  43085. * @param {*} key The key to search for.
  43086. * @returns {number} Returns the index of the matched value, else `-1`.
  43087. */
  43088. function assocIndexOf(array, key) {
  43089. var length = array.length;
  43090. while (length--) {
  43091. if (eq(array[length][0], key)) {
  43092. return length;
  43093. }
  43094. }
  43095. return -1;
  43096. }
  43097. /**
  43098. * Aggregates elements of `collection` on `accumulator` with keys transformed
  43099. * by `iteratee` and values set by `setter`.
  43100. *
  43101. * @private
  43102. * @param {Array|Object} collection The collection to iterate over.
  43103. * @param {Function} setter The function to set `accumulator` values.
  43104. * @param {Function} iteratee The iteratee to transform keys.
  43105. * @param {Object} accumulator The initial aggregated object.
  43106. * @returns {Function} Returns `accumulator`.
  43107. */
  43108. function baseAggregator(collection, setter, iteratee, accumulator) {
  43109. baseEach(collection, function (value, key, collection) {
  43110. setter(accumulator, value, iteratee(value), collection);
  43111. });
  43112. return accumulator;
  43113. }
  43114. /**
  43115. * The base implementation of `_.forEach` without support for iteratee shorthands.
  43116. *
  43117. * @private
  43118. * @param {Array|Object} collection The collection to iterate over.
  43119. * @param {Function} iteratee The function invoked per iteration.
  43120. * @returns {Array|Object} Returns `collection`.
  43121. */
  43122. var baseEach = createBaseEach(baseForOwn);
  43123. /**
  43124. * The base implementation of `baseForOwn` which iterates over `object`
  43125. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  43126. * Iteratee functions may exit iteration early by explicitly returning `false`.
  43127. *
  43128. * @private
  43129. * @param {Object} object The object to iterate over.
  43130. * @param {Function} iteratee The function invoked per iteration.
  43131. * @param {Function} keysFunc The function to get the keys of `object`.
  43132. * @returns {Object} Returns `object`.
  43133. */
  43134. var baseFor = createBaseFor();
  43135. /**
  43136. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  43137. *
  43138. * @private
  43139. * @param {Object} object The object to iterate over.
  43140. * @param {Function} iteratee The function invoked per iteration.
  43141. * @returns {Object} Returns `object`.
  43142. */
  43143. function baseForOwn(object, iteratee) {
  43144. return object && baseFor(object, iteratee, keys);
  43145. }
  43146. /**
  43147. * The base implementation of `_.get` without support for default values.
  43148. *
  43149. * @private
  43150. * @param {Object} object The object to query.
  43151. * @param {Array|string} path The path of the property to get.
  43152. * @returns {*} Returns the resolved value.
  43153. */
  43154. function baseGet(object, path) {
  43155. path = isKey(path, object) ? [path] : castPath(path);
  43156. var index = 0,
  43157. length = path.length;
  43158. while (object != null && index < length) {
  43159. object = object[toKey(path[index++])];
  43160. }
  43161. return index && index == length ? object : undefined;
  43162. }
  43163. /**
  43164. * The base implementation of `getTag`.
  43165. *
  43166. * @private
  43167. * @param {*} value The value to query.
  43168. * @returns {string} Returns the `toStringTag`.
  43169. */
  43170. function baseGetTag(value) {
  43171. return objectToString.call(value);
  43172. }
  43173. /**
  43174. * The base implementation of `_.hasIn` without support for deep paths.
  43175. *
  43176. * @private
  43177. * @param {Object} [object] The object to query.
  43178. * @param {Array|string} key The key to check.
  43179. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  43180. */
  43181. function baseHasIn(object, key) {
  43182. return object != null && key in Object(object);
  43183. }
  43184. /**
  43185. * The base implementation of `_.isEqual` which supports partial comparisons
  43186. * and tracks traversed objects.
  43187. *
  43188. * @private
  43189. * @param {*} value The value to compare.
  43190. * @param {*} other The other value to compare.
  43191. * @param {Function} [customizer] The function to customize comparisons.
  43192. * @param {boolean} [bitmask] The bitmask of comparison flags.
  43193. * The bitmask may be composed of the following flags:
  43194. * 1 - Unordered comparison
  43195. * 2 - Partial comparison
  43196. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  43197. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  43198. */
  43199. function baseIsEqual(value, other, customizer, bitmask, stack) {
  43200. if (value === other) {
  43201. return true;
  43202. }
  43203. if (value == null || other == null || !isObject(value) && !isObjectLike(other)) {
  43204. return value !== value && other !== other;
  43205. }
  43206. return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
  43207. }
  43208. /**
  43209. * A specialized version of `baseIsEqual` for arrays and objects which performs
  43210. * deep comparisons and tracks traversed objects enabling objects with circular
  43211. * references to be compared.
  43212. *
  43213. * @private
  43214. * @param {Object} object The object to compare.
  43215. * @param {Object} other The other object to compare.
  43216. * @param {Function} equalFunc The function to determine equivalents of values.
  43217. * @param {Function} [customizer] The function to customize comparisons.
  43218. * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual`
  43219. * for more details.
  43220. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  43221. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  43222. */
  43223. function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
  43224. var objIsArr = isArray(object),
  43225. othIsArr = isArray(other),
  43226. objTag = arrayTag,
  43227. othTag = arrayTag;
  43228. if (!objIsArr) {
  43229. objTag = getTag(object);
  43230. objTag = objTag == argsTag ? objectTag : objTag;
  43231. }
  43232. if (!othIsArr) {
  43233. othTag = getTag(other);
  43234. othTag = othTag == argsTag ? objectTag : othTag;
  43235. }
  43236. var objIsObj = objTag == objectTag && !isHostObject(object),
  43237. othIsObj = othTag == objectTag && !isHostObject(other),
  43238. isSameTag = objTag == othTag;
  43239. if (isSameTag && !objIsObj) {
  43240. stack || (stack = new Stack());
  43241. return objIsArr || isTypedArray(object) ? equalArrays(object, other, equalFunc, customizer, bitmask, stack) : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack);
  43242. }
  43243. if (!(bitmask & PARTIAL_COMPARE_FLAG)) {
  43244. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  43245. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  43246. if (objIsWrapped || othIsWrapped) {
  43247. var objUnwrapped = objIsWrapped ? object.value() : object,
  43248. othUnwrapped = othIsWrapped ? other.value() : other;
  43249. stack || (stack = new Stack());
  43250. return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack);
  43251. }
  43252. }
  43253. if (!isSameTag) {
  43254. return false;
  43255. }
  43256. stack || (stack = new Stack());
  43257. return equalObjects(object, other, equalFunc, customizer, bitmask, stack);
  43258. }
  43259. /**
  43260. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  43261. *
  43262. * @private
  43263. * @param {Object} object The object to inspect.
  43264. * @param {Object} source The object of property values to match.
  43265. * @param {Array} matchData The property names, values, and compare flags to match.
  43266. * @param {Function} [customizer] The function to customize comparisons.
  43267. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  43268. */
  43269. function baseIsMatch(object, source, matchData, customizer) {
  43270. var index = matchData.length,
  43271. length = index,
  43272. noCustomizer = !customizer;
  43273. if (object == null) {
  43274. return !length;
  43275. }
  43276. object = Object(object);
  43277. while (index--) {
  43278. var data = matchData[index];
  43279. if (noCustomizer && data[2] ? data[1] !== object[data[0]] : !(data[0] in object)) {
  43280. return false;
  43281. }
  43282. }
  43283. while (++index < length) {
  43284. data = matchData[index];
  43285. var key = data[0],
  43286. objValue = object[key],
  43287. srcValue = data[1];
  43288. if (noCustomizer && data[2]) {
  43289. if (objValue === undefined && !(key in object)) {
  43290. return false;
  43291. }
  43292. } else {
  43293. var stack = new Stack();
  43294. if (customizer) {
  43295. var result = customizer(objValue, srcValue, key, object, source, stack);
  43296. }
  43297. if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack) : result)) {
  43298. return false;
  43299. }
  43300. }
  43301. }
  43302. return true;
  43303. }
  43304. /**
  43305. * The base implementation of `_.isNative` without bad shim checks.
  43306. *
  43307. * @private
  43308. * @param {*} value The value to check.
  43309. * @returns {boolean} Returns `true` if `value` is a native function,
  43310. * else `false`.
  43311. */
  43312. function baseIsNative(value) {
  43313. if (!isObject(value) || isMasked(value)) {
  43314. return false;
  43315. }
  43316. var pattern = isFunction(value) || isHostObject(value) ? reIsNative : reIsHostCtor;
  43317. return pattern.test(toSource(value));
  43318. }
  43319. /**
  43320. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  43321. *
  43322. * @private
  43323. * @param {*} value The value to check.
  43324. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  43325. */
  43326. function baseIsTypedArray(value) {
  43327. return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
  43328. }
  43329. /**
  43330. * The base implementation of `_.iteratee`.
  43331. *
  43332. * @private
  43333. * @param {*} [value=_.identity] The value to convert to an iteratee.
  43334. * @returns {Function} Returns the iteratee.
  43335. */
  43336. function baseIteratee(value) {
  43337. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  43338. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  43339. if (typeof value == 'function') {
  43340. return value;
  43341. }
  43342. if (value == null) {
  43343. return identity;
  43344. }
  43345. if (_typeof(value) == 'object') {
  43346. return isArray(value) ? baseMatchesProperty(value[0], value[1]) : baseMatches(value);
  43347. }
  43348. return property(value);
  43349. }
  43350. /**
  43351. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  43352. *
  43353. * @private
  43354. * @param {Object} object The object to query.
  43355. * @returns {Array} Returns the array of property names.
  43356. */
  43357. function baseKeys(object) {
  43358. if (!isPrototype(object)) {
  43359. return nativeKeys(object);
  43360. }
  43361. var result = [];
  43362. for (var key in Object(object)) {
  43363. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  43364. result.push(key);
  43365. }
  43366. }
  43367. return result;
  43368. }
  43369. /**
  43370. * The base implementation of `_.matches` which doesn't clone `source`.
  43371. *
  43372. * @private
  43373. * @param {Object} source The object of property values to match.
  43374. * @returns {Function} Returns the new spec function.
  43375. */
  43376. function baseMatches(source) {
  43377. var matchData = getMatchData(source);
  43378. if (matchData.length == 1 && matchData[0][2]) {
  43379. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  43380. }
  43381. return function (object) {
  43382. return object === source || baseIsMatch(object, source, matchData);
  43383. };
  43384. }
  43385. /**
  43386. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  43387. *
  43388. * @private
  43389. * @param {string} path The path of the property to get.
  43390. * @param {*} srcValue The value to match.
  43391. * @returns {Function} Returns the new spec function.
  43392. */
  43393. function baseMatchesProperty(path, srcValue) {
  43394. if (isKey(path) && isStrictComparable(srcValue)) {
  43395. return matchesStrictComparable(toKey(path), srcValue);
  43396. }
  43397. return function (object) {
  43398. var objValue = get(object, path);
  43399. return objValue === undefined && objValue === srcValue ? hasIn(object, path) : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
  43400. };
  43401. }
  43402. /**
  43403. * A specialized version of `baseProperty` which supports deep paths.
  43404. *
  43405. * @private
  43406. * @param {Array|string} path The path of the property to get.
  43407. * @returns {Function} Returns the new accessor function.
  43408. */
  43409. function basePropertyDeep(path) {
  43410. return function (object) {
  43411. return baseGet(object, path);
  43412. };
  43413. }
  43414. /**
  43415. * The base implementation of `_.toString` which doesn't convert nullish
  43416. * values to empty strings.
  43417. *
  43418. * @private
  43419. * @param {*} value The value to process.
  43420. * @returns {string} Returns the string.
  43421. */
  43422. function baseToString(value) {
  43423. // Exit early for strings to avoid a performance hit in some environments.
  43424. if (typeof value == 'string') {
  43425. return value;
  43426. }
  43427. if (isSymbol(value)) {
  43428. return symbolToString ? symbolToString.call(value) : '';
  43429. }
  43430. var result = value + '';
  43431. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  43432. }
  43433. /**
  43434. * Casts `value` to a path array if it's not one.
  43435. *
  43436. * @private
  43437. * @param {*} value The value to inspect.
  43438. * @returns {Array} Returns the cast property path array.
  43439. */
  43440. function castPath(value) {
  43441. return isArray(value) ? value : stringToPath(value);
  43442. }
  43443. /**
  43444. * Creates a function like `_.groupBy`.
  43445. *
  43446. * @private
  43447. * @param {Function} setter The function to set accumulator values.
  43448. * @param {Function} [initializer] The accumulator object initializer.
  43449. * @returns {Function} Returns the new aggregator function.
  43450. */
  43451. function createAggregator(setter, initializer) {
  43452. return function (collection, iteratee) {
  43453. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  43454. accumulator = initializer ? initializer() : {};
  43455. return func(collection, setter, baseIteratee(iteratee, 2), accumulator);
  43456. };
  43457. }
  43458. /**
  43459. * Creates a `baseEach` or `baseEachRight` function.
  43460. *
  43461. * @private
  43462. * @param {Function} eachFunc The function to iterate over a collection.
  43463. * @param {boolean} [fromRight] Specify iterating from right to left.
  43464. * @returns {Function} Returns the new base function.
  43465. */
  43466. function createBaseEach(eachFunc, fromRight) {
  43467. return function (collection, iteratee) {
  43468. if (collection == null) {
  43469. return collection;
  43470. }
  43471. if (!isArrayLike(collection)) {
  43472. return eachFunc(collection, iteratee);
  43473. }
  43474. var length = collection.length,
  43475. index = fromRight ? length : -1,
  43476. iterable = Object(collection);
  43477. while (fromRight ? index-- : ++index < length) {
  43478. if (iteratee(iterable[index], index, iterable) === false) {
  43479. break;
  43480. }
  43481. }
  43482. return collection;
  43483. };
  43484. }
  43485. /**
  43486. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  43487. *
  43488. * @private
  43489. * @param {boolean} [fromRight] Specify iterating from right to left.
  43490. * @returns {Function} Returns the new base function.
  43491. */
  43492. function createBaseFor(fromRight) {
  43493. return function (object, iteratee, keysFunc) {
  43494. var index = -1,
  43495. iterable = Object(object),
  43496. props = keysFunc(object),
  43497. length = props.length;
  43498. while (length--) {
  43499. var key = props[fromRight ? length : ++index];
  43500. if (iteratee(iterable[key], key, iterable) === false) {
  43501. break;
  43502. }
  43503. }
  43504. return object;
  43505. };
  43506. }
  43507. /**
  43508. * A specialized version of `baseIsEqualDeep` for arrays with support for
  43509. * partial deep comparisons.
  43510. *
  43511. * @private
  43512. * @param {Array} array The array to compare.
  43513. * @param {Array} other The other array to compare.
  43514. * @param {Function} equalFunc The function to determine equivalents of values.
  43515. * @param {Function} customizer The function to customize comparisons.
  43516. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  43517. * for more details.
  43518. * @param {Object} stack Tracks traversed `array` and `other` objects.
  43519. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  43520. */
  43521. function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
  43522. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  43523. arrLength = array.length,
  43524. othLength = other.length;
  43525. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  43526. return false;
  43527. } // Assume cyclic values are equal.
  43528. var stacked = stack.get(array);
  43529. if (stacked && stack.get(other)) {
  43530. return stacked == other;
  43531. }
  43532. var index = -1,
  43533. result = true,
  43534. seen = bitmask & UNORDERED_COMPARE_FLAG ? new SetCache() : undefined;
  43535. stack.set(array, other);
  43536. stack.set(other, array); // Ignore non-index properties.
  43537. while (++index < arrLength) {
  43538. var arrValue = array[index],
  43539. othValue = other[index];
  43540. if (customizer) {
  43541. var compared = isPartial ? customizer(othValue, arrValue, index, other, array, stack) : customizer(arrValue, othValue, index, array, other, stack);
  43542. }
  43543. if (compared !== undefined) {
  43544. if (compared) {
  43545. continue;
  43546. }
  43547. result = false;
  43548. break;
  43549. } // Recursively compare arrays (susceptible to call stack limits).
  43550. if (seen) {
  43551. if (!arraySome(other, function (othValue, othIndex) {
  43552. if (!seen.has(othIndex) && (arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  43553. return seen.add(othIndex);
  43554. }
  43555. })) {
  43556. result = false;
  43557. break;
  43558. }
  43559. } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  43560. result = false;
  43561. break;
  43562. }
  43563. }
  43564. stack['delete'](array);
  43565. stack['delete'](other);
  43566. return result;
  43567. }
  43568. /**
  43569. * A specialized version of `baseIsEqualDeep` for comparing objects of
  43570. * the same `toStringTag`.
  43571. *
  43572. * **Note:** This function only supports comparing values with tags of
  43573. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  43574. *
  43575. * @private
  43576. * @param {Object} object The object to compare.
  43577. * @param {Object} other The other object to compare.
  43578. * @param {string} tag The `toStringTag` of the objects to compare.
  43579. * @param {Function} equalFunc The function to determine equivalents of values.
  43580. * @param {Function} customizer The function to customize comparisons.
  43581. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  43582. * for more details.
  43583. * @param {Object} stack Tracks traversed `object` and `other` objects.
  43584. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  43585. */
  43586. function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) {
  43587. switch (tag) {
  43588. case dataViewTag:
  43589. if (object.byteLength != other.byteLength || object.byteOffset != other.byteOffset) {
  43590. return false;
  43591. }
  43592. object = object.buffer;
  43593. other = other.buffer;
  43594. case arrayBufferTag:
  43595. if (object.byteLength != other.byteLength || !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  43596. return false;
  43597. }
  43598. return true;
  43599. case boolTag:
  43600. case dateTag:
  43601. case numberTag:
  43602. // Coerce booleans to `1` or `0` and dates to milliseconds.
  43603. // Invalid dates are coerced to `NaN`.
  43604. return eq(+object, +other);
  43605. case errorTag:
  43606. return object.name == other.name && object.message == other.message;
  43607. case regexpTag:
  43608. case stringTag:
  43609. // Coerce regexes to strings and treat strings, primitives and objects,
  43610. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  43611. // for more details.
  43612. return object == other + '';
  43613. case mapTag:
  43614. var convert = mapToArray;
  43615. case setTag:
  43616. var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
  43617. convert || (convert = setToArray);
  43618. if (object.size != other.size && !isPartial) {
  43619. return false;
  43620. } // Assume cyclic values are equal.
  43621. var stacked = stack.get(object);
  43622. if (stacked) {
  43623. return stacked == other;
  43624. }
  43625. bitmask |= UNORDERED_COMPARE_FLAG; // Recursively compare objects (susceptible to call stack limits).
  43626. stack.set(object, other);
  43627. var result = equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack);
  43628. stack['delete'](object);
  43629. return result;
  43630. case symbolTag:
  43631. if (symbolValueOf) {
  43632. return symbolValueOf.call(object) == symbolValueOf.call(other);
  43633. }
  43634. }
  43635. return false;
  43636. }
  43637. /**
  43638. * A specialized version of `baseIsEqualDeep` for objects with support for
  43639. * partial deep comparisons.
  43640. *
  43641. * @private
  43642. * @param {Object} object The object to compare.
  43643. * @param {Object} other The other object to compare.
  43644. * @param {Function} equalFunc The function to determine equivalents of values.
  43645. * @param {Function} customizer The function to customize comparisons.
  43646. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  43647. * for more details.
  43648. * @param {Object} stack Tracks traversed `object` and `other` objects.
  43649. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  43650. */
  43651. function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
  43652. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  43653. objProps = keys(object),
  43654. objLength = objProps.length,
  43655. othProps = keys(other),
  43656. othLength = othProps.length;
  43657. if (objLength != othLength && !isPartial) {
  43658. return false;
  43659. }
  43660. var index = objLength;
  43661. while (index--) {
  43662. var key = objProps[index];
  43663. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  43664. return false;
  43665. }
  43666. } // Assume cyclic values are equal.
  43667. var stacked = stack.get(object);
  43668. if (stacked && stack.get(other)) {
  43669. return stacked == other;
  43670. }
  43671. var result = true;
  43672. stack.set(object, other);
  43673. stack.set(other, object);
  43674. var skipCtor = isPartial;
  43675. while (++index < objLength) {
  43676. key = objProps[index];
  43677. var objValue = object[key],
  43678. othValue = other[key];
  43679. if (customizer) {
  43680. var compared = isPartial ? customizer(othValue, objValue, key, other, object, stack) : customizer(objValue, othValue, key, object, other, stack);
  43681. } // Recursively compare objects (susceptible to call stack limits).
  43682. if (!(compared === undefined ? objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack) : compared)) {
  43683. result = false;
  43684. break;
  43685. }
  43686. skipCtor || (skipCtor = key == 'constructor');
  43687. }
  43688. if (result && !skipCtor) {
  43689. var objCtor = object.constructor,
  43690. othCtor = other.constructor; // Non `Object` object instances with different constructors are not equal.
  43691. if (objCtor != othCtor && 'constructor' in object && 'constructor' in other && !(typeof objCtor == 'function' && objCtor instanceof objCtor && typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  43692. result = false;
  43693. }
  43694. }
  43695. stack['delete'](object);
  43696. stack['delete'](other);
  43697. return result;
  43698. }
  43699. /**
  43700. * Gets the data for `map`.
  43701. *
  43702. * @private
  43703. * @param {Object} map The map to query.
  43704. * @param {string} key The reference key.
  43705. * @returns {*} Returns the map data.
  43706. */
  43707. function getMapData(map, key) {
  43708. var data = map.__data__;
  43709. return isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
  43710. }
  43711. /**
  43712. * Gets the property names, values, and compare flags of `object`.
  43713. *
  43714. * @private
  43715. * @param {Object} object The object to query.
  43716. * @returns {Array} Returns the match data of `object`.
  43717. */
  43718. function getMatchData(object) {
  43719. var result = keys(object),
  43720. length = result.length;
  43721. while (length--) {
  43722. var key = result[length],
  43723. value = object[key];
  43724. result[length] = [key, value, isStrictComparable(value)];
  43725. }
  43726. return result;
  43727. }
  43728. /**
  43729. * Gets the native function at `key` of `object`.
  43730. *
  43731. * @private
  43732. * @param {Object} object The object to query.
  43733. * @param {string} key The key of the method to get.
  43734. * @returns {*} Returns the function if it's native, else `undefined`.
  43735. */
  43736. function getNative(object, key) {
  43737. var value = getValue(object, key);
  43738. return baseIsNative(value) ? value : undefined;
  43739. }
  43740. /**
  43741. * Gets the `toStringTag` of `value`.
  43742. *
  43743. * @private
  43744. * @param {*} value The value to query.
  43745. * @returns {string} Returns the `toStringTag`.
  43746. */
  43747. var getTag = baseGetTag; // Fallback for data views, maps, sets, and weak maps in IE 11,
  43748. // for data views in Edge < 14, and promises in Node.js.
  43749. 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) {
  43750. getTag = function getTag(value) {
  43751. var result = objectToString.call(value),
  43752. Ctor = result == objectTag ? value.constructor : undefined,
  43753. ctorString = Ctor ? toSource(Ctor) : undefined;
  43754. if (ctorString) {
  43755. switch (ctorString) {
  43756. case dataViewCtorString:
  43757. return dataViewTag;
  43758. case mapCtorString:
  43759. return mapTag;
  43760. case promiseCtorString:
  43761. return promiseTag;
  43762. case setCtorString:
  43763. return setTag;
  43764. case weakMapCtorString:
  43765. return weakMapTag;
  43766. }
  43767. }
  43768. return result;
  43769. };
  43770. }
  43771. /**
  43772. * Checks if `path` exists on `object`.
  43773. *
  43774. * @private
  43775. * @param {Object} object The object to query.
  43776. * @param {Array|string} path The path to check.
  43777. * @param {Function} hasFunc The function to check properties.
  43778. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  43779. */
  43780. function hasPath(object, path, hasFunc) {
  43781. path = isKey(path, object) ? [path] : castPath(path);
  43782. var result,
  43783. index = -1,
  43784. length = path.length;
  43785. while (++index < length) {
  43786. var key = toKey(path[index]);
  43787. if (!(result = object != null && hasFunc(object, key))) {
  43788. break;
  43789. }
  43790. object = object[key];
  43791. }
  43792. if (result) {
  43793. return result;
  43794. }
  43795. var length = object ? object.length : 0;
  43796. return !!length && isLength(length) && isIndex(key, length) && (isArray(object) || isArguments(object));
  43797. }
  43798. /**
  43799. * Checks if `value` is a valid array-like index.
  43800. *
  43801. * @private
  43802. * @param {*} value The value to check.
  43803. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  43804. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  43805. */
  43806. function isIndex(value, length) {
  43807. length = length == null ? MAX_SAFE_INTEGER : length;
  43808. return !!length && (typeof value == 'number' || reIsUint.test(value)) && value > -1 && value % 1 == 0 && value < length;
  43809. }
  43810. /**
  43811. * Checks if `value` is a property name and not a property path.
  43812. *
  43813. * @private
  43814. * @param {*} value The value to check.
  43815. * @param {Object} [object] The object to query keys on.
  43816. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  43817. */
  43818. function isKey(value, object) {
  43819. if (isArray(value)) {
  43820. return false;
  43821. }
  43822. var type = _typeof(value);
  43823. if (type == 'number' || type == 'symbol' || type == 'boolean' || value == null || isSymbol(value)) {
  43824. return true;
  43825. }
  43826. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object != null && value in Object(object);
  43827. }
  43828. /**
  43829. * Checks if `value` is suitable for use as unique object key.
  43830. *
  43831. * @private
  43832. * @param {*} value The value to check.
  43833. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  43834. */
  43835. function isKeyable(value) {
  43836. var type = _typeof(value);
  43837. return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean' ? value !== '__proto__' : value === null;
  43838. }
  43839. /**
  43840. * Checks if `func` has its source masked.
  43841. *
  43842. * @private
  43843. * @param {Function} func The function to check.
  43844. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  43845. */
  43846. function isMasked(func) {
  43847. return !!maskSrcKey && maskSrcKey in func;
  43848. }
  43849. /**
  43850. * Checks if `value` is likely a prototype object.
  43851. *
  43852. * @private
  43853. * @param {*} value The value to check.
  43854. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  43855. */
  43856. function isPrototype(value) {
  43857. var Ctor = value && value.constructor,
  43858. proto = typeof Ctor == 'function' && Ctor.prototype || objectProto;
  43859. return value === proto;
  43860. }
  43861. /**
  43862. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  43863. *
  43864. * @private
  43865. * @param {*} value The value to check.
  43866. * @returns {boolean} Returns `true` if `value` if suitable for strict
  43867. * equality comparisons, else `false`.
  43868. */
  43869. function isStrictComparable(value) {
  43870. return value === value && !isObject(value);
  43871. }
  43872. /**
  43873. * A specialized version of `matchesProperty` for source values suitable
  43874. * for strict equality comparisons, i.e. `===`.
  43875. *
  43876. * @private
  43877. * @param {string} key The key of the property to get.
  43878. * @param {*} srcValue The value to match.
  43879. * @returns {Function} Returns the new spec function.
  43880. */
  43881. function matchesStrictComparable(key, srcValue) {
  43882. return function (object) {
  43883. if (object == null) {
  43884. return false;
  43885. }
  43886. return object[key] === srcValue && (srcValue !== undefined || key in Object(object));
  43887. };
  43888. }
  43889. /**
  43890. * Converts `string` to a property path array.
  43891. *
  43892. * @private
  43893. * @param {string} string The string to convert.
  43894. * @returns {Array} Returns the property path array.
  43895. */
  43896. var stringToPath = memoize(function (string) {
  43897. string = toString(string);
  43898. var result = [];
  43899. if (reLeadingDot.test(string)) {
  43900. result.push('');
  43901. }
  43902. string.replace(rePropName, function (match, number, quote, string) {
  43903. result.push(quote ? string.replace(reEscapeChar, '$1') : number || match);
  43904. });
  43905. return result;
  43906. });
  43907. /**
  43908. * Converts `value` to a string key if it's not a string or symbol.
  43909. *
  43910. * @private
  43911. * @param {*} value The value to inspect.
  43912. * @returns {string|symbol} Returns the key.
  43913. */
  43914. function toKey(value) {
  43915. if (typeof value == 'string' || isSymbol(value)) {
  43916. return value;
  43917. }
  43918. var result = value + '';
  43919. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  43920. }
  43921. /**
  43922. * Converts `func` to its source code.
  43923. *
  43924. * @private
  43925. * @param {Function} func The function to process.
  43926. * @returns {string} Returns the source code.
  43927. */
  43928. function toSource(func) {
  43929. if (func != null) {
  43930. try {
  43931. return funcToString.call(func);
  43932. } catch (e) {}
  43933. try {
  43934. return func + '';
  43935. } catch (e) {}
  43936. }
  43937. return '';
  43938. }
  43939. /**
  43940. * Creates an object composed of keys generated from the results of running
  43941. * each element of `collection` thru `iteratee`. The order of grouped values
  43942. * is determined by the order they occur in `collection`. The corresponding
  43943. * value of each key is an array of elements responsible for generating the
  43944. * key. The iteratee is invoked with one argument: (value).
  43945. *
  43946. * @static
  43947. * @memberOf _
  43948. * @since 0.1.0
  43949. * @category Collection
  43950. * @param {Array|Object} collection The collection to iterate over.
  43951. * @param {Function} [iteratee=_.identity]
  43952. * The iteratee to transform keys.
  43953. * @returns {Object} Returns the composed aggregate object.
  43954. * @example
  43955. *
  43956. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  43957. * // => { '4': [4.2], '6': [6.1, 6.3] }
  43958. *
  43959. * // The `_.property` iteratee shorthand.
  43960. * _.groupBy(['one', 'two', 'three'], 'length');
  43961. * // => { '3': ['one', 'two'], '5': ['three'] }
  43962. */
  43963. var groupBy = createAggregator(function (result, value, key) {
  43964. if (hasOwnProperty.call(result, key)) {
  43965. result[key].push(value);
  43966. } else {
  43967. result[key] = [value];
  43968. }
  43969. });
  43970. /**
  43971. * Creates a function that memoizes the result of `func`. If `resolver` is
  43972. * provided, it determines the cache key for storing the result based on the
  43973. * arguments provided to the memoized function. By default, the first argument
  43974. * provided to the memoized function is used as the map cache key. The `func`
  43975. * is invoked with the `this` binding of the memoized function.
  43976. *
  43977. * **Note:** The cache is exposed as the `cache` property on the memoized
  43978. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  43979. * constructor with one whose instances implement the
  43980. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  43981. * method interface of `delete`, `get`, `has`, and `set`.
  43982. *
  43983. * @static
  43984. * @memberOf _
  43985. * @since 0.1.0
  43986. * @category Function
  43987. * @param {Function} func The function to have its output memoized.
  43988. * @param {Function} [resolver] The function to resolve the cache key.
  43989. * @returns {Function} Returns the new memoized function.
  43990. * @example
  43991. *
  43992. * var object = { 'a': 1, 'b': 2 };
  43993. * var other = { 'c': 3, 'd': 4 };
  43994. *
  43995. * var values = _.memoize(_.values);
  43996. * values(object);
  43997. * // => [1, 2]
  43998. *
  43999. * values(other);
  44000. * // => [3, 4]
  44001. *
  44002. * object.a = 2;
  44003. * values(object);
  44004. * // => [1, 2]
  44005. *
  44006. * // Modify the result cache.
  44007. * values.cache.set(object, ['a', 'b']);
  44008. * values(object);
  44009. * // => ['a', 'b']
  44010. *
  44011. * // Replace `_.memoize.Cache`.
  44012. * _.memoize.Cache = WeakMap;
  44013. */
  44014. function memoize(func, resolver) {
  44015. if (typeof func != 'function' || resolver && typeof resolver != 'function') {
  44016. throw new TypeError(FUNC_ERROR_TEXT);
  44017. }
  44018. var memoized = function memoized() {
  44019. var args = arguments,
  44020. key = resolver ? resolver.apply(this, args) : args[0],
  44021. cache = memoized.cache;
  44022. if (cache.has(key)) {
  44023. return cache.get(key);
  44024. }
  44025. var result = func.apply(this, args);
  44026. memoized.cache = cache.set(key, result);
  44027. return result;
  44028. };
  44029. memoized.cache = new (memoize.Cache || MapCache)();
  44030. return memoized;
  44031. } // Assign cache to `_.memoize`.
  44032. memoize.Cache = MapCache;
  44033. /**
  44034. * Performs a
  44035. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  44036. * comparison between two values to determine if they are equivalent.
  44037. *
  44038. * @static
  44039. * @memberOf _
  44040. * @since 4.0.0
  44041. * @category Lang
  44042. * @param {*} value The value to compare.
  44043. * @param {*} other The other value to compare.
  44044. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  44045. * @example
  44046. *
  44047. * var object = { 'a': 1 };
  44048. * var other = { 'a': 1 };
  44049. *
  44050. * _.eq(object, object);
  44051. * // => true
  44052. *
  44053. * _.eq(object, other);
  44054. * // => false
  44055. *
  44056. * _.eq('a', 'a');
  44057. * // => true
  44058. *
  44059. * _.eq('a', Object('a'));
  44060. * // => false
  44061. *
  44062. * _.eq(NaN, NaN);
  44063. * // => true
  44064. */
  44065. function eq(value, other) {
  44066. return value === other || value !== value && other !== other;
  44067. }
  44068. /**
  44069. * Checks if `value` is likely an `arguments` object.
  44070. *
  44071. * @static
  44072. * @memberOf _
  44073. * @since 0.1.0
  44074. * @category Lang
  44075. * @param {*} value The value to check.
  44076. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  44077. * else `false`.
  44078. * @example
  44079. *
  44080. * _.isArguments(function() { return arguments; }());
  44081. * // => true
  44082. *
  44083. * _.isArguments([1, 2, 3]);
  44084. * // => false
  44085. */
  44086. function isArguments(value) {
  44087. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  44088. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') && (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  44089. }
  44090. /**
  44091. * Checks if `value` is classified as an `Array` object.
  44092. *
  44093. * @static
  44094. * @memberOf _
  44095. * @since 0.1.0
  44096. * @category Lang
  44097. * @param {*} value The value to check.
  44098. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  44099. * @example
  44100. *
  44101. * _.isArray([1, 2, 3]);
  44102. * // => true
  44103. *
  44104. * _.isArray(document.body.children);
  44105. * // => false
  44106. *
  44107. * _.isArray('abc');
  44108. * // => false
  44109. *
  44110. * _.isArray(_.noop);
  44111. * // => false
  44112. */
  44113. var isArray = Array.isArray;
  44114. /**
  44115. * Checks if `value` is array-like. A value is considered array-like if it's
  44116. * not a function and has a `value.length` that's an integer greater than or
  44117. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  44118. *
  44119. * @static
  44120. * @memberOf _
  44121. * @since 4.0.0
  44122. * @category Lang
  44123. * @param {*} value The value to check.
  44124. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  44125. * @example
  44126. *
  44127. * _.isArrayLike([1, 2, 3]);
  44128. * // => true
  44129. *
  44130. * _.isArrayLike(document.body.children);
  44131. * // => true
  44132. *
  44133. * _.isArrayLike('abc');
  44134. * // => true
  44135. *
  44136. * _.isArrayLike(_.noop);
  44137. * // => false
  44138. */
  44139. function isArrayLike(value) {
  44140. return value != null && isLength(value.length) && !isFunction(value);
  44141. }
  44142. /**
  44143. * This method is like `_.isArrayLike` except that it also checks if `value`
  44144. * is an object.
  44145. *
  44146. * @static
  44147. * @memberOf _
  44148. * @since 4.0.0
  44149. * @category Lang
  44150. * @param {*} value The value to check.
  44151. * @returns {boolean} Returns `true` if `value` is an array-like object,
  44152. * else `false`.
  44153. * @example
  44154. *
  44155. * _.isArrayLikeObject([1, 2, 3]);
  44156. * // => true
  44157. *
  44158. * _.isArrayLikeObject(document.body.children);
  44159. * // => true
  44160. *
  44161. * _.isArrayLikeObject('abc');
  44162. * // => false
  44163. *
  44164. * _.isArrayLikeObject(_.noop);
  44165. * // => false
  44166. */
  44167. function isArrayLikeObject(value) {
  44168. return isObjectLike(value) && isArrayLike(value);
  44169. }
  44170. /**
  44171. * Checks if `value` is classified as a `Function` object.
  44172. *
  44173. * @static
  44174. * @memberOf _
  44175. * @since 0.1.0
  44176. * @category Lang
  44177. * @param {*} value The value to check.
  44178. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  44179. * @example
  44180. *
  44181. * _.isFunction(_);
  44182. * // => true
  44183. *
  44184. * _.isFunction(/abc/);
  44185. * // => false
  44186. */
  44187. function isFunction(value) {
  44188. // The use of `Object#toString` avoids issues with the `typeof` operator
  44189. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  44190. var tag = isObject(value) ? objectToString.call(value) : '';
  44191. return tag == funcTag || tag == genTag;
  44192. }
  44193. /**
  44194. * Checks if `value` is a valid array-like length.
  44195. *
  44196. * **Note:** This method is loosely based on
  44197. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  44198. *
  44199. * @static
  44200. * @memberOf _
  44201. * @since 4.0.0
  44202. * @category Lang
  44203. * @param {*} value The value to check.
  44204. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  44205. * @example
  44206. *
  44207. * _.isLength(3);
  44208. * // => true
  44209. *
  44210. * _.isLength(Number.MIN_VALUE);
  44211. * // => false
  44212. *
  44213. * _.isLength(Infinity);
  44214. * // => false
  44215. *
  44216. * _.isLength('3');
  44217. * // => false
  44218. */
  44219. function isLength(value) {
  44220. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  44221. }
  44222. /**
  44223. * Checks if `value` is the
  44224. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  44225. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  44226. *
  44227. * @static
  44228. * @memberOf _
  44229. * @since 0.1.0
  44230. * @category Lang
  44231. * @param {*} value The value to check.
  44232. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  44233. * @example
  44234. *
  44235. * _.isObject({});
  44236. * // => true
  44237. *
  44238. * _.isObject([1, 2, 3]);
  44239. * // => true
  44240. *
  44241. * _.isObject(_.noop);
  44242. * // => true
  44243. *
  44244. * _.isObject(null);
  44245. * // => false
  44246. */
  44247. function isObject(value) {
  44248. var type = _typeof(value);
  44249. return !!value && (type == 'object' || type == 'function');
  44250. }
  44251. /**
  44252. * Checks if `value` is object-like. A value is object-like if it's not `null`
  44253. * and has a `typeof` result of "object".
  44254. *
  44255. * @static
  44256. * @memberOf _
  44257. * @since 4.0.0
  44258. * @category Lang
  44259. * @param {*} value The value to check.
  44260. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  44261. * @example
  44262. *
  44263. * _.isObjectLike({});
  44264. * // => true
  44265. *
  44266. * _.isObjectLike([1, 2, 3]);
  44267. * // => true
  44268. *
  44269. * _.isObjectLike(_.noop);
  44270. * // => false
  44271. *
  44272. * _.isObjectLike(null);
  44273. * // => false
  44274. */
  44275. function isObjectLike(value) {
  44276. return !!value && _typeof(value) == 'object';
  44277. }
  44278. /**
  44279. * Checks if `value` is classified as a `Symbol` primitive or object.
  44280. *
  44281. * @static
  44282. * @memberOf _
  44283. * @since 4.0.0
  44284. * @category Lang
  44285. * @param {*} value The value to check.
  44286. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  44287. * @example
  44288. *
  44289. * _.isSymbol(Symbol.iterator);
  44290. * // => true
  44291. *
  44292. * _.isSymbol('abc');
  44293. * // => false
  44294. */
  44295. function isSymbol(value) {
  44296. return _typeof(value) == 'symbol' || isObjectLike(value) && objectToString.call(value) == symbolTag;
  44297. }
  44298. /**
  44299. * Checks if `value` is classified as a typed array.
  44300. *
  44301. * @static
  44302. * @memberOf _
  44303. * @since 3.0.0
  44304. * @category Lang
  44305. * @param {*} value The value to check.
  44306. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  44307. * @example
  44308. *
  44309. * _.isTypedArray(new Uint8Array);
  44310. * // => true
  44311. *
  44312. * _.isTypedArray([]);
  44313. * // => false
  44314. */
  44315. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  44316. /**
  44317. * Converts `value` to a string. An empty string is returned for `null`
  44318. * and `undefined` values. The sign of `-0` is preserved.
  44319. *
  44320. * @static
  44321. * @memberOf _
  44322. * @since 4.0.0
  44323. * @category Lang
  44324. * @param {*} value The value to process.
  44325. * @returns {string} Returns the string.
  44326. * @example
  44327. *
  44328. * _.toString(null);
  44329. * // => ''
  44330. *
  44331. * _.toString(-0);
  44332. * // => '-0'
  44333. *
  44334. * _.toString([1, 2, 3]);
  44335. * // => '1,2,3'
  44336. */
  44337. function toString(value) {
  44338. return value == null ? '' : baseToString(value);
  44339. }
  44340. /**
  44341. * Gets the value at `path` of `object`. If the resolved value is
  44342. * `undefined`, the `defaultValue` is returned in its place.
  44343. *
  44344. * @static
  44345. * @memberOf _
  44346. * @since 3.7.0
  44347. * @category Object
  44348. * @param {Object} object The object to query.
  44349. * @param {Array|string} path The path of the property to get.
  44350. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  44351. * @returns {*} Returns the resolved value.
  44352. * @example
  44353. *
  44354. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  44355. *
  44356. * _.get(object, 'a[0].b.c');
  44357. * // => 3
  44358. *
  44359. * _.get(object, ['a', '0', 'b', 'c']);
  44360. * // => 3
  44361. *
  44362. * _.get(object, 'a.b.c', 'default');
  44363. * // => 'default'
  44364. */
  44365. function get(object, path, defaultValue) {
  44366. var result = object == null ? undefined : baseGet(object, path);
  44367. return result === undefined ? defaultValue : result;
  44368. }
  44369. /**
  44370. * Checks if `path` is a direct or inherited property of `object`.
  44371. *
  44372. * @static
  44373. * @memberOf _
  44374. * @since 4.0.0
  44375. * @category Object
  44376. * @param {Object} object The object to query.
  44377. * @param {Array|string} path The path to check.
  44378. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  44379. * @example
  44380. *
  44381. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  44382. *
  44383. * _.hasIn(object, 'a');
  44384. * // => true
  44385. *
  44386. * _.hasIn(object, 'a.b');
  44387. * // => true
  44388. *
  44389. * _.hasIn(object, ['a', 'b']);
  44390. * // => true
  44391. *
  44392. * _.hasIn(object, 'b');
  44393. * // => false
  44394. */
  44395. function hasIn(object, path) {
  44396. return object != null && hasPath(object, path, baseHasIn);
  44397. }
  44398. /**
  44399. * Creates an array of the own enumerable property names of `object`.
  44400. *
  44401. * **Note:** Non-object values are coerced to objects. See the
  44402. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  44403. * for more details.
  44404. *
  44405. * @static
  44406. * @since 0.1.0
  44407. * @memberOf _
  44408. * @category Object
  44409. * @param {Object} object The object to query.
  44410. * @returns {Array} Returns the array of property names.
  44411. * @example
  44412. *
  44413. * function Foo() {
  44414. * this.a = 1;
  44415. * this.b = 2;
  44416. * }
  44417. *
  44418. * Foo.prototype.c = 3;
  44419. *
  44420. * _.keys(new Foo);
  44421. * // => ['a', 'b'] (iteration order is not guaranteed)
  44422. *
  44423. * _.keys('hi');
  44424. * // => ['0', '1']
  44425. */
  44426. function keys(object) {
  44427. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  44428. }
  44429. /**
  44430. * This method returns the first argument it receives.
  44431. *
  44432. * @static
  44433. * @since 0.1.0
  44434. * @memberOf _
  44435. * @category Util
  44436. * @param {*} value Any value.
  44437. * @returns {*} Returns `value`.
  44438. * @example
  44439. *
  44440. * var object = { 'a': 1 };
  44441. *
  44442. * console.log(_.identity(object) === object);
  44443. * // => true
  44444. */
  44445. function identity(value) {
  44446. return value;
  44447. }
  44448. /**
  44449. * Creates a function that returns the value at `path` of a given object.
  44450. *
  44451. * @static
  44452. * @memberOf _
  44453. * @since 2.4.0
  44454. * @category Util
  44455. * @param {Array|string} path The path of the property to get.
  44456. * @returns {Function} Returns the new accessor function.
  44457. * @example
  44458. *
  44459. * var objects = [
  44460. * { 'a': { 'b': 2 } },
  44461. * { 'a': { 'b': 1 } }
  44462. * ];
  44463. *
  44464. * _.map(objects, _.property('a.b'));
  44465. * // => [2, 1]
  44466. *
  44467. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  44468. * // => [1, 2]
  44469. */
  44470. function property(path) {
  44471. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  44472. }
  44473. module.exports = groupBy;
  44474. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  44475. },{}],319:[function(require,module,exports){
  44476. "use strict";
  44477. 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); }
  44478. /**
  44479. * lodash 3.0.3 (Custom Build) <https://lodash.com/>
  44480. * Build: `lodash modularize exports="npm" -o ./`
  44481. * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
  44482. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  44483. * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  44484. * Available under MIT license <https://lodash.com/license>
  44485. */
  44486. /** `Object#toString` result references. */
  44487. var boolTag = '[object Boolean]';
  44488. /** Used for built-in method references. */
  44489. var objectProto = Object.prototype;
  44490. /**
  44491. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  44492. * of values.
  44493. */
  44494. var objectToString = objectProto.toString;
  44495. /**
  44496. * Checks if `value` is classified as a boolean primitive or object.
  44497. *
  44498. * @static
  44499. * @memberOf _
  44500. * @category Lang
  44501. * @param {*} value The value to check.
  44502. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  44503. * @example
  44504. *
  44505. * _.isBoolean(false);
  44506. * // => true
  44507. *
  44508. * _.isBoolean(null);
  44509. * // => false
  44510. */
  44511. function isBoolean(value) {
  44512. return value === true || value === false || isObjectLike(value) && objectToString.call(value) == boolTag;
  44513. }
  44514. /**
  44515. * Checks if `value` is object-like. A value is object-like if it's not `null`
  44516. * and has a `typeof` result of "object".
  44517. *
  44518. * @static
  44519. * @memberOf _
  44520. * @category Lang
  44521. * @param {*} value The value to check.
  44522. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  44523. * @example
  44524. *
  44525. * _.isObjectLike({});
  44526. * // => true
  44527. *
  44528. * _.isObjectLike([1, 2, 3]);
  44529. * // => true
  44530. *
  44531. * _.isObjectLike(_.noop);
  44532. * // => false
  44533. *
  44534. * _.isObjectLike(null);
  44535. * // => false
  44536. */
  44537. function isObjectLike(value) {
  44538. return !!value && _typeof(value) == 'object';
  44539. }
  44540. module.exports = isBoolean;
  44541. },{}],320:[function(require,module,exports){
  44542. (function (global){
  44543. "use strict";
  44544. 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); }
  44545. /**
  44546. * Lodash (Custom Build) <https://lodash.com/>
  44547. * Build: `lodash modularize exports="npm" -o ./`
  44548. * Copyright JS Foundation and other contributors <https://js.foundation/>
  44549. * Released under MIT license <https://lodash.com/license>
  44550. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  44551. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  44552. */
  44553. /** Used as the size to enable large array optimizations. */
  44554. var LARGE_ARRAY_SIZE = 200;
  44555. /** Used to stand-in for `undefined` hash values. */
  44556. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  44557. /** Used to compose bitmasks for value comparisons. */
  44558. var COMPARE_PARTIAL_FLAG = 1,
  44559. COMPARE_UNORDERED_FLAG = 2;
  44560. /** Used as references for various `Number` constants. */
  44561. var MAX_SAFE_INTEGER = 9007199254740991;
  44562. /** `Object#toString` result references. */
  44563. var argsTag = '[object Arguments]',
  44564. arrayTag = '[object Array]',
  44565. asyncTag = '[object AsyncFunction]',
  44566. boolTag = '[object Boolean]',
  44567. dateTag = '[object Date]',
  44568. errorTag = '[object Error]',
  44569. funcTag = '[object Function]',
  44570. genTag = '[object GeneratorFunction]',
  44571. mapTag = '[object Map]',
  44572. numberTag = '[object Number]',
  44573. nullTag = '[object Null]',
  44574. objectTag = '[object Object]',
  44575. promiseTag = '[object Promise]',
  44576. proxyTag = '[object Proxy]',
  44577. regexpTag = '[object RegExp]',
  44578. setTag = '[object Set]',
  44579. stringTag = '[object String]',
  44580. symbolTag = '[object Symbol]',
  44581. undefinedTag = '[object Undefined]',
  44582. weakMapTag = '[object WeakMap]';
  44583. var arrayBufferTag = '[object ArrayBuffer]',
  44584. dataViewTag = '[object DataView]',
  44585. float32Tag = '[object Float32Array]',
  44586. float64Tag = '[object Float64Array]',
  44587. int8Tag = '[object Int8Array]',
  44588. int16Tag = '[object Int16Array]',
  44589. int32Tag = '[object Int32Array]',
  44590. uint8Tag = '[object Uint8Array]',
  44591. uint8ClampedTag = '[object Uint8ClampedArray]',
  44592. uint16Tag = '[object Uint16Array]',
  44593. uint32Tag = '[object Uint32Array]';
  44594. /**
  44595. * Used to match `RegExp`
  44596. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  44597. */
  44598. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  44599. /** Used to detect host constructors (Safari). */
  44600. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  44601. /** Used to detect unsigned integer values. */
  44602. var reIsUint = /^(?:0|[1-9]\d*)$/;
  44603. /** Used to identify `toStringTag` values of typed arrays. */
  44604. var typedArrayTags = {};
  44605. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = typedArrayTags[uint32Tag] = true;
  44606. 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;
  44607. /** Detect free variable `global` from Node.js. */
  44608. var freeGlobal = (typeof global === "undefined" ? "undefined" : _typeof(global)) == 'object' && global && global.Object === Object && global;
  44609. /** Detect free variable `self`. */
  44610. var freeSelf = (typeof self === "undefined" ? "undefined" : _typeof(self)) == 'object' && self && self.Object === Object && self;
  44611. /** Used as a reference to the global object. */
  44612. var root = freeGlobal || freeSelf || Function('return this')();
  44613. /** Detect free variable `exports`. */
  44614. var freeExports = (typeof exports === "undefined" ? "undefined" : _typeof(exports)) == 'object' && exports && !exports.nodeType && exports;
  44615. /** Detect free variable `module`. */
  44616. var freeModule = freeExports && (typeof module === "undefined" ? "undefined" : _typeof(module)) == 'object' && module && !module.nodeType && module;
  44617. /** Detect the popular CommonJS extension `module.exports`. */
  44618. var moduleExports = freeModule && freeModule.exports === freeExports;
  44619. /** Detect free variable `process` from Node.js. */
  44620. var freeProcess = moduleExports && freeGlobal.process;
  44621. /** Used to access faster Node.js helpers. */
  44622. var nodeUtil = function () {
  44623. try {
  44624. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  44625. } catch (e) {}
  44626. }();
  44627. /* Node.js helper references. */
  44628. var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  44629. /**
  44630. * A specialized version of `_.filter` for arrays without support for
  44631. * iteratee shorthands.
  44632. *
  44633. * @private
  44634. * @param {Array} [array] The array to iterate over.
  44635. * @param {Function} predicate The function invoked per iteration.
  44636. * @returns {Array} Returns the new filtered array.
  44637. */
  44638. function arrayFilter(array, predicate) {
  44639. var index = -1,
  44640. length = array == null ? 0 : array.length,
  44641. resIndex = 0,
  44642. result = [];
  44643. while (++index < length) {
  44644. var value = array[index];
  44645. if (predicate(value, index, array)) {
  44646. result[resIndex++] = value;
  44647. }
  44648. }
  44649. return result;
  44650. }
  44651. /**
  44652. * Appends the elements of `values` to `array`.
  44653. *
  44654. * @private
  44655. * @param {Array} array The array to modify.
  44656. * @param {Array} values The values to append.
  44657. * @returns {Array} Returns `array`.
  44658. */
  44659. function arrayPush(array, values) {
  44660. var index = -1,
  44661. length = values.length,
  44662. offset = array.length;
  44663. while (++index < length) {
  44664. array[offset + index] = values[index];
  44665. }
  44666. return array;
  44667. }
  44668. /**
  44669. * A specialized version of `_.some` for arrays without support for iteratee
  44670. * shorthands.
  44671. *
  44672. * @private
  44673. * @param {Array} [array] The array to iterate over.
  44674. * @param {Function} predicate The function invoked per iteration.
  44675. * @returns {boolean} Returns `true` if any element passes the predicate check,
  44676. * else `false`.
  44677. */
  44678. function arraySome(array, predicate) {
  44679. var index = -1,
  44680. length = array == null ? 0 : array.length;
  44681. while (++index < length) {
  44682. if (predicate(array[index], index, array)) {
  44683. return true;
  44684. }
  44685. }
  44686. return false;
  44687. }
  44688. /**
  44689. * The base implementation of `_.times` without support for iteratee shorthands
  44690. * or max array length checks.
  44691. *
  44692. * @private
  44693. * @param {number} n The number of times to invoke `iteratee`.
  44694. * @param {Function} iteratee The function invoked per iteration.
  44695. * @returns {Array} Returns the array of results.
  44696. */
  44697. function baseTimes(n, iteratee) {
  44698. var index = -1,
  44699. result = Array(n);
  44700. while (++index < n) {
  44701. result[index] = iteratee(index);
  44702. }
  44703. return result;
  44704. }
  44705. /**
  44706. * The base implementation of `_.unary` without support for storing metadata.
  44707. *
  44708. * @private
  44709. * @param {Function} func The function to cap arguments for.
  44710. * @returns {Function} Returns the new capped function.
  44711. */
  44712. function baseUnary(func) {
  44713. return function (value) {
  44714. return func(value);
  44715. };
  44716. }
  44717. /**
  44718. * Checks if a `cache` value for `key` exists.
  44719. *
  44720. * @private
  44721. * @param {Object} cache The cache to query.
  44722. * @param {string} key The key of the entry to check.
  44723. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  44724. */
  44725. function cacheHas(cache, key) {
  44726. return cache.has(key);
  44727. }
  44728. /**
  44729. * Gets the value at `key` of `object`.
  44730. *
  44731. * @private
  44732. * @param {Object} [object] The object to query.
  44733. * @param {string} key The key of the property to get.
  44734. * @returns {*} Returns the property value.
  44735. */
  44736. function getValue(object, key) {
  44737. return object == null ? undefined : object[key];
  44738. }
  44739. /**
  44740. * Converts `map` to its key-value pairs.
  44741. *
  44742. * @private
  44743. * @param {Object} map The map to convert.
  44744. * @returns {Array} Returns the key-value pairs.
  44745. */
  44746. function mapToArray(map) {
  44747. var index = -1,
  44748. result = Array(map.size);
  44749. map.forEach(function (value, key) {
  44750. result[++index] = [key, value];
  44751. });
  44752. return result;
  44753. }
  44754. /**
  44755. * Creates a unary function that invokes `func` with its argument transformed.
  44756. *
  44757. * @private
  44758. * @param {Function} func The function to wrap.
  44759. * @param {Function} transform The argument transform.
  44760. * @returns {Function} Returns the new function.
  44761. */
  44762. function overArg(func, transform) {
  44763. return function (arg) {
  44764. return func(transform(arg));
  44765. };
  44766. }
  44767. /**
  44768. * Converts `set` to an array of its values.
  44769. *
  44770. * @private
  44771. * @param {Object} set The set to convert.
  44772. * @returns {Array} Returns the values.
  44773. */
  44774. function setToArray(set) {
  44775. var index = -1,
  44776. result = Array(set.size);
  44777. set.forEach(function (value) {
  44778. result[++index] = value;
  44779. });
  44780. return result;
  44781. }
  44782. /** Used for built-in method references. */
  44783. var arrayProto = Array.prototype,
  44784. funcProto = Function.prototype,
  44785. objectProto = Object.prototype;
  44786. /** Used to detect overreaching core-js shims. */
  44787. var coreJsData = root['__core-js_shared__'];
  44788. /** Used to resolve the decompiled source of functions. */
  44789. var funcToString = funcProto.toString;
  44790. /** Used to check objects for own properties. */
  44791. var hasOwnProperty = objectProto.hasOwnProperty;
  44792. /** Used to detect methods masquerading as native. */
  44793. var maskSrcKey = function () {
  44794. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  44795. return uid ? 'Symbol(src)_1.' + uid : '';
  44796. }();
  44797. /**
  44798. * Used to resolve the
  44799. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  44800. * of values.
  44801. */
  44802. var nativeObjectToString = objectProto.toString;
  44803. /** Used to detect if a method is native. */
  44804. var reIsNative = RegExp('^' + funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
  44805. /** Built-in value references. */
  44806. var Buffer = moduleExports ? root.Buffer : undefined,
  44807. _Symbol = root.Symbol,
  44808. Uint8Array = root.Uint8Array,
  44809. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  44810. splice = arrayProto.splice,
  44811. symToStringTag = _Symbol ? _Symbol.toStringTag : undefined;
  44812. /* Built-in method references for those with the same name as other `lodash` methods. */
  44813. var nativeGetSymbols = Object.getOwnPropertySymbols,
  44814. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  44815. nativeKeys = overArg(Object.keys, Object);
  44816. /* Built-in method references that are verified to be native. */
  44817. var DataView = getNative(root, 'DataView'),
  44818. Map = getNative(root, 'Map'),
  44819. Promise = getNative(root, 'Promise'),
  44820. Set = getNative(root, 'Set'),
  44821. WeakMap = getNative(root, 'WeakMap'),
  44822. nativeCreate = getNative(Object, 'create');
  44823. /** Used to detect maps, sets, and weakmaps. */
  44824. var dataViewCtorString = toSource(DataView),
  44825. mapCtorString = toSource(Map),
  44826. promiseCtorString = toSource(Promise),
  44827. setCtorString = toSource(Set),
  44828. weakMapCtorString = toSource(WeakMap);
  44829. /** Used to convert symbols to primitives and strings. */
  44830. var symbolProto = _Symbol ? _Symbol.prototype : undefined,
  44831. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
  44832. /**
  44833. * Creates a hash object.
  44834. *
  44835. * @private
  44836. * @constructor
  44837. * @param {Array} [entries] The key-value pairs to cache.
  44838. */
  44839. function Hash(entries) {
  44840. var index = -1,
  44841. length = entries == null ? 0 : entries.length;
  44842. this.clear();
  44843. while (++index < length) {
  44844. var entry = entries[index];
  44845. this.set(entry[0], entry[1]);
  44846. }
  44847. }
  44848. /**
  44849. * Removes all key-value entries from the hash.
  44850. *
  44851. * @private
  44852. * @name clear
  44853. * @memberOf Hash
  44854. */
  44855. function hashClear() {
  44856. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  44857. this.size = 0;
  44858. }
  44859. /**
  44860. * Removes `key` and its value from the hash.
  44861. *
  44862. * @private
  44863. * @name delete
  44864. * @memberOf Hash
  44865. * @param {Object} hash The hash to modify.
  44866. * @param {string} key The key of the value to remove.
  44867. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  44868. */
  44869. function hashDelete(key) {
  44870. var result = this.has(key) && delete this.__data__[key];
  44871. this.size -= result ? 1 : 0;
  44872. return result;
  44873. }
  44874. /**
  44875. * Gets the hash value for `key`.
  44876. *
  44877. * @private
  44878. * @name get
  44879. * @memberOf Hash
  44880. * @param {string} key The key of the value to get.
  44881. * @returns {*} Returns the entry value.
  44882. */
  44883. function hashGet(key) {
  44884. var data = this.__data__;
  44885. if (nativeCreate) {
  44886. var result = data[key];
  44887. return result === HASH_UNDEFINED ? undefined : result;
  44888. }
  44889. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  44890. }
  44891. /**
  44892. * Checks if a hash value for `key` exists.
  44893. *
  44894. * @private
  44895. * @name has
  44896. * @memberOf Hash
  44897. * @param {string} key The key of the entry to check.
  44898. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  44899. */
  44900. function hashHas(key) {
  44901. var data = this.__data__;
  44902. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  44903. }
  44904. /**
  44905. * Sets the hash `key` to `value`.
  44906. *
  44907. * @private
  44908. * @name set
  44909. * @memberOf Hash
  44910. * @param {string} key The key of the value to set.
  44911. * @param {*} value The value to set.
  44912. * @returns {Object} Returns the hash instance.
  44913. */
  44914. function hashSet(key, value) {
  44915. var data = this.__data__;
  44916. this.size += this.has(key) ? 0 : 1;
  44917. data[key] = nativeCreate && value === undefined ? HASH_UNDEFINED : value;
  44918. return this;
  44919. } // Add methods to `Hash`.
  44920. Hash.prototype.clear = hashClear;
  44921. Hash.prototype['delete'] = hashDelete;
  44922. Hash.prototype.get = hashGet;
  44923. Hash.prototype.has = hashHas;
  44924. Hash.prototype.set = hashSet;
  44925. /**
  44926. * Creates an list cache object.
  44927. *
  44928. * @private
  44929. * @constructor
  44930. * @param {Array} [entries] The key-value pairs to cache.
  44931. */
  44932. function ListCache(entries) {
  44933. var index = -1,
  44934. length = entries == null ? 0 : entries.length;
  44935. this.clear();
  44936. while (++index < length) {
  44937. var entry = entries[index];
  44938. this.set(entry[0], entry[1]);
  44939. }
  44940. }
  44941. /**
  44942. * Removes all key-value entries from the list cache.
  44943. *
  44944. * @private
  44945. * @name clear
  44946. * @memberOf ListCache
  44947. */
  44948. function listCacheClear() {
  44949. this.__data__ = [];
  44950. this.size = 0;
  44951. }
  44952. /**
  44953. * Removes `key` and its value from the list cache.
  44954. *
  44955. * @private
  44956. * @name delete
  44957. * @memberOf ListCache
  44958. * @param {string} key The key of the value to remove.
  44959. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  44960. */
  44961. function listCacheDelete(key) {
  44962. var data = this.__data__,
  44963. index = assocIndexOf(data, key);
  44964. if (index < 0) {
  44965. return false;
  44966. }
  44967. var lastIndex = data.length - 1;
  44968. if (index == lastIndex) {
  44969. data.pop();
  44970. } else {
  44971. splice.call(data, index, 1);
  44972. }
  44973. --this.size;
  44974. return true;
  44975. }
  44976. /**
  44977. * Gets the list cache value for `key`.
  44978. *
  44979. * @private
  44980. * @name get
  44981. * @memberOf ListCache
  44982. * @param {string} key The key of the value to get.
  44983. * @returns {*} Returns the entry value.
  44984. */
  44985. function listCacheGet(key) {
  44986. var data = this.__data__,
  44987. index = assocIndexOf(data, key);
  44988. return index < 0 ? undefined : data[index][1];
  44989. }
  44990. /**
  44991. * Checks if a list cache value for `key` exists.
  44992. *
  44993. * @private
  44994. * @name has
  44995. * @memberOf ListCache
  44996. * @param {string} key The key of the entry to check.
  44997. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  44998. */
  44999. function listCacheHas(key) {
  45000. return assocIndexOf(this.__data__, key) > -1;
  45001. }
  45002. /**
  45003. * Sets the list cache `key` to `value`.
  45004. *
  45005. * @private
  45006. * @name set
  45007. * @memberOf ListCache
  45008. * @param {string} key The key of the value to set.
  45009. * @param {*} value The value to set.
  45010. * @returns {Object} Returns the list cache instance.
  45011. */
  45012. function listCacheSet(key, value) {
  45013. var data = this.__data__,
  45014. index = assocIndexOf(data, key);
  45015. if (index < 0) {
  45016. ++this.size;
  45017. data.push([key, value]);
  45018. } else {
  45019. data[index][1] = value;
  45020. }
  45021. return this;
  45022. } // Add methods to `ListCache`.
  45023. ListCache.prototype.clear = listCacheClear;
  45024. ListCache.prototype['delete'] = listCacheDelete;
  45025. ListCache.prototype.get = listCacheGet;
  45026. ListCache.prototype.has = listCacheHas;
  45027. ListCache.prototype.set = listCacheSet;
  45028. /**
  45029. * Creates a map cache object to store key-value pairs.
  45030. *
  45031. * @private
  45032. * @constructor
  45033. * @param {Array} [entries] The key-value pairs to cache.
  45034. */
  45035. function MapCache(entries) {
  45036. var index = -1,
  45037. length = entries == null ? 0 : entries.length;
  45038. this.clear();
  45039. while (++index < length) {
  45040. var entry = entries[index];
  45041. this.set(entry[0], entry[1]);
  45042. }
  45043. }
  45044. /**
  45045. * Removes all key-value entries from the map.
  45046. *
  45047. * @private
  45048. * @name clear
  45049. * @memberOf MapCache
  45050. */
  45051. function mapCacheClear() {
  45052. this.size = 0;
  45053. this.__data__ = {
  45054. 'hash': new Hash(),
  45055. 'map': new (Map || ListCache)(),
  45056. 'string': new Hash()
  45057. };
  45058. }
  45059. /**
  45060. * Removes `key` and its value from the map.
  45061. *
  45062. * @private
  45063. * @name delete
  45064. * @memberOf MapCache
  45065. * @param {string} key The key of the value to remove.
  45066. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  45067. */
  45068. function mapCacheDelete(key) {
  45069. var result = getMapData(this, key)['delete'](key);
  45070. this.size -= result ? 1 : 0;
  45071. return result;
  45072. }
  45073. /**
  45074. * Gets the map value for `key`.
  45075. *
  45076. * @private
  45077. * @name get
  45078. * @memberOf MapCache
  45079. * @param {string} key The key of the value to get.
  45080. * @returns {*} Returns the entry value.
  45081. */
  45082. function mapCacheGet(key) {
  45083. return getMapData(this, key).get(key);
  45084. }
  45085. /**
  45086. * Checks if a map value for `key` exists.
  45087. *
  45088. * @private
  45089. * @name has
  45090. * @memberOf MapCache
  45091. * @param {string} key The key of the entry to check.
  45092. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  45093. */
  45094. function mapCacheHas(key) {
  45095. return getMapData(this, key).has(key);
  45096. }
  45097. /**
  45098. * Sets the map `key` to `value`.
  45099. *
  45100. * @private
  45101. * @name set
  45102. * @memberOf MapCache
  45103. * @param {string} key The key of the value to set.
  45104. * @param {*} value The value to set.
  45105. * @returns {Object} Returns the map cache instance.
  45106. */
  45107. function mapCacheSet(key, value) {
  45108. var data = getMapData(this, key),
  45109. size = data.size;
  45110. data.set(key, value);
  45111. this.size += data.size == size ? 0 : 1;
  45112. return this;
  45113. } // Add methods to `MapCache`.
  45114. MapCache.prototype.clear = mapCacheClear;
  45115. MapCache.prototype['delete'] = mapCacheDelete;
  45116. MapCache.prototype.get = mapCacheGet;
  45117. MapCache.prototype.has = mapCacheHas;
  45118. MapCache.prototype.set = mapCacheSet;
  45119. /**
  45120. *
  45121. * Creates an array cache object to store unique values.
  45122. *
  45123. * @private
  45124. * @constructor
  45125. * @param {Array} [values] The values to cache.
  45126. */
  45127. function SetCache(values) {
  45128. var index = -1,
  45129. length = values == null ? 0 : values.length;
  45130. this.__data__ = new MapCache();
  45131. while (++index < length) {
  45132. this.add(values[index]);
  45133. }
  45134. }
  45135. /**
  45136. * Adds `value` to the array cache.
  45137. *
  45138. * @private
  45139. * @name add
  45140. * @memberOf SetCache
  45141. * @alias push
  45142. * @param {*} value The value to cache.
  45143. * @returns {Object} Returns the cache instance.
  45144. */
  45145. function setCacheAdd(value) {
  45146. this.__data__.set(value, HASH_UNDEFINED);
  45147. return this;
  45148. }
  45149. /**
  45150. * Checks if `value` is in the array cache.
  45151. *
  45152. * @private
  45153. * @name has
  45154. * @memberOf SetCache
  45155. * @param {*} value The value to search for.
  45156. * @returns {number} Returns `true` if `value` is found, else `false`.
  45157. */
  45158. function setCacheHas(value) {
  45159. return this.__data__.has(value);
  45160. } // Add methods to `SetCache`.
  45161. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  45162. SetCache.prototype.has = setCacheHas;
  45163. /**
  45164. * Creates a stack cache object to store key-value pairs.
  45165. *
  45166. * @private
  45167. * @constructor
  45168. * @param {Array} [entries] The key-value pairs to cache.
  45169. */
  45170. function Stack(entries) {
  45171. var data = this.__data__ = new ListCache(entries);
  45172. this.size = data.size;
  45173. }
  45174. /**
  45175. * Removes all key-value entries from the stack.
  45176. *
  45177. * @private
  45178. * @name clear
  45179. * @memberOf Stack
  45180. */
  45181. function stackClear() {
  45182. this.__data__ = new ListCache();
  45183. this.size = 0;
  45184. }
  45185. /**
  45186. * Removes `key` and its value from the stack.
  45187. *
  45188. * @private
  45189. * @name delete
  45190. * @memberOf Stack
  45191. * @param {string} key The key of the value to remove.
  45192. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  45193. */
  45194. function stackDelete(key) {
  45195. var data = this.__data__,
  45196. result = data['delete'](key);
  45197. this.size = data.size;
  45198. return result;
  45199. }
  45200. /**
  45201. * Gets the stack value for `key`.
  45202. *
  45203. * @private
  45204. * @name get
  45205. * @memberOf Stack
  45206. * @param {string} key The key of the value to get.
  45207. * @returns {*} Returns the entry value.
  45208. */
  45209. function stackGet(key) {
  45210. return this.__data__.get(key);
  45211. }
  45212. /**
  45213. * Checks if a stack value for `key` exists.
  45214. *
  45215. * @private
  45216. * @name has
  45217. * @memberOf Stack
  45218. * @param {string} key The key of the entry to check.
  45219. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  45220. */
  45221. function stackHas(key) {
  45222. return this.__data__.has(key);
  45223. }
  45224. /**
  45225. * Sets the stack `key` to `value`.
  45226. *
  45227. * @private
  45228. * @name set
  45229. * @memberOf Stack
  45230. * @param {string} key The key of the value to set.
  45231. * @param {*} value The value to set.
  45232. * @returns {Object} Returns the stack cache instance.
  45233. */
  45234. function stackSet(key, value) {
  45235. var data = this.__data__;
  45236. if (data instanceof ListCache) {
  45237. var pairs = data.__data__;
  45238. if (!Map || pairs.length < LARGE_ARRAY_SIZE - 1) {
  45239. pairs.push([key, value]);
  45240. this.size = ++data.size;
  45241. return this;
  45242. }
  45243. data = this.__data__ = new MapCache(pairs);
  45244. }
  45245. data.set(key, value);
  45246. this.size = data.size;
  45247. return this;
  45248. } // Add methods to `Stack`.
  45249. Stack.prototype.clear = stackClear;
  45250. Stack.prototype['delete'] = stackDelete;
  45251. Stack.prototype.get = stackGet;
  45252. Stack.prototype.has = stackHas;
  45253. Stack.prototype.set = stackSet;
  45254. /**
  45255. * Creates an array of the enumerable property names of the array-like `value`.
  45256. *
  45257. * @private
  45258. * @param {*} value The value to query.
  45259. * @param {boolean} inherited Specify returning inherited property names.
  45260. * @returns {Array} Returns the array of property names.
  45261. */
  45262. function arrayLikeKeys(value, inherited) {
  45263. var isArr = isArray(value),
  45264. isArg = !isArr && isArguments(value),
  45265. isBuff = !isArr && !isArg && isBuffer(value),
  45266. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  45267. skipIndexes = isArr || isArg || isBuff || isType,
  45268. result = skipIndexes ? baseTimes(value.length, String) : [],
  45269. length = result.length;
  45270. for (var key in value) {
  45271. if ((inherited || hasOwnProperty.call(value, key)) && !(skipIndexes && ( // Safari 9 has enumerable `arguments.length` in strict mode.
  45272. key == 'length' || // Node.js 0.10 has enumerable non-index properties on buffers.
  45273. isBuff && (key == 'offset' || key == 'parent') || // PhantomJS 2 has enumerable non-index properties on typed arrays.
  45274. isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset') || // Skip index properties.
  45275. isIndex(key, length)))) {
  45276. result.push(key);
  45277. }
  45278. }
  45279. return result;
  45280. }
  45281. /**
  45282. * Gets the index at which the `key` is found in `array` of key-value pairs.
  45283. *
  45284. * @private
  45285. * @param {Array} array The array to inspect.
  45286. * @param {*} key The key to search for.
  45287. * @returns {number} Returns the index of the matched value, else `-1`.
  45288. */
  45289. function assocIndexOf(array, key) {
  45290. var length = array.length;
  45291. while (length--) {
  45292. if (eq(array[length][0], key)) {
  45293. return length;
  45294. }
  45295. }
  45296. return -1;
  45297. }
  45298. /**
  45299. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  45300. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  45301. * symbols of `object`.
  45302. *
  45303. * @private
  45304. * @param {Object} object The object to query.
  45305. * @param {Function} keysFunc The function to get the keys of `object`.
  45306. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  45307. * @returns {Array} Returns the array of property names and symbols.
  45308. */
  45309. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  45310. var result = keysFunc(object);
  45311. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  45312. }
  45313. /**
  45314. * The base implementation of `getTag` without fallbacks for buggy environments.
  45315. *
  45316. * @private
  45317. * @param {*} value The value to query.
  45318. * @returns {string} Returns the `toStringTag`.
  45319. */
  45320. function baseGetTag(value) {
  45321. if (value == null) {
  45322. return value === undefined ? undefinedTag : nullTag;
  45323. }
  45324. return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
  45325. }
  45326. /**
  45327. * The base implementation of `_.isArguments`.
  45328. *
  45329. * @private
  45330. * @param {*} value The value to check.
  45331. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  45332. */
  45333. function baseIsArguments(value) {
  45334. return isObjectLike(value) && baseGetTag(value) == argsTag;
  45335. }
  45336. /**
  45337. * The base implementation of `_.isEqual` which supports partial comparisons
  45338. * and tracks traversed objects.
  45339. *
  45340. * @private
  45341. * @param {*} value The value to compare.
  45342. * @param {*} other The other value to compare.
  45343. * @param {boolean} bitmask The bitmask flags.
  45344. * 1 - Unordered comparison
  45345. * 2 - Partial comparison
  45346. * @param {Function} [customizer] The function to customize comparisons.
  45347. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  45348. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  45349. */
  45350. function baseIsEqual(value, other, bitmask, customizer, stack) {
  45351. if (value === other) {
  45352. return true;
  45353. }
  45354. if (value == null || other == null || !isObjectLike(value) && !isObjectLike(other)) {
  45355. return value !== value && other !== other;
  45356. }
  45357. return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  45358. }
  45359. /**
  45360. * A specialized version of `baseIsEqual` for arrays and objects which performs
  45361. * deep comparisons and tracks traversed objects enabling objects with circular
  45362. * references to be compared.
  45363. *
  45364. * @private
  45365. * @param {Object} object The object to compare.
  45366. * @param {Object} other The other object to compare.
  45367. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  45368. * @param {Function} customizer The function to customize comparisons.
  45369. * @param {Function} equalFunc The function to determine equivalents of values.
  45370. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  45371. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  45372. */
  45373. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  45374. var objIsArr = isArray(object),
  45375. othIsArr = isArray(other),
  45376. objTag = objIsArr ? arrayTag : getTag(object),
  45377. othTag = othIsArr ? arrayTag : getTag(other);
  45378. objTag = objTag == argsTag ? objectTag : objTag;
  45379. othTag = othTag == argsTag ? objectTag : othTag;
  45380. var objIsObj = objTag == objectTag,
  45381. othIsObj = othTag == objectTag,
  45382. isSameTag = objTag == othTag;
  45383. if (isSameTag && isBuffer(object)) {
  45384. if (!isBuffer(other)) {
  45385. return false;
  45386. }
  45387. objIsArr = true;
  45388. objIsObj = false;
  45389. }
  45390. if (isSameTag && !objIsObj) {
  45391. stack || (stack = new Stack());
  45392. return objIsArr || isTypedArray(object) ? equalArrays(object, other, bitmask, customizer, equalFunc, stack) : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  45393. }
  45394. if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
  45395. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  45396. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  45397. if (objIsWrapped || othIsWrapped) {
  45398. var objUnwrapped = objIsWrapped ? object.value() : object,
  45399. othUnwrapped = othIsWrapped ? other.value() : other;
  45400. stack || (stack = new Stack());
  45401. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  45402. }
  45403. }
  45404. if (!isSameTag) {
  45405. return false;
  45406. }
  45407. stack || (stack = new Stack());
  45408. return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  45409. }
  45410. /**
  45411. * The base implementation of `_.isNative` without bad shim checks.
  45412. *
  45413. * @private
  45414. * @param {*} value The value to check.
  45415. * @returns {boolean} Returns `true` if `value` is a native function,
  45416. * else `false`.
  45417. */
  45418. function baseIsNative(value) {
  45419. if (!isObject(value) || isMasked(value)) {
  45420. return false;
  45421. }
  45422. var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  45423. return pattern.test(toSource(value));
  45424. }
  45425. /**
  45426. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  45427. *
  45428. * @private
  45429. * @param {*} value The value to check.
  45430. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  45431. */
  45432. function baseIsTypedArray(value) {
  45433. return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
  45434. }
  45435. /**
  45436. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  45437. *
  45438. * @private
  45439. * @param {Object} object The object to query.
  45440. * @returns {Array} Returns the array of property names.
  45441. */
  45442. function baseKeys(object) {
  45443. if (!isPrototype(object)) {
  45444. return nativeKeys(object);
  45445. }
  45446. var result = [];
  45447. for (var key in Object(object)) {
  45448. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  45449. result.push(key);
  45450. }
  45451. }
  45452. return result;
  45453. }
  45454. /**
  45455. * A specialized version of `baseIsEqualDeep` for arrays with support for
  45456. * partial deep comparisons.
  45457. *
  45458. * @private
  45459. * @param {Array} array The array to compare.
  45460. * @param {Array} other The other array to compare.
  45461. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  45462. * @param {Function} customizer The function to customize comparisons.
  45463. * @param {Function} equalFunc The function to determine equivalents of values.
  45464. * @param {Object} stack Tracks traversed `array` and `other` objects.
  45465. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  45466. */
  45467. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  45468. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  45469. arrLength = array.length,
  45470. othLength = other.length;
  45471. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  45472. return false;
  45473. } // Assume cyclic values are equal.
  45474. var stacked = stack.get(array);
  45475. if (stacked && stack.get(other)) {
  45476. return stacked == other;
  45477. }
  45478. var index = -1,
  45479. result = true,
  45480. seen = bitmask & COMPARE_UNORDERED_FLAG ? new SetCache() : undefined;
  45481. stack.set(array, other);
  45482. stack.set(other, array); // Ignore non-index properties.
  45483. while (++index < arrLength) {
  45484. var arrValue = array[index],
  45485. othValue = other[index];
  45486. if (customizer) {
  45487. var compared = isPartial ? customizer(othValue, arrValue, index, other, array, stack) : customizer(arrValue, othValue, index, array, other, stack);
  45488. }
  45489. if (compared !== undefined) {
  45490. if (compared) {
  45491. continue;
  45492. }
  45493. result = false;
  45494. break;
  45495. } // Recursively compare arrays (susceptible to call stack limits).
  45496. if (seen) {
  45497. if (!arraySome(other, function (othValue, othIndex) {
  45498. if (!cacheHas(seen, othIndex) && (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  45499. return seen.push(othIndex);
  45500. }
  45501. })) {
  45502. result = false;
  45503. break;
  45504. }
  45505. } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  45506. result = false;
  45507. break;
  45508. }
  45509. }
  45510. stack['delete'](array);
  45511. stack['delete'](other);
  45512. return result;
  45513. }
  45514. /**
  45515. * A specialized version of `baseIsEqualDeep` for comparing objects of
  45516. * the same `toStringTag`.
  45517. *
  45518. * **Note:** This function only supports comparing values with tags of
  45519. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  45520. *
  45521. * @private
  45522. * @param {Object} object The object to compare.
  45523. * @param {Object} other The other object to compare.
  45524. * @param {string} tag The `toStringTag` of the objects to compare.
  45525. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  45526. * @param {Function} customizer The function to customize comparisons.
  45527. * @param {Function} equalFunc The function to determine equivalents of values.
  45528. * @param {Object} stack Tracks traversed `object` and `other` objects.
  45529. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  45530. */
  45531. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  45532. switch (tag) {
  45533. case dataViewTag:
  45534. if (object.byteLength != other.byteLength || object.byteOffset != other.byteOffset) {
  45535. return false;
  45536. }
  45537. object = object.buffer;
  45538. other = other.buffer;
  45539. case arrayBufferTag:
  45540. if (object.byteLength != other.byteLength || !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  45541. return false;
  45542. }
  45543. return true;
  45544. case boolTag:
  45545. case dateTag:
  45546. case numberTag:
  45547. // Coerce booleans to `1` or `0` and dates to milliseconds.
  45548. // Invalid dates are coerced to `NaN`.
  45549. return eq(+object, +other);
  45550. case errorTag:
  45551. return object.name == other.name && object.message == other.message;
  45552. case regexpTag:
  45553. case stringTag:
  45554. // Coerce regexes to strings and treat strings, primitives and objects,
  45555. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  45556. // for more details.
  45557. return object == other + '';
  45558. case mapTag:
  45559. var convert = mapToArray;
  45560. case setTag:
  45561. var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
  45562. convert || (convert = setToArray);
  45563. if (object.size != other.size && !isPartial) {
  45564. return false;
  45565. } // Assume cyclic values are equal.
  45566. var stacked = stack.get(object);
  45567. if (stacked) {
  45568. return stacked == other;
  45569. }
  45570. bitmask |= COMPARE_UNORDERED_FLAG; // Recursively compare objects (susceptible to call stack limits).
  45571. stack.set(object, other);
  45572. var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  45573. stack['delete'](object);
  45574. return result;
  45575. case symbolTag:
  45576. if (symbolValueOf) {
  45577. return symbolValueOf.call(object) == symbolValueOf.call(other);
  45578. }
  45579. }
  45580. return false;
  45581. }
  45582. /**
  45583. * A specialized version of `baseIsEqualDeep` for objects with support for
  45584. * partial deep comparisons.
  45585. *
  45586. * @private
  45587. * @param {Object} object The object to compare.
  45588. * @param {Object} other The other object to compare.
  45589. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  45590. * @param {Function} customizer The function to customize comparisons.
  45591. * @param {Function} equalFunc The function to determine equivalents of values.
  45592. * @param {Object} stack Tracks traversed `object` and `other` objects.
  45593. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  45594. */
  45595. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  45596. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  45597. objProps = getAllKeys(object),
  45598. objLength = objProps.length,
  45599. othProps = getAllKeys(other),
  45600. othLength = othProps.length;
  45601. if (objLength != othLength && !isPartial) {
  45602. return false;
  45603. }
  45604. var index = objLength;
  45605. while (index--) {
  45606. var key = objProps[index];
  45607. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  45608. return false;
  45609. }
  45610. } // Assume cyclic values are equal.
  45611. var stacked = stack.get(object);
  45612. if (stacked && stack.get(other)) {
  45613. return stacked == other;
  45614. }
  45615. var result = true;
  45616. stack.set(object, other);
  45617. stack.set(other, object);
  45618. var skipCtor = isPartial;
  45619. while (++index < objLength) {
  45620. key = objProps[index];
  45621. var objValue = object[key],
  45622. othValue = other[key];
  45623. if (customizer) {
  45624. var compared = isPartial ? customizer(othValue, objValue, key, other, object, stack) : customizer(objValue, othValue, key, object, other, stack);
  45625. } // Recursively compare objects (susceptible to call stack limits).
  45626. if (!(compared === undefined ? objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack) : compared)) {
  45627. result = false;
  45628. break;
  45629. }
  45630. skipCtor || (skipCtor = key == 'constructor');
  45631. }
  45632. if (result && !skipCtor) {
  45633. var objCtor = object.constructor,
  45634. othCtor = other.constructor; // Non `Object` object instances with different constructors are not equal.
  45635. if (objCtor != othCtor && 'constructor' in object && 'constructor' in other && !(typeof objCtor == 'function' && objCtor instanceof objCtor && typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  45636. result = false;
  45637. }
  45638. }
  45639. stack['delete'](object);
  45640. stack['delete'](other);
  45641. return result;
  45642. }
  45643. /**
  45644. * Creates an array of own enumerable property names and symbols of `object`.
  45645. *
  45646. * @private
  45647. * @param {Object} object The object to query.
  45648. * @returns {Array} Returns the array of property names and symbols.
  45649. */
  45650. function getAllKeys(object) {
  45651. return baseGetAllKeys(object, keys, getSymbols);
  45652. }
  45653. /**
  45654. * Gets the data for `map`.
  45655. *
  45656. * @private
  45657. * @param {Object} map The map to query.
  45658. * @param {string} key The reference key.
  45659. * @returns {*} Returns the map data.
  45660. */
  45661. function getMapData(map, key) {
  45662. var data = map.__data__;
  45663. return isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
  45664. }
  45665. /**
  45666. * Gets the native function at `key` of `object`.
  45667. *
  45668. * @private
  45669. * @param {Object} object The object to query.
  45670. * @param {string} key The key of the method to get.
  45671. * @returns {*} Returns the function if it's native, else `undefined`.
  45672. */
  45673. function getNative(object, key) {
  45674. var value = getValue(object, key);
  45675. return baseIsNative(value) ? value : undefined;
  45676. }
  45677. /**
  45678. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  45679. *
  45680. * @private
  45681. * @param {*} value The value to query.
  45682. * @returns {string} Returns the raw `toStringTag`.
  45683. */
  45684. function getRawTag(value) {
  45685. var isOwn = hasOwnProperty.call(value, symToStringTag),
  45686. tag = value[symToStringTag];
  45687. try {
  45688. value[symToStringTag] = undefined;
  45689. var unmasked = true;
  45690. } catch (e) {}
  45691. var result = nativeObjectToString.call(value);
  45692. if (unmasked) {
  45693. if (isOwn) {
  45694. value[symToStringTag] = tag;
  45695. } else {
  45696. delete value[symToStringTag];
  45697. }
  45698. }
  45699. return result;
  45700. }
  45701. /**
  45702. * Creates an array of the own enumerable symbols of `object`.
  45703. *
  45704. * @private
  45705. * @param {Object} object The object to query.
  45706. * @returns {Array} Returns the array of symbols.
  45707. */
  45708. var getSymbols = !nativeGetSymbols ? stubArray : function (object) {
  45709. if (object == null) {
  45710. return [];
  45711. }
  45712. object = Object(object);
  45713. return arrayFilter(nativeGetSymbols(object), function (symbol) {
  45714. return propertyIsEnumerable.call(object, symbol);
  45715. });
  45716. };
  45717. /**
  45718. * Gets the `toStringTag` of `value`.
  45719. *
  45720. * @private
  45721. * @param {*} value The value to query.
  45722. * @returns {string} Returns the `toStringTag`.
  45723. */
  45724. var getTag = baseGetTag; // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  45725. 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) {
  45726. getTag = function getTag(value) {
  45727. var result = baseGetTag(value),
  45728. Ctor = result == objectTag ? value.constructor : undefined,
  45729. ctorString = Ctor ? toSource(Ctor) : '';
  45730. if (ctorString) {
  45731. switch (ctorString) {
  45732. case dataViewCtorString:
  45733. return dataViewTag;
  45734. case mapCtorString:
  45735. return mapTag;
  45736. case promiseCtorString:
  45737. return promiseTag;
  45738. case setCtorString:
  45739. return setTag;
  45740. case weakMapCtorString:
  45741. return weakMapTag;
  45742. }
  45743. }
  45744. return result;
  45745. };
  45746. }
  45747. /**
  45748. * Checks if `value` is a valid array-like index.
  45749. *
  45750. * @private
  45751. * @param {*} value The value to check.
  45752. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  45753. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  45754. */
  45755. function isIndex(value, length) {
  45756. length = length == null ? MAX_SAFE_INTEGER : length;
  45757. return !!length && (typeof value == 'number' || reIsUint.test(value)) && value > -1 && value % 1 == 0 && value < length;
  45758. }
  45759. /**
  45760. * Checks if `value` is suitable for use as unique object key.
  45761. *
  45762. * @private
  45763. * @param {*} value The value to check.
  45764. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  45765. */
  45766. function isKeyable(value) {
  45767. var type = _typeof(value);
  45768. return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean' ? value !== '__proto__' : value === null;
  45769. }
  45770. /**
  45771. * Checks if `func` has its source masked.
  45772. *
  45773. * @private
  45774. * @param {Function} func The function to check.
  45775. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  45776. */
  45777. function isMasked(func) {
  45778. return !!maskSrcKey && maskSrcKey in func;
  45779. }
  45780. /**
  45781. * Checks if `value` is likely a prototype object.
  45782. *
  45783. * @private
  45784. * @param {*} value The value to check.
  45785. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  45786. */
  45787. function isPrototype(value) {
  45788. var Ctor = value && value.constructor,
  45789. proto = typeof Ctor == 'function' && Ctor.prototype || objectProto;
  45790. return value === proto;
  45791. }
  45792. /**
  45793. * Converts `value` to a string using `Object.prototype.toString`.
  45794. *
  45795. * @private
  45796. * @param {*} value The value to convert.
  45797. * @returns {string} Returns the converted string.
  45798. */
  45799. function objectToString(value) {
  45800. return nativeObjectToString.call(value);
  45801. }
  45802. /**
  45803. * Converts `func` to its source code.
  45804. *
  45805. * @private
  45806. * @param {Function} func The function to convert.
  45807. * @returns {string} Returns the source code.
  45808. */
  45809. function toSource(func) {
  45810. if (func != null) {
  45811. try {
  45812. return funcToString.call(func);
  45813. } catch (e) {}
  45814. try {
  45815. return func + '';
  45816. } catch (e) {}
  45817. }
  45818. return '';
  45819. }
  45820. /**
  45821. * Performs a
  45822. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  45823. * comparison between two values to determine if they are equivalent.
  45824. *
  45825. * @static
  45826. * @memberOf _
  45827. * @since 4.0.0
  45828. * @category Lang
  45829. * @param {*} value The value to compare.
  45830. * @param {*} other The other value to compare.
  45831. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  45832. * @example
  45833. *
  45834. * var object = { 'a': 1 };
  45835. * var other = { 'a': 1 };
  45836. *
  45837. * _.eq(object, object);
  45838. * // => true
  45839. *
  45840. * _.eq(object, other);
  45841. * // => false
  45842. *
  45843. * _.eq('a', 'a');
  45844. * // => true
  45845. *
  45846. * _.eq('a', Object('a'));
  45847. * // => false
  45848. *
  45849. * _.eq(NaN, NaN);
  45850. * // => true
  45851. */
  45852. function eq(value, other) {
  45853. return value === other || value !== value && other !== other;
  45854. }
  45855. /**
  45856. * Checks if `value` is likely an `arguments` object.
  45857. *
  45858. * @static
  45859. * @memberOf _
  45860. * @since 0.1.0
  45861. * @category Lang
  45862. * @param {*} value The value to check.
  45863. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  45864. * else `false`.
  45865. * @example
  45866. *
  45867. * _.isArguments(function() { return arguments; }());
  45868. * // => true
  45869. *
  45870. * _.isArguments([1, 2, 3]);
  45871. * // => false
  45872. */
  45873. var isArguments = baseIsArguments(function () {
  45874. return arguments;
  45875. }()) ? baseIsArguments : function (value) {
  45876. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
  45877. };
  45878. /**
  45879. * Checks if `value` is classified as an `Array` object.
  45880. *
  45881. * @static
  45882. * @memberOf _
  45883. * @since 0.1.0
  45884. * @category Lang
  45885. * @param {*} value The value to check.
  45886. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  45887. * @example
  45888. *
  45889. * _.isArray([1, 2, 3]);
  45890. * // => true
  45891. *
  45892. * _.isArray(document.body.children);
  45893. * // => false
  45894. *
  45895. * _.isArray('abc');
  45896. * // => false
  45897. *
  45898. * _.isArray(_.noop);
  45899. * // => false
  45900. */
  45901. var isArray = Array.isArray;
  45902. /**
  45903. * Checks if `value` is array-like. A value is considered array-like if it's
  45904. * not a function and has a `value.length` that's an integer greater than or
  45905. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  45906. *
  45907. * @static
  45908. * @memberOf _
  45909. * @since 4.0.0
  45910. * @category Lang
  45911. * @param {*} value The value to check.
  45912. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  45913. * @example
  45914. *
  45915. * _.isArrayLike([1, 2, 3]);
  45916. * // => true
  45917. *
  45918. * _.isArrayLike(document.body.children);
  45919. * // => true
  45920. *
  45921. * _.isArrayLike('abc');
  45922. * // => true
  45923. *
  45924. * _.isArrayLike(_.noop);
  45925. * // => false
  45926. */
  45927. function isArrayLike(value) {
  45928. return value != null && isLength(value.length) && !isFunction(value);
  45929. }
  45930. /**
  45931. * Checks if `value` is a buffer.
  45932. *
  45933. * @static
  45934. * @memberOf _
  45935. * @since 4.3.0
  45936. * @category Lang
  45937. * @param {*} value The value to check.
  45938. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  45939. * @example
  45940. *
  45941. * _.isBuffer(new Buffer(2));
  45942. * // => true
  45943. *
  45944. * _.isBuffer(new Uint8Array(2));
  45945. * // => false
  45946. */
  45947. var isBuffer = nativeIsBuffer || stubFalse;
  45948. /**
  45949. * Performs a deep comparison between two values to determine if they are
  45950. * equivalent.
  45951. *
  45952. * **Note:** This method supports comparing arrays, array buffers, booleans,
  45953. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  45954. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  45955. * by their own, not inherited, enumerable properties. Functions and DOM
  45956. * nodes are compared by strict equality, i.e. `===`.
  45957. *
  45958. * @static
  45959. * @memberOf _
  45960. * @since 0.1.0
  45961. * @category Lang
  45962. * @param {*} value The value to compare.
  45963. * @param {*} other The other value to compare.
  45964. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  45965. * @example
  45966. *
  45967. * var object = { 'a': 1 };
  45968. * var other = { 'a': 1 };
  45969. *
  45970. * _.isEqual(object, other);
  45971. * // => true
  45972. *
  45973. * object === other;
  45974. * // => false
  45975. */
  45976. function isEqual(value, other) {
  45977. return baseIsEqual(value, other);
  45978. }
  45979. /**
  45980. * Checks if `value` is classified as a `Function` object.
  45981. *
  45982. * @static
  45983. * @memberOf _
  45984. * @since 0.1.0
  45985. * @category Lang
  45986. * @param {*} value The value to check.
  45987. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  45988. * @example
  45989. *
  45990. * _.isFunction(_);
  45991. * // => true
  45992. *
  45993. * _.isFunction(/abc/);
  45994. * // => false
  45995. */
  45996. function isFunction(value) {
  45997. if (!isObject(value)) {
  45998. return false;
  45999. } // The use of `Object#toString` avoids issues with the `typeof` operator
  46000. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  46001. var tag = baseGetTag(value);
  46002. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  46003. }
  46004. /**
  46005. * Checks if `value` is a valid array-like length.
  46006. *
  46007. * **Note:** This method is loosely based on
  46008. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  46009. *
  46010. * @static
  46011. * @memberOf _
  46012. * @since 4.0.0
  46013. * @category Lang
  46014. * @param {*} value The value to check.
  46015. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  46016. * @example
  46017. *
  46018. * _.isLength(3);
  46019. * // => true
  46020. *
  46021. * _.isLength(Number.MIN_VALUE);
  46022. * // => false
  46023. *
  46024. * _.isLength(Infinity);
  46025. * // => false
  46026. *
  46027. * _.isLength('3');
  46028. * // => false
  46029. */
  46030. function isLength(value) {
  46031. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  46032. }
  46033. /**
  46034. * Checks if `value` is the
  46035. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  46036. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  46037. *
  46038. * @static
  46039. * @memberOf _
  46040. * @since 0.1.0
  46041. * @category Lang
  46042. * @param {*} value The value to check.
  46043. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  46044. * @example
  46045. *
  46046. * _.isObject({});
  46047. * // => true
  46048. *
  46049. * _.isObject([1, 2, 3]);
  46050. * // => true
  46051. *
  46052. * _.isObject(_.noop);
  46053. * // => true
  46054. *
  46055. * _.isObject(null);
  46056. * // => false
  46057. */
  46058. function isObject(value) {
  46059. var type = _typeof(value);
  46060. return value != null && (type == 'object' || type == 'function');
  46061. }
  46062. /**
  46063. * Checks if `value` is object-like. A value is object-like if it's not `null`
  46064. * and has a `typeof` result of "object".
  46065. *
  46066. * @static
  46067. * @memberOf _
  46068. * @since 4.0.0
  46069. * @category Lang
  46070. * @param {*} value The value to check.
  46071. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  46072. * @example
  46073. *
  46074. * _.isObjectLike({});
  46075. * // => true
  46076. *
  46077. * _.isObjectLike([1, 2, 3]);
  46078. * // => true
  46079. *
  46080. * _.isObjectLike(_.noop);
  46081. * // => false
  46082. *
  46083. * _.isObjectLike(null);
  46084. * // => false
  46085. */
  46086. function isObjectLike(value) {
  46087. return value != null && _typeof(value) == 'object';
  46088. }
  46089. /**
  46090. * Checks if `value` is classified as a typed array.
  46091. *
  46092. * @static
  46093. * @memberOf _
  46094. * @since 3.0.0
  46095. * @category Lang
  46096. * @param {*} value The value to check.
  46097. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  46098. * @example
  46099. *
  46100. * _.isTypedArray(new Uint8Array);
  46101. * // => true
  46102. *
  46103. * _.isTypedArray([]);
  46104. * // => false
  46105. */
  46106. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  46107. /**
  46108. * Creates an array of the own enumerable property names of `object`.
  46109. *
  46110. * **Note:** Non-object values are coerced to objects. See the
  46111. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  46112. * for more details.
  46113. *
  46114. * @static
  46115. * @since 0.1.0
  46116. * @memberOf _
  46117. * @category Object
  46118. * @param {Object} object The object to query.
  46119. * @returns {Array} Returns the array of property names.
  46120. * @example
  46121. *
  46122. * function Foo() {
  46123. * this.a = 1;
  46124. * this.b = 2;
  46125. * }
  46126. *
  46127. * Foo.prototype.c = 3;
  46128. *
  46129. * _.keys(new Foo);
  46130. * // => ['a', 'b'] (iteration order is not guaranteed)
  46131. *
  46132. * _.keys('hi');
  46133. * // => ['0', '1']
  46134. */
  46135. function keys(object) {
  46136. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  46137. }
  46138. /**
  46139. * This method returns a new empty array.
  46140. *
  46141. * @static
  46142. * @memberOf _
  46143. * @since 4.13.0
  46144. * @category Util
  46145. * @returns {Array} Returns the new empty array.
  46146. * @example
  46147. *
  46148. * var arrays = _.times(2, _.stubArray);
  46149. *
  46150. * console.log(arrays);
  46151. * // => [[], []]
  46152. *
  46153. * console.log(arrays[0] === arrays[1]);
  46154. * // => false
  46155. */
  46156. function stubArray() {
  46157. return [];
  46158. }
  46159. /**
  46160. * This method returns `false`.
  46161. *
  46162. * @static
  46163. * @memberOf _
  46164. * @since 4.13.0
  46165. * @category Util
  46166. * @returns {boolean} Returns `false`.
  46167. * @example
  46168. *
  46169. * _.times(2, _.stubFalse);
  46170. * // => [false, false]
  46171. */
  46172. function stubFalse() {
  46173. return false;
  46174. }
  46175. module.exports = isEqual;
  46176. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  46177. },{}],321:[function(require,module,exports){
  46178. (function (global){
  46179. "use strict";
  46180. 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); }
  46181. /**
  46182. * Lodash (Custom Build) <https://lodash.com/>
  46183. * Build: `lodash modularize exports="npm" -o ./`
  46184. * Copyright JS Foundation and other contributors <https://js.foundation/>
  46185. * Released under MIT license <https://lodash.com/license>
  46186. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  46187. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  46188. */
  46189. /** `Object#toString` result references. */
  46190. var asyncTag = '[object AsyncFunction]',
  46191. funcTag = '[object Function]',
  46192. genTag = '[object GeneratorFunction]',
  46193. nullTag = '[object Null]',
  46194. proxyTag = '[object Proxy]',
  46195. undefinedTag = '[object Undefined]';
  46196. /** Detect free variable `global` from Node.js. */
  46197. var freeGlobal = (typeof global === "undefined" ? "undefined" : _typeof(global)) == 'object' && global && global.Object === Object && global;
  46198. /** Detect free variable `self`. */
  46199. var freeSelf = (typeof self === "undefined" ? "undefined" : _typeof(self)) == 'object' && self && self.Object === Object && self;
  46200. /** Used as a reference to the global object. */
  46201. var root = freeGlobal || freeSelf || Function('return this')();
  46202. /** Used for built-in method references. */
  46203. var objectProto = Object.prototype;
  46204. /** Used to check objects for own properties. */
  46205. var hasOwnProperty = objectProto.hasOwnProperty;
  46206. /**
  46207. * Used to resolve the
  46208. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  46209. * of values.
  46210. */
  46211. var nativeObjectToString = objectProto.toString;
  46212. /** Built-in value references. */
  46213. var _Symbol = root.Symbol,
  46214. symToStringTag = _Symbol ? _Symbol.toStringTag : undefined;
  46215. /**
  46216. * The base implementation of `getTag` without fallbacks for buggy environments.
  46217. *
  46218. * @private
  46219. * @param {*} value The value to query.
  46220. * @returns {string} Returns the `toStringTag`.
  46221. */
  46222. function baseGetTag(value) {
  46223. if (value == null) {
  46224. return value === undefined ? undefinedTag : nullTag;
  46225. }
  46226. return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
  46227. }
  46228. /**
  46229. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  46230. *
  46231. * @private
  46232. * @param {*} value The value to query.
  46233. * @returns {string} Returns the raw `toStringTag`.
  46234. */
  46235. function getRawTag(value) {
  46236. var isOwn = hasOwnProperty.call(value, symToStringTag),
  46237. tag = value[symToStringTag];
  46238. try {
  46239. value[symToStringTag] = undefined;
  46240. var unmasked = true;
  46241. } catch (e) {}
  46242. var result = nativeObjectToString.call(value);
  46243. if (unmasked) {
  46244. if (isOwn) {
  46245. value[symToStringTag] = tag;
  46246. } else {
  46247. delete value[symToStringTag];
  46248. }
  46249. }
  46250. return result;
  46251. }
  46252. /**
  46253. * Converts `value` to a string using `Object.prototype.toString`.
  46254. *
  46255. * @private
  46256. * @param {*} value The value to convert.
  46257. * @returns {string} Returns the converted string.
  46258. */
  46259. function objectToString(value) {
  46260. return nativeObjectToString.call(value);
  46261. }
  46262. /**
  46263. * Checks if `value` is classified as a `Function` object.
  46264. *
  46265. * @static
  46266. * @memberOf _
  46267. * @since 0.1.0
  46268. * @category Lang
  46269. * @param {*} value The value to check.
  46270. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  46271. * @example
  46272. *
  46273. * _.isFunction(_);
  46274. * // => true
  46275. *
  46276. * _.isFunction(/abc/);
  46277. * // => false
  46278. */
  46279. function isFunction(value) {
  46280. if (!isObject(value)) {
  46281. return false;
  46282. } // The use of `Object#toString` avoids issues with the `typeof` operator
  46283. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  46284. var tag = baseGetTag(value);
  46285. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  46286. }
  46287. /**
  46288. * Checks if `value` is the
  46289. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  46290. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  46291. *
  46292. * @static
  46293. * @memberOf _
  46294. * @since 0.1.0
  46295. * @category Lang
  46296. * @param {*} value The value to check.
  46297. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  46298. * @example
  46299. *
  46300. * _.isObject({});
  46301. * // => true
  46302. *
  46303. * _.isObject([1, 2, 3]);
  46304. * // => true
  46305. *
  46306. * _.isObject(_.noop);
  46307. * // => true
  46308. *
  46309. * _.isObject(null);
  46310. * // => false
  46311. */
  46312. function isObject(value) {
  46313. var type = _typeof(value);
  46314. return value != null && (type == 'object' || type == 'function');
  46315. }
  46316. module.exports = isFunction;
  46317. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  46318. },{}],322:[function(require,module,exports){
  46319. "use strict";
  46320. /**
  46321. * lodash 4.0.0 (Custom Build) <https://lodash.com/>
  46322. * Build: `lodash modularize exports="npm" -o ./`
  46323. * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
  46324. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  46325. * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  46326. * Available under MIT license <https://lodash.com/license>
  46327. */
  46328. /**
  46329. * Checks if `value` is `null` or `undefined`.
  46330. *
  46331. * @static
  46332. * @memberOf _
  46333. * @category Lang
  46334. * @param {*} value The value to check.
  46335. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  46336. * @example
  46337. *
  46338. * _.isNil(null);
  46339. * // => true
  46340. *
  46341. * _.isNil(void 0);
  46342. * // => true
  46343. *
  46344. * _.isNil(NaN);
  46345. * // => false
  46346. */
  46347. function isNil(value) {
  46348. return value == null;
  46349. }
  46350. module.exports = isNil;
  46351. },{}],323:[function(require,module,exports){
  46352. "use strict";
  46353. /**
  46354. * lodash 3.0.1 (Custom Build) <https://lodash.com/>
  46355. * Build: `lodash modern modularize exports="npm" -o ./`
  46356. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  46357. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  46358. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  46359. * Available under MIT license <https://lodash.com/license>
  46360. */
  46361. /**
  46362. * Checks if `value` is `undefined`.
  46363. *
  46364. * @static
  46365. * @memberOf _
  46366. * @category Lang
  46367. * @param {*} value The value to check.
  46368. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  46369. * @example
  46370. *
  46371. * _.isUndefined(void 0);
  46372. * // => true
  46373. *
  46374. * _.isUndefined(null);
  46375. * // => false
  46376. */
  46377. function isUndefined(value) {
  46378. return value === undefined;
  46379. }
  46380. module.exports = isUndefined;
  46381. },{}],324:[function(require,module,exports){
  46382. (function (global){
  46383. "use strict";
  46384. 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); }
  46385. /**
  46386. * lodash (Custom Build) <https://lodash.com/>
  46387. * Build: `lodash modularize exports="npm" -o ./`
  46388. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  46389. * Released under MIT license <https://lodash.com/license>
  46390. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  46391. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  46392. */
  46393. /** Used as the size to enable large array optimizations. */
  46394. var LARGE_ARRAY_SIZE = 200;
  46395. /** Used to stand-in for `undefined` hash values. */
  46396. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  46397. /** Used as references for various `Number` constants. */
  46398. var INFINITY = 1 / 0;
  46399. /** `Object#toString` result references. */
  46400. var funcTag = '[object Function]',
  46401. genTag = '[object GeneratorFunction]';
  46402. /**
  46403. * Used to match `RegExp`
  46404. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  46405. */
  46406. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  46407. /** Used to detect host constructors (Safari). */
  46408. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  46409. /** Detect free variable `global` from Node.js. */
  46410. var freeGlobal = (typeof global === "undefined" ? "undefined" : _typeof(global)) == 'object' && global && global.Object === Object && global;
  46411. /** Detect free variable `self`. */
  46412. var freeSelf = (typeof self === "undefined" ? "undefined" : _typeof(self)) == 'object' && self && self.Object === Object && self;
  46413. /** Used as a reference to the global object. */
  46414. var root = freeGlobal || freeSelf || Function('return this')();
  46415. /**
  46416. * A specialized version of `_.includes` for arrays without support for
  46417. * specifying an index to search from.
  46418. *
  46419. * @private
  46420. * @param {Array} [array] The array to inspect.
  46421. * @param {*} target The value to search for.
  46422. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  46423. */
  46424. function arrayIncludes(array, value) {
  46425. var length = array ? array.length : 0;
  46426. return !!length && baseIndexOf(array, value, 0) > -1;
  46427. }
  46428. /**
  46429. * This function is like `arrayIncludes` except that it accepts a comparator.
  46430. *
  46431. * @private
  46432. * @param {Array} [array] The array to inspect.
  46433. * @param {*} target The value to search for.
  46434. * @param {Function} comparator The comparator invoked per element.
  46435. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  46436. */
  46437. function arrayIncludesWith(array, value, comparator) {
  46438. var index = -1,
  46439. length = array ? array.length : 0;
  46440. while (++index < length) {
  46441. if (comparator(value, array[index])) {
  46442. return true;
  46443. }
  46444. }
  46445. return false;
  46446. }
  46447. /**
  46448. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  46449. * support for iteratee shorthands.
  46450. *
  46451. * @private
  46452. * @param {Array} array The array to inspect.
  46453. * @param {Function} predicate The function invoked per iteration.
  46454. * @param {number} fromIndex The index to search from.
  46455. * @param {boolean} [fromRight] Specify iterating from right to left.
  46456. * @returns {number} Returns the index of the matched value, else `-1`.
  46457. */
  46458. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  46459. var length = array.length,
  46460. index = fromIndex + (fromRight ? 1 : -1);
  46461. while (fromRight ? index-- : ++index < length) {
  46462. if (predicate(array[index], index, array)) {
  46463. return index;
  46464. }
  46465. }
  46466. return -1;
  46467. }
  46468. /**
  46469. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  46470. *
  46471. * @private
  46472. * @param {Array} array The array to inspect.
  46473. * @param {*} value The value to search for.
  46474. * @param {number} fromIndex The index to search from.
  46475. * @returns {number} Returns the index of the matched value, else `-1`.
  46476. */
  46477. function baseIndexOf(array, value, fromIndex) {
  46478. if (value !== value) {
  46479. return baseFindIndex(array, baseIsNaN, fromIndex);
  46480. }
  46481. var index = fromIndex - 1,
  46482. length = array.length;
  46483. while (++index < length) {
  46484. if (array[index] === value) {
  46485. return index;
  46486. }
  46487. }
  46488. return -1;
  46489. }
  46490. /**
  46491. * The base implementation of `_.isNaN` without support for number objects.
  46492. *
  46493. * @private
  46494. * @param {*} value The value to check.
  46495. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  46496. */
  46497. function baseIsNaN(value) {
  46498. return value !== value;
  46499. }
  46500. /**
  46501. * Checks if a cache value for `key` exists.
  46502. *
  46503. * @private
  46504. * @param {Object} cache The cache to query.
  46505. * @param {string} key The key of the entry to check.
  46506. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  46507. */
  46508. function cacheHas(cache, key) {
  46509. return cache.has(key);
  46510. }
  46511. /**
  46512. * Gets the value at `key` of `object`.
  46513. *
  46514. * @private
  46515. * @param {Object} [object] The object to query.
  46516. * @param {string} key The key of the property to get.
  46517. * @returns {*} Returns the property value.
  46518. */
  46519. function getValue(object, key) {
  46520. return object == null ? undefined : object[key];
  46521. }
  46522. /**
  46523. * Checks if `value` is a host object in IE < 9.
  46524. *
  46525. * @private
  46526. * @param {*} value The value to check.
  46527. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  46528. */
  46529. function isHostObject(value) {
  46530. // Many host objects are `Object` objects that can coerce to strings
  46531. // despite having improperly defined `toString` methods.
  46532. var result = false;
  46533. if (value != null && typeof value.toString != 'function') {
  46534. try {
  46535. result = !!(value + '');
  46536. } catch (e) {}
  46537. }
  46538. return result;
  46539. }
  46540. /**
  46541. * Converts `set` to an array of its values.
  46542. *
  46543. * @private
  46544. * @param {Object} set The set to convert.
  46545. * @returns {Array} Returns the values.
  46546. */
  46547. function setToArray(set) {
  46548. var index = -1,
  46549. result = Array(set.size);
  46550. set.forEach(function (value) {
  46551. result[++index] = value;
  46552. });
  46553. return result;
  46554. }
  46555. /** Used for built-in method references. */
  46556. var arrayProto = Array.prototype,
  46557. funcProto = Function.prototype,
  46558. objectProto = Object.prototype;
  46559. /** Used to detect overreaching core-js shims. */
  46560. var coreJsData = root['__core-js_shared__'];
  46561. /** Used to detect methods masquerading as native. */
  46562. var maskSrcKey = function () {
  46563. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  46564. return uid ? 'Symbol(src)_1.' + uid : '';
  46565. }();
  46566. /** Used to resolve the decompiled source of functions. */
  46567. var funcToString = funcProto.toString;
  46568. /** Used to check objects for own properties. */
  46569. var hasOwnProperty = objectProto.hasOwnProperty;
  46570. /**
  46571. * Used to resolve the
  46572. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  46573. * of values.
  46574. */
  46575. var objectToString = objectProto.toString;
  46576. /** Used to detect if a method is native. */
  46577. var reIsNative = RegExp('^' + funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
  46578. /** Built-in value references. */
  46579. var splice = arrayProto.splice;
  46580. /* Built-in method references that are verified to be native. */
  46581. var Map = getNative(root, 'Map'),
  46582. Set = getNative(root, 'Set'),
  46583. nativeCreate = getNative(Object, 'create');
  46584. /**
  46585. * Creates a hash object.
  46586. *
  46587. * @private
  46588. * @constructor
  46589. * @param {Array} [entries] The key-value pairs to cache.
  46590. */
  46591. function Hash(entries) {
  46592. var index = -1,
  46593. length = entries ? entries.length : 0;
  46594. this.clear();
  46595. while (++index < length) {
  46596. var entry = entries[index];
  46597. this.set(entry[0], entry[1]);
  46598. }
  46599. }
  46600. /**
  46601. * Removes all key-value entries from the hash.
  46602. *
  46603. * @private
  46604. * @name clear
  46605. * @memberOf Hash
  46606. */
  46607. function hashClear() {
  46608. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  46609. }
  46610. /**
  46611. * Removes `key` and its value from the hash.
  46612. *
  46613. * @private
  46614. * @name delete
  46615. * @memberOf Hash
  46616. * @param {Object} hash The hash to modify.
  46617. * @param {string} key The key of the value to remove.
  46618. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  46619. */
  46620. function hashDelete(key) {
  46621. return this.has(key) && delete this.__data__[key];
  46622. }
  46623. /**
  46624. * Gets the hash value for `key`.
  46625. *
  46626. * @private
  46627. * @name get
  46628. * @memberOf Hash
  46629. * @param {string} key The key of the value to get.
  46630. * @returns {*} Returns the entry value.
  46631. */
  46632. function hashGet(key) {
  46633. var data = this.__data__;
  46634. if (nativeCreate) {
  46635. var result = data[key];
  46636. return result === HASH_UNDEFINED ? undefined : result;
  46637. }
  46638. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  46639. }
  46640. /**
  46641. * Checks if a hash value for `key` exists.
  46642. *
  46643. * @private
  46644. * @name has
  46645. * @memberOf Hash
  46646. * @param {string} key The key of the entry to check.
  46647. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  46648. */
  46649. function hashHas(key) {
  46650. var data = this.__data__;
  46651. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  46652. }
  46653. /**
  46654. * Sets the hash `key` to `value`.
  46655. *
  46656. * @private
  46657. * @name set
  46658. * @memberOf Hash
  46659. * @param {string} key The key of the value to set.
  46660. * @param {*} value The value to set.
  46661. * @returns {Object} Returns the hash instance.
  46662. */
  46663. function hashSet(key, value) {
  46664. var data = this.__data__;
  46665. data[key] = nativeCreate && value === undefined ? HASH_UNDEFINED : value;
  46666. return this;
  46667. } // Add methods to `Hash`.
  46668. Hash.prototype.clear = hashClear;
  46669. Hash.prototype['delete'] = hashDelete;
  46670. Hash.prototype.get = hashGet;
  46671. Hash.prototype.has = hashHas;
  46672. Hash.prototype.set = hashSet;
  46673. /**
  46674. * Creates an list cache object.
  46675. *
  46676. * @private
  46677. * @constructor
  46678. * @param {Array} [entries] The key-value pairs to cache.
  46679. */
  46680. function ListCache(entries) {
  46681. var index = -1,
  46682. length = entries ? entries.length : 0;
  46683. this.clear();
  46684. while (++index < length) {
  46685. var entry = entries[index];
  46686. this.set(entry[0], entry[1]);
  46687. }
  46688. }
  46689. /**
  46690. * Removes all key-value entries from the list cache.
  46691. *
  46692. * @private
  46693. * @name clear
  46694. * @memberOf ListCache
  46695. */
  46696. function listCacheClear() {
  46697. this.__data__ = [];
  46698. }
  46699. /**
  46700. * Removes `key` and its value from the list cache.
  46701. *
  46702. * @private
  46703. * @name delete
  46704. * @memberOf ListCache
  46705. * @param {string} key The key of the value to remove.
  46706. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  46707. */
  46708. function listCacheDelete(key) {
  46709. var data = this.__data__,
  46710. index = assocIndexOf(data, key);
  46711. if (index < 0) {
  46712. return false;
  46713. }
  46714. var lastIndex = data.length - 1;
  46715. if (index == lastIndex) {
  46716. data.pop();
  46717. } else {
  46718. splice.call(data, index, 1);
  46719. }
  46720. return true;
  46721. }
  46722. /**
  46723. * Gets the list cache value for `key`.
  46724. *
  46725. * @private
  46726. * @name get
  46727. * @memberOf ListCache
  46728. * @param {string} key The key of the value to get.
  46729. * @returns {*} Returns the entry value.
  46730. */
  46731. function listCacheGet(key) {
  46732. var data = this.__data__,
  46733. index = assocIndexOf(data, key);
  46734. return index < 0 ? undefined : data[index][1];
  46735. }
  46736. /**
  46737. * Checks if a list cache value for `key` exists.
  46738. *
  46739. * @private
  46740. * @name has
  46741. * @memberOf ListCache
  46742. * @param {string} key The key of the entry to check.
  46743. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  46744. */
  46745. function listCacheHas(key) {
  46746. return assocIndexOf(this.__data__, key) > -1;
  46747. }
  46748. /**
  46749. * Sets the list cache `key` to `value`.
  46750. *
  46751. * @private
  46752. * @name set
  46753. * @memberOf ListCache
  46754. * @param {string} key The key of the value to set.
  46755. * @param {*} value The value to set.
  46756. * @returns {Object} Returns the list cache instance.
  46757. */
  46758. function listCacheSet(key, value) {
  46759. var data = this.__data__,
  46760. index = assocIndexOf(data, key);
  46761. if (index < 0) {
  46762. data.push([key, value]);
  46763. } else {
  46764. data[index][1] = value;
  46765. }
  46766. return this;
  46767. } // Add methods to `ListCache`.
  46768. ListCache.prototype.clear = listCacheClear;
  46769. ListCache.prototype['delete'] = listCacheDelete;
  46770. ListCache.prototype.get = listCacheGet;
  46771. ListCache.prototype.has = listCacheHas;
  46772. ListCache.prototype.set = listCacheSet;
  46773. /**
  46774. * Creates a map cache object to store key-value pairs.
  46775. *
  46776. * @private
  46777. * @constructor
  46778. * @param {Array} [entries] The key-value pairs to cache.
  46779. */
  46780. function MapCache(entries) {
  46781. var index = -1,
  46782. length = entries ? entries.length : 0;
  46783. this.clear();
  46784. while (++index < length) {
  46785. var entry = entries[index];
  46786. this.set(entry[0], entry[1]);
  46787. }
  46788. }
  46789. /**
  46790. * Removes all key-value entries from the map.
  46791. *
  46792. * @private
  46793. * @name clear
  46794. * @memberOf MapCache
  46795. */
  46796. function mapCacheClear() {
  46797. this.__data__ = {
  46798. 'hash': new Hash(),
  46799. 'map': new (Map || ListCache)(),
  46800. 'string': new Hash()
  46801. };
  46802. }
  46803. /**
  46804. * Removes `key` and its value from the map.
  46805. *
  46806. * @private
  46807. * @name delete
  46808. * @memberOf MapCache
  46809. * @param {string} key The key of the value to remove.
  46810. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  46811. */
  46812. function mapCacheDelete(key) {
  46813. return getMapData(this, key)['delete'](key);
  46814. }
  46815. /**
  46816. * Gets the map value for `key`.
  46817. *
  46818. * @private
  46819. * @name get
  46820. * @memberOf MapCache
  46821. * @param {string} key The key of the value to get.
  46822. * @returns {*} Returns the entry value.
  46823. */
  46824. function mapCacheGet(key) {
  46825. return getMapData(this, key).get(key);
  46826. }
  46827. /**
  46828. * Checks if a map value for `key` exists.
  46829. *
  46830. * @private
  46831. * @name has
  46832. * @memberOf MapCache
  46833. * @param {string} key The key of the entry to check.
  46834. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  46835. */
  46836. function mapCacheHas(key) {
  46837. return getMapData(this, key).has(key);
  46838. }
  46839. /**
  46840. * Sets the map `key` to `value`.
  46841. *
  46842. * @private
  46843. * @name set
  46844. * @memberOf MapCache
  46845. * @param {string} key The key of the value to set.
  46846. * @param {*} value The value to set.
  46847. * @returns {Object} Returns the map cache instance.
  46848. */
  46849. function mapCacheSet(key, value) {
  46850. getMapData(this, key).set(key, value);
  46851. return this;
  46852. } // Add methods to `MapCache`.
  46853. MapCache.prototype.clear = mapCacheClear;
  46854. MapCache.prototype['delete'] = mapCacheDelete;
  46855. MapCache.prototype.get = mapCacheGet;
  46856. MapCache.prototype.has = mapCacheHas;
  46857. MapCache.prototype.set = mapCacheSet;
  46858. /**
  46859. *
  46860. * Creates an array cache object to store unique values.
  46861. *
  46862. * @private
  46863. * @constructor
  46864. * @param {Array} [values] The values to cache.
  46865. */
  46866. function SetCache(values) {
  46867. var index = -1,
  46868. length = values ? values.length : 0;
  46869. this.__data__ = new MapCache();
  46870. while (++index < length) {
  46871. this.add(values[index]);
  46872. }
  46873. }
  46874. /**
  46875. * Adds `value` to the array cache.
  46876. *
  46877. * @private
  46878. * @name add
  46879. * @memberOf SetCache
  46880. * @alias push
  46881. * @param {*} value The value to cache.
  46882. * @returns {Object} Returns the cache instance.
  46883. */
  46884. function setCacheAdd(value) {
  46885. this.__data__.set(value, HASH_UNDEFINED);
  46886. return this;
  46887. }
  46888. /**
  46889. * Checks if `value` is in the array cache.
  46890. *
  46891. * @private
  46892. * @name has
  46893. * @memberOf SetCache
  46894. * @param {*} value The value to search for.
  46895. * @returns {number} Returns `true` if `value` is found, else `false`.
  46896. */
  46897. function setCacheHas(value) {
  46898. return this.__data__.has(value);
  46899. } // Add methods to `SetCache`.
  46900. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  46901. SetCache.prototype.has = setCacheHas;
  46902. /**
  46903. * Gets the index at which the `key` is found in `array` of key-value pairs.
  46904. *
  46905. * @private
  46906. * @param {Array} array The array to inspect.
  46907. * @param {*} key The key to search for.
  46908. * @returns {number} Returns the index of the matched value, else `-1`.
  46909. */
  46910. function assocIndexOf(array, key) {
  46911. var length = array.length;
  46912. while (length--) {
  46913. if (eq(array[length][0], key)) {
  46914. return length;
  46915. }
  46916. }
  46917. return -1;
  46918. }
  46919. /**
  46920. * The base implementation of `_.isNative` without bad shim checks.
  46921. *
  46922. * @private
  46923. * @param {*} value The value to check.
  46924. * @returns {boolean} Returns `true` if `value` is a native function,
  46925. * else `false`.
  46926. */
  46927. function baseIsNative(value) {
  46928. if (!isObject(value) || isMasked(value)) {
  46929. return false;
  46930. }
  46931. var pattern = isFunction(value) || isHostObject(value) ? reIsNative : reIsHostCtor;
  46932. return pattern.test(toSource(value));
  46933. }
  46934. /**
  46935. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  46936. *
  46937. * @private
  46938. * @param {Array} array The array to inspect.
  46939. * @param {Function} [iteratee] The iteratee invoked per element.
  46940. * @param {Function} [comparator] The comparator invoked per element.
  46941. * @returns {Array} Returns the new duplicate free array.
  46942. */
  46943. function baseUniq(array, iteratee, comparator) {
  46944. var index = -1,
  46945. includes = arrayIncludes,
  46946. length = array.length,
  46947. isCommon = true,
  46948. result = [],
  46949. seen = result;
  46950. if (comparator) {
  46951. isCommon = false;
  46952. includes = arrayIncludesWith;
  46953. } else if (length >= LARGE_ARRAY_SIZE) {
  46954. var set = iteratee ? null : createSet(array);
  46955. if (set) {
  46956. return setToArray(set);
  46957. }
  46958. isCommon = false;
  46959. includes = cacheHas;
  46960. seen = new SetCache();
  46961. } else {
  46962. seen = iteratee ? [] : result;
  46963. }
  46964. outer: while (++index < length) {
  46965. var value = array[index],
  46966. computed = iteratee ? iteratee(value) : value;
  46967. value = comparator || value !== 0 ? value : 0;
  46968. if (isCommon && computed === computed) {
  46969. var seenIndex = seen.length;
  46970. while (seenIndex--) {
  46971. if (seen[seenIndex] === computed) {
  46972. continue outer;
  46973. }
  46974. }
  46975. if (iteratee) {
  46976. seen.push(computed);
  46977. }
  46978. result.push(value);
  46979. } else if (!includes(seen, computed, comparator)) {
  46980. if (seen !== result) {
  46981. seen.push(computed);
  46982. }
  46983. result.push(value);
  46984. }
  46985. }
  46986. return result;
  46987. }
  46988. /**
  46989. * Creates a set object of `values`.
  46990. *
  46991. * @private
  46992. * @param {Array} values The values to add to the set.
  46993. * @returns {Object} Returns the new set.
  46994. */
  46995. var createSet = !(Set && 1 / setToArray(new Set([, -0]))[1] == INFINITY) ? noop : function (values) {
  46996. return new Set(values);
  46997. };
  46998. /**
  46999. * Gets the data for `map`.
  47000. *
  47001. * @private
  47002. * @param {Object} map The map to query.
  47003. * @param {string} key The reference key.
  47004. * @returns {*} Returns the map data.
  47005. */
  47006. function getMapData(map, key) {
  47007. var data = map.__data__;
  47008. return isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
  47009. }
  47010. /**
  47011. * Gets the native function at `key` of `object`.
  47012. *
  47013. * @private
  47014. * @param {Object} object The object to query.
  47015. * @param {string} key The key of the method to get.
  47016. * @returns {*} Returns the function if it's native, else `undefined`.
  47017. */
  47018. function getNative(object, key) {
  47019. var value = getValue(object, key);
  47020. return baseIsNative(value) ? value : undefined;
  47021. }
  47022. /**
  47023. * Checks if `value` is suitable for use as unique object key.
  47024. *
  47025. * @private
  47026. * @param {*} value The value to check.
  47027. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  47028. */
  47029. function isKeyable(value) {
  47030. var type = _typeof(value);
  47031. return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean' ? value !== '__proto__' : value === null;
  47032. }
  47033. /**
  47034. * Checks if `func` has its source masked.
  47035. *
  47036. * @private
  47037. * @param {Function} func The function to check.
  47038. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  47039. */
  47040. function isMasked(func) {
  47041. return !!maskSrcKey && maskSrcKey in func;
  47042. }
  47043. /**
  47044. * Converts `func` to its source code.
  47045. *
  47046. * @private
  47047. * @param {Function} func The function to process.
  47048. * @returns {string} Returns the source code.
  47049. */
  47050. function toSource(func) {
  47051. if (func != null) {
  47052. try {
  47053. return funcToString.call(func);
  47054. } catch (e) {}
  47055. try {
  47056. return func + '';
  47057. } catch (e) {}
  47058. }
  47059. return '';
  47060. }
  47061. /**
  47062. * Creates a duplicate-free version of an array, using
  47063. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  47064. * for equality comparisons, in which only the first occurrence of each
  47065. * element is kept.
  47066. *
  47067. * @static
  47068. * @memberOf _
  47069. * @since 0.1.0
  47070. * @category Array
  47071. * @param {Array} array The array to inspect.
  47072. * @returns {Array} Returns the new duplicate free array.
  47073. * @example
  47074. *
  47075. * _.uniq([2, 1, 2]);
  47076. * // => [2, 1]
  47077. */
  47078. function uniq(array) {
  47079. return array && array.length ? baseUniq(array) : [];
  47080. }
  47081. /**
  47082. * Performs a
  47083. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  47084. * comparison between two values to determine if they are equivalent.
  47085. *
  47086. * @static
  47087. * @memberOf _
  47088. * @since 4.0.0
  47089. * @category Lang
  47090. * @param {*} value The value to compare.
  47091. * @param {*} other The other value to compare.
  47092. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  47093. * @example
  47094. *
  47095. * var object = { 'a': 1 };
  47096. * var other = { 'a': 1 };
  47097. *
  47098. * _.eq(object, object);
  47099. * // => true
  47100. *
  47101. * _.eq(object, other);
  47102. * // => false
  47103. *
  47104. * _.eq('a', 'a');
  47105. * // => true
  47106. *
  47107. * _.eq('a', Object('a'));
  47108. * // => false
  47109. *
  47110. * _.eq(NaN, NaN);
  47111. * // => true
  47112. */
  47113. function eq(value, other) {
  47114. return value === other || value !== value && other !== other;
  47115. }
  47116. /**
  47117. * Checks if `value` is classified as a `Function` object.
  47118. *
  47119. * @static
  47120. * @memberOf _
  47121. * @since 0.1.0
  47122. * @category Lang
  47123. * @param {*} value The value to check.
  47124. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  47125. * @example
  47126. *
  47127. * _.isFunction(_);
  47128. * // => true
  47129. *
  47130. * _.isFunction(/abc/);
  47131. * // => false
  47132. */
  47133. function isFunction(value) {
  47134. // The use of `Object#toString` avoids issues with the `typeof` operator
  47135. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  47136. var tag = isObject(value) ? objectToString.call(value) : '';
  47137. return tag == funcTag || tag == genTag;
  47138. }
  47139. /**
  47140. * Checks if `value` is the
  47141. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  47142. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  47143. *
  47144. * @static
  47145. * @memberOf _
  47146. * @since 0.1.0
  47147. * @category Lang
  47148. * @param {*} value The value to check.
  47149. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  47150. * @example
  47151. *
  47152. * _.isObject({});
  47153. * // => true
  47154. *
  47155. * _.isObject([1, 2, 3]);
  47156. * // => true
  47157. *
  47158. * _.isObject(_.noop);
  47159. * // => true
  47160. *
  47161. * _.isObject(null);
  47162. * // => false
  47163. */
  47164. function isObject(value) {
  47165. var type = _typeof(value);
  47166. return !!value && (type == 'object' || type == 'function');
  47167. }
  47168. /**
  47169. * This method returns `undefined`.
  47170. *
  47171. * @static
  47172. * @memberOf _
  47173. * @since 2.3.0
  47174. * @category Util
  47175. * @example
  47176. *
  47177. * _.times(2, _.noop);
  47178. * // => [undefined, undefined]
  47179. */
  47180. function noop() {// No operation performed.
  47181. }
  47182. module.exports = uniq;
  47183. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  47184. },{}],325:[function(require,module,exports){
  47185. 'use strict';
  47186. var inherits = require('inherits');
  47187. var HashBase = require('hash-base');
  47188. var Buffer = require('safe-buffer').Buffer;
  47189. var ARRAY16 = new Array(16);
  47190. function MD5() {
  47191. HashBase.call(this, 64); // state
  47192. this._a = 0x67452301;
  47193. this._b = 0xefcdab89;
  47194. this._c = 0x98badcfe;
  47195. this._d = 0x10325476;
  47196. }
  47197. inherits(MD5, HashBase);
  47198. MD5.prototype._update = function () {
  47199. var M = ARRAY16;
  47200. for (var i = 0; i < 16; ++i) {
  47201. M[i] = this._block.readInt32LE(i * 4);
  47202. }
  47203. var a = this._a;
  47204. var b = this._b;
  47205. var c = this._c;
  47206. var d = this._d;
  47207. a = fnF(a, b, c, d, M[0], 0xd76aa478, 7);
  47208. d = fnF(d, a, b, c, M[1], 0xe8c7b756, 12);
  47209. c = fnF(c, d, a, b, M[2], 0x242070db, 17);
  47210. b = fnF(b, c, d, a, M[3], 0xc1bdceee, 22);
  47211. a = fnF(a, b, c, d, M[4], 0xf57c0faf, 7);
  47212. d = fnF(d, a, b, c, M[5], 0x4787c62a, 12);
  47213. c = fnF(c, d, a, b, M[6], 0xa8304613, 17);
  47214. b = fnF(b, c, d, a, M[7], 0xfd469501, 22);
  47215. a = fnF(a, b, c, d, M[8], 0x698098d8, 7);
  47216. d = fnF(d, a, b, c, M[9], 0x8b44f7af, 12);
  47217. c = fnF(c, d, a, b, M[10], 0xffff5bb1, 17);
  47218. b = fnF(b, c, d, a, M[11], 0x895cd7be, 22);
  47219. a = fnF(a, b, c, d, M[12], 0x6b901122, 7);
  47220. d = fnF(d, a, b, c, M[13], 0xfd987193, 12);
  47221. c = fnF(c, d, a, b, M[14], 0xa679438e, 17);
  47222. b = fnF(b, c, d, a, M[15], 0x49b40821, 22);
  47223. a = fnG(a, b, c, d, M[1], 0xf61e2562, 5);
  47224. d = fnG(d, a, b, c, M[6], 0xc040b340, 9);
  47225. c = fnG(c, d, a, b, M[11], 0x265e5a51, 14);
  47226. b = fnG(b, c, d, a, M[0], 0xe9b6c7aa, 20);
  47227. a = fnG(a, b, c, d, M[5], 0xd62f105d, 5);
  47228. d = fnG(d, a, b, c, M[10], 0x02441453, 9);
  47229. c = fnG(c, d, a, b, M[15], 0xd8a1e681, 14);
  47230. b = fnG(b, c, d, a, M[4], 0xe7d3fbc8, 20);
  47231. a = fnG(a, b, c, d, M[9], 0x21e1cde6, 5);
  47232. d = fnG(d, a, b, c, M[14], 0xc33707d6, 9);
  47233. c = fnG(c, d, a, b, M[3], 0xf4d50d87, 14);
  47234. b = fnG(b, c, d, a, M[8], 0x455a14ed, 20);
  47235. a = fnG(a, b, c, d, M[13], 0xa9e3e905, 5);
  47236. d = fnG(d, a, b, c, M[2], 0xfcefa3f8, 9);
  47237. c = fnG(c, d, a, b, M[7], 0x676f02d9, 14);
  47238. b = fnG(b, c, d, a, M[12], 0x8d2a4c8a, 20);
  47239. a = fnH(a, b, c, d, M[5], 0xfffa3942, 4);
  47240. d = fnH(d, a, b, c, M[8], 0x8771f681, 11);
  47241. c = fnH(c, d, a, b, M[11], 0x6d9d6122, 16);
  47242. b = fnH(b, c, d, a, M[14], 0xfde5380c, 23);
  47243. a = fnH(a, b, c, d, M[1], 0xa4beea44, 4);
  47244. d = fnH(d, a, b, c, M[4], 0x4bdecfa9, 11);
  47245. c = fnH(c, d, a, b, M[7], 0xf6bb4b60, 16);
  47246. b = fnH(b, c, d, a, M[10], 0xbebfbc70, 23);
  47247. a = fnH(a, b, c, d, M[13], 0x289b7ec6, 4);
  47248. d = fnH(d, a, b, c, M[0], 0xeaa127fa, 11);
  47249. c = fnH(c, d, a, b, M[3], 0xd4ef3085, 16);
  47250. b = fnH(b, c, d, a, M[6], 0x04881d05, 23);
  47251. a = fnH(a, b, c, d, M[9], 0xd9d4d039, 4);
  47252. d = fnH(d, a, b, c, M[12], 0xe6db99e5, 11);
  47253. c = fnH(c, d, a, b, M[15], 0x1fa27cf8, 16);
  47254. b = fnH(b, c, d, a, M[2], 0xc4ac5665, 23);
  47255. a = fnI(a, b, c, d, M[0], 0xf4292244, 6);
  47256. d = fnI(d, a, b, c, M[7], 0x432aff97, 10);
  47257. c = fnI(c, d, a, b, M[14], 0xab9423a7, 15);
  47258. b = fnI(b, c, d, a, M[5], 0xfc93a039, 21);
  47259. a = fnI(a, b, c, d, M[12], 0x655b59c3, 6);
  47260. d = fnI(d, a, b, c, M[3], 0x8f0ccc92, 10);
  47261. c = fnI(c, d, a, b, M[10], 0xffeff47d, 15);
  47262. b = fnI(b, c, d, a, M[1], 0x85845dd1, 21);
  47263. a = fnI(a, b, c, d, M[8], 0x6fa87e4f, 6);
  47264. d = fnI(d, a, b, c, M[15], 0xfe2ce6e0, 10);
  47265. c = fnI(c, d, a, b, M[6], 0xa3014314, 15);
  47266. b = fnI(b, c, d, a, M[13], 0x4e0811a1, 21);
  47267. a = fnI(a, b, c, d, M[4], 0xf7537e82, 6);
  47268. d = fnI(d, a, b, c, M[11], 0xbd3af235, 10);
  47269. c = fnI(c, d, a, b, M[2], 0x2ad7d2bb, 15);
  47270. b = fnI(b, c, d, a, M[9], 0xeb86d391, 21);
  47271. this._a = this._a + a | 0;
  47272. this._b = this._b + b | 0;
  47273. this._c = this._c + c | 0;
  47274. this._d = this._d + d | 0;
  47275. };
  47276. MD5.prototype._digest = function () {
  47277. // create padding and handle blocks
  47278. this._block[this._blockOffset++] = 0x80;
  47279. if (this._blockOffset > 56) {
  47280. this._block.fill(0, this._blockOffset, 64);
  47281. this._update();
  47282. this._blockOffset = 0;
  47283. }
  47284. this._block.fill(0, this._blockOffset, 56);
  47285. this._block.writeUInt32LE(this._length[0], 56);
  47286. this._block.writeUInt32LE(this._length[1], 60);
  47287. this._update(); // produce result
  47288. var buffer = Buffer.allocUnsafe(16);
  47289. buffer.writeInt32LE(this._a, 0);
  47290. buffer.writeInt32LE(this._b, 4);
  47291. buffer.writeInt32LE(this._c, 8);
  47292. buffer.writeInt32LE(this._d, 12);
  47293. return buffer;
  47294. };
  47295. function rotl(x, n) {
  47296. return x << n | x >>> 32 - n;
  47297. }
  47298. function fnF(a, b, c, d, m, k, s) {
  47299. return rotl(a + (b & c | ~b & d) + m + k | 0, s) + b | 0;
  47300. }
  47301. function fnG(a, b, c, d, m, k, s) {
  47302. return rotl(a + (b & d | c & ~d) + m + k | 0, s) + b | 0;
  47303. }
  47304. function fnH(a, b, c, d, m, k, s) {
  47305. return rotl(a + (b ^ c ^ d) + m + k | 0, s) + b | 0;
  47306. }
  47307. function fnI(a, b, c, d, m, k, s) {
  47308. return rotl(a + (c ^ (b | ~d)) + m + k | 0, s) + b | 0;
  47309. }
  47310. module.exports = MD5;
  47311. },{"hash-base":261,"inherits":278,"safe-buffer":384}],326:[function(require,module,exports){
  47312. "use strict";
  47313. var bn = require('bn.js');
  47314. var brorand = require('brorand');
  47315. function MillerRabin(rand) {
  47316. this.rand = rand || new brorand.Rand();
  47317. }
  47318. module.exports = MillerRabin;
  47319. MillerRabin.create = function create(rand) {
  47320. return new MillerRabin(rand);
  47321. };
  47322. MillerRabin.prototype._randbelow = function _randbelow(n) {
  47323. var len = n.bitLength();
  47324. var min_bytes = Math.ceil(len / 8); // Generage random bytes until a number less than n is found.
  47325. // This ensures that 0..n-1 have an equal probability of being selected.
  47326. do {
  47327. var a = new bn(this.rand.generate(min_bytes));
  47328. } while (a.cmp(n) >= 0);
  47329. return a;
  47330. };
  47331. MillerRabin.prototype._randrange = function _randrange(start, stop) {
  47332. // Generate a random number greater than or equal to start and less than stop.
  47333. var size = stop.sub(start);
  47334. return start.add(this._randbelow(size));
  47335. };
  47336. MillerRabin.prototype.test = function test(n, k, cb) {
  47337. var len = n.bitLength();
  47338. var red = bn.mont(n);
  47339. var rone = new bn(1).toRed(red);
  47340. if (!k) k = Math.max(1, len / 48 | 0); // Find d and s, (n - 1) = (2 ^ s) * d;
  47341. var n1 = n.subn(1);
  47342. for (var s = 0; !n1.testn(s); s++) {}
  47343. var d = n.shrn(s);
  47344. var rn1 = n1.toRed(red);
  47345. var prime = true;
  47346. for (; k > 0; k--) {
  47347. var a = this._randrange(new bn(2), n1);
  47348. if (cb) cb(a);
  47349. var x = a.toRed(red).redPow(d);
  47350. if (x.cmp(rone) === 0 || x.cmp(rn1) === 0) continue;
  47351. for (var i = 1; i < s; i++) {
  47352. x = x.redSqr();
  47353. if (x.cmp(rone) === 0) return false;
  47354. if (x.cmp(rn1) === 0) break;
  47355. }
  47356. if (i === s) return false;
  47357. }
  47358. return prime;
  47359. };
  47360. MillerRabin.prototype.getDivisor = function getDivisor(n, k) {
  47361. var len = n.bitLength();
  47362. var red = bn.mont(n);
  47363. var rone = new bn(1).toRed(red);
  47364. if (!k) k = Math.max(1, len / 48 | 0); // Find d and s, (n - 1) = (2 ^ s) * d;
  47365. var n1 = n.subn(1);
  47366. for (var s = 0; !n1.testn(s); s++) {}
  47367. var d = n.shrn(s);
  47368. var rn1 = n1.toRed(red);
  47369. for (; k > 0; k--) {
  47370. var a = this._randrange(new bn(2), n1);
  47371. var g = n.gcd(a);
  47372. if (g.cmpn(1) !== 0) return g;
  47373. var x = a.toRed(red).redPow(d);
  47374. if (x.cmp(rone) === 0 || x.cmp(rn1) === 0) continue;
  47375. for (var i = 1; i < s; i++) {
  47376. x = x.redSqr();
  47377. if (x.cmp(rone) === 0) return x.fromRed().subn(1).gcd(n);
  47378. if (x.cmp(rn1) === 0) break;
  47379. }
  47380. if (i === s) {
  47381. x = x.redSqr();
  47382. return x.fromRed().subn(1).gcd(n);
  47383. }
  47384. }
  47385. return false;
  47386. };
  47387. },{"bn.js":327,"brorand":184}],327:[function(require,module,exports){
  47388. arguments[4][181][0].apply(exports,arguments)
  47389. },{"buffer":185,"dup":181}],328:[function(require,module,exports){
  47390. "use strict";
  47391. module.exports = assert;
  47392. function assert(val, msg) {
  47393. if (!val) throw new Error(msg || 'Assertion failed');
  47394. }
  47395. assert.equal = function assertEqual(l, r, msg) {
  47396. if (l != r) throw new Error(msg || 'Assertion failed: ' + l + ' != ' + r);
  47397. };
  47398. },{}],329:[function(require,module,exports){
  47399. 'use strict';
  47400. var utils = exports;
  47401. function toArray(msg, enc) {
  47402. if (Array.isArray(msg)) return msg.slice();
  47403. if (!msg) return [];
  47404. var res = [];
  47405. if (typeof msg !== 'string') {
  47406. for (var i = 0; i < msg.length; i++) {
  47407. res[i] = msg[i] | 0;
  47408. }
  47409. return res;
  47410. }
  47411. if (enc === 'hex') {
  47412. msg = msg.replace(/[^a-z0-9]+/ig, '');
  47413. if (msg.length % 2 !== 0) msg = '0' + msg;
  47414. for (var i = 0; i < msg.length; i += 2) {
  47415. res.push(parseInt(msg[i] + msg[i + 1], 16));
  47416. }
  47417. } else {
  47418. for (var i = 0; i < msg.length; i++) {
  47419. var c = msg.charCodeAt(i);
  47420. var hi = c >> 8;
  47421. var lo = c & 0xff;
  47422. if (hi) res.push(hi, lo);else res.push(lo);
  47423. }
  47424. }
  47425. return res;
  47426. }
  47427. utils.toArray = toArray;
  47428. function zero2(word) {
  47429. if (word.length === 1) return '0' + word;else return word;
  47430. }
  47431. utils.zero2 = zero2;
  47432. function toHex(msg) {
  47433. var res = '';
  47434. for (var i = 0; i < msg.length; i++) {
  47435. res += zero2(msg[i].toString(16));
  47436. }
  47437. return res;
  47438. }
  47439. utils.toHex = toHex;
  47440. utils.encode = function encode(arr, enc) {
  47441. if (enc === 'hex') return toHex(arr);else return arr;
  47442. };
  47443. },{}],330:[function(require,module,exports){
  47444. // Top level file is just a mixin of submodules & constants
  47445. 'use strict';
  47446. var assign = require('./lib/utils/common').assign;
  47447. var deflate = require('./lib/deflate');
  47448. var inflate = require('./lib/inflate');
  47449. var constants = require('./lib/zlib/constants');
  47450. var pako = {};
  47451. assign(pako, deflate, inflate, constants);
  47452. module.exports = pako;
  47453. },{"./lib/deflate":331,"./lib/inflate":332,"./lib/utils/common":333,"./lib/zlib/constants":336}],331:[function(require,module,exports){
  47454. 'use strict';
  47455. var zlib_deflate = require('./zlib/deflate');
  47456. var utils = require('./utils/common');
  47457. var strings = require('./utils/strings');
  47458. var msg = require('./zlib/messages');
  47459. var ZStream = require('./zlib/zstream');
  47460. var toString = Object.prototype.toString;
  47461. /* Public constants ==========================================================*/
  47462. /* ===========================================================================*/
  47463. var Z_NO_FLUSH = 0;
  47464. var Z_FINISH = 4;
  47465. var Z_OK = 0;
  47466. var Z_STREAM_END = 1;
  47467. var Z_SYNC_FLUSH = 2;
  47468. var Z_DEFAULT_COMPRESSION = -1;
  47469. var Z_DEFAULT_STRATEGY = 0;
  47470. var Z_DEFLATED = 8;
  47471. /* ===========================================================================*/
  47472. /**
  47473. * class Deflate
  47474. *
  47475. * Generic JS-style wrapper for zlib calls. If you don't need
  47476. * streaming behaviour - use more simple functions: [[deflate]],
  47477. * [[deflateRaw]] and [[gzip]].
  47478. **/
  47479. /* internal
  47480. * Deflate.chunks -> Array
  47481. *
  47482. * Chunks of output data, if [[Deflate#onData]] not overridden.
  47483. **/
  47484. /**
  47485. * Deflate.result -> Uint8Array|Array
  47486. *
  47487. * Compressed result, generated by default [[Deflate#onData]]
  47488. * and [[Deflate#onEnd]] handlers. Filled after you push last chunk
  47489. * (call [[Deflate#push]] with `Z_FINISH` / `true` param) or if you
  47490. * push a chunk with explicit flush (call [[Deflate#push]] with
  47491. * `Z_SYNC_FLUSH` param).
  47492. **/
  47493. /**
  47494. * Deflate.err -> Number
  47495. *
  47496. * Error code after deflate finished. 0 (Z_OK) on success.
  47497. * You will not need it in real life, because deflate errors
  47498. * are possible only on wrong options or bad `onData` / `onEnd`
  47499. * custom handlers.
  47500. **/
  47501. /**
  47502. * Deflate.msg -> String
  47503. *
  47504. * Error message, if [[Deflate.err]] != 0
  47505. **/
  47506. /**
  47507. * new Deflate(options)
  47508. * - options (Object): zlib deflate options.
  47509. *
  47510. * Creates new deflator instance with specified params. Throws exception
  47511. * on bad params. Supported options:
  47512. *
  47513. * - `level`
  47514. * - `windowBits`
  47515. * - `memLevel`
  47516. * - `strategy`
  47517. * - `dictionary`
  47518. *
  47519. * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
  47520. * for more information on these.
  47521. *
  47522. * Additional options, for internal needs:
  47523. *
  47524. * - `chunkSize` - size of generated data chunks (16K by default)
  47525. * - `raw` (Boolean) - do raw deflate
  47526. * - `gzip` (Boolean) - create gzip wrapper
  47527. * - `to` (String) - if equal to 'string', then result will be "binary string"
  47528. * (each char code [0..255])
  47529. * - `header` (Object) - custom header for gzip
  47530. * - `text` (Boolean) - true if compressed data believed to be text
  47531. * - `time` (Number) - modification time, unix timestamp
  47532. * - `os` (Number) - operation system code
  47533. * - `extra` (Array) - array of bytes with extra data (max 65536)
  47534. * - `name` (String) - file name (binary string)
  47535. * - `comment` (String) - comment (binary string)
  47536. * - `hcrc` (Boolean) - true if header crc should be added
  47537. *
  47538. * ##### Example:
  47539. *
  47540. * ```javascript
  47541. * var pako = require('pako')
  47542. * , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])
  47543. * , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);
  47544. *
  47545. * var deflate = new pako.Deflate({ level: 3});
  47546. *
  47547. * deflate.push(chunk1, false);
  47548. * deflate.push(chunk2, true); // true -> last chunk
  47549. *
  47550. * if (deflate.err) { throw new Error(deflate.err); }
  47551. *
  47552. * console.log(deflate.result);
  47553. * ```
  47554. **/
  47555. function Deflate(options) {
  47556. if (!(this instanceof Deflate)) return new Deflate(options);
  47557. this.options = utils.assign({
  47558. level: Z_DEFAULT_COMPRESSION,
  47559. method: Z_DEFLATED,
  47560. chunkSize: 16384,
  47561. windowBits: 15,
  47562. memLevel: 8,
  47563. strategy: Z_DEFAULT_STRATEGY,
  47564. to: ''
  47565. }, options || {});
  47566. var opt = this.options;
  47567. if (opt.raw && opt.windowBits > 0) {
  47568. opt.windowBits = -opt.windowBits;
  47569. } else if (opt.gzip && opt.windowBits > 0 && opt.windowBits < 16) {
  47570. opt.windowBits += 16;
  47571. }
  47572. this.err = 0; // error code, if happens (0 = Z_OK)
  47573. this.msg = ''; // error message
  47574. this.ended = false; // used to avoid multiple onEnd() calls
  47575. this.chunks = []; // chunks of compressed data
  47576. this.strm = new ZStream();
  47577. this.strm.avail_out = 0;
  47578. var status = zlib_deflate.deflateInit2(this.strm, opt.level, opt.method, opt.windowBits, opt.memLevel, opt.strategy);
  47579. if (status !== Z_OK) {
  47580. throw new Error(msg[status]);
  47581. }
  47582. if (opt.header) {
  47583. zlib_deflate.deflateSetHeader(this.strm, opt.header);
  47584. }
  47585. if (opt.dictionary) {
  47586. var dict; // Convert data if needed
  47587. if (typeof opt.dictionary === 'string') {
  47588. // If we need to compress text, change encoding to utf8.
  47589. dict = strings.string2buf(opt.dictionary);
  47590. } else if (toString.call(opt.dictionary) === '[object ArrayBuffer]') {
  47591. dict = new Uint8Array(opt.dictionary);
  47592. } else {
  47593. dict = opt.dictionary;
  47594. }
  47595. status = zlib_deflate.deflateSetDictionary(this.strm, dict);
  47596. if (status !== Z_OK) {
  47597. throw new Error(msg[status]);
  47598. }
  47599. this._dict_set = true;
  47600. }
  47601. }
  47602. /**
  47603. * Deflate#push(data[, mode]) -> Boolean
  47604. * - data (Uint8Array|Array|ArrayBuffer|String): input data. Strings will be
  47605. * converted to utf8 byte sequence.
  47606. * - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
  47607. * See constants. Skipped or `false` means Z_NO_FLUSH, `true` means Z_FINISH.
  47608. *
  47609. * Sends input data to deflate pipe, generating [[Deflate#onData]] calls with
  47610. * new compressed chunks. Returns `true` on success. The last data block must have
  47611. * mode Z_FINISH (or `true`). That will flush internal pending buffers and call
  47612. * [[Deflate#onEnd]]. For interim explicit flushes (without ending the stream) you
  47613. * can use mode Z_SYNC_FLUSH, keeping the compression context.
  47614. *
  47615. * On fail call [[Deflate#onEnd]] with error code and return false.
  47616. *
  47617. * We strongly recommend to use `Uint8Array` on input for best speed (output
  47618. * array format is detected automatically). Also, don't skip last param and always
  47619. * use the same type in your code (boolean or number). That will improve JS speed.
  47620. *
  47621. * For regular `Array`-s make sure all elements are [0..255].
  47622. *
  47623. * ##### Example
  47624. *
  47625. * ```javascript
  47626. * push(chunk, false); // push one of data chunks
  47627. * ...
  47628. * push(chunk, true); // push last chunk
  47629. * ```
  47630. **/
  47631. Deflate.prototype.push = function (data, mode) {
  47632. var strm = this.strm;
  47633. var chunkSize = this.options.chunkSize;
  47634. var status, _mode;
  47635. if (this.ended) {
  47636. return false;
  47637. }
  47638. _mode = mode === ~~mode ? mode : mode === true ? Z_FINISH : Z_NO_FLUSH; // Convert data if needed
  47639. if (typeof data === 'string') {
  47640. // If we need to compress text, change encoding to utf8.
  47641. strm.input = strings.string2buf(data);
  47642. } else if (toString.call(data) === '[object ArrayBuffer]') {
  47643. strm.input = new Uint8Array(data);
  47644. } else {
  47645. strm.input = data;
  47646. }
  47647. strm.next_in = 0;
  47648. strm.avail_in = strm.input.length;
  47649. do {
  47650. if (strm.avail_out === 0) {
  47651. strm.output = new utils.Buf8(chunkSize);
  47652. strm.next_out = 0;
  47653. strm.avail_out = chunkSize;
  47654. }
  47655. status = zlib_deflate.deflate(strm, _mode);
  47656. /* no bad return value */
  47657. if (status !== Z_STREAM_END && status !== Z_OK) {
  47658. this.onEnd(status);
  47659. this.ended = true;
  47660. return false;
  47661. }
  47662. if (strm.avail_out === 0 || strm.avail_in === 0 && (_mode === Z_FINISH || _mode === Z_SYNC_FLUSH)) {
  47663. if (this.options.to === 'string') {
  47664. this.onData(strings.buf2binstring(utils.shrinkBuf(strm.output, strm.next_out)));
  47665. } else {
  47666. this.onData(utils.shrinkBuf(strm.output, strm.next_out));
  47667. }
  47668. }
  47669. } while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== Z_STREAM_END); // Finalize on the last chunk.
  47670. if (_mode === Z_FINISH) {
  47671. status = zlib_deflate.deflateEnd(this.strm);
  47672. this.onEnd(status);
  47673. this.ended = true;
  47674. return status === Z_OK;
  47675. } // callback interim results if Z_SYNC_FLUSH.
  47676. if (_mode === Z_SYNC_FLUSH) {
  47677. this.onEnd(Z_OK);
  47678. strm.avail_out = 0;
  47679. return true;
  47680. }
  47681. return true;
  47682. };
  47683. /**
  47684. * Deflate#onData(chunk) -> Void
  47685. * - chunk (Uint8Array|Array|String): output data. Type of array depends
  47686. * on js engine support. When string output requested, each chunk
  47687. * will be string.
  47688. *
  47689. * By default, stores data blocks in `chunks[]` property and glue
  47690. * those in `onEnd`. Override this handler, if you need another behaviour.
  47691. **/
  47692. Deflate.prototype.onData = function (chunk) {
  47693. this.chunks.push(chunk);
  47694. };
  47695. /**
  47696. * Deflate#onEnd(status) -> Void
  47697. * - status (Number): deflate status. 0 (Z_OK) on success,
  47698. * other if not.
  47699. *
  47700. * Called once after you tell deflate that the input stream is
  47701. * complete (Z_FINISH) or should be flushed (Z_SYNC_FLUSH)
  47702. * or if an error happened. By default - join collected chunks,
  47703. * free memory and fill `results` / `err` properties.
  47704. **/
  47705. Deflate.prototype.onEnd = function (status) {
  47706. // On success - join
  47707. if (status === Z_OK) {
  47708. if (this.options.to === 'string') {
  47709. this.result = this.chunks.join('');
  47710. } else {
  47711. this.result = utils.flattenChunks(this.chunks);
  47712. }
  47713. }
  47714. this.chunks = [];
  47715. this.err = status;
  47716. this.msg = this.strm.msg;
  47717. };
  47718. /**
  47719. * deflate(data[, options]) -> Uint8Array|Array|String
  47720. * - data (Uint8Array|Array|String): input data to compress.
  47721. * - options (Object): zlib deflate options.
  47722. *
  47723. * Compress `data` with deflate algorithm and `options`.
  47724. *
  47725. * Supported options are:
  47726. *
  47727. * - level
  47728. * - windowBits
  47729. * - memLevel
  47730. * - strategy
  47731. * - dictionary
  47732. *
  47733. * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
  47734. * for more information on these.
  47735. *
  47736. * Sugar (options):
  47737. *
  47738. * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify
  47739. * negative windowBits implicitly.
  47740. * - `to` (String) - if equal to 'string', then result will be "binary string"
  47741. * (each char code [0..255])
  47742. *
  47743. * ##### Example:
  47744. *
  47745. * ```javascript
  47746. * var pako = require('pako')
  47747. * , data = Uint8Array([1,2,3,4,5,6,7,8,9]);
  47748. *
  47749. * console.log(pako.deflate(data));
  47750. * ```
  47751. **/
  47752. function deflate(input, options) {
  47753. var deflator = new Deflate(options);
  47754. deflator.push(input, true); // That will never happens, if you don't cheat with options :)
  47755. if (deflator.err) {
  47756. throw deflator.msg || msg[deflator.err];
  47757. }
  47758. return deflator.result;
  47759. }
  47760. /**
  47761. * deflateRaw(data[, options]) -> Uint8Array|Array|String
  47762. * - data (Uint8Array|Array|String): input data to compress.
  47763. * - options (Object): zlib deflate options.
  47764. *
  47765. * The same as [[deflate]], but creates raw data, without wrapper
  47766. * (header and adler32 crc).
  47767. **/
  47768. function deflateRaw(input, options) {
  47769. options = options || {};
  47770. options.raw = true;
  47771. return deflate(input, options);
  47772. }
  47773. /**
  47774. * gzip(data[, options]) -> Uint8Array|Array|String
  47775. * - data (Uint8Array|Array|String): input data to compress.
  47776. * - options (Object): zlib deflate options.
  47777. *
  47778. * The same as [[deflate]], but create gzip wrapper instead of
  47779. * deflate one.
  47780. **/
  47781. function gzip(input, options) {
  47782. options = options || {};
  47783. options.gzip = true;
  47784. return deflate(input, options);
  47785. }
  47786. exports.Deflate = Deflate;
  47787. exports.deflate = deflate;
  47788. exports.deflateRaw = deflateRaw;
  47789. exports.gzip = gzip;
  47790. },{"./utils/common":333,"./utils/strings":334,"./zlib/deflate":338,"./zlib/messages":343,"./zlib/zstream":345}],332:[function(require,module,exports){
  47791. 'use strict';
  47792. var zlib_inflate = require('./zlib/inflate');
  47793. var utils = require('./utils/common');
  47794. var strings = require('./utils/strings');
  47795. var c = require('./zlib/constants');
  47796. var msg = require('./zlib/messages');
  47797. var ZStream = require('./zlib/zstream');
  47798. var GZheader = require('./zlib/gzheader');
  47799. var toString = Object.prototype.toString;
  47800. /**
  47801. * class Inflate
  47802. *
  47803. * Generic JS-style wrapper for zlib calls. If you don't need
  47804. * streaming behaviour - use more simple functions: [[inflate]]
  47805. * and [[inflateRaw]].
  47806. **/
  47807. /* internal
  47808. * inflate.chunks -> Array
  47809. *
  47810. * Chunks of output data, if [[Inflate#onData]] not overridden.
  47811. **/
  47812. /**
  47813. * Inflate.result -> Uint8Array|Array|String
  47814. *
  47815. * Uncompressed result, generated by default [[Inflate#onData]]
  47816. * and [[Inflate#onEnd]] handlers. Filled after you push last chunk
  47817. * (call [[Inflate#push]] with `Z_FINISH` / `true` param) or if you
  47818. * push a chunk with explicit flush (call [[Inflate#push]] with
  47819. * `Z_SYNC_FLUSH` param).
  47820. **/
  47821. /**
  47822. * Inflate.err -> Number
  47823. *
  47824. * Error code after inflate finished. 0 (Z_OK) on success.
  47825. * Should be checked if broken data possible.
  47826. **/
  47827. /**
  47828. * Inflate.msg -> String
  47829. *
  47830. * Error message, if [[Inflate.err]] != 0
  47831. **/
  47832. /**
  47833. * new Inflate(options)
  47834. * - options (Object): zlib inflate options.
  47835. *
  47836. * Creates new inflator instance with specified params. Throws exception
  47837. * on bad params. Supported options:
  47838. *
  47839. * - `windowBits`
  47840. * - `dictionary`
  47841. *
  47842. * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
  47843. * for more information on these.
  47844. *
  47845. * Additional options, for internal needs:
  47846. *
  47847. * - `chunkSize` - size of generated data chunks (16K by default)
  47848. * - `raw` (Boolean) - do raw inflate
  47849. * - `to` (String) - if equal to 'string', then result will be converted
  47850. * from utf8 to utf16 (javascript) string. When string output requested,
  47851. * chunk length can differ from `chunkSize`, depending on content.
  47852. *
  47853. * By default, when no options set, autodetect deflate/gzip data format via
  47854. * wrapper header.
  47855. *
  47856. * ##### Example:
  47857. *
  47858. * ```javascript
  47859. * var pako = require('pako')
  47860. * , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])
  47861. * , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);
  47862. *
  47863. * var inflate = new pako.Inflate({ level: 3});
  47864. *
  47865. * inflate.push(chunk1, false);
  47866. * inflate.push(chunk2, true); // true -> last chunk
  47867. *
  47868. * if (inflate.err) { throw new Error(inflate.err); }
  47869. *
  47870. * console.log(inflate.result);
  47871. * ```
  47872. **/
  47873. function Inflate(options) {
  47874. if (!(this instanceof Inflate)) return new Inflate(options);
  47875. this.options = utils.assign({
  47876. chunkSize: 16384,
  47877. windowBits: 0,
  47878. to: ''
  47879. }, options || {});
  47880. var opt = this.options; // Force window size for `raw` data, if not set directly,
  47881. // because we have no header for autodetect.
  47882. if (opt.raw && opt.windowBits >= 0 && opt.windowBits < 16) {
  47883. opt.windowBits = -opt.windowBits;
  47884. if (opt.windowBits === 0) {
  47885. opt.windowBits = -15;
  47886. }
  47887. } // If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate
  47888. if (opt.windowBits >= 0 && opt.windowBits < 16 && !(options && options.windowBits)) {
  47889. opt.windowBits += 32;
  47890. } // Gzip header has no info about windows size, we can do autodetect only
  47891. // for deflate. So, if window size not set, force it to max when gzip possible
  47892. if (opt.windowBits > 15 && opt.windowBits < 48) {
  47893. // bit 3 (16) -> gzipped data
  47894. // bit 4 (32) -> autodetect gzip/deflate
  47895. if ((opt.windowBits & 15) === 0) {
  47896. opt.windowBits |= 15;
  47897. }
  47898. }
  47899. this.err = 0; // error code, if happens (0 = Z_OK)
  47900. this.msg = ''; // error message
  47901. this.ended = false; // used to avoid multiple onEnd() calls
  47902. this.chunks = []; // chunks of compressed data
  47903. this.strm = new ZStream();
  47904. this.strm.avail_out = 0;
  47905. var status = zlib_inflate.inflateInit2(this.strm, opt.windowBits);
  47906. if (status !== c.Z_OK) {
  47907. throw new Error(msg[status]);
  47908. }
  47909. this.header = new GZheader();
  47910. zlib_inflate.inflateGetHeader(this.strm, this.header); // Setup dictionary
  47911. if (opt.dictionary) {
  47912. // Convert data if needed
  47913. if (typeof opt.dictionary === 'string') {
  47914. opt.dictionary = strings.string2buf(opt.dictionary);
  47915. } else if (toString.call(opt.dictionary) === '[object ArrayBuffer]') {
  47916. opt.dictionary = new Uint8Array(opt.dictionary);
  47917. }
  47918. if (opt.raw) {
  47919. //In raw mode we need to set the dictionary early
  47920. status = zlib_inflate.inflateSetDictionary(this.strm, opt.dictionary);
  47921. if (status !== c.Z_OK) {
  47922. throw new Error(msg[status]);
  47923. }
  47924. }
  47925. }
  47926. }
  47927. /**
  47928. * Inflate#push(data[, mode]) -> Boolean
  47929. * - data (Uint8Array|Array|ArrayBuffer|String): input data
  47930. * - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
  47931. * See constants. Skipped or `false` means Z_NO_FLUSH, `true` means Z_FINISH.
  47932. *
  47933. * Sends input data to inflate pipe, generating [[Inflate#onData]] calls with
  47934. * new output chunks. Returns `true` on success. The last data block must have
  47935. * mode Z_FINISH (or `true`). That will flush internal pending buffers and call
  47936. * [[Inflate#onEnd]]. For interim explicit flushes (without ending the stream) you
  47937. * can use mode Z_SYNC_FLUSH, keeping the decompression context.
  47938. *
  47939. * On fail call [[Inflate#onEnd]] with error code and return false.
  47940. *
  47941. * We strongly recommend to use `Uint8Array` on input for best speed (output
  47942. * format is detected automatically). Also, don't skip last param and always
  47943. * use the same type in your code (boolean or number). That will improve JS speed.
  47944. *
  47945. * For regular `Array`-s make sure all elements are [0..255].
  47946. *
  47947. * ##### Example
  47948. *
  47949. * ```javascript
  47950. * push(chunk, false); // push one of data chunks
  47951. * ...
  47952. * push(chunk, true); // push last chunk
  47953. * ```
  47954. **/
  47955. Inflate.prototype.push = function (data, mode) {
  47956. var strm = this.strm;
  47957. var chunkSize = this.options.chunkSize;
  47958. var dictionary = this.options.dictionary;
  47959. var status, _mode;
  47960. var next_out_utf8, tail, utf8str; // Flag to properly process Z_BUF_ERROR on testing inflate call
  47961. // when we check that all output data was flushed.
  47962. var allowBufError = false;
  47963. if (this.ended) {
  47964. return false;
  47965. }
  47966. _mode = mode === ~~mode ? mode : mode === true ? c.Z_FINISH : c.Z_NO_FLUSH; // Convert data if needed
  47967. if (typeof data === 'string') {
  47968. // Only binary strings can be decompressed on practice
  47969. strm.input = strings.binstring2buf(data);
  47970. } else if (toString.call(data) === '[object ArrayBuffer]') {
  47971. strm.input = new Uint8Array(data);
  47972. } else {
  47973. strm.input = data;
  47974. }
  47975. strm.next_in = 0;
  47976. strm.avail_in = strm.input.length;
  47977. do {
  47978. if (strm.avail_out === 0) {
  47979. strm.output = new utils.Buf8(chunkSize);
  47980. strm.next_out = 0;
  47981. strm.avail_out = chunkSize;
  47982. }
  47983. status = zlib_inflate.inflate(strm, c.Z_NO_FLUSH);
  47984. /* no bad return value */
  47985. if (status === c.Z_NEED_DICT && dictionary) {
  47986. status = zlib_inflate.inflateSetDictionary(this.strm, dictionary);
  47987. }
  47988. if (status === c.Z_BUF_ERROR && allowBufError === true) {
  47989. status = c.Z_OK;
  47990. allowBufError = false;
  47991. }
  47992. if (status !== c.Z_STREAM_END && status !== c.Z_OK) {
  47993. this.onEnd(status);
  47994. this.ended = true;
  47995. return false;
  47996. }
  47997. if (strm.next_out) {
  47998. if (strm.avail_out === 0 || status === c.Z_STREAM_END || strm.avail_in === 0 && (_mode === c.Z_FINISH || _mode === c.Z_SYNC_FLUSH)) {
  47999. if (this.options.to === 'string') {
  48000. next_out_utf8 = strings.utf8border(strm.output, strm.next_out);
  48001. tail = strm.next_out - next_out_utf8;
  48002. utf8str = strings.buf2string(strm.output, next_out_utf8); // move tail
  48003. strm.next_out = tail;
  48004. strm.avail_out = chunkSize - tail;
  48005. if (tail) {
  48006. utils.arraySet(strm.output, strm.output, next_out_utf8, tail, 0);
  48007. }
  48008. this.onData(utf8str);
  48009. } else {
  48010. this.onData(utils.shrinkBuf(strm.output, strm.next_out));
  48011. }
  48012. }
  48013. } // When no more input data, we should check that internal inflate buffers
  48014. // are flushed. The only way to do it when avail_out = 0 - run one more
  48015. // inflate pass. But if output data not exists, inflate return Z_BUF_ERROR.
  48016. // Here we set flag to process this error properly.
  48017. //
  48018. // NOTE. Deflate does not return error in this case and does not needs such
  48019. // logic.
  48020. if (strm.avail_in === 0 && strm.avail_out === 0) {
  48021. allowBufError = true;
  48022. }
  48023. } while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== c.Z_STREAM_END);
  48024. if (status === c.Z_STREAM_END) {
  48025. _mode = c.Z_FINISH;
  48026. } // Finalize on the last chunk.
  48027. if (_mode === c.Z_FINISH) {
  48028. status = zlib_inflate.inflateEnd(this.strm);
  48029. this.onEnd(status);
  48030. this.ended = true;
  48031. return status === c.Z_OK;
  48032. } // callback interim results if Z_SYNC_FLUSH.
  48033. if (_mode === c.Z_SYNC_FLUSH) {
  48034. this.onEnd(c.Z_OK);
  48035. strm.avail_out = 0;
  48036. return true;
  48037. }
  48038. return true;
  48039. };
  48040. /**
  48041. * Inflate#onData(chunk) -> Void
  48042. * - chunk (Uint8Array|Array|String): output data. Type of array depends
  48043. * on js engine support. When string output requested, each chunk
  48044. * will be string.
  48045. *
  48046. * By default, stores data blocks in `chunks[]` property and glue
  48047. * those in `onEnd`. Override this handler, if you need another behaviour.
  48048. **/
  48049. Inflate.prototype.onData = function (chunk) {
  48050. this.chunks.push(chunk);
  48051. };
  48052. /**
  48053. * Inflate#onEnd(status) -> Void
  48054. * - status (Number): inflate status. 0 (Z_OK) on success,
  48055. * other if not.
  48056. *
  48057. * Called either after you tell inflate that the input stream is
  48058. * complete (Z_FINISH) or should be flushed (Z_SYNC_FLUSH)
  48059. * or if an error happened. By default - join collected chunks,
  48060. * free memory and fill `results` / `err` properties.
  48061. **/
  48062. Inflate.prototype.onEnd = function (status) {
  48063. // On success - join
  48064. if (status === c.Z_OK) {
  48065. if (this.options.to === 'string') {
  48066. // Glue & convert here, until we teach pako to send
  48067. // utf8 aligned strings to onData
  48068. this.result = this.chunks.join('');
  48069. } else {
  48070. this.result = utils.flattenChunks(this.chunks);
  48071. }
  48072. }
  48073. this.chunks = [];
  48074. this.err = status;
  48075. this.msg = this.strm.msg;
  48076. };
  48077. /**
  48078. * inflate(data[, options]) -> Uint8Array|Array|String
  48079. * - data (Uint8Array|Array|String): input data to decompress.
  48080. * - options (Object): zlib inflate options.
  48081. *
  48082. * Decompress `data` with inflate/ungzip and `options`. Autodetect
  48083. * format via wrapper header by default. That's why we don't provide
  48084. * separate `ungzip` method.
  48085. *
  48086. * Supported options are:
  48087. *
  48088. * - windowBits
  48089. *
  48090. * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
  48091. * for more information.
  48092. *
  48093. * Sugar (options):
  48094. *
  48095. * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify
  48096. * negative windowBits implicitly.
  48097. * - `to` (String) - if equal to 'string', then result will be converted
  48098. * from utf8 to utf16 (javascript) string. When string output requested,
  48099. * chunk length can differ from `chunkSize`, depending on content.
  48100. *
  48101. *
  48102. * ##### Example:
  48103. *
  48104. * ```javascript
  48105. * var pako = require('pako')
  48106. * , input = pako.deflate([1,2,3,4,5,6,7,8,9])
  48107. * , output;
  48108. *
  48109. * try {
  48110. * output = pako.inflate(input);
  48111. * } catch (err)
  48112. * console.log(err);
  48113. * }
  48114. * ```
  48115. **/
  48116. function inflate(input, options) {
  48117. var inflator = new Inflate(options);
  48118. inflator.push(input, true); // That will never happens, if you don't cheat with options :)
  48119. if (inflator.err) {
  48120. throw inflator.msg || msg[inflator.err];
  48121. }
  48122. return inflator.result;
  48123. }
  48124. /**
  48125. * inflateRaw(data[, options]) -> Uint8Array|Array|String
  48126. * - data (Uint8Array|Array|String): input data to decompress.
  48127. * - options (Object): zlib inflate options.
  48128. *
  48129. * The same as [[inflate]], but creates raw data, without wrapper
  48130. * (header and adler32 crc).
  48131. **/
  48132. function inflateRaw(input, options) {
  48133. options = options || {};
  48134. options.raw = true;
  48135. return inflate(input, options);
  48136. }
  48137. /**
  48138. * ungzip(data[, options]) -> Uint8Array|Array|String
  48139. * - data (Uint8Array|Array|String): input data to decompress.
  48140. * - options (Object): zlib inflate options.
  48141. *
  48142. * Just shortcut to [[inflate]], because it autodetects format
  48143. * by header.content. Done for convenience.
  48144. **/
  48145. exports.Inflate = Inflate;
  48146. exports.inflate = inflate;
  48147. exports.inflateRaw = inflateRaw;
  48148. exports.ungzip = inflate;
  48149. },{"./utils/common":333,"./utils/strings":334,"./zlib/constants":336,"./zlib/gzheader":339,"./zlib/inflate":341,"./zlib/messages":343,"./zlib/zstream":345}],333:[function(require,module,exports){
  48150. 'use strict';
  48151. 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); }
  48152. var TYPED_OK = typeof Uint8Array !== 'undefined' && typeof Uint16Array !== 'undefined' && typeof Int32Array !== 'undefined';
  48153. function _has(obj, key) {
  48154. return Object.prototype.hasOwnProperty.call(obj, key);
  48155. }
  48156. exports.assign = function (obj
  48157. /*from1, from2, from3, ...*/
  48158. ) {
  48159. var sources = Array.prototype.slice.call(arguments, 1);
  48160. while (sources.length) {
  48161. var source = sources.shift();
  48162. if (!source) {
  48163. continue;
  48164. }
  48165. if (_typeof(source) !== 'object') {
  48166. throw new TypeError(source + 'must be non-object');
  48167. }
  48168. for (var p in source) {
  48169. if (_has(source, p)) {
  48170. obj[p] = source[p];
  48171. }
  48172. }
  48173. }
  48174. return obj;
  48175. }; // reduce buffer size, avoiding mem copy
  48176. exports.shrinkBuf = function (buf, size) {
  48177. if (buf.length === size) {
  48178. return buf;
  48179. }
  48180. if (buf.subarray) {
  48181. return buf.subarray(0, size);
  48182. }
  48183. buf.length = size;
  48184. return buf;
  48185. };
  48186. var fnTyped = {
  48187. arraySet: function arraySet(dest, src, src_offs, len, dest_offs) {
  48188. if (src.subarray && dest.subarray) {
  48189. dest.set(src.subarray(src_offs, src_offs + len), dest_offs);
  48190. return;
  48191. } // Fallback to ordinary array
  48192. for (var i = 0; i < len; i++) {
  48193. dest[dest_offs + i] = src[src_offs + i];
  48194. }
  48195. },
  48196. // Join array of chunks to single array.
  48197. flattenChunks: function flattenChunks(chunks) {
  48198. var i, l, len, pos, chunk, result; // calculate data length
  48199. len = 0;
  48200. for (i = 0, l = chunks.length; i < l; i++) {
  48201. len += chunks[i].length;
  48202. } // join chunks
  48203. result = new Uint8Array(len);
  48204. pos = 0;
  48205. for (i = 0, l = chunks.length; i < l; i++) {
  48206. chunk = chunks[i];
  48207. result.set(chunk, pos);
  48208. pos += chunk.length;
  48209. }
  48210. return result;
  48211. }
  48212. };
  48213. var fnUntyped = {
  48214. arraySet: function arraySet(dest, src, src_offs, len, dest_offs) {
  48215. for (var i = 0; i < len; i++) {
  48216. dest[dest_offs + i] = src[src_offs + i];
  48217. }
  48218. },
  48219. // Join array of chunks to single array.
  48220. flattenChunks: function flattenChunks(chunks) {
  48221. return [].concat.apply([], chunks);
  48222. }
  48223. }; // Enable/Disable typed arrays use, for testing
  48224. //
  48225. exports.setTyped = function (on) {
  48226. if (on) {
  48227. exports.Buf8 = Uint8Array;
  48228. exports.Buf16 = Uint16Array;
  48229. exports.Buf32 = Int32Array;
  48230. exports.assign(exports, fnTyped);
  48231. } else {
  48232. exports.Buf8 = Array;
  48233. exports.Buf16 = Array;
  48234. exports.Buf32 = Array;
  48235. exports.assign(exports, fnUntyped);
  48236. }
  48237. };
  48238. exports.setTyped(TYPED_OK);
  48239. },{}],334:[function(require,module,exports){
  48240. // String encode/decode helpers
  48241. 'use strict';
  48242. var utils = require('./common'); // Quick check if we can use fast array to bin string conversion
  48243. //
  48244. // - apply(Array) can fail on Android 2.2
  48245. // - apply(Uint8Array) can fail on iOS 5.1 Safari
  48246. //
  48247. var STR_APPLY_OK = true;
  48248. var STR_APPLY_UIA_OK = true;
  48249. try {
  48250. String.fromCharCode.apply(null, [0]);
  48251. } catch (__) {
  48252. STR_APPLY_OK = false;
  48253. }
  48254. try {
  48255. String.fromCharCode.apply(null, new Uint8Array(1));
  48256. } catch (__) {
  48257. STR_APPLY_UIA_OK = false;
  48258. } // Table with utf8 lengths (calculated by first byte of sequence)
  48259. // Note, that 5 & 6-byte values and some 4-byte values can not be represented in JS,
  48260. // because max possible codepoint is 0x10ffff
  48261. var _utf8len = new utils.Buf8(256);
  48262. for (var q = 0; q < 256; q++) {
  48263. _utf8len[q] = q >= 252 ? 6 : q >= 248 ? 5 : q >= 240 ? 4 : q >= 224 ? 3 : q >= 192 ? 2 : 1;
  48264. }
  48265. _utf8len[254] = _utf8len[254] = 1; // Invalid sequence start
  48266. // convert string to array (typed, when possible)
  48267. exports.string2buf = function (str) {
  48268. var buf,
  48269. c,
  48270. c2,
  48271. m_pos,
  48272. i,
  48273. str_len = str.length,
  48274. buf_len = 0; // count binary size
  48275. for (m_pos = 0; m_pos < str_len; m_pos++) {
  48276. c = str.charCodeAt(m_pos);
  48277. if ((c & 0xfc00) === 0xd800 && m_pos + 1 < str_len) {
  48278. c2 = str.charCodeAt(m_pos + 1);
  48279. if ((c2 & 0xfc00) === 0xdc00) {
  48280. c = 0x10000 + (c - 0xd800 << 10) + (c2 - 0xdc00);
  48281. m_pos++;
  48282. }
  48283. }
  48284. buf_len += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4;
  48285. } // allocate buffer
  48286. buf = new utils.Buf8(buf_len); // convert
  48287. for (i = 0, m_pos = 0; i < buf_len; m_pos++) {
  48288. c = str.charCodeAt(m_pos);
  48289. if ((c & 0xfc00) === 0xd800 && m_pos + 1 < str_len) {
  48290. c2 = str.charCodeAt(m_pos + 1);
  48291. if ((c2 & 0xfc00) === 0xdc00) {
  48292. c = 0x10000 + (c - 0xd800 << 10) + (c2 - 0xdc00);
  48293. m_pos++;
  48294. }
  48295. }
  48296. if (c < 0x80) {
  48297. /* one byte */
  48298. buf[i++] = c;
  48299. } else if (c < 0x800) {
  48300. /* two bytes */
  48301. buf[i++] = 0xC0 | c >>> 6;
  48302. buf[i++] = 0x80 | c & 0x3f;
  48303. } else if (c < 0x10000) {
  48304. /* three bytes */
  48305. buf[i++] = 0xE0 | c >>> 12;
  48306. buf[i++] = 0x80 | c >>> 6 & 0x3f;
  48307. buf[i++] = 0x80 | c & 0x3f;
  48308. } else {
  48309. /* four bytes */
  48310. buf[i++] = 0xf0 | c >>> 18;
  48311. buf[i++] = 0x80 | c >>> 12 & 0x3f;
  48312. buf[i++] = 0x80 | c >>> 6 & 0x3f;
  48313. buf[i++] = 0x80 | c & 0x3f;
  48314. }
  48315. }
  48316. return buf;
  48317. }; // Helper (used in 2 places)
  48318. function buf2binstring(buf, len) {
  48319. // On Chrome, the arguments in a function call that are allowed is `65534`.
  48320. // If the length of the buffer is smaller than that, we can use this optimization,
  48321. // otherwise we will take a slower path.
  48322. if (len < 65534) {
  48323. if (buf.subarray && STR_APPLY_UIA_OK || !buf.subarray && STR_APPLY_OK) {
  48324. return String.fromCharCode.apply(null, utils.shrinkBuf(buf, len));
  48325. }
  48326. }
  48327. var result = '';
  48328. for (var i = 0; i < len; i++) {
  48329. result += String.fromCharCode(buf[i]);
  48330. }
  48331. return result;
  48332. } // Convert byte array to binary string
  48333. exports.buf2binstring = function (buf) {
  48334. return buf2binstring(buf, buf.length);
  48335. }; // Convert binary string (typed, when possible)
  48336. exports.binstring2buf = function (str) {
  48337. var buf = new utils.Buf8(str.length);
  48338. for (var i = 0, len = buf.length; i < len; i++) {
  48339. buf[i] = str.charCodeAt(i);
  48340. }
  48341. return buf;
  48342. }; // convert array to string
  48343. exports.buf2string = function (buf, max) {
  48344. var i, out, c, c_len;
  48345. var len = max || buf.length; // Reserve max possible length (2 words per char)
  48346. // NB: by unknown reasons, Array is significantly faster for
  48347. // String.fromCharCode.apply than Uint16Array.
  48348. var utf16buf = new Array(len * 2);
  48349. for (out = 0, i = 0; i < len;) {
  48350. c = buf[i++]; // quick process ascii
  48351. if (c < 0x80) {
  48352. utf16buf[out++] = c;
  48353. continue;
  48354. }
  48355. c_len = _utf8len[c]; // skip 5 & 6 byte codes
  48356. if (c_len > 4) {
  48357. utf16buf[out++] = 0xfffd;
  48358. i += c_len - 1;
  48359. continue;
  48360. } // apply mask on first byte
  48361. c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07; // join the rest
  48362. while (c_len > 1 && i < len) {
  48363. c = c << 6 | buf[i++] & 0x3f;
  48364. c_len--;
  48365. } // terminated by end of string?
  48366. if (c_len > 1) {
  48367. utf16buf[out++] = 0xfffd;
  48368. continue;
  48369. }
  48370. if (c < 0x10000) {
  48371. utf16buf[out++] = c;
  48372. } else {
  48373. c -= 0x10000;
  48374. utf16buf[out++] = 0xd800 | c >> 10 & 0x3ff;
  48375. utf16buf[out++] = 0xdc00 | c & 0x3ff;
  48376. }
  48377. }
  48378. return buf2binstring(utf16buf, out);
  48379. }; // Calculate max possible position in utf8 buffer,
  48380. // that will not break sequence. If that's not possible
  48381. // - (very small limits) return max size as is.
  48382. //
  48383. // buf[] - utf8 bytes array
  48384. // max - length limit (mandatory);
  48385. exports.utf8border = function (buf, max) {
  48386. var pos;
  48387. max = max || buf.length;
  48388. if (max > buf.length) {
  48389. max = buf.length;
  48390. } // go back from last position, until start of sequence found
  48391. pos = max - 1;
  48392. while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) {
  48393. pos--;
  48394. } // Very small and broken sequence,
  48395. // return max, because we should return something anyway.
  48396. if (pos < 0) {
  48397. return max;
  48398. } // If we came to start of buffer - that means buffer is too small,
  48399. // return max too.
  48400. if (pos === 0) {
  48401. return max;
  48402. }
  48403. return pos + _utf8len[buf[pos]] > max ? pos : max;
  48404. };
  48405. },{"./common":333}],335:[function(require,module,exports){
  48406. 'use strict'; // Note: adler32 takes 12% for level 0 and 2% for level 6.
  48407. // It isn't worth it to make additional optimizations as in original.
  48408. // Small size is preferable.
  48409. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  48410. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  48411. //
  48412. // This software is provided 'as-is', without any express or implied
  48413. // warranty. In no event will the authors be held liable for any damages
  48414. // arising from the use of this software.
  48415. //
  48416. // Permission is granted to anyone to use this software for any purpose,
  48417. // including commercial applications, and to alter it and redistribute it
  48418. // freely, subject to the following restrictions:
  48419. //
  48420. // 1. The origin of this software must not be misrepresented; you must not
  48421. // claim that you wrote the original software. If you use this software
  48422. // in a product, an acknowledgment in the product documentation would be
  48423. // appreciated but is not required.
  48424. // 2. Altered source versions must be plainly marked as such, and must not be
  48425. // misrepresented as being the original software.
  48426. // 3. This notice may not be removed or altered from any source distribution.
  48427. function adler32(adler, buf, len, pos) {
  48428. var s1 = adler & 0xffff | 0,
  48429. s2 = adler >>> 16 & 0xffff | 0,
  48430. n = 0;
  48431. while (len !== 0) {
  48432. // Set limit ~ twice less than 5552, to keep
  48433. // s2 in 31-bits, because we force signed ints.
  48434. // in other case %= will fail.
  48435. n = len > 2000 ? 2000 : len;
  48436. len -= n;
  48437. do {
  48438. s1 = s1 + buf[pos++] | 0;
  48439. s2 = s2 + s1 | 0;
  48440. } while (--n);
  48441. s1 %= 65521;
  48442. s2 %= 65521;
  48443. }
  48444. return s1 | s2 << 16 | 0;
  48445. }
  48446. module.exports = adler32;
  48447. },{}],336:[function(require,module,exports){
  48448. 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  48449. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  48450. //
  48451. // This software is provided 'as-is', without any express or implied
  48452. // warranty. In no event will the authors be held liable for any damages
  48453. // arising from the use of this software.
  48454. //
  48455. // Permission is granted to anyone to use this software for any purpose,
  48456. // including commercial applications, and to alter it and redistribute it
  48457. // freely, subject to the following restrictions:
  48458. //
  48459. // 1. The origin of this software must not be misrepresented; you must not
  48460. // claim that you wrote the original software. If you use this software
  48461. // in a product, an acknowledgment in the product documentation would be
  48462. // appreciated but is not required.
  48463. // 2. Altered source versions must be plainly marked as such, and must not be
  48464. // misrepresented as being the original software.
  48465. // 3. This notice may not be removed or altered from any source distribution.
  48466. module.exports = {
  48467. /* Allowed flush values; see deflate() and inflate() below for details */
  48468. Z_NO_FLUSH: 0,
  48469. Z_PARTIAL_FLUSH: 1,
  48470. Z_SYNC_FLUSH: 2,
  48471. Z_FULL_FLUSH: 3,
  48472. Z_FINISH: 4,
  48473. Z_BLOCK: 5,
  48474. Z_TREES: 6,
  48475. /* Return codes for the compression/decompression functions. Negative values
  48476. * are errors, positive values are used for special but normal events.
  48477. */
  48478. Z_OK: 0,
  48479. Z_STREAM_END: 1,
  48480. Z_NEED_DICT: 2,
  48481. Z_ERRNO: -1,
  48482. Z_STREAM_ERROR: -2,
  48483. Z_DATA_ERROR: -3,
  48484. //Z_MEM_ERROR: -4,
  48485. Z_BUF_ERROR: -5,
  48486. //Z_VERSION_ERROR: -6,
  48487. /* compression levels */
  48488. Z_NO_COMPRESSION: 0,
  48489. Z_BEST_SPEED: 1,
  48490. Z_BEST_COMPRESSION: 9,
  48491. Z_DEFAULT_COMPRESSION: -1,
  48492. Z_FILTERED: 1,
  48493. Z_HUFFMAN_ONLY: 2,
  48494. Z_RLE: 3,
  48495. Z_FIXED: 4,
  48496. Z_DEFAULT_STRATEGY: 0,
  48497. /* Possible values of the data_type field (though see inflate()) */
  48498. Z_BINARY: 0,
  48499. Z_TEXT: 1,
  48500. //Z_ASCII: 1, // = Z_TEXT (deprecated)
  48501. Z_UNKNOWN: 2,
  48502. /* The deflate compression method */
  48503. Z_DEFLATED: 8 //Z_NULL: null // Use -1 or null inline, depending on var type
  48504. };
  48505. },{}],337:[function(require,module,exports){
  48506. 'use strict'; // Note: we can't get significant speed boost here.
  48507. // So write code to minimize size - no pregenerated tables
  48508. // and array tools dependencies.
  48509. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  48510. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  48511. //
  48512. // This software is provided 'as-is', without any express or implied
  48513. // warranty. In no event will the authors be held liable for any damages
  48514. // arising from the use of this software.
  48515. //
  48516. // Permission is granted to anyone to use this software for any purpose,
  48517. // including commercial applications, and to alter it and redistribute it
  48518. // freely, subject to the following restrictions:
  48519. //
  48520. // 1. The origin of this software must not be misrepresented; you must not
  48521. // claim that you wrote the original software. If you use this software
  48522. // in a product, an acknowledgment in the product documentation would be
  48523. // appreciated but is not required.
  48524. // 2. Altered source versions must be plainly marked as such, and must not be
  48525. // misrepresented as being the original software.
  48526. // 3. This notice may not be removed or altered from any source distribution.
  48527. // Use ordinary array, since untyped makes no boost here
  48528. function makeTable() {
  48529. var c,
  48530. table = [];
  48531. for (var n = 0; n < 256; n++) {
  48532. c = n;
  48533. for (var k = 0; k < 8; k++) {
  48534. c = c & 1 ? 0xEDB88320 ^ c >>> 1 : c >>> 1;
  48535. }
  48536. table[n] = c;
  48537. }
  48538. return table;
  48539. } // Create table on load. Just 255 signed longs. Not a problem.
  48540. var crcTable = makeTable();
  48541. function crc32(crc, buf, len, pos) {
  48542. var t = crcTable,
  48543. end = pos + len;
  48544. crc ^= -1;
  48545. for (var i = pos; i < end; i++) {
  48546. crc = crc >>> 8 ^ t[(crc ^ buf[i]) & 0xFF];
  48547. }
  48548. return crc ^ -1; // >>> 0;
  48549. }
  48550. module.exports = crc32;
  48551. },{}],338:[function(require,module,exports){
  48552. 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  48553. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  48554. //
  48555. // This software is provided 'as-is', without any express or implied
  48556. // warranty. In no event will the authors be held liable for any damages
  48557. // arising from the use of this software.
  48558. //
  48559. // Permission is granted to anyone to use this software for any purpose,
  48560. // including commercial applications, and to alter it and redistribute it
  48561. // freely, subject to the following restrictions:
  48562. //
  48563. // 1. The origin of this software must not be misrepresented; you must not
  48564. // claim that you wrote the original software. If you use this software
  48565. // in a product, an acknowledgment in the product documentation would be
  48566. // appreciated but is not required.
  48567. // 2. Altered source versions must be plainly marked as such, and must not be
  48568. // misrepresented as being the original software.
  48569. // 3. This notice may not be removed or altered from any source distribution.
  48570. var utils = require('../utils/common');
  48571. var trees = require('./trees');
  48572. var adler32 = require('./adler32');
  48573. var crc32 = require('./crc32');
  48574. var msg = require('./messages');
  48575. /* Public constants ==========================================================*/
  48576. /* ===========================================================================*/
  48577. /* Allowed flush values; see deflate() and inflate() below for details */
  48578. var Z_NO_FLUSH = 0;
  48579. var Z_PARTIAL_FLUSH = 1; //var Z_SYNC_FLUSH = 2;
  48580. var Z_FULL_FLUSH = 3;
  48581. var Z_FINISH = 4;
  48582. var Z_BLOCK = 5; //var Z_TREES = 6;
  48583. /* Return codes for the compression/decompression functions. Negative values
  48584. * are errors, positive values are used for special but normal events.
  48585. */
  48586. var Z_OK = 0;
  48587. var Z_STREAM_END = 1; //var Z_NEED_DICT = 2;
  48588. //var Z_ERRNO = -1;
  48589. var Z_STREAM_ERROR = -2;
  48590. var Z_DATA_ERROR = -3; //var Z_MEM_ERROR = -4;
  48591. var Z_BUF_ERROR = -5; //var Z_VERSION_ERROR = -6;
  48592. /* compression levels */
  48593. //var Z_NO_COMPRESSION = 0;
  48594. //var Z_BEST_SPEED = 1;
  48595. //var Z_BEST_COMPRESSION = 9;
  48596. var Z_DEFAULT_COMPRESSION = -1;
  48597. var Z_FILTERED = 1;
  48598. var Z_HUFFMAN_ONLY = 2;
  48599. var Z_RLE = 3;
  48600. var Z_FIXED = 4;
  48601. var Z_DEFAULT_STRATEGY = 0;
  48602. /* Possible values of the data_type field (though see inflate()) */
  48603. //var Z_BINARY = 0;
  48604. //var Z_TEXT = 1;
  48605. //var Z_ASCII = 1; // = Z_TEXT
  48606. var Z_UNKNOWN = 2;
  48607. /* The deflate compression method */
  48608. var Z_DEFLATED = 8;
  48609. /*============================================================================*/
  48610. var MAX_MEM_LEVEL = 9;
  48611. /* Maximum value for memLevel in deflateInit2 */
  48612. var MAX_WBITS = 15;
  48613. /* 32K LZ77 window */
  48614. var DEF_MEM_LEVEL = 8;
  48615. var LENGTH_CODES = 29;
  48616. /* number of length codes, not counting the special END_BLOCK code */
  48617. var LITERALS = 256;
  48618. /* number of literal bytes 0..255 */
  48619. var L_CODES = LITERALS + 1 + LENGTH_CODES;
  48620. /* number of Literal or Length codes, including the END_BLOCK code */
  48621. var D_CODES = 30;
  48622. /* number of distance codes */
  48623. var BL_CODES = 19;
  48624. /* number of codes used to transfer the bit lengths */
  48625. var HEAP_SIZE = 2 * L_CODES + 1;
  48626. /* maximum heap size */
  48627. var MAX_BITS = 15;
  48628. /* All codes must not exceed MAX_BITS bits */
  48629. var MIN_MATCH = 3;
  48630. var MAX_MATCH = 258;
  48631. var MIN_LOOKAHEAD = MAX_MATCH + MIN_MATCH + 1;
  48632. var PRESET_DICT = 0x20;
  48633. var INIT_STATE = 42;
  48634. var EXTRA_STATE = 69;
  48635. var NAME_STATE = 73;
  48636. var COMMENT_STATE = 91;
  48637. var HCRC_STATE = 103;
  48638. var BUSY_STATE = 113;
  48639. var FINISH_STATE = 666;
  48640. var BS_NEED_MORE = 1;
  48641. /* block not completed, need more input or more output */
  48642. var BS_BLOCK_DONE = 2;
  48643. /* block flush performed */
  48644. var BS_FINISH_STARTED = 3;
  48645. /* finish started, need only more output at next deflate */
  48646. var BS_FINISH_DONE = 4;
  48647. /* finish done, accept no more input or output */
  48648. var OS_CODE = 0x03; // Unix :) . Don't detect, use this default.
  48649. function err(strm, errorCode) {
  48650. strm.msg = msg[errorCode];
  48651. return errorCode;
  48652. }
  48653. function rank(f) {
  48654. return (f << 1) - (f > 4 ? 9 : 0);
  48655. }
  48656. function zero(buf) {
  48657. var len = buf.length;
  48658. while (--len >= 0) {
  48659. buf[len] = 0;
  48660. }
  48661. }
  48662. /* =========================================================================
  48663. * Flush as much pending output as possible. All deflate() output goes
  48664. * through this function so some applications may wish to modify it
  48665. * to avoid allocating a large strm->output buffer and copying into it.
  48666. * (See also read_buf()).
  48667. */
  48668. function flush_pending(strm) {
  48669. var s = strm.state; //_tr_flush_bits(s);
  48670. var len = s.pending;
  48671. if (len > strm.avail_out) {
  48672. len = strm.avail_out;
  48673. }
  48674. if (len === 0) {
  48675. return;
  48676. }
  48677. utils.arraySet(strm.output, s.pending_buf, s.pending_out, len, strm.next_out);
  48678. strm.next_out += len;
  48679. s.pending_out += len;
  48680. strm.total_out += len;
  48681. strm.avail_out -= len;
  48682. s.pending -= len;
  48683. if (s.pending === 0) {
  48684. s.pending_out = 0;
  48685. }
  48686. }
  48687. function flush_block_only(s, last) {
  48688. trees._tr_flush_block(s, s.block_start >= 0 ? s.block_start : -1, s.strstart - s.block_start, last);
  48689. s.block_start = s.strstart;
  48690. flush_pending(s.strm);
  48691. }
  48692. function put_byte(s, b) {
  48693. s.pending_buf[s.pending++] = b;
  48694. }
  48695. /* =========================================================================
  48696. * Put a short in the pending buffer. The 16-bit value is put in MSB order.
  48697. * IN assertion: the stream state is correct and there is enough room in
  48698. * pending_buf.
  48699. */
  48700. function putShortMSB(s, b) {
  48701. // put_byte(s, (Byte)(b >> 8));
  48702. // put_byte(s, (Byte)(b & 0xff));
  48703. s.pending_buf[s.pending++] = b >>> 8 & 0xff;
  48704. s.pending_buf[s.pending++] = b & 0xff;
  48705. }
  48706. /* ===========================================================================
  48707. * Read a new buffer from the current input stream, update the adler32
  48708. * and total number of bytes read. All deflate() input goes through
  48709. * this function so some applications may wish to modify it to avoid
  48710. * allocating a large strm->input buffer and copying from it.
  48711. * (See also flush_pending()).
  48712. */
  48713. function read_buf(strm, buf, start, size) {
  48714. var len = strm.avail_in;
  48715. if (len > size) {
  48716. len = size;
  48717. }
  48718. if (len === 0) {
  48719. return 0;
  48720. }
  48721. strm.avail_in -= len; // zmemcpy(buf, strm->next_in, len);
  48722. utils.arraySet(buf, strm.input, strm.next_in, len, start);
  48723. if (strm.state.wrap === 1) {
  48724. strm.adler = adler32(strm.adler, buf, len, start);
  48725. } else if (strm.state.wrap === 2) {
  48726. strm.adler = crc32(strm.adler, buf, len, start);
  48727. }
  48728. strm.next_in += len;
  48729. strm.total_in += len;
  48730. return len;
  48731. }
  48732. /* ===========================================================================
  48733. * Set match_start to the longest match starting at the given string and
  48734. * return its length. Matches shorter or equal to prev_length are discarded,
  48735. * in which case the result is equal to prev_length and match_start is
  48736. * garbage.
  48737. * IN assertions: cur_match is the head of the hash chain for the current
  48738. * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
  48739. * OUT assertion: the match length is not greater than s->lookahead.
  48740. */
  48741. function longest_match(s, cur_match) {
  48742. var chain_length = s.max_chain_length;
  48743. /* max hash chain length */
  48744. var scan = s.strstart;
  48745. /* current string */
  48746. var match;
  48747. /* matched string */
  48748. var len;
  48749. /* length of current match */
  48750. var best_len = s.prev_length;
  48751. /* best match length so far */
  48752. var nice_match = s.nice_match;
  48753. /* stop if match long enough */
  48754. var limit = s.strstart > s.w_size - MIN_LOOKAHEAD ? s.strstart - (s.w_size - MIN_LOOKAHEAD) : 0
  48755. /*NIL*/
  48756. ;
  48757. var _win = s.window; // shortcut
  48758. var wmask = s.w_mask;
  48759. var prev = s.prev;
  48760. /* Stop when cur_match becomes <= limit. To simplify the code,
  48761. * we prevent matches with the string of window index 0.
  48762. */
  48763. var strend = s.strstart + MAX_MATCH;
  48764. var scan_end1 = _win[scan + best_len - 1];
  48765. var scan_end = _win[scan + best_len];
  48766. /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
  48767. * It is easy to get rid of this optimization if necessary.
  48768. */
  48769. // Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  48770. /* Do not waste too much time if we already have a good match: */
  48771. if (s.prev_length >= s.good_match) {
  48772. chain_length >>= 2;
  48773. }
  48774. /* Do not look for matches beyond the end of the input. This is necessary
  48775. * to make deflate deterministic.
  48776. */
  48777. if (nice_match > s.lookahead) {
  48778. nice_match = s.lookahead;
  48779. } // Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  48780. do {
  48781. // Assert(cur_match < s->strstart, "no future");
  48782. match = cur_match;
  48783. /* Skip to next match if the match length cannot increase
  48784. * or if the match length is less than 2. Note that the checks below
  48785. * for insufficient lookahead only occur occasionally for performance
  48786. * reasons. Therefore uninitialized memory will be accessed, and
  48787. * conditional jumps will be made that depend on those values.
  48788. * However the length of the match is limited to the lookahead, so
  48789. * the output of deflate is not affected by the uninitialized values.
  48790. */
  48791. if (_win[match + best_len] !== scan_end || _win[match + best_len - 1] !== scan_end1 || _win[match] !== _win[scan] || _win[++match] !== _win[scan + 1]) {
  48792. continue;
  48793. }
  48794. /* The check at best_len-1 can be removed because it will be made
  48795. * again later. (This heuristic is not always a win.)
  48796. * It is not necessary to compare scan[2] and match[2] since they
  48797. * are always equal when the other bytes match, given that
  48798. * the hash keys are equal and that HASH_BITS >= 8.
  48799. */
  48800. scan += 2;
  48801. match++; // Assert(*scan == *match, "match[2]?");
  48802. /* We check for insufficient lookahead only every 8th comparison;
  48803. * the 256th check will be made at strstart+258.
  48804. */
  48805. do {
  48806. /*jshint noempty:false*/
  48807. } 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");
  48808. len = MAX_MATCH - (strend - scan);
  48809. scan = strend - MAX_MATCH;
  48810. if (len > best_len) {
  48811. s.match_start = cur_match;
  48812. best_len = len;
  48813. if (len >= nice_match) {
  48814. break;
  48815. }
  48816. scan_end1 = _win[scan + best_len - 1];
  48817. scan_end = _win[scan + best_len];
  48818. }
  48819. } while ((cur_match = prev[cur_match & wmask]) > limit && --chain_length !== 0);
  48820. if (best_len <= s.lookahead) {
  48821. return best_len;
  48822. }
  48823. return s.lookahead;
  48824. }
  48825. /* ===========================================================================
  48826. * Fill the window when the lookahead becomes insufficient.
  48827. * Updates strstart and lookahead.
  48828. *
  48829. * IN assertion: lookahead < MIN_LOOKAHEAD
  48830. * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
  48831. * At least one byte has been read, or avail_in == 0; reads are
  48832. * performed for at least two bytes (required for the zip translate_eol
  48833. * option -- not supported here).
  48834. */
  48835. function fill_window(s) {
  48836. var _w_size = s.w_size;
  48837. var p, n, m, more, str; //Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
  48838. do {
  48839. more = s.window_size - s.lookahead - s.strstart; // JS ints have 32 bit, block below not needed
  48840. /* Deal with !@#$% 64K limit: */
  48841. //if (sizeof(int) <= 2) {
  48842. // if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  48843. // more = wsize;
  48844. //
  48845. // } else if (more == (unsigned)(-1)) {
  48846. // /* Very unlikely, but possible on 16 bit machine if
  48847. // * strstart == 0 && lookahead == 1 (input done a byte at time)
  48848. // */
  48849. // more--;
  48850. // }
  48851. //}
  48852. /* If the window is almost full and there is insufficient lookahead,
  48853. * move the upper half to the lower one to make room in the upper half.
  48854. */
  48855. if (s.strstart >= _w_size + (_w_size - MIN_LOOKAHEAD)) {
  48856. utils.arraySet(s.window, s.window, _w_size, _w_size, 0);
  48857. s.match_start -= _w_size;
  48858. s.strstart -= _w_size;
  48859. /* we now have strstart >= MAX_DIST */
  48860. s.block_start -= _w_size;
  48861. /* Slide the hash table (could be avoided with 32 bit values
  48862. at the expense of memory usage). We slide even when level == 0
  48863. to keep the hash table consistent if we switch back to level > 0
  48864. later. (Using level 0 permanently is not an optimal usage of
  48865. zlib, so we don't care about this pathological case.)
  48866. */
  48867. n = s.hash_size;
  48868. p = n;
  48869. do {
  48870. m = s.head[--p];
  48871. s.head[p] = m >= _w_size ? m - _w_size : 0;
  48872. } while (--n);
  48873. n = _w_size;
  48874. p = n;
  48875. do {
  48876. m = s.prev[--p];
  48877. s.prev[p] = m >= _w_size ? m - _w_size : 0;
  48878. /* If n is not on any hash chain, prev[n] is garbage but
  48879. * its value will never be used.
  48880. */
  48881. } while (--n);
  48882. more += _w_size;
  48883. }
  48884. if (s.strm.avail_in === 0) {
  48885. break;
  48886. }
  48887. /* If there was no sliding:
  48888. * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
  48889. * more == window_size - lookahead - strstart
  48890. * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
  48891. * => more >= window_size - 2*WSIZE + 2
  48892. * In the BIG_MEM or MMAP case (not yet supported),
  48893. * window_size == input_size + MIN_LOOKAHEAD &&
  48894. * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
  48895. * Otherwise, window_size == 2*WSIZE so more >= 2.
  48896. * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
  48897. */
  48898. //Assert(more >= 2, "more < 2");
  48899. n = read_buf(s.strm, s.window, s.strstart + s.lookahead, more);
  48900. s.lookahead += n;
  48901. /* Initialize the hash value now that we have some input: */
  48902. if (s.lookahead + s.insert >= MIN_MATCH) {
  48903. str = s.strstart - s.insert;
  48904. s.ins_h = s.window[str];
  48905. /* UPDATE_HASH(s, s->ins_h, s->window[str + 1]); */
  48906. s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str + 1]) & s.hash_mask; //#if MIN_MATCH != 3
  48907. // Call update_hash() MIN_MATCH-3 more times
  48908. //#endif
  48909. while (s.insert) {
  48910. /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */
  48911. s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
  48912. s.prev[str & s.w_mask] = s.head[s.ins_h];
  48913. s.head[s.ins_h] = str;
  48914. str++;
  48915. s.insert--;
  48916. if (s.lookahead + s.insert < MIN_MATCH) {
  48917. break;
  48918. }
  48919. }
  48920. }
  48921. /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
  48922. * but this is not important since only literal bytes will be emitted.
  48923. */
  48924. } while (s.lookahead < MIN_LOOKAHEAD && s.strm.avail_in !== 0);
  48925. /* If the WIN_INIT bytes after the end of the current data have never been
  48926. * written, then zero those bytes in order to avoid memory check reports of
  48927. * the use of uninitialized (or uninitialised as Julian writes) bytes by
  48928. * the longest match routines. Update the high water mark for the next
  48929. * time through here. WIN_INIT is set to MAX_MATCH since the longest match
  48930. * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
  48931. */
  48932. // if (s.high_water < s.window_size) {
  48933. // var curr = s.strstart + s.lookahead;
  48934. // var init = 0;
  48935. //
  48936. // if (s.high_water < curr) {
  48937. // /* Previous high water mark below current data -- zero WIN_INIT
  48938. // * bytes or up to end of window, whichever is less.
  48939. // */
  48940. // init = s.window_size - curr;
  48941. // if (init > WIN_INIT)
  48942. // init = WIN_INIT;
  48943. // zmemzero(s->window + curr, (unsigned)init);
  48944. // s->high_water = curr + init;
  48945. // }
  48946. // else if (s->high_water < (ulg)curr + WIN_INIT) {
  48947. // /* High water mark at or above current data, but below current data
  48948. // * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
  48949. // * to end of window, whichever is less.
  48950. // */
  48951. // init = (ulg)curr + WIN_INIT - s->high_water;
  48952. // if (init > s->window_size - s->high_water)
  48953. // init = s->window_size - s->high_water;
  48954. // zmemzero(s->window + s->high_water, (unsigned)init);
  48955. // s->high_water += init;
  48956. // }
  48957. // }
  48958. //
  48959. // Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
  48960. // "not enough room for search");
  48961. }
  48962. /* ===========================================================================
  48963. * Copy without compression as much as possible from the input stream, return
  48964. * the current block state.
  48965. * This function does not insert new strings in the dictionary since
  48966. * uncompressible data is probably not useful. This function is used
  48967. * only for the level=0 compression option.
  48968. * NOTE: this function should be optimized to avoid extra copying from
  48969. * window to pending_buf.
  48970. */
  48971. function deflate_stored(s, flush) {
  48972. /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
  48973. * to pending_buf_size, and each stored block has a 5 byte header:
  48974. */
  48975. var max_block_size = 0xffff;
  48976. if (max_block_size > s.pending_buf_size - 5) {
  48977. max_block_size = s.pending_buf_size - 5;
  48978. }
  48979. /* Copy as much as possible from input to output: */
  48980. for (;;) {
  48981. /* Fill the window as much as possible: */
  48982. if (s.lookahead <= 1) {
  48983. //Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  48984. // s->block_start >= (long)s->w_size, "slide too late");
  48985. // if (!(s.strstart < s.w_size + (s.w_size - MIN_LOOKAHEAD) ||
  48986. // s.block_start >= s.w_size)) {
  48987. // throw new Error("slide too late");
  48988. // }
  48989. fill_window(s);
  48990. if (s.lookahead === 0 && flush === Z_NO_FLUSH) {
  48991. return BS_NEED_MORE;
  48992. }
  48993. if (s.lookahead === 0) {
  48994. break;
  48995. }
  48996. /* flush the current block */
  48997. } //Assert(s->block_start >= 0L, "block gone");
  48998. // if (s.block_start < 0) throw new Error("block gone");
  48999. s.strstart += s.lookahead;
  49000. s.lookahead = 0;
  49001. /* Emit a stored block if pending_buf will be full: */
  49002. var max_start = s.block_start + max_block_size;
  49003. if (s.strstart === 0 || s.strstart >= max_start) {
  49004. /* strstart == 0 is possible when wraparound on 16-bit machine */
  49005. s.lookahead = s.strstart - max_start;
  49006. s.strstart = max_start;
  49007. /*** FLUSH_BLOCK(s, 0); ***/
  49008. flush_block_only(s, false);
  49009. if (s.strm.avail_out === 0) {
  49010. return BS_NEED_MORE;
  49011. }
  49012. /***/
  49013. }
  49014. /* Flush if we may have to slide, otherwise block_start may become
  49015. * negative and the data will be gone:
  49016. */
  49017. if (s.strstart - s.block_start >= s.w_size - MIN_LOOKAHEAD) {
  49018. /*** FLUSH_BLOCK(s, 0); ***/
  49019. flush_block_only(s, false);
  49020. if (s.strm.avail_out === 0) {
  49021. return BS_NEED_MORE;
  49022. }
  49023. /***/
  49024. }
  49025. }
  49026. s.insert = 0;
  49027. if (flush === Z_FINISH) {
  49028. /*** FLUSH_BLOCK(s, 1); ***/
  49029. flush_block_only(s, true);
  49030. if (s.strm.avail_out === 0) {
  49031. return BS_FINISH_STARTED;
  49032. }
  49033. /***/
  49034. return BS_FINISH_DONE;
  49035. }
  49036. if (s.strstart > s.block_start) {
  49037. /*** FLUSH_BLOCK(s, 0); ***/
  49038. flush_block_only(s, false);
  49039. if (s.strm.avail_out === 0) {
  49040. return BS_NEED_MORE;
  49041. }
  49042. /***/
  49043. }
  49044. return BS_NEED_MORE;
  49045. }
  49046. /* ===========================================================================
  49047. * Compress as much as possible from the input stream, return the current
  49048. * block state.
  49049. * This function does not perform lazy evaluation of matches and inserts
  49050. * new strings in the dictionary only for unmatched strings or for short
  49051. * matches. It is used only for the fast compression options.
  49052. */
  49053. function deflate_fast(s, flush) {
  49054. var hash_head;
  49055. /* head of the hash chain */
  49056. var bflush;
  49057. /* set if current block must be flushed */
  49058. for (;;) {
  49059. /* Make sure that we always have enough lookahead, except
  49060. * at the end of the input file. We need MAX_MATCH bytes
  49061. * for the next match, plus MIN_MATCH bytes to insert the
  49062. * string following the next match.
  49063. */
  49064. if (s.lookahead < MIN_LOOKAHEAD) {
  49065. fill_window(s);
  49066. if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {
  49067. return BS_NEED_MORE;
  49068. }
  49069. if (s.lookahead === 0) {
  49070. break;
  49071. /* flush the current block */
  49072. }
  49073. }
  49074. /* Insert the string window[strstart .. strstart+2] in the
  49075. * dictionary, and set hash_head to the head of the hash chain:
  49076. */
  49077. hash_head = 0
  49078. /*NIL*/
  49079. ;
  49080. if (s.lookahead >= MIN_MATCH) {
  49081. /*** INSERT_STRING(s, s.strstart, hash_head); ***/
  49082. s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
  49083. hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
  49084. s.head[s.ins_h] = s.strstart;
  49085. /***/
  49086. }
  49087. /* Find the longest match, discarding those <= prev_length.
  49088. * At this point we have always match_length < MIN_MATCH
  49089. */
  49090. if (hash_head !== 0
  49091. /*NIL*/
  49092. && s.strstart - hash_head <= s.w_size - MIN_LOOKAHEAD) {
  49093. /* To simplify the code, we prevent matches with the string
  49094. * of window index 0 (in particular we have to avoid a match
  49095. * of the string with itself at the start of the input file).
  49096. */
  49097. s.match_length = longest_match(s, hash_head);
  49098. /* longest_match() sets match_start */
  49099. }
  49100. if (s.match_length >= MIN_MATCH) {
  49101. // check_match(s, s.strstart, s.match_start, s.match_length); // for debug only
  49102. /*** _tr_tally_dist(s, s.strstart - s.match_start,
  49103. s.match_length - MIN_MATCH, bflush); ***/
  49104. bflush = trees._tr_tally(s, s.strstart - s.match_start, s.match_length - MIN_MATCH);
  49105. s.lookahead -= s.match_length;
  49106. /* Insert new strings in the hash table only if the match length
  49107. * is not too large. This saves time but degrades compression.
  49108. */
  49109. if (s.match_length <= s.max_lazy_match
  49110. /*max_insert_length*/
  49111. && s.lookahead >= MIN_MATCH) {
  49112. s.match_length--;
  49113. /* string at strstart already in table */
  49114. do {
  49115. s.strstart++;
  49116. /*** INSERT_STRING(s, s.strstart, hash_head); ***/
  49117. s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
  49118. hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
  49119. s.head[s.ins_h] = s.strstart;
  49120. /***/
  49121. /* strstart never exceeds WSIZE-MAX_MATCH, so there are
  49122. * always MIN_MATCH bytes ahead.
  49123. */
  49124. } while (--s.match_length !== 0);
  49125. s.strstart++;
  49126. } else {
  49127. s.strstart += s.match_length;
  49128. s.match_length = 0;
  49129. s.ins_h = s.window[s.strstart];
  49130. /* UPDATE_HASH(s, s.ins_h, s.window[s.strstart+1]); */
  49131. s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + 1]) & s.hash_mask; //#if MIN_MATCH != 3
  49132. // Call UPDATE_HASH() MIN_MATCH-3 more times
  49133. //#endif
  49134. /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
  49135. * matter since it will be recomputed at next deflate call.
  49136. */
  49137. }
  49138. } else {
  49139. /* No match, output a literal byte */
  49140. //Tracevv((stderr,"%c", s.window[s.strstart]));
  49141. /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
  49142. bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
  49143. s.lookahead--;
  49144. s.strstart++;
  49145. }
  49146. if (bflush) {
  49147. /*** FLUSH_BLOCK(s, 0); ***/
  49148. flush_block_only(s, false);
  49149. if (s.strm.avail_out === 0) {
  49150. return BS_NEED_MORE;
  49151. }
  49152. /***/
  49153. }
  49154. }
  49155. s.insert = s.strstart < MIN_MATCH - 1 ? s.strstart : MIN_MATCH - 1;
  49156. if (flush === Z_FINISH) {
  49157. /*** FLUSH_BLOCK(s, 1); ***/
  49158. flush_block_only(s, true);
  49159. if (s.strm.avail_out === 0) {
  49160. return BS_FINISH_STARTED;
  49161. }
  49162. /***/
  49163. return BS_FINISH_DONE;
  49164. }
  49165. if (s.last_lit) {
  49166. /*** FLUSH_BLOCK(s, 0); ***/
  49167. flush_block_only(s, false);
  49168. if (s.strm.avail_out === 0) {
  49169. return BS_NEED_MORE;
  49170. }
  49171. /***/
  49172. }
  49173. return BS_BLOCK_DONE;
  49174. }
  49175. /* ===========================================================================
  49176. * Same as above, but achieves better compression. We use a lazy
  49177. * evaluation for matches: a match is finally adopted only if there is
  49178. * no better match at the next window position.
  49179. */
  49180. function deflate_slow(s, flush) {
  49181. var hash_head;
  49182. /* head of hash chain */
  49183. var bflush;
  49184. /* set if current block must be flushed */
  49185. var max_insert;
  49186. /* Process the input block. */
  49187. for (;;) {
  49188. /* Make sure that we always have enough lookahead, except
  49189. * at the end of the input file. We need MAX_MATCH bytes
  49190. * for the next match, plus MIN_MATCH bytes to insert the
  49191. * string following the next match.
  49192. */
  49193. if (s.lookahead < MIN_LOOKAHEAD) {
  49194. fill_window(s);
  49195. if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {
  49196. return BS_NEED_MORE;
  49197. }
  49198. if (s.lookahead === 0) {
  49199. break;
  49200. }
  49201. /* flush the current block */
  49202. }
  49203. /* Insert the string window[strstart .. strstart+2] in the
  49204. * dictionary, and set hash_head to the head of the hash chain:
  49205. */
  49206. hash_head = 0
  49207. /*NIL*/
  49208. ;
  49209. if (s.lookahead >= MIN_MATCH) {
  49210. /*** INSERT_STRING(s, s.strstart, hash_head); ***/
  49211. s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
  49212. hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
  49213. s.head[s.ins_h] = s.strstart;
  49214. /***/
  49215. }
  49216. /* Find the longest match, discarding those <= prev_length.
  49217. */
  49218. s.prev_length = s.match_length;
  49219. s.prev_match = s.match_start;
  49220. s.match_length = MIN_MATCH - 1;
  49221. if (hash_head !== 0
  49222. /*NIL*/
  49223. && s.prev_length < s.max_lazy_match && s.strstart - hash_head <= s.w_size - MIN_LOOKAHEAD
  49224. /*MAX_DIST(s)*/
  49225. ) {
  49226. /* To simplify the code, we prevent matches with the string
  49227. * of window index 0 (in particular we have to avoid a match
  49228. * of the string with itself at the start of the input file).
  49229. */
  49230. s.match_length = longest_match(s, hash_head);
  49231. /* longest_match() sets match_start */
  49232. if (s.match_length <= 5 && (s.strategy === Z_FILTERED || s.match_length === MIN_MATCH && s.strstart - s.match_start > 4096
  49233. /*TOO_FAR*/
  49234. )) {
  49235. /* If prev_match is also MIN_MATCH, match_start is garbage
  49236. * but we will ignore the current match anyway.
  49237. */
  49238. s.match_length = MIN_MATCH - 1;
  49239. }
  49240. }
  49241. /* If there was a match at the previous step and the current
  49242. * match is not better, output the previous match:
  49243. */
  49244. if (s.prev_length >= MIN_MATCH && s.match_length <= s.prev_length) {
  49245. max_insert = s.strstart + s.lookahead - MIN_MATCH;
  49246. /* Do not insert strings in hash table beyond this. */
  49247. //check_match(s, s.strstart-1, s.prev_match, s.prev_length);
  49248. /***_tr_tally_dist(s, s.strstart - 1 - s.prev_match,
  49249. s.prev_length - MIN_MATCH, bflush);***/
  49250. bflush = trees._tr_tally(s, s.strstart - 1 - s.prev_match, s.prev_length - MIN_MATCH);
  49251. /* Insert in hash table all strings up to the end of the match.
  49252. * strstart-1 and strstart are already inserted. If there is not
  49253. * enough lookahead, the last two strings are not inserted in
  49254. * the hash table.
  49255. */
  49256. s.lookahead -= s.prev_length - 1;
  49257. s.prev_length -= 2;
  49258. do {
  49259. if (++s.strstart <= max_insert) {
  49260. /*** INSERT_STRING(s, s.strstart, hash_head); ***/
  49261. s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
  49262. hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
  49263. s.head[s.ins_h] = s.strstart;
  49264. /***/
  49265. }
  49266. } while (--s.prev_length !== 0);
  49267. s.match_available = 0;
  49268. s.match_length = MIN_MATCH - 1;
  49269. s.strstart++;
  49270. if (bflush) {
  49271. /*** FLUSH_BLOCK(s, 0); ***/
  49272. flush_block_only(s, false);
  49273. if (s.strm.avail_out === 0) {
  49274. return BS_NEED_MORE;
  49275. }
  49276. /***/
  49277. }
  49278. } else if (s.match_available) {
  49279. /* If there was no match at the previous position, output a
  49280. * single literal. If there was a match but the current match
  49281. * is longer, truncate the previous match to a single literal.
  49282. */
  49283. //Tracevv((stderr,"%c", s->window[s->strstart-1]));
  49284. /*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/
  49285. bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]);
  49286. if (bflush) {
  49287. /*** FLUSH_BLOCK_ONLY(s, 0) ***/
  49288. flush_block_only(s, false);
  49289. /***/
  49290. }
  49291. s.strstart++;
  49292. s.lookahead--;
  49293. if (s.strm.avail_out === 0) {
  49294. return BS_NEED_MORE;
  49295. }
  49296. } else {
  49297. /* There is no previous match to compare with, wait for
  49298. * the next step to decide.
  49299. */
  49300. s.match_available = 1;
  49301. s.strstart++;
  49302. s.lookahead--;
  49303. }
  49304. } //Assert (flush != Z_NO_FLUSH, "no flush?");
  49305. if (s.match_available) {
  49306. //Tracevv((stderr,"%c", s->window[s->strstart-1]));
  49307. /*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/
  49308. bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]);
  49309. s.match_available = 0;
  49310. }
  49311. s.insert = s.strstart < MIN_MATCH - 1 ? s.strstart : MIN_MATCH - 1;
  49312. if (flush === Z_FINISH) {
  49313. /*** FLUSH_BLOCK(s, 1); ***/
  49314. flush_block_only(s, true);
  49315. if (s.strm.avail_out === 0) {
  49316. return BS_FINISH_STARTED;
  49317. }
  49318. /***/
  49319. return BS_FINISH_DONE;
  49320. }
  49321. if (s.last_lit) {
  49322. /*** FLUSH_BLOCK(s, 0); ***/
  49323. flush_block_only(s, false);
  49324. if (s.strm.avail_out === 0) {
  49325. return BS_NEED_MORE;
  49326. }
  49327. /***/
  49328. }
  49329. return BS_BLOCK_DONE;
  49330. }
  49331. /* ===========================================================================
  49332. * For Z_RLE, simply look for runs of bytes, generate matches only of distance
  49333. * one. Do not maintain a hash table. (It will be regenerated if this run of
  49334. * deflate switches away from Z_RLE.)
  49335. */
  49336. function deflate_rle(s, flush) {
  49337. var bflush;
  49338. /* set if current block must be flushed */
  49339. var prev;
  49340. /* byte at distance one to match */
  49341. var scan, strend;
  49342. /* scan goes up to strend for length of run */
  49343. var _win = s.window;
  49344. for (;;) {
  49345. /* Make sure that we always have enough lookahead, except
  49346. * at the end of the input file. We need MAX_MATCH bytes
  49347. * for the longest run, plus one for the unrolled loop.
  49348. */
  49349. if (s.lookahead <= MAX_MATCH) {
  49350. fill_window(s);
  49351. if (s.lookahead <= MAX_MATCH && flush === Z_NO_FLUSH) {
  49352. return BS_NEED_MORE;
  49353. }
  49354. if (s.lookahead === 0) {
  49355. break;
  49356. }
  49357. /* flush the current block */
  49358. }
  49359. /* See how many times the previous byte repeats */
  49360. s.match_length = 0;
  49361. if (s.lookahead >= MIN_MATCH && s.strstart > 0) {
  49362. scan = s.strstart - 1;
  49363. prev = _win[scan];
  49364. if (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan]) {
  49365. strend = s.strstart + MAX_MATCH;
  49366. do {
  49367. /*jshint noempty:false*/
  49368. } 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);
  49369. s.match_length = MAX_MATCH - (strend - scan);
  49370. if (s.match_length > s.lookahead) {
  49371. s.match_length = s.lookahead;
  49372. }
  49373. } //Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
  49374. }
  49375. /* Emit match if have run of MIN_MATCH or longer, else emit literal */
  49376. if (s.match_length >= MIN_MATCH) {
  49377. //check_match(s, s.strstart, s.strstart - 1, s.match_length);
  49378. /*** _tr_tally_dist(s, 1, s.match_length - MIN_MATCH, bflush); ***/
  49379. bflush = trees._tr_tally(s, 1, s.match_length - MIN_MATCH);
  49380. s.lookahead -= s.match_length;
  49381. s.strstart += s.match_length;
  49382. s.match_length = 0;
  49383. } else {
  49384. /* No match, output a literal byte */
  49385. //Tracevv((stderr,"%c", s->window[s->strstart]));
  49386. /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
  49387. bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
  49388. s.lookahead--;
  49389. s.strstart++;
  49390. }
  49391. if (bflush) {
  49392. /*** FLUSH_BLOCK(s, 0); ***/
  49393. flush_block_only(s, false);
  49394. if (s.strm.avail_out === 0) {
  49395. return BS_NEED_MORE;
  49396. }
  49397. /***/
  49398. }
  49399. }
  49400. s.insert = 0;
  49401. if (flush === Z_FINISH) {
  49402. /*** FLUSH_BLOCK(s, 1); ***/
  49403. flush_block_only(s, true);
  49404. if (s.strm.avail_out === 0) {
  49405. return BS_FINISH_STARTED;
  49406. }
  49407. /***/
  49408. return BS_FINISH_DONE;
  49409. }
  49410. if (s.last_lit) {
  49411. /*** FLUSH_BLOCK(s, 0); ***/
  49412. flush_block_only(s, false);
  49413. if (s.strm.avail_out === 0) {
  49414. return BS_NEED_MORE;
  49415. }
  49416. /***/
  49417. }
  49418. return BS_BLOCK_DONE;
  49419. }
  49420. /* ===========================================================================
  49421. * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table.
  49422. * (It will be regenerated if this run of deflate switches away from Huffman.)
  49423. */
  49424. function deflate_huff(s, flush) {
  49425. var bflush;
  49426. /* set if current block must be flushed */
  49427. for (;;) {
  49428. /* Make sure that we have a literal to write. */
  49429. if (s.lookahead === 0) {
  49430. fill_window(s);
  49431. if (s.lookahead === 0) {
  49432. if (flush === Z_NO_FLUSH) {
  49433. return BS_NEED_MORE;
  49434. }
  49435. break;
  49436. /* flush the current block */
  49437. }
  49438. }
  49439. /* Output a literal byte */
  49440. s.match_length = 0; //Tracevv((stderr,"%c", s->window[s->strstart]));
  49441. /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
  49442. bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
  49443. s.lookahead--;
  49444. s.strstart++;
  49445. if (bflush) {
  49446. /*** FLUSH_BLOCK(s, 0); ***/
  49447. flush_block_only(s, false);
  49448. if (s.strm.avail_out === 0) {
  49449. return BS_NEED_MORE;
  49450. }
  49451. /***/
  49452. }
  49453. }
  49454. s.insert = 0;
  49455. if (flush === Z_FINISH) {
  49456. /*** FLUSH_BLOCK(s, 1); ***/
  49457. flush_block_only(s, true);
  49458. if (s.strm.avail_out === 0) {
  49459. return BS_FINISH_STARTED;
  49460. }
  49461. /***/
  49462. return BS_FINISH_DONE;
  49463. }
  49464. if (s.last_lit) {
  49465. /*** FLUSH_BLOCK(s, 0); ***/
  49466. flush_block_only(s, false);
  49467. if (s.strm.avail_out === 0) {
  49468. return BS_NEED_MORE;
  49469. }
  49470. /***/
  49471. }
  49472. return BS_BLOCK_DONE;
  49473. }
  49474. /* Values for max_lazy_match, good_match and max_chain_length, depending on
  49475. * the desired pack level (0..9). The values given below have been tuned to
  49476. * exclude worst case performance for pathological files. Better values may be
  49477. * found for specific files.
  49478. */
  49479. function Config(good_length, max_lazy, nice_length, max_chain, func) {
  49480. this.good_length = good_length;
  49481. this.max_lazy = max_lazy;
  49482. this.nice_length = nice_length;
  49483. this.max_chain = max_chain;
  49484. this.func = func;
  49485. }
  49486. var configuration_table;
  49487. configuration_table = [
  49488. /* good lazy nice chain */
  49489. new Config(0, 0, 0, 0, deflate_stored),
  49490. /* 0 store only */
  49491. new Config(4, 4, 8, 4, deflate_fast),
  49492. /* 1 max speed, no lazy matches */
  49493. new Config(4, 5, 16, 8, deflate_fast),
  49494. /* 2 */
  49495. new Config(4, 6, 32, 32, deflate_fast),
  49496. /* 3 */
  49497. new Config(4, 4, 16, 16, deflate_slow),
  49498. /* 4 lazy matches */
  49499. new Config(8, 16, 32, 32, deflate_slow),
  49500. /* 5 */
  49501. new Config(8, 16, 128, 128, deflate_slow),
  49502. /* 6 */
  49503. new Config(8, 32, 128, 256, deflate_slow),
  49504. /* 7 */
  49505. new Config(32, 128, 258, 1024, deflate_slow),
  49506. /* 8 */
  49507. new Config(32, 258, 258, 4096, deflate_slow)
  49508. /* 9 max compression */
  49509. ];
  49510. /* ===========================================================================
  49511. * Initialize the "longest match" routines for a new zlib stream
  49512. */
  49513. function lm_init(s) {
  49514. s.window_size = 2 * s.w_size;
  49515. /*** CLEAR_HASH(s); ***/
  49516. zero(s.head); // Fill with NIL (= 0);
  49517. /* Set the default configuration parameters:
  49518. */
  49519. s.max_lazy_match = configuration_table[s.level].max_lazy;
  49520. s.good_match = configuration_table[s.level].good_length;
  49521. s.nice_match = configuration_table[s.level].nice_length;
  49522. s.max_chain_length = configuration_table[s.level].max_chain;
  49523. s.strstart = 0;
  49524. s.block_start = 0;
  49525. s.lookahead = 0;
  49526. s.insert = 0;
  49527. s.match_length = s.prev_length = MIN_MATCH - 1;
  49528. s.match_available = 0;
  49529. s.ins_h = 0;
  49530. }
  49531. function DeflateState() {
  49532. this.strm = null;
  49533. /* pointer back to this zlib stream */
  49534. this.status = 0;
  49535. /* as the name implies */
  49536. this.pending_buf = null;
  49537. /* output still pending */
  49538. this.pending_buf_size = 0;
  49539. /* size of pending_buf */
  49540. this.pending_out = 0;
  49541. /* next pending byte to output to the stream */
  49542. this.pending = 0;
  49543. /* nb of bytes in the pending buffer */
  49544. this.wrap = 0;
  49545. /* bit 0 true for zlib, bit 1 true for gzip */
  49546. this.gzhead = null;
  49547. /* gzip header information to write */
  49548. this.gzindex = 0;
  49549. /* where in extra, name, or comment */
  49550. this.method = Z_DEFLATED;
  49551. /* can only be DEFLATED */
  49552. this.last_flush = -1;
  49553. /* value of flush param for previous deflate call */
  49554. this.w_size = 0;
  49555. /* LZ77 window size (32K by default) */
  49556. this.w_bits = 0;
  49557. /* log2(w_size) (8..16) */
  49558. this.w_mask = 0;
  49559. /* w_size - 1 */
  49560. this.window = null;
  49561. /* Sliding window. Input bytes are read into the second half of the window,
  49562. * and move to the first half later to keep a dictionary of at least wSize
  49563. * bytes. With this organization, matches are limited to a distance of
  49564. * wSize-MAX_MATCH bytes, but this ensures that IO is always
  49565. * performed with a length multiple of the block size.
  49566. */
  49567. this.window_size = 0;
  49568. /* Actual size of window: 2*wSize, except when the user input buffer
  49569. * is directly used as sliding window.
  49570. */
  49571. this.prev = null;
  49572. /* Link to older string with same hash index. To limit the size of this
  49573. * array to 64K, this link is maintained only for the last 32K strings.
  49574. * An index in this array is thus a window index modulo 32K.
  49575. */
  49576. this.head = null;
  49577. /* Heads of the hash chains or NIL. */
  49578. this.ins_h = 0;
  49579. /* hash index of string to be inserted */
  49580. this.hash_size = 0;
  49581. /* number of elements in hash table */
  49582. this.hash_bits = 0;
  49583. /* log2(hash_size) */
  49584. this.hash_mask = 0;
  49585. /* hash_size-1 */
  49586. this.hash_shift = 0;
  49587. /* Number of bits by which ins_h must be shifted at each input
  49588. * step. It must be such that after MIN_MATCH steps, the oldest
  49589. * byte no longer takes part in the hash key, that is:
  49590. * hash_shift * MIN_MATCH >= hash_bits
  49591. */
  49592. this.block_start = 0;
  49593. /* Window position at the beginning of the current output block. Gets
  49594. * negative when the window is moved backwards.
  49595. */
  49596. this.match_length = 0;
  49597. /* length of best match */
  49598. this.prev_match = 0;
  49599. /* previous match */
  49600. this.match_available = 0;
  49601. /* set if previous match exists */
  49602. this.strstart = 0;
  49603. /* start of string to insert */
  49604. this.match_start = 0;
  49605. /* start of matching string */
  49606. this.lookahead = 0;
  49607. /* number of valid bytes ahead in window */
  49608. this.prev_length = 0;
  49609. /* Length of the best match at previous step. Matches not greater than this
  49610. * are discarded. This is used in the lazy match evaluation.
  49611. */
  49612. this.max_chain_length = 0;
  49613. /* To speed up deflation, hash chains are never searched beyond this
  49614. * length. A higher limit improves compression ratio but degrades the
  49615. * speed.
  49616. */
  49617. this.max_lazy_match = 0;
  49618. /* Attempt to find a better match only when the current match is strictly
  49619. * smaller than this value. This mechanism is used only for compression
  49620. * levels >= 4.
  49621. */
  49622. // That's alias to max_lazy_match, don't use directly
  49623. //this.max_insert_length = 0;
  49624. /* Insert new strings in the hash table only if the match length is not
  49625. * greater than this length. This saves time but degrades compression.
  49626. * max_insert_length is used only for compression levels <= 3.
  49627. */
  49628. this.level = 0;
  49629. /* compression level (1..9) */
  49630. this.strategy = 0;
  49631. /* favor or force Huffman coding*/
  49632. this.good_match = 0;
  49633. /* Use a faster search when the previous match is longer than this */
  49634. this.nice_match = 0;
  49635. /* Stop searching when current match exceeds this */
  49636. /* used by trees.c: */
  49637. /* Didn't use ct_data typedef below to suppress compiler warning */
  49638. // struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  49639. // struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  49640. // struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  49641. // Use flat array of DOUBLE size, with interleaved fata,
  49642. // because JS does not support effective
  49643. this.dyn_ltree = new utils.Buf16(HEAP_SIZE * 2);
  49644. this.dyn_dtree = new utils.Buf16((2 * D_CODES + 1) * 2);
  49645. this.bl_tree = new utils.Buf16((2 * BL_CODES + 1) * 2);
  49646. zero(this.dyn_ltree);
  49647. zero(this.dyn_dtree);
  49648. zero(this.bl_tree);
  49649. this.l_desc = null;
  49650. /* desc. for literal tree */
  49651. this.d_desc = null;
  49652. /* desc. for distance tree */
  49653. this.bl_desc = null;
  49654. /* desc. for bit length tree */
  49655. //ush bl_count[MAX_BITS+1];
  49656. this.bl_count = new utils.Buf16(MAX_BITS + 1);
  49657. /* number of codes at each bit length for an optimal tree */
  49658. //int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  49659. this.heap = new utils.Buf16(2 * L_CODES + 1);
  49660. /* heap used to build the Huffman trees */
  49661. zero(this.heap);
  49662. this.heap_len = 0;
  49663. /* number of elements in the heap */
  49664. this.heap_max = 0;
  49665. /* element of largest frequency */
  49666. /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
  49667. * The same heap array is used to build all trees.
  49668. */
  49669. this.depth = new utils.Buf16(2 * L_CODES + 1); //uch depth[2*L_CODES+1];
  49670. zero(this.depth);
  49671. /* Depth of each subtree used as tie breaker for trees of equal frequency
  49672. */
  49673. this.l_buf = 0;
  49674. /* buffer index for literals or lengths */
  49675. this.lit_bufsize = 0;
  49676. /* Size of match buffer for literals/lengths. There are 4 reasons for
  49677. * limiting lit_bufsize to 64K:
  49678. * - frequencies can be kept in 16 bit counters
  49679. * - if compression is not successful for the first block, all input
  49680. * data is still in the window so we can still emit a stored block even
  49681. * when input comes from standard input. (This can also be done for
  49682. * all blocks if lit_bufsize is not greater than 32K.)
  49683. * - if compression is not successful for a file smaller than 64K, we can
  49684. * even emit a stored file instead of a stored block (saving 5 bytes).
  49685. * This is applicable only for zip (not gzip or zlib).
  49686. * - creating new Huffman trees less frequently may not provide fast
  49687. * adaptation to changes in the input data statistics. (Take for
  49688. * example a binary file with poorly compressible code followed by
  49689. * a highly compressible string table.) Smaller buffer sizes give
  49690. * fast adaptation but have of course the overhead of transmitting
  49691. * trees more frequently.
  49692. * - I can't count above 4
  49693. */
  49694. this.last_lit = 0;
  49695. /* running index in l_buf */
  49696. this.d_buf = 0;
  49697. /* Buffer index for distances. To simplify the code, d_buf and l_buf have
  49698. * the same number of elements. To use different lengths, an extra flag
  49699. * array would be necessary.
  49700. */
  49701. this.opt_len = 0;
  49702. /* bit length of current block with optimal trees */
  49703. this.static_len = 0;
  49704. /* bit length of current block with static trees */
  49705. this.matches = 0;
  49706. /* number of string matches in current block */
  49707. this.insert = 0;
  49708. /* bytes at end of window left to insert */
  49709. this.bi_buf = 0;
  49710. /* Output buffer. bits are inserted starting at the bottom (least
  49711. * significant bits).
  49712. */
  49713. this.bi_valid = 0;
  49714. /* Number of valid bits in bi_buf. All bits above the last valid bit
  49715. * are always zero.
  49716. */
  49717. // Used for window memory init. We safely ignore it for JS. That makes
  49718. // sense only for pointers and memory check tools.
  49719. //this.high_water = 0;
  49720. /* High water mark offset in window for initialized bytes -- bytes above
  49721. * this are set to zero in order to avoid memory check warnings when
  49722. * longest match routines access bytes past the input. This is then
  49723. * updated to the new high water mark.
  49724. */
  49725. }
  49726. function deflateResetKeep(strm) {
  49727. var s;
  49728. if (!strm || !strm.state) {
  49729. return err(strm, Z_STREAM_ERROR);
  49730. }
  49731. strm.total_in = strm.total_out = 0;
  49732. strm.data_type = Z_UNKNOWN;
  49733. s = strm.state;
  49734. s.pending = 0;
  49735. s.pending_out = 0;
  49736. if (s.wrap < 0) {
  49737. s.wrap = -s.wrap;
  49738. /* was made negative by deflate(..., Z_FINISH); */
  49739. }
  49740. s.status = s.wrap ? INIT_STATE : BUSY_STATE;
  49741. strm.adler = s.wrap === 2 ? 0 // crc32(0, Z_NULL, 0)
  49742. : 1; // adler32(0, Z_NULL, 0)
  49743. s.last_flush = Z_NO_FLUSH;
  49744. trees._tr_init(s);
  49745. return Z_OK;
  49746. }
  49747. function deflateReset(strm) {
  49748. var ret = deflateResetKeep(strm);
  49749. if (ret === Z_OK) {
  49750. lm_init(strm.state);
  49751. }
  49752. return ret;
  49753. }
  49754. function deflateSetHeader(strm, head) {
  49755. if (!strm || !strm.state) {
  49756. return Z_STREAM_ERROR;
  49757. }
  49758. if (strm.state.wrap !== 2) {
  49759. return Z_STREAM_ERROR;
  49760. }
  49761. strm.state.gzhead = head;
  49762. return Z_OK;
  49763. }
  49764. function deflateInit2(strm, level, method, windowBits, memLevel, strategy) {
  49765. if (!strm) {
  49766. // === Z_NULL
  49767. return Z_STREAM_ERROR;
  49768. }
  49769. var wrap = 1;
  49770. if (level === Z_DEFAULT_COMPRESSION) {
  49771. level = 6;
  49772. }
  49773. if (windowBits < 0) {
  49774. /* suppress zlib wrapper */
  49775. wrap = 0;
  49776. windowBits = -windowBits;
  49777. } else if (windowBits > 15) {
  49778. wrap = 2;
  49779. /* write gzip wrapper instead */
  49780. windowBits -= 16;
  49781. }
  49782. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method !== Z_DEFLATED || windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
  49783. return err(strm, Z_STREAM_ERROR);
  49784. }
  49785. if (windowBits === 8) {
  49786. windowBits = 9;
  49787. }
  49788. /* until 256-byte window bug fixed */
  49789. var s = new DeflateState();
  49790. strm.state = s;
  49791. s.strm = strm;
  49792. s.wrap = wrap;
  49793. s.gzhead = null;
  49794. s.w_bits = windowBits;
  49795. s.w_size = 1 << s.w_bits;
  49796. s.w_mask = s.w_size - 1;
  49797. s.hash_bits = memLevel + 7;
  49798. s.hash_size = 1 << s.hash_bits;
  49799. s.hash_mask = s.hash_size - 1;
  49800. s.hash_shift = ~~((s.hash_bits + MIN_MATCH - 1) / MIN_MATCH);
  49801. s.window = new utils.Buf8(s.w_size * 2);
  49802. s.head = new utils.Buf16(s.hash_size);
  49803. s.prev = new utils.Buf16(s.w_size); // Don't need mem init magic for JS.
  49804. //s.high_water = 0; /* nothing written to s->window yet */
  49805. s.lit_bufsize = 1 << memLevel + 6;
  49806. /* 16K elements by default */
  49807. s.pending_buf_size = s.lit_bufsize * 4; //overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  49808. //s->pending_buf = (uchf *) overlay;
  49809. s.pending_buf = new utils.Buf8(s.pending_buf_size); // It is offset from `s.pending_buf` (size is `s.lit_bufsize * 2`)
  49810. //s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  49811. s.d_buf = 1 * s.lit_bufsize; //s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  49812. s.l_buf = (1 + 2) * s.lit_bufsize;
  49813. s.level = level;
  49814. s.strategy = strategy;
  49815. s.method = method;
  49816. return deflateReset(strm);
  49817. }
  49818. function deflateInit(strm, level) {
  49819. return deflateInit2(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY);
  49820. }
  49821. function deflate(strm, flush) {
  49822. var old_flush, s;
  49823. var beg, val; // for gzip header write only
  49824. if (!strm || !strm.state || flush > Z_BLOCK || flush < 0) {
  49825. return strm ? err(strm, Z_STREAM_ERROR) : Z_STREAM_ERROR;
  49826. }
  49827. s = strm.state;
  49828. if (!strm.output || !strm.input && strm.avail_in !== 0 || s.status === FINISH_STATE && flush !== Z_FINISH) {
  49829. return err(strm, strm.avail_out === 0 ? Z_BUF_ERROR : Z_STREAM_ERROR);
  49830. }
  49831. s.strm = strm;
  49832. /* just in case */
  49833. old_flush = s.last_flush;
  49834. s.last_flush = flush;
  49835. /* Write the header */
  49836. if (s.status === INIT_STATE) {
  49837. if (s.wrap === 2) {
  49838. // GZIP header
  49839. strm.adler = 0; //crc32(0L, Z_NULL, 0);
  49840. put_byte(s, 31);
  49841. put_byte(s, 139);
  49842. put_byte(s, 8);
  49843. if (!s.gzhead) {
  49844. // s->gzhead == Z_NULL
  49845. put_byte(s, 0);
  49846. put_byte(s, 0);
  49847. put_byte(s, 0);
  49848. put_byte(s, 0);
  49849. put_byte(s, 0);
  49850. put_byte(s, s.level === 9 ? 2 : s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ? 4 : 0);
  49851. put_byte(s, OS_CODE);
  49852. s.status = BUSY_STATE;
  49853. } else {
  49854. 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));
  49855. put_byte(s, s.gzhead.time & 0xff);
  49856. put_byte(s, s.gzhead.time >> 8 & 0xff);
  49857. put_byte(s, s.gzhead.time >> 16 & 0xff);
  49858. put_byte(s, s.gzhead.time >> 24 & 0xff);
  49859. put_byte(s, s.level === 9 ? 2 : s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ? 4 : 0);
  49860. put_byte(s, s.gzhead.os & 0xff);
  49861. if (s.gzhead.extra && s.gzhead.extra.length) {
  49862. put_byte(s, s.gzhead.extra.length & 0xff);
  49863. put_byte(s, s.gzhead.extra.length >> 8 & 0xff);
  49864. }
  49865. if (s.gzhead.hcrc) {
  49866. strm.adler = crc32(strm.adler, s.pending_buf, s.pending, 0);
  49867. }
  49868. s.gzindex = 0;
  49869. s.status = EXTRA_STATE;
  49870. }
  49871. } else // DEFLATE header
  49872. {
  49873. var header = Z_DEFLATED + (s.w_bits - 8 << 4) << 8;
  49874. var level_flags = -1;
  49875. if (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2) {
  49876. level_flags = 0;
  49877. } else if (s.level < 6) {
  49878. level_flags = 1;
  49879. } else if (s.level === 6) {
  49880. level_flags = 2;
  49881. } else {
  49882. level_flags = 3;
  49883. }
  49884. header |= level_flags << 6;
  49885. if (s.strstart !== 0) {
  49886. header |= PRESET_DICT;
  49887. }
  49888. header += 31 - header % 31;
  49889. s.status = BUSY_STATE;
  49890. putShortMSB(s, header);
  49891. /* Save the adler32 of the preset dictionary: */
  49892. if (s.strstart !== 0) {
  49893. putShortMSB(s, strm.adler >>> 16);
  49894. putShortMSB(s, strm.adler & 0xffff);
  49895. }
  49896. strm.adler = 1; // adler32(0L, Z_NULL, 0);
  49897. }
  49898. } //#ifdef GZIP
  49899. if (s.status === EXTRA_STATE) {
  49900. if (s.gzhead.extra
  49901. /* != Z_NULL*/
  49902. ) {
  49903. beg = s.pending;
  49904. /* start of bytes to update crc */
  49905. while (s.gzindex < (s.gzhead.extra.length & 0xffff)) {
  49906. if (s.pending === s.pending_buf_size) {
  49907. if (s.gzhead.hcrc && s.pending > beg) {
  49908. strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  49909. }
  49910. flush_pending(strm);
  49911. beg = s.pending;
  49912. if (s.pending === s.pending_buf_size) {
  49913. break;
  49914. }
  49915. }
  49916. put_byte(s, s.gzhead.extra[s.gzindex] & 0xff);
  49917. s.gzindex++;
  49918. }
  49919. if (s.gzhead.hcrc && s.pending > beg) {
  49920. strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  49921. }
  49922. if (s.gzindex === s.gzhead.extra.length) {
  49923. s.gzindex = 0;
  49924. s.status = NAME_STATE;
  49925. }
  49926. } else {
  49927. s.status = NAME_STATE;
  49928. }
  49929. }
  49930. if (s.status === NAME_STATE) {
  49931. if (s.gzhead.name
  49932. /* != Z_NULL*/
  49933. ) {
  49934. beg = s.pending;
  49935. /* start of bytes to update crc */
  49936. //int val;
  49937. do {
  49938. if (s.pending === s.pending_buf_size) {
  49939. if (s.gzhead.hcrc && s.pending > beg) {
  49940. strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  49941. }
  49942. flush_pending(strm);
  49943. beg = s.pending;
  49944. if (s.pending === s.pending_buf_size) {
  49945. val = 1;
  49946. break;
  49947. }
  49948. } // JS specific: little magic to add zero terminator to end of string
  49949. if (s.gzindex < s.gzhead.name.length) {
  49950. val = s.gzhead.name.charCodeAt(s.gzindex++) & 0xff;
  49951. } else {
  49952. val = 0;
  49953. }
  49954. put_byte(s, val);
  49955. } while (val !== 0);
  49956. if (s.gzhead.hcrc && s.pending > beg) {
  49957. strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  49958. }
  49959. if (val === 0) {
  49960. s.gzindex = 0;
  49961. s.status = COMMENT_STATE;
  49962. }
  49963. } else {
  49964. s.status = COMMENT_STATE;
  49965. }
  49966. }
  49967. if (s.status === COMMENT_STATE) {
  49968. if (s.gzhead.comment
  49969. /* != Z_NULL*/
  49970. ) {
  49971. beg = s.pending;
  49972. /* start of bytes to update crc */
  49973. //int val;
  49974. do {
  49975. if (s.pending === s.pending_buf_size) {
  49976. if (s.gzhead.hcrc && s.pending > beg) {
  49977. strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  49978. }
  49979. flush_pending(strm);
  49980. beg = s.pending;
  49981. if (s.pending === s.pending_buf_size) {
  49982. val = 1;
  49983. break;
  49984. }
  49985. } // JS specific: little magic to add zero terminator to end of string
  49986. if (s.gzindex < s.gzhead.comment.length) {
  49987. val = s.gzhead.comment.charCodeAt(s.gzindex++) & 0xff;
  49988. } else {
  49989. val = 0;
  49990. }
  49991. put_byte(s, val);
  49992. } while (val !== 0);
  49993. if (s.gzhead.hcrc && s.pending > beg) {
  49994. strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  49995. }
  49996. if (val === 0) {
  49997. s.status = HCRC_STATE;
  49998. }
  49999. } else {
  50000. s.status = HCRC_STATE;
  50001. }
  50002. }
  50003. if (s.status === HCRC_STATE) {
  50004. if (s.gzhead.hcrc) {
  50005. if (s.pending + 2 > s.pending_buf_size) {
  50006. flush_pending(strm);
  50007. }
  50008. if (s.pending + 2 <= s.pending_buf_size) {
  50009. put_byte(s, strm.adler & 0xff);
  50010. put_byte(s, strm.adler >> 8 & 0xff);
  50011. strm.adler = 0; //crc32(0L, Z_NULL, 0);
  50012. s.status = BUSY_STATE;
  50013. }
  50014. } else {
  50015. s.status = BUSY_STATE;
  50016. }
  50017. } //#endif
  50018. /* Flush as much pending output as possible */
  50019. if (s.pending !== 0) {
  50020. flush_pending(strm);
  50021. if (strm.avail_out === 0) {
  50022. /* Since avail_out is 0, deflate will be called again with
  50023. * more output space, but possibly with both pending and
  50024. * avail_in equal to zero. There won't be anything to do,
  50025. * but this is not an error situation so make sure we
  50026. * return OK instead of BUF_ERROR at next call of deflate:
  50027. */
  50028. s.last_flush = -1;
  50029. return Z_OK;
  50030. }
  50031. /* Make sure there is something to do and avoid duplicate consecutive
  50032. * flushes. For repeated and useless calls with Z_FINISH, we keep
  50033. * returning Z_STREAM_END instead of Z_BUF_ERROR.
  50034. */
  50035. } else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) && flush !== Z_FINISH) {
  50036. return err(strm, Z_BUF_ERROR);
  50037. }
  50038. /* User must not provide more input after the first FINISH: */
  50039. if (s.status === FINISH_STATE && strm.avail_in !== 0) {
  50040. return err(strm, Z_BUF_ERROR);
  50041. }
  50042. /* Start a new block or continue the current one.
  50043. */
  50044. if (strm.avail_in !== 0 || s.lookahead !== 0 || flush !== Z_NO_FLUSH && s.status !== FINISH_STATE) {
  50045. 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);
  50046. if (bstate === BS_FINISH_STARTED || bstate === BS_FINISH_DONE) {
  50047. s.status = FINISH_STATE;
  50048. }
  50049. if (bstate === BS_NEED_MORE || bstate === BS_FINISH_STARTED) {
  50050. if (strm.avail_out === 0) {
  50051. s.last_flush = -1;
  50052. /* avoid BUF_ERROR next call, see above */
  50053. }
  50054. return Z_OK;
  50055. /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
  50056. * of deflate should use the same flush parameter to make sure
  50057. * that the flush is complete. So we don't have to output an
  50058. * empty block here, this will be done at next call. This also
  50059. * ensures that for a very small output buffer, we emit at most
  50060. * one empty block.
  50061. */
  50062. }
  50063. if (bstate === BS_BLOCK_DONE) {
  50064. if (flush === Z_PARTIAL_FLUSH) {
  50065. trees._tr_align(s);
  50066. } else if (flush !== Z_BLOCK) {
  50067. /* FULL_FLUSH or SYNC_FLUSH */
  50068. trees._tr_stored_block(s, 0, 0, false);
  50069. /* For a full flush, this empty block will be recognized
  50070. * as a special marker by inflate_sync().
  50071. */
  50072. if (flush === Z_FULL_FLUSH) {
  50073. /*** CLEAR_HASH(s); ***/
  50074. /* forget history */
  50075. zero(s.head); // Fill with NIL (= 0);
  50076. if (s.lookahead === 0) {
  50077. s.strstart = 0;
  50078. s.block_start = 0;
  50079. s.insert = 0;
  50080. }
  50081. }
  50082. }
  50083. flush_pending(strm);
  50084. if (strm.avail_out === 0) {
  50085. s.last_flush = -1;
  50086. /* avoid BUF_ERROR at next call, see above */
  50087. return Z_OK;
  50088. }
  50089. }
  50090. } //Assert(strm->avail_out > 0, "bug2");
  50091. //if (strm.avail_out <= 0) { throw new Error("bug2");}
  50092. if (flush !== Z_FINISH) {
  50093. return Z_OK;
  50094. }
  50095. if (s.wrap <= 0) {
  50096. return Z_STREAM_END;
  50097. }
  50098. /* Write the trailer */
  50099. if (s.wrap === 2) {
  50100. put_byte(s, strm.adler & 0xff);
  50101. put_byte(s, strm.adler >> 8 & 0xff);
  50102. put_byte(s, strm.adler >> 16 & 0xff);
  50103. put_byte(s, strm.adler >> 24 & 0xff);
  50104. put_byte(s, strm.total_in & 0xff);
  50105. put_byte(s, strm.total_in >> 8 & 0xff);
  50106. put_byte(s, strm.total_in >> 16 & 0xff);
  50107. put_byte(s, strm.total_in >> 24 & 0xff);
  50108. } else {
  50109. putShortMSB(s, strm.adler >>> 16);
  50110. putShortMSB(s, strm.adler & 0xffff);
  50111. }
  50112. flush_pending(strm);
  50113. /* If avail_out is zero, the application will call deflate again
  50114. * to flush the rest.
  50115. */
  50116. if (s.wrap > 0) {
  50117. s.wrap = -s.wrap;
  50118. }
  50119. /* write the trailer only once! */
  50120. return s.pending !== 0 ? Z_OK : Z_STREAM_END;
  50121. }
  50122. function deflateEnd(strm) {
  50123. var status;
  50124. if (!strm
  50125. /*== Z_NULL*/
  50126. || !strm.state
  50127. /*== Z_NULL*/
  50128. ) {
  50129. return Z_STREAM_ERROR;
  50130. }
  50131. status = strm.state.status;
  50132. if (status !== INIT_STATE && status !== EXTRA_STATE && status !== NAME_STATE && status !== COMMENT_STATE && status !== HCRC_STATE && status !== BUSY_STATE && status !== FINISH_STATE) {
  50133. return err(strm, Z_STREAM_ERROR);
  50134. }
  50135. strm.state = null;
  50136. return status === BUSY_STATE ? err(strm, Z_DATA_ERROR) : Z_OK;
  50137. }
  50138. /* =========================================================================
  50139. * Initializes the compression dictionary from the given byte
  50140. * sequence without producing any compressed output.
  50141. */
  50142. function deflateSetDictionary(strm, dictionary) {
  50143. var dictLength = dictionary.length;
  50144. var s;
  50145. var str, n;
  50146. var wrap;
  50147. var avail;
  50148. var next;
  50149. var input;
  50150. var tmpDict;
  50151. if (!strm
  50152. /*== Z_NULL*/
  50153. || !strm.state
  50154. /*== Z_NULL*/
  50155. ) {
  50156. return Z_STREAM_ERROR;
  50157. }
  50158. s = strm.state;
  50159. wrap = s.wrap;
  50160. if (wrap === 2 || wrap === 1 && s.status !== INIT_STATE || s.lookahead) {
  50161. return Z_STREAM_ERROR;
  50162. }
  50163. /* when using zlib wrappers, compute Adler-32 for provided dictionary */
  50164. if (wrap === 1) {
  50165. /* adler32(strm->adler, dictionary, dictLength); */
  50166. strm.adler = adler32(strm.adler, dictionary, dictLength, 0);
  50167. }
  50168. s.wrap = 0;
  50169. /* avoid computing Adler-32 in read_buf */
  50170. /* if dictionary would fill window, just replace the history */
  50171. if (dictLength >= s.w_size) {
  50172. if (wrap === 0) {
  50173. /* already empty otherwise */
  50174. /*** CLEAR_HASH(s); ***/
  50175. zero(s.head); // Fill with NIL (= 0);
  50176. s.strstart = 0;
  50177. s.block_start = 0;
  50178. s.insert = 0;
  50179. }
  50180. /* use the tail */
  50181. // dictionary = dictionary.slice(dictLength - s.w_size);
  50182. tmpDict = new utils.Buf8(s.w_size);
  50183. utils.arraySet(tmpDict, dictionary, dictLength - s.w_size, s.w_size, 0);
  50184. dictionary = tmpDict;
  50185. dictLength = s.w_size;
  50186. }
  50187. /* insert dictionary into window and hash */
  50188. avail = strm.avail_in;
  50189. next = strm.next_in;
  50190. input = strm.input;
  50191. strm.avail_in = dictLength;
  50192. strm.next_in = 0;
  50193. strm.input = dictionary;
  50194. fill_window(s);
  50195. while (s.lookahead >= MIN_MATCH) {
  50196. str = s.strstart;
  50197. n = s.lookahead - (MIN_MATCH - 1);
  50198. do {
  50199. /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */
  50200. s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
  50201. s.prev[str & s.w_mask] = s.head[s.ins_h];
  50202. s.head[s.ins_h] = str;
  50203. str++;
  50204. } while (--n);
  50205. s.strstart = str;
  50206. s.lookahead = MIN_MATCH - 1;
  50207. fill_window(s);
  50208. }
  50209. s.strstart += s.lookahead;
  50210. s.block_start = s.strstart;
  50211. s.insert = s.lookahead;
  50212. s.lookahead = 0;
  50213. s.match_length = s.prev_length = MIN_MATCH - 1;
  50214. s.match_available = 0;
  50215. strm.next_in = next;
  50216. strm.input = input;
  50217. strm.avail_in = avail;
  50218. s.wrap = wrap;
  50219. return Z_OK;
  50220. }
  50221. exports.deflateInit = deflateInit;
  50222. exports.deflateInit2 = deflateInit2;
  50223. exports.deflateReset = deflateReset;
  50224. exports.deflateResetKeep = deflateResetKeep;
  50225. exports.deflateSetHeader = deflateSetHeader;
  50226. exports.deflate = deflate;
  50227. exports.deflateEnd = deflateEnd;
  50228. exports.deflateSetDictionary = deflateSetDictionary;
  50229. exports.deflateInfo = 'pako deflate (from Nodeca project)';
  50230. /* Not implemented
  50231. exports.deflateBound = deflateBound;
  50232. exports.deflateCopy = deflateCopy;
  50233. exports.deflateParams = deflateParams;
  50234. exports.deflatePending = deflatePending;
  50235. exports.deflatePrime = deflatePrime;
  50236. exports.deflateTune = deflateTune;
  50237. */
  50238. },{"../utils/common":333,"./adler32":335,"./crc32":337,"./messages":343,"./trees":344}],339:[function(require,module,exports){
  50239. 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  50240. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  50241. //
  50242. // This software is provided 'as-is', without any express or implied
  50243. // warranty. In no event will the authors be held liable for any damages
  50244. // arising from the use of this software.
  50245. //
  50246. // Permission is granted to anyone to use this software for any purpose,
  50247. // including commercial applications, and to alter it and redistribute it
  50248. // freely, subject to the following restrictions:
  50249. //
  50250. // 1. The origin of this software must not be misrepresented; you must not
  50251. // claim that you wrote the original software. If you use this software
  50252. // in a product, an acknowledgment in the product documentation would be
  50253. // appreciated but is not required.
  50254. // 2. Altered source versions must be plainly marked as such, and must not be
  50255. // misrepresented as being the original software.
  50256. // 3. This notice may not be removed or altered from any source distribution.
  50257. function GZheader() {
  50258. /* true if compressed data believed to be text */
  50259. this.text = 0;
  50260. /* modification time */
  50261. this.time = 0;
  50262. /* extra flags (not used when writing a gzip file) */
  50263. this.xflags = 0;
  50264. /* operating system */
  50265. this.os = 0;
  50266. /* pointer to extra field or Z_NULL if none */
  50267. this.extra = null;
  50268. /* extra field length (valid if extra != Z_NULL) */
  50269. this.extra_len = 0; // Actually, we don't need it in JS,
  50270. // but leave for few code modifications
  50271. //
  50272. // Setup limits is not necessary because in js we should not preallocate memory
  50273. // for inflate use constant limit in 65536 bytes
  50274. //
  50275. /* space at extra (only when reading header) */
  50276. // this.extra_max = 0;
  50277. /* pointer to zero-terminated file name or Z_NULL */
  50278. this.name = '';
  50279. /* space at name (only when reading header) */
  50280. // this.name_max = 0;
  50281. /* pointer to zero-terminated comment or Z_NULL */
  50282. this.comment = '';
  50283. /* space at comment (only when reading header) */
  50284. // this.comm_max = 0;
  50285. /* true if there was or will be a header crc */
  50286. this.hcrc = 0;
  50287. /* true when done reading gzip header (not used when writing a gzip file) */
  50288. this.done = false;
  50289. }
  50290. module.exports = GZheader;
  50291. },{}],340:[function(require,module,exports){
  50292. 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  50293. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  50294. //
  50295. // This software is provided 'as-is', without any express or implied
  50296. // warranty. In no event will the authors be held liable for any damages
  50297. // arising from the use of this software.
  50298. //
  50299. // Permission is granted to anyone to use this software for any purpose,
  50300. // including commercial applications, and to alter it and redistribute it
  50301. // freely, subject to the following restrictions:
  50302. //
  50303. // 1. The origin of this software must not be misrepresented; you must not
  50304. // claim that you wrote the original software. If you use this software
  50305. // in a product, an acknowledgment in the product documentation would be
  50306. // appreciated but is not required.
  50307. // 2. Altered source versions must be plainly marked as such, and must not be
  50308. // misrepresented as being the original software.
  50309. // 3. This notice may not be removed or altered from any source distribution.
  50310. // See state defs from inflate.js
  50311. var BAD = 30;
  50312. /* got a data error -- remain here until reset */
  50313. var TYPE = 12;
  50314. /* i: waiting for type bits, including last-flag bit */
  50315. /*
  50316. Decode literal, length, and distance codes and write out the resulting
  50317. literal and match bytes until either not enough input or output is
  50318. available, an end-of-block is encountered, or a data error is encountered.
  50319. When large enough input and output buffers are supplied to inflate(), for
  50320. example, a 16K input buffer and a 64K output buffer, more than 95% of the
  50321. inflate execution time is spent in this routine.
  50322. Entry assumptions:
  50323. state.mode === LEN
  50324. strm.avail_in >= 6
  50325. strm.avail_out >= 258
  50326. start >= strm.avail_out
  50327. state.bits < 8
  50328. On return, state.mode is one of:
  50329. LEN -- ran out of enough output space or enough available input
  50330. TYPE -- reached end of block code, inflate() to interpret next block
  50331. BAD -- error in block data
  50332. Notes:
  50333. - The maximum input bits used by a length/distance pair is 15 bits for the
  50334. length code, 5 bits for the length extra, 15 bits for the distance code,
  50335. and 13 bits for the distance extra. This totals 48 bits, or six bytes.
  50336. Therefore if strm.avail_in >= 6, then there is enough input to avoid
  50337. checking for available input while decoding.
  50338. - The maximum bytes that a single length/distance pair can output is 258
  50339. bytes, which is the maximum length that can be coded. inflate_fast()
  50340. requires strm.avail_out >= 258 for each loop to avoid checking for
  50341. output space.
  50342. */
  50343. module.exports = function inflate_fast(strm, start) {
  50344. var state;
  50345. var _in;
  50346. /* local strm.input */
  50347. var last;
  50348. /* have enough input while in < last */
  50349. var _out;
  50350. /* local strm.output */
  50351. var beg;
  50352. /* inflate()'s initial strm.output */
  50353. var end;
  50354. /* while out < end, enough space available */
  50355. //#ifdef INFLATE_STRICT
  50356. var dmax;
  50357. /* maximum distance from zlib header */
  50358. //#endif
  50359. var wsize;
  50360. /* window size or zero if not using window */
  50361. var whave;
  50362. /* valid bytes in the window */
  50363. var wnext;
  50364. /* window write index */
  50365. // Use `s_window` instead `window`, avoid conflict with instrumentation tools
  50366. var s_window;
  50367. /* allocated sliding window, if wsize != 0 */
  50368. var hold;
  50369. /* local strm.hold */
  50370. var bits;
  50371. /* local strm.bits */
  50372. var lcode;
  50373. /* local strm.lencode */
  50374. var dcode;
  50375. /* local strm.distcode */
  50376. var lmask;
  50377. /* mask for first level of length codes */
  50378. var dmask;
  50379. /* mask for first level of distance codes */
  50380. var here;
  50381. /* retrieved table entry */
  50382. var op;
  50383. /* code bits, operation, extra bits, or */
  50384. /* window position, window bytes to copy */
  50385. var len;
  50386. /* match length, unused bytes */
  50387. var dist;
  50388. /* match distance */
  50389. var from;
  50390. /* where to copy match from */
  50391. var from_source;
  50392. var input, output; // JS specific, because we have no pointers
  50393. /* copy state to local variables */
  50394. state = strm.state; //here = state.here;
  50395. _in = strm.next_in;
  50396. input = strm.input;
  50397. last = _in + (strm.avail_in - 5);
  50398. _out = strm.next_out;
  50399. output = strm.output;
  50400. beg = _out - (start - strm.avail_out);
  50401. end = _out + (strm.avail_out - 257); //#ifdef INFLATE_STRICT
  50402. dmax = state.dmax; //#endif
  50403. wsize = state.wsize;
  50404. whave = state.whave;
  50405. wnext = state.wnext;
  50406. s_window = state.window;
  50407. hold = state.hold;
  50408. bits = state.bits;
  50409. lcode = state.lencode;
  50410. dcode = state.distcode;
  50411. lmask = (1 << state.lenbits) - 1;
  50412. dmask = (1 << state.distbits) - 1;
  50413. /* decode literals and length/distances until end-of-block or not enough
  50414. input data or output space */
  50415. top: do {
  50416. if (bits < 15) {
  50417. hold += input[_in++] << bits;
  50418. bits += 8;
  50419. hold += input[_in++] << bits;
  50420. bits += 8;
  50421. }
  50422. here = lcode[hold & lmask];
  50423. dolen: for (;;) {
  50424. // Goto emulation
  50425. op = here >>> 24
  50426. /*here.bits*/
  50427. ;
  50428. hold >>>= op;
  50429. bits -= op;
  50430. op = here >>> 16 & 0xff
  50431. /*here.op*/
  50432. ;
  50433. if (op === 0) {
  50434. /* literal */
  50435. //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
  50436. // "inflate: literal '%c'\n" :
  50437. // "inflate: literal 0x%02x\n", here.val));
  50438. output[_out++] = here & 0xffff
  50439. /*here.val*/
  50440. ;
  50441. } else if (op & 16) {
  50442. /* length base */
  50443. len = here & 0xffff
  50444. /*here.val*/
  50445. ;
  50446. op &= 15;
  50447. /* number of extra bits */
  50448. if (op) {
  50449. if (bits < op) {
  50450. hold += input[_in++] << bits;
  50451. bits += 8;
  50452. }
  50453. len += hold & (1 << op) - 1;
  50454. hold >>>= op;
  50455. bits -= op;
  50456. } //Tracevv((stderr, "inflate: length %u\n", len));
  50457. if (bits < 15) {
  50458. hold += input[_in++] << bits;
  50459. bits += 8;
  50460. hold += input[_in++] << bits;
  50461. bits += 8;
  50462. }
  50463. here = dcode[hold & dmask];
  50464. dodist: for (;;) {
  50465. // goto emulation
  50466. op = here >>> 24
  50467. /*here.bits*/
  50468. ;
  50469. hold >>>= op;
  50470. bits -= op;
  50471. op = here >>> 16 & 0xff
  50472. /*here.op*/
  50473. ;
  50474. if (op & 16) {
  50475. /* distance base */
  50476. dist = here & 0xffff
  50477. /*here.val*/
  50478. ;
  50479. op &= 15;
  50480. /* number of extra bits */
  50481. if (bits < op) {
  50482. hold += input[_in++] << bits;
  50483. bits += 8;
  50484. if (bits < op) {
  50485. hold += input[_in++] << bits;
  50486. bits += 8;
  50487. }
  50488. }
  50489. dist += hold & (1 << op) - 1; //#ifdef INFLATE_STRICT
  50490. if (dist > dmax) {
  50491. strm.msg = 'invalid distance too far back';
  50492. state.mode = BAD;
  50493. break top;
  50494. } //#endif
  50495. hold >>>= op;
  50496. bits -= op; //Tracevv((stderr, "inflate: distance %u\n", dist));
  50497. op = _out - beg;
  50498. /* max distance in output */
  50499. if (dist > op) {
  50500. /* see if copy from window */
  50501. op = dist - op;
  50502. /* distance back in window */
  50503. if (op > whave) {
  50504. if (state.sane) {
  50505. strm.msg = 'invalid distance too far back';
  50506. state.mode = BAD;
  50507. break top;
  50508. } // (!) This block is disabled in zlib defaults,
  50509. // don't enable it for binary compatibility
  50510. //#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
  50511. // if (len <= op - whave) {
  50512. // do {
  50513. // output[_out++] = 0;
  50514. // } while (--len);
  50515. // continue top;
  50516. // }
  50517. // len -= op - whave;
  50518. // do {
  50519. // output[_out++] = 0;
  50520. // } while (--op > whave);
  50521. // if (op === 0) {
  50522. // from = _out - dist;
  50523. // do {
  50524. // output[_out++] = output[from++];
  50525. // } while (--len);
  50526. // continue top;
  50527. // }
  50528. //#endif
  50529. }
  50530. from = 0; // window index
  50531. from_source = s_window;
  50532. if (wnext === 0) {
  50533. /* very common case */
  50534. from += wsize - op;
  50535. if (op < len) {
  50536. /* some from window */
  50537. len -= op;
  50538. do {
  50539. output[_out++] = s_window[from++];
  50540. } while (--op);
  50541. from = _out - dist;
  50542. /* rest from output */
  50543. from_source = output;
  50544. }
  50545. } else if (wnext < op) {
  50546. /* wrap around window */
  50547. from += wsize + wnext - op;
  50548. op -= wnext;
  50549. if (op < len) {
  50550. /* some from end of window */
  50551. len -= op;
  50552. do {
  50553. output[_out++] = s_window[from++];
  50554. } while (--op);
  50555. from = 0;
  50556. if (wnext < len) {
  50557. /* some from start of window */
  50558. op = wnext;
  50559. len -= op;
  50560. do {
  50561. output[_out++] = s_window[from++];
  50562. } while (--op);
  50563. from = _out - dist;
  50564. /* rest from output */
  50565. from_source = output;
  50566. }
  50567. }
  50568. } else {
  50569. /* contiguous in window */
  50570. from += wnext - op;
  50571. if (op < len) {
  50572. /* some from window */
  50573. len -= op;
  50574. do {
  50575. output[_out++] = s_window[from++];
  50576. } while (--op);
  50577. from = _out - dist;
  50578. /* rest from output */
  50579. from_source = output;
  50580. }
  50581. }
  50582. while (len > 2) {
  50583. output[_out++] = from_source[from++];
  50584. output[_out++] = from_source[from++];
  50585. output[_out++] = from_source[from++];
  50586. len -= 3;
  50587. }
  50588. if (len) {
  50589. output[_out++] = from_source[from++];
  50590. if (len > 1) {
  50591. output[_out++] = from_source[from++];
  50592. }
  50593. }
  50594. } else {
  50595. from = _out - dist;
  50596. /* copy direct from output */
  50597. do {
  50598. /* minimum length is three */
  50599. output[_out++] = output[from++];
  50600. output[_out++] = output[from++];
  50601. output[_out++] = output[from++];
  50602. len -= 3;
  50603. } while (len > 2);
  50604. if (len) {
  50605. output[_out++] = output[from++];
  50606. if (len > 1) {
  50607. output[_out++] = output[from++];
  50608. }
  50609. }
  50610. }
  50611. } else if ((op & 64) === 0) {
  50612. /* 2nd level distance code */
  50613. here = dcode[(here & 0xffff) + (
  50614. /*here.val*/
  50615. hold & (1 << op) - 1)];
  50616. continue dodist;
  50617. } else {
  50618. strm.msg = 'invalid distance code';
  50619. state.mode = BAD;
  50620. break top;
  50621. }
  50622. break; // need to emulate goto via "continue"
  50623. }
  50624. } else if ((op & 64) === 0) {
  50625. /* 2nd level length code */
  50626. here = lcode[(here & 0xffff) + (
  50627. /*here.val*/
  50628. hold & (1 << op) - 1)];
  50629. continue dolen;
  50630. } else if (op & 32) {
  50631. /* end-of-block */
  50632. //Tracevv((stderr, "inflate: end of block\n"));
  50633. state.mode = TYPE;
  50634. break top;
  50635. } else {
  50636. strm.msg = 'invalid literal/length code';
  50637. state.mode = BAD;
  50638. break top;
  50639. }
  50640. break; // need to emulate goto via "continue"
  50641. }
  50642. } while (_in < last && _out < end);
  50643. /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
  50644. len = bits >> 3;
  50645. _in -= len;
  50646. bits -= len << 3;
  50647. hold &= (1 << bits) - 1;
  50648. /* update state and return */
  50649. strm.next_in = _in;
  50650. strm.next_out = _out;
  50651. strm.avail_in = _in < last ? 5 + (last - _in) : 5 - (_in - last);
  50652. strm.avail_out = _out < end ? 257 + (end - _out) : 257 - (_out - end);
  50653. state.hold = hold;
  50654. state.bits = bits;
  50655. return;
  50656. };
  50657. },{}],341:[function(require,module,exports){
  50658. 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  50659. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  50660. //
  50661. // This software is provided 'as-is', without any express or implied
  50662. // warranty. In no event will the authors be held liable for any damages
  50663. // arising from the use of this software.
  50664. //
  50665. // Permission is granted to anyone to use this software for any purpose,
  50666. // including commercial applications, and to alter it and redistribute it
  50667. // freely, subject to the following restrictions:
  50668. //
  50669. // 1. The origin of this software must not be misrepresented; you must not
  50670. // claim that you wrote the original software. If you use this software
  50671. // in a product, an acknowledgment in the product documentation would be
  50672. // appreciated but is not required.
  50673. // 2. Altered source versions must be plainly marked as such, and must not be
  50674. // misrepresented as being the original software.
  50675. // 3. This notice may not be removed or altered from any source distribution.
  50676. var utils = require('../utils/common');
  50677. var adler32 = require('./adler32');
  50678. var crc32 = require('./crc32');
  50679. var inflate_fast = require('./inffast');
  50680. var inflate_table = require('./inftrees');
  50681. var CODES = 0;
  50682. var LENS = 1;
  50683. var DISTS = 2;
  50684. /* Public constants ==========================================================*/
  50685. /* ===========================================================================*/
  50686. /* Allowed flush values; see deflate() and inflate() below for details */
  50687. //var Z_NO_FLUSH = 0;
  50688. //var Z_PARTIAL_FLUSH = 1;
  50689. //var Z_SYNC_FLUSH = 2;
  50690. //var Z_FULL_FLUSH = 3;
  50691. var Z_FINISH = 4;
  50692. var Z_BLOCK = 5;
  50693. var Z_TREES = 6;
  50694. /* Return codes for the compression/decompression functions. Negative values
  50695. * are errors, positive values are used for special but normal events.
  50696. */
  50697. var Z_OK = 0;
  50698. var Z_STREAM_END = 1;
  50699. var Z_NEED_DICT = 2; //var Z_ERRNO = -1;
  50700. var Z_STREAM_ERROR = -2;
  50701. var Z_DATA_ERROR = -3;
  50702. var Z_MEM_ERROR = -4;
  50703. var Z_BUF_ERROR = -5; //var Z_VERSION_ERROR = -6;
  50704. /* The deflate compression method */
  50705. var Z_DEFLATED = 8;
  50706. /* STATES ====================================================================*/
  50707. /* ===========================================================================*/
  50708. var HEAD = 1;
  50709. /* i: waiting for magic header */
  50710. var FLAGS = 2;
  50711. /* i: waiting for method and flags (gzip) */
  50712. var TIME = 3;
  50713. /* i: waiting for modification time (gzip) */
  50714. var OS = 4;
  50715. /* i: waiting for extra flags and operating system (gzip) */
  50716. var EXLEN = 5;
  50717. /* i: waiting for extra length (gzip) */
  50718. var EXTRA = 6;
  50719. /* i: waiting for extra bytes (gzip) */
  50720. var NAME = 7;
  50721. /* i: waiting for end of file name (gzip) */
  50722. var COMMENT = 8;
  50723. /* i: waiting for end of comment (gzip) */
  50724. var HCRC = 9;
  50725. /* i: waiting for header crc (gzip) */
  50726. var DICTID = 10;
  50727. /* i: waiting for dictionary check value */
  50728. var DICT = 11;
  50729. /* waiting for inflateSetDictionary() call */
  50730. var TYPE = 12;
  50731. /* i: waiting for type bits, including last-flag bit */
  50732. var TYPEDO = 13;
  50733. /* i: same, but skip check to exit inflate on new block */
  50734. var STORED = 14;
  50735. /* i: waiting for stored size (length and complement) */
  50736. var COPY_ = 15;
  50737. /* i/o: same as COPY below, but only first time in */
  50738. var COPY = 16;
  50739. /* i/o: waiting for input or output to copy stored block */
  50740. var TABLE = 17;
  50741. /* i: waiting for dynamic block table lengths */
  50742. var LENLENS = 18;
  50743. /* i: waiting for code length code lengths */
  50744. var CODELENS = 19;
  50745. /* i: waiting for length/lit and distance code lengths */
  50746. var LEN_ = 20;
  50747. /* i: same as LEN below, but only first time in */
  50748. var LEN = 21;
  50749. /* i: waiting for length/lit/eob code */
  50750. var LENEXT = 22;
  50751. /* i: waiting for length extra bits */
  50752. var DIST = 23;
  50753. /* i: waiting for distance code */
  50754. var DISTEXT = 24;
  50755. /* i: waiting for distance extra bits */
  50756. var MATCH = 25;
  50757. /* o: waiting for output space to copy string */
  50758. var LIT = 26;
  50759. /* o: waiting for output space to write literal */
  50760. var CHECK = 27;
  50761. /* i: waiting for 32-bit check value */
  50762. var LENGTH = 28;
  50763. /* i: waiting for 32-bit length (gzip) */
  50764. var DONE = 29;
  50765. /* finished check, done -- remain here until reset */
  50766. var BAD = 30;
  50767. /* got a data error -- remain here until reset */
  50768. var MEM = 31;
  50769. /* got an inflate() memory error -- remain here until reset */
  50770. var SYNC = 32;
  50771. /* looking for synchronization bytes to restart inflate() */
  50772. /* ===========================================================================*/
  50773. var ENOUGH_LENS = 852;
  50774. var ENOUGH_DISTS = 592; //var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);
  50775. var MAX_WBITS = 15;
  50776. /* 32K LZ77 window */
  50777. var DEF_WBITS = MAX_WBITS;
  50778. function zswap32(q) {
  50779. return (q >>> 24 & 0xff) + (q >>> 8 & 0xff00) + ((q & 0xff00) << 8) + ((q & 0xff) << 24);
  50780. }
  50781. function InflateState() {
  50782. this.mode = 0;
  50783. /* current inflate mode */
  50784. this.last = false;
  50785. /* true if processing last block */
  50786. this.wrap = 0;
  50787. /* bit 0 true for zlib, bit 1 true for gzip */
  50788. this.havedict = false;
  50789. /* true if dictionary provided */
  50790. this.flags = 0;
  50791. /* gzip header method and flags (0 if zlib) */
  50792. this.dmax = 0;
  50793. /* zlib header max distance (INFLATE_STRICT) */
  50794. this.check = 0;
  50795. /* protected copy of check value */
  50796. this.total = 0;
  50797. /* protected copy of output count */
  50798. // TODO: may be {}
  50799. this.head = null;
  50800. /* where to save gzip header information */
  50801. /* sliding window */
  50802. this.wbits = 0;
  50803. /* log base 2 of requested window size */
  50804. this.wsize = 0;
  50805. /* window size or zero if not using window */
  50806. this.whave = 0;
  50807. /* valid bytes in the window */
  50808. this.wnext = 0;
  50809. /* window write index */
  50810. this.window = null;
  50811. /* allocated sliding window, if needed */
  50812. /* bit accumulator */
  50813. this.hold = 0;
  50814. /* input bit accumulator */
  50815. this.bits = 0;
  50816. /* number of bits in "in" */
  50817. /* for string and stored block copying */
  50818. this.length = 0;
  50819. /* literal or length of data to copy */
  50820. this.offset = 0;
  50821. /* distance back to copy string from */
  50822. /* for table and code decoding */
  50823. this.extra = 0;
  50824. /* extra bits needed */
  50825. /* fixed and dynamic code tables */
  50826. this.lencode = null;
  50827. /* starting table for length/literal codes */
  50828. this.distcode = null;
  50829. /* starting table for distance codes */
  50830. this.lenbits = 0;
  50831. /* index bits for lencode */
  50832. this.distbits = 0;
  50833. /* index bits for distcode */
  50834. /* dynamic table building */
  50835. this.ncode = 0;
  50836. /* number of code length code lengths */
  50837. this.nlen = 0;
  50838. /* number of length code lengths */
  50839. this.ndist = 0;
  50840. /* number of distance code lengths */
  50841. this.have = 0;
  50842. /* number of code lengths in lens[] */
  50843. this.next = null;
  50844. /* next available space in codes[] */
  50845. this.lens = new utils.Buf16(320);
  50846. /* temporary storage for code lengths */
  50847. this.work = new utils.Buf16(288);
  50848. /* work area for code table building */
  50849. /*
  50850. because we don't have pointers in js, we use lencode and distcode directly
  50851. as buffers so we don't need codes
  50852. */
  50853. //this.codes = new utils.Buf32(ENOUGH); /* space for code tables */
  50854. this.lendyn = null;
  50855. /* dynamic table for length/literal codes (JS specific) */
  50856. this.distdyn = null;
  50857. /* dynamic table for distance codes (JS specific) */
  50858. this.sane = 0;
  50859. /* if false, allow invalid distance too far */
  50860. this.back = 0;
  50861. /* bits back of last unprocessed length/lit */
  50862. this.was = 0;
  50863. /* initial length of match */
  50864. }
  50865. function inflateResetKeep(strm) {
  50866. var state;
  50867. if (!strm || !strm.state) {
  50868. return Z_STREAM_ERROR;
  50869. }
  50870. state = strm.state;
  50871. strm.total_in = strm.total_out = state.total = 0;
  50872. strm.msg = '';
  50873. /*Z_NULL*/
  50874. if (state.wrap) {
  50875. /* to support ill-conceived Java test suite */
  50876. strm.adler = state.wrap & 1;
  50877. }
  50878. state.mode = HEAD;
  50879. state.last = 0;
  50880. state.havedict = 0;
  50881. state.dmax = 32768;
  50882. state.head = null
  50883. /*Z_NULL*/
  50884. ;
  50885. state.hold = 0;
  50886. state.bits = 0; //state.lencode = state.distcode = state.next = state.codes;
  50887. state.lencode = state.lendyn = new utils.Buf32(ENOUGH_LENS);
  50888. state.distcode = state.distdyn = new utils.Buf32(ENOUGH_DISTS);
  50889. state.sane = 1;
  50890. state.back = -1; //Tracev((stderr, "inflate: reset\n"));
  50891. return Z_OK;
  50892. }
  50893. function inflateReset(strm) {
  50894. var state;
  50895. if (!strm || !strm.state) {
  50896. return Z_STREAM_ERROR;
  50897. }
  50898. state = strm.state;
  50899. state.wsize = 0;
  50900. state.whave = 0;
  50901. state.wnext = 0;
  50902. return inflateResetKeep(strm);
  50903. }
  50904. function inflateReset2(strm, windowBits) {
  50905. var wrap;
  50906. var state;
  50907. /* get the state */
  50908. if (!strm || !strm.state) {
  50909. return Z_STREAM_ERROR;
  50910. }
  50911. state = strm.state;
  50912. /* extract wrap request from windowBits parameter */
  50913. if (windowBits < 0) {
  50914. wrap = 0;
  50915. windowBits = -windowBits;
  50916. } else {
  50917. wrap = (windowBits >> 4) + 1;
  50918. if (windowBits < 48) {
  50919. windowBits &= 15;
  50920. }
  50921. }
  50922. /* set number of window bits, free window if different */
  50923. if (windowBits && (windowBits < 8 || windowBits > 15)) {
  50924. return Z_STREAM_ERROR;
  50925. }
  50926. if (state.window !== null && state.wbits !== windowBits) {
  50927. state.window = null;
  50928. }
  50929. /* update state and reset the rest of it */
  50930. state.wrap = wrap;
  50931. state.wbits = windowBits;
  50932. return inflateReset(strm);
  50933. }
  50934. function inflateInit2(strm, windowBits) {
  50935. var ret;
  50936. var state;
  50937. if (!strm) {
  50938. return Z_STREAM_ERROR;
  50939. } //strm.msg = Z_NULL; /* in case we return an error */
  50940. state = new InflateState(); //if (state === Z_NULL) return Z_MEM_ERROR;
  50941. //Tracev((stderr, "inflate: allocated\n"));
  50942. strm.state = state;
  50943. state.window = null
  50944. /*Z_NULL*/
  50945. ;
  50946. ret = inflateReset2(strm, windowBits);
  50947. if (ret !== Z_OK) {
  50948. strm.state = null
  50949. /*Z_NULL*/
  50950. ;
  50951. }
  50952. return ret;
  50953. }
  50954. function inflateInit(strm) {
  50955. return inflateInit2(strm, DEF_WBITS);
  50956. }
  50957. /*
  50958. Return state with length and distance decoding tables and index sizes set to
  50959. fixed code decoding. Normally this returns fixed tables from inffixed.h.
  50960. If BUILDFIXED is defined, then instead this routine builds the tables the
  50961. first time it's called, and returns those tables the first time and
  50962. thereafter. This reduces the size of the code by about 2K bytes, in
  50963. exchange for a little execution time. However, BUILDFIXED should not be
  50964. used for threaded applications, since the rewriting of the tables and virgin
  50965. may not be thread-safe.
  50966. */
  50967. var virgin = true;
  50968. var lenfix, distfix; // We have no pointers in JS, so keep tables separate
  50969. function fixedtables(state) {
  50970. /* build fixed huffman tables if first call (may not be thread safe) */
  50971. if (virgin) {
  50972. var sym;
  50973. lenfix = new utils.Buf32(512);
  50974. distfix = new utils.Buf32(32);
  50975. /* literal/length table */
  50976. sym = 0;
  50977. while (sym < 144) {
  50978. state.lens[sym++] = 8;
  50979. }
  50980. while (sym < 256) {
  50981. state.lens[sym++] = 9;
  50982. }
  50983. while (sym < 280) {
  50984. state.lens[sym++] = 7;
  50985. }
  50986. while (sym < 288) {
  50987. state.lens[sym++] = 8;
  50988. }
  50989. inflate_table(LENS, state.lens, 0, 288, lenfix, 0, state.work, {
  50990. bits: 9
  50991. });
  50992. /* distance table */
  50993. sym = 0;
  50994. while (sym < 32) {
  50995. state.lens[sym++] = 5;
  50996. }
  50997. inflate_table(DISTS, state.lens, 0, 32, distfix, 0, state.work, {
  50998. bits: 5
  50999. });
  51000. /* do this just once */
  51001. virgin = false;
  51002. }
  51003. state.lencode = lenfix;
  51004. state.lenbits = 9;
  51005. state.distcode = distfix;
  51006. state.distbits = 5;
  51007. }
  51008. /*
  51009. Update the window with the last wsize (normally 32K) bytes written before
  51010. returning. If window does not exist yet, create it. This is only called
  51011. when a window is already in use, or when output has been written during this
  51012. inflate call, but the end of the deflate stream has not been reached yet.
  51013. It is also called to create a window for dictionary data when a dictionary
  51014. is loaded.
  51015. Providing output buffers larger than 32K to inflate() should provide a speed
  51016. advantage, since only the last 32K of output is copied to the sliding window
  51017. upon return from inflate(), and since all distances after the first 32K of
  51018. output will fall in the output data, making match copies simpler and faster.
  51019. The advantage may be dependent on the size of the processor's data caches.
  51020. */
  51021. function updatewindow(strm, src, end, copy) {
  51022. var dist;
  51023. var state = strm.state;
  51024. /* if it hasn't been done already, allocate space for the window */
  51025. if (state.window === null) {
  51026. state.wsize = 1 << state.wbits;
  51027. state.wnext = 0;
  51028. state.whave = 0;
  51029. state.window = new utils.Buf8(state.wsize);
  51030. }
  51031. /* copy state->wsize or less output bytes into the circular window */
  51032. if (copy >= state.wsize) {
  51033. utils.arraySet(state.window, src, end - state.wsize, state.wsize, 0);
  51034. state.wnext = 0;
  51035. state.whave = state.wsize;
  51036. } else {
  51037. dist = state.wsize - state.wnext;
  51038. if (dist > copy) {
  51039. dist = copy;
  51040. } //zmemcpy(state->window + state->wnext, end - copy, dist);
  51041. utils.arraySet(state.window, src, end - copy, dist, state.wnext);
  51042. copy -= dist;
  51043. if (copy) {
  51044. //zmemcpy(state->window, end - copy, copy);
  51045. utils.arraySet(state.window, src, end - copy, copy, 0);
  51046. state.wnext = copy;
  51047. state.whave = state.wsize;
  51048. } else {
  51049. state.wnext += dist;
  51050. if (state.wnext === state.wsize) {
  51051. state.wnext = 0;
  51052. }
  51053. if (state.whave < state.wsize) {
  51054. state.whave += dist;
  51055. }
  51056. }
  51057. }
  51058. return 0;
  51059. }
  51060. function inflate(strm, flush) {
  51061. var state;
  51062. var input, output; // input/output buffers
  51063. var next;
  51064. /* next input INDEX */
  51065. var put;
  51066. /* next output INDEX */
  51067. var have, left;
  51068. /* available input and output */
  51069. var hold;
  51070. /* bit buffer */
  51071. var bits;
  51072. /* bits in bit buffer */
  51073. var _in, _out;
  51074. /* save starting available input and output */
  51075. var copy;
  51076. /* number of stored or match bytes to copy */
  51077. var from;
  51078. /* where to copy match bytes from */
  51079. var from_source;
  51080. var here = 0;
  51081. /* current decoding table entry */
  51082. var here_bits, here_op, here_val; // paked "here" denormalized (JS specific)
  51083. //var last; /* parent table entry */
  51084. var last_bits, last_op, last_val; // paked "last" denormalized (JS specific)
  51085. var len;
  51086. /* length to copy for repeats, bits to drop */
  51087. var ret;
  51088. /* return code */
  51089. var hbuf = new utils.Buf8(4);
  51090. /* buffer for gzip header crc calculation */
  51091. var opts;
  51092. var n; // temporary var for NEED_BITS
  51093. var order =
  51094. /* permutation of code lengths */
  51095. [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
  51096. if (!strm || !strm.state || !strm.output || !strm.input && strm.avail_in !== 0) {
  51097. return Z_STREAM_ERROR;
  51098. }
  51099. state = strm.state;
  51100. if (state.mode === TYPE) {
  51101. state.mode = TYPEDO;
  51102. }
  51103. /* skip check */
  51104. //--- LOAD() ---
  51105. put = strm.next_out;
  51106. output = strm.output;
  51107. left = strm.avail_out;
  51108. next = strm.next_in;
  51109. input = strm.input;
  51110. have = strm.avail_in;
  51111. hold = state.hold;
  51112. bits = state.bits; //---
  51113. _in = have;
  51114. _out = left;
  51115. ret = Z_OK;
  51116. inf_leave: // goto emulation
  51117. for (;;) {
  51118. switch (state.mode) {
  51119. case HEAD:
  51120. if (state.wrap === 0) {
  51121. state.mode = TYPEDO;
  51122. break;
  51123. } //=== NEEDBITS(16);
  51124. while (bits < 16) {
  51125. if (have === 0) {
  51126. break inf_leave;
  51127. }
  51128. have--;
  51129. hold += input[next++] << bits;
  51130. bits += 8;
  51131. } //===//
  51132. if (state.wrap & 2 && hold === 0x8b1f) {
  51133. /* gzip header */
  51134. state.check = 0
  51135. /*crc32(0L, Z_NULL, 0)*/
  51136. ; //=== CRC2(state.check, hold);
  51137. hbuf[0] = hold & 0xff;
  51138. hbuf[1] = hold >>> 8 & 0xff;
  51139. state.check = crc32(state.check, hbuf, 2, 0); //===//
  51140. //=== INITBITS();
  51141. hold = 0;
  51142. bits = 0; //===//
  51143. state.mode = FLAGS;
  51144. break;
  51145. }
  51146. state.flags = 0;
  51147. /* expect zlib header */
  51148. if (state.head) {
  51149. state.head.done = false;
  51150. }
  51151. if (!(state.wrap & 1) ||
  51152. /* check if zlib header allowed */
  51153. (((hold & 0xff) <<
  51154. /*BITS(8)*/
  51155. 8) + (hold >> 8)) % 31) {
  51156. strm.msg = 'incorrect header check';
  51157. state.mode = BAD;
  51158. break;
  51159. }
  51160. if ((hold & 0x0f) !==
  51161. /*BITS(4)*/
  51162. Z_DEFLATED) {
  51163. strm.msg = 'unknown compression method';
  51164. state.mode = BAD;
  51165. break;
  51166. } //--- DROPBITS(4) ---//
  51167. hold >>>= 4;
  51168. bits -= 4; //---//
  51169. len = (hold & 0x0f) +
  51170. /*BITS(4)*/
  51171. 8;
  51172. if (state.wbits === 0) {
  51173. state.wbits = len;
  51174. } else if (len > state.wbits) {
  51175. strm.msg = 'invalid window size';
  51176. state.mode = BAD;
  51177. break;
  51178. }
  51179. state.dmax = 1 << len; //Tracev((stderr, "inflate: zlib header ok\n"));
  51180. strm.adler = state.check = 1
  51181. /*adler32(0L, Z_NULL, 0)*/
  51182. ;
  51183. state.mode = hold & 0x200 ? DICTID : TYPE; //=== INITBITS();
  51184. hold = 0;
  51185. bits = 0; //===//
  51186. break;
  51187. case FLAGS:
  51188. //=== NEEDBITS(16); */
  51189. while (bits < 16) {
  51190. if (have === 0) {
  51191. break inf_leave;
  51192. }
  51193. have--;
  51194. hold += input[next++] << bits;
  51195. bits += 8;
  51196. } //===//
  51197. state.flags = hold;
  51198. if ((state.flags & 0xff) !== Z_DEFLATED) {
  51199. strm.msg = 'unknown compression method';
  51200. state.mode = BAD;
  51201. break;
  51202. }
  51203. if (state.flags & 0xe000) {
  51204. strm.msg = 'unknown header flags set';
  51205. state.mode = BAD;
  51206. break;
  51207. }
  51208. if (state.head) {
  51209. state.head.text = hold >> 8 & 1;
  51210. }
  51211. if (state.flags & 0x0200) {
  51212. //=== CRC2(state.check, hold);
  51213. hbuf[0] = hold & 0xff;
  51214. hbuf[1] = hold >>> 8 & 0xff;
  51215. state.check = crc32(state.check, hbuf, 2, 0); //===//
  51216. } //=== INITBITS();
  51217. hold = 0;
  51218. bits = 0; //===//
  51219. state.mode = TIME;
  51220. /* falls through */
  51221. case TIME:
  51222. //=== NEEDBITS(32); */
  51223. while (bits < 32) {
  51224. if (have === 0) {
  51225. break inf_leave;
  51226. }
  51227. have--;
  51228. hold += input[next++] << bits;
  51229. bits += 8;
  51230. } //===//
  51231. if (state.head) {
  51232. state.head.time = hold;
  51233. }
  51234. if (state.flags & 0x0200) {
  51235. //=== CRC4(state.check, hold)
  51236. hbuf[0] = hold & 0xff;
  51237. hbuf[1] = hold >>> 8 & 0xff;
  51238. hbuf[2] = hold >>> 16 & 0xff;
  51239. hbuf[3] = hold >>> 24 & 0xff;
  51240. state.check = crc32(state.check, hbuf, 4, 0); //===
  51241. } //=== INITBITS();
  51242. hold = 0;
  51243. bits = 0; //===//
  51244. state.mode = OS;
  51245. /* falls through */
  51246. case OS:
  51247. //=== NEEDBITS(16); */
  51248. while (bits < 16) {
  51249. if (have === 0) {
  51250. break inf_leave;
  51251. }
  51252. have--;
  51253. hold += input[next++] << bits;
  51254. bits += 8;
  51255. } //===//
  51256. if (state.head) {
  51257. state.head.xflags = hold & 0xff;
  51258. state.head.os = hold >> 8;
  51259. }
  51260. if (state.flags & 0x0200) {
  51261. //=== CRC2(state.check, hold);
  51262. hbuf[0] = hold & 0xff;
  51263. hbuf[1] = hold >>> 8 & 0xff;
  51264. state.check = crc32(state.check, hbuf, 2, 0); //===//
  51265. } //=== INITBITS();
  51266. hold = 0;
  51267. bits = 0; //===//
  51268. state.mode = EXLEN;
  51269. /* falls through */
  51270. case EXLEN:
  51271. if (state.flags & 0x0400) {
  51272. //=== NEEDBITS(16); */
  51273. while (bits < 16) {
  51274. if (have === 0) {
  51275. break inf_leave;
  51276. }
  51277. have--;
  51278. hold += input[next++] << bits;
  51279. bits += 8;
  51280. } //===//
  51281. state.length = hold;
  51282. if (state.head) {
  51283. state.head.extra_len = hold;
  51284. }
  51285. if (state.flags & 0x0200) {
  51286. //=== CRC2(state.check, hold);
  51287. hbuf[0] = hold & 0xff;
  51288. hbuf[1] = hold >>> 8 & 0xff;
  51289. state.check = crc32(state.check, hbuf, 2, 0); //===//
  51290. } //=== INITBITS();
  51291. hold = 0;
  51292. bits = 0; //===//
  51293. } else if (state.head) {
  51294. state.head.extra = null
  51295. /*Z_NULL*/
  51296. ;
  51297. }
  51298. state.mode = EXTRA;
  51299. /* falls through */
  51300. case EXTRA:
  51301. if (state.flags & 0x0400) {
  51302. copy = state.length;
  51303. if (copy > have) {
  51304. copy = have;
  51305. }
  51306. if (copy) {
  51307. if (state.head) {
  51308. len = state.head.extra_len - state.length;
  51309. if (!state.head.extra) {
  51310. // Use untyped array for more convenient processing later
  51311. state.head.extra = new Array(state.head.extra_len);
  51312. }
  51313. utils.arraySet(state.head.extra, input, next, // extra field is limited to 65536 bytes
  51314. // - no need for additional size check
  51315. copy,
  51316. /*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/
  51317. len); //zmemcpy(state.head.extra + len, next,
  51318. // len + copy > state.head.extra_max ?
  51319. // state.head.extra_max - len : copy);
  51320. }
  51321. if (state.flags & 0x0200) {
  51322. state.check = crc32(state.check, input, copy, next);
  51323. }
  51324. have -= copy;
  51325. next += copy;
  51326. state.length -= copy;
  51327. }
  51328. if (state.length) {
  51329. break inf_leave;
  51330. }
  51331. }
  51332. state.length = 0;
  51333. state.mode = NAME;
  51334. /* falls through */
  51335. case NAME:
  51336. if (state.flags & 0x0800) {
  51337. if (have === 0) {
  51338. break inf_leave;
  51339. }
  51340. copy = 0;
  51341. do {
  51342. // TODO: 2 or 1 bytes?
  51343. len = input[next + copy++];
  51344. /* use constant limit because in js we should not preallocate memory */
  51345. if (state.head && len && state.length < 65536
  51346. /*state.head.name_max*/
  51347. ) {
  51348. state.head.name += String.fromCharCode(len);
  51349. }
  51350. } while (len && copy < have);
  51351. if (state.flags & 0x0200) {
  51352. state.check = crc32(state.check, input, copy, next);
  51353. }
  51354. have -= copy;
  51355. next += copy;
  51356. if (len) {
  51357. break inf_leave;
  51358. }
  51359. } else if (state.head) {
  51360. state.head.name = null;
  51361. }
  51362. state.length = 0;
  51363. state.mode = COMMENT;
  51364. /* falls through */
  51365. case COMMENT:
  51366. if (state.flags & 0x1000) {
  51367. if (have === 0) {
  51368. break inf_leave;
  51369. }
  51370. copy = 0;
  51371. do {
  51372. len = input[next + copy++];
  51373. /* use constant limit because in js we should not preallocate memory */
  51374. if (state.head && len && state.length < 65536
  51375. /*state.head.comm_max*/
  51376. ) {
  51377. state.head.comment += String.fromCharCode(len);
  51378. }
  51379. } while (len && copy < have);
  51380. if (state.flags & 0x0200) {
  51381. state.check = crc32(state.check, input, copy, next);
  51382. }
  51383. have -= copy;
  51384. next += copy;
  51385. if (len) {
  51386. break inf_leave;
  51387. }
  51388. } else if (state.head) {
  51389. state.head.comment = null;
  51390. }
  51391. state.mode = HCRC;
  51392. /* falls through */
  51393. case HCRC:
  51394. if (state.flags & 0x0200) {
  51395. //=== NEEDBITS(16); */
  51396. while (bits < 16) {
  51397. if (have === 0) {
  51398. break inf_leave;
  51399. }
  51400. have--;
  51401. hold += input[next++] << bits;
  51402. bits += 8;
  51403. } //===//
  51404. if (hold !== (state.check & 0xffff)) {
  51405. strm.msg = 'header crc mismatch';
  51406. state.mode = BAD;
  51407. break;
  51408. } //=== INITBITS();
  51409. hold = 0;
  51410. bits = 0; //===//
  51411. }
  51412. if (state.head) {
  51413. state.head.hcrc = state.flags >> 9 & 1;
  51414. state.head.done = true;
  51415. }
  51416. strm.adler = state.check = 0;
  51417. state.mode = TYPE;
  51418. break;
  51419. case DICTID:
  51420. //=== NEEDBITS(32); */
  51421. while (bits < 32) {
  51422. if (have === 0) {
  51423. break inf_leave;
  51424. }
  51425. have--;
  51426. hold += input[next++] << bits;
  51427. bits += 8;
  51428. } //===//
  51429. strm.adler = state.check = zswap32(hold); //=== INITBITS();
  51430. hold = 0;
  51431. bits = 0; //===//
  51432. state.mode = DICT;
  51433. /* falls through */
  51434. case DICT:
  51435. if (state.havedict === 0) {
  51436. //--- RESTORE() ---
  51437. strm.next_out = put;
  51438. strm.avail_out = left;
  51439. strm.next_in = next;
  51440. strm.avail_in = have;
  51441. state.hold = hold;
  51442. state.bits = bits; //---
  51443. return Z_NEED_DICT;
  51444. }
  51445. strm.adler = state.check = 1
  51446. /*adler32(0L, Z_NULL, 0)*/
  51447. ;
  51448. state.mode = TYPE;
  51449. /* falls through */
  51450. case TYPE:
  51451. if (flush === Z_BLOCK || flush === Z_TREES) {
  51452. break inf_leave;
  51453. }
  51454. /* falls through */
  51455. case TYPEDO:
  51456. if (state.last) {
  51457. //--- BYTEBITS() ---//
  51458. hold >>>= bits & 7;
  51459. bits -= bits & 7; //---//
  51460. state.mode = CHECK;
  51461. break;
  51462. } //=== NEEDBITS(3); */
  51463. while (bits < 3) {
  51464. if (have === 0) {
  51465. break inf_leave;
  51466. }
  51467. have--;
  51468. hold += input[next++] << bits;
  51469. bits += 8;
  51470. } //===//
  51471. state.last = hold & 0x01
  51472. /*BITS(1)*/
  51473. ; //--- DROPBITS(1) ---//
  51474. hold >>>= 1;
  51475. bits -= 1; //---//
  51476. switch (hold & 0x03) {
  51477. /*BITS(2)*/
  51478. case 0:
  51479. /* stored block */
  51480. //Tracev((stderr, "inflate: stored block%s\n",
  51481. // state.last ? " (last)" : ""));
  51482. state.mode = STORED;
  51483. break;
  51484. case 1:
  51485. /* fixed block */
  51486. fixedtables(state); //Tracev((stderr, "inflate: fixed codes block%s\n",
  51487. // state.last ? " (last)" : ""));
  51488. state.mode = LEN_;
  51489. /* decode codes */
  51490. if (flush === Z_TREES) {
  51491. //--- DROPBITS(2) ---//
  51492. hold >>>= 2;
  51493. bits -= 2; //---//
  51494. break inf_leave;
  51495. }
  51496. break;
  51497. case 2:
  51498. /* dynamic block */
  51499. //Tracev((stderr, "inflate: dynamic codes block%s\n",
  51500. // state.last ? " (last)" : ""));
  51501. state.mode = TABLE;
  51502. break;
  51503. case 3:
  51504. strm.msg = 'invalid block type';
  51505. state.mode = BAD;
  51506. } //--- DROPBITS(2) ---//
  51507. hold >>>= 2;
  51508. bits -= 2; //---//
  51509. break;
  51510. case STORED:
  51511. //--- BYTEBITS() ---// /* go to byte boundary */
  51512. hold >>>= bits & 7;
  51513. bits -= bits & 7; //---//
  51514. //=== NEEDBITS(32); */
  51515. while (bits < 32) {
  51516. if (have === 0) {
  51517. break inf_leave;
  51518. }
  51519. have--;
  51520. hold += input[next++] << bits;
  51521. bits += 8;
  51522. } //===//
  51523. if ((hold & 0xffff) !== (hold >>> 16 ^ 0xffff)) {
  51524. strm.msg = 'invalid stored block lengths';
  51525. state.mode = BAD;
  51526. break;
  51527. }
  51528. state.length = hold & 0xffff; //Tracev((stderr, "inflate: stored length %u\n",
  51529. // state.length));
  51530. //=== INITBITS();
  51531. hold = 0;
  51532. bits = 0; //===//
  51533. state.mode = COPY_;
  51534. if (flush === Z_TREES) {
  51535. break inf_leave;
  51536. }
  51537. /* falls through */
  51538. case COPY_:
  51539. state.mode = COPY;
  51540. /* falls through */
  51541. case COPY:
  51542. copy = state.length;
  51543. if (copy) {
  51544. if (copy > have) {
  51545. copy = have;
  51546. }
  51547. if (copy > left) {
  51548. copy = left;
  51549. }
  51550. if (copy === 0) {
  51551. break inf_leave;
  51552. } //--- zmemcpy(put, next, copy); ---
  51553. utils.arraySet(output, input, next, copy, put); //---//
  51554. have -= copy;
  51555. next += copy;
  51556. left -= copy;
  51557. put += copy;
  51558. state.length -= copy;
  51559. break;
  51560. } //Tracev((stderr, "inflate: stored end\n"));
  51561. state.mode = TYPE;
  51562. break;
  51563. case TABLE:
  51564. //=== NEEDBITS(14); */
  51565. while (bits < 14) {
  51566. if (have === 0) {
  51567. break inf_leave;
  51568. }
  51569. have--;
  51570. hold += input[next++] << bits;
  51571. bits += 8;
  51572. } //===//
  51573. state.nlen = (hold & 0x1f) +
  51574. /*BITS(5)*/
  51575. 257; //--- DROPBITS(5) ---//
  51576. hold >>>= 5;
  51577. bits -= 5; //---//
  51578. state.ndist = (hold & 0x1f) +
  51579. /*BITS(5)*/
  51580. 1; //--- DROPBITS(5) ---//
  51581. hold >>>= 5;
  51582. bits -= 5; //---//
  51583. state.ncode = (hold & 0x0f) +
  51584. /*BITS(4)*/
  51585. 4; //--- DROPBITS(4) ---//
  51586. hold >>>= 4;
  51587. bits -= 4; //---//
  51588. //#ifndef PKZIP_BUG_WORKAROUND
  51589. if (state.nlen > 286 || state.ndist > 30) {
  51590. strm.msg = 'too many length or distance symbols';
  51591. state.mode = BAD;
  51592. break;
  51593. } //#endif
  51594. //Tracev((stderr, "inflate: table sizes ok\n"));
  51595. state.have = 0;
  51596. state.mode = LENLENS;
  51597. /* falls through */
  51598. case LENLENS:
  51599. while (state.have < state.ncode) {
  51600. //=== NEEDBITS(3);
  51601. while (bits < 3) {
  51602. if (have === 0) {
  51603. break inf_leave;
  51604. }
  51605. have--;
  51606. hold += input[next++] << bits;
  51607. bits += 8;
  51608. } //===//
  51609. state.lens[order[state.have++]] = hold & 0x07; //BITS(3);
  51610. //--- DROPBITS(3) ---//
  51611. hold >>>= 3;
  51612. bits -= 3; //---//
  51613. }
  51614. while (state.have < 19) {
  51615. state.lens[order[state.have++]] = 0;
  51616. } // We have separate tables & no pointers. 2 commented lines below not needed.
  51617. //state.next = state.codes;
  51618. //state.lencode = state.next;
  51619. // Switch to use dynamic table
  51620. state.lencode = state.lendyn;
  51621. state.lenbits = 7;
  51622. opts = {
  51623. bits: state.lenbits
  51624. };
  51625. ret = inflate_table(CODES, state.lens, 0, 19, state.lencode, 0, state.work, opts);
  51626. state.lenbits = opts.bits;
  51627. if (ret) {
  51628. strm.msg = 'invalid code lengths set';
  51629. state.mode = BAD;
  51630. break;
  51631. } //Tracev((stderr, "inflate: code lengths ok\n"));
  51632. state.have = 0;
  51633. state.mode = CODELENS;
  51634. /* falls through */
  51635. case CODELENS:
  51636. while (state.have < state.nlen + state.ndist) {
  51637. for (;;) {
  51638. here = state.lencode[hold & (1 << state.lenbits) - 1];
  51639. /*BITS(state.lenbits)*/
  51640. here_bits = here >>> 24;
  51641. here_op = here >>> 16 & 0xff;
  51642. here_val = here & 0xffff;
  51643. if (here_bits <= bits) {
  51644. break;
  51645. } //--- PULLBYTE() ---//
  51646. if (have === 0) {
  51647. break inf_leave;
  51648. }
  51649. have--;
  51650. hold += input[next++] << bits;
  51651. bits += 8; //---//
  51652. }
  51653. if (here_val < 16) {
  51654. //--- DROPBITS(here.bits) ---//
  51655. hold >>>= here_bits;
  51656. bits -= here_bits; //---//
  51657. state.lens[state.have++] = here_val;
  51658. } else {
  51659. if (here_val === 16) {
  51660. //=== NEEDBITS(here.bits + 2);
  51661. n = here_bits + 2;
  51662. while (bits < n) {
  51663. if (have === 0) {
  51664. break inf_leave;
  51665. }
  51666. have--;
  51667. hold += input[next++] << bits;
  51668. bits += 8;
  51669. } //===//
  51670. //--- DROPBITS(here.bits) ---//
  51671. hold >>>= here_bits;
  51672. bits -= here_bits; //---//
  51673. if (state.have === 0) {
  51674. strm.msg = 'invalid bit length repeat';
  51675. state.mode = BAD;
  51676. break;
  51677. }
  51678. len = state.lens[state.have - 1];
  51679. copy = 3 + (hold & 0x03); //BITS(2);
  51680. //--- DROPBITS(2) ---//
  51681. hold >>>= 2;
  51682. bits -= 2; //---//
  51683. } else if (here_val === 17) {
  51684. //=== NEEDBITS(here.bits + 3);
  51685. n = here_bits + 3;
  51686. while (bits < n) {
  51687. if (have === 0) {
  51688. break inf_leave;
  51689. }
  51690. have--;
  51691. hold += input[next++] << bits;
  51692. bits += 8;
  51693. } //===//
  51694. //--- DROPBITS(here.bits) ---//
  51695. hold >>>= here_bits;
  51696. bits -= here_bits; //---//
  51697. len = 0;
  51698. copy = 3 + (hold & 0x07); //BITS(3);
  51699. //--- DROPBITS(3) ---//
  51700. hold >>>= 3;
  51701. bits -= 3; //---//
  51702. } else {
  51703. //=== NEEDBITS(here.bits + 7);
  51704. n = here_bits + 7;
  51705. while (bits < n) {
  51706. if (have === 0) {
  51707. break inf_leave;
  51708. }
  51709. have--;
  51710. hold += input[next++] << bits;
  51711. bits += 8;
  51712. } //===//
  51713. //--- DROPBITS(here.bits) ---//
  51714. hold >>>= here_bits;
  51715. bits -= here_bits; //---//
  51716. len = 0;
  51717. copy = 11 + (hold & 0x7f); //BITS(7);
  51718. //--- DROPBITS(7) ---//
  51719. hold >>>= 7;
  51720. bits -= 7; //---//
  51721. }
  51722. if (state.have + copy > state.nlen + state.ndist) {
  51723. strm.msg = 'invalid bit length repeat';
  51724. state.mode = BAD;
  51725. break;
  51726. }
  51727. while (copy--) {
  51728. state.lens[state.have++] = len;
  51729. }
  51730. }
  51731. }
  51732. /* handle error breaks in while */
  51733. if (state.mode === BAD) {
  51734. break;
  51735. }
  51736. /* check for end-of-block code (better have one) */
  51737. if (state.lens[256] === 0) {
  51738. strm.msg = 'invalid code -- missing end-of-block';
  51739. state.mode = BAD;
  51740. break;
  51741. }
  51742. /* build code tables -- note: do not change the lenbits or distbits
  51743. values here (9 and 6) without reading the comments in inftrees.h
  51744. concerning the ENOUGH constants, which depend on those values */
  51745. state.lenbits = 9;
  51746. opts = {
  51747. bits: state.lenbits
  51748. };
  51749. 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.
  51750. // state.next_index = opts.table_index;
  51751. state.lenbits = opts.bits; // state.lencode = state.next;
  51752. if (ret) {
  51753. strm.msg = 'invalid literal/lengths set';
  51754. state.mode = BAD;
  51755. break;
  51756. }
  51757. state.distbits = 6; //state.distcode.copy(state.codes);
  51758. // Switch to use dynamic table
  51759. state.distcode = state.distdyn;
  51760. opts = {
  51761. bits: state.distbits
  51762. };
  51763. 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.
  51764. // state.next_index = opts.table_index;
  51765. state.distbits = opts.bits; // state.distcode = state.next;
  51766. if (ret) {
  51767. strm.msg = 'invalid distances set';
  51768. state.mode = BAD;
  51769. break;
  51770. } //Tracev((stderr, 'inflate: codes ok\n'));
  51771. state.mode = LEN_;
  51772. if (flush === Z_TREES) {
  51773. break inf_leave;
  51774. }
  51775. /* falls through */
  51776. case LEN_:
  51777. state.mode = LEN;
  51778. /* falls through */
  51779. case LEN:
  51780. if (have >= 6 && left >= 258) {
  51781. //--- RESTORE() ---
  51782. strm.next_out = put;
  51783. strm.avail_out = left;
  51784. strm.next_in = next;
  51785. strm.avail_in = have;
  51786. state.hold = hold;
  51787. state.bits = bits; //---
  51788. inflate_fast(strm, _out); //--- LOAD() ---
  51789. put = strm.next_out;
  51790. output = strm.output;
  51791. left = strm.avail_out;
  51792. next = strm.next_in;
  51793. input = strm.input;
  51794. have = strm.avail_in;
  51795. hold = state.hold;
  51796. bits = state.bits; //---
  51797. if (state.mode === TYPE) {
  51798. state.back = -1;
  51799. }
  51800. break;
  51801. }
  51802. state.back = 0;
  51803. for (;;) {
  51804. here = state.lencode[hold & (1 << state.lenbits) - 1];
  51805. /*BITS(state.lenbits)*/
  51806. here_bits = here >>> 24;
  51807. here_op = here >>> 16 & 0xff;
  51808. here_val = here & 0xffff;
  51809. if (here_bits <= bits) {
  51810. break;
  51811. } //--- PULLBYTE() ---//
  51812. if (have === 0) {
  51813. break inf_leave;
  51814. }
  51815. have--;
  51816. hold += input[next++] << bits;
  51817. bits += 8; //---//
  51818. }
  51819. if (here_op && (here_op & 0xf0) === 0) {
  51820. last_bits = here_bits;
  51821. last_op = here_op;
  51822. last_val = here_val;
  51823. for (;;) {
  51824. here = state.lencode[last_val + ((hold & (1 << last_bits + last_op) - 1) >>
  51825. /*BITS(last.bits + last.op)*/
  51826. last_bits)];
  51827. here_bits = here >>> 24;
  51828. here_op = here >>> 16 & 0xff;
  51829. here_val = here & 0xffff;
  51830. if (last_bits + here_bits <= bits) {
  51831. break;
  51832. } //--- PULLBYTE() ---//
  51833. if (have === 0) {
  51834. break inf_leave;
  51835. }
  51836. have--;
  51837. hold += input[next++] << bits;
  51838. bits += 8; //---//
  51839. } //--- DROPBITS(last.bits) ---//
  51840. hold >>>= last_bits;
  51841. bits -= last_bits; //---//
  51842. state.back += last_bits;
  51843. } //--- DROPBITS(here.bits) ---//
  51844. hold >>>= here_bits;
  51845. bits -= here_bits; //---//
  51846. state.back += here_bits;
  51847. state.length = here_val;
  51848. if (here_op === 0) {
  51849. //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
  51850. // "inflate: literal '%c'\n" :
  51851. // "inflate: literal 0x%02x\n", here.val));
  51852. state.mode = LIT;
  51853. break;
  51854. }
  51855. if (here_op & 32) {
  51856. //Tracevv((stderr, "inflate: end of block\n"));
  51857. state.back = -1;
  51858. state.mode = TYPE;
  51859. break;
  51860. }
  51861. if (here_op & 64) {
  51862. strm.msg = 'invalid literal/length code';
  51863. state.mode = BAD;
  51864. break;
  51865. }
  51866. state.extra = here_op & 15;
  51867. state.mode = LENEXT;
  51868. /* falls through */
  51869. case LENEXT:
  51870. if (state.extra) {
  51871. //=== NEEDBITS(state.extra);
  51872. n = state.extra;
  51873. while (bits < n) {
  51874. if (have === 0) {
  51875. break inf_leave;
  51876. }
  51877. have--;
  51878. hold += input[next++] << bits;
  51879. bits += 8;
  51880. } //===//
  51881. state.length += hold & (1 << state.extra) - 1
  51882. /*BITS(state.extra)*/
  51883. ; //--- DROPBITS(state.extra) ---//
  51884. hold >>>= state.extra;
  51885. bits -= state.extra; //---//
  51886. state.back += state.extra;
  51887. } //Tracevv((stderr, "inflate: length %u\n", state.length));
  51888. state.was = state.length;
  51889. state.mode = DIST;
  51890. /* falls through */
  51891. case DIST:
  51892. for (;;) {
  51893. here = state.distcode[hold & (1 << state.distbits) - 1];
  51894. /*BITS(state.distbits)*/
  51895. here_bits = here >>> 24;
  51896. here_op = here >>> 16 & 0xff;
  51897. here_val = here & 0xffff;
  51898. if (here_bits <= bits) {
  51899. break;
  51900. } //--- PULLBYTE() ---//
  51901. if (have === 0) {
  51902. break inf_leave;
  51903. }
  51904. have--;
  51905. hold += input[next++] << bits;
  51906. bits += 8; //---//
  51907. }
  51908. if ((here_op & 0xf0) === 0) {
  51909. last_bits = here_bits;
  51910. last_op = here_op;
  51911. last_val = here_val;
  51912. for (;;) {
  51913. here = state.distcode[last_val + ((hold & (1 << last_bits + last_op) - 1) >>
  51914. /*BITS(last.bits + last.op)*/
  51915. last_bits)];
  51916. here_bits = here >>> 24;
  51917. here_op = here >>> 16 & 0xff;
  51918. here_val = here & 0xffff;
  51919. if (last_bits + here_bits <= bits) {
  51920. break;
  51921. } //--- PULLBYTE() ---//
  51922. if (have === 0) {
  51923. break inf_leave;
  51924. }
  51925. have--;
  51926. hold += input[next++] << bits;
  51927. bits += 8; //---//
  51928. } //--- DROPBITS(last.bits) ---//
  51929. hold >>>= last_bits;
  51930. bits -= last_bits; //---//
  51931. state.back += last_bits;
  51932. } //--- DROPBITS(here.bits) ---//
  51933. hold >>>= here_bits;
  51934. bits -= here_bits; //---//
  51935. state.back += here_bits;
  51936. if (here_op & 64) {
  51937. strm.msg = 'invalid distance code';
  51938. state.mode = BAD;
  51939. break;
  51940. }
  51941. state.offset = here_val;
  51942. state.extra = here_op & 15;
  51943. state.mode = DISTEXT;
  51944. /* falls through */
  51945. case DISTEXT:
  51946. if (state.extra) {
  51947. //=== NEEDBITS(state.extra);
  51948. n = state.extra;
  51949. while (bits < n) {
  51950. if (have === 0) {
  51951. break inf_leave;
  51952. }
  51953. have--;
  51954. hold += input[next++] << bits;
  51955. bits += 8;
  51956. } //===//
  51957. state.offset += hold & (1 << state.extra) - 1
  51958. /*BITS(state.extra)*/
  51959. ; //--- DROPBITS(state.extra) ---//
  51960. hold >>>= state.extra;
  51961. bits -= state.extra; //---//
  51962. state.back += state.extra;
  51963. } //#ifdef INFLATE_STRICT
  51964. if (state.offset > state.dmax) {
  51965. strm.msg = 'invalid distance too far back';
  51966. state.mode = BAD;
  51967. break;
  51968. } //#endif
  51969. //Tracevv((stderr, "inflate: distance %u\n", state.offset));
  51970. state.mode = MATCH;
  51971. /* falls through */
  51972. case MATCH:
  51973. if (left === 0) {
  51974. break inf_leave;
  51975. }
  51976. copy = _out - left;
  51977. if (state.offset > copy) {
  51978. /* copy from window */
  51979. copy = state.offset - copy;
  51980. if (copy > state.whave) {
  51981. if (state.sane) {
  51982. strm.msg = 'invalid distance too far back';
  51983. state.mode = BAD;
  51984. break;
  51985. } // (!) This block is disabled in zlib defaults,
  51986. // don't enable it for binary compatibility
  51987. //#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
  51988. // Trace((stderr, "inflate.c too far\n"));
  51989. // copy -= state.whave;
  51990. // if (copy > state.length) { copy = state.length; }
  51991. // if (copy > left) { copy = left; }
  51992. // left -= copy;
  51993. // state.length -= copy;
  51994. // do {
  51995. // output[put++] = 0;
  51996. // } while (--copy);
  51997. // if (state.length === 0) { state.mode = LEN; }
  51998. // break;
  51999. //#endif
  52000. }
  52001. if (copy > state.wnext) {
  52002. copy -= state.wnext;
  52003. from = state.wsize - copy;
  52004. } else {
  52005. from = state.wnext - copy;
  52006. }
  52007. if (copy > state.length) {
  52008. copy = state.length;
  52009. }
  52010. from_source = state.window;
  52011. } else {
  52012. /* copy from output */
  52013. from_source = output;
  52014. from = put - state.offset;
  52015. copy = state.length;
  52016. }
  52017. if (copy > left) {
  52018. copy = left;
  52019. }
  52020. left -= copy;
  52021. state.length -= copy;
  52022. do {
  52023. output[put++] = from_source[from++];
  52024. } while (--copy);
  52025. if (state.length === 0) {
  52026. state.mode = LEN;
  52027. }
  52028. break;
  52029. case LIT:
  52030. if (left === 0) {
  52031. break inf_leave;
  52032. }
  52033. output[put++] = state.length;
  52034. left--;
  52035. state.mode = LEN;
  52036. break;
  52037. case CHECK:
  52038. if (state.wrap) {
  52039. //=== NEEDBITS(32);
  52040. while (bits < 32) {
  52041. if (have === 0) {
  52042. break inf_leave;
  52043. }
  52044. have--; // Use '|' instead of '+' to make sure that result is signed
  52045. hold |= input[next++] << bits;
  52046. bits += 8;
  52047. } //===//
  52048. _out -= left;
  52049. strm.total_out += _out;
  52050. state.total += _out;
  52051. if (_out) {
  52052. strm.adler = state.check =
  52053. /*UPDATE(state.check, put - _out, _out);*/
  52054. state.flags ? crc32(state.check, output, _out, put - _out) : adler32(state.check, output, _out, put - _out);
  52055. }
  52056. _out = left; // NB: crc32 stored as signed 32-bit int, zswap32 returns signed too
  52057. if ((state.flags ? hold : zswap32(hold)) !== state.check) {
  52058. strm.msg = 'incorrect data check';
  52059. state.mode = BAD;
  52060. break;
  52061. } //=== INITBITS();
  52062. hold = 0;
  52063. bits = 0; //===//
  52064. //Tracev((stderr, "inflate: check matches trailer\n"));
  52065. }
  52066. state.mode = LENGTH;
  52067. /* falls through */
  52068. case LENGTH:
  52069. if (state.wrap && state.flags) {
  52070. //=== NEEDBITS(32);
  52071. while (bits < 32) {
  52072. if (have === 0) {
  52073. break inf_leave;
  52074. }
  52075. have--;
  52076. hold += input[next++] << bits;
  52077. bits += 8;
  52078. } //===//
  52079. if (hold !== (state.total & 0xffffffff)) {
  52080. strm.msg = 'incorrect length check';
  52081. state.mode = BAD;
  52082. break;
  52083. } //=== INITBITS();
  52084. hold = 0;
  52085. bits = 0; //===//
  52086. //Tracev((stderr, "inflate: length matches trailer\n"));
  52087. }
  52088. state.mode = DONE;
  52089. /* falls through */
  52090. case DONE:
  52091. ret = Z_STREAM_END;
  52092. break inf_leave;
  52093. case BAD:
  52094. ret = Z_DATA_ERROR;
  52095. break inf_leave;
  52096. case MEM:
  52097. return Z_MEM_ERROR;
  52098. case SYNC:
  52099. /* falls through */
  52100. default:
  52101. return Z_STREAM_ERROR;
  52102. }
  52103. } // inf_leave <- here is real place for "goto inf_leave", emulated via "break inf_leave"
  52104. /*
  52105. Return from inflate(), updating the total counts and the check value.
  52106. If there was no progress during the inflate() call, return a buffer
  52107. error. Call updatewindow() to create and/or update the window state.
  52108. Note: a memory error from inflate() is non-recoverable.
  52109. */
  52110. //--- RESTORE() ---
  52111. strm.next_out = put;
  52112. strm.avail_out = left;
  52113. strm.next_in = next;
  52114. strm.avail_in = have;
  52115. state.hold = hold;
  52116. state.bits = bits; //---
  52117. if (state.wsize || _out !== strm.avail_out && state.mode < BAD && (state.mode < CHECK || flush !== Z_FINISH)) {
  52118. if (updatewindow(strm, strm.output, strm.next_out, _out - strm.avail_out)) {
  52119. state.mode = MEM;
  52120. return Z_MEM_ERROR;
  52121. }
  52122. }
  52123. _in -= strm.avail_in;
  52124. _out -= strm.avail_out;
  52125. strm.total_in += _in;
  52126. strm.total_out += _out;
  52127. state.total += _out;
  52128. if (state.wrap && _out) {
  52129. strm.adler = state.check =
  52130. /*UPDATE(state.check, strm.next_out - _out, _out);*/
  52131. state.flags ? crc32(state.check, output, _out, strm.next_out - _out) : adler32(state.check, output, _out, strm.next_out - _out);
  52132. }
  52133. strm.data_type = state.bits + (state.last ? 64 : 0) + (state.mode === TYPE ? 128 : 0) + (state.mode === LEN_ || state.mode === COPY_ ? 256 : 0);
  52134. if ((_in === 0 && _out === 0 || flush === Z_FINISH) && ret === Z_OK) {
  52135. ret = Z_BUF_ERROR;
  52136. }
  52137. return ret;
  52138. }
  52139. function inflateEnd(strm) {
  52140. if (!strm || !strm.state
  52141. /*|| strm->zfree == (free_func)0*/
  52142. ) {
  52143. return Z_STREAM_ERROR;
  52144. }
  52145. var state = strm.state;
  52146. if (state.window) {
  52147. state.window = null;
  52148. }
  52149. strm.state = null;
  52150. return Z_OK;
  52151. }
  52152. function inflateGetHeader(strm, head) {
  52153. var state;
  52154. /* check state */
  52155. if (!strm || !strm.state) {
  52156. return Z_STREAM_ERROR;
  52157. }
  52158. state = strm.state;
  52159. if ((state.wrap & 2) === 0) {
  52160. return Z_STREAM_ERROR;
  52161. }
  52162. /* save header structure */
  52163. state.head = head;
  52164. head.done = false;
  52165. return Z_OK;
  52166. }
  52167. function inflateSetDictionary(strm, dictionary) {
  52168. var dictLength = dictionary.length;
  52169. var state;
  52170. var dictid;
  52171. var ret;
  52172. /* check state */
  52173. if (!strm
  52174. /* == Z_NULL */
  52175. || !strm.state
  52176. /* == Z_NULL */
  52177. ) {
  52178. return Z_STREAM_ERROR;
  52179. }
  52180. state = strm.state;
  52181. if (state.wrap !== 0 && state.mode !== DICT) {
  52182. return Z_STREAM_ERROR;
  52183. }
  52184. /* check for correct dictionary identifier */
  52185. if (state.mode === DICT) {
  52186. dictid = 1;
  52187. /* adler32(0, null, 0)*/
  52188. /* dictid = adler32(dictid, dictionary, dictLength); */
  52189. dictid = adler32(dictid, dictionary, dictLength, 0);
  52190. if (dictid !== state.check) {
  52191. return Z_DATA_ERROR;
  52192. }
  52193. }
  52194. /* copy dictionary to window using updatewindow(), which will amend the
  52195. existing dictionary if appropriate */
  52196. ret = updatewindow(strm, dictionary, dictLength, dictLength);
  52197. if (ret) {
  52198. state.mode = MEM;
  52199. return Z_MEM_ERROR;
  52200. }
  52201. state.havedict = 1; // Tracev((stderr, "inflate: dictionary set\n"));
  52202. return Z_OK;
  52203. }
  52204. exports.inflateReset = inflateReset;
  52205. exports.inflateReset2 = inflateReset2;
  52206. exports.inflateResetKeep = inflateResetKeep;
  52207. exports.inflateInit = inflateInit;
  52208. exports.inflateInit2 = inflateInit2;
  52209. exports.inflate = inflate;
  52210. exports.inflateEnd = inflateEnd;
  52211. exports.inflateGetHeader = inflateGetHeader;
  52212. exports.inflateSetDictionary = inflateSetDictionary;
  52213. exports.inflateInfo = 'pako inflate (from Nodeca project)';
  52214. /* Not implemented
  52215. exports.inflateCopy = inflateCopy;
  52216. exports.inflateGetDictionary = inflateGetDictionary;
  52217. exports.inflateMark = inflateMark;
  52218. exports.inflatePrime = inflatePrime;
  52219. exports.inflateSync = inflateSync;
  52220. exports.inflateSyncPoint = inflateSyncPoint;
  52221. exports.inflateUndermine = inflateUndermine;
  52222. */
  52223. },{"../utils/common":333,"./adler32":335,"./crc32":337,"./inffast":340,"./inftrees":342}],342:[function(require,module,exports){
  52224. 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  52225. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  52226. //
  52227. // This software is provided 'as-is', without any express or implied
  52228. // warranty. In no event will the authors be held liable for any damages
  52229. // arising from the use of this software.
  52230. //
  52231. // Permission is granted to anyone to use this software for any purpose,
  52232. // including commercial applications, and to alter it and redistribute it
  52233. // freely, subject to the following restrictions:
  52234. //
  52235. // 1. The origin of this software must not be misrepresented; you must not
  52236. // claim that you wrote the original software. If you use this software
  52237. // in a product, an acknowledgment in the product documentation would be
  52238. // appreciated but is not required.
  52239. // 2. Altered source versions must be plainly marked as such, and must not be
  52240. // misrepresented as being the original software.
  52241. // 3. This notice may not be removed or altered from any source distribution.
  52242. var utils = require('../utils/common');
  52243. var MAXBITS = 15;
  52244. var ENOUGH_LENS = 852;
  52245. var ENOUGH_DISTS = 592; //var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);
  52246. var CODES = 0;
  52247. var LENS = 1;
  52248. var DISTS = 2;
  52249. var lbase = [
  52250. /* Length codes 257..285 base */
  52251. 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];
  52252. var lext = [
  52253. /* Length codes 257..285 extra */
  52254. 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];
  52255. var dbase = [
  52256. /* Distance codes 0..29 base */
  52257. 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];
  52258. var dext = [
  52259. /* Distance codes 0..29 extra */
  52260. 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];
  52261. module.exports = function inflate_table(type, lens, lens_index, codes, table, table_index, work, opts) {
  52262. var bits = opts.bits; //here = opts.here; /* table entry for duplication */
  52263. var len = 0;
  52264. /* a code's length in bits */
  52265. var sym = 0;
  52266. /* index of code symbols */
  52267. var min = 0,
  52268. max = 0;
  52269. /* minimum and maximum code lengths */
  52270. var root = 0;
  52271. /* number of index bits for root table */
  52272. var curr = 0;
  52273. /* number of index bits for current table */
  52274. var drop = 0;
  52275. /* code bits to drop for sub-table */
  52276. var left = 0;
  52277. /* number of prefix codes available */
  52278. var used = 0;
  52279. /* code entries in table used */
  52280. var huff = 0;
  52281. /* Huffman code */
  52282. var incr;
  52283. /* for incrementing code, index */
  52284. var fill;
  52285. /* index for replicating entries */
  52286. var low;
  52287. /* low bits for current root entry */
  52288. var mask;
  52289. /* mask for low root bits */
  52290. var next;
  52291. /* next available space in table */
  52292. var base = null;
  52293. /* base value table to use */
  52294. var base_index = 0; // var shoextra; /* extra bits table to use */
  52295. var end;
  52296. /* use base and extra for symbol > end */
  52297. var count = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1]; /* number of codes of each length */
  52298. var offs = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1]; /* offsets in table for each length */
  52299. var extra = null;
  52300. var extra_index = 0;
  52301. var here_bits, here_op, here_val;
  52302. /*
  52303. Process a set of code lengths to create a canonical Huffman code. The
  52304. code lengths are lens[0..codes-1]. Each length corresponds to the
  52305. symbols 0..codes-1. The Huffman code is generated by first sorting the
  52306. symbols by length from short to long, and retaining the symbol order
  52307. for codes with equal lengths. Then the code starts with all zero bits
  52308. for the first code of the shortest length, and the codes are integer
  52309. increments for the same length, and zeros are appended as the length
  52310. increases. For the deflate format, these bits are stored backwards
  52311. from their more natural integer increment ordering, and so when the
  52312. decoding tables are built in the large loop below, the integer codes
  52313. are incremented backwards.
  52314. This routine assumes, but does not check, that all of the entries in
  52315. lens[] are in the range 0..MAXBITS. The caller must assure this.
  52316. 1..MAXBITS is interpreted as that code length. zero means that that
  52317. symbol does not occur in this code.
  52318. The codes are sorted by computing a count of codes for each length,
  52319. creating from that a table of starting indices for each length in the
  52320. sorted table, and then entering the symbols in order in the sorted
  52321. table. The sorted table is work[], with that space being provided by
  52322. the caller.
  52323. The length counts are used for other purposes as well, i.e. finding
  52324. the minimum and maximum length codes, determining if there are any
  52325. codes at all, checking for a valid set of lengths, and looking ahead
  52326. at length counts to determine sub-table sizes when building the
  52327. decoding tables.
  52328. */
  52329. /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
  52330. for (len = 0; len <= MAXBITS; len++) {
  52331. count[len] = 0;
  52332. }
  52333. for (sym = 0; sym < codes; sym++) {
  52334. count[lens[lens_index + sym]]++;
  52335. }
  52336. /* bound code lengths, force root to be within code lengths */
  52337. root = bits;
  52338. for (max = MAXBITS; max >= 1; max--) {
  52339. if (count[max] !== 0) {
  52340. break;
  52341. }
  52342. }
  52343. if (root > max) {
  52344. root = max;
  52345. }
  52346. if (max === 0) {
  52347. /* no symbols to code at all */
  52348. //table.op[opts.table_index] = 64; //here.op = (var char)64; /* invalid code marker */
  52349. //table.bits[opts.table_index] = 1; //here.bits = (var char)1;
  52350. //table.val[opts.table_index++] = 0; //here.val = (var short)0;
  52351. table[table_index++] = 1 << 24 | 64 << 16 | 0; //table.op[opts.table_index] = 64;
  52352. //table.bits[opts.table_index] = 1;
  52353. //table.val[opts.table_index++] = 0;
  52354. table[table_index++] = 1 << 24 | 64 << 16 | 0;
  52355. opts.bits = 1;
  52356. return 0;
  52357. /* no symbols, but wait for decoding to report error */
  52358. }
  52359. for (min = 1; min < max; min++) {
  52360. if (count[min] !== 0) {
  52361. break;
  52362. }
  52363. }
  52364. if (root < min) {
  52365. root = min;
  52366. }
  52367. /* check for an over-subscribed or incomplete set of lengths */
  52368. left = 1;
  52369. for (len = 1; len <= MAXBITS; len++) {
  52370. left <<= 1;
  52371. left -= count[len];
  52372. if (left < 0) {
  52373. return -1;
  52374. }
  52375. /* over-subscribed */
  52376. }
  52377. if (left > 0 && (type === CODES || max !== 1)) {
  52378. return -1;
  52379. /* incomplete set */
  52380. }
  52381. /* generate offsets into symbol table for each length for sorting */
  52382. offs[1] = 0;
  52383. for (len = 1; len < MAXBITS; len++) {
  52384. offs[len + 1] = offs[len] + count[len];
  52385. }
  52386. /* sort symbols by length, by symbol order within each length */
  52387. for (sym = 0; sym < codes; sym++) {
  52388. if (lens[lens_index + sym] !== 0) {
  52389. work[offs[lens[lens_index + sym]]++] = sym;
  52390. }
  52391. }
  52392. /*
  52393. Create and fill in decoding tables. In this loop, the table being
  52394. filled is at next and has curr index bits. The code being used is huff
  52395. with length len. That code is converted to an index by dropping drop
  52396. bits off of the bottom. For codes where len is less than drop + curr,
  52397. those top drop + curr - len bits are incremented through all values to
  52398. fill the table with replicated entries.
  52399. root is the number of index bits for the root table. When len exceeds
  52400. root, sub-tables are created pointed to by the root entry with an index
  52401. of the low root bits of huff. This is saved in low to check for when a
  52402. new sub-table should be started. drop is zero when the root table is
  52403. being filled, and drop is root when sub-tables are being filled.
  52404. When a new sub-table is needed, it is necessary to look ahead in the
  52405. code lengths to determine what size sub-table is needed. The length
  52406. counts are used for this, and so count[] is decremented as codes are
  52407. entered in the tables.
  52408. used keeps track of how many table entries have been allocated from the
  52409. provided *table space. It is checked for LENS and DIST tables against
  52410. the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
  52411. the initial root table size constants. See the comments in inftrees.h
  52412. for more information.
  52413. sym increments through all symbols, and the loop terminates when
  52414. all codes of length max, i.e. all codes, have been processed. This
  52415. routine permits incomplete codes, so another loop after this one fills
  52416. in the rest of the decoding tables with invalid code markers.
  52417. */
  52418. /* set up for code type */
  52419. // poor man optimization - use if-else instead of switch,
  52420. // to avoid deopts in old v8
  52421. if (type === CODES) {
  52422. base = extra = work;
  52423. /* dummy value--not used */
  52424. end = 19;
  52425. } else if (type === LENS) {
  52426. base = lbase;
  52427. base_index -= 257;
  52428. extra = lext;
  52429. extra_index -= 257;
  52430. end = 256;
  52431. } else {
  52432. /* DISTS */
  52433. base = dbase;
  52434. extra = dext;
  52435. end = -1;
  52436. }
  52437. /* initialize opts for loop */
  52438. huff = 0;
  52439. /* starting code */
  52440. sym = 0;
  52441. /* starting code symbol */
  52442. len = min;
  52443. /* starting code length */
  52444. next = table_index;
  52445. /* current table to fill in */
  52446. curr = root;
  52447. /* current table index bits */
  52448. drop = 0;
  52449. /* current bits to drop from code for index */
  52450. low = -1;
  52451. /* trigger new sub-table when len > root */
  52452. used = 1 << root;
  52453. /* use root table entries */
  52454. mask = used - 1;
  52455. /* mask for comparing low */
  52456. /* check available table space */
  52457. if (type === LENS && used > ENOUGH_LENS || type === DISTS && used > ENOUGH_DISTS) {
  52458. return 1;
  52459. }
  52460. /* process all codes and make table entries */
  52461. for (;;) {
  52462. /* create table entry */
  52463. here_bits = len - drop;
  52464. if (work[sym] < end) {
  52465. here_op = 0;
  52466. here_val = work[sym];
  52467. } else if (work[sym] > end) {
  52468. here_op = extra[extra_index + work[sym]];
  52469. here_val = base[base_index + work[sym]];
  52470. } else {
  52471. here_op = 32 + 64;
  52472. /* end of block */
  52473. here_val = 0;
  52474. }
  52475. /* replicate for those indices with low len bits equal to huff */
  52476. incr = 1 << len - drop;
  52477. fill = 1 << curr;
  52478. min = fill;
  52479. /* save offset to next table */
  52480. do {
  52481. fill -= incr;
  52482. table[next + (huff >> drop) + fill] = here_bits << 24 | here_op << 16 | here_val | 0;
  52483. } while (fill !== 0);
  52484. /* backwards increment the len-bit code huff */
  52485. incr = 1 << len - 1;
  52486. while (huff & incr) {
  52487. incr >>= 1;
  52488. }
  52489. if (incr !== 0) {
  52490. huff &= incr - 1;
  52491. huff += incr;
  52492. } else {
  52493. huff = 0;
  52494. }
  52495. /* go to next symbol, update count, len */
  52496. sym++;
  52497. if (--count[len] === 0) {
  52498. if (len === max) {
  52499. break;
  52500. }
  52501. len = lens[lens_index + work[sym]];
  52502. }
  52503. /* create new sub-table if needed */
  52504. if (len > root && (huff & mask) !== low) {
  52505. /* if first time, transition to sub-tables */
  52506. if (drop === 0) {
  52507. drop = root;
  52508. }
  52509. /* increment past last table */
  52510. next += min;
  52511. /* here min is 1 << curr */
  52512. /* determine length of next table */
  52513. curr = len - drop;
  52514. left = 1 << curr;
  52515. while (curr + drop < max) {
  52516. left -= count[curr + drop];
  52517. if (left <= 0) {
  52518. break;
  52519. }
  52520. curr++;
  52521. left <<= 1;
  52522. }
  52523. /* check for enough space */
  52524. used += 1 << curr;
  52525. if (type === LENS && used > ENOUGH_LENS || type === DISTS && used > ENOUGH_DISTS) {
  52526. return 1;
  52527. }
  52528. /* point entry in root table to sub-table */
  52529. low = huff & mask;
  52530. /*table.op[low] = curr;
  52531. table.bits[low] = root;
  52532. table.val[low] = next - opts.table_index;*/
  52533. table[low] = root << 24 | curr << 16 | next - table_index | 0;
  52534. }
  52535. }
  52536. /* fill in remaining table entry if code is incomplete (guaranteed to have
  52537. at most one remaining entry, since if the code is incomplete, the
  52538. maximum code length that was allowed to get this far is one bit) */
  52539. if (huff !== 0) {
  52540. //table.op[next + huff] = 64; /* invalid code marker */
  52541. //table.bits[next + huff] = len - drop;
  52542. //table.val[next + huff] = 0;
  52543. table[next + huff] = len - drop << 24 | 64 << 16 | 0;
  52544. }
  52545. /* set return parameters */
  52546. //opts.table_index += used;
  52547. opts.bits = root;
  52548. return 0;
  52549. };
  52550. },{"../utils/common":333}],343:[function(require,module,exports){
  52551. 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  52552. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  52553. //
  52554. // This software is provided 'as-is', without any express or implied
  52555. // warranty. In no event will the authors be held liable for any damages
  52556. // arising from the use of this software.
  52557. //
  52558. // Permission is granted to anyone to use this software for any purpose,
  52559. // including commercial applications, and to alter it and redistribute it
  52560. // freely, subject to the following restrictions:
  52561. //
  52562. // 1. The origin of this software must not be misrepresented; you must not
  52563. // claim that you wrote the original software. If you use this software
  52564. // in a product, an acknowledgment in the product documentation would be
  52565. // appreciated but is not required.
  52566. // 2. Altered source versions must be plainly marked as such, and must not be
  52567. // misrepresented as being the original software.
  52568. // 3. This notice may not be removed or altered from any source distribution.
  52569. module.exports = {
  52570. 2: 'need dictionary',
  52571. /* Z_NEED_DICT 2 */
  52572. 1: 'stream end',
  52573. /* Z_STREAM_END 1 */
  52574. 0: '',
  52575. /* Z_OK 0 */
  52576. '-1': 'file error',
  52577. /* Z_ERRNO (-1) */
  52578. '-2': 'stream error',
  52579. /* Z_STREAM_ERROR (-2) */
  52580. '-3': 'data error',
  52581. /* Z_DATA_ERROR (-3) */
  52582. '-4': 'insufficient memory',
  52583. /* Z_MEM_ERROR (-4) */
  52584. '-5': 'buffer error',
  52585. /* Z_BUF_ERROR (-5) */
  52586. '-6': 'incompatible version'
  52587. /* Z_VERSION_ERROR (-6) */
  52588. };
  52589. },{}],344:[function(require,module,exports){
  52590. 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  52591. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  52592. //
  52593. // This software is provided 'as-is', without any express or implied
  52594. // warranty. In no event will the authors be held liable for any damages
  52595. // arising from the use of this software.
  52596. //
  52597. // Permission is granted to anyone to use this software for any purpose,
  52598. // including commercial applications, and to alter it and redistribute it
  52599. // freely, subject to the following restrictions:
  52600. //
  52601. // 1. The origin of this software must not be misrepresented; you must not
  52602. // claim that you wrote the original software. If you use this software
  52603. // in a product, an acknowledgment in the product documentation would be
  52604. // appreciated but is not required.
  52605. // 2. Altered source versions must be plainly marked as such, and must not be
  52606. // misrepresented as being the original software.
  52607. // 3. This notice may not be removed or altered from any source distribution.
  52608. /* eslint-disable space-unary-ops */
  52609. var utils = require('../utils/common');
  52610. /* Public constants ==========================================================*/
  52611. /* ===========================================================================*/
  52612. //var Z_FILTERED = 1;
  52613. //var Z_HUFFMAN_ONLY = 2;
  52614. //var Z_RLE = 3;
  52615. var Z_FIXED = 4; //var Z_DEFAULT_STRATEGY = 0;
  52616. /* Possible values of the data_type field (though see inflate()) */
  52617. var Z_BINARY = 0;
  52618. var Z_TEXT = 1; //var Z_ASCII = 1; // = Z_TEXT
  52619. var Z_UNKNOWN = 2;
  52620. /*============================================================================*/
  52621. function zero(buf) {
  52622. var len = buf.length;
  52623. while (--len >= 0) {
  52624. buf[len] = 0;
  52625. }
  52626. } // From zutil.h
  52627. var STORED_BLOCK = 0;
  52628. var STATIC_TREES = 1;
  52629. var DYN_TREES = 2;
  52630. /* The three kinds of block type */
  52631. var MIN_MATCH = 3;
  52632. var MAX_MATCH = 258;
  52633. /* The minimum and maximum match lengths */
  52634. // From deflate.h
  52635. /* ===========================================================================
  52636. * Internal compression state.
  52637. */
  52638. var LENGTH_CODES = 29;
  52639. /* number of length codes, not counting the special END_BLOCK code */
  52640. var LITERALS = 256;
  52641. /* number of literal bytes 0..255 */
  52642. var L_CODES = LITERALS + 1 + LENGTH_CODES;
  52643. /* number of Literal or Length codes, including the END_BLOCK code */
  52644. var D_CODES = 30;
  52645. /* number of distance codes */
  52646. var BL_CODES = 19;
  52647. /* number of codes used to transfer the bit lengths */
  52648. var HEAP_SIZE = 2 * L_CODES + 1;
  52649. /* maximum heap size */
  52650. var MAX_BITS = 15;
  52651. /* All codes must not exceed MAX_BITS bits */
  52652. var Buf_size = 16;
  52653. /* size of bit buffer in bi_buf */
  52654. /* ===========================================================================
  52655. * Constants
  52656. */
  52657. var MAX_BL_BITS = 7;
  52658. /* Bit length codes must not exceed MAX_BL_BITS bits */
  52659. var END_BLOCK = 256;
  52660. /* end of block literal code */
  52661. var REP_3_6 = 16;
  52662. /* repeat previous bit length 3-6 times (2 bits of repeat count) */
  52663. var REPZ_3_10 = 17;
  52664. /* repeat a zero length 3-10 times (3 bits of repeat count) */
  52665. var REPZ_11_138 = 18;
  52666. /* repeat a zero length 11-138 times (7 bits of repeat count) */
  52667. /* eslint-disable comma-spacing,array-bracket-spacing */
  52668. var extra_lbits =
  52669. /* extra bits for each length code */
  52670. [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];
  52671. var extra_dbits =
  52672. /* extra bits for each distance code */
  52673. [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];
  52674. var extra_blbits =
  52675. /* extra bits for each bit length code */
  52676. [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7];
  52677. var bl_order = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
  52678. /* eslint-enable comma-spacing,array-bracket-spacing */
  52679. /* The lengths of the bit length codes are sent in order of decreasing
  52680. * probability, to avoid transmitting the lengths for unused bit length codes.
  52681. */
  52682. /* ===========================================================================
  52683. * Local data. These are initialized only once.
  52684. */
  52685. // We pre-fill arrays with 0 to avoid uninitialized gaps
  52686. var DIST_CODE_LEN = 512;
  52687. /* see definition of array dist_code below */
  52688. // !!!! Use flat array instead of structure, Freq = i*2, Len = i*2+1
  52689. var static_ltree = new Array((L_CODES + 2) * 2);
  52690. zero(static_ltree);
  52691. /* The static literal tree. Since the bit lengths are imposed, there is no
  52692. * need for the L_CODES extra codes used during heap construction. However
  52693. * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
  52694. * below).
  52695. */
  52696. var static_dtree = new Array(D_CODES * 2);
  52697. zero(static_dtree);
  52698. /* The static distance tree. (Actually a trivial tree since all codes use
  52699. * 5 bits.)
  52700. */
  52701. var _dist_code = new Array(DIST_CODE_LEN);
  52702. zero(_dist_code);
  52703. /* Distance codes. The first 256 values correspond to the distances
  52704. * 3 .. 258, the last 256 values correspond to the top 8 bits of
  52705. * the 15 bit distances.
  52706. */
  52707. var _length_code = new Array(MAX_MATCH - MIN_MATCH + 1);
  52708. zero(_length_code);
  52709. /* length code for each normalized match length (0 == MIN_MATCH) */
  52710. var base_length = new Array(LENGTH_CODES);
  52711. zero(base_length);
  52712. /* First normalized length for each code (0 = MIN_MATCH) */
  52713. var base_dist = new Array(D_CODES);
  52714. zero(base_dist);
  52715. /* First normalized distance for each code (0 = distance of 1) */
  52716. function StaticTreeDesc(static_tree, extra_bits, extra_base, elems, max_length) {
  52717. this.static_tree = static_tree;
  52718. /* static tree or NULL */
  52719. this.extra_bits = extra_bits;
  52720. /* extra bits for each code or NULL */
  52721. this.extra_base = extra_base;
  52722. /* base index for extra_bits */
  52723. this.elems = elems;
  52724. /* max number of elements in the tree */
  52725. this.max_length = max_length;
  52726. /* max bit length for the codes */
  52727. // show if `static_tree` has data or dummy - needed for monomorphic objects
  52728. this.has_stree = static_tree && static_tree.length;
  52729. }
  52730. var static_l_desc;
  52731. var static_d_desc;
  52732. var static_bl_desc;
  52733. function TreeDesc(dyn_tree, stat_desc) {
  52734. this.dyn_tree = dyn_tree;
  52735. /* the dynamic tree */
  52736. this.max_code = 0;
  52737. /* largest code with non zero frequency */
  52738. this.stat_desc = stat_desc;
  52739. /* the corresponding static tree */
  52740. }
  52741. function d_code(dist) {
  52742. return dist < 256 ? _dist_code[dist] : _dist_code[256 + (dist >>> 7)];
  52743. }
  52744. /* ===========================================================================
  52745. * Output a short LSB first on the stream.
  52746. * IN assertion: there is enough room in pendingBuf.
  52747. */
  52748. function put_short(s, w) {
  52749. // put_byte(s, (uch)((w) & 0xff));
  52750. // put_byte(s, (uch)((ush)(w) >> 8));
  52751. s.pending_buf[s.pending++] = w & 0xff;
  52752. s.pending_buf[s.pending++] = w >>> 8 & 0xff;
  52753. }
  52754. /* ===========================================================================
  52755. * Send a value on a given number of bits.
  52756. * IN assertion: length <= 16 and value fits in length bits.
  52757. */
  52758. function send_bits(s, value, length) {
  52759. if (s.bi_valid > Buf_size - length) {
  52760. s.bi_buf |= value << s.bi_valid & 0xffff;
  52761. put_short(s, s.bi_buf);
  52762. s.bi_buf = value >> Buf_size - s.bi_valid;
  52763. s.bi_valid += length - Buf_size;
  52764. } else {
  52765. s.bi_buf |= value << s.bi_valid & 0xffff;
  52766. s.bi_valid += length;
  52767. }
  52768. }
  52769. function send_code(s, c, tree) {
  52770. send_bits(s, tree[c * 2]
  52771. /*.Code*/
  52772. , tree[c * 2 + 1]
  52773. /*.Len*/
  52774. );
  52775. }
  52776. /* ===========================================================================
  52777. * Reverse the first len bits of a code, using straightforward code (a faster
  52778. * method would use a table)
  52779. * IN assertion: 1 <= len <= 15
  52780. */
  52781. function bi_reverse(code, len) {
  52782. var res = 0;
  52783. do {
  52784. res |= code & 1;
  52785. code >>>= 1;
  52786. res <<= 1;
  52787. } while (--len > 0);
  52788. return res >>> 1;
  52789. }
  52790. /* ===========================================================================
  52791. * Flush the bit buffer, keeping at most 7 bits in it.
  52792. */
  52793. function bi_flush(s) {
  52794. if (s.bi_valid === 16) {
  52795. put_short(s, s.bi_buf);
  52796. s.bi_buf = 0;
  52797. s.bi_valid = 0;
  52798. } else if (s.bi_valid >= 8) {
  52799. s.pending_buf[s.pending++] = s.bi_buf & 0xff;
  52800. s.bi_buf >>= 8;
  52801. s.bi_valid -= 8;
  52802. }
  52803. }
  52804. /* ===========================================================================
  52805. * Compute the optimal bit lengths for a tree and update the total bit length
  52806. * for the current block.
  52807. * IN assertion: the fields freq and dad are set, heap[heap_max] and
  52808. * above are the tree nodes sorted by increasing frequency.
  52809. * OUT assertions: the field len is set to the optimal bit length, the
  52810. * array bl_count contains the frequencies for each bit length.
  52811. * The length opt_len is updated; static_len is also updated if stree is
  52812. * not null.
  52813. */
  52814. function gen_bitlen(s, desc) // deflate_state *s;
  52815. // tree_desc *desc; /* the tree descriptor */
  52816. {
  52817. var tree = desc.dyn_tree;
  52818. var max_code = desc.max_code;
  52819. var stree = desc.stat_desc.static_tree;
  52820. var has_stree = desc.stat_desc.has_stree;
  52821. var extra = desc.stat_desc.extra_bits;
  52822. var base = desc.stat_desc.extra_base;
  52823. var max_length = desc.stat_desc.max_length;
  52824. var h;
  52825. /* heap index */
  52826. var n, m;
  52827. /* iterate over the tree elements */
  52828. var bits;
  52829. /* bit length */
  52830. var xbits;
  52831. /* extra bits */
  52832. var f;
  52833. /* frequency */
  52834. var overflow = 0;
  52835. /* number of elements with bit length too large */
  52836. for (bits = 0; bits <= MAX_BITS; bits++) {
  52837. s.bl_count[bits] = 0;
  52838. }
  52839. /* In a first pass, compute the optimal bit lengths (which may
  52840. * overflow in the case of the bit length tree).
  52841. */
  52842. tree[s.heap[s.heap_max] * 2 + 1]
  52843. /*.Len*/
  52844. = 0;
  52845. /* root of the heap */
  52846. for (h = s.heap_max + 1; h < HEAP_SIZE; h++) {
  52847. n = s.heap[h];
  52848. bits = tree[tree[n * 2 + 1]
  52849. /*.Dad*/
  52850. * 2 + 1]
  52851. /*.Len*/
  52852. + 1;
  52853. if (bits > max_length) {
  52854. bits = max_length;
  52855. overflow++;
  52856. }
  52857. tree[n * 2 + 1]
  52858. /*.Len*/
  52859. = bits;
  52860. /* We overwrite tree[n].Dad which is no longer needed */
  52861. if (n > max_code) {
  52862. continue;
  52863. }
  52864. /* not a leaf node */
  52865. s.bl_count[bits]++;
  52866. xbits = 0;
  52867. if (n >= base) {
  52868. xbits = extra[n - base];
  52869. }
  52870. f = tree[n * 2]
  52871. /*.Freq*/
  52872. ;
  52873. s.opt_len += f * (bits + xbits);
  52874. if (has_stree) {
  52875. s.static_len += f * (stree[n * 2 + 1]
  52876. /*.Len*/
  52877. + xbits);
  52878. }
  52879. }
  52880. if (overflow === 0) {
  52881. return;
  52882. } // Trace((stderr,"\nbit length overflow\n"));
  52883. /* This happens for example on obj2 and pic of the Calgary corpus */
  52884. /* Find the first bit length which could increase: */
  52885. do {
  52886. bits = max_length - 1;
  52887. while (s.bl_count[bits] === 0) {
  52888. bits--;
  52889. }
  52890. s.bl_count[bits]--;
  52891. /* move one leaf down the tree */
  52892. s.bl_count[bits + 1] += 2;
  52893. /* move one overflow item as its brother */
  52894. s.bl_count[max_length]--;
  52895. /* The brother of the overflow item also moves one step up,
  52896. * but this does not affect bl_count[max_length]
  52897. */
  52898. overflow -= 2;
  52899. } while (overflow > 0);
  52900. /* Now recompute all bit lengths, scanning in increasing frequency.
  52901. * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
  52902. * lengths instead of fixing only the wrong ones. This idea is taken
  52903. * from 'ar' written by Haruhiko Okumura.)
  52904. */
  52905. for (bits = max_length; bits !== 0; bits--) {
  52906. n = s.bl_count[bits];
  52907. while (n !== 0) {
  52908. m = s.heap[--h];
  52909. if (m > max_code) {
  52910. continue;
  52911. }
  52912. if (tree[m * 2 + 1]
  52913. /*.Len*/
  52914. !== bits) {
  52915. // Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  52916. s.opt_len += (bits - tree[m * 2 + 1]
  52917. /*.Len*/
  52918. ) * tree[m * 2]
  52919. /*.Freq*/
  52920. ;
  52921. tree[m * 2 + 1]
  52922. /*.Len*/
  52923. = bits;
  52924. }
  52925. n--;
  52926. }
  52927. }
  52928. }
  52929. /* ===========================================================================
  52930. * Generate the codes for a given tree and bit counts (which need not be
  52931. * optimal).
  52932. * IN assertion: the array bl_count contains the bit length statistics for
  52933. * the given tree and the field len is set for all tree elements.
  52934. * OUT assertion: the field code is set for all tree elements of non
  52935. * zero code length.
  52936. */
  52937. function gen_codes(tree, max_code, bl_count) // ct_data *tree; /* the tree to decorate */
  52938. // int max_code; /* largest code with non zero frequency */
  52939. // ushf *bl_count; /* number of codes at each bit length */
  52940. {
  52941. var next_code = new Array(MAX_BITS + 1);
  52942. /* next code value for each bit length */
  52943. var code = 0;
  52944. /* running code value */
  52945. var bits;
  52946. /* bit index */
  52947. var n;
  52948. /* code index */
  52949. /* The distribution counts are first used to generate the code values
  52950. * without bit reversal.
  52951. */
  52952. for (bits = 1; bits <= MAX_BITS; bits++) {
  52953. next_code[bits] = code = code + bl_count[bits - 1] << 1;
  52954. }
  52955. /* Check that the bit counts in bl_count are consistent. The last code
  52956. * must be all ones.
  52957. */
  52958. //Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  52959. // "inconsistent bit counts");
  52960. //Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  52961. for (n = 0; n <= max_code; n++) {
  52962. var len = tree[n * 2 + 1]
  52963. /*.Len*/
  52964. ;
  52965. if (len === 0) {
  52966. continue;
  52967. }
  52968. /* Now reverse the bits */
  52969. tree[n * 2]
  52970. /*.Code*/
  52971. = bi_reverse(next_code[len]++, len); //Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  52972. // n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  52973. }
  52974. }
  52975. /* ===========================================================================
  52976. * Initialize the various 'constant' tables.
  52977. */
  52978. function tr_static_init() {
  52979. var n;
  52980. /* iterates over tree elements */
  52981. var bits;
  52982. /* bit counter */
  52983. var length;
  52984. /* length value */
  52985. var code;
  52986. /* code value */
  52987. var dist;
  52988. /* distance index */
  52989. var bl_count = new Array(MAX_BITS + 1);
  52990. /* number of codes at each bit length for an optimal tree */
  52991. // do check in _tr_init()
  52992. //if (static_init_done) return;
  52993. /* For some embedded targets, global variables are not initialized: */
  52994. /*#ifdef NO_INIT_GLOBAL_POINTERS
  52995. static_l_desc.static_tree = static_ltree;
  52996. static_l_desc.extra_bits = extra_lbits;
  52997. static_d_desc.static_tree = static_dtree;
  52998. static_d_desc.extra_bits = extra_dbits;
  52999. static_bl_desc.extra_bits = extra_blbits;
  53000. #endif*/
  53001. /* Initialize the mapping length (0..255) -> length code (0..28) */
  53002. length = 0;
  53003. for (code = 0; code < LENGTH_CODES - 1; code++) {
  53004. base_length[code] = length;
  53005. for (n = 0; n < 1 << extra_lbits[code]; n++) {
  53006. _length_code[length++] = code;
  53007. }
  53008. } //Assert (length == 256, "tr_static_init: length != 256");
  53009. /* Note that the length 255 (match length 258) can be represented
  53010. * in two different ways: code 284 + 5 bits or code 285, so we
  53011. * overwrite length_code[255] to use the best encoding:
  53012. */
  53013. _length_code[length - 1] = code;
  53014. /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
  53015. dist = 0;
  53016. for (code = 0; code < 16; code++) {
  53017. base_dist[code] = dist;
  53018. for (n = 0; n < 1 << extra_dbits[code]; n++) {
  53019. _dist_code[dist++] = code;
  53020. }
  53021. } //Assert (dist == 256, "tr_static_init: dist != 256");
  53022. dist >>= 7;
  53023. /* from now on, all distances are divided by 128 */
  53024. for (; code < D_CODES; code++) {
  53025. base_dist[code] = dist << 7;
  53026. for (n = 0; n < 1 << extra_dbits[code] - 7; n++) {
  53027. _dist_code[256 + dist++] = code;
  53028. }
  53029. } //Assert (dist == 256, "tr_static_init: 256+dist != 512");
  53030. /* Construct the codes of the static literal tree */
  53031. for (bits = 0; bits <= MAX_BITS; bits++) {
  53032. bl_count[bits] = 0;
  53033. }
  53034. n = 0;
  53035. while (n <= 143) {
  53036. static_ltree[n * 2 + 1]
  53037. /*.Len*/
  53038. = 8;
  53039. n++;
  53040. bl_count[8]++;
  53041. }
  53042. while (n <= 255) {
  53043. static_ltree[n * 2 + 1]
  53044. /*.Len*/
  53045. = 9;
  53046. n++;
  53047. bl_count[9]++;
  53048. }
  53049. while (n <= 279) {
  53050. static_ltree[n * 2 + 1]
  53051. /*.Len*/
  53052. = 7;
  53053. n++;
  53054. bl_count[7]++;
  53055. }
  53056. while (n <= 287) {
  53057. static_ltree[n * 2 + 1]
  53058. /*.Len*/
  53059. = 8;
  53060. n++;
  53061. bl_count[8]++;
  53062. }
  53063. /* Codes 286 and 287 do not exist, but we must include them in the
  53064. * tree construction to get a canonical Huffman tree (longest code
  53065. * all ones)
  53066. */
  53067. gen_codes(static_ltree, L_CODES + 1, bl_count);
  53068. /* The static distance tree is trivial: */
  53069. for (n = 0; n < D_CODES; n++) {
  53070. static_dtree[n * 2 + 1]
  53071. /*.Len*/
  53072. = 5;
  53073. static_dtree[n * 2]
  53074. /*.Code*/
  53075. = bi_reverse(n, 5);
  53076. } // Now data ready and we can init static trees
  53077. static_l_desc = new StaticTreeDesc(static_ltree, extra_lbits, LITERALS + 1, L_CODES, MAX_BITS);
  53078. static_d_desc = new StaticTreeDesc(static_dtree, extra_dbits, 0, D_CODES, MAX_BITS);
  53079. static_bl_desc = new StaticTreeDesc(new Array(0), extra_blbits, 0, BL_CODES, MAX_BL_BITS); //static_init_done = true;
  53080. }
  53081. /* ===========================================================================
  53082. * Initialize a new block.
  53083. */
  53084. function init_block(s) {
  53085. var n;
  53086. /* iterates over tree elements */
  53087. /* Initialize the trees. */
  53088. for (n = 0; n < L_CODES; n++) {
  53089. s.dyn_ltree[n * 2]
  53090. /*.Freq*/
  53091. = 0;
  53092. }
  53093. for (n = 0; n < D_CODES; n++) {
  53094. s.dyn_dtree[n * 2]
  53095. /*.Freq*/
  53096. = 0;
  53097. }
  53098. for (n = 0; n < BL_CODES; n++) {
  53099. s.bl_tree[n * 2]
  53100. /*.Freq*/
  53101. = 0;
  53102. }
  53103. s.dyn_ltree[END_BLOCK * 2]
  53104. /*.Freq*/
  53105. = 1;
  53106. s.opt_len = s.static_len = 0;
  53107. s.last_lit = s.matches = 0;
  53108. }
  53109. /* ===========================================================================
  53110. * Flush the bit buffer and align the output on a byte boundary
  53111. */
  53112. function bi_windup(s) {
  53113. if (s.bi_valid > 8) {
  53114. put_short(s, s.bi_buf);
  53115. } else if (s.bi_valid > 0) {
  53116. //put_byte(s, (Byte)s->bi_buf);
  53117. s.pending_buf[s.pending++] = s.bi_buf;
  53118. }
  53119. s.bi_buf = 0;
  53120. s.bi_valid = 0;
  53121. }
  53122. /* ===========================================================================
  53123. * Copy a stored block, storing first the length and its
  53124. * one's complement if requested.
  53125. */
  53126. function copy_block(s, buf, len, header) //DeflateState *s;
  53127. //charf *buf; /* the input data */
  53128. //unsigned len; /* its length */
  53129. //int header; /* true if block header must be written */
  53130. {
  53131. bi_windup(s);
  53132. /* align on byte boundary */
  53133. if (header) {
  53134. put_short(s, len);
  53135. put_short(s, ~len);
  53136. } // while (len--) {
  53137. // put_byte(s, *buf++);
  53138. // }
  53139. utils.arraySet(s.pending_buf, s.window, buf, len, s.pending);
  53140. s.pending += len;
  53141. }
  53142. /* ===========================================================================
  53143. * Compares to subtrees, using the tree depth as tie breaker when
  53144. * the subtrees have equal frequency. This minimizes the worst case length.
  53145. */
  53146. function smaller(tree, n, m, depth) {
  53147. var _n2 = n * 2;
  53148. var _m2 = m * 2;
  53149. return tree[_n2]
  53150. /*.Freq*/
  53151. < tree[_m2]
  53152. /*.Freq*/
  53153. || tree[_n2]
  53154. /*.Freq*/
  53155. === tree[_m2]
  53156. /*.Freq*/
  53157. && depth[n] <= depth[m];
  53158. }
  53159. /* ===========================================================================
  53160. * Restore the heap property by moving down the tree starting at node k,
  53161. * exchanging a node with the smallest of its two sons if necessary, stopping
  53162. * when the heap property is re-established (each father smaller than its
  53163. * two sons).
  53164. */
  53165. function pqdownheap(s, tree, k) // deflate_state *s;
  53166. // ct_data *tree; /* the tree to restore */
  53167. // int k; /* node to move down */
  53168. {
  53169. var v = s.heap[k];
  53170. var j = k << 1;
  53171. /* left son of k */
  53172. while (j <= s.heap_len) {
  53173. /* Set j to the smallest of the two sons: */
  53174. if (j < s.heap_len && smaller(tree, s.heap[j + 1], s.heap[j], s.depth)) {
  53175. j++;
  53176. }
  53177. /* Exit if v is smaller than both sons */
  53178. if (smaller(tree, v, s.heap[j], s.depth)) {
  53179. break;
  53180. }
  53181. /* Exchange v with the smallest son */
  53182. s.heap[k] = s.heap[j];
  53183. k = j;
  53184. /* And continue down the tree, setting j to the left son of k */
  53185. j <<= 1;
  53186. }
  53187. s.heap[k] = v;
  53188. } // inlined manually
  53189. // var SMALLEST = 1;
  53190. /* ===========================================================================
  53191. * Send the block data compressed using the given Huffman trees
  53192. */
  53193. function compress_block(s, ltree, dtree) // deflate_state *s;
  53194. // const ct_data *ltree; /* literal tree */
  53195. // const ct_data *dtree; /* distance tree */
  53196. {
  53197. var dist;
  53198. /* distance of matched string */
  53199. var lc;
  53200. /* match length or unmatched char (if dist == 0) */
  53201. var lx = 0;
  53202. /* running index in l_buf */
  53203. var code;
  53204. /* the code to send */
  53205. var extra;
  53206. /* number of extra bits to send */
  53207. if (s.last_lit !== 0) {
  53208. do {
  53209. dist = s.pending_buf[s.d_buf + lx * 2] << 8 | s.pending_buf[s.d_buf + lx * 2 + 1];
  53210. lc = s.pending_buf[s.l_buf + lx];
  53211. lx++;
  53212. if (dist === 0) {
  53213. send_code(s, lc, ltree);
  53214. /* send a literal byte */
  53215. //Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  53216. } else {
  53217. /* Here, lc is the match length - MIN_MATCH */
  53218. code = _length_code[lc];
  53219. send_code(s, code + LITERALS + 1, ltree);
  53220. /* send the length code */
  53221. extra = extra_lbits[code];
  53222. if (extra !== 0) {
  53223. lc -= base_length[code];
  53224. send_bits(s, lc, extra);
  53225. /* send the extra length bits */
  53226. }
  53227. dist--;
  53228. /* dist is now the match distance - 1 */
  53229. code = d_code(dist); //Assert (code < D_CODES, "bad d_code");
  53230. send_code(s, code, dtree);
  53231. /* send the distance code */
  53232. extra = extra_dbits[code];
  53233. if (extra !== 0) {
  53234. dist -= base_dist[code];
  53235. send_bits(s, dist, extra);
  53236. /* send the extra distance bits */
  53237. }
  53238. }
  53239. /* literal or match pair ? */
  53240. /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
  53241. //Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  53242. // "pendingBuf overflow");
  53243. } while (lx < s.last_lit);
  53244. }
  53245. send_code(s, END_BLOCK, ltree);
  53246. }
  53247. /* ===========================================================================
  53248. * Construct one Huffman tree and assigns the code bit strings and lengths.
  53249. * Update the total bit length for the current block.
  53250. * IN assertion: the field freq is set for all tree elements.
  53251. * OUT assertions: the fields len and code are set to the optimal bit length
  53252. * and corresponding code. The length opt_len is updated; static_len is
  53253. * also updated if stree is not null. The field max_code is set.
  53254. */
  53255. function build_tree(s, desc) // deflate_state *s;
  53256. // tree_desc *desc; /* the tree descriptor */
  53257. {
  53258. var tree = desc.dyn_tree;
  53259. var stree = desc.stat_desc.static_tree;
  53260. var has_stree = desc.stat_desc.has_stree;
  53261. var elems = desc.stat_desc.elems;
  53262. var n, m;
  53263. /* iterate over heap elements */
  53264. var max_code = -1;
  53265. /* largest code with non zero frequency */
  53266. var node;
  53267. /* new node being created */
  53268. /* Construct the initial heap, with least frequent element in
  53269. * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
  53270. * heap[0] is not used.
  53271. */
  53272. s.heap_len = 0;
  53273. s.heap_max = HEAP_SIZE;
  53274. for (n = 0; n < elems; n++) {
  53275. if (tree[n * 2]
  53276. /*.Freq*/
  53277. !== 0) {
  53278. s.heap[++s.heap_len] = max_code = n;
  53279. s.depth[n] = 0;
  53280. } else {
  53281. tree[n * 2 + 1]
  53282. /*.Len*/
  53283. = 0;
  53284. }
  53285. }
  53286. /* The pkzip format requires that at least one distance code exists,
  53287. * and that at least one bit should be sent even if there is only one
  53288. * possible code. So to avoid special checks later on we force at least
  53289. * two codes of non zero frequency.
  53290. */
  53291. while (s.heap_len < 2) {
  53292. node = s.heap[++s.heap_len] = max_code < 2 ? ++max_code : 0;
  53293. tree[node * 2]
  53294. /*.Freq*/
  53295. = 1;
  53296. s.depth[node] = 0;
  53297. s.opt_len--;
  53298. if (has_stree) {
  53299. s.static_len -= stree[node * 2 + 1]
  53300. /*.Len*/
  53301. ;
  53302. }
  53303. /* node is 0 or 1 so it does not have extra bits */
  53304. }
  53305. desc.max_code = max_code;
  53306. /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
  53307. * establish sub-heaps of increasing lengths:
  53308. */
  53309. for (n = s.heap_len >> 1
  53310. /*int /2*/
  53311. ; n >= 1; n--) {
  53312. pqdownheap(s, tree, n);
  53313. }
  53314. /* Construct the Huffman tree by repeatedly combining the least two
  53315. * frequent nodes.
  53316. */
  53317. node = elems;
  53318. /* next internal node of the tree */
  53319. do {
  53320. //pqremove(s, tree, n); /* n = node of least frequency */
  53321. /*** pqremove ***/
  53322. n = s.heap[1
  53323. /*SMALLEST*/
  53324. ];
  53325. s.heap[1
  53326. /*SMALLEST*/
  53327. ] = s.heap[s.heap_len--];
  53328. pqdownheap(s, tree, 1
  53329. /*SMALLEST*/
  53330. );
  53331. /***/
  53332. m = s.heap[1
  53333. /*SMALLEST*/
  53334. ];
  53335. /* m = node of next least frequency */
  53336. s.heap[--s.heap_max] = n;
  53337. /* keep the nodes sorted by frequency */
  53338. s.heap[--s.heap_max] = m;
  53339. /* Create a new node father of n and m */
  53340. tree[node * 2]
  53341. /*.Freq*/
  53342. = tree[n * 2]
  53343. /*.Freq*/
  53344. + tree[m * 2]
  53345. /*.Freq*/
  53346. ;
  53347. s.depth[node] = (s.depth[n] >= s.depth[m] ? s.depth[n] : s.depth[m]) + 1;
  53348. tree[n * 2 + 1]
  53349. /*.Dad*/
  53350. = tree[m * 2 + 1]
  53351. /*.Dad*/
  53352. = node;
  53353. /* and insert the new node in the heap */
  53354. s.heap[1
  53355. /*SMALLEST*/
  53356. ] = node++;
  53357. pqdownheap(s, tree, 1
  53358. /*SMALLEST*/
  53359. );
  53360. } while (s.heap_len >= 2);
  53361. s.heap[--s.heap_max] = s.heap[1
  53362. /*SMALLEST*/
  53363. ];
  53364. /* At this point, the fields freq and dad are set. We can now
  53365. * generate the bit lengths.
  53366. */
  53367. gen_bitlen(s, desc);
  53368. /* The field len is now set, we can generate the bit codes */
  53369. gen_codes(tree, max_code, s.bl_count);
  53370. }
  53371. /* ===========================================================================
  53372. * Scan a literal or distance tree to determine the frequencies of the codes
  53373. * in the bit length tree.
  53374. */
  53375. function scan_tree(s, tree, max_code) // deflate_state *s;
  53376. // ct_data *tree; /* the tree to be scanned */
  53377. // int max_code; /* and its largest code of non zero frequency */
  53378. {
  53379. var n;
  53380. /* iterates over all tree elements */
  53381. var prevlen = -1;
  53382. /* last emitted length */
  53383. var curlen;
  53384. /* length of current code */
  53385. var nextlen = tree[0 * 2 + 1]
  53386. /*.Len*/
  53387. ;
  53388. /* length of next code */
  53389. var count = 0;
  53390. /* repeat count of the current code */
  53391. var max_count = 7;
  53392. /* max repeat count */
  53393. var min_count = 4;
  53394. /* min repeat count */
  53395. if (nextlen === 0) {
  53396. max_count = 138;
  53397. min_count = 3;
  53398. }
  53399. tree[(max_code + 1) * 2 + 1]
  53400. /*.Len*/
  53401. = 0xffff;
  53402. /* guard */
  53403. for (n = 0; n <= max_code; n++) {
  53404. curlen = nextlen;
  53405. nextlen = tree[(n + 1) * 2 + 1]
  53406. /*.Len*/
  53407. ;
  53408. if (++count < max_count && curlen === nextlen) {
  53409. continue;
  53410. } else if (count < min_count) {
  53411. s.bl_tree[curlen * 2]
  53412. /*.Freq*/
  53413. += count;
  53414. } else if (curlen !== 0) {
  53415. if (curlen !== prevlen) {
  53416. s.bl_tree[curlen * 2] /*.Freq*/++;
  53417. }
  53418. s.bl_tree[REP_3_6 * 2] /*.Freq*/++;
  53419. } else if (count <= 10) {
  53420. s.bl_tree[REPZ_3_10 * 2] /*.Freq*/++;
  53421. } else {
  53422. s.bl_tree[REPZ_11_138 * 2] /*.Freq*/++;
  53423. }
  53424. count = 0;
  53425. prevlen = curlen;
  53426. if (nextlen === 0) {
  53427. max_count = 138;
  53428. min_count = 3;
  53429. } else if (curlen === nextlen) {
  53430. max_count = 6;
  53431. min_count = 3;
  53432. } else {
  53433. max_count = 7;
  53434. min_count = 4;
  53435. }
  53436. }
  53437. }
  53438. /* ===========================================================================
  53439. * Send a literal or distance tree in compressed form, using the codes in
  53440. * bl_tree.
  53441. */
  53442. function send_tree(s, tree, max_code) // deflate_state *s;
  53443. // ct_data *tree; /* the tree to be scanned */
  53444. // int max_code; /* and its largest code of non zero frequency */
  53445. {
  53446. var n;
  53447. /* iterates over all tree elements */
  53448. var prevlen = -1;
  53449. /* last emitted length */
  53450. var curlen;
  53451. /* length of current code */
  53452. var nextlen = tree[0 * 2 + 1]
  53453. /*.Len*/
  53454. ;
  53455. /* length of next code */
  53456. var count = 0;
  53457. /* repeat count of the current code */
  53458. var max_count = 7;
  53459. /* max repeat count */
  53460. var min_count = 4;
  53461. /* min repeat count */
  53462. /* tree[max_code+1].Len = -1; */
  53463. /* guard already set */
  53464. if (nextlen === 0) {
  53465. max_count = 138;
  53466. min_count = 3;
  53467. }
  53468. for (n = 0; n <= max_code; n++) {
  53469. curlen = nextlen;
  53470. nextlen = tree[(n + 1) * 2 + 1]
  53471. /*.Len*/
  53472. ;
  53473. if (++count < max_count && curlen === nextlen) {
  53474. continue;
  53475. } else if (count < min_count) {
  53476. do {
  53477. send_code(s, curlen, s.bl_tree);
  53478. } while (--count !== 0);
  53479. } else if (curlen !== 0) {
  53480. if (curlen !== prevlen) {
  53481. send_code(s, curlen, s.bl_tree);
  53482. count--;
  53483. } //Assert(count >= 3 && count <= 6, " 3_6?");
  53484. send_code(s, REP_3_6, s.bl_tree);
  53485. send_bits(s, count - 3, 2);
  53486. } else if (count <= 10) {
  53487. send_code(s, REPZ_3_10, s.bl_tree);
  53488. send_bits(s, count - 3, 3);
  53489. } else {
  53490. send_code(s, REPZ_11_138, s.bl_tree);
  53491. send_bits(s, count - 11, 7);
  53492. }
  53493. count = 0;
  53494. prevlen = curlen;
  53495. if (nextlen === 0) {
  53496. max_count = 138;
  53497. min_count = 3;
  53498. } else if (curlen === nextlen) {
  53499. max_count = 6;
  53500. min_count = 3;
  53501. } else {
  53502. max_count = 7;
  53503. min_count = 4;
  53504. }
  53505. }
  53506. }
  53507. /* ===========================================================================
  53508. * Construct the Huffman tree for the bit lengths and return the index in
  53509. * bl_order of the last bit length code to send.
  53510. */
  53511. function build_bl_tree(s) {
  53512. var max_blindex;
  53513. /* index of last bit length code of non zero freq */
  53514. /* Determine the bit length frequencies for literal and distance trees */
  53515. scan_tree(s, s.dyn_ltree, s.l_desc.max_code);
  53516. scan_tree(s, s.dyn_dtree, s.d_desc.max_code);
  53517. /* Build the bit length tree: */
  53518. build_tree(s, s.bl_desc);
  53519. /* opt_len now includes the length of the tree representations, except
  53520. * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
  53521. */
  53522. /* Determine the number of bit length codes to send. The pkzip format
  53523. * requires that at least 4 bit length codes be sent. (appnote.txt says
  53524. * 3 but the actual value used is 4.)
  53525. */
  53526. for (max_blindex = BL_CODES - 1; max_blindex >= 3; max_blindex--) {
  53527. if (s.bl_tree[bl_order[max_blindex] * 2 + 1]
  53528. /*.Len*/
  53529. !== 0) {
  53530. break;
  53531. }
  53532. }
  53533. /* Update opt_len to include the bit length tree and counts */
  53534. s.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4; //Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  53535. // s->opt_len, s->static_len));
  53536. return max_blindex;
  53537. }
  53538. /* ===========================================================================
  53539. * Send the header for a block using dynamic Huffman trees: the counts, the
  53540. * lengths of the bit length codes, the literal tree and the distance tree.
  53541. * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
  53542. */
  53543. function send_all_trees(s, lcodes, dcodes, blcodes) // deflate_state *s;
  53544. // int lcodes, dcodes, blcodes; /* number of codes for each tree */
  53545. {
  53546. var rank;
  53547. /* index in bl_order */
  53548. //Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  53549. //Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  53550. // "too many codes");
  53551. //Tracev((stderr, "\nbl counts: "));
  53552. send_bits(s, lcodes - 257, 5);
  53553. /* not +255 as stated in appnote.txt */
  53554. send_bits(s, dcodes - 1, 5);
  53555. send_bits(s, blcodes - 4, 4);
  53556. /* not -3 as stated in appnote.txt */
  53557. for (rank = 0; rank < blcodes; rank++) {
  53558. //Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  53559. send_bits(s, s.bl_tree[bl_order[rank] * 2 + 1]
  53560. /*.Len*/
  53561. , 3);
  53562. } //Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  53563. send_tree(s, s.dyn_ltree, lcodes - 1);
  53564. /* literal tree */
  53565. //Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  53566. send_tree(s, s.dyn_dtree, dcodes - 1);
  53567. /* distance tree */
  53568. //Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  53569. }
  53570. /* ===========================================================================
  53571. * Check if the data type is TEXT or BINARY, using the following algorithm:
  53572. * - TEXT if the two conditions below are satisfied:
  53573. * a) There are no non-portable control characters belonging to the
  53574. * "black list" (0..6, 14..25, 28..31).
  53575. * b) There is at least one printable character belonging to the
  53576. * "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
  53577. * - BINARY otherwise.
  53578. * - The following partially-portable control characters form a
  53579. * "gray list" that is ignored in this detection algorithm:
  53580. * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
  53581. * IN assertion: the fields Freq of dyn_ltree are set.
  53582. */
  53583. function detect_data_type(s) {
  53584. /* black_mask is the bit mask of black-listed bytes
  53585. * set bits 0..6, 14..25, and 28..31
  53586. * 0xf3ffc07f = binary 11110011111111111100000001111111
  53587. */
  53588. var black_mask = 0xf3ffc07f;
  53589. var n;
  53590. /* Check for non-textual ("black-listed") bytes. */
  53591. for (n = 0; n <= 31; n++, black_mask >>>= 1) {
  53592. if (black_mask & 1 && s.dyn_ltree[n * 2]
  53593. /*.Freq*/
  53594. !== 0) {
  53595. return Z_BINARY;
  53596. }
  53597. }
  53598. /* Check for textual ("white-listed") bytes. */
  53599. if (s.dyn_ltree[9 * 2]
  53600. /*.Freq*/
  53601. !== 0 || s.dyn_ltree[10 * 2]
  53602. /*.Freq*/
  53603. !== 0 || s.dyn_ltree[13 * 2]
  53604. /*.Freq*/
  53605. !== 0) {
  53606. return Z_TEXT;
  53607. }
  53608. for (n = 32; n < LITERALS; n++) {
  53609. if (s.dyn_ltree[n * 2]
  53610. /*.Freq*/
  53611. !== 0) {
  53612. return Z_TEXT;
  53613. }
  53614. }
  53615. /* There are no "black-listed" or "white-listed" bytes:
  53616. * this stream either is empty or has tolerated ("gray-listed") bytes only.
  53617. */
  53618. return Z_BINARY;
  53619. }
  53620. var static_init_done = false;
  53621. /* ===========================================================================
  53622. * Initialize the tree data structures for a new zlib stream.
  53623. */
  53624. function _tr_init(s) {
  53625. if (!static_init_done) {
  53626. tr_static_init();
  53627. static_init_done = true;
  53628. }
  53629. s.l_desc = new TreeDesc(s.dyn_ltree, static_l_desc);
  53630. s.d_desc = new TreeDesc(s.dyn_dtree, static_d_desc);
  53631. s.bl_desc = new TreeDesc(s.bl_tree, static_bl_desc);
  53632. s.bi_buf = 0;
  53633. s.bi_valid = 0;
  53634. /* Initialize the first block of the first file: */
  53635. init_block(s);
  53636. }
  53637. /* ===========================================================================
  53638. * Send a stored block
  53639. */
  53640. function _tr_stored_block(s, buf, stored_len, last) //DeflateState *s;
  53641. //charf *buf; /* input block */
  53642. //ulg stored_len; /* length of input block */
  53643. //int last; /* one if this is the last block for a file */
  53644. {
  53645. send_bits(s, (STORED_BLOCK << 1) + (last ? 1 : 0), 3);
  53646. /* send block type */
  53647. copy_block(s, buf, stored_len, true);
  53648. /* with header */
  53649. }
  53650. /* ===========================================================================
  53651. * Send one empty static block to give enough lookahead for inflate.
  53652. * This takes 10 bits, of which 7 may remain in the bit buffer.
  53653. */
  53654. function _tr_align(s) {
  53655. send_bits(s, STATIC_TREES << 1, 3);
  53656. send_code(s, END_BLOCK, static_ltree);
  53657. bi_flush(s);
  53658. }
  53659. /* ===========================================================================
  53660. * Determine the best encoding for the current block: dynamic trees, static
  53661. * trees or store, and output the encoded block to the zip file.
  53662. */
  53663. function _tr_flush_block(s, buf, stored_len, last) //DeflateState *s;
  53664. //charf *buf; /* input block, or NULL if too old */
  53665. //ulg stored_len; /* length of input block */
  53666. //int last; /* one if this is the last block for a file */
  53667. {
  53668. var opt_lenb, static_lenb;
  53669. /* opt_len and static_len in bytes */
  53670. var max_blindex = 0;
  53671. /* index of last bit length code of non zero freq */
  53672. /* Build the Huffman trees unless a stored block is forced */
  53673. if (s.level > 0) {
  53674. /* Check if the file is binary or text */
  53675. if (s.strm.data_type === Z_UNKNOWN) {
  53676. s.strm.data_type = detect_data_type(s);
  53677. }
  53678. /* Construct the literal and distance trees */
  53679. build_tree(s, s.l_desc); // Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  53680. // s->static_len));
  53681. build_tree(s, s.d_desc); // Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  53682. // s->static_len));
  53683. /* At this point, opt_len and static_len are the total bit lengths of
  53684. * the compressed block data, excluding the tree representations.
  53685. */
  53686. /* Build the bit length tree for the above two trees, and get the index
  53687. * in bl_order of the last bit length code to send.
  53688. */
  53689. max_blindex = build_bl_tree(s);
  53690. /* Determine the best encoding. Compute the block lengths in bytes. */
  53691. opt_lenb = s.opt_len + 3 + 7 >>> 3;
  53692. static_lenb = s.static_len + 3 + 7 >>> 3; // Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  53693. // opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  53694. // s->last_lit));
  53695. if (static_lenb <= opt_lenb) {
  53696. opt_lenb = static_lenb;
  53697. }
  53698. } else {
  53699. // Assert(buf != (char*)0, "lost buf");
  53700. opt_lenb = static_lenb = stored_len + 5;
  53701. /* force a stored block */
  53702. }
  53703. if (stored_len + 4 <= opt_lenb && buf !== -1) {
  53704. /* 4: two words for the lengths */
  53705. /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
  53706. * Otherwise we can't have processed more than WSIZE input bytes since
  53707. * the last block flush, because compression would have been
  53708. * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
  53709. * transform a block into a stored block.
  53710. */
  53711. _tr_stored_block(s, buf, stored_len, last);
  53712. } else if (s.strategy === Z_FIXED || static_lenb === opt_lenb) {
  53713. send_bits(s, (STATIC_TREES << 1) + (last ? 1 : 0), 3);
  53714. compress_block(s, static_ltree, static_dtree);
  53715. } else {
  53716. send_bits(s, (DYN_TREES << 1) + (last ? 1 : 0), 3);
  53717. send_all_trees(s, s.l_desc.max_code + 1, s.d_desc.max_code + 1, max_blindex + 1);
  53718. compress_block(s, s.dyn_ltree, s.dyn_dtree);
  53719. } // Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  53720. /* The above check is made mod 2^32, for files larger than 512 MB
  53721. * and uLong implemented on 32 bits.
  53722. */
  53723. init_block(s);
  53724. if (last) {
  53725. bi_windup(s);
  53726. } // Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  53727. // s->compressed_len-7*last));
  53728. }
  53729. /* ===========================================================================
  53730. * Save the match info and tally the frequency counts. Return true if
  53731. * the current block must be flushed.
  53732. */
  53733. function _tr_tally(s, dist, lc) // deflate_state *s;
  53734. // unsigned dist; /* distance of matched string */
  53735. // unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */
  53736. {
  53737. //var out_length, in_length, dcode;
  53738. s.pending_buf[s.d_buf + s.last_lit * 2] = dist >>> 8 & 0xff;
  53739. s.pending_buf[s.d_buf + s.last_lit * 2 + 1] = dist & 0xff;
  53740. s.pending_buf[s.l_buf + s.last_lit] = lc & 0xff;
  53741. s.last_lit++;
  53742. if (dist === 0) {
  53743. /* lc is the unmatched char */
  53744. s.dyn_ltree[lc * 2] /*.Freq*/++;
  53745. } else {
  53746. s.matches++;
  53747. /* Here, lc is the match length - MIN_MATCH */
  53748. dist--;
  53749. /* dist = match distance - 1 */
  53750. //Assert((ush)dist < (ush)MAX_DIST(s) &&
  53751. // (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  53752. // (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  53753. s.dyn_ltree[(_length_code[lc] + LITERALS + 1) * 2] /*.Freq*/++;
  53754. s.dyn_dtree[d_code(dist) * 2] /*.Freq*/++;
  53755. } // (!) This block is disabled in zlib defaults,
  53756. // don't enable it for binary compatibility
  53757. //#ifdef TRUNCATE_BLOCK
  53758. // /* Try to guess if it is profitable to stop the current block here */
  53759. // if ((s.last_lit & 0x1fff) === 0 && s.level > 2) {
  53760. // /* Compute an upper bound for the compressed length */
  53761. // out_length = s.last_lit*8;
  53762. // in_length = s.strstart - s.block_start;
  53763. //
  53764. // for (dcode = 0; dcode < D_CODES; dcode++) {
  53765. // out_length += s.dyn_dtree[dcode*2]/*.Freq*/ * (5 + extra_dbits[dcode]);
  53766. // }
  53767. // out_length >>>= 3;
  53768. // //Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  53769. // // s->last_lit, in_length, out_length,
  53770. // // 100L - out_length*100L/in_length));
  53771. // if (s.matches < (s.last_lit>>1)/*int /2*/ && out_length < (in_length>>1)/*int /2*/) {
  53772. // return true;
  53773. // }
  53774. // }
  53775. //#endif
  53776. return s.last_lit === s.lit_bufsize - 1;
  53777. /* We avoid equality with lit_bufsize because of wraparound at 64K
  53778. * on 16 bit machines and because stored blocks are restricted to
  53779. * 64K-1 bytes.
  53780. */
  53781. }
  53782. exports._tr_init = _tr_init;
  53783. exports._tr_stored_block = _tr_stored_block;
  53784. exports._tr_flush_block = _tr_flush_block;
  53785. exports._tr_tally = _tr_tally;
  53786. exports._tr_align = _tr_align;
  53787. },{"../utils/common":333}],345:[function(require,module,exports){
  53788. 'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  53789. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  53790. //
  53791. // This software is provided 'as-is', without any express or implied
  53792. // warranty. In no event will the authors be held liable for any damages
  53793. // arising from the use of this software.
  53794. //
  53795. // Permission is granted to anyone to use this software for any purpose,
  53796. // including commercial applications, and to alter it and redistribute it
  53797. // freely, subject to the following restrictions:
  53798. //
  53799. // 1. The origin of this software must not be misrepresented; you must not
  53800. // claim that you wrote the original software. If you use this software
  53801. // in a product, an acknowledgment in the product documentation would be
  53802. // appreciated but is not required.
  53803. // 2. Altered source versions must be plainly marked as such, and must not be
  53804. // misrepresented as being the original software.
  53805. // 3. This notice may not be removed or altered from any source distribution.
  53806. function ZStream() {
  53807. /* next input byte */
  53808. this.input = null; // JS specific, because we have no pointers
  53809. this.next_in = 0;
  53810. /* number of bytes available at input */
  53811. this.avail_in = 0;
  53812. /* total number of input bytes read so far */
  53813. this.total_in = 0;
  53814. /* next output byte should be put there */
  53815. this.output = null; // JS specific, because we have no pointers
  53816. this.next_out = 0;
  53817. /* remaining free space at output */
  53818. this.avail_out = 0;
  53819. /* total number of bytes output so far */
  53820. this.total_out = 0;
  53821. /* last error message, NULL if no error */
  53822. this.msg = ''
  53823. /*Z_NULL*/
  53824. ;
  53825. /* not visible by applications */
  53826. this.state = null;
  53827. /* best guess about the data type: binary or text */
  53828. this.data_type = 2
  53829. /*Z_UNKNOWN*/
  53830. ;
  53831. /* adler32 value of the uncompressed data */
  53832. this.adler = 0;
  53833. }
  53834. module.exports = ZStream;
  53835. },{}],346:[function(require,module,exports){
  53836. module.exports={"2.16.840.1.101.3.4.1.1": "aes-128-ecb",
  53837. "2.16.840.1.101.3.4.1.2": "aes-128-cbc",
  53838. "2.16.840.1.101.3.4.1.3": "aes-128-ofb",
  53839. "2.16.840.1.101.3.4.1.4": "aes-128-cfb",
  53840. "2.16.840.1.101.3.4.1.21": "aes-192-ecb",
  53841. "2.16.840.1.101.3.4.1.22": "aes-192-cbc",
  53842. "2.16.840.1.101.3.4.1.23": "aes-192-ofb",
  53843. "2.16.840.1.101.3.4.1.24": "aes-192-cfb",
  53844. "2.16.840.1.101.3.4.1.41": "aes-256-ecb",
  53845. "2.16.840.1.101.3.4.1.42": "aes-256-cbc",
  53846. "2.16.840.1.101.3.4.1.43": "aes-256-ofb",
  53847. "2.16.840.1.101.3.4.1.44": "aes-256-cfb"
  53848. }
  53849. },{}],347:[function(require,module,exports){
  53850. // from https://github.com/indutny/self-signed/blob/gh-pages/lib/asn1.js
  53851. // Fedor, you are amazing.
  53852. 'use strict';
  53853. var asn1 = require('asn1.js');
  53854. exports.certificate = require('./certificate');
  53855. var RSAPrivateKey = asn1.define('RSAPrivateKey', function () {
  53856. 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());
  53857. });
  53858. exports.RSAPrivateKey = RSAPrivateKey;
  53859. var RSAPublicKey = asn1.define('RSAPublicKey', function () {
  53860. this.seq().obj(this.key('modulus').int(), this.key('publicExponent').int());
  53861. });
  53862. exports.RSAPublicKey = RSAPublicKey;
  53863. var PublicKey = asn1.define('SubjectPublicKeyInfo', function () {
  53864. this.seq().obj(this.key('algorithm').use(AlgorithmIdentifier), this.key('subjectPublicKey').bitstr());
  53865. });
  53866. exports.PublicKey = PublicKey;
  53867. var AlgorithmIdentifier = asn1.define('AlgorithmIdentifier', function () {
  53868. 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());
  53869. });
  53870. var PrivateKeyInfo = asn1.define('PrivateKeyInfo', function () {
  53871. this.seq().obj(this.key('version').int(), this.key('algorithm').use(AlgorithmIdentifier), this.key('subjectPrivateKey').octstr());
  53872. });
  53873. exports.PrivateKey = PrivateKeyInfo;
  53874. var EncryptedPrivateKeyInfo = asn1.define('EncryptedPrivateKeyInfo', function () {
  53875. 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());
  53876. });
  53877. exports.EncryptedPrivateKey = EncryptedPrivateKeyInfo;
  53878. var DSAPrivateKey = asn1.define('DSAPrivateKey', function () {
  53879. 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());
  53880. });
  53881. exports.DSAPrivateKey = DSAPrivateKey;
  53882. exports.DSAparam = asn1.define('DSAparam', function () {
  53883. this.int();
  53884. });
  53885. var ECPrivateKey = asn1.define('ECPrivateKey', function () {
  53886. 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());
  53887. });
  53888. exports.ECPrivateKey = ECPrivateKey;
  53889. var ECParameters = asn1.define('ECParameters', function () {
  53890. this.choice({
  53891. namedCurve: this.objid()
  53892. });
  53893. });
  53894. exports.signature = asn1.define('signature', function () {
  53895. this.seq().obj(this.key('r').int(), this.key('s').int());
  53896. });
  53897. },{"./certificate":348,"asn1.js":167}],348:[function(require,module,exports){
  53898. // from https://github.com/Rantanen/node-dtls/blob/25a7dc861bda38cfeac93a723500eea4f0ac2e86/Certificate.js
  53899. // thanks to @Rantanen
  53900. 'use strict';
  53901. var asn = require('asn1.js');
  53902. var Time = asn.define('Time', function () {
  53903. this.choice({
  53904. utcTime: this.utctime(),
  53905. generalTime: this.gentime()
  53906. });
  53907. });
  53908. var AttributeTypeValue = asn.define('AttributeTypeValue', function () {
  53909. this.seq().obj(this.key('type').objid(), this.key('value').any());
  53910. });
  53911. var AlgorithmIdentifier = asn.define('AlgorithmIdentifier', function () {
  53912. this.seq().obj(this.key('algorithm').objid(), this.key('parameters').optional(), this.key('curve').objid().optional());
  53913. });
  53914. var SubjectPublicKeyInfo = asn.define('SubjectPublicKeyInfo', function () {
  53915. this.seq().obj(this.key('algorithm').use(AlgorithmIdentifier), this.key('subjectPublicKey').bitstr());
  53916. });
  53917. var RelativeDistinguishedName = asn.define('RelativeDistinguishedName', function () {
  53918. this.setof(AttributeTypeValue);
  53919. });
  53920. var RDNSequence = asn.define('RDNSequence', function () {
  53921. this.seqof(RelativeDistinguishedName);
  53922. });
  53923. var Name = asn.define('Name', function () {
  53924. this.choice({
  53925. rdnSequence: this.use(RDNSequence)
  53926. });
  53927. });
  53928. var Validity = asn.define('Validity', function () {
  53929. this.seq().obj(this.key('notBefore').use(Time), this.key('notAfter').use(Time));
  53930. });
  53931. var Extension = asn.define('Extension', function () {
  53932. this.seq().obj(this.key('extnID').objid(), this.key('critical').bool().def(false), this.key('extnValue').octstr());
  53933. });
  53934. var TBSCertificate = asn.define('TBSCertificate', function () {
  53935. 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());
  53936. });
  53937. var X509Certificate = asn.define('X509Certificate', function () {
  53938. this.seq().obj(this.key('tbsCertificate').use(TBSCertificate), this.key('signatureAlgorithm').use(AlgorithmIdentifier), this.key('signatureValue').bitstr());
  53939. });
  53940. module.exports = X509Certificate;
  53941. },{"asn1.js":167}],349:[function(require,module,exports){
  53942. "use strict";
  53943. // adapted from https://github.com/apatil/pemstrip
  53944. 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;
  53945. var startRegex = /^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----/m;
  53946. var fullRegex = /^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----([0-9A-z\n\r+/=]+)-----END \1-----$/m;
  53947. var evp = require('evp_bytestokey');
  53948. var ciphers = require('browserify-aes');
  53949. var Buffer = require('safe-buffer').Buffer;
  53950. module.exports = function (okey, password) {
  53951. var key = okey.toString();
  53952. var match = key.match(findProc);
  53953. var decrypted;
  53954. if (!match) {
  53955. var match2 = key.match(fullRegex);
  53956. decrypted = Buffer.from(match2[2].replace(/[\r\n]/g, ''), 'base64');
  53957. } else {
  53958. var suite = 'aes' + match[1];
  53959. var iv = Buffer.from(match[2], 'hex');
  53960. var cipherText = Buffer.from(match[3].replace(/[\r\n]/g, ''), 'base64');
  53961. var cipherKey = evp(password, iv.slice(0, 8), parseInt(match[1], 10)).key;
  53962. var out = [];
  53963. var cipher = ciphers.createDecipheriv(suite, cipherKey, iv);
  53964. out.push(cipher.update(cipherText));
  53965. out.push(cipher.final());
  53966. decrypted = Buffer.concat(out);
  53967. }
  53968. var tag = key.match(startRegex)[1];
  53969. return {
  53970. tag: tag,
  53971. data: decrypted
  53972. };
  53973. };
  53974. },{"browserify-aes":188,"evp_bytestokey":259,"safe-buffer":384}],350:[function(require,module,exports){
  53975. "use strict";
  53976. 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); }
  53977. var asn1 = require('./asn1');
  53978. var aesid = require('./aesid.json');
  53979. var fixProc = require('./fixProc');
  53980. var ciphers = require('browserify-aes');
  53981. var compat = require('pbkdf2');
  53982. var Buffer = require('safe-buffer').Buffer;
  53983. module.exports = parseKeys;
  53984. function parseKeys(buffer) {
  53985. var password;
  53986. if (_typeof(buffer) === 'object' && !Buffer.isBuffer(buffer)) {
  53987. password = buffer.passphrase;
  53988. buffer = buffer.key;
  53989. }
  53990. if (typeof buffer === 'string') {
  53991. buffer = Buffer.from(buffer);
  53992. }
  53993. var stripped = fixProc(buffer, password);
  53994. var type = stripped.tag;
  53995. var data = stripped.data;
  53996. var subtype, ndata;
  53997. switch (type) {
  53998. case 'CERTIFICATE':
  53999. ndata = asn1.certificate.decode(data, 'der').tbsCertificate.subjectPublicKeyInfo;
  54000. // falls through
  54001. case 'PUBLIC KEY':
  54002. if (!ndata) {
  54003. ndata = asn1.PublicKey.decode(data, 'der');
  54004. }
  54005. subtype = ndata.algorithm.algorithm.join('.');
  54006. switch (subtype) {
  54007. case '1.2.840.113549.1.1.1':
  54008. return asn1.RSAPublicKey.decode(ndata.subjectPublicKey.data, 'der');
  54009. case '1.2.840.10045.2.1':
  54010. ndata.subjectPrivateKey = ndata.subjectPublicKey;
  54011. return {
  54012. type: 'ec',
  54013. data: ndata
  54014. };
  54015. case '1.2.840.10040.4.1':
  54016. ndata.algorithm.params.pub_key = asn1.DSAparam.decode(ndata.subjectPublicKey.data, 'der');
  54017. return {
  54018. type: 'dsa',
  54019. data: ndata.algorithm.params
  54020. };
  54021. default:
  54022. throw new Error('unknown key id ' + subtype);
  54023. }
  54024. // throw new Error('unknown key type ' + type)
  54025. case 'ENCRYPTED PRIVATE KEY':
  54026. data = asn1.EncryptedPrivateKey.decode(data, 'der');
  54027. data = decrypt(data, password);
  54028. // falls through
  54029. case 'PRIVATE KEY':
  54030. ndata = asn1.PrivateKey.decode(data, 'der');
  54031. subtype = ndata.algorithm.algorithm.join('.');
  54032. switch (subtype) {
  54033. case '1.2.840.113549.1.1.1':
  54034. return asn1.RSAPrivateKey.decode(ndata.subjectPrivateKey, 'der');
  54035. case '1.2.840.10045.2.1':
  54036. return {
  54037. curve: ndata.algorithm.curve,
  54038. privateKey: asn1.ECPrivateKey.decode(ndata.subjectPrivateKey, 'der').privateKey
  54039. };
  54040. case '1.2.840.10040.4.1':
  54041. ndata.algorithm.params.priv_key = asn1.DSAparam.decode(ndata.subjectPrivateKey, 'der');
  54042. return {
  54043. type: 'dsa',
  54044. params: ndata.algorithm.params
  54045. };
  54046. default:
  54047. throw new Error('unknown key id ' + subtype);
  54048. }
  54049. // throw new Error('unknown key type ' + type)
  54050. case 'RSA PUBLIC KEY':
  54051. return asn1.RSAPublicKey.decode(data, 'der');
  54052. case 'RSA PRIVATE KEY':
  54053. return asn1.RSAPrivateKey.decode(data, 'der');
  54054. case 'DSA PRIVATE KEY':
  54055. return {
  54056. type: 'dsa',
  54057. params: asn1.DSAPrivateKey.decode(data, 'der')
  54058. };
  54059. case 'EC PRIVATE KEY':
  54060. data = asn1.ECPrivateKey.decode(data, 'der');
  54061. return {
  54062. curve: data.parameters.value,
  54063. privateKey: data.privateKey
  54064. };
  54065. default:
  54066. throw new Error('unknown key type ' + type);
  54067. }
  54068. }
  54069. parseKeys.signature = asn1.signature;
  54070. function decrypt(data, password) {
  54071. var salt = data.algorithm.decrypt.kde.kdeparams.salt;
  54072. var iters = parseInt(data.algorithm.decrypt.kde.kdeparams.iters.toString(), 10);
  54073. var algo = aesid[data.algorithm.decrypt.cipher.algo.join('.')];
  54074. var iv = data.algorithm.decrypt.cipher.iv;
  54075. var cipherText = data.subjectPrivateKey;
  54076. var keylen = parseInt(algo.split('-')[1], 10) / 8;
  54077. var key = compat.pbkdf2Sync(password, salt, iters, keylen, 'sha1');
  54078. var cipher = ciphers.createDecipheriv(algo, key, iv);
  54079. var out = [];
  54080. out.push(cipher.update(cipherText));
  54081. out.push(cipher.final());
  54082. return Buffer.concat(out);
  54083. }
  54084. },{"./aesid.json":346,"./asn1":347,"./fixProc":349,"browserify-aes":188,"pbkdf2":351,"safe-buffer":384}],351:[function(require,module,exports){
  54085. "use strict";
  54086. exports.pbkdf2 = require('./lib/async');
  54087. exports.pbkdf2Sync = require('./lib/sync');
  54088. },{"./lib/async":352,"./lib/sync":355}],352:[function(require,module,exports){
  54089. (function (process,global){
  54090. "use strict";
  54091. var Buffer = require('safe-buffer').Buffer;
  54092. var checkParameters = require('./precondition');
  54093. var defaultEncoding = require('./default-encoding');
  54094. var sync = require('./sync');
  54095. var toBuffer = require('./to-buffer');
  54096. var ZERO_BUF;
  54097. var subtle = global.crypto && global.crypto.subtle;
  54098. var toBrowser = {
  54099. sha: 'SHA-1',
  54100. 'sha-1': 'SHA-1',
  54101. sha1: 'SHA-1',
  54102. sha256: 'SHA-256',
  54103. 'sha-256': 'SHA-256',
  54104. sha384: 'SHA-384',
  54105. 'sha-384': 'SHA-384',
  54106. 'sha-512': 'SHA-512',
  54107. sha512: 'SHA-512'
  54108. };
  54109. var checks = [];
  54110. function checkNative(algo) {
  54111. if (global.process && !global.process.browser) {
  54112. return Promise.resolve(false);
  54113. }
  54114. if (!subtle || !subtle.importKey || !subtle.deriveBits) {
  54115. return Promise.resolve(false);
  54116. }
  54117. if (checks[algo] !== undefined) {
  54118. return checks[algo];
  54119. }
  54120. ZERO_BUF = ZERO_BUF || Buffer.alloc(8);
  54121. var prom = browserPbkdf2(ZERO_BUF, ZERO_BUF, 10, 128, algo).then(function () {
  54122. return true;
  54123. }).catch(function () {
  54124. return false;
  54125. });
  54126. checks[algo] = prom;
  54127. return prom;
  54128. }
  54129. function browserPbkdf2(password, salt, iterations, length, algo) {
  54130. return subtle.importKey('raw', password, {
  54131. name: 'PBKDF2'
  54132. }, false, ['deriveBits']).then(function (key) {
  54133. return subtle.deriveBits({
  54134. name: 'PBKDF2',
  54135. salt: salt,
  54136. iterations: iterations,
  54137. hash: {
  54138. name: algo
  54139. }
  54140. }, key, length << 3);
  54141. }).then(function (res) {
  54142. return Buffer.from(res);
  54143. });
  54144. }
  54145. function resolvePromise(promise, callback) {
  54146. promise.then(function (out) {
  54147. process.nextTick(function () {
  54148. callback(null, out);
  54149. });
  54150. }, function (e) {
  54151. process.nextTick(function () {
  54152. callback(e);
  54153. });
  54154. });
  54155. }
  54156. module.exports = function (password, salt, iterations, keylen, digest, callback) {
  54157. if (typeof digest === 'function') {
  54158. callback = digest;
  54159. digest = undefined;
  54160. }
  54161. digest = digest || 'sha1';
  54162. var algo = toBrowser[digest.toLowerCase()];
  54163. if (!algo || typeof global.Promise !== 'function') {
  54164. return process.nextTick(function () {
  54165. var out;
  54166. try {
  54167. out = sync(password, salt, iterations, keylen, digest);
  54168. } catch (e) {
  54169. return callback(e);
  54170. }
  54171. callback(null, out);
  54172. });
  54173. }
  54174. checkParameters(iterations, keylen);
  54175. password = toBuffer(password, defaultEncoding, 'Password');
  54176. salt = toBuffer(salt, defaultEncoding, 'Salt');
  54177. if (typeof callback !== 'function') throw new Error('No callback provided to pbkdf2');
  54178. resolvePromise(checkNative(algo).then(function (resp) {
  54179. if (resp) return browserPbkdf2(password, salt, iterations, keylen, algo);
  54180. return sync(password, salt, iterations, keylen, digest);
  54181. }), callback);
  54182. };
  54183. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  54184. },{"./default-encoding":353,"./precondition":354,"./sync":355,"./to-buffer":356,"_process":358,"safe-buffer":384}],353:[function(require,module,exports){
  54185. (function (process){
  54186. "use strict";
  54187. var defaultEncoding;
  54188. /* istanbul ignore next */
  54189. if (process.browser) {
  54190. defaultEncoding = 'utf-8';
  54191. } else if (process.version) {
  54192. var pVersionMajor = parseInt(process.version.split('.')[0].slice(1), 10);
  54193. defaultEncoding = pVersionMajor >= 6 ? 'utf-8' : 'binary';
  54194. } else {
  54195. defaultEncoding = 'utf-8';
  54196. }
  54197. module.exports = defaultEncoding;
  54198. }).call(this,require('_process'))
  54199. },{"_process":358}],354:[function(require,module,exports){
  54200. "use strict";
  54201. var MAX_ALLOC = Math.pow(2, 30) - 1; // default in iojs
  54202. module.exports = function (iterations, keylen) {
  54203. if (typeof iterations !== 'number') {
  54204. throw new TypeError('Iterations not a number');
  54205. }
  54206. if (iterations < 0) {
  54207. throw new TypeError('Bad iterations');
  54208. }
  54209. if (typeof keylen !== 'number') {
  54210. throw new TypeError('Key length not a number');
  54211. }
  54212. if (keylen < 0 || keylen > MAX_ALLOC || keylen !== keylen) {
  54213. /* eslint no-self-compare: 0 */
  54214. throw new TypeError('Bad key length');
  54215. }
  54216. };
  54217. },{}],355:[function(require,module,exports){
  54218. "use strict";
  54219. var md5 = require('create-hash/md5');
  54220. var RIPEMD160 = require('ripemd160');
  54221. var sha = require('sha.js');
  54222. var Buffer = require('safe-buffer').Buffer;
  54223. var checkParameters = require('./precondition');
  54224. var defaultEncoding = require('./default-encoding');
  54225. var toBuffer = require('./to-buffer');
  54226. var ZEROS = Buffer.alloc(128);
  54227. var sizes = {
  54228. md5: 16,
  54229. sha1: 20,
  54230. sha224: 28,
  54231. sha256: 32,
  54232. sha384: 48,
  54233. sha512: 64,
  54234. rmd160: 20,
  54235. ripemd160: 20
  54236. };
  54237. function Hmac(alg, key, saltLen) {
  54238. var hash = getDigest(alg);
  54239. var blocksize = alg === 'sha512' || alg === 'sha384' ? 128 : 64;
  54240. if (key.length > blocksize) {
  54241. key = hash(key);
  54242. } else if (key.length < blocksize) {
  54243. key = Buffer.concat([key, ZEROS], blocksize);
  54244. }
  54245. var ipad = Buffer.allocUnsafe(blocksize + sizes[alg]);
  54246. var opad = Buffer.allocUnsafe(blocksize + sizes[alg]);
  54247. for (var i = 0; i < blocksize; i++) {
  54248. ipad[i] = key[i] ^ 0x36;
  54249. opad[i] = key[i] ^ 0x5C;
  54250. }
  54251. var ipad1 = Buffer.allocUnsafe(blocksize + saltLen + 4);
  54252. ipad.copy(ipad1, 0, 0, blocksize);
  54253. this.ipad1 = ipad1;
  54254. this.ipad2 = ipad;
  54255. this.opad = opad;
  54256. this.alg = alg;
  54257. this.blocksize = blocksize;
  54258. this.hash = hash;
  54259. this.size = sizes[alg];
  54260. }
  54261. Hmac.prototype.run = function (data, ipad) {
  54262. data.copy(ipad, this.blocksize);
  54263. var h = this.hash(ipad);
  54264. h.copy(this.opad, this.blocksize);
  54265. return this.hash(this.opad);
  54266. };
  54267. function getDigest(alg) {
  54268. function shaFunc(data) {
  54269. return sha(alg).update(data).digest();
  54270. }
  54271. function rmd160Func(data) {
  54272. return new RIPEMD160().update(data).digest();
  54273. }
  54274. if (alg === 'rmd160' || alg === 'ripemd160') return rmd160Func;
  54275. if (alg === 'md5') return md5;
  54276. return shaFunc;
  54277. }
  54278. function pbkdf2(password, salt, iterations, keylen, digest) {
  54279. checkParameters(iterations, keylen);
  54280. password = toBuffer(password, defaultEncoding, 'Password');
  54281. salt = toBuffer(salt, defaultEncoding, 'Salt');
  54282. digest = digest || 'sha1';
  54283. var hmac = new Hmac(digest, password, salt.length);
  54284. var DK = Buffer.allocUnsafe(keylen);
  54285. var block1 = Buffer.allocUnsafe(salt.length + 4);
  54286. salt.copy(block1, 0, 0, salt.length);
  54287. var destPos = 0;
  54288. var hLen = sizes[digest];
  54289. var l = Math.ceil(keylen / hLen);
  54290. for (var i = 1; i <= l; i++) {
  54291. block1.writeUInt32BE(i, salt.length);
  54292. var T = hmac.run(block1, hmac.ipad1);
  54293. var U = T;
  54294. for (var j = 1; j < iterations; j++) {
  54295. U = hmac.run(U, hmac.ipad2);
  54296. for (var k = 0; k < hLen; k++) {
  54297. T[k] ^= U[k];
  54298. }
  54299. }
  54300. T.copy(DK, destPos);
  54301. destPos += hLen;
  54302. }
  54303. return DK;
  54304. }
  54305. module.exports = pbkdf2;
  54306. },{"./default-encoding":353,"./precondition":354,"./to-buffer":356,"create-hash/md5":223,"ripemd160":383,"safe-buffer":384,"sha.js":389}],356:[function(require,module,exports){
  54307. "use strict";
  54308. var Buffer = require('safe-buffer').Buffer;
  54309. module.exports = function (thing, encoding, name) {
  54310. if (Buffer.isBuffer(thing)) {
  54311. return thing;
  54312. } else if (typeof thing === 'string') {
  54313. return Buffer.from(thing, encoding);
  54314. } else if (ArrayBuffer.isView(thing)) {
  54315. return Buffer.from(thing.buffer);
  54316. } else {
  54317. throw new TypeError(name + ' must be a string, a Buffer, a typed array or a DataView');
  54318. }
  54319. };
  54320. },{"safe-buffer":384}],357:[function(require,module,exports){
  54321. (function (process){
  54322. 'use strict';
  54323. if (typeof process === 'undefined' || !process.version || process.version.indexOf('v0.') === 0 || process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
  54324. module.exports = {
  54325. nextTick: nextTick
  54326. };
  54327. } else {
  54328. module.exports = process;
  54329. }
  54330. function nextTick(fn, arg1, arg2, arg3) {
  54331. if (typeof fn !== 'function') {
  54332. throw new TypeError('"callback" argument must be a function');
  54333. }
  54334. var len = arguments.length;
  54335. var args, i;
  54336. switch (len) {
  54337. case 0:
  54338. case 1:
  54339. return process.nextTick(fn);
  54340. case 2:
  54341. return process.nextTick(function afterTickOne() {
  54342. fn.call(null, arg1);
  54343. });
  54344. case 3:
  54345. return process.nextTick(function afterTickTwo() {
  54346. fn.call(null, arg1, arg2);
  54347. });
  54348. case 4:
  54349. return process.nextTick(function afterTickThree() {
  54350. fn.call(null, arg1, arg2, arg3);
  54351. });
  54352. default:
  54353. args = new Array(len - 1);
  54354. i = 0;
  54355. while (i < args.length) {
  54356. args[i++] = arguments[i];
  54357. }
  54358. return process.nextTick(function afterTick() {
  54359. fn.apply(null, args);
  54360. });
  54361. }
  54362. }
  54363. }).call(this,require('_process'))
  54364. },{"_process":358}],358:[function(require,module,exports){
  54365. "use strict";
  54366. // shim for using process in browser
  54367. var process = module.exports = {}; // cached from whatever global is present so that test runners that stub it
  54368. // don't break things. But we need to wrap it in a try catch in case it is
  54369. // wrapped in strict mode code which doesn't define any globals. It's inside a
  54370. // function because try/catches deoptimize in certain engines.
  54371. var cachedSetTimeout;
  54372. var cachedClearTimeout;
  54373. function defaultSetTimout() {
  54374. throw new Error('setTimeout has not been defined');
  54375. }
  54376. function defaultClearTimeout() {
  54377. throw new Error('clearTimeout has not been defined');
  54378. }
  54379. (function () {
  54380. try {
  54381. if (typeof setTimeout === 'function') {
  54382. cachedSetTimeout = setTimeout;
  54383. } else {
  54384. cachedSetTimeout = defaultSetTimout;
  54385. }
  54386. } catch (e) {
  54387. cachedSetTimeout = defaultSetTimout;
  54388. }
  54389. try {
  54390. if (typeof clearTimeout === 'function') {
  54391. cachedClearTimeout = clearTimeout;
  54392. } else {
  54393. cachedClearTimeout = defaultClearTimeout;
  54394. }
  54395. } catch (e) {
  54396. cachedClearTimeout = defaultClearTimeout;
  54397. }
  54398. })();
  54399. function runTimeout(fun) {
  54400. if (cachedSetTimeout === setTimeout) {
  54401. //normal enviroments in sane situations
  54402. return setTimeout(fun, 0);
  54403. } // if setTimeout wasn't available but was latter defined
  54404. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  54405. cachedSetTimeout = setTimeout;
  54406. return setTimeout(fun, 0);
  54407. }
  54408. try {
  54409. // when when somebody has screwed with setTimeout but no I.E. maddness
  54410. return cachedSetTimeout(fun, 0);
  54411. } catch (e) {
  54412. try {
  54413. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  54414. return cachedSetTimeout.call(null, fun, 0);
  54415. } catch (e) {
  54416. // 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
  54417. return cachedSetTimeout.call(this, fun, 0);
  54418. }
  54419. }
  54420. }
  54421. function runClearTimeout(marker) {
  54422. if (cachedClearTimeout === clearTimeout) {
  54423. //normal enviroments in sane situations
  54424. return clearTimeout(marker);
  54425. } // if clearTimeout wasn't available but was latter defined
  54426. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  54427. cachedClearTimeout = clearTimeout;
  54428. return clearTimeout(marker);
  54429. }
  54430. try {
  54431. // when when somebody has screwed with setTimeout but no I.E. maddness
  54432. return cachedClearTimeout(marker);
  54433. } catch (e) {
  54434. try {
  54435. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  54436. return cachedClearTimeout.call(null, marker);
  54437. } catch (e) {
  54438. // 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.
  54439. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  54440. return cachedClearTimeout.call(this, marker);
  54441. }
  54442. }
  54443. }
  54444. var queue = [];
  54445. var draining = false;
  54446. var currentQueue;
  54447. var queueIndex = -1;
  54448. function cleanUpNextTick() {
  54449. if (!draining || !currentQueue) {
  54450. return;
  54451. }
  54452. draining = false;
  54453. if (currentQueue.length) {
  54454. queue = currentQueue.concat(queue);
  54455. } else {
  54456. queueIndex = -1;
  54457. }
  54458. if (queue.length) {
  54459. drainQueue();
  54460. }
  54461. }
  54462. function drainQueue() {
  54463. if (draining) {
  54464. return;
  54465. }
  54466. var timeout = runTimeout(cleanUpNextTick);
  54467. draining = true;
  54468. var len = queue.length;
  54469. while (len) {
  54470. currentQueue = queue;
  54471. queue = [];
  54472. while (++queueIndex < len) {
  54473. if (currentQueue) {
  54474. currentQueue[queueIndex].run();
  54475. }
  54476. }
  54477. queueIndex = -1;
  54478. len = queue.length;
  54479. }
  54480. currentQueue = null;
  54481. draining = false;
  54482. runClearTimeout(timeout);
  54483. }
  54484. process.nextTick = function (fun) {
  54485. var args = new Array(arguments.length - 1);
  54486. if (arguments.length > 1) {
  54487. for (var i = 1; i < arguments.length; i++) {
  54488. args[i - 1] = arguments[i];
  54489. }
  54490. }
  54491. queue.push(new Item(fun, args));
  54492. if (queue.length === 1 && !draining) {
  54493. runTimeout(drainQueue);
  54494. }
  54495. }; // v8 likes predictible objects
  54496. function Item(fun, array) {
  54497. this.fun = fun;
  54498. this.array = array;
  54499. }
  54500. Item.prototype.run = function () {
  54501. this.fun.apply(null, this.array);
  54502. };
  54503. process.title = 'browser';
  54504. process.browser = true;
  54505. process.env = {};
  54506. process.argv = [];
  54507. process.version = ''; // empty string to avoid regexp issues
  54508. process.versions = {};
  54509. function noop() {}
  54510. process.on = noop;
  54511. process.addListener = noop;
  54512. process.once = noop;
  54513. process.off = noop;
  54514. process.removeListener = noop;
  54515. process.removeAllListeners = noop;
  54516. process.emit = noop;
  54517. process.prependListener = noop;
  54518. process.prependOnceListener = noop;
  54519. process.listeners = function (name) {
  54520. return [];
  54521. };
  54522. process.binding = function (name) {
  54523. throw new Error('process.binding is not supported');
  54524. };
  54525. process.cwd = function () {
  54526. return '/';
  54527. };
  54528. process.chdir = function (dir) {
  54529. throw new Error('process.chdir is not supported');
  54530. };
  54531. process.umask = function () {
  54532. return 0;
  54533. };
  54534. },{}],359:[function(require,module,exports){
  54535. "use strict";
  54536. exports.publicEncrypt = require('./publicEncrypt');
  54537. exports.privateDecrypt = require('./privateDecrypt');
  54538. exports.privateEncrypt = function privateEncrypt(key, buf) {
  54539. return exports.publicEncrypt(key, buf, true);
  54540. };
  54541. exports.publicDecrypt = function publicDecrypt(key, buf) {
  54542. return exports.privateDecrypt(key, buf, true);
  54543. };
  54544. },{"./privateDecrypt":362,"./publicEncrypt":363}],360:[function(require,module,exports){
  54545. "use strict";
  54546. var createHash = require('create-hash');
  54547. var Buffer = require('safe-buffer').Buffer;
  54548. module.exports = function (seed, len) {
  54549. var t = Buffer.alloc(0);
  54550. var i = 0;
  54551. var c;
  54552. while (t.length < len) {
  54553. c = i2ops(i++);
  54554. t = Buffer.concat([t, createHash('sha1').update(seed).update(c).digest()]);
  54555. }
  54556. return t.slice(0, len);
  54557. };
  54558. function i2ops(c) {
  54559. var out = Buffer.allocUnsafe(4);
  54560. out.writeUInt32BE(c, 0);
  54561. return out;
  54562. }
  54563. },{"create-hash":222,"safe-buffer":384}],361:[function(require,module,exports){
  54564. arguments[4][181][0].apply(exports,arguments)
  54565. },{"buffer":185,"dup":181}],362:[function(require,module,exports){
  54566. "use strict";
  54567. var parseKeys = require('parse-asn1');
  54568. var mgf = require('./mgf');
  54569. var xor = require('./xor');
  54570. var BN = require('bn.js');
  54571. var crt = require('browserify-rsa');
  54572. var createHash = require('create-hash');
  54573. var withPublic = require('./withPublic');
  54574. var Buffer = require('safe-buffer').Buffer;
  54575. module.exports = function privateDecrypt(privateKey, enc, reverse) {
  54576. var padding;
  54577. if (privateKey.padding) {
  54578. padding = privateKey.padding;
  54579. } else if (reverse) {
  54580. padding = 1;
  54581. } else {
  54582. padding = 4;
  54583. }
  54584. var key = parseKeys(privateKey);
  54585. var k = key.modulus.byteLength();
  54586. if (enc.length > k || new BN(enc).cmp(key.modulus) >= 0) {
  54587. throw new Error('decryption error');
  54588. }
  54589. var msg;
  54590. if (reverse) {
  54591. msg = withPublic(new BN(enc), key);
  54592. } else {
  54593. msg = crt(enc, key);
  54594. }
  54595. var zBuffer = Buffer.alloc(k - msg.length);
  54596. msg = Buffer.concat([zBuffer, msg], k);
  54597. if (padding === 4) {
  54598. return oaep(key, msg);
  54599. } else if (padding === 1) {
  54600. return pkcs1(key, msg, reverse);
  54601. } else if (padding === 3) {
  54602. return msg;
  54603. } else {
  54604. throw new Error('unknown padding');
  54605. }
  54606. };
  54607. function oaep(key, msg) {
  54608. var k = key.modulus.byteLength();
  54609. var iHash = createHash('sha1').update(Buffer.alloc(0)).digest();
  54610. var hLen = iHash.length;
  54611. if (msg[0] !== 0) {
  54612. throw new Error('decryption error');
  54613. }
  54614. var maskedSeed = msg.slice(1, hLen + 1);
  54615. var maskedDb = msg.slice(hLen + 1);
  54616. var seed = xor(maskedSeed, mgf(maskedDb, hLen));
  54617. var db = xor(maskedDb, mgf(seed, k - hLen - 1));
  54618. if (compare(iHash, db.slice(0, hLen))) {
  54619. throw new Error('decryption error');
  54620. }
  54621. var i = hLen;
  54622. while (db[i] === 0) {
  54623. i++;
  54624. }
  54625. if (db[i++] !== 1) {
  54626. throw new Error('decryption error');
  54627. }
  54628. return db.slice(i);
  54629. }
  54630. function pkcs1(key, msg, reverse) {
  54631. var p1 = msg.slice(0, 2);
  54632. var i = 2;
  54633. var status = 0;
  54634. while (msg[i++] !== 0) {
  54635. if (i >= msg.length) {
  54636. status++;
  54637. break;
  54638. }
  54639. }
  54640. var ps = msg.slice(2, i - 1);
  54641. if (p1.toString('hex') !== '0002' && !reverse || p1.toString('hex') !== '0001' && reverse) {
  54642. status++;
  54643. }
  54644. if (ps.length < 8) {
  54645. status++;
  54646. }
  54647. if (status) {
  54648. throw new Error('decryption error');
  54649. }
  54650. return msg.slice(i);
  54651. }
  54652. function compare(a, b) {
  54653. a = Buffer.from(a);
  54654. b = Buffer.from(b);
  54655. var dif = 0;
  54656. var len = a.length;
  54657. if (a.length !== b.length) {
  54658. dif++;
  54659. len = Math.min(a.length, b.length);
  54660. }
  54661. var i = -1;
  54662. while (++i < len) {
  54663. dif += a[i] ^ b[i];
  54664. }
  54665. return dif;
  54666. }
  54667. },{"./mgf":360,"./withPublic":364,"./xor":365,"bn.js":361,"browserify-rsa":206,"create-hash":222,"parse-asn1":350,"safe-buffer":384}],363:[function(require,module,exports){
  54668. "use strict";
  54669. var parseKeys = require('parse-asn1');
  54670. var randomBytes = require('randombytes');
  54671. var createHash = require('create-hash');
  54672. var mgf = require('./mgf');
  54673. var xor = require('./xor');
  54674. var BN = require('bn.js');
  54675. var withPublic = require('./withPublic');
  54676. var crt = require('browserify-rsa');
  54677. var Buffer = require('safe-buffer').Buffer;
  54678. module.exports = function publicEncrypt(publicKey, msg, reverse) {
  54679. var padding;
  54680. if (publicKey.padding) {
  54681. padding = publicKey.padding;
  54682. } else if (reverse) {
  54683. padding = 1;
  54684. } else {
  54685. padding = 4;
  54686. }
  54687. var key = parseKeys(publicKey);
  54688. var paddedMsg;
  54689. if (padding === 4) {
  54690. paddedMsg = oaep(key, msg);
  54691. } else if (padding === 1) {
  54692. paddedMsg = pkcs1(key, msg, reverse);
  54693. } else if (padding === 3) {
  54694. paddedMsg = new BN(msg);
  54695. if (paddedMsg.cmp(key.modulus) >= 0) {
  54696. throw new Error('data too long for modulus');
  54697. }
  54698. } else {
  54699. throw new Error('unknown padding');
  54700. }
  54701. if (reverse) {
  54702. return crt(paddedMsg, key);
  54703. } else {
  54704. return withPublic(paddedMsg, key);
  54705. }
  54706. };
  54707. function oaep(key, msg) {
  54708. var k = key.modulus.byteLength();
  54709. var mLen = msg.length;
  54710. var iHash = createHash('sha1').update(Buffer.alloc(0)).digest();
  54711. var hLen = iHash.length;
  54712. var hLen2 = 2 * hLen;
  54713. if (mLen > k - hLen2 - 2) {
  54714. throw new Error('message too long');
  54715. }
  54716. var ps = Buffer.alloc(k - mLen - hLen2 - 2);
  54717. var dblen = k - hLen - 1;
  54718. var seed = randomBytes(hLen);
  54719. var maskedDb = xor(Buffer.concat([iHash, ps, Buffer.alloc(1, 1), msg], dblen), mgf(seed, dblen));
  54720. var maskedSeed = xor(seed, mgf(maskedDb, hLen));
  54721. return new BN(Buffer.concat([Buffer.alloc(1), maskedSeed, maskedDb], k));
  54722. }
  54723. function pkcs1(key, msg, reverse) {
  54724. var mLen = msg.length;
  54725. var k = key.modulus.byteLength();
  54726. if (mLen > k - 11) {
  54727. throw new Error('message too long');
  54728. }
  54729. var ps;
  54730. if (reverse) {
  54731. ps = Buffer.alloc(k - mLen - 3, 0xff);
  54732. } else {
  54733. ps = nonZero(k - mLen - 3);
  54734. }
  54735. return new BN(Buffer.concat([Buffer.from([0, reverse ? 1 : 2]), ps, Buffer.alloc(1), msg], k));
  54736. }
  54737. function nonZero(len) {
  54738. var out = Buffer.allocUnsafe(len);
  54739. var i = 0;
  54740. var cache = randomBytes(len * 2);
  54741. var cur = 0;
  54742. var num;
  54743. while (i < len) {
  54744. if (cur === cache.length) {
  54745. cache = randomBytes(len * 2);
  54746. cur = 0;
  54747. }
  54748. num = cache[cur++];
  54749. if (num) {
  54750. out[i++] = num;
  54751. }
  54752. }
  54753. return out;
  54754. }
  54755. },{"./mgf":360,"./withPublic":364,"./xor":365,"bn.js":361,"browserify-rsa":206,"create-hash":222,"parse-asn1":350,"randombytes":366,"safe-buffer":384}],364:[function(require,module,exports){
  54756. "use strict";
  54757. var BN = require('bn.js');
  54758. var Buffer = require('safe-buffer').Buffer;
  54759. function withPublic(paddedMsg, key) {
  54760. return Buffer.from(paddedMsg.toRed(BN.mont(key.modulus)).redPow(new BN(key.publicExponent)).fromRed().toArray());
  54761. }
  54762. module.exports = withPublic;
  54763. },{"bn.js":361,"safe-buffer":384}],365:[function(require,module,exports){
  54764. "use strict";
  54765. module.exports = function xor(a, b) {
  54766. var len = a.length;
  54767. var i = -1;
  54768. while (++i < len) {
  54769. a[i] ^= b[i];
  54770. }
  54771. return a;
  54772. };
  54773. },{}],366:[function(require,module,exports){
  54774. (function (process,global){
  54775. 'use strict'; // limit of Crypto.getRandomValues()
  54776. // https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
  54777. var MAX_BYTES = 65536; // Node supports requesting up to this number of bytes
  54778. // https://github.com/nodejs/node/blob/master/lib/internal/crypto/random.js#L48
  54779. var MAX_UINT32 = 4294967295;
  54780. function oldBrowser() {
  54781. throw new Error('Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11');
  54782. }
  54783. var Buffer = require('safe-buffer').Buffer;
  54784. var crypto = global.crypto || global.msCrypto;
  54785. if (crypto && crypto.getRandomValues) {
  54786. module.exports = randomBytes;
  54787. } else {
  54788. module.exports = oldBrowser;
  54789. }
  54790. function randomBytes(size, cb) {
  54791. // phantomjs needs to throw
  54792. if (size > MAX_UINT32) throw new RangeError('requested too many random bytes');
  54793. var bytes = Buffer.allocUnsafe(size);
  54794. if (size > 0) {
  54795. // getRandomValues fails on IE if size == 0
  54796. if (size > MAX_BYTES) {
  54797. // this is the max bytes crypto.getRandomValues
  54798. // can do at once see https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
  54799. for (var generated = 0; generated < size; generated += MAX_BYTES) {
  54800. // buffer.slice automatically checks if the end is past the end of
  54801. // the buffer so we don't have to here
  54802. crypto.getRandomValues(bytes.slice(generated, generated + MAX_BYTES));
  54803. }
  54804. } else {
  54805. crypto.getRandomValues(bytes);
  54806. }
  54807. }
  54808. if (typeof cb === 'function') {
  54809. return process.nextTick(function () {
  54810. cb(null, bytes);
  54811. });
  54812. }
  54813. return bytes;
  54814. }
  54815. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  54816. },{"_process":358,"safe-buffer":384}],367:[function(require,module,exports){
  54817. (function (process,global){
  54818. 'use strict';
  54819. function oldBrowser() {
  54820. throw new Error('secure random number generation not supported by this browser\nuse chrome, FireFox or Internet Explorer 11');
  54821. }
  54822. var safeBuffer = require('safe-buffer');
  54823. var randombytes = require('randombytes');
  54824. var Buffer = safeBuffer.Buffer;
  54825. var kBufferMaxLength = safeBuffer.kMaxLength;
  54826. var crypto = global.crypto || global.msCrypto;
  54827. var kMaxUint32 = Math.pow(2, 32) - 1;
  54828. function assertOffset(offset, length) {
  54829. if (typeof offset !== 'number' || offset !== offset) {
  54830. // eslint-disable-line no-self-compare
  54831. throw new TypeError('offset must be a number');
  54832. }
  54833. if (offset > kMaxUint32 || offset < 0) {
  54834. throw new TypeError('offset must be a uint32');
  54835. }
  54836. if (offset > kBufferMaxLength || offset > length) {
  54837. throw new RangeError('offset out of range');
  54838. }
  54839. }
  54840. function assertSize(size, offset, length) {
  54841. if (typeof size !== 'number' || size !== size) {
  54842. // eslint-disable-line no-self-compare
  54843. throw new TypeError('size must be a number');
  54844. }
  54845. if (size > kMaxUint32 || size < 0) {
  54846. throw new TypeError('size must be a uint32');
  54847. }
  54848. if (size + offset > length || size > kBufferMaxLength) {
  54849. throw new RangeError('buffer too small');
  54850. }
  54851. }
  54852. if (crypto && crypto.getRandomValues || !process.browser) {
  54853. exports.randomFill = randomFill;
  54854. exports.randomFillSync = randomFillSync;
  54855. } else {
  54856. exports.randomFill = oldBrowser;
  54857. exports.randomFillSync = oldBrowser;
  54858. }
  54859. function randomFill(buf, offset, size, cb) {
  54860. if (!Buffer.isBuffer(buf) && !(buf instanceof global.Uint8Array)) {
  54861. throw new TypeError('"buf" argument must be a Buffer or Uint8Array');
  54862. }
  54863. if (typeof offset === 'function') {
  54864. cb = offset;
  54865. offset = 0;
  54866. size = buf.length;
  54867. } else if (typeof size === 'function') {
  54868. cb = size;
  54869. size = buf.length - offset;
  54870. } else if (typeof cb !== 'function') {
  54871. throw new TypeError('"cb" argument must be a function');
  54872. }
  54873. assertOffset(offset, buf.length);
  54874. assertSize(size, offset, buf.length);
  54875. return actualFill(buf, offset, size, cb);
  54876. }
  54877. function actualFill(buf, offset, size, cb) {
  54878. if (process.browser) {
  54879. var ourBuf = buf.buffer;
  54880. var uint = new Uint8Array(ourBuf, offset, size);
  54881. crypto.getRandomValues(uint);
  54882. if (cb) {
  54883. process.nextTick(function () {
  54884. cb(null, buf);
  54885. });
  54886. return;
  54887. }
  54888. return buf;
  54889. }
  54890. if (cb) {
  54891. randombytes(size, function (err, bytes) {
  54892. if (err) {
  54893. return cb(err);
  54894. }
  54895. bytes.copy(buf, offset);
  54896. cb(null, buf);
  54897. });
  54898. return;
  54899. }
  54900. var bytes = randombytes(size);
  54901. bytes.copy(buf, offset);
  54902. return buf;
  54903. }
  54904. function randomFillSync(buf, offset, size) {
  54905. if (typeof offset === 'undefined') {
  54906. offset = 0;
  54907. }
  54908. if (!Buffer.isBuffer(buf) && !(buf instanceof global.Uint8Array)) {
  54909. throw new TypeError('"buf" argument must be a Buffer or Uint8Array');
  54910. }
  54911. assertOffset(offset, buf.length);
  54912. if (size === undefined) size = buf.length - offset;
  54913. assertSize(size, offset, buf.length);
  54914. return actualFill(buf, offset, size);
  54915. }
  54916. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  54917. },{"_process":358,"randombytes":366,"safe-buffer":384}],368:[function(require,module,exports){
  54918. 'use strict';
  54919. 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); }
  54920. function _inheritsLoose(subClass, superClass) {
  54921. subClass.prototype = Object.create(superClass.prototype);
  54922. subClass.prototype.constructor = subClass;
  54923. subClass.__proto__ = superClass;
  54924. }
  54925. var codes = {};
  54926. function createErrorType(code, message, Base) {
  54927. if (!Base) {
  54928. Base = Error;
  54929. }
  54930. function getMessage(arg1, arg2, arg3) {
  54931. if (typeof message === 'string') {
  54932. return message;
  54933. } else {
  54934. return message(arg1, arg2, arg3);
  54935. }
  54936. }
  54937. var NodeError = /*#__PURE__*/function (_Base) {
  54938. _inheritsLoose(NodeError, _Base);
  54939. function NodeError(arg1, arg2, arg3) {
  54940. return _Base.call(this, getMessage(arg1, arg2, arg3)) || this;
  54941. }
  54942. return NodeError;
  54943. }(Base);
  54944. NodeError.prototype.name = Base.name;
  54945. NodeError.prototype.code = code;
  54946. codes[code] = NodeError;
  54947. } // https://github.com/nodejs/node/blob/v10.8.0/lib/internal/errors.js
  54948. function oneOf(expected, thing) {
  54949. if (Array.isArray(expected)) {
  54950. var len = expected.length;
  54951. expected = expected.map(function (i) {
  54952. return String(i);
  54953. });
  54954. if (len > 2) {
  54955. return "one of ".concat(thing, " ").concat(expected.slice(0, len - 1).join(', '), ", or ") + expected[len - 1];
  54956. } else if (len === 2) {
  54957. return "one of ".concat(thing, " ").concat(expected[0], " or ").concat(expected[1]);
  54958. } else {
  54959. return "of ".concat(thing, " ").concat(expected[0]);
  54960. }
  54961. } else {
  54962. return "of ".concat(thing, " ").concat(String(expected));
  54963. }
  54964. } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
  54965. function startsWith(str, search, pos) {
  54966. return str.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;
  54967. } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
  54968. function endsWith(str, search, this_len) {
  54969. if (this_len === undefined || this_len > str.length) {
  54970. this_len = str.length;
  54971. }
  54972. return str.substring(this_len - search.length, this_len) === search;
  54973. } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes
  54974. function includes(str, search, start) {
  54975. if (typeof start !== 'number') {
  54976. start = 0;
  54977. }
  54978. if (start + search.length > str.length) {
  54979. return false;
  54980. } else {
  54981. return str.indexOf(search, start) !== -1;
  54982. }
  54983. }
  54984. createErrorType('ERR_INVALID_OPT_VALUE', function (name, value) {
  54985. return 'The value "' + value + '" is invalid for option "' + name + '"';
  54986. }, TypeError);
  54987. createErrorType('ERR_INVALID_ARG_TYPE', function (name, expected, actual) {
  54988. // determiner: 'must be' or 'must not be'
  54989. var determiner;
  54990. if (typeof expected === 'string' && startsWith(expected, 'not ')) {
  54991. determiner = 'must not be';
  54992. expected = expected.replace(/^not /, '');
  54993. } else {
  54994. determiner = 'must be';
  54995. }
  54996. var msg;
  54997. if (endsWith(name, ' argument')) {
  54998. // For cases like 'first argument'
  54999. msg = "The ".concat(name, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
  55000. } else {
  55001. var type = includes(name, '.') ? 'property' : 'argument';
  55002. msg = "The \"".concat(name, "\" ").concat(type, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
  55003. }
  55004. msg += ". Received type ".concat(_typeof(actual));
  55005. return msg;
  55006. }, TypeError);
  55007. createErrorType('ERR_STREAM_PUSH_AFTER_EOF', 'stream.push() after EOF');
  55008. createErrorType('ERR_METHOD_NOT_IMPLEMENTED', function (name) {
  55009. return 'The ' + name + ' method is not implemented';
  55010. });
  55011. createErrorType('ERR_STREAM_PREMATURE_CLOSE', 'Premature close');
  55012. createErrorType('ERR_STREAM_DESTROYED', function (name) {
  55013. return 'Cannot call ' + name + ' after a stream was destroyed';
  55014. });
  55015. createErrorType('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times');
  55016. createErrorType('ERR_STREAM_CANNOT_PIPE', 'Cannot pipe, not readable');
  55017. createErrorType('ERR_STREAM_WRITE_AFTER_END', 'write after end');
  55018. createErrorType('ERR_STREAM_NULL_VALUES', 'May not write null values to stream', TypeError);
  55019. createErrorType('ERR_UNKNOWN_ENCODING', function (arg) {
  55020. return 'Unknown encoding: ' + arg;
  55021. }, TypeError);
  55022. createErrorType('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event');
  55023. module.exports.codes = codes;
  55024. },{}],369:[function(require,module,exports){
  55025. (function (process){
  55026. // Copyright Joyent, Inc. and other Node contributors.
  55027. //
  55028. // Permission is hereby granted, free of charge, to any person obtaining a
  55029. // copy of this software and associated documentation files (the
  55030. // "Software"), to deal in the Software without restriction, including
  55031. // without limitation the rights to use, copy, modify, merge, publish,
  55032. // distribute, sublicense, and/or sell copies of the Software, and to permit
  55033. // persons to whom the Software is furnished to do so, subject to the
  55034. // following conditions:
  55035. //
  55036. // The above copyright notice and this permission notice shall be included
  55037. // in all copies or substantial portions of the Software.
  55038. //
  55039. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  55040. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  55041. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  55042. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  55043. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  55044. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  55045. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  55046. // a duplex stream is just a stream that is both readable and writable.
  55047. // Since JS doesn't have multiple prototypal inheritance, this class
  55048. // prototypally inherits from Readable, and then parasitically from
  55049. // Writable.
  55050. 'use strict';
  55051. /*<replacement>*/
  55052. var objectKeys = Object.keys || function (obj) {
  55053. var keys = [];
  55054. for (var key in obj) {
  55055. keys.push(key);
  55056. }
  55057. return keys;
  55058. };
  55059. /*</replacement>*/
  55060. module.exports = Duplex;
  55061. var Readable = require('./_stream_readable');
  55062. var Writable = require('./_stream_writable');
  55063. require('inherits')(Duplex, Readable);
  55064. {
  55065. // Allow the keys array to be GC'ed.
  55066. var keys = objectKeys(Writable.prototype);
  55067. for (var v = 0; v < keys.length; v++) {
  55068. var method = keys[v];
  55069. if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
  55070. }
  55071. }
  55072. function Duplex(options) {
  55073. if (!(this instanceof Duplex)) return new Duplex(options);
  55074. Readable.call(this, options);
  55075. Writable.call(this, options);
  55076. this.allowHalfOpen = true;
  55077. if (options) {
  55078. if (options.readable === false) this.readable = false;
  55079. if (options.writable === false) this.writable = false;
  55080. if (options.allowHalfOpen === false) {
  55081. this.allowHalfOpen = false;
  55082. this.once('end', onend);
  55083. }
  55084. }
  55085. }
  55086. Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
  55087. // making it explicit this property is not enumerable
  55088. // because otherwise some prototype manipulation in
  55089. // userland will fail
  55090. enumerable: false,
  55091. get: function get() {
  55092. return this._writableState.highWaterMark;
  55093. }
  55094. });
  55095. Object.defineProperty(Duplex.prototype, 'writableBuffer', {
  55096. // making it explicit this property is not enumerable
  55097. // because otherwise some prototype manipulation in
  55098. // userland will fail
  55099. enumerable: false,
  55100. get: function get() {
  55101. return this._writableState && this._writableState.getBuffer();
  55102. }
  55103. });
  55104. Object.defineProperty(Duplex.prototype, 'writableLength', {
  55105. // making it explicit this property is not enumerable
  55106. // because otherwise some prototype manipulation in
  55107. // userland will fail
  55108. enumerable: false,
  55109. get: function get() {
  55110. return this._writableState.length;
  55111. }
  55112. }); // the no-half-open enforcer
  55113. function onend() {
  55114. // If the writable side ended, then we're ok.
  55115. if (this._writableState.ended) return; // no more data can be written.
  55116. // But allow more writes to happen in this tick.
  55117. process.nextTick(onEndNT, this);
  55118. }
  55119. function onEndNT(self) {
  55120. self.end();
  55121. }
  55122. Object.defineProperty(Duplex.prototype, 'destroyed', {
  55123. // making it explicit this property is not enumerable
  55124. // because otherwise some prototype manipulation in
  55125. // userland will fail
  55126. enumerable: false,
  55127. get: function get() {
  55128. if (this._readableState === undefined || this._writableState === undefined) {
  55129. return false;
  55130. }
  55131. return this._readableState.destroyed && this._writableState.destroyed;
  55132. },
  55133. set: function set(value) {
  55134. // we ignore the value if the stream
  55135. // has not been initialized yet
  55136. if (this._readableState === undefined || this._writableState === undefined) {
  55137. return;
  55138. } // backward compatibility, the user is explicitly
  55139. // managing destroyed
  55140. this._readableState.destroyed = value;
  55141. this._writableState.destroyed = value;
  55142. }
  55143. });
  55144. }).call(this,require('_process'))
  55145. },{"./_stream_readable":371,"./_stream_writable":373,"_process":358,"inherits":278}],370:[function(require,module,exports){
  55146. // Copyright Joyent, Inc. and other Node contributors.
  55147. //
  55148. // Permission is hereby granted, free of charge, to any person obtaining a
  55149. // copy of this software and associated documentation files (the
  55150. // "Software"), to deal in the Software without restriction, including
  55151. // without limitation the rights to use, copy, modify, merge, publish,
  55152. // distribute, sublicense, and/or sell copies of the Software, and to permit
  55153. // persons to whom the Software is furnished to do so, subject to the
  55154. // following conditions:
  55155. //
  55156. // The above copyright notice and this permission notice shall be included
  55157. // in all copies or substantial portions of the Software.
  55158. //
  55159. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  55160. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  55161. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  55162. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  55163. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  55164. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  55165. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  55166. // a passthrough stream.
  55167. // basically just the most minimal sort of Transform stream.
  55168. // Every written chunk gets output as-is.
  55169. 'use strict';
  55170. module.exports = PassThrough;
  55171. var Transform = require('./_stream_transform');
  55172. require('inherits')(PassThrough, Transform);
  55173. function PassThrough(options) {
  55174. if (!(this instanceof PassThrough)) return new PassThrough(options);
  55175. Transform.call(this, options);
  55176. }
  55177. PassThrough.prototype._transform = function (chunk, encoding, cb) {
  55178. cb(null, chunk);
  55179. };
  55180. },{"./_stream_transform":372,"inherits":278}],371:[function(require,module,exports){
  55181. (function (process,global){
  55182. // Copyright Joyent, Inc. and other Node contributors.
  55183. //
  55184. // Permission is hereby granted, free of charge, to any person obtaining a
  55185. // copy of this software and associated documentation files (the
  55186. // "Software"), to deal in the Software without restriction, including
  55187. // without limitation the rights to use, copy, modify, merge, publish,
  55188. // distribute, sublicense, and/or sell copies of the Software, and to permit
  55189. // persons to whom the Software is furnished to do so, subject to the
  55190. // following conditions:
  55191. //
  55192. // The above copyright notice and this permission notice shall be included
  55193. // in all copies or substantial portions of the Software.
  55194. //
  55195. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  55196. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  55197. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  55198. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  55199. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  55200. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  55201. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  55202. 'use strict';
  55203. module.exports = Readable;
  55204. /*<replacement>*/
  55205. var Duplex;
  55206. /*</replacement>*/
  55207. Readable.ReadableState = ReadableState;
  55208. /*<replacement>*/
  55209. var EE = require('events').EventEmitter;
  55210. var EElistenerCount = function EElistenerCount(emitter, type) {
  55211. return emitter.listeners(type).length;
  55212. };
  55213. /*</replacement>*/
  55214. /*<replacement>*/
  55215. var Stream = require('./internal/streams/stream');
  55216. /*</replacement>*/
  55217. var Buffer = require('buffer').Buffer;
  55218. var OurUint8Array = global.Uint8Array || function () {};
  55219. function _uint8ArrayToBuffer(chunk) {
  55220. return Buffer.from(chunk);
  55221. }
  55222. function _isUint8Array(obj) {
  55223. return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
  55224. }
  55225. /*<replacement>*/
  55226. var debugUtil = require('util');
  55227. var debug;
  55228. if (debugUtil && debugUtil.debuglog) {
  55229. debug = debugUtil.debuglog('stream');
  55230. } else {
  55231. debug = function debug() {};
  55232. }
  55233. /*</replacement>*/
  55234. var BufferList = require('./internal/streams/buffer_list');
  55235. var destroyImpl = require('./internal/streams/destroy');
  55236. var _require = require('./internal/streams/state'),
  55237. getHighWaterMark = _require.getHighWaterMark;
  55238. var _require$codes = require('../errors').codes,
  55239. ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
  55240. ERR_STREAM_PUSH_AFTER_EOF = _require$codes.ERR_STREAM_PUSH_AFTER_EOF,
  55241. ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
  55242. ERR_STREAM_UNSHIFT_AFTER_END_EVENT = _require$codes.ERR_STREAM_UNSHIFT_AFTER_END_EVENT; // Lazy loaded to improve the startup performance.
  55243. var StringDecoder;
  55244. var createReadableStreamAsyncIterator;
  55245. var from;
  55246. require('inherits')(Readable, Stream);
  55247. var errorOrDestroy = destroyImpl.errorOrDestroy;
  55248. var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
  55249. function prependListener(emitter, event, fn) {
  55250. // Sadly this is not cacheable as some libraries bundle their own
  55251. // event emitter implementation with them.
  55252. 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
  55253. // userland ones. NEVER DO THIS. This is here only because this code needs
  55254. // to continue to work with older versions of Node.js that do not include
  55255. // the prependListener() method. The goal is to eventually remove this hack.
  55256. 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]];
  55257. }
  55258. function ReadableState(options, stream, isDuplex) {
  55259. Duplex = Duplex || require('./_stream_duplex');
  55260. options = options || {}; // Duplex streams are both readable and writable, but share
  55261. // the same options object.
  55262. // However, some cases require setting options to different
  55263. // values for the readable and the writable sides of the duplex stream.
  55264. // These options can be provided separately as readableXXX and writableXXX.
  55265. if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex; // object stream flag. Used to make read(n) ignore n and to
  55266. // make all the buffer merging and length checks go away
  55267. this.objectMode = !!options.objectMode;
  55268. if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode; // the point at which it stops calling _read() to fill the buffer
  55269. // Note: 0 is a valid value, means "don't call _read preemptively ever"
  55270. this.highWaterMark = getHighWaterMark(this, options, 'readableHighWaterMark', isDuplex); // A linked list is used to store data chunks instead of an array because the
  55271. // linked list can remove elements from the beginning faster than
  55272. // array.shift()
  55273. this.buffer = new BufferList();
  55274. this.length = 0;
  55275. this.pipes = null;
  55276. this.pipesCount = 0;
  55277. this.flowing = null;
  55278. this.ended = false;
  55279. this.endEmitted = false;
  55280. this.reading = false; // a flag to be able to tell if the event 'readable'/'data' is emitted
  55281. // immediately, or on a later tick. We set this to true at first, because
  55282. // any actions that shouldn't happen until "later" should generally also
  55283. // not happen before the first read call.
  55284. this.sync = true; // whenever we return null, then we set a flag to say
  55285. // that we're awaiting a 'readable' event emission.
  55286. this.needReadable = false;
  55287. this.emittedReadable = false;
  55288. this.readableListening = false;
  55289. this.resumeScheduled = false;
  55290. this.paused = true; // Should close be emitted on destroy. Defaults to true.
  55291. this.emitClose = options.emitClose !== false; // Should .destroy() be called after 'end' (and potentially 'finish')
  55292. this.autoDestroy = !!options.autoDestroy; // has it been destroyed
  55293. this.destroyed = false; // Crypto is kind of old and crusty. Historically, its default string
  55294. // encoding is 'binary' so we have to make this configurable.
  55295. // Everything else in the universe uses 'utf8', though.
  55296. this.defaultEncoding = options.defaultEncoding || 'utf8'; // the number of writers that are awaiting a drain event in .pipe()s
  55297. this.awaitDrain = 0; // if true, a maybeReadMore has been scheduled
  55298. this.readingMore = false;
  55299. this.decoder = null;
  55300. this.encoding = null;
  55301. if (options.encoding) {
  55302. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  55303. this.decoder = new StringDecoder(options.encoding);
  55304. this.encoding = options.encoding;
  55305. }
  55306. }
  55307. function Readable(options) {
  55308. Duplex = Duplex || require('./_stream_duplex');
  55309. if (!(this instanceof Readable)) return new Readable(options); // Checking for a Stream.Duplex instance is faster here instead of inside
  55310. // the ReadableState constructor, at least with V8 6.5
  55311. var isDuplex = this instanceof Duplex;
  55312. this._readableState = new ReadableState(options, this, isDuplex); // legacy
  55313. this.readable = true;
  55314. if (options) {
  55315. if (typeof options.read === 'function') this._read = options.read;
  55316. if (typeof options.destroy === 'function') this._destroy = options.destroy;
  55317. }
  55318. Stream.call(this);
  55319. }
  55320. Object.defineProperty(Readable.prototype, 'destroyed', {
  55321. // making it explicit this property is not enumerable
  55322. // because otherwise some prototype manipulation in
  55323. // userland will fail
  55324. enumerable: false,
  55325. get: function get() {
  55326. if (this._readableState === undefined) {
  55327. return false;
  55328. }
  55329. return this._readableState.destroyed;
  55330. },
  55331. set: function set(value) {
  55332. // we ignore the value if the stream
  55333. // has not been initialized yet
  55334. if (!this._readableState) {
  55335. return;
  55336. } // backward compatibility, the user is explicitly
  55337. // managing destroyed
  55338. this._readableState.destroyed = value;
  55339. }
  55340. });
  55341. Readable.prototype.destroy = destroyImpl.destroy;
  55342. Readable.prototype._undestroy = destroyImpl.undestroy;
  55343. Readable.prototype._destroy = function (err, cb) {
  55344. cb(err);
  55345. }; // Manually shove something into the read() buffer.
  55346. // This returns true if the highWaterMark has not been hit yet,
  55347. // similar to how Writable.write() returns true if you should
  55348. // write() some more.
  55349. Readable.prototype.push = function (chunk, encoding) {
  55350. var state = this._readableState;
  55351. var skipChunkCheck;
  55352. if (!state.objectMode) {
  55353. if (typeof chunk === 'string') {
  55354. encoding = encoding || state.defaultEncoding;
  55355. if (encoding !== state.encoding) {
  55356. chunk = Buffer.from(chunk, encoding);
  55357. encoding = '';
  55358. }
  55359. skipChunkCheck = true;
  55360. }
  55361. } else {
  55362. skipChunkCheck = true;
  55363. }
  55364. return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
  55365. }; // Unshift should *always* be something directly out of read()
  55366. Readable.prototype.unshift = function (chunk) {
  55367. return readableAddChunk(this, chunk, null, true, false);
  55368. };
  55369. function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
  55370. debug('readableAddChunk', chunk);
  55371. var state = stream._readableState;
  55372. if (chunk === null) {
  55373. state.reading = false;
  55374. onEofChunk(stream, state);
  55375. } else {
  55376. var er;
  55377. if (!skipChunkCheck) er = chunkInvalid(state, chunk);
  55378. if (er) {
  55379. errorOrDestroy(stream, er);
  55380. } else if (state.objectMode || chunk && chunk.length > 0) {
  55381. if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
  55382. chunk = _uint8ArrayToBuffer(chunk);
  55383. }
  55384. if (addToFront) {
  55385. if (state.endEmitted) errorOrDestroy(stream, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());else addChunk(stream, state, chunk, true);
  55386. } else if (state.ended) {
  55387. errorOrDestroy(stream, new ERR_STREAM_PUSH_AFTER_EOF());
  55388. } else if (state.destroyed) {
  55389. return false;
  55390. } else {
  55391. state.reading = false;
  55392. if (state.decoder && !encoding) {
  55393. chunk = state.decoder.write(chunk);
  55394. if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
  55395. } else {
  55396. addChunk(stream, state, chunk, false);
  55397. }
  55398. }
  55399. } else if (!addToFront) {
  55400. state.reading = false;
  55401. maybeReadMore(stream, state);
  55402. }
  55403. } // We can push more data if we are below the highWaterMark.
  55404. // Also, if we have no data yet, we can stand some more bytes.
  55405. // This is to work around cases where hwm=0, such as the repl.
  55406. return !state.ended && (state.length < state.highWaterMark || state.length === 0);
  55407. }
  55408. function addChunk(stream, state, chunk, addToFront) {
  55409. if (state.flowing && state.length === 0 && !state.sync) {
  55410. state.awaitDrain = 0;
  55411. stream.emit('data', chunk);
  55412. } else {
  55413. // update the buffer info.
  55414. state.length += state.objectMode ? 1 : chunk.length;
  55415. if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
  55416. if (state.needReadable) emitReadable(stream);
  55417. }
  55418. maybeReadMore(stream, state);
  55419. }
  55420. function chunkInvalid(state, chunk) {
  55421. var er;
  55422. if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
  55423. er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer', 'Uint8Array'], chunk);
  55424. }
  55425. return er;
  55426. }
  55427. Readable.prototype.isPaused = function () {
  55428. return this._readableState.flowing === false;
  55429. }; // backwards compatibility.
  55430. Readable.prototype.setEncoding = function (enc) {
  55431. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  55432. var decoder = new StringDecoder(enc);
  55433. this._readableState.decoder = decoder; // If setEncoding(null), decoder.encoding equals utf8
  55434. this._readableState.encoding = this._readableState.decoder.encoding; // Iterate over current buffer to convert already stored Buffers:
  55435. var p = this._readableState.buffer.head;
  55436. var content = '';
  55437. while (p !== null) {
  55438. content += decoder.write(p.data);
  55439. p = p.next;
  55440. }
  55441. this._readableState.buffer.clear();
  55442. if (content !== '') this._readableState.buffer.push(content);
  55443. this._readableState.length = content.length;
  55444. return this;
  55445. }; // Don't raise the hwm > 1GB
  55446. var MAX_HWM = 0x40000000;
  55447. function computeNewHighWaterMark(n) {
  55448. if (n >= MAX_HWM) {
  55449. // TODO(ronag): Throw ERR_VALUE_OUT_OF_RANGE.
  55450. n = MAX_HWM;
  55451. } else {
  55452. // Get the next highest power of 2 to prevent increasing hwm excessively in
  55453. // tiny amounts
  55454. n--;
  55455. n |= n >>> 1;
  55456. n |= n >>> 2;
  55457. n |= n >>> 4;
  55458. n |= n >>> 8;
  55459. n |= n >>> 16;
  55460. n++;
  55461. }
  55462. return n;
  55463. } // This function is designed to be inlinable, so please take care when making
  55464. // changes to the function body.
  55465. function howMuchToRead(n, state) {
  55466. if (n <= 0 || state.length === 0 && state.ended) return 0;
  55467. if (state.objectMode) return 1;
  55468. if (n !== n) {
  55469. // Only flow one buffer at a time
  55470. if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
  55471. } // If we're asking for more than the current hwm, then raise the hwm.
  55472. if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
  55473. if (n <= state.length) return n; // Don't have enough
  55474. if (!state.ended) {
  55475. state.needReadable = true;
  55476. return 0;
  55477. }
  55478. return state.length;
  55479. } // you can override either this method, or the async _read(n) below.
  55480. Readable.prototype.read = function (n) {
  55481. debug('read', n);
  55482. n = parseInt(n, 10);
  55483. var state = this._readableState;
  55484. var nOrig = n;
  55485. if (n !== 0) state.emittedReadable = false; // if we're doing read(0) to trigger a readable event, but we
  55486. // already have a bunch of data in the buffer, then just trigger
  55487. // the 'readable' event and move on.
  55488. if (n === 0 && state.needReadable && ((state.highWaterMark !== 0 ? state.length >= state.highWaterMark : state.length > 0) || state.ended)) {
  55489. debug('read: emitReadable', state.length, state.ended);
  55490. if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
  55491. return null;
  55492. }
  55493. n = howMuchToRead(n, state); // if we've ended, and we're now clear, then finish it up.
  55494. if (n === 0 && state.ended) {
  55495. if (state.length === 0) endReadable(this);
  55496. return null;
  55497. } // All the actual chunk generation logic needs to be
  55498. // *below* the call to _read. The reason is that in certain
  55499. // synthetic stream cases, such as passthrough streams, _read
  55500. // may be a completely synchronous operation which may change
  55501. // the state of the read buffer, providing enough data when
  55502. // before there was *not* enough.
  55503. //
  55504. // So, the steps are:
  55505. // 1. Figure out what the state of things will be after we do
  55506. // a read from the buffer.
  55507. //
  55508. // 2. If that resulting state will trigger a _read, then call _read.
  55509. // Note that this may be asynchronous, or synchronous. Yes, it is
  55510. // deeply ugly to write APIs this way, but that still doesn't mean
  55511. // that the Readable class should behave improperly, as streams are
  55512. // designed to be sync/async agnostic.
  55513. // Take note if the _read call is sync or async (ie, if the read call
  55514. // has returned yet), so that we know whether or not it's safe to emit
  55515. // 'readable' etc.
  55516. //
  55517. // 3. Actually pull the requested chunks out of the buffer and return.
  55518. // if we need a readable event, then we need to do some reading.
  55519. var doRead = state.needReadable;
  55520. debug('need readable', doRead); // if we currently have less than the highWaterMark, then also read some
  55521. if (state.length === 0 || state.length - n < state.highWaterMark) {
  55522. doRead = true;
  55523. debug('length less than watermark', doRead);
  55524. } // however, if we've ended, then there's no point, and if we're already
  55525. // reading, then it's unnecessary.
  55526. if (state.ended || state.reading) {
  55527. doRead = false;
  55528. debug('reading or ended', doRead);
  55529. } else if (doRead) {
  55530. debug('do read');
  55531. state.reading = true;
  55532. state.sync = true; // if the length is currently zero, then we *need* a readable event.
  55533. if (state.length === 0) state.needReadable = true; // call internal read method
  55534. this._read(state.highWaterMark);
  55535. state.sync = false; // If _read pushed data synchronously, then `reading` will be false,
  55536. // and we need to re-evaluate how much data we can return to the user.
  55537. if (!state.reading) n = howMuchToRead(nOrig, state);
  55538. }
  55539. var ret;
  55540. if (n > 0) ret = fromList(n, state);else ret = null;
  55541. if (ret === null) {
  55542. state.needReadable = state.length <= state.highWaterMark;
  55543. n = 0;
  55544. } else {
  55545. state.length -= n;
  55546. state.awaitDrain = 0;
  55547. }
  55548. if (state.length === 0) {
  55549. // If we have nothing in the buffer, then we want to know
  55550. // as soon as we *do* get something into the buffer.
  55551. if (!state.ended) state.needReadable = true; // If we tried to read() past the EOF, then emit end on the next tick.
  55552. if (nOrig !== n && state.ended) endReadable(this);
  55553. }
  55554. if (ret !== null) this.emit('data', ret);
  55555. return ret;
  55556. };
  55557. function onEofChunk(stream, state) {
  55558. debug('onEofChunk');
  55559. if (state.ended) return;
  55560. if (state.decoder) {
  55561. var chunk = state.decoder.end();
  55562. if (chunk && chunk.length) {
  55563. state.buffer.push(chunk);
  55564. state.length += state.objectMode ? 1 : chunk.length;
  55565. }
  55566. }
  55567. state.ended = true;
  55568. if (state.sync) {
  55569. // if we are sync, wait until next tick to emit the data.
  55570. // Otherwise we risk emitting data in the flow()
  55571. // the readable code triggers during a read() call
  55572. emitReadable(stream);
  55573. } else {
  55574. // emit 'readable' now to make sure it gets picked up.
  55575. state.needReadable = false;
  55576. if (!state.emittedReadable) {
  55577. state.emittedReadable = true;
  55578. emitReadable_(stream);
  55579. }
  55580. }
  55581. } // Don't emit readable right away in sync mode, because this can trigger
  55582. // another read() call => stack overflow. This way, it might trigger
  55583. // a nextTick recursion warning, but that's not so bad.
  55584. function emitReadable(stream) {
  55585. var state = stream._readableState;
  55586. debug('emitReadable', state.needReadable, state.emittedReadable);
  55587. state.needReadable = false;
  55588. if (!state.emittedReadable) {
  55589. debug('emitReadable', state.flowing);
  55590. state.emittedReadable = true;
  55591. process.nextTick(emitReadable_, stream);
  55592. }
  55593. }
  55594. function emitReadable_(stream) {
  55595. var state = stream._readableState;
  55596. debug('emitReadable_', state.destroyed, state.length, state.ended);
  55597. if (!state.destroyed && (state.length || state.ended)) {
  55598. stream.emit('readable');
  55599. state.emittedReadable = false;
  55600. } // The stream needs another readable event if
  55601. // 1. It is not flowing, as the flow mechanism will take
  55602. // care of it.
  55603. // 2. It is not ended.
  55604. // 3. It is below the highWaterMark, so we can schedule
  55605. // another readable later.
  55606. state.needReadable = !state.flowing && !state.ended && state.length <= state.highWaterMark;
  55607. flow(stream);
  55608. } // at this point, the user has presumably seen the 'readable' event,
  55609. // and called read() to consume some data. that may have triggered
  55610. // in turn another _read(n) call, in which case reading = true if
  55611. // it's in progress.
  55612. // However, if we're not ended, or reading, and the length < hwm,
  55613. // then go ahead and try to read some more preemptively.
  55614. function maybeReadMore(stream, state) {
  55615. if (!state.readingMore) {
  55616. state.readingMore = true;
  55617. process.nextTick(maybeReadMore_, stream, state);
  55618. }
  55619. }
  55620. function maybeReadMore_(stream, state) {
  55621. // Attempt to read more data if we should.
  55622. //
  55623. // The conditions for reading more data are (one of):
  55624. // - Not enough data buffered (state.length < state.highWaterMark). The loop
  55625. // is responsible for filling the buffer with enough data if such data
  55626. // is available. If highWaterMark is 0 and we are not in the flowing mode
  55627. // we should _not_ attempt to buffer any extra data. We'll get more data
  55628. // when the stream consumer calls read() instead.
  55629. // - No data in the buffer, and the stream is in flowing mode. In this mode
  55630. // the loop below is responsible for ensuring read() is called. Failing to
  55631. // call read here would abort the flow and there's no other mechanism for
  55632. // continuing the flow if the stream consumer has just subscribed to the
  55633. // 'data' event.
  55634. //
  55635. // In addition to the above conditions to keep reading data, the following
  55636. // conditions prevent the data from being read:
  55637. // - The stream has ended (state.ended).
  55638. // - There is already a pending 'read' operation (state.reading). This is a
  55639. // case where the the stream has called the implementation defined _read()
  55640. // method, but they are processing the call asynchronously and have _not_
  55641. // called push() with new data. In this case we skip performing more
  55642. // read()s. The execution ends in this method again after the _read() ends
  55643. // up calling push() with more data.
  55644. while (!state.reading && !state.ended && (state.length < state.highWaterMark || state.flowing && state.length === 0)) {
  55645. var len = state.length;
  55646. debug('maybeReadMore read 0');
  55647. stream.read(0);
  55648. if (len === state.length) // didn't get any data, stop spinning.
  55649. break;
  55650. }
  55651. state.readingMore = false;
  55652. } // abstract method. to be overridden in specific implementation classes.
  55653. // call cb(er, data) where data is <= n in length.
  55654. // for virtual (non-string, non-buffer) streams, "length" is somewhat
  55655. // arbitrary, and perhaps not very meaningful.
  55656. Readable.prototype._read = function (n) {
  55657. errorOrDestroy(this, new ERR_METHOD_NOT_IMPLEMENTED('_read()'));
  55658. };
  55659. Readable.prototype.pipe = function (dest, pipeOpts) {
  55660. var src = this;
  55661. var state = this._readableState;
  55662. switch (state.pipesCount) {
  55663. case 0:
  55664. state.pipes = dest;
  55665. break;
  55666. case 1:
  55667. state.pipes = [state.pipes, dest];
  55668. break;
  55669. default:
  55670. state.pipes.push(dest);
  55671. break;
  55672. }
  55673. state.pipesCount += 1;
  55674. debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
  55675. var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
  55676. var endFn = doEnd ? onend : unpipe;
  55677. if (state.endEmitted) process.nextTick(endFn);else src.once('end', endFn);
  55678. dest.on('unpipe', onunpipe);
  55679. function onunpipe(readable, unpipeInfo) {
  55680. debug('onunpipe');
  55681. if (readable === src) {
  55682. if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
  55683. unpipeInfo.hasUnpiped = true;
  55684. cleanup();
  55685. }
  55686. }
  55687. }
  55688. function onend() {
  55689. debug('onend');
  55690. dest.end();
  55691. } // when the dest drains, it reduces the awaitDrain counter
  55692. // on the source. This would be more elegant with a .once()
  55693. // handler in flow(), but adding and removing repeatedly is
  55694. // too slow.
  55695. var ondrain = pipeOnDrain(src);
  55696. dest.on('drain', ondrain);
  55697. var cleanedUp = false;
  55698. function cleanup() {
  55699. debug('cleanup'); // cleanup event handlers once the pipe is broken
  55700. dest.removeListener('close', onclose);
  55701. dest.removeListener('finish', onfinish);
  55702. dest.removeListener('drain', ondrain);
  55703. dest.removeListener('error', onerror);
  55704. dest.removeListener('unpipe', onunpipe);
  55705. src.removeListener('end', onend);
  55706. src.removeListener('end', unpipe);
  55707. src.removeListener('data', ondata);
  55708. cleanedUp = true; // if the reader is waiting for a drain event from this
  55709. // specific writer, then it would cause it to never start
  55710. // flowing again.
  55711. // So, if this is awaiting a drain, then we just call it now.
  55712. // If we don't know, then assume that we are waiting for one.
  55713. if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
  55714. }
  55715. src.on('data', ondata);
  55716. function ondata(chunk) {
  55717. debug('ondata');
  55718. var ret = dest.write(chunk);
  55719. debug('dest.write', ret);
  55720. if (ret === false) {
  55721. // If the user unpiped during `dest.write()`, it is possible
  55722. // to get stuck in a permanently paused state if that write
  55723. // also returned false.
  55724. // => Check whether `dest` is still a piping destination.
  55725. if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
  55726. debug('false write response, pause', state.awaitDrain);
  55727. state.awaitDrain++;
  55728. }
  55729. src.pause();
  55730. }
  55731. } // if the dest has an error, then stop piping into it.
  55732. // however, don't suppress the throwing behavior for this.
  55733. function onerror(er) {
  55734. debug('onerror', er);
  55735. unpipe();
  55736. dest.removeListener('error', onerror);
  55737. if (EElistenerCount(dest, 'error') === 0) errorOrDestroy(dest, er);
  55738. } // Make sure our error handler is attached before userland ones.
  55739. prependListener(dest, 'error', onerror); // Both close and finish should trigger unpipe, but only once.
  55740. function onclose() {
  55741. dest.removeListener('finish', onfinish);
  55742. unpipe();
  55743. }
  55744. dest.once('close', onclose);
  55745. function onfinish() {
  55746. debug('onfinish');
  55747. dest.removeListener('close', onclose);
  55748. unpipe();
  55749. }
  55750. dest.once('finish', onfinish);
  55751. function unpipe() {
  55752. debug('unpipe');
  55753. src.unpipe(dest);
  55754. } // tell the dest that it's being piped to
  55755. dest.emit('pipe', src); // start the flow if it hasn't been started already.
  55756. if (!state.flowing) {
  55757. debug('pipe resume');
  55758. src.resume();
  55759. }
  55760. return dest;
  55761. };
  55762. function pipeOnDrain(src) {
  55763. return function pipeOnDrainFunctionResult() {
  55764. var state = src._readableState;
  55765. debug('pipeOnDrain', state.awaitDrain);
  55766. if (state.awaitDrain) state.awaitDrain--;
  55767. if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
  55768. state.flowing = true;
  55769. flow(src);
  55770. }
  55771. };
  55772. }
  55773. Readable.prototype.unpipe = function (dest) {
  55774. var state = this._readableState;
  55775. var unpipeInfo = {
  55776. hasUnpiped: false
  55777. }; // if we're not piping anywhere, then do nothing.
  55778. if (state.pipesCount === 0) return this; // just one destination. most common case.
  55779. if (state.pipesCount === 1) {
  55780. // passed in one, but it's not the right one.
  55781. if (dest && dest !== state.pipes) return this;
  55782. if (!dest) dest = state.pipes; // got a match.
  55783. state.pipes = null;
  55784. state.pipesCount = 0;
  55785. state.flowing = false;
  55786. if (dest) dest.emit('unpipe', this, unpipeInfo);
  55787. return this;
  55788. } // slow case. multiple pipe destinations.
  55789. if (!dest) {
  55790. // remove all.
  55791. var dests = state.pipes;
  55792. var len = state.pipesCount;
  55793. state.pipes = null;
  55794. state.pipesCount = 0;
  55795. state.flowing = false;
  55796. for (var i = 0; i < len; i++) {
  55797. dests[i].emit('unpipe', this, {
  55798. hasUnpiped: false
  55799. });
  55800. }
  55801. return this;
  55802. } // try to find the right one.
  55803. var index = indexOf(state.pipes, dest);
  55804. if (index === -1) return this;
  55805. state.pipes.splice(index, 1);
  55806. state.pipesCount -= 1;
  55807. if (state.pipesCount === 1) state.pipes = state.pipes[0];
  55808. dest.emit('unpipe', this, unpipeInfo);
  55809. return this;
  55810. }; // set up data events if they are asked for
  55811. // Ensure readable listeners eventually get something
  55812. Readable.prototype.on = function (ev, fn) {
  55813. var res = Stream.prototype.on.call(this, ev, fn);
  55814. var state = this._readableState;
  55815. if (ev === 'data') {
  55816. // update readableListening so that resume() may be a no-op
  55817. // a few lines down. This is needed to support once('readable').
  55818. state.readableListening = this.listenerCount('readable') > 0; // Try start flowing on next tick if stream isn't explicitly paused
  55819. if (state.flowing !== false) this.resume();
  55820. } else if (ev === 'readable') {
  55821. if (!state.endEmitted && !state.readableListening) {
  55822. state.readableListening = state.needReadable = true;
  55823. state.flowing = false;
  55824. state.emittedReadable = false;
  55825. debug('on readable', state.length, state.reading);
  55826. if (state.length) {
  55827. emitReadable(this);
  55828. } else if (!state.reading) {
  55829. process.nextTick(nReadingNextTick, this);
  55830. }
  55831. }
  55832. }
  55833. return res;
  55834. };
  55835. Readable.prototype.addListener = Readable.prototype.on;
  55836. Readable.prototype.removeListener = function (ev, fn) {
  55837. var res = Stream.prototype.removeListener.call(this, ev, fn);
  55838. if (ev === 'readable') {
  55839. // We need to check if there is someone still listening to
  55840. // readable and reset the state. However this needs to happen
  55841. // after readable has been emitted but before I/O (nextTick) to
  55842. // support once('readable', fn) cycles. This means that calling
  55843. // resume within the same tick will have no
  55844. // effect.
  55845. process.nextTick(updateReadableListening, this);
  55846. }
  55847. return res;
  55848. };
  55849. Readable.prototype.removeAllListeners = function (ev) {
  55850. var res = Stream.prototype.removeAllListeners.apply(this, arguments);
  55851. if (ev === 'readable' || ev === undefined) {
  55852. // We need to check if there is someone still listening to
  55853. // readable and reset the state. However this needs to happen
  55854. // after readable has been emitted but before I/O (nextTick) to
  55855. // support once('readable', fn) cycles. This means that calling
  55856. // resume within the same tick will have no
  55857. // effect.
  55858. process.nextTick(updateReadableListening, this);
  55859. }
  55860. return res;
  55861. };
  55862. function updateReadableListening(self) {
  55863. var state = self._readableState;
  55864. state.readableListening = self.listenerCount('readable') > 0;
  55865. if (state.resumeScheduled && !state.paused) {
  55866. // flowing needs to be set to true now, otherwise
  55867. // the upcoming resume will not flow.
  55868. state.flowing = true; // crude way to check if we should resume
  55869. } else if (self.listenerCount('data') > 0) {
  55870. self.resume();
  55871. }
  55872. }
  55873. function nReadingNextTick(self) {
  55874. debug('readable nexttick read 0');
  55875. self.read(0);
  55876. } // pause() and resume() are remnants of the legacy readable stream API
  55877. // If the user uses them, then switch into old mode.
  55878. Readable.prototype.resume = function () {
  55879. var state = this._readableState;
  55880. if (!state.flowing) {
  55881. debug('resume'); // we flow only if there is no one listening
  55882. // for readable, but we still have to call
  55883. // resume()
  55884. state.flowing = !state.readableListening;
  55885. resume(this, state);
  55886. }
  55887. state.paused = false;
  55888. return this;
  55889. };
  55890. function resume(stream, state) {
  55891. if (!state.resumeScheduled) {
  55892. state.resumeScheduled = true;
  55893. process.nextTick(resume_, stream, state);
  55894. }
  55895. }
  55896. function resume_(stream, state) {
  55897. debug('resume', state.reading);
  55898. if (!state.reading) {
  55899. stream.read(0);
  55900. }
  55901. state.resumeScheduled = false;
  55902. stream.emit('resume');
  55903. flow(stream);
  55904. if (state.flowing && !state.reading) stream.read(0);
  55905. }
  55906. Readable.prototype.pause = function () {
  55907. debug('call pause flowing=%j', this._readableState.flowing);
  55908. if (this._readableState.flowing !== false) {
  55909. debug('pause');
  55910. this._readableState.flowing = false;
  55911. this.emit('pause');
  55912. }
  55913. this._readableState.paused = true;
  55914. return this;
  55915. };
  55916. function flow(stream) {
  55917. var state = stream._readableState;
  55918. debug('flow', state.flowing);
  55919. while (state.flowing && stream.read() !== null) {
  55920. ;
  55921. }
  55922. } // wrap an old-style stream as the async data source.
  55923. // This is *not* part of the readable stream interface.
  55924. // It is an ugly unfortunate mess of history.
  55925. Readable.prototype.wrap = function (stream) {
  55926. var _this = this;
  55927. var state = this._readableState;
  55928. var paused = false;
  55929. stream.on('end', function () {
  55930. debug('wrapped end');
  55931. if (state.decoder && !state.ended) {
  55932. var chunk = state.decoder.end();
  55933. if (chunk && chunk.length) _this.push(chunk);
  55934. }
  55935. _this.push(null);
  55936. });
  55937. stream.on('data', function (chunk) {
  55938. debug('wrapped data');
  55939. if (state.decoder) chunk = state.decoder.write(chunk); // don't skip over falsy values in objectMode
  55940. if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
  55941. var ret = _this.push(chunk);
  55942. if (!ret) {
  55943. paused = true;
  55944. stream.pause();
  55945. }
  55946. }); // proxy all the other methods.
  55947. // important when wrapping filters and duplexes.
  55948. for (var i in stream) {
  55949. if (this[i] === undefined && typeof stream[i] === 'function') {
  55950. this[i] = function methodWrap(method) {
  55951. return function methodWrapReturnFunction() {
  55952. return stream[method].apply(stream, arguments);
  55953. };
  55954. }(i);
  55955. }
  55956. } // proxy certain important events.
  55957. for (var n = 0; n < kProxyEvents.length; n++) {
  55958. stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
  55959. } // when we try to consume some more bytes, simply unpause the
  55960. // underlying stream.
  55961. this._read = function (n) {
  55962. debug('wrapped _read', n);
  55963. if (paused) {
  55964. paused = false;
  55965. stream.resume();
  55966. }
  55967. };
  55968. return this;
  55969. };
  55970. if (typeof Symbol === 'function') {
  55971. Readable.prototype[Symbol.asyncIterator] = function () {
  55972. if (createReadableStreamAsyncIterator === undefined) {
  55973. createReadableStreamAsyncIterator = require('./internal/streams/async_iterator');
  55974. }
  55975. return createReadableStreamAsyncIterator(this);
  55976. };
  55977. }
  55978. Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
  55979. // making it explicit this property is not enumerable
  55980. // because otherwise some prototype manipulation in
  55981. // userland will fail
  55982. enumerable: false,
  55983. get: function get() {
  55984. return this._readableState.highWaterMark;
  55985. }
  55986. });
  55987. Object.defineProperty(Readable.prototype, 'readableBuffer', {
  55988. // making it explicit this property is not enumerable
  55989. // because otherwise some prototype manipulation in
  55990. // userland will fail
  55991. enumerable: false,
  55992. get: function get() {
  55993. return this._readableState && this._readableState.buffer;
  55994. }
  55995. });
  55996. Object.defineProperty(Readable.prototype, 'readableFlowing', {
  55997. // making it explicit this property is not enumerable
  55998. // because otherwise some prototype manipulation in
  55999. // userland will fail
  56000. enumerable: false,
  56001. get: function get() {
  56002. return this._readableState.flowing;
  56003. },
  56004. set: function set(state) {
  56005. if (this._readableState) {
  56006. this._readableState.flowing = state;
  56007. }
  56008. }
  56009. }); // exposed for testing purposes only.
  56010. Readable._fromList = fromList;
  56011. Object.defineProperty(Readable.prototype, 'readableLength', {
  56012. // making it explicit this property is not enumerable
  56013. // because otherwise some prototype manipulation in
  56014. // userland will fail
  56015. enumerable: false,
  56016. get: function get() {
  56017. return this._readableState.length;
  56018. }
  56019. }); // Pluck off n bytes from an array of buffers.
  56020. // Length is the combined lengths of all the buffers in the list.
  56021. // This function is designed to be inlinable, so please take care when making
  56022. // changes to the function body.
  56023. function fromList(n, state) {
  56024. // nothing buffered
  56025. if (state.length === 0) return null;
  56026. var ret;
  56027. if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
  56028. // read it all, truncate the list
  56029. if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.first();else ret = state.buffer.concat(state.length);
  56030. state.buffer.clear();
  56031. } else {
  56032. // read part of list
  56033. ret = state.buffer.consume(n, state.decoder);
  56034. }
  56035. return ret;
  56036. }
  56037. function endReadable(stream) {
  56038. var state = stream._readableState;
  56039. debug('endReadable', state.endEmitted);
  56040. if (!state.endEmitted) {
  56041. state.ended = true;
  56042. process.nextTick(endReadableNT, state, stream);
  56043. }
  56044. }
  56045. function endReadableNT(state, stream) {
  56046. debug('endReadableNT', state.endEmitted, state.length); // Check that we didn't get one last unshift.
  56047. if (!state.endEmitted && state.length === 0) {
  56048. state.endEmitted = true;
  56049. stream.readable = false;
  56050. stream.emit('end');
  56051. if (state.autoDestroy) {
  56052. // In case of duplex streams we need a way to detect
  56053. // if the writable side is ready for autoDestroy as well
  56054. var wState = stream._writableState;
  56055. if (!wState || wState.autoDestroy && wState.finished) {
  56056. stream.destroy();
  56057. }
  56058. }
  56059. }
  56060. }
  56061. if (typeof Symbol === 'function') {
  56062. Readable.from = function (iterable, opts) {
  56063. if (from === undefined) {
  56064. from = require('./internal/streams/from');
  56065. }
  56066. return from(Readable, iterable, opts);
  56067. };
  56068. }
  56069. function indexOf(xs, x) {
  56070. for (var i = 0, l = xs.length; i < l; i++) {
  56071. if (xs[i] === x) return i;
  56072. }
  56073. return -1;
  56074. }
  56075. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  56076. },{"../errors":368,"./_stream_duplex":369,"./internal/streams/async_iterator":374,"./internal/streams/buffer_list":375,"./internal/streams/destroy":376,"./internal/streams/from":378,"./internal/streams/state":380,"./internal/streams/stream":381,"_process":358,"buffer":216,"events":258,"inherits":278,"string_decoder/":410,"util":185}],372:[function(require,module,exports){
  56077. // Copyright Joyent, Inc. and other Node contributors.
  56078. //
  56079. // Permission is hereby granted, free of charge, to any person obtaining a
  56080. // copy of this software and associated documentation files (the
  56081. // "Software"), to deal in the Software without restriction, including
  56082. // without limitation the rights to use, copy, modify, merge, publish,
  56083. // distribute, sublicense, and/or sell copies of the Software, and to permit
  56084. // persons to whom the Software is furnished to do so, subject to the
  56085. // following conditions:
  56086. //
  56087. // The above copyright notice and this permission notice shall be included
  56088. // in all copies or substantial portions of the Software.
  56089. //
  56090. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  56091. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  56092. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  56093. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  56094. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  56095. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  56096. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  56097. // a transform stream is a readable/writable stream where you do
  56098. // something with the data. Sometimes it's called a "filter",
  56099. // but that's not a great name for it, since that implies a thing where
  56100. // some bits pass through, and others are simply ignored. (That would
  56101. // be a valid example of a transform, of course.)
  56102. //
  56103. // While the output is causally related to the input, it's not a
  56104. // necessarily symmetric or synchronous transformation. For example,
  56105. // a zlib stream might take multiple plain-text writes(), and then
  56106. // emit a single compressed chunk some time in the future.
  56107. //
  56108. // Here's how this works:
  56109. //
  56110. // The Transform stream has all the aspects of the readable and writable
  56111. // stream classes. When you write(chunk), that calls _write(chunk,cb)
  56112. // internally, and returns false if there's a lot of pending writes
  56113. // buffered up. When you call read(), that calls _read(n) until
  56114. // there's enough pending readable data buffered up.
  56115. //
  56116. // In a transform stream, the written data is placed in a buffer. When
  56117. // _read(n) is called, it transforms the queued up data, calling the
  56118. // buffered _write cb's as it consumes chunks. If consuming a single
  56119. // written chunk would result in multiple output chunks, then the first
  56120. // outputted bit calls the readcb, and subsequent chunks just go into
  56121. // the read buffer, and will cause it to emit 'readable' if necessary.
  56122. //
  56123. // This way, back-pressure is actually determined by the reading side,
  56124. // since _read has to be called to start processing a new chunk. However,
  56125. // a pathological inflate type of transform can cause excessive buffering
  56126. // here. For example, imagine a stream where every byte of input is
  56127. // interpreted as an integer from 0-255, and then results in that many
  56128. // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
  56129. // 1kb of data being output. In this case, you could write a very small
  56130. // amount of input, and end up with a very large amount of output. In
  56131. // such a pathological inflating mechanism, there'd be no way to tell
  56132. // the system to stop doing the transform. A single 4MB write could
  56133. // cause the system to run out of memory.
  56134. //
  56135. // However, even in such a pathological case, only a single written chunk
  56136. // would be consumed, and then the rest would wait (un-transformed) until
  56137. // the results of the previous transformed chunk were consumed.
  56138. 'use strict';
  56139. module.exports = Transform;
  56140. var _require$codes = require('../errors').codes,
  56141. ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
  56142. ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
  56143. ERR_TRANSFORM_ALREADY_TRANSFORMING = _require$codes.ERR_TRANSFORM_ALREADY_TRANSFORMING,
  56144. ERR_TRANSFORM_WITH_LENGTH_0 = _require$codes.ERR_TRANSFORM_WITH_LENGTH_0;
  56145. var Duplex = require('./_stream_duplex');
  56146. require('inherits')(Transform, Duplex);
  56147. function afterTransform(er, data) {
  56148. var ts = this._transformState;
  56149. ts.transforming = false;
  56150. var cb = ts.writecb;
  56151. if (cb === null) {
  56152. return this.emit('error', new ERR_MULTIPLE_CALLBACK());
  56153. }
  56154. ts.writechunk = null;
  56155. ts.writecb = null;
  56156. if (data != null) // single equals check for both `null` and `undefined`
  56157. this.push(data);
  56158. cb(er);
  56159. var rs = this._readableState;
  56160. rs.reading = false;
  56161. if (rs.needReadable || rs.length < rs.highWaterMark) {
  56162. this._read(rs.highWaterMark);
  56163. }
  56164. }
  56165. function Transform(options) {
  56166. if (!(this instanceof Transform)) return new Transform(options);
  56167. Duplex.call(this, options);
  56168. this._transformState = {
  56169. afterTransform: afterTransform.bind(this),
  56170. needTransform: false,
  56171. transforming: false,
  56172. writecb: null,
  56173. writechunk: null,
  56174. writeencoding: null
  56175. }; // start out asking for a readable event once data is transformed.
  56176. this._readableState.needReadable = true; // we have implemented the _read method, and done the other things
  56177. // that Readable wants before the first _read call, so unset the
  56178. // sync guard flag.
  56179. this._readableState.sync = false;
  56180. if (options) {
  56181. if (typeof options.transform === 'function') this._transform = options.transform;
  56182. if (typeof options.flush === 'function') this._flush = options.flush;
  56183. } // When the writable side finishes, then flush out anything remaining.
  56184. this.on('prefinish', prefinish);
  56185. }
  56186. function prefinish() {
  56187. var _this = this;
  56188. if (typeof this._flush === 'function' && !this._readableState.destroyed) {
  56189. this._flush(function (er, data) {
  56190. done(_this, er, data);
  56191. });
  56192. } else {
  56193. done(this, null, null);
  56194. }
  56195. }
  56196. Transform.prototype.push = function (chunk, encoding) {
  56197. this._transformState.needTransform = false;
  56198. return Duplex.prototype.push.call(this, chunk, encoding);
  56199. }; // This is the part where you do stuff!
  56200. // override this function in implementation classes.
  56201. // 'chunk' is an input chunk.
  56202. //
  56203. // Call `push(newChunk)` to pass along transformed output
  56204. // to the readable side. You may call 'push' zero or more times.
  56205. //
  56206. // Call `cb(err)` when you are done with this chunk. If you pass
  56207. // an error, then that'll put the hurt on the whole operation. If you
  56208. // never call cb(), then you'll never get another chunk.
  56209. Transform.prototype._transform = function (chunk, encoding, cb) {
  56210. cb(new ERR_METHOD_NOT_IMPLEMENTED('_transform()'));
  56211. };
  56212. Transform.prototype._write = function (chunk, encoding, cb) {
  56213. var ts = this._transformState;
  56214. ts.writecb = cb;
  56215. ts.writechunk = chunk;
  56216. ts.writeencoding = encoding;
  56217. if (!ts.transforming) {
  56218. var rs = this._readableState;
  56219. if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
  56220. }
  56221. }; // Doesn't matter what the args are here.
  56222. // _transform does all the work.
  56223. // That we got here means that the readable side wants more data.
  56224. Transform.prototype._read = function (n) {
  56225. var ts = this._transformState;
  56226. if (ts.writechunk !== null && !ts.transforming) {
  56227. ts.transforming = true;
  56228. this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
  56229. } else {
  56230. // mark that we need a transform, so that any data that comes in
  56231. // will get processed, now that we've asked for it.
  56232. ts.needTransform = true;
  56233. }
  56234. };
  56235. Transform.prototype._destroy = function (err, cb) {
  56236. Duplex.prototype._destroy.call(this, err, function (err2) {
  56237. cb(err2);
  56238. });
  56239. };
  56240. function done(stream, er, data) {
  56241. if (er) return stream.emit('error', er);
  56242. if (data != null) // single equals check for both `null` and `undefined`
  56243. stream.push(data); // TODO(BridgeAR): Write a test for these two error cases
  56244. // if there's nothing in the write buffer, then that means
  56245. // that nothing more will ever be provided
  56246. if (stream._writableState.length) throw new ERR_TRANSFORM_WITH_LENGTH_0();
  56247. if (stream._transformState.transforming) throw new ERR_TRANSFORM_ALREADY_TRANSFORMING();
  56248. return stream.push(null);
  56249. }
  56250. },{"../errors":368,"./_stream_duplex":369,"inherits":278}],373:[function(require,module,exports){
  56251. (function (process,global){
  56252. // Copyright Joyent, Inc. and other Node contributors.
  56253. //
  56254. // Permission is hereby granted, free of charge, to any person obtaining a
  56255. // copy of this software and associated documentation files (the
  56256. // "Software"), to deal in the Software without restriction, including
  56257. // without limitation the rights to use, copy, modify, merge, publish,
  56258. // distribute, sublicense, and/or sell copies of the Software, and to permit
  56259. // persons to whom the Software is furnished to do so, subject to the
  56260. // following conditions:
  56261. //
  56262. // The above copyright notice and this permission notice shall be included
  56263. // in all copies or substantial portions of the Software.
  56264. //
  56265. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  56266. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  56267. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  56268. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  56269. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  56270. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  56271. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  56272. // A bit simpler than readable streams.
  56273. // Implement an async ._write(chunk, encoding, cb), and it'll handle all
  56274. // the drain event emission and buffering.
  56275. 'use strict';
  56276. module.exports = Writable;
  56277. /* <replacement> */
  56278. function WriteReq(chunk, encoding, cb) {
  56279. this.chunk = chunk;
  56280. this.encoding = encoding;
  56281. this.callback = cb;
  56282. this.next = null;
  56283. } // It seems a linked list but it is not
  56284. // there will be only 2 of these for each stream
  56285. function CorkedRequest(state) {
  56286. var _this = this;
  56287. this.next = null;
  56288. this.entry = null;
  56289. this.finish = function () {
  56290. onCorkedFinish(_this, state);
  56291. };
  56292. }
  56293. /* </replacement> */
  56294. /*<replacement>*/
  56295. var Duplex;
  56296. /*</replacement>*/
  56297. Writable.WritableState = WritableState;
  56298. /*<replacement>*/
  56299. var internalUtil = {
  56300. deprecate: require('util-deprecate')
  56301. };
  56302. /*</replacement>*/
  56303. /*<replacement>*/
  56304. var Stream = require('./internal/streams/stream');
  56305. /*</replacement>*/
  56306. var Buffer = require('buffer').Buffer;
  56307. var OurUint8Array = global.Uint8Array || function () {};
  56308. function _uint8ArrayToBuffer(chunk) {
  56309. return Buffer.from(chunk);
  56310. }
  56311. function _isUint8Array(obj) {
  56312. return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
  56313. }
  56314. var destroyImpl = require('./internal/streams/destroy');
  56315. var _require = require('./internal/streams/state'),
  56316. getHighWaterMark = _require.getHighWaterMark;
  56317. var _require$codes = require('../errors').codes,
  56318. ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
  56319. ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
  56320. ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
  56321. ERR_STREAM_CANNOT_PIPE = _require$codes.ERR_STREAM_CANNOT_PIPE,
  56322. ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED,
  56323. ERR_STREAM_NULL_VALUES = _require$codes.ERR_STREAM_NULL_VALUES,
  56324. ERR_STREAM_WRITE_AFTER_END = _require$codes.ERR_STREAM_WRITE_AFTER_END,
  56325. ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING;
  56326. var errorOrDestroy = destroyImpl.errorOrDestroy;
  56327. require('inherits')(Writable, Stream);
  56328. function nop() {}
  56329. function WritableState(options, stream, isDuplex) {
  56330. Duplex = Duplex || require('./_stream_duplex');
  56331. options = options || {}; // Duplex streams are both readable and writable, but share
  56332. // the same options object.
  56333. // However, some cases require setting options to different
  56334. // values for the readable and the writable sides of the duplex stream,
  56335. // e.g. options.readableObjectMode vs. options.writableObjectMode, etc.
  56336. if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex; // object stream flag to indicate whether or not this stream
  56337. // contains buffers or objects.
  56338. this.objectMode = !!options.objectMode;
  56339. if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode; // the point at which write() starts returning false
  56340. // Note: 0 is a valid value, means that we always return false if
  56341. // the entire buffer is not flushed immediately on write()
  56342. this.highWaterMark = getHighWaterMark(this, options, 'writableHighWaterMark', isDuplex); // if _final has been called
  56343. this.finalCalled = false; // drain event flag.
  56344. this.needDrain = false; // at the start of calling end()
  56345. this.ending = false; // when end() has been called, and returned
  56346. this.ended = false; // when 'finish' is emitted
  56347. this.finished = false; // has it been destroyed
  56348. this.destroyed = false; // should we decode strings into buffers before passing to _write?
  56349. // this is here so that some node-core streams can optimize string
  56350. // handling at a lower level.
  56351. var noDecode = options.decodeStrings === false;
  56352. this.decodeStrings = !noDecode; // Crypto is kind of old and crusty. Historically, its default string
  56353. // encoding is 'binary' so we have to make this configurable.
  56354. // Everything else in the universe uses 'utf8', though.
  56355. this.defaultEncoding = options.defaultEncoding || 'utf8'; // not an actual buffer we keep track of, but a measurement
  56356. // of how much we're waiting to get pushed to some underlying
  56357. // socket or file.
  56358. this.length = 0; // a flag to see when we're in the middle of a write.
  56359. this.writing = false; // when true all writes will be buffered until .uncork() call
  56360. this.corked = 0; // a flag to be able to tell if the onwrite cb is called immediately,
  56361. // or on a later tick. We set this to true at first, because any
  56362. // actions that shouldn't happen until "later" should generally also
  56363. // not happen before the first write call.
  56364. this.sync = true; // a flag to know if we're processing previously buffered items, which
  56365. // may call the _write() callback in the same tick, so that we don't
  56366. // end up in an overlapped onwrite situation.
  56367. this.bufferProcessing = false; // the callback that's passed to _write(chunk,cb)
  56368. this.onwrite = function (er) {
  56369. onwrite(stream, er);
  56370. }; // the callback that the user supplies to write(chunk,encoding,cb)
  56371. this.writecb = null; // the amount that is being written when _write is called.
  56372. this.writelen = 0;
  56373. this.bufferedRequest = null;
  56374. this.lastBufferedRequest = null; // number of pending user-supplied write callbacks
  56375. // this must be 0 before 'finish' can be emitted
  56376. this.pendingcb = 0; // emit prefinish if the only thing we're waiting for is _write cbs
  56377. // This is relevant for synchronous Transform streams
  56378. this.prefinished = false; // True if the error was already emitted and should not be thrown again
  56379. this.errorEmitted = false; // Should close be emitted on destroy. Defaults to true.
  56380. this.emitClose = options.emitClose !== false; // Should .destroy() be called after 'finish' (and potentially 'end')
  56381. this.autoDestroy = !!options.autoDestroy; // count buffered requests
  56382. this.bufferedRequestCount = 0; // allocate the first CorkedRequest, there is always
  56383. // one allocated and free to use, and we maintain at most two
  56384. this.corkedRequestsFree = new CorkedRequest(this);
  56385. }
  56386. WritableState.prototype.getBuffer = function getBuffer() {
  56387. var current = this.bufferedRequest;
  56388. var out = [];
  56389. while (current) {
  56390. out.push(current);
  56391. current = current.next;
  56392. }
  56393. return out;
  56394. };
  56395. (function () {
  56396. try {
  56397. Object.defineProperty(WritableState.prototype, 'buffer', {
  56398. get: internalUtil.deprecate(function writableStateBufferGetter() {
  56399. return this.getBuffer();
  56400. }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
  56401. });
  56402. } catch (_) {}
  56403. })(); // Test _writableState for inheritance to account for Duplex streams,
  56404. // whose prototype chain only points to Readable.
  56405. var realHasInstance;
  56406. if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
  56407. realHasInstance = Function.prototype[Symbol.hasInstance];
  56408. Object.defineProperty(Writable, Symbol.hasInstance, {
  56409. value: function value(object) {
  56410. if (realHasInstance.call(this, object)) return true;
  56411. if (this !== Writable) return false;
  56412. return object && object._writableState instanceof WritableState;
  56413. }
  56414. });
  56415. } else {
  56416. realHasInstance = function realHasInstance(object) {
  56417. return object instanceof this;
  56418. };
  56419. }
  56420. function Writable(options) {
  56421. Duplex = Duplex || require('./_stream_duplex'); // Writable ctor is applied to Duplexes, too.
  56422. // `realHasInstance` is necessary because using plain `instanceof`
  56423. // would return false, as no `_writableState` property is attached.
  56424. // Trying to use the custom `instanceof` for Writable here will also break the
  56425. // Node.js LazyTransform implementation, which has a non-trivial getter for
  56426. // `_writableState` that would lead to infinite recursion.
  56427. // Checking for a Stream.Duplex instance is faster here instead of inside
  56428. // the WritableState constructor, at least with V8 6.5
  56429. var isDuplex = this instanceof Duplex;
  56430. if (!isDuplex && !realHasInstance.call(Writable, this)) return new Writable(options);
  56431. this._writableState = new WritableState(options, this, isDuplex); // legacy.
  56432. this.writable = true;
  56433. if (options) {
  56434. if (typeof options.write === 'function') this._write = options.write;
  56435. if (typeof options.writev === 'function') this._writev = options.writev;
  56436. if (typeof options.destroy === 'function') this._destroy = options.destroy;
  56437. if (typeof options.final === 'function') this._final = options.final;
  56438. }
  56439. Stream.call(this);
  56440. } // Otherwise people can pipe Writable streams, which is just wrong.
  56441. Writable.prototype.pipe = function () {
  56442. errorOrDestroy(this, new ERR_STREAM_CANNOT_PIPE());
  56443. };
  56444. function writeAfterEnd(stream, cb) {
  56445. var er = new ERR_STREAM_WRITE_AFTER_END(); // TODO: defer error events consistently everywhere, not just the cb
  56446. errorOrDestroy(stream, er);
  56447. process.nextTick(cb, er);
  56448. } // Checks that a user-supplied chunk is valid, especially for the particular
  56449. // mode the stream is in. Currently this means that `null` is never accepted
  56450. // and undefined/non-string values are only allowed in object mode.
  56451. function validChunk(stream, state, chunk, cb) {
  56452. var er;
  56453. if (chunk === null) {
  56454. er = new ERR_STREAM_NULL_VALUES();
  56455. } else if (typeof chunk !== 'string' && !state.objectMode) {
  56456. er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer'], chunk);
  56457. }
  56458. if (er) {
  56459. errorOrDestroy(stream, er);
  56460. process.nextTick(cb, er);
  56461. return false;
  56462. }
  56463. return true;
  56464. }
  56465. Writable.prototype.write = function (chunk, encoding, cb) {
  56466. var state = this._writableState;
  56467. var ret = false;
  56468. var isBuf = !state.objectMode && _isUint8Array(chunk);
  56469. if (isBuf && !Buffer.isBuffer(chunk)) {
  56470. chunk = _uint8ArrayToBuffer(chunk);
  56471. }
  56472. if (typeof encoding === 'function') {
  56473. cb = encoding;
  56474. encoding = null;
  56475. }
  56476. if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
  56477. if (typeof cb !== 'function') cb = nop;
  56478. if (state.ending) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
  56479. state.pendingcb++;
  56480. ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
  56481. }
  56482. return ret;
  56483. };
  56484. Writable.prototype.cork = function () {
  56485. this._writableState.corked++;
  56486. };
  56487. Writable.prototype.uncork = function () {
  56488. var state = this._writableState;
  56489. if (state.corked) {
  56490. state.corked--;
  56491. if (!state.writing && !state.corked && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
  56492. }
  56493. };
  56494. Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
  56495. // node::ParseEncoding() requires lower case.
  56496. if (typeof encoding === 'string') encoding = encoding.toLowerCase();
  56497. 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);
  56498. this._writableState.defaultEncoding = encoding;
  56499. return this;
  56500. };
  56501. Object.defineProperty(Writable.prototype, 'writableBuffer', {
  56502. // making it explicit this property is not enumerable
  56503. // because otherwise some prototype manipulation in
  56504. // userland will fail
  56505. enumerable: false,
  56506. get: function get() {
  56507. return this._writableState && this._writableState.getBuffer();
  56508. }
  56509. });
  56510. function decodeChunk(state, chunk, encoding) {
  56511. if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
  56512. chunk = Buffer.from(chunk, encoding);
  56513. }
  56514. return chunk;
  56515. }
  56516. Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
  56517. // making it explicit this property is not enumerable
  56518. // because otherwise some prototype manipulation in
  56519. // userland will fail
  56520. enumerable: false,
  56521. get: function get() {
  56522. return this._writableState.highWaterMark;
  56523. }
  56524. }); // if we're already writing something, then just put this
  56525. // in the queue, and wait our turn. Otherwise, call _write
  56526. // If we return false, then we need a drain event, so set that flag.
  56527. function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
  56528. if (!isBuf) {
  56529. var newChunk = decodeChunk(state, chunk, encoding);
  56530. if (chunk !== newChunk) {
  56531. isBuf = true;
  56532. encoding = 'buffer';
  56533. chunk = newChunk;
  56534. }
  56535. }
  56536. var len = state.objectMode ? 1 : chunk.length;
  56537. state.length += len;
  56538. var ret = state.length < state.highWaterMark; // we must ensure that previous needDrain will not be reset to false.
  56539. if (!ret) state.needDrain = true;
  56540. if (state.writing || state.corked) {
  56541. var last = state.lastBufferedRequest;
  56542. state.lastBufferedRequest = {
  56543. chunk: chunk,
  56544. encoding: encoding,
  56545. isBuf: isBuf,
  56546. callback: cb,
  56547. next: null
  56548. };
  56549. if (last) {
  56550. last.next = state.lastBufferedRequest;
  56551. } else {
  56552. state.bufferedRequest = state.lastBufferedRequest;
  56553. }
  56554. state.bufferedRequestCount += 1;
  56555. } else {
  56556. doWrite(stream, state, false, len, chunk, encoding, cb);
  56557. }
  56558. return ret;
  56559. }
  56560. function doWrite(stream, state, writev, len, chunk, encoding, cb) {
  56561. state.writelen = len;
  56562. state.writecb = cb;
  56563. state.writing = true;
  56564. state.sync = true;
  56565. 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);
  56566. state.sync = false;
  56567. }
  56568. function onwriteError(stream, state, sync, er, cb) {
  56569. --state.pendingcb;
  56570. if (sync) {
  56571. // defer the callback if we are being called synchronously
  56572. // to avoid piling up things on the stack
  56573. process.nextTick(cb, er); // this can emit finish, and it will always happen
  56574. // after error
  56575. process.nextTick(finishMaybe, stream, state);
  56576. stream._writableState.errorEmitted = true;
  56577. errorOrDestroy(stream, er);
  56578. } else {
  56579. // the caller expect this to happen before if
  56580. // it is async
  56581. cb(er);
  56582. stream._writableState.errorEmitted = true;
  56583. errorOrDestroy(stream, er); // this can emit finish, but finish must
  56584. // always follow error
  56585. finishMaybe(stream, state);
  56586. }
  56587. }
  56588. function onwriteStateUpdate(state) {
  56589. state.writing = false;
  56590. state.writecb = null;
  56591. state.length -= state.writelen;
  56592. state.writelen = 0;
  56593. }
  56594. function onwrite(stream, er) {
  56595. var state = stream._writableState;
  56596. var sync = state.sync;
  56597. var cb = state.writecb;
  56598. if (typeof cb !== 'function') throw new ERR_MULTIPLE_CALLBACK();
  56599. onwriteStateUpdate(state);
  56600. if (er) onwriteError(stream, state, sync, er, cb);else {
  56601. // Check if we're actually ready to finish, but don't emit yet
  56602. var finished = needFinish(state) || stream.destroyed;
  56603. if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
  56604. clearBuffer(stream, state);
  56605. }
  56606. if (sync) {
  56607. process.nextTick(afterWrite, stream, state, finished, cb);
  56608. } else {
  56609. afterWrite(stream, state, finished, cb);
  56610. }
  56611. }
  56612. }
  56613. function afterWrite(stream, state, finished, cb) {
  56614. if (!finished) onwriteDrain(stream, state);
  56615. state.pendingcb--;
  56616. cb();
  56617. finishMaybe(stream, state);
  56618. } // Must force callback to be called on nextTick, so that we don't
  56619. // emit 'drain' before the write() consumer gets the 'false' return
  56620. // value, and has a chance to attach a 'drain' listener.
  56621. function onwriteDrain(stream, state) {
  56622. if (state.length === 0 && state.needDrain) {
  56623. state.needDrain = false;
  56624. stream.emit('drain');
  56625. }
  56626. } // if there's something in the buffer waiting, then process it
  56627. function clearBuffer(stream, state) {
  56628. state.bufferProcessing = true;
  56629. var entry = state.bufferedRequest;
  56630. if (stream._writev && entry && entry.next) {
  56631. // Fast case, write everything using _writev()
  56632. var l = state.bufferedRequestCount;
  56633. var buffer = new Array(l);
  56634. var holder = state.corkedRequestsFree;
  56635. holder.entry = entry;
  56636. var count = 0;
  56637. var allBuffers = true;
  56638. while (entry) {
  56639. buffer[count] = entry;
  56640. if (!entry.isBuf) allBuffers = false;
  56641. entry = entry.next;
  56642. count += 1;
  56643. }
  56644. buffer.allBuffers = allBuffers;
  56645. doWrite(stream, state, true, state.length, buffer, '', holder.finish); // doWrite is almost always async, defer these to save a bit of time
  56646. // as the hot path ends with doWrite
  56647. state.pendingcb++;
  56648. state.lastBufferedRequest = null;
  56649. if (holder.next) {
  56650. state.corkedRequestsFree = holder.next;
  56651. holder.next = null;
  56652. } else {
  56653. state.corkedRequestsFree = new CorkedRequest(state);
  56654. }
  56655. state.bufferedRequestCount = 0;
  56656. } else {
  56657. // Slow case, write chunks one-by-one
  56658. while (entry) {
  56659. var chunk = entry.chunk;
  56660. var encoding = entry.encoding;
  56661. var cb = entry.callback;
  56662. var len = state.objectMode ? 1 : chunk.length;
  56663. doWrite(stream, state, false, len, chunk, encoding, cb);
  56664. entry = entry.next;
  56665. state.bufferedRequestCount--; // if we didn't call the onwrite immediately, then
  56666. // it means that we need to wait until it does.
  56667. // also, that means that the chunk and cb are currently
  56668. // being processed, so move the buffer counter past them.
  56669. if (state.writing) {
  56670. break;
  56671. }
  56672. }
  56673. if (entry === null) state.lastBufferedRequest = null;
  56674. }
  56675. state.bufferedRequest = entry;
  56676. state.bufferProcessing = false;
  56677. }
  56678. Writable.prototype._write = function (chunk, encoding, cb) {
  56679. cb(new ERR_METHOD_NOT_IMPLEMENTED('_write()'));
  56680. };
  56681. Writable.prototype._writev = null;
  56682. Writable.prototype.end = function (chunk, encoding, cb) {
  56683. var state = this._writableState;
  56684. if (typeof chunk === 'function') {
  56685. cb = chunk;
  56686. chunk = null;
  56687. encoding = null;
  56688. } else if (typeof encoding === 'function') {
  56689. cb = encoding;
  56690. encoding = null;
  56691. }
  56692. if (chunk !== null && chunk !== undefined) this.write(chunk, encoding); // .end() fully uncorks
  56693. if (state.corked) {
  56694. state.corked = 1;
  56695. this.uncork();
  56696. } // ignore unnecessary end() calls.
  56697. if (!state.ending) endWritable(this, state, cb);
  56698. return this;
  56699. };
  56700. Object.defineProperty(Writable.prototype, 'writableLength', {
  56701. // making it explicit this property is not enumerable
  56702. // because otherwise some prototype manipulation in
  56703. // userland will fail
  56704. enumerable: false,
  56705. get: function get() {
  56706. return this._writableState.length;
  56707. }
  56708. });
  56709. function needFinish(state) {
  56710. return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
  56711. }
  56712. function callFinal(stream, state) {
  56713. stream._final(function (err) {
  56714. state.pendingcb--;
  56715. if (err) {
  56716. errorOrDestroy(stream, err);
  56717. }
  56718. state.prefinished = true;
  56719. stream.emit('prefinish');
  56720. finishMaybe(stream, state);
  56721. });
  56722. }
  56723. function prefinish(stream, state) {
  56724. if (!state.prefinished && !state.finalCalled) {
  56725. if (typeof stream._final === 'function' && !state.destroyed) {
  56726. state.pendingcb++;
  56727. state.finalCalled = true;
  56728. process.nextTick(callFinal, stream, state);
  56729. } else {
  56730. state.prefinished = true;
  56731. stream.emit('prefinish');
  56732. }
  56733. }
  56734. }
  56735. function finishMaybe(stream, state) {
  56736. var need = needFinish(state);
  56737. if (need) {
  56738. prefinish(stream, state);
  56739. if (state.pendingcb === 0) {
  56740. state.finished = true;
  56741. stream.emit('finish');
  56742. if (state.autoDestroy) {
  56743. // In case of duplex streams we need a way to detect
  56744. // if the readable side is ready for autoDestroy as well
  56745. var rState = stream._readableState;
  56746. if (!rState || rState.autoDestroy && rState.endEmitted) {
  56747. stream.destroy();
  56748. }
  56749. }
  56750. }
  56751. }
  56752. return need;
  56753. }
  56754. function endWritable(stream, state, cb) {
  56755. state.ending = true;
  56756. finishMaybe(stream, state);
  56757. if (cb) {
  56758. if (state.finished) process.nextTick(cb);else stream.once('finish', cb);
  56759. }
  56760. state.ended = true;
  56761. stream.writable = false;
  56762. }
  56763. function onCorkedFinish(corkReq, state, err) {
  56764. var entry = corkReq.entry;
  56765. corkReq.entry = null;
  56766. while (entry) {
  56767. var cb = entry.callback;
  56768. state.pendingcb--;
  56769. cb(err);
  56770. entry = entry.next;
  56771. } // reuse the free corkReq.
  56772. state.corkedRequestsFree.next = corkReq;
  56773. }
  56774. Object.defineProperty(Writable.prototype, 'destroyed', {
  56775. // making it explicit this property is not enumerable
  56776. // because otherwise some prototype manipulation in
  56777. // userland will fail
  56778. enumerable: false,
  56779. get: function get() {
  56780. if (this._writableState === undefined) {
  56781. return false;
  56782. }
  56783. return this._writableState.destroyed;
  56784. },
  56785. set: function set(value) {
  56786. // we ignore the value if the stream
  56787. // has not been initialized yet
  56788. if (!this._writableState) {
  56789. return;
  56790. } // backward compatibility, the user is explicitly
  56791. // managing destroyed
  56792. this._writableState.destroyed = value;
  56793. }
  56794. });
  56795. Writable.prototype.destroy = destroyImpl.destroy;
  56796. Writable.prototype._undestroy = destroyImpl.undestroy;
  56797. Writable.prototype._destroy = function (err, cb) {
  56798. cb(err);
  56799. };
  56800. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  56801. },{"../errors":368,"./_stream_duplex":369,"./internal/streams/destroy":376,"./internal/streams/state":380,"./internal/streams/stream":381,"_process":358,"buffer":216,"inherits":278,"util-deprecate":412}],374:[function(require,module,exports){
  56802. (function (process){
  56803. 'use strict';
  56804. var _Object$setPrototypeO;
  56805. function _defineProperty(obj, key, value) {
  56806. if (key in obj) {
  56807. Object.defineProperty(obj, key, {
  56808. value: value,
  56809. enumerable: true,
  56810. configurable: true,
  56811. writable: true
  56812. });
  56813. } else {
  56814. obj[key] = value;
  56815. }
  56816. return obj;
  56817. }
  56818. var finished = require('./end-of-stream');
  56819. var kLastResolve = Symbol('lastResolve');
  56820. var kLastReject = Symbol('lastReject');
  56821. var kError = Symbol('error');
  56822. var kEnded = Symbol('ended');
  56823. var kLastPromise = Symbol('lastPromise');
  56824. var kHandlePromise = Symbol('handlePromise');
  56825. var kStream = Symbol('stream');
  56826. function createIterResult(value, done) {
  56827. return {
  56828. value: value,
  56829. done: done
  56830. };
  56831. }
  56832. function readAndResolve(iter) {
  56833. var resolve = iter[kLastResolve];
  56834. if (resolve !== null) {
  56835. var data = iter[kStream].read(); // we defer if data is null
  56836. // we can be expecting either 'end' or
  56837. // 'error'
  56838. if (data !== null) {
  56839. iter[kLastPromise] = null;
  56840. iter[kLastResolve] = null;
  56841. iter[kLastReject] = null;
  56842. resolve(createIterResult(data, false));
  56843. }
  56844. }
  56845. }
  56846. function onReadable(iter) {
  56847. // we wait for the next tick, because it might
  56848. // emit an error with process.nextTick
  56849. process.nextTick(readAndResolve, iter);
  56850. }
  56851. function wrapForNext(lastPromise, iter) {
  56852. return function (resolve, reject) {
  56853. lastPromise.then(function () {
  56854. if (iter[kEnded]) {
  56855. resolve(createIterResult(undefined, true));
  56856. return;
  56857. }
  56858. iter[kHandlePromise](resolve, reject);
  56859. }, reject);
  56860. };
  56861. }
  56862. var AsyncIteratorPrototype = Object.getPrototypeOf(function () {});
  56863. var ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf((_Object$setPrototypeO = {
  56864. get stream() {
  56865. return this[kStream];
  56866. },
  56867. next: function next() {
  56868. var _this = this; // if we have detected an error in the meanwhile
  56869. // reject straight away
  56870. var error = this[kError];
  56871. if (error !== null) {
  56872. return Promise.reject(error);
  56873. }
  56874. if (this[kEnded]) {
  56875. return Promise.resolve(createIterResult(undefined, true));
  56876. }
  56877. if (this[kStream].destroyed) {
  56878. // We need to defer via nextTick because if .destroy(err) is
  56879. // called, the error will be emitted via nextTick, and
  56880. // we cannot guarantee that there is no error lingering around
  56881. // waiting to be emitted.
  56882. return new Promise(function (resolve, reject) {
  56883. process.nextTick(function () {
  56884. if (_this[kError]) {
  56885. reject(_this[kError]);
  56886. } else {
  56887. resolve(createIterResult(undefined, true));
  56888. }
  56889. });
  56890. });
  56891. } // if we have multiple next() calls
  56892. // we will wait for the previous Promise to finish
  56893. // this logic is optimized to support for await loops,
  56894. // where next() is only called once at a time
  56895. var lastPromise = this[kLastPromise];
  56896. var promise;
  56897. if (lastPromise) {
  56898. promise = new Promise(wrapForNext(lastPromise, this));
  56899. } else {
  56900. // fast path needed to support multiple this.push()
  56901. // without triggering the next() queue
  56902. var data = this[kStream].read();
  56903. if (data !== null) {
  56904. return Promise.resolve(createIterResult(data, false));
  56905. }
  56906. promise = new Promise(this[kHandlePromise]);
  56907. }
  56908. this[kLastPromise] = promise;
  56909. return promise;
  56910. }
  56911. }, _defineProperty(_Object$setPrototypeO, Symbol.asyncIterator, function () {
  56912. return this;
  56913. }), _defineProperty(_Object$setPrototypeO, "return", function _return() {
  56914. var _this2 = this; // destroy(err, cb) is a private API
  56915. // we can guarantee we have that here, because we control the
  56916. // Readable class this is attached to
  56917. return new Promise(function (resolve, reject) {
  56918. _this2[kStream].destroy(null, function (err) {
  56919. if (err) {
  56920. reject(err);
  56921. return;
  56922. }
  56923. resolve(createIterResult(undefined, true));
  56924. });
  56925. });
  56926. }), _Object$setPrototypeO), AsyncIteratorPrototype);
  56927. var createReadableStreamAsyncIterator = function createReadableStreamAsyncIterator(stream) {
  56928. var _Object$create;
  56929. var iterator = Object.create(ReadableStreamAsyncIteratorPrototype, (_Object$create = {}, _defineProperty(_Object$create, kStream, {
  56930. value: stream,
  56931. writable: true
  56932. }), _defineProperty(_Object$create, kLastResolve, {
  56933. value: null,
  56934. writable: true
  56935. }), _defineProperty(_Object$create, kLastReject, {
  56936. value: null,
  56937. writable: true
  56938. }), _defineProperty(_Object$create, kError, {
  56939. value: null,
  56940. writable: true
  56941. }), _defineProperty(_Object$create, kEnded, {
  56942. value: stream._readableState.endEmitted,
  56943. writable: true
  56944. }), _defineProperty(_Object$create, kHandlePromise, {
  56945. value: function value(resolve, reject) {
  56946. var data = iterator[kStream].read();
  56947. if (data) {
  56948. iterator[kLastPromise] = null;
  56949. iterator[kLastResolve] = null;
  56950. iterator[kLastReject] = null;
  56951. resolve(createIterResult(data, false));
  56952. } else {
  56953. iterator[kLastResolve] = resolve;
  56954. iterator[kLastReject] = reject;
  56955. }
  56956. },
  56957. writable: true
  56958. }), _Object$create));
  56959. iterator[kLastPromise] = null;
  56960. finished(stream, function (err) {
  56961. if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') {
  56962. var reject = iterator[kLastReject]; // reject if we are waiting for data in the Promise
  56963. // returned by next() and store the error
  56964. if (reject !== null) {
  56965. iterator[kLastPromise] = null;
  56966. iterator[kLastResolve] = null;
  56967. iterator[kLastReject] = null;
  56968. reject(err);
  56969. }
  56970. iterator[kError] = err;
  56971. return;
  56972. }
  56973. var resolve = iterator[kLastResolve];
  56974. if (resolve !== null) {
  56975. iterator[kLastPromise] = null;
  56976. iterator[kLastResolve] = null;
  56977. iterator[kLastReject] = null;
  56978. resolve(createIterResult(undefined, true));
  56979. }
  56980. iterator[kEnded] = true;
  56981. });
  56982. stream.on('readable', onReadable.bind(null, iterator));
  56983. return iterator;
  56984. };
  56985. module.exports = createReadableStreamAsyncIterator;
  56986. }).call(this,require('_process'))
  56987. },{"./end-of-stream":377,"_process":358}],375:[function(require,module,exports){
  56988. 'use strict';
  56989. function ownKeys(object, enumerableOnly) {
  56990. var keys = Object.keys(object);
  56991. if (Object.getOwnPropertySymbols) {
  56992. var symbols = Object.getOwnPropertySymbols(object);
  56993. if (enumerableOnly) symbols = symbols.filter(function (sym) {
  56994. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  56995. });
  56996. keys.push.apply(keys, symbols);
  56997. }
  56998. return keys;
  56999. }
  57000. function _objectSpread(target) {
  57001. for (var i = 1; i < arguments.length; i++) {
  57002. var source = arguments[i] != null ? arguments[i] : {};
  57003. if (i % 2) {
  57004. ownKeys(Object(source), true).forEach(function (key) {
  57005. _defineProperty(target, key, source[key]);
  57006. });
  57007. } else if (Object.getOwnPropertyDescriptors) {
  57008. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  57009. } else {
  57010. ownKeys(Object(source)).forEach(function (key) {
  57011. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  57012. });
  57013. }
  57014. }
  57015. return target;
  57016. }
  57017. function _defineProperty(obj, key, value) {
  57018. if (key in obj) {
  57019. Object.defineProperty(obj, key, {
  57020. value: value,
  57021. enumerable: true,
  57022. configurable: true,
  57023. writable: true
  57024. });
  57025. } else {
  57026. obj[key] = value;
  57027. }
  57028. return obj;
  57029. }
  57030. function _classCallCheck(instance, Constructor) {
  57031. if (!(instance instanceof Constructor)) {
  57032. throw new TypeError("Cannot call a class as a function");
  57033. }
  57034. }
  57035. function _defineProperties(target, props) {
  57036. for (var i = 0; i < props.length; i++) {
  57037. var descriptor = props[i];
  57038. descriptor.enumerable = descriptor.enumerable || false;
  57039. descriptor.configurable = true;
  57040. if ("value" in descriptor) descriptor.writable = true;
  57041. Object.defineProperty(target, descriptor.key, descriptor);
  57042. }
  57043. }
  57044. function _createClass(Constructor, protoProps, staticProps) {
  57045. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  57046. if (staticProps) _defineProperties(Constructor, staticProps);
  57047. return Constructor;
  57048. }
  57049. var _require = require('buffer'),
  57050. Buffer = _require.Buffer;
  57051. var _require2 = require('util'),
  57052. inspect = _require2.inspect;
  57053. var custom = inspect && inspect.custom || 'inspect';
  57054. function copyBuffer(src, target, offset) {
  57055. Buffer.prototype.copy.call(src, target, offset);
  57056. }
  57057. module.exports = /*#__PURE__*/function () {
  57058. function BufferList() {
  57059. _classCallCheck(this, BufferList);
  57060. this.head = null;
  57061. this.tail = null;
  57062. this.length = 0;
  57063. }
  57064. _createClass(BufferList, [{
  57065. key: "push",
  57066. value: function push(v) {
  57067. var entry = {
  57068. data: v,
  57069. next: null
  57070. };
  57071. if (this.length > 0) this.tail.next = entry;else this.head = entry;
  57072. this.tail = entry;
  57073. ++this.length;
  57074. }
  57075. }, {
  57076. key: "unshift",
  57077. value: function unshift(v) {
  57078. var entry = {
  57079. data: v,
  57080. next: this.head
  57081. };
  57082. if (this.length === 0) this.tail = entry;
  57083. this.head = entry;
  57084. ++this.length;
  57085. }
  57086. }, {
  57087. key: "shift",
  57088. value: function shift() {
  57089. if (this.length === 0) return;
  57090. var ret = this.head.data;
  57091. if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
  57092. --this.length;
  57093. return ret;
  57094. }
  57095. }, {
  57096. key: "clear",
  57097. value: function clear() {
  57098. this.head = this.tail = null;
  57099. this.length = 0;
  57100. }
  57101. }, {
  57102. key: "join",
  57103. value: function join(s) {
  57104. if (this.length === 0) return '';
  57105. var p = this.head;
  57106. var ret = '' + p.data;
  57107. while (p = p.next) {
  57108. ret += s + p.data;
  57109. }
  57110. return ret;
  57111. }
  57112. }, {
  57113. key: "concat",
  57114. value: function concat(n) {
  57115. if (this.length === 0) return Buffer.alloc(0);
  57116. var ret = Buffer.allocUnsafe(n >>> 0);
  57117. var p = this.head;
  57118. var i = 0;
  57119. while (p) {
  57120. copyBuffer(p.data, ret, i);
  57121. i += p.data.length;
  57122. p = p.next;
  57123. }
  57124. return ret;
  57125. } // Consumes a specified amount of bytes or characters from the buffered data.
  57126. }, {
  57127. key: "consume",
  57128. value: function consume(n, hasStrings) {
  57129. var ret;
  57130. if (n < this.head.data.length) {
  57131. // `slice` is the same for buffers and strings.
  57132. ret = this.head.data.slice(0, n);
  57133. this.head.data = this.head.data.slice(n);
  57134. } else if (n === this.head.data.length) {
  57135. // First chunk is a perfect match.
  57136. ret = this.shift();
  57137. } else {
  57138. // Result spans more than one buffer.
  57139. ret = hasStrings ? this._getString(n) : this._getBuffer(n);
  57140. }
  57141. return ret;
  57142. }
  57143. }, {
  57144. key: "first",
  57145. value: function first() {
  57146. return this.head.data;
  57147. } // Consumes a specified amount of characters from the buffered data.
  57148. }, {
  57149. key: "_getString",
  57150. value: function _getString(n) {
  57151. var p = this.head;
  57152. var c = 1;
  57153. var ret = p.data;
  57154. n -= ret.length;
  57155. while (p = p.next) {
  57156. var str = p.data;
  57157. var nb = n > str.length ? str.length : n;
  57158. if (nb === str.length) ret += str;else ret += str.slice(0, n);
  57159. n -= nb;
  57160. if (n === 0) {
  57161. if (nb === str.length) {
  57162. ++c;
  57163. if (p.next) this.head = p.next;else this.head = this.tail = null;
  57164. } else {
  57165. this.head = p;
  57166. p.data = str.slice(nb);
  57167. }
  57168. break;
  57169. }
  57170. ++c;
  57171. }
  57172. this.length -= c;
  57173. return ret;
  57174. } // Consumes a specified amount of bytes from the buffered data.
  57175. }, {
  57176. key: "_getBuffer",
  57177. value: function _getBuffer(n) {
  57178. var ret = Buffer.allocUnsafe(n);
  57179. var p = this.head;
  57180. var c = 1;
  57181. p.data.copy(ret);
  57182. n -= p.data.length;
  57183. while (p = p.next) {
  57184. var buf = p.data;
  57185. var nb = n > buf.length ? buf.length : n;
  57186. buf.copy(ret, ret.length - n, 0, nb);
  57187. n -= nb;
  57188. if (n === 0) {
  57189. if (nb === buf.length) {
  57190. ++c;
  57191. if (p.next) this.head = p.next;else this.head = this.tail = null;
  57192. } else {
  57193. this.head = p;
  57194. p.data = buf.slice(nb);
  57195. }
  57196. break;
  57197. }
  57198. ++c;
  57199. }
  57200. this.length -= c;
  57201. return ret;
  57202. } // Make sure the linked list only shows the minimal necessary information.
  57203. }, {
  57204. key: custom,
  57205. value: function value(_, options) {
  57206. return inspect(this, _objectSpread({}, options, {
  57207. // Only inspect one level.
  57208. depth: 0,
  57209. // It should not recurse.
  57210. customInspect: false
  57211. }));
  57212. }
  57213. }]);
  57214. return BufferList;
  57215. }();
  57216. },{"buffer":216,"util":185}],376:[function(require,module,exports){
  57217. (function (process){
  57218. 'use strict'; // undocumented cb() API, needed for core, not for public API
  57219. function destroy(err, cb) {
  57220. var _this = this;
  57221. var readableDestroyed = this._readableState && this._readableState.destroyed;
  57222. var writableDestroyed = this._writableState && this._writableState.destroyed;
  57223. if (readableDestroyed || writableDestroyed) {
  57224. if (cb) {
  57225. cb(err);
  57226. } else if (err) {
  57227. if (!this._writableState) {
  57228. process.nextTick(emitErrorNT, this, err);
  57229. } else if (!this._writableState.errorEmitted) {
  57230. this._writableState.errorEmitted = true;
  57231. process.nextTick(emitErrorNT, this, err);
  57232. }
  57233. }
  57234. return this;
  57235. } // we set destroyed to true before firing error callbacks in order
  57236. // to make it re-entrance safe in case destroy() is called within callbacks
  57237. if (this._readableState) {
  57238. this._readableState.destroyed = true;
  57239. } // if this is a duplex stream mark the writable part as destroyed as well
  57240. if (this._writableState) {
  57241. this._writableState.destroyed = true;
  57242. }
  57243. this._destroy(err || null, function (err) {
  57244. if (!cb && err) {
  57245. if (!_this._writableState) {
  57246. process.nextTick(emitErrorAndCloseNT, _this, err);
  57247. } else if (!_this._writableState.errorEmitted) {
  57248. _this._writableState.errorEmitted = true;
  57249. process.nextTick(emitErrorAndCloseNT, _this, err);
  57250. } else {
  57251. process.nextTick(emitCloseNT, _this);
  57252. }
  57253. } else if (cb) {
  57254. process.nextTick(emitCloseNT, _this);
  57255. cb(err);
  57256. } else {
  57257. process.nextTick(emitCloseNT, _this);
  57258. }
  57259. });
  57260. return this;
  57261. }
  57262. function emitErrorAndCloseNT(self, err) {
  57263. emitErrorNT(self, err);
  57264. emitCloseNT(self);
  57265. }
  57266. function emitCloseNT(self) {
  57267. if (self._writableState && !self._writableState.emitClose) return;
  57268. if (self._readableState && !self._readableState.emitClose) return;
  57269. self.emit('close');
  57270. }
  57271. function undestroy() {
  57272. if (this._readableState) {
  57273. this._readableState.destroyed = false;
  57274. this._readableState.reading = false;
  57275. this._readableState.ended = false;
  57276. this._readableState.endEmitted = false;
  57277. }
  57278. if (this._writableState) {
  57279. this._writableState.destroyed = false;
  57280. this._writableState.ended = false;
  57281. this._writableState.ending = false;
  57282. this._writableState.finalCalled = false;
  57283. this._writableState.prefinished = false;
  57284. this._writableState.finished = false;
  57285. this._writableState.errorEmitted = false;
  57286. }
  57287. }
  57288. function emitErrorNT(self, err) {
  57289. self.emit('error', err);
  57290. }
  57291. function errorOrDestroy(stream, err) {
  57292. // We have tests that rely on errors being emitted
  57293. // in the same tick, so changing this is semver major.
  57294. // For now when you opt-in to autoDestroy we allow
  57295. // the error to be emitted nextTick. In a future
  57296. // semver major update we should change the default to this.
  57297. var rState = stream._readableState;
  57298. var wState = stream._writableState;
  57299. if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);else stream.emit('error', err);
  57300. }
  57301. module.exports = {
  57302. destroy: destroy,
  57303. undestroy: undestroy,
  57304. errorOrDestroy: errorOrDestroy
  57305. };
  57306. }).call(this,require('_process'))
  57307. },{"_process":358}],377:[function(require,module,exports){
  57308. // Ported from https://github.com/mafintosh/end-of-stream with
  57309. // permission from the author, Mathias Buus (@mafintosh).
  57310. 'use strict';
  57311. var ERR_STREAM_PREMATURE_CLOSE = require('../../../errors').codes.ERR_STREAM_PREMATURE_CLOSE;
  57312. function once(callback) {
  57313. var called = false;
  57314. return function () {
  57315. if (called) return;
  57316. called = true;
  57317. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  57318. args[_key] = arguments[_key];
  57319. }
  57320. callback.apply(this, args);
  57321. };
  57322. }
  57323. function noop() {}
  57324. function isRequest(stream) {
  57325. return stream.setHeader && typeof stream.abort === 'function';
  57326. }
  57327. function eos(stream, opts, callback) {
  57328. if (typeof opts === 'function') return eos(stream, null, opts);
  57329. if (!opts) opts = {};
  57330. callback = once(callback || noop);
  57331. var readable = opts.readable || opts.readable !== false && stream.readable;
  57332. var writable = opts.writable || opts.writable !== false && stream.writable;
  57333. var onlegacyfinish = function onlegacyfinish() {
  57334. if (!stream.writable) onfinish();
  57335. };
  57336. var writableEnded = stream._writableState && stream._writableState.finished;
  57337. var onfinish = function onfinish() {
  57338. writable = false;
  57339. writableEnded = true;
  57340. if (!readable) callback.call(stream);
  57341. };
  57342. var readableEnded = stream._readableState && stream._readableState.endEmitted;
  57343. var onend = function onend() {
  57344. readable = false;
  57345. readableEnded = true;
  57346. if (!writable) callback.call(stream);
  57347. };
  57348. var onerror = function onerror(err) {
  57349. callback.call(stream, err);
  57350. };
  57351. var onclose = function onclose() {
  57352. var err;
  57353. if (readable && !readableEnded) {
  57354. if (!stream._readableState || !stream._readableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
  57355. return callback.call(stream, err);
  57356. }
  57357. if (writable && !writableEnded) {
  57358. if (!stream._writableState || !stream._writableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
  57359. return callback.call(stream, err);
  57360. }
  57361. };
  57362. var onrequest = function onrequest() {
  57363. stream.req.on('finish', onfinish);
  57364. };
  57365. if (isRequest(stream)) {
  57366. stream.on('complete', onfinish);
  57367. stream.on('abort', onclose);
  57368. if (stream.req) onrequest();else stream.on('request', onrequest);
  57369. } else if (writable && !stream._writableState) {
  57370. // legacy streams
  57371. stream.on('end', onlegacyfinish);
  57372. stream.on('close', onlegacyfinish);
  57373. }
  57374. stream.on('end', onend);
  57375. stream.on('finish', onfinish);
  57376. if (opts.error !== false) stream.on('error', onerror);
  57377. stream.on('close', onclose);
  57378. return function () {
  57379. stream.removeListener('complete', onfinish);
  57380. stream.removeListener('abort', onclose);
  57381. stream.removeListener('request', onrequest);
  57382. if (stream.req) stream.req.removeListener('finish', onfinish);
  57383. stream.removeListener('end', onlegacyfinish);
  57384. stream.removeListener('close', onlegacyfinish);
  57385. stream.removeListener('finish', onfinish);
  57386. stream.removeListener('end', onend);
  57387. stream.removeListener('error', onerror);
  57388. stream.removeListener('close', onclose);
  57389. };
  57390. }
  57391. module.exports = eos;
  57392. },{"../../../errors":368}],378:[function(require,module,exports){
  57393. "use strict";
  57394. module.exports = function () {
  57395. throw new Error('Readable.from is not available in the browser');
  57396. };
  57397. },{}],379:[function(require,module,exports){
  57398. // Ported from https://github.com/mafintosh/pump with
  57399. // permission from the author, Mathias Buus (@mafintosh).
  57400. 'use strict';
  57401. var eos;
  57402. function once(callback) {
  57403. var called = false;
  57404. return function () {
  57405. if (called) return;
  57406. called = true;
  57407. callback.apply(void 0, arguments);
  57408. };
  57409. }
  57410. var _require$codes = require('../../../errors').codes,
  57411. ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS,
  57412. ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED;
  57413. function noop(err) {
  57414. // Rethrow the error if it exists to avoid swallowing it
  57415. if (err) throw err;
  57416. }
  57417. function isRequest(stream) {
  57418. return stream.setHeader && typeof stream.abort === 'function';
  57419. }
  57420. function destroyer(stream, reading, writing, callback) {
  57421. callback = once(callback);
  57422. var closed = false;
  57423. stream.on('close', function () {
  57424. closed = true;
  57425. });
  57426. if (eos === undefined) eos = require('./end-of-stream');
  57427. eos(stream, {
  57428. readable: reading,
  57429. writable: writing
  57430. }, function (err) {
  57431. if (err) return callback(err);
  57432. closed = true;
  57433. callback();
  57434. });
  57435. var destroyed = false;
  57436. return function (err) {
  57437. if (closed) return;
  57438. if (destroyed) return;
  57439. destroyed = true; // request.destroy just do .end - .abort is what we want
  57440. if (isRequest(stream)) return stream.abort();
  57441. if (typeof stream.destroy === 'function') return stream.destroy();
  57442. callback(err || new ERR_STREAM_DESTROYED('pipe'));
  57443. };
  57444. }
  57445. function call(fn) {
  57446. fn();
  57447. }
  57448. function pipe(from, to) {
  57449. return from.pipe(to);
  57450. }
  57451. function popCallback(streams) {
  57452. if (!streams.length) return noop;
  57453. if (typeof streams[streams.length - 1] !== 'function') return noop;
  57454. return streams.pop();
  57455. }
  57456. function pipeline() {
  57457. for (var _len = arguments.length, streams = new Array(_len), _key = 0; _key < _len; _key++) {
  57458. streams[_key] = arguments[_key];
  57459. }
  57460. var callback = popCallback(streams);
  57461. if (Array.isArray(streams[0])) streams = streams[0];
  57462. if (streams.length < 2) {
  57463. throw new ERR_MISSING_ARGS('streams');
  57464. }
  57465. var error;
  57466. var destroys = streams.map(function (stream, i) {
  57467. var reading = i < streams.length - 1;
  57468. var writing = i > 0;
  57469. return destroyer(stream, reading, writing, function (err) {
  57470. if (!error) error = err;
  57471. if (err) destroys.forEach(call);
  57472. if (reading) return;
  57473. destroys.forEach(call);
  57474. callback(error);
  57475. });
  57476. });
  57477. return streams.reduce(pipe);
  57478. }
  57479. module.exports = pipeline;
  57480. },{"../../../errors":368,"./end-of-stream":377}],380:[function(require,module,exports){
  57481. 'use strict';
  57482. var ERR_INVALID_OPT_VALUE = require('../../../errors').codes.ERR_INVALID_OPT_VALUE;
  57483. function highWaterMarkFrom(options, isDuplex, duplexKey) {
  57484. return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
  57485. }
  57486. function getHighWaterMark(state, options, duplexKey, isDuplex) {
  57487. var hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
  57488. if (hwm != null) {
  57489. if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) {
  57490. var name = isDuplex ? duplexKey : 'highWaterMark';
  57491. throw new ERR_INVALID_OPT_VALUE(name, hwm);
  57492. }
  57493. return Math.floor(hwm);
  57494. } // Default value
  57495. return state.objectMode ? 16 : 16 * 1024;
  57496. }
  57497. module.exports = {
  57498. getHighWaterMark: getHighWaterMark
  57499. };
  57500. },{"../../../errors":368}],381:[function(require,module,exports){
  57501. "use strict";
  57502. module.exports = require('events').EventEmitter;
  57503. },{"events":258}],382:[function(require,module,exports){
  57504. "use strict";
  57505. exports = module.exports = require('./lib/_stream_readable.js');
  57506. exports.Stream = exports;
  57507. exports.Readable = exports;
  57508. exports.Writable = require('./lib/_stream_writable.js');
  57509. exports.Duplex = require('./lib/_stream_duplex.js');
  57510. exports.Transform = require('./lib/_stream_transform.js');
  57511. exports.PassThrough = require('./lib/_stream_passthrough.js');
  57512. exports.finished = require('./lib/internal/streams/end-of-stream.js');
  57513. exports.pipeline = require('./lib/internal/streams/pipeline.js');
  57514. },{"./lib/_stream_duplex.js":369,"./lib/_stream_passthrough.js":370,"./lib/_stream_readable.js":371,"./lib/_stream_transform.js":372,"./lib/_stream_writable.js":373,"./lib/internal/streams/end-of-stream.js":377,"./lib/internal/streams/pipeline.js":379}],383:[function(require,module,exports){
  57515. 'use strict';
  57516. var Buffer = require('buffer').Buffer;
  57517. var inherits = require('inherits');
  57518. var HashBase = require('hash-base');
  57519. var ARRAY16 = new Array(16);
  57520. 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];
  57521. 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];
  57522. 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];
  57523. 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];
  57524. var hl = [0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e];
  57525. var hr = [0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000];
  57526. function RIPEMD160() {
  57527. HashBase.call(this, 64); // state
  57528. this._a = 0x67452301;
  57529. this._b = 0xefcdab89;
  57530. this._c = 0x98badcfe;
  57531. this._d = 0x10325476;
  57532. this._e = 0xc3d2e1f0;
  57533. }
  57534. inherits(RIPEMD160, HashBase);
  57535. RIPEMD160.prototype._update = function () {
  57536. var words = ARRAY16;
  57537. for (var j = 0; j < 16; ++j) {
  57538. words[j] = this._block.readInt32LE(j * 4);
  57539. }
  57540. var al = this._a | 0;
  57541. var bl = this._b | 0;
  57542. var cl = this._c | 0;
  57543. var dl = this._d | 0;
  57544. var el = this._e | 0;
  57545. var ar = this._a | 0;
  57546. var br = this._b | 0;
  57547. var cr = this._c | 0;
  57548. var dr = this._d | 0;
  57549. var er = this._e | 0; // computation
  57550. for (var i = 0; i < 80; i += 1) {
  57551. var tl;
  57552. var tr;
  57553. if (i < 16) {
  57554. tl = fn1(al, bl, cl, dl, el, words[zl[i]], hl[0], sl[i]);
  57555. tr = fn5(ar, br, cr, dr, er, words[zr[i]], hr[0], sr[i]);
  57556. } else if (i < 32) {
  57557. tl = fn2(al, bl, cl, dl, el, words[zl[i]], hl[1], sl[i]);
  57558. tr = fn4(ar, br, cr, dr, er, words[zr[i]], hr[1], sr[i]);
  57559. } else if (i < 48) {
  57560. tl = fn3(al, bl, cl, dl, el, words[zl[i]], hl[2], sl[i]);
  57561. tr = fn3(ar, br, cr, dr, er, words[zr[i]], hr[2], sr[i]);
  57562. } else if (i < 64) {
  57563. tl = fn4(al, bl, cl, dl, el, words[zl[i]], hl[3], sl[i]);
  57564. tr = fn2(ar, br, cr, dr, er, words[zr[i]], hr[3], sr[i]);
  57565. } else {
  57566. // if (i<80) {
  57567. tl = fn5(al, bl, cl, dl, el, words[zl[i]], hl[4], sl[i]);
  57568. tr = fn1(ar, br, cr, dr, er, words[zr[i]], hr[4], sr[i]);
  57569. }
  57570. al = el;
  57571. el = dl;
  57572. dl = rotl(cl, 10);
  57573. cl = bl;
  57574. bl = tl;
  57575. ar = er;
  57576. er = dr;
  57577. dr = rotl(cr, 10);
  57578. cr = br;
  57579. br = tr;
  57580. } // update state
  57581. var t = this._b + cl + dr | 0;
  57582. this._b = this._c + dl + er | 0;
  57583. this._c = this._d + el + ar | 0;
  57584. this._d = this._e + al + br | 0;
  57585. this._e = this._a + bl + cr | 0;
  57586. this._a = t;
  57587. };
  57588. RIPEMD160.prototype._digest = function () {
  57589. // create padding and handle blocks
  57590. this._block[this._blockOffset++] = 0x80;
  57591. if (this._blockOffset > 56) {
  57592. this._block.fill(0, this._blockOffset, 64);
  57593. this._update();
  57594. this._blockOffset = 0;
  57595. }
  57596. this._block.fill(0, this._blockOffset, 56);
  57597. this._block.writeUInt32LE(this._length[0], 56);
  57598. this._block.writeUInt32LE(this._length[1], 60);
  57599. this._update(); // produce result
  57600. var buffer = Buffer.alloc ? Buffer.alloc(20) : new Buffer(20);
  57601. buffer.writeInt32LE(this._a, 0);
  57602. buffer.writeInt32LE(this._b, 4);
  57603. buffer.writeInt32LE(this._c, 8);
  57604. buffer.writeInt32LE(this._d, 12);
  57605. buffer.writeInt32LE(this._e, 16);
  57606. return buffer;
  57607. };
  57608. function rotl(x, n) {
  57609. return x << n | x >>> 32 - n;
  57610. }
  57611. function fn1(a, b, c, d, e, m, k, s) {
  57612. return rotl(a + (b ^ c ^ d) + m + k | 0, s) + e | 0;
  57613. }
  57614. function fn2(a, b, c, d, e, m, k, s) {
  57615. return rotl(a + (b & c | ~b & d) + m + k | 0, s) + e | 0;
  57616. }
  57617. function fn3(a, b, c, d, e, m, k, s) {
  57618. return rotl(a + ((b | ~c) ^ d) + m + k | 0, s) + e | 0;
  57619. }
  57620. function fn4(a, b, c, d, e, m, k, s) {
  57621. return rotl(a + (b & d | c & ~d) + m + k | 0, s) + e | 0;
  57622. }
  57623. function fn5(a, b, c, d, e, m, k, s) {
  57624. return rotl(a + (b ^ (c | ~d)) + m + k | 0, s) + e | 0;
  57625. }
  57626. module.exports = RIPEMD160;
  57627. },{"buffer":216,"hash-base":261,"inherits":278}],384:[function(require,module,exports){
  57628. "use strict";
  57629. /* eslint-disable node/no-deprecated-api */
  57630. var buffer = require('buffer');
  57631. var Buffer = buffer.Buffer; // alternative to using Object.keys for old browsers
  57632. function copyProps(src, dst) {
  57633. for (var key in src) {
  57634. dst[key] = src[key];
  57635. }
  57636. }
  57637. if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
  57638. module.exports = buffer;
  57639. } else {
  57640. // Copy properties from require('buffer')
  57641. copyProps(buffer, exports);
  57642. exports.Buffer = SafeBuffer;
  57643. }
  57644. function SafeBuffer(arg, encodingOrOffset, length) {
  57645. return Buffer(arg, encodingOrOffset, length);
  57646. } // Copy static methods from Buffer
  57647. copyProps(Buffer, SafeBuffer);
  57648. SafeBuffer.from = function (arg, encodingOrOffset, length) {
  57649. if (typeof arg === 'number') {
  57650. throw new TypeError('Argument must not be a number');
  57651. }
  57652. return Buffer(arg, encodingOrOffset, length);
  57653. };
  57654. SafeBuffer.alloc = function (size, fill, encoding) {
  57655. if (typeof size !== 'number') {
  57656. throw new TypeError('Argument must be a number');
  57657. }
  57658. var buf = Buffer(size);
  57659. if (fill !== undefined) {
  57660. if (typeof encoding === 'string') {
  57661. buf.fill(fill, encoding);
  57662. } else {
  57663. buf.fill(fill);
  57664. }
  57665. } else {
  57666. buf.fill(0);
  57667. }
  57668. return buf;
  57669. };
  57670. SafeBuffer.allocUnsafe = function (size) {
  57671. if (typeof size !== 'number') {
  57672. throw new TypeError('Argument must be a number');
  57673. }
  57674. return Buffer(size);
  57675. };
  57676. SafeBuffer.allocUnsafeSlow = function (size) {
  57677. if (typeof size !== 'number') {
  57678. throw new TypeError('Argument must be a number');
  57679. }
  57680. return buffer.SlowBuffer(size);
  57681. };
  57682. },{"buffer":216}],385:[function(require,module,exports){
  57683. (function (process){
  57684. /* eslint-disable node/no-deprecated-api */
  57685. 'use strict';
  57686. 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); }
  57687. var buffer = require('buffer');
  57688. var Buffer = buffer.Buffer;
  57689. var safer = {};
  57690. var key;
  57691. for (key in buffer) {
  57692. if (!buffer.hasOwnProperty(key)) continue;
  57693. if (key === 'SlowBuffer' || key === 'Buffer') continue;
  57694. safer[key] = buffer[key];
  57695. }
  57696. var Safer = safer.Buffer = {};
  57697. for (key in Buffer) {
  57698. if (!Buffer.hasOwnProperty(key)) continue;
  57699. if (key === 'allocUnsafe' || key === 'allocUnsafeSlow') continue;
  57700. Safer[key] = Buffer[key];
  57701. }
  57702. safer.Buffer.prototype = Buffer.prototype;
  57703. if (!Safer.from || Safer.from === Uint8Array.from) {
  57704. Safer.from = function (value, encodingOrOffset, length) {
  57705. if (typeof value === 'number') {
  57706. throw new TypeError('The "value" argument must not be of type number. Received type ' + _typeof(value));
  57707. }
  57708. if (value && typeof value.length === 'undefined') {
  57709. throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type ' + _typeof(value));
  57710. }
  57711. return Buffer(value, encodingOrOffset, length);
  57712. };
  57713. }
  57714. if (!Safer.alloc) {
  57715. Safer.alloc = function (size, fill, encoding) {
  57716. if (typeof size !== 'number') {
  57717. throw new TypeError('The "size" argument must be of type number. Received type ' + _typeof(size));
  57718. }
  57719. if (size < 0 || size >= 2 * (1 << 30)) {
  57720. throw new RangeError('The value "' + size + '" is invalid for option "size"');
  57721. }
  57722. var buf = Buffer(size);
  57723. if (!fill || fill.length === 0) {
  57724. buf.fill(0);
  57725. } else if (typeof encoding === 'string') {
  57726. buf.fill(fill, encoding);
  57727. } else {
  57728. buf.fill(fill);
  57729. }
  57730. return buf;
  57731. };
  57732. }
  57733. if (!safer.kStringMaxLength) {
  57734. try {
  57735. safer.kStringMaxLength = process.binding('buffer').kStringMaxLength;
  57736. } catch (e) {// we can't determine kStringMaxLength in environments where process.binding
  57737. // is unsupported, so let's not set it
  57738. }
  57739. }
  57740. if (!safer.constants) {
  57741. safer.constants = {
  57742. MAX_LENGTH: safer.kMaxLength
  57743. };
  57744. if (safer.kStringMaxLength) {
  57745. safer.constants.MAX_STRING_LENGTH = safer.kStringMaxLength;
  57746. }
  57747. }
  57748. module.exports = safer;
  57749. }).call(this,require('_process'))
  57750. },{"_process":358,"buffer":216}],386:[function(require,module,exports){
  57751. "use strict";
  57752. 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; } } }; }
  57753. 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); }
  57754. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  57755. 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); } }
  57756. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  57757. function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
  57758. 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."); }
  57759. 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); }
  57760. function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
  57761. function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
  57762. 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; }
  57763. Object.defineProperty(exports, "__esModule", {
  57764. value: true
  57765. });
  57766. var ed5 = require("xmlchars/xml/1.0/ed5");
  57767. var ed2 = require("xmlchars/xml/1.1/ed2");
  57768. var NSed3 = require("xmlchars/xmlns/1.0/ed3");
  57769. var isS = ed5.isS;
  57770. var isChar10 = ed5.isChar;
  57771. var isNameStartChar = ed5.isNameStartChar;
  57772. var isNameChar = ed5.isNameChar;
  57773. var S_LIST = ed5.S_LIST;
  57774. var NAME_RE = ed5.NAME_RE;
  57775. var isChar11 = ed2.isChar;
  57776. var isNCNameStartChar = NSed3.isNCNameStartChar;
  57777. var isNCNameChar = NSed3.isNCNameChar;
  57778. var NC_NAME_RE = NSed3.NC_NAME_RE;
  57779. var XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
  57780. var XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
  57781. var rootNS = {
  57782. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  57783. __proto__: null,
  57784. xml: XML_NAMESPACE,
  57785. xmlns: XMLNS_NAMESPACE
  57786. };
  57787. var XML_ENTITIES = {
  57788. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  57789. __proto__: null,
  57790. amp: "&",
  57791. gt: ">",
  57792. lt: "<",
  57793. quot: "\"",
  57794. apos: "'"
  57795. }; // EOC: end-of-chunk
  57796. var EOC = -1;
  57797. var NL_LIKE = -2;
  57798. var S_BEGIN = 0; // Initial state.
  57799. var S_BEGIN_WHITESPACE = 1; // leading whitespace
  57800. var S_DOCTYPE = 2; // <!DOCTYPE
  57801. var S_DOCTYPE_QUOTE = 3; // <!DOCTYPE "//blah
  57802. var S_DTD = 4; // <!DOCTYPE "//blah" [ ...
  57803. var S_DTD_QUOTED = 5; // <!DOCTYPE "//blah" [ "foo
  57804. var S_DTD_OPEN_WAKA = 6;
  57805. var S_DTD_OPEN_WAKA_BANG = 7;
  57806. var S_DTD_COMMENT = 8; // <!--
  57807. var S_DTD_COMMENT_ENDING = 9; // <!-- blah -
  57808. var S_DTD_COMMENT_ENDED = 10; // <!-- blah --
  57809. var S_DTD_PI = 11; // <?
  57810. var S_DTD_PI_ENDING = 12; // <?hi "there" ?
  57811. var S_TEXT = 13; // general stuff
  57812. var S_ENTITY = 14; // &amp and such
  57813. var S_OPEN_WAKA = 15; // <
  57814. var S_OPEN_WAKA_BANG = 16; // <!...
  57815. var S_COMMENT = 17; // <!--
  57816. var S_COMMENT_ENDING = 18; // <!-- blah -
  57817. var S_COMMENT_ENDED = 19; // <!-- blah --
  57818. var S_CDATA = 20; // <![CDATA[ something
  57819. var S_CDATA_ENDING = 21; // ]
  57820. var S_CDATA_ENDING_2 = 22; // ]]
  57821. var S_PI_FIRST_CHAR = 23; // <?hi, first char
  57822. var S_PI_REST = 24; // <?hi, rest of the name
  57823. var S_PI_BODY = 25; // <?hi there
  57824. var S_PI_ENDING = 26; // <?hi "there" ?
  57825. var S_XML_DECL_NAME_START = 27; // <?xml
  57826. var S_XML_DECL_NAME = 28; // <?xml foo
  57827. var S_XML_DECL_EQ = 29; // <?xml foo=
  57828. var S_XML_DECL_VALUE_START = 30; // <?xml foo=
  57829. var S_XML_DECL_VALUE = 31; // <?xml foo="bar"
  57830. var S_XML_DECL_SEPARATOR = 32; // <?xml foo="bar"
  57831. var S_XML_DECL_ENDING = 33; // <?xml ... ?
  57832. var S_OPEN_TAG = 34; // <strong
  57833. var S_OPEN_TAG_SLASH = 35; // <strong /
  57834. var S_ATTRIB = 36; // <a
  57835. var S_ATTRIB_NAME = 37; // <a foo
  57836. var S_ATTRIB_NAME_SAW_WHITE = 38; // <a foo _
  57837. var S_ATTRIB_VALUE = 39; // <a foo=
  57838. var S_ATTRIB_VALUE_QUOTED = 40; // <a foo="bar
  57839. var S_ATTRIB_VALUE_CLOSED = 41; // <a foo="bar"
  57840. var S_ATTRIB_VALUE_UNQUOTED = 42; // <a foo=bar
  57841. var S_CLOSE_TAG = 43; // </a
  57842. var S_CLOSE_TAG_SAW_WHITE = 44; // </a >
  57843. var TAB = 9;
  57844. var NL = 0xA;
  57845. var CR = 0xD;
  57846. var SPACE = 0x20;
  57847. var BANG = 0x21;
  57848. var DQUOTE = 0x22;
  57849. var AMP = 0x26;
  57850. var SQUOTE = 0x27;
  57851. var MINUS = 0x2D;
  57852. var FORWARD_SLASH = 0x2F;
  57853. var SEMICOLON = 0x3B;
  57854. var LESS = 0x3C;
  57855. var EQUAL = 0x3D;
  57856. var GREATER = 0x3E;
  57857. var QUESTION = 0x3F;
  57858. var OPEN_BRACKET = 0x5B;
  57859. var CLOSE_BRACKET = 0x5D;
  57860. var NEL = 0x85;
  57861. var LS = 0x2028; // Line Separator
  57862. var isQuote = function isQuote(c) {
  57863. return c === DQUOTE || c === SQUOTE;
  57864. };
  57865. var QUOTES = [DQUOTE, SQUOTE];
  57866. var DOCTYPE_TERMINATOR = [].concat(QUOTES, [OPEN_BRACKET, GREATER]);
  57867. var DTD_TERMINATOR = [].concat(QUOTES, [LESS, CLOSE_BRACKET]);
  57868. var XML_DECL_NAME_TERMINATOR = [EQUAL, QUESTION].concat(_toConsumableArray(S_LIST));
  57869. var ATTRIB_VALUE_UNQUOTED_TERMINATOR = [].concat(_toConsumableArray(S_LIST), [GREATER, AMP, LESS]);
  57870. function nsPairCheck(parser, prefix, uri) {
  57871. switch (prefix) {
  57872. case "xml":
  57873. if (uri !== XML_NAMESPACE) {
  57874. parser.fail("xml prefix must be bound to ".concat(XML_NAMESPACE, "."));
  57875. }
  57876. break;
  57877. case "xmlns":
  57878. if (uri !== XMLNS_NAMESPACE) {
  57879. parser.fail("xmlns prefix must be bound to ".concat(XMLNS_NAMESPACE, "."));
  57880. }
  57881. break;
  57882. default:
  57883. }
  57884. switch (uri) {
  57885. case XMLNS_NAMESPACE:
  57886. 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, "."));
  57887. break;
  57888. case XML_NAMESPACE:
  57889. switch (prefix) {
  57890. case "xml":
  57891. // Assinging the XML namespace to "xml" is fine.
  57892. break;
  57893. case "":
  57894. parser.fail("the default namespace may not be set to ".concat(uri, "."));
  57895. break;
  57896. default:
  57897. parser.fail("may not assign the xml namespace to another prefix.");
  57898. }
  57899. break;
  57900. default:
  57901. }
  57902. }
  57903. function nsMappingCheck(parser, mapping) {
  57904. for (var _i = 0, _Object$keys = Object.keys(mapping); _i < _Object$keys.length; _i++) {
  57905. var local = _Object$keys[_i];
  57906. nsPairCheck(parser, local, mapping[local]);
  57907. }
  57908. }
  57909. var isNCName = function isNCName(name) {
  57910. return NC_NAME_RE.test(name);
  57911. };
  57912. var isName = function isName(name) {
  57913. return NAME_RE.test(name);
  57914. };
  57915. var FORBIDDEN_START = 0;
  57916. var FORBIDDEN_BRACKET = 1;
  57917. var FORBIDDEN_BRACKET_BRACKET = 2;
  57918. /**
  57919. * The list of supported events.
  57920. */
  57921. exports.EVENTS = ["xmldecl", "text", "processinginstruction", "doctype", "comment", "opentagstart", "attribute", "opentag", "closetag", "cdata", "error", "end", "ready"];
  57922. var EVENT_NAME_TO_HANDLER_NAME = {
  57923. xmldecl: "xmldeclHandler",
  57924. text: "textHandler",
  57925. processinginstruction: "piHandler",
  57926. doctype: "doctypeHandler",
  57927. comment: "commentHandler",
  57928. opentagstart: "openTagStartHandler",
  57929. attribute: "attributeHandler",
  57930. opentag: "openTagHandler",
  57931. closetag: "closeTagHandler",
  57932. cdata: "cdataHandler",
  57933. error: "errorHandler",
  57934. end: "endHandler",
  57935. ready: "readyHandler"
  57936. };
  57937. var SaxesParser = /*#__PURE__*/function () {
  57938. /**
  57939. * @param opt The parser options.
  57940. */
  57941. function SaxesParser(opt) {
  57942. _classCallCheck(this, SaxesParser);
  57943. this.opt = opt !== null && opt !== void 0 ? opt : {};
  57944. this.fragmentOpt = !!this.opt.fragment;
  57945. var xmlnsOpt = this.xmlnsOpt = !!this.opt.xmlns;
  57946. this.trackPosition = this.opt.position !== false;
  57947. this.fileName = this.opt.fileName;
  57948. if (xmlnsOpt) {
  57949. // This is the function we use to perform name checks on PIs and entities.
  57950. // When namespaces are used, colons are not allowed in PI target names or
  57951. // entity names. So the check depends on whether namespaces are used. See:
  57952. //
  57953. // https://www.w3.org/XML/xml-names-19990114-errata.html
  57954. // NE08
  57955. //
  57956. this.nameStartCheck = isNCNameStartChar;
  57957. this.nameCheck = isNCNameChar;
  57958. this.isName = isNCName; // eslint-disable-next-line @typescript-eslint/unbound-method
  57959. this.processAttribs = this.processAttribsNS; // eslint-disable-next-line @typescript-eslint/unbound-method
  57960. this.pushAttrib = this.pushAttribNS; // eslint-disable-next-line @typescript-eslint/no-explicit-any
  57961. this.ns = Object.assign({
  57962. __proto__: null
  57963. }, rootNS);
  57964. var additional = this.opt.additionalNamespaces;
  57965. if (additional != null) {
  57966. nsMappingCheck(this, additional);
  57967. Object.assign(this.ns, additional);
  57968. }
  57969. } else {
  57970. this.nameStartCheck = isNameStartChar;
  57971. this.nameCheck = isNameChar;
  57972. this.isName = isName; // eslint-disable-next-line @typescript-eslint/unbound-method
  57973. this.processAttribs = this.processAttribsPlain; // eslint-disable-next-line @typescript-eslint/unbound-method
  57974. this.pushAttrib = this.pushAttribPlain;
  57975. } //
  57976. // The order of the members in this table needs to correspond to the state
  57977. // numbers given to the states that correspond to the methods being recorded
  57978. // here.
  57979. //
  57980. this.stateTable = [
  57981. /* eslint-disable @typescript-eslint/unbound-method */
  57982. 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];
  57983. this._init();
  57984. }
  57985. /**
  57986. * Indicates whether or not the parser is closed. If ``true``, wait for
  57987. * the ``ready`` event to write again.
  57988. */
  57989. _createClass(SaxesParser, [{
  57990. key: "_init",
  57991. value: function _init() {
  57992. var _a;
  57993. this.openWakaBang = "";
  57994. this.text = "";
  57995. this.name = "";
  57996. this.piTarget = "";
  57997. this.entity = "";
  57998. this.q = null;
  57999. this.tags = [];
  58000. this.tag = null;
  58001. this.topNS = null;
  58002. this.chunk = "";
  58003. this.chunkPosition = 0;
  58004. this.i = 0;
  58005. this.prevI = 0;
  58006. this.carriedFromPrevious = undefined;
  58007. this.forbiddenState = FORBIDDEN_START;
  58008. this.attribList = []; // The logic is organized so as to minimize the need to check
  58009. // this.opt.fragment while parsing.
  58010. var fragmentOpt = this.fragmentOpt;
  58011. this.state = fragmentOpt ? S_TEXT : S_BEGIN; // We want these to be all true if we are dealing with a fragment.
  58012. this.reportedTextBeforeRoot = this.reportedTextAfterRoot = this.closedRoot = this.sawRoot = fragmentOpt; // An XML declaration is intially possible only when parsing whole
  58013. // documents.
  58014. this.xmlDeclPossible = !fragmentOpt;
  58015. this.xmlDeclExpects = ["version"];
  58016. this.entityReturnState = undefined;
  58017. var defaultXMLVersion = this.opt.defaultXMLVersion;
  58018. if (defaultXMLVersion === undefined) {
  58019. if (this.opt.forceXMLVersion === true) {
  58020. throw new Error("forceXMLVersion set but defaultXMLVersion is not set");
  58021. }
  58022. defaultXMLVersion = "1.0";
  58023. }
  58024. this.setXMLVersion(defaultXMLVersion);
  58025. this.positionAtNewLine = 0;
  58026. this.doctype = false;
  58027. this._closed = false;
  58028. this.xmlDecl = {
  58029. version: undefined,
  58030. encoding: undefined,
  58031. standalone: undefined
  58032. };
  58033. this.line = 1;
  58034. this.column = 0;
  58035. this.ENTITIES = Object.create(XML_ENTITIES); // eslint-disable-next-line no-unused-expressions
  58036. (_a = this.readyHandler) === null || _a === void 0 ? void 0 : _a.call(this);
  58037. }
  58038. /**
  58039. * The stream position the parser is currently looking at. This field is
  58040. * zero-based.
  58041. *
  58042. * This field is not based on counting Unicode characters but is to be
  58043. * interpreted as a plain index into a JavaScript string.
  58044. */
  58045. }, {
  58046. key: "on",
  58047. /**
  58048. * Set an event listener on an event. The parser supports one handler per
  58049. * event type. If you try to set an event handler over an existing handler,
  58050. * the old handler is silently overwritten.
  58051. *
  58052. * @param name The event to listen to.
  58053. *
  58054. * @param handler The handler to set.
  58055. */
  58056. value: function on(name, handler) {
  58057. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  58058. this[EVENT_NAME_TO_HANDLER_NAME[name]] = handler;
  58059. }
  58060. /**
  58061. * Unset an event handler.
  58062. *
  58063. * @parma name The event to stop listening to.
  58064. */
  58065. }, {
  58066. key: "off",
  58067. value: function off(name) {
  58068. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  58069. this[EVENT_NAME_TO_HANDLER_NAME[name]] = undefined;
  58070. }
  58071. /**
  58072. * Make an error object. The error object will have a message that contains
  58073. * the ``fileName`` option passed at the creation of the parser. If position
  58074. * tracking was turned on, it will also have line and column number
  58075. * information.
  58076. *
  58077. * @param message The message describing the error to report.
  58078. *
  58079. * @returns An error object with a properly formatted message.
  58080. */
  58081. }, {
  58082. key: "makeError",
  58083. value: function makeError(message) {
  58084. var _a;
  58085. var msg = (_a = this.fileName) !== null && _a !== void 0 ? _a : "";
  58086. if (this.trackPosition) {
  58087. if (msg.length > 0) {
  58088. msg += ":";
  58089. }
  58090. msg += "".concat(this.line, ":").concat(this.column);
  58091. }
  58092. if (msg.length > 0) {
  58093. msg += ": ";
  58094. }
  58095. return new Error(msg + message);
  58096. }
  58097. /**
  58098. * Report a parsing error. This method is made public so that client code may
  58099. * check for issues that are outside the scope of this project and can report
  58100. * errors.
  58101. *
  58102. * @param message The error to report.
  58103. *
  58104. * @returns this
  58105. */
  58106. }, {
  58107. key: "fail",
  58108. value: function fail(message) {
  58109. var err = this.makeError(message);
  58110. var handler = this.errorHandler;
  58111. if (handler === undefined) {
  58112. throw err;
  58113. } else {
  58114. handler(err);
  58115. }
  58116. return this;
  58117. }
  58118. /**
  58119. * Write a XML data to the parser.
  58120. *
  58121. * @param chunk The XML data to write.
  58122. *
  58123. * @returns this
  58124. */
  58125. }, {
  58126. key: "write",
  58127. value: function write(chunk) {
  58128. if (this.closed) {
  58129. return this.fail("cannot write after close; assign an onready handler.");
  58130. }
  58131. var end = false;
  58132. if (chunk === null) {
  58133. // We cannot return immediately because carriedFromPrevious may need
  58134. // processing.
  58135. end = true;
  58136. chunk = "";
  58137. } else if (_typeof(chunk) === "object") {
  58138. chunk = chunk.toString();
  58139. } // We checked if performing a pre-decomposition of the string into an array
  58140. // of single complete characters (``Array.from(chunk)``) would be faster
  58141. // than the current repeated calls to ``charCodeAt``. As of August 2018, it
  58142. // isn't. (There may be Node-specific code that would perform faster than
  58143. // ``Array.from`` but don't want to be dependent on Node.)
  58144. if (this.carriedFromPrevious !== undefined) {
  58145. // The previous chunk had char we must carry over.
  58146. chunk = "".concat(this.carriedFromPrevious).concat(chunk);
  58147. this.carriedFromPrevious = undefined;
  58148. }
  58149. var limit = chunk.length;
  58150. var lastCode = chunk.charCodeAt(limit - 1);
  58151. if (!end && ( // A trailing CR or surrogate must be carried over to the next
  58152. // chunk.
  58153. lastCode === CR || lastCode >= 0xD800 && lastCode <= 0xDBFF)) {
  58154. // The chunk ends with a character that must be carried over. We cannot
  58155. // know how to handle it until we get the next chunk or the end of the
  58156. // stream. So save it for later.
  58157. this.carriedFromPrevious = chunk[limit - 1];
  58158. limit--;
  58159. chunk = chunk.slice(0, limit);
  58160. }
  58161. var stateTable = this.stateTable;
  58162. this.chunk = chunk;
  58163. this.i = 0;
  58164. while (this.i < limit) {
  58165. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  58166. stateTable[this.state].call(this);
  58167. }
  58168. this.chunkPosition += limit;
  58169. return end ? this.end() : this;
  58170. }
  58171. /**
  58172. * Close the current stream. Perform final well-formedness checks and reset
  58173. * the parser tstate.
  58174. *
  58175. * @returns this
  58176. */
  58177. }, {
  58178. key: "close",
  58179. value: function close() {
  58180. return this.write(null);
  58181. }
  58182. /**
  58183. * Get a single code point out of the current chunk. This updates the current
  58184. * position if we do position tracking.
  58185. *
  58186. * This is the algorithm to use for XML 1.0.
  58187. *
  58188. * @returns The character read.
  58189. */
  58190. }, {
  58191. key: "getCode10",
  58192. value: function getCode10() {
  58193. var chunk = this.chunk,
  58194. i = this.i;
  58195. this.prevI = i; // Yes, we do this instead of doing this.i++. Doing it this way, we do not
  58196. // read this.i again, which is a bit faster.
  58197. this.i = i + 1;
  58198. if (i >= chunk.length) {
  58199. return EOC;
  58200. } // Using charCodeAt and handling the surrogates ourselves is faster
  58201. // than using codePointAt.
  58202. var code = chunk.charCodeAt(i);
  58203. this.column++;
  58204. if (code < 0xD800) {
  58205. if (code >= SPACE || code === TAB) {
  58206. return code;
  58207. }
  58208. switch (code) {
  58209. case NL:
  58210. this.line++;
  58211. this.column = 0;
  58212. this.positionAtNewLine = this.position;
  58213. return NL;
  58214. case CR:
  58215. // We may get NaN if we read past the end of the chunk, which is fine.
  58216. if (chunk.charCodeAt(i + 1) === NL) {
  58217. // A \r\n sequence is converted to \n so we have to skip over the
  58218. // next character. We already know it has a size of 1 so ++ is fine
  58219. // here.
  58220. this.i = i + 2;
  58221. } // Otherwise, a \r is just converted to \n, so we don't have to skip
  58222. // ahead.
  58223. // In either case, \r becomes \n.
  58224. this.line++;
  58225. this.column = 0;
  58226. this.positionAtNewLine = this.position;
  58227. return NL_LIKE;
  58228. default:
  58229. // If we get here, then code < SPACE and it is not NL CR or TAB.
  58230. this.fail("disallowed character.");
  58231. return code;
  58232. }
  58233. }
  58234. if (code > 0xDBFF) {
  58235. // This is a specialized version of isChar10 that takes into account
  58236. // that in this context code > 0xDBFF and code <= 0xFFFF. So it does not
  58237. // test cases that don't need testing.
  58238. if (!(code >= 0xE000 && code <= 0xFFFD)) {
  58239. this.fail("disallowed character.");
  58240. }
  58241. return code;
  58242. }
  58243. var final = 0x10000 + (code - 0xD800) * 0x400 + (chunk.charCodeAt(i + 1) - 0xDC00);
  58244. this.i = i + 2; // This is a specialized version of isChar10 that takes into account that in
  58245. // this context necessarily final >= 0x10000.
  58246. if (final > 0x10FFFF) {
  58247. this.fail("disallowed character.");
  58248. }
  58249. return final;
  58250. }
  58251. /**
  58252. * Get a single code point out of the current chunk. This updates the current
  58253. * position if we do position tracking.
  58254. *
  58255. * This is the algorithm to use for XML 1.1.
  58256. *
  58257. * @returns {number} The character read.
  58258. */
  58259. }, {
  58260. key: "getCode11",
  58261. value: function getCode11() {
  58262. var chunk = this.chunk,
  58263. i = this.i;
  58264. this.prevI = i; // Yes, we do this instead of doing this.i++. Doing it this way, we do not
  58265. // read this.i again, which is a bit faster.
  58266. this.i = i + 1;
  58267. if (i >= chunk.length) {
  58268. return EOC;
  58269. } // Using charCodeAt and handling the surrogates ourselves is faster
  58270. // than using codePointAt.
  58271. var code = chunk.charCodeAt(i);
  58272. this.column++;
  58273. if (code < 0xD800) {
  58274. if (code > 0x1F && code < 0x7F || code > 0x9F && code !== LS || code === TAB) {
  58275. return code;
  58276. }
  58277. switch (code) {
  58278. case NL:
  58279. // 0xA
  58280. this.line++;
  58281. this.column = 0;
  58282. this.positionAtNewLine = this.position;
  58283. return NL;
  58284. case CR:
  58285. {
  58286. // 0xD
  58287. // We may get NaN if we read past the end of the chunk, which is
  58288. // fine.
  58289. var next = chunk.charCodeAt(i + 1);
  58290. if (next === NL || next === NEL) {
  58291. // A CR NL or CR NEL sequence is converted to NL so we have to skip
  58292. // over the next character. We already know it has a size of 1.
  58293. this.i = i + 2;
  58294. } // Otherwise, a CR is just converted to NL, no skip.
  58295. }
  58296. /* yes, fall through */
  58297. case NEL: // 0x85
  58298. case LS:
  58299. // Ox2028
  58300. this.line++;
  58301. this.column = 0;
  58302. this.positionAtNewLine = this.position;
  58303. return NL_LIKE;
  58304. default:
  58305. this.fail("disallowed character.");
  58306. return code;
  58307. }
  58308. }
  58309. if (code > 0xDBFF) {
  58310. // This is a specialized version of isCharAndNotRestricted that takes into
  58311. // account that in this context code > 0xDBFF and code <= 0xFFFF. So it
  58312. // does not test cases that don't need testing.
  58313. if (!(code >= 0xE000 && code <= 0xFFFD)) {
  58314. this.fail("disallowed character.");
  58315. }
  58316. return code;
  58317. }
  58318. var final = 0x10000 + (code - 0xD800) * 0x400 + (chunk.charCodeAt(i + 1) - 0xDC00);
  58319. this.i = i + 2; // This is a specialized version of isCharAndNotRestricted that takes into
  58320. // account that in this context necessarily final >= 0x10000.
  58321. if (final > 0x10FFFF) {
  58322. this.fail("disallowed character.");
  58323. }
  58324. return final;
  58325. }
  58326. /**
  58327. * Like ``getCode`` but with the return value normalized so that ``NL`` is
  58328. * returned for ``NL_LIKE``.
  58329. */
  58330. }, {
  58331. key: "getCodeNorm",
  58332. value: function getCodeNorm() {
  58333. var c = this.getCode();
  58334. return c === NL_LIKE ? NL : c;
  58335. }
  58336. }, {
  58337. key: "unget",
  58338. value: function unget() {
  58339. this.i = this.prevI;
  58340. this.column--;
  58341. }
  58342. /**
  58343. * Capture characters into a buffer until encountering one of a set of
  58344. * characters.
  58345. *
  58346. * @param chars An array of codepoints. Encountering a character in the array
  58347. * ends the capture. (``chars`` may safely contain ``NL``.)
  58348. *
  58349. * @return The character code that made the capture end, or ``EOC`` if we hit
  58350. * the end of the chunk. The return value cannot be NL_LIKE: NL is returned
  58351. * instead.
  58352. */
  58353. }, {
  58354. key: "captureTo",
  58355. value: function captureTo(chars) {
  58356. var start = this.i;
  58357. var chunk = this.chunk; // eslint-disable-next-line no-constant-condition
  58358. while (true) {
  58359. var c = this.getCode();
  58360. var isNLLike = c === NL_LIKE;
  58361. var final = isNLLike ? NL : c;
  58362. if (final === EOC || chars.includes(final)) {
  58363. this.text += chunk.slice(start, this.prevI);
  58364. return final;
  58365. }
  58366. if (isNLLike) {
  58367. this.text += "".concat(chunk.slice(start, this.prevI), "\n");
  58368. start = this.i;
  58369. }
  58370. }
  58371. }
  58372. /**
  58373. * Capture characters into a buffer until encountering a character.
  58374. *
  58375. * @param char The codepoint that ends the capture. **NOTE ``char`` MAY NOT
  58376. * CONTAIN ``NL``.** Passing ``NL`` will result in buggy behavior.
  58377. *
  58378. * @return ``true`` if we ran into the character. Otherwise, we ran into the
  58379. * end of the current chunk.
  58380. */
  58381. }, {
  58382. key: "captureToChar",
  58383. value: function captureToChar(char) {
  58384. var start = this.i;
  58385. var chunk = this.chunk; // eslint-disable-next-line no-constant-condition
  58386. while (true) {
  58387. var c = this.getCode();
  58388. switch (c) {
  58389. case NL_LIKE:
  58390. this.text += "".concat(chunk.slice(start, this.prevI), "\n");
  58391. start = this.i;
  58392. c = NL;
  58393. break;
  58394. case EOC:
  58395. this.text += chunk.slice(start);
  58396. return false;
  58397. default:
  58398. }
  58399. if (c === char) {
  58400. this.text += chunk.slice(start, this.prevI);
  58401. return true;
  58402. }
  58403. }
  58404. }
  58405. /**
  58406. * Capture characters that satisfy ``isNameChar`` into the ``name`` field of
  58407. * this parser.
  58408. *
  58409. * @return The character code that made the test fail, or ``EOC`` if we hit
  58410. * the end of the chunk. The return value cannot be NL_LIKE: NL is returned
  58411. * instead.
  58412. */
  58413. }, {
  58414. key: "captureNameChars",
  58415. value: function captureNameChars() {
  58416. var chunk = this.chunk,
  58417. start = this.i; // eslint-disable-next-line no-constant-condition
  58418. while (true) {
  58419. var c = this.getCode();
  58420. if (c === EOC) {
  58421. this.name += chunk.slice(start);
  58422. return EOC;
  58423. } // NL is not a name char so we don't have to test specifically for it.
  58424. if (!isNameChar(c)) {
  58425. this.name += chunk.slice(start, this.prevI);
  58426. return c === NL_LIKE ? NL : c;
  58427. }
  58428. }
  58429. }
  58430. /**
  58431. * Skip white spaces.
  58432. *
  58433. * @return The character that ended the skip, or ``EOC`` if we hit
  58434. * the end of the chunk. The return value cannot be NL_LIKE: NL is returned
  58435. * instead.
  58436. */
  58437. }, {
  58438. key: "skipSpaces",
  58439. value: function skipSpaces() {
  58440. // eslint-disable-next-line no-constant-condition
  58441. while (true) {
  58442. var c = this.getCodeNorm();
  58443. if (c === EOC || !isS(c)) {
  58444. return c;
  58445. }
  58446. }
  58447. }
  58448. }, {
  58449. key: "setXMLVersion",
  58450. value: function setXMLVersion(version) {
  58451. this.currentXMLVersion = version;
  58452. /* eslint-disable @typescript-eslint/unbound-method */
  58453. if (version === "1.0") {
  58454. this.isChar = isChar10;
  58455. this.getCode = this.getCode10;
  58456. } else {
  58457. this.isChar = isChar11;
  58458. this.getCode = this.getCode11;
  58459. }
  58460. /* eslint-enable @typescript-eslint/unbound-method */
  58461. } // STATE ENGINE METHODS
  58462. // This needs to be a state separate from S_BEGIN_WHITESPACE because we want
  58463. // to be sure never to come back to this state later.
  58464. }, {
  58465. key: "sBegin",
  58466. value: function sBegin() {
  58467. // We are essentially peeking at the first character of the chunk. Since
  58468. // S_BEGIN can be in effect only when we start working on the first chunk,
  58469. // the index at which we must look is necessarily 0. Note also that the
  58470. // following test does not depend on decoding surrogates.
  58471. // If the initial character is 0xFEFF, ignore it.
  58472. if (this.chunk.charCodeAt(0) === 0xFEFF) {
  58473. this.i++;
  58474. this.column++;
  58475. }
  58476. this.state = S_BEGIN_WHITESPACE;
  58477. }
  58478. }, {
  58479. key: "sBeginWhitespace",
  58480. value: function sBeginWhitespace() {
  58481. // We need to know whether we've encountered spaces or not because as soon
  58482. // as we run into a space, an XML declaration is no longer possible. Rather
  58483. // than slow down skipSpaces even in places where we don't care whether it
  58484. // skipped anything or not, we check whether prevI is equal to the value of
  58485. // i from before we skip spaces.
  58486. var iBefore = this.i;
  58487. var c = this.skipSpaces();
  58488. if (this.prevI !== iBefore) {
  58489. this.xmlDeclPossible = false;
  58490. }
  58491. switch (c) {
  58492. case LESS:
  58493. this.state = S_OPEN_WAKA; // We could naively call closeText but in this state, it is not normal
  58494. // to have text be filled with any data.
  58495. if (this.text.length !== 0) {
  58496. throw new Error("no-empty text at start");
  58497. }
  58498. break;
  58499. case EOC:
  58500. break;
  58501. default:
  58502. this.unget();
  58503. this.state = S_TEXT;
  58504. this.xmlDeclPossible = false;
  58505. }
  58506. }
  58507. }, {
  58508. key: "sDoctype",
  58509. value: function sDoctype() {
  58510. var _a;
  58511. var c = this.captureTo(DOCTYPE_TERMINATOR);
  58512. switch (c) {
  58513. case GREATER:
  58514. {
  58515. // eslint-disable-next-line no-unused-expressions
  58516. (_a = this.doctypeHandler) === null || _a === void 0 ? void 0 : _a.call(this, this.text);
  58517. this.text = "";
  58518. this.state = S_TEXT;
  58519. this.doctype = true; // just remember that we saw it.
  58520. break;
  58521. }
  58522. case EOC:
  58523. break;
  58524. default:
  58525. this.text += String.fromCodePoint(c);
  58526. if (c === OPEN_BRACKET) {
  58527. this.state = S_DTD;
  58528. } else if (isQuote(c)) {
  58529. this.state = S_DOCTYPE_QUOTE;
  58530. this.q = c;
  58531. }
  58532. }
  58533. }
  58534. }, {
  58535. key: "sDoctypeQuote",
  58536. value: function sDoctypeQuote() {
  58537. var q = this.q;
  58538. if (this.captureToChar(q)) {
  58539. this.text += String.fromCodePoint(q);
  58540. this.q = null;
  58541. this.state = S_DOCTYPE;
  58542. }
  58543. }
  58544. }, {
  58545. key: "sDTD",
  58546. value: function sDTD() {
  58547. var c = this.captureTo(DTD_TERMINATOR);
  58548. if (c === EOC) {
  58549. return;
  58550. }
  58551. this.text += String.fromCodePoint(c);
  58552. if (c === CLOSE_BRACKET) {
  58553. this.state = S_DOCTYPE;
  58554. } else if (c === LESS) {
  58555. this.state = S_DTD_OPEN_WAKA;
  58556. } else if (isQuote(c)) {
  58557. this.state = S_DTD_QUOTED;
  58558. this.q = c;
  58559. }
  58560. }
  58561. }, {
  58562. key: "sDTDQuoted",
  58563. value: function sDTDQuoted() {
  58564. var q = this.q;
  58565. if (this.captureToChar(q)) {
  58566. this.text += String.fromCodePoint(q);
  58567. this.state = S_DTD;
  58568. this.q = null;
  58569. }
  58570. }
  58571. }, {
  58572. key: "sDTDOpenWaka",
  58573. value: function sDTDOpenWaka() {
  58574. var c = this.getCodeNorm();
  58575. this.text += String.fromCodePoint(c);
  58576. switch (c) {
  58577. case BANG:
  58578. this.state = S_DTD_OPEN_WAKA_BANG;
  58579. this.openWakaBang = "";
  58580. break;
  58581. case QUESTION:
  58582. this.state = S_DTD_PI;
  58583. break;
  58584. default:
  58585. this.state = S_DTD;
  58586. }
  58587. }
  58588. }, {
  58589. key: "sDTDOpenWakaBang",
  58590. value: function sDTDOpenWakaBang() {
  58591. var char = String.fromCodePoint(this.getCodeNorm());
  58592. var owb = this.openWakaBang += char;
  58593. this.text += char;
  58594. if (owb !== "-") {
  58595. this.state = owb === "--" ? S_DTD_COMMENT : S_DTD;
  58596. this.openWakaBang = "";
  58597. }
  58598. }
  58599. }, {
  58600. key: "sDTDComment",
  58601. value: function sDTDComment() {
  58602. if (this.captureToChar(MINUS)) {
  58603. this.text += "-";
  58604. this.state = S_DTD_COMMENT_ENDING;
  58605. }
  58606. }
  58607. }, {
  58608. key: "sDTDCommentEnding",
  58609. value: function sDTDCommentEnding() {
  58610. var c = this.getCodeNorm();
  58611. this.text += String.fromCodePoint(c);
  58612. this.state = c === MINUS ? S_DTD_COMMENT_ENDED : S_DTD_COMMENT;
  58613. }
  58614. }, {
  58615. key: "sDTDCommentEnded",
  58616. value: function sDTDCommentEnded() {
  58617. var c = this.getCodeNorm();
  58618. this.text += String.fromCodePoint(c);
  58619. if (c === GREATER) {
  58620. this.state = S_DTD;
  58621. } else {
  58622. this.fail("malformed comment."); // <!-- blah -- bloo --> will be recorded as
  58623. // a comment of " blah -- bloo "
  58624. this.state = S_DTD_COMMENT;
  58625. }
  58626. }
  58627. }, {
  58628. key: "sDTDPI",
  58629. value: function sDTDPI() {
  58630. if (this.captureToChar(QUESTION)) {
  58631. this.text += "?";
  58632. this.state = S_DTD_PI_ENDING;
  58633. }
  58634. }
  58635. }, {
  58636. key: "sDTDPIEnding",
  58637. value: function sDTDPIEnding() {
  58638. var c = this.getCodeNorm();
  58639. this.text += String.fromCodePoint(c);
  58640. if (c === GREATER) {
  58641. this.state = S_DTD;
  58642. }
  58643. }
  58644. }, {
  58645. key: "sText",
  58646. value: function sText() {
  58647. //
  58648. // We did try a version of saxes where the S_TEXT state was split in two
  58649. // states: one for text inside the root element, and one for text
  58650. // outside. This was avoiding having to test this.tags.length to decide
  58651. // what implementation to actually use.
  58652. //
  58653. // Peformance testing on gigabyte-size files did not show any advantage to
  58654. // using the two states solution instead of the current one. Conversely, it
  58655. // made the code a bit more complicated elsewhere. For instance, a comment
  58656. // can appear before the root element so when a comment ended it was
  58657. // necessary to determine whether to return to the S_TEXT state or to the
  58658. // new text-outside-root state.
  58659. //
  58660. if (this.tags.length !== 0) {
  58661. this.handleTextInRoot();
  58662. } else {
  58663. this.handleTextOutsideRoot();
  58664. }
  58665. }
  58666. }, {
  58667. key: "sEntity",
  58668. value: function sEntity() {
  58669. // This is essentially a specialized version of captureToChar(SEMICOLON...)
  58670. var start = this.i;
  58671. var chunk = this.chunk; // eslint-disable-next-line no-labels, no-restricted-syntax
  58672. loop: // eslint-disable-next-line no-constant-condition
  58673. while (true) {
  58674. switch (this.getCode()) {
  58675. case NL_LIKE:
  58676. this.entity += "".concat(chunk.slice(start, this.prevI), "\n");
  58677. start = this.i;
  58678. break;
  58679. case SEMICOLON:
  58680. {
  58681. var entityReturnState = this.entityReturnState;
  58682. var entity = this.entity + chunk.slice(start, this.prevI);
  58683. this.state = entityReturnState;
  58684. var parsed = void 0;
  58685. if (entity === "") {
  58686. this.fail("empty entity name.");
  58687. parsed = "&;";
  58688. } else {
  58689. parsed = this.parseEntity(entity);
  58690. this.entity = "";
  58691. }
  58692. if (entityReturnState !== S_TEXT || this.textHandler !== undefined) {
  58693. this.text += parsed;
  58694. } // eslint-disable-next-line no-labels
  58695. break loop;
  58696. }
  58697. case EOC:
  58698. this.entity += chunk.slice(start); // eslint-disable-next-line no-labels
  58699. break loop;
  58700. default:
  58701. }
  58702. }
  58703. }
  58704. }, {
  58705. key: "sOpenWaka",
  58706. value: function sOpenWaka() {
  58707. // Reminder: a state handler is called with at least one character
  58708. // available in the current chunk. So the first call to get code inside of
  58709. // a state handler cannot return ``EOC``. That's why we don't test
  58710. // for it.
  58711. var c = this.getCode(); // either a /, ?, !, or text is coming next.
  58712. if (isNameStartChar(c)) {
  58713. this.state = S_OPEN_TAG;
  58714. this.unget();
  58715. this.xmlDeclPossible = false;
  58716. } else {
  58717. switch (c) {
  58718. case FORWARD_SLASH:
  58719. this.state = S_CLOSE_TAG;
  58720. this.xmlDeclPossible = false;
  58721. break;
  58722. case BANG:
  58723. this.state = S_OPEN_WAKA_BANG;
  58724. this.openWakaBang = "";
  58725. this.xmlDeclPossible = false;
  58726. break;
  58727. case QUESTION:
  58728. this.state = S_PI_FIRST_CHAR;
  58729. break;
  58730. default:
  58731. this.fail("disallowed character in tag name");
  58732. this.state = S_TEXT;
  58733. this.xmlDeclPossible = false;
  58734. }
  58735. }
  58736. }
  58737. }, {
  58738. key: "sOpenWakaBang",
  58739. value: function sOpenWakaBang() {
  58740. this.openWakaBang += String.fromCodePoint(this.getCodeNorm());
  58741. switch (this.openWakaBang) {
  58742. case "[CDATA[":
  58743. if (!this.sawRoot && !this.reportedTextBeforeRoot) {
  58744. this.fail("text data outside of root node.");
  58745. this.reportedTextBeforeRoot = true;
  58746. }
  58747. if (this.closedRoot && !this.reportedTextAfterRoot) {
  58748. this.fail("text data outside of root node.");
  58749. this.reportedTextAfterRoot = true;
  58750. }
  58751. this.state = S_CDATA;
  58752. this.openWakaBang = "";
  58753. break;
  58754. case "--":
  58755. this.state = S_COMMENT;
  58756. this.openWakaBang = "";
  58757. break;
  58758. case "DOCTYPE":
  58759. this.state = S_DOCTYPE;
  58760. if (this.doctype || this.sawRoot) {
  58761. this.fail("inappropriately located doctype declaration.");
  58762. }
  58763. this.openWakaBang = "";
  58764. break;
  58765. default:
  58766. // 7 happens to be the maximum length of the string that can possibly
  58767. // match one of the cases above.
  58768. if (this.openWakaBang.length >= 7) {
  58769. this.fail("incorrect syntax.");
  58770. }
  58771. }
  58772. }
  58773. }, {
  58774. key: "sComment",
  58775. value: function sComment() {
  58776. if (this.captureToChar(MINUS)) {
  58777. this.state = S_COMMENT_ENDING;
  58778. }
  58779. }
  58780. }, {
  58781. key: "sCommentEnding",
  58782. value: function sCommentEnding() {
  58783. var _a;
  58784. var c = this.getCodeNorm();
  58785. if (c === MINUS) {
  58786. this.state = S_COMMENT_ENDED; // eslint-disable-next-line no-unused-expressions
  58787. (_a = this.commentHandler) === null || _a === void 0 ? void 0 : _a.call(this, this.text);
  58788. this.text = "";
  58789. } else {
  58790. this.text += "-".concat(String.fromCodePoint(c));
  58791. this.state = S_COMMENT;
  58792. }
  58793. }
  58794. }, {
  58795. key: "sCommentEnded",
  58796. value: function sCommentEnded() {
  58797. var c = this.getCodeNorm();
  58798. if (c !== GREATER) {
  58799. this.fail("malformed comment."); // <!-- blah -- bloo --> will be recorded as
  58800. // a comment of " blah -- bloo "
  58801. this.text += "--".concat(String.fromCodePoint(c));
  58802. this.state = S_COMMENT;
  58803. } else {
  58804. this.state = S_TEXT;
  58805. }
  58806. }
  58807. }, {
  58808. key: "sCData",
  58809. value: function sCData() {
  58810. if (this.captureToChar(CLOSE_BRACKET)) {
  58811. this.state = S_CDATA_ENDING;
  58812. }
  58813. }
  58814. }, {
  58815. key: "sCDataEnding",
  58816. value: function sCDataEnding() {
  58817. var c = this.getCodeNorm();
  58818. if (c === CLOSE_BRACKET) {
  58819. this.state = S_CDATA_ENDING_2;
  58820. } else {
  58821. this.text += "]".concat(String.fromCodePoint(c));
  58822. this.state = S_CDATA;
  58823. }
  58824. }
  58825. }, {
  58826. key: "sCDataEnding2",
  58827. value: function sCDataEnding2() {
  58828. var _a;
  58829. var c = this.getCodeNorm();
  58830. switch (c) {
  58831. case GREATER:
  58832. {
  58833. // eslint-disable-next-line no-unused-expressions
  58834. (_a = this.cdataHandler) === null || _a === void 0 ? void 0 : _a.call(this, this.text);
  58835. this.text = "";
  58836. this.state = S_TEXT;
  58837. break;
  58838. }
  58839. case CLOSE_BRACKET:
  58840. this.text += "]";
  58841. break;
  58842. default:
  58843. this.text += "]]".concat(String.fromCodePoint(c));
  58844. this.state = S_CDATA;
  58845. }
  58846. } // We need this separate state to check the first character fo the pi target
  58847. // with this.nameStartCheck which allows less characters than this.nameCheck.
  58848. }, {
  58849. key: "sPIFirstChar",
  58850. value: function sPIFirstChar() {
  58851. var c = this.getCodeNorm(); // This is first because in the case where the file is well-formed this is
  58852. // the branch taken. We optimize for well-formedness.
  58853. if (this.nameStartCheck(c)) {
  58854. this.piTarget += String.fromCodePoint(c);
  58855. this.state = S_PI_REST;
  58856. } else if (c === QUESTION || isS(c)) {
  58857. this.fail("processing instruction without a target.");
  58858. this.state = c === QUESTION ? S_PI_ENDING : S_PI_BODY;
  58859. } else {
  58860. this.fail("disallowed character in processing instruction name.");
  58861. this.piTarget += String.fromCodePoint(c);
  58862. this.state = S_PI_REST;
  58863. }
  58864. }
  58865. }, {
  58866. key: "sPIRest",
  58867. value: function sPIRest() {
  58868. // Capture characters into a piTarget while ``this.nameCheck`` run on the
  58869. // character read returns true.
  58870. var chunk = this.chunk,
  58871. start = this.i; // eslint-disable-next-line no-constant-condition
  58872. while (true) {
  58873. var c = this.getCodeNorm();
  58874. if (c === EOC) {
  58875. this.piTarget += chunk.slice(start);
  58876. return;
  58877. } // NL cannot satisfy this.nameCheck so we don't have to test specifically
  58878. // for it.
  58879. if (!this.nameCheck(c)) {
  58880. this.piTarget += chunk.slice(start, this.prevI);
  58881. var isQuestion = c === QUESTION;
  58882. if (isQuestion || isS(c)) {
  58883. if (this.piTarget === "xml") {
  58884. if (!this.xmlDeclPossible) {
  58885. this.fail("an XML declaration must be at the start of the document.");
  58886. }
  58887. this.state = isQuestion ? S_XML_DECL_ENDING : S_XML_DECL_NAME_START;
  58888. } else {
  58889. this.state = isQuestion ? S_PI_ENDING : S_PI_BODY;
  58890. }
  58891. } else {
  58892. this.fail("disallowed character in processing instruction name.");
  58893. this.piTarget += String.fromCodePoint(c);
  58894. }
  58895. break;
  58896. }
  58897. }
  58898. }
  58899. }, {
  58900. key: "sPIBody",
  58901. value: function sPIBody() {
  58902. if (this.text.length === 0) {
  58903. var c = this.getCodeNorm();
  58904. if (c === QUESTION) {
  58905. this.state = S_PI_ENDING;
  58906. } else if (!isS(c)) {
  58907. this.text = String.fromCodePoint(c);
  58908. }
  58909. } // The question mark character is not valid inside any of the XML
  58910. // declaration name/value pairs.
  58911. else if (this.captureToChar(QUESTION)) {
  58912. this.state = S_PI_ENDING;
  58913. }
  58914. }
  58915. }, {
  58916. key: "sPIEnding",
  58917. value: function sPIEnding() {
  58918. var _a;
  58919. var c = this.getCodeNorm();
  58920. if (c === GREATER) {
  58921. var piTarget = this.piTarget;
  58922. if (piTarget.toLowerCase() === "xml") {
  58923. this.fail("the XML declaration must appear at the start of the document.");
  58924. } // eslint-disable-next-line no-unused-expressions
  58925. (_a = this.piHandler) === null || _a === void 0 ? void 0 : _a.call(this, {
  58926. target: piTarget,
  58927. body: this.text
  58928. });
  58929. this.piTarget = this.text = "";
  58930. this.state = S_TEXT;
  58931. } else if (c === QUESTION) {
  58932. // We ran into ?? as part of a processing instruction. We initially took
  58933. // the first ? as a sign that the PI was ending, but it is not. So we have
  58934. // to add it to the body but we take the new ? as a sign that the PI is
  58935. // ending.
  58936. this.text += "?";
  58937. } else {
  58938. this.text += "?".concat(String.fromCodePoint(c));
  58939. this.state = S_PI_BODY;
  58940. }
  58941. this.xmlDeclPossible = false;
  58942. }
  58943. }, {
  58944. key: "sXMLDeclNameStart",
  58945. value: function sXMLDeclNameStart() {
  58946. var c = this.skipSpaces(); // The question mark character is not valid inside any of the XML
  58947. // declaration name/value pairs.
  58948. if (c === QUESTION) {
  58949. // It is valid to go to S_XML_DECL_ENDING from this state.
  58950. this.state = S_XML_DECL_ENDING;
  58951. return;
  58952. }
  58953. if (c !== EOC) {
  58954. this.state = S_XML_DECL_NAME;
  58955. this.name = String.fromCodePoint(c);
  58956. }
  58957. }
  58958. }, {
  58959. key: "sXMLDeclName",
  58960. value: function sXMLDeclName() {
  58961. var c = this.captureTo(XML_DECL_NAME_TERMINATOR); // The question mark character is not valid inside any of the XML
  58962. // declaration name/value pairs.
  58963. if (c === QUESTION) {
  58964. this.state = S_XML_DECL_ENDING;
  58965. this.name += this.text;
  58966. this.text = "";
  58967. this.fail("XML declaration is incomplete.");
  58968. return;
  58969. }
  58970. if (!(isS(c) || c === EQUAL)) {
  58971. return;
  58972. }
  58973. this.name += this.text;
  58974. this.text = "";
  58975. if (!this.xmlDeclExpects.includes(this.name)) {
  58976. switch (this.name.length) {
  58977. case 0:
  58978. this.fail("did not expect any more name/value pairs.");
  58979. break;
  58980. case 1:
  58981. this.fail("expected the name ".concat(this.xmlDeclExpects[0], "."));
  58982. break;
  58983. default:
  58984. this.fail("expected one of ".concat(this.xmlDeclExpects.join(", ")));
  58985. }
  58986. }
  58987. this.state = c === EQUAL ? S_XML_DECL_VALUE_START : S_XML_DECL_EQ;
  58988. }
  58989. }, {
  58990. key: "sXMLDeclEq",
  58991. value: function sXMLDeclEq() {
  58992. var c = this.getCodeNorm(); // The question mark character is not valid inside any of the XML
  58993. // declaration name/value pairs.
  58994. if (c === QUESTION) {
  58995. this.state = S_XML_DECL_ENDING;
  58996. this.fail("XML declaration is incomplete.");
  58997. return;
  58998. }
  58999. if (isS(c)) {
  59000. return;
  59001. }
  59002. if (c !== EQUAL) {
  59003. this.fail("value required.");
  59004. }
  59005. this.state = S_XML_DECL_VALUE_START;
  59006. }
  59007. }, {
  59008. key: "sXMLDeclValueStart",
  59009. value: function sXMLDeclValueStart() {
  59010. var c = this.getCodeNorm(); // The question mark character is not valid inside any of the XML
  59011. // declaration name/value pairs.
  59012. if (c === QUESTION) {
  59013. this.state = S_XML_DECL_ENDING;
  59014. this.fail("XML declaration is incomplete.");
  59015. return;
  59016. }
  59017. if (isS(c)) {
  59018. return;
  59019. }
  59020. if (!isQuote(c)) {
  59021. this.fail("value must be quoted.");
  59022. this.q = SPACE;
  59023. } else {
  59024. this.q = c;
  59025. }
  59026. this.state = S_XML_DECL_VALUE;
  59027. }
  59028. }, {
  59029. key: "sXMLDeclValue",
  59030. value: function sXMLDeclValue() {
  59031. var c = this.captureTo([this.q, QUESTION]); // The question mark character is not valid inside any of the XML
  59032. // declaration name/value pairs.
  59033. if (c === QUESTION) {
  59034. this.state = S_XML_DECL_ENDING;
  59035. this.text = "";
  59036. this.fail("XML declaration is incomplete.");
  59037. return;
  59038. }
  59039. if (c === EOC) {
  59040. return;
  59041. }
  59042. var value = this.text;
  59043. this.text = "";
  59044. switch (this.name) {
  59045. case "version":
  59046. {
  59047. this.xmlDeclExpects = ["encoding", "standalone"];
  59048. var version = value;
  59049. this.xmlDecl.version = version; // This is the test specified by XML 1.0 but it is fine for XML 1.1.
  59050. if (!/^1\.[0-9]+$/.test(version)) {
  59051. this.fail("version number must match /^1\\.[0-9]+$/.");
  59052. } // When forceXMLVersion is set, the XML declaration is ignored.
  59053. else if (!this.opt.forceXMLVersion) {
  59054. this.setXMLVersion(version);
  59055. }
  59056. break;
  59057. }
  59058. case "encoding":
  59059. if (!/^[A-Za-z][A-Za-z0-9._-]*$/.test(value)) {
  59060. this.fail("encoding value must match \
  59061. /^[A-Za-z0-9][A-Za-z0-9._-]*$/.");
  59062. }
  59063. this.xmlDeclExpects = ["standalone"];
  59064. this.xmlDecl.encoding = value;
  59065. break;
  59066. case "standalone":
  59067. if (value !== "yes" && value !== "no") {
  59068. this.fail("standalone value must match \"yes\" or \"no\".");
  59069. }
  59070. this.xmlDeclExpects = [];
  59071. this.xmlDecl.standalone = value;
  59072. break;
  59073. default: // We don't need to raise an error here since we've already raised one
  59074. // when checking what name was expected.
  59075. }
  59076. this.name = "";
  59077. this.state = S_XML_DECL_SEPARATOR;
  59078. }
  59079. }, {
  59080. key: "sXMLDeclSeparator",
  59081. value: function sXMLDeclSeparator() {
  59082. var c = this.getCodeNorm(); // The question mark character is not valid inside any of the XML
  59083. // declaration name/value pairs.
  59084. if (c === QUESTION) {
  59085. // It is valid to go to S_XML_DECL_ENDING from this state.
  59086. this.state = S_XML_DECL_ENDING;
  59087. return;
  59088. }
  59089. if (!isS(c)) {
  59090. this.fail("whitespace required.");
  59091. this.unget();
  59092. }
  59093. this.state = S_XML_DECL_NAME_START;
  59094. }
  59095. }, {
  59096. key: "sXMLDeclEnding",
  59097. value: function sXMLDeclEnding() {
  59098. var _a;
  59099. var c = this.getCodeNorm();
  59100. if (c === GREATER) {
  59101. if (this.piTarget !== "xml") {
  59102. this.fail("processing instructions are not allowed before root.");
  59103. } else if (this.name !== "version" && this.xmlDeclExpects.includes("version")) {
  59104. this.fail("XML declaration must contain a version.");
  59105. } // eslint-disable-next-line no-unused-expressions
  59106. (_a = this.xmldeclHandler) === null || _a === void 0 ? void 0 : _a.call(this, this.xmlDecl);
  59107. this.name = "";
  59108. this.piTarget = this.text = "";
  59109. this.state = S_TEXT;
  59110. } else {
  59111. // We got here because the previous character was a ?, but the question
  59112. // mark character is not valid inside any of the XML declaration
  59113. // name/value pairs.
  59114. this.fail("The character ? is disallowed anywhere in XML declarations.");
  59115. }
  59116. this.xmlDeclPossible = false;
  59117. }
  59118. }, {
  59119. key: "sOpenTag",
  59120. value: function sOpenTag() {
  59121. var _a;
  59122. var c = this.captureNameChars();
  59123. if (c === EOC) {
  59124. return;
  59125. }
  59126. var tag = this.tag = {
  59127. name: this.name,
  59128. attributes: Object.create(null)
  59129. };
  59130. this.name = "";
  59131. if (this.xmlnsOpt) {
  59132. this.topNS = tag.ns = Object.create(null);
  59133. } // eslint-disable-next-line no-unused-expressions
  59134. (_a = this.openTagStartHandler) === null || _a === void 0 ? void 0 : _a.call(this, tag);
  59135. this.sawRoot = true;
  59136. if (!this.fragmentOpt && this.closedRoot) {
  59137. this.fail("documents may contain only one root.");
  59138. }
  59139. switch (c) {
  59140. case GREATER:
  59141. this.openTag();
  59142. break;
  59143. case FORWARD_SLASH:
  59144. this.state = S_OPEN_TAG_SLASH;
  59145. break;
  59146. default:
  59147. if (!isS(c)) {
  59148. this.fail("disallowed character in tag name.");
  59149. }
  59150. this.state = S_ATTRIB;
  59151. }
  59152. }
  59153. }, {
  59154. key: "sOpenTagSlash",
  59155. value: function sOpenTagSlash() {
  59156. if (this.getCode() === GREATER) {
  59157. this.openSelfClosingTag();
  59158. } else {
  59159. this.fail("forward-slash in opening tag not followed by >.");
  59160. this.state = S_ATTRIB;
  59161. }
  59162. }
  59163. }, {
  59164. key: "sAttrib",
  59165. value: function sAttrib() {
  59166. var c = this.skipSpaces();
  59167. if (c === EOC) {
  59168. return;
  59169. }
  59170. if (isNameStartChar(c)) {
  59171. this.unget();
  59172. this.state = S_ATTRIB_NAME;
  59173. } else if (c === GREATER) {
  59174. this.openTag();
  59175. } else if (c === FORWARD_SLASH) {
  59176. this.state = S_OPEN_TAG_SLASH;
  59177. } else {
  59178. this.fail("disallowed character in attribute name.");
  59179. }
  59180. }
  59181. }, {
  59182. key: "sAttribName",
  59183. value: function sAttribName() {
  59184. var c = this.captureNameChars();
  59185. if (c === EQUAL) {
  59186. this.state = S_ATTRIB_VALUE;
  59187. } else if (isS(c)) {
  59188. this.state = S_ATTRIB_NAME_SAW_WHITE;
  59189. } else if (c === GREATER) {
  59190. this.fail("attribute without value.");
  59191. this.pushAttrib(this.name, this.name);
  59192. this.name = this.text = "";
  59193. this.openTag();
  59194. } else if (c !== EOC) {
  59195. this.fail("disallowed character in attribute name.");
  59196. }
  59197. }
  59198. }, {
  59199. key: "sAttribNameSawWhite",
  59200. value: function sAttribNameSawWhite() {
  59201. var c = this.skipSpaces();
  59202. switch (c) {
  59203. case EOC:
  59204. return;
  59205. case EQUAL:
  59206. this.state = S_ATTRIB_VALUE;
  59207. break;
  59208. default:
  59209. this.fail("attribute without value."); // Should we do this???
  59210. // this.tag.attributes[this.name] = "";
  59211. this.text = "";
  59212. this.name = "";
  59213. if (c === GREATER) {
  59214. this.openTag();
  59215. } else if (isNameStartChar(c)) {
  59216. this.unget();
  59217. this.state = S_ATTRIB_NAME;
  59218. } else {
  59219. this.fail("disallowed character in attribute name.");
  59220. this.state = S_ATTRIB;
  59221. }
  59222. }
  59223. }
  59224. }, {
  59225. key: "sAttribValue",
  59226. value: function sAttribValue() {
  59227. var c = this.getCodeNorm();
  59228. if (isQuote(c)) {
  59229. this.q = c;
  59230. this.state = S_ATTRIB_VALUE_QUOTED;
  59231. } else if (!isS(c)) {
  59232. this.fail("unquoted attribute value.");
  59233. this.state = S_ATTRIB_VALUE_UNQUOTED;
  59234. this.unget();
  59235. }
  59236. }
  59237. }, {
  59238. key: "sAttribValueQuoted",
  59239. value: function sAttribValueQuoted() {
  59240. // We deliberately do not use captureTo here. The specialized code we use
  59241. // here is faster than using captureTo.
  59242. var q = this.q,
  59243. chunk = this.chunk;
  59244. var start = this.i; // eslint-disable-next-line no-constant-condition
  59245. while (true) {
  59246. switch (this.getCode()) {
  59247. case q:
  59248. this.pushAttrib(this.name, this.text + chunk.slice(start, this.prevI));
  59249. this.name = this.text = "";
  59250. this.q = null;
  59251. this.state = S_ATTRIB_VALUE_CLOSED;
  59252. return;
  59253. case AMP:
  59254. this.text += chunk.slice(start, this.prevI);
  59255. this.state = S_ENTITY;
  59256. this.entityReturnState = S_ATTRIB_VALUE_QUOTED;
  59257. return;
  59258. case NL:
  59259. case NL_LIKE:
  59260. case TAB:
  59261. this.text += "".concat(chunk.slice(start, this.prevI), " ");
  59262. start = this.i;
  59263. break;
  59264. case LESS:
  59265. this.text += chunk.slice(start, this.prevI);
  59266. this.fail("disallowed character.");
  59267. return;
  59268. case EOC:
  59269. this.text += chunk.slice(start);
  59270. return;
  59271. default:
  59272. }
  59273. }
  59274. }
  59275. }, {
  59276. key: "sAttribValueClosed",
  59277. value: function sAttribValueClosed() {
  59278. var c = this.getCodeNorm();
  59279. if (isS(c)) {
  59280. this.state = S_ATTRIB;
  59281. } else if (c === GREATER) {
  59282. this.openTag();
  59283. } else if (c === FORWARD_SLASH) {
  59284. this.state = S_OPEN_TAG_SLASH;
  59285. } else if (isNameStartChar(c)) {
  59286. this.fail("no whitespace between attributes.");
  59287. this.unget();
  59288. this.state = S_ATTRIB_NAME;
  59289. } else {
  59290. this.fail("disallowed character in attribute name.");
  59291. }
  59292. }
  59293. }, {
  59294. key: "sAttribValueUnquoted",
  59295. value: function sAttribValueUnquoted() {
  59296. // We don't do anything regarding EOL or space handling for unquoted
  59297. // attributes. We already have failed by the time we get here, and the
  59298. // contract that saxes upholds states that upon failure, it is not safe to
  59299. // rely on the data passed to event handlers (other than
  59300. // ``onerror``). Passing "bad" data is not a problem.
  59301. var c = this.captureTo(ATTRIB_VALUE_UNQUOTED_TERMINATOR);
  59302. switch (c) {
  59303. case AMP:
  59304. this.state = S_ENTITY;
  59305. this.entityReturnState = S_ATTRIB_VALUE_UNQUOTED;
  59306. break;
  59307. case LESS:
  59308. this.fail("disallowed character.");
  59309. break;
  59310. case EOC:
  59311. break;
  59312. default:
  59313. if (this.text.includes("]]>")) {
  59314. this.fail("the string \"]]>\" is disallowed in char data.");
  59315. }
  59316. this.pushAttrib(this.name, this.text);
  59317. this.name = this.text = "";
  59318. if (c === GREATER) {
  59319. this.openTag();
  59320. } else {
  59321. this.state = S_ATTRIB;
  59322. }
  59323. }
  59324. }
  59325. }, {
  59326. key: "sCloseTag",
  59327. value: function sCloseTag() {
  59328. var c = this.captureNameChars();
  59329. if (c === GREATER) {
  59330. this.closeTag();
  59331. } else if (isS(c)) {
  59332. this.state = S_CLOSE_TAG_SAW_WHITE;
  59333. } else if (c !== EOC) {
  59334. this.fail("disallowed character in closing tag.");
  59335. }
  59336. }
  59337. }, {
  59338. key: "sCloseTagSawWhite",
  59339. value: function sCloseTagSawWhite() {
  59340. switch (this.skipSpaces()) {
  59341. case GREATER:
  59342. this.closeTag();
  59343. break;
  59344. case EOC:
  59345. break;
  59346. default:
  59347. this.fail("disallowed character in closing tag.");
  59348. }
  59349. } // END OF STATE ENGINE METHODS
  59350. }, {
  59351. key: "handleTextInRoot",
  59352. value: function handleTextInRoot() {
  59353. // This is essentially a specialized version of captureTo which is optimized
  59354. // for performing the ]]> check. A previous version of this code, checked
  59355. // ``this.text`` for the presence of ]]>. It simplified the code but was
  59356. // very costly when character data contained a lot of entities to be parsed.
  59357. //
  59358. // Since we are using a specialized loop, we also keep track of the presence
  59359. // of ]]> in text data. The sequence ]]> is forbidden to appear as-is.
  59360. //
  59361. var start = this.i,
  59362. forbiddenState = this.forbiddenState;
  59363. var chunk = this.chunk,
  59364. handler = this.textHandler; // eslint-disable-next-line no-labels, no-restricted-syntax
  59365. scanLoop: // eslint-disable-next-line no-constant-condition
  59366. while (true) {
  59367. switch (this.getCode()) {
  59368. case LESS:
  59369. {
  59370. this.state = S_OPEN_WAKA;
  59371. if (handler !== undefined) {
  59372. var text = this.text;
  59373. var slice = chunk.slice(start, this.prevI);
  59374. if (text.length !== 0) {
  59375. handler(text + slice);
  59376. this.text = "";
  59377. } else if (slice.length !== 0) {
  59378. handler(slice);
  59379. }
  59380. }
  59381. forbiddenState = FORBIDDEN_START; // eslint-disable-next-line no-labels
  59382. break scanLoop;
  59383. }
  59384. case AMP:
  59385. this.state = S_ENTITY;
  59386. this.entityReturnState = S_TEXT;
  59387. if (handler !== undefined) {
  59388. this.text += chunk.slice(start, this.prevI);
  59389. }
  59390. forbiddenState = FORBIDDEN_START; // eslint-disable-next-line no-labels
  59391. break scanLoop;
  59392. case CLOSE_BRACKET:
  59393. switch (forbiddenState) {
  59394. case FORBIDDEN_START:
  59395. forbiddenState = FORBIDDEN_BRACKET;
  59396. break;
  59397. case FORBIDDEN_BRACKET:
  59398. forbiddenState = FORBIDDEN_BRACKET_BRACKET;
  59399. break;
  59400. case FORBIDDEN_BRACKET_BRACKET:
  59401. break;
  59402. default:
  59403. throw new Error("impossible state");
  59404. }
  59405. break;
  59406. case GREATER:
  59407. if (forbiddenState === FORBIDDEN_BRACKET_BRACKET) {
  59408. this.fail("the string \"]]>\" is disallowed in char data.");
  59409. }
  59410. forbiddenState = FORBIDDEN_START;
  59411. break;
  59412. case NL_LIKE:
  59413. if (handler !== undefined) {
  59414. this.text += "".concat(chunk.slice(start, this.prevI), "\n");
  59415. }
  59416. start = this.i;
  59417. forbiddenState = FORBIDDEN_START;
  59418. break;
  59419. case EOC:
  59420. if (handler !== undefined) {
  59421. this.text += chunk.slice(start);
  59422. } // eslint-disable-next-line no-labels
  59423. break scanLoop;
  59424. default:
  59425. forbiddenState = FORBIDDEN_START;
  59426. }
  59427. }
  59428. this.forbiddenState = forbiddenState;
  59429. }
  59430. }, {
  59431. key: "handleTextOutsideRoot",
  59432. value: function handleTextOutsideRoot() {
  59433. // This is essentially a specialized version of captureTo which is optimized
  59434. // for a specialized task. We keep track of the presence of non-space
  59435. // characters in the text since these are errors when appearing outside the
  59436. // document root element.
  59437. var start = this.i;
  59438. var chunk = this.chunk,
  59439. handler = this.textHandler;
  59440. var nonSpace = false; // eslint-disable-next-line no-labels, no-restricted-syntax
  59441. outRootLoop: // eslint-disable-next-line no-constant-condition
  59442. while (true) {
  59443. var code = this.getCode();
  59444. switch (code) {
  59445. case LESS:
  59446. {
  59447. this.state = S_OPEN_WAKA;
  59448. if (handler !== undefined) {
  59449. var text = this.text;
  59450. var slice = chunk.slice(start, this.prevI);
  59451. if (text.length !== 0) {
  59452. handler(text + slice);
  59453. this.text = "";
  59454. } else if (slice.length !== 0) {
  59455. handler(slice);
  59456. }
  59457. } // eslint-disable-next-line no-labels
  59458. break outRootLoop;
  59459. }
  59460. case AMP:
  59461. this.state = S_ENTITY;
  59462. this.entityReturnState = S_TEXT;
  59463. if (handler !== undefined) {
  59464. this.text += chunk.slice(start, this.prevI);
  59465. }
  59466. nonSpace = true; // eslint-disable-next-line no-labels
  59467. break outRootLoop;
  59468. case NL_LIKE:
  59469. if (handler !== undefined) {
  59470. this.text += "".concat(chunk.slice(start, this.prevI), "\n");
  59471. }
  59472. start = this.i;
  59473. break;
  59474. case EOC:
  59475. if (handler !== undefined) {
  59476. this.text += chunk.slice(start);
  59477. } // eslint-disable-next-line no-labels
  59478. break outRootLoop;
  59479. default:
  59480. if (!isS(code)) {
  59481. nonSpace = true;
  59482. }
  59483. }
  59484. }
  59485. if (!nonSpace) {
  59486. return;
  59487. } // We use the reportedTextBeforeRoot and reportedTextAfterRoot flags
  59488. // to avoid reporting errors for every single character that is out of
  59489. // place.
  59490. if (!this.sawRoot && !this.reportedTextBeforeRoot) {
  59491. this.fail("text data outside of root node.");
  59492. this.reportedTextBeforeRoot = true;
  59493. }
  59494. if (this.closedRoot && !this.reportedTextAfterRoot) {
  59495. this.fail("text data outside of root node.");
  59496. this.reportedTextAfterRoot = true;
  59497. }
  59498. }
  59499. }, {
  59500. key: "pushAttribNS",
  59501. value: function pushAttribNS(name, value) {
  59502. var _a;
  59503. var _this$qname = this.qname(name),
  59504. prefix = _this$qname.prefix,
  59505. local = _this$qname.local;
  59506. var attr = {
  59507. name: name,
  59508. prefix: prefix,
  59509. local: local,
  59510. value: value
  59511. };
  59512. this.attribList.push(attr); // eslint-disable-next-line no-unused-expressions
  59513. (_a = this.attributeHandler) === null || _a === void 0 ? void 0 : _a.call(this, attr);
  59514. if (prefix === "xmlns") {
  59515. var trimmed = value.trim();
  59516. if (this.currentXMLVersion === "1.0" && trimmed === "") {
  59517. this.fail("invalid attempt to undefine prefix in XML 1.0");
  59518. }
  59519. this.topNS[local] = trimmed;
  59520. nsPairCheck(this, local, trimmed);
  59521. } else if (name === "xmlns") {
  59522. var _trimmed = value.trim();
  59523. this.topNS[""] = _trimmed;
  59524. nsPairCheck(this, "", _trimmed);
  59525. }
  59526. }
  59527. }, {
  59528. key: "pushAttribPlain",
  59529. value: function pushAttribPlain(name, value) {
  59530. var _a;
  59531. var attr = {
  59532. name: name,
  59533. value: value
  59534. };
  59535. this.attribList.push(attr); // eslint-disable-next-line no-unused-expressions
  59536. (_a = this.attributeHandler) === null || _a === void 0 ? void 0 : _a.call(this, attr);
  59537. }
  59538. /**
  59539. * End parsing. This performs final well-formedness checks and resets the
  59540. * parser to a clean state.
  59541. *
  59542. * @returns this
  59543. */
  59544. }, {
  59545. key: "end",
  59546. value: function end() {
  59547. var _a, _b;
  59548. if (!this.sawRoot) {
  59549. this.fail("document must contain a root element.");
  59550. }
  59551. var tags = this.tags;
  59552. while (tags.length > 0) {
  59553. var tag = tags.pop();
  59554. this.fail("unclosed tag: ".concat(tag.name));
  59555. }
  59556. if (this.state !== S_BEGIN && this.state !== S_TEXT) {
  59557. this.fail("unexpected end.");
  59558. }
  59559. var text = this.text;
  59560. if (text.length !== 0) {
  59561. // eslint-disable-next-line no-unused-expressions
  59562. (_a = this.textHandler) === null || _a === void 0 ? void 0 : _a.call(this, text);
  59563. this.text = "";
  59564. }
  59565. this._closed = true; // eslint-disable-next-line no-unused-expressions
  59566. (_b = this.endHandler) === null || _b === void 0 ? void 0 : _b.call(this);
  59567. this._init();
  59568. return this;
  59569. }
  59570. /**
  59571. * Resolve a namespace prefix.
  59572. *
  59573. * @param prefix The prefix to resolve.
  59574. *
  59575. * @returns The namespace URI or ``undefined`` if the prefix is not defined.
  59576. */
  59577. }, {
  59578. key: "resolve",
  59579. value: function resolve(prefix) {
  59580. var _a, _b;
  59581. var uri = this.topNS[prefix];
  59582. if (uri !== undefined) {
  59583. return uri;
  59584. }
  59585. var tags = this.tags;
  59586. for (var index = tags.length - 1; index >= 0; index--) {
  59587. uri = tags[index].ns[prefix];
  59588. if (uri !== undefined) {
  59589. return uri;
  59590. }
  59591. }
  59592. uri = this.ns[prefix];
  59593. if (uri !== undefined) {
  59594. return uri;
  59595. }
  59596. return (_b = (_a = this.opt).resolvePrefix) === null || _b === void 0 ? void 0 : _b.call(_a, prefix);
  59597. }
  59598. /**
  59599. * Parse a qname into its prefix and local name parts.
  59600. *
  59601. * @param name The name to parse
  59602. *
  59603. * @returns
  59604. */
  59605. }, {
  59606. key: "qname",
  59607. value: function qname(name) {
  59608. // This is faster than using name.split(":").
  59609. var colon = name.indexOf(":");
  59610. if (colon === -1) {
  59611. return {
  59612. prefix: "",
  59613. local: name
  59614. };
  59615. }
  59616. var local = name.slice(colon + 1);
  59617. var prefix = name.slice(0, colon);
  59618. if (prefix === "" || local === "" || local.includes(":")) {
  59619. this.fail("malformed name: ".concat(name, "."));
  59620. }
  59621. return {
  59622. prefix: prefix,
  59623. local: local
  59624. };
  59625. }
  59626. }, {
  59627. key: "processAttribsNS",
  59628. value: function processAttribsNS() {
  59629. var _a;
  59630. var attribList = this.attribList;
  59631. var tag = this.tag;
  59632. {
  59633. // add namespace info to tag
  59634. var _this$qname2 = this.qname(tag.name),
  59635. prefix = _this$qname2.prefix,
  59636. local = _this$qname2.local;
  59637. tag.prefix = prefix;
  59638. tag.local = local;
  59639. var uri = tag.uri = (_a = this.resolve(prefix)) !== null && _a !== void 0 ? _a : "";
  59640. if (prefix !== "") {
  59641. if (prefix === "xmlns") {
  59642. this.fail("tags may not have \"xmlns\" as prefix.");
  59643. }
  59644. if (uri === "") {
  59645. this.fail("unbound namespace prefix: ".concat(JSON.stringify(prefix), "."));
  59646. tag.uri = prefix;
  59647. }
  59648. }
  59649. }
  59650. if (attribList.length === 0) {
  59651. return;
  59652. }
  59653. var attributes = tag.attributes;
  59654. var seen = new Set(); // Note: do not apply default ns to attributes:
  59655. // http://www.w3.org/TR/REC-xml-names/#defaulting
  59656. var _iterator = _createForOfIteratorHelper(attribList),
  59657. _step;
  59658. try {
  59659. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  59660. var attr = _step.value;
  59661. var name = attr.name,
  59662. _prefix = attr.prefix,
  59663. _local = attr.local;
  59664. var _uri = void 0;
  59665. var eqname = void 0;
  59666. if (_prefix === "") {
  59667. _uri = name === "xmlns" ? XMLNS_NAMESPACE : "";
  59668. eqname = name;
  59669. } else {
  59670. _uri = this.resolve(_prefix); // if there's any attributes with an undefined namespace,
  59671. // then fail on them now.
  59672. if (_uri === undefined) {
  59673. this.fail("unbound namespace prefix: ".concat(JSON.stringify(_prefix), "."));
  59674. _uri = _prefix;
  59675. }
  59676. eqname = "{".concat(_uri, "}").concat(_local);
  59677. }
  59678. if (seen.has(eqname)) {
  59679. this.fail("duplicate attribute: ".concat(eqname, "."));
  59680. }
  59681. seen.add(eqname);
  59682. attr.uri = _uri;
  59683. attributes[name] = attr;
  59684. }
  59685. } catch (err) {
  59686. _iterator.e(err);
  59687. } finally {
  59688. _iterator.f();
  59689. }
  59690. this.attribList = [];
  59691. }
  59692. }, {
  59693. key: "processAttribsPlain",
  59694. value: function processAttribsPlain() {
  59695. var attribList = this.attribList; // eslint-disable-next-line prefer-destructuring
  59696. var attributes = this.tag.attributes;
  59697. var _iterator2 = _createForOfIteratorHelper(attribList),
  59698. _step2;
  59699. try {
  59700. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  59701. var _step2$value = _step2.value,
  59702. name = _step2$value.name,
  59703. value = _step2$value.value;
  59704. if (attributes[name] !== undefined) {
  59705. this.fail("duplicate attribute: ".concat(name, "."));
  59706. }
  59707. attributes[name] = value;
  59708. }
  59709. } catch (err) {
  59710. _iterator2.e(err);
  59711. } finally {
  59712. _iterator2.f();
  59713. }
  59714. this.attribList = [];
  59715. }
  59716. /**
  59717. * Handle a complete open tag. This parser code calls this once it has seen
  59718. * the whole tag. This method checks for well-formeness and then emits
  59719. * ``onopentag``.
  59720. */
  59721. }, {
  59722. key: "openTag",
  59723. value: function openTag() {
  59724. var _a;
  59725. this.processAttribs();
  59726. var tags = this.tags;
  59727. var tag = this.tag;
  59728. tag.isSelfClosing = false; // There cannot be any pending text here due to the onopentagstart that was
  59729. // necessarily emitted before we get here. So we do not check text.
  59730. // eslint-disable-next-line no-unused-expressions
  59731. (_a = this.openTagHandler) === null || _a === void 0 ? void 0 : _a.call(this, tag);
  59732. tags.push(tag);
  59733. this.state = S_TEXT;
  59734. this.name = "";
  59735. }
  59736. /**
  59737. * Handle a complete self-closing tag. This parser code calls this once it has
  59738. * seen the whole tag. This method checks for well-formeness and then emits
  59739. * ``onopentag`` and ``onclosetag``.
  59740. */
  59741. }, {
  59742. key: "openSelfClosingTag",
  59743. value: function openSelfClosingTag() {
  59744. var _a, _b, _c;
  59745. this.processAttribs();
  59746. var tags = this.tags;
  59747. var tag = this.tag;
  59748. tag.isSelfClosing = true; // There cannot be any pending text here due to the onopentagstart that was
  59749. // necessarily emitted before we get here. So we do not check text.
  59750. // eslint-disable-next-line no-unused-expressions
  59751. (_a = this.openTagHandler) === null || _a === void 0 ? void 0 : _a.call(this, tag); // eslint-disable-next-line no-unused-expressions
  59752. (_b = this.closeTagHandler) === null || _b === void 0 ? void 0 : _b.call(this, tag);
  59753. var top = this.tag = (_c = tags[tags.length - 1]) !== null && _c !== void 0 ? _c : null;
  59754. if (top === null) {
  59755. this.closedRoot = true;
  59756. }
  59757. this.state = S_TEXT;
  59758. this.name = "";
  59759. }
  59760. /**
  59761. * Handle a complete close tag. This parser code calls this once it has seen
  59762. * the whole tag. This method checks for well-formeness and then emits
  59763. * ``onclosetag``.
  59764. */
  59765. }, {
  59766. key: "closeTag",
  59767. value: function closeTag() {
  59768. var tags = this.tags,
  59769. name = this.name; // Our state after this will be S_TEXT, no matter what, and we can clear
  59770. // tagName now.
  59771. this.state = S_TEXT;
  59772. this.name = "";
  59773. if (name === "") {
  59774. this.fail("weird empty close tag.");
  59775. this.text += "</>";
  59776. return;
  59777. }
  59778. var handler = this.closeTagHandler;
  59779. var l = tags.length;
  59780. while (l-- > 0) {
  59781. var tag = this.tag = tags.pop();
  59782. this.topNS = tag.ns; // eslint-disable-next-line no-unused-expressions
  59783. handler === null || handler === void 0 ? void 0 : handler(tag);
  59784. if (tag.name === name) {
  59785. break;
  59786. }
  59787. this.fail("unexpected close tag.");
  59788. }
  59789. if (l === 0) {
  59790. this.closedRoot = true;
  59791. } else if (l < 0) {
  59792. this.fail("unmatched closing tag: ".concat(name, "."));
  59793. this.text += "</".concat(name, ">");
  59794. }
  59795. }
  59796. /**
  59797. * Resolves an entity. Makes any necessary well-formedness checks.
  59798. *
  59799. * @param entity The entity to resolve.
  59800. *
  59801. * @returns The parsed entity.
  59802. */
  59803. }, {
  59804. key: "parseEntity",
  59805. value: function parseEntity(entity) {
  59806. // startsWith would be significantly slower for this test.
  59807. // eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
  59808. if (entity[0] !== "#") {
  59809. var defined = this.ENTITIES[entity];
  59810. if (defined !== undefined) {
  59811. return defined;
  59812. }
  59813. this.fail(this.isName(entity) ? "undefined entity." : "disallowed character in entity name.");
  59814. return "&".concat(entity, ";");
  59815. }
  59816. var num = NaN;
  59817. if (entity[1] === "x" && /^#x[0-9a-f]+$/i.test(entity)) {
  59818. num = parseInt(entity.slice(2), 16);
  59819. } else if (/^#[0-9]+$/.test(entity)) {
  59820. num = parseInt(entity.slice(1), 10);
  59821. } // The character reference is required to match the CHAR production.
  59822. if (!this.isChar(num)) {
  59823. this.fail("malformed character entity.");
  59824. return "&".concat(entity, ";");
  59825. }
  59826. return String.fromCodePoint(num);
  59827. }
  59828. }, {
  59829. key: "closed",
  59830. get: function get() {
  59831. return this._closed;
  59832. }
  59833. }, {
  59834. key: "position",
  59835. get: function get() {
  59836. return this.chunkPosition + this.i;
  59837. }
  59838. /**
  59839. * The column number of the next character to be read by the parser. *
  59840. * This field is zero-based. (The first column in a line is 0.)
  59841. *
  59842. * This field reports the index at which the next character would be in the
  59843. * line if the line were represented as a JavaScript string. Note that this
  59844. * *can* be different to a count based on the number of *Unicode characters*
  59845. * due to how JavaScript handles astral plane characters.
  59846. *
  59847. * See [[column]] for a number that corresponds to a count of Unicode
  59848. * characters.
  59849. */
  59850. }, {
  59851. key: "columnIndex",
  59852. get: function get() {
  59853. return this.position - this.positionAtNewLine;
  59854. }
  59855. }]);
  59856. return SaxesParser;
  59857. }();
  59858. exports.SaxesParser = SaxesParser;
  59859. },{"xmlchars/xml/1.0/ed5":431,"xmlchars/xml/1.1/ed2":432,"xmlchars/xmlns/1.0/ed3":433}],387:[function(require,module,exports){
  59860. (function (setImmediate){
  59861. 'use strict';
  59862. module.exports = typeof setImmediate === 'function' ? setImmediate : function setImmediate() {
  59863. var args = [].slice.apply(arguments);
  59864. args.splice(1, 0, 0);
  59865. setTimeout.apply(null, args);
  59866. };
  59867. }).call(this,require("timers").setImmediate)
  59868. },{"timers":411}],388:[function(require,module,exports){
  59869. "use strict";
  59870. var Buffer = require('safe-buffer').Buffer; // prototype class for hash functions
  59871. function Hash(blockSize, finalSize) {
  59872. this._block = Buffer.alloc(blockSize);
  59873. this._finalSize = finalSize;
  59874. this._blockSize = blockSize;
  59875. this._len = 0;
  59876. }
  59877. Hash.prototype.update = function (data, enc) {
  59878. if (typeof data === 'string') {
  59879. enc = enc || 'utf8';
  59880. data = Buffer.from(data, enc);
  59881. }
  59882. var block = this._block;
  59883. var blockSize = this._blockSize;
  59884. var length = data.length;
  59885. var accum = this._len;
  59886. for (var offset = 0; offset < length;) {
  59887. var assigned = accum % blockSize;
  59888. var remainder = Math.min(length - offset, blockSize - assigned);
  59889. for (var i = 0; i < remainder; i++) {
  59890. block[assigned + i] = data[offset + i];
  59891. }
  59892. accum += remainder;
  59893. offset += remainder;
  59894. if (accum % blockSize === 0) {
  59895. this._update(block);
  59896. }
  59897. }
  59898. this._len += length;
  59899. return this;
  59900. };
  59901. Hash.prototype.digest = function (enc) {
  59902. var rem = this._len % this._blockSize;
  59903. this._block[rem] = 0x80; // zero (rem + 1) trailing bits, where (rem + 1) is the smallest
  59904. // non-negative solution to the equation (length + 1 + (rem + 1)) === finalSize mod blockSize
  59905. this._block.fill(0, rem + 1);
  59906. if (rem >= this._finalSize) {
  59907. this._update(this._block);
  59908. this._block.fill(0);
  59909. }
  59910. var bits = this._len * 8; // uint32
  59911. if (bits <= 0xffffffff) {
  59912. this._block.writeUInt32BE(bits, this._blockSize - 4); // uint64
  59913. } else {
  59914. var lowBits = (bits & 0xffffffff) >>> 0;
  59915. var highBits = (bits - lowBits) / 0x100000000;
  59916. this._block.writeUInt32BE(highBits, this._blockSize - 8);
  59917. this._block.writeUInt32BE(lowBits, this._blockSize - 4);
  59918. }
  59919. this._update(this._block);
  59920. var hash = this._hash();
  59921. return enc ? hash.toString(enc) : hash;
  59922. };
  59923. Hash.prototype._update = function () {
  59924. throw new Error('_update must be implemented by subclass');
  59925. };
  59926. module.exports = Hash;
  59927. },{"safe-buffer":384}],389:[function(require,module,exports){
  59928. "use strict";
  59929. var _exports = module.exports = function SHA(algorithm) {
  59930. algorithm = algorithm.toLowerCase();
  59931. var Algorithm = _exports[algorithm];
  59932. if (!Algorithm) throw new Error(algorithm + ' is not supported (we accept pull requests)');
  59933. return new Algorithm();
  59934. };
  59935. _exports.sha = require('./sha');
  59936. _exports.sha1 = require('./sha1');
  59937. _exports.sha224 = require('./sha224');
  59938. _exports.sha256 = require('./sha256');
  59939. _exports.sha384 = require('./sha384');
  59940. _exports.sha512 = require('./sha512');
  59941. },{"./sha":390,"./sha1":391,"./sha224":392,"./sha256":393,"./sha384":394,"./sha512":395}],390:[function(require,module,exports){
  59942. "use strict";
  59943. /*
  59944. * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined
  59945. * in FIPS PUB 180-1
  59946. * This source code is derived from sha1.js of the same repository.
  59947. * The difference between SHA-0 and SHA-1 is just a bitwise rotate left
  59948. * operation was added.
  59949. */
  59950. var inherits = require('inherits');
  59951. var Hash = require('./hash');
  59952. var Buffer = require('safe-buffer').Buffer;
  59953. var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0];
  59954. var W = new Array(80);
  59955. function Sha() {
  59956. this.init();
  59957. this._w = W;
  59958. Hash.call(this, 64, 56);
  59959. }
  59960. inherits(Sha, Hash);
  59961. Sha.prototype.init = function () {
  59962. this._a = 0x67452301;
  59963. this._b = 0xefcdab89;
  59964. this._c = 0x98badcfe;
  59965. this._d = 0x10325476;
  59966. this._e = 0xc3d2e1f0;
  59967. return this;
  59968. };
  59969. function rotl5(num) {
  59970. return num << 5 | num >>> 27;
  59971. }
  59972. function rotl30(num) {
  59973. return num << 30 | num >>> 2;
  59974. }
  59975. function ft(s, b, c, d) {
  59976. if (s === 0) return b & c | ~b & d;
  59977. if (s === 2) return b & c | b & d | c & d;
  59978. return b ^ c ^ d;
  59979. }
  59980. Sha.prototype._update = function (M) {
  59981. var W = this._w;
  59982. var a = this._a | 0;
  59983. var b = this._b | 0;
  59984. var c = this._c | 0;
  59985. var d = this._d | 0;
  59986. var e = this._e | 0;
  59987. for (var i = 0; i < 16; ++i) {
  59988. W[i] = M.readInt32BE(i * 4);
  59989. }
  59990. for (; i < 80; ++i) {
  59991. W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
  59992. }
  59993. for (var j = 0; j < 80; ++j) {
  59994. var s = ~~(j / 20);
  59995. var t = rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s] | 0;
  59996. e = d;
  59997. d = c;
  59998. c = rotl30(b);
  59999. b = a;
  60000. a = t;
  60001. }
  60002. this._a = a + this._a | 0;
  60003. this._b = b + this._b | 0;
  60004. this._c = c + this._c | 0;
  60005. this._d = d + this._d | 0;
  60006. this._e = e + this._e | 0;
  60007. };
  60008. Sha.prototype._hash = function () {
  60009. var H = Buffer.allocUnsafe(20);
  60010. H.writeInt32BE(this._a | 0, 0);
  60011. H.writeInt32BE(this._b | 0, 4);
  60012. H.writeInt32BE(this._c | 0, 8);
  60013. H.writeInt32BE(this._d | 0, 12);
  60014. H.writeInt32BE(this._e | 0, 16);
  60015. return H;
  60016. };
  60017. module.exports = Sha;
  60018. },{"./hash":388,"inherits":278,"safe-buffer":384}],391:[function(require,module,exports){
  60019. "use strict";
  60020. /*
  60021. * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
  60022. * in FIPS PUB 180-1
  60023. * Version 2.1a Copyright Paul Johnston 2000 - 2002.
  60024. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  60025. * Distributed under the BSD License
  60026. * See http://pajhome.org.uk/crypt/md5 for details.
  60027. */
  60028. var inherits = require('inherits');
  60029. var Hash = require('./hash');
  60030. var Buffer = require('safe-buffer').Buffer;
  60031. var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0];
  60032. var W = new Array(80);
  60033. function Sha1() {
  60034. this.init();
  60035. this._w = W;
  60036. Hash.call(this, 64, 56);
  60037. }
  60038. inherits(Sha1, Hash);
  60039. Sha1.prototype.init = function () {
  60040. this._a = 0x67452301;
  60041. this._b = 0xefcdab89;
  60042. this._c = 0x98badcfe;
  60043. this._d = 0x10325476;
  60044. this._e = 0xc3d2e1f0;
  60045. return this;
  60046. };
  60047. function rotl1(num) {
  60048. return num << 1 | num >>> 31;
  60049. }
  60050. function rotl5(num) {
  60051. return num << 5 | num >>> 27;
  60052. }
  60053. function rotl30(num) {
  60054. return num << 30 | num >>> 2;
  60055. }
  60056. function ft(s, b, c, d) {
  60057. if (s === 0) return b & c | ~b & d;
  60058. if (s === 2) return b & c | b & d | c & d;
  60059. return b ^ c ^ d;
  60060. }
  60061. Sha1.prototype._update = function (M) {
  60062. var W = this._w;
  60063. var a = this._a | 0;
  60064. var b = this._b | 0;
  60065. var c = this._c | 0;
  60066. var d = this._d | 0;
  60067. var e = this._e | 0;
  60068. for (var i = 0; i < 16; ++i) {
  60069. W[i] = M.readInt32BE(i * 4);
  60070. }
  60071. for (; i < 80; ++i) {
  60072. W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]);
  60073. }
  60074. for (var j = 0; j < 80; ++j) {
  60075. var s = ~~(j / 20);
  60076. var t = rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s] | 0;
  60077. e = d;
  60078. d = c;
  60079. c = rotl30(b);
  60080. b = a;
  60081. a = t;
  60082. }
  60083. this._a = a + this._a | 0;
  60084. this._b = b + this._b | 0;
  60085. this._c = c + this._c | 0;
  60086. this._d = d + this._d | 0;
  60087. this._e = e + this._e | 0;
  60088. };
  60089. Sha1.prototype._hash = function () {
  60090. var H = Buffer.allocUnsafe(20);
  60091. H.writeInt32BE(this._a | 0, 0);
  60092. H.writeInt32BE(this._b | 0, 4);
  60093. H.writeInt32BE(this._c | 0, 8);
  60094. H.writeInt32BE(this._d | 0, 12);
  60095. H.writeInt32BE(this._e | 0, 16);
  60096. return H;
  60097. };
  60098. module.exports = Sha1;
  60099. },{"./hash":388,"inherits":278,"safe-buffer":384}],392:[function(require,module,exports){
  60100. "use strict";
  60101. /**
  60102. * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
  60103. * in FIPS 180-2
  60104. * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
  60105. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  60106. *
  60107. */
  60108. var inherits = require('inherits');
  60109. var Sha256 = require('./sha256');
  60110. var Hash = require('./hash');
  60111. var Buffer = require('safe-buffer').Buffer;
  60112. var W = new Array(64);
  60113. function Sha224() {
  60114. this.init();
  60115. this._w = W; // new Array(64)
  60116. Hash.call(this, 64, 56);
  60117. }
  60118. inherits(Sha224, Sha256);
  60119. Sha224.prototype.init = function () {
  60120. this._a = 0xc1059ed8;
  60121. this._b = 0x367cd507;
  60122. this._c = 0x3070dd17;
  60123. this._d = 0xf70e5939;
  60124. this._e = 0xffc00b31;
  60125. this._f = 0x68581511;
  60126. this._g = 0x64f98fa7;
  60127. this._h = 0xbefa4fa4;
  60128. return this;
  60129. };
  60130. Sha224.prototype._hash = function () {
  60131. var H = Buffer.allocUnsafe(28);
  60132. H.writeInt32BE(this._a, 0);
  60133. H.writeInt32BE(this._b, 4);
  60134. H.writeInt32BE(this._c, 8);
  60135. H.writeInt32BE(this._d, 12);
  60136. H.writeInt32BE(this._e, 16);
  60137. H.writeInt32BE(this._f, 20);
  60138. H.writeInt32BE(this._g, 24);
  60139. return H;
  60140. };
  60141. module.exports = Sha224;
  60142. },{"./hash":388,"./sha256":393,"inherits":278,"safe-buffer":384}],393:[function(require,module,exports){
  60143. "use strict";
  60144. /**
  60145. * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
  60146. * in FIPS 180-2
  60147. * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
  60148. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  60149. *
  60150. */
  60151. var inherits = require('inherits');
  60152. var Hash = require('./hash');
  60153. var Buffer = require('safe-buffer').Buffer;
  60154. 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];
  60155. var W = new Array(64);
  60156. function Sha256() {
  60157. this.init();
  60158. this._w = W; // new Array(64)
  60159. Hash.call(this, 64, 56);
  60160. }
  60161. inherits(Sha256, Hash);
  60162. Sha256.prototype.init = function () {
  60163. this._a = 0x6a09e667;
  60164. this._b = 0xbb67ae85;
  60165. this._c = 0x3c6ef372;
  60166. this._d = 0xa54ff53a;
  60167. this._e = 0x510e527f;
  60168. this._f = 0x9b05688c;
  60169. this._g = 0x1f83d9ab;
  60170. this._h = 0x5be0cd19;
  60171. return this;
  60172. };
  60173. function ch(x, y, z) {
  60174. return z ^ x & (y ^ z);
  60175. }
  60176. function maj(x, y, z) {
  60177. return x & y | z & (x | y);
  60178. }
  60179. function sigma0(x) {
  60180. return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10);
  60181. }
  60182. function sigma1(x) {
  60183. return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7);
  60184. }
  60185. function gamma0(x) {
  60186. return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ x >>> 3;
  60187. }
  60188. function gamma1(x) {
  60189. return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ x >>> 10;
  60190. }
  60191. Sha256.prototype._update = function (M) {
  60192. var W = this._w;
  60193. var a = this._a | 0;
  60194. var b = this._b | 0;
  60195. var c = this._c | 0;
  60196. var d = this._d | 0;
  60197. var e = this._e | 0;
  60198. var f = this._f | 0;
  60199. var g = this._g | 0;
  60200. var h = this._h | 0;
  60201. for (var i = 0; i < 16; ++i) {
  60202. W[i] = M.readInt32BE(i * 4);
  60203. }
  60204. for (; i < 64; ++i) {
  60205. W[i] = gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16] | 0;
  60206. }
  60207. for (var j = 0; j < 64; ++j) {
  60208. var T1 = h + sigma1(e) + ch(e, f, g) + K[j] + W[j] | 0;
  60209. var T2 = sigma0(a) + maj(a, b, c) | 0;
  60210. h = g;
  60211. g = f;
  60212. f = e;
  60213. e = d + T1 | 0;
  60214. d = c;
  60215. c = b;
  60216. b = a;
  60217. a = T1 + T2 | 0;
  60218. }
  60219. this._a = a + this._a | 0;
  60220. this._b = b + this._b | 0;
  60221. this._c = c + this._c | 0;
  60222. this._d = d + this._d | 0;
  60223. this._e = e + this._e | 0;
  60224. this._f = f + this._f | 0;
  60225. this._g = g + this._g | 0;
  60226. this._h = h + this._h | 0;
  60227. };
  60228. Sha256.prototype._hash = function () {
  60229. var H = Buffer.allocUnsafe(32);
  60230. H.writeInt32BE(this._a, 0);
  60231. H.writeInt32BE(this._b, 4);
  60232. H.writeInt32BE(this._c, 8);
  60233. H.writeInt32BE(this._d, 12);
  60234. H.writeInt32BE(this._e, 16);
  60235. H.writeInt32BE(this._f, 20);
  60236. H.writeInt32BE(this._g, 24);
  60237. H.writeInt32BE(this._h, 28);
  60238. return H;
  60239. };
  60240. module.exports = Sha256;
  60241. },{"./hash":388,"inherits":278,"safe-buffer":384}],394:[function(require,module,exports){
  60242. "use strict";
  60243. var inherits = require('inherits');
  60244. var SHA512 = require('./sha512');
  60245. var Hash = require('./hash');
  60246. var Buffer = require('safe-buffer').Buffer;
  60247. var W = new Array(160);
  60248. function Sha384() {
  60249. this.init();
  60250. this._w = W;
  60251. Hash.call(this, 128, 112);
  60252. }
  60253. inherits(Sha384, SHA512);
  60254. Sha384.prototype.init = function () {
  60255. this._ah = 0xcbbb9d5d;
  60256. this._bh = 0x629a292a;
  60257. this._ch = 0x9159015a;
  60258. this._dh = 0x152fecd8;
  60259. this._eh = 0x67332667;
  60260. this._fh = 0x8eb44a87;
  60261. this._gh = 0xdb0c2e0d;
  60262. this._hh = 0x47b5481d;
  60263. this._al = 0xc1059ed8;
  60264. this._bl = 0x367cd507;
  60265. this._cl = 0x3070dd17;
  60266. this._dl = 0xf70e5939;
  60267. this._el = 0xffc00b31;
  60268. this._fl = 0x68581511;
  60269. this._gl = 0x64f98fa7;
  60270. this._hl = 0xbefa4fa4;
  60271. return this;
  60272. };
  60273. Sha384.prototype._hash = function () {
  60274. var H = Buffer.allocUnsafe(48);
  60275. function writeInt64BE(h, l, offset) {
  60276. H.writeInt32BE(h, offset);
  60277. H.writeInt32BE(l, offset + 4);
  60278. }
  60279. writeInt64BE(this._ah, this._al, 0);
  60280. writeInt64BE(this._bh, this._bl, 8);
  60281. writeInt64BE(this._ch, this._cl, 16);
  60282. writeInt64BE(this._dh, this._dl, 24);
  60283. writeInt64BE(this._eh, this._el, 32);
  60284. writeInt64BE(this._fh, this._fl, 40);
  60285. return H;
  60286. };
  60287. module.exports = Sha384;
  60288. },{"./hash":388,"./sha512":395,"inherits":278,"safe-buffer":384}],395:[function(require,module,exports){
  60289. "use strict";
  60290. var inherits = require('inherits');
  60291. var Hash = require('./hash');
  60292. var Buffer = require('safe-buffer').Buffer;
  60293. 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];
  60294. var W = new Array(160);
  60295. function Sha512() {
  60296. this.init();
  60297. this._w = W;
  60298. Hash.call(this, 128, 112);
  60299. }
  60300. inherits(Sha512, Hash);
  60301. Sha512.prototype.init = function () {
  60302. this._ah = 0x6a09e667;
  60303. this._bh = 0xbb67ae85;
  60304. this._ch = 0x3c6ef372;
  60305. this._dh = 0xa54ff53a;
  60306. this._eh = 0x510e527f;
  60307. this._fh = 0x9b05688c;
  60308. this._gh = 0x1f83d9ab;
  60309. this._hh = 0x5be0cd19;
  60310. this._al = 0xf3bcc908;
  60311. this._bl = 0x84caa73b;
  60312. this._cl = 0xfe94f82b;
  60313. this._dl = 0x5f1d36f1;
  60314. this._el = 0xade682d1;
  60315. this._fl = 0x2b3e6c1f;
  60316. this._gl = 0xfb41bd6b;
  60317. this._hl = 0x137e2179;
  60318. return this;
  60319. };
  60320. function Ch(x, y, z) {
  60321. return z ^ x & (y ^ z);
  60322. }
  60323. function maj(x, y, z) {
  60324. return x & y | z & (x | y);
  60325. }
  60326. function sigma0(x, xl) {
  60327. return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25);
  60328. }
  60329. function sigma1(x, xl) {
  60330. return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23);
  60331. }
  60332. function Gamma0(x, xl) {
  60333. return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ x >>> 7;
  60334. }
  60335. function Gamma0l(x, xl) {
  60336. return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25);
  60337. }
  60338. function Gamma1(x, xl) {
  60339. return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ x >>> 6;
  60340. }
  60341. function Gamma1l(x, xl) {
  60342. return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26);
  60343. }
  60344. function getCarry(a, b) {
  60345. return a >>> 0 < b >>> 0 ? 1 : 0;
  60346. }
  60347. Sha512.prototype._update = function (M) {
  60348. var W = this._w;
  60349. var ah = this._ah | 0;
  60350. var bh = this._bh | 0;
  60351. var ch = this._ch | 0;
  60352. var dh = this._dh | 0;
  60353. var eh = this._eh | 0;
  60354. var fh = this._fh | 0;
  60355. var gh = this._gh | 0;
  60356. var hh = this._hh | 0;
  60357. var al = this._al | 0;
  60358. var bl = this._bl | 0;
  60359. var cl = this._cl | 0;
  60360. var dl = this._dl | 0;
  60361. var el = this._el | 0;
  60362. var fl = this._fl | 0;
  60363. var gl = this._gl | 0;
  60364. var hl = this._hl | 0;
  60365. for (var i = 0; i < 32; i += 2) {
  60366. W[i] = M.readInt32BE(i * 4);
  60367. W[i + 1] = M.readInt32BE(i * 4 + 4);
  60368. }
  60369. for (; i < 160; i += 2) {
  60370. var xh = W[i - 15 * 2];
  60371. var xl = W[i - 15 * 2 + 1];
  60372. var gamma0 = Gamma0(xh, xl);
  60373. var gamma0l = Gamma0l(xl, xh);
  60374. xh = W[i - 2 * 2];
  60375. xl = W[i - 2 * 2 + 1];
  60376. var gamma1 = Gamma1(xh, xl);
  60377. var gamma1l = Gamma1l(xl, xh); // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
  60378. var Wi7h = W[i - 7 * 2];
  60379. var Wi7l = W[i - 7 * 2 + 1];
  60380. var Wi16h = W[i - 16 * 2];
  60381. var Wi16l = W[i - 16 * 2 + 1];
  60382. var Wil = gamma0l + Wi7l | 0;
  60383. var Wih = gamma0 + Wi7h + getCarry(Wil, gamma0l) | 0;
  60384. Wil = Wil + gamma1l | 0;
  60385. Wih = Wih + gamma1 + getCarry(Wil, gamma1l) | 0;
  60386. Wil = Wil + Wi16l | 0;
  60387. Wih = Wih + Wi16h + getCarry(Wil, Wi16l) | 0;
  60388. W[i] = Wih;
  60389. W[i + 1] = Wil;
  60390. }
  60391. for (var j = 0; j < 160; j += 2) {
  60392. Wih = W[j];
  60393. Wil = W[j + 1];
  60394. var majh = maj(ah, bh, ch);
  60395. var majl = maj(al, bl, cl);
  60396. var sigma0h = sigma0(ah, al);
  60397. var sigma0l = sigma0(al, ah);
  60398. var sigma1h = sigma1(eh, el);
  60399. var sigma1l = sigma1(el, eh); // t1 = h + sigma1 + ch + K[j] + W[j]
  60400. var Kih = K[j];
  60401. var Kil = K[j + 1];
  60402. var chh = Ch(eh, fh, gh);
  60403. var chl = Ch(el, fl, gl);
  60404. var t1l = hl + sigma1l | 0;
  60405. var t1h = hh + sigma1h + getCarry(t1l, hl) | 0;
  60406. t1l = t1l + chl | 0;
  60407. t1h = t1h + chh + getCarry(t1l, chl) | 0;
  60408. t1l = t1l + Kil | 0;
  60409. t1h = t1h + Kih + getCarry(t1l, Kil) | 0;
  60410. t1l = t1l + Wil | 0;
  60411. t1h = t1h + Wih + getCarry(t1l, Wil) | 0; // t2 = sigma0 + maj
  60412. var t2l = sigma0l + majl | 0;
  60413. var t2h = sigma0h + majh + getCarry(t2l, sigma0l) | 0;
  60414. hh = gh;
  60415. hl = gl;
  60416. gh = fh;
  60417. gl = fl;
  60418. fh = eh;
  60419. fl = el;
  60420. el = dl + t1l | 0;
  60421. eh = dh + t1h + getCarry(el, dl) | 0;
  60422. dh = ch;
  60423. dl = cl;
  60424. ch = bh;
  60425. cl = bl;
  60426. bh = ah;
  60427. bl = al;
  60428. al = t1l + t2l | 0;
  60429. ah = t1h + t2h + getCarry(al, t1l) | 0;
  60430. }
  60431. this._al = this._al + al | 0;
  60432. this._bl = this._bl + bl | 0;
  60433. this._cl = this._cl + cl | 0;
  60434. this._dl = this._dl + dl | 0;
  60435. this._el = this._el + el | 0;
  60436. this._fl = this._fl + fl | 0;
  60437. this._gl = this._gl + gl | 0;
  60438. this._hl = this._hl + hl | 0;
  60439. this._ah = this._ah + ah + getCarry(this._al, al) | 0;
  60440. this._bh = this._bh + bh + getCarry(this._bl, bl) | 0;
  60441. this._ch = this._ch + ch + getCarry(this._cl, cl) | 0;
  60442. this._dh = this._dh + dh + getCarry(this._dl, dl) | 0;
  60443. this._eh = this._eh + eh + getCarry(this._el, el) | 0;
  60444. this._fh = this._fh + fh + getCarry(this._fl, fl) | 0;
  60445. this._gh = this._gh + gh + getCarry(this._gl, gl) | 0;
  60446. this._hh = this._hh + hh + getCarry(this._hl, hl) | 0;
  60447. };
  60448. Sha512.prototype._hash = function () {
  60449. var H = Buffer.allocUnsafe(64);
  60450. function writeInt64BE(h, l, offset) {
  60451. H.writeInt32BE(h, offset);
  60452. H.writeInt32BE(l, offset + 4);
  60453. }
  60454. writeInt64BE(this._ah, this._al, 0);
  60455. writeInt64BE(this._bh, this._bl, 8);
  60456. writeInt64BE(this._ch, this._cl, 16);
  60457. writeInt64BE(this._dh, this._dl, 24);
  60458. writeInt64BE(this._eh, this._el, 32);
  60459. writeInt64BE(this._fh, this._fl, 40);
  60460. writeInt64BE(this._gh, this._gl, 48);
  60461. writeInt64BE(this._hh, this._hl, 56);
  60462. return H;
  60463. };
  60464. module.exports = Sha512;
  60465. },{"./hash":388,"inherits":278,"safe-buffer":384}],396:[function(require,module,exports){
  60466. "use strict";
  60467. // Copyright Joyent, Inc. and other Node contributors.
  60468. //
  60469. // Permission is hereby granted, free of charge, to any person obtaining a
  60470. // copy of this software and associated documentation files (the
  60471. // "Software"), to deal in the Software without restriction, including
  60472. // without limitation the rights to use, copy, modify, merge, publish,
  60473. // distribute, sublicense, and/or sell copies of the Software, and to permit
  60474. // persons to whom the Software is furnished to do so, subject to the
  60475. // following conditions:
  60476. //
  60477. // The above copyright notice and this permission notice shall be included
  60478. // in all copies or substantial portions of the Software.
  60479. //
  60480. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  60481. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  60482. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  60483. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  60484. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  60485. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  60486. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  60487. module.exports = Stream;
  60488. var EE = require('events').EventEmitter;
  60489. var inherits = require('inherits');
  60490. inherits(Stream, EE);
  60491. Stream.Readable = require('readable-stream/readable.js');
  60492. Stream.Writable = require('readable-stream/writable.js');
  60493. Stream.Duplex = require('readable-stream/duplex.js');
  60494. Stream.Transform = require('readable-stream/transform.js');
  60495. Stream.PassThrough = require('readable-stream/passthrough.js'); // Backwards-compat with node 0.4.x
  60496. Stream.Stream = Stream; // old-style streams. Note that the pipe method (the only relevant
  60497. // part of this class) is overridden in the Readable class.
  60498. function Stream() {
  60499. EE.call(this);
  60500. }
  60501. Stream.prototype.pipe = function (dest, options) {
  60502. var source = this;
  60503. function ondata(chunk) {
  60504. if (dest.writable) {
  60505. if (false === dest.write(chunk) && source.pause) {
  60506. source.pause();
  60507. }
  60508. }
  60509. }
  60510. source.on('data', ondata);
  60511. function ondrain() {
  60512. if (source.readable && source.resume) {
  60513. source.resume();
  60514. }
  60515. }
  60516. dest.on('drain', ondrain); // If the 'end' option is not supplied, dest.end() will be called when
  60517. // source gets the 'end' or 'close' events. Only dest.end() once.
  60518. if (!dest._isStdio && (!options || options.end !== false)) {
  60519. source.on('end', onend);
  60520. source.on('close', onclose);
  60521. }
  60522. var didOnEnd = false;
  60523. function onend() {
  60524. if (didOnEnd) return;
  60525. didOnEnd = true;
  60526. dest.end();
  60527. }
  60528. function onclose() {
  60529. if (didOnEnd) return;
  60530. didOnEnd = true;
  60531. if (typeof dest.destroy === 'function') dest.destroy();
  60532. } // don't leave dangling pipes when there are errors.
  60533. function onerror(er) {
  60534. cleanup();
  60535. if (EE.listenerCount(this, 'error') === 0) {
  60536. throw er; // Unhandled stream error in pipe.
  60537. }
  60538. }
  60539. source.on('error', onerror);
  60540. dest.on('error', onerror); // remove all the event listeners that were added.
  60541. function cleanup() {
  60542. source.removeListener('data', ondata);
  60543. dest.removeListener('drain', ondrain);
  60544. source.removeListener('end', onend);
  60545. source.removeListener('close', onclose);
  60546. source.removeListener('error', onerror);
  60547. dest.removeListener('error', onerror);
  60548. source.removeListener('end', cleanup);
  60549. source.removeListener('close', cleanup);
  60550. dest.removeListener('close', cleanup);
  60551. }
  60552. source.on('end', cleanup);
  60553. source.on('close', cleanup);
  60554. dest.on('close', cleanup);
  60555. dest.emit('pipe', source); // Allow for unix-like usage: A.pipe(B).pipe(C)
  60556. return dest;
  60557. };
  60558. },{"events":258,"inherits":278,"readable-stream/duplex.js":397,"readable-stream/passthrough.js":406,"readable-stream/readable.js":407,"readable-stream/transform.js":408,"readable-stream/writable.js":409}],397:[function(require,module,exports){
  60559. "use strict";
  60560. module.exports = require('./lib/_stream_duplex.js');
  60561. },{"./lib/_stream_duplex.js":398}],398:[function(require,module,exports){
  60562. // Copyright Joyent, Inc. and other Node contributors.
  60563. //
  60564. // Permission is hereby granted, free of charge, to any person obtaining a
  60565. // copy of this software and associated documentation files (the
  60566. // "Software"), to deal in the Software without restriction, including
  60567. // without limitation the rights to use, copy, modify, merge, publish,
  60568. // distribute, sublicense, and/or sell copies of the Software, and to permit
  60569. // persons to whom the Software is furnished to do so, subject to the
  60570. // following conditions:
  60571. //
  60572. // The above copyright notice and this permission notice shall be included
  60573. // in all copies or substantial portions of the Software.
  60574. //
  60575. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  60576. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  60577. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  60578. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  60579. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  60580. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  60581. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  60582. // a duplex stream is just a stream that is both readable and writable.
  60583. // Since JS doesn't have multiple prototypal inheritance, this class
  60584. // prototypally inherits from Readable, and then parasitically from
  60585. // Writable.
  60586. 'use strict';
  60587. /*<replacement>*/
  60588. var pna = require('process-nextick-args');
  60589. /*</replacement>*/
  60590. /*<replacement>*/
  60591. var objectKeys = Object.keys || function (obj) {
  60592. var keys = [];
  60593. for (var key in obj) {
  60594. keys.push(key);
  60595. }
  60596. return keys;
  60597. };
  60598. /*</replacement>*/
  60599. module.exports = Duplex;
  60600. /*<replacement>*/
  60601. var util = Object.create(require('core-util-is'));
  60602. util.inherits = require('inherits');
  60603. /*</replacement>*/
  60604. var Readable = require('./_stream_readable');
  60605. var Writable = require('./_stream_writable');
  60606. util.inherits(Duplex, Readable);
  60607. {
  60608. // avoid scope creep, the keys array can then be collected
  60609. var keys = objectKeys(Writable.prototype);
  60610. for (var v = 0; v < keys.length; v++) {
  60611. var method = keys[v];
  60612. if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
  60613. }
  60614. }
  60615. function Duplex(options) {
  60616. if (!(this instanceof Duplex)) return new Duplex(options);
  60617. Readable.call(this, options);
  60618. Writable.call(this, options);
  60619. if (options && options.readable === false) this.readable = false;
  60620. if (options && options.writable === false) this.writable = false;
  60621. this.allowHalfOpen = true;
  60622. if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
  60623. this.once('end', onend);
  60624. }
  60625. Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
  60626. // making it explicit this property is not enumerable
  60627. // because otherwise some prototype manipulation in
  60628. // userland will fail
  60629. enumerable: false,
  60630. get: function get() {
  60631. return this._writableState.highWaterMark;
  60632. }
  60633. }); // the no-half-open enforcer
  60634. function onend() {
  60635. // if we allow half-open state, or if the writable side ended,
  60636. // then we're ok.
  60637. if (this.allowHalfOpen || this._writableState.ended) return; // no more data can be written.
  60638. // But allow more writes to happen in this tick.
  60639. pna.nextTick(onEndNT, this);
  60640. }
  60641. function onEndNT(self) {
  60642. self.end();
  60643. }
  60644. Object.defineProperty(Duplex.prototype, 'destroyed', {
  60645. get: function get() {
  60646. if (this._readableState === undefined || this._writableState === undefined) {
  60647. return false;
  60648. }
  60649. return this._readableState.destroyed && this._writableState.destroyed;
  60650. },
  60651. set: function set(value) {
  60652. // we ignore the value if the stream
  60653. // has not been initialized yet
  60654. if (this._readableState === undefined || this._writableState === undefined) {
  60655. return;
  60656. } // backward compatibility, the user is explicitly
  60657. // managing destroyed
  60658. this._readableState.destroyed = value;
  60659. this._writableState.destroyed = value;
  60660. }
  60661. });
  60662. Duplex.prototype._destroy = function (err, cb) {
  60663. this.push(null);
  60664. this.end();
  60665. pna.nextTick(cb, err);
  60666. };
  60667. },{"./_stream_readable":400,"./_stream_writable":402,"core-util-is":219,"inherits":278,"process-nextick-args":357}],399:[function(require,module,exports){
  60668. // Copyright Joyent, Inc. and other Node contributors.
  60669. //
  60670. // Permission is hereby granted, free of charge, to any person obtaining a
  60671. // copy of this software and associated documentation files (the
  60672. // "Software"), to deal in the Software without restriction, including
  60673. // without limitation the rights to use, copy, modify, merge, publish,
  60674. // distribute, sublicense, and/or sell copies of the Software, and to permit
  60675. // persons to whom the Software is furnished to do so, subject to the
  60676. // following conditions:
  60677. //
  60678. // The above copyright notice and this permission notice shall be included
  60679. // in all copies or substantial portions of the Software.
  60680. //
  60681. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  60682. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  60683. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  60684. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  60685. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  60686. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  60687. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  60688. // a passthrough stream.
  60689. // basically just the most minimal sort of Transform stream.
  60690. // Every written chunk gets output as-is.
  60691. 'use strict';
  60692. module.exports = PassThrough;
  60693. var Transform = require('./_stream_transform');
  60694. /*<replacement>*/
  60695. var util = Object.create(require('core-util-is'));
  60696. util.inherits = require('inherits');
  60697. /*</replacement>*/
  60698. util.inherits(PassThrough, Transform);
  60699. function PassThrough(options) {
  60700. if (!(this instanceof PassThrough)) return new PassThrough(options);
  60701. Transform.call(this, options);
  60702. }
  60703. PassThrough.prototype._transform = function (chunk, encoding, cb) {
  60704. cb(null, chunk);
  60705. };
  60706. },{"./_stream_transform":401,"core-util-is":219,"inherits":278}],400:[function(require,module,exports){
  60707. (function (process,global){
  60708. // Copyright Joyent, Inc. and other Node contributors.
  60709. //
  60710. // Permission is hereby granted, free of charge, to any person obtaining a
  60711. // copy of this software and associated documentation files (the
  60712. // "Software"), to deal in the Software without restriction, including
  60713. // without limitation the rights to use, copy, modify, merge, publish,
  60714. // distribute, sublicense, and/or sell copies of the Software, and to permit
  60715. // persons to whom the Software is furnished to do so, subject to the
  60716. // following conditions:
  60717. //
  60718. // The above copyright notice and this permission notice shall be included
  60719. // in all copies or substantial portions of the Software.
  60720. //
  60721. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  60722. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  60723. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  60724. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  60725. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  60726. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  60727. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  60728. 'use strict';
  60729. /*<replacement>*/
  60730. var pna = require('process-nextick-args');
  60731. /*</replacement>*/
  60732. module.exports = Readable;
  60733. /*<replacement>*/
  60734. var isArray = require('isarray');
  60735. /*</replacement>*/
  60736. /*<replacement>*/
  60737. var Duplex;
  60738. /*</replacement>*/
  60739. Readable.ReadableState = ReadableState;
  60740. /*<replacement>*/
  60741. var EE = require('events').EventEmitter;
  60742. var EElistenerCount = function EElistenerCount(emitter, type) {
  60743. return emitter.listeners(type).length;
  60744. };
  60745. /*</replacement>*/
  60746. /*<replacement>*/
  60747. var Stream = require('./internal/streams/stream');
  60748. /*</replacement>*/
  60749. /*<replacement>*/
  60750. var Buffer = require('safe-buffer').Buffer;
  60751. var OurUint8Array = global.Uint8Array || function () {};
  60752. function _uint8ArrayToBuffer(chunk) {
  60753. return Buffer.from(chunk);
  60754. }
  60755. function _isUint8Array(obj) {
  60756. return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
  60757. }
  60758. /*</replacement>*/
  60759. /*<replacement>*/
  60760. var util = Object.create(require('core-util-is'));
  60761. util.inherits = require('inherits');
  60762. /*</replacement>*/
  60763. /*<replacement>*/
  60764. var debugUtil = require('util');
  60765. var debug = void 0;
  60766. if (debugUtil && debugUtil.debuglog) {
  60767. debug = debugUtil.debuglog('stream');
  60768. } else {
  60769. debug = function debug() {};
  60770. }
  60771. /*</replacement>*/
  60772. var BufferList = require('./internal/streams/BufferList');
  60773. var destroyImpl = require('./internal/streams/destroy');
  60774. var StringDecoder;
  60775. util.inherits(Readable, Stream);
  60776. var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
  60777. function prependListener(emitter, event, fn) {
  60778. // Sadly this is not cacheable as some libraries bundle their own
  60779. // event emitter implementation with them.
  60780. 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
  60781. // userland ones. NEVER DO THIS. This is here only because this code needs
  60782. // to continue to work with older versions of Node.js that do not include
  60783. // the prependListener() method. The goal is to eventually remove this hack.
  60784. 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]];
  60785. }
  60786. function ReadableState(options, stream) {
  60787. Duplex = Duplex || require('./_stream_duplex');
  60788. options = options || {}; // Duplex streams are both readable and writable, but share
  60789. // the same options object.
  60790. // However, some cases require setting options to different
  60791. // values for the readable and the writable sides of the duplex stream.
  60792. // These options can be provided separately as readableXXX and writableXXX.
  60793. var isDuplex = stream instanceof Duplex; // object stream flag. Used to make read(n) ignore n and to
  60794. // make all the buffer merging and length checks go away
  60795. this.objectMode = !!options.objectMode;
  60796. if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode; // the point at which it stops calling _read() to fill the buffer
  60797. // Note: 0 is a valid value, means "don't call _read preemptively ever"
  60798. var hwm = options.highWaterMark;
  60799. var readableHwm = options.readableHighWaterMark;
  60800. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  60801. if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (readableHwm || readableHwm === 0)) this.highWaterMark = readableHwm;else this.highWaterMark = defaultHwm; // cast to ints.
  60802. this.highWaterMark = Math.floor(this.highWaterMark); // A linked list is used to store data chunks instead of an array because the
  60803. // linked list can remove elements from the beginning faster than
  60804. // array.shift()
  60805. this.buffer = new BufferList();
  60806. this.length = 0;
  60807. this.pipes = null;
  60808. this.pipesCount = 0;
  60809. this.flowing = null;
  60810. this.ended = false;
  60811. this.endEmitted = false;
  60812. this.reading = false; // a flag to be able to tell if the event 'readable'/'data' is emitted
  60813. // immediately, or on a later tick. We set this to true at first, because
  60814. // any actions that shouldn't happen until "later" should generally also
  60815. // not happen before the first read call.
  60816. this.sync = true; // whenever we return null, then we set a flag to say
  60817. // that we're awaiting a 'readable' event emission.
  60818. this.needReadable = false;
  60819. this.emittedReadable = false;
  60820. this.readableListening = false;
  60821. this.resumeScheduled = false; // has it been destroyed
  60822. this.destroyed = false; // Crypto is kind of old and crusty. Historically, its default string
  60823. // encoding is 'binary' so we have to make this configurable.
  60824. // Everything else in the universe uses 'utf8', though.
  60825. this.defaultEncoding = options.defaultEncoding || 'utf8'; // the number of writers that are awaiting a drain event in .pipe()s
  60826. this.awaitDrain = 0; // if true, a maybeReadMore has been scheduled
  60827. this.readingMore = false;
  60828. this.decoder = null;
  60829. this.encoding = null;
  60830. if (options.encoding) {
  60831. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  60832. this.decoder = new StringDecoder(options.encoding);
  60833. this.encoding = options.encoding;
  60834. }
  60835. }
  60836. function Readable(options) {
  60837. Duplex = Duplex || require('./_stream_duplex');
  60838. if (!(this instanceof Readable)) return new Readable(options);
  60839. this._readableState = new ReadableState(options, this); // legacy
  60840. this.readable = true;
  60841. if (options) {
  60842. if (typeof options.read === 'function') this._read = options.read;
  60843. if (typeof options.destroy === 'function') this._destroy = options.destroy;
  60844. }
  60845. Stream.call(this);
  60846. }
  60847. Object.defineProperty(Readable.prototype, 'destroyed', {
  60848. get: function get() {
  60849. if (this._readableState === undefined) {
  60850. return false;
  60851. }
  60852. return this._readableState.destroyed;
  60853. },
  60854. set: function set(value) {
  60855. // we ignore the value if the stream
  60856. // has not been initialized yet
  60857. if (!this._readableState) {
  60858. return;
  60859. } // backward compatibility, the user is explicitly
  60860. // managing destroyed
  60861. this._readableState.destroyed = value;
  60862. }
  60863. });
  60864. Readable.prototype.destroy = destroyImpl.destroy;
  60865. Readable.prototype._undestroy = destroyImpl.undestroy;
  60866. Readable.prototype._destroy = function (err, cb) {
  60867. this.push(null);
  60868. cb(err);
  60869. }; // Manually shove something into the read() buffer.
  60870. // This returns true if the highWaterMark has not been hit yet,
  60871. // similar to how Writable.write() returns true if you should
  60872. // write() some more.
  60873. Readable.prototype.push = function (chunk, encoding) {
  60874. var state = this._readableState;
  60875. var skipChunkCheck;
  60876. if (!state.objectMode) {
  60877. if (typeof chunk === 'string') {
  60878. encoding = encoding || state.defaultEncoding;
  60879. if (encoding !== state.encoding) {
  60880. chunk = Buffer.from(chunk, encoding);
  60881. encoding = '';
  60882. }
  60883. skipChunkCheck = true;
  60884. }
  60885. } else {
  60886. skipChunkCheck = true;
  60887. }
  60888. return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
  60889. }; // Unshift should *always* be something directly out of read()
  60890. Readable.prototype.unshift = function (chunk) {
  60891. return readableAddChunk(this, chunk, null, true, false);
  60892. };
  60893. function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
  60894. var state = stream._readableState;
  60895. if (chunk === null) {
  60896. state.reading = false;
  60897. onEofChunk(stream, state);
  60898. } else {
  60899. var er;
  60900. if (!skipChunkCheck) er = chunkInvalid(state, chunk);
  60901. if (er) {
  60902. stream.emit('error', er);
  60903. } else if (state.objectMode || chunk && chunk.length > 0) {
  60904. if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
  60905. chunk = _uint8ArrayToBuffer(chunk);
  60906. }
  60907. if (addToFront) {
  60908. if (state.endEmitted) stream.emit('error', new Error('stream.unshift() after end event'));else addChunk(stream, state, chunk, true);
  60909. } else if (state.ended) {
  60910. stream.emit('error', new Error('stream.push() after EOF'));
  60911. } else {
  60912. state.reading = false;
  60913. if (state.decoder && !encoding) {
  60914. chunk = state.decoder.write(chunk);
  60915. if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
  60916. } else {
  60917. addChunk(stream, state, chunk, false);
  60918. }
  60919. }
  60920. } else if (!addToFront) {
  60921. state.reading = false;
  60922. }
  60923. }
  60924. return needMoreData(state);
  60925. }
  60926. function addChunk(stream, state, chunk, addToFront) {
  60927. if (state.flowing && state.length === 0 && !state.sync) {
  60928. stream.emit('data', chunk);
  60929. stream.read(0);
  60930. } else {
  60931. // update the buffer info.
  60932. state.length += state.objectMode ? 1 : chunk.length;
  60933. if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
  60934. if (state.needReadable) emitReadable(stream);
  60935. }
  60936. maybeReadMore(stream, state);
  60937. }
  60938. function chunkInvalid(state, chunk) {
  60939. var er;
  60940. if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
  60941. er = new TypeError('Invalid non-string/buffer chunk');
  60942. }
  60943. return er;
  60944. } // if it's past the high water mark, we can push in some more.
  60945. // Also, if we have no data yet, we can stand some
  60946. // more bytes. This is to work around cases where hwm=0,
  60947. // such as the repl. Also, if the push() triggered a
  60948. // readable event, and the user called read(largeNumber) such that
  60949. // needReadable was set, then we ought to push more, so that another
  60950. // 'readable' event will be triggered.
  60951. function needMoreData(state) {
  60952. return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
  60953. }
  60954. Readable.prototype.isPaused = function () {
  60955. return this._readableState.flowing === false;
  60956. }; // backwards compatibility.
  60957. Readable.prototype.setEncoding = function (enc) {
  60958. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  60959. this._readableState.decoder = new StringDecoder(enc);
  60960. this._readableState.encoding = enc;
  60961. return this;
  60962. }; // Don't raise the hwm > 8MB
  60963. var MAX_HWM = 0x800000;
  60964. function computeNewHighWaterMark(n) {
  60965. if (n >= MAX_HWM) {
  60966. n = MAX_HWM;
  60967. } else {
  60968. // Get the next highest power of 2 to prevent increasing hwm excessively in
  60969. // tiny amounts
  60970. n--;
  60971. n |= n >>> 1;
  60972. n |= n >>> 2;
  60973. n |= n >>> 4;
  60974. n |= n >>> 8;
  60975. n |= n >>> 16;
  60976. n++;
  60977. }
  60978. return n;
  60979. } // This function is designed to be inlinable, so please take care when making
  60980. // changes to the function body.
  60981. function howMuchToRead(n, state) {
  60982. if (n <= 0 || state.length === 0 && state.ended) return 0;
  60983. if (state.objectMode) return 1;
  60984. if (n !== n) {
  60985. // Only flow one buffer at a time
  60986. if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
  60987. } // If we're asking for more than the current hwm, then raise the hwm.
  60988. if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
  60989. if (n <= state.length) return n; // Don't have enough
  60990. if (!state.ended) {
  60991. state.needReadable = true;
  60992. return 0;
  60993. }
  60994. return state.length;
  60995. } // you can override either this method, or the async _read(n) below.
  60996. Readable.prototype.read = function (n) {
  60997. debug('read', n);
  60998. n = parseInt(n, 10);
  60999. var state = this._readableState;
  61000. var nOrig = n;
  61001. if (n !== 0) state.emittedReadable = false; // if we're doing read(0) to trigger a readable event, but we
  61002. // already have a bunch of data in the buffer, then just trigger
  61003. // the 'readable' event and move on.
  61004. if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
  61005. debug('read: emitReadable', state.length, state.ended);
  61006. if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
  61007. return null;
  61008. }
  61009. n = howMuchToRead(n, state); // if we've ended, and we're now clear, then finish it up.
  61010. if (n === 0 && state.ended) {
  61011. if (state.length === 0) endReadable(this);
  61012. return null;
  61013. } // All the actual chunk generation logic needs to be
  61014. // *below* the call to _read. The reason is that in certain
  61015. // synthetic stream cases, such as passthrough streams, _read
  61016. // may be a completely synchronous operation which may change
  61017. // the state of the read buffer, providing enough data when
  61018. // before there was *not* enough.
  61019. //
  61020. // So, the steps are:
  61021. // 1. Figure out what the state of things will be after we do
  61022. // a read from the buffer.
  61023. //
  61024. // 2. If that resulting state will trigger a _read, then call _read.
  61025. // Note that this may be asynchronous, or synchronous. Yes, it is
  61026. // deeply ugly to write APIs this way, but that still doesn't mean
  61027. // that the Readable class should behave improperly, as streams are
  61028. // designed to be sync/async agnostic.
  61029. // Take note if the _read call is sync or async (ie, if the read call
  61030. // has returned yet), so that we know whether or not it's safe to emit
  61031. // 'readable' etc.
  61032. //
  61033. // 3. Actually pull the requested chunks out of the buffer and return.
  61034. // if we need a readable event, then we need to do some reading.
  61035. var doRead = state.needReadable;
  61036. debug('need readable', doRead); // if we currently have less than the highWaterMark, then also read some
  61037. if (state.length === 0 || state.length - n < state.highWaterMark) {
  61038. doRead = true;
  61039. debug('length less than watermark', doRead);
  61040. } // however, if we've ended, then there's no point, and if we're already
  61041. // reading, then it's unnecessary.
  61042. if (state.ended || state.reading) {
  61043. doRead = false;
  61044. debug('reading or ended', doRead);
  61045. } else if (doRead) {
  61046. debug('do read');
  61047. state.reading = true;
  61048. state.sync = true; // if the length is currently zero, then we *need* a readable event.
  61049. if (state.length === 0) state.needReadable = true; // call internal read method
  61050. this._read(state.highWaterMark);
  61051. state.sync = false; // If _read pushed data synchronously, then `reading` will be false,
  61052. // and we need to re-evaluate how much data we can return to the user.
  61053. if (!state.reading) n = howMuchToRead(nOrig, state);
  61054. }
  61055. var ret;
  61056. if (n > 0) ret = fromList(n, state);else ret = null;
  61057. if (ret === null) {
  61058. state.needReadable = true;
  61059. n = 0;
  61060. } else {
  61061. state.length -= n;
  61062. }
  61063. if (state.length === 0) {
  61064. // If we have nothing in the buffer, then we want to know
  61065. // as soon as we *do* get something into the buffer.
  61066. if (!state.ended) state.needReadable = true; // If we tried to read() past the EOF, then emit end on the next tick.
  61067. if (nOrig !== n && state.ended) endReadable(this);
  61068. }
  61069. if (ret !== null) this.emit('data', ret);
  61070. return ret;
  61071. };
  61072. function onEofChunk(stream, state) {
  61073. if (state.ended) return;
  61074. if (state.decoder) {
  61075. var chunk = state.decoder.end();
  61076. if (chunk && chunk.length) {
  61077. state.buffer.push(chunk);
  61078. state.length += state.objectMode ? 1 : chunk.length;
  61079. }
  61080. }
  61081. state.ended = true; // emit 'readable' now to make sure it gets picked up.
  61082. emitReadable(stream);
  61083. } // Don't emit readable right away in sync mode, because this can trigger
  61084. // another read() call => stack overflow. This way, it might trigger
  61085. // a nextTick recursion warning, but that's not so bad.
  61086. function emitReadable(stream) {
  61087. var state = stream._readableState;
  61088. state.needReadable = false;
  61089. if (!state.emittedReadable) {
  61090. debug('emitReadable', state.flowing);
  61091. state.emittedReadable = true;
  61092. if (state.sync) pna.nextTick(emitReadable_, stream);else emitReadable_(stream);
  61093. }
  61094. }
  61095. function emitReadable_(stream) {
  61096. debug('emit readable');
  61097. stream.emit('readable');
  61098. flow(stream);
  61099. } // at this point, the user has presumably seen the 'readable' event,
  61100. // and called read() to consume some data. that may have triggered
  61101. // in turn another _read(n) call, in which case reading = true if
  61102. // it's in progress.
  61103. // However, if we're not ended, or reading, and the length < hwm,
  61104. // then go ahead and try to read some more preemptively.
  61105. function maybeReadMore(stream, state) {
  61106. if (!state.readingMore) {
  61107. state.readingMore = true;
  61108. pna.nextTick(maybeReadMore_, stream, state);
  61109. }
  61110. }
  61111. function maybeReadMore_(stream, state) {
  61112. var len = state.length;
  61113. while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
  61114. debug('maybeReadMore read 0');
  61115. stream.read(0);
  61116. if (len === state.length) // didn't get any data, stop spinning.
  61117. break;else len = state.length;
  61118. }
  61119. state.readingMore = false;
  61120. } // abstract method. to be overridden in specific implementation classes.
  61121. // call cb(er, data) where data is <= n in length.
  61122. // for virtual (non-string, non-buffer) streams, "length" is somewhat
  61123. // arbitrary, and perhaps not very meaningful.
  61124. Readable.prototype._read = function (n) {
  61125. this.emit('error', new Error('_read() is not implemented'));
  61126. };
  61127. Readable.prototype.pipe = function (dest, pipeOpts) {
  61128. var src = this;
  61129. var state = this._readableState;
  61130. switch (state.pipesCount) {
  61131. case 0:
  61132. state.pipes = dest;
  61133. break;
  61134. case 1:
  61135. state.pipes = [state.pipes, dest];
  61136. break;
  61137. default:
  61138. state.pipes.push(dest);
  61139. break;
  61140. }
  61141. state.pipesCount += 1;
  61142. debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
  61143. var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
  61144. var endFn = doEnd ? onend : unpipe;
  61145. if (state.endEmitted) pna.nextTick(endFn);else src.once('end', endFn);
  61146. dest.on('unpipe', onunpipe);
  61147. function onunpipe(readable, unpipeInfo) {
  61148. debug('onunpipe');
  61149. if (readable === src) {
  61150. if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
  61151. unpipeInfo.hasUnpiped = true;
  61152. cleanup();
  61153. }
  61154. }
  61155. }
  61156. function onend() {
  61157. debug('onend');
  61158. dest.end();
  61159. } // when the dest drains, it reduces the awaitDrain counter
  61160. // on the source. This would be more elegant with a .once()
  61161. // handler in flow(), but adding and removing repeatedly is
  61162. // too slow.
  61163. var ondrain = pipeOnDrain(src);
  61164. dest.on('drain', ondrain);
  61165. var cleanedUp = false;
  61166. function cleanup() {
  61167. debug('cleanup'); // cleanup event handlers once the pipe is broken
  61168. dest.removeListener('close', onclose);
  61169. dest.removeListener('finish', onfinish);
  61170. dest.removeListener('drain', ondrain);
  61171. dest.removeListener('error', onerror);
  61172. dest.removeListener('unpipe', onunpipe);
  61173. src.removeListener('end', onend);
  61174. src.removeListener('end', unpipe);
  61175. src.removeListener('data', ondata);
  61176. cleanedUp = true; // if the reader is waiting for a drain event from this
  61177. // specific writer, then it would cause it to never start
  61178. // flowing again.
  61179. // So, if this is awaiting a drain, then we just call it now.
  61180. // If we don't know, then assume that we are waiting for one.
  61181. if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
  61182. } // If the user pushes more data while we're writing to dest then we'll end up
  61183. // in ondata again. However, we only want to increase awaitDrain once because
  61184. // dest will only emit one 'drain' event for the multiple writes.
  61185. // => Introduce a guard on increasing awaitDrain.
  61186. var increasedAwaitDrain = false;
  61187. src.on('data', ondata);
  61188. function ondata(chunk) {
  61189. debug('ondata');
  61190. increasedAwaitDrain = false;
  61191. var ret = dest.write(chunk);
  61192. if (false === ret && !increasedAwaitDrain) {
  61193. // If the user unpiped during `dest.write()`, it is possible
  61194. // to get stuck in a permanently paused state if that write
  61195. // also returned false.
  61196. // => Check whether `dest` is still a piping destination.
  61197. if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
  61198. debug('false write response, pause', src._readableState.awaitDrain);
  61199. src._readableState.awaitDrain++;
  61200. increasedAwaitDrain = true;
  61201. }
  61202. src.pause();
  61203. }
  61204. } // if the dest has an error, then stop piping into it.
  61205. // however, don't suppress the throwing behavior for this.
  61206. function onerror(er) {
  61207. debug('onerror', er);
  61208. unpipe();
  61209. dest.removeListener('error', onerror);
  61210. if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
  61211. } // Make sure our error handler is attached before userland ones.
  61212. prependListener(dest, 'error', onerror); // Both close and finish should trigger unpipe, but only once.
  61213. function onclose() {
  61214. dest.removeListener('finish', onfinish);
  61215. unpipe();
  61216. }
  61217. dest.once('close', onclose);
  61218. function onfinish() {
  61219. debug('onfinish');
  61220. dest.removeListener('close', onclose);
  61221. unpipe();
  61222. }
  61223. dest.once('finish', onfinish);
  61224. function unpipe() {
  61225. debug('unpipe');
  61226. src.unpipe(dest);
  61227. } // tell the dest that it's being piped to
  61228. dest.emit('pipe', src); // start the flow if it hasn't been started already.
  61229. if (!state.flowing) {
  61230. debug('pipe resume');
  61231. src.resume();
  61232. }
  61233. return dest;
  61234. };
  61235. function pipeOnDrain(src) {
  61236. return function () {
  61237. var state = src._readableState;
  61238. debug('pipeOnDrain', state.awaitDrain);
  61239. if (state.awaitDrain) state.awaitDrain--;
  61240. if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
  61241. state.flowing = true;
  61242. flow(src);
  61243. }
  61244. };
  61245. }
  61246. Readable.prototype.unpipe = function (dest) {
  61247. var state = this._readableState;
  61248. var unpipeInfo = {
  61249. hasUnpiped: false
  61250. }; // if we're not piping anywhere, then do nothing.
  61251. if (state.pipesCount === 0) return this; // just one destination. most common case.
  61252. if (state.pipesCount === 1) {
  61253. // passed in one, but it's not the right one.
  61254. if (dest && dest !== state.pipes) return this;
  61255. if (!dest) dest = state.pipes; // got a match.
  61256. state.pipes = null;
  61257. state.pipesCount = 0;
  61258. state.flowing = false;
  61259. if (dest) dest.emit('unpipe', this, unpipeInfo);
  61260. return this;
  61261. } // slow case. multiple pipe destinations.
  61262. if (!dest) {
  61263. // remove all.
  61264. var dests = state.pipes;
  61265. var len = state.pipesCount;
  61266. state.pipes = null;
  61267. state.pipesCount = 0;
  61268. state.flowing = false;
  61269. for (var i = 0; i < len; i++) {
  61270. dests[i].emit('unpipe', this, unpipeInfo);
  61271. }
  61272. return this;
  61273. } // try to find the right one.
  61274. var index = indexOf(state.pipes, dest);
  61275. if (index === -1) return this;
  61276. state.pipes.splice(index, 1);
  61277. state.pipesCount -= 1;
  61278. if (state.pipesCount === 1) state.pipes = state.pipes[0];
  61279. dest.emit('unpipe', this, unpipeInfo);
  61280. return this;
  61281. }; // set up data events if they are asked for
  61282. // Ensure readable listeners eventually get something
  61283. Readable.prototype.on = function (ev, fn) {
  61284. var res = Stream.prototype.on.call(this, ev, fn);
  61285. if (ev === 'data') {
  61286. // Start flowing on next tick if stream isn't explicitly paused
  61287. if (this._readableState.flowing !== false) this.resume();
  61288. } else if (ev === 'readable') {
  61289. var state = this._readableState;
  61290. if (!state.endEmitted && !state.readableListening) {
  61291. state.readableListening = state.needReadable = true;
  61292. state.emittedReadable = false;
  61293. if (!state.reading) {
  61294. pna.nextTick(nReadingNextTick, this);
  61295. } else if (state.length) {
  61296. emitReadable(this);
  61297. }
  61298. }
  61299. }
  61300. return res;
  61301. };
  61302. Readable.prototype.addListener = Readable.prototype.on;
  61303. function nReadingNextTick(self) {
  61304. debug('readable nexttick read 0');
  61305. self.read(0);
  61306. } // pause() and resume() are remnants of the legacy readable stream API
  61307. // If the user uses them, then switch into old mode.
  61308. Readable.prototype.resume = function () {
  61309. var state = this._readableState;
  61310. if (!state.flowing) {
  61311. debug('resume');
  61312. state.flowing = true;
  61313. resume(this, state);
  61314. }
  61315. return this;
  61316. };
  61317. function resume(stream, state) {
  61318. if (!state.resumeScheduled) {
  61319. state.resumeScheduled = true;
  61320. pna.nextTick(resume_, stream, state);
  61321. }
  61322. }
  61323. function resume_(stream, state) {
  61324. if (!state.reading) {
  61325. debug('resume read 0');
  61326. stream.read(0);
  61327. }
  61328. state.resumeScheduled = false;
  61329. state.awaitDrain = 0;
  61330. stream.emit('resume');
  61331. flow(stream);
  61332. if (state.flowing && !state.reading) stream.read(0);
  61333. }
  61334. Readable.prototype.pause = function () {
  61335. debug('call pause flowing=%j', this._readableState.flowing);
  61336. if (false !== this._readableState.flowing) {
  61337. debug('pause');
  61338. this._readableState.flowing = false;
  61339. this.emit('pause');
  61340. }
  61341. return this;
  61342. };
  61343. function flow(stream) {
  61344. var state = stream._readableState;
  61345. debug('flow', state.flowing);
  61346. while (state.flowing && stream.read() !== null) {}
  61347. } // wrap an old-style stream as the async data source.
  61348. // This is *not* part of the readable stream interface.
  61349. // It is an ugly unfortunate mess of history.
  61350. Readable.prototype.wrap = function (stream) {
  61351. var _this = this;
  61352. var state = this._readableState;
  61353. var paused = false;
  61354. stream.on('end', function () {
  61355. debug('wrapped end');
  61356. if (state.decoder && !state.ended) {
  61357. var chunk = state.decoder.end();
  61358. if (chunk && chunk.length) _this.push(chunk);
  61359. }
  61360. _this.push(null);
  61361. });
  61362. stream.on('data', function (chunk) {
  61363. debug('wrapped data');
  61364. if (state.decoder) chunk = state.decoder.write(chunk); // don't skip over falsy values in objectMode
  61365. if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
  61366. var ret = _this.push(chunk);
  61367. if (!ret) {
  61368. paused = true;
  61369. stream.pause();
  61370. }
  61371. }); // proxy all the other methods.
  61372. // important when wrapping filters and duplexes.
  61373. for (var i in stream) {
  61374. if (this[i] === undefined && typeof stream[i] === 'function') {
  61375. this[i] = function (method) {
  61376. return function () {
  61377. return stream[method].apply(stream, arguments);
  61378. };
  61379. }(i);
  61380. }
  61381. } // proxy certain important events.
  61382. for (var n = 0; n < kProxyEvents.length; n++) {
  61383. stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
  61384. } // when we try to consume some more bytes, simply unpause the
  61385. // underlying stream.
  61386. this._read = function (n) {
  61387. debug('wrapped _read', n);
  61388. if (paused) {
  61389. paused = false;
  61390. stream.resume();
  61391. }
  61392. };
  61393. return this;
  61394. };
  61395. Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
  61396. // making it explicit this property is not enumerable
  61397. // because otherwise some prototype manipulation in
  61398. // userland will fail
  61399. enumerable: false,
  61400. get: function get() {
  61401. return this._readableState.highWaterMark;
  61402. }
  61403. }); // exposed for testing purposes only.
  61404. Readable._fromList = fromList; // Pluck off n bytes from an array of buffers.
  61405. // Length is the combined lengths of all the buffers in the list.
  61406. // This function is designed to be inlinable, so please take care when making
  61407. // changes to the function body.
  61408. function fromList(n, state) {
  61409. // nothing buffered
  61410. if (state.length === 0) return null;
  61411. var ret;
  61412. if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
  61413. // read it all, truncate the list
  61414. 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);
  61415. state.buffer.clear();
  61416. } else {
  61417. // read part of list
  61418. ret = fromListPartial(n, state.buffer, state.decoder);
  61419. }
  61420. return ret;
  61421. } // Extracts only enough buffered data to satisfy the amount requested.
  61422. // This function is designed to be inlinable, so please take care when making
  61423. // changes to the function body.
  61424. function fromListPartial(n, list, hasStrings) {
  61425. var ret;
  61426. if (n < list.head.data.length) {
  61427. // slice is the same for buffers and strings
  61428. ret = list.head.data.slice(0, n);
  61429. list.head.data = list.head.data.slice(n);
  61430. } else if (n === list.head.data.length) {
  61431. // first chunk is a perfect match
  61432. ret = list.shift();
  61433. } else {
  61434. // result spans more than one buffer
  61435. ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
  61436. }
  61437. return ret;
  61438. } // Copies a specified amount of characters from the list of buffered data
  61439. // chunks.
  61440. // This function is designed to be inlinable, so please take care when making
  61441. // changes to the function body.
  61442. function copyFromBufferString(n, list) {
  61443. var p = list.head;
  61444. var c = 1;
  61445. var ret = p.data;
  61446. n -= ret.length;
  61447. while (p = p.next) {
  61448. var str = p.data;
  61449. var nb = n > str.length ? str.length : n;
  61450. if (nb === str.length) ret += str;else ret += str.slice(0, n);
  61451. n -= nb;
  61452. if (n === 0) {
  61453. if (nb === str.length) {
  61454. ++c;
  61455. if (p.next) list.head = p.next;else list.head = list.tail = null;
  61456. } else {
  61457. list.head = p;
  61458. p.data = str.slice(nb);
  61459. }
  61460. break;
  61461. }
  61462. ++c;
  61463. }
  61464. list.length -= c;
  61465. return ret;
  61466. } // Copies a specified amount of bytes from the list of buffered data chunks.
  61467. // This function is designed to be inlinable, so please take care when making
  61468. // changes to the function body.
  61469. function copyFromBuffer(n, list) {
  61470. var ret = Buffer.allocUnsafe(n);
  61471. var p = list.head;
  61472. var c = 1;
  61473. p.data.copy(ret);
  61474. n -= p.data.length;
  61475. while (p = p.next) {
  61476. var buf = p.data;
  61477. var nb = n > buf.length ? buf.length : n;
  61478. buf.copy(ret, ret.length - n, 0, nb);
  61479. n -= nb;
  61480. if (n === 0) {
  61481. if (nb === buf.length) {
  61482. ++c;
  61483. if (p.next) list.head = p.next;else list.head = list.tail = null;
  61484. } else {
  61485. list.head = p;
  61486. p.data = buf.slice(nb);
  61487. }
  61488. break;
  61489. }
  61490. ++c;
  61491. }
  61492. list.length -= c;
  61493. return ret;
  61494. }
  61495. function endReadable(stream) {
  61496. var state = stream._readableState; // If we get here before consuming all the bytes, then that is a
  61497. // bug in node. Should never happen.
  61498. if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
  61499. if (!state.endEmitted) {
  61500. state.ended = true;
  61501. pna.nextTick(endReadableNT, state, stream);
  61502. }
  61503. }
  61504. function endReadableNT(state, stream) {
  61505. // Check that we didn't get one last unshift.
  61506. if (!state.endEmitted && state.length === 0) {
  61507. state.endEmitted = true;
  61508. stream.readable = false;
  61509. stream.emit('end');
  61510. }
  61511. }
  61512. function indexOf(xs, x) {
  61513. for (var i = 0, l = xs.length; i < l; i++) {
  61514. if (xs[i] === x) return i;
  61515. }
  61516. return -1;
  61517. }
  61518. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  61519. },{"./_stream_duplex":398,"./internal/streams/BufferList":403,"./internal/streams/destroy":404,"./internal/streams/stream":405,"_process":358,"core-util-is":219,"events":258,"inherits":278,"isarray":280,"process-nextick-args":357,"safe-buffer":384,"string_decoder/":410,"util":185}],401:[function(require,module,exports){
  61520. // Copyright Joyent, Inc. and other Node contributors.
  61521. //
  61522. // Permission is hereby granted, free of charge, to any person obtaining a
  61523. // copy of this software and associated documentation files (the
  61524. // "Software"), to deal in the Software without restriction, including
  61525. // without limitation the rights to use, copy, modify, merge, publish,
  61526. // distribute, sublicense, and/or sell copies of the Software, and to permit
  61527. // persons to whom the Software is furnished to do so, subject to the
  61528. // following conditions:
  61529. //
  61530. // The above copyright notice and this permission notice shall be included
  61531. // in all copies or substantial portions of the Software.
  61532. //
  61533. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  61534. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  61535. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  61536. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  61537. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  61538. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  61539. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  61540. // a transform stream is a readable/writable stream where you do
  61541. // something with the data. Sometimes it's called a "filter",
  61542. // but that's not a great name for it, since that implies a thing where
  61543. // some bits pass through, and others are simply ignored. (That would
  61544. // be a valid example of a transform, of course.)
  61545. //
  61546. // While the output is causally related to the input, it's not a
  61547. // necessarily symmetric or synchronous transformation. For example,
  61548. // a zlib stream might take multiple plain-text writes(), and then
  61549. // emit a single compressed chunk some time in the future.
  61550. //
  61551. // Here's how this works:
  61552. //
  61553. // The Transform stream has all the aspects of the readable and writable
  61554. // stream classes. When you write(chunk), that calls _write(chunk,cb)
  61555. // internally, and returns false if there's a lot of pending writes
  61556. // buffered up. When you call read(), that calls _read(n) until
  61557. // there's enough pending readable data buffered up.
  61558. //
  61559. // In a transform stream, the written data is placed in a buffer. When
  61560. // _read(n) is called, it transforms the queued up data, calling the
  61561. // buffered _write cb's as it consumes chunks. If consuming a single
  61562. // written chunk would result in multiple output chunks, then the first
  61563. // outputted bit calls the readcb, and subsequent chunks just go into
  61564. // the read buffer, and will cause it to emit 'readable' if necessary.
  61565. //
  61566. // This way, back-pressure is actually determined by the reading side,
  61567. // since _read has to be called to start processing a new chunk. However,
  61568. // a pathological inflate type of transform can cause excessive buffering
  61569. // here. For example, imagine a stream where every byte of input is
  61570. // interpreted as an integer from 0-255, and then results in that many
  61571. // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
  61572. // 1kb of data being output. In this case, you could write a very small
  61573. // amount of input, and end up with a very large amount of output. In
  61574. // such a pathological inflating mechanism, there'd be no way to tell
  61575. // the system to stop doing the transform. A single 4MB write could
  61576. // cause the system to run out of memory.
  61577. //
  61578. // However, even in such a pathological case, only a single written chunk
  61579. // would be consumed, and then the rest would wait (un-transformed) until
  61580. // the results of the previous transformed chunk were consumed.
  61581. 'use strict';
  61582. module.exports = Transform;
  61583. var Duplex = require('./_stream_duplex');
  61584. /*<replacement>*/
  61585. var util = Object.create(require('core-util-is'));
  61586. util.inherits = require('inherits');
  61587. /*</replacement>*/
  61588. util.inherits(Transform, Duplex);
  61589. function afterTransform(er, data) {
  61590. var ts = this._transformState;
  61591. ts.transforming = false;
  61592. var cb = ts.writecb;
  61593. if (!cb) {
  61594. return this.emit('error', new Error('write callback called multiple times'));
  61595. }
  61596. ts.writechunk = null;
  61597. ts.writecb = null;
  61598. if (data != null) // single equals check for both `null` and `undefined`
  61599. this.push(data);
  61600. cb(er);
  61601. var rs = this._readableState;
  61602. rs.reading = false;
  61603. if (rs.needReadable || rs.length < rs.highWaterMark) {
  61604. this._read(rs.highWaterMark);
  61605. }
  61606. }
  61607. function Transform(options) {
  61608. if (!(this instanceof Transform)) return new Transform(options);
  61609. Duplex.call(this, options);
  61610. this._transformState = {
  61611. afterTransform: afterTransform.bind(this),
  61612. needTransform: false,
  61613. transforming: false,
  61614. writecb: null,
  61615. writechunk: null,
  61616. writeencoding: null
  61617. }; // start out asking for a readable event once data is transformed.
  61618. this._readableState.needReadable = true; // we have implemented the _read method, and done the other things
  61619. // that Readable wants before the first _read call, so unset the
  61620. // sync guard flag.
  61621. this._readableState.sync = false;
  61622. if (options) {
  61623. if (typeof options.transform === 'function') this._transform = options.transform;
  61624. if (typeof options.flush === 'function') this._flush = options.flush;
  61625. } // When the writable side finishes, then flush out anything remaining.
  61626. this.on('prefinish', prefinish);
  61627. }
  61628. function prefinish() {
  61629. var _this = this;
  61630. if (typeof this._flush === 'function') {
  61631. this._flush(function (er, data) {
  61632. done(_this, er, data);
  61633. });
  61634. } else {
  61635. done(this, null, null);
  61636. }
  61637. }
  61638. Transform.prototype.push = function (chunk, encoding) {
  61639. this._transformState.needTransform = false;
  61640. return Duplex.prototype.push.call(this, chunk, encoding);
  61641. }; // This is the part where you do stuff!
  61642. // override this function in implementation classes.
  61643. // 'chunk' is an input chunk.
  61644. //
  61645. // Call `push(newChunk)` to pass along transformed output
  61646. // to the readable side. You may call 'push' zero or more times.
  61647. //
  61648. // Call `cb(err)` when you are done with this chunk. If you pass
  61649. // an error, then that'll put the hurt on the whole operation. If you
  61650. // never call cb(), then you'll never get another chunk.
  61651. Transform.prototype._transform = function (chunk, encoding, cb) {
  61652. throw new Error('_transform() is not implemented');
  61653. };
  61654. Transform.prototype._write = function (chunk, encoding, cb) {
  61655. var ts = this._transformState;
  61656. ts.writecb = cb;
  61657. ts.writechunk = chunk;
  61658. ts.writeencoding = encoding;
  61659. if (!ts.transforming) {
  61660. var rs = this._readableState;
  61661. if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
  61662. }
  61663. }; // Doesn't matter what the args are here.
  61664. // _transform does all the work.
  61665. // That we got here means that the readable side wants more data.
  61666. Transform.prototype._read = function (n) {
  61667. var ts = this._transformState;
  61668. if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
  61669. ts.transforming = true;
  61670. this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
  61671. } else {
  61672. // mark that we need a transform, so that any data that comes in
  61673. // will get processed, now that we've asked for it.
  61674. ts.needTransform = true;
  61675. }
  61676. };
  61677. Transform.prototype._destroy = function (err, cb) {
  61678. var _this2 = this;
  61679. Duplex.prototype._destroy.call(this, err, function (err2) {
  61680. cb(err2);
  61681. _this2.emit('close');
  61682. });
  61683. };
  61684. function done(stream, er, data) {
  61685. if (er) return stream.emit('error', er);
  61686. if (data != null) // single equals check for both `null` and `undefined`
  61687. stream.push(data); // if there's nothing in the write buffer, then that means
  61688. // that nothing more will ever be provided
  61689. if (stream._writableState.length) throw new Error('Calling transform done when ws.length != 0');
  61690. if (stream._transformState.transforming) throw new Error('Calling transform done when still transforming');
  61691. return stream.push(null);
  61692. }
  61693. },{"./_stream_duplex":398,"core-util-is":219,"inherits":278}],402:[function(require,module,exports){
  61694. (function (process,global,setImmediate){
  61695. // Copyright Joyent, Inc. and other Node contributors.
  61696. //
  61697. // Permission is hereby granted, free of charge, to any person obtaining a
  61698. // copy of this software and associated documentation files (the
  61699. // "Software"), to deal in the Software without restriction, including
  61700. // without limitation the rights to use, copy, modify, merge, publish,
  61701. // distribute, sublicense, and/or sell copies of the Software, and to permit
  61702. // persons to whom the Software is furnished to do so, subject to the
  61703. // following conditions:
  61704. //
  61705. // The above copyright notice and this permission notice shall be included
  61706. // in all copies or substantial portions of the Software.
  61707. //
  61708. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  61709. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  61710. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  61711. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  61712. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  61713. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  61714. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  61715. // A bit simpler than readable streams.
  61716. // Implement an async ._write(chunk, encoding, cb), and it'll handle all
  61717. // the drain event emission and buffering.
  61718. 'use strict';
  61719. /*<replacement>*/
  61720. var pna = require('process-nextick-args');
  61721. /*</replacement>*/
  61722. module.exports = Writable;
  61723. /* <replacement> */
  61724. function WriteReq(chunk, encoding, cb) {
  61725. this.chunk = chunk;
  61726. this.encoding = encoding;
  61727. this.callback = cb;
  61728. this.next = null;
  61729. } // It seems a linked list but it is not
  61730. // there will be only 2 of these for each stream
  61731. function CorkedRequest(state) {
  61732. var _this = this;
  61733. this.next = null;
  61734. this.entry = null;
  61735. this.finish = function () {
  61736. onCorkedFinish(_this, state);
  61737. };
  61738. }
  61739. /* </replacement> */
  61740. /*<replacement>*/
  61741. var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : pna.nextTick;
  61742. /*</replacement>*/
  61743. /*<replacement>*/
  61744. var Duplex;
  61745. /*</replacement>*/
  61746. Writable.WritableState = WritableState;
  61747. /*<replacement>*/
  61748. var util = Object.create(require('core-util-is'));
  61749. util.inherits = require('inherits');
  61750. /*</replacement>*/
  61751. /*<replacement>*/
  61752. var internalUtil = {
  61753. deprecate: require('util-deprecate')
  61754. };
  61755. /*</replacement>*/
  61756. /*<replacement>*/
  61757. var Stream = require('./internal/streams/stream');
  61758. /*</replacement>*/
  61759. /*<replacement>*/
  61760. var Buffer = require('safe-buffer').Buffer;
  61761. var OurUint8Array = global.Uint8Array || function () {};
  61762. function _uint8ArrayToBuffer(chunk) {
  61763. return Buffer.from(chunk);
  61764. }
  61765. function _isUint8Array(obj) {
  61766. return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
  61767. }
  61768. /*</replacement>*/
  61769. var destroyImpl = require('./internal/streams/destroy');
  61770. util.inherits(Writable, Stream);
  61771. function nop() {}
  61772. function WritableState(options, stream) {
  61773. Duplex = Duplex || require('./_stream_duplex');
  61774. options = options || {}; // Duplex streams are both readable and writable, but share
  61775. // the same options object.
  61776. // However, some cases require setting options to different
  61777. // values for the readable and the writable sides of the duplex stream.
  61778. // These options can be provided separately as readableXXX and writableXXX.
  61779. var isDuplex = stream instanceof Duplex; // object stream flag to indicate whether or not this stream
  61780. // contains buffers or objects.
  61781. this.objectMode = !!options.objectMode;
  61782. if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode; // the point at which write() starts returning false
  61783. // Note: 0 is a valid value, means that we always return false if
  61784. // the entire buffer is not flushed immediately on write()
  61785. var hwm = options.highWaterMark;
  61786. var writableHwm = options.writableHighWaterMark;
  61787. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  61788. if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (writableHwm || writableHwm === 0)) this.highWaterMark = writableHwm;else this.highWaterMark = defaultHwm; // cast to ints.
  61789. this.highWaterMark = Math.floor(this.highWaterMark); // if _final has been called
  61790. this.finalCalled = false; // drain event flag.
  61791. this.needDrain = false; // at the start of calling end()
  61792. this.ending = false; // when end() has been called, and returned
  61793. this.ended = false; // when 'finish' is emitted
  61794. this.finished = false; // has it been destroyed
  61795. this.destroyed = false; // should we decode strings into buffers before passing to _write?
  61796. // this is here so that some node-core streams can optimize string
  61797. // handling at a lower level.
  61798. var noDecode = options.decodeStrings === false;
  61799. this.decodeStrings = !noDecode; // Crypto is kind of old and crusty. Historically, its default string
  61800. // encoding is 'binary' so we have to make this configurable.
  61801. // Everything else in the universe uses 'utf8', though.
  61802. this.defaultEncoding = options.defaultEncoding || 'utf8'; // not an actual buffer we keep track of, but a measurement
  61803. // of how much we're waiting to get pushed to some underlying
  61804. // socket or file.
  61805. this.length = 0; // a flag to see when we're in the middle of a write.
  61806. this.writing = false; // when true all writes will be buffered until .uncork() call
  61807. this.corked = 0; // a flag to be able to tell if the onwrite cb is called immediately,
  61808. // or on a later tick. We set this to true at first, because any
  61809. // actions that shouldn't happen until "later" should generally also
  61810. // not happen before the first write call.
  61811. this.sync = true; // a flag to know if we're processing previously buffered items, which
  61812. // may call the _write() callback in the same tick, so that we don't
  61813. // end up in an overlapped onwrite situation.
  61814. this.bufferProcessing = false; // the callback that's passed to _write(chunk,cb)
  61815. this.onwrite = function (er) {
  61816. onwrite(stream, er);
  61817. }; // the callback that the user supplies to write(chunk,encoding,cb)
  61818. this.writecb = null; // the amount that is being written when _write is called.
  61819. this.writelen = 0;
  61820. this.bufferedRequest = null;
  61821. this.lastBufferedRequest = null; // number of pending user-supplied write callbacks
  61822. // this must be 0 before 'finish' can be emitted
  61823. this.pendingcb = 0; // emit prefinish if the only thing we're waiting for is _write cbs
  61824. // This is relevant for synchronous Transform streams
  61825. this.prefinished = false; // True if the error was already emitted and should not be thrown again
  61826. this.errorEmitted = false; // count buffered requests
  61827. this.bufferedRequestCount = 0; // allocate the first CorkedRequest, there is always
  61828. // one allocated and free to use, and we maintain at most two
  61829. this.corkedRequestsFree = new CorkedRequest(this);
  61830. }
  61831. WritableState.prototype.getBuffer = function getBuffer() {
  61832. var current = this.bufferedRequest;
  61833. var out = [];
  61834. while (current) {
  61835. out.push(current);
  61836. current = current.next;
  61837. }
  61838. return out;
  61839. };
  61840. (function () {
  61841. try {
  61842. Object.defineProperty(WritableState.prototype, 'buffer', {
  61843. get: internalUtil.deprecate(function () {
  61844. return this.getBuffer();
  61845. }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
  61846. });
  61847. } catch (_) {}
  61848. })(); // Test _writableState for inheritance to account for Duplex streams,
  61849. // whose prototype chain only points to Readable.
  61850. var realHasInstance;
  61851. if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
  61852. realHasInstance = Function.prototype[Symbol.hasInstance];
  61853. Object.defineProperty(Writable, Symbol.hasInstance, {
  61854. value: function value(object) {
  61855. if (realHasInstance.call(this, object)) return true;
  61856. if (this !== Writable) return false;
  61857. return object && object._writableState instanceof WritableState;
  61858. }
  61859. });
  61860. } else {
  61861. realHasInstance = function realHasInstance(object) {
  61862. return object instanceof this;
  61863. };
  61864. }
  61865. function Writable(options) {
  61866. Duplex = Duplex || require('./_stream_duplex'); // Writable ctor is applied to Duplexes, too.
  61867. // `realHasInstance` is necessary because using plain `instanceof`
  61868. // would return false, as no `_writableState` property is attached.
  61869. // Trying to use the custom `instanceof` for Writable here will also break the
  61870. // Node.js LazyTransform implementation, which has a non-trivial getter for
  61871. // `_writableState` that would lead to infinite recursion.
  61872. if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) {
  61873. return new Writable(options);
  61874. }
  61875. this._writableState = new WritableState(options, this); // legacy.
  61876. this.writable = true;
  61877. if (options) {
  61878. if (typeof options.write === 'function') this._write = options.write;
  61879. if (typeof options.writev === 'function') this._writev = options.writev;
  61880. if (typeof options.destroy === 'function') this._destroy = options.destroy;
  61881. if (typeof options.final === 'function') this._final = options.final;
  61882. }
  61883. Stream.call(this);
  61884. } // Otherwise people can pipe Writable streams, which is just wrong.
  61885. Writable.prototype.pipe = function () {
  61886. this.emit('error', new Error('Cannot pipe, not readable'));
  61887. };
  61888. function writeAfterEnd(stream, cb) {
  61889. var er = new Error('write after end'); // TODO: defer error events consistently everywhere, not just the cb
  61890. stream.emit('error', er);
  61891. pna.nextTick(cb, er);
  61892. } // Checks that a user-supplied chunk is valid, especially for the particular
  61893. // mode the stream is in. Currently this means that `null` is never accepted
  61894. // and undefined/non-string values are only allowed in object mode.
  61895. function validChunk(stream, state, chunk, cb) {
  61896. var valid = true;
  61897. var er = false;
  61898. if (chunk === null) {
  61899. er = new TypeError('May not write null values to stream');
  61900. } else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
  61901. er = new TypeError('Invalid non-string/buffer chunk');
  61902. }
  61903. if (er) {
  61904. stream.emit('error', er);
  61905. pna.nextTick(cb, er);
  61906. valid = false;
  61907. }
  61908. return valid;
  61909. }
  61910. Writable.prototype.write = function (chunk, encoding, cb) {
  61911. var state = this._writableState;
  61912. var ret = false;
  61913. var isBuf = !state.objectMode && _isUint8Array(chunk);
  61914. if (isBuf && !Buffer.isBuffer(chunk)) {
  61915. chunk = _uint8ArrayToBuffer(chunk);
  61916. }
  61917. if (typeof encoding === 'function') {
  61918. cb = encoding;
  61919. encoding = null;
  61920. }
  61921. if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
  61922. if (typeof cb !== 'function') cb = nop;
  61923. if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
  61924. state.pendingcb++;
  61925. ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
  61926. }
  61927. return ret;
  61928. };
  61929. Writable.prototype.cork = function () {
  61930. var state = this._writableState;
  61931. state.corked++;
  61932. };
  61933. Writable.prototype.uncork = function () {
  61934. var state = this._writableState;
  61935. if (state.corked) {
  61936. state.corked--;
  61937. if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
  61938. }
  61939. };
  61940. Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
  61941. // node::ParseEncoding() requires lower case.
  61942. if (typeof encoding === 'string') encoding = encoding.toLowerCase();
  61943. 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);
  61944. this._writableState.defaultEncoding = encoding;
  61945. return this;
  61946. };
  61947. function decodeChunk(state, chunk, encoding) {
  61948. if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
  61949. chunk = Buffer.from(chunk, encoding);
  61950. }
  61951. return chunk;
  61952. }
  61953. Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
  61954. // making it explicit this property is not enumerable
  61955. // because otherwise some prototype manipulation in
  61956. // userland will fail
  61957. enumerable: false,
  61958. get: function get() {
  61959. return this._writableState.highWaterMark;
  61960. }
  61961. }); // if we're already writing something, then just put this
  61962. // in the queue, and wait our turn. Otherwise, call _write
  61963. // If we return false, then we need a drain event, so set that flag.
  61964. function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
  61965. if (!isBuf) {
  61966. var newChunk = decodeChunk(state, chunk, encoding);
  61967. if (chunk !== newChunk) {
  61968. isBuf = true;
  61969. encoding = 'buffer';
  61970. chunk = newChunk;
  61971. }
  61972. }
  61973. var len = state.objectMode ? 1 : chunk.length;
  61974. state.length += len;
  61975. var ret = state.length < state.highWaterMark; // we must ensure that previous needDrain will not be reset to false.
  61976. if (!ret) state.needDrain = true;
  61977. if (state.writing || state.corked) {
  61978. var last = state.lastBufferedRequest;
  61979. state.lastBufferedRequest = {
  61980. chunk: chunk,
  61981. encoding: encoding,
  61982. isBuf: isBuf,
  61983. callback: cb,
  61984. next: null
  61985. };
  61986. if (last) {
  61987. last.next = state.lastBufferedRequest;
  61988. } else {
  61989. state.bufferedRequest = state.lastBufferedRequest;
  61990. }
  61991. state.bufferedRequestCount += 1;
  61992. } else {
  61993. doWrite(stream, state, false, len, chunk, encoding, cb);
  61994. }
  61995. return ret;
  61996. }
  61997. function doWrite(stream, state, writev, len, chunk, encoding, cb) {
  61998. state.writelen = len;
  61999. state.writecb = cb;
  62000. state.writing = true;
  62001. state.sync = true;
  62002. if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
  62003. state.sync = false;
  62004. }
  62005. function onwriteError(stream, state, sync, er, cb) {
  62006. --state.pendingcb;
  62007. if (sync) {
  62008. // defer the callback if we are being called synchronously
  62009. // to avoid piling up things on the stack
  62010. pna.nextTick(cb, er); // this can emit finish, and it will always happen
  62011. // after error
  62012. pna.nextTick(finishMaybe, stream, state);
  62013. stream._writableState.errorEmitted = true;
  62014. stream.emit('error', er);
  62015. } else {
  62016. // the caller expect this to happen before if
  62017. // it is async
  62018. cb(er);
  62019. stream._writableState.errorEmitted = true;
  62020. stream.emit('error', er); // this can emit finish, but finish must
  62021. // always follow error
  62022. finishMaybe(stream, state);
  62023. }
  62024. }
  62025. function onwriteStateUpdate(state) {
  62026. state.writing = false;
  62027. state.writecb = null;
  62028. state.length -= state.writelen;
  62029. state.writelen = 0;
  62030. }
  62031. function onwrite(stream, er) {
  62032. var state = stream._writableState;
  62033. var sync = state.sync;
  62034. var cb = state.writecb;
  62035. onwriteStateUpdate(state);
  62036. if (er) onwriteError(stream, state, sync, er, cb);else {
  62037. // Check if we're actually ready to finish, but don't emit yet
  62038. var finished = needFinish(state);
  62039. if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
  62040. clearBuffer(stream, state);
  62041. }
  62042. if (sync) {
  62043. /*<replacement>*/
  62044. asyncWrite(afterWrite, stream, state, finished, cb);
  62045. /*</replacement>*/
  62046. } else {
  62047. afterWrite(stream, state, finished, cb);
  62048. }
  62049. }
  62050. }
  62051. function afterWrite(stream, state, finished, cb) {
  62052. if (!finished) onwriteDrain(stream, state);
  62053. state.pendingcb--;
  62054. cb();
  62055. finishMaybe(stream, state);
  62056. } // Must force callback to be called on nextTick, so that we don't
  62057. // emit 'drain' before the write() consumer gets the 'false' return
  62058. // value, and has a chance to attach a 'drain' listener.
  62059. function onwriteDrain(stream, state) {
  62060. if (state.length === 0 && state.needDrain) {
  62061. state.needDrain = false;
  62062. stream.emit('drain');
  62063. }
  62064. } // if there's something in the buffer waiting, then process it
  62065. function clearBuffer(stream, state) {
  62066. state.bufferProcessing = true;
  62067. var entry = state.bufferedRequest;
  62068. if (stream._writev && entry && entry.next) {
  62069. // Fast case, write everything using _writev()
  62070. var l = state.bufferedRequestCount;
  62071. var buffer = new Array(l);
  62072. var holder = state.corkedRequestsFree;
  62073. holder.entry = entry;
  62074. var count = 0;
  62075. var allBuffers = true;
  62076. while (entry) {
  62077. buffer[count] = entry;
  62078. if (!entry.isBuf) allBuffers = false;
  62079. entry = entry.next;
  62080. count += 1;
  62081. }
  62082. buffer.allBuffers = allBuffers;
  62083. doWrite(stream, state, true, state.length, buffer, '', holder.finish); // doWrite is almost always async, defer these to save a bit of time
  62084. // as the hot path ends with doWrite
  62085. state.pendingcb++;
  62086. state.lastBufferedRequest = null;
  62087. if (holder.next) {
  62088. state.corkedRequestsFree = holder.next;
  62089. holder.next = null;
  62090. } else {
  62091. state.corkedRequestsFree = new CorkedRequest(state);
  62092. }
  62093. state.bufferedRequestCount = 0;
  62094. } else {
  62095. // Slow case, write chunks one-by-one
  62096. while (entry) {
  62097. var chunk = entry.chunk;
  62098. var encoding = entry.encoding;
  62099. var cb = entry.callback;
  62100. var len = state.objectMode ? 1 : chunk.length;
  62101. doWrite(stream, state, false, len, chunk, encoding, cb);
  62102. entry = entry.next;
  62103. state.bufferedRequestCount--; // if we didn't call the onwrite immediately, then
  62104. // it means that we need to wait until it does.
  62105. // also, that means that the chunk and cb are currently
  62106. // being processed, so move the buffer counter past them.
  62107. if (state.writing) {
  62108. break;
  62109. }
  62110. }
  62111. if (entry === null) state.lastBufferedRequest = null;
  62112. }
  62113. state.bufferedRequest = entry;
  62114. state.bufferProcessing = false;
  62115. }
  62116. Writable.prototype._write = function (chunk, encoding, cb) {
  62117. cb(new Error('_write() is not implemented'));
  62118. };
  62119. Writable.prototype._writev = null;
  62120. Writable.prototype.end = function (chunk, encoding, cb) {
  62121. var state = this._writableState;
  62122. if (typeof chunk === 'function') {
  62123. cb = chunk;
  62124. chunk = null;
  62125. encoding = null;
  62126. } else if (typeof encoding === 'function') {
  62127. cb = encoding;
  62128. encoding = null;
  62129. }
  62130. if (chunk !== null && chunk !== undefined) this.write(chunk, encoding); // .end() fully uncorks
  62131. if (state.corked) {
  62132. state.corked = 1;
  62133. this.uncork();
  62134. } // ignore unnecessary end() calls.
  62135. if (!state.ending && !state.finished) endWritable(this, state, cb);
  62136. };
  62137. function needFinish(state) {
  62138. return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
  62139. }
  62140. function callFinal(stream, state) {
  62141. stream._final(function (err) {
  62142. state.pendingcb--;
  62143. if (err) {
  62144. stream.emit('error', err);
  62145. }
  62146. state.prefinished = true;
  62147. stream.emit('prefinish');
  62148. finishMaybe(stream, state);
  62149. });
  62150. }
  62151. function prefinish(stream, state) {
  62152. if (!state.prefinished && !state.finalCalled) {
  62153. if (typeof stream._final === 'function') {
  62154. state.pendingcb++;
  62155. state.finalCalled = true;
  62156. pna.nextTick(callFinal, stream, state);
  62157. } else {
  62158. state.prefinished = true;
  62159. stream.emit('prefinish');
  62160. }
  62161. }
  62162. }
  62163. function finishMaybe(stream, state) {
  62164. var need = needFinish(state);
  62165. if (need) {
  62166. prefinish(stream, state);
  62167. if (state.pendingcb === 0) {
  62168. state.finished = true;
  62169. stream.emit('finish');
  62170. }
  62171. }
  62172. return need;
  62173. }
  62174. function endWritable(stream, state, cb) {
  62175. state.ending = true;
  62176. finishMaybe(stream, state);
  62177. if (cb) {
  62178. if (state.finished) pna.nextTick(cb);else stream.once('finish', cb);
  62179. }
  62180. state.ended = true;
  62181. stream.writable = false;
  62182. }
  62183. function onCorkedFinish(corkReq, state, err) {
  62184. var entry = corkReq.entry;
  62185. corkReq.entry = null;
  62186. while (entry) {
  62187. var cb = entry.callback;
  62188. state.pendingcb--;
  62189. cb(err);
  62190. entry = entry.next;
  62191. }
  62192. if (state.corkedRequestsFree) {
  62193. state.corkedRequestsFree.next = corkReq;
  62194. } else {
  62195. state.corkedRequestsFree = corkReq;
  62196. }
  62197. }
  62198. Object.defineProperty(Writable.prototype, 'destroyed', {
  62199. get: function get() {
  62200. if (this._writableState === undefined) {
  62201. return false;
  62202. }
  62203. return this._writableState.destroyed;
  62204. },
  62205. set: function set(value) {
  62206. // we ignore the value if the stream
  62207. // has not been initialized yet
  62208. if (!this._writableState) {
  62209. return;
  62210. } // backward compatibility, the user is explicitly
  62211. // managing destroyed
  62212. this._writableState.destroyed = value;
  62213. }
  62214. });
  62215. Writable.prototype.destroy = destroyImpl.destroy;
  62216. Writable.prototype._undestroy = destroyImpl.undestroy;
  62217. Writable.prototype._destroy = function (err, cb) {
  62218. this.end();
  62219. cb(err);
  62220. };
  62221. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("timers").setImmediate)
  62222. },{"./_stream_duplex":398,"./internal/streams/destroy":404,"./internal/streams/stream":405,"_process":358,"core-util-is":219,"inherits":278,"process-nextick-args":357,"safe-buffer":384,"timers":411,"util-deprecate":412}],403:[function(require,module,exports){
  62223. 'use strict';
  62224. function _classCallCheck(instance, Constructor) {
  62225. if (!(instance instanceof Constructor)) {
  62226. throw new TypeError("Cannot call a class as a function");
  62227. }
  62228. }
  62229. var Buffer = require('safe-buffer').Buffer;
  62230. var util = require('util');
  62231. function copyBuffer(src, target, offset) {
  62232. src.copy(target, offset);
  62233. }
  62234. module.exports = function () {
  62235. function BufferList() {
  62236. _classCallCheck(this, BufferList);
  62237. this.head = null;
  62238. this.tail = null;
  62239. this.length = 0;
  62240. }
  62241. BufferList.prototype.push = function push(v) {
  62242. var entry = {
  62243. data: v,
  62244. next: null
  62245. };
  62246. if (this.length > 0) this.tail.next = entry;else this.head = entry;
  62247. this.tail = entry;
  62248. ++this.length;
  62249. };
  62250. BufferList.prototype.unshift = function unshift(v) {
  62251. var entry = {
  62252. data: v,
  62253. next: this.head
  62254. };
  62255. if (this.length === 0) this.tail = entry;
  62256. this.head = entry;
  62257. ++this.length;
  62258. };
  62259. BufferList.prototype.shift = function shift() {
  62260. if (this.length === 0) return;
  62261. var ret = this.head.data;
  62262. if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
  62263. --this.length;
  62264. return ret;
  62265. };
  62266. BufferList.prototype.clear = function clear() {
  62267. this.head = this.tail = null;
  62268. this.length = 0;
  62269. };
  62270. BufferList.prototype.join = function join(s) {
  62271. if (this.length === 0) return '';
  62272. var p = this.head;
  62273. var ret = '' + p.data;
  62274. while (p = p.next) {
  62275. ret += s + p.data;
  62276. }
  62277. return ret;
  62278. };
  62279. BufferList.prototype.concat = function concat(n) {
  62280. if (this.length === 0) return Buffer.alloc(0);
  62281. if (this.length === 1) return this.head.data;
  62282. var ret = Buffer.allocUnsafe(n >>> 0);
  62283. var p = this.head;
  62284. var i = 0;
  62285. while (p) {
  62286. copyBuffer(p.data, ret, i);
  62287. i += p.data.length;
  62288. p = p.next;
  62289. }
  62290. return ret;
  62291. };
  62292. return BufferList;
  62293. }();
  62294. if (util && util.inspect && util.inspect.custom) {
  62295. module.exports.prototype[util.inspect.custom] = function () {
  62296. var obj = util.inspect({
  62297. length: this.length
  62298. });
  62299. return this.constructor.name + ' ' + obj;
  62300. };
  62301. }
  62302. },{"safe-buffer":384,"util":185}],404:[function(require,module,exports){
  62303. 'use strict';
  62304. /*<replacement>*/
  62305. var pna = require('process-nextick-args');
  62306. /*</replacement>*/
  62307. // undocumented cb() API, needed for core, not for public API
  62308. function destroy(err, cb) {
  62309. var _this = this;
  62310. var readableDestroyed = this._readableState && this._readableState.destroyed;
  62311. var writableDestroyed = this._writableState && this._writableState.destroyed;
  62312. if (readableDestroyed || writableDestroyed) {
  62313. if (cb) {
  62314. cb(err);
  62315. } else if (err && (!this._writableState || !this._writableState.errorEmitted)) {
  62316. pna.nextTick(emitErrorNT, this, err);
  62317. }
  62318. return this;
  62319. } // we set destroyed to true before firing error callbacks in order
  62320. // to make it re-entrance safe in case destroy() is called within callbacks
  62321. if (this._readableState) {
  62322. this._readableState.destroyed = true;
  62323. } // if this is a duplex stream mark the writable part as destroyed as well
  62324. if (this._writableState) {
  62325. this._writableState.destroyed = true;
  62326. }
  62327. this._destroy(err || null, function (err) {
  62328. if (!cb && err) {
  62329. pna.nextTick(emitErrorNT, _this, err);
  62330. if (_this._writableState) {
  62331. _this._writableState.errorEmitted = true;
  62332. }
  62333. } else if (cb) {
  62334. cb(err);
  62335. }
  62336. });
  62337. return this;
  62338. }
  62339. function undestroy() {
  62340. if (this._readableState) {
  62341. this._readableState.destroyed = false;
  62342. this._readableState.reading = false;
  62343. this._readableState.ended = false;
  62344. this._readableState.endEmitted = false;
  62345. }
  62346. if (this._writableState) {
  62347. this._writableState.destroyed = false;
  62348. this._writableState.ended = false;
  62349. this._writableState.ending = false;
  62350. this._writableState.finished = false;
  62351. this._writableState.errorEmitted = false;
  62352. }
  62353. }
  62354. function emitErrorNT(self, err) {
  62355. self.emit('error', err);
  62356. }
  62357. module.exports = {
  62358. destroy: destroy,
  62359. undestroy: undestroy
  62360. };
  62361. },{"process-nextick-args":357}],405:[function(require,module,exports){
  62362. arguments[4][381][0].apply(exports,arguments)
  62363. },{"dup":381,"events":258}],406:[function(require,module,exports){
  62364. "use strict";
  62365. module.exports = require('./readable').PassThrough;
  62366. },{"./readable":407}],407:[function(require,module,exports){
  62367. "use strict";
  62368. exports = module.exports = require('./lib/_stream_readable.js');
  62369. exports.Stream = exports;
  62370. exports.Readable = exports;
  62371. exports.Writable = require('./lib/_stream_writable.js');
  62372. exports.Duplex = require('./lib/_stream_duplex.js');
  62373. exports.Transform = require('./lib/_stream_transform.js');
  62374. exports.PassThrough = require('./lib/_stream_passthrough.js');
  62375. },{"./lib/_stream_duplex.js":398,"./lib/_stream_passthrough.js":399,"./lib/_stream_readable.js":400,"./lib/_stream_transform.js":401,"./lib/_stream_writable.js":402}],408:[function(require,module,exports){
  62376. "use strict";
  62377. module.exports = require('./readable').Transform;
  62378. },{"./readable":407}],409:[function(require,module,exports){
  62379. "use strict";
  62380. module.exports = require('./lib/_stream_writable.js');
  62381. },{"./lib/_stream_writable.js":402}],410:[function(require,module,exports){
  62382. // Copyright Joyent, Inc. and other Node contributors.
  62383. //
  62384. // Permission is hereby granted, free of charge, to any person obtaining a
  62385. // copy of this software and associated documentation files (the
  62386. // "Software"), to deal in the Software without restriction, including
  62387. // without limitation the rights to use, copy, modify, merge, publish,
  62388. // distribute, sublicense, and/or sell copies of the Software, and to permit
  62389. // persons to whom the Software is furnished to do so, subject to the
  62390. // following conditions:
  62391. //
  62392. // The above copyright notice and this permission notice shall be included
  62393. // in all copies or substantial portions of the Software.
  62394. //
  62395. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  62396. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  62397. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  62398. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  62399. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  62400. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  62401. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  62402. 'use strict';
  62403. /*<replacement>*/
  62404. var Buffer = require('safe-buffer').Buffer;
  62405. /*</replacement>*/
  62406. var isEncoding = Buffer.isEncoding || function (encoding) {
  62407. encoding = '' + encoding;
  62408. switch (encoding && encoding.toLowerCase()) {
  62409. case 'hex':
  62410. case 'utf8':
  62411. case 'utf-8':
  62412. case 'ascii':
  62413. case 'binary':
  62414. case 'base64':
  62415. case 'ucs2':
  62416. case 'ucs-2':
  62417. case 'utf16le':
  62418. case 'utf-16le':
  62419. case 'raw':
  62420. return true;
  62421. default:
  62422. return false;
  62423. }
  62424. };
  62425. function _normalizeEncoding(enc) {
  62426. if (!enc) return 'utf8';
  62427. var retried;
  62428. while (true) {
  62429. switch (enc) {
  62430. case 'utf8':
  62431. case 'utf-8':
  62432. return 'utf8';
  62433. case 'ucs2':
  62434. case 'ucs-2':
  62435. case 'utf16le':
  62436. case 'utf-16le':
  62437. return 'utf16le';
  62438. case 'latin1':
  62439. case 'binary':
  62440. return 'latin1';
  62441. case 'base64':
  62442. case 'ascii':
  62443. case 'hex':
  62444. return enc;
  62445. default:
  62446. if (retried) return; // undefined
  62447. enc = ('' + enc).toLowerCase();
  62448. retried = true;
  62449. }
  62450. }
  62451. }
  62452. ; // Do not cache `Buffer.isEncoding` when checking encoding names as some
  62453. // modules monkey-patch it to support additional encodings
  62454. function normalizeEncoding(enc) {
  62455. var nenc = _normalizeEncoding(enc);
  62456. if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
  62457. return nenc || enc;
  62458. } // StringDecoder provides an interface for efficiently splitting a series of
  62459. // buffers into a series of JS strings without breaking apart multi-byte
  62460. // characters.
  62461. exports.StringDecoder = StringDecoder;
  62462. function StringDecoder(encoding) {
  62463. this.encoding = normalizeEncoding(encoding);
  62464. var nb;
  62465. switch (this.encoding) {
  62466. case 'utf16le':
  62467. this.text = utf16Text;
  62468. this.end = utf16End;
  62469. nb = 4;
  62470. break;
  62471. case 'utf8':
  62472. this.fillLast = utf8FillLast;
  62473. nb = 4;
  62474. break;
  62475. case 'base64':
  62476. this.text = base64Text;
  62477. this.end = base64End;
  62478. nb = 3;
  62479. break;
  62480. default:
  62481. this.write = simpleWrite;
  62482. this.end = simpleEnd;
  62483. return;
  62484. }
  62485. this.lastNeed = 0;
  62486. this.lastTotal = 0;
  62487. this.lastChar = Buffer.allocUnsafe(nb);
  62488. }
  62489. StringDecoder.prototype.write = function (buf) {
  62490. if (buf.length === 0) return '';
  62491. var r;
  62492. var i;
  62493. if (this.lastNeed) {
  62494. r = this.fillLast(buf);
  62495. if (r === undefined) return '';
  62496. i = this.lastNeed;
  62497. this.lastNeed = 0;
  62498. } else {
  62499. i = 0;
  62500. }
  62501. if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
  62502. return r || '';
  62503. };
  62504. StringDecoder.prototype.end = utf8End; // Returns only complete characters in a Buffer
  62505. StringDecoder.prototype.text = utf8Text; // Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
  62506. StringDecoder.prototype.fillLast = function (buf) {
  62507. if (this.lastNeed <= buf.length) {
  62508. buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
  62509. return this.lastChar.toString(this.encoding, 0, this.lastTotal);
  62510. }
  62511. buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
  62512. this.lastNeed -= buf.length;
  62513. }; // Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
  62514. // continuation byte. If an invalid byte is detected, -2 is returned.
  62515. function utf8CheckByte(byte) {
  62516. 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;
  62517. return byte >> 6 === 0x02 ? -1 : -2;
  62518. } // Checks at most 3 bytes at the end of a Buffer in order to detect an
  62519. // incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4)
  62520. // needed to complete the UTF-8 character (if applicable) are returned.
  62521. function utf8CheckIncomplete(self, buf, i) {
  62522. var j = buf.length - 1;
  62523. if (j < i) return 0;
  62524. var nb = utf8CheckByte(buf[j]);
  62525. if (nb >= 0) {
  62526. if (nb > 0) self.lastNeed = nb - 1;
  62527. return nb;
  62528. }
  62529. if (--j < i || nb === -2) return 0;
  62530. nb = utf8CheckByte(buf[j]);
  62531. if (nb >= 0) {
  62532. if (nb > 0) self.lastNeed = nb - 2;
  62533. return nb;
  62534. }
  62535. if (--j < i || nb === -2) return 0;
  62536. nb = utf8CheckByte(buf[j]);
  62537. if (nb >= 0) {
  62538. if (nb > 0) {
  62539. if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
  62540. }
  62541. return nb;
  62542. }
  62543. return 0;
  62544. } // Validates as many continuation bytes for a multi-byte UTF-8 character as
  62545. // needed or are available. If we see a non-continuation byte where we expect
  62546. // one, we "replace" the validated continuation bytes we've seen so far with
  62547. // a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding
  62548. // behavior. The continuation byte check is included three times in the case
  62549. // where all of the continuation bytes for a character exist in the same buffer.
  62550. // It is also done this way as a slight performance increase instead of using a
  62551. // loop.
  62552. function utf8CheckExtraBytes(self, buf, p) {
  62553. if ((buf[0] & 0xC0) !== 0x80) {
  62554. self.lastNeed = 0;
  62555. return "\uFFFD";
  62556. }
  62557. if (self.lastNeed > 1 && buf.length > 1) {
  62558. if ((buf[1] & 0xC0) !== 0x80) {
  62559. self.lastNeed = 1;
  62560. return "\uFFFD";
  62561. }
  62562. if (self.lastNeed > 2 && buf.length > 2) {
  62563. if ((buf[2] & 0xC0) !== 0x80) {
  62564. self.lastNeed = 2;
  62565. return "\uFFFD";
  62566. }
  62567. }
  62568. }
  62569. } // Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
  62570. function utf8FillLast(buf) {
  62571. var p = this.lastTotal - this.lastNeed;
  62572. var r = utf8CheckExtraBytes(this, buf, p);
  62573. if (r !== undefined) return r;
  62574. if (this.lastNeed <= buf.length) {
  62575. buf.copy(this.lastChar, p, 0, this.lastNeed);
  62576. return this.lastChar.toString(this.encoding, 0, this.lastTotal);
  62577. }
  62578. buf.copy(this.lastChar, p, 0, buf.length);
  62579. this.lastNeed -= buf.length;
  62580. } // Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a
  62581. // partial character, the character's bytes are buffered until the required
  62582. // number of bytes are available.
  62583. function utf8Text(buf, i) {
  62584. var total = utf8CheckIncomplete(this, buf, i);
  62585. if (!this.lastNeed) return buf.toString('utf8', i);
  62586. this.lastTotal = total;
  62587. var end = buf.length - (total - this.lastNeed);
  62588. buf.copy(this.lastChar, 0, end);
  62589. return buf.toString('utf8', i, end);
  62590. } // For UTF-8, a replacement character is added when ending on a partial
  62591. // character.
  62592. function utf8End(buf) {
  62593. var r = buf && buf.length ? this.write(buf) : '';
  62594. if (this.lastNeed) return r + "\uFFFD";
  62595. return r;
  62596. } // UTF-16LE typically needs two bytes per character, but even if we have an even
  62597. // number of bytes available, we need to check if we end on a leading/high
  62598. // surrogate. In that case, we need to wait for the next two bytes in order to
  62599. // decode the last character properly.
  62600. function utf16Text(buf, i) {
  62601. if ((buf.length - i) % 2 === 0) {
  62602. var r = buf.toString('utf16le', i);
  62603. if (r) {
  62604. var c = r.charCodeAt(r.length - 1);
  62605. if (c >= 0xD800 && c <= 0xDBFF) {
  62606. this.lastNeed = 2;
  62607. this.lastTotal = 4;
  62608. this.lastChar[0] = buf[buf.length - 2];
  62609. this.lastChar[1] = buf[buf.length - 1];
  62610. return r.slice(0, -1);
  62611. }
  62612. }
  62613. return r;
  62614. }
  62615. this.lastNeed = 1;
  62616. this.lastTotal = 2;
  62617. this.lastChar[0] = buf[buf.length - 1];
  62618. return buf.toString('utf16le', i, buf.length - 1);
  62619. } // For UTF-16LE we do not explicitly append special replacement characters if we
  62620. // end on a partial character, we simply let v8 handle that.
  62621. function utf16End(buf) {
  62622. var r = buf && buf.length ? this.write(buf) : '';
  62623. if (this.lastNeed) {
  62624. var end = this.lastTotal - this.lastNeed;
  62625. return r + this.lastChar.toString('utf16le', 0, end);
  62626. }
  62627. return r;
  62628. }
  62629. function base64Text(buf, i) {
  62630. var n = (buf.length - i) % 3;
  62631. if (n === 0) return buf.toString('base64', i);
  62632. this.lastNeed = 3 - n;
  62633. this.lastTotal = 3;
  62634. if (n === 1) {
  62635. this.lastChar[0] = buf[buf.length - 1];
  62636. } else {
  62637. this.lastChar[0] = buf[buf.length - 2];
  62638. this.lastChar[1] = buf[buf.length - 1];
  62639. }
  62640. return buf.toString('base64', i, buf.length - n);
  62641. }
  62642. function base64End(buf) {
  62643. var r = buf && buf.length ? this.write(buf) : '';
  62644. if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
  62645. return r;
  62646. } // Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex)
  62647. function simpleWrite(buf) {
  62648. return buf.toString(this.encoding);
  62649. }
  62650. function simpleEnd(buf) {
  62651. return buf && buf.length ? this.write(buf) : '';
  62652. }
  62653. },{"safe-buffer":384}],411:[function(require,module,exports){
  62654. (function (setImmediate,clearImmediate){
  62655. "use strict";
  62656. var nextTick = require('process/browser.js').nextTick;
  62657. var apply = Function.prototype.apply;
  62658. var slice = Array.prototype.slice;
  62659. var immediateIds = {};
  62660. var nextImmediateId = 0; // DOM APIs, for completeness
  62661. exports.setTimeout = function () {
  62662. return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
  62663. };
  62664. exports.setInterval = function () {
  62665. return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
  62666. };
  62667. exports.clearTimeout = exports.clearInterval = function (timeout) {
  62668. timeout.close();
  62669. };
  62670. function Timeout(id, clearFn) {
  62671. this._id = id;
  62672. this._clearFn = clearFn;
  62673. }
  62674. Timeout.prototype.unref = Timeout.prototype.ref = function () {};
  62675. Timeout.prototype.close = function () {
  62676. this._clearFn.call(window, this._id);
  62677. }; // Does not start the time, just sets up the members needed.
  62678. exports.enroll = function (item, msecs) {
  62679. clearTimeout(item._idleTimeoutId);
  62680. item._idleTimeout = msecs;
  62681. };
  62682. exports.unenroll = function (item) {
  62683. clearTimeout(item._idleTimeoutId);
  62684. item._idleTimeout = -1;
  62685. };
  62686. exports._unrefActive = exports.active = function (item) {
  62687. clearTimeout(item._idleTimeoutId);
  62688. var msecs = item._idleTimeout;
  62689. if (msecs >= 0) {
  62690. item._idleTimeoutId = setTimeout(function onTimeout() {
  62691. if (item._onTimeout) item._onTimeout();
  62692. }, msecs);
  62693. }
  62694. }; // That's not how node.js implements it but the exposed api is the same.
  62695. exports.setImmediate = typeof setImmediate === "function" ? setImmediate : function (fn) {
  62696. var id = nextImmediateId++;
  62697. var args = arguments.length < 2 ? false : slice.call(arguments, 1);
  62698. immediateIds[id] = true;
  62699. nextTick(function onNextTick() {
  62700. if (immediateIds[id]) {
  62701. // fn.call() is faster so we optimize for the common use-case
  62702. // @see http://jsperf.com/call-apply-segu
  62703. if (args) {
  62704. fn.apply(null, args);
  62705. } else {
  62706. fn.call(null);
  62707. } // Prevent ids from leaking
  62708. exports.clearImmediate(id);
  62709. }
  62710. });
  62711. return id;
  62712. };
  62713. exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate : function (id) {
  62714. delete immediateIds[id];
  62715. };
  62716. }).call(this,require("timers").setImmediate,require("timers").clearImmediate)
  62717. },{"process/browser.js":358,"timers":411}],412:[function(require,module,exports){
  62718. (function (global){
  62719. "use strict";
  62720. /**
  62721. * Module exports.
  62722. */
  62723. module.exports = deprecate;
  62724. /**
  62725. * Mark that a method should not be used.
  62726. * Returns a modified function which warns once by default.
  62727. *
  62728. * If `localStorage.noDeprecation = true` is set, then it is a no-op.
  62729. *
  62730. * If `localStorage.throwDeprecation = true` is set, then deprecated functions
  62731. * will throw an Error when invoked.
  62732. *
  62733. * If `localStorage.traceDeprecation = true` is set, then deprecated functions
  62734. * will invoke `console.trace()` instead of `console.error()`.
  62735. *
  62736. * @param {Function} fn - the function to deprecate
  62737. * @param {String} msg - the string to print to the console when `fn` is invoked
  62738. * @returns {Function} a new "deprecated" version of `fn`
  62739. * @api public
  62740. */
  62741. function deprecate(fn, msg) {
  62742. if (config('noDeprecation')) {
  62743. return fn;
  62744. }
  62745. var warned = false;
  62746. function deprecated() {
  62747. if (!warned) {
  62748. if (config('throwDeprecation')) {
  62749. throw new Error(msg);
  62750. } else if (config('traceDeprecation')) {
  62751. console.trace(msg);
  62752. } else {
  62753. console.warn(msg);
  62754. }
  62755. warned = true;
  62756. }
  62757. return fn.apply(this, arguments);
  62758. }
  62759. return deprecated;
  62760. }
  62761. /**
  62762. * Checks `localStorage` for boolean values for the given `name`.
  62763. *
  62764. * @param {String} name
  62765. * @returns {Boolean}
  62766. * @api private
  62767. */
  62768. function config(name) {
  62769. // accessing global.localStorage can trigger a DOMException in sandboxed iframes
  62770. try {
  62771. if (!global.localStorage) return false;
  62772. } catch (_) {
  62773. return false;
  62774. }
  62775. var val = global.localStorage[name];
  62776. if (null == val) return false;
  62777. return String(val).toLowerCase() === 'true';
  62778. }
  62779. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  62780. },{}],413:[function(require,module,exports){
  62781. "use strict";
  62782. if (typeof Object.create === 'function') {
  62783. // implementation from standard node.js 'util' module
  62784. module.exports = function inherits(ctor, superCtor) {
  62785. ctor.super_ = superCtor;
  62786. ctor.prototype = Object.create(superCtor.prototype, {
  62787. constructor: {
  62788. value: ctor,
  62789. enumerable: false,
  62790. writable: true,
  62791. configurable: true
  62792. }
  62793. });
  62794. };
  62795. } else {
  62796. // old school shim for old browsers
  62797. module.exports = function inherits(ctor, superCtor) {
  62798. ctor.super_ = superCtor;
  62799. var TempCtor = function TempCtor() {};
  62800. TempCtor.prototype = superCtor.prototype;
  62801. ctor.prototype = new TempCtor();
  62802. ctor.prototype.constructor = ctor;
  62803. };
  62804. }
  62805. },{}],414:[function(require,module,exports){
  62806. "use strict";
  62807. 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); }
  62808. module.exports = function isBuffer(arg) {
  62809. return arg && _typeof(arg) === 'object' && typeof arg.copy === 'function' && typeof arg.fill === 'function' && typeof arg.readUInt8 === 'function';
  62810. };
  62811. },{}],415:[function(require,module,exports){
  62812. (function (process,global){
  62813. "use strict";
  62814. 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); }
  62815. // Copyright Joyent, Inc. and other Node contributors.
  62816. //
  62817. // Permission is hereby granted, free of charge, to any person obtaining a
  62818. // copy of this software and associated documentation files (the
  62819. // "Software"), to deal in the Software without restriction, including
  62820. // without limitation the rights to use, copy, modify, merge, publish,
  62821. // distribute, sublicense, and/or sell copies of the Software, and to permit
  62822. // persons to whom the Software is furnished to do so, subject to the
  62823. // following conditions:
  62824. //
  62825. // The above copyright notice and this permission notice shall be included
  62826. // in all copies or substantial portions of the Software.
  62827. //
  62828. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  62829. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  62830. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  62831. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  62832. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  62833. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  62834. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  62835. var formatRegExp = /%[sdj%]/g;
  62836. exports.format = function (f) {
  62837. if (!isString(f)) {
  62838. var objects = [];
  62839. for (var i = 0; i < arguments.length; i++) {
  62840. objects.push(inspect(arguments[i]));
  62841. }
  62842. return objects.join(' ');
  62843. }
  62844. var i = 1;
  62845. var args = arguments;
  62846. var len = args.length;
  62847. var str = String(f).replace(formatRegExp, function (x) {
  62848. if (x === '%%') return '%';
  62849. if (i >= len) return x;
  62850. switch (x) {
  62851. case '%s':
  62852. return String(args[i++]);
  62853. case '%d':
  62854. return Number(args[i++]);
  62855. case '%j':
  62856. try {
  62857. return JSON.stringify(args[i++]);
  62858. } catch (_) {
  62859. return '[Circular]';
  62860. }
  62861. default:
  62862. return x;
  62863. }
  62864. });
  62865. for (var x = args[i]; i < len; x = args[++i]) {
  62866. if (isNull(x) || !isObject(x)) {
  62867. str += ' ' + x;
  62868. } else {
  62869. str += ' ' + inspect(x);
  62870. }
  62871. }
  62872. return str;
  62873. }; // Mark that a method should not be used.
  62874. // Returns a modified function which warns once by default.
  62875. // If --no-deprecation is set, then it is a no-op.
  62876. exports.deprecate = function (fn, msg) {
  62877. // Allow for deprecating things in the process of starting up.
  62878. if (isUndefined(global.process)) {
  62879. return function () {
  62880. return exports.deprecate(fn, msg).apply(this, arguments);
  62881. };
  62882. }
  62883. if (process.noDeprecation === true) {
  62884. return fn;
  62885. }
  62886. var warned = false;
  62887. function deprecated() {
  62888. if (!warned) {
  62889. if (process.throwDeprecation) {
  62890. throw new Error(msg);
  62891. } else if (process.traceDeprecation) {
  62892. console.trace(msg);
  62893. } else {
  62894. console.error(msg);
  62895. }
  62896. warned = true;
  62897. }
  62898. return fn.apply(this, arguments);
  62899. }
  62900. return deprecated;
  62901. };
  62902. var debugs = {};
  62903. var debugEnviron;
  62904. exports.debuglog = function (set) {
  62905. if (isUndefined(debugEnviron)) debugEnviron = process.env.NODE_DEBUG || '';
  62906. set = set.toUpperCase();
  62907. if (!debugs[set]) {
  62908. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  62909. var pid = process.pid;
  62910. debugs[set] = function () {
  62911. var msg = exports.format.apply(exports, arguments);
  62912. console.error('%s %d: %s', set, pid, msg);
  62913. };
  62914. } else {
  62915. debugs[set] = function () {};
  62916. }
  62917. }
  62918. return debugs[set];
  62919. };
  62920. /**
  62921. * Echos the value of a value. Trys to print the value out
  62922. * in the best way possible given the different types.
  62923. *
  62924. * @param {Object} obj The object to print out.
  62925. * @param {Object} opts Optional options object that alters the output.
  62926. */
  62927. /* legacy: obj, showHidden, depth, colors*/
  62928. function inspect(obj, opts) {
  62929. // default options
  62930. var ctx = {
  62931. seen: [],
  62932. stylize: stylizeNoColor
  62933. }; // legacy...
  62934. if (arguments.length >= 3) ctx.depth = arguments[2];
  62935. if (arguments.length >= 4) ctx.colors = arguments[3];
  62936. if (isBoolean(opts)) {
  62937. // legacy...
  62938. ctx.showHidden = opts;
  62939. } else if (opts) {
  62940. // got an "options" object
  62941. exports._extend(ctx, opts);
  62942. } // set default options
  62943. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  62944. if (isUndefined(ctx.depth)) ctx.depth = 2;
  62945. if (isUndefined(ctx.colors)) ctx.colors = false;
  62946. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  62947. if (ctx.colors) ctx.stylize = stylizeWithColor;
  62948. return formatValue(ctx, obj, ctx.depth);
  62949. }
  62950. exports.inspect = inspect; // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  62951. inspect.colors = {
  62952. 'bold': [1, 22],
  62953. 'italic': [3, 23],
  62954. 'underline': [4, 24],
  62955. 'inverse': [7, 27],
  62956. 'white': [37, 39],
  62957. 'grey': [90, 39],
  62958. 'black': [30, 39],
  62959. 'blue': [34, 39],
  62960. 'cyan': [36, 39],
  62961. 'green': [32, 39],
  62962. 'magenta': [35, 39],
  62963. 'red': [31, 39],
  62964. 'yellow': [33, 39]
  62965. }; // Don't use 'blue' not visible on cmd.exe
  62966. inspect.styles = {
  62967. 'special': 'cyan',
  62968. 'number': 'yellow',
  62969. 'boolean': 'yellow',
  62970. 'undefined': 'grey',
  62971. 'null': 'bold',
  62972. 'string': 'green',
  62973. 'date': 'magenta',
  62974. // "name": intentionally not styling
  62975. 'regexp': 'red'
  62976. };
  62977. function stylizeWithColor(str, styleType) {
  62978. var style = inspect.styles[styleType];
  62979. if (style) {
  62980. return "\x1B[" + inspect.colors[style][0] + 'm' + str + "\x1B[" + inspect.colors[style][1] + 'm';
  62981. } else {
  62982. return str;
  62983. }
  62984. }
  62985. function stylizeNoColor(str, styleType) {
  62986. return str;
  62987. }
  62988. function arrayToHash(array) {
  62989. var hash = {};
  62990. array.forEach(function (val, idx) {
  62991. hash[val] = true;
  62992. });
  62993. return hash;
  62994. }
  62995. function formatValue(ctx, value, recurseTimes) {
  62996. // Provide a hook for user-specified inspect functions.
  62997. // Check that value is an object with an inspect function on it
  62998. if (ctx.customInspect && value && isFunction(value.inspect) && // Filter out the util module, it's inspect function is special
  62999. value.inspect !== exports.inspect && // Also filter out any prototype objects using the circular check.
  63000. !(value.constructor && value.constructor.prototype === value)) {
  63001. var ret = value.inspect(recurseTimes, ctx);
  63002. if (!isString(ret)) {
  63003. ret = formatValue(ctx, ret, recurseTimes);
  63004. }
  63005. return ret;
  63006. } // Primitive types cannot have properties
  63007. var primitive = formatPrimitive(ctx, value);
  63008. if (primitive) {
  63009. return primitive;
  63010. } // Look up the keys of the object.
  63011. var keys = Object.keys(value);
  63012. var visibleKeys = arrayToHash(keys);
  63013. if (ctx.showHidden) {
  63014. keys = Object.getOwnPropertyNames(value);
  63015. } // IE doesn't make error fields non-enumerable
  63016. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  63017. if (isError(value) && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  63018. return formatError(value);
  63019. } // Some type of object without properties can be shortcutted.
  63020. if (keys.length === 0) {
  63021. if (isFunction(value)) {
  63022. var name = value.name ? ': ' + value.name : '';
  63023. return ctx.stylize('[Function' + name + ']', 'special');
  63024. }
  63025. if (isRegExp(value)) {
  63026. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  63027. }
  63028. if (isDate(value)) {
  63029. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  63030. }
  63031. if (isError(value)) {
  63032. return formatError(value);
  63033. }
  63034. }
  63035. var base = '',
  63036. array = false,
  63037. braces = ['{', '}']; // Make Array say that they are Array
  63038. if (isArray(value)) {
  63039. array = true;
  63040. braces = ['[', ']'];
  63041. } // Make functions say that they are functions
  63042. if (isFunction(value)) {
  63043. var n = value.name ? ': ' + value.name : '';
  63044. base = ' [Function' + n + ']';
  63045. } // Make RegExps say that they are RegExps
  63046. if (isRegExp(value)) {
  63047. base = ' ' + RegExp.prototype.toString.call(value);
  63048. } // Make dates with properties first say the date
  63049. if (isDate(value)) {
  63050. base = ' ' + Date.prototype.toUTCString.call(value);
  63051. } // Make error with message first say the error
  63052. if (isError(value)) {
  63053. base = ' ' + formatError(value);
  63054. }
  63055. if (keys.length === 0 && (!array || value.length == 0)) {
  63056. return braces[0] + base + braces[1];
  63057. }
  63058. if (recurseTimes < 0) {
  63059. if (isRegExp(value)) {
  63060. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  63061. } else {
  63062. return ctx.stylize('[Object]', 'special');
  63063. }
  63064. }
  63065. ctx.seen.push(value);
  63066. var output;
  63067. if (array) {
  63068. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  63069. } else {
  63070. output = keys.map(function (key) {
  63071. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  63072. });
  63073. }
  63074. ctx.seen.pop();
  63075. return reduceToSingleString(output, base, braces);
  63076. }
  63077. function formatPrimitive(ctx, value) {
  63078. if (isUndefined(value)) return ctx.stylize('undefined', 'undefined');
  63079. if (isString(value)) {
  63080. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '').replace(/'/g, "\\'").replace(/\\"/g, '"') + '\'';
  63081. return ctx.stylize(simple, 'string');
  63082. }
  63083. if (isNumber(value)) return ctx.stylize('' + value, 'number');
  63084. if (isBoolean(value)) return ctx.stylize('' + value, 'boolean'); // For some reason typeof null is "object", so special case here.
  63085. if (isNull(value)) return ctx.stylize('null', 'null');
  63086. }
  63087. function formatError(value) {
  63088. return '[' + Error.prototype.toString.call(value) + ']';
  63089. }
  63090. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  63091. var output = [];
  63092. for (var i = 0, l = value.length; i < l; ++i) {
  63093. if (hasOwnProperty(value, String(i))) {
  63094. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, String(i), true));
  63095. } else {
  63096. output.push('');
  63097. }
  63098. }
  63099. keys.forEach(function (key) {
  63100. if (!key.match(/^\d+$/)) {
  63101. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, key, true));
  63102. }
  63103. });
  63104. return output;
  63105. }
  63106. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  63107. var name, str, desc;
  63108. desc = Object.getOwnPropertyDescriptor(value, key) || {
  63109. value: value[key]
  63110. };
  63111. if (desc.get) {
  63112. if (desc.set) {
  63113. str = ctx.stylize('[Getter/Setter]', 'special');
  63114. } else {
  63115. str = ctx.stylize('[Getter]', 'special');
  63116. }
  63117. } else {
  63118. if (desc.set) {
  63119. str = ctx.stylize('[Setter]', 'special');
  63120. }
  63121. }
  63122. if (!hasOwnProperty(visibleKeys, key)) {
  63123. name = '[' + key + ']';
  63124. }
  63125. if (!str) {
  63126. if (ctx.seen.indexOf(desc.value) < 0) {
  63127. if (isNull(recurseTimes)) {
  63128. str = formatValue(ctx, desc.value, null);
  63129. } else {
  63130. str = formatValue(ctx, desc.value, recurseTimes - 1);
  63131. }
  63132. if (str.indexOf('\n') > -1) {
  63133. if (array) {
  63134. str = str.split('\n').map(function (line) {
  63135. return ' ' + line;
  63136. }).join('\n').substr(2);
  63137. } else {
  63138. str = '\n' + str.split('\n').map(function (line) {
  63139. return ' ' + line;
  63140. }).join('\n');
  63141. }
  63142. }
  63143. } else {
  63144. str = ctx.stylize('[Circular]', 'special');
  63145. }
  63146. }
  63147. if (isUndefined(name)) {
  63148. if (array && key.match(/^\d+$/)) {
  63149. return str;
  63150. }
  63151. name = JSON.stringify('' + key);
  63152. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  63153. name = name.substr(1, name.length - 2);
  63154. name = ctx.stylize(name, 'name');
  63155. } else {
  63156. name = name.replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'");
  63157. name = ctx.stylize(name, 'string');
  63158. }
  63159. }
  63160. return name + ': ' + str;
  63161. }
  63162. function reduceToSingleString(output, base, braces) {
  63163. var numLinesEst = 0;
  63164. var length = output.reduce(function (prev, cur) {
  63165. numLinesEst++;
  63166. if (cur.indexOf('\n') >= 0) numLinesEst++;
  63167. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  63168. }, 0);
  63169. if (length > 60) {
  63170. return braces[0] + (base === '' ? '' : base + '\n ') + ' ' + output.join(',\n ') + ' ' + braces[1];
  63171. }
  63172. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  63173. } // NOTE: These type checking functions intentionally don't use `instanceof`
  63174. // because it is fragile and can be easily faked with `Object.create()`.
  63175. function isArray(ar) {
  63176. return Array.isArray(ar);
  63177. }
  63178. exports.isArray = isArray;
  63179. function isBoolean(arg) {
  63180. return typeof arg === 'boolean';
  63181. }
  63182. exports.isBoolean = isBoolean;
  63183. function isNull(arg) {
  63184. return arg === null;
  63185. }
  63186. exports.isNull = isNull;
  63187. function isNullOrUndefined(arg) {
  63188. return arg == null;
  63189. }
  63190. exports.isNullOrUndefined = isNullOrUndefined;
  63191. function isNumber(arg) {
  63192. return typeof arg === 'number';
  63193. }
  63194. exports.isNumber = isNumber;
  63195. function isString(arg) {
  63196. return typeof arg === 'string';
  63197. }
  63198. exports.isString = isString;
  63199. function isSymbol(arg) {
  63200. return _typeof(arg) === 'symbol';
  63201. }
  63202. exports.isSymbol = isSymbol;
  63203. function isUndefined(arg) {
  63204. return arg === void 0;
  63205. }
  63206. exports.isUndefined = isUndefined;
  63207. function isRegExp(re) {
  63208. return isObject(re) && objectToString(re) === '[object RegExp]';
  63209. }
  63210. exports.isRegExp = isRegExp;
  63211. function isObject(arg) {
  63212. return _typeof(arg) === 'object' && arg !== null;
  63213. }
  63214. exports.isObject = isObject;
  63215. function isDate(d) {
  63216. return isObject(d) && objectToString(d) === '[object Date]';
  63217. }
  63218. exports.isDate = isDate;
  63219. function isError(e) {
  63220. return isObject(e) && (objectToString(e) === '[object Error]' || e instanceof Error);
  63221. }
  63222. exports.isError = isError;
  63223. function isFunction(arg) {
  63224. return typeof arg === 'function';
  63225. }
  63226. exports.isFunction = isFunction;
  63227. function isPrimitive(arg) {
  63228. return arg === null || typeof arg === 'boolean' || typeof arg === 'number' || typeof arg === 'string' || _typeof(arg) === 'symbol' || // ES6 symbol
  63229. typeof arg === 'undefined';
  63230. }
  63231. exports.isPrimitive = isPrimitive;
  63232. exports.isBuffer = require('./support/isBuffer');
  63233. function objectToString(o) {
  63234. return Object.prototype.toString.call(o);
  63235. }
  63236. function pad(n) {
  63237. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  63238. }
  63239. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; // 26 Feb 16:19:34
  63240. function timestamp() {
  63241. var d = new Date();
  63242. var time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(':');
  63243. return [d.getDate(), months[d.getMonth()], time].join(' ');
  63244. } // log is just a thin wrapper to console.log that prepends a timestamp
  63245. exports.log = function () {
  63246. console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
  63247. };
  63248. /**
  63249. * Inherit the prototype methods from one constructor into another.
  63250. *
  63251. * The Function.prototype.inherits from lang.js rewritten as a standalone
  63252. * function (not on Function.prototype). NOTE: If this file is to be loaded
  63253. * during bootstrapping this function needs to be rewritten using some native
  63254. * functions as prototype setup using normal JavaScript does not work as
  63255. * expected during bootstrapping (see mirror.js in r114903).
  63256. *
  63257. * @param {function} ctor Constructor function which needs to inherit the
  63258. * prototype.
  63259. * @param {function} superCtor Constructor function to inherit prototype from.
  63260. */
  63261. exports.inherits = require('inherits');
  63262. exports._extend = function (origin, add) {
  63263. // Don't do anything if add isn't an object
  63264. if (!add || !isObject(add)) return origin;
  63265. var keys = Object.keys(add);
  63266. var i = keys.length;
  63267. while (i--) {
  63268. origin[keys[i]] = add[keys[i]];
  63269. }
  63270. return origin;
  63271. };
  63272. function hasOwnProperty(obj, prop) {
  63273. return Object.prototype.hasOwnProperty.call(obj, prop);
  63274. }
  63275. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  63276. },{"./support/isBuffer":414,"_process":358,"inherits":413}],416:[function(require,module,exports){
  63277. "use strict";
  63278. Object.defineProperty(exports, "__esModule", {
  63279. value: true
  63280. });
  63281. Object.defineProperty(exports, "v1", {
  63282. enumerable: true,
  63283. get: function get() {
  63284. return _v.default;
  63285. }
  63286. });
  63287. Object.defineProperty(exports, "v3", {
  63288. enumerable: true,
  63289. get: function get() {
  63290. return _v2.default;
  63291. }
  63292. });
  63293. Object.defineProperty(exports, "v4", {
  63294. enumerable: true,
  63295. get: function get() {
  63296. return _v3.default;
  63297. }
  63298. });
  63299. Object.defineProperty(exports, "v5", {
  63300. enumerable: true,
  63301. get: function get() {
  63302. return _v4.default;
  63303. }
  63304. });
  63305. Object.defineProperty(exports, "NIL", {
  63306. enumerable: true,
  63307. get: function get() {
  63308. return _nil.default;
  63309. }
  63310. });
  63311. Object.defineProperty(exports, "version", {
  63312. enumerable: true,
  63313. get: function get() {
  63314. return _version.default;
  63315. }
  63316. });
  63317. Object.defineProperty(exports, "validate", {
  63318. enumerable: true,
  63319. get: function get() {
  63320. return _validate.default;
  63321. }
  63322. });
  63323. Object.defineProperty(exports, "stringify", {
  63324. enumerable: true,
  63325. get: function get() {
  63326. return _stringify.default;
  63327. }
  63328. });
  63329. Object.defineProperty(exports, "parse", {
  63330. enumerable: true,
  63331. get: function get() {
  63332. return _parse.default;
  63333. }
  63334. });
  63335. var _v = _interopRequireDefault(require("./v1.js"));
  63336. var _v2 = _interopRequireDefault(require("./v3.js"));
  63337. var _v3 = _interopRequireDefault(require("./v4.js"));
  63338. var _v4 = _interopRequireDefault(require("./v5.js"));
  63339. var _nil = _interopRequireDefault(require("./nil.js"));
  63340. var _version = _interopRequireDefault(require("./version.js"));
  63341. var _validate = _interopRequireDefault(require("./validate.js"));
  63342. var _stringify = _interopRequireDefault(require("./stringify.js"));
  63343. var _parse = _interopRequireDefault(require("./parse.js"));
  63344. function _interopRequireDefault(obj) {
  63345. return obj && obj.__esModule ? obj : {
  63346. default: obj
  63347. };
  63348. }
  63349. },{"./nil.js":418,"./parse.js":419,"./stringify.js":423,"./v1.js":424,"./v3.js":425,"./v4.js":427,"./v5.js":428,"./validate.js":429,"./version.js":430}],417:[function(require,module,exports){
  63350. "use strict";
  63351. Object.defineProperty(exports, "__esModule", {
  63352. value: true
  63353. });
  63354. exports.default = void 0;
  63355. /*
  63356. * Browser-compatible JavaScript MD5
  63357. *
  63358. * Modification of JavaScript MD5
  63359. * https://github.com/blueimp/JavaScript-MD5
  63360. *
  63361. * Copyright 2011, Sebastian Tschan
  63362. * https://blueimp.net
  63363. *
  63364. * Licensed under the MIT license:
  63365. * https://opensource.org/licenses/MIT
  63366. *
  63367. * Based on
  63368. * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
  63369. * Digest Algorithm, as defined in RFC 1321.
  63370. * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
  63371. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  63372. * Distributed under the BSD License
  63373. * See http://pajhome.org.uk/crypt/md5 for more info.
  63374. */
  63375. function md5(bytes) {
  63376. if (typeof bytes === 'string') {
  63377. var msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
  63378. bytes = new Uint8Array(msg.length);
  63379. for (var i = 0; i < msg.length; ++i) {
  63380. bytes[i] = msg.charCodeAt(i);
  63381. }
  63382. }
  63383. return md5ToHexEncodedArray(wordsToMd5(bytesToWords(bytes), bytes.length * 8));
  63384. }
  63385. /*
  63386. * Convert an array of little-endian words to an array of bytes
  63387. */
  63388. function md5ToHexEncodedArray(input) {
  63389. var output = [];
  63390. var length32 = input.length * 32;
  63391. var hexTab = '0123456789abcdef';
  63392. for (var i = 0; i < length32; i += 8) {
  63393. var x = input[i >> 5] >>> i % 32 & 0xff;
  63394. var hex = parseInt(hexTab.charAt(x >>> 4 & 0x0f) + hexTab.charAt(x & 0x0f), 16);
  63395. output.push(hex);
  63396. }
  63397. return output;
  63398. }
  63399. /**
  63400. * Calculate output length with padding and bit length
  63401. */
  63402. function getOutputLength(inputLength8) {
  63403. return (inputLength8 + 64 >>> 9 << 4) + 14 + 1;
  63404. }
  63405. /*
  63406. * Calculate the MD5 of an array of little-endian words, and a bit length.
  63407. */
  63408. function wordsToMd5(x, len) {
  63409. /* append padding */
  63410. x[len >> 5] |= 0x80 << len % 32;
  63411. x[getOutputLength(len) - 1] = len;
  63412. var a = 1732584193;
  63413. var b = -271733879;
  63414. var c = -1732584194;
  63415. var d = 271733878;
  63416. for (var i = 0; i < x.length; i += 16) {
  63417. var olda = a;
  63418. var oldb = b;
  63419. var oldc = c;
  63420. var oldd = d;
  63421. a = md5ff(a, b, c, d, x[i], 7, -680876936);
  63422. d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
  63423. c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
  63424. b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330);
  63425. a = md5ff(a, b, c, d, x[i + 4], 7, -176418897);
  63426. d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426);
  63427. c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341);
  63428. b = md5ff(b, c, d, a, x[i + 7], 22, -45705983);
  63429. a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416);
  63430. d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417);
  63431. c = md5ff(c, d, a, b, x[i + 10], 17, -42063);
  63432. b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162);
  63433. a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682);
  63434. d = md5ff(d, a, b, c, x[i + 13], 12, -40341101);
  63435. c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290);
  63436. b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329);
  63437. a = md5gg(a, b, c, d, x[i + 1], 5, -165796510);
  63438. d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632);
  63439. c = md5gg(c, d, a, b, x[i + 11], 14, 643717713);
  63440. b = md5gg(b, c, d, a, x[i], 20, -373897302);
  63441. a = md5gg(a, b, c, d, x[i + 5], 5, -701558691);
  63442. d = md5gg(d, a, b, c, x[i + 10], 9, 38016083);
  63443. c = md5gg(c, d, a, b, x[i + 15], 14, -660478335);
  63444. b = md5gg(b, c, d, a, x[i + 4], 20, -405537848);
  63445. a = md5gg(a, b, c, d, x[i + 9], 5, 568446438);
  63446. d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690);
  63447. c = md5gg(c, d, a, b, x[i + 3], 14, -187363961);
  63448. b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501);
  63449. a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467);
  63450. d = md5gg(d, a, b, c, x[i + 2], 9, -51403784);
  63451. c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473);
  63452. b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734);
  63453. a = md5hh(a, b, c, d, x[i + 5], 4, -378558);
  63454. d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463);
  63455. c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562);
  63456. b = md5hh(b, c, d, a, x[i + 14], 23, -35309556);
  63457. a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060);
  63458. d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353);
  63459. c = md5hh(c, d, a, b, x[i + 7], 16, -155497632);
  63460. b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640);
  63461. a = md5hh(a, b, c, d, x[i + 13], 4, 681279174);
  63462. d = md5hh(d, a, b, c, x[i], 11, -358537222);
  63463. c = md5hh(c, d, a, b, x[i + 3], 16, -722521979);
  63464. b = md5hh(b, c, d, a, x[i + 6], 23, 76029189);
  63465. a = md5hh(a, b, c, d, x[i + 9], 4, -640364487);
  63466. d = md5hh(d, a, b, c, x[i + 12], 11, -421815835);
  63467. c = md5hh(c, d, a, b, x[i + 15], 16, 530742520);
  63468. b = md5hh(b, c, d, a, x[i + 2], 23, -995338651);
  63469. a = md5ii(a, b, c, d, x[i], 6, -198630844);
  63470. d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415);
  63471. c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905);
  63472. b = md5ii(b, c, d, a, x[i + 5], 21, -57434055);
  63473. a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571);
  63474. d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606);
  63475. c = md5ii(c, d, a, b, x[i + 10], 15, -1051523);
  63476. b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799);
  63477. a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359);
  63478. d = md5ii(d, a, b, c, x[i + 15], 10, -30611744);
  63479. c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380);
  63480. b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649);
  63481. a = md5ii(a, b, c, d, x[i + 4], 6, -145523070);
  63482. d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379);
  63483. c = md5ii(c, d, a, b, x[i + 2], 15, 718787259);
  63484. b = md5ii(b, c, d, a, x[i + 9], 21, -343485551);
  63485. a = safeAdd(a, olda);
  63486. b = safeAdd(b, oldb);
  63487. c = safeAdd(c, oldc);
  63488. d = safeAdd(d, oldd);
  63489. }
  63490. return [a, b, c, d];
  63491. }
  63492. /*
  63493. * Convert an array bytes to an array of little-endian words
  63494. * Characters >255 have their high-byte silently ignored.
  63495. */
  63496. function bytesToWords(input) {
  63497. if (input.length === 0) {
  63498. return [];
  63499. }
  63500. var length8 = input.length * 8;
  63501. var output = new Uint32Array(getOutputLength(length8));
  63502. for (var i = 0; i < length8; i += 8) {
  63503. output[i >> 5] |= (input[i / 8] & 0xff) << i % 32;
  63504. }
  63505. return output;
  63506. }
  63507. /*
  63508. * Add integers, wrapping at 2^32. This uses 16-bit operations internally
  63509. * to work around bugs in some JS interpreters.
  63510. */
  63511. function safeAdd(x, y) {
  63512. var lsw = (x & 0xffff) + (y & 0xffff);
  63513. var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  63514. return msw << 16 | lsw & 0xffff;
  63515. }
  63516. /*
  63517. * Bitwise rotate a 32-bit number to the left.
  63518. */
  63519. function bitRotateLeft(num, cnt) {
  63520. return num << cnt | num >>> 32 - cnt;
  63521. }
  63522. /*
  63523. * These functions implement the four basic operations the algorithm uses.
  63524. */
  63525. function md5cmn(q, a, b, x, s, t) {
  63526. return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b);
  63527. }
  63528. function md5ff(a, b, c, d, x, s, t) {
  63529. return md5cmn(b & c | ~b & d, a, b, x, s, t);
  63530. }
  63531. function md5gg(a, b, c, d, x, s, t) {
  63532. return md5cmn(b & d | c & ~d, a, b, x, s, t);
  63533. }
  63534. function md5hh(a, b, c, d, x, s, t) {
  63535. return md5cmn(b ^ c ^ d, a, b, x, s, t);
  63536. }
  63537. function md5ii(a, b, c, d, x, s, t) {
  63538. return md5cmn(c ^ (b | ~d), a, b, x, s, t);
  63539. }
  63540. var _default = md5;
  63541. exports.default = _default;
  63542. },{}],418:[function(require,module,exports){
  63543. "use strict";
  63544. Object.defineProperty(exports, "__esModule", {
  63545. value: true
  63546. });
  63547. exports.default = void 0;
  63548. var _default = '00000000-0000-0000-0000-000000000000';
  63549. exports.default = _default;
  63550. },{}],419:[function(require,module,exports){
  63551. "use strict";
  63552. Object.defineProperty(exports, "__esModule", {
  63553. value: true
  63554. });
  63555. exports.default = void 0;
  63556. var _validate = _interopRequireDefault(require("./validate.js"));
  63557. function _interopRequireDefault(obj) {
  63558. return obj && obj.__esModule ? obj : {
  63559. default: obj
  63560. };
  63561. }
  63562. function parse(uuid) {
  63563. if (!(0, _validate.default)(uuid)) {
  63564. throw TypeError('Invalid UUID');
  63565. }
  63566. var v;
  63567. var arr = new Uint8Array(16); // Parse ########-....-....-....-............
  63568. arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;
  63569. arr[1] = v >>> 16 & 0xff;
  63570. arr[2] = v >>> 8 & 0xff;
  63571. arr[3] = v & 0xff; // Parse ........-####-....-....-............
  63572. arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8;
  63573. arr[5] = v & 0xff; // Parse ........-....-####-....-............
  63574. arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8;
  63575. arr[7] = v & 0xff; // Parse ........-....-....-####-............
  63576. arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8;
  63577. arr[9] = v & 0xff; // Parse ........-....-....-....-############
  63578. // (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
  63579. arr[10] = (v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000 & 0xff;
  63580. arr[11] = v / 0x100000000 & 0xff;
  63581. arr[12] = v >>> 24 & 0xff;
  63582. arr[13] = v >>> 16 & 0xff;
  63583. arr[14] = v >>> 8 & 0xff;
  63584. arr[15] = v & 0xff;
  63585. return arr;
  63586. }
  63587. var _default = parse;
  63588. exports.default = _default;
  63589. },{"./validate.js":429}],420:[function(require,module,exports){
  63590. "use strict";
  63591. Object.defineProperty(exports, "__esModule", {
  63592. value: true
  63593. });
  63594. exports.default = void 0;
  63595. 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;
  63596. exports.default = _default;
  63597. },{}],421:[function(require,module,exports){
  63598. "use strict";
  63599. Object.defineProperty(exports, "__esModule", {
  63600. value: true
  63601. });
  63602. exports.default = rng; // Unique ID creation requires a high quality random # generator. In the browser we therefore
  63603. // require the crypto API and do not support built-in fallback to lower quality random number
  63604. // generators (like Math.random()).
  63605. // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
  63606. // find the complete implementation of crypto (msCrypto) on IE11.
  63607. var getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
  63608. var rnds8 = new Uint8Array(16);
  63609. function rng() {
  63610. if (!getRandomValues) {
  63611. throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
  63612. }
  63613. return getRandomValues(rnds8);
  63614. }
  63615. },{}],422:[function(require,module,exports){
  63616. "use strict";
  63617. Object.defineProperty(exports, "__esModule", {
  63618. value: true
  63619. });
  63620. exports.default = void 0; // Adapted from Chris Veness' SHA1 code at
  63621. // http://www.movable-type.co.uk/scripts/sha1.html
  63622. function f(s, x, y, z) {
  63623. switch (s) {
  63624. case 0:
  63625. return x & y ^ ~x & z;
  63626. case 1:
  63627. return x ^ y ^ z;
  63628. case 2:
  63629. return x & y ^ x & z ^ y & z;
  63630. case 3:
  63631. return x ^ y ^ z;
  63632. }
  63633. }
  63634. function ROTL(x, n) {
  63635. return x << n | x >>> 32 - n;
  63636. }
  63637. function sha1(bytes) {
  63638. var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
  63639. var H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
  63640. if (typeof bytes === 'string') {
  63641. var msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
  63642. bytes = [];
  63643. for (var i = 0; i < msg.length; ++i) {
  63644. bytes.push(msg.charCodeAt(i));
  63645. }
  63646. } else if (!Array.isArray(bytes)) {
  63647. // Convert Array-like to Array
  63648. bytes = Array.prototype.slice.call(bytes);
  63649. }
  63650. bytes.push(0x80);
  63651. var l = bytes.length / 4 + 2;
  63652. var N = Math.ceil(l / 16);
  63653. var M = new Array(N);
  63654. for (var _i = 0; _i < N; ++_i) {
  63655. var arr = new Uint32Array(16);
  63656. for (var j = 0; j < 16; ++j) {
  63657. 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];
  63658. }
  63659. M[_i] = arr;
  63660. }
  63661. M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32);
  63662. M[N - 1][14] = Math.floor(M[N - 1][14]);
  63663. M[N - 1][15] = (bytes.length - 1) * 8 & 0xffffffff;
  63664. for (var _i2 = 0; _i2 < N; ++_i2) {
  63665. var W = new Uint32Array(80);
  63666. for (var t = 0; t < 16; ++t) {
  63667. W[t] = M[_i2][t];
  63668. }
  63669. for (var _t = 16; _t < 80; ++_t) {
  63670. W[_t] = ROTL(W[_t - 3] ^ W[_t - 8] ^ W[_t - 14] ^ W[_t - 16], 1);
  63671. }
  63672. var a = H[0];
  63673. var b = H[1];
  63674. var c = H[2];
  63675. var d = H[3];
  63676. var e = H[4];
  63677. for (var _t2 = 0; _t2 < 80; ++_t2) {
  63678. var s = Math.floor(_t2 / 20);
  63679. var T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[_t2] >>> 0;
  63680. e = d;
  63681. d = c;
  63682. c = ROTL(b, 30) >>> 0;
  63683. b = a;
  63684. a = T;
  63685. }
  63686. H[0] = H[0] + a >>> 0;
  63687. H[1] = H[1] + b >>> 0;
  63688. H[2] = H[2] + c >>> 0;
  63689. H[3] = H[3] + d >>> 0;
  63690. H[4] = H[4] + e >>> 0;
  63691. }
  63692. 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];
  63693. }
  63694. var _default = sha1;
  63695. exports.default = _default;
  63696. },{}],423:[function(require,module,exports){
  63697. "use strict";
  63698. Object.defineProperty(exports, "__esModule", {
  63699. value: true
  63700. });
  63701. exports.default = void 0;
  63702. var _validate = _interopRequireDefault(require("./validate.js"));
  63703. function _interopRequireDefault(obj) {
  63704. return obj && obj.__esModule ? obj : {
  63705. default: obj
  63706. };
  63707. }
  63708. /**
  63709. * Convert array of 16 byte values to UUID string format of the form:
  63710. * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
  63711. */
  63712. var byteToHex = [];
  63713. for (var i = 0; i < 256; ++i) {
  63714. byteToHex.push((i + 0x100).toString(16).substr(1));
  63715. }
  63716. function stringify(arr) {
  63717. var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  63718. // Note: Be careful editing this code! It's been tuned for performance
  63719. // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
  63720. 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
  63721. // of the following:
  63722. // - One or more input array values don't map to a hex octet (leading to
  63723. // "undefined" in the uuid)
  63724. // - Invalid input values for the RFC `version` or `variant` fields
  63725. if (!(0, _validate.default)(uuid)) {
  63726. throw TypeError('Stringified UUID is invalid');
  63727. }
  63728. return uuid;
  63729. }
  63730. var _default = stringify;
  63731. exports.default = _default;
  63732. },{"./validate.js":429}],424:[function(require,module,exports){
  63733. "use strict";
  63734. Object.defineProperty(exports, "__esModule", {
  63735. value: true
  63736. });
  63737. exports.default = void 0;
  63738. var _rng = _interopRequireDefault(require("./rng.js"));
  63739. var _stringify = _interopRequireDefault(require("./stringify.js"));
  63740. function _interopRequireDefault(obj) {
  63741. return obj && obj.__esModule ? obj : {
  63742. default: obj
  63743. };
  63744. } // **`v1()` - Generate time-based UUID**
  63745. //
  63746. // Inspired by https://github.com/LiosK/UUID.js
  63747. // and http://docs.python.org/library/uuid.html
  63748. var _nodeId;
  63749. var _clockseq; // Previous uuid creation time
  63750. var _lastMSecs = 0;
  63751. var _lastNSecs = 0; // See https://github.com/uuidjs/uuid for API details
  63752. function v1(options, buf, offset) {
  63753. var i = buf && offset || 0;
  63754. var b = buf || new Array(16);
  63755. options = options || {};
  63756. var node = options.node || _nodeId;
  63757. var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq; // node and clockseq need to be initialized to random values if they're not
  63758. // specified. We do this lazily to minimize issues related to insufficient
  63759. // system entropy. See #189
  63760. if (node == null || clockseq == null) {
  63761. var seedBytes = options.random || (options.rng || _rng.default)();
  63762. if (node == null) {
  63763. // Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
  63764. node = _nodeId = [seedBytes[0] | 0x01, seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]];
  63765. }
  63766. if (clockseq == null) {
  63767. // Per 4.2.2, randomize (14 bit) clockseq
  63768. clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 0x3fff;
  63769. }
  63770. } // UUID timestamps are 100 nano-second units since the Gregorian epoch,
  63771. // (1582-10-15 00:00). JSNumbers aren't precise enough for this, so
  63772. // time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'
  63773. // (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.
  63774. var msecs = options.msecs !== undefined ? options.msecs : Date.now(); // Per 4.2.1.2, use count of uuid's generated during the current clock
  63775. // cycle to simulate higher resolution clock
  63776. var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1; // Time since last uuid creation (in msecs)
  63777. var dt = msecs - _lastMSecs + (nsecs - _lastNSecs) / 10000; // Per 4.2.1.2, Bump clockseq on clock regression
  63778. if (dt < 0 && options.clockseq === undefined) {
  63779. clockseq = clockseq + 1 & 0x3fff;
  63780. } // Reset nsecs if clock regresses (new clockseq) or we've moved onto a new
  63781. // time interval
  63782. if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) {
  63783. nsecs = 0;
  63784. } // Per 4.2.1.2 Throw error if too many uuids are requested
  63785. if (nsecs >= 10000) {
  63786. throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");
  63787. }
  63788. _lastMSecs = msecs;
  63789. _lastNSecs = nsecs;
  63790. _clockseq = clockseq; // Per 4.1.4 - Convert from unix epoch to Gregorian epoch
  63791. msecs += 12219292800000; // `time_low`
  63792. var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
  63793. b[i++] = tl >>> 24 & 0xff;
  63794. b[i++] = tl >>> 16 & 0xff;
  63795. b[i++] = tl >>> 8 & 0xff;
  63796. b[i++] = tl & 0xff; // `time_mid`
  63797. var tmh = msecs / 0x100000000 * 10000 & 0xfffffff;
  63798. b[i++] = tmh >>> 8 & 0xff;
  63799. b[i++] = tmh & 0xff; // `time_high_and_version`
  63800. b[i++] = tmh >>> 24 & 0xf | 0x10; // include version
  63801. b[i++] = tmh >>> 16 & 0xff; // `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)
  63802. b[i++] = clockseq >>> 8 | 0x80; // `clock_seq_low`
  63803. b[i++] = clockseq & 0xff; // `node`
  63804. for (var n = 0; n < 6; ++n) {
  63805. b[i + n] = node[n];
  63806. }
  63807. return buf || (0, _stringify.default)(b);
  63808. }
  63809. var _default = v1;
  63810. exports.default = _default;
  63811. },{"./rng.js":421,"./stringify.js":423}],425:[function(require,module,exports){
  63812. "use strict";
  63813. Object.defineProperty(exports, "__esModule", {
  63814. value: true
  63815. });
  63816. exports.default = void 0;
  63817. var _v = _interopRequireDefault(require("./v35.js"));
  63818. var _md = _interopRequireDefault(require("./md5.js"));
  63819. function _interopRequireDefault(obj) {
  63820. return obj && obj.__esModule ? obj : {
  63821. default: obj
  63822. };
  63823. }
  63824. var v3 = (0, _v.default)('v3', 0x30, _md.default);
  63825. var _default = v3;
  63826. exports.default = _default;
  63827. },{"./md5.js":417,"./v35.js":426}],426:[function(require,module,exports){
  63828. "use strict";
  63829. Object.defineProperty(exports, "__esModule", {
  63830. value: true
  63831. });
  63832. exports.default = _default;
  63833. exports.URL = exports.DNS = void 0;
  63834. var _stringify = _interopRequireDefault(require("./stringify.js"));
  63835. var _parse = _interopRequireDefault(require("./parse.js"));
  63836. function _interopRequireDefault(obj) {
  63837. return obj && obj.__esModule ? obj : {
  63838. default: obj
  63839. };
  63840. }
  63841. function stringToBytes(str) {
  63842. str = unescape(encodeURIComponent(str)); // UTF8 escape
  63843. var bytes = [];
  63844. for (var i = 0; i < str.length; ++i) {
  63845. bytes.push(str.charCodeAt(i));
  63846. }
  63847. return bytes;
  63848. }
  63849. var DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
  63850. exports.DNS = DNS;
  63851. var URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
  63852. exports.URL = URL;
  63853. function _default(name, version, hashfunc) {
  63854. function generateUUID(value, namespace, buf, offset) {
  63855. if (typeof value === 'string') {
  63856. value = stringToBytes(value);
  63857. }
  63858. if (typeof namespace === 'string') {
  63859. namespace = (0, _parse.default)(namespace);
  63860. }
  63861. if (namespace.length !== 16) {
  63862. throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');
  63863. } // Compute hash of namespace and value, Per 4.3
  63864. // Future: Use spread syntax when supported on all platforms, e.g. `bytes =
  63865. // hashfunc([...namespace, ... value])`
  63866. var bytes = new Uint8Array(16 + value.length);
  63867. bytes.set(namespace);
  63868. bytes.set(value, namespace.length);
  63869. bytes = hashfunc(bytes);
  63870. bytes[6] = bytes[6] & 0x0f | version;
  63871. bytes[8] = bytes[8] & 0x3f | 0x80;
  63872. if (buf) {
  63873. offset = offset || 0;
  63874. for (var i = 0; i < 16; ++i) {
  63875. buf[offset + i] = bytes[i];
  63876. }
  63877. return buf;
  63878. }
  63879. return (0, _stringify.default)(bytes);
  63880. } // Function#name is not settable on some platforms (#270)
  63881. try {
  63882. generateUUID.name = name; // eslint-disable-next-line no-empty
  63883. } catch (err) {} // For CommonJS default export support
  63884. generateUUID.DNS = DNS;
  63885. generateUUID.URL = URL;
  63886. return generateUUID;
  63887. }
  63888. },{"./parse.js":419,"./stringify.js":423}],427:[function(require,module,exports){
  63889. "use strict";
  63890. Object.defineProperty(exports, "__esModule", {
  63891. value: true
  63892. });
  63893. exports.default = void 0;
  63894. var _rng = _interopRequireDefault(require("./rng.js"));
  63895. var _stringify = _interopRequireDefault(require("./stringify.js"));
  63896. function _interopRequireDefault(obj) {
  63897. return obj && obj.__esModule ? obj : {
  63898. default: obj
  63899. };
  63900. }
  63901. function v4(options, buf, offset) {
  63902. options = options || {};
  63903. var rnds = options.random || (options.rng || _rng.default)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
  63904. rnds[6] = rnds[6] & 0x0f | 0x40;
  63905. rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
  63906. if (buf) {
  63907. offset = offset || 0;
  63908. for (var i = 0; i < 16; ++i) {
  63909. buf[offset + i] = rnds[i];
  63910. }
  63911. return buf;
  63912. }
  63913. return (0, _stringify.default)(rnds);
  63914. }
  63915. var _default = v4;
  63916. exports.default = _default;
  63917. },{"./rng.js":421,"./stringify.js":423}],428:[function(require,module,exports){
  63918. "use strict";
  63919. Object.defineProperty(exports, "__esModule", {
  63920. value: true
  63921. });
  63922. exports.default = void 0;
  63923. var _v = _interopRequireDefault(require("./v35.js"));
  63924. var _sha = _interopRequireDefault(require("./sha1.js"));
  63925. function _interopRequireDefault(obj) {
  63926. return obj && obj.__esModule ? obj : {
  63927. default: obj
  63928. };
  63929. }
  63930. var v5 = (0, _v.default)('v5', 0x50, _sha.default);
  63931. var _default = v5;
  63932. exports.default = _default;
  63933. },{"./sha1.js":422,"./v35.js":426}],429:[function(require,module,exports){
  63934. "use strict";
  63935. Object.defineProperty(exports, "__esModule", {
  63936. value: true
  63937. });
  63938. exports.default = void 0;
  63939. var _regex = _interopRequireDefault(require("./regex.js"));
  63940. function _interopRequireDefault(obj) {
  63941. return obj && obj.__esModule ? obj : {
  63942. default: obj
  63943. };
  63944. }
  63945. function validate(uuid) {
  63946. return typeof uuid === 'string' && _regex.default.test(uuid);
  63947. }
  63948. var _default = validate;
  63949. exports.default = _default;
  63950. },{"./regex.js":420}],430:[function(require,module,exports){
  63951. "use strict";
  63952. Object.defineProperty(exports, "__esModule", {
  63953. value: true
  63954. });
  63955. exports.default = void 0;
  63956. var _validate = _interopRequireDefault(require("./validate.js"));
  63957. function _interopRequireDefault(obj) {
  63958. return obj && obj.__esModule ? obj : {
  63959. default: obj
  63960. };
  63961. }
  63962. function version(uuid) {
  63963. if (!(0, _validate.default)(uuid)) {
  63964. throw TypeError('Invalid UUID');
  63965. }
  63966. return parseInt(uuid.substr(14, 1), 16);
  63967. }
  63968. var _default = version;
  63969. exports.default = _default;
  63970. },{"./validate.js":429}],431:[function(require,module,exports){
  63971. "use strict";
  63972. /**
  63973. * Character classes and associated utilities for the 5th edition of XML 1.0.
  63974. *
  63975. * @author Louis-Dominique Dubeau
  63976. * @license MIT
  63977. * @copyright Louis-Dominique Dubeau
  63978. */
  63979. Object.defineProperty(exports, "__esModule", {
  63980. value: true
  63981. }); //
  63982. // Fragments.
  63983. //
  63984. exports.CHAR = "\t\n\r -\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF";
  63985. exports.S = " \t\r\n"; // tslint:disable-next-line:max-line-length
  63986. 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";
  63987. exports.NAME_CHAR = "-" + exports.NAME_START_CHAR + ".0-9\xB7\u0300-\u036F\u203F-\u2040"; //
  63988. // Regular expressions.
  63989. //
  63990. exports.CHAR_RE = new RegExp("^[" + exports.CHAR + "]$", "u");
  63991. exports.S_RE = new RegExp("^[" + exports.S + "]+$", "u");
  63992. exports.NAME_START_CHAR_RE = new RegExp("^[" + exports.NAME_START_CHAR + "]$", "u");
  63993. exports.NAME_CHAR_RE = new RegExp("^[" + exports.NAME_CHAR + "]$", "u");
  63994. exports.NAME_RE = new RegExp("^[" + exports.NAME_START_CHAR + "][" + exports.NAME_CHAR + "]*$", "u");
  63995. exports.NMTOKEN_RE = new RegExp("^[" + exports.NAME_CHAR + "]+$", "u");
  63996. var TAB = 9;
  63997. var NL = 0xA;
  63998. var CR = 0xD;
  63999. var SPACE = 0x20; //
  64000. // Lists.
  64001. //
  64002. /** All characters in the ``S`` production. */
  64003. exports.S_LIST = [SPACE, NL, CR, TAB];
  64004. /**
  64005. * Determines whether a codepoint matches the ``CHAR`` production.
  64006. *
  64007. * @param c The code point.
  64008. *
  64009. * @returns ``true`` if the codepoint matches ``CHAR``.
  64010. */
  64011. function isChar(c) {
  64012. return c >= SPACE && c <= 0xD7FF || c === NL || c === CR || c === TAB || c >= 0xE000 && c <= 0xFFFD || c >= 0x10000 && c <= 0x10FFFF;
  64013. }
  64014. exports.isChar = isChar;
  64015. /**
  64016. * Determines whether a codepoint matches the ``S`` (space) production.
  64017. *
  64018. * @param c The code point.
  64019. *
  64020. * @returns ``true`` if the codepoint matches ``S``.
  64021. */
  64022. function isS(c) {
  64023. return c === SPACE || c === NL || c === CR || c === TAB;
  64024. }
  64025. exports.isS = isS;
  64026. /**
  64027. * Determines whether a codepoint matches the ``NAME_START_CHAR`` production.
  64028. *
  64029. * @param c The code point.
  64030. *
  64031. * @returns ``true`` if the codepoint matches ``NAME_START_CHAR``.
  64032. */
  64033. function isNameStartChar(c) {
  64034. 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;
  64035. }
  64036. exports.isNameStartChar = isNameStartChar;
  64037. /**
  64038. * Determines whether a codepoint matches the ``NAME_CHAR`` production.
  64039. *
  64040. * @param c The code point.
  64041. *
  64042. * @returns ``true`` if the codepoint matches ``NAME_CHAR``.
  64043. */
  64044. function isNameChar(c) {
  64045. return isNameStartChar(c) || c >= 0x30 && c <= 0x39 || c === 0x2D || c === 0x2E || c === 0xB7 || c >= 0x0300 && c <= 0x036F || c >= 0x203F && c <= 0x2040;
  64046. }
  64047. exports.isNameChar = isNameChar;
  64048. },{}],432:[function(require,module,exports){
  64049. "use strict";
  64050. /**
  64051. * Character classes and associated utilities for the 2nd edition of XML 1.1.
  64052. *
  64053. * @author Louis-Dominique Dubeau
  64054. * @license MIT
  64055. * @copyright Louis-Dominique Dubeau
  64056. */
  64057. Object.defineProperty(exports, "__esModule", {
  64058. value: true
  64059. }); //
  64060. // Fragments.
  64061. //
  64062. exports.CHAR = "\x01-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF";
  64063. exports.RESTRICTED_CHAR = "\x01-\b\x0B\f\x0E-\x1F\x7F-\x84\x86-\x9F";
  64064. exports.S = " \t\r\n"; // tslint:disable-next-line:max-line-length
  64065. 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";
  64066. exports.NAME_CHAR = "-" + exports.NAME_START_CHAR + ".0-9\xB7\u0300-\u036F\u203F-\u2040"; //
  64067. // Regular expressions.
  64068. //
  64069. exports.CHAR_RE = new RegExp("^[" + exports.CHAR + "]$", "u");
  64070. exports.RESTRICTED_CHAR_RE = new RegExp("^[" + exports.RESTRICTED_CHAR + "]$", "u");
  64071. exports.S_RE = new RegExp("^[" + exports.S + "]+$", "u");
  64072. exports.NAME_START_CHAR_RE = new RegExp("^[" + exports.NAME_START_CHAR + "]$", "u");
  64073. exports.NAME_CHAR_RE = new RegExp("^[" + exports.NAME_CHAR + "]$", "u");
  64074. exports.NAME_RE = new RegExp("^[" + exports.NAME_START_CHAR + "][" + exports.NAME_CHAR + "]*$", "u");
  64075. exports.NMTOKEN_RE = new RegExp("^[" + exports.NAME_CHAR + "]+$", "u");
  64076. var TAB = 9;
  64077. var NL = 0xA;
  64078. var CR = 0xD;
  64079. var SPACE = 0x20; //
  64080. // Lists.
  64081. //
  64082. /** All characters in the ``S`` production. */
  64083. exports.S_LIST = [SPACE, NL, CR, TAB];
  64084. /**
  64085. * Determines whether a codepoint matches the ``CHAR`` production.
  64086. *
  64087. * @param c The code point.
  64088. *
  64089. * @returns ``true`` if the codepoint matches ``CHAR``.
  64090. */
  64091. function isChar(c) {
  64092. return c >= 0x0001 && c <= 0xD7FF || c >= 0xE000 && c <= 0xFFFD || c >= 0x10000 && c <= 0x10FFFF;
  64093. }
  64094. exports.isChar = isChar;
  64095. /**
  64096. * Determines whether a codepoint matches the ``RESTRICTED_CHAR`` production.
  64097. *
  64098. * @param c The code point.
  64099. *
  64100. * @returns ``true`` if the codepoint matches ``RESTRICTED_CHAR``.
  64101. */
  64102. function isRestrictedChar(c) {
  64103. return c >= 0x1 && c <= 0x8 || c === 0xB || c === 0xC || c >= 0xE && c <= 0x1F || c >= 0x7F && c <= 0x84 || c >= 0x86 && c <= 0x9F;
  64104. }
  64105. exports.isRestrictedChar = isRestrictedChar;
  64106. /**
  64107. * Determines whether a codepoint matches the ``CHAR`` production and does not
  64108. * match the ``RESTRICTED_CHAR`` production. ``isCharAndNotRestricted(x)`` is
  64109. * equivalent to ``isChar(x) && !isRestrictedChar(x)``. This function is faster
  64110. * than running the two-call equivalent.
  64111. *
  64112. * @param c The code point.
  64113. *
  64114. * @returns ``true`` if the codepoint matches ``CHAR`` and does not match
  64115. * ``RESTRICTED_CHAR``.
  64116. */
  64117. function isCharAndNotRestricted(c) {
  64118. 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;
  64119. }
  64120. exports.isCharAndNotRestricted = isCharAndNotRestricted;
  64121. /**
  64122. * Determines whether a codepoint matches the ``S`` (space) production.
  64123. *
  64124. * @param c The code point.
  64125. *
  64126. * @returns ``true`` if the codepoint matches ``S``.
  64127. */
  64128. function isS(c) {
  64129. return c === SPACE || c === NL || c === CR || c === TAB;
  64130. }
  64131. exports.isS = isS;
  64132. /**
  64133. * Determines whether a codepoint matches the ``NAME_START_CHAR`` production.
  64134. *
  64135. * @param c The code point.
  64136. *
  64137. * @returns ``true`` if the codepoint matches ``NAME_START_CHAR``.
  64138. */
  64139. // tslint:disable-next-line:cyclomatic-complexity
  64140. function isNameStartChar(c) {
  64141. 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;
  64142. }
  64143. exports.isNameStartChar = isNameStartChar;
  64144. /**
  64145. * Determines whether a codepoint matches the ``NAME_CHAR`` production.
  64146. *
  64147. * @param c The code point.
  64148. *
  64149. * @returns ``true`` if the codepoint matches ``NAME_CHAR``.
  64150. */
  64151. function isNameChar(c) {
  64152. return isNameStartChar(c) || c >= 0x30 && c <= 0x39 || c === 0x2D || c === 0x2E || c === 0xB7 || c >= 0x0300 && c <= 0x036F || c >= 0x203F && c <= 0x2040;
  64153. }
  64154. exports.isNameChar = isNameChar;
  64155. },{}],433:[function(require,module,exports){
  64156. "use strict";
  64157. /**
  64158. * Character class utilities for XML NS 1.0 edition 3.
  64159. *
  64160. * @author Louis-Dominique Dubeau
  64161. * @license MIT
  64162. * @copyright Louis-Dominique Dubeau
  64163. */
  64164. Object.defineProperty(exports, "__esModule", {
  64165. value: true
  64166. }); //
  64167. // Fragments.
  64168. //
  64169. // tslint:disable-next-line:max-line-length
  64170. 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";
  64171. exports.NC_NAME_CHAR = "-" + exports.NC_NAME_START_CHAR + ".0-9\xB7\u0300-\u036F\u203F-\u2040"; //
  64172. // Regular expressions.
  64173. //
  64174. exports.NC_NAME_START_CHAR_RE = new RegExp("^[" + exports.NC_NAME_START_CHAR + "]$", "u");
  64175. exports.NC_NAME_CHAR_RE = new RegExp("^[" + exports.NC_NAME_CHAR + "]$", "u");
  64176. exports.NC_NAME_RE = new RegExp("^[" + exports.NC_NAME_START_CHAR + "][" + exports.NC_NAME_CHAR + "]*$", "u");
  64177. /**
  64178. * Determines whether a codepoint matches [[NC_NAME_START_CHAR]].
  64179. *
  64180. * @param c The code point.
  64181. *
  64182. * @returns ``true`` if the codepoint matches.
  64183. */
  64184. // tslint:disable-next-line:cyclomatic-complexity
  64185. function isNCNameStartChar(c) {
  64186. 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;
  64187. }
  64188. exports.isNCNameStartChar = isNCNameStartChar;
  64189. /**
  64190. * Determines whether a codepoint matches [[NC_NAME_CHAR]].
  64191. *
  64192. * @param c The code point.
  64193. *
  64194. * @returns ``true`` if the codepoint matches.
  64195. */
  64196. function isNCNameChar(c) {
  64197. return isNCNameStartChar(c) || c === 0x2D || c === 0x2E || c >= 0x30 && c <= 0x39 || c === 0x00B7 || c >= 0x0300 && c <= 0x036F || c >= 0x203F && c <= 0x2040;
  64198. }
  64199. exports.isNCNameChar = isNCNameChar;
  64200. },{}]},{},[15])(15)
  64201. });
  64202. //# sourceMappingURL=exceljs.bare.js.map