shpjs.js 751 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583
  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.shp = f() } })(function () {
  2. 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 })()({
  3. 1: [function (require, module, exports) {
  4. 'use strict';
  5. const Promise = require('lie');
  6. const combine = require('./combine');
  7. const Buffer = require('buffer').Buffer;
  8. module.exports = binaryAjax;
  9. function binaryAjax(_url, type) {
  10. return new Promise(function (resolve, reject) {
  11. const url = combine(_url, type);
  12. const ajax = new XMLHttpRequest();
  13. ajax.open('GET', url, true);
  14. if (type !== 'prj' && type !== 'cpg') {
  15. ajax.responseType = 'arraybuffer';
  16. }
  17. ajax.addEventListener('load', function () {
  18. if (ajax.status > 399) {
  19. if (type === 'prj' || type === 'cpg') {
  20. return resolve(false);
  21. } else {
  22. return reject(new Error(ajax.status));
  23. }
  24. }
  25. if (type !== 'prj' && type !== 'cpg') {
  26. return resolve(Buffer.from(ajax.response));
  27. } else {
  28. return resolve(ajax.response);
  29. }
  30. }, false);
  31. ajax.send();
  32. });
  33. }
  34. }, { "./combine": 3, "buffer": 8, "lie": 12 }], 2: [function (require, module, exports) {
  35. (function (global) {
  36. (function () {
  37. 'use strict';
  38. const fallback = require('./binaryajax-browser');
  39. const combine = require('./combine');
  40. const Buffer = require('buffer').Buffer;
  41. module.exports = async function binaryAjax(_url, type) {
  42. if (!global.fetch) {
  43. return fallback(_url, type);
  44. }
  45. const url = combine(_url, type);
  46. const isOptionalTxt = type === 'prj' || type === 'cpg';
  47. try {
  48. const resp = await fetch(url);
  49. if (resp.status > 399) {
  50. throw new Error(resp.statusText);
  51. }
  52. if (isOptionalTxt) {
  53. return resp.text();
  54. }
  55. const parsed = await resp.arrayBuffer();
  56. return Buffer.from(parsed);
  57. } catch (e) {
  58. // console.log('ERROR', e, type);
  59. if (isOptionalTxt || type === 'dbf') {
  60. return false;
  61. }
  62. throw e;
  63. }
  64. };
  65. }).call(this)
  66. }).call(this, typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  67. }, { "./binaryajax-browser": 1, "./combine": 3, "buffer": 8 }], 3: [function (require, module, exports) {
  68. (function (global) {
  69. (function () {
  70. const URL = global.URL;
  71. module.exports = (base, type) => {
  72. if (!type) {
  73. return base;
  74. }
  75. const url = new URL(base);
  76. url.pathname = `${url.pathname}.${type}`;
  77. return url.href;
  78. };
  79. }).call(this)
  80. }).call(this, typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  81. }, {}], 4: [function (require, module, exports) {
  82. 'use strict';
  83. function isClockWise(array) {
  84. let sum = 0;
  85. let i = 1;
  86. const len = array.length;
  87. let prev, cur;
  88. while (i < len) {
  89. prev = cur || array[0];
  90. cur = array[i];
  91. sum += ((cur[0] - prev[0]) * (cur[1] + prev[1]));
  92. i++;
  93. }
  94. return sum > 0;
  95. }
  96. function polyReduce(a, b) {
  97. if (isClockWise(b) || !a.length) {
  98. a.push([b]);
  99. } else {
  100. a[a.length - 1].push(b);
  101. }
  102. return a;
  103. }
  104. ParseShp.prototype.parsePoint = function (data) {
  105. return {
  106. type: 'Point',
  107. coordinates: this.parseCoord(data, 0)
  108. };
  109. };
  110. ParseShp.prototype.parseZPoint = function (data) {
  111. const pointXY = this.parsePoint(data);
  112. pointXY.coordinates.push(data.readDoubleLE(16));
  113. return pointXY;
  114. };
  115. ParseShp.prototype.parsePointArray = function (data, offset, num) {
  116. const out = [];
  117. let done = 0;
  118. while (done < num) {
  119. out.push(this.parseCoord(data, offset));
  120. offset += 16;
  121. done++;
  122. }
  123. return out;
  124. };
  125. ParseShp.prototype.parseZPointArray = function (data, zOffset, num, coordinates) {
  126. let i = 0;
  127. while (i < num) {
  128. coordinates[i].push(data.readDoubleLE(zOffset));
  129. i++;
  130. zOffset += 8;
  131. }
  132. return coordinates;
  133. };
  134. ParseShp.prototype.parseArrayGroup = function (data, offset, partOffset, num, tot) {
  135. const out = [];
  136. let done = 0;
  137. let curNum; let nextNum = 0;
  138. let pointNumber;
  139. while (done < num) {
  140. done++;
  141. partOffset += 4;
  142. curNum = nextNum;
  143. if (done === num) {
  144. nextNum = tot;
  145. } else {
  146. nextNum = data.readInt32LE(partOffset);
  147. }
  148. pointNumber = nextNum - curNum;
  149. if (!pointNumber) {
  150. continue;
  151. }
  152. out.push(this.parsePointArray(data, offset, pointNumber));
  153. offset += (pointNumber << 4);
  154. }
  155. return out;
  156. };
  157. ParseShp.prototype.parseZArrayGroup = function (data, zOffset, num, coordinates) {
  158. let i = 0;
  159. while (i < num) {
  160. coordinates[i] = this.parseZPointArray(data, zOffset, coordinates[i].length, coordinates[i]);
  161. zOffset += (coordinates[i].length << 3);
  162. i++;
  163. }
  164. return coordinates;
  165. };
  166. ParseShp.prototype.parseMultiPoint = function (data) {
  167. const out = {};
  168. const num = data.readInt32LE(32, true);
  169. if (!num) {
  170. return null;
  171. }
  172. const mins = this.parseCoord(data, 0);
  173. const maxs = this.parseCoord(data, 16);
  174. out.bbox = [
  175. mins[0],
  176. mins[1],
  177. maxs[0],
  178. maxs[1]
  179. ];
  180. const offset = 36;
  181. if (num === 1) {
  182. out.type = 'Point';
  183. out.coordinates = this.parseCoord(data, offset);
  184. } else {
  185. out.type = 'MultiPoint';
  186. out.coordinates = this.parsePointArray(data, offset, num);
  187. }
  188. return out;
  189. };
  190. ParseShp.prototype.parseZMultiPoint = function (data) {
  191. const geoJson = this.parseMultiPoint(data);
  192. if (!geoJson) {
  193. return null;
  194. }
  195. let num;
  196. if (geoJson.type === 'Point') {
  197. geoJson.coordinates.push(data.readDoubleLE(72));
  198. return geoJson;
  199. } else {
  200. num = geoJson.coordinates.length;
  201. }
  202. const zOffset = 52 + (num << 4);
  203. geoJson.coordinates = this.parseZPointArray(data, zOffset, num, geoJson.coordinates);
  204. return geoJson;
  205. };
  206. ParseShp.prototype.parsePolyline = function (data) {
  207. const out = {};
  208. const numParts = data.readInt32LE(32);
  209. if (!numParts) {
  210. return null;
  211. }
  212. const mins = this.parseCoord(data, 0);
  213. const maxs = this.parseCoord(data, 16);
  214. out.bbox = [
  215. mins[0],
  216. mins[1],
  217. maxs[0],
  218. maxs[1]
  219. ];
  220. const num = data.readInt32LE(36);
  221. let offset, partOffset;
  222. if (numParts === 1) {
  223. out.type = 'LineString';
  224. offset = 44;
  225. out.coordinates = this.parsePointArray(data, offset, num);
  226. } else {
  227. out.type = 'MultiLineString';
  228. offset = 40 + (numParts << 2);
  229. partOffset = 40;
  230. out.coordinates = this.parseArrayGroup(data, offset, partOffset, numParts, num);
  231. }
  232. return out;
  233. };
  234. ParseShp.prototype.parseZPolyline = function (data) {
  235. const geoJson = this.parsePolyline(data);
  236. if (!geoJson) {
  237. return null;
  238. }
  239. const num = geoJson.coordinates.length;
  240. let zOffset;
  241. if (geoJson.type === 'LineString') {
  242. zOffset = 60 + (num << 4);
  243. geoJson.coordinates = this.parseZPointArray(data, zOffset, num, geoJson.coordinates);
  244. return geoJson;
  245. } else {
  246. const totalPoints = geoJson.coordinates.reduce(function (a, v) {
  247. return a + v.length;
  248. }, 0);
  249. zOffset = 56 + (totalPoints << 4) + (num << 2);
  250. geoJson.coordinates = this.parseZArrayGroup(data, zOffset, num, geoJson.coordinates);
  251. return geoJson;
  252. }
  253. };
  254. ParseShp.prototype.polyFuncs = function (out) {
  255. if (!out) {
  256. return out;
  257. }
  258. if (out.type === 'LineString') {
  259. out.type = 'Polygon';
  260. out.coordinates = [out.coordinates];
  261. return out;
  262. } else {
  263. out.coordinates = out.coordinates.reduce(polyReduce, []);
  264. if (out.coordinates.length === 1) {
  265. out.type = 'Polygon';
  266. out.coordinates = out.coordinates[0];
  267. return out;
  268. } else {
  269. out.type = 'MultiPolygon';
  270. return out;
  271. }
  272. }
  273. };
  274. ParseShp.prototype.parsePolygon = function (data) {
  275. return this.polyFuncs(this.parsePolyline(data));
  276. };
  277. ParseShp.prototype.parseZPolygon = function (data) {
  278. return this.polyFuncs(this.parseZPolyline(data));
  279. };
  280. const shpFuncObj = {
  281. 1: 'parsePoint',
  282. 3: 'parsePolyline',
  283. 5: 'parsePolygon',
  284. 8: 'parseMultiPoint',
  285. 11: 'parseZPoint',
  286. 13: 'parseZPolyline',
  287. 15: 'parseZPolygon',
  288. 18: 'parseZMultiPoint'
  289. };
  290. function makeParseCoord(trans) {
  291. if (trans) {
  292. return function (data, offset) {
  293. const args = [data.readDoubleLE(offset), data.readDoubleLE(offset + 8)];
  294. return trans.inverse(args);
  295. };
  296. } else {
  297. return function (data, offset) {
  298. return [data.readDoubleLE(offset), data.readDoubleLE(offset + 8)];
  299. };
  300. }
  301. }
  302. function ParseShp(buffer, trans) {
  303. if (!(this instanceof ParseShp)) {
  304. return new ParseShp(buffer, trans);
  305. }
  306. this.buffer = buffer;
  307. this.headers = this.parseHeader();
  308. if (this.headers.length < this.buffer.byteLength) {
  309. this.buffer = this.buffer.slice(0, this.headers.length);
  310. }
  311. this.shpFuncs(trans);
  312. this.rows = this.getRows();
  313. }
  314. ParseShp.prototype.shpFuncs = function (tran) {
  315. let num = this.headers.shpCode;
  316. if (num > 20) {
  317. num -= 20;
  318. }
  319. if (!(num in shpFuncObj)) {
  320. throw new Error('I don\'t know that shp type');
  321. }
  322. this.parseFunc = this[shpFuncObj[num]];
  323. this.parseCoord = makeParseCoord(tran);
  324. };
  325. ParseShp.prototype.getShpCode = function () {
  326. return this.parseHeader().shpCode;
  327. };
  328. ParseShp.prototype.parseHeader = function () {
  329. const view = this.buffer.slice(0, 100);
  330. return {
  331. length: view.readInt32BE(6 << 2) << 1,
  332. version: view.readInt32LE(7 << 2),
  333. shpCode: view.readInt32LE(8 << 2),
  334. bbox: [
  335. view.readDoubleLE(9 << 2),
  336. view.readDoubleLE(11 << 2),
  337. view.readDoubleLE(13 << 2),
  338. view.readDoubleLE(13 << 2)
  339. ]
  340. };
  341. };
  342. ParseShp.prototype.getRows = function () {
  343. let offset = 100;
  344. const len = this.buffer.byteLength;
  345. const out = [];
  346. let current;
  347. while (offset < len) {
  348. current = this.getRow(offset);
  349. if (!current) {
  350. break;
  351. }
  352. offset += 8;
  353. offset += current.len;
  354. if (current.type) {
  355. out.push(this.parseFunc(current.data));
  356. } else {
  357. out.push(null);
  358. }
  359. }
  360. return out;
  361. };
  362. ParseShp.prototype.getRow = function (offset) {
  363. const view = this.buffer.slice(offset, offset + 12);
  364. const len = view.readInt32BE(4) << 1;
  365. const id = view.readInt32BE(0);
  366. if (len === 0) {
  367. return {
  368. id: id,
  369. len: len,
  370. type: 0
  371. };
  372. }
  373. return {
  374. id: id,
  375. len: len,
  376. data: this.buffer.slice(offset + 12, offset + len + 8),
  377. type: view.readInt32LE(8)
  378. };
  379. };
  380. module.exports = function (buffer, trans) {
  381. return new ParseShp(buffer, trans).rows;
  382. };
  383. }, {}], 5: [function (require, module, exports) {
  384. 'use strict';
  385. const JSZip = require('jszip');
  386. module.exports = async (buffer) => {
  387. const zip = new JSZip();
  388. await zip.loadAsync(buffer);
  389. const files = zip.file(/.+/);
  390. const out = {};
  391. await Promise.all(files.map(async (a) => {
  392. let result;
  393. if (a.name.slice(-3).toLowerCase() === 'shp' || a.name.slice(-3).toLowerCase() === 'dbf') {
  394. result = await a.async('nodebuffer');
  395. } else {
  396. result = await a.async('text');
  397. }
  398. out[a.name] = result;
  399. }));
  400. return out;
  401. };
  402. }, { "jszip": 11 }], 6: [function (require, module, exports) {
  403. 'use strict'
  404. exports.byteLength = byteLength
  405. exports.toByteArray = toByteArray
  406. exports.fromByteArray = fromByteArray
  407. var lookup = []
  408. var revLookup = []
  409. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
  410. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  411. for (var i = 0, len = code.length; i < len; ++i) {
  412. lookup[i] = code[i]
  413. revLookup[code.charCodeAt(i)] = i
  414. }
  415. // Support decoding URL-safe base64 strings, as Node.js does.
  416. // See: https://en.wikipedia.org/wiki/Base64#URL_applications
  417. revLookup['-'.charCodeAt(0)] = 62
  418. revLookup['_'.charCodeAt(0)] = 63
  419. function getLens(b64) {
  420. var len = b64.length
  421. if (len % 4 > 0) {
  422. throw new Error('Invalid string. Length must be a multiple of 4')
  423. }
  424. // Trim off extra bytes after placeholder bytes are found
  425. // See: https://github.com/beatgammit/base64-js/issues/42
  426. var validLen = b64.indexOf('=')
  427. if (validLen === -1) validLen = len
  428. var placeHoldersLen = validLen === len
  429. ? 0
  430. : 4 - (validLen % 4)
  431. return [validLen, placeHoldersLen]
  432. }
  433. // base64 is 4/3 + up to two characters of the original data
  434. function byteLength(b64) {
  435. var lens = getLens(b64)
  436. var validLen = lens[0]
  437. var placeHoldersLen = lens[1]
  438. return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
  439. }
  440. function _byteLength(b64, validLen, placeHoldersLen) {
  441. return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
  442. }
  443. function toByteArray(b64) {
  444. var tmp
  445. var lens = getLens(b64)
  446. var validLen = lens[0]
  447. var placeHoldersLen = lens[1]
  448. var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
  449. var curByte = 0
  450. // if there are placeholders, only get up to the last complete 4 chars
  451. var len = placeHoldersLen > 0
  452. ? validLen - 4
  453. : validLen
  454. var i
  455. for (i = 0; i < len; i += 4) {
  456. tmp =
  457. (revLookup[b64.charCodeAt(i)] << 18) |
  458. (revLookup[b64.charCodeAt(i + 1)] << 12) |
  459. (revLookup[b64.charCodeAt(i + 2)] << 6) |
  460. revLookup[b64.charCodeAt(i + 3)]
  461. arr[curByte++] = (tmp >> 16) & 0xFF
  462. arr[curByte++] = (tmp >> 8) & 0xFF
  463. arr[curByte++] = tmp & 0xFF
  464. }
  465. if (placeHoldersLen === 2) {
  466. tmp =
  467. (revLookup[b64.charCodeAt(i)] << 2) |
  468. (revLookup[b64.charCodeAt(i + 1)] >> 4)
  469. arr[curByte++] = tmp & 0xFF
  470. }
  471. if (placeHoldersLen === 1) {
  472. tmp =
  473. (revLookup[b64.charCodeAt(i)] << 10) |
  474. (revLookup[b64.charCodeAt(i + 1)] << 4) |
  475. (revLookup[b64.charCodeAt(i + 2)] >> 2)
  476. arr[curByte++] = (tmp >> 8) & 0xFF
  477. arr[curByte++] = tmp & 0xFF
  478. }
  479. return arr
  480. }
  481. function tripletToBase64(num) {
  482. return lookup[num >> 18 & 0x3F] +
  483. lookup[num >> 12 & 0x3F] +
  484. lookup[num >> 6 & 0x3F] +
  485. lookup[num & 0x3F]
  486. }
  487. function encodeChunk(uint8, start, end) {
  488. var tmp
  489. var output = []
  490. for (var i = start; i < end; i += 3) {
  491. tmp =
  492. ((uint8[i] << 16) & 0xFF0000) +
  493. ((uint8[i + 1] << 8) & 0xFF00) +
  494. (uint8[i + 2] & 0xFF)
  495. output.push(tripletToBase64(tmp))
  496. }
  497. return output.join('')
  498. }
  499. function fromByteArray(uint8) {
  500. var tmp
  501. var len = uint8.length
  502. var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
  503. var parts = []
  504. var maxChunkLength = 16383 // must be multiple of 3
  505. // go through the array every three bytes, we'll deal with trailing stuff later
  506. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  507. parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
  508. }
  509. // pad the end with zeros, but make sure to not forget the extra bytes
  510. if (extraBytes === 1) {
  511. tmp = uint8[len - 1]
  512. parts.push(
  513. lookup[tmp >> 2] +
  514. lookup[(tmp << 4) & 0x3F] +
  515. '=='
  516. )
  517. } else if (extraBytes === 2) {
  518. tmp = (uint8[len - 2] << 8) + uint8[len - 1]
  519. parts.push(
  520. lookup[tmp >> 10] +
  521. lookup[(tmp >> 4) & 0x3F] +
  522. lookup[(tmp << 2) & 0x3F] +
  523. '='
  524. )
  525. }
  526. return parts.join('')
  527. }
  528. }, {}], 7: [function (require, module, exports) {
  529. }, {}], 8: [function (require, module, exports) {
  530. (function (Buffer) {
  531. (function () {
  532. /*!
  533. * The buffer module from node.js, for the browser.
  534. *
  535. * @author Feross Aboukhadijeh <https://feross.org>
  536. * @license MIT
  537. */
  538. /* eslint-disable no-proto */
  539. 'use strict'
  540. var base64 = require('base64-js')
  541. var ieee754 = require('ieee754')
  542. exports.Buffer = Buffer
  543. exports.SlowBuffer = SlowBuffer
  544. exports.INSPECT_MAX_BYTES = 50
  545. var K_MAX_LENGTH = 0x7fffffff
  546. exports.kMaxLength = K_MAX_LENGTH
  547. /**
  548. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  549. * === true Use Uint8Array implementation (fastest)
  550. * === false Print warning and recommend using `buffer` v4.x which has an Object
  551. * implementation (most compatible, even IE6)
  552. *
  553. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  554. * Opera 11.6+, iOS 4.2+.
  555. *
  556. * We report that the browser does not support typed arrays if the are not subclassable
  557. * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
  558. * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
  559. * for __proto__ and has a buggy typed array implementation.
  560. */
  561. Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
  562. if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
  563. typeof console.error === 'function') {
  564. // console.error(
  565. // 'This browser lacks typed array (Uint8Array) support which is required by ' +
  566. // '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
  567. // )
  568. }
  569. function typedArraySupport() {
  570. // Can typed array instances can be augmented?
  571. try {
  572. var arr = new Uint8Array(1)
  573. arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42 } }
  574. return arr.foo() === 42
  575. } catch (e) {
  576. return false
  577. }
  578. }
  579. Object.defineProperty(Buffer.prototype, 'parent', {
  580. enumerable: true,
  581. get: function () {
  582. if (!Buffer.isBuffer(this)) return undefined
  583. return this.buffer
  584. }
  585. })
  586. Object.defineProperty(Buffer.prototype, 'offset', {
  587. enumerable: true,
  588. get: function () {
  589. if (!Buffer.isBuffer(this)) return undefined
  590. return this.byteOffset
  591. }
  592. })
  593. function createBuffer(length) {
  594. if (length > K_MAX_LENGTH) {
  595. throw new RangeError('The value "' + length + '" is invalid for option "size"')
  596. }
  597. // Return an augmented `Uint8Array` instance
  598. var buf = new Uint8Array(length)
  599. buf.__proto__ = Buffer.prototype
  600. return buf
  601. }
  602. /**
  603. * The Buffer constructor returns instances of `Uint8Array` that have their
  604. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  605. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  606. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  607. * returns a single octet.
  608. *
  609. * The `Uint8Array` prototype remains unmodified.
  610. */
  611. function Buffer(arg, encodingOrOffset, length) {
  612. // Common case.
  613. if (typeof arg === 'number') {
  614. if (typeof encodingOrOffset === 'string') {
  615. throw new TypeError(
  616. 'The "string" argument must be of type string. Received type number'
  617. )
  618. }
  619. return allocUnsafe(arg)
  620. }
  621. return from(arg, encodingOrOffset, length)
  622. }
  623. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  624. if (typeof Symbol !== 'undefined' && Symbol.species != null &&
  625. Buffer[Symbol.species] === Buffer) {
  626. Object.defineProperty(Buffer, Symbol.species, {
  627. value: null,
  628. configurable: true,
  629. enumerable: false,
  630. writable: false
  631. })
  632. }
  633. Buffer.poolSize = 8192 // not used by this implementation
  634. function from(value, encodingOrOffset, length) {
  635. if (typeof value === 'string') {
  636. return fromString(value, encodingOrOffset)
  637. }
  638. if (ArrayBuffer.isView(value)) {
  639. return fromArrayLike(value)
  640. }
  641. if (value == null) {
  642. throw TypeError(
  643. 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
  644. 'or Array-like Object. Received type ' + (typeof value)
  645. )
  646. }
  647. if (isInstance(value, ArrayBuffer) ||
  648. (value && isInstance(value.buffer, ArrayBuffer))) {
  649. return fromArrayBuffer(value, encodingOrOffset, length)
  650. }
  651. if (typeof value === 'number') {
  652. throw new TypeError(
  653. 'The "value" argument must not be of type number. Received type number'
  654. )
  655. }
  656. var valueOf = value.valueOf && value.valueOf()
  657. if (valueOf != null && valueOf !== value) {
  658. return Buffer.from(valueOf, encodingOrOffset, length)
  659. }
  660. var b = fromObject(value)
  661. if (b) return b
  662. if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
  663. typeof value[Symbol.toPrimitive] === 'function') {
  664. return Buffer.from(
  665. value[Symbol.toPrimitive]('string'), encodingOrOffset, length
  666. )
  667. }
  668. throw new TypeError(
  669. 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
  670. 'or Array-like Object. Received type ' + (typeof value)
  671. )
  672. }
  673. /**
  674. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  675. * if value is a number.
  676. * Buffer.from(str[, encoding])
  677. * Buffer.from(array)
  678. * Buffer.from(buffer)
  679. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  680. **/
  681. Buffer.from = function (value, encodingOrOffset, length) {
  682. return from(value, encodingOrOffset, length)
  683. }
  684. // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
  685. // https://github.com/feross/buffer/pull/148
  686. Buffer.prototype.__proto__ = Uint8Array.prototype
  687. Buffer.__proto__ = Uint8Array
  688. function assertSize(size) {
  689. if (typeof size !== 'number') {
  690. throw new TypeError('"size" argument must be of type number')
  691. } else if (size < 0) {
  692. throw new RangeError('The value "' + size + '" is invalid for option "size"')
  693. }
  694. }
  695. function alloc(size, fill, encoding) {
  696. assertSize(size)
  697. if (size <= 0) {
  698. return createBuffer(size)
  699. }
  700. if (fill !== undefined) {
  701. // Only pay attention to encoding if it's a string. This
  702. // prevents accidentally sending in a number that would
  703. // be interpretted as a start offset.
  704. return typeof encoding === 'string'
  705. ? createBuffer(size).fill(fill, encoding)
  706. : createBuffer(size).fill(fill)
  707. }
  708. return createBuffer(size)
  709. }
  710. /**
  711. * Creates a new filled Buffer instance.
  712. * alloc(size[, fill[, encoding]])
  713. **/
  714. Buffer.alloc = function (size, fill, encoding) {
  715. return alloc(size, fill, encoding)
  716. }
  717. function allocUnsafe(size) {
  718. assertSize(size)
  719. return createBuffer(size < 0 ? 0 : checked(size) | 0)
  720. }
  721. /**
  722. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  723. * */
  724. Buffer.allocUnsafe = function (size) {
  725. return allocUnsafe(size)
  726. }
  727. /**
  728. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  729. */
  730. Buffer.allocUnsafeSlow = function (size) {
  731. return allocUnsafe(size)
  732. }
  733. function fromString(string, encoding) {
  734. if (typeof encoding !== 'string' || encoding === '') {
  735. encoding = 'utf8'
  736. }
  737. if (!Buffer.isEncoding(encoding)) {
  738. throw new TypeError('Unknown encoding: ' + encoding)
  739. }
  740. var length = byteLength(string, encoding) | 0
  741. var buf = createBuffer(length)
  742. var actual = buf.write(string, encoding)
  743. if (actual !== length) {
  744. // Writing a hex string, for example, that contains invalid characters will
  745. // cause everything after the first invalid character to be ignored. (e.g.
  746. // 'abxxcd' will be treated as 'ab')
  747. buf = buf.slice(0, actual)
  748. }
  749. return buf
  750. }
  751. function fromArrayLike(array) {
  752. var length = array.length < 0 ? 0 : checked(array.length) | 0
  753. var buf = createBuffer(length)
  754. for (var i = 0; i < length; i += 1) {
  755. buf[i] = array[i] & 255
  756. }
  757. return buf
  758. }
  759. function fromArrayBuffer(array, byteOffset, length) {
  760. if (byteOffset < 0 || array.byteLength < byteOffset) {
  761. throw new RangeError('"offset" is outside of buffer bounds')
  762. }
  763. if (array.byteLength < byteOffset + (length || 0)) {
  764. throw new RangeError('"length" is outside of buffer bounds')
  765. }
  766. var buf
  767. if (byteOffset === undefined && length === undefined) {
  768. buf = new Uint8Array(array)
  769. } else if (length === undefined) {
  770. buf = new Uint8Array(array, byteOffset)
  771. } else {
  772. buf = new Uint8Array(array, byteOffset, length)
  773. }
  774. // Return an augmented `Uint8Array` instance
  775. buf.__proto__ = Buffer.prototype
  776. return buf
  777. }
  778. function fromObject(obj) {
  779. if (Buffer.isBuffer(obj)) {
  780. var len = checked(obj.length) | 0
  781. var buf = createBuffer(len)
  782. if (buf.length === 0) {
  783. return buf
  784. }
  785. obj.copy(buf, 0, 0, len)
  786. return buf
  787. }
  788. if (obj.length !== undefined) {
  789. if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
  790. return createBuffer(0)
  791. }
  792. return fromArrayLike(obj)
  793. }
  794. if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
  795. return fromArrayLike(obj.data)
  796. }
  797. }
  798. function checked(length) {
  799. // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
  800. // length is NaN (which is otherwise coerced to zero.)
  801. if (length >= K_MAX_LENGTH) {
  802. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  803. 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
  804. }
  805. return length | 0
  806. }
  807. function SlowBuffer(length) {
  808. if (+length != length) { // eslint-disable-line eqeqeq
  809. length = 0
  810. }
  811. return Buffer.alloc(+length)
  812. }
  813. Buffer.isBuffer = function isBuffer(b) {
  814. return b != null && b._isBuffer === true &&
  815. b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
  816. }
  817. Buffer.compare = function compare(a, b) {
  818. if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength)
  819. if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength)
  820. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  821. throw new TypeError(
  822. 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
  823. )
  824. }
  825. if (a === b) return 0
  826. var x = a.length
  827. var y = b.length
  828. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  829. if (a[i] !== b[i]) {
  830. x = a[i]
  831. y = b[i]
  832. break
  833. }
  834. }
  835. if (x < y) return -1
  836. if (y < x) return 1
  837. return 0
  838. }
  839. Buffer.isEncoding = function isEncoding(encoding) {
  840. switch (String(encoding).toLowerCase()) {
  841. case 'hex':
  842. case 'utf8':
  843. case 'utf-8':
  844. case 'ascii':
  845. case 'latin1':
  846. case 'binary':
  847. case 'base64':
  848. case 'ucs2':
  849. case 'ucs-2':
  850. case 'utf16le':
  851. case 'utf-16le':
  852. return true
  853. default:
  854. return false
  855. }
  856. }
  857. Buffer.concat = function concat(list, length) {
  858. if (!Array.isArray(list)) {
  859. throw new TypeError('"list" argument must be an Array of Buffers')
  860. }
  861. if (list.length === 0) {
  862. return Buffer.alloc(0)
  863. }
  864. var i
  865. if (length === undefined) {
  866. length = 0
  867. for (i = 0; i < list.length; ++i) {
  868. length += list[i].length
  869. }
  870. }
  871. var buffer = Buffer.allocUnsafe(length)
  872. var pos = 0
  873. for (i = 0; i < list.length; ++i) {
  874. var buf = list[i]
  875. if (isInstance(buf, Uint8Array)) {
  876. buf = Buffer.from(buf)
  877. }
  878. if (!Buffer.isBuffer(buf)) {
  879. throw new TypeError('"list" argument must be an Array of Buffers')
  880. }
  881. buf.copy(buffer, pos)
  882. pos += buf.length
  883. }
  884. return buffer
  885. }
  886. function byteLength(string, encoding) {
  887. if (Buffer.isBuffer(string)) {
  888. return string.length
  889. }
  890. if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
  891. return string.byteLength
  892. }
  893. if (typeof string !== 'string') {
  894. throw new TypeError(
  895. 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
  896. 'Received type ' + typeof string
  897. )
  898. }
  899. var len = string.length
  900. var mustMatch = (arguments.length > 2 && arguments[2] === true)
  901. if (!mustMatch && len === 0) return 0
  902. // Use a for loop to avoid recursion
  903. var loweredCase = false
  904. for (; ;) {
  905. switch (encoding) {
  906. case 'ascii':
  907. case 'latin1':
  908. case 'binary':
  909. return len
  910. case 'utf8':
  911. case 'utf-8':
  912. return utf8ToBytes(string).length
  913. case 'ucs2':
  914. case 'ucs-2':
  915. case 'utf16le':
  916. case 'utf-16le':
  917. return len * 2
  918. case 'hex':
  919. return len >>> 1
  920. case 'base64':
  921. return base64ToBytes(string).length
  922. default:
  923. if (loweredCase) {
  924. return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
  925. }
  926. encoding = ('' + encoding).toLowerCase()
  927. loweredCase = true
  928. }
  929. }
  930. }
  931. Buffer.byteLength = byteLength
  932. function slowToString(encoding, start, end) {
  933. var loweredCase = false
  934. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  935. // property of a typed array.
  936. // This behaves neither like String nor Uint8Array in that we set start/end
  937. // to their upper/lower bounds if the value passed is out of range.
  938. // undefined is handled specially as per ECMA-262 6th Edition,
  939. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  940. if (start === undefined || start < 0) {
  941. start = 0
  942. }
  943. // Return early if start > this.length. Done here to prevent potential uint32
  944. // coercion fail below.
  945. if (start > this.length) {
  946. return ''
  947. }
  948. if (end === undefined || end > this.length) {
  949. end = this.length
  950. }
  951. if (end <= 0) {
  952. return ''
  953. }
  954. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  955. end >>>= 0
  956. start >>>= 0
  957. if (end <= start) {
  958. return ''
  959. }
  960. if (!encoding) encoding = 'utf8'
  961. while (true) {
  962. switch (encoding) {
  963. case 'hex':
  964. return hexSlice(this, start, end)
  965. case 'utf8':
  966. case 'utf-8':
  967. return utf8Slice(this, start, end)
  968. case 'ascii':
  969. return asciiSlice(this, start, end)
  970. case 'latin1':
  971. case 'binary':
  972. return latin1Slice(this, start, end)
  973. case 'base64':
  974. return base64Slice(this, start, end)
  975. case 'ucs2':
  976. case 'ucs-2':
  977. case 'utf16le':
  978. case 'utf-16le':
  979. return utf16leSlice(this, start, end)
  980. default:
  981. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  982. encoding = (encoding + '').toLowerCase()
  983. loweredCase = true
  984. }
  985. }
  986. }
  987. // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
  988. // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
  989. // reliably in a browserify context because there could be multiple different
  990. // copies of the 'buffer' package in use. This method works even for Buffer
  991. // instances that were created from another copy of the `buffer` package.
  992. // See: https://github.com/feross/buffer/issues/154
  993. Buffer.prototype._isBuffer = true
  994. function swap(b, n, m) {
  995. var i = b[n]
  996. b[n] = b[m]
  997. b[m] = i
  998. }
  999. Buffer.prototype.swap16 = function swap16() {
  1000. var len = this.length
  1001. if (len % 2 !== 0) {
  1002. throw new RangeError('Buffer size must be a multiple of 16-bits')
  1003. }
  1004. for (var i = 0; i < len; i += 2) {
  1005. swap(this, i, i + 1)
  1006. }
  1007. return this
  1008. }
  1009. Buffer.prototype.swap32 = function swap32() {
  1010. var len = this.length
  1011. if (len % 4 !== 0) {
  1012. throw new RangeError('Buffer size must be a multiple of 32-bits')
  1013. }
  1014. for (var i = 0; i < len; i += 4) {
  1015. swap(this, i, i + 3)
  1016. swap(this, i + 1, i + 2)
  1017. }
  1018. return this
  1019. }
  1020. Buffer.prototype.swap64 = function swap64() {
  1021. var len = this.length
  1022. if (len % 8 !== 0) {
  1023. throw new RangeError('Buffer size must be a multiple of 64-bits')
  1024. }
  1025. for (var i = 0; i < len; i += 8) {
  1026. swap(this, i, i + 7)
  1027. swap(this, i + 1, i + 6)
  1028. swap(this, i + 2, i + 5)
  1029. swap(this, i + 3, i + 4)
  1030. }
  1031. return this
  1032. }
  1033. Buffer.prototype.toString = function toString() {
  1034. var length = this.length
  1035. if (length === 0) return ''
  1036. if (arguments.length === 0) return utf8Slice(this, 0, length)
  1037. return slowToString.apply(this, arguments)
  1038. }
  1039. Buffer.prototype.toLocaleString = Buffer.prototype.toString
  1040. Buffer.prototype.equals = function equals(b) {
  1041. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  1042. if (this === b) return true
  1043. return Buffer.compare(this, b) === 0
  1044. }
  1045. Buffer.prototype.inspect = function inspect() {
  1046. var str = ''
  1047. var max = exports.INSPECT_MAX_BYTES
  1048. str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim()
  1049. if (this.length > max) str += ' ... '
  1050. return '<Buffer ' + str + '>'
  1051. }
  1052. Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
  1053. if (isInstance(target, Uint8Array)) {
  1054. target = Buffer.from(target, target.offset, target.byteLength)
  1055. }
  1056. if (!Buffer.isBuffer(target)) {
  1057. throw new TypeError(
  1058. 'The "target" argument must be one of type Buffer or Uint8Array. ' +
  1059. 'Received type ' + (typeof target)
  1060. )
  1061. }
  1062. if (start === undefined) {
  1063. start = 0
  1064. }
  1065. if (end === undefined) {
  1066. end = target ? target.length : 0
  1067. }
  1068. if (thisStart === undefined) {
  1069. thisStart = 0
  1070. }
  1071. if (thisEnd === undefined) {
  1072. thisEnd = this.length
  1073. }
  1074. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  1075. throw new RangeError('out of range index')
  1076. }
  1077. if (thisStart >= thisEnd && start >= end) {
  1078. return 0
  1079. }
  1080. if (thisStart >= thisEnd) {
  1081. return -1
  1082. }
  1083. if (start >= end) {
  1084. return 1
  1085. }
  1086. start >>>= 0
  1087. end >>>= 0
  1088. thisStart >>>= 0
  1089. thisEnd >>>= 0
  1090. if (this === target) return 0
  1091. var x = thisEnd - thisStart
  1092. var y = end - start
  1093. var len = Math.min(x, y)
  1094. var thisCopy = this.slice(thisStart, thisEnd)
  1095. var targetCopy = target.slice(start, end)
  1096. for (var i = 0; i < len; ++i) {
  1097. if (thisCopy[i] !== targetCopy[i]) {
  1098. x = thisCopy[i]
  1099. y = targetCopy[i]
  1100. break
  1101. }
  1102. }
  1103. if (x < y) return -1
  1104. if (y < x) return 1
  1105. return 0
  1106. }
  1107. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  1108. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  1109. //
  1110. // Arguments:
  1111. // - buffer - a Buffer to search
  1112. // - val - a string, Buffer, or number
  1113. // - byteOffset - an index into `buffer`; will be clamped to an int32
  1114. // - encoding - an optional encoding, relevant is val is a string
  1115. // - dir - true for indexOf, false for lastIndexOf
  1116. function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
  1117. // Empty buffer means no match
  1118. if (buffer.length === 0) return -1
  1119. // Normalize byteOffset
  1120. if (typeof byteOffset === 'string') {
  1121. encoding = byteOffset
  1122. byteOffset = 0
  1123. } else if (byteOffset > 0x7fffffff) {
  1124. byteOffset = 0x7fffffff
  1125. } else if (byteOffset < -0x80000000) {
  1126. byteOffset = -0x80000000
  1127. }
  1128. byteOffset = +byteOffset // Coerce to Number.
  1129. if (numberIsNaN(byteOffset)) {
  1130. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  1131. byteOffset = dir ? 0 : (buffer.length - 1)
  1132. }
  1133. // Normalize byteOffset: negative offsets start from the end of the buffer
  1134. if (byteOffset < 0) byteOffset = buffer.length + byteOffset
  1135. if (byteOffset >= buffer.length) {
  1136. if (dir) return -1
  1137. else byteOffset = buffer.length - 1
  1138. } else if (byteOffset < 0) {
  1139. if (dir) byteOffset = 0
  1140. else return -1
  1141. }
  1142. // Normalize val
  1143. if (typeof val === 'string') {
  1144. val = Buffer.from(val, encoding)
  1145. }
  1146. // Finally, search either indexOf (if dir is true) or lastIndexOf
  1147. if (Buffer.isBuffer(val)) {
  1148. // Special case: looking for empty string/buffer always fails
  1149. if (val.length === 0) {
  1150. return -1
  1151. }
  1152. return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
  1153. } else if (typeof val === 'number') {
  1154. val = val & 0xFF // Search for a byte value [0-255]
  1155. if (typeof Uint8Array.prototype.indexOf === 'function') {
  1156. if (dir) {
  1157. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
  1158. } else {
  1159. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
  1160. }
  1161. }
  1162. return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
  1163. }
  1164. throw new TypeError('val must be string, number or Buffer')
  1165. }
  1166. function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
  1167. var indexSize = 1
  1168. var arrLength = arr.length
  1169. var valLength = val.length
  1170. if (encoding !== undefined) {
  1171. encoding = String(encoding).toLowerCase()
  1172. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  1173. encoding === 'utf16le' || encoding === 'utf-16le') {
  1174. if (arr.length < 2 || val.length < 2) {
  1175. return -1
  1176. }
  1177. indexSize = 2
  1178. arrLength /= 2
  1179. valLength /= 2
  1180. byteOffset /= 2
  1181. }
  1182. }
  1183. function read(buf, i) {
  1184. if (indexSize === 1) {
  1185. return buf[i]
  1186. } else {
  1187. return buf.readUInt16BE(i * indexSize)
  1188. }
  1189. }
  1190. var i
  1191. if (dir) {
  1192. var foundIndex = -1
  1193. for (i = byteOffset; i < arrLength; i++) {
  1194. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  1195. if (foundIndex === -1) foundIndex = i
  1196. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  1197. } else {
  1198. if (foundIndex !== -1) i -= i - foundIndex
  1199. foundIndex = -1
  1200. }
  1201. }
  1202. } else {
  1203. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
  1204. for (i = byteOffset; i >= 0; i--) {
  1205. var found = true
  1206. for (var j = 0; j < valLength; j++) {
  1207. if (read(arr, i + j) !== read(val, j)) {
  1208. found = false
  1209. break
  1210. }
  1211. }
  1212. if (found) return i
  1213. }
  1214. }
  1215. return -1
  1216. }
  1217. Buffer.prototype.includes = function includes(val, byteOffset, encoding) {
  1218. return this.indexOf(val, byteOffset, encoding) !== -1
  1219. }
  1220. Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
  1221. return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
  1222. }
  1223. Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
  1224. return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
  1225. }
  1226. function hexWrite(buf, string, offset, length) {
  1227. offset = Number(offset) || 0
  1228. var remaining = buf.length - offset
  1229. if (!length) {
  1230. length = remaining
  1231. } else {
  1232. length = Number(length)
  1233. if (length > remaining) {
  1234. length = remaining
  1235. }
  1236. }
  1237. var strLen = string.length
  1238. if (length > strLen / 2) {
  1239. length = strLen / 2
  1240. }
  1241. for (var i = 0; i < length; ++i) {
  1242. var parsed = parseInt(string.substr(i * 2, 2), 16)
  1243. if (numberIsNaN(parsed)) return i
  1244. buf[offset + i] = parsed
  1245. }
  1246. return i
  1247. }
  1248. function utf8Write(buf, string, offset, length) {
  1249. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  1250. }
  1251. function asciiWrite(buf, string, offset, length) {
  1252. return blitBuffer(asciiToBytes(string), buf, offset, length)
  1253. }
  1254. function latin1Write(buf, string, offset, length) {
  1255. return asciiWrite(buf, string, offset, length)
  1256. }
  1257. function base64Write(buf, string, offset, length) {
  1258. return blitBuffer(base64ToBytes(string), buf, offset, length)
  1259. }
  1260. function ucs2Write(buf, string, offset, length) {
  1261. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  1262. }
  1263. Buffer.prototype.write = function write(string, offset, length, encoding) {
  1264. // Buffer#write(string)
  1265. if (offset === undefined) {
  1266. encoding = 'utf8'
  1267. length = this.length
  1268. offset = 0
  1269. // Buffer#write(string, encoding)
  1270. } else if (length === undefined && typeof offset === 'string') {
  1271. encoding = offset
  1272. length = this.length
  1273. offset = 0
  1274. // Buffer#write(string, offset[, length][, encoding])
  1275. } else if (isFinite(offset)) {
  1276. offset = offset >>> 0
  1277. if (isFinite(length)) {
  1278. length = length >>> 0
  1279. if (encoding === undefined) encoding = 'utf8'
  1280. } else {
  1281. encoding = length
  1282. length = undefined
  1283. }
  1284. } else {
  1285. throw new Error(
  1286. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  1287. )
  1288. }
  1289. var remaining = this.length - offset
  1290. if (length === undefined || length > remaining) length = remaining
  1291. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  1292. throw new RangeError('Attempt to write outside buffer bounds')
  1293. }
  1294. if (!encoding) encoding = 'utf8'
  1295. var loweredCase = false
  1296. for (; ;) {
  1297. switch (encoding) {
  1298. case 'hex':
  1299. return hexWrite(this, string, offset, length)
  1300. case 'utf8':
  1301. case 'utf-8':
  1302. return utf8Write(this, string, offset, length)
  1303. case 'ascii':
  1304. return asciiWrite(this, string, offset, length)
  1305. case 'latin1':
  1306. case 'binary':
  1307. return latin1Write(this, string, offset, length)
  1308. case 'base64':
  1309. // Warning: maxLength not taken into account in base64Write
  1310. return base64Write(this, string, offset, length)
  1311. case 'ucs2':
  1312. case 'ucs-2':
  1313. case 'utf16le':
  1314. case 'utf-16le':
  1315. return ucs2Write(this, string, offset, length)
  1316. default:
  1317. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  1318. encoding = ('' + encoding).toLowerCase()
  1319. loweredCase = true
  1320. }
  1321. }
  1322. }
  1323. Buffer.prototype.toJSON = function toJSON() {
  1324. return {
  1325. type: 'Buffer',
  1326. data: Array.prototype.slice.call(this._arr || this, 0)
  1327. }
  1328. }
  1329. function base64Slice(buf, start, end) {
  1330. if (start === 0 && end === buf.length) {
  1331. return base64.fromByteArray(buf)
  1332. } else {
  1333. return base64.fromByteArray(buf.slice(start, end))
  1334. }
  1335. }
  1336. function utf8Slice(buf, start, end) {
  1337. end = Math.min(buf.length, end)
  1338. var res = []
  1339. var i = start
  1340. while (i < end) {
  1341. var firstByte = buf[i]
  1342. var codePoint = null
  1343. var bytesPerSequence = (firstByte > 0xEF) ? 4
  1344. : (firstByte > 0xDF) ? 3
  1345. : (firstByte > 0xBF) ? 2
  1346. : 1
  1347. if (i + bytesPerSequence <= end) {
  1348. var secondByte, thirdByte, fourthByte, tempCodePoint
  1349. switch (bytesPerSequence) {
  1350. case 1:
  1351. if (firstByte < 0x80) {
  1352. codePoint = firstByte
  1353. }
  1354. break
  1355. case 2:
  1356. secondByte = buf[i + 1]
  1357. if ((secondByte & 0xC0) === 0x80) {
  1358. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
  1359. if (tempCodePoint > 0x7F) {
  1360. codePoint = tempCodePoint
  1361. }
  1362. }
  1363. break
  1364. case 3:
  1365. secondByte = buf[i + 1]
  1366. thirdByte = buf[i + 2]
  1367. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  1368. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
  1369. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  1370. codePoint = tempCodePoint
  1371. }
  1372. }
  1373. break
  1374. case 4:
  1375. secondByte = buf[i + 1]
  1376. thirdByte = buf[i + 2]
  1377. fourthByte = buf[i + 3]
  1378. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  1379. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
  1380. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  1381. codePoint = tempCodePoint
  1382. }
  1383. }
  1384. }
  1385. }
  1386. if (codePoint === null) {
  1387. // we did not generate a valid codePoint so insert a
  1388. // replacement char (U+FFFD) and advance only 1 byte
  1389. codePoint = 0xFFFD
  1390. bytesPerSequence = 1
  1391. } else if (codePoint > 0xFFFF) {
  1392. // encode to utf16 (surrogate pair dance)
  1393. codePoint -= 0x10000
  1394. res.push(codePoint >>> 10 & 0x3FF | 0xD800)
  1395. codePoint = 0xDC00 | codePoint & 0x3FF
  1396. }
  1397. res.push(codePoint)
  1398. i += bytesPerSequence
  1399. }
  1400. return decodeCodePointsArray(res)
  1401. }
  1402. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  1403. // the lowest limit is Chrome, with 0x10000 args.
  1404. // We go 1 magnitude less, for safety
  1405. var MAX_ARGUMENTS_LENGTH = 0x1000
  1406. function decodeCodePointsArray(codePoints) {
  1407. var len = codePoints.length
  1408. if (len <= MAX_ARGUMENTS_LENGTH) {
  1409. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  1410. }
  1411. // Decode in chunks to avoid "call stack size exceeded".
  1412. var res = ''
  1413. var i = 0
  1414. while (i < len) {
  1415. res += String.fromCharCode.apply(
  1416. String,
  1417. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  1418. )
  1419. }
  1420. return res
  1421. }
  1422. function asciiSlice(buf, start, end) {
  1423. var ret = ''
  1424. end = Math.min(buf.length, end)
  1425. for (var i = start; i < end; ++i) {
  1426. ret += String.fromCharCode(buf[i] & 0x7F)
  1427. }
  1428. return ret
  1429. }
  1430. function latin1Slice(buf, start, end) {
  1431. var ret = ''
  1432. end = Math.min(buf.length, end)
  1433. for (var i = start; i < end; ++i) {
  1434. ret += String.fromCharCode(buf[i])
  1435. }
  1436. return ret
  1437. }
  1438. function hexSlice(buf, start, end) {
  1439. var len = buf.length
  1440. if (!start || start < 0) start = 0
  1441. if (!end || end < 0 || end > len) end = len
  1442. var out = ''
  1443. for (var i = start; i < end; ++i) {
  1444. out += toHex(buf[i])
  1445. }
  1446. return out
  1447. }
  1448. function utf16leSlice(buf, start, end) {
  1449. var bytes = buf.slice(start, end)
  1450. var res = ''
  1451. for (var i = 0; i < bytes.length; i += 2) {
  1452. res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
  1453. }
  1454. return res
  1455. }
  1456. Buffer.prototype.slice = function slice(start, end) {
  1457. var len = this.length
  1458. start = ~~start
  1459. end = end === undefined ? len : ~~end
  1460. if (start < 0) {
  1461. start += len
  1462. if (start < 0) start = 0
  1463. } else if (start > len) {
  1464. start = len
  1465. }
  1466. if (end < 0) {
  1467. end += len
  1468. if (end < 0) end = 0
  1469. } else if (end > len) {
  1470. end = len
  1471. }
  1472. if (end < start) end = start
  1473. var newBuf = this.subarray(start, end)
  1474. // Return an augmented `Uint8Array` instance
  1475. newBuf.__proto__ = Buffer.prototype
  1476. return newBuf
  1477. }
  1478. /*
  1479. * Need to make sure that buffer isn't trying to write out of bounds.
  1480. */
  1481. function checkOffset(offset, ext, length) {
  1482. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  1483. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  1484. }
  1485. Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) {
  1486. offset = offset >>> 0
  1487. byteLength = byteLength >>> 0
  1488. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1489. var val = this[offset]
  1490. var mul = 1
  1491. var i = 0
  1492. while (++i < byteLength && (mul *= 0x100)) {
  1493. val += this[offset + i] * mul
  1494. }
  1495. return val
  1496. }
  1497. Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) {
  1498. offset = offset >>> 0
  1499. byteLength = byteLength >>> 0
  1500. if (!noAssert) {
  1501. checkOffset(offset, byteLength, this.length)
  1502. }
  1503. var val = this[offset + --byteLength]
  1504. var mul = 1
  1505. while (byteLength > 0 && (mul *= 0x100)) {
  1506. val += this[offset + --byteLength] * mul
  1507. }
  1508. return val
  1509. }
  1510. Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) {
  1511. offset = offset >>> 0
  1512. if (!noAssert) checkOffset(offset, 1, this.length)
  1513. return this[offset]
  1514. }
  1515. Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
  1516. offset = offset >>> 0
  1517. if (!noAssert) checkOffset(offset, 2, this.length)
  1518. return this[offset] | (this[offset + 1] << 8)
  1519. }
  1520. Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
  1521. offset = offset >>> 0
  1522. if (!noAssert) checkOffset(offset, 2, this.length)
  1523. return (this[offset] << 8) | this[offset + 1]
  1524. }
  1525. Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
  1526. offset = offset >>> 0
  1527. if (!noAssert) checkOffset(offset, 4, this.length)
  1528. return ((this[offset]) |
  1529. (this[offset + 1] << 8) |
  1530. (this[offset + 2] << 16)) +
  1531. (this[offset + 3] * 0x1000000)
  1532. }
  1533. Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
  1534. offset = offset >>> 0
  1535. if (!noAssert) checkOffset(offset, 4, this.length)
  1536. return (this[offset] * 0x1000000) +
  1537. ((this[offset + 1] << 16) |
  1538. (this[offset + 2] << 8) |
  1539. this[offset + 3])
  1540. }
  1541. Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) {
  1542. offset = offset >>> 0
  1543. byteLength = byteLength >>> 0
  1544. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1545. var val = this[offset]
  1546. var mul = 1
  1547. var i = 0
  1548. while (++i < byteLength && (mul *= 0x100)) {
  1549. val += this[offset + i] * mul
  1550. }
  1551. mul *= 0x80
  1552. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  1553. return val
  1554. }
  1555. Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) {
  1556. offset = offset >>> 0
  1557. byteLength = byteLength >>> 0
  1558. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1559. var i = byteLength
  1560. var mul = 1
  1561. var val = this[offset + --i]
  1562. while (i > 0 && (mul *= 0x100)) {
  1563. val += this[offset + --i] * mul
  1564. }
  1565. mul *= 0x80
  1566. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  1567. return val
  1568. }
  1569. Buffer.prototype.readInt8 = function readInt8(offset, noAssert) {
  1570. offset = offset >>> 0
  1571. if (!noAssert) checkOffset(offset, 1, this.length)
  1572. if (!(this[offset] & 0x80)) return (this[offset])
  1573. return ((0xff - this[offset] + 1) * -1)
  1574. }
  1575. Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
  1576. offset = offset >>> 0
  1577. if (!noAssert) checkOffset(offset, 2, this.length)
  1578. var val = this[offset] | (this[offset + 1] << 8)
  1579. return (val & 0x8000) ? val | 0xFFFF0000 : val
  1580. }
  1581. Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
  1582. offset = offset >>> 0
  1583. if (!noAssert) checkOffset(offset, 2, this.length)
  1584. var val = this[offset + 1] | (this[offset] << 8)
  1585. return (val & 0x8000) ? val | 0xFFFF0000 : val
  1586. }
  1587. Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
  1588. offset = offset >>> 0
  1589. if (!noAssert) checkOffset(offset, 4, this.length)
  1590. return (this[offset]) |
  1591. (this[offset + 1] << 8) |
  1592. (this[offset + 2] << 16) |
  1593. (this[offset + 3] << 24)
  1594. }
  1595. Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
  1596. offset = offset >>> 0
  1597. if (!noAssert) checkOffset(offset, 4, this.length)
  1598. return (this[offset] << 24) |
  1599. (this[offset + 1] << 16) |
  1600. (this[offset + 2] << 8) |
  1601. (this[offset + 3])
  1602. }
  1603. Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
  1604. offset = offset >>> 0
  1605. if (!noAssert) checkOffset(offset, 4, this.length)
  1606. return ieee754.read(this, offset, true, 23, 4)
  1607. }
  1608. Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
  1609. offset = offset >>> 0
  1610. if (!noAssert) checkOffset(offset, 4, this.length)
  1611. return ieee754.read(this, offset, false, 23, 4)
  1612. }
  1613. Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
  1614. offset = offset >>> 0
  1615. if (!noAssert) checkOffset(offset, 8, this.length)
  1616. return ieee754.read(this, offset, true, 52, 8)
  1617. }
  1618. Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
  1619. offset = offset >>> 0
  1620. if (!noAssert) checkOffset(offset, 8, this.length)
  1621. return ieee754.read(this, offset, false, 52, 8)
  1622. }
  1623. function checkInt(buf, value, offset, ext, max, min) {
  1624. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  1625. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  1626. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  1627. }
  1628. Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) {
  1629. value = +value
  1630. offset = offset >>> 0
  1631. byteLength = byteLength >>> 0
  1632. if (!noAssert) {
  1633. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  1634. checkInt(this, value, offset, byteLength, maxBytes, 0)
  1635. }
  1636. var mul = 1
  1637. var i = 0
  1638. this[offset] = value & 0xFF
  1639. while (++i < byteLength && (mul *= 0x100)) {
  1640. this[offset + i] = (value / mul) & 0xFF
  1641. }
  1642. return offset + byteLength
  1643. }
  1644. Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) {
  1645. value = +value
  1646. offset = offset >>> 0
  1647. byteLength = byteLength >>> 0
  1648. if (!noAssert) {
  1649. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  1650. checkInt(this, value, offset, byteLength, maxBytes, 0)
  1651. }
  1652. var i = byteLength - 1
  1653. var mul = 1
  1654. this[offset + i] = value & 0xFF
  1655. while (--i >= 0 && (mul *= 0x100)) {
  1656. this[offset + i] = (value / mul) & 0xFF
  1657. }
  1658. return offset + byteLength
  1659. }
  1660. Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
  1661. value = +value
  1662. offset = offset >>> 0
  1663. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  1664. this[offset] = (value & 0xff)
  1665. return offset + 1
  1666. }
  1667. Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
  1668. value = +value
  1669. offset = offset >>> 0
  1670. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  1671. this[offset] = (value & 0xff)
  1672. this[offset + 1] = (value >>> 8)
  1673. return offset + 2
  1674. }
  1675. Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
  1676. value = +value
  1677. offset = offset >>> 0
  1678. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  1679. this[offset] = (value >>> 8)
  1680. this[offset + 1] = (value & 0xff)
  1681. return offset + 2
  1682. }
  1683. Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
  1684. value = +value
  1685. offset = offset >>> 0
  1686. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  1687. this[offset + 3] = (value >>> 24)
  1688. this[offset + 2] = (value >>> 16)
  1689. this[offset + 1] = (value >>> 8)
  1690. this[offset] = (value & 0xff)
  1691. return offset + 4
  1692. }
  1693. Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
  1694. value = +value
  1695. offset = offset >>> 0
  1696. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  1697. this[offset] = (value >>> 24)
  1698. this[offset + 1] = (value >>> 16)
  1699. this[offset + 2] = (value >>> 8)
  1700. this[offset + 3] = (value & 0xff)
  1701. return offset + 4
  1702. }
  1703. Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) {
  1704. value = +value
  1705. offset = offset >>> 0
  1706. if (!noAssert) {
  1707. var limit = Math.pow(2, (8 * byteLength) - 1)
  1708. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  1709. }
  1710. var i = 0
  1711. var mul = 1
  1712. var sub = 0
  1713. this[offset] = value & 0xFF
  1714. while (++i < byteLength && (mul *= 0x100)) {
  1715. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  1716. sub = 1
  1717. }
  1718. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  1719. }
  1720. return offset + byteLength
  1721. }
  1722. Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) {
  1723. value = +value
  1724. offset = offset >>> 0
  1725. if (!noAssert) {
  1726. var limit = Math.pow(2, (8 * byteLength) - 1)
  1727. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  1728. }
  1729. var i = byteLength - 1
  1730. var mul = 1
  1731. var sub = 0
  1732. this[offset + i] = value & 0xFF
  1733. while (--i >= 0 && (mul *= 0x100)) {
  1734. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  1735. sub = 1
  1736. }
  1737. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  1738. }
  1739. return offset + byteLength
  1740. }
  1741. Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
  1742. value = +value
  1743. offset = offset >>> 0
  1744. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
  1745. if (value < 0) value = 0xff + value + 1
  1746. this[offset] = (value & 0xff)
  1747. return offset + 1
  1748. }
  1749. Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
  1750. value = +value
  1751. offset = offset >>> 0
  1752. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  1753. this[offset] = (value & 0xff)
  1754. this[offset + 1] = (value >>> 8)
  1755. return offset + 2
  1756. }
  1757. Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
  1758. value = +value
  1759. offset = offset >>> 0
  1760. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  1761. this[offset] = (value >>> 8)
  1762. this[offset + 1] = (value & 0xff)
  1763. return offset + 2
  1764. }
  1765. Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
  1766. value = +value
  1767. offset = offset >>> 0
  1768. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  1769. this[offset] = (value & 0xff)
  1770. this[offset + 1] = (value >>> 8)
  1771. this[offset + 2] = (value >>> 16)
  1772. this[offset + 3] = (value >>> 24)
  1773. return offset + 4
  1774. }
  1775. Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
  1776. value = +value
  1777. offset = offset >>> 0
  1778. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  1779. if (value < 0) value = 0xffffffff + value + 1
  1780. this[offset] = (value >>> 24)
  1781. this[offset + 1] = (value >>> 16)
  1782. this[offset + 2] = (value >>> 8)
  1783. this[offset + 3] = (value & 0xff)
  1784. return offset + 4
  1785. }
  1786. function checkIEEE754(buf, value, offset, ext, max, min) {
  1787. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  1788. if (offset < 0) throw new RangeError('Index out of range')
  1789. }
  1790. function writeFloat(buf, value, offset, littleEndian, noAssert) {
  1791. value = +value
  1792. offset = offset >>> 0
  1793. if (!noAssert) {
  1794. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  1795. }
  1796. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  1797. return offset + 4
  1798. }
  1799. Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
  1800. return writeFloat(this, value, offset, true, noAssert)
  1801. }
  1802. Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
  1803. return writeFloat(this, value, offset, false, noAssert)
  1804. }
  1805. function writeDouble(buf, value, offset, littleEndian, noAssert) {
  1806. value = +value
  1807. offset = offset >>> 0
  1808. if (!noAssert) {
  1809. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  1810. }
  1811. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  1812. return offset + 8
  1813. }
  1814. Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
  1815. return writeDouble(this, value, offset, true, noAssert)
  1816. }
  1817. Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
  1818. return writeDouble(this, value, offset, false, noAssert)
  1819. }
  1820. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  1821. Buffer.prototype.copy = function copy(target, targetStart, start, end) {
  1822. if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
  1823. if (!start) start = 0
  1824. if (!end && end !== 0) end = this.length
  1825. if (targetStart >= target.length) targetStart = target.length
  1826. if (!targetStart) targetStart = 0
  1827. if (end > 0 && end < start) end = start
  1828. // Copy 0 bytes; we're done
  1829. if (end === start) return 0
  1830. if (target.length === 0 || this.length === 0) return 0
  1831. // Fatal error conditions
  1832. if (targetStart < 0) {
  1833. throw new RangeError('targetStart out of bounds')
  1834. }
  1835. if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
  1836. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  1837. // Are we oob?
  1838. if (end > this.length) end = this.length
  1839. if (target.length - targetStart < end - start) {
  1840. end = target.length - targetStart + start
  1841. }
  1842. var len = end - start
  1843. if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
  1844. // Use built-in when available, missing from IE11
  1845. this.copyWithin(targetStart, start, end)
  1846. } else if (this === target && start < targetStart && targetStart < end) {
  1847. // descending copy from end
  1848. for (var i = len - 1; i >= 0; --i) {
  1849. target[i + targetStart] = this[i + start]
  1850. }
  1851. } else {
  1852. Uint8Array.prototype.set.call(
  1853. target,
  1854. this.subarray(start, end),
  1855. targetStart
  1856. )
  1857. }
  1858. return len
  1859. }
  1860. // Usage:
  1861. // buffer.fill(number[, offset[, end]])
  1862. // buffer.fill(buffer[, offset[, end]])
  1863. // buffer.fill(string[, offset[, end]][, encoding])
  1864. Buffer.prototype.fill = function fill(val, start, end, encoding) {
  1865. // Handle string cases:
  1866. if (typeof val === 'string') {
  1867. if (typeof start === 'string') {
  1868. encoding = start
  1869. start = 0
  1870. end = this.length
  1871. } else if (typeof end === 'string') {
  1872. encoding = end
  1873. end = this.length
  1874. }
  1875. if (encoding !== undefined && typeof encoding !== 'string') {
  1876. throw new TypeError('encoding must be a string')
  1877. }
  1878. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  1879. throw new TypeError('Unknown encoding: ' + encoding)
  1880. }
  1881. if (val.length === 1) {
  1882. var code = val.charCodeAt(0)
  1883. if ((encoding === 'utf8' && code < 128) ||
  1884. encoding === 'latin1') {
  1885. // Fast path: If `val` fits into a single byte, use that numeric value.
  1886. val = code
  1887. }
  1888. }
  1889. } else if (typeof val === 'number') {
  1890. val = val & 255
  1891. }
  1892. // Invalid ranges are not set to a default, so can range check early.
  1893. if (start < 0 || this.length < start || this.length < end) {
  1894. throw new RangeError('Out of range index')
  1895. }
  1896. if (end <= start) {
  1897. return this
  1898. }
  1899. start = start >>> 0
  1900. end = end === undefined ? this.length : end >>> 0
  1901. if (!val) val = 0
  1902. var i
  1903. if (typeof val === 'number') {
  1904. for (i = start; i < end; ++i) {
  1905. this[i] = val
  1906. }
  1907. } else {
  1908. var bytes = Buffer.isBuffer(val)
  1909. ? val
  1910. : Buffer.from(val, encoding)
  1911. var len = bytes.length
  1912. if (len === 0) {
  1913. throw new TypeError('The value "' + val +
  1914. '" is invalid for argument "value"')
  1915. }
  1916. for (i = 0; i < end - start; ++i) {
  1917. this[i + start] = bytes[i % len]
  1918. }
  1919. }
  1920. return this
  1921. }
  1922. // HELPER FUNCTIONS
  1923. // ================
  1924. var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
  1925. function base64clean(str) {
  1926. // Node takes equal signs as end of the Base64 encoding
  1927. str = str.split('=')[0]
  1928. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  1929. str = str.trim().replace(INVALID_BASE64_RE, '')
  1930. // Node converts strings with length < 2 to ''
  1931. if (str.length < 2) return ''
  1932. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  1933. while (str.length % 4 !== 0) {
  1934. str = str + '='
  1935. }
  1936. return str
  1937. }
  1938. function toHex(n) {
  1939. if (n < 16) return '0' + n.toString(16)
  1940. return n.toString(16)
  1941. }
  1942. function utf8ToBytes(string, units) {
  1943. units = units || Infinity
  1944. var codePoint
  1945. var length = string.length
  1946. var leadSurrogate = null
  1947. var bytes = []
  1948. for (var i = 0; i < length; ++i) {
  1949. codePoint = string.charCodeAt(i)
  1950. // is surrogate component
  1951. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  1952. // last char was a lead
  1953. if (!leadSurrogate) {
  1954. // no lead yet
  1955. if (codePoint > 0xDBFF) {
  1956. // unexpected trail
  1957. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1958. continue
  1959. } else if (i + 1 === length) {
  1960. // unpaired lead
  1961. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1962. continue
  1963. }
  1964. // valid lead
  1965. leadSurrogate = codePoint
  1966. continue
  1967. }
  1968. // 2 leads in a row
  1969. if (codePoint < 0xDC00) {
  1970. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1971. leadSurrogate = codePoint
  1972. continue
  1973. }
  1974. // valid surrogate pair
  1975. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
  1976. } else if (leadSurrogate) {
  1977. // valid bmp char, but last char was a lead
  1978. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1979. }
  1980. leadSurrogate = null
  1981. // encode utf8
  1982. if (codePoint < 0x80) {
  1983. if ((units -= 1) < 0) break
  1984. bytes.push(codePoint)
  1985. } else if (codePoint < 0x800) {
  1986. if ((units -= 2) < 0) break
  1987. bytes.push(
  1988. codePoint >> 0x6 | 0xC0,
  1989. codePoint & 0x3F | 0x80
  1990. )
  1991. } else if (codePoint < 0x10000) {
  1992. if ((units -= 3) < 0) break
  1993. bytes.push(
  1994. codePoint >> 0xC | 0xE0,
  1995. codePoint >> 0x6 & 0x3F | 0x80,
  1996. codePoint & 0x3F | 0x80
  1997. )
  1998. } else if (codePoint < 0x110000) {
  1999. if ((units -= 4) < 0) break
  2000. bytes.push(
  2001. codePoint >> 0x12 | 0xF0,
  2002. codePoint >> 0xC & 0x3F | 0x80,
  2003. codePoint >> 0x6 & 0x3F | 0x80,
  2004. codePoint & 0x3F | 0x80
  2005. )
  2006. } else {
  2007. throw new Error('Invalid code point')
  2008. }
  2009. }
  2010. return bytes
  2011. }
  2012. function asciiToBytes(str) {
  2013. var byteArray = []
  2014. for (var i = 0; i < str.length; ++i) {
  2015. // Node's code seems to be doing this and not & 0x7F..
  2016. byteArray.push(str.charCodeAt(i) & 0xFF)
  2017. }
  2018. return byteArray
  2019. }
  2020. function utf16leToBytes(str, units) {
  2021. var c, hi, lo
  2022. var byteArray = []
  2023. for (var i = 0; i < str.length; ++i) {
  2024. if ((units -= 2) < 0) break
  2025. c = str.charCodeAt(i)
  2026. hi = c >> 8
  2027. lo = c % 256
  2028. byteArray.push(lo)
  2029. byteArray.push(hi)
  2030. }
  2031. return byteArray
  2032. }
  2033. function base64ToBytes(str) {
  2034. return base64.toByteArray(base64clean(str))
  2035. }
  2036. function blitBuffer(src, dst, offset, length) {
  2037. for (var i = 0; i < length; ++i) {
  2038. if ((i + offset >= dst.length) || (i >= src.length)) break
  2039. dst[i + offset] = src[i]
  2040. }
  2041. return i
  2042. }
  2043. // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
  2044. // the `instanceof` check but they should be treated as of that type.
  2045. // See: https://github.com/feross/buffer/issues/166
  2046. function isInstance(obj, type) {
  2047. return obj instanceof type ||
  2048. (obj != null && obj.constructor != null && obj.constructor.name != null &&
  2049. obj.constructor.name === type.name)
  2050. }
  2051. function numberIsNaN(obj) {
  2052. // For IE11 support
  2053. return obj !== obj // eslint-disable-line no-self-compare
  2054. }
  2055. }).call(this)
  2056. }).call(this, require("buffer").Buffer)
  2057. }, { "base64-js": 6, "buffer": 8, "ieee754": 9 }], 9: [function (require, module, exports) {
  2058. /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
  2059. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  2060. var e, m
  2061. var eLen = (nBytes * 8) - mLen - 1
  2062. var eMax = (1 << eLen) - 1
  2063. var eBias = eMax >> 1
  2064. var nBits = -7
  2065. var i = isLE ? (nBytes - 1) : 0
  2066. var d = isLE ? -1 : 1
  2067. var s = buffer[offset + i]
  2068. i += d
  2069. e = s & ((1 << (-nBits)) - 1)
  2070. s >>= (-nBits)
  2071. nBits += eLen
  2072. for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) { }
  2073. m = e & ((1 << (-nBits)) - 1)
  2074. e >>= (-nBits)
  2075. nBits += mLen
  2076. for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) { }
  2077. if (e === 0) {
  2078. e = 1 - eBias
  2079. } else if (e === eMax) {
  2080. return m ? NaN : ((s ? -1 : 1) * Infinity)
  2081. } else {
  2082. m = m + Math.pow(2, mLen)
  2083. e = e - eBias
  2084. }
  2085. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  2086. }
  2087. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  2088. var e, m, c
  2089. var eLen = (nBytes * 8) - mLen - 1
  2090. var eMax = (1 << eLen) - 1
  2091. var eBias = eMax >> 1
  2092. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
  2093. var i = isLE ? 0 : (nBytes - 1)
  2094. var d = isLE ? 1 : -1
  2095. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
  2096. value = Math.abs(value)
  2097. if (isNaN(value) || value === Infinity) {
  2098. m = isNaN(value) ? 1 : 0
  2099. e = eMax
  2100. } else {
  2101. e = Math.floor(Math.log(value) / Math.LN2)
  2102. if (value * (c = Math.pow(2, -e)) < 1) {
  2103. e--
  2104. c *= 2
  2105. }
  2106. if (e + eBias >= 1) {
  2107. value += rt / c
  2108. } else {
  2109. value += rt * Math.pow(2, 1 - eBias)
  2110. }
  2111. if (value * c >= 2) {
  2112. e++
  2113. c /= 2
  2114. }
  2115. if (e + eBias >= eMax) {
  2116. m = 0
  2117. e = eMax
  2118. } else if (e + eBias >= 1) {
  2119. m = ((value * c) - 1) * Math.pow(2, mLen)
  2120. e = e + eBias
  2121. } else {
  2122. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
  2123. e = 0
  2124. }
  2125. }
  2126. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) { }
  2127. e = (e << mLen) | m
  2128. eLen += mLen
  2129. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) { }
  2130. buffer[offset + i - d] |= s * 128
  2131. }
  2132. }, {}], 10: [function (require, module, exports) {
  2133. (function (global) {
  2134. (function () {
  2135. 'use strict';
  2136. var Mutation = global.MutationObserver || global.WebKitMutationObserver;
  2137. var scheduleDrain;
  2138. {
  2139. if (Mutation) {
  2140. var called = 0;
  2141. var observer = new Mutation(nextTick);
  2142. var element = global.document.createTextNode('');
  2143. observer.observe(element, {
  2144. characterData: true
  2145. });
  2146. scheduleDrain = function () {
  2147. element.data = (called = ++called % 2);
  2148. };
  2149. } else if (!global.setImmediate && typeof global.MessageChannel !== 'undefined') {
  2150. var channel = new global.MessageChannel();
  2151. channel.port1.onmessage = nextTick;
  2152. scheduleDrain = function () {
  2153. channel.port2.postMessage(0);
  2154. };
  2155. } else if ('document' in global && 'onreadystatechange' in global.document.createElement('script')) {
  2156. scheduleDrain = function () {
  2157. // Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
  2158. // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
  2159. var scriptEl = global.document.createElement('script');
  2160. scriptEl.onreadystatechange = function () {
  2161. nextTick();
  2162. scriptEl.onreadystatechange = null;
  2163. scriptEl.parentNode.removeChild(scriptEl);
  2164. scriptEl = null;
  2165. };
  2166. global.document.documentElement.appendChild(scriptEl);
  2167. };
  2168. } else {
  2169. scheduleDrain = function () {
  2170. setTimeout(nextTick, 0);
  2171. };
  2172. }
  2173. }
  2174. var draining;
  2175. var queue = [];
  2176. //named nextTick for less confusing stack traces
  2177. function nextTick() {
  2178. draining = true;
  2179. var i, oldQueue;
  2180. var len = queue.length;
  2181. while (len) {
  2182. oldQueue = queue;
  2183. queue = [];
  2184. i = -1;
  2185. while (++i < len) {
  2186. oldQueue[i]();
  2187. }
  2188. len = queue.length;
  2189. }
  2190. draining = false;
  2191. }
  2192. module.exports = immediate;
  2193. function immediate(task) {
  2194. if (queue.push(task) === 1 && !draining) {
  2195. scheduleDrain();
  2196. }
  2197. }
  2198. }).call(this)
  2199. }).call(this, typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2200. }, {}], 11: [function (require, module, exports) {
  2201. (function (global, Buffer, setImmediate) {
  2202. (function () {
  2203. /*!
  2204. JSZip v3.6.0 - A JavaScript class for generating and reading zip files
  2205. <http://stuartk.com/jszip>
  2206. (c) 2009-2016 Stuart Knightley <stuart [at] stuartk.com>
  2207. Dual licenced under the MIT license or GPLv3. See https://raw.github.com/Stuk/jszip/master/LICENSE.markdown.
  2208. JSZip uses the library pako released under the MIT license :
  2209. https://github.com/nodeca/pako/blob/master/LICENSE
  2210. */
  2211. !function (e) { if ("object" == typeof exports && "undefined" != typeof module) module.exports = e(); else if ("function" == typeof define && define.amd) define([], e); else { ("undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof self ? self : this).JSZip = e() } }(function () { return function s(a, o, u) { function h(r, e) { if (!o[r]) { if (!a[r]) { var t = "function" == typeof require && require; if (!e && t) return t(r, !0); if (f) return f(r, !0); var n = new Error("Cannot find module '" + r + "'"); throw n.code = "MODULE_NOT_FOUND", n } var i = o[r] = { exports: {} }; a[r][0].call(i.exports, function (e) { var t = a[r][1][e]; return h(t || e) }, i, i.exports, s, a, o, u) } return o[r].exports } for (var f = "function" == typeof require && require, e = 0; e < u.length; e++)h(u[e]); return h }({ 1: [function (l, t, n) { (function (r) { !function (e) { "object" == typeof n && void 0 !== t ? t.exports = e() : ("undefined" != typeof window ? window : void 0 !== r ? r : "undefined" != typeof self ? self : this).JSZip = e() }(function () { return function s(a, o, u) { function h(t, e) { if (!o[t]) { if (!a[t]) { var r = "function" == typeof l && l; if (!e && r) return r(t, !0); if (f) return f(t, !0); var n = new Error("Cannot find module '" + t + "'"); throw n.code = "MODULE_NOT_FOUND", n } var i = o[t] = { exports: {} }; a[t][0].call(i.exports, function (e) { return h(a[t][1][e] || e) }, i, i.exports, s, a, o, u) } return o[t].exports } for (var f = "function" == typeof l && l, e = 0; e < u.length; e++)h(u[e]); return h }({ 1: [function (l, t, n) { (function (r) { !function (e) { "object" == typeof n && void 0 !== t ? t.exports = e() : ("undefined" != typeof window ? window : void 0 !== r ? r : "undefined" != typeof self ? self : this).JSZip = e() }(function () { return function s(a, o, u) { function h(t, e) { if (!o[t]) { if (!a[t]) { var r = "function" == typeof l && l; if (!e && r) return r(t, !0); if (f) return f(t, !0); var n = new Error("Cannot find module '" + t + "'"); throw n.code = "MODULE_NOT_FOUND", n } var i = o[t] = { exports: {} }; a[t][0].call(i.exports, function (e) { return h(a[t][1][e] || e) }, i, i.exports, s, a, o, u) } return o[t].exports } for (var f = "function" == typeof l && l, e = 0; e < u.length; e++)h(u[e]); return h }({ 1: [function (l, t, n) { (function (r) { !function (e) { "object" == typeof n && void 0 !== t ? t.exports = e() : ("undefined" != typeof window ? window : void 0 !== r ? r : "undefined" != typeof self ? self : this).JSZip = e() }(function () { return function s(a, o, u) { function h(t, e) { if (!o[t]) { if (!a[t]) { var r = "function" == typeof l && l; if (!e && r) return r(t, !0); if (f) return f(t, !0); var n = new Error("Cannot find module '" + t + "'"); throw n.code = "MODULE_NOT_FOUND", n } var i = o[t] = { exports: {} }; a[t][0].call(i.exports, function (e) { return h(a[t][1][e] || e) }, i, i.exports, s, a, o, u) } return o[t].exports } for (var f = "function" == typeof l && l, e = 0; e < u.length; e++)h(u[e]); return h }({ 1: [function (l, t, n) { (function (r) { !function (e) { "object" == typeof n && void 0 !== t ? t.exports = e() : ("undefined" != typeof window ? window : void 0 !== r ? r : "undefined" != typeof self ? self : this).JSZip = e() }(function () { return function s(a, o, u) { function h(t, e) { if (!o[t]) { if (!a[t]) { var r = "function" == typeof l && l; if (!e && r) return r(t, !0); if (f) return f(t, !0); var n = new Error("Cannot find module '" + t + "'"); throw n.code = "MODULE_NOT_FOUND", n } var i = o[t] = { exports: {} }; a[t][0].call(i.exports, function (e) { return h(a[t][1][e] || e) }, i, i.exports, s, a, o, u) } return o[t].exports } for (var f = "function" == typeof l && l, e = 0; e < u.length; e++)h(u[e]); return h }({ 1: [function (l, t, n) { (function (r) { !function (e) { "object" == typeof n && void 0 !== t ? t.exports = e() : ("undefined" != typeof window ? window : void 0 !== r ? r : "undefined" != typeof self ? self : this).JSZip = e() }(function () { return function s(a, o, u) { function h(t, e) { if (!o[t]) { if (!a[t]) { var r = "function" == typeof l && l; if (!e && r) return r(t, !0); if (f) return f(t, !0); var n = new Error("Cannot find module '" + t + "'"); throw n.code = "MODULE_NOT_FOUND", n } var i = o[t] = { exports: {} }; a[t][0].call(i.exports, function (e) { return h(a[t][1][e] || e) }, i, i.exports, s, a, o, u) } return o[t].exports } for (var f = "function" == typeof l && l, e = 0; e < u.length; e++)h(u[e]); return h }({ 1: [function (e, t, r) { "use strict"; var c = e("./utils"), l = e("./support"), p = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; r.encode = function (e) { for (var t, r, n, i, s, a, o, u = [], h = 0, f = e.length, l = f, d = "string" !== c.getTypeOf(e); h < e.length;)l = f - h, n = d ? (t = e[h++], r = h < f ? e[h++] : 0, h < f ? e[h++] : 0) : (t = e.charCodeAt(h++), r = h < f ? e.charCodeAt(h++) : 0, h < f ? e.charCodeAt(h++) : 0), i = t >> 2, s = (3 & t) << 4 | r >> 4, a = 1 < l ? (15 & r) << 2 | n >> 6 : 64, o = 2 < l ? 63 & n : 64, u.push(p.charAt(i) + p.charAt(s) + p.charAt(a) + p.charAt(o)); return u.join("") }, r.decode = function (e) { var t, r, n, i, s, a, o = 0, u = 0; if ("data:" === e.substr(0, "data:".length)) throw new Error("Invalid base64 input, it looks like a data url."); var h, f = 3 * (e = e.replace(/[^A-Za-z0-9\+\/\=]/g, "")).length / 4; if (e.charAt(e.length - 1) === p.charAt(64) && f--, e.charAt(e.length - 2) === p.charAt(64) && f--, f % 1 != 0) throw new Error("Invalid base64 input, bad content length."); for (h = l.uint8array ? new Uint8Array(0 | f) : new Array(0 | f); o < e.length;)t = p.indexOf(e.charAt(o++)) << 2 | (i = p.indexOf(e.charAt(o++))) >> 4, r = (15 & i) << 4 | (s = p.indexOf(e.charAt(o++))) >> 2, n = (3 & s) << 6 | (a = p.indexOf(e.charAt(o++))), h[u++] = t, 64 !== s && (h[u++] = r), 64 !== a && (h[u++] = n); return h } }, { "./support": 30, "./utils": 32 }], 2: [function (e, t, r) { "use strict"; var n = e("./external"), i = e("./stream/DataWorker"), s = e("./stream/Crc32Probe"), a = e("./stream/DataLengthProbe"); function o(e, t, r, n, i) { this.compressedSize = e, this.uncompressedSize = t, this.crc32 = r, this.compression = n, this.compressedContent = i } o.prototype = { getContentWorker: function () { var e = new i(n.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new a("data_length")), t = this; return e.on("end", function () { if (this.streamInfo.data_length !== t.uncompressedSize) throw new Error("Bug : uncompressed data size mismatch") }), e }, getCompressedWorker: function () { return new i(n.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize", this.compressedSize).withStreamInfo("uncompressedSize", this.uncompressedSize).withStreamInfo("crc32", this.crc32).withStreamInfo("compression", this.compression) } }, o.createWorkerFrom = function (e, t, r) { return e.pipe(new s).pipe(new a("uncompressedSize")).pipe(t.compressWorker(r)).pipe(new a("compressedSize")).withStreamInfo("compression", t) }, t.exports = o }, { "./external": 6, "./stream/Crc32Probe": 25, "./stream/DataLengthProbe": 26, "./stream/DataWorker": 27 }], 3: [function (e, t, r) { "use strict"; var n = e("./stream/GenericWorker"); r.STORE = { magic: "\0\0", compressWorker: function (e) { return new n("STORE compression") }, uncompressWorker: function () { return new n("STORE decompression") } }, r.DEFLATE = e("./flate") }, { "./flate": 7, "./stream/GenericWorker": 28 }], 4: [function (e, t, r) { "use strict"; var n = e("./utils"), a = function () { for (var e, t = [], r = 0; r < 256; r++) { e = r; for (var n = 0; n < 8; n++)e = 1 & e ? 3988292384 ^ e >>> 1 : e >>> 1; t[r] = e } return t }(); t.exports = function (e, t) { return void 0 !== e && e.length ? "string" !== n.getTypeOf(e) ? function (e, t, r) { var n = a, i = 0 + r; e ^= -1; for (var s = 0; s < i; s++)e = e >>> 8 ^ n[255 & (e ^ t[s])]; return -1 ^ e }(0 | t, e, e.length) : function (e, t, r) { var n = a, i = 0 + r; e ^= -1; for (var s = 0; s < i; s++)e = e >>> 8 ^ n[255 & (e ^ t.charCodeAt(s))]; return -1 ^ e }(0 | t, e, e.length) : 0 } }, { "./utils": 32 }], 5: [function (e, t, r) { "use strict"; r.base64 = !1, r.binary = !1, r.dir = !1, r.createFolders = !0, r.date = null, r.compression = null, r.compressionOptions = null, r.comment = null, r.unixPermissions = null, r.dosPermissions = null }, {}], 6: [function (e, t, r) { "use strict"; var n; n = "undefined" != typeof Promise ? Promise : e("lie"), t.exports = { Promise: n } }, { lie: 37 }], 7: [function (e, t, r) { "use strict"; var n = "undefined" != typeof Uint8Array && "undefined" != typeof Uint16Array && "undefined" != typeof Uint32Array, i = e("pako"), s = e("./utils"), a = e("./stream/GenericWorker"), o = n ? "uint8array" : "array"; function u(e, t) { a.call(this, "FlateWorker/" + e), this._pako = null, this._pakoAction = e, this._pakoOptions = t, this.meta = {} } r.magic = "\b\0", s.inherits(u, a), u.prototype.processChunk = function (e) { this.meta = e.meta, null === this._pako && this._createPako(), this._pako.push(s.transformTo(o, e.data), !1) }, u.prototype.flush = function () { a.prototype.flush.call(this), null === this._pako && this._createPako(), this._pako.push([], !0) }, u.prototype.cleanUp = function () { a.prototype.cleanUp.call(this), this._pako = null }, u.prototype._createPako = function () { this._pako = new i[this._pakoAction]({ raw: !0, level: this._pakoOptions.level || -1 }); var t = this; this._pako.onData = function (e) { t.push({ data: e, meta: t.meta }) } }, r.compressWorker = function (e) { return new u("Deflate", e) }, r.uncompressWorker = function () { return new u("Inflate", {}) } }, { "./stream/GenericWorker": 28, "./utils": 32, pako: 38 }], 8: [function (e, t, r) { "use strict"; function I(e, t) { var r, n = ""; for (r = 0; r < t; r++)n += String.fromCharCode(255 & e), e >>>= 8; return n } function i(e, t, r, n, i, s) { var a, o, u = e.file, h = e.compression, f = s !== B.utf8encode, l = O.transformTo("string", s(u.name)), d = O.transformTo("string", B.utf8encode(u.name)), c = u.comment, p = O.transformTo("string", s(c)), m = O.transformTo("string", B.utf8encode(c)), _ = d.length !== u.name.length, g = m.length !== c.length, v = "", b = "", w = "", y = u.dir, k = u.date, x = { crc32: 0, compressedSize: 0, uncompressedSize: 0 }; t && !r || (x.crc32 = e.crc32, x.compressedSize = e.compressedSize, x.uncompressedSize = e.uncompressedSize); var S = 0; t && (S |= 8), f || !_ && !g || (S |= 2048); var z, E = 0, C = 0; y && (E |= 16), "UNIX" === i ? (C = 798, E |= ((z = u.unixPermissions) || (z = y ? 16893 : 33204), (65535 & z) << 16)) : (C = 20, E |= 63 & (u.dosPermissions || 0)), a = k.getUTCHours(), a <<= 6, a |= k.getUTCMinutes(), a <<= 5, a |= k.getUTCSeconds() / 2, o = k.getUTCFullYear() - 1980, o <<= 4, o |= k.getUTCMonth() + 1, o <<= 5, o |= k.getUTCDate(), _ && (v += "up" + I((b = I(1, 1) + I(T(l), 4) + d).length, 2) + b), g && (v += "uc" + I((w = I(1, 1) + I(T(p), 4) + m).length, 2) + w); var A = ""; return A += "\n\0", A += I(S, 2), A += h.magic, A += I(a, 2), A += I(o, 2), A += I(x.crc32, 4), A += I(x.compressedSize, 4), A += I(x.uncompressedSize, 4), A += I(l.length, 2), A += I(v.length, 2), { fileRecord: R.LOCAL_FILE_HEADER + A + l + v, dirRecord: R.CENTRAL_FILE_HEADER + I(C, 2) + A + I(p.length, 2) + "\0\0\0\0" + I(E, 4) + I(n, 4) + l + v + p } } var O = e("../utils"), s = e("../stream/GenericWorker"), B = e("../utf8"), T = e("../crc32"), R = e("../signature"); function n(e, t, r, n) { s.call(this, "ZipFileWorker"), this.bytesWritten = 0, this.zipComment = t, this.zipPlatform = r, this.encodeFileName = n, this.streamFiles = e, this.accumulate = !1, this.contentBuffer = [], this.dirRecords = [], this.currentSourceOffset = 0, this.entriesCount = 0, this.currentFile = null, this._sources = [] } O.inherits(n, s), n.prototype.push = function (e) { var t = e.meta.percent || 0, r = this.entriesCount, n = this._sources.length; this.accumulate ? this.contentBuffer.push(e) : (this.bytesWritten += e.data.length, s.prototype.push.call(this, { data: e.data, meta: { currentFile: this.currentFile, percent: r ? (t + 100 * (r - n - 1)) / r : 100 } })) }, n.prototype.openedSource = function (e) { this.currentSourceOffset = this.bytesWritten, this.currentFile = e.file.name; var t = this.streamFiles && !e.file.dir; if (t) { var r = i(e, t, !1, this.currentSourceOffset, this.zipPlatform, this.encodeFileName); this.push({ data: r.fileRecord, meta: { percent: 0 } }) } else this.accumulate = !0 }, n.prototype.closedSource = function (e) { this.accumulate = !1; var t, r = this.streamFiles && !e.file.dir, n = i(e, r, !0, this.currentSourceOffset, this.zipPlatform, this.encodeFileName); if (this.dirRecords.push(n.dirRecord), r) this.push({ data: (t = e, R.DATA_DESCRIPTOR + I(t.crc32, 4) + I(t.compressedSize, 4) + I(t.uncompressedSize, 4)), meta: { percent: 100 } }); else for (this.push({ data: n.fileRecord, meta: { percent: 0 } }); this.contentBuffer.length;)this.push(this.contentBuffer.shift()); this.currentFile = null }, n.prototype.flush = function () { for (var e = this.bytesWritten, t = 0; t < this.dirRecords.length; t++)this.push({ data: this.dirRecords[t], meta: { percent: 100 } }); var r, n, i, s, a, o, u = this.bytesWritten - e, h = (r = this.dirRecords.length, n = u, i = e, s = this.zipComment, a = this.encodeFileName, o = O.transformTo("string", a(s)), R.CENTRAL_DIRECTORY_END + "\0\0\0\0" + I(r, 2) + I(r, 2) + I(n, 4) + I(i, 4) + I(o.length, 2) + o); this.push({ data: h, meta: { percent: 100 } }) }, n.prototype.prepareNextSource = function () { this.previous = this._sources.shift(), this.openedSource(this.previous.streamInfo), this.isPaused ? this.previous.pause() : this.previous.resume() }, n.prototype.registerPrevious = function (e) { this._sources.push(e); var t = this; return e.on("data", function (e) { t.processChunk(e) }), e.on("end", function () { t.closedSource(t.previous.streamInfo), t._sources.length ? t.prepareNextSource() : t.end() }), e.on("error", function (e) { t.error(e) }), this }, n.prototype.resume = function () { return !!s.prototype.resume.call(this) && (!this.previous && this._sources.length ? (this.prepareNextSource(), !0) : this.previous || this._sources.length || this.generatedError ? void 0 : (this.end(), !0)) }, n.prototype.error = function (e) { var t = this._sources; if (!s.prototype.error.call(this, e)) return !1; for (var r = 0; r < t.length; r++)try { t[r].error(e) } catch (e) { } return !0 }, n.prototype.lock = function () { s.prototype.lock.call(this); for (var e = this._sources, t = 0; t < e.length; t++)e[t].lock() }, t.exports = n }, { "../crc32": 4, "../signature": 23, "../stream/GenericWorker": 28, "../utf8": 31, "../utils": 32 }], 9: [function (e, t, r) { "use strict"; var h = e("../compressions"), n = e("./ZipFileWorker"); r.generateWorker = function (e, a, t) { var o = new n(a.streamFiles, t, a.platform, a.encodeFileName), u = 0; try { e.forEach(function (e, t) { u++; var r = function (e, t) { var r = e || t, n = h[r]; if (!n) throw new Error(r + " is not a valid compression method !"); return n }(t.options.compression, a.compression), n = t.options.compressionOptions || a.compressionOptions || {}, i = t.dir, s = t.date; t._compressWorker(r, n).withStreamInfo("file", { name: e, dir: i, date: s, comment: t.comment || "", unixPermissions: t.unixPermissions, dosPermissions: t.dosPermissions }).pipe(o) }), o.entriesCount = u } catch (e) { o.error(e) } return o } }, { "../compressions": 3, "./ZipFileWorker": 8 }], 10: [function (e, t, r) { "use strict"; function n() { if (!(this instanceof n)) return new n; if (arguments.length) throw new Error("The constructor with parameters has been removed in JSZip 3.0, please check the upgrade guide."); this.files = {}, this.comment = null, this.root = "", this.clone = function () { var e = new n; for (var t in this) "function" != typeof this[t] && (e[t] = this[t]); return e } } (n.prototype = e("./object")).loadAsync = e("./load"), n.support = e("./support"), n.defaults = e("./defaults"), n.version = "3.5.0", n.loadAsync = function (e, t) { return (new n).loadAsync(e, t) }, n.external = e("./external"), t.exports = n }, { "./defaults": 5, "./external": 6, "./load": 11, "./object": 15, "./support": 30 }], 11: [function (e, t, r) { "use strict"; var n = e("./utils"), i = e("./external"), o = e("./utf8"), u = e("./zipEntries"), s = e("./stream/Crc32Probe"), h = e("./nodejsUtils"); function f(n) { return new i.Promise(function (e, t) { var r = n.decompressed.getContentWorker().pipe(new s); r.on("error", function (e) { t(e) }).on("end", function () { r.streamInfo.crc32 !== n.decompressed.crc32 ? t(new Error("Corrupted zip : CRC32 mismatch")) : e() }).resume() }) } t.exports = function (e, s) { var a = this; return s = n.extend(s || {}, { base64: !1, checkCRC32: !1, optimizedBinaryString: !1, createFolders: !1, decodeFileName: o.utf8decode }), h.isNode && h.isStream(e) ? i.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file.")) : n.prepareContent("the loaded zip file", e, !0, s.optimizedBinaryString, s.base64).then(function (e) { var t = new u(s); return t.load(e), t }).then(function (e) { var t = [i.Promise.resolve(e)], r = e.files; if (s.checkCRC32) for (var n = 0; n < r.length; n++)t.push(f(r[n])); return i.Promise.all(t) }).then(function (e) { for (var t = e.shift(), r = t.files, n = 0; n < r.length; n++) { var i = r[n]; a.file(i.fileNameStr, i.decompressed, { binary: !0, optimizedBinaryString: !0, date: i.date, dir: i.dir, comment: i.fileCommentStr.length ? i.fileCommentStr : null, unixPermissions: i.unixPermissions, dosPermissions: i.dosPermissions, createFolders: s.createFolders }) } return t.zipComment.length && (a.comment = t.zipComment), a }) } }, { "./external": 6, "./nodejsUtils": 14, "./stream/Crc32Probe": 25, "./utf8": 31, "./utils": 32, "./zipEntries": 33 }], 12: [function (e, t, r) { "use strict"; var n = e("../utils"), i = e("../stream/GenericWorker"); function s(e, t) { i.call(this, "Nodejs stream input adapter for " + e), this._upstreamEnded = !1, this._bindStream(t) } n.inherits(s, i), s.prototype._bindStream = function (e) { var t = this; (this._stream = e).pause(), e.on("data", function (e) { t.push({ data: e, meta: { percent: 0 } }) }).on("error", function (e) { t.isPaused ? this.generatedError = e : t.error(e) }).on("end", function () { t.isPaused ? t._upstreamEnded = !0 : t.end() }) }, s.prototype.pause = function () { return !!i.prototype.pause.call(this) && (this._stream.pause(), !0) }, s.prototype.resume = function () { return !!i.prototype.resume.call(this) && (this._upstreamEnded ? this.end() : this._stream.resume(), !0) }, t.exports = s }, { "../stream/GenericWorker": 28, "../utils": 32 }], 13: [function (e, t, r) { "use strict"; var i = e("readable-stream").Readable; function n(e, t, r) { i.call(this, t), this._helper = e; var n = this; e.on("data", function (e, t) { n.push(e) || n._helper.pause(), r && r(t) }).on("error", function (e) { n.emit("error", e) }).on("end", function () { n.push(null) }) } e("../utils").inherits(n, i), n.prototype._read = function () { this._helper.resume() }, t.exports = n }, { "../utils": 32, "readable-stream": 16 }], 14: [function (e, t, r) { "use strict"; t.exports = { isNode: "undefined" != typeof Buffer, newBufferFrom: function (e, t) { if (Buffer.from && Buffer.from !== Uint8Array.from) return Buffer.from(e, t); if ("number" == typeof e) throw new Error('The "data" argument must not be a number'); return new Buffer(e, t) }, allocBuffer: function (e) { if (Buffer.alloc) return Buffer.alloc(e); var t = new Buffer(e); return t.fill(0), t }, isBuffer: function (e) { return Buffer.isBuffer(e) }, isStream: function (e) { return e && "function" == typeof e.on && "function" == typeof e.pause && "function" == typeof e.resume } } }, {}], 15: [function (e, t, r) { "use strict"; function s(e, t, r) { var n, i = f.getTypeOf(t), s = f.extend(r || {}, d); s.date = s.date || new Date, null !== s.compression && (s.compression = s.compression.toUpperCase()), "string" == typeof s.unixPermissions && (s.unixPermissions = parseInt(s.unixPermissions, 8)), s.unixPermissions && 16384 & s.unixPermissions && (s.dir = !0), s.dosPermissions && 16 & s.dosPermissions && (s.dir = !0), s.dir && (e = h(e)), s.createFolders && (n = function (e) { "/" === e.slice(-1) && (e = e.substring(0, e.length - 1)); var t = e.lastIndexOf("/"); return 0 < t ? e.substring(0, t) : "" }(e)) && g.call(this, n, !0); var a, o = "string" === i && !1 === s.binary && !1 === s.base64; r && void 0 !== r.binary || (s.binary = !o), (t instanceof c && 0 === t.uncompressedSize || s.dir || !t || 0 === t.length) && (s.base64 = !1, s.binary = !0, t = "", s.compression = "STORE", i = "string"), a = t instanceof c || t instanceof l ? t : m.isNode && m.isStream(t) ? new _(e, t) : f.prepareContent(e, t, s.binary, s.optimizedBinaryString, s.base64); var u = new p(e, a, s); this.files[e] = u } function h(e) { return "/" !== e.slice(-1) && (e += "/"), e } var i = e("./utf8"), f = e("./utils"), l = e("./stream/GenericWorker"), a = e("./stream/StreamHelper"), d = e("./defaults"), c = e("./compressedObject"), p = e("./zipObject"), o = e("./generate"), m = e("./nodejsUtils"), _ = e("./nodejs/NodejsStreamInputAdapter"), g = function (e, t) { return t = void 0 !== t ? t : d.createFolders, e = h(e), this.files[e] || s.call(this, e, null, { dir: !0, createFolders: t }), this.files[e] }; function u(e) { return "[object RegExp]" === Object.prototype.toString.call(e) } var n = { load: function () { throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.") }, forEach: function (e) { var t, r, n; for (t in this.files) this.files.hasOwnProperty(t) && (n = this.files[t], (r = t.slice(this.root.length, t.length)) && t.slice(0, this.root.length) === this.root && e(r, n)) }, filter: function (r) { var n = []; return this.forEach(function (e, t) { r(e, t) && n.push(t) }), n }, file: function (e, t, r) { if (1 !== arguments.length) return e = this.root + e, s.call(this, e, t, r), this; if (u(e)) { var n = e; return this.filter(function (e, t) { return !t.dir && n.test(e) }) } var i = this.files[this.root + e]; return i && !i.dir ? i : null }, folder: function (r) { if (!r) return this; if (u(r)) return this.filter(function (e, t) { return t.dir && r.test(e) }); var e = this.root + r, t = g.call(this, e), n = this.clone(); return n.root = t.name, n }, remove: function (r) { r = this.root + r; var e = this.files[r]; if (e || ("/" !== r.slice(-1) && (r += "/"), e = this.files[r]), e && !e.dir) delete this.files[r]; else for (var t = this.filter(function (e, t) { return t.name.slice(0, r.length) === r }), n = 0; n < t.length; n++)delete this.files[t[n].name]; return this }, generate: function (e) { throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.") }, generateInternalStream: function (e) { var t, r = {}; try { if ((r = f.extend(e || {}, { streamFiles: !1, compression: "STORE", compressionOptions: null, type: "", platform: "DOS", comment: null, mimeType: "application/zip", encodeFileName: i.utf8encode })).type = r.type.toLowerCase(), r.compression = r.compression.toUpperCase(), "binarystring" === r.type && (r.type = "string"), !r.type) throw new Error("No output type specified."); f.checkSupport(r.type), "darwin" !== r.platform && "freebsd" !== r.platform && "linux" !== r.platform && "sunos" !== r.platform || (r.platform = "UNIX"), "win32" === r.platform && (r.platform = "DOS"); var n = r.comment || this.comment || ""; t = o.generateWorker(this, r, n) } catch (e) { (t = new l("error")).error(e) } return new a(t, r.type || "string", r.mimeType) }, generateAsync: function (e, t) { return this.generateInternalStream(e).accumulate(t) }, generateNodeStream: function (e, t) { return (e = e || {}).type || (e.type = "nodebuffer"), this.generateInternalStream(e).toNodejsStream(t) } }; t.exports = n }, { "./compressedObject": 2, "./defaults": 5, "./generate": 9, "./nodejs/NodejsStreamInputAdapter": 12, "./nodejsUtils": 14, "./stream/GenericWorker": 28, "./stream/StreamHelper": 29, "./utf8": 31, "./utils": 32, "./zipObject": 35 }], 16: [function (e, t, r) { t.exports = e("stream") }, { stream: void 0 }], 17: [function (e, t, r) { "use strict"; var n = e("./DataReader"); function i(e) { n.call(this, e); for (var t = 0; t < this.data.length; t++)e[t] = 255 & e[t] } e("../utils").inherits(i, n), i.prototype.byteAt = function (e) { return this.data[this.zero + e] }, i.prototype.lastIndexOfSignature = function (e) { for (var t = e.charCodeAt(0), r = e.charCodeAt(1), n = e.charCodeAt(2), i = e.charCodeAt(3), s = this.length - 4; 0 <= s; --s)if (this.data[s] === t && this.data[s + 1] === r && this.data[s + 2] === n && this.data[s + 3] === i) return s - this.zero; return -1 }, i.prototype.readAndCheckSignature = function (e) { var t = e.charCodeAt(0), r = e.charCodeAt(1), n = e.charCodeAt(2), i = e.charCodeAt(3), s = this.readData(4); return t === s[0] && r === s[1] && n === s[2] && i === s[3] }, i.prototype.readData = function (e) { if (this.checkOffset(e), 0 === e) return []; var t = this.data.slice(this.zero + this.index, this.zero + this.index + e); return this.index += e, t }, t.exports = i }, { "../utils": 32, "./DataReader": 18 }], 18: [function (e, t, r) { "use strict"; var n = e("../utils"); function i(e) { this.data = e, this.length = e.length, this.index = 0, this.zero = 0 } i.prototype = { checkOffset: function (e) { this.checkIndex(this.index + e) }, checkIndex: function (e) { if (this.length < this.zero + e || e < 0) throw new Error("End of data reached (data length = " + this.length + ", asked index = " + e + "). Corrupted zip ?") }, setIndex: function (e) { this.checkIndex(e), this.index = e }, skip: function (e) { this.setIndex(this.index + e) }, byteAt: function (e) { }, readInt: function (e) { var t, r = 0; for (this.checkOffset(e), t = this.index + e - 1; t >= this.index; t--)r = (r << 8) + this.byteAt(t); return this.index += e, r }, readString: function (e) { return n.transformTo("string", this.readData(e)) }, readData: function (e) { }, lastIndexOfSignature: function (e) { }, readAndCheckSignature: function (e) { }, readDate: function () { var e = this.readInt(4); return new Date(Date.UTC(1980 + (e >> 25 & 127), (e >> 21 & 15) - 1, e >> 16 & 31, e >> 11 & 31, e >> 5 & 63, (31 & e) << 1)) } }, t.exports = i }, { "../utils": 32 }], 19: [function (e, t, r) { "use strict"; var n = e("./Uint8ArrayReader"); function i(e) { n.call(this, e) } e("../utils").inherits(i, n), i.prototype.readData = function (e) { this.checkOffset(e); var t = this.data.slice(this.zero + this.index, this.zero + this.index + e); return this.index += e, t }, t.exports = i }, { "../utils": 32, "./Uint8ArrayReader": 21 }], 20: [function (e, t, r) { "use strict"; var n = e("./DataReader"); function i(e) { n.call(this, e) } e("../utils").inherits(i, n), i.prototype.byteAt = function (e) { return this.data.charCodeAt(this.zero + e) }, i.prototype.lastIndexOfSignature = function (e) { return this.data.lastIndexOf(e) - this.zero }, i.prototype.readAndCheckSignature = function (e) { return e === this.readData(4) }, i.prototype.readData = function (e) { this.checkOffset(e); var t = this.data.slice(this.zero + this.index, this.zero + this.index + e); return this.index += e, t }, t.exports = i }, { "../utils": 32, "./DataReader": 18 }], 21: [function (e, t, r) { "use strict"; var n = e("./ArrayReader"); function i(e) { n.call(this, e) } e("../utils").inherits(i, n), i.prototype.readData = function (e) { if (this.checkOffset(e), 0 === e) return new Uint8Array(0); var t = this.data.subarray(this.zero + this.index, this.zero + this.index + e); return this.index += e, t }, t.exports = i }, { "../utils": 32, "./ArrayReader": 17 }], 22: [function (e, t, r) { "use strict"; var n = e("../utils"), i = e("../support"), s = e("./ArrayReader"), a = e("./StringReader"), o = e("./NodeBufferReader"), u = e("./Uint8ArrayReader"); t.exports = function (e) { var t = n.getTypeOf(e); return n.checkSupport(t), "string" !== t || i.uint8array ? "nodebuffer" === t ? new o(e) : i.uint8array ? new u(n.transformTo("uint8array", e)) : new s(n.transformTo("array", e)) : new a(e) } }, { "../support": 30, "../utils": 32, "./ArrayReader": 17, "./NodeBufferReader": 19, "./StringReader": 20, "./Uint8ArrayReader": 21 }], 23: [function (e, t, r) { "use strict"; r.LOCAL_FILE_HEADER = "PK", r.CENTRAL_FILE_HEADER = "PK", r.CENTRAL_DIRECTORY_END = "PK", r.ZIP64_CENTRAL_DIRECTORY_LOCATOR = "PK", r.ZIP64_CENTRAL_DIRECTORY_END = "PK", r.DATA_DESCRIPTOR = "PK\b" }, {}], 24: [function (e, t, r) { "use strict"; var n = e("./GenericWorker"), i = e("../utils"); function s(e) { n.call(this, "ConvertWorker to " + e), this.destType = e } i.inherits(s, n), s.prototype.processChunk = function (e) { this.push({ data: i.transformTo(this.destType, e.data), meta: e.meta }) }, t.exports = s }, { "../utils": 32, "./GenericWorker": 28 }], 25: [function (e, t, r) { "use strict"; var n = e("./GenericWorker"), i = e("../crc32"); function s() { n.call(this, "Crc32Probe"), this.withStreamInfo("crc32", 0) } e("../utils").inherits(s, n), s.prototype.processChunk = function (e) { this.streamInfo.crc32 = i(e.data, this.streamInfo.crc32 || 0), this.push(e) }, t.exports = s }, { "../crc32": 4, "../utils": 32, "./GenericWorker": 28 }], 26: [function (e, t, r) { "use strict"; var n = e("../utils"), i = e("./GenericWorker"); function s(e) { i.call(this, "DataLengthProbe for " + e), this.propName = e, this.withStreamInfo(e, 0) } n.inherits(s, i), s.prototype.processChunk = function (e) { if (e) { var t = this.streamInfo[this.propName] || 0; this.streamInfo[this.propName] = t + e.data.length } i.prototype.processChunk.call(this, e) }, t.exports = s }, { "../utils": 32, "./GenericWorker": 28 }], 27: [function (e, t, r) { "use strict"; var n = e("../utils"), i = e("./GenericWorker"); function s(e) { i.call(this, "DataWorker"); var t = this; this.dataIsReady = !1, this.index = 0, this.max = 0, this.data = null, this.type = "", this._tickScheduled = !1, e.then(function (e) { t.dataIsReady = !0, t.data = e, t.max = e && e.length || 0, t.type = n.getTypeOf(e), t.isPaused || t._tickAndRepeat() }, function (e) { t.error(e) }) } n.inherits(s, i), s.prototype.cleanUp = function () { i.prototype.cleanUp.call(this), this.data = null }, s.prototype.resume = function () { return !!i.prototype.resume.call(this) && (!this._tickScheduled && this.dataIsReady && (this._tickScheduled = !0, n.delay(this._tickAndRepeat, [], this)), !0) }, s.prototype._tickAndRepeat = function () { this._tickScheduled = !1, this.isPaused || this.isFinished || (this._tick(), this.isFinished || (n.delay(this._tickAndRepeat, [], this), this._tickScheduled = !0)) }, s.prototype._tick = function () { if (this.isPaused || this.isFinished) return !1; var e = null, t = Math.min(this.max, this.index + 16384); if (this.index >= this.max) return this.end(); switch (this.type) { case "string": e = this.data.substring(this.index, t); break; case "uint8array": e = this.data.subarray(this.index, t); break; case "array": case "nodebuffer": e = this.data.slice(this.index, t) }return this.index = t, this.push({ data: e, meta: { percent: this.max ? this.index / this.max * 100 : 0 } }) }, t.exports = s }, { "../utils": 32, "./GenericWorker": 28 }], 28: [function (e, t, r) { "use strict"; function n(e) { this.name = e || "default", this.streamInfo = {}, this.generatedError = null, this.extraStreamInfo = {}, this.isPaused = !0, this.isFinished = !1, this.isLocked = !1, this._listeners = { data: [], end: [], error: [] }, this.previous = null } n.prototype = { push: function (e) { this.emit("data", e) }, end: function () { if (this.isFinished) return !1; this.flush(); try { this.emit("end"), this.cleanUp(), this.isFinished = !0 } catch (e) { this.emit("error", e) } return !0 }, error: function (e) { return !this.isFinished && (this.isPaused ? this.generatedError = e : (this.isFinished = !0, this.emit("error", e), this.previous && this.previous.error(e), this.cleanUp()), !0) }, on: function (e, t) { return this._listeners[e].push(t), this }, cleanUp: function () { this.streamInfo = this.generatedError = this.extraStreamInfo = null, this._listeners = [] }, emit: function (e, t) { if (this._listeners[e]) for (var r = 0; r < this._listeners[e].length; r++)this._listeners[e][r].call(this, t) }, pipe: function (e) { return e.registerPrevious(this) }, registerPrevious: function (e) { if (this.isLocked) throw new Error("The stream '" + this + "' has already been used."); this.streamInfo = e.streamInfo, this.mergeStreamInfo(), this.previous = e; var t = this; return e.on("data", function (e) { t.processChunk(e) }), e.on("end", function () { t.end() }), e.on("error", function (e) { t.error(e) }), this }, pause: function () { return !this.isPaused && !this.isFinished && (this.isPaused = !0, this.previous && this.previous.pause(), !0) }, resume: function () { if (!this.isPaused || this.isFinished) return !1; var e = this.isPaused = !1; return this.generatedError && (this.error(this.generatedError), e = !0), this.previous && this.previous.resume(), !e }, flush: function () { }, processChunk: function (e) { this.push(e) }, withStreamInfo: function (e, t) { return this.extraStreamInfo[e] = t, this.mergeStreamInfo(), this }, mergeStreamInfo: function () { for (var e in this.extraStreamInfo) this.extraStreamInfo.hasOwnProperty(e) && (this.streamInfo[e] = this.extraStreamInfo[e]) }, lock: function () { if (this.isLocked) throw new Error("The stream '" + this + "' has already been used."); this.isLocked = !0, this.previous && this.previous.lock() }, toString: function () { var e = "Worker " + this.name; return this.previous ? this.previous + " -> " + e : e } }, t.exports = n }, {}], 29: [function (e, t, r) { "use strict"; var h = e("../utils"), i = e("./ConvertWorker"), s = e("./GenericWorker"), f = e("../base64"), n = e("../support"), a = e("../external"), o = null; if (n.nodestream) try { o = e("../nodejs/NodejsStreamOutputAdapter") } catch (e) { } function u(e, t, r) { var n = t; switch (t) { case "blob": case "arraybuffer": n = "uint8array"; break; case "base64": n = "string" }try { this._internalType = n, this._outputType = t, this._mimeType = r, h.checkSupport(n), this._worker = e.pipe(new i(n)), e.lock() } catch (e) { this._worker = new s("error"), this._worker.error(e) } } u.prototype = { accumulate: function (e) { return o = this, u = e, new a.Promise(function (t, r) { var n = [], i = o._internalType, s = o._outputType, a = o._mimeType; o.on("data", function (e, t) { n.push(e), u && u(t) }).on("error", function (e) { n = [], r(e) }).on("end", function () { try { var e = function (e, t, r) { switch (e) { case "blob": return h.newBlob(h.transformTo("arraybuffer", t), r); case "base64": return f.encode(t); default: return h.transformTo(e, t) } }(s, function (e, t) { var r, n = 0, i = null, s = 0; for (r = 0; r < t.length; r++)s += t[r].length; switch (e) { case "string": return t.join(""); case "array": return Array.prototype.concat.apply([], t); case "uint8array": for (i = new Uint8Array(s), r = 0; r < t.length; r++)i.set(t[r], n), n += t[r].length; return i; case "nodebuffer": return Buffer.concat(t); default: throw new Error("concat : unsupported type '" + e + "'") } }(i, n), a); t(e) } catch (e) { r(e) } n = [] }).resume() }); var o, u }, on: function (e, t) { var r = this; return "data" === e ? this._worker.on(e, function (e) { t.call(r, e.data, e.meta) }) : this._worker.on(e, function () { h.delay(t, arguments, r) }), this }, resume: function () { return h.delay(this._worker.resume, [], this._worker), this }, pause: function () { return this._worker.pause(), this }, toNodejsStream: function (e) { if (h.checkSupport("nodestream"), "nodebuffer" !== this._outputType) throw new Error(this._outputType + " is not supported by this method"); return new o(this, { objectMode: "nodebuffer" !== this._outputType }, e) } }, t.exports = u }, { "../base64": 1, "../external": 6, "../nodejs/NodejsStreamOutputAdapter": 13, "../support": 30, "../utils": 32, "./ConvertWorker": 24, "./GenericWorker": 28 }], 30: [function (e, t, r) { "use strict"; if (r.base64 = !0, r.array = !0, r.string = !0, r.arraybuffer = "undefined" != typeof ArrayBuffer && "undefined" != typeof Uint8Array, r.nodebuffer = "undefined" != typeof Buffer, r.uint8array = "undefined" != typeof Uint8Array, "undefined" == typeof ArrayBuffer) r.blob = !1; else { var n = new ArrayBuffer(0); try { r.blob = 0 === new Blob([n], { type: "application/zip" }).size } catch (e) { try { var i = new (self.BlobBuilder || self.WebKitBlobBuilder || self.MozBlobBuilder || self.MSBlobBuilder); i.append(n), r.blob = 0 === i.getBlob("application/zip").size } catch (e) { r.blob = !1 } } } try { r.nodestream = !!e("readable-stream").Readable } catch (e) { r.nodestream = !1 } }, { "readable-stream": 16 }], 31: [function (e, t, s) { "use strict"; for (var o = e("./utils"), u = e("./support"), r = e("./nodejsUtils"), n = e("./stream/GenericWorker"), h = new Array(256), i = 0; i < 256; i++)h[i] = 252 <= i ? 6 : 248 <= i ? 5 : 240 <= i ? 4 : 224 <= i ? 3 : 192 <= i ? 2 : 1; function a() { n.call(this, "utf-8 decode"), this.leftOver = null } function f() { n.call(this, "utf-8 encode") } h[254] = h[254] = 1, s.utf8encode = function (e) { return u.nodebuffer ? r.newBufferFrom(e, "utf-8") : function (e) { var t, r, n, i, s, a = e.length, o = 0; for (i = 0; i < a; i++)55296 == (64512 & (r = e.charCodeAt(i))) && i + 1 < a && 56320 == (64512 & (n = e.charCodeAt(i + 1))) && (r = 65536 + (r - 55296 << 10) + (n - 56320), i++), o += r < 128 ? 1 : r < 2048 ? 2 : r < 65536 ? 3 : 4; for (t = u.uint8array ? new Uint8Array(o) : new Array(o), i = s = 0; s < o; i++)55296 == (64512 & (r = e.charCodeAt(i))) && i + 1 < a && 56320 == (64512 & (n = e.charCodeAt(i + 1))) && (r = 65536 + (r - 55296 << 10) + (n - 56320), i++), r < 128 ? t[s++] = r : (r < 2048 ? t[s++] = 192 | r >>> 6 : (r < 65536 ? t[s++] = 224 | r >>> 12 : (t[s++] = 240 | r >>> 18, t[s++] = 128 | r >>> 12 & 63), t[s++] = 128 | r >>> 6 & 63), t[s++] = 128 | 63 & r); return t }(e) }, s.utf8decode = function (e) { return u.nodebuffer ? o.transformTo("nodebuffer", e).toString("utf-8") : function (e) { var t, r, n, i, s = e.length, a = new Array(2 * s); for (t = r = 0; t < s;)if ((n = e[t++]) < 128) a[r++] = n; else if (4 < (i = h[n])) a[r++] = 65533, t += i - 1; else { for (n &= 2 === i ? 31 : 3 === i ? 15 : 7; 1 < i && t < s;)n = n << 6 | 63 & e[t++], i--; 1 < i ? a[r++] = 65533 : n < 65536 ? a[r++] = n : (n -= 65536, a[r++] = 55296 | n >> 10 & 1023, a[r++] = 56320 | 1023 & n) } return a.length !== r && (a.subarray ? a = a.subarray(0, r) : a.length = r), o.applyFromCharCode(a) }(e = o.transformTo(u.uint8array ? "uint8array" : "array", e)) }, o.inherits(a, n), a.prototype.processChunk = function (e) { var t = o.transformTo(u.uint8array ? "uint8array" : "array", e.data); if (this.leftOver && this.leftOver.length) { if (u.uint8array) { var r = t; (t = new Uint8Array(r.length + this.leftOver.length)).set(this.leftOver, 0), t.set(r, this.leftOver.length) } else t = this.leftOver.concat(t); this.leftOver = null } var n = function (e, t) { var r; for ((t = t || e.length) > e.length && (t = e.length), r = t - 1; 0 <= r && 128 == (192 & e[r]);)r--; return r < 0 ? t : 0 === r ? t : r + h[e[r]] > t ? r : t }(t), i = t; n !== t.length && (u.uint8array ? (i = t.subarray(0, n), this.leftOver = t.subarray(n, t.length)) : (i = t.slice(0, n), this.leftOver = t.slice(n, t.length))), this.push({ data: s.utf8decode(i), meta: e.meta }) }, a.prototype.flush = function () { this.leftOver && this.leftOver.length && (this.push({ data: s.utf8decode(this.leftOver), meta: {} }), this.leftOver = null) }, s.Utf8DecodeWorker = a, o.inherits(f, n), f.prototype.processChunk = function (e) { this.push({ data: s.utf8encode(e.data), meta: e.meta }) }, s.Utf8EncodeWorker = f }, { "./nodejsUtils": 14, "./stream/GenericWorker": 28, "./support": 30, "./utils": 32 }], 32: [function (e, t, o) { "use strict"; var u = e("./support"), h = e("./base64"), r = e("./nodejsUtils"), n = e("set-immediate-shim"), f = e("./external"); function i(e) { return e } function l(e, t) { for (var r = 0; r < e.length; ++r)t[r] = 255 & e.charCodeAt(r); return t } o.newBlob = function (t, r) { o.checkSupport("blob"); try { return new Blob([t], { type: r }) } catch (e) { try { var n = new (self.BlobBuilder || self.WebKitBlobBuilder || self.MozBlobBuilder || self.MSBlobBuilder); return n.append(t), n.getBlob(r) } catch (e) { throw new Error("Bug : can't construct the Blob.") } } }; var s = { stringifyByChunk: function (e, t, r) { var n = [], i = 0, s = e.length; if (s <= r) return String.fromCharCode.apply(null, e); for (; i < s;)"array" === t || "nodebuffer" === t ? n.push(String.fromCharCode.apply(null, e.slice(i, Math.min(i + r, s)))) : n.push(String.fromCharCode.apply(null, e.subarray(i, Math.min(i + r, s)))), i += r; return n.join("") }, stringifyByChar: function (e) { for (var t = "", r = 0; r < e.length; r++)t += String.fromCharCode(e[r]); return t }, applyCanBeUsed: { uint8array: function () { try { return u.uint8array && 1 === String.fromCharCode.apply(null, new Uint8Array(1)).length } catch (e) { return !1 } }(), nodebuffer: function () { try { return u.nodebuffer && 1 === String.fromCharCode.apply(null, r.allocBuffer(1)).length } catch (e) { return !1 } }() } }; function a(e) { var t = 65536, r = o.getTypeOf(e), n = !0; if ("uint8array" === r ? n = s.applyCanBeUsed.uint8array : "nodebuffer" === r && (n = s.applyCanBeUsed.nodebuffer), n) for (; 1 < t;)try { return s.stringifyByChunk(e, r, t) } catch (e) { t = Math.floor(t / 2) } return s.stringifyByChar(e) } function d(e, t) { for (var r = 0; r < e.length; r++)t[r] = e[r]; return t } o.applyFromCharCode = a; var c = {}; c.string = { string: i, array: function (e) { return l(e, new Array(e.length)) }, arraybuffer: function (e) { return c.string.uint8array(e).buffer }, uint8array: function (e) { return l(e, new Uint8Array(e.length)) }, nodebuffer: function (e) { return l(e, r.allocBuffer(e.length)) } }, c.array = { string: a, array: i, arraybuffer: function (e) { return new Uint8Array(e).buffer }, uint8array: function (e) { return new Uint8Array(e) }, nodebuffer: function (e) { return r.newBufferFrom(e) } }, c.arraybuffer = { string: function (e) { return a(new Uint8Array(e)) }, array: function (e) { return d(new Uint8Array(e), new Array(e.byteLength)) }, arraybuffer: i, uint8array: function (e) { return new Uint8Array(e) }, nodebuffer: function (e) { return r.newBufferFrom(new Uint8Array(e)) } }, c.uint8array = { string: a, array: function (e) { return d(e, new Array(e.length)) }, arraybuffer: function (e) { return e.buffer }, uint8array: i, nodebuffer: function (e) { return r.newBufferFrom(e) } }, c.nodebuffer = { string: a, array: function (e) { return d(e, new Array(e.length)) }, arraybuffer: function (e) { return c.nodebuffer.uint8array(e).buffer }, uint8array: function (e) { return d(e, new Uint8Array(e.length)) }, nodebuffer: i }, o.transformTo = function (e, t) { if (t = t || "", !e) return t; o.checkSupport(e); var r = o.getTypeOf(t); return c[r][e](t) }, o.getTypeOf = function (e) { return "string" == typeof e ? "string" : "[object Array]" === Object.prototype.toString.call(e) ? "array" : u.nodebuffer && r.isBuffer(e) ? "nodebuffer" : u.uint8array && e instanceof Uint8Array ? "uint8array" : u.arraybuffer && e instanceof ArrayBuffer ? "arraybuffer" : void 0 }, o.checkSupport = function (e) { if (!u[e.toLowerCase()]) throw new Error(e + " is not supported by this platform") }, o.MAX_VALUE_16BITS = 65535, o.MAX_VALUE_32BITS = -1, o.pretty = function (e) { var t, r, n = ""; for (r = 0; r < (e || "").length; r++)n += "\\x" + ((t = e.charCodeAt(r)) < 16 ? "0" : "") + t.toString(16).toUpperCase(); return n }, o.delay = function (e, t, r) { n(function () { e.apply(r || null, t || []) }) }, o.inherits = function (e, t) { function r() { } r.prototype = t.prototype, e.prototype = new r }, o.extend = function () { var e, t, r = {}; for (e = 0; e < arguments.length; e++)for (t in arguments[e]) arguments[e].hasOwnProperty(t) && void 0 === r[t] && (r[t] = arguments[e][t]); return r }, o.prepareContent = function (n, e, i, s, a) { return f.Promise.resolve(e).then(function (n) { return u.blob && (n instanceof Blob || -1 !== ["[object File]", "[object Blob]"].indexOf(Object.prototype.toString.call(n))) && "undefined" != typeof FileReader ? new f.Promise(function (t, r) { var e = new FileReader; e.onload = function (e) { t(e.target.result) }, e.onerror = function (e) { r(e.target.error) }, e.readAsArrayBuffer(n) }) : n }).then(function (e) { var t, r = o.getTypeOf(e); return r ? ("arraybuffer" === r ? e = o.transformTo("uint8array", e) : "string" === r && (a ? e = h.decode(e) : i && !0 !== s && (e = l(t = e, u.uint8array ? new Uint8Array(t.length) : new Array(t.length)))), e) : f.Promise.reject(new Error("Can't read the data of '" + n + "'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?")) }) } }, { "./base64": 1, "./external": 6, "./nodejsUtils": 14, "./support": 30, "set-immediate-shim": 54 }], 33: [function (e, t, r) { "use strict"; var n = e("./reader/readerFor"), i = e("./utils"), s = e("./signature"), a = e("./zipEntry"), o = (e("./utf8"), e("./support")); function u(e) { this.files = [], this.loadOptions = e } u.prototype = { checkSignature: function (e) { if (!this.reader.readAndCheckSignature(e)) { this.reader.index -= 4; var t = this.reader.readString(4); throw new Error("Corrupted zip or bug: unexpected signature (" + i.pretty(t) + ", expected " + i.pretty(e) + ")") } }, isSignature: function (e, t) { var r = this.reader.index; this.reader.setIndex(e); var n = this.reader.readString(4) === t; return this.reader.setIndex(r), n }, readBlockEndOfCentral: function () { this.diskNumber = this.reader.readInt(2), this.diskWithCentralDirStart = this.reader.readInt(2), this.centralDirRecordsOnThisDisk = this.reader.readInt(2), this.centralDirRecords = this.reader.readInt(2), this.centralDirSize = this.reader.readInt(4), this.centralDirOffset = this.reader.readInt(4), this.zipCommentLength = this.reader.readInt(2); var e = this.reader.readData(this.zipCommentLength), t = o.uint8array ? "uint8array" : "array", r = i.transformTo(t, e); this.zipComment = this.loadOptions.decodeFileName(r) }, readBlockZip64EndOfCentral: function () { this.zip64EndOfCentralSize = this.reader.readInt(8), this.reader.skip(4), this.diskNumber = this.reader.readInt(4), this.diskWithCentralDirStart = this.reader.readInt(4), this.centralDirRecordsOnThisDisk = this.reader.readInt(8), this.centralDirRecords = this.reader.readInt(8), this.centralDirSize = this.reader.readInt(8), this.centralDirOffset = this.reader.readInt(8), this.zip64ExtensibleData = {}; for (var e, t, r, n = this.zip64EndOfCentralSize - 44; 0 < n;)e = this.reader.readInt(2), t = this.reader.readInt(4), r = this.reader.readData(t), this.zip64ExtensibleData[e] = { id: e, length: t, value: r } }, readBlockZip64EndOfCentralLocator: function () { if (this.diskWithZip64CentralDirStart = this.reader.readInt(4), this.relativeOffsetEndOfZip64CentralDir = this.reader.readInt(8), this.disksCount = this.reader.readInt(4), 1 < this.disksCount) throw new Error("Multi-volumes zip are not supported") }, readLocalFiles: function () { var e, t; for (e = 0; e < this.files.length; e++)t = this.files[e], this.reader.setIndex(t.localHeaderOffset), this.checkSignature(s.LOCAL_FILE_HEADER), t.readLocalPart(this.reader), t.handleUTF8(), t.processAttributes() }, readCentralDir: function () { var e; for (this.reader.setIndex(this.centralDirOffset); this.reader.readAndCheckSignature(s.CENTRAL_FILE_HEADER);)(e = new a({ zip64: this.zip64 }, this.loadOptions)).readCentralPart(this.reader), this.files.push(e); if (this.centralDirRecords !== this.files.length && 0 !== this.centralDirRecords && 0 === this.files.length) throw new Error("Corrupted zip or bug: expected " + this.centralDirRecords + " records in central dir, got " + this.files.length) }, readEndOfCentral: function () { var e = this.reader.lastIndexOfSignature(s.CENTRAL_DIRECTORY_END); if (e < 0) throw this.isSignature(0, s.LOCAL_FILE_HEADER) ? new Error("Corrupted zip: can't find end of central directory") : 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"); this.reader.setIndex(e); var t = e; if (this.checkSignature(s.CENTRAL_DIRECTORY_END), this.readBlockEndOfCentral(), this.diskNumber === i.MAX_VALUE_16BITS || this.diskWithCentralDirStart === i.MAX_VALUE_16BITS || this.centralDirRecordsOnThisDisk === i.MAX_VALUE_16BITS || this.centralDirRecords === i.MAX_VALUE_16BITS || this.centralDirSize === i.MAX_VALUE_32BITS || this.centralDirOffset === i.MAX_VALUE_32BITS) { if (this.zip64 = !0, (e = this.reader.lastIndexOfSignature(s.ZIP64_CENTRAL_DIRECTORY_LOCATOR)) < 0) throw new Error("Corrupted zip: can't find the ZIP64 end of central directory locator"); if (this.reader.setIndex(e), this.checkSignature(s.ZIP64_CENTRAL_DIRECTORY_LOCATOR), this.readBlockZip64EndOfCentralLocator(), !this.isSignature(this.relativeOffsetEndOfZip64CentralDir, s.ZIP64_CENTRAL_DIRECTORY_END) && (this.relativeOffsetEndOfZip64CentralDir = this.reader.lastIndexOfSignature(s.ZIP64_CENTRAL_DIRECTORY_END), this.relativeOffsetEndOfZip64CentralDir < 0)) throw new Error("Corrupted zip: can't find the ZIP64 end of central directory"); this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir), this.checkSignature(s.ZIP64_CENTRAL_DIRECTORY_END), this.readBlockZip64EndOfCentral() } var r = this.centralDirOffset + this.centralDirSize; this.zip64 && (r += 20, r += 12 + this.zip64EndOfCentralSize); var n = t - r; if (0 < n) this.isSignature(t, s.CENTRAL_FILE_HEADER) || (this.reader.zero = n); else if (n < 0) throw new Error("Corrupted zip: missing " + Math.abs(n) + " bytes.") }, prepareReader: function (e) { this.reader = n(e) }, load: function (e) { this.prepareReader(e), this.readEndOfCentral(), this.readCentralDir(), this.readLocalFiles() } }, t.exports = u }, { "./reader/readerFor": 22, "./signature": 23, "./support": 30, "./utf8": 31, "./utils": 32, "./zipEntry": 34 }], 34: [function (e, t, r) { "use strict"; var n = e("./reader/readerFor"), s = e("./utils"), i = e("./compressedObject"), a = e("./crc32"), o = e("./utf8"), u = e("./compressions"), h = e("./support"); function f(e, t) { this.options = e, this.loadOptions = t } f.prototype = { isEncrypted: function () { return 1 == (1 & this.bitFlag) }, useUTF8: function () { return 2048 == (2048 & this.bitFlag) }, readLocalPart: function (e) { var t, r; if (e.skip(22), this.fileNameLength = e.readInt(2), r = e.readInt(2), this.fileName = e.readData(this.fileNameLength), e.skip(r), -1 === this.compressedSize || -1 === this.uncompressedSize) throw new Error("Bug or corrupted zip : didn't get enough information from the central directory (compressedSize === -1 || uncompressedSize === -1)"); if (null === (t = function (e) { for (var t in u) if (u.hasOwnProperty(t) && u[t].magic === e) return u[t]; return null }(this.compressionMethod))) throw new Error("Corrupted zip : compression " + s.pretty(this.compressionMethod) + " unknown (inner file : " + s.transformTo("string", this.fileName) + ")"); this.decompressed = new i(this.compressedSize, this.uncompressedSize, this.crc32, t, e.readData(this.compressedSize)) }, readCentralPart: function (e) { this.versionMadeBy = e.readInt(2), e.skip(2), this.bitFlag = e.readInt(2), this.compressionMethod = e.readString(2), this.date = e.readDate(), this.crc32 = e.readInt(4), this.compressedSize = e.readInt(4), this.uncompressedSize = e.readInt(4); var t = e.readInt(2); if (this.extraFieldsLength = e.readInt(2), this.fileCommentLength = e.readInt(2), this.diskNumberStart = e.readInt(2), this.internalFileAttributes = e.readInt(2), this.externalFileAttributes = e.readInt(4), this.localHeaderOffset = e.readInt(4), this.isEncrypted()) throw new Error("Encrypted zip are not supported"); e.skip(t), this.readExtraFields(e), this.parseZIP64ExtraField(e), this.fileComment = e.readData(this.fileCommentLength) }, processAttributes: function () { this.unixPermissions = null, this.dosPermissions = null; var e = this.versionMadeBy >> 8; this.dir = !!(16 & this.externalFileAttributes), 0 == e && (this.dosPermissions = 63 & this.externalFileAttributes), 3 == e && (this.unixPermissions = this.externalFileAttributes >> 16 & 65535), this.dir || "/" !== this.fileNameStr.slice(-1) || (this.dir = !0) }, parseZIP64ExtraField: function (e) { if (this.extraFields[1]) { var t = n(this.extraFields[1].value); this.uncompressedSize === s.MAX_VALUE_32BITS && (this.uncompressedSize = t.readInt(8)), this.compressedSize === s.MAX_VALUE_32BITS && (this.compressedSize = t.readInt(8)), this.localHeaderOffset === s.MAX_VALUE_32BITS && (this.localHeaderOffset = t.readInt(8)), this.diskNumberStart === s.MAX_VALUE_32BITS && (this.diskNumberStart = t.readInt(4)) } }, readExtraFields: function (e) { var t, r, n, i = e.index + this.extraFieldsLength; for (this.extraFields || (this.extraFields = {}); e.index + 4 < i;)t = e.readInt(2), r = e.readInt(2), n = e.readData(r), this.extraFields[t] = { id: t, length: r, value: n }; e.setIndex(i) }, handleUTF8: function () { var e = h.uint8array ? "uint8array" : "array"; if (this.useUTF8()) this.fileNameStr = o.utf8decode(this.fileName), this.fileCommentStr = o.utf8decode(this.fileComment); else { var t = this.findExtraFieldUnicodePath(); if (null !== t) this.fileNameStr = t; else { var r = s.transformTo(e, this.fileName); this.fileNameStr = this.loadOptions.decodeFileName(r) } var n = this.findExtraFieldUnicodeComment(); if (null !== n) this.fileCommentStr = n; else { var i = s.transformTo(e, this.fileComment); this.fileCommentStr = this.loadOptions.decodeFileName(i) } } }, findExtraFieldUnicodePath: function () { var e = this.extraFields[28789]; if (e) { var t = n(e.value); return 1 !== t.readInt(1) ? null : a(this.fileName) !== t.readInt(4) ? null : o.utf8decode(t.readData(e.length - 5)) } return null }, findExtraFieldUnicodeComment: function () { var e = this.extraFields[25461]; if (e) { var t = n(e.value); return 1 !== t.readInt(1) ? null : a(this.fileComment) !== t.readInt(4) ? null : o.utf8decode(t.readData(e.length - 5)) } return null } }, t.exports = f }, { "./compressedObject": 2, "./compressions": 3, "./crc32": 4, "./reader/readerFor": 22, "./support": 30, "./utf8": 31, "./utils": 32 }], 35: [function (e, t, r) { "use strict"; function n(e, t, r) { this.name = e, this.dir = r.dir, this.date = r.date, this.comment = r.comment, this.unixPermissions = r.unixPermissions, this.dosPermissions = r.dosPermissions, this._data = t, this._dataBinary = r.binary, this.options = { compression: r.compression, compressionOptions: r.compressionOptions } } var s = e("./stream/StreamHelper"), i = e("./stream/DataWorker"), a = e("./utf8"), o = e("./compressedObject"), u = e("./stream/GenericWorker"); n.prototype = { internalStream: function (e) { var t = null, r = "string"; try { if (!e) throw new Error("No output type specified."); var n = "string" === (r = e.toLowerCase()) || "text" === r; "binarystring" !== r && "text" !== r || (r = "string"), t = this._decompressWorker(); var i = !this._dataBinary; i && !n && (t = t.pipe(new a.Utf8EncodeWorker)), !i && n && (t = t.pipe(new a.Utf8DecodeWorker)) } catch (e) { (t = new u("error")).error(e) } return new s(t, r, "") }, async: function (e, t) { return this.internalStream(e).accumulate(t) }, nodeStream: function (e, t) { return this.internalStream(e || "nodebuffer").toNodejsStream(t) }, _compressWorker: function (e, t) { if (this._data instanceof o && this._data.compression.magic === e.magic) return this._data.getCompressedWorker(); var r = this._decompressWorker(); return this._dataBinary || (r = r.pipe(new a.Utf8EncodeWorker)), o.createWorkerFrom(r, e, t) }, _decompressWorker: function () { return this._data instanceof o ? this._data.getContentWorker() : this._data instanceof u ? this._data : new i(this._data) } }; for (var h = ["asText", "asBinary", "asNodeBuffer", "asUint8Array", "asArrayBuffer"], f = function () { throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.") }, l = 0; l < h.length; l++)n.prototype[h[l]] = f; t.exports = n }, { "./compressedObject": 2, "./stream/DataWorker": 27, "./stream/GenericWorker": 28, "./stream/StreamHelper": 29, "./utf8": 31 }], 36: [function (e, f, t) { (function (t) { "use strict"; var r, n, e = t.MutationObserver || t.WebKitMutationObserver; if (e) { var i = 0, s = new e(h), a = t.document.createTextNode(""); s.observe(a, { characterData: !0 }), r = function () { a.data = i = ++i % 2 } } else if (t.setImmediate || void 0 === t.MessageChannel) r = "document" in t && "onreadystatechange" in t.document.createElement("script") ? function () { var e = t.document.createElement("script"); e.onreadystatechange = function () { h(), e.onreadystatechange = null, e.parentNode.removeChild(e), e = null }, t.document.documentElement.appendChild(e) } : function () { setTimeout(h, 0) }; else { var o = new t.MessageChannel; o.port1.onmessage = h, r = function () { o.port2.postMessage(0) } } var u = []; function h() { var e, t; n = !0; for (var r = u.length; r;) { for (t = u, u = [], e = -1; ++e < r;)t[e](); r = u.length } n = !1 } f.exports = function (e) { 1 !== u.push(e) || n || r() } }).call(this, void 0 !== r ? r : "undefined" != typeof self ? self : "undefined" != typeof window ? window : {}) }, {}], 37: [function (e, t, r) { "use strict"; var i = e("immediate"); function h() { } var f = {}, s = ["REJECTED"], a = ["FULFILLED"], n = ["PENDING"]; function o(e) { if ("function" != typeof e) throw new TypeError("resolver must be a function"); this.state = n, this.queue = [], this.outcome = void 0, e !== h && c(this, e) } function u(e, t, r) { this.promise = e, "function" == typeof t && (this.onFulfilled = t, this.callFulfilled = this.otherCallFulfilled), "function" == typeof r && (this.onRejected = r, this.callRejected = this.otherCallRejected) } function l(t, r, n) { i(function () { var e; try { e = r(n) } catch (e) { return f.reject(t, e) } e === t ? f.reject(t, new TypeError("Cannot resolve promise with itself")) : f.resolve(t, e) }) } function d(e) { var t = e && e.then; if (e && ("object" == typeof e || "function" == typeof e) && "function" == typeof t) return function () { t.apply(e, arguments) } } function c(t, e) { var r = !1; function n(e) { r || (r = !0, f.reject(t, e)) } function i(e) { r || (r = !0, f.resolve(t, e)) } var s = p(function () { e(i, n) }); "error" === s.status && n(s.value) } function p(e, t) { var r = {}; try { r.value = e(t), r.status = "success" } catch (e) { r.status = "error", r.value = e } return r } (t.exports = o).prototype.finally = function (t) { if ("function" != typeof t) return this; var r = this.constructor; return this.then(function (e) { return r.resolve(t()).then(function () { return e }) }, function (e) { return r.resolve(t()).then(function () { throw e }) }) }, o.prototype.catch = function (e) { return this.then(null, e) }, o.prototype.then = function (e, t) { if ("function" != typeof e && this.state === a || "function" != typeof t && this.state === s) return this; var r = new this.constructor(h); return this.state !== n ? l(r, this.state === a ? e : t, this.outcome) : this.queue.push(new u(r, e, t)), r }, u.prototype.callFulfilled = function (e) { f.resolve(this.promise, e) }, u.prototype.otherCallFulfilled = function (e) { l(this.promise, this.onFulfilled, e) }, u.prototype.callRejected = function (e) { f.reject(this.promise, e) }, u.prototype.otherCallRejected = function (e) { l(this.promise, this.onRejected, e) }, f.resolve = function (e, t) { var r = p(d, t); if ("error" === r.status) return f.reject(e, r.value); var n = r.value; if (n) c(e, n); else { e.state = a, e.outcome = t; for (var i = -1, s = e.queue.length; ++i < s;)e.queue[i].callFulfilled(t) } return e }, f.reject = function (e, t) { e.state = s, e.outcome = t; for (var r = -1, n = e.queue.length; ++r < n;)e.queue[r].callRejected(t); return e }, o.resolve = function (e) { return e instanceof this ? e : f.resolve(new this(h), e) }, o.reject = function (e) { var t = new this(h); return f.reject(t, e) }, o.all = function (e) { var r = this; if ("[object Array]" !== Object.prototype.toString.call(e)) return this.reject(new TypeError("must be an array")); var n = e.length, i = !1; if (!n) return this.resolve([]); for (var s = new Array(n), a = 0, t = -1, o = new this(h); ++t < n;)u(e[t], t); return o; function u(e, t) { r.resolve(e).then(function (e) { s[t] = e, ++a !== n || i || (i = !0, f.resolve(o, s)) }, function (e) { i || (i = !0, f.reject(o, e)) }) } }, o.race = function (e) { if ("[object Array]" !== Object.prototype.toString.call(e)) return this.reject(new TypeError("must be an array")); var t = e.length, r = !1; if (!t) return this.resolve([]); for (var n, i = -1, s = new this(h); ++i < t;)n = e[i], this.resolve(n).then(function (e) { r || (r = !0, f.resolve(s, e)) }, function (e) { r || (r = !0, f.reject(s, e)) }); return s } }, { immediate: 36 }], 38: [function (e, t, r) { "use strict"; var n = {}; (0, e("./lib/utils/common").assign)(n, e("./lib/deflate"), e("./lib/inflate"), e("./lib/zlib/constants")), t.exports = n }, { "./lib/deflate": 39, "./lib/inflate": 40, "./lib/utils/common": 41, "./lib/zlib/constants": 44 }], 39: [function (e, t, r) { "use strict"; var a = e("./zlib/deflate"), o = e("./utils/common"), u = e("./utils/strings"), i = e("./zlib/messages"), s = e("./zlib/zstream"), h = Object.prototype.toString, f = 0, l = -1, d = 0, c = 8; function p(e) { if (!(this instanceof p)) return new p(e); this.options = o.assign({ level: l, method: c, chunkSize: 16384, windowBits: 15, memLevel: 8, strategy: d, to: "" }, e || {}); var t = this.options; t.raw && 0 < t.windowBits ? t.windowBits = -t.windowBits : t.gzip && 0 < t.windowBits && t.windowBits < 16 && (t.windowBits += 16), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new s, this.strm.avail_out = 0; var r = a.deflateInit2(this.strm, t.level, t.method, t.windowBits, t.memLevel, t.strategy); if (r !== f) throw new Error(i[r]); if (t.header && a.deflateSetHeader(this.strm, t.header), t.dictionary) { var n; if (n = "string" == typeof t.dictionary ? u.string2buf(t.dictionary) : "[object ArrayBuffer]" === h.call(t.dictionary) ? new Uint8Array(t.dictionary) : t.dictionary, (r = a.deflateSetDictionary(this.strm, n)) !== f) throw new Error(i[r]); this._dict_set = !0 } } function n(e, t) { var r = new p(t); if (r.push(e, !0), r.err) throw r.msg || i[r.err]; return r.result } p.prototype.push = function (e, t) { var r, n, i = this.strm, s = this.options.chunkSize; if (this.ended) return !1; n = t === ~~t ? t : !0 === t ? 4 : 0, "string" == typeof e ? i.input = u.string2buf(e) : "[object ArrayBuffer]" === h.call(e) ? i.input = new Uint8Array(e) : i.input = e, i.next_in = 0, i.avail_in = i.input.length; do { if (0 === i.avail_out && (i.output = new o.Buf8(s), i.next_out = 0, i.avail_out = s), 1 !== (r = a.deflate(i, n)) && r !== f) return this.onEnd(r), !(this.ended = !0); 0 !== i.avail_out && (0 !== i.avail_in || 4 !== n && 2 !== n) || ("string" === this.options.to ? this.onData(u.buf2binstring(o.shrinkBuf(i.output, i.next_out))) : this.onData(o.shrinkBuf(i.output, i.next_out))) } while ((0 < i.avail_in || 0 === i.avail_out) && 1 !== r); return 4 === n ? (r = a.deflateEnd(this.strm), this.onEnd(r), this.ended = !0, r === f) : 2 !== n || (this.onEnd(f), !(i.avail_out = 0)) }, p.prototype.onData = function (e) { this.chunks.push(e) }, p.prototype.onEnd = function (e) { e === f && ("string" === this.options.to ? this.result = this.chunks.join("") : this.result = o.flattenChunks(this.chunks)), this.chunks = [], this.err = e, this.msg = this.strm.msg }, r.Deflate = p, r.deflate = n, r.deflateRaw = function (e, t) { return (t = t || {}).raw = !0, n(e, t) }, r.gzip = function (e, t) { return (t = t || {}).gzip = !0, n(e, t) } }, { "./utils/common": 41, "./utils/strings": 42, "./zlib/deflate": 46, "./zlib/messages": 51, "./zlib/zstream": 53 }], 40: [function (e, t, r) { "use strict"; var d = e("./zlib/inflate"), c = e("./utils/common"), p = e("./utils/strings"), m = e("./zlib/constants"), n = e("./zlib/messages"), i = e("./zlib/zstream"), s = e("./zlib/gzheader"), _ = Object.prototype.toString; function a(e) { if (!(this instanceof a)) return new a(e); this.options = c.assign({ chunkSize: 16384, windowBits: 0, to: "" }, e || {}); var t = this.options; t.raw && 0 <= t.windowBits && t.windowBits < 16 && (t.windowBits = -t.windowBits, 0 === t.windowBits && (t.windowBits = -15)), !(0 <= t.windowBits && t.windowBits < 16) || e && e.windowBits || (t.windowBits += 32), 15 < t.windowBits && t.windowBits < 48 && 0 == (15 & t.windowBits) && (t.windowBits |= 15), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new i, this.strm.avail_out = 0; var r = d.inflateInit2(this.strm, t.windowBits); if (r !== m.Z_OK) throw new Error(n[r]); this.header = new s, d.inflateGetHeader(this.strm, this.header) } function o(e, t) { var r = new a(t); if (r.push(e, !0), r.err) throw r.msg || n[r.err]; return r.result } a.prototype.push = function (e, t) { var r, n, i, s, a, o, u = this.strm, h = this.options.chunkSize, f = this.options.dictionary, l = !1; if (this.ended) return !1; n = t === ~~t ? t : !0 === t ? m.Z_FINISH : m.Z_NO_FLUSH, "string" == typeof e ? u.input = p.binstring2buf(e) : "[object ArrayBuffer]" === _.call(e) ? u.input = new Uint8Array(e) : u.input = e, u.next_in = 0, u.avail_in = u.input.length; do { if (0 === u.avail_out && (u.output = new c.Buf8(h), u.next_out = 0, u.avail_out = h), (r = d.inflate(u, m.Z_NO_FLUSH)) === m.Z_NEED_DICT && f && (o = "string" == typeof f ? p.string2buf(f) : "[object ArrayBuffer]" === _.call(f) ? new Uint8Array(f) : f, r = d.inflateSetDictionary(this.strm, o)), r === m.Z_BUF_ERROR && !0 === l && (r = m.Z_OK, l = !1), r !== m.Z_STREAM_END && r !== m.Z_OK) return this.onEnd(r), !(this.ended = !0); u.next_out && (0 !== u.avail_out && r !== m.Z_STREAM_END && (0 !== u.avail_in || n !== m.Z_FINISH && n !== m.Z_SYNC_FLUSH) || ("string" === this.options.to ? (i = p.utf8border(u.output, u.next_out), s = u.next_out - i, a = p.buf2string(u.output, i), u.next_out = s, u.avail_out = h - s, s && c.arraySet(u.output, u.output, i, s, 0), this.onData(a)) : this.onData(c.shrinkBuf(u.output, u.next_out)))), 0 === u.avail_in && 0 === u.avail_out && (l = !0) } while ((0 < u.avail_in || 0 === u.avail_out) && r !== m.Z_STREAM_END); return r === m.Z_STREAM_END && (n = m.Z_FINISH), n === m.Z_FINISH ? (r = d.inflateEnd(this.strm), this.onEnd(r), this.ended = !0, r === m.Z_OK) : n !== m.Z_SYNC_FLUSH || (this.onEnd(m.Z_OK), !(u.avail_out = 0)) }, a.prototype.onData = function (e) { this.chunks.push(e) }, a.prototype.onEnd = function (e) { e === m.Z_OK && ("string" === this.options.to ? this.result = this.chunks.join("") : this.result = c.flattenChunks(this.chunks)), this.chunks = [], this.err = e, this.msg = this.strm.msg }, r.Inflate = a, r.inflate = o, r.inflateRaw = function (e, t) { return (t = t || {}).raw = !0, o(e, t) }, r.ungzip = o }, { "./utils/common": 41, "./utils/strings": 42, "./zlib/constants": 44, "./zlib/gzheader": 47, "./zlib/inflate": 49, "./zlib/messages": 51, "./zlib/zstream": 53 }], 41: [function (e, t, r) { "use strict"; var n = "undefined" != typeof Uint8Array && "undefined" != typeof Uint16Array && "undefined" != typeof Int32Array; r.assign = function (e) { for (var t = Array.prototype.slice.call(arguments, 1); t.length;) { var r = t.shift(); if (r) { if ("object" != typeof r) throw new TypeError(r + "must be non-object"); for (var n in r) r.hasOwnProperty(n) && (e[n] = r[n]) } } return e }, r.shrinkBuf = function (e, t) { return e.length === t ? e : e.subarray ? e.subarray(0, t) : (e.length = t, e) }; var i = { arraySet: function (e, t, r, n, i) { if (t.subarray && e.subarray) e.set(t.subarray(r, r + n), i); else for (var s = 0; s < n; s++)e[i + s] = t[r + s] }, flattenChunks: function (e) { var t, r, n, i, s, a; for (t = n = 0, r = e.length; t < r; t++)n += e[t].length; for (a = new Uint8Array(n), t = i = 0, r = e.length; t < r; t++)s = e[t], a.set(s, i), i += s.length; return a } }, s = { arraySet: function (e, t, r, n, i) { for (var s = 0; s < n; s++)e[i + s] = t[r + s] }, flattenChunks: function (e) { return [].concat.apply([], e) } }; r.setTyped = function (e) { e ? (r.Buf8 = Uint8Array, r.Buf16 = Uint16Array, r.Buf32 = Int32Array, r.assign(r, i)) : (r.Buf8 = Array, r.Buf16 = Array, r.Buf32 = Array, r.assign(r, s)) }, r.setTyped(n) }, {}], 42: [function (e, t, r) { "use strict"; var u = e("./common"), i = !0, s = !0; try { String.fromCharCode.apply(null, [0]) } catch (e) { i = !1 } try { String.fromCharCode.apply(null, new Uint8Array(1)) } catch (e) { s = !1 } for (var h = new u.Buf8(256), n = 0; n < 256; n++)h[n] = 252 <= n ? 6 : 248 <= n ? 5 : 240 <= n ? 4 : 224 <= n ? 3 : 192 <= n ? 2 : 1; function f(e, t) { if (t < 65537 && (e.subarray && s || !e.subarray && i)) return String.fromCharCode.apply(null, u.shrinkBuf(e, t)); for (var r = "", n = 0; n < t; n++)r += String.fromCharCode(e[n]); return r } h[254] = h[254] = 1, r.string2buf = function (e) { var t, r, n, i, s, a = e.length, o = 0; for (i = 0; i < a; i++)55296 == (64512 & (r = e.charCodeAt(i))) && i + 1 < a && 56320 == (64512 & (n = e.charCodeAt(i + 1))) && (r = 65536 + (r - 55296 << 10) + (n - 56320), i++), o += r < 128 ? 1 : r < 2048 ? 2 : r < 65536 ? 3 : 4; for (t = new u.Buf8(o), i = s = 0; s < o; i++)55296 == (64512 & (r = e.charCodeAt(i))) && i + 1 < a && 56320 == (64512 & (n = e.charCodeAt(i + 1))) && (r = 65536 + (r - 55296 << 10) + (n - 56320), i++), r < 128 ? t[s++] = r : (r < 2048 ? t[s++] = 192 | r >>> 6 : (r < 65536 ? t[s++] = 224 | r >>> 12 : (t[s++] = 240 | r >>> 18, t[s++] = 128 | r >>> 12 & 63), t[s++] = 128 | r >>> 6 & 63), t[s++] = 128 | 63 & r); return t }, r.buf2binstring = function (e) { return f(e, e.length) }, r.binstring2buf = function (e) { for (var t = new u.Buf8(e.length), r = 0, n = t.length; r < n; r++)t[r] = e.charCodeAt(r); return t }, r.buf2string = function (e, t) { var r, n, i, s, a = t || e.length, o = new Array(2 * a); for (r = n = 0; r < a;)if ((i = e[r++]) < 128) o[n++] = i; else if (4 < (s = h[i])) o[n++] = 65533, r += s - 1; else { for (i &= 2 === s ? 31 : 3 === s ? 15 : 7; 1 < s && r < a;)i = i << 6 | 63 & e[r++], s--; 1 < s ? o[n++] = 65533 : i < 65536 ? o[n++] = i : (i -= 65536, o[n++] = 55296 | i >> 10 & 1023, o[n++] = 56320 | 1023 & i) } return f(o, n) }, r.utf8border = function (e, t) { var r; for ((t = t || e.length) > e.length && (t = e.length), r = t - 1; 0 <= r && 128 == (192 & e[r]);)r--; return r < 0 ? t : 0 === r ? t : r + h[e[r]] > t ? r : t } }, { "./common": 41 }], 43: [function (e, t, r) { "use strict"; t.exports = function (e, t, r, n) { for (var i = 65535 & e | 0, s = e >>> 16 & 65535 | 0, a = 0; 0 !== r;) { for (r -= a = 2e3 < r ? 2e3 : r; s = s + (i = i + t[n++] | 0) | 0, --a;); i %= 65521, s %= 65521 } return i | s << 16 | 0 } }, {}], 44: [function (e, t, r) { "use strict"; t.exports = { Z_NO_FLUSH: 0, Z_PARTIAL_FLUSH: 1, Z_SYNC_FLUSH: 2, Z_FULL_FLUSH: 3, Z_FINISH: 4, Z_BLOCK: 5, Z_TREES: 6, Z_OK: 0, Z_STREAM_END: 1, Z_NEED_DICT: 2, Z_ERRNO: -1, Z_STREAM_ERROR: -2, Z_DATA_ERROR: -3, Z_BUF_ERROR: -5, Z_NO_COMPRESSION: 0, Z_BEST_SPEED: 1, Z_BEST_COMPRESSION: 9, Z_DEFAULT_COMPRESSION: -1, Z_FILTERED: 1, Z_HUFFMAN_ONLY: 2, Z_RLE: 3, Z_FIXED: 4, Z_DEFAULT_STRATEGY: 0, Z_BINARY: 0, Z_TEXT: 1, Z_UNKNOWN: 2, Z_DEFLATED: 8 } }, {}], 45: [function (e, t, r) { "use strict"; var o = function () { for (var e, t = [], r = 0; r < 256; r++) { e = r; for (var n = 0; n < 8; n++)e = 1 & e ? 3988292384 ^ e >>> 1 : e >>> 1; t[r] = e } return t }(); t.exports = function (e, t, r, n) { var i = o, s = n + r; e ^= -1; for (var a = n; a < s; a++)e = e >>> 8 ^ i[255 & (e ^ t[a])]; return -1 ^ e } }, {}], 46: [function (e, t, r) { "use strict"; var u, d = e("../utils/common"), h = e("./trees"), c = e("./adler32"), p = e("./crc32"), n = e("./messages"), f = 0, l = 0, m = -2, i = 2, _ = 8, s = 286, a = 30, o = 19, g = 2 * s + 1, v = 15, b = 3, w = 258, y = w + b + 1, k = 42, x = 113; function S(e, t) { return e.msg = n[t], t } function z(e) { return (e << 1) - (4 < e ? 9 : 0) } function E(e) { for (var t = e.length; 0 <= --t;)e[t] = 0 } function C(e) { var t = e.state, r = t.pending; r > e.avail_out && (r = e.avail_out), 0 !== r && (d.arraySet(e.output, t.pending_buf, t.pending_out, r, e.next_out), e.next_out += r, t.pending_out += r, e.total_out += r, e.avail_out -= r, t.pending -= r, 0 === t.pending && (t.pending_out = 0)) } function A(e, t) { h._tr_flush_block(e, 0 <= e.block_start ? e.block_start : -1, e.strstart - e.block_start, t), e.block_start = e.strstart, C(e.strm) } function I(e, t) { e.pending_buf[e.pending++] = t } function O(e, t) { e.pending_buf[e.pending++] = t >>> 8 & 255, e.pending_buf[e.pending++] = 255 & t } function B(e, t) { var r, n, i = e.max_chain_length, s = e.strstart, a = e.prev_length, o = e.nice_match, u = e.strstart > e.w_size - y ? e.strstart - (e.w_size - y) : 0, h = e.window, f = e.w_mask, l = e.prev, d = e.strstart + w, c = h[s + a - 1], p = h[s + a]; e.prev_length >= e.good_match && (i >>= 2), o > e.lookahead && (o = e.lookahead); do { if (h[(r = t) + a] === p && h[r + a - 1] === c && h[r] === h[s] && h[++r] === h[s + 1]) { s += 2, r++; do { } while (h[++s] === h[++r] && h[++s] === h[++r] && h[++s] === h[++r] && h[++s] === h[++r] && h[++s] === h[++r] && h[++s] === h[++r] && h[++s] === h[++r] && h[++s] === h[++r] && s < d); if (n = w - (d - s), s = d - w, a < n) { if (e.match_start = t, o <= (a = n)) break; c = h[s + a - 1], p = h[s + a] } } } while ((t = l[t & f]) > u && 0 != --i); return a <= e.lookahead ? a : e.lookahead } function T(e) { var t, r, n, i, s, a, o, u, h, f, l = e.w_size; do { if (i = e.window_size - e.lookahead - e.strstart, e.strstart >= l + (l - y)) { for (d.arraySet(e.window, e.window, l, l, 0), e.match_start -= l, e.strstart -= l, e.block_start -= l, t = r = e.hash_size; n = e.head[--t], e.head[t] = l <= n ? n - l : 0, --r;); for (t = r = l; n = e.prev[--t], e.prev[t] = l <= n ? n - l : 0, --r;); i += l } if (0 === e.strm.avail_in) break; if (a = e.strm, o = e.window, u = e.strstart + e.lookahead, f = void 0, (h = i) < (f = a.avail_in) && (f = h), r = 0 === f ? 0 : (a.avail_in -= f, d.arraySet(o, a.input, a.next_in, f, u), 1 === a.state.wrap ? a.adler = c(a.adler, o, f, u) : 2 === a.state.wrap && (a.adler = p(a.adler, o, f, u)), a.next_in += f, a.total_in += f, f), e.lookahead += r, e.lookahead + e.insert >= b) for (s = e.strstart - e.insert, e.ins_h = e.window[s], e.ins_h = (e.ins_h << e.hash_shift ^ e.window[s + 1]) & e.hash_mask; e.insert && (e.ins_h = (e.ins_h << e.hash_shift ^ e.window[s + b - 1]) & e.hash_mask, e.prev[s & e.w_mask] = e.head[e.ins_h], e.head[e.ins_h] = s, s++, e.insert--, !(e.lookahead + e.insert < b));); } while (e.lookahead < y && 0 !== e.strm.avail_in) } function R(e, t) { for (var r, n; ;) { if (e.lookahead < y) { if (T(e), e.lookahead < y && t === f) return 1; if (0 === e.lookahead) break } if (r = 0, e.lookahead >= b && (e.ins_h = (e.ins_h << e.hash_shift ^ e.window[e.strstart + b - 1]) & e.hash_mask, r = e.prev[e.strstart & e.w_mask] = e.head[e.ins_h], e.head[e.ins_h] = e.strstart), 0 !== r && e.strstart - r <= e.w_size - y && (e.match_length = B(e, r)), e.match_length >= b) if (n = h._tr_tally(e, e.strstart - e.match_start, e.match_length - b), e.lookahead -= e.match_length, e.match_length <= e.max_lazy_match && e.lookahead >= b) { for (e.match_length--; e.strstart++, e.ins_h = (e.ins_h << e.hash_shift ^ e.window[e.strstart + b - 1]) & e.hash_mask, r = e.prev[e.strstart & e.w_mask] = e.head[e.ins_h], e.head[e.ins_h] = e.strstart, 0 != --e.match_length;); e.strstart++ } else e.strstart += e.match_length, e.match_length = 0, e.ins_h = e.window[e.strstart], e.ins_h = (e.ins_h << e.hash_shift ^ e.window[e.strstart + 1]) & e.hash_mask; else n = h._tr_tally(e, 0, e.window[e.strstart]), e.lookahead--, e.strstart++; if (n && (A(e, !1), 0 === e.strm.avail_out)) return 1 } return e.insert = e.strstart < b - 1 ? e.strstart : b - 1, 4 === t ? (A(e, !0), 0 === e.strm.avail_out ? 3 : 4) : e.last_lit && (A(e, !1), 0 === e.strm.avail_out) ? 1 : 2 } function D(e, t) { for (var r, n, i; ;) { if (e.lookahead < y) { if (T(e), e.lookahead < y && t === f) return 1; if (0 === e.lookahead) break } if (r = 0, e.lookahead >= b && (e.ins_h = (e.ins_h << e.hash_shift ^ e.window[e.strstart + b - 1]) & e.hash_mask, r = e.prev[e.strstart & e.w_mask] = e.head[e.ins_h], e.head[e.ins_h] = e.strstart), e.prev_length = e.match_length, e.prev_match = e.match_start, e.match_length = b - 1, 0 !== r && e.prev_length < e.max_lazy_match && e.strstart - r <= e.w_size - y && (e.match_length = B(e, r), e.match_length <= 5 && (1 === e.strategy || e.match_length === b && 4096 < e.strstart - e.match_start) && (e.match_length = b - 1)), e.prev_length >= b && e.match_length <= e.prev_length) { for (i = e.strstart + e.lookahead - b, n = h._tr_tally(e, e.strstart - 1 - e.prev_match, e.prev_length - b), e.lookahead -= e.prev_length - 1, e.prev_length -= 2; ++e.strstart <= i && (e.ins_h = (e.ins_h << e.hash_shift ^ e.window[e.strstart + b - 1]) & e.hash_mask, r = e.prev[e.strstart & e.w_mask] = e.head[e.ins_h], e.head[e.ins_h] = e.strstart), 0 != --e.prev_length;); if (e.match_available = 0, e.match_length = b - 1, e.strstart++, n && (A(e, !1), 0 === e.strm.avail_out)) return 1 } else if (e.match_available) { if ((n = h._tr_tally(e, 0, e.window[e.strstart - 1])) && A(e, !1), e.strstart++, e.lookahead--, 0 === e.strm.avail_out) return 1 } else e.match_available = 1, e.strstart++, e.lookahead-- } return e.match_available && (n = h._tr_tally(e, 0, e.window[e.strstart - 1]), e.match_available = 0), e.insert = e.strstart < b - 1 ? e.strstart : b - 1, 4 === t ? (A(e, !0), 0 === e.strm.avail_out ? 3 : 4) : e.last_lit && (A(e, !1), 0 === e.strm.avail_out) ? 1 : 2 } function F(e, t, r, n, i) { this.good_length = e, this.max_lazy = t, this.nice_length = r, this.max_chain = n, this.func = i } function N() { this.strm = null, this.status = 0, this.pending_buf = null, this.pending_buf_size = 0, this.pending_out = 0, this.pending = 0, this.wrap = 0, this.gzhead = null, this.gzindex = 0, this.method = _, this.last_flush = -1, this.w_size = 0, this.w_bits = 0, this.w_mask = 0, this.window = null, this.window_size = 0, this.prev = null, this.head = null, this.ins_h = 0, this.hash_size = 0, this.hash_bits = 0, this.hash_mask = 0, this.hash_shift = 0, this.block_start = 0, this.match_length = 0, this.prev_match = 0, this.match_available = 0, this.strstart = 0, this.match_start = 0, this.lookahead = 0, this.prev_length = 0, this.max_chain_length = 0, this.max_lazy_match = 0, this.level = 0, this.strategy = 0, this.good_match = 0, this.nice_match = 0, this.dyn_ltree = new d.Buf16(2 * g), this.dyn_dtree = new d.Buf16(2 * (2 * a + 1)), this.bl_tree = new d.Buf16(2 * (2 * o + 1)), E(this.dyn_ltree), E(this.dyn_dtree), E(this.bl_tree), this.l_desc = null, this.d_desc = null, this.bl_desc = null, this.bl_count = new d.Buf16(v + 1), this.heap = new d.Buf16(2 * s + 1), E(this.heap), this.heap_len = 0, this.heap_max = 0, this.depth = new d.Buf16(2 * s + 1), E(this.depth), this.l_buf = 0, this.lit_bufsize = 0, this.last_lit = 0, this.d_buf = 0, this.opt_len = 0, this.static_len = 0, this.matches = 0, this.insert = 0, this.bi_buf = 0, this.bi_valid = 0 } function U(e) { var t; return e && e.state ? (e.total_in = e.total_out = 0, e.data_type = i, (t = e.state).pending = 0, t.pending_out = 0, t.wrap < 0 && (t.wrap = -t.wrap), t.status = t.wrap ? k : x, e.adler = 2 === t.wrap ? 0 : 1, t.last_flush = f, h._tr_init(t), l) : S(e, m) } function P(e) { var t, r = U(e); return r === l && ((t = e.state).window_size = 2 * t.w_size, E(t.head), t.max_lazy_match = u[t.level].max_lazy, t.good_match = u[t.level].good_length, t.nice_match = u[t.level].nice_length, t.max_chain_length = u[t.level].max_chain, t.strstart = 0, t.block_start = 0, t.lookahead = 0, t.insert = 0, t.match_length = t.prev_length = b - 1, t.match_available = 0, t.ins_h = 0), r } function L(e, t, r, n, i, s) { if (!e) return m; var a = 1; if (-1 === t && (t = 6), n < 0 ? (a = 0, n = -n) : 15 < n && (a = 2, n -= 16), i < 1 || 9 < i || r !== _ || n < 8 || 15 < n || t < 0 || 9 < t || s < 0 || 4 < s) return S(e, m); 8 === n && (n = 9); var o = new N; return (e.state = o).strm = e, o.wrap = a, o.gzhead = null, o.w_bits = n, o.w_size = 1 << o.w_bits, o.w_mask = o.w_size - 1, o.hash_bits = i + 7, o.hash_size = 1 << o.hash_bits, o.hash_mask = o.hash_size - 1, o.hash_shift = ~~((o.hash_bits + b - 1) / b), o.window = new d.Buf8(2 * o.w_size), o.head = new d.Buf16(o.hash_size), o.prev = new d.Buf16(o.w_size), o.lit_bufsize = 1 << i + 6, o.pending_buf_size = 4 * o.lit_bufsize, o.pending_buf = new d.Buf8(o.pending_buf_size), o.d_buf = 1 * o.lit_bufsize, o.l_buf = 3 * o.lit_bufsize, o.level = t, o.strategy = s, o.method = r, P(e) } u = [new F(0, 0, 0, 0, function (e, t) { var r = 65535; for (r > e.pending_buf_size - 5 && (r = e.pending_buf_size - 5); ;) { if (e.lookahead <= 1) { if (T(e), 0 === e.lookahead && t === f) return 1; if (0 === e.lookahead) break } e.strstart += e.lookahead, e.lookahead = 0; var n = e.block_start + r; if ((0 === e.strstart || e.strstart >= n) && (e.lookahead = e.strstart - n, e.strstart = n, A(e, !1), 0 === e.strm.avail_out)) return 1; if (e.strstart - e.block_start >= e.w_size - y && (A(e, !1), 0 === e.strm.avail_out)) return 1 } return e.insert = 0, 4 === t ? (A(e, !0), 0 === e.strm.avail_out ? 3 : 4) : (e.strstart > e.block_start && (A(e, !1), e.strm.avail_out), 1) }), new F(4, 4, 8, 4, R), new F(4, 5, 16, 8, R), new F(4, 6, 32, 32, R), new F(4, 4, 16, 16, D), new F(8, 16, 32, 32, D), new F(8, 16, 128, 128, D), new F(8, 32, 128, 256, D), new F(32, 128, 258, 1024, D), new F(32, 258, 258, 4096, D)], r.deflateInit = function (e, t) { return L(e, t, _, 15, 8, 0) }, r.deflateInit2 = L, r.deflateReset = P, r.deflateResetKeep = U, r.deflateSetHeader = function (e, t) { return e && e.state ? 2 !== e.state.wrap ? m : (e.state.gzhead = t, l) : m }, r.deflate = function (e, t) { var r, n, i, s; if (!e || !e.state || 5 < t || t < 0) return e ? S(e, m) : m; if (n = e.state, !e.output || !e.input && 0 !== e.avail_in || 666 === n.status && 4 !== t) return S(e, 0 === e.avail_out ? -5 : m); if (n.strm = e, r = n.last_flush, n.last_flush = t, n.status === k) if (2 === n.wrap) e.adler = 0, I(n, 31), I(n, 139), I(n, 8), n.gzhead ? (I(n, (n.gzhead.text ? 1 : 0) + (n.gzhead.hcrc ? 2 : 0) + (n.gzhead.extra ? 4 : 0) + (n.gzhead.name ? 8 : 0) + (n.gzhead.comment ? 16 : 0)), I(n, 255 & n.gzhead.time), I(n, n.gzhead.time >> 8 & 255), I(n, n.gzhead.time >> 16 & 255), I(n, n.gzhead.time >> 24 & 255), I(n, 9 === n.level ? 2 : 2 <= n.strategy || n.level < 2 ? 4 : 0), I(n, 255 & n.gzhead.os), n.gzhead.extra && n.gzhead.extra.length && (I(n, 255 & n.gzhead.extra.length), I(n, n.gzhead.extra.length >> 8 & 255)), n.gzhead.hcrc && (e.adler = p(e.adler, n.pending_buf, n.pending, 0)), n.gzindex = 0, n.status = 69) : (I(n, 0), I(n, 0), I(n, 0), I(n, 0), I(n, 0), I(n, 9 === n.level ? 2 : 2 <= n.strategy || n.level < 2 ? 4 : 0), I(n, 3), n.status = x); else { var a = _ + (n.w_bits - 8 << 4) << 8; a |= (2 <= n.strategy || n.level < 2 ? 0 : n.level < 6 ? 1 : 6 === n.level ? 2 : 3) << 6, 0 !== n.strstart && (a |= 32), a += 31 - a % 31, n.status = x, O(n, a), 0 !== n.strstart && (O(n, e.adler >>> 16), O(n, 65535 & e.adler)), e.adler = 1 } if (69 === n.status) if (n.gzhead.extra) { for (i = n.pending; n.gzindex < (65535 & n.gzhead.extra.length) && (n.pending !== n.pending_buf_size || (n.gzhead.hcrc && n.pending > i && (e.adler = p(e.adler, n.pending_buf, n.pending - i, i)), C(e), i = n.pending, n.pending !== n.pending_buf_size));)I(n, 255 & n.gzhead.extra[n.gzindex]), n.gzindex++; n.gzhead.hcrc && n.pending > i && (e.adler = p(e.adler, n.pending_buf, n.pending - i, i)), n.gzindex === n.gzhead.extra.length && (n.gzindex = 0, n.status = 73) } else n.status = 73; if (73 === n.status) if (n.gzhead.name) { i = n.pending; do { if (n.pending === n.pending_buf_size && (n.gzhead.hcrc && n.pending > i && (e.adler = p(e.adler, n.pending_buf, n.pending - i, i)), C(e), i = n.pending, n.pending === n.pending_buf_size)) { s = 1; break } s = n.gzindex < n.gzhead.name.length ? 255 & n.gzhead.name.charCodeAt(n.gzindex++) : 0, I(n, s) } while (0 !== s); n.gzhead.hcrc && n.pending > i && (e.adler = p(e.adler, n.pending_buf, n.pending - i, i)), 0 === s && (n.gzindex = 0, n.status = 91) } else n.status = 91; if (91 === n.status) if (n.gzhead.comment) { i = n.pending; do { if (n.pending === n.pending_buf_size && (n.gzhead.hcrc && n.pending > i && (e.adler = p(e.adler, n.pending_buf, n.pending - i, i)), C(e), i = n.pending, n.pending === n.pending_buf_size)) { s = 1; break } s = n.gzindex < n.gzhead.comment.length ? 255 & n.gzhead.comment.charCodeAt(n.gzindex++) : 0, I(n, s) } while (0 !== s); n.gzhead.hcrc && n.pending > i && (e.adler = p(e.adler, n.pending_buf, n.pending - i, i)), 0 === s && (n.status = 103) } else n.status = 103; if (103 === n.status && (n.gzhead.hcrc ? (n.pending + 2 > n.pending_buf_size && C(e), n.pending + 2 <= n.pending_buf_size && (I(n, 255 & e.adler), I(n, e.adler >> 8 & 255), e.adler = 0, n.status = x)) : n.status = x), 0 !== n.pending) { if (C(e), 0 === e.avail_out) return n.last_flush = -1, l } else if (0 === e.avail_in && z(t) <= z(r) && 4 !== t) return S(e, -5); if (666 === n.status && 0 !== e.avail_in) return S(e, -5); if (0 !== e.avail_in || 0 !== n.lookahead || t !== f && 666 !== n.status) { var o = 2 === n.strategy ? function (e, t) { for (var r; ;) { if (0 === e.lookahead && (T(e), 0 === e.lookahead)) { if (t === f) return 1; break } if (e.match_length = 0, r = h._tr_tally(e, 0, e.window[e.strstart]), e.lookahead--, e.strstart++, r && (A(e, !1), 0 === e.strm.avail_out)) return 1 } return e.insert = 0, 4 === t ? (A(e, !0), 0 === e.strm.avail_out ? 3 : 4) : e.last_lit && (A(e, !1), 0 === e.strm.avail_out) ? 1 : 2 }(n, t) : 3 === n.strategy ? function (e, t) { for (var r, n, i, s, a = e.window; ;) { if (e.lookahead <= w) { if (T(e), e.lookahead <= w && t === f) return 1; if (0 === e.lookahead) break } if (e.match_length = 0, e.lookahead >= b && 0 < e.strstart && (n = a[i = e.strstart - 1]) === a[++i] && n === a[++i] && n === a[++i]) { s = e.strstart + w; do { } while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && i < s); e.match_length = w - (s - i), e.match_length > e.lookahead && (e.match_length = e.lookahead) } if (e.match_length >= b ? (r = h._tr_tally(e, 1, e.match_length - b), e.lookahead -= e.match_length, e.strstart += e.match_length, e.match_length = 0) : (r = h._tr_tally(e, 0, e.window[e.strstart]), e.lookahead--, e.strstart++), r && (A(e, !1), 0 === e.strm.avail_out)) return 1 } return e.insert = 0, 4 === t ? (A(e, !0), 0 === e.strm.avail_out ? 3 : 4) : e.last_lit && (A(e, !1), 0 === e.strm.avail_out) ? 1 : 2 }(n, t) : u[n.level].func(n, t); if (3 !== o && 4 !== o || (n.status = 666), 1 === o || 3 === o) return 0 === e.avail_out && (n.last_flush = -1), l; if (2 === o && (1 === t ? h._tr_align(n) : 5 !== t && (h._tr_stored_block(n, 0, 0, !1), 3 === t && (E(n.head), 0 === n.lookahead && (n.strstart = 0, n.block_start = 0, n.insert = 0))), C(e), 0 === e.avail_out)) return n.last_flush = -1, l } return 4 !== t ? l : n.wrap <= 0 ? 1 : (2 === n.wrap ? (I(n, 255 & e.adler), I(n, e.adler >> 8 & 255), I(n, e.adler >> 16 & 255), I(n, e.adler >> 24 & 255), I(n, 255 & e.total_in), I(n, e.total_in >> 8 & 255), I(n, e.total_in >> 16 & 255), I(n, e.total_in >> 24 & 255)) : (O(n, e.adler >>> 16), O(n, 65535 & e.adler)), C(e), 0 < n.wrap && (n.wrap = -n.wrap), 0 !== n.pending ? l : 1) }, r.deflateEnd = function (e) { var t; return e && e.state ? (t = e.state.status) !== k && 69 !== t && 73 !== t && 91 !== t && 103 !== t && t !== x && 666 !== t ? S(e, m) : (e.state = null, t === x ? S(e, -3) : l) : m }, r.deflateSetDictionary = function (e, t) { var r, n, i, s, a, o, u, h, f = t.length; if (!e || !e.state) return m; if (2 === (s = (r = e.state).wrap) || 1 === s && r.status !== k || r.lookahead) return m; for (1 === s && (e.adler = c(e.adler, t, f, 0)), r.wrap = 0, f >= r.w_size && (0 === s && (E(r.head), r.strstart = 0, r.block_start = 0, r.insert = 0), h = new d.Buf8(r.w_size), d.arraySet(h, t, f - r.w_size, r.w_size, 0), t = h, f = r.w_size), a = e.avail_in, o = e.next_in, u = e.input, e.avail_in = f, e.next_in = 0, e.input = t, T(r); r.lookahead >= b;) { for (n = r.strstart, i = r.lookahead - (b - 1); r.ins_h = (r.ins_h << r.hash_shift ^ r.window[n + b - 1]) & r.hash_mask, r.prev[n & r.w_mask] = r.head[r.ins_h], r.head[r.ins_h] = n, n++, --i;); r.strstart = n, r.lookahead = b - 1, T(r) } return r.strstart += r.lookahead, r.block_start = r.strstart, r.insert = r.lookahead, r.lookahead = 0, r.match_length = r.prev_length = b - 1, r.match_available = 0, e.next_in = o, e.input = u, e.avail_in = a, r.wrap = s, l }, r.deflateInfo = "pako deflate (from Nodeca project)" }, { "../utils/common": 41, "./adler32": 43, "./crc32": 45, "./messages": 51, "./trees": 52 }], 47: [function (e, t, r) { "use strict"; t.exports = function () { this.text = 0, this.time = 0, this.xflags = 0, this.os = 0, this.extra = null, this.extra_len = 0, this.name = "", this.comment = "", this.hcrc = 0, this.done = !1 } }, {}], 48: [function (e, t, r) { "use strict"; t.exports = function (e, t) { var r, n, i, s, a, o, u, h, f, l, d, c, p, m, _, g, v, b, w, y, k, x, S, z, E; r = e.state, n = e.next_in, z = e.input, i = n + (e.avail_in - 5), s = e.next_out, E = e.output, a = s - (t - e.avail_out), o = s + (e.avail_out - 257), u = r.dmax, h = r.wsize, f = r.whave, l = r.wnext, d = r.window, c = r.hold, p = r.bits, m = r.lencode, _ = r.distcode, g = (1 << r.lenbits) - 1, v = (1 << r.distbits) - 1; e: do { p < 15 && (c += z[n++] << p, p += 8, c += z[n++] << p, p += 8), b = m[c & g]; t: for (; ;) { if (c >>>= w = b >>> 24, p -= w, 0 == (w = b >>> 16 & 255)) E[s++] = 65535 & b; else { if (!(16 & w)) { if (0 == (64 & w)) { b = m[(65535 & b) + (c & (1 << w) - 1)]; continue t } if (32 & w) { r.mode = 12; break e } e.msg = "invalid literal/length code", r.mode = 30; break e } y = 65535 & b, (w &= 15) && (p < w && (c += z[n++] << p, p += 8), y += c & (1 << w) - 1, c >>>= w, p -= w), p < 15 && (c += z[n++] << p, p += 8, c += z[n++] << p, p += 8), b = _[c & v]; r: for (; ;) { if (c >>>= w = b >>> 24, p -= w, !(16 & (w = b >>> 16 & 255))) { if (0 == (64 & w)) { b = _[(65535 & b) + (c & (1 << w) - 1)]; continue r } e.msg = "invalid distance code", r.mode = 30; break e } if (k = 65535 & b, p < (w &= 15) && (c += z[n++] << p, (p += 8) < w && (c += z[n++] << p, p += 8)), u < (k += c & (1 << w) - 1)) { e.msg = "invalid distance too far back", r.mode = 30; break e } if (c >>>= w, p -= w, (w = s - a) < k) { if (f < (w = k - w) && r.sane) { e.msg = "invalid distance too far back", r.mode = 30; break e } if (S = d, (x = 0) === l) { if (x += h - w, w < y) { for (y -= w; E[s++] = d[x++], --w;); x = s - k, S = E } } else if (l < w) { if (x += h + l - w, (w -= l) < y) { for (y -= w; E[s++] = d[x++], --w;); if (x = 0, l < y) { for (y -= w = l; E[s++] = d[x++], --w;); x = s - k, S = E } } } else if (x += l - w, w < y) { for (y -= w; E[s++] = d[x++], --w;); x = s - k, S = E } for (; 2 < y;)E[s++] = S[x++], E[s++] = S[x++], E[s++] = S[x++], y -= 3; y && (E[s++] = S[x++], 1 < y && (E[s++] = S[x++])) } else { for (x = s - k; E[s++] = E[x++], E[s++] = E[x++], E[s++] = E[x++], 2 < (y -= 3);); y && (E[s++] = E[x++], 1 < y && (E[s++] = E[x++])) } break } } break } } while (n < i && s < o); n -= y = p >> 3, c &= (1 << (p -= y << 3)) - 1, e.next_in = n, e.next_out = s, e.avail_in = n < i ? i - n + 5 : 5 - (n - i), e.avail_out = s < o ? o - s + 257 : 257 - (s - o), r.hold = c, r.bits = p } }, {}], 49: [function (e, t, r) { "use strict"; var I = e("../utils/common"), O = e("./adler32"), B = e("./crc32"), T = e("./inffast"), R = e("./inftrees"), D = 1, F = 2, N = 0, U = -2, P = 1, n = 852, i = 592; function L(e) { return (e >>> 24 & 255) + (e >>> 8 & 65280) + ((65280 & e) << 8) + ((255 & e) << 24) } function s() { this.mode = 0, this.last = !1, this.wrap = 0, this.havedict = !1, this.flags = 0, this.dmax = 0, this.check = 0, this.total = 0, this.head = null, this.wbits = 0, this.wsize = 0, this.whave = 0, this.wnext = 0, this.window = null, this.hold = 0, this.bits = 0, this.length = 0, this.offset = 0, this.extra = 0, this.lencode = null, this.distcode = null, this.lenbits = 0, this.distbits = 0, this.ncode = 0, this.nlen = 0, this.ndist = 0, this.have = 0, this.next = null, this.lens = new I.Buf16(320), this.work = new I.Buf16(288), this.lendyn = null, this.distdyn = null, this.sane = 0, this.back = 0, this.was = 0 } function a(e) { var t; return e && e.state ? (t = e.state, e.total_in = e.total_out = t.total = 0, e.msg = "", t.wrap && (e.adler = 1 & t.wrap), t.mode = P, t.last = 0, t.havedict = 0, t.dmax = 32768, t.head = null, t.hold = 0, t.bits = 0, t.lencode = t.lendyn = new I.Buf32(n), t.distcode = t.distdyn = new I.Buf32(i), t.sane = 1, t.back = -1, N) : U } function o(e) { var t; return e && e.state ? ((t = e.state).wsize = 0, t.whave = 0, t.wnext = 0, a(e)) : U } function u(e, t) { var r, n; return e && e.state ? (n = e.state, t < 0 ? (r = 0, t = -t) : (r = 1 + (t >> 4), t < 48 && (t &= 15)), t && (t < 8 || 15 < t) ? U : (null !== n.window && n.wbits !== t && (n.window = null), n.wrap = r, n.wbits = t, o(e))) : U } function h(e, t) { var r, n; return e ? (n = new s, (e.state = n).window = null, (r = u(e, t)) !== N && (e.state = null), r) : U } var f, l, d = !0; function j(e) { if (d) { var t; for (f = new I.Buf32(512), l = new I.Buf32(32), t = 0; t < 144;)e.lens[t++] = 8; for (; t < 256;)e.lens[t++] = 9; for (; t < 280;)e.lens[t++] = 7; for (; t < 288;)e.lens[t++] = 8; for (R(D, e.lens, 0, 288, f, 0, e.work, { bits: 9 }), t = 0; t < 32;)e.lens[t++] = 5; R(F, e.lens, 0, 32, l, 0, e.work, { bits: 5 }), d = !1 } e.lencode = f, e.lenbits = 9, e.distcode = l, e.distbits = 5 } function Z(e, t, r, n) { var i, s = e.state; return null === s.window && (s.wsize = 1 << s.wbits, s.wnext = 0, s.whave = 0, s.window = new I.Buf8(s.wsize)), n >= s.wsize ? (I.arraySet(s.window, t, r - s.wsize, s.wsize, 0), s.wnext = 0, s.whave = s.wsize) : (n < (i = s.wsize - s.wnext) && (i = n), I.arraySet(s.window, t, r - n, i, s.wnext), (n -= i) ? (I.arraySet(s.window, t, r - n, n, 0), s.wnext = n, s.whave = s.wsize) : (s.wnext += i, s.wnext === s.wsize && (s.wnext = 0), s.whave < s.wsize && (s.whave += i))), 0 } r.inflateReset = o, r.inflateReset2 = u, r.inflateResetKeep = a, r.inflateInit = function (e) { return h(e, 15) }, r.inflateInit2 = h, r.inflate = function (e, t) { var r, n, i, s, a, o, u, h, f, l, d, c, p, m, _, g, v, b, w, y, k, x, S, z, E = 0, C = new I.Buf8(4), A = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]; if (!e || !e.state || !e.output || !e.input && 0 !== e.avail_in) return U; 12 === (r = e.state).mode && (r.mode = 13), a = e.next_out, i = e.output, u = e.avail_out, s = e.next_in, n = e.input, o = e.avail_in, h = r.hold, f = r.bits, l = o, d = u, x = N; e: for (; ;)switch (r.mode) { case P: if (0 === r.wrap) { r.mode = 13; break } for (; f < 16;) { if (0 === o) break e; o--, h += n[s++] << f, f += 8 } if (2 & r.wrap && 35615 === h) { C[r.check = 0] = 255 & h, C[1] = h >>> 8 & 255, r.check = B(r.check, C, 2, 0), f = h = 0, r.mode = 2; break } if (r.flags = 0, r.head && (r.head.done = !1), !(1 & r.wrap) || (((255 & h) << 8) + (h >> 8)) % 31) { e.msg = "incorrect header check", r.mode = 30; break } if (8 != (15 & h)) { e.msg = "unknown compression method", r.mode = 30; break } if (f -= 4, k = 8 + (15 & (h >>>= 4)), 0 === r.wbits) r.wbits = k; else if (k > r.wbits) { e.msg = "invalid window size", r.mode = 30; break } r.dmax = 1 << k, e.adler = r.check = 1, r.mode = 512 & h ? 10 : 12, f = h = 0; break; case 2: for (; f < 16;) { if (0 === o) break e; o--, h += n[s++] << f, f += 8 } if (r.flags = h, 8 != (255 & r.flags)) { e.msg = "unknown compression method", r.mode = 30; break } if (57344 & r.flags) { e.msg = "unknown header flags set", r.mode = 30; break } r.head && (r.head.text = h >> 8 & 1), 512 & r.flags && (C[0] = 255 & h, C[1] = h >>> 8 & 255, r.check = B(r.check, C, 2, 0)), f = h = 0, r.mode = 3; case 3: for (; f < 32;) { if (0 === o) break e; o--, h += n[s++] << f, f += 8 } r.head && (r.head.time = h), 512 & r.flags && (C[0] = 255 & h, C[1] = h >>> 8 & 255, C[2] = h >>> 16 & 255, C[3] = h >>> 24 & 255, r.check = B(r.check, C, 4, 0)), f = h = 0, r.mode = 4; case 4: for (; f < 16;) { if (0 === o) break e; o--, h += n[s++] << f, f += 8 } r.head && (r.head.xflags = 255 & h, r.head.os = h >> 8), 512 & r.flags && (C[0] = 255 & h, C[1] = h >>> 8 & 255, r.check = B(r.check, C, 2, 0)), f = h = 0, r.mode = 5; case 5: if (1024 & r.flags) { for (; f < 16;) { if (0 === o) break e; o--, h += n[s++] << f, f += 8 } r.length = h, r.head && (r.head.extra_len = h), 512 & r.flags && (C[0] = 255 & h, C[1] = h >>> 8 & 255, r.check = B(r.check, C, 2, 0)), f = h = 0 } else r.head && (r.head.extra = null); r.mode = 6; case 6: if (1024 & r.flags && (o < (c = r.length) && (c = o), c && (r.head && (k = r.head.extra_len - r.length, r.head.extra || (r.head.extra = new Array(r.head.extra_len)), I.arraySet(r.head.extra, n, s, c, k)), 512 & r.flags && (r.check = B(r.check, n, c, s)), o -= c, s += c, r.length -= c), r.length)) break e; r.length = 0, r.mode = 7; case 7: if (2048 & r.flags) { if (0 === o) break e; for (c = 0; k = n[s + c++], r.head && k && r.length < 65536 && (r.head.name += String.fromCharCode(k)), k && c < o;); if (512 & r.flags && (r.check = B(r.check, n, c, s)), o -= c, s += c, k) break e } else r.head && (r.head.name = null); r.length = 0, r.mode = 8; case 8: if (4096 & r.flags) { if (0 === o) break e; for (c = 0; k = n[s + c++], r.head && k && r.length < 65536 && (r.head.comment += String.fromCharCode(k)), k && c < o;); if (512 & r.flags && (r.check = B(r.check, n, c, s)), o -= c, s += c, k) break e } else r.head && (r.head.comment = null); r.mode = 9; case 9: if (512 & r.flags) { for (; f < 16;) { if (0 === o) break e; o--, h += n[s++] << f, f += 8 } if (h !== (65535 & r.check)) { e.msg = "header crc mismatch", r.mode = 30; break } f = h = 0 } r.head && (r.head.hcrc = r.flags >> 9 & 1, r.head.done = !0), e.adler = r.check = 0, r.mode = 12; break; case 10: for (; f < 32;) { if (0 === o) break e; o--, h += n[s++] << f, f += 8 } e.adler = r.check = L(h), f = h = 0, r.mode = 11; case 11: if (0 === r.havedict) return e.next_out = a, e.avail_out = u, e.next_in = s, e.avail_in = o, r.hold = h, r.bits = f, 2; e.adler = r.check = 1, r.mode = 12; case 12: if (5 === t || 6 === t) break e; case 13: if (r.last) { h >>>= 7 & f, f -= 7 & f, r.mode = 27; break } for (; f < 3;) { if (0 === o) break e; o--, h += n[s++] << f, f += 8 } switch (r.last = 1 & h, f -= 1, 3 & (h >>>= 1)) { case 0: r.mode = 14; break; case 1: if (j(r), r.mode = 20, 6 !== t) break; h >>>= 2, f -= 2; break e; case 2: r.mode = 17; break; case 3: e.msg = "invalid block type", r.mode = 30 }h >>>= 2, f -= 2; break; case 14: for (h >>>= 7 & f, f -= 7 & f; f < 32;) { if (0 === o) break e; o--, h += n[s++] << f, f += 8 } if ((65535 & h) != (h >>> 16 ^ 65535)) { e.msg = "invalid stored block lengths", r.mode = 30; break } if (r.length = 65535 & h, f = h = 0, r.mode = 15, 6 === t) break e; case 15: r.mode = 16; case 16: if (c = r.length) { if (o < c && (c = o), u < c && (c = u), 0 === c) break e; I.arraySet(i, n, s, c, a), o -= c, s += c, u -= c, a += c, r.length -= c; break } r.mode = 12; break; case 17: for (; f < 14;) { if (0 === o) break e; o--, h += n[s++] << f, f += 8 } if (r.nlen = 257 + (31 & h), h >>>= 5, f -= 5, r.ndist = 1 + (31 & h), h >>>= 5, f -= 5, r.ncode = 4 + (15 & h), h >>>= 4, f -= 4, 286 < r.nlen || 30 < r.ndist) { e.msg = "too many length or distance symbols", r.mode = 30; break } r.have = 0, r.mode = 18; case 18: for (; r.have < r.ncode;) { for (; f < 3;) { if (0 === o) break e; o--, h += n[s++] << f, f += 8 } r.lens[A[r.have++]] = 7 & h, h >>>= 3, f -= 3 } for (; r.have < 19;)r.lens[A[r.have++]] = 0; if (r.lencode = r.lendyn, r.lenbits = 7, S = { bits: r.lenbits }, x = R(0, r.lens, 0, 19, r.lencode, 0, r.work, S), r.lenbits = S.bits, x) { e.msg = "invalid code lengths set", r.mode = 30; break } r.have = 0, r.mode = 19; case 19: for (; r.have < r.nlen + r.ndist;) { for (; g = (E = r.lencode[h & (1 << r.lenbits) - 1]) >>> 16 & 255, v = 65535 & E, !((_ = E >>> 24) <= f);) { if (0 === o) break e; o--, h += n[s++] << f, f += 8 } if (v < 16) h >>>= _, f -= _, r.lens[r.have++] = v; else { if (16 === v) { for (z = _ + 2; f < z;) { if (0 === o) break e; o--, h += n[s++] << f, f += 8 } if (h >>>= _, f -= _, 0 === r.have) { e.msg = "invalid bit length repeat", r.mode = 30; break } k = r.lens[r.have - 1], c = 3 + (3 & h), h >>>= 2, f -= 2 } else if (17 === v) { for (z = _ + 3; f < z;) { if (0 === o) break e; o--, h += n[s++] << f, f += 8 } f -= _, k = 0, c = 3 + (7 & (h >>>= _)), h >>>= 3, f -= 3 } else { for (z = _ + 7; f < z;) { if (0 === o) break e; o--, h += n[s++] << f, f += 8 } f -= _, k = 0, c = 11 + (127 & (h >>>= _)), h >>>= 7, f -= 7 } if (r.have + c > r.nlen + r.ndist) { e.msg = "invalid bit length repeat", r.mode = 30; break } for (; c--;)r.lens[r.have++] = k } } if (30 === r.mode) break; if (0 === r.lens[256]) { e.msg = "invalid code -- missing end-of-block", r.mode = 30; break } if (r.lenbits = 9, S = { bits: r.lenbits }, x = R(D, r.lens, 0, r.nlen, r.lencode, 0, r.work, S), r.lenbits = S.bits, x) { e.msg = "invalid literal/lengths set", r.mode = 30; break } if (r.distbits = 6, r.distcode = r.distdyn, S = { bits: r.distbits }, x = R(F, r.lens, r.nlen, r.ndist, r.distcode, 0, r.work, S), r.distbits = S.bits, x) { e.msg = "invalid distances set", r.mode = 30; break } if (r.mode = 20, 6 === t) break e; case 20: r.mode = 21; case 21: if (6 <= o && 258 <= u) { e.next_out = a, e.avail_out = u, e.next_in = s, e.avail_in = o, r.hold = h, r.bits = f, T(e, d), a = e.next_out, i = e.output, u = e.avail_out, s = e.next_in, n = e.input, o = e.avail_in, h = r.hold, f = r.bits, 12 === r.mode && (r.back = -1); break } for (r.back = 0; g = (E = r.lencode[h & (1 << r.lenbits) - 1]) >>> 16 & 255, v = 65535 & E, !((_ = E >>> 24) <= f);) { if (0 === o) break e; o--, h += n[s++] << f, f += 8 } if (g && 0 == (240 & g)) { for (b = _, w = g, y = v; g = (E = r.lencode[y + ((h & (1 << b + w) - 1) >> b)]) >>> 16 & 255, v = 65535 & E, !(b + (_ = E >>> 24) <= f);) { if (0 === o) break e; o--, h += n[s++] << f, f += 8 } h >>>= b, f -= b, r.back += b } if (h >>>= _, f -= _, r.back += _, r.length = v, 0 === g) { r.mode = 26; break } if (32 & g) { r.back = -1, r.mode = 12; break } if (64 & g) { e.msg = "invalid literal/length code", r.mode = 30; break } r.extra = 15 & g, r.mode = 22; case 22: if (r.extra) { for (z = r.extra; f < z;) { if (0 === o) break e; o--, h += n[s++] << f, f += 8 } r.length += h & (1 << r.extra) - 1, h >>>= r.extra, f -= r.extra, r.back += r.extra } r.was = r.length, r.mode = 23; case 23: for (; g = (E = r.distcode[h & (1 << r.distbits) - 1]) >>> 16 & 255, v = 65535 & E, !((_ = E >>> 24) <= f);) { if (0 === o) break e; o--, h += n[s++] << f, f += 8 } if (0 == (240 & g)) { for (b = _, w = g, y = v; g = (E = r.distcode[y + ((h & (1 << b + w) - 1) >> b)]) >>> 16 & 255, v = 65535 & E, !(b + (_ = E >>> 24) <= f);) { if (0 === o) break e; o--, h += n[s++] << f, f += 8 } h >>>= b, f -= b, r.back += b } if (h >>>= _, f -= _, r.back += _, 64 & g) { e.msg = "invalid distance code", r.mode = 30; break } r.offset = v, r.extra = 15 & g, r.mode = 24; case 24: if (r.extra) { for (z = r.extra; f < z;) { if (0 === o) break e; o--, h += n[s++] << f, f += 8 } r.offset += h & (1 << r.extra) - 1, h >>>= r.extra, f -= r.extra, r.back += r.extra } if (r.offset > r.dmax) { e.msg = "invalid distance too far back", r.mode = 30; break } r.mode = 25; case 25: if (0 === u) break e; if (c = d - u, r.offset > c) { if ((c = r.offset - c) > r.whave && r.sane) { e.msg = "invalid distance too far back", r.mode = 30; break } p = c > r.wnext ? (c -= r.wnext, r.wsize - c) : r.wnext - c, c > r.length && (c = r.length), m = r.window } else m = i, p = a - r.offset, c = r.length; for (u < c && (c = u), u -= c, r.length -= c; i[a++] = m[p++], --c;); 0 === r.length && (r.mode = 21); break; case 26: if (0 === u) break e; i[a++] = r.length, u--, r.mode = 21; break; case 27: if (r.wrap) { for (; f < 32;) { if (0 === o) break e; o--, h |= n[s++] << f, f += 8 } if (d -= u, e.total_out += d, r.total += d, d && (e.adler = r.check = r.flags ? B(r.check, i, d, a - d) : O(r.check, i, d, a - d)), d = u, (r.flags ? h : L(h)) !== r.check) { e.msg = "incorrect data check", r.mode = 30; break } f = h = 0 } r.mode = 28; case 28: if (r.wrap && r.flags) { for (; f < 32;) { if (0 === o) break e; o--, h += n[s++] << f, f += 8 } if (h !== (4294967295 & r.total)) { e.msg = "incorrect length check", r.mode = 30; break } f = h = 0 } r.mode = 29; case 29: x = 1; break e; case 30: x = -3; break e; case 31: return -4; case 32: default: return U }return e.next_out = a, e.avail_out = u, e.next_in = s, e.avail_in = o, r.hold = h, r.bits = f, (r.wsize || d !== e.avail_out && r.mode < 30 && (r.mode < 27 || 4 !== t)) && Z(e, e.output, e.next_out, d - e.avail_out) ? (r.mode = 31, -4) : (l -= e.avail_in, d -= e.avail_out, e.total_in += l, e.total_out += d, r.total += d, r.wrap && d && (e.adler = r.check = r.flags ? B(r.check, i, d, e.next_out - d) : O(r.check, i, d, e.next_out - d)), e.data_type = r.bits + (r.last ? 64 : 0) + (12 === r.mode ? 128 : 0) + (20 === r.mode || 15 === r.mode ? 256 : 0), (0 == l && 0 === d || 4 === t) && x === N && (x = -5), x) }, r.inflateEnd = function (e) { if (!e || !e.state) return U; var t = e.state; return t.window && (t.window = null), e.state = null, N }, r.inflateGetHeader = function (e, t) { var r; return e && e.state ? 0 == (2 & (r = e.state).wrap) ? U : ((r.head = t).done = !1, N) : U }, r.inflateSetDictionary = function (e, t) { var r, n = t.length; return e && e.state ? 0 !== (r = e.state).wrap && 11 !== r.mode ? U : 11 === r.mode && O(1, t, n, 0) !== r.check ? -3 : Z(e, t, n, n) ? (r.mode = 31, -4) : (r.havedict = 1, N) : U }, r.inflateInfo = "pako inflate (from Nodeca project)" }, { "../utils/common": 41, "./adler32": 43, "./crc32": 45, "./inffast": 48, "./inftrees": 50 }], 50: [function (e, t, r) { "use strict"; var D = e("../utils/common"), F = [3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0], N = [16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78], U = [1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0], P = [16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64]; t.exports = function (e, t, r, n, i, s, a, o) { var u, h, f, l, d, c, p, m, _, g = o.bits, v = 0, b = 0, w = 0, y = 0, k = 0, x = 0, S = 0, z = 0, E = 0, C = 0, A = null, I = 0, O = new D.Buf16(16), B = new D.Buf16(16), T = null, R = 0; for (v = 0; v <= 15; v++)O[v] = 0; for (b = 0; b < n; b++)O[t[r + b]]++; for (k = g, y = 15; 1 <= y && 0 === O[y]; y--); if (y < k && (k = y), 0 === y) return i[s++] = 20971520, i[s++] = 20971520, o.bits = 1, 0; for (w = 1; w < y && 0 === O[w]; w++); for (k < w && (k = w), v = z = 1; v <= 15; v++)if (z <<= 1, (z -= O[v]) < 0) return -1; if (0 < z && (0 === e || 1 !== y)) return -1; for (B[1] = 0, v = 1; v < 15; v++)B[v + 1] = B[v] + O[v]; for (b = 0; b < n; b++)0 !== t[r + b] && (a[B[t[r + b]]++] = b); if (c = 0 === e ? (A = T = a, 19) : 1 === e ? (A = F, I -= 257, T = N, R -= 257, 256) : (A = U, T = P, -1), v = w, d = s, S = b = C = 0, f = -1, l = (E = 1 << (x = k)) - 1, 1 === e && 852 < E || 2 === e && 592 < E) return 1; for (; ;) { for (p = v - S, _ = a[b] < c ? (m = 0, a[b]) : a[b] > c ? (m = T[R + a[b]], A[I + a[b]]) : (m = 96, 0), u = 1 << v - S, w = h = 1 << x; i[d + (C >> S) + (h -= u)] = p << 24 | m << 16 | _ | 0, 0 !== h;); for (u = 1 << v - 1; C & u;)u >>= 1; if (0 !== u ? (C &= u - 1, C += u) : C = 0, b++, 0 == --O[v]) { if (v === y) break; v = t[r + a[b]] } if (k < v && (C & l) !== f) { for (0 === S && (S = k), d += w, z = 1 << (x = v - S); x + S < y && !((z -= O[x + S]) <= 0);)x++, z <<= 1; if (E += 1 << x, 1 === e && 852 < E || 2 === e && 592 < E) return 1; i[f = C & l] = k << 24 | x << 16 | d - s | 0 } } return 0 !== C && (i[d + C] = v - S << 24 | 64 << 16 | 0), o.bits = k, 0 } }, { "../utils/common": 41 }], 51: [function (e, t, r) { "use strict"; t.exports = { 2: "need dictionary", 1: "stream end", 0: "", "-1": "file error", "-2": "stream error", "-3": "data error", "-4": "insufficient memory", "-5": "buffer error", "-6": "incompatible version" } }, {}], 52: [function (e, t, r) { "use strict"; var o = e("../utils/common"); function n(e) { for (var t = e.length; 0 <= --t;)e[t] = 0 } var _ = 15, i = 16, u = [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], h = [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], a = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7], f = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15], l = new Array(576); n(l); var d = new Array(60); n(d); var c = new Array(512); n(c); var p = new Array(256); n(p); var m = new Array(29); n(m); var g, v, b, w = new Array(30); function y(e, t, r, n, i) { this.static_tree = e, this.extra_bits = t, this.extra_base = r, this.elems = n, this.max_length = i, this.has_stree = e && e.length } function s(e, t) { this.dyn_tree = e, this.max_code = 0, this.stat_desc = t } function k(e) { return e < 256 ? c[e] : c[256 + (e >>> 7)] } function x(e, t) { e.pending_buf[e.pending++] = 255 & t, e.pending_buf[e.pending++] = t >>> 8 & 255 } function S(e, t, r) { e.bi_valid > i - r ? (e.bi_buf |= t << e.bi_valid & 65535, x(e, e.bi_buf), e.bi_buf = t >> i - e.bi_valid, e.bi_valid += r - i) : (e.bi_buf |= t << e.bi_valid & 65535, e.bi_valid += r) } function z(e, t, r) { S(e, r[2 * t], r[2 * t + 1]) } function E(e, t) { for (var r = 0; r |= 1 & e, e >>>= 1, r <<= 1, 0 < --t;); return r >>> 1 } function C(e, t, r) { var n, i, s = new Array(_ + 1), a = 0; for (n = 1; n <= _; n++)s[n] = a = a + r[n - 1] << 1; for (i = 0; i <= t; i++) { var o = e[2 * i + 1]; 0 !== o && (e[2 * i] = E(s[o]++, o)) } } function A(e) { var t; for (t = 0; t < 286; t++)e.dyn_ltree[2 * t] = 0; for (t = 0; t < 30; t++)e.dyn_dtree[2 * t] = 0; for (t = 0; t < 19; t++)e.bl_tree[2 * t] = 0; e.dyn_ltree[512] = 1, e.opt_len = e.static_len = 0, e.last_lit = e.matches = 0 } function I(e) { 8 < e.bi_valid ? x(e, e.bi_buf) : 0 < e.bi_valid && (e.pending_buf[e.pending++] = e.bi_buf), e.bi_buf = 0, e.bi_valid = 0 } function O(e, t, r, n) { var i = 2 * t, s = 2 * r; return e[i] < e[s] || e[i] === e[s] && n[t] <= n[r] } function B(e, t, r) { for (var n = e.heap[r], i = r << 1; i <= e.heap_len && (i < e.heap_len && O(t, e.heap[i + 1], e.heap[i], e.depth) && i++, !O(t, n, e.heap[i], e.depth));)e.heap[r] = e.heap[i], r = i, i <<= 1; e.heap[r] = n } function T(e, t, r) { var n, i, s, a, o = 0; if (0 !== e.last_lit) for (; n = e.pending_buf[e.d_buf + 2 * o] << 8 | e.pending_buf[e.d_buf + 2 * o + 1], i = e.pending_buf[e.l_buf + o], o++, 0 === n ? z(e, i, t) : (z(e, (s = p[i]) + 256 + 1, t), 0 !== (a = u[s]) && S(e, i -= m[s], a), z(e, s = k(--n), r), 0 !== (a = h[s]) && S(e, n -= w[s], a)), o < e.last_lit;); z(e, 256, t) } function R(e, t) { var r, n, i, s = t.dyn_tree, a = t.stat_desc.static_tree, o = t.stat_desc.has_stree, u = t.stat_desc.elems, h = -1; for (e.heap_len = 0, e.heap_max = 573, r = 0; r < u; r++)0 !== s[2 * r] ? (e.heap[++e.heap_len] = h = r, e.depth[r] = 0) : s[2 * r + 1] = 0; for (; e.heap_len < 2;)s[2 * (i = e.heap[++e.heap_len] = h < 2 ? ++h : 0)] = 1, e.depth[i] = 0, e.opt_len--, o && (e.static_len -= a[2 * i + 1]); for (t.max_code = h, r = e.heap_len >> 1; 1 <= r; r--)B(e, s, r); for (i = u; r = e.heap[1], e.heap[1] = e.heap[e.heap_len--], B(e, s, 1), n = e.heap[1], e.heap[--e.heap_max] = r, e.heap[--e.heap_max] = n, s[2 * i] = s[2 * r] + s[2 * n], e.depth[i] = (e.depth[r] >= e.depth[n] ? e.depth[r] : e.depth[n]) + 1, s[2 * r + 1] = s[2 * n + 1] = i, e.heap[1] = i++, B(e, s, 1), 2 <= e.heap_len;); e.heap[--e.heap_max] = e.heap[1], function (e, t) { var r, n, i, s, a, o, u = t.dyn_tree, h = t.max_code, f = t.stat_desc.static_tree, l = t.stat_desc.has_stree, d = t.stat_desc.extra_bits, c = t.stat_desc.extra_base, p = t.stat_desc.max_length, m = 0; for (s = 0; s <= _; s++)e.bl_count[s] = 0; for (u[2 * e.heap[e.heap_max] + 1] = 0, r = e.heap_max + 1; r < 573; r++)p < (s = u[2 * u[2 * (n = e.heap[r]) + 1] + 1] + 1) && (s = p, m++), u[2 * n + 1] = s, h < n || (e.bl_count[s]++, a = 0, c <= n && (a = d[n - c]), o = u[2 * n], e.opt_len += o * (s + a), l && (e.static_len += o * (f[2 * n + 1] + a))); if (0 !== m) { do { for (s = p - 1; 0 === e.bl_count[s];)s--; e.bl_count[s]--, e.bl_count[s + 1] += 2, e.bl_count[p]--, m -= 2 } while (0 < m); for (s = p; 0 !== s; s--)for (n = e.bl_count[s]; 0 !== n;)h < (i = e.heap[--r]) || (u[2 * i + 1] !== s && (e.opt_len += (s - u[2 * i + 1]) * u[2 * i], u[2 * i + 1] = s), n--) } }(e, t), C(s, h, e.bl_count) } function D(e, t, r) { var n, i, s = -1, a = t[1], o = 0, u = 7, h = 4; for (0 === a && (u = 138, h = 3), t[2 * (r + 1) + 1] = 65535, n = 0; n <= r; n++)i = a, a = t[2 * (n + 1) + 1], ++o < u && i === a || (o < h ? e.bl_tree[2 * i] += o : 0 !== i ? (i !== s && e.bl_tree[2 * i]++, e.bl_tree[32]++) : o <= 10 ? e.bl_tree[34]++ : e.bl_tree[36]++, s = i, h = (o = 0) === a ? (u = 138, 3) : i === a ? (u = 6, 3) : (u = 7, 4)) } function F(e, t, r) { var n, i, s = -1, a = t[1], o = 0, u = 7, h = 4; for (0 === a && (u = 138, h = 3), n = 0; n <= r; n++)if (i = a, a = t[2 * (n + 1) + 1], !(++o < u && i === a)) { if (o < h) for (; z(e, i, e.bl_tree), 0 != --o;); else 0 !== i ? (i !== s && (z(e, i, e.bl_tree), o--), z(e, 16, e.bl_tree), S(e, o - 3, 2)) : o <= 10 ? (z(e, 17, e.bl_tree), S(e, o - 3, 3)) : (z(e, 18, e.bl_tree), S(e, o - 11, 7)); s = i, h = (o = 0) === a ? (u = 138, 3) : i === a ? (u = 6, 3) : (u = 7, 4) } } n(w); var N = !1; function U(e, t, r, n) { var i, s, a; S(e, 0 + (n ? 1 : 0), 3), s = t, a = r, I(i = e), x(i, a), x(i, ~a), o.arraySet(i.pending_buf, i.window, s, a, i.pending), i.pending += a } r._tr_init = function (e) { N || (function () { var e, t, r, n, i, s = new Array(_ + 1); for (n = r = 0; n < 28; n++)for (m[n] = r, e = 0; e < 1 << u[n]; e++)p[r++] = n; for (p[r - 1] = n, n = i = 0; n < 16; n++)for (w[n] = i, e = 0; e < 1 << h[n]; e++)c[i++] = n; for (i >>= 7; n < 30; n++)for (w[n] = i << 7, e = 0; e < 1 << h[n] - 7; e++)c[256 + i++] = n; for (t = 0; t <= _; t++)s[t] = 0; for (e = 0; e <= 143;)l[2 * e + 1] = 8, e++, s[8]++; for (; e <= 255;)l[2 * e + 1] = 9, e++, s[9]++; for (; e <= 279;)l[2 * e + 1] = 7, e++, s[7]++; for (; e <= 287;)l[2 * e + 1] = 8, e++, s[8]++; for (C(l, 287, s), e = 0; e < 30; e++)d[2 * e + 1] = 5, d[2 * e] = E(e, 5); g = new y(l, u, 257, 286, _), v = new y(d, h, 0, 30, _), b = new y(new Array(0), a, 0, 19, 7) }(), N = !0), e.l_desc = new s(e.dyn_ltree, g), e.d_desc = new s(e.dyn_dtree, v), e.bl_desc = new s(e.bl_tree, b), e.bi_buf = 0, e.bi_valid = 0, A(e) }, r._tr_stored_block = U, r._tr_flush_block = function (e, t, r, n) { var i, s, a = 0; 0 < e.level ? (2 === e.strm.data_type && (e.strm.data_type = function (e) { var t, r = 4093624447; for (t = 0; t <= 31; t++, r >>>= 1)if (1 & r && 0 !== e.dyn_ltree[2 * t]) return 0; if (0 !== e.dyn_ltree[18] || 0 !== e.dyn_ltree[20] || 0 !== e.dyn_ltree[26]) return 1; for (t = 32; t < 256; t++)if (0 !== e.dyn_ltree[2 * t]) return 1; return 0 }(e)), R(e, e.l_desc), R(e, e.d_desc), a = function (e) { var t; for (D(e, e.dyn_ltree, e.l_desc.max_code), D(e, e.dyn_dtree, e.d_desc.max_code), R(e, e.bl_desc), t = 18; 3 <= t && 0 === e.bl_tree[2 * f[t] + 1]; t--); return e.opt_len += 3 * (t + 1) + 5 + 5 + 4, t }(e), i = e.opt_len + 3 + 7 >>> 3, (s = e.static_len + 3 + 7 >>> 3) <= i && (i = s)) : i = s = r + 5, r + 4 <= i && -1 !== t ? U(e, t, r, n) : 4 === e.strategy || s === i ? (S(e, 2 + (n ? 1 : 0), 3), T(e, l, d)) : (S(e, 4 + (n ? 1 : 0), 3), function (e, t, r, n) { var i; for (S(e, t - 257, 5), S(e, r - 1, 5), S(e, n - 4, 4), i = 0; i < n; i++)S(e, e.bl_tree[2 * f[i] + 1], 3); F(e, e.dyn_ltree, t - 1), F(e, e.dyn_dtree, r - 1) }(e, e.l_desc.max_code + 1, e.d_desc.max_code + 1, a + 1), T(e, e.dyn_ltree, e.dyn_dtree)), A(e), n && I(e) }, r._tr_tally = function (e, t, r) { return e.pending_buf[e.d_buf + 2 * e.last_lit] = t >>> 8 & 255, e.pending_buf[e.d_buf + 2 * e.last_lit + 1] = 255 & t, e.pending_buf[e.l_buf + e.last_lit] = 255 & r, e.last_lit++, 0 === t ? e.dyn_ltree[2 * r]++ : (e.matches++, t--, e.dyn_ltree[2 * (p[r] + 256 + 1)]++, e.dyn_dtree[2 * k(t)]++), e.last_lit === e.lit_bufsize - 1 }, r._tr_align = function (e) { var t; S(e, 2, 3), z(e, 256, l), 16 === (t = e).bi_valid ? (x(t, t.bi_buf), t.bi_buf = 0, t.bi_valid = 0) : 8 <= t.bi_valid && (t.pending_buf[t.pending++] = 255 & t.bi_buf, t.bi_buf >>= 8, t.bi_valid -= 8) } }, { "../utils/common": 41 }], 53: [function (e, t, r) { "use strict"; t.exports = function () { this.input = null, this.next_in = 0, this.avail_in = 0, this.total_in = 0, this.output = null, this.next_out = 0, this.avail_out = 0, this.total_out = 0, this.msg = "", this.state = null, this.data_type = 2, this.adler = 0 } }, {}], 54: [function (e, t, r) { "use strict"; t.exports = "function" == typeof setImmediate ? setImmediate : function () { var e = [].slice.apply(arguments); e.splice(1, 0, 0), setTimeout.apply(null, e) } }, {}] }, {}, [10])(10) }) }).call(this, void 0 !== r ? r : "undefined" != typeof self ? self : "undefined" != typeof window ? window : {}) }, {}] }, {}, [1])(1) }) }).call(this, void 0 !== r ? r : "undefined" != typeof self ? self : "undefined" != typeof window ? window : {}) }, {}] }, {}, [1])(1) }) }).call(this, void 0 !== r ? r : "undefined" != typeof self ? self : "undefined" != typeof window ? window : {}) }, {}] }, {}, [1])(1) }) }).call(this, void 0 !== r ? r : "undefined" != typeof self ? self : "undefined" != typeof window ? window : {}) }, {}] }, {}, [1])(1) }) }).call(this, "undefined" != typeof global ? global : "undefined" != typeof self ? self : "undefined" != typeof window ? window : {}) }, {}] }, {}, [1])(1) });
  2212. }).call(this)
  2213. }).call(this, typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}, require("buffer").Buffer, require("timers").setImmediate)
  2214. }, { "buffer": 8, "timers": 22 }], 12: [function (require, module, exports) {
  2215. 'use strict';
  2216. var immediate = require('immediate');
  2217. /* istanbul ignore next */
  2218. function INTERNAL() { }
  2219. var handlers = {};
  2220. var REJECTED = ['REJECTED'];
  2221. var FULFILLED = ['FULFILLED'];
  2222. var PENDING = ['PENDING'];
  2223. module.exports = Promise;
  2224. function Promise(resolver) {
  2225. if (typeof resolver !== 'function') {
  2226. throw new TypeError('resolver must be a function');
  2227. }
  2228. this.state = PENDING;
  2229. this.queue = [];
  2230. this.outcome = void 0;
  2231. if (resolver !== INTERNAL) {
  2232. safelyResolveThenable(this, resolver);
  2233. }
  2234. }
  2235. Promise.prototype["finally"] = function (callback) {
  2236. if (typeof callback !== 'function') {
  2237. return this;
  2238. }
  2239. var p = this.constructor;
  2240. return this.then(resolve, reject);
  2241. function resolve(value) {
  2242. function yes() {
  2243. return value;
  2244. }
  2245. return p.resolve(callback()).then(yes);
  2246. }
  2247. function reject(reason) {
  2248. function no() {
  2249. throw reason;
  2250. }
  2251. return p.resolve(callback()).then(no);
  2252. }
  2253. };
  2254. Promise.prototype["catch"] = function (onRejected) {
  2255. return this.then(null, onRejected);
  2256. };
  2257. Promise.prototype.then = function (onFulfilled, onRejected) {
  2258. if (typeof onFulfilled !== 'function' && this.state === FULFILLED ||
  2259. typeof onRejected !== 'function' && this.state === REJECTED) {
  2260. return this;
  2261. }
  2262. var promise = new this.constructor(INTERNAL);
  2263. if (this.state !== PENDING) {
  2264. var resolver = this.state === FULFILLED ? onFulfilled : onRejected;
  2265. unwrap(promise, resolver, this.outcome);
  2266. } else {
  2267. this.queue.push(new QueueItem(promise, onFulfilled, onRejected));
  2268. }
  2269. return promise;
  2270. };
  2271. function QueueItem(promise, onFulfilled, onRejected) {
  2272. this.promise = promise;
  2273. if (typeof onFulfilled === 'function') {
  2274. this.onFulfilled = onFulfilled;
  2275. this.callFulfilled = this.otherCallFulfilled;
  2276. }
  2277. if (typeof onRejected === 'function') {
  2278. this.onRejected = onRejected;
  2279. this.callRejected = this.otherCallRejected;
  2280. }
  2281. }
  2282. QueueItem.prototype.callFulfilled = function (value) {
  2283. handlers.resolve(this.promise, value);
  2284. };
  2285. QueueItem.prototype.otherCallFulfilled = function (value) {
  2286. unwrap(this.promise, this.onFulfilled, value);
  2287. };
  2288. QueueItem.prototype.callRejected = function (value) {
  2289. handlers.reject(this.promise, value);
  2290. };
  2291. QueueItem.prototype.otherCallRejected = function (value) {
  2292. unwrap(this.promise, this.onRejected, value);
  2293. };
  2294. function unwrap(promise, func, value) {
  2295. immediate(function () {
  2296. var returnValue;
  2297. try {
  2298. returnValue = func(value);
  2299. } catch (e) {
  2300. return handlers.reject(promise, e);
  2301. }
  2302. if (returnValue === promise) {
  2303. handlers.reject(promise, new TypeError('Cannot resolve promise with itself'));
  2304. } else {
  2305. handlers.resolve(promise, returnValue);
  2306. }
  2307. });
  2308. }
  2309. handlers.resolve = function (self, value) {
  2310. var result = tryCatch(getThen, value);
  2311. if (result.status === 'error') {
  2312. return handlers.reject(self, result.value);
  2313. }
  2314. var thenable = result.value;
  2315. if (thenable) {
  2316. safelyResolveThenable(self, thenable);
  2317. } else {
  2318. self.state = FULFILLED;
  2319. self.outcome = value;
  2320. var i = -1;
  2321. var len = self.queue.length;
  2322. while (++i < len) {
  2323. self.queue[i].callFulfilled(value);
  2324. }
  2325. }
  2326. return self;
  2327. };
  2328. handlers.reject = function (self, error) {
  2329. self.state = REJECTED;
  2330. self.outcome = error;
  2331. var i = -1;
  2332. var len = self.queue.length;
  2333. while (++i < len) {
  2334. self.queue[i].callRejected(error);
  2335. }
  2336. return self;
  2337. };
  2338. function getThen(obj) {
  2339. // Make sure we only access the accessor once as required by the spec
  2340. var then = obj && obj.then;
  2341. if (obj && (typeof obj === 'object' || typeof obj === 'function') && typeof then === 'function') {
  2342. return function appyThen() {
  2343. then.apply(obj, arguments);
  2344. };
  2345. }
  2346. }
  2347. function safelyResolveThenable(self, thenable) {
  2348. // Either fulfill, reject or reject with error
  2349. var called = false;
  2350. function onError(value) {
  2351. if (called) {
  2352. return;
  2353. }
  2354. called = true;
  2355. handlers.reject(self, value);
  2356. }
  2357. function onSuccess(value) {
  2358. if (called) {
  2359. return;
  2360. }
  2361. called = true;
  2362. handlers.resolve(self, value);
  2363. }
  2364. function tryToUnwrap() {
  2365. thenable(onSuccess, onError);
  2366. }
  2367. var result = tryCatch(tryToUnwrap);
  2368. if (result.status === 'error') {
  2369. onError(result.value);
  2370. }
  2371. }
  2372. function tryCatch(func, value) {
  2373. var out = {};
  2374. try {
  2375. out.value = func(value);
  2376. out.status = 'success';
  2377. } catch (e) {
  2378. out.status = 'error';
  2379. out.value = e;
  2380. }
  2381. return out;
  2382. }
  2383. Promise.resolve = resolve;
  2384. function resolve(value) {
  2385. if (value instanceof this) {
  2386. return value;
  2387. }
  2388. return handlers.resolve(new this(INTERNAL), value);
  2389. }
  2390. Promise.reject = reject;
  2391. function reject(reason) {
  2392. var promise = new this(INTERNAL);
  2393. return handlers.reject(promise, reason);
  2394. }
  2395. Promise.all = all;
  2396. function all(iterable) {
  2397. var self = this;
  2398. if (Object.prototype.toString.call(iterable) !== '[object Array]') {
  2399. return this.reject(new TypeError('must be an array'));
  2400. }
  2401. var len = iterable.length;
  2402. var called = false;
  2403. if (!len) {
  2404. return this.resolve([]);
  2405. }
  2406. var values = new Array(len);
  2407. var resolved = 0;
  2408. var i = -1;
  2409. var promise = new this(INTERNAL);
  2410. while (++i < len) {
  2411. allResolver(iterable[i], i);
  2412. }
  2413. return promise;
  2414. function allResolver(value, i) {
  2415. self.resolve(value).then(resolveFromAll, function (error) {
  2416. if (!called) {
  2417. called = true;
  2418. handlers.reject(promise, error);
  2419. }
  2420. });
  2421. function resolveFromAll(outValue) {
  2422. values[i] = outValue;
  2423. if (++resolved === len && !called) {
  2424. called = true;
  2425. handlers.resolve(promise, values);
  2426. }
  2427. }
  2428. }
  2429. }
  2430. Promise.race = race;
  2431. function race(iterable) {
  2432. var self = this;
  2433. if (Object.prototype.toString.call(iterable) !== '[object Array]') {
  2434. return this.reject(new TypeError('must be an array'));
  2435. }
  2436. var len = iterable.length;
  2437. var called = false;
  2438. if (!len) {
  2439. return this.resolve([]);
  2440. }
  2441. var i = -1;
  2442. var promise = new this(INTERNAL);
  2443. while (++i < len) {
  2444. resolver(iterable[i]);
  2445. }
  2446. return promise;
  2447. function resolver(value) {
  2448. self.resolve(value).then(function (response) {
  2449. if (!called) {
  2450. called = true;
  2451. handlers.resolve(promise, response);
  2452. }
  2453. }, function (error) {
  2454. if (!called) {
  2455. called = true;
  2456. handlers.reject(promise, error);
  2457. }
  2458. });
  2459. }
  2460. }
  2461. }, { "immediate": 10 }], 13: [function (require, module, exports) {
  2462. ; (function () { // closure for web browsers
  2463. if (typeof module === 'object' && module.exports) {
  2464. module.exports = LRUCache
  2465. } else {
  2466. // just set the global for non-node platforms.
  2467. this.LRUCache = LRUCache
  2468. }
  2469. function hOP(obj, key) {
  2470. return Object.prototype.hasOwnProperty.call(obj, key)
  2471. }
  2472. function naiveLength() { return 1 }
  2473. var didTypeWarning = false
  2474. function typeCheckKey(key) {
  2475. if (!didTypeWarning && typeof key !== 'string' && typeof key !== 'number') {
  2476. didTypeWarning = true
  2477. // console.error(new TypeError("LRU: key must be a string or number. Almost certainly a bug! " + typeof key).stack)
  2478. }
  2479. }
  2480. function LRUCache(options) {
  2481. if (!(this instanceof LRUCache))
  2482. return new LRUCache(options)
  2483. if (typeof options === 'number')
  2484. options = { max: options }
  2485. if (!options)
  2486. options = {}
  2487. this._max = options.max
  2488. // Kind of weird to have a default max of Infinity, but oh well.
  2489. if (!this._max || !(typeof this._max === "number") || this._max <= 0)
  2490. this._max = Infinity
  2491. this._lengthCalculator = options.length || naiveLength
  2492. if (typeof this._lengthCalculator !== "function")
  2493. this._lengthCalculator = naiveLength
  2494. this._allowStale = options.stale || false
  2495. this._maxAge = options.maxAge || null
  2496. this._dispose = options.dispose
  2497. this.reset()
  2498. }
  2499. // resize the cache when the max changes.
  2500. Object.defineProperty(LRUCache.prototype, "max",
  2501. {
  2502. set: function (mL) {
  2503. if (!mL || !(typeof mL === "number") || mL <= 0) mL = Infinity
  2504. this._max = mL
  2505. if (this._length > this._max) trim(this)
  2506. }
  2507. , get: function () { return this._max }
  2508. , enumerable: true
  2509. })
  2510. // resize the cache when the lengthCalculator changes.
  2511. Object.defineProperty(LRUCache.prototype, "lengthCalculator",
  2512. {
  2513. set: function (lC) {
  2514. if (typeof lC !== "function") {
  2515. this._lengthCalculator = naiveLength
  2516. this._length = this._itemCount
  2517. for (var key in this._cache) {
  2518. this._cache[key].length = 1
  2519. }
  2520. } else {
  2521. this._lengthCalculator = lC
  2522. this._length = 0
  2523. for (var key in this._cache) {
  2524. this._cache[key].length = this._lengthCalculator(this._cache[key].value)
  2525. this._length += this._cache[key].length
  2526. }
  2527. }
  2528. if (this._length > this._max) trim(this)
  2529. }
  2530. , get: function () { return this._lengthCalculator }
  2531. , enumerable: true
  2532. })
  2533. Object.defineProperty(LRUCache.prototype, "length",
  2534. {
  2535. get: function () { return this._length }
  2536. , enumerable: true
  2537. })
  2538. Object.defineProperty(LRUCache.prototype, "itemCount",
  2539. {
  2540. get: function () { return this._itemCount }
  2541. , enumerable: true
  2542. })
  2543. LRUCache.prototype.forEach = function (fn, thisp) {
  2544. thisp = thisp || this
  2545. var i = 0
  2546. var itemCount = this._itemCount
  2547. for (var k = this._mru - 1; k >= 0 && i < itemCount; k--) if (this._lruList[k]) {
  2548. i++
  2549. var hit = this._lruList[k]
  2550. if (isStale(this, hit)) {
  2551. del(this, hit)
  2552. if (!this._allowStale) hit = undefined
  2553. }
  2554. if (hit) {
  2555. fn.call(thisp, hit.value, hit.key, this)
  2556. }
  2557. }
  2558. }
  2559. LRUCache.prototype.keys = function () {
  2560. var keys = new Array(this._itemCount)
  2561. var i = 0
  2562. for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) {
  2563. var hit = this._lruList[k]
  2564. keys[i++] = hit.key
  2565. }
  2566. return keys
  2567. }
  2568. LRUCache.prototype.values = function () {
  2569. var values = new Array(this._itemCount)
  2570. var i = 0
  2571. for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) {
  2572. var hit = this._lruList[k]
  2573. values[i++] = hit.value
  2574. }
  2575. return values
  2576. }
  2577. LRUCache.prototype.reset = function () {
  2578. if (this._dispose && this._cache) {
  2579. for (var k in this._cache) {
  2580. this._dispose(k, this._cache[k].value)
  2581. }
  2582. }
  2583. this._cache = Object.create(null) // hash of items by key
  2584. this._lruList = Object.create(null) // list of items in order of use recency
  2585. this._mru = 0 // most recently used
  2586. this._lru = 0 // least recently used
  2587. this._length = 0 // number of items in the list
  2588. this._itemCount = 0
  2589. }
  2590. LRUCache.prototype.dump = function () {
  2591. var arr = []
  2592. var i = 0
  2593. for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) {
  2594. var hit = this._lruList[k]
  2595. if (!isStale(this, hit)) {
  2596. //Do not store staled hits
  2597. ++i
  2598. arr.push({
  2599. k: hit.key,
  2600. v: hit.value,
  2601. e: hit.now + (hit.maxAge || 0)
  2602. });
  2603. }
  2604. }
  2605. //arr has the most read first
  2606. return arr
  2607. }
  2608. LRUCache.prototype.dumpLru = function () {
  2609. return this._lruList
  2610. }
  2611. LRUCache.prototype.set = function (key, value, maxAge) {
  2612. maxAge = maxAge || this._maxAge
  2613. typeCheckKey(key)
  2614. var now = maxAge ? Date.now() : 0
  2615. var len = this._lengthCalculator(value)
  2616. if (hOP(this._cache, key)) {
  2617. if (len > this._max) {
  2618. del(this, this._cache[key])
  2619. return false
  2620. }
  2621. // dispose of the old one before overwriting
  2622. if (this._dispose)
  2623. this._dispose(key, this._cache[key].value)
  2624. this._cache[key].now = now
  2625. this._cache[key].maxAge = maxAge
  2626. this._cache[key].value = value
  2627. this._length += (len - this._cache[key].length)
  2628. this._cache[key].length = len
  2629. this.get(key)
  2630. if (this._length > this._max)
  2631. trim(this)
  2632. return true
  2633. }
  2634. var hit = new Entry(key, value, this._mru++, len, now, maxAge)
  2635. // oversized objects fall out of cache automatically.
  2636. if (hit.length > this._max) {
  2637. if (this._dispose) this._dispose(key, value)
  2638. return false
  2639. }
  2640. this._length += hit.length
  2641. this._lruList[hit.lu] = this._cache[key] = hit
  2642. this._itemCount++
  2643. if (this._length > this._max)
  2644. trim(this)
  2645. return true
  2646. }
  2647. LRUCache.prototype.has = function (key) {
  2648. typeCheckKey(key)
  2649. if (!hOP(this._cache, key)) return false
  2650. var hit = this._cache[key]
  2651. if (isStale(this, hit)) {
  2652. return false
  2653. }
  2654. return true
  2655. }
  2656. LRUCache.prototype.get = function (key) {
  2657. typeCheckKey(key)
  2658. return get(this, key, true)
  2659. }
  2660. LRUCache.prototype.peek = function (key) {
  2661. typeCheckKey(key)
  2662. return get(this, key, false)
  2663. }
  2664. LRUCache.prototype.pop = function () {
  2665. var hit = this._lruList[this._lru]
  2666. del(this, hit)
  2667. return hit || null
  2668. }
  2669. LRUCache.prototype.del = function (key) {
  2670. typeCheckKey(key)
  2671. del(this, this._cache[key])
  2672. }
  2673. LRUCache.prototype.load = function (arr) {
  2674. //reset the cache
  2675. this.reset();
  2676. var now = Date.now()
  2677. //A previous serialized cache has the most recent items first
  2678. for (var l = arr.length - 1; l >= 0; l--) {
  2679. var hit = arr[l]
  2680. typeCheckKey(hit.k)
  2681. var expiresAt = hit.e || 0
  2682. if (expiresAt === 0) {
  2683. //the item was created without expiration in a non aged cache
  2684. this.set(hit.k, hit.v)
  2685. } else {
  2686. var maxAge = expiresAt - now
  2687. //dont add already expired items
  2688. if (maxAge > 0) this.set(hit.k, hit.v, maxAge)
  2689. }
  2690. }
  2691. }
  2692. function get(self, key, doUse) {
  2693. typeCheckKey(key)
  2694. var hit = self._cache[key]
  2695. if (hit) {
  2696. if (isStale(self, hit)) {
  2697. del(self, hit)
  2698. if (!self._allowStale) hit = undefined
  2699. } else {
  2700. if (doUse) use(self, hit)
  2701. }
  2702. if (hit) hit = hit.value
  2703. }
  2704. return hit
  2705. }
  2706. function isStale(self, hit) {
  2707. if (!hit || (!hit.maxAge && !self._maxAge)) return false
  2708. var stale = false;
  2709. var diff = Date.now() - hit.now
  2710. if (hit.maxAge) {
  2711. stale = diff > hit.maxAge
  2712. } else {
  2713. stale = self._maxAge && (diff > self._maxAge)
  2714. }
  2715. return stale;
  2716. }
  2717. function use(self, hit) {
  2718. shiftLU(self, hit)
  2719. hit.lu = self._mru++
  2720. self._lruList[hit.lu] = hit
  2721. }
  2722. function trim(self) {
  2723. while (self._lru < self._mru && self._length > self._max)
  2724. del(self, self._lruList[self._lru])
  2725. }
  2726. function shiftLU(self, hit) {
  2727. delete self._lruList[hit.lu]
  2728. while (self._lru < self._mru && !self._lruList[self._lru]) self._lru++
  2729. }
  2730. function del(self, hit) {
  2731. if (hit) {
  2732. if (self._dispose) self._dispose(hit.key, hit.value)
  2733. self._length -= hit.length
  2734. self._itemCount--
  2735. delete self._cache[hit.key]
  2736. shiftLU(self, hit)
  2737. }
  2738. }
  2739. // classy, since V8 prefers predictable objects.
  2740. function Entry(key, value, lu, length, now, maxAge) {
  2741. this.key = key
  2742. this.value = value
  2743. this.lu = lu
  2744. this.length = length
  2745. this.now = now
  2746. if (maxAge) this.maxAge = maxAge
  2747. }
  2748. })()
  2749. }, {}], 14: [function (require, module, exports) {
  2750. require('text-encoding-polyfill');
  2751. var StringDecoder = require('string_decoder').StringDecoder;
  2752. function defaultDecoder(data) {
  2753. var decoder = new StringDecoder();
  2754. var out = decoder.write(data) + decoder.end();
  2755. return out.replace(/\0/g, '').trim();
  2756. }
  2757. module.exports = createDecoder;
  2758. var regex = /^(?:ANSI\s)?(\d+)$/m;
  2759. function createDecoder(encoding, second) {
  2760. if (!encoding) {
  2761. return defaultDecoder;
  2762. }
  2763. try {
  2764. new TextDecoder(encoding.trim());
  2765. } catch (e) {
  2766. var match = regex.exec(encoding);
  2767. if (match && !second) {
  2768. return createDecoder('windows-' + match[1], true);
  2769. } else {
  2770. return defaultDecoder;
  2771. }
  2772. }
  2773. return browserDecoder;
  2774. function browserDecoder(buffer) {
  2775. var decoder = new TextDecoder(encoding);
  2776. var out = decoder.decode(buffer, {
  2777. stream: true
  2778. }) + decoder.decode();
  2779. return out.replace(/\0/g, '').trim();
  2780. }
  2781. }
  2782. }, { "string_decoder": 19, "text-encoding-polyfill": 20 }], 15: [function (require, module, exports) {
  2783. var createDecoder = require('./decoder');
  2784. function dbfHeader(data) {
  2785. var out = {};
  2786. out.lastUpdated = new Date(data.readUInt8(1) + 1900, data.readUInt8(2), data.readUInt8(3));
  2787. out.records = data.readUInt32LE(4);
  2788. out.headerLen = data.readUInt16LE(8);
  2789. out.recLen = data.readUInt16LE(10);
  2790. return out;
  2791. }
  2792. function dbfRowHeader(data, headerLen, decoder) {
  2793. var out = [];
  2794. var offset = 32;
  2795. while (offset < headerLen) {
  2796. out.push({
  2797. name: decoder(data.slice(offset, offset + 11)),
  2798. dataType: String.fromCharCode(data.readUInt8(offset + 11)),
  2799. len: data.readUInt8(offset + 16),
  2800. decimal: data.readUInt8(offset + 17)
  2801. });
  2802. if (data.readUInt8(offset + 32) === 13) {
  2803. break;
  2804. } else {
  2805. offset += 32;
  2806. }
  2807. }
  2808. return out;
  2809. }
  2810. function rowFuncs(buffer, offset, len, type, decoder) {
  2811. var data = buffer.slice(offset, offset + len);
  2812. var textData = decoder(data);
  2813. switch (type) {
  2814. case 'N':
  2815. case 'F':
  2816. case 'O':
  2817. return parseFloat(textData, 10);
  2818. case 'D':
  2819. return new Date(textData.slice(0, 4), parseInt(textData.slice(4, 6), 10) - 1, textData.slice(6, 8));
  2820. case 'L':
  2821. return textData.toLowerCase() === 'y' || textData.toLowerCase() === 't';
  2822. default:
  2823. return textData;
  2824. }
  2825. }
  2826. function parseRow(buffer, offset, rowHeaders, decoder) {
  2827. var out = {};
  2828. var i = 0;
  2829. var len = rowHeaders.length;
  2830. var field;
  2831. var header;
  2832. while (i < len) {
  2833. header = rowHeaders[i];
  2834. field = rowFuncs(buffer, offset, header.len, header.dataType, decoder);
  2835. offset += header.len;
  2836. if (typeof field !== 'undefined') {
  2837. out[header.name] = field;
  2838. }
  2839. i++;
  2840. }
  2841. return out;
  2842. }
  2843. module.exports = function (buffer, encoding) {
  2844. var decoder = createDecoder(encoding);
  2845. var header = dbfHeader(buffer);
  2846. var rowHeaders = dbfRowHeader(buffer, header.headerLen - 1, decoder);
  2847. var offset = ((rowHeaders.length + 1) << 5) + 2;
  2848. var recLen = header.recLen;
  2849. var records = header.records;
  2850. var out = [];
  2851. while (records) {
  2852. out.push(parseRow(buffer, offset, rowHeaders, decoder));
  2853. offset += recLen;
  2854. records--;
  2855. }
  2856. return out;
  2857. };
  2858. }, { "./decoder": 14 }], 16: [function (require, module, exports) {
  2859. // shim for using process in browser
  2860. var process = module.exports = {};
  2861. // cached from whatever global is present so that test runners that stub it
  2862. // don't break things. But we need to wrap it in a try catch in case it is
  2863. // wrapped in strict mode code which doesn't define any globals. It's inside a
  2864. // function because try/catches deoptimize in certain engines.
  2865. var cachedSetTimeout;
  2866. var cachedClearTimeout;
  2867. function defaultSetTimout() {
  2868. throw new Error('setTimeout has not been defined');
  2869. }
  2870. function defaultClearTimeout() {
  2871. throw new Error('clearTimeout has not been defined');
  2872. }
  2873. (function () {
  2874. try {
  2875. if (typeof setTimeout === 'function') {
  2876. cachedSetTimeout = setTimeout;
  2877. } else {
  2878. cachedSetTimeout = defaultSetTimout;
  2879. }
  2880. } catch (e) {
  2881. cachedSetTimeout = defaultSetTimout;
  2882. }
  2883. try {
  2884. if (typeof clearTimeout === 'function') {
  2885. cachedClearTimeout = clearTimeout;
  2886. } else {
  2887. cachedClearTimeout = defaultClearTimeout;
  2888. }
  2889. } catch (e) {
  2890. cachedClearTimeout = defaultClearTimeout;
  2891. }
  2892. }())
  2893. function runTimeout(fun) {
  2894. if (cachedSetTimeout === setTimeout) {
  2895. //normal enviroments in sane situations
  2896. return setTimeout(fun, 0);
  2897. }
  2898. // if setTimeout wasn't available but was latter defined
  2899. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  2900. cachedSetTimeout = setTimeout;
  2901. return setTimeout(fun, 0);
  2902. }
  2903. try {
  2904. // when when somebody has screwed with setTimeout but no I.E. maddness
  2905. return cachedSetTimeout(fun, 0);
  2906. } catch (e) {
  2907. try {
  2908. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  2909. return cachedSetTimeout.call(null, fun, 0);
  2910. } catch (e) {
  2911. // 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
  2912. return cachedSetTimeout.call(this, fun, 0);
  2913. }
  2914. }
  2915. }
  2916. function runClearTimeout(marker) {
  2917. if (cachedClearTimeout === clearTimeout) {
  2918. //normal enviroments in sane situations
  2919. return clearTimeout(marker);
  2920. }
  2921. // if clearTimeout wasn't available but was latter defined
  2922. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  2923. cachedClearTimeout = clearTimeout;
  2924. return clearTimeout(marker);
  2925. }
  2926. try {
  2927. // when when somebody has screwed with setTimeout but no I.E. maddness
  2928. return cachedClearTimeout(marker);
  2929. } catch (e) {
  2930. try {
  2931. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  2932. return cachedClearTimeout.call(null, marker);
  2933. } catch (e) {
  2934. // 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.
  2935. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  2936. return cachedClearTimeout.call(this, marker);
  2937. }
  2938. }
  2939. }
  2940. var queue = [];
  2941. var draining = false;
  2942. var currentQueue;
  2943. var queueIndex = -1;
  2944. function cleanUpNextTick() {
  2945. if (!draining || !currentQueue) {
  2946. return;
  2947. }
  2948. draining = false;
  2949. if (currentQueue.length) {
  2950. queue = currentQueue.concat(queue);
  2951. } else {
  2952. queueIndex = -1;
  2953. }
  2954. if (queue.length) {
  2955. drainQueue();
  2956. }
  2957. }
  2958. function drainQueue() {
  2959. if (draining) {
  2960. return;
  2961. }
  2962. var timeout = runTimeout(cleanUpNextTick);
  2963. draining = true;
  2964. var len = queue.length;
  2965. while (len) {
  2966. currentQueue = queue;
  2967. queue = [];
  2968. while (++queueIndex < len) {
  2969. if (currentQueue) {
  2970. currentQueue[queueIndex].run();
  2971. }
  2972. }
  2973. queueIndex = -1;
  2974. len = queue.length;
  2975. }
  2976. currentQueue = null;
  2977. draining = false;
  2978. runClearTimeout(timeout);
  2979. }
  2980. process.nextTick = function (fun) {
  2981. var args = new Array(arguments.length - 1);
  2982. if (arguments.length > 1) {
  2983. for (var i = 1; i < arguments.length; i++) {
  2984. args[i - 1] = arguments[i];
  2985. }
  2986. }
  2987. queue.push(new Item(fun, args));
  2988. if (queue.length === 1 && !draining) {
  2989. runTimeout(drainQueue);
  2990. }
  2991. };
  2992. // v8 likes predictible objects
  2993. function Item(fun, array) {
  2994. this.fun = fun;
  2995. this.array = array;
  2996. }
  2997. Item.prototype.run = function () {
  2998. this.fun.apply(null, this.array);
  2999. };
  3000. process.title = 'browser';
  3001. process.browser = true;
  3002. process.env = {};
  3003. process.argv = [];
  3004. process.version = ''; // empty string to avoid regexp issues
  3005. process.versions = {};
  3006. function noop() { }
  3007. process.on = noop;
  3008. process.addListener = noop;
  3009. process.once = noop;
  3010. process.off = noop;
  3011. process.removeListener = noop;
  3012. process.removeAllListeners = noop;
  3013. process.emit = noop;
  3014. process.prependListener = noop;
  3015. process.prependOnceListener = noop;
  3016. process.listeners = function (name) { return [] }
  3017. process.binding = function (name) {
  3018. throw new Error('process.binding is not supported');
  3019. };
  3020. process.cwd = function () { return '/' };
  3021. process.chdir = function (dir) {
  3022. throw new Error('process.chdir is not supported');
  3023. };
  3024. process.umask = function () { return 0; };
  3025. }, {}], 17: [function (require, module, exports) {
  3026. (function (global, factory) {
  3027. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  3028. typeof define === 'function' && define.amd ? define(factory) :
  3029. (global.proj4 = factory());
  3030. }(this, (function () {
  3031. 'use strict';
  3032. var globals = function (defs) {
  3033. defs('EPSG:4326', "+title=WGS 84 (long/lat) +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees");
  3034. defs('EPSG:4269', "+title=NAD83 (long/lat) +proj=longlat +a=6378137.0 +b=6356752.31414036 +ellps=GRS80 +datum=NAD83 +units=degrees");
  3035. defs('EPSG:3857', "+title=WGS 84 / Pseudo-Mercator +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs");
  3036. defs.WGS84 = defs['EPSG:4326'];
  3037. defs['EPSG:3785'] = defs['EPSG:3857']; // maintain backward compat, official code is 3857
  3038. defs.GOOGLE = defs['EPSG:3857'];
  3039. defs['EPSG:900913'] = defs['EPSG:3857'];
  3040. defs['EPSG:102113'] = defs['EPSG:3857'];
  3041. };
  3042. var PJD_3PARAM = 1;
  3043. var PJD_7PARAM = 2;
  3044. var PJD_GRIDSHIFT = 3;
  3045. var PJD_WGS84 = 4; // WGS84 or equivalent
  3046. var PJD_NODATUM = 5; // WGS84 or equivalent
  3047. var SRS_WGS84_SEMIMAJOR = 6378137.0; // only used in grid shift transforms
  3048. var SRS_WGS84_SEMIMINOR = 6356752.314; // only used in grid shift transforms
  3049. var SRS_WGS84_ESQUARED = 0.0066943799901413165; // only used in grid shift transforms
  3050. var SEC_TO_RAD = 4.84813681109535993589914102357e-6;
  3051. var HALF_PI = Math.PI / 2;
  3052. // ellipoid pj_set_ell.c
  3053. var SIXTH = 0.1666666666666666667;
  3054. /* 1/6 */
  3055. var RA4 = 0.04722222222222222222;
  3056. /* 17/360 */
  3057. var RA6 = 0.02215608465608465608;
  3058. var EPSLN = 1.0e-10;
  3059. // you'd think you could use Number.EPSILON above but that makes
  3060. // Mollweide get into an infinate loop.
  3061. var D2R = 0.01745329251994329577;
  3062. var R2D = 57.29577951308232088;
  3063. var FORTPI = Math.PI / 4;
  3064. var TWO_PI = Math.PI * 2;
  3065. // SPI is slightly greater than Math.PI, so values that exceed the -180..180
  3066. // degree range by a tiny amount don't get wrapped. This prevents points that
  3067. // have drifted from their original location along the 180th meridian (due to
  3068. // floating point error) from changing their sign.
  3069. var SPI = 3.14159265359;
  3070. var exports$1 = {};
  3071. exports$1.greenwich = 0.0; //"0dE",
  3072. exports$1.lisbon = -9.131906111111; //"9d07'54.862\"W",
  3073. exports$1.paris = 2.337229166667; //"2d20'14.025\"E",
  3074. exports$1.bogota = -74.080916666667; //"74d04'51.3\"W",
  3075. exports$1.madrid = -3.687938888889; //"3d41'16.58\"W",
  3076. exports$1.rome = 12.452333333333; //"12d27'8.4\"E",
  3077. exports$1.bern = 7.439583333333; //"7d26'22.5\"E",
  3078. exports$1.jakarta = 106.807719444444; //"106d48'27.79\"E",
  3079. exports$1.ferro = -17.666666666667; //"17d40'W",
  3080. exports$1.brussels = 4.367975; //"4d22'4.71\"E",
  3081. exports$1.stockholm = 18.058277777778; //"18d3'29.8\"E",
  3082. exports$1.athens = 23.7163375; //"23d42'58.815\"E",
  3083. exports$1.oslo = 10.722916666667; //"10d43'22.5\"E"
  3084. var units = {
  3085. ft: { to_meter: 0.3048 },
  3086. 'us-ft': { to_meter: 1200 / 3937 }
  3087. };
  3088. var ignoredChar = /[\s_\-\/\(\)]/g;
  3089. function match(obj, key) {
  3090. if (obj[key]) {
  3091. return obj[key];
  3092. }
  3093. var keys = Object.keys(obj);
  3094. var lkey = key.toLowerCase().replace(ignoredChar, '');
  3095. var i = -1;
  3096. var testkey, processedKey;
  3097. while (++i < keys.length) {
  3098. testkey = keys[i];
  3099. processedKey = testkey.toLowerCase().replace(ignoredChar, '');
  3100. if (processedKey === lkey) {
  3101. return obj[testkey];
  3102. }
  3103. }
  3104. }
  3105. var parseProj = function (defData) {
  3106. var self = {};
  3107. var paramObj = defData.split('+').map(function (v) {
  3108. return v.trim();
  3109. }).filter(function (a) {
  3110. return a;
  3111. }).reduce(function (p, a) {
  3112. var split = a.split('=');
  3113. split.push(true);
  3114. p[split[0].toLowerCase()] = split[1];
  3115. return p;
  3116. }, {});
  3117. var paramName, paramVal, paramOutname;
  3118. var params = {
  3119. proj: 'projName',
  3120. datum: 'datumCode',
  3121. rf: function (v) {
  3122. self.rf = parseFloat(v);
  3123. },
  3124. lat_0: function (v) {
  3125. self.lat0 = v * D2R;
  3126. },
  3127. lat_1: function (v) {
  3128. self.lat1 = v * D2R;
  3129. },
  3130. lat_2: function (v) {
  3131. self.lat2 = v * D2R;
  3132. },
  3133. lat_ts: function (v) {
  3134. self.lat_ts = v * D2R;
  3135. },
  3136. lon_0: function (v) {
  3137. self.long0 = v * D2R;
  3138. },
  3139. lon_1: function (v) {
  3140. self.long1 = v * D2R;
  3141. },
  3142. lon_2: function (v) {
  3143. self.long2 = v * D2R;
  3144. },
  3145. alpha: function (v) {
  3146. self.alpha = parseFloat(v) * D2R;
  3147. },
  3148. gamma: function (v) {
  3149. self.rectified_grid_angle = parseFloat(v);
  3150. },
  3151. lonc: function (v) {
  3152. self.longc = v * D2R;
  3153. },
  3154. x_0: function (v) {
  3155. self.x0 = parseFloat(v);
  3156. },
  3157. y_0: function (v) {
  3158. self.y0 = parseFloat(v);
  3159. },
  3160. k_0: function (v) {
  3161. self.k0 = parseFloat(v);
  3162. },
  3163. k: function (v) {
  3164. self.k0 = parseFloat(v);
  3165. },
  3166. a: function (v) {
  3167. self.a = parseFloat(v);
  3168. },
  3169. b: function (v) {
  3170. self.b = parseFloat(v);
  3171. },
  3172. r_a: function () {
  3173. self.R_A = true;
  3174. },
  3175. zone: function (v) {
  3176. self.zone = parseInt(v, 10);
  3177. },
  3178. south: function () {
  3179. self.utmSouth = true;
  3180. },
  3181. towgs84: function (v) {
  3182. self.datum_params = v.split(",").map(function (a) {
  3183. return parseFloat(a);
  3184. });
  3185. },
  3186. to_meter: function (v) {
  3187. self.to_meter = parseFloat(v);
  3188. },
  3189. units: function (v) {
  3190. self.units = v;
  3191. var unit = match(units, v);
  3192. if (unit) {
  3193. self.to_meter = unit.to_meter;
  3194. }
  3195. },
  3196. from_greenwich: function (v) {
  3197. self.from_greenwich = v * D2R;
  3198. },
  3199. pm: function (v) {
  3200. var pm = match(exports$1, v);
  3201. self.from_greenwich = (pm ? pm : parseFloat(v)) * D2R;
  3202. },
  3203. nadgrids: function (v) {
  3204. if (v === '@null') {
  3205. self.datumCode = 'none';
  3206. }
  3207. else {
  3208. self.nadgrids = v;
  3209. }
  3210. },
  3211. axis: function (v) {
  3212. var legalAxis = "ewnsud";
  3213. if (v.length === 3 && legalAxis.indexOf(v.substr(0, 1)) !== -1 && legalAxis.indexOf(v.substr(1, 1)) !== -1 && legalAxis.indexOf(v.substr(2, 1)) !== -1) {
  3214. self.axis = v;
  3215. }
  3216. },
  3217. approx: function () {
  3218. self.approx = true;
  3219. }
  3220. };
  3221. for (paramName in paramObj) {
  3222. paramVal = paramObj[paramName];
  3223. if (paramName in params) {
  3224. paramOutname = params[paramName];
  3225. if (typeof paramOutname === 'function') {
  3226. paramOutname(paramVal);
  3227. }
  3228. else {
  3229. self[paramOutname] = paramVal;
  3230. }
  3231. }
  3232. else {
  3233. self[paramName] = paramVal;
  3234. }
  3235. }
  3236. if (typeof self.datumCode === 'string' && self.datumCode !== "WGS84") {
  3237. self.datumCode = self.datumCode.toLowerCase();
  3238. }
  3239. return self;
  3240. };
  3241. var NEUTRAL = 1;
  3242. var KEYWORD = 2;
  3243. var NUMBER = 3;
  3244. var QUOTED = 4;
  3245. var AFTERQUOTE = 5;
  3246. var ENDED = -1;
  3247. var whitespace = /\s/;
  3248. var latin = /[A-Za-z]/;
  3249. var keyword = /[A-Za-z84]/;
  3250. var endThings = /[,\]]/;
  3251. var digets = /[\d\.E\-\+]/;
  3252. // const ignoredChar = /[\s_\-\/\(\)]/g;
  3253. function Parser(text) {
  3254. if (typeof text !== 'string') {
  3255. throw new Error('not a string');
  3256. }
  3257. this.text = text.trim();
  3258. this.level = 0;
  3259. this.place = 0;
  3260. this.root = null;
  3261. this.stack = [];
  3262. this.currentObject = null;
  3263. this.state = NEUTRAL;
  3264. }
  3265. Parser.prototype.readCharicter = function () {
  3266. var char = this.text[this.place++];
  3267. if (this.state !== QUOTED) {
  3268. while (whitespace.test(char)) {
  3269. if (this.place >= this.text.length) {
  3270. return;
  3271. }
  3272. char = this.text[this.place++];
  3273. }
  3274. }
  3275. switch (this.state) {
  3276. case NEUTRAL:
  3277. return this.neutral(char);
  3278. case KEYWORD:
  3279. return this.keyword(char)
  3280. case QUOTED:
  3281. return this.quoted(char);
  3282. case AFTERQUOTE:
  3283. return this.afterquote(char);
  3284. case NUMBER:
  3285. return this.number(char);
  3286. case ENDED:
  3287. return;
  3288. }
  3289. };
  3290. Parser.prototype.afterquote = function (char) {
  3291. if (char === '"') {
  3292. this.word += '"';
  3293. this.state = QUOTED;
  3294. return;
  3295. }
  3296. if (endThings.test(char)) {
  3297. this.word = this.word.trim();
  3298. this.afterItem(char);
  3299. return;
  3300. }
  3301. throw new Error('havn\'t handled "' + char + '" in afterquote yet, index ' + this.place);
  3302. };
  3303. Parser.prototype.afterItem = function (char) {
  3304. if (char === ',') {
  3305. if (this.word !== null) {
  3306. this.currentObject.push(this.word);
  3307. }
  3308. this.word = null;
  3309. this.state = NEUTRAL;
  3310. return;
  3311. }
  3312. if (char === ']') {
  3313. this.level--;
  3314. if (this.word !== null) {
  3315. this.currentObject.push(this.word);
  3316. this.word = null;
  3317. }
  3318. this.state = NEUTRAL;
  3319. this.currentObject = this.stack.pop();
  3320. if (!this.currentObject) {
  3321. this.state = ENDED;
  3322. }
  3323. return;
  3324. }
  3325. };
  3326. Parser.prototype.number = function (char) {
  3327. if (digets.test(char)) {
  3328. this.word += char;
  3329. return;
  3330. }
  3331. if (endThings.test(char)) {
  3332. this.word = parseFloat(this.word);
  3333. this.afterItem(char);
  3334. return;
  3335. }
  3336. throw new Error('havn\'t handled "' + char + '" in number yet, index ' + this.place);
  3337. };
  3338. Parser.prototype.quoted = function (char) {
  3339. if (char === '"') {
  3340. this.state = AFTERQUOTE;
  3341. return;
  3342. }
  3343. this.word += char;
  3344. return;
  3345. };
  3346. Parser.prototype.keyword = function (char) {
  3347. if (keyword.test(char)) {
  3348. this.word += char;
  3349. return;
  3350. }
  3351. if (char === '[') {
  3352. var newObjects = [];
  3353. newObjects.push(this.word);
  3354. this.level++;
  3355. if (this.root === null) {
  3356. this.root = newObjects;
  3357. } else {
  3358. this.currentObject.push(newObjects);
  3359. }
  3360. this.stack.push(this.currentObject);
  3361. this.currentObject = newObjects;
  3362. this.state = NEUTRAL;
  3363. return;
  3364. }
  3365. if (endThings.test(char)) {
  3366. this.afterItem(char);
  3367. return;
  3368. }
  3369. throw new Error('havn\'t handled "' + char + '" in keyword yet, index ' + this.place);
  3370. };
  3371. Parser.prototype.neutral = function (char) {
  3372. if (latin.test(char)) {
  3373. this.word = char;
  3374. this.state = KEYWORD;
  3375. return;
  3376. }
  3377. if (char === '"') {
  3378. this.word = '';
  3379. this.state = QUOTED;
  3380. return;
  3381. }
  3382. if (digets.test(char)) {
  3383. this.word = char;
  3384. this.state = NUMBER;
  3385. return;
  3386. }
  3387. if (endThings.test(char)) {
  3388. this.afterItem(char);
  3389. return;
  3390. }
  3391. throw new Error('havn\'t handled "' + char + '" in neutral yet, index ' + this.place);
  3392. };
  3393. Parser.prototype.output = function () {
  3394. while (this.place < this.text.length) {
  3395. this.readCharicter();
  3396. }
  3397. if (this.state === ENDED) {
  3398. return this.root;
  3399. }
  3400. throw new Error('unable to parse string "' + this.text + '". State is ' + this.state);
  3401. };
  3402. function parseString(txt) {
  3403. var parser = new Parser(txt);
  3404. return parser.output();
  3405. }
  3406. function mapit(obj, key, value) {
  3407. if (Array.isArray(key)) {
  3408. value.unshift(key);
  3409. key = null;
  3410. }
  3411. var thing = key ? {} : obj;
  3412. var out = value.reduce(function (newObj, item) {
  3413. sExpr(item, newObj);
  3414. return newObj
  3415. }, thing);
  3416. if (key) {
  3417. obj[key] = out;
  3418. }
  3419. }
  3420. function sExpr(v, obj) {
  3421. if (!Array.isArray(v)) {
  3422. obj[v] = true;
  3423. return;
  3424. }
  3425. var key = v.shift();
  3426. if (key === 'PARAMETER') {
  3427. key = v.shift();
  3428. }
  3429. if (v.length === 1) {
  3430. if (Array.isArray(v[0])) {
  3431. obj[key] = {};
  3432. sExpr(v[0], obj[key]);
  3433. return;
  3434. }
  3435. obj[key] = v[0];
  3436. return;
  3437. }
  3438. if (!v.length) {
  3439. obj[key] = true;
  3440. return;
  3441. }
  3442. if (key === 'TOWGS84') {
  3443. obj[key] = v;
  3444. return;
  3445. }
  3446. if (key === 'AXIS') {
  3447. if (!(key in obj)) {
  3448. obj[key] = [];
  3449. }
  3450. obj[key].push(v);
  3451. return;
  3452. }
  3453. if (!Array.isArray(key)) {
  3454. obj[key] = {};
  3455. }
  3456. var i;
  3457. switch (key) {
  3458. case 'UNIT':
  3459. case 'PRIMEM':
  3460. case 'VERT_DATUM':
  3461. obj[key] = {
  3462. name: v[0].toLowerCase(),
  3463. convert: v[1]
  3464. };
  3465. if (v.length === 3) {
  3466. sExpr(v[2], obj[key]);
  3467. }
  3468. return;
  3469. case 'SPHEROID':
  3470. case 'ELLIPSOID':
  3471. obj[key] = {
  3472. name: v[0],
  3473. a: v[1],
  3474. rf: v[2]
  3475. };
  3476. if (v.length === 4) {
  3477. sExpr(v[3], obj[key]);
  3478. }
  3479. return;
  3480. case 'PROJECTEDCRS':
  3481. case 'PROJCRS':
  3482. case 'GEOGCS':
  3483. case 'GEOCCS':
  3484. case 'PROJCS':
  3485. case 'LOCAL_CS':
  3486. case 'GEODCRS':
  3487. case 'GEODETICCRS':
  3488. case 'GEODETICDATUM':
  3489. case 'EDATUM':
  3490. case 'ENGINEERINGDATUM':
  3491. case 'VERT_CS':
  3492. case 'VERTCRS':
  3493. case 'VERTICALCRS':
  3494. case 'COMPD_CS':
  3495. case 'COMPOUNDCRS':
  3496. case 'ENGINEERINGCRS':
  3497. case 'ENGCRS':
  3498. case 'FITTED_CS':
  3499. case 'LOCAL_DATUM':
  3500. case 'DATUM':
  3501. v[0] = ['name', v[0]];
  3502. mapit(obj, key, v);
  3503. return;
  3504. default:
  3505. i = -1;
  3506. while (++i < v.length) {
  3507. if (!Array.isArray(v[i])) {
  3508. return sExpr(v, obj[key]);
  3509. }
  3510. }
  3511. return mapit(obj, key, v);
  3512. }
  3513. }
  3514. var D2R$1 = 0.01745329251994329577;
  3515. function rename(obj, params) {
  3516. var outName = params[0];
  3517. var inName = params[1];
  3518. if (!(outName in obj) && (inName in obj)) {
  3519. obj[outName] = obj[inName];
  3520. if (params.length === 3) {
  3521. obj[outName] = params[2](obj[outName]);
  3522. }
  3523. }
  3524. }
  3525. function d2r(input) {
  3526. return input * D2R$1;
  3527. }
  3528. function cleanWKT(wkt) {
  3529. if (wkt.type === 'GEOGCS') {
  3530. wkt.projName = 'longlat';
  3531. } else if (wkt.type === 'LOCAL_CS') {
  3532. wkt.projName = 'identity';
  3533. wkt.local = true;
  3534. } else {
  3535. if (typeof wkt.PROJECTION === 'object') {
  3536. wkt.projName = Object.keys(wkt.PROJECTION)[0];
  3537. } else {
  3538. wkt.projName = wkt.PROJECTION;
  3539. }
  3540. }
  3541. if (wkt.AXIS) {
  3542. var axisOrder = '';
  3543. for (var i = 0, ii = wkt.AXIS.length; i < ii; ++i) {
  3544. var axis = [wkt.AXIS[i][0].toLowerCase(), wkt.AXIS[i][1].toLowerCase()];
  3545. if (axis[0].indexOf('north') !== -1 || ((axis[0] === 'y' || axis[0] === 'lat') && axis[1] === 'north')) {
  3546. axisOrder += 'n';
  3547. } else if (axis[0].indexOf('south') !== -1 || ((axis[0] === 'y' || axis[0] === 'lat') && axis[1] === 'south')) {
  3548. axisOrder += 's';
  3549. } else if (axis[0].indexOf('east') !== -1 || ((axis[0] === 'x' || axis[0] === 'lon') && axis[1] === 'east')) {
  3550. axisOrder += 'e';
  3551. } else if (axis[0].indexOf('west') !== -1 || ((axis[0] === 'x' || axis[0] === 'lon') && axis[1] === 'west')) {
  3552. axisOrder += 'w';
  3553. }
  3554. }
  3555. if (axisOrder.length === 2) {
  3556. axisOrder += 'u';
  3557. }
  3558. if (axisOrder.length === 3) {
  3559. wkt.axis = axisOrder;
  3560. }
  3561. }
  3562. if (wkt.UNIT) {
  3563. wkt.units = wkt.UNIT.name.toLowerCase();
  3564. if (wkt.units === 'metre') {
  3565. wkt.units = 'meter';
  3566. }
  3567. if (wkt.UNIT.convert) {
  3568. if (wkt.type === 'GEOGCS') {
  3569. if (wkt.DATUM && wkt.DATUM.SPHEROID) {
  3570. wkt.to_meter = wkt.UNIT.convert * wkt.DATUM.SPHEROID.a;
  3571. }
  3572. } else {
  3573. wkt.to_meter = wkt.UNIT.convert;
  3574. }
  3575. }
  3576. }
  3577. var geogcs = wkt.GEOGCS;
  3578. if (wkt.type === 'GEOGCS') {
  3579. geogcs = wkt;
  3580. }
  3581. if (geogcs) {
  3582. //if(wkt.GEOGCS.PRIMEM&&wkt.GEOGCS.PRIMEM.convert){
  3583. // wkt.from_greenwich=wkt.GEOGCS.PRIMEM.convert*D2R;
  3584. //}
  3585. if (geogcs.DATUM) {
  3586. wkt.datumCode = geogcs.DATUM.name.toLowerCase();
  3587. } else {
  3588. wkt.datumCode = geogcs.name.toLowerCase();
  3589. }
  3590. if (wkt.datumCode.slice(0, 2) === 'd_') {
  3591. wkt.datumCode = wkt.datumCode.slice(2);
  3592. }
  3593. if (wkt.datumCode === 'new_zealand_geodetic_datum_1949' || wkt.datumCode === 'new_zealand_1949') {
  3594. wkt.datumCode = 'nzgd49';
  3595. }
  3596. if (wkt.datumCode === 'wgs_1984' || wkt.datumCode === 'world_geodetic_system_1984') {
  3597. if (wkt.PROJECTION === 'Mercator_Auxiliary_Sphere') {
  3598. wkt.sphere = true;
  3599. }
  3600. wkt.datumCode = 'wgs84';
  3601. }
  3602. if (wkt.datumCode.slice(-6) === '_ferro') {
  3603. wkt.datumCode = wkt.datumCode.slice(0, - 6);
  3604. }
  3605. if (wkt.datumCode.slice(-8) === '_jakarta') {
  3606. wkt.datumCode = wkt.datumCode.slice(0, - 8);
  3607. }
  3608. if (~wkt.datumCode.indexOf('belge')) {
  3609. wkt.datumCode = 'rnb72';
  3610. }
  3611. if (geogcs.DATUM && geogcs.DATUM.SPHEROID) {
  3612. wkt.ellps = geogcs.DATUM.SPHEROID.name.replace('_19', '').replace(/[Cc]larke\_18/, 'clrk');
  3613. if (wkt.ellps.toLowerCase().slice(0, 13) === 'international') {
  3614. wkt.ellps = 'intl';
  3615. }
  3616. wkt.a = geogcs.DATUM.SPHEROID.a;
  3617. wkt.rf = parseFloat(geogcs.DATUM.SPHEROID.rf, 10);
  3618. }
  3619. if (geogcs.DATUM && geogcs.DATUM.TOWGS84) {
  3620. wkt.datum_params = geogcs.DATUM.TOWGS84;
  3621. }
  3622. if (~wkt.datumCode.indexOf('osgb_1936')) {
  3623. wkt.datumCode = 'osgb36';
  3624. }
  3625. if (~wkt.datumCode.indexOf('osni_1952')) {
  3626. wkt.datumCode = 'osni52';
  3627. }
  3628. if (~wkt.datumCode.indexOf('tm65')
  3629. || ~wkt.datumCode.indexOf('geodetic_datum_of_1965')) {
  3630. wkt.datumCode = 'ire65';
  3631. }
  3632. if (wkt.datumCode === 'ch1903+') {
  3633. wkt.datumCode = 'ch1903';
  3634. }
  3635. if (~wkt.datumCode.indexOf('israel')) {
  3636. wkt.datumCode = 'isr93';
  3637. }
  3638. }
  3639. if (wkt.b && !isFinite(wkt.b)) {
  3640. wkt.b = wkt.a;
  3641. }
  3642. function toMeter(input) {
  3643. var ratio = wkt.to_meter || 1;
  3644. return input * ratio;
  3645. }
  3646. var renamer = function (a) {
  3647. return rename(wkt, a);
  3648. };
  3649. var list = [
  3650. ['standard_parallel_1', 'Standard_Parallel_1'],
  3651. ['standard_parallel_1', 'Latitude of 1st standard parallel'],
  3652. ['standard_parallel_2', 'Standard_Parallel_2'],
  3653. ['standard_parallel_2', 'Latitude of 2nd standard parallel'],
  3654. ['false_easting', 'False_Easting'],
  3655. ['false_easting', 'False easting'],
  3656. ['false-easting', 'Easting at false origin'],
  3657. ['false_northing', 'False_Northing'],
  3658. ['false_northing', 'False northing'],
  3659. ['false_northing', 'Northing at false origin'],
  3660. ['central_meridian', 'Central_Meridian'],
  3661. ['central_meridian', 'Longitude of natural origin'],
  3662. ['central_meridian', 'Longitude of false origin'],
  3663. ['latitude_of_origin', 'Latitude_Of_Origin'],
  3664. ['latitude_of_origin', 'Central_Parallel'],
  3665. ['latitude_of_origin', 'Latitude of natural origin'],
  3666. ['latitude_of_origin', 'Latitude of false origin'],
  3667. ['scale_factor', 'Scale_Factor'],
  3668. ['k0', 'scale_factor'],
  3669. ['latitude_of_center', 'Latitude_Of_Center'],
  3670. ['latitude_of_center', 'Latitude_of_center'],
  3671. ['lat0', 'latitude_of_center', d2r],
  3672. ['longitude_of_center', 'Longitude_Of_Center'],
  3673. ['longitude_of_center', 'Longitude_of_center'],
  3674. ['longc', 'longitude_of_center', d2r],
  3675. ['x0', 'false_easting', toMeter],
  3676. ['y0', 'false_northing', toMeter],
  3677. ['long0', 'central_meridian', d2r],
  3678. ['lat0', 'latitude_of_origin', d2r],
  3679. ['lat0', 'standard_parallel_1', d2r],
  3680. ['lat1', 'standard_parallel_1', d2r],
  3681. ['lat2', 'standard_parallel_2', d2r],
  3682. ['azimuth', 'Azimuth'],
  3683. ['alpha', 'azimuth', d2r],
  3684. ['srsCode', 'name']
  3685. ];
  3686. list.forEach(renamer);
  3687. if (!wkt.long0 && wkt.longc && (wkt.projName === 'Albers_Conic_Equal_Area' || wkt.projName === 'Lambert_Azimuthal_Equal_Area')) {
  3688. wkt.long0 = wkt.longc;
  3689. }
  3690. if (!wkt.lat_ts && wkt.lat1 && (wkt.projName === 'Stereographic_South_Pole' || wkt.projName === 'Polar Stereographic (variant B)')) {
  3691. wkt.lat0 = d2r(wkt.lat1 > 0 ? 90 : -90);
  3692. wkt.lat_ts = wkt.lat1;
  3693. }
  3694. }
  3695. var wkt = function (wkt) {
  3696. var lisp = parseString(wkt);
  3697. var type = lisp.shift();
  3698. var name = lisp.shift();
  3699. lisp.unshift(['name', name]);
  3700. lisp.unshift(['type', type]);
  3701. var obj = {};
  3702. sExpr(lisp, obj);
  3703. cleanWKT(obj);
  3704. return obj;
  3705. };
  3706. function defs(name) {
  3707. /*global console*/
  3708. var that = this;
  3709. if (arguments.length === 2) {
  3710. var def = arguments[1];
  3711. if (typeof def === 'string') {
  3712. if (def.charAt(0) === '+') {
  3713. defs[name] = parseProj(arguments[1]);
  3714. }
  3715. else {
  3716. defs[name] = wkt(arguments[1]);
  3717. }
  3718. } else {
  3719. defs[name] = def;
  3720. }
  3721. }
  3722. else if (arguments.length === 1) {
  3723. if (Array.isArray(name)) {
  3724. return name.map(function (v) {
  3725. if (Array.isArray(v)) {
  3726. defs.apply(that, v);
  3727. }
  3728. else {
  3729. defs(v);
  3730. }
  3731. });
  3732. }
  3733. else if (typeof name === 'string') {
  3734. if (name in defs) {
  3735. return defs[name];
  3736. }
  3737. }
  3738. else if ('EPSG' in name) {
  3739. defs['EPSG:' + name.EPSG] = name;
  3740. }
  3741. else if ('ESRI' in name) {
  3742. defs['ESRI:' + name.ESRI] = name;
  3743. }
  3744. else if ('IAU2000' in name) {
  3745. defs['IAU2000:' + name.IAU2000] = name;
  3746. }
  3747. else {
  3748. // console.log(name);
  3749. }
  3750. return;
  3751. }
  3752. }
  3753. globals(defs);
  3754. function testObj(code) {
  3755. return typeof code === 'string';
  3756. }
  3757. function testDef(code) {
  3758. return code in defs;
  3759. }
  3760. var codeWords = ['PROJECTEDCRS', 'PROJCRS', 'GEOGCS', 'GEOCCS', 'PROJCS', 'LOCAL_CS', 'GEODCRS', 'GEODETICCRS', 'GEODETICDATUM', 'ENGCRS', 'ENGINEERINGCRS'];
  3761. function testWKT(code) {
  3762. return codeWords.some(function (word) {
  3763. return code.indexOf(word) > -1;
  3764. });
  3765. }
  3766. var codes = ['3857', '900913', '3785', '102113'];
  3767. function checkMercator(item) {
  3768. var auth = match(item, 'authority');
  3769. if (!auth) {
  3770. return;
  3771. }
  3772. var code = match(auth, 'epsg');
  3773. return code && codes.indexOf(code) > -1;
  3774. }
  3775. function checkProjStr(item) {
  3776. var ext = match(item, 'extension');
  3777. if (!ext) {
  3778. return;
  3779. }
  3780. return match(ext, 'proj4');
  3781. }
  3782. function testProj(code) {
  3783. return code[0] === '+';
  3784. }
  3785. function parse(code) {
  3786. if (testObj(code)) {
  3787. //check to see if this is a WKT string
  3788. if (testDef(code)) {
  3789. return defs[code];
  3790. }
  3791. if (testWKT(code)) {
  3792. var out = wkt(code);
  3793. // test of spetial case, due to this being a very common and often malformed
  3794. if (checkMercator(out)) {
  3795. return defs['EPSG:3857'];
  3796. }
  3797. var maybeProjStr = checkProjStr(out);
  3798. if (maybeProjStr) {
  3799. return parseProj(maybeProjStr);
  3800. }
  3801. return out;
  3802. }
  3803. if (testProj(code)) {
  3804. return parseProj(code);
  3805. }
  3806. } else {
  3807. return code;
  3808. }
  3809. }
  3810. var extend = function (destination, source) {
  3811. destination = destination || {};
  3812. var value, property;
  3813. if (!source) {
  3814. return destination;
  3815. }
  3816. for (property in source) {
  3817. value = source[property];
  3818. if (value !== undefined) {
  3819. destination[property] = value;
  3820. }
  3821. }
  3822. return destination;
  3823. };
  3824. var msfnz = function (eccent, sinphi, cosphi) {
  3825. var con = eccent * sinphi;
  3826. return cosphi / (Math.sqrt(1 - con * con));
  3827. };
  3828. var sign = function (x) {
  3829. return x < 0 ? -1 : 1;
  3830. };
  3831. var adjust_lon = function (x) {
  3832. return (Math.abs(x) <= SPI) ? x : (x - (sign(x) * TWO_PI));
  3833. };
  3834. var tsfnz = function (eccent, phi, sinphi) {
  3835. var con = eccent * sinphi;
  3836. var com = 0.5 * eccent;
  3837. con = Math.pow(((1 - con) / (1 + con)), com);
  3838. return (Math.tan(0.5 * (HALF_PI - phi)) / con);
  3839. };
  3840. var phi2z = function (eccent, ts) {
  3841. var eccnth = 0.5 * eccent;
  3842. var con, dphi;
  3843. var phi = HALF_PI - 2 * Math.atan(ts);
  3844. for (var i = 0; i <= 15; i++) {
  3845. con = eccent * Math.sin(phi);
  3846. dphi = HALF_PI - 2 * Math.atan(ts * (Math.pow(((1 - con) / (1 + con)), eccnth))) - phi;
  3847. phi += dphi;
  3848. if (Math.abs(dphi) <= 0.0000000001) {
  3849. return phi;
  3850. }
  3851. }
  3852. //console.log("phi2z has NoConvergence");
  3853. return -9999;
  3854. };
  3855. function init() {
  3856. var con = this.b / this.a;
  3857. this.es = 1 - con * con;
  3858. if (!('x0' in this)) {
  3859. this.x0 = 0;
  3860. }
  3861. if (!('y0' in this)) {
  3862. this.y0 = 0;
  3863. }
  3864. this.e = Math.sqrt(this.es);
  3865. if (this.lat_ts) {
  3866. if (this.sphere) {
  3867. this.k0 = Math.cos(this.lat_ts);
  3868. }
  3869. else {
  3870. this.k0 = msfnz(this.e, Math.sin(this.lat_ts), Math.cos(this.lat_ts));
  3871. }
  3872. }
  3873. else {
  3874. if (!this.k0) {
  3875. if (this.k) {
  3876. this.k0 = this.k;
  3877. }
  3878. else {
  3879. this.k0 = 1;
  3880. }
  3881. }
  3882. }
  3883. }
  3884. /* Mercator forward equations--mapping lat,long to x,y
  3885. --------------------------------------------------*/
  3886. function forward(p) {
  3887. var lon = p.x;
  3888. var lat = p.y;
  3889. // convert to radians
  3890. if (lat * R2D > 90 && lat * R2D < -90 && lon * R2D > 180 && lon * R2D < -180) {
  3891. return null;
  3892. }
  3893. var x, y;
  3894. if (Math.abs(Math.abs(lat) - HALF_PI) <= EPSLN) {
  3895. return null;
  3896. }
  3897. else {
  3898. if (this.sphere) {
  3899. x = this.x0 + this.a * this.k0 * adjust_lon(lon - this.long0);
  3900. y = this.y0 + this.a * this.k0 * Math.log(Math.tan(FORTPI + 0.5 * lat));
  3901. }
  3902. else {
  3903. var sinphi = Math.sin(lat);
  3904. var ts = tsfnz(this.e, lat, sinphi);
  3905. x = this.x0 + this.a * this.k0 * adjust_lon(lon - this.long0);
  3906. y = this.y0 - this.a * this.k0 * Math.log(ts);
  3907. }
  3908. p.x = x;
  3909. p.y = y;
  3910. return p;
  3911. }
  3912. }
  3913. /* Mercator inverse equations--mapping x,y to lat/long
  3914. --------------------------------------------------*/
  3915. function inverse(p) {
  3916. var x = p.x - this.x0;
  3917. var y = p.y - this.y0;
  3918. var lon, lat;
  3919. if (this.sphere) {
  3920. lat = HALF_PI - 2 * Math.atan(Math.exp(-y / (this.a * this.k0)));
  3921. }
  3922. else {
  3923. var ts = Math.exp(-y / (this.a * this.k0));
  3924. lat = phi2z(this.e, ts);
  3925. if (lat === -9999) {
  3926. return null;
  3927. }
  3928. }
  3929. lon = adjust_lon(this.long0 + x / (this.a * this.k0));
  3930. p.x = lon;
  3931. p.y = lat;
  3932. return p;
  3933. }
  3934. var names$1 = ["Mercator", "Popular Visualisation Pseudo Mercator", "Mercator_1SP", "Mercator_Auxiliary_Sphere", "merc"];
  3935. var merc = {
  3936. init: init,
  3937. forward: forward,
  3938. inverse: inverse,
  3939. names: names$1
  3940. };
  3941. function init$1() {
  3942. //no-op for longlat
  3943. }
  3944. function identity(pt) {
  3945. return pt;
  3946. }
  3947. var names$2 = ["longlat", "identity"];
  3948. var longlat = {
  3949. init: init$1,
  3950. forward: identity,
  3951. inverse: identity,
  3952. names: names$2
  3953. };
  3954. var projs = [merc, longlat];
  3955. var names = {};
  3956. var projStore = [];
  3957. function add(proj, i) {
  3958. var len = projStore.length;
  3959. if (!proj.names) {
  3960. // console.log(i);
  3961. return true;
  3962. }
  3963. projStore[len] = proj;
  3964. proj.names.forEach(function (n) {
  3965. names[n.toLowerCase()] = len;
  3966. });
  3967. return this;
  3968. }
  3969. function get(name) {
  3970. if (!name) {
  3971. return false;
  3972. }
  3973. var n = name.toLowerCase();
  3974. if (typeof names[n] !== 'undefined' && projStore[names[n]]) {
  3975. return projStore[names[n]];
  3976. }
  3977. }
  3978. function start() {
  3979. projs.forEach(add);
  3980. }
  3981. var projections = {
  3982. start: start,
  3983. add: add,
  3984. get: get
  3985. };
  3986. var exports$2 = {};
  3987. exports$2.MERIT = {
  3988. a: 6378137.0,
  3989. rf: 298.257,
  3990. ellipseName: "MERIT 1983"
  3991. };
  3992. exports$2.SGS85 = {
  3993. a: 6378136.0,
  3994. rf: 298.257,
  3995. ellipseName: "Soviet Geodetic System 85"
  3996. };
  3997. exports$2.GRS80 = {
  3998. a: 6378137.0,
  3999. rf: 298.257222101,
  4000. ellipseName: "GRS 1980(IUGG, 1980)"
  4001. };
  4002. exports$2.IAU76 = {
  4003. a: 6378140.0,
  4004. rf: 298.257,
  4005. ellipseName: "IAU 1976"
  4006. };
  4007. exports$2.airy = {
  4008. a: 6377563.396,
  4009. b: 6356256.910,
  4010. ellipseName: "Airy 1830"
  4011. };
  4012. exports$2.APL4 = {
  4013. a: 6378137,
  4014. rf: 298.25,
  4015. ellipseName: "Appl. Physics. 1965"
  4016. };
  4017. exports$2.NWL9D = {
  4018. a: 6378145.0,
  4019. rf: 298.25,
  4020. ellipseName: "Naval Weapons Lab., 1965"
  4021. };
  4022. exports$2.mod_airy = {
  4023. a: 6377340.189,
  4024. b: 6356034.446,
  4025. ellipseName: "Modified Airy"
  4026. };
  4027. exports$2.andrae = {
  4028. a: 6377104.43,
  4029. rf: 300.0,
  4030. ellipseName: "Andrae 1876 (Den., Iclnd.)"
  4031. };
  4032. exports$2.aust_SA = {
  4033. a: 6378160.0,
  4034. rf: 298.25,
  4035. ellipseName: "Australian Natl & S. Amer. 1969"
  4036. };
  4037. exports$2.GRS67 = {
  4038. a: 6378160.0,
  4039. rf: 298.2471674270,
  4040. ellipseName: "GRS 67(IUGG 1967)"
  4041. };
  4042. exports$2.bessel = {
  4043. a: 6377397.155,
  4044. rf: 299.1528128,
  4045. ellipseName: "Bessel 1841"
  4046. };
  4047. exports$2.bess_nam = {
  4048. a: 6377483.865,
  4049. rf: 299.1528128,
  4050. ellipseName: "Bessel 1841 (Namibia)"
  4051. };
  4052. exports$2.clrk66 = {
  4053. a: 6378206.4,
  4054. b: 6356583.8,
  4055. ellipseName: "Clarke 1866"
  4056. };
  4057. exports$2.clrk80 = {
  4058. a: 6378249.145,
  4059. rf: 293.4663,
  4060. ellipseName: "Clarke 1880 mod."
  4061. };
  4062. exports$2.clrk58 = {
  4063. a: 6378293.645208759,
  4064. rf: 294.2606763692654,
  4065. ellipseName: "Clarke 1858"
  4066. };
  4067. exports$2.CPM = {
  4068. a: 6375738.7,
  4069. rf: 334.29,
  4070. ellipseName: "Comm. des Poids et Mesures 1799"
  4071. };
  4072. exports$2.delmbr = {
  4073. a: 6376428.0,
  4074. rf: 311.5,
  4075. ellipseName: "Delambre 1810 (Belgium)"
  4076. };
  4077. exports$2.engelis = {
  4078. a: 6378136.05,
  4079. rf: 298.2566,
  4080. ellipseName: "Engelis 1985"
  4081. };
  4082. exports$2.evrst30 = {
  4083. a: 6377276.345,
  4084. rf: 300.8017,
  4085. ellipseName: "Everest 1830"
  4086. };
  4087. exports$2.evrst48 = {
  4088. a: 6377304.063,
  4089. rf: 300.8017,
  4090. ellipseName: "Everest 1948"
  4091. };
  4092. exports$2.evrst56 = {
  4093. a: 6377301.243,
  4094. rf: 300.8017,
  4095. ellipseName: "Everest 1956"
  4096. };
  4097. exports$2.evrst69 = {
  4098. a: 6377295.664,
  4099. rf: 300.8017,
  4100. ellipseName: "Everest 1969"
  4101. };
  4102. exports$2.evrstSS = {
  4103. a: 6377298.556,
  4104. rf: 300.8017,
  4105. ellipseName: "Everest (Sabah & Sarawak)"
  4106. };
  4107. exports$2.fschr60 = {
  4108. a: 6378166.0,
  4109. rf: 298.3,
  4110. ellipseName: "Fischer (Mercury Datum) 1960"
  4111. };
  4112. exports$2.fschr60m = {
  4113. a: 6378155.0,
  4114. rf: 298.3,
  4115. ellipseName: "Fischer 1960"
  4116. };
  4117. exports$2.fschr68 = {
  4118. a: 6378150.0,
  4119. rf: 298.3,
  4120. ellipseName: "Fischer 1968"
  4121. };
  4122. exports$2.helmert = {
  4123. a: 6378200.0,
  4124. rf: 298.3,
  4125. ellipseName: "Helmert 1906"
  4126. };
  4127. exports$2.hough = {
  4128. a: 6378270.0,
  4129. rf: 297.0,
  4130. ellipseName: "Hough"
  4131. };
  4132. exports$2.intl = {
  4133. a: 6378388.0,
  4134. rf: 297.0,
  4135. ellipseName: "International 1909 (Hayford)"
  4136. };
  4137. exports$2.kaula = {
  4138. a: 6378163.0,
  4139. rf: 298.24,
  4140. ellipseName: "Kaula 1961"
  4141. };
  4142. exports$2.lerch = {
  4143. a: 6378139.0,
  4144. rf: 298.257,
  4145. ellipseName: "Lerch 1979"
  4146. };
  4147. exports$2.mprts = {
  4148. a: 6397300.0,
  4149. rf: 191.0,
  4150. ellipseName: "Maupertius 1738"
  4151. };
  4152. exports$2.new_intl = {
  4153. a: 6378157.5,
  4154. b: 6356772.2,
  4155. ellipseName: "New International 1967"
  4156. };
  4157. exports$2.plessis = {
  4158. a: 6376523.0,
  4159. rf: 6355863.0,
  4160. ellipseName: "Plessis 1817 (France)"
  4161. };
  4162. exports$2.krass = {
  4163. a: 6378245.0,
  4164. rf: 298.3,
  4165. ellipseName: "Krassovsky, 1942"
  4166. };
  4167. exports$2.SEasia = {
  4168. a: 6378155.0,
  4169. b: 6356773.3205,
  4170. ellipseName: "Southeast Asia"
  4171. };
  4172. exports$2.walbeck = {
  4173. a: 6376896.0,
  4174. b: 6355834.8467,
  4175. ellipseName: "Walbeck"
  4176. };
  4177. exports$2.WGS60 = {
  4178. a: 6378165.0,
  4179. rf: 298.3,
  4180. ellipseName: "WGS 60"
  4181. };
  4182. exports$2.WGS66 = {
  4183. a: 6378145.0,
  4184. rf: 298.25,
  4185. ellipseName: "WGS 66"
  4186. };
  4187. exports$2.WGS7 = {
  4188. a: 6378135.0,
  4189. rf: 298.26,
  4190. ellipseName: "WGS 72"
  4191. };
  4192. var WGS84 = exports$2.WGS84 = {
  4193. a: 6378137.0,
  4194. rf: 298.257223563,
  4195. ellipseName: "WGS 84"
  4196. };
  4197. exports$2.sphere = {
  4198. a: 6370997.0,
  4199. b: 6370997.0,
  4200. ellipseName: "Normal Sphere (r=6370997)"
  4201. };
  4202. function eccentricity(a, b, rf, R_A) {
  4203. var a2 = a * a; // used in geocentric
  4204. var b2 = b * b; // used in geocentric
  4205. var es = (a2 - b2) / a2; // e ^ 2
  4206. var e = 0;
  4207. if (R_A) {
  4208. a *= 1 - es * (SIXTH + es * (RA4 + es * RA6));
  4209. a2 = a * a;
  4210. es = 0;
  4211. } else {
  4212. e = Math.sqrt(es); // eccentricity
  4213. }
  4214. var ep2 = (a2 - b2) / b2; // used in geocentric
  4215. return {
  4216. es: es,
  4217. e: e,
  4218. ep2: ep2
  4219. };
  4220. }
  4221. function sphere(a, b, rf, ellps, sphere) {
  4222. if (!a) { // do we have an ellipsoid?
  4223. var ellipse = match(exports$2, ellps);
  4224. if (!ellipse) {
  4225. ellipse = WGS84;
  4226. }
  4227. a = ellipse.a;
  4228. b = ellipse.b;
  4229. rf = ellipse.rf;
  4230. }
  4231. if (rf && !b) {
  4232. b = (1.0 - 1.0 / rf) * a;
  4233. }
  4234. if (rf === 0 || Math.abs(a - b) < EPSLN) {
  4235. sphere = true;
  4236. b = a;
  4237. }
  4238. return {
  4239. a: a,
  4240. b: b,
  4241. rf: rf,
  4242. sphere: sphere
  4243. };
  4244. }
  4245. var exports$3 = {};
  4246. exports$3.wgs84 = {
  4247. towgs84: "0,0,0",
  4248. ellipse: "WGS84",
  4249. datumName: "WGS84"
  4250. };
  4251. exports$3.ch1903 = {
  4252. towgs84: "674.374,15.056,405.346",
  4253. ellipse: "bessel",
  4254. datumName: "swiss"
  4255. };
  4256. exports$3.ggrs87 = {
  4257. towgs84: "-199.87,74.79,246.62",
  4258. ellipse: "GRS80",
  4259. datumName: "Greek_Geodetic_Reference_System_1987"
  4260. };
  4261. exports$3.nad83 = {
  4262. towgs84: "0,0,0",
  4263. ellipse: "GRS80",
  4264. datumName: "North_American_Datum_1983"
  4265. };
  4266. exports$3.nad27 = {
  4267. nadgrids: "@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat",
  4268. ellipse: "clrk66",
  4269. datumName: "North_American_Datum_1927"
  4270. };
  4271. exports$3.potsdam = {
  4272. towgs84: "598.1,73.7,418.2,0.202,0.045,-2.455,6.7",
  4273. ellipse: "bessel",
  4274. datumName: "Potsdam Rauenberg 1950 DHDN"
  4275. };
  4276. exports$3.carthage = {
  4277. towgs84: "-263.0,6.0,431.0",
  4278. ellipse: "clark80",
  4279. datumName: "Carthage 1934 Tunisia"
  4280. };
  4281. exports$3.hermannskogel = {
  4282. towgs84: "577.326,90.129,463.919,5.137,1.474,5.297,2.4232",
  4283. ellipse: "bessel",
  4284. datumName: "Hermannskogel"
  4285. };
  4286. exports$3.osni52 = {
  4287. towgs84: "482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15",
  4288. ellipse: "airy",
  4289. datumName: "Irish National"
  4290. };
  4291. exports$3.ire65 = {
  4292. towgs84: "482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15",
  4293. ellipse: "mod_airy",
  4294. datumName: "Ireland 1965"
  4295. };
  4296. exports$3.rassadiran = {
  4297. towgs84: "-133.63,-157.5,-158.62",
  4298. ellipse: "intl",
  4299. datumName: "Rassadiran"
  4300. };
  4301. exports$3.nzgd49 = {
  4302. towgs84: "59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993",
  4303. ellipse: "intl",
  4304. datumName: "New Zealand Geodetic Datum 1949"
  4305. };
  4306. exports$3.osgb36 = {
  4307. towgs84: "446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894",
  4308. ellipse: "airy",
  4309. datumName: "Airy 1830"
  4310. };
  4311. exports$3.s_jtsk = {
  4312. towgs84: "589,76,480",
  4313. ellipse: 'bessel',
  4314. datumName: 'S-JTSK (Ferro)'
  4315. };
  4316. exports$3.beduaram = {
  4317. towgs84: '-106,-87,188',
  4318. ellipse: 'clrk80',
  4319. datumName: 'Beduaram'
  4320. };
  4321. exports$3.gunung_segara = {
  4322. towgs84: '-403,684,41',
  4323. ellipse: 'bessel',
  4324. datumName: 'Gunung Segara Jakarta'
  4325. };
  4326. exports$3.rnb72 = {
  4327. towgs84: "106.869,-52.2978,103.724,-0.33657,0.456955,-1.84218,1",
  4328. ellipse: "intl",
  4329. datumName: "Reseau National Belge 1972"
  4330. };
  4331. function datum(datumCode, datum_params, a, b, es, ep2, nadgrids) {
  4332. var out = {};
  4333. if (datumCode === undefined || datumCode === 'none') {
  4334. out.datum_type = PJD_NODATUM;
  4335. } else {
  4336. out.datum_type = PJD_WGS84;
  4337. }
  4338. if (datum_params) {
  4339. out.datum_params = datum_params.map(parseFloat);
  4340. if (out.datum_params[0] !== 0 || out.datum_params[1] !== 0 || out.datum_params[2] !== 0) {
  4341. out.datum_type = PJD_3PARAM;
  4342. }
  4343. if (out.datum_params.length > 3) {
  4344. if (out.datum_params[3] !== 0 || out.datum_params[4] !== 0 || out.datum_params[5] !== 0 || out.datum_params[6] !== 0) {
  4345. out.datum_type = PJD_7PARAM;
  4346. out.datum_params[3] *= SEC_TO_RAD;
  4347. out.datum_params[4] *= SEC_TO_RAD;
  4348. out.datum_params[5] *= SEC_TO_RAD;
  4349. out.datum_params[6] = (out.datum_params[6] / 1000000.0) + 1.0;
  4350. }
  4351. }
  4352. }
  4353. if (nadgrids) {
  4354. out.datum_type = PJD_GRIDSHIFT;
  4355. out.grids = nadgrids;
  4356. }
  4357. out.a = a; //datum object also uses these values
  4358. out.b = b;
  4359. out.es = es;
  4360. out.ep2 = ep2;
  4361. return out;
  4362. }
  4363. /**
  4364. * Resources for details of NTv2 file formats:
  4365. * - https://web.archive.org/web/20140127204822if_/http://www.mgs.gov.on.ca:80/stdprodconsume/groups/content/@mgs/@iandit/documents/resourcelist/stel02_047447.pdf
  4366. * - http://mimaka.com/help/gs/html/004_NTV2%20Data%20Format.htm
  4367. */
  4368. var loadedNadgrids = {};
  4369. /**
  4370. * Load a binary NTv2 file (.gsb) to a key that can be used in a proj string like +nadgrids=<key>. Pass the NTv2 file
  4371. * as an ArrayBuffer.
  4372. */
  4373. function nadgrid(key, data) {
  4374. var view = new DataView(data);
  4375. var isLittleEndian = detectLittleEndian(view);
  4376. var header = readHeader(view, isLittleEndian);
  4377. if (header.nSubgrids > 1) {
  4378. // console.log('Only single NTv2 subgrids are currently supported, subsequent sub grids are ignored');
  4379. }
  4380. var subgrids = readSubgrids(view, header, isLittleEndian);
  4381. var nadgrid = { header: header, subgrids: subgrids };
  4382. loadedNadgrids[key] = nadgrid;
  4383. return nadgrid;
  4384. }
  4385. /**
  4386. * Given a proj4 value for nadgrids, return an array of loaded grids
  4387. */
  4388. function getNadgrids(nadgrids) {
  4389. // Format details: http://proj.maptools.org/gen_parms.html
  4390. if (nadgrids === undefined) { return null; }
  4391. var grids = nadgrids.split(',');
  4392. return grids.map(parseNadgridString);
  4393. }
  4394. function parseNadgridString(value) {
  4395. if (value.length === 0) {
  4396. return null;
  4397. }
  4398. var optional = value[0] === '@';
  4399. if (optional) {
  4400. value = value.slice(1);
  4401. }
  4402. if (value === 'null') {
  4403. return { name: 'null', mandatory: !optional, grid: null, isNull: true };
  4404. }
  4405. return {
  4406. name: value,
  4407. mandatory: !optional,
  4408. grid: loadedNadgrids[value] || null,
  4409. isNull: false
  4410. };
  4411. }
  4412. function secondsToRadians(seconds) {
  4413. return (seconds / 3600) * Math.PI / 180;
  4414. }
  4415. function detectLittleEndian(view) {
  4416. var nFields = view.getInt32(8, false);
  4417. if (nFields === 11) {
  4418. return false;
  4419. }
  4420. nFields = view.getInt32(8, true);
  4421. if (nFields !== 11) {
  4422. console.warn('Failed to detect nadgrid endian-ness, defaulting to little-endian');
  4423. }
  4424. return true;
  4425. }
  4426. function readHeader(view, isLittleEndian) {
  4427. return {
  4428. nFields: view.getInt32(8, isLittleEndian),
  4429. nSubgridFields: view.getInt32(24, isLittleEndian),
  4430. nSubgrids: view.getInt32(40, isLittleEndian),
  4431. shiftType: decodeString(view, 56, 56 + 8).trim(),
  4432. fromSemiMajorAxis: view.getFloat64(120, isLittleEndian),
  4433. fromSemiMinorAxis: view.getFloat64(136, isLittleEndian),
  4434. toSemiMajorAxis: view.getFloat64(152, isLittleEndian),
  4435. toSemiMinorAxis: view.getFloat64(168, isLittleEndian),
  4436. };
  4437. }
  4438. function decodeString(view, start, end) {
  4439. return String.fromCharCode.apply(null, new Uint8Array(view.buffer.slice(start, end)));
  4440. }
  4441. function readSubgrids(view, header, isLittleEndian) {
  4442. var gridOffset = 176;
  4443. var grids = [];
  4444. for (var i = 0; i < header.nSubgrids; i++) {
  4445. var subHeader = readGridHeader(view, gridOffset, isLittleEndian);
  4446. var nodes = readGridNodes(view, gridOffset, subHeader, isLittleEndian);
  4447. var lngColumnCount = Math.round(
  4448. 1 + (subHeader.upperLongitude - subHeader.lowerLongitude) / subHeader.longitudeInterval);
  4449. var latColumnCount = Math.round(
  4450. 1 + (subHeader.upperLatitude - subHeader.lowerLatitude) / subHeader.latitudeInterval);
  4451. // Proj4 operates on radians whereas the coordinates are in seconds in the grid
  4452. grids.push({
  4453. ll: [secondsToRadians(subHeader.lowerLongitude), secondsToRadians(subHeader.lowerLatitude)],
  4454. del: [secondsToRadians(subHeader.longitudeInterval), secondsToRadians(subHeader.latitudeInterval)],
  4455. lim: [lngColumnCount, latColumnCount],
  4456. count: subHeader.gridNodeCount,
  4457. cvs: mapNodes(nodes)
  4458. });
  4459. }
  4460. return grids;
  4461. }
  4462. function mapNodes(nodes) {
  4463. return nodes.map(function (r) { return [secondsToRadians(r.longitudeShift), secondsToRadians(r.latitudeShift)]; });
  4464. }
  4465. function readGridHeader(view, offset, isLittleEndian) {
  4466. return {
  4467. name: decodeString(view, offset + 8, offset + 16).trim(),
  4468. parent: decodeString(view, offset + 24, offset + 24 + 8).trim(),
  4469. lowerLatitude: view.getFloat64(offset + 72, isLittleEndian),
  4470. upperLatitude: view.getFloat64(offset + 88, isLittleEndian),
  4471. lowerLongitude: view.getFloat64(offset + 104, isLittleEndian),
  4472. upperLongitude: view.getFloat64(offset + 120, isLittleEndian),
  4473. latitudeInterval: view.getFloat64(offset + 136, isLittleEndian),
  4474. longitudeInterval: view.getFloat64(offset + 152, isLittleEndian),
  4475. gridNodeCount: view.getInt32(offset + 168, isLittleEndian)
  4476. };
  4477. }
  4478. function readGridNodes(view, offset, gridHeader, isLittleEndian) {
  4479. var nodesOffset = offset + 176;
  4480. var gridRecordLength = 16;
  4481. var gridShiftRecords = [];
  4482. for (var i = 0; i < gridHeader.gridNodeCount; i++) {
  4483. var record = {
  4484. latitudeShift: view.getFloat32(nodesOffset + i * gridRecordLength, isLittleEndian),
  4485. longitudeShift: view.getFloat32(nodesOffset + i * gridRecordLength + 4, isLittleEndian),
  4486. latitudeAccuracy: view.getFloat32(nodesOffset + i * gridRecordLength + 8, isLittleEndian),
  4487. longitudeAccuracy: view.getFloat32(nodesOffset + i * gridRecordLength + 12, isLittleEndian),
  4488. };
  4489. gridShiftRecords.push(record);
  4490. }
  4491. return gridShiftRecords;
  4492. }
  4493. function Projection(srsCode, callback) {
  4494. if (!(this instanceof Projection)) {
  4495. return new Projection(srsCode);
  4496. }
  4497. callback = callback || function (error) {
  4498. if (error) {
  4499. throw error;
  4500. }
  4501. };
  4502. var json = parse(srsCode);
  4503. if (typeof json !== 'object') {
  4504. callback(srsCode);
  4505. return;
  4506. }
  4507. var ourProj = Projection.projections.get(json.projName);
  4508. if (!ourProj) {
  4509. callback(srsCode);
  4510. return;
  4511. }
  4512. if (json.datumCode && json.datumCode !== 'none') {
  4513. var datumDef = match(exports$3, json.datumCode);
  4514. if (datumDef) {
  4515. json.datum_params = json.datum_params || (datumDef.towgs84 ? datumDef.towgs84.split(',') : null);
  4516. json.ellps = datumDef.ellipse;
  4517. json.datumName = datumDef.datumName ? datumDef.datumName : json.datumCode;
  4518. }
  4519. }
  4520. json.k0 = json.k0 || 1.0;
  4521. json.axis = json.axis || 'enu';
  4522. json.ellps = json.ellps || 'wgs84';
  4523. json.lat1 = json.lat1 || json.lat0; // Lambert_Conformal_Conic_1SP, for example, needs this
  4524. var sphere_ = sphere(json.a, json.b, json.rf, json.ellps, json.sphere);
  4525. var ecc = eccentricity(sphere_.a, sphere_.b, sphere_.rf, json.R_A);
  4526. var nadgrids = getNadgrids(json.nadgrids);
  4527. var datumObj = json.datum || datum(json.datumCode, json.datum_params, sphere_.a, sphere_.b, ecc.es, ecc.ep2,
  4528. nadgrids);
  4529. extend(this, json); // transfer everything over from the projection because we don't know what we'll need
  4530. extend(this, ourProj); // transfer all the methods from the projection
  4531. // copy the 4 things over we calulated in deriveConstants.sphere
  4532. this.a = sphere_.a;
  4533. this.b = sphere_.b;
  4534. this.rf = sphere_.rf;
  4535. this.sphere = sphere_.sphere;
  4536. // copy the 3 things we calculated in deriveConstants.eccentricity
  4537. this.es = ecc.es;
  4538. this.e = ecc.e;
  4539. this.ep2 = ecc.ep2;
  4540. // add in the datum object
  4541. this.datum = datumObj;
  4542. // init the projection
  4543. this.init();
  4544. // legecy callback from back in the day when it went to spatialreference.org
  4545. callback(null, this);
  4546. }
  4547. Projection.projections = projections;
  4548. Projection.projections.start();
  4549. 'use strict';
  4550. function compareDatums(source, dest) {
  4551. if (source.datum_type !== dest.datum_type) {
  4552. return false; // false, datums are not equal
  4553. } else if (source.a !== dest.a || Math.abs(source.es - dest.es) > 0.000000000050) {
  4554. // the tolerance for es is to ensure that GRS80 and WGS84
  4555. // are considered identical
  4556. return false;
  4557. } else if (source.datum_type === PJD_3PARAM) {
  4558. return (source.datum_params[0] === dest.datum_params[0] && source.datum_params[1] === dest.datum_params[1] && source.datum_params[2] === dest.datum_params[2]);
  4559. } else if (source.datum_type === PJD_7PARAM) {
  4560. return (source.datum_params[0] === dest.datum_params[0] && source.datum_params[1] === dest.datum_params[1] && source.datum_params[2] === dest.datum_params[2] && source.datum_params[3] === dest.datum_params[3] && source.datum_params[4] === dest.datum_params[4] && source.datum_params[5] === dest.datum_params[5] && source.datum_params[6] === dest.datum_params[6]);
  4561. } else {
  4562. return true; // datums are equal
  4563. }
  4564. } // cs_compare_datums()
  4565. /*
  4566. * The function Convert_Geodetic_To_Geocentric converts geodetic coordinates
  4567. * (latitude, longitude, and height) to geocentric coordinates (X, Y, Z),
  4568. * according to the current ellipsoid parameters.
  4569. *
  4570. * Latitude : Geodetic latitude in radians (input)
  4571. * Longitude : Geodetic longitude in radians (input)
  4572. * Height : Geodetic height, in meters (input)
  4573. * X : Calculated Geocentric X coordinate, in meters (output)
  4574. * Y : Calculated Geocentric Y coordinate, in meters (output)
  4575. * Z : Calculated Geocentric Z coordinate, in meters (output)
  4576. *
  4577. */
  4578. function geodeticToGeocentric(p, es, a) {
  4579. var Longitude = p.x;
  4580. var Latitude = p.y;
  4581. var Height = p.z ? p.z : 0; //Z value not always supplied
  4582. var Rn; /* Earth radius at location */
  4583. var Sin_Lat; /* Math.sin(Latitude) */
  4584. var Sin2_Lat; /* Square of Math.sin(Latitude) */
  4585. var Cos_Lat; /* Math.cos(Latitude) */
  4586. /*
  4587. ** Don't blow up if Latitude is just a little out of the value
  4588. ** range as it may just be a rounding issue. Also removed longitude
  4589. ** test, it should be wrapped by Math.cos() and Math.sin(). NFW for PROJ.4, Sep/2001.
  4590. */
  4591. if (Latitude < -HALF_PI && Latitude > -1.001 * HALF_PI) {
  4592. Latitude = -HALF_PI;
  4593. } else if (Latitude > HALF_PI && Latitude < 1.001 * HALF_PI) {
  4594. Latitude = HALF_PI;
  4595. } else if (Latitude < -HALF_PI) {
  4596. /* Latitude out of range */
  4597. //..reportError('geocent:lat out of range:' + Latitude);
  4598. return { x: -Infinity, y: -Infinity, z: p.z };
  4599. } else if (Latitude > HALF_PI) {
  4600. /* Latitude out of range */
  4601. return { x: Infinity, y: Infinity, z: p.z };
  4602. }
  4603. if (Longitude > Math.PI) {
  4604. Longitude -= (2 * Math.PI);
  4605. }
  4606. Sin_Lat = Math.sin(Latitude);
  4607. Cos_Lat = Math.cos(Latitude);
  4608. Sin2_Lat = Sin_Lat * Sin_Lat;
  4609. Rn = a / (Math.sqrt(1.0e0 - es * Sin2_Lat));
  4610. return {
  4611. x: (Rn + Height) * Cos_Lat * Math.cos(Longitude),
  4612. y: (Rn + Height) * Cos_Lat * Math.sin(Longitude),
  4613. z: ((Rn * (1 - es)) + Height) * Sin_Lat
  4614. };
  4615. } // cs_geodetic_to_geocentric()
  4616. function geocentricToGeodetic(p, es, a, b) {
  4617. /* local defintions and variables */
  4618. /* end-criterium of loop, accuracy of sin(Latitude) */
  4619. var genau = 1e-12;
  4620. var genau2 = (genau * genau);
  4621. var maxiter = 30;
  4622. var P; /* distance between semi-minor axis and location */
  4623. var RR; /* distance between center and location */
  4624. var CT; /* sin of geocentric latitude */
  4625. var ST; /* cos of geocentric latitude */
  4626. var RX;
  4627. var RK;
  4628. var RN; /* Earth radius at location */
  4629. var CPHI0; /* cos of start or old geodetic latitude in iterations */
  4630. var SPHI0; /* sin of start or old geodetic latitude in iterations */
  4631. var CPHI; /* cos of searched geodetic latitude */
  4632. var SPHI; /* sin of searched geodetic latitude */
  4633. var SDPHI; /* end-criterium: addition-theorem of sin(Latitude(iter)-Latitude(iter-1)) */
  4634. var iter; /* # of continous iteration, max. 30 is always enough (s.a.) */
  4635. var X = p.x;
  4636. var Y = p.y;
  4637. var Z = p.z ? p.z : 0.0; //Z value not always supplied
  4638. var Longitude;
  4639. var Latitude;
  4640. var Height;
  4641. P = Math.sqrt(X * X + Y * Y);
  4642. RR = Math.sqrt(X * X + Y * Y + Z * Z);
  4643. /* special cases for latitude and longitude */
  4644. if (P / a < genau) {
  4645. /* special case, if P=0. (X=0., Y=0.) */
  4646. Longitude = 0.0;
  4647. /* if (X,Y,Z)=(0.,0.,0.) then Height becomes semi-minor axis
  4648. * of ellipsoid (=center of mass), Latitude becomes PI/2 */
  4649. if (RR / a < genau) {
  4650. Latitude = HALF_PI;
  4651. Height = -b;
  4652. return {
  4653. x: p.x,
  4654. y: p.y,
  4655. z: p.z
  4656. };
  4657. }
  4658. } else {
  4659. /* ellipsoidal (geodetic) longitude
  4660. * interval: -PI < Longitude <= +PI */
  4661. Longitude = Math.atan2(Y, X);
  4662. }
  4663. /* --------------------------------------------------------------
  4664. * Following iterative algorithm was developped by
  4665. * "Institut for Erdmessung", University of Hannover, July 1988.
  4666. * Internet: www.ife.uni-hannover.de
  4667. * Iterative computation of CPHI,SPHI and Height.
  4668. * Iteration of CPHI and SPHI to 10**-12 radian resp.
  4669. * 2*10**-7 arcsec.
  4670. * --------------------------------------------------------------
  4671. */
  4672. CT = Z / RR;
  4673. ST = P / RR;
  4674. RX = 1.0 / Math.sqrt(1.0 - es * (2.0 - es) * ST * ST);
  4675. CPHI0 = ST * (1.0 - es) * RX;
  4676. SPHI0 = CT * RX;
  4677. iter = 0;
  4678. /* loop to find sin(Latitude) resp. Latitude
  4679. * until |sin(Latitude(iter)-Latitude(iter-1))| < genau */
  4680. do {
  4681. iter++;
  4682. RN = a / Math.sqrt(1.0 - es * SPHI0 * SPHI0);
  4683. /* ellipsoidal (geodetic) height */
  4684. Height = P * CPHI0 + Z * SPHI0 - RN * (1.0 - es * SPHI0 * SPHI0);
  4685. RK = es * RN / (RN + Height);
  4686. RX = 1.0 / Math.sqrt(1.0 - RK * (2.0 - RK) * ST * ST);
  4687. CPHI = ST * (1.0 - RK) * RX;
  4688. SPHI = CT * RX;
  4689. SDPHI = SPHI * CPHI0 - CPHI * SPHI0;
  4690. CPHI0 = CPHI;
  4691. SPHI0 = SPHI;
  4692. }
  4693. while (SDPHI * SDPHI > genau2 && iter < maxiter);
  4694. /* ellipsoidal (geodetic) latitude */
  4695. Latitude = Math.atan(SPHI / Math.abs(CPHI));
  4696. return {
  4697. x: Longitude,
  4698. y: Latitude,
  4699. z: Height
  4700. };
  4701. } // cs_geocentric_to_geodetic()
  4702. /****************************************************************/
  4703. // pj_geocentic_to_wgs84( p )
  4704. // p = point to transform in geocentric coordinates (x,y,z)
  4705. /** point object, nothing fancy, just allows values to be
  4706. passed back and forth by reference rather than by value.
  4707. Other point classes may be used as long as they have
  4708. x and y properties, which will get modified in the transform method.
  4709. */
  4710. function geocentricToWgs84(p, datum_type, datum_params) {
  4711. if (datum_type === PJD_3PARAM) {
  4712. // if( x[io] === HUGE_VAL )
  4713. // continue;
  4714. return {
  4715. x: p.x + datum_params[0],
  4716. y: p.y + datum_params[1],
  4717. z: p.z + datum_params[2],
  4718. };
  4719. } else if (datum_type === PJD_7PARAM) {
  4720. var Dx_BF = datum_params[0];
  4721. var Dy_BF = datum_params[1];
  4722. var Dz_BF = datum_params[2];
  4723. var Rx_BF = datum_params[3];
  4724. var Ry_BF = datum_params[4];
  4725. var Rz_BF = datum_params[5];
  4726. var M_BF = datum_params[6];
  4727. // if( x[io] === HUGE_VAL )
  4728. // continue;
  4729. return {
  4730. x: M_BF * (p.x - Rz_BF * p.y + Ry_BF * p.z) + Dx_BF,
  4731. y: M_BF * (Rz_BF * p.x + p.y - Rx_BF * p.z) + Dy_BF,
  4732. z: M_BF * (-Ry_BF * p.x + Rx_BF * p.y + p.z) + Dz_BF
  4733. };
  4734. }
  4735. } // cs_geocentric_to_wgs84
  4736. /****************************************************************/
  4737. // pj_geocentic_from_wgs84()
  4738. // coordinate system definition,
  4739. // point to transform in geocentric coordinates (x,y,z)
  4740. function geocentricFromWgs84(p, datum_type, datum_params) {
  4741. if (datum_type === PJD_3PARAM) {
  4742. //if( x[io] === HUGE_VAL )
  4743. // continue;
  4744. return {
  4745. x: p.x - datum_params[0],
  4746. y: p.y - datum_params[1],
  4747. z: p.z - datum_params[2],
  4748. };
  4749. } else if (datum_type === PJD_7PARAM) {
  4750. var Dx_BF = datum_params[0];
  4751. var Dy_BF = datum_params[1];
  4752. var Dz_BF = datum_params[2];
  4753. var Rx_BF = datum_params[3];
  4754. var Ry_BF = datum_params[4];
  4755. var Rz_BF = datum_params[5];
  4756. var M_BF = datum_params[6];
  4757. var x_tmp = (p.x - Dx_BF) / M_BF;
  4758. var y_tmp = (p.y - Dy_BF) / M_BF;
  4759. var z_tmp = (p.z - Dz_BF) / M_BF;
  4760. //if( x[io] === HUGE_VAL )
  4761. // continue;
  4762. return {
  4763. x: x_tmp + Rz_BF * y_tmp - Ry_BF * z_tmp,
  4764. y: -Rz_BF * x_tmp + y_tmp + Rx_BF * z_tmp,
  4765. z: Ry_BF * x_tmp - Rx_BF * y_tmp + z_tmp
  4766. };
  4767. } //cs_geocentric_from_wgs84()
  4768. }
  4769. function checkParams(type) {
  4770. return (type === PJD_3PARAM || type === PJD_7PARAM);
  4771. }
  4772. var datum_transform = function (source, dest, point) {
  4773. // Short cut if the datums are identical.
  4774. if (compareDatums(source, dest)) {
  4775. return point; // in this case, zero is sucess,
  4776. // whereas cs_compare_datums returns 1 to indicate TRUE
  4777. // confusing, should fix this
  4778. }
  4779. // Explicitly skip datum transform by setting 'datum=none' as parameter for either source or dest
  4780. if (source.datum_type === PJD_NODATUM || dest.datum_type === PJD_NODATUM) {
  4781. return point;
  4782. }
  4783. // If this datum requires grid shifts, then apply it to geodetic coordinates.
  4784. var source_a = source.a;
  4785. var source_es = source.es;
  4786. if (source.datum_type === PJD_GRIDSHIFT) {
  4787. var gridShiftCode = applyGridShift(source, false, point);
  4788. if (gridShiftCode !== 0) {
  4789. return undefined;
  4790. }
  4791. source_a = SRS_WGS84_SEMIMAJOR;
  4792. source_es = SRS_WGS84_ESQUARED;
  4793. }
  4794. var dest_a = dest.a;
  4795. var dest_b = dest.b;
  4796. var dest_es = dest.es;
  4797. if (dest.datum_type === PJD_GRIDSHIFT) {
  4798. dest_a = SRS_WGS84_SEMIMAJOR;
  4799. dest_b = SRS_WGS84_SEMIMINOR;
  4800. dest_es = SRS_WGS84_ESQUARED;
  4801. }
  4802. // Do we need to go through geocentric coordinates?
  4803. if (source_es === dest_es && source_a === dest_a && !checkParams(source.datum_type) && !checkParams(dest.datum_type)) {
  4804. return point;
  4805. }
  4806. // Convert to geocentric coordinates.
  4807. point = geodeticToGeocentric(point, source_es, source_a);
  4808. // Convert between datums
  4809. if (checkParams(source.datum_type)) {
  4810. point = geocentricToWgs84(point, source.datum_type, source.datum_params);
  4811. }
  4812. if (checkParams(dest.datum_type)) {
  4813. point = geocentricFromWgs84(point, dest.datum_type, dest.datum_params);
  4814. }
  4815. point = geocentricToGeodetic(point, dest_es, dest_a, dest_b);
  4816. if (dest.datum_type === PJD_GRIDSHIFT) {
  4817. var destGridShiftResult = applyGridShift(dest, true, point);
  4818. if (destGridShiftResult !== 0) {
  4819. return undefined;
  4820. }
  4821. }
  4822. return point;
  4823. };
  4824. function applyGridShift(source, inverse, point) {
  4825. if (source.grids === null || source.grids.length === 0) {
  4826. // console.log('Grid shift grids not found');
  4827. return -1;
  4828. }
  4829. var input = { x: -point.x, y: point.y };
  4830. var output = { x: Number.NaN, y: Number.NaN };
  4831. var attemptedGrids = [];
  4832. for (var i = 0; i < source.grids.length; i++) {
  4833. var grid = source.grids[i];
  4834. attemptedGrids.push(grid.name);
  4835. if (grid.isNull) {
  4836. output = input;
  4837. break;
  4838. }
  4839. if (grid.grid === null) {
  4840. if (grid.mandatory) {
  4841. // console.log("Unable to find mandatory grid '" + grid.name + "'");
  4842. return -1;
  4843. }
  4844. continue;
  4845. }
  4846. var subgrid = grid.grid.subgrids[0];
  4847. // skip tables that don't match our point at all
  4848. var epsilon = (Math.abs(subgrid.del[1]) + Math.abs(subgrid.del[0])) / 10000.0;
  4849. var minX = subgrid.ll[0] - epsilon;
  4850. var minY = subgrid.ll[1] - epsilon;
  4851. var maxX = subgrid.ll[0] + (subgrid.lim[0] - 1) * subgrid.del[0] + epsilon;
  4852. var maxY = subgrid.ll[1] + (subgrid.lim[1] - 1) * subgrid.del[1] + epsilon;
  4853. if (minY > input.y || minX > input.x || maxY < input.y || maxX < input.x) {
  4854. continue;
  4855. }
  4856. output = applySubgridShift(input, inverse, subgrid);
  4857. if (!isNaN(output.x)) {
  4858. break;
  4859. }
  4860. }
  4861. if (isNaN(output.x)) {
  4862. // console.log("Failed to find a grid shift table for location '" +
  4863. // -input.x * R2D + " " + input.y * R2D + " tried: '" + attemptedGrids + "'");
  4864. return -1;
  4865. }
  4866. point.x = -output.x;
  4867. point.y = output.y;
  4868. return 0;
  4869. }
  4870. function applySubgridShift(pin, inverse, ct) {
  4871. var val = { x: Number.NaN, y: Number.NaN };
  4872. if (isNaN(pin.x)) { return val; }
  4873. var tb = { x: pin.x, y: pin.y };
  4874. tb.x -= ct.ll[0];
  4875. tb.y -= ct.ll[1];
  4876. tb.x = adjust_lon(tb.x - Math.PI) + Math.PI;
  4877. var t = nadInterpolate(tb, ct);
  4878. if (inverse) {
  4879. if (isNaN(t.x)) {
  4880. return val;
  4881. }
  4882. t.x = tb.x - t.x;
  4883. t.y = tb.y - t.y;
  4884. var i = 9, tol = 1e-12;
  4885. var dif, del;
  4886. do {
  4887. del = nadInterpolate(t, ct);
  4888. if (isNaN(del.x)) {
  4889. // console.log("Inverse grid shift iteration failed, presumably at grid edge. Using first approximation.");
  4890. break;
  4891. }
  4892. dif = { x: tb.x - (del.x + t.x), y: tb.y - (del.y + t.y) };
  4893. t.x += dif.x;
  4894. t.y += dif.y;
  4895. } while (i-- && Math.abs(dif.x) > tol && Math.abs(dif.y) > tol);
  4896. if (i < 0) {
  4897. // console.log("Inverse grid shift iterator failed to converge.");
  4898. return val;
  4899. }
  4900. val.x = adjust_lon(t.x + ct.ll[0]);
  4901. val.y = t.y + ct.ll[1];
  4902. } else {
  4903. if (!isNaN(t.x)) {
  4904. val.x = pin.x + t.x;
  4905. val.y = pin.y + t.y;
  4906. }
  4907. }
  4908. return val;
  4909. }
  4910. function nadInterpolate(pin, ct) {
  4911. var t = { x: pin.x / ct.del[0], y: pin.y / ct.del[1] };
  4912. var indx = { x: Math.floor(t.x), y: Math.floor(t.y) };
  4913. var frct = { x: t.x - 1.0 * indx.x, y: t.y - 1.0 * indx.y };
  4914. var val = { x: Number.NaN, y: Number.NaN };
  4915. var inx;
  4916. if (indx.x < 0 || indx.x >= ct.lim[0]) {
  4917. return val;
  4918. }
  4919. if (indx.y < 0 || indx.y >= ct.lim[1]) {
  4920. return val;
  4921. }
  4922. inx = (indx.y * ct.lim[0]) + indx.x;
  4923. var f00 = { x: ct.cvs[inx][0], y: ct.cvs[inx][1] };
  4924. inx++;
  4925. var f10 = { x: ct.cvs[inx][0], y: ct.cvs[inx][1] };
  4926. inx += ct.lim[0];
  4927. var f11 = { x: ct.cvs[inx][0], y: ct.cvs[inx][1] };
  4928. inx--;
  4929. var f01 = { x: ct.cvs[inx][0], y: ct.cvs[inx][1] };
  4930. var m11 = frct.x * frct.y, m10 = frct.x * (1.0 - frct.y),
  4931. m00 = (1.0 - frct.x) * (1.0 - frct.y), m01 = (1.0 - frct.x) * frct.y;
  4932. val.x = (m00 * f00.x + m10 * f10.x + m01 * f01.x + m11 * f11.x);
  4933. val.y = (m00 * f00.y + m10 * f10.y + m01 * f01.y + m11 * f11.y);
  4934. return val;
  4935. }
  4936. var adjust_axis = function (crs, denorm, point) {
  4937. var xin = point.x,
  4938. yin = point.y,
  4939. zin = point.z || 0.0;
  4940. var v, t, i;
  4941. var out = {};
  4942. for (i = 0; i < 3; i++) {
  4943. if (denorm && i === 2 && point.z === undefined) {
  4944. continue;
  4945. }
  4946. if (i === 0) {
  4947. v = xin;
  4948. if ("ew".indexOf(crs.axis[i]) !== -1) {
  4949. t = 'x';
  4950. } else {
  4951. t = 'y';
  4952. }
  4953. }
  4954. else if (i === 1) {
  4955. v = yin;
  4956. if ("ns".indexOf(crs.axis[i]) !== -1) {
  4957. t = 'y';
  4958. } else {
  4959. t = 'x';
  4960. }
  4961. }
  4962. else {
  4963. v = zin;
  4964. t = 'z';
  4965. }
  4966. switch (crs.axis[i]) {
  4967. case 'e':
  4968. out[t] = v;
  4969. break;
  4970. case 'w':
  4971. out[t] = -v;
  4972. break;
  4973. case 'n':
  4974. out[t] = v;
  4975. break;
  4976. case 's':
  4977. out[t] = -v;
  4978. break;
  4979. case 'u':
  4980. if (point[t] !== undefined) {
  4981. out.z = v;
  4982. }
  4983. break;
  4984. case 'd':
  4985. if (point[t] !== undefined) {
  4986. out.z = -v;
  4987. }
  4988. break;
  4989. default:
  4990. //console.log("ERROR: unknow axis ("+crs.axis[i]+") - check definition of "+crs.projName);
  4991. return null;
  4992. }
  4993. }
  4994. return out;
  4995. };
  4996. var toPoint = function (array) {
  4997. var out = {
  4998. x: array[0],
  4999. y: array[1]
  5000. };
  5001. if (array.length > 2) {
  5002. out.z = array[2];
  5003. }
  5004. if (array.length > 3) {
  5005. out.m = array[3];
  5006. }
  5007. return out;
  5008. };
  5009. var checkSanity = function (point) {
  5010. checkCoord(point.x);
  5011. checkCoord(point.y);
  5012. };
  5013. function checkCoord(num) {
  5014. if (typeof Number.isFinite === 'function') {
  5015. if (Number.isFinite(num)) {
  5016. return;
  5017. }
  5018. throw new TypeError('coordinates must be finite numbers');
  5019. }
  5020. if (typeof num !== 'number' || num !== num || !isFinite(num)) {
  5021. throw new TypeError('coordinates must be finite numbers');
  5022. }
  5023. }
  5024. function checkNotWGS(source, dest) {
  5025. return ((source.datum.datum_type === PJD_3PARAM || source.datum.datum_type === PJD_7PARAM) && dest.datumCode !== 'WGS84') || ((dest.datum.datum_type === PJD_3PARAM || dest.datum.datum_type === PJD_7PARAM) && source.datumCode !== 'WGS84');
  5026. }
  5027. function transform(source, dest, point) {
  5028. var wgs84;
  5029. if (Array.isArray(point)) {
  5030. point = toPoint(point);
  5031. }
  5032. checkSanity(point);
  5033. // Workaround for datum shifts towgs84, if either source or destination projection is not wgs84
  5034. if (source.datum && dest.datum && checkNotWGS(source, dest)) {
  5035. wgs84 = new Projection('WGS84');
  5036. point = transform(source, wgs84, point);
  5037. source = wgs84;
  5038. }
  5039. // DGR, 2010/11/12
  5040. if (source.axis !== 'enu') {
  5041. point = adjust_axis(source, false, point);
  5042. }
  5043. // Transform source points to long/lat, if they aren't already.
  5044. if (source.projName === 'longlat') {
  5045. point = {
  5046. x: point.x * D2R,
  5047. y: point.y * D2R,
  5048. z: point.z || 0
  5049. };
  5050. } else {
  5051. if (source.to_meter) {
  5052. point = {
  5053. x: point.x * source.to_meter,
  5054. y: point.y * source.to_meter,
  5055. z: point.z || 0
  5056. };
  5057. }
  5058. point = source.inverse(point); // Convert Cartesian to longlat
  5059. if (!point) {
  5060. return;
  5061. }
  5062. }
  5063. // Adjust for the prime meridian if necessary
  5064. if (source.from_greenwich) {
  5065. point.x += source.from_greenwich;
  5066. }
  5067. // Convert datums if needed, and if possible.
  5068. point = datum_transform(source.datum, dest.datum, point);
  5069. if (!point) {
  5070. return;
  5071. }
  5072. // Adjust for the prime meridian if necessary
  5073. if (dest.from_greenwich) {
  5074. point = {
  5075. x: point.x - dest.from_greenwich,
  5076. y: point.y,
  5077. z: point.z || 0
  5078. };
  5079. }
  5080. if (dest.projName === 'longlat') {
  5081. // convert radians to decimal degrees
  5082. point = {
  5083. x: point.x * R2D,
  5084. y: point.y * R2D,
  5085. z: point.z || 0
  5086. };
  5087. } else { // else project
  5088. point = dest.forward(point);
  5089. if (dest.to_meter) {
  5090. point = {
  5091. x: point.x / dest.to_meter,
  5092. y: point.y / dest.to_meter,
  5093. z: point.z || 0
  5094. };
  5095. }
  5096. }
  5097. // DGR, 2010/11/12
  5098. if (dest.axis !== 'enu') {
  5099. return adjust_axis(dest, true, point);
  5100. }
  5101. return point;
  5102. }
  5103. var wgs84 = Projection('WGS84');
  5104. function transformer(from, to, coords) {
  5105. var transformedArray, out, keys;
  5106. if (Array.isArray(coords)) {
  5107. transformedArray = transform(from, to, coords) || { x: NaN, y: NaN };
  5108. if (coords.length > 2) {
  5109. if ((typeof from.name !== 'undefined' && from.name === 'geocent') || (typeof to.name !== 'undefined' && to.name === 'geocent')) {
  5110. if (typeof transformedArray.z === 'number') {
  5111. return [transformedArray.x, transformedArray.y, transformedArray.z].concat(coords.splice(3));
  5112. } else {
  5113. return [transformedArray.x, transformedArray.y, coords[2]].concat(coords.splice(3));
  5114. }
  5115. } else {
  5116. return [transformedArray.x, transformedArray.y].concat(coords.splice(2));
  5117. }
  5118. } else {
  5119. return [transformedArray.x, transformedArray.y];
  5120. }
  5121. } else {
  5122. out = transform(from, to, coords);
  5123. keys = Object.keys(coords);
  5124. if (keys.length === 2) {
  5125. return out;
  5126. }
  5127. keys.forEach(function (key) {
  5128. if ((typeof from.name !== 'undefined' && from.name === 'geocent') || (typeof to.name !== 'undefined' && to.name === 'geocent')) {
  5129. if (key === 'x' || key === 'y' || key === 'z') {
  5130. return;
  5131. }
  5132. } else {
  5133. if (key === 'x' || key === 'y') {
  5134. return;
  5135. }
  5136. }
  5137. out[key] = coords[key];
  5138. });
  5139. return out;
  5140. }
  5141. }
  5142. function checkProj(item) {
  5143. if (item instanceof Projection) {
  5144. return item;
  5145. }
  5146. if (item.oProj) {
  5147. return item.oProj;
  5148. }
  5149. return Projection(item);
  5150. }
  5151. function proj4$1(fromProj, toProj, coord) {
  5152. fromProj = checkProj(fromProj);
  5153. var single = false;
  5154. var obj;
  5155. if (typeof toProj === 'undefined') {
  5156. toProj = fromProj;
  5157. fromProj = wgs84;
  5158. single = true;
  5159. } else if (typeof toProj.x !== 'undefined' || Array.isArray(toProj)) {
  5160. coord = toProj;
  5161. toProj = fromProj;
  5162. fromProj = wgs84;
  5163. single = true;
  5164. }
  5165. toProj = checkProj(toProj);
  5166. if (coord) {
  5167. return transformer(fromProj, toProj, coord);
  5168. } else {
  5169. obj = {
  5170. forward: function (coords) {
  5171. return transformer(fromProj, toProj, coords);
  5172. },
  5173. inverse: function (coords) {
  5174. return transformer(toProj, fromProj, coords);
  5175. }
  5176. };
  5177. if (single) {
  5178. obj.oProj = toProj;
  5179. }
  5180. return obj;
  5181. }
  5182. }
  5183. /**
  5184. * UTM zones are grouped, and assigned to one of a group of 6
  5185. * sets.
  5186. *
  5187. * {int} @private
  5188. */
  5189. var NUM_100K_SETS = 6;
  5190. /**
  5191. * The column letters (for easting) of the lower left value, per
  5192. * set.
  5193. *
  5194. * {string} @private
  5195. */
  5196. var SET_ORIGIN_COLUMN_LETTERS = 'AJSAJS';
  5197. /**
  5198. * The row letters (for northing) of the lower left value, per
  5199. * set.
  5200. *
  5201. * {string} @private
  5202. */
  5203. var SET_ORIGIN_ROW_LETTERS = 'AFAFAF';
  5204. var A = 65; // A
  5205. var I = 73; // I
  5206. var O = 79; // O
  5207. var V = 86; // V
  5208. var Z = 90; // Z
  5209. var mgrs = {
  5210. forward: forward$1,
  5211. inverse: inverse$1,
  5212. toPoint: toPoint$1
  5213. };
  5214. /**
  5215. * Conversion of lat/lon to MGRS.
  5216. *
  5217. * @param {object} ll Object literal with lat and lon properties on a
  5218. * WGS84 ellipsoid.
  5219. * @param {int} accuracy Accuracy in digits (5 for 1 m, 4 for 10 m, 3 for
  5220. * 100 m, 2 for 1000 m or 1 for 10000 m). Optional, default is 5.
  5221. * @return {string} the MGRS string for the given location and accuracy.
  5222. */
  5223. function forward$1(ll, accuracy) {
  5224. accuracy = accuracy || 5; // default accuracy 1m
  5225. return encode(LLtoUTM({
  5226. lat: ll[1],
  5227. lon: ll[0]
  5228. }), accuracy);
  5229. }
  5230. /**
  5231. * Conversion of MGRS to lat/lon.
  5232. *
  5233. * @param {string} mgrs MGRS string.
  5234. * @return {array} An array with left (longitude), bottom (latitude), right
  5235. * (longitude) and top (latitude) values in WGS84, representing the
  5236. * bounding box for the provided MGRS reference.
  5237. */
  5238. function inverse$1(mgrs) {
  5239. var bbox = UTMtoLL(decode(mgrs.toUpperCase()));
  5240. if (bbox.lat && bbox.lon) {
  5241. return [bbox.lon, bbox.lat, bbox.lon, bbox.lat];
  5242. }
  5243. return [bbox.left, bbox.bottom, bbox.right, bbox.top];
  5244. }
  5245. function toPoint$1(mgrs) {
  5246. var bbox = UTMtoLL(decode(mgrs.toUpperCase()));
  5247. if (bbox.lat && bbox.lon) {
  5248. return [bbox.lon, bbox.lat];
  5249. }
  5250. return [(bbox.left + bbox.right) / 2, (bbox.top + bbox.bottom) / 2];
  5251. }
  5252. /**
  5253. * Conversion from degrees to radians.
  5254. *
  5255. * @private
  5256. * @param {number} deg the angle in degrees.
  5257. * @return {number} the angle in radians.
  5258. */
  5259. function degToRad(deg) {
  5260. return (deg * (Math.PI / 180.0));
  5261. }
  5262. /**
  5263. * Conversion from radians to degrees.
  5264. *
  5265. * @private
  5266. * @param {number} rad the angle in radians.
  5267. * @return {number} the angle in degrees.
  5268. */
  5269. function radToDeg(rad) {
  5270. return (180.0 * (rad / Math.PI));
  5271. }
  5272. /**
  5273. * Converts a set of Longitude and Latitude co-ordinates to UTM
  5274. * using the WGS84 ellipsoid.
  5275. *
  5276. * @private
  5277. * @param {object} ll Object literal with lat and lon properties
  5278. * representing the WGS84 coordinate to be converted.
  5279. * @return {object} Object literal containing the UTM value with easting,
  5280. * northing, zoneNumber and zoneLetter properties, and an optional
  5281. * accuracy property in digits. Returns null if the conversion failed.
  5282. */
  5283. function LLtoUTM(ll) {
  5284. var Lat = ll.lat;
  5285. var Long = ll.lon;
  5286. var a = 6378137.0; //ellip.radius;
  5287. var eccSquared = 0.00669438; //ellip.eccsq;
  5288. var k0 = 0.9996;
  5289. var LongOrigin;
  5290. var eccPrimeSquared;
  5291. var N, T, C, A, M;
  5292. var LatRad = degToRad(Lat);
  5293. var LongRad = degToRad(Long);
  5294. var LongOriginRad;
  5295. var ZoneNumber;
  5296. // (int)
  5297. ZoneNumber = Math.floor((Long + 180) / 6) + 1;
  5298. //Make sure the longitude 180.00 is in Zone 60
  5299. if (Long === 180) {
  5300. ZoneNumber = 60;
  5301. }
  5302. // Special zone for Norway
  5303. if (Lat >= 56.0 && Lat < 64.0 && Long >= 3.0 && Long < 12.0) {
  5304. ZoneNumber = 32;
  5305. }
  5306. // Special zones for Svalbard
  5307. if (Lat >= 72.0 && Lat < 84.0) {
  5308. if (Long >= 0.0 && Long < 9.0) {
  5309. ZoneNumber = 31;
  5310. }
  5311. else if (Long >= 9.0 && Long < 21.0) {
  5312. ZoneNumber = 33;
  5313. }
  5314. else if (Long >= 21.0 && Long < 33.0) {
  5315. ZoneNumber = 35;
  5316. }
  5317. else if (Long >= 33.0 && Long < 42.0) {
  5318. ZoneNumber = 37;
  5319. }
  5320. }
  5321. LongOrigin = (ZoneNumber - 1) * 6 - 180 + 3; //+3 puts origin
  5322. // in middle of
  5323. // zone
  5324. LongOriginRad = degToRad(LongOrigin);
  5325. eccPrimeSquared = (eccSquared) / (1 - eccSquared);
  5326. N = a / Math.sqrt(1 - eccSquared * Math.sin(LatRad) * Math.sin(LatRad));
  5327. T = Math.tan(LatRad) * Math.tan(LatRad);
  5328. C = eccPrimeSquared * Math.cos(LatRad) * Math.cos(LatRad);
  5329. A = Math.cos(LatRad) * (LongRad - LongOriginRad);
  5330. M = a * ((1 - eccSquared / 4 - 3 * eccSquared * eccSquared / 64 - 5 * eccSquared * eccSquared * eccSquared / 256) * LatRad - (3 * eccSquared / 8 + 3 * eccSquared * eccSquared / 32 + 45 * eccSquared * eccSquared * eccSquared / 1024) * Math.sin(2 * LatRad) + (15 * eccSquared * eccSquared / 256 + 45 * eccSquared * eccSquared * eccSquared / 1024) * Math.sin(4 * LatRad) - (35 * eccSquared * eccSquared * eccSquared / 3072) * Math.sin(6 * LatRad));
  5331. var UTMEasting = (k0 * N * (A + (1 - T + C) * A * A * A / 6.0 + (5 - 18 * T + T * T + 72 * C - 58 * eccPrimeSquared) * A * A * A * A * A / 120.0) + 500000.0);
  5332. var UTMNorthing = (k0 * (M + N * Math.tan(LatRad) * (A * A / 2 + (5 - T + 9 * C + 4 * C * C) * A * A * A * A / 24.0 + (61 - 58 * T + T * T + 600 * C - 330 * eccPrimeSquared) * A * A * A * A * A * A / 720.0)));
  5333. if (Lat < 0.0) {
  5334. UTMNorthing += 10000000.0; //10000000 meter offset for
  5335. // southern hemisphere
  5336. }
  5337. return {
  5338. northing: Math.round(UTMNorthing),
  5339. easting: Math.round(UTMEasting),
  5340. zoneNumber: ZoneNumber,
  5341. zoneLetter: getLetterDesignator(Lat)
  5342. };
  5343. }
  5344. /**
  5345. * Converts UTM coords to lat/long, using the WGS84 ellipsoid. This is a convenience
  5346. * class where the Zone can be specified as a single string eg."60N" which
  5347. * is then broken down into the ZoneNumber and ZoneLetter.
  5348. *
  5349. * @private
  5350. * @param {object} utm An object literal with northing, easting, zoneNumber
  5351. * and zoneLetter properties. If an optional accuracy property is
  5352. * provided (in meters), a bounding box will be returned instead of
  5353. * latitude and longitude.
  5354. * @return {object} An object literal containing either lat and lon values
  5355. * (if no accuracy was provided), or top, right, bottom and left values
  5356. * for the bounding box calculated according to the provided accuracy.
  5357. * Returns null if the conversion failed.
  5358. */
  5359. function UTMtoLL(utm) {
  5360. var UTMNorthing = utm.northing;
  5361. var UTMEasting = utm.easting;
  5362. var zoneLetter = utm.zoneLetter;
  5363. var zoneNumber = utm.zoneNumber;
  5364. // check the ZoneNummber is valid
  5365. if (zoneNumber < 0 || zoneNumber > 60) {
  5366. return null;
  5367. }
  5368. var k0 = 0.9996;
  5369. var a = 6378137.0; //ellip.radius;
  5370. var eccSquared = 0.00669438; //ellip.eccsq;
  5371. var eccPrimeSquared;
  5372. var e1 = (1 - Math.sqrt(1 - eccSquared)) / (1 + Math.sqrt(1 - eccSquared));
  5373. var N1, T1, C1, R1, D, M;
  5374. var LongOrigin;
  5375. var mu, phi1Rad;
  5376. // remove 500,000 meter offset for longitude
  5377. var x = UTMEasting - 500000.0;
  5378. var y = UTMNorthing;
  5379. // We must know somehow if we are in the Northern or Southern
  5380. // hemisphere, this is the only time we use the letter So even
  5381. // if the Zone letter isn't exactly correct it should indicate
  5382. // the hemisphere correctly
  5383. if (zoneLetter < 'N') {
  5384. y -= 10000000.0; // remove 10,000,000 meter offset used
  5385. // for southern hemisphere
  5386. }
  5387. // There are 60 zones with zone 1 being at West -180 to -174
  5388. LongOrigin = (zoneNumber - 1) * 6 - 180 + 3; // +3 puts origin
  5389. // in middle of
  5390. // zone
  5391. eccPrimeSquared = (eccSquared) / (1 - eccSquared);
  5392. M = y / k0;
  5393. mu = M / (a * (1 - eccSquared / 4 - 3 * eccSquared * eccSquared / 64 - 5 * eccSquared * eccSquared * eccSquared / 256));
  5394. phi1Rad = mu + (3 * e1 / 2 - 27 * e1 * e1 * e1 / 32) * Math.sin(2 * mu) + (21 * e1 * e1 / 16 - 55 * e1 * e1 * e1 * e1 / 32) * Math.sin(4 * mu) + (151 * e1 * e1 * e1 / 96) * Math.sin(6 * mu);
  5395. // double phi1 = ProjMath.radToDeg(phi1Rad);
  5396. N1 = a / Math.sqrt(1 - eccSquared * Math.sin(phi1Rad) * Math.sin(phi1Rad));
  5397. T1 = Math.tan(phi1Rad) * Math.tan(phi1Rad);
  5398. C1 = eccPrimeSquared * Math.cos(phi1Rad) * Math.cos(phi1Rad);
  5399. R1 = a * (1 - eccSquared) / Math.pow(1 - eccSquared * Math.sin(phi1Rad) * Math.sin(phi1Rad), 1.5);
  5400. D = x / (N1 * k0);
  5401. var lat = phi1Rad - (N1 * Math.tan(phi1Rad) / R1) * (D * D / 2 - (5 + 3 * T1 + 10 * C1 - 4 * C1 * C1 - 9 * eccPrimeSquared) * D * D * D * D / 24 + (61 + 90 * T1 + 298 * C1 + 45 * T1 * T1 - 252 * eccPrimeSquared - 3 * C1 * C1) * D * D * D * D * D * D / 720);
  5402. lat = radToDeg(lat);
  5403. var lon = (D - (1 + 2 * T1 + C1) * D * D * D / 6 + (5 - 2 * C1 + 28 * T1 - 3 * C1 * C1 + 8 * eccPrimeSquared + 24 * T1 * T1) * D * D * D * D * D / 120) / Math.cos(phi1Rad);
  5404. lon = LongOrigin + radToDeg(lon);
  5405. var result;
  5406. if (utm.accuracy) {
  5407. var topRight = UTMtoLL({
  5408. northing: utm.northing + utm.accuracy,
  5409. easting: utm.easting + utm.accuracy,
  5410. zoneLetter: utm.zoneLetter,
  5411. zoneNumber: utm.zoneNumber
  5412. });
  5413. result = {
  5414. top: topRight.lat,
  5415. right: topRight.lon,
  5416. bottom: lat,
  5417. left: lon
  5418. };
  5419. }
  5420. else {
  5421. result = {
  5422. lat: lat,
  5423. lon: lon
  5424. };
  5425. }
  5426. return result;
  5427. }
  5428. /**
  5429. * Calculates the MGRS letter designator for the given latitude.
  5430. *
  5431. * @private
  5432. * @param {number} lat The latitude in WGS84 to get the letter designator
  5433. * for.
  5434. * @return {char} The letter designator.
  5435. */
  5436. function getLetterDesignator(lat) {
  5437. //This is here as an error flag to show that the Latitude is
  5438. //outside MGRS limits
  5439. var LetterDesignator = 'Z';
  5440. if ((84 >= lat) && (lat >= 72)) {
  5441. LetterDesignator = 'X';
  5442. }
  5443. else if ((72 > lat) && (lat >= 64)) {
  5444. LetterDesignator = 'W';
  5445. }
  5446. else if ((64 > lat) && (lat >= 56)) {
  5447. LetterDesignator = 'V';
  5448. }
  5449. else if ((56 > lat) && (lat >= 48)) {
  5450. LetterDesignator = 'U';
  5451. }
  5452. else if ((48 > lat) && (lat >= 40)) {
  5453. LetterDesignator = 'T';
  5454. }
  5455. else if ((40 > lat) && (lat >= 32)) {
  5456. LetterDesignator = 'S';
  5457. }
  5458. else if ((32 > lat) && (lat >= 24)) {
  5459. LetterDesignator = 'R';
  5460. }
  5461. else if ((24 > lat) && (lat >= 16)) {
  5462. LetterDesignator = 'Q';
  5463. }
  5464. else if ((16 > lat) && (lat >= 8)) {
  5465. LetterDesignator = 'P';
  5466. }
  5467. else if ((8 > lat) && (lat >= 0)) {
  5468. LetterDesignator = 'N';
  5469. }
  5470. else if ((0 > lat) && (lat >= -8)) {
  5471. LetterDesignator = 'M';
  5472. }
  5473. else if ((-8 > lat) && (lat >= -16)) {
  5474. LetterDesignator = 'L';
  5475. }
  5476. else if ((-16 > lat) && (lat >= -24)) {
  5477. LetterDesignator = 'K';
  5478. }
  5479. else if ((-24 > lat) && (lat >= -32)) {
  5480. LetterDesignator = 'J';
  5481. }
  5482. else if ((-32 > lat) && (lat >= -40)) {
  5483. LetterDesignator = 'H';
  5484. }
  5485. else if ((-40 > lat) && (lat >= -48)) {
  5486. LetterDesignator = 'G';
  5487. }
  5488. else if ((-48 > lat) && (lat >= -56)) {
  5489. LetterDesignator = 'F';
  5490. }
  5491. else if ((-56 > lat) && (lat >= -64)) {
  5492. LetterDesignator = 'E';
  5493. }
  5494. else if ((-64 > lat) && (lat >= -72)) {
  5495. LetterDesignator = 'D';
  5496. }
  5497. else if ((-72 > lat) && (lat >= -80)) {
  5498. LetterDesignator = 'C';
  5499. }
  5500. return LetterDesignator;
  5501. }
  5502. /**
  5503. * Encodes a UTM location as MGRS string.
  5504. *
  5505. * @private
  5506. * @param {object} utm An object literal with easting, northing,
  5507. * zoneLetter, zoneNumber
  5508. * @param {number} accuracy Accuracy in digits (1-5).
  5509. * @return {string} MGRS string for the given UTM location.
  5510. */
  5511. function encode(utm, accuracy) {
  5512. // prepend with leading zeroes
  5513. var seasting = "00000" + utm.easting,
  5514. snorthing = "00000" + utm.northing;
  5515. return utm.zoneNumber + utm.zoneLetter + get100kID(utm.easting, utm.northing, utm.zoneNumber) + seasting.substr(seasting.length - 5, accuracy) + snorthing.substr(snorthing.length - 5, accuracy);
  5516. }
  5517. /**
  5518. * Get the two letter 100k designator for a given UTM easting,
  5519. * northing and zone number value.
  5520. *
  5521. * @private
  5522. * @param {number} easting
  5523. * @param {number} northing
  5524. * @param {number} zoneNumber
  5525. * @return the two letter 100k designator for the given UTM location.
  5526. */
  5527. function get100kID(easting, northing, zoneNumber) {
  5528. var setParm = get100kSetForZone(zoneNumber);
  5529. var setColumn = Math.floor(easting / 100000);
  5530. var setRow = Math.floor(northing / 100000) % 20;
  5531. return getLetter100kID(setColumn, setRow, setParm);
  5532. }
  5533. /**
  5534. * Given a UTM zone number, figure out the MGRS 100K set it is in.
  5535. *
  5536. * @private
  5537. * @param {number} i An UTM zone number.
  5538. * @return {number} the 100k set the UTM zone is in.
  5539. */
  5540. function get100kSetForZone(i) {
  5541. var setParm = i % NUM_100K_SETS;
  5542. if (setParm === 0) {
  5543. setParm = NUM_100K_SETS;
  5544. }
  5545. return setParm;
  5546. }
  5547. /**
  5548. * Get the two-letter MGRS 100k designator given information
  5549. * translated from the UTM northing, easting and zone number.
  5550. *
  5551. * @private
  5552. * @param {number} column the column index as it relates to the MGRS
  5553. * 100k set spreadsheet, created from the UTM easting.
  5554. * Values are 1-8.
  5555. * @param {number} row the row index as it relates to the MGRS 100k set
  5556. * spreadsheet, created from the UTM northing value. Values
  5557. * are from 0-19.
  5558. * @param {number} parm the set block, as it relates to the MGRS 100k set
  5559. * spreadsheet, created from the UTM zone. Values are from
  5560. * 1-60.
  5561. * @return two letter MGRS 100k code.
  5562. */
  5563. function getLetter100kID(column, row, parm) {
  5564. // colOrigin and rowOrigin are the letters at the origin of the set
  5565. var index = parm - 1;
  5566. var colOrigin = SET_ORIGIN_COLUMN_LETTERS.charCodeAt(index);
  5567. var rowOrigin = SET_ORIGIN_ROW_LETTERS.charCodeAt(index);
  5568. // colInt and rowInt are the letters to build to return
  5569. var colInt = colOrigin + column - 1;
  5570. var rowInt = rowOrigin + row;
  5571. var rollover = false;
  5572. if (colInt > Z) {
  5573. colInt = colInt - Z + A - 1;
  5574. rollover = true;
  5575. }
  5576. if (colInt === I || (colOrigin < I && colInt > I) || ((colInt > I || colOrigin < I) && rollover)) {
  5577. colInt++;
  5578. }
  5579. if (colInt === O || (colOrigin < O && colInt > O) || ((colInt > O || colOrigin < O) && rollover)) {
  5580. colInt++;
  5581. if (colInt === I) {
  5582. colInt++;
  5583. }
  5584. }
  5585. if (colInt > Z) {
  5586. colInt = colInt - Z + A - 1;
  5587. }
  5588. if (rowInt > V) {
  5589. rowInt = rowInt - V + A - 1;
  5590. rollover = true;
  5591. }
  5592. else {
  5593. rollover = false;
  5594. }
  5595. if (((rowInt === I) || ((rowOrigin < I) && (rowInt > I))) || (((rowInt > I) || (rowOrigin < I)) && rollover)) {
  5596. rowInt++;
  5597. }
  5598. if (((rowInt === O) || ((rowOrigin < O) && (rowInt > O))) || (((rowInt > O) || (rowOrigin < O)) && rollover)) {
  5599. rowInt++;
  5600. if (rowInt === I) {
  5601. rowInt++;
  5602. }
  5603. }
  5604. if (rowInt > V) {
  5605. rowInt = rowInt - V + A - 1;
  5606. }
  5607. var twoLetter = String.fromCharCode(colInt) + String.fromCharCode(rowInt);
  5608. return twoLetter;
  5609. }
  5610. /**
  5611. * Decode the UTM parameters from a MGRS string.
  5612. *
  5613. * @private
  5614. * @param {string} mgrsString an UPPERCASE coordinate string is expected.
  5615. * @return {object} An object literal with easting, northing, zoneLetter,
  5616. * zoneNumber and accuracy (in meters) properties.
  5617. */
  5618. function decode(mgrsString) {
  5619. if (mgrsString && mgrsString.length === 0) {
  5620. throw ("MGRSPoint coverting from nothing");
  5621. }
  5622. var length = mgrsString.length;
  5623. var hunK = null;
  5624. var sb = "";
  5625. var testChar;
  5626. var i = 0;
  5627. // get Zone number
  5628. while (!(/[A-Z]/).test(testChar = mgrsString.charAt(i))) {
  5629. if (i >= 2) {
  5630. throw ("MGRSPoint bad conversion from: " + mgrsString);
  5631. }
  5632. sb += testChar;
  5633. i++;
  5634. }
  5635. var zoneNumber = parseInt(sb, 10);
  5636. if (i === 0 || i + 3 > length) {
  5637. // A good MGRS string has to be 4-5 digits long,
  5638. // ##AAA/#AAA at least.
  5639. throw ("MGRSPoint bad conversion from: " + mgrsString);
  5640. }
  5641. var zoneLetter = mgrsString.charAt(i++);
  5642. // Should we check the zone letter here? Why not.
  5643. if (zoneLetter <= 'A' || zoneLetter === 'B' || zoneLetter === 'Y' || zoneLetter >= 'Z' || zoneLetter === 'I' || zoneLetter === 'O') {
  5644. throw ("MGRSPoint zone letter " + zoneLetter + " not handled: " + mgrsString);
  5645. }
  5646. hunK = mgrsString.substring(i, i += 2);
  5647. var set = get100kSetForZone(zoneNumber);
  5648. var east100k = getEastingFromChar(hunK.charAt(0), set);
  5649. var north100k = getNorthingFromChar(hunK.charAt(1), set);
  5650. // We have a bug where the northing may be 2000000 too low.
  5651. // How
  5652. // do we know when to roll over?
  5653. while (north100k < getMinNorthing(zoneLetter)) {
  5654. north100k += 2000000;
  5655. }
  5656. // calculate the char index for easting/northing separator
  5657. var remainder = length - i;
  5658. if (remainder % 2 !== 0) {
  5659. throw ("MGRSPoint has to have an even number \nof digits after the zone letter and two 100km letters - front \nhalf for easting meters, second half for \nnorthing meters" + mgrsString);
  5660. }
  5661. var sep = remainder / 2;
  5662. var sepEasting = 0.0;
  5663. var sepNorthing = 0.0;
  5664. var accuracyBonus, sepEastingString, sepNorthingString, easting, northing;
  5665. if (sep > 0) {
  5666. accuracyBonus = 100000.0 / Math.pow(10, sep);
  5667. sepEastingString = mgrsString.substring(i, i + sep);
  5668. sepEasting = parseFloat(sepEastingString) * accuracyBonus;
  5669. sepNorthingString = mgrsString.substring(i + sep);
  5670. sepNorthing = parseFloat(sepNorthingString) * accuracyBonus;
  5671. }
  5672. easting = sepEasting + east100k;
  5673. northing = sepNorthing + north100k;
  5674. return {
  5675. easting: easting,
  5676. northing: northing,
  5677. zoneLetter: zoneLetter,
  5678. zoneNumber: zoneNumber,
  5679. accuracy: accuracyBonus
  5680. };
  5681. }
  5682. /**
  5683. * Given the first letter from a two-letter MGRS 100k zone, and given the
  5684. * MGRS table set for the zone number, figure out the easting value that
  5685. * should be added to the other, secondary easting value.
  5686. *
  5687. * @private
  5688. * @param {char} e The first letter from a two-letter MGRS 100´k zone.
  5689. * @param {number} set The MGRS table set for the zone number.
  5690. * @return {number} The easting value for the given letter and set.
  5691. */
  5692. function getEastingFromChar(e, set) {
  5693. // colOrigin is the letter at the origin of the set for the
  5694. // column
  5695. var curCol = SET_ORIGIN_COLUMN_LETTERS.charCodeAt(set - 1);
  5696. var eastingValue = 100000.0;
  5697. var rewindMarker = false;
  5698. while (curCol !== e.charCodeAt(0)) {
  5699. curCol++;
  5700. if (curCol === I) {
  5701. curCol++;
  5702. }
  5703. if (curCol === O) {
  5704. curCol++;
  5705. }
  5706. if (curCol > Z) {
  5707. if (rewindMarker) {
  5708. throw ("Bad character: " + e);
  5709. }
  5710. curCol = A;
  5711. rewindMarker = true;
  5712. }
  5713. eastingValue += 100000.0;
  5714. }
  5715. return eastingValue;
  5716. }
  5717. /**
  5718. * Given the second letter from a two-letter MGRS 100k zone, and given the
  5719. * MGRS table set for the zone number, figure out the northing value that
  5720. * should be added to the other, secondary northing value. You have to
  5721. * remember that Northings are determined from the equator, and the vertical
  5722. * cycle of letters mean a 2000000 additional northing meters. This happens
  5723. * approx. every 18 degrees of latitude. This method does *NOT* count any
  5724. * additional northings. You have to figure out how many 2000000 meters need
  5725. * to be added for the zone letter of the MGRS coordinate.
  5726. *
  5727. * @private
  5728. * @param {char} n Second letter of the MGRS 100k zone
  5729. * @param {number} set The MGRS table set number, which is dependent on the
  5730. * UTM zone number.
  5731. * @return {number} The northing value for the given letter and set.
  5732. */
  5733. function getNorthingFromChar(n, set) {
  5734. if (n > 'V') {
  5735. throw ("MGRSPoint given invalid Northing " + n);
  5736. }
  5737. // rowOrigin is the letter at the origin of the set for the
  5738. // column
  5739. var curRow = SET_ORIGIN_ROW_LETTERS.charCodeAt(set - 1);
  5740. var northingValue = 0.0;
  5741. var rewindMarker = false;
  5742. while (curRow !== n.charCodeAt(0)) {
  5743. curRow++;
  5744. if (curRow === I) {
  5745. curRow++;
  5746. }
  5747. if (curRow === O) {
  5748. curRow++;
  5749. }
  5750. // fixing a bug making whole application hang in this loop
  5751. // when 'n' is a wrong character
  5752. if (curRow > V) {
  5753. if (rewindMarker) { // making sure that this loop ends
  5754. throw ("Bad character: " + n);
  5755. }
  5756. curRow = A;
  5757. rewindMarker = true;
  5758. }
  5759. northingValue += 100000.0;
  5760. }
  5761. return northingValue;
  5762. }
  5763. /**
  5764. * The function getMinNorthing returns the minimum northing value of a MGRS
  5765. * zone.
  5766. *
  5767. * Ported from Geotrans' c Lattitude_Band_Value structure table.
  5768. *
  5769. * @private
  5770. * @param {char} zoneLetter The MGRS zone to get the min northing for.
  5771. * @return {number}
  5772. */
  5773. function getMinNorthing(zoneLetter) {
  5774. var northing;
  5775. switch (zoneLetter) {
  5776. case 'C':
  5777. northing = 1100000.0;
  5778. break;
  5779. case 'D':
  5780. northing = 2000000.0;
  5781. break;
  5782. case 'E':
  5783. northing = 2800000.0;
  5784. break;
  5785. case 'F':
  5786. northing = 3700000.0;
  5787. break;
  5788. case 'G':
  5789. northing = 4600000.0;
  5790. break;
  5791. case 'H':
  5792. northing = 5500000.0;
  5793. break;
  5794. case 'J':
  5795. northing = 6400000.0;
  5796. break;
  5797. case 'K':
  5798. northing = 7300000.0;
  5799. break;
  5800. case 'L':
  5801. northing = 8200000.0;
  5802. break;
  5803. case 'M':
  5804. northing = 9100000.0;
  5805. break;
  5806. case 'N':
  5807. northing = 0.0;
  5808. break;
  5809. case 'P':
  5810. northing = 800000.0;
  5811. break;
  5812. case 'Q':
  5813. northing = 1700000.0;
  5814. break;
  5815. case 'R':
  5816. northing = 2600000.0;
  5817. break;
  5818. case 'S':
  5819. northing = 3500000.0;
  5820. break;
  5821. case 'T':
  5822. northing = 4400000.0;
  5823. break;
  5824. case 'U':
  5825. northing = 5300000.0;
  5826. break;
  5827. case 'V':
  5828. northing = 6200000.0;
  5829. break;
  5830. case 'W':
  5831. northing = 7000000.0;
  5832. break;
  5833. case 'X':
  5834. northing = 7900000.0;
  5835. break;
  5836. default:
  5837. northing = -1.0;
  5838. }
  5839. if (northing >= 0.0) {
  5840. return northing;
  5841. }
  5842. else {
  5843. throw ("Invalid zone letter: " + zoneLetter);
  5844. }
  5845. }
  5846. function Point(x, y, z) {
  5847. if (!(this instanceof Point)) {
  5848. return new Point(x, y, z);
  5849. }
  5850. if (Array.isArray(x)) {
  5851. this.x = x[0];
  5852. this.y = x[1];
  5853. this.z = x[2] || 0.0;
  5854. } else if (typeof x === 'object') {
  5855. this.x = x.x;
  5856. this.y = x.y;
  5857. this.z = x.z || 0.0;
  5858. } else if (typeof x === 'string' && typeof y === 'undefined') {
  5859. var coords = x.split(',');
  5860. this.x = parseFloat(coords[0], 10);
  5861. this.y = parseFloat(coords[1], 10);
  5862. this.z = parseFloat(coords[2], 10) || 0.0;
  5863. } else {
  5864. this.x = x;
  5865. this.y = y;
  5866. this.z = z || 0.0;
  5867. }
  5868. console.warn('proj4.Point will be removed in version 3, use proj4.toPoint');
  5869. }
  5870. Point.fromMGRS = function (mgrsStr) {
  5871. return new Point(toPoint$1(mgrsStr));
  5872. };
  5873. Point.prototype.toMGRS = function (accuracy) {
  5874. return forward$1([this.x, this.y], accuracy);
  5875. };
  5876. var C00 = 1;
  5877. var C02 = 0.25;
  5878. var C04 = 0.046875;
  5879. var C06 = 0.01953125;
  5880. var C08 = 0.01068115234375;
  5881. var C22 = 0.75;
  5882. var C44 = 0.46875;
  5883. var C46 = 0.01302083333333333333;
  5884. var C48 = 0.00712076822916666666;
  5885. var C66 = 0.36458333333333333333;
  5886. var C68 = 0.00569661458333333333;
  5887. var C88 = 0.3076171875;
  5888. var pj_enfn = function (es) {
  5889. var en = [];
  5890. en[0] = C00 - es * (C02 + es * (C04 + es * (C06 + es * C08)));
  5891. en[1] = es * (C22 - es * (C04 + es * (C06 + es * C08)));
  5892. var t = es * es;
  5893. en[2] = t * (C44 - es * (C46 + es * C48));
  5894. t *= es;
  5895. en[3] = t * (C66 - es * C68);
  5896. en[4] = t * es * C88;
  5897. return en;
  5898. };
  5899. var pj_mlfn = function (phi, sphi, cphi, en) {
  5900. cphi *= sphi;
  5901. sphi *= sphi;
  5902. return (en[0] * phi - cphi * (en[1] + sphi * (en[2] + sphi * (en[3] + sphi * en[4]))));
  5903. };
  5904. var MAX_ITER = 20;
  5905. var pj_inv_mlfn = function (arg, es, en) {
  5906. var k = 1 / (1 - es);
  5907. var phi = arg;
  5908. for (var i = MAX_ITER; i; --i) { /* rarely goes over 2 iterations */
  5909. var s = Math.sin(phi);
  5910. var t = 1 - es * s * s;
  5911. //t = this.pj_mlfn(phi, s, Math.cos(phi), en) - arg;
  5912. //phi -= t * (t * Math.sqrt(t)) * k;
  5913. t = (pj_mlfn(phi, s, Math.cos(phi), en) - arg) * (t * Math.sqrt(t)) * k;
  5914. phi -= t;
  5915. if (Math.abs(t) < EPSLN) {
  5916. return phi;
  5917. }
  5918. }
  5919. //..reportError("cass:pj_inv_mlfn: Convergence error");
  5920. return phi;
  5921. };
  5922. // Heavily based on this tmerc projection implementation
  5923. // https://github.com/mbloch/mapshaper-proj/blob/master/src/projections/tmerc.js
  5924. function init$2() {
  5925. this.x0 = this.x0 !== undefined ? this.x0 : 0;
  5926. this.y0 = this.y0 !== undefined ? this.y0 : 0;
  5927. this.long0 = this.long0 !== undefined ? this.long0 : 0;
  5928. this.lat0 = this.lat0 !== undefined ? this.lat0 : 0;
  5929. if (this.es) {
  5930. this.en = pj_enfn(this.es);
  5931. this.ml0 = pj_mlfn(this.lat0, Math.sin(this.lat0), Math.cos(this.lat0), this.en);
  5932. }
  5933. }
  5934. /**
  5935. Transverse Mercator Forward - long/lat to x/y
  5936. long/lat in radians
  5937. */
  5938. function forward$2(p) {
  5939. var lon = p.x;
  5940. var lat = p.y;
  5941. var delta_lon = adjust_lon(lon - this.long0);
  5942. var con;
  5943. var x, y;
  5944. var sin_phi = Math.sin(lat);
  5945. var cos_phi = Math.cos(lat);
  5946. if (!this.es) {
  5947. var b = cos_phi * Math.sin(delta_lon);
  5948. if ((Math.abs(Math.abs(b) - 1)) < EPSLN) {
  5949. return (93);
  5950. }
  5951. else {
  5952. x = 0.5 * this.a * this.k0 * Math.log((1 + b) / (1 - b)) + this.x0;
  5953. y = cos_phi * Math.cos(delta_lon) / Math.sqrt(1 - Math.pow(b, 2));
  5954. b = Math.abs(y);
  5955. if (b >= 1) {
  5956. if ((b - 1) > EPSLN) {
  5957. return (93);
  5958. }
  5959. else {
  5960. y = 0;
  5961. }
  5962. }
  5963. else {
  5964. y = Math.acos(y);
  5965. }
  5966. if (lat < 0) {
  5967. y = -y;
  5968. }
  5969. y = this.a * this.k0 * (y - this.lat0) + this.y0;
  5970. }
  5971. }
  5972. else {
  5973. var al = cos_phi * delta_lon;
  5974. var als = Math.pow(al, 2);
  5975. var c = this.ep2 * Math.pow(cos_phi, 2);
  5976. var cs = Math.pow(c, 2);
  5977. var tq = Math.abs(cos_phi) > EPSLN ? Math.tan(lat) : 0;
  5978. var t = Math.pow(tq, 2);
  5979. var ts = Math.pow(t, 2);
  5980. con = 1 - this.es * Math.pow(sin_phi, 2);
  5981. al = al / Math.sqrt(con);
  5982. var ml = pj_mlfn(lat, sin_phi, cos_phi, this.en);
  5983. x = this.a * (this.k0 * al * (1 +
  5984. als / 6 * (1 - t + c +
  5985. als / 20 * (5 - 18 * t + ts + 14 * c - 58 * t * c +
  5986. als / 42 * (61 + 179 * ts - ts * t - 479 * t))))) +
  5987. this.x0;
  5988. y = this.a * (this.k0 * (ml - this.ml0 +
  5989. sin_phi * delta_lon * al / 2 * (1 +
  5990. als / 12 * (5 - t + 9 * c + 4 * cs +
  5991. als / 30 * (61 + ts - 58 * t + 270 * c - 330 * t * c +
  5992. als / 56 * (1385 + 543 * ts - ts * t - 3111 * t)))))) +
  5993. this.y0;
  5994. }
  5995. p.x = x;
  5996. p.y = y;
  5997. return p;
  5998. }
  5999. /**
  6000. Transverse Mercator Inverse - x/y to long/lat
  6001. */
  6002. function inverse$2(p) {
  6003. var con, phi;
  6004. var lat, lon;
  6005. var x = (p.x - this.x0) * (1 / this.a);
  6006. var y = (p.y - this.y0) * (1 / this.a);
  6007. if (!this.es) {
  6008. var f = Math.exp(x / this.k0);
  6009. var g = 0.5 * (f - 1 / f);
  6010. var temp = this.lat0 + y / this.k0;
  6011. var h = Math.cos(temp);
  6012. con = Math.sqrt((1 - Math.pow(h, 2)) / (1 + Math.pow(g, 2)));
  6013. lat = Math.asin(con);
  6014. if (y < 0) {
  6015. lat = -lat;
  6016. }
  6017. if ((g === 0) && (h === 0)) {
  6018. lon = 0;
  6019. }
  6020. else {
  6021. lon = adjust_lon(Math.atan2(g, h) + this.long0);
  6022. }
  6023. }
  6024. else { // ellipsoidal form
  6025. con = this.ml0 + y / this.k0;
  6026. phi = pj_inv_mlfn(con, this.es, this.en);
  6027. if (Math.abs(phi) < HALF_PI) {
  6028. var sin_phi = Math.sin(phi);
  6029. var cos_phi = Math.cos(phi);
  6030. var tan_phi = Math.abs(cos_phi) > EPSLN ? Math.tan(phi) : 0;
  6031. var c = this.ep2 * Math.pow(cos_phi, 2);
  6032. var cs = Math.pow(c, 2);
  6033. var t = Math.pow(tan_phi, 2);
  6034. var ts = Math.pow(t, 2);
  6035. con = 1 - this.es * Math.pow(sin_phi, 2);
  6036. var d = x * Math.sqrt(con) / this.k0;
  6037. var ds = Math.pow(d, 2);
  6038. con = con * tan_phi;
  6039. lat = phi - (con * ds / (1 - this.es)) * 0.5 * (1 -
  6040. ds / 12 * (5 + 3 * t - 9 * c * t + c - 4 * cs -
  6041. ds / 30 * (61 + 90 * t - 252 * c * t + 45 * ts + 46 * c -
  6042. ds / 56 * (1385 + 3633 * t + 4095 * ts + 1574 * ts * t))));
  6043. lon = adjust_lon(this.long0 + (d * (1 -
  6044. ds / 6 * (1 + 2 * t + c -
  6045. ds / 20 * (5 + 28 * t + 24 * ts + 8 * c * t + 6 * c -
  6046. ds / 42 * (61 + 662 * t + 1320 * ts + 720 * ts * t)))) / cos_phi));
  6047. }
  6048. else {
  6049. lat = HALF_PI * sign(y);
  6050. lon = 0;
  6051. }
  6052. }
  6053. p.x = lon;
  6054. p.y = lat;
  6055. return p;
  6056. }
  6057. var names$3 = ["Fast_Transverse_Mercator", "Fast Transverse Mercator"];
  6058. var tmerc = {
  6059. init: init$2,
  6060. forward: forward$2,
  6061. inverse: inverse$2,
  6062. names: names$3
  6063. };
  6064. var sinh = function (x) {
  6065. var r = Math.exp(x);
  6066. r = (r - 1 / r) / 2;
  6067. return r;
  6068. };
  6069. var hypot = function (x, y) {
  6070. x = Math.abs(x);
  6071. y = Math.abs(y);
  6072. var a = Math.max(x, y);
  6073. var b = Math.min(x, y) / (a ? a : 1);
  6074. return a * Math.sqrt(1 + Math.pow(b, 2));
  6075. };
  6076. var log1py = function (x) {
  6077. var y = 1 + x;
  6078. var z = y - 1;
  6079. return z === 0 ? x : x * Math.log(y) / z;
  6080. };
  6081. var asinhy = function (x) {
  6082. var y = Math.abs(x);
  6083. y = log1py(y * (1 + y / (hypot(1, y) + 1)));
  6084. return x < 0 ? -y : y;
  6085. };
  6086. var gatg = function (pp, B) {
  6087. var cos_2B = 2 * Math.cos(2 * B);
  6088. var i = pp.length - 1;
  6089. var h1 = pp[i];
  6090. var h2 = 0;
  6091. var h;
  6092. while (--i >= 0) {
  6093. h = -h2 + cos_2B * h1 + pp[i];
  6094. h2 = h1;
  6095. h1 = h;
  6096. }
  6097. return (B + h * Math.sin(2 * B));
  6098. };
  6099. var clens = function (pp, arg_r) {
  6100. var r = 2 * Math.cos(arg_r);
  6101. var i = pp.length - 1;
  6102. var hr1 = pp[i];
  6103. var hr2 = 0;
  6104. var hr;
  6105. while (--i >= 0) {
  6106. hr = -hr2 + r * hr1 + pp[i];
  6107. hr2 = hr1;
  6108. hr1 = hr;
  6109. }
  6110. return Math.sin(arg_r) * hr;
  6111. };
  6112. var cosh = function (x) {
  6113. var r = Math.exp(x);
  6114. r = (r + 1 / r) / 2;
  6115. return r;
  6116. };
  6117. var clens_cmplx = function (pp, arg_r, arg_i) {
  6118. var sin_arg_r = Math.sin(arg_r);
  6119. var cos_arg_r = Math.cos(arg_r);
  6120. var sinh_arg_i = sinh(arg_i);
  6121. var cosh_arg_i = cosh(arg_i);
  6122. var r = 2 * cos_arg_r * cosh_arg_i;
  6123. var i = -2 * sin_arg_r * sinh_arg_i;
  6124. var j = pp.length - 1;
  6125. var hr = pp[j];
  6126. var hi1 = 0;
  6127. var hr1 = 0;
  6128. var hi = 0;
  6129. var hr2;
  6130. var hi2;
  6131. while (--j >= 0) {
  6132. hr2 = hr1;
  6133. hi2 = hi1;
  6134. hr1 = hr;
  6135. hi1 = hi;
  6136. hr = -hr2 + r * hr1 - i * hi1 + pp[j];
  6137. hi = -hi2 + i * hr1 + r * hi1;
  6138. }
  6139. r = sin_arg_r * cosh_arg_i;
  6140. i = cos_arg_r * sinh_arg_i;
  6141. return [r * hr - i * hi, r * hi + i * hr];
  6142. };
  6143. // Heavily based on this etmerc projection implementation
  6144. // https://github.com/mbloch/mapshaper-proj/blob/master/src/projections/etmerc.js
  6145. function init$3() {
  6146. if (!this.approx && (isNaN(this.es) || this.es <= 0)) {
  6147. throw new Error('Incorrect elliptical usage. Try using the +approx option in the proj string, or PROJECTION["Fast_Transverse_Mercator"] in the WKT.');
  6148. }
  6149. if (this.approx) {
  6150. // When '+approx' is set, use tmerc instead
  6151. tmerc.init.apply(this);
  6152. this.forward = tmerc.forward;
  6153. this.inverse = tmerc.inverse;
  6154. }
  6155. this.x0 = this.x0 !== undefined ? this.x0 : 0;
  6156. this.y0 = this.y0 !== undefined ? this.y0 : 0;
  6157. this.long0 = this.long0 !== undefined ? this.long0 : 0;
  6158. this.lat0 = this.lat0 !== undefined ? this.lat0 : 0;
  6159. this.cgb = [];
  6160. this.cbg = [];
  6161. this.utg = [];
  6162. this.gtu = [];
  6163. var f = this.es / (1 + Math.sqrt(1 - this.es));
  6164. var n = f / (2 - f);
  6165. var np = n;
  6166. this.cgb[0] = n * (2 + n * (-2 / 3 + n * (-2 + n * (116 / 45 + n * (26 / 45 + n * (-2854 / 675))))));
  6167. this.cbg[0] = n * (-2 + n * (2 / 3 + n * (4 / 3 + n * (-82 / 45 + n * (32 / 45 + n * (4642 / 4725))))));
  6168. np = np * n;
  6169. this.cgb[1] = np * (7 / 3 + n * (-8 / 5 + n * (-227 / 45 + n * (2704 / 315 + n * (2323 / 945)))));
  6170. this.cbg[1] = np * (5 / 3 + n * (-16 / 15 + n * (-13 / 9 + n * (904 / 315 + n * (-1522 / 945)))));
  6171. np = np * n;
  6172. this.cgb[2] = np * (56 / 15 + n * (-136 / 35 + n * (-1262 / 105 + n * (73814 / 2835))));
  6173. this.cbg[2] = np * (-26 / 15 + n * (34 / 21 + n * (8 / 5 + n * (-12686 / 2835))));
  6174. np = np * n;
  6175. this.cgb[3] = np * (4279 / 630 + n * (-332 / 35 + n * (-399572 / 14175)));
  6176. this.cbg[3] = np * (1237 / 630 + n * (-12 / 5 + n * (-24832 / 14175)));
  6177. np = np * n;
  6178. this.cgb[4] = np * (4174 / 315 + n * (-144838 / 6237));
  6179. this.cbg[4] = np * (-734 / 315 + n * (109598 / 31185));
  6180. np = np * n;
  6181. this.cgb[5] = np * (601676 / 22275);
  6182. this.cbg[5] = np * (444337 / 155925);
  6183. np = Math.pow(n, 2);
  6184. this.Qn = this.k0 / (1 + n) * (1 + np * (1 / 4 + np * (1 / 64 + np / 256)));
  6185. this.utg[0] = n * (-0.5 + n * (2 / 3 + n * (-37 / 96 + n * (1 / 360 + n * (81 / 512 + n * (-96199 / 604800))))));
  6186. this.gtu[0] = n * (0.5 + n * (-2 / 3 + n * (5 / 16 + n * (41 / 180 + n * (-127 / 288 + n * (7891 / 37800))))));
  6187. this.utg[1] = np * (-1 / 48 + n * (-1 / 15 + n * (437 / 1440 + n * (-46 / 105 + n * (1118711 / 3870720)))));
  6188. this.gtu[1] = np * (13 / 48 + n * (-3 / 5 + n * (557 / 1440 + n * (281 / 630 + n * (-1983433 / 1935360)))));
  6189. np = np * n;
  6190. this.utg[2] = np * (-17 / 480 + n * (37 / 840 + n * (209 / 4480 + n * (-5569 / 90720))));
  6191. this.gtu[2] = np * (61 / 240 + n * (-103 / 140 + n * (15061 / 26880 + n * (167603 / 181440))));
  6192. np = np * n;
  6193. this.utg[3] = np * (-4397 / 161280 + n * (11 / 504 + n * (830251 / 7257600)));
  6194. this.gtu[3] = np * (49561 / 161280 + n * (-179 / 168 + n * (6601661 / 7257600)));
  6195. np = np * n;
  6196. this.utg[4] = np * (-4583 / 161280 + n * (108847 / 3991680));
  6197. this.gtu[4] = np * (34729 / 80640 + n * (-3418889 / 1995840));
  6198. np = np * n;
  6199. this.utg[5] = np * (-20648693 / 638668800);
  6200. this.gtu[5] = np * (212378941 / 319334400);
  6201. var Z = gatg(this.cbg, this.lat0);
  6202. this.Zb = -this.Qn * (Z + clens(this.gtu, 2 * Z));
  6203. }
  6204. function forward$3(p) {
  6205. var Ce = adjust_lon(p.x - this.long0);
  6206. var Cn = p.y;
  6207. Cn = gatg(this.cbg, Cn);
  6208. var sin_Cn = Math.sin(Cn);
  6209. var cos_Cn = Math.cos(Cn);
  6210. var sin_Ce = Math.sin(Ce);
  6211. var cos_Ce = Math.cos(Ce);
  6212. Cn = Math.atan2(sin_Cn, cos_Ce * cos_Cn);
  6213. Ce = Math.atan2(sin_Ce * cos_Cn, hypot(sin_Cn, cos_Cn * cos_Ce));
  6214. Ce = asinhy(Math.tan(Ce));
  6215. var tmp = clens_cmplx(this.gtu, 2 * Cn, 2 * Ce);
  6216. Cn = Cn + tmp[0];
  6217. Ce = Ce + tmp[1];
  6218. var x;
  6219. var y;
  6220. if (Math.abs(Ce) <= 2.623395162778) {
  6221. x = this.a * (this.Qn * Ce) + this.x0;
  6222. y = this.a * (this.Qn * Cn + this.Zb) + this.y0;
  6223. }
  6224. else {
  6225. x = Infinity;
  6226. y = Infinity;
  6227. }
  6228. p.x = x;
  6229. p.y = y;
  6230. return p;
  6231. }
  6232. function inverse$3(p) {
  6233. var Ce = (p.x - this.x0) * (1 / this.a);
  6234. var Cn = (p.y - this.y0) * (1 / this.a);
  6235. Cn = (Cn - this.Zb) / this.Qn;
  6236. Ce = Ce / this.Qn;
  6237. var lon;
  6238. var lat;
  6239. if (Math.abs(Ce) <= 2.623395162778) {
  6240. var tmp = clens_cmplx(this.utg, 2 * Cn, 2 * Ce);
  6241. Cn = Cn + tmp[0];
  6242. Ce = Ce + tmp[1];
  6243. Ce = Math.atan(sinh(Ce));
  6244. var sin_Cn = Math.sin(Cn);
  6245. var cos_Cn = Math.cos(Cn);
  6246. var sin_Ce = Math.sin(Ce);
  6247. var cos_Ce = Math.cos(Ce);
  6248. Cn = Math.atan2(sin_Cn * cos_Ce, hypot(sin_Ce, cos_Ce * cos_Cn));
  6249. Ce = Math.atan2(sin_Ce, cos_Ce * cos_Cn);
  6250. lon = adjust_lon(Ce + this.long0);
  6251. lat = gatg(this.cgb, Cn);
  6252. }
  6253. else {
  6254. lon = Infinity;
  6255. lat = Infinity;
  6256. }
  6257. p.x = lon;
  6258. p.y = lat;
  6259. return p;
  6260. }
  6261. var names$4 = ["Extended_Transverse_Mercator", "Extended Transverse Mercator", "etmerc", "Transverse_Mercator", "Transverse Mercator", "tmerc"];
  6262. var etmerc = {
  6263. init: init$3,
  6264. forward: forward$3,
  6265. inverse: inverse$3,
  6266. names: names$4
  6267. };
  6268. var adjust_zone = function (zone, lon) {
  6269. if (zone === undefined) {
  6270. zone = Math.floor((adjust_lon(lon) + Math.PI) * 30 / Math.PI) + 1;
  6271. if (zone < 0) {
  6272. return 0;
  6273. } else if (zone > 60) {
  6274. return 60;
  6275. }
  6276. }
  6277. return zone;
  6278. };
  6279. var dependsOn = 'etmerc';
  6280. function init$4() {
  6281. var zone = adjust_zone(this.zone, this.long0);
  6282. if (zone === undefined) {
  6283. throw new Error('unknown utm zone');
  6284. }
  6285. this.lat0 = 0;
  6286. this.long0 = ((6 * Math.abs(zone)) - 183) * D2R;
  6287. this.x0 = 500000;
  6288. this.y0 = this.utmSouth ? 10000000 : 0;
  6289. this.k0 = 0.9996;
  6290. etmerc.init.apply(this);
  6291. this.forward = etmerc.forward;
  6292. this.inverse = etmerc.inverse;
  6293. }
  6294. var names$5 = ["Universal Transverse Mercator System", "utm"];
  6295. var utm = {
  6296. init: init$4,
  6297. names: names$5,
  6298. dependsOn: dependsOn
  6299. };
  6300. var srat = function (esinp, exp) {
  6301. return (Math.pow((1 - esinp) / (1 + esinp), exp));
  6302. };
  6303. var MAX_ITER$1 = 20;
  6304. function init$6() {
  6305. var sphi = Math.sin(this.lat0);
  6306. var cphi = Math.cos(this.lat0);
  6307. cphi *= cphi;
  6308. this.rc = Math.sqrt(1 - this.es) / (1 - this.es * sphi * sphi);
  6309. this.C = Math.sqrt(1 + this.es * cphi * cphi / (1 - this.es));
  6310. this.phic0 = Math.asin(sphi / this.C);
  6311. this.ratexp = 0.5 * this.C * this.e;
  6312. this.K = Math.tan(0.5 * this.phic0 + FORTPI) / (Math.pow(Math.tan(0.5 * this.lat0 + FORTPI), this.C) * srat(this.e * sphi, this.ratexp));
  6313. }
  6314. function forward$5(p) {
  6315. var lon = p.x;
  6316. var lat = p.y;
  6317. p.y = 2 * Math.atan(this.K * Math.pow(Math.tan(0.5 * lat + FORTPI), this.C) * srat(this.e * Math.sin(lat), this.ratexp)) - HALF_PI;
  6318. p.x = this.C * lon;
  6319. return p;
  6320. }
  6321. function inverse$5(p) {
  6322. var DEL_TOL = 1e-14;
  6323. var lon = p.x / this.C;
  6324. var lat = p.y;
  6325. var num = Math.pow(Math.tan(0.5 * lat + FORTPI) / this.K, 1 / this.C);
  6326. for (var i = MAX_ITER$1; i > 0; --i) {
  6327. lat = 2 * Math.atan(num * srat(this.e * Math.sin(p.y), - 0.5 * this.e)) - HALF_PI;
  6328. if (Math.abs(lat - p.y) < DEL_TOL) {
  6329. break;
  6330. }
  6331. p.y = lat;
  6332. }
  6333. /* convergence failed */
  6334. if (!i) {
  6335. return null;
  6336. }
  6337. p.x = lon;
  6338. p.y = lat;
  6339. return p;
  6340. }
  6341. var names$7 = ["gauss"];
  6342. var gauss = {
  6343. init: init$6,
  6344. forward: forward$5,
  6345. inverse: inverse$5,
  6346. names: names$7
  6347. };
  6348. function init$5() {
  6349. gauss.init.apply(this);
  6350. if (!this.rc) {
  6351. return;
  6352. }
  6353. this.sinc0 = Math.sin(this.phic0);
  6354. this.cosc0 = Math.cos(this.phic0);
  6355. this.R2 = 2 * this.rc;
  6356. if (!this.title) {
  6357. this.title = "Oblique Stereographic Alternative";
  6358. }
  6359. }
  6360. function forward$4(p) {
  6361. var sinc, cosc, cosl, k;
  6362. p.x = adjust_lon(p.x - this.long0);
  6363. gauss.forward.apply(this, [p]);
  6364. sinc = Math.sin(p.y);
  6365. cosc = Math.cos(p.y);
  6366. cosl = Math.cos(p.x);
  6367. k = this.k0 * this.R2 / (1 + this.sinc0 * sinc + this.cosc0 * cosc * cosl);
  6368. p.x = k * cosc * Math.sin(p.x);
  6369. p.y = k * (this.cosc0 * sinc - this.sinc0 * cosc * cosl);
  6370. p.x = this.a * p.x + this.x0;
  6371. p.y = this.a * p.y + this.y0;
  6372. return p;
  6373. }
  6374. function inverse$4(p) {
  6375. var sinc, cosc, lon, lat, rho;
  6376. p.x = (p.x - this.x0) / this.a;
  6377. p.y = (p.y - this.y0) / this.a;
  6378. p.x /= this.k0;
  6379. p.y /= this.k0;
  6380. if ((rho = Math.sqrt(p.x * p.x + p.y * p.y))) {
  6381. var c = 2 * Math.atan2(rho, this.R2);
  6382. sinc = Math.sin(c);
  6383. cosc = Math.cos(c);
  6384. lat = Math.asin(cosc * this.sinc0 + p.y * sinc * this.cosc0 / rho);
  6385. lon = Math.atan2(p.x * sinc, rho * this.cosc0 * cosc - p.y * this.sinc0 * sinc);
  6386. }
  6387. else {
  6388. lat = this.phic0;
  6389. lon = 0;
  6390. }
  6391. p.x = lon;
  6392. p.y = lat;
  6393. gauss.inverse.apply(this, [p]);
  6394. p.x = adjust_lon(p.x + this.long0);
  6395. return p;
  6396. }
  6397. var names$6 = ["Stereographic_North_Pole", "Oblique_Stereographic", "Polar_Stereographic", "sterea", "Oblique Stereographic Alternative", "Double_Stereographic"];
  6398. var sterea = {
  6399. init: init$5,
  6400. forward: forward$4,
  6401. inverse: inverse$4,
  6402. names: names$6
  6403. };
  6404. function ssfn_(phit, sinphi, eccen) {
  6405. sinphi *= eccen;
  6406. return (Math.tan(0.5 * (HALF_PI + phit)) * Math.pow((1 - sinphi) / (1 + sinphi), 0.5 * eccen));
  6407. }
  6408. function init$7() {
  6409. this.coslat0 = Math.cos(this.lat0);
  6410. this.sinlat0 = Math.sin(this.lat0);
  6411. if (this.sphere) {
  6412. if (this.k0 === 1 && !isNaN(this.lat_ts) && Math.abs(this.coslat0) <= EPSLN) {
  6413. this.k0 = 0.5 * (1 + sign(this.lat0) * Math.sin(this.lat_ts));
  6414. }
  6415. }
  6416. else {
  6417. if (Math.abs(this.coslat0) <= EPSLN) {
  6418. if (this.lat0 > 0) {
  6419. //North pole
  6420. //trace('stere:north pole');
  6421. this.con = 1;
  6422. }
  6423. else {
  6424. //South pole
  6425. //trace('stere:south pole');
  6426. this.con = -1;
  6427. }
  6428. }
  6429. this.cons = Math.sqrt(Math.pow(1 + this.e, 1 + this.e) * Math.pow(1 - this.e, 1 - this.e));
  6430. if (this.k0 === 1 && !isNaN(this.lat_ts) && Math.abs(this.coslat0) <= EPSLN) {
  6431. this.k0 = 0.5 * this.cons * msfnz(this.e, Math.sin(this.lat_ts), Math.cos(this.lat_ts)) / tsfnz(this.e, this.con * this.lat_ts, this.con * Math.sin(this.lat_ts));
  6432. }
  6433. this.ms1 = msfnz(this.e, this.sinlat0, this.coslat0);
  6434. this.X0 = 2 * Math.atan(this.ssfn_(this.lat0, this.sinlat0, this.e)) - HALF_PI;
  6435. this.cosX0 = Math.cos(this.X0);
  6436. this.sinX0 = Math.sin(this.X0);
  6437. }
  6438. }
  6439. // Stereographic forward equations--mapping lat,long to x,y
  6440. function forward$6(p) {
  6441. var lon = p.x;
  6442. var lat = p.y;
  6443. var sinlat = Math.sin(lat);
  6444. var coslat = Math.cos(lat);
  6445. var A, X, sinX, cosX, ts, rh;
  6446. var dlon = adjust_lon(lon - this.long0);
  6447. if (Math.abs(Math.abs(lon - this.long0) - Math.PI) <= EPSLN && Math.abs(lat + this.lat0) <= EPSLN) {
  6448. //case of the origine point
  6449. //trace('stere:this is the origin point');
  6450. p.x = NaN;
  6451. p.y = NaN;
  6452. return p;
  6453. }
  6454. if (this.sphere) {
  6455. //trace('stere:sphere case');
  6456. A = 2 * this.k0 / (1 + this.sinlat0 * sinlat + this.coslat0 * coslat * Math.cos(dlon));
  6457. p.x = this.a * A * coslat * Math.sin(dlon) + this.x0;
  6458. p.y = this.a * A * (this.coslat0 * sinlat - this.sinlat0 * coslat * Math.cos(dlon)) + this.y0;
  6459. return p;
  6460. }
  6461. else {
  6462. X = 2 * Math.atan(this.ssfn_(lat, sinlat, this.e)) - HALF_PI;
  6463. cosX = Math.cos(X);
  6464. sinX = Math.sin(X);
  6465. if (Math.abs(this.coslat0) <= EPSLN) {
  6466. ts = tsfnz(this.e, lat * this.con, this.con * sinlat);
  6467. rh = 2 * this.a * this.k0 * ts / this.cons;
  6468. p.x = this.x0 + rh * Math.sin(lon - this.long0);
  6469. p.y = this.y0 - this.con * rh * Math.cos(lon - this.long0);
  6470. //trace(p.toString());
  6471. return p;
  6472. }
  6473. else if (Math.abs(this.sinlat0) < EPSLN) {
  6474. //Eq
  6475. //trace('stere:equateur');
  6476. A = 2 * this.a * this.k0 / (1 + cosX * Math.cos(dlon));
  6477. p.y = A * sinX;
  6478. }
  6479. else {
  6480. //other case
  6481. //trace('stere:normal case');
  6482. A = 2 * this.a * this.k0 * this.ms1 / (this.cosX0 * (1 + this.sinX0 * sinX + this.cosX0 * cosX * Math.cos(dlon)));
  6483. p.y = A * (this.cosX0 * sinX - this.sinX0 * cosX * Math.cos(dlon)) + this.y0;
  6484. }
  6485. p.x = A * cosX * Math.sin(dlon) + this.x0;
  6486. }
  6487. //trace(p.toString());
  6488. return p;
  6489. }
  6490. //* Stereographic inverse equations--mapping x,y to lat/long
  6491. function inverse$6(p) {
  6492. p.x -= this.x0;
  6493. p.y -= this.y0;
  6494. var lon, lat, ts, ce, Chi;
  6495. var rh = Math.sqrt(p.x * p.x + p.y * p.y);
  6496. if (this.sphere) {
  6497. var c = 2 * Math.atan(rh / (2 * this.a * this.k0));
  6498. lon = this.long0;
  6499. lat = this.lat0;
  6500. if (rh <= EPSLN) {
  6501. p.x = lon;
  6502. p.y = lat;
  6503. return p;
  6504. }
  6505. lat = Math.asin(Math.cos(c) * this.sinlat0 + p.y * Math.sin(c) * this.coslat0 / rh);
  6506. if (Math.abs(this.coslat0) < EPSLN) {
  6507. if (this.lat0 > 0) {
  6508. lon = adjust_lon(this.long0 + Math.atan2(p.x, - 1 * p.y));
  6509. }
  6510. else {
  6511. lon = adjust_lon(this.long0 + Math.atan2(p.x, p.y));
  6512. }
  6513. }
  6514. else {
  6515. lon = adjust_lon(this.long0 + Math.atan2(p.x * Math.sin(c), rh * this.coslat0 * Math.cos(c) - p.y * this.sinlat0 * Math.sin(c)));
  6516. }
  6517. p.x = lon;
  6518. p.y = lat;
  6519. return p;
  6520. }
  6521. else {
  6522. if (Math.abs(this.coslat0) <= EPSLN) {
  6523. if (rh <= EPSLN) {
  6524. lat = this.lat0;
  6525. lon = this.long0;
  6526. p.x = lon;
  6527. p.y = lat;
  6528. //trace(p.toString());
  6529. return p;
  6530. }
  6531. p.x *= this.con;
  6532. p.y *= this.con;
  6533. ts = rh * this.cons / (2 * this.a * this.k0);
  6534. lat = this.con * phi2z(this.e, ts);
  6535. lon = this.con * adjust_lon(this.con * this.long0 + Math.atan2(p.x, - 1 * p.y));
  6536. }
  6537. else {
  6538. ce = 2 * Math.atan(rh * this.cosX0 / (2 * this.a * this.k0 * this.ms1));
  6539. lon = this.long0;
  6540. if (rh <= EPSLN) {
  6541. Chi = this.X0;
  6542. }
  6543. else {
  6544. Chi = Math.asin(Math.cos(ce) * this.sinX0 + p.y * Math.sin(ce) * this.cosX0 / rh);
  6545. lon = adjust_lon(this.long0 + Math.atan2(p.x * Math.sin(ce), rh * this.cosX0 * Math.cos(ce) - p.y * this.sinX0 * Math.sin(ce)));
  6546. }
  6547. lat = -1 * phi2z(this.e, Math.tan(0.5 * (HALF_PI + Chi)));
  6548. }
  6549. }
  6550. p.x = lon;
  6551. p.y = lat;
  6552. //trace(p.toString());
  6553. return p;
  6554. }
  6555. var names$8 = ["stere", "Stereographic_South_Pole", "Polar Stereographic (variant B)"];
  6556. var stere = {
  6557. init: init$7,
  6558. forward: forward$6,
  6559. inverse: inverse$6,
  6560. names: names$8,
  6561. ssfn_: ssfn_
  6562. };
  6563. /*
  6564. references:
  6565. Formules et constantes pour le Calcul pour la
  6566. projection cylindrique conforme à axe oblique et pour la transformation entre
  6567. des systèmes de référence.
  6568. http://www.swisstopo.admin.ch/internet/swisstopo/fr/home/topics/survey/sys/refsys/switzerland.parsysrelated1.31216.downloadList.77004.DownloadFile.tmp/swissprojectionfr.pdf
  6569. */
  6570. function init$8() {
  6571. var phy0 = this.lat0;
  6572. this.lambda0 = this.long0;
  6573. var sinPhy0 = Math.sin(phy0);
  6574. var semiMajorAxis = this.a;
  6575. var invF = this.rf;
  6576. var flattening = 1 / invF;
  6577. var e2 = 2 * flattening - Math.pow(flattening, 2);
  6578. var e = this.e = Math.sqrt(e2);
  6579. this.R = this.k0 * semiMajorAxis * Math.sqrt(1 - e2) / (1 - e2 * Math.pow(sinPhy0, 2));
  6580. this.alpha = Math.sqrt(1 + e2 / (1 - e2) * Math.pow(Math.cos(phy0), 4));
  6581. this.b0 = Math.asin(sinPhy0 / this.alpha);
  6582. var k1 = Math.log(Math.tan(Math.PI / 4 + this.b0 / 2));
  6583. var k2 = Math.log(Math.tan(Math.PI / 4 + phy0 / 2));
  6584. var k3 = Math.log((1 + e * sinPhy0) / (1 - e * sinPhy0));
  6585. this.K = k1 - this.alpha * k2 + this.alpha * e / 2 * k3;
  6586. }
  6587. function forward$7(p) {
  6588. var Sa1 = Math.log(Math.tan(Math.PI / 4 - p.y / 2));
  6589. var Sa2 = this.e / 2 * Math.log((1 + this.e * Math.sin(p.y)) / (1 - this.e * Math.sin(p.y)));
  6590. var S = -this.alpha * (Sa1 + Sa2) + this.K;
  6591. // spheric latitude
  6592. var b = 2 * (Math.atan(Math.exp(S)) - Math.PI / 4);
  6593. // spheric longitude
  6594. var I = this.alpha * (p.x - this.lambda0);
  6595. // psoeudo equatorial rotation
  6596. var rotI = Math.atan(Math.sin(I) / (Math.sin(this.b0) * Math.tan(b) + Math.cos(this.b0) * Math.cos(I)));
  6597. var rotB = Math.asin(Math.cos(this.b0) * Math.sin(b) - Math.sin(this.b0) * Math.cos(b) * Math.cos(I));
  6598. p.y = this.R / 2 * Math.log((1 + Math.sin(rotB)) / (1 - Math.sin(rotB))) + this.y0;
  6599. p.x = this.R * rotI + this.x0;
  6600. return p;
  6601. }
  6602. function inverse$7(p) {
  6603. var Y = p.x - this.x0;
  6604. var X = p.y - this.y0;
  6605. var rotI = Y / this.R;
  6606. var rotB = 2 * (Math.atan(Math.exp(X / this.R)) - Math.PI / 4);
  6607. var b = Math.asin(Math.cos(this.b0) * Math.sin(rotB) + Math.sin(this.b0) * Math.cos(rotB) * Math.cos(rotI));
  6608. var I = Math.atan(Math.sin(rotI) / (Math.cos(this.b0) * Math.cos(rotI) - Math.sin(this.b0) * Math.tan(rotB)));
  6609. var lambda = this.lambda0 + I / this.alpha;
  6610. var S = 0;
  6611. var phy = b;
  6612. var prevPhy = -1000;
  6613. var iteration = 0;
  6614. while (Math.abs(phy - prevPhy) > 0.0000001) {
  6615. if (++iteration > 20) {
  6616. //...reportError("omercFwdInfinity");
  6617. return;
  6618. }
  6619. //S = Math.log(Math.tan(Math.PI / 4 + phy / 2));
  6620. S = 1 / this.alpha * (Math.log(Math.tan(Math.PI / 4 + b / 2)) - this.K) + this.e * Math.log(Math.tan(Math.PI / 4 + Math.asin(this.e * Math.sin(phy)) / 2));
  6621. prevPhy = phy;
  6622. phy = 2 * Math.atan(Math.exp(S)) - Math.PI / 2;
  6623. }
  6624. p.x = lambda;
  6625. p.y = phy;
  6626. return p;
  6627. }
  6628. var names$9 = ["somerc"];
  6629. var somerc = {
  6630. init: init$8,
  6631. forward: forward$7,
  6632. inverse: inverse$7,
  6633. names: names$9
  6634. };
  6635. var TOL = 1e-7;
  6636. function isTypeA(P) {
  6637. var typeAProjections = ['Hotine_Oblique_Mercator', 'Hotine_Oblique_Mercator_Azimuth_Natural_Origin'];
  6638. var projectionName = typeof P.PROJECTION === "object" ? Object.keys(P.PROJECTION)[0] : P.PROJECTION;
  6639. return 'no_uoff' in P || 'no_off' in P || typeAProjections.indexOf(projectionName) !== -1;
  6640. }
  6641. /* Initialize the Oblique Mercator projection
  6642. ------------------------------------------*/
  6643. function init$9() {
  6644. var con, com, cosph0, D, F, H, L, sinph0, p, J, gamma = 0,
  6645. gamma0, lamc = 0, lam1 = 0, lam2 = 0, phi1 = 0, phi2 = 0, alpha_c = 0;
  6646. // only Type A uses the no_off or no_uoff property
  6647. // https://github.com/OSGeo/proj.4/issues/104
  6648. this.no_off = isTypeA(this);
  6649. this.no_rot = 'no_rot' in this;
  6650. var alp = false;
  6651. if ("alpha" in this) {
  6652. alp = true;
  6653. }
  6654. var gam = false;
  6655. if ("rectified_grid_angle" in this) {
  6656. gam = true;
  6657. }
  6658. if (alp) {
  6659. alpha_c = this.alpha;
  6660. }
  6661. if (gam) {
  6662. gamma = (this.rectified_grid_angle * D2R);
  6663. }
  6664. if (alp || gam) {
  6665. lamc = this.longc;
  6666. } else {
  6667. lam1 = this.long1;
  6668. phi1 = this.lat1;
  6669. lam2 = this.long2;
  6670. phi2 = this.lat2;
  6671. if (Math.abs(phi1 - phi2) <= TOL || (con = Math.abs(phi1)) <= TOL ||
  6672. Math.abs(con - HALF_PI) <= TOL || Math.abs(Math.abs(this.lat0) - HALF_PI) <= TOL ||
  6673. Math.abs(Math.abs(phi2) - HALF_PI) <= TOL) {
  6674. throw new Error();
  6675. }
  6676. }
  6677. var one_es = 1.0 - this.es;
  6678. com = Math.sqrt(one_es);
  6679. if (Math.abs(this.lat0) > EPSLN) {
  6680. sinph0 = Math.sin(this.lat0);
  6681. cosph0 = Math.cos(this.lat0);
  6682. con = 1 - this.es * sinph0 * sinph0;
  6683. this.B = cosph0 * cosph0;
  6684. this.B = Math.sqrt(1 + this.es * this.B * this.B / one_es);
  6685. this.A = this.B * this.k0 * com / con;
  6686. D = this.B * com / (cosph0 * Math.sqrt(con));
  6687. F = D * D - 1;
  6688. if (F <= 0) {
  6689. F = 0;
  6690. } else {
  6691. F = Math.sqrt(F);
  6692. if (this.lat0 < 0) {
  6693. F = -F;
  6694. }
  6695. }
  6696. this.E = F += D;
  6697. this.E *= Math.pow(tsfnz(this.e, this.lat0, sinph0), this.B);
  6698. } else {
  6699. this.B = 1 / com;
  6700. this.A = this.k0;
  6701. this.E = D = F = 1;
  6702. }
  6703. if (alp || gam) {
  6704. if (alp) {
  6705. gamma0 = Math.asin(Math.sin(alpha_c) / D);
  6706. if (!gam) {
  6707. gamma = alpha_c;
  6708. }
  6709. } else {
  6710. gamma0 = gamma;
  6711. alpha_c = Math.asin(D * Math.sin(gamma0));
  6712. }
  6713. this.lam0 = lamc - Math.asin(0.5 * (F - 1 / F) * Math.tan(gamma0)) / this.B;
  6714. } else {
  6715. H = Math.pow(tsfnz(this.e, phi1, Math.sin(phi1)), this.B);
  6716. L = Math.pow(tsfnz(this.e, phi2, Math.sin(phi2)), this.B);
  6717. F = this.E / H;
  6718. p = (L - H) / (L + H);
  6719. J = this.E * this.E;
  6720. J = (J - L * H) / (J + L * H);
  6721. con = lam1 - lam2;
  6722. if (con < -Math.pi) {
  6723. lam2 -= TWO_PI;
  6724. } else if (con > Math.pi) {
  6725. lam2 += TWO_PI;
  6726. }
  6727. this.lam0 = adjust_lon(0.5 * (lam1 + lam2) - Math.atan(J * Math.tan(0.5 * this.B * (lam1 - lam2)) / p) / this.B);
  6728. gamma0 = Math.atan(2 * Math.sin(this.B * adjust_lon(lam1 - this.lam0)) / (F - 1 / F));
  6729. gamma = alpha_c = Math.asin(D * Math.sin(gamma0));
  6730. }
  6731. this.singam = Math.sin(gamma0);
  6732. this.cosgam = Math.cos(gamma0);
  6733. this.sinrot = Math.sin(gamma);
  6734. this.cosrot = Math.cos(gamma);
  6735. this.rB = 1 / this.B;
  6736. this.ArB = this.A * this.rB;
  6737. this.BrA = 1 / this.ArB;
  6738. if (this.no_off) {
  6739. this.u_0 = 0;
  6740. } else {
  6741. this.u_0 = Math.abs(this.ArB * Math.atan(Math.sqrt(D * D - 1) / Math.cos(alpha_c)));
  6742. if (this.lat0 < 0) {
  6743. this.u_0 = - this.u_0;
  6744. }
  6745. }
  6746. F = 0.5 * gamma0;
  6747. this.v_pole_n = this.ArB * Math.log(Math.tan(FORTPI - F));
  6748. this.v_pole_s = this.ArB * Math.log(Math.tan(FORTPI + F));
  6749. }
  6750. /* Oblique Mercator forward equations--mapping lat,long to x,y
  6751. ----------------------------------------------------------*/
  6752. function forward$8(p) {
  6753. var coords = {};
  6754. var S, T, U, V, W, temp, u, v;
  6755. p.x = p.x - this.lam0;
  6756. if (Math.abs(Math.abs(p.y) - HALF_PI) > EPSLN) {
  6757. W = this.E / Math.pow(tsfnz(this.e, p.y, Math.sin(p.y)), this.B);
  6758. temp = 1 / W;
  6759. S = 0.5 * (W - temp);
  6760. T = 0.5 * (W + temp);
  6761. V = Math.sin(this.B * p.x);
  6762. U = (S * this.singam - V * this.cosgam) / T;
  6763. if (Math.abs(Math.abs(U) - 1.0) < EPSLN) {
  6764. throw new Error();
  6765. }
  6766. v = 0.5 * this.ArB * Math.log((1 - U) / (1 + U));
  6767. temp = Math.cos(this.B * p.x);
  6768. if (Math.abs(temp) < TOL) {
  6769. u = this.A * p.x;
  6770. } else {
  6771. u = this.ArB * Math.atan2((S * this.cosgam + V * this.singam), temp);
  6772. }
  6773. } else {
  6774. v = p.y > 0 ? this.v_pole_n : this.v_pole_s;
  6775. u = this.ArB * p.y;
  6776. }
  6777. if (this.no_rot) {
  6778. coords.x = u;
  6779. coords.y = v;
  6780. } else {
  6781. u -= this.u_0;
  6782. coords.x = v * this.cosrot + u * this.sinrot;
  6783. coords.y = u * this.cosrot - v * this.sinrot;
  6784. }
  6785. coords.x = (this.a * coords.x + this.x0);
  6786. coords.y = (this.a * coords.y + this.y0);
  6787. return coords;
  6788. }
  6789. function inverse$8(p) {
  6790. var u, v, Qp, Sp, Tp, Vp, Up;
  6791. var coords = {};
  6792. p.x = (p.x - this.x0) * (1.0 / this.a);
  6793. p.y = (p.y - this.y0) * (1.0 / this.a);
  6794. if (this.no_rot) {
  6795. v = p.y;
  6796. u = p.x;
  6797. } else {
  6798. v = p.x * this.cosrot - p.y * this.sinrot;
  6799. u = p.y * this.cosrot + p.x * this.sinrot + this.u_0;
  6800. }
  6801. Qp = Math.exp(-this.BrA * v);
  6802. Sp = 0.5 * (Qp - 1 / Qp);
  6803. Tp = 0.5 * (Qp + 1 / Qp);
  6804. Vp = Math.sin(this.BrA * u);
  6805. Up = (Vp * this.cosgam + Sp * this.singam) / Tp;
  6806. if (Math.abs(Math.abs(Up) - 1) < EPSLN) {
  6807. coords.x = 0;
  6808. coords.y = Up < 0 ? -HALF_PI : HALF_PI;
  6809. } else {
  6810. coords.y = this.E / Math.sqrt((1 + Up) / (1 - Up));
  6811. coords.y = phi2z(this.e, Math.pow(coords.y, 1 / this.B));
  6812. if (coords.y === Infinity) {
  6813. throw new Error();
  6814. }
  6815. coords.x = -this.rB * Math.atan2((Sp * this.cosgam - Vp * this.singam), Math.cos(this.BrA * u));
  6816. }
  6817. coords.x += this.lam0;
  6818. return coords;
  6819. }
  6820. var names$10 = ["Hotine_Oblique_Mercator", "Hotine Oblique Mercator", "Hotine_Oblique_Mercator_Azimuth_Natural_Origin", "Hotine_Oblique_Mercator_Two_Point_Natural_Origin", "Hotine_Oblique_Mercator_Azimuth_Center", "Oblique_Mercator", "omerc"];
  6821. var omerc = {
  6822. init: init$9,
  6823. forward: forward$8,
  6824. inverse: inverse$8,
  6825. names: names$10
  6826. };
  6827. function init$10() {
  6828. //double lat0; /* the reference latitude */
  6829. //double long0; /* the reference longitude */
  6830. //double lat1; /* first standard parallel */
  6831. //double lat2; /* second standard parallel */
  6832. //double r_maj; /* major axis */
  6833. //double r_min; /* minor axis */
  6834. //double false_east; /* x offset in meters */
  6835. //double false_north; /* y offset in meters */
  6836. //the above value can be set with proj4.defs
  6837. //example: proj4.defs("EPSG:2154","+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs");
  6838. if (!this.lat2) {
  6839. this.lat2 = this.lat1;
  6840. } //if lat2 is not defined
  6841. if (!this.k0) {
  6842. this.k0 = 1;
  6843. }
  6844. this.x0 = this.x0 || 0;
  6845. this.y0 = this.y0 || 0;
  6846. // Standard Parallels cannot be equal and on opposite sides of the equator
  6847. if (Math.abs(this.lat1 + this.lat2) < EPSLN) {
  6848. return;
  6849. }
  6850. var temp = this.b / this.a;
  6851. this.e = Math.sqrt(1 - temp * temp);
  6852. var sin1 = Math.sin(this.lat1);
  6853. var cos1 = Math.cos(this.lat1);
  6854. var ms1 = msfnz(this.e, sin1, cos1);
  6855. var ts1 = tsfnz(this.e, this.lat1, sin1);
  6856. var sin2 = Math.sin(this.lat2);
  6857. var cos2 = Math.cos(this.lat2);
  6858. var ms2 = msfnz(this.e, sin2, cos2);
  6859. var ts2 = tsfnz(this.e, this.lat2, sin2);
  6860. var ts0 = tsfnz(this.e, this.lat0, Math.sin(this.lat0));
  6861. if (Math.abs(this.lat1 - this.lat2) > EPSLN) {
  6862. this.ns = Math.log(ms1 / ms2) / Math.log(ts1 / ts2);
  6863. }
  6864. else {
  6865. this.ns = sin1;
  6866. }
  6867. if (isNaN(this.ns)) {
  6868. this.ns = sin1;
  6869. }
  6870. this.f0 = ms1 / (this.ns * Math.pow(ts1, this.ns));
  6871. this.rh = this.a * this.f0 * Math.pow(ts0, this.ns);
  6872. if (!this.title) {
  6873. this.title = "Lambert Conformal Conic";
  6874. }
  6875. }
  6876. // Lambert Conformal conic forward equations--mapping lat,long to x,y
  6877. // -----------------------------------------------------------------
  6878. function forward$9(p) {
  6879. var lon = p.x;
  6880. var lat = p.y;
  6881. // singular cases :
  6882. if (Math.abs(2 * Math.abs(lat) - Math.PI) <= EPSLN) {
  6883. lat = sign(lat) * (HALF_PI - 2 * EPSLN);
  6884. }
  6885. var con = Math.abs(Math.abs(lat) - HALF_PI);
  6886. var ts, rh1;
  6887. if (con > EPSLN) {
  6888. ts = tsfnz(this.e, lat, Math.sin(lat));
  6889. rh1 = this.a * this.f0 * Math.pow(ts, this.ns);
  6890. }
  6891. else {
  6892. con = lat * this.ns;
  6893. if (con <= 0) {
  6894. return null;
  6895. }
  6896. rh1 = 0;
  6897. }
  6898. var theta = this.ns * adjust_lon(lon - this.long0);
  6899. p.x = this.k0 * (rh1 * Math.sin(theta)) + this.x0;
  6900. p.y = this.k0 * (this.rh - rh1 * Math.cos(theta)) + this.y0;
  6901. return p;
  6902. }
  6903. // Lambert Conformal Conic inverse equations--mapping x,y to lat/long
  6904. // -----------------------------------------------------------------
  6905. function inverse$9(p) {
  6906. var rh1, con, ts;
  6907. var lat, lon;
  6908. var x = (p.x - this.x0) / this.k0;
  6909. var y = (this.rh - (p.y - this.y0) / this.k0);
  6910. if (this.ns > 0) {
  6911. rh1 = Math.sqrt(x * x + y * y);
  6912. con = 1;
  6913. }
  6914. else {
  6915. rh1 = -Math.sqrt(x * x + y * y);
  6916. con = -1;
  6917. }
  6918. var theta = 0;
  6919. if (rh1 !== 0) {
  6920. theta = Math.atan2((con * x), (con * y));
  6921. }
  6922. if ((rh1 !== 0) || (this.ns > 0)) {
  6923. con = 1 / this.ns;
  6924. ts = Math.pow((rh1 / (this.a * this.f0)), con);
  6925. lat = phi2z(this.e, ts);
  6926. if (lat === -9999) {
  6927. return null;
  6928. }
  6929. }
  6930. else {
  6931. lat = -HALF_PI;
  6932. }
  6933. lon = adjust_lon(theta / this.ns + this.long0);
  6934. p.x = lon;
  6935. p.y = lat;
  6936. return p;
  6937. }
  6938. var names$11 = [
  6939. "Lambert Tangential Conformal Conic Projection",
  6940. "Lambert_Conformal_Conic",
  6941. "Lambert_Conformal_Conic_1SP",
  6942. "Lambert_Conformal_Conic_2SP",
  6943. "lcc"
  6944. ];
  6945. var lcc = {
  6946. init: init$10,
  6947. forward: forward$9,
  6948. inverse: inverse$9,
  6949. names: names$11
  6950. };
  6951. function init$11() {
  6952. this.a = 6377397.155;
  6953. this.es = 0.006674372230614;
  6954. this.e = Math.sqrt(this.es);
  6955. if (!this.lat0) {
  6956. this.lat0 = 0.863937979737193;
  6957. }
  6958. if (!this.long0) {
  6959. this.long0 = 0.7417649320975901 - 0.308341501185665;
  6960. }
  6961. /* if scale not set default to 0.9999 */
  6962. if (!this.k0) {
  6963. this.k0 = 0.9999;
  6964. }
  6965. this.s45 = 0.785398163397448; /* 45 */
  6966. this.s90 = 2 * this.s45;
  6967. this.fi0 = this.lat0;
  6968. this.e2 = this.es;
  6969. this.e = Math.sqrt(this.e2);
  6970. this.alfa = Math.sqrt(1 + (this.e2 * Math.pow(Math.cos(this.fi0), 4)) / (1 - this.e2));
  6971. this.uq = 1.04216856380474;
  6972. this.u0 = Math.asin(Math.sin(this.fi0) / this.alfa);
  6973. this.g = Math.pow((1 + this.e * Math.sin(this.fi0)) / (1 - this.e * Math.sin(this.fi0)), this.alfa * this.e / 2);
  6974. this.k = Math.tan(this.u0 / 2 + this.s45) / Math.pow(Math.tan(this.fi0 / 2 + this.s45), this.alfa) * this.g;
  6975. this.k1 = this.k0;
  6976. this.n0 = this.a * Math.sqrt(1 - this.e2) / (1 - this.e2 * Math.pow(Math.sin(this.fi0), 2));
  6977. this.s0 = 1.37008346281555;
  6978. this.n = Math.sin(this.s0);
  6979. this.ro0 = this.k1 * this.n0 / Math.tan(this.s0);
  6980. this.ad = this.s90 - this.uq;
  6981. }
  6982. /* ellipsoid */
  6983. /* calculate xy from lat/lon */
  6984. /* Constants, identical to inverse transform function */
  6985. function forward$10(p) {
  6986. var gfi, u, deltav, s, d, eps, ro;
  6987. var lon = p.x;
  6988. var lat = p.y;
  6989. var delta_lon = adjust_lon(lon - this.long0);
  6990. /* Transformation */
  6991. gfi = Math.pow(((1 + this.e * Math.sin(lat)) / (1 - this.e * Math.sin(lat))), (this.alfa * this.e / 2));
  6992. u = 2 * (Math.atan(this.k * Math.pow(Math.tan(lat / 2 + this.s45), this.alfa) / gfi) - this.s45);
  6993. deltav = -delta_lon * this.alfa;
  6994. s = Math.asin(Math.cos(this.ad) * Math.sin(u) + Math.sin(this.ad) * Math.cos(u) * Math.cos(deltav));
  6995. d = Math.asin(Math.cos(u) * Math.sin(deltav) / Math.cos(s));
  6996. eps = this.n * d;
  6997. ro = this.ro0 * Math.pow(Math.tan(this.s0 / 2 + this.s45), this.n) / Math.pow(Math.tan(s / 2 + this.s45), this.n);
  6998. p.y = ro * Math.cos(eps) / 1;
  6999. p.x = ro * Math.sin(eps) / 1;
  7000. if (!this.czech) {
  7001. p.y *= -1;
  7002. p.x *= -1;
  7003. }
  7004. return (p);
  7005. }
  7006. /* calculate lat/lon from xy */
  7007. function inverse$10(p) {
  7008. var u, deltav, s, d, eps, ro, fi1;
  7009. var ok;
  7010. /* Transformation */
  7011. /* revert y, x*/
  7012. var tmp = p.x;
  7013. p.x = p.y;
  7014. p.y = tmp;
  7015. if (!this.czech) {
  7016. p.y *= -1;
  7017. p.x *= -1;
  7018. }
  7019. ro = Math.sqrt(p.x * p.x + p.y * p.y);
  7020. eps = Math.atan2(p.y, p.x);
  7021. d = eps / Math.sin(this.s0);
  7022. s = 2 * (Math.atan(Math.pow(this.ro0 / ro, 1 / this.n) * Math.tan(this.s0 / 2 + this.s45)) - this.s45);
  7023. u = Math.asin(Math.cos(this.ad) * Math.sin(s) - Math.sin(this.ad) * Math.cos(s) * Math.cos(d));
  7024. deltav = Math.asin(Math.cos(s) * Math.sin(d) / Math.cos(u));
  7025. p.x = this.long0 - deltav / this.alfa;
  7026. fi1 = u;
  7027. ok = 0;
  7028. var iter = 0;
  7029. do {
  7030. p.y = 2 * (Math.atan(Math.pow(this.k, - 1 / this.alfa) * Math.pow(Math.tan(u / 2 + this.s45), 1 / this.alfa) * Math.pow((1 + this.e * Math.sin(fi1)) / (1 - this.e * Math.sin(fi1)), this.e / 2)) - this.s45);
  7031. if (Math.abs(fi1 - p.y) < 0.0000000001) {
  7032. ok = 1;
  7033. }
  7034. fi1 = p.y;
  7035. iter += 1;
  7036. } while (ok === 0 && iter < 15);
  7037. if (iter >= 15) {
  7038. return null;
  7039. }
  7040. return (p);
  7041. }
  7042. var names$12 = ["Krovak", "krovak"];
  7043. var krovak = {
  7044. init: init$11,
  7045. forward: forward$10,
  7046. inverse: inverse$10,
  7047. names: names$12
  7048. };
  7049. var mlfn = function (e0, e1, e2, e3, phi) {
  7050. return (e0 * phi - e1 * Math.sin(2 * phi) + e2 * Math.sin(4 * phi) - e3 * Math.sin(6 * phi));
  7051. };
  7052. var e0fn = function (x) {
  7053. return (1 - 0.25 * x * (1 + x / 16 * (3 + 1.25 * x)));
  7054. };
  7055. var e1fn = function (x) {
  7056. return (0.375 * x * (1 + 0.25 * x * (1 + 0.46875 * x)));
  7057. };
  7058. var e2fn = function (x) {
  7059. return (0.05859375 * x * x * (1 + 0.75 * x));
  7060. };
  7061. var e3fn = function (x) {
  7062. return (x * x * x * (35 / 3072));
  7063. };
  7064. var gN = function (a, e, sinphi) {
  7065. var temp = e * sinphi;
  7066. return a / Math.sqrt(1 - temp * temp);
  7067. };
  7068. var adjust_lat = function (x) {
  7069. return (Math.abs(x) < HALF_PI) ? x : (x - (sign(x) * Math.PI));
  7070. };
  7071. var imlfn = function (ml, e0, e1, e2, e3) {
  7072. var phi;
  7073. var dphi;
  7074. phi = ml / e0;
  7075. for (var i = 0; i < 15; i++) {
  7076. dphi = (ml - (e0 * phi - e1 * Math.sin(2 * phi) + e2 * Math.sin(4 * phi) - e3 * Math.sin(6 * phi))) / (e0 - 2 * e1 * Math.cos(2 * phi) + 4 * e2 * Math.cos(4 * phi) - 6 * e3 * Math.cos(6 * phi));
  7077. phi += dphi;
  7078. if (Math.abs(dphi) <= 0.0000000001) {
  7079. return phi;
  7080. }
  7081. }
  7082. //..reportError("IMLFN-CONV:Latitude failed to converge after 15 iterations");
  7083. return NaN;
  7084. };
  7085. function init$12() {
  7086. if (!this.sphere) {
  7087. this.e0 = e0fn(this.es);
  7088. this.e1 = e1fn(this.es);
  7089. this.e2 = e2fn(this.es);
  7090. this.e3 = e3fn(this.es);
  7091. this.ml0 = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, this.lat0);
  7092. }
  7093. }
  7094. /* Cassini forward equations--mapping lat,long to x,y
  7095. -----------------------------------------------------------------------*/
  7096. function forward$11(p) {
  7097. /* Forward equations
  7098. -----------------*/
  7099. var x, y;
  7100. var lam = p.x;
  7101. var phi = p.y;
  7102. lam = adjust_lon(lam - this.long0);
  7103. if (this.sphere) {
  7104. x = this.a * Math.asin(Math.cos(phi) * Math.sin(lam));
  7105. y = this.a * (Math.atan2(Math.tan(phi), Math.cos(lam)) - this.lat0);
  7106. }
  7107. else {
  7108. //ellipsoid
  7109. var sinphi = Math.sin(phi);
  7110. var cosphi = Math.cos(phi);
  7111. var nl = gN(this.a, this.e, sinphi);
  7112. var tl = Math.tan(phi) * Math.tan(phi);
  7113. var al = lam * Math.cos(phi);
  7114. var asq = al * al;
  7115. var cl = this.es * cosphi * cosphi / (1 - this.es);
  7116. var ml = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, phi);
  7117. x = nl * al * (1 - asq * tl * (1 / 6 - (8 - tl + 8 * cl) * asq / 120));
  7118. y = ml - this.ml0 + nl * sinphi / cosphi * asq * (0.5 + (5 - tl + 6 * cl) * asq / 24);
  7119. }
  7120. p.x = x + this.x0;
  7121. p.y = y + this.y0;
  7122. return p;
  7123. }
  7124. /* Inverse equations
  7125. -----------------*/
  7126. function inverse$11(p) {
  7127. p.x -= this.x0;
  7128. p.y -= this.y0;
  7129. var x = p.x / this.a;
  7130. var y = p.y / this.a;
  7131. var phi, lam;
  7132. if (this.sphere) {
  7133. var dd = y + this.lat0;
  7134. phi = Math.asin(Math.sin(dd) * Math.cos(x));
  7135. lam = Math.atan2(Math.tan(x), Math.cos(dd));
  7136. }
  7137. else {
  7138. /* ellipsoid */
  7139. var ml1 = this.ml0 / this.a + y;
  7140. var phi1 = imlfn(ml1, this.e0, this.e1, this.e2, this.e3);
  7141. if (Math.abs(Math.abs(phi1) - HALF_PI) <= EPSLN) {
  7142. p.x = this.long0;
  7143. p.y = HALF_PI;
  7144. if (y < 0) {
  7145. p.y *= -1;
  7146. }
  7147. return p;
  7148. }
  7149. var nl1 = gN(this.a, this.e, Math.sin(phi1));
  7150. var rl1 = nl1 * nl1 * nl1 / this.a / this.a * (1 - this.es);
  7151. var tl1 = Math.pow(Math.tan(phi1), 2);
  7152. var dl = x * this.a / nl1;
  7153. var dsq = dl * dl;
  7154. phi = phi1 - nl1 * Math.tan(phi1) / rl1 * dl * dl * (0.5 - (1 + 3 * tl1) * dl * dl / 24);
  7155. lam = dl * (1 - dsq * (tl1 / 3 + (1 + 3 * tl1) * tl1 * dsq / 15)) / Math.cos(phi1);
  7156. }
  7157. p.x = adjust_lon(lam + this.long0);
  7158. p.y = adjust_lat(phi);
  7159. return p;
  7160. }
  7161. var names$13 = ["Cassini", "Cassini_Soldner", "cass"];
  7162. var cass = {
  7163. init: init$12,
  7164. forward: forward$11,
  7165. inverse: inverse$11,
  7166. names: names$13
  7167. };
  7168. var qsfnz = function (eccent, sinphi) {
  7169. var con;
  7170. if (eccent > 1.0e-7) {
  7171. con = eccent * sinphi;
  7172. return ((1 - eccent * eccent) * (sinphi / (1 - con * con) - (0.5 / eccent) * Math.log((1 - con) / (1 + con))));
  7173. }
  7174. else {
  7175. return (2 * sinphi);
  7176. }
  7177. };
  7178. /*
  7179. reference
  7180. "New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
  7181. The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
  7182. */
  7183. var S_POLE = 1;
  7184. var N_POLE = 2;
  7185. var EQUIT = 3;
  7186. var OBLIQ = 4;
  7187. /* Initialize the Lambert Azimuthal Equal Area projection
  7188. ------------------------------------------------------*/
  7189. function init$13() {
  7190. var t = Math.abs(this.lat0);
  7191. if (Math.abs(t - HALF_PI) < EPSLN) {
  7192. this.mode = this.lat0 < 0 ? this.S_POLE : this.N_POLE;
  7193. }
  7194. else if (Math.abs(t) < EPSLN) {
  7195. this.mode = this.EQUIT;
  7196. }
  7197. else {
  7198. this.mode = this.OBLIQ;
  7199. }
  7200. if (this.es > 0) {
  7201. var sinphi;
  7202. this.qp = qsfnz(this.e, 1);
  7203. this.mmf = 0.5 / (1 - this.es);
  7204. this.apa = authset(this.es);
  7205. switch (this.mode) {
  7206. case this.N_POLE:
  7207. this.dd = 1;
  7208. break;
  7209. case this.S_POLE:
  7210. this.dd = 1;
  7211. break;
  7212. case this.EQUIT:
  7213. this.rq = Math.sqrt(0.5 * this.qp);
  7214. this.dd = 1 / this.rq;
  7215. this.xmf = 1;
  7216. this.ymf = 0.5 * this.qp;
  7217. break;
  7218. case this.OBLIQ:
  7219. this.rq = Math.sqrt(0.5 * this.qp);
  7220. sinphi = Math.sin(this.lat0);
  7221. this.sinb1 = qsfnz(this.e, sinphi) / this.qp;
  7222. this.cosb1 = Math.sqrt(1 - this.sinb1 * this.sinb1);
  7223. this.dd = Math.cos(this.lat0) / (Math.sqrt(1 - this.es * sinphi * sinphi) * this.rq * this.cosb1);
  7224. this.ymf = (this.xmf = this.rq) / this.dd;
  7225. this.xmf *= this.dd;
  7226. break;
  7227. }
  7228. }
  7229. else {
  7230. if (this.mode === this.OBLIQ) {
  7231. this.sinph0 = Math.sin(this.lat0);
  7232. this.cosph0 = Math.cos(this.lat0);
  7233. }
  7234. }
  7235. }
  7236. /* Lambert Azimuthal Equal Area forward equations--mapping lat,long to x,y
  7237. -----------------------------------------------------------------------*/
  7238. function forward$12(p) {
  7239. /* Forward equations
  7240. -----------------*/
  7241. var x, y, coslam, sinlam, sinphi, q, sinb, cosb, b, cosphi;
  7242. var lam = p.x;
  7243. var phi = p.y;
  7244. lam = adjust_lon(lam - this.long0);
  7245. if (this.sphere) {
  7246. sinphi = Math.sin(phi);
  7247. cosphi = Math.cos(phi);
  7248. coslam = Math.cos(lam);
  7249. if (this.mode === this.OBLIQ || this.mode === this.EQUIT) {
  7250. y = (this.mode === this.EQUIT) ? 1 + cosphi * coslam : 1 + this.sinph0 * sinphi + this.cosph0 * cosphi * coslam;
  7251. if (y <= EPSLN) {
  7252. return null;
  7253. }
  7254. y = Math.sqrt(2 / y);
  7255. x = y * cosphi * Math.sin(lam);
  7256. y *= (this.mode === this.EQUIT) ? sinphi : this.cosph0 * sinphi - this.sinph0 * cosphi * coslam;
  7257. }
  7258. else if (this.mode === this.N_POLE || this.mode === this.S_POLE) {
  7259. if (this.mode === this.N_POLE) {
  7260. coslam = -coslam;
  7261. }
  7262. if (Math.abs(phi + this.lat0) < EPSLN) {
  7263. return null;
  7264. }
  7265. y = FORTPI - phi * 0.5;
  7266. y = 2 * ((this.mode === this.S_POLE) ? Math.cos(y) : Math.sin(y));
  7267. x = y * Math.sin(lam);
  7268. y *= coslam;
  7269. }
  7270. }
  7271. else {
  7272. sinb = 0;
  7273. cosb = 0;
  7274. b = 0;
  7275. coslam = Math.cos(lam);
  7276. sinlam = Math.sin(lam);
  7277. sinphi = Math.sin(phi);
  7278. q = qsfnz(this.e, sinphi);
  7279. if (this.mode === this.OBLIQ || this.mode === this.EQUIT) {
  7280. sinb = q / this.qp;
  7281. cosb = Math.sqrt(1 - sinb * sinb);
  7282. }
  7283. switch (this.mode) {
  7284. case this.OBLIQ:
  7285. b = 1 + this.sinb1 * sinb + this.cosb1 * cosb * coslam;
  7286. break;
  7287. case this.EQUIT:
  7288. b = 1 + cosb * coslam;
  7289. break;
  7290. case this.N_POLE:
  7291. b = HALF_PI + phi;
  7292. q = this.qp - q;
  7293. break;
  7294. case this.S_POLE:
  7295. b = phi - HALF_PI;
  7296. q = this.qp + q;
  7297. break;
  7298. }
  7299. if (Math.abs(b) < EPSLN) {
  7300. return null;
  7301. }
  7302. switch (this.mode) {
  7303. case this.OBLIQ:
  7304. case this.EQUIT:
  7305. b = Math.sqrt(2 / b);
  7306. if (this.mode === this.OBLIQ) {
  7307. y = this.ymf * b * (this.cosb1 * sinb - this.sinb1 * cosb * coslam);
  7308. }
  7309. else {
  7310. y = (b = Math.sqrt(2 / (1 + cosb * coslam))) * sinb * this.ymf;
  7311. }
  7312. x = this.xmf * b * cosb * sinlam;
  7313. break;
  7314. case this.N_POLE:
  7315. case this.S_POLE:
  7316. if (q >= 0) {
  7317. x = (b = Math.sqrt(q)) * sinlam;
  7318. y = coslam * ((this.mode === this.S_POLE) ? b : -b);
  7319. }
  7320. else {
  7321. x = y = 0;
  7322. }
  7323. break;
  7324. }
  7325. }
  7326. p.x = this.a * x + this.x0;
  7327. p.y = this.a * y + this.y0;
  7328. return p;
  7329. }
  7330. /* Inverse equations
  7331. -----------------*/
  7332. function inverse$12(p) {
  7333. p.x -= this.x0;
  7334. p.y -= this.y0;
  7335. var x = p.x / this.a;
  7336. var y = p.y / this.a;
  7337. var lam, phi, cCe, sCe, q, rho, ab;
  7338. if (this.sphere) {
  7339. var cosz = 0,
  7340. rh, sinz = 0;
  7341. rh = Math.sqrt(x * x + y * y);
  7342. phi = rh * 0.5;
  7343. if (phi > 1) {
  7344. return null;
  7345. }
  7346. phi = 2 * Math.asin(phi);
  7347. if (this.mode === this.OBLIQ || this.mode === this.EQUIT) {
  7348. sinz = Math.sin(phi);
  7349. cosz = Math.cos(phi);
  7350. }
  7351. switch (this.mode) {
  7352. case this.EQUIT:
  7353. phi = (Math.abs(rh) <= EPSLN) ? 0 : Math.asin(y * sinz / rh);
  7354. x *= sinz;
  7355. y = cosz * rh;
  7356. break;
  7357. case this.OBLIQ:
  7358. phi = (Math.abs(rh) <= EPSLN) ? this.lat0 : Math.asin(cosz * this.sinph0 + y * sinz * this.cosph0 / rh);
  7359. x *= sinz * this.cosph0;
  7360. y = (cosz - Math.sin(phi) * this.sinph0) * rh;
  7361. break;
  7362. case this.N_POLE:
  7363. y = -y;
  7364. phi = HALF_PI - phi;
  7365. break;
  7366. case this.S_POLE:
  7367. phi -= HALF_PI;
  7368. break;
  7369. }
  7370. lam = (y === 0 && (this.mode === this.EQUIT || this.mode === this.OBLIQ)) ? 0 : Math.atan2(x, y);
  7371. }
  7372. else {
  7373. ab = 0;
  7374. if (this.mode === this.OBLIQ || this.mode === this.EQUIT) {
  7375. x /= this.dd;
  7376. y *= this.dd;
  7377. rho = Math.sqrt(x * x + y * y);
  7378. if (rho < EPSLN) {
  7379. p.x = this.long0;
  7380. p.y = this.lat0;
  7381. return p;
  7382. }
  7383. sCe = 2 * Math.asin(0.5 * rho / this.rq);
  7384. cCe = Math.cos(sCe);
  7385. x *= (sCe = Math.sin(sCe));
  7386. if (this.mode === this.OBLIQ) {
  7387. ab = cCe * this.sinb1 + y * sCe * this.cosb1 / rho;
  7388. q = this.qp * ab;
  7389. y = rho * this.cosb1 * cCe - y * this.sinb1 * sCe;
  7390. }
  7391. else {
  7392. ab = y * sCe / rho;
  7393. q = this.qp * ab;
  7394. y = rho * cCe;
  7395. }
  7396. }
  7397. else if (this.mode === this.N_POLE || this.mode === this.S_POLE) {
  7398. if (this.mode === this.N_POLE) {
  7399. y = -y;
  7400. }
  7401. q = (x * x + y * y);
  7402. if (!q) {
  7403. p.x = this.long0;
  7404. p.y = this.lat0;
  7405. return p;
  7406. }
  7407. ab = 1 - q / this.qp;
  7408. if (this.mode === this.S_POLE) {
  7409. ab = -ab;
  7410. }
  7411. }
  7412. lam = Math.atan2(x, y);
  7413. phi = authlat(Math.asin(ab), this.apa);
  7414. }
  7415. p.x = adjust_lon(this.long0 + lam);
  7416. p.y = phi;
  7417. return p;
  7418. }
  7419. /* determine latitude from authalic latitude */
  7420. var P00 = 0.33333333333333333333;
  7421. var P01 = 0.17222222222222222222;
  7422. var P02 = 0.10257936507936507936;
  7423. var P10 = 0.06388888888888888888;
  7424. var P11 = 0.06640211640211640211;
  7425. var P20 = 0.01641501294219154443;
  7426. function authset(es) {
  7427. var t;
  7428. var APA = [];
  7429. APA[0] = es * P00;
  7430. t = es * es;
  7431. APA[0] += t * P01;
  7432. APA[1] = t * P10;
  7433. t *= es;
  7434. APA[0] += t * P02;
  7435. APA[1] += t * P11;
  7436. APA[2] = t * P20;
  7437. return APA;
  7438. }
  7439. function authlat(beta, APA) {
  7440. var t = beta + beta;
  7441. return (beta + APA[0] * Math.sin(t) + APA[1] * Math.sin(t + t) + APA[2] * Math.sin(t + t + t));
  7442. }
  7443. var names$14 = ["Lambert Azimuthal Equal Area", "Lambert_Azimuthal_Equal_Area", "laea"];
  7444. var laea = {
  7445. init: init$13,
  7446. forward: forward$12,
  7447. inverse: inverse$12,
  7448. names: names$14,
  7449. S_POLE: S_POLE,
  7450. N_POLE: N_POLE,
  7451. EQUIT: EQUIT,
  7452. OBLIQ: OBLIQ
  7453. };
  7454. var asinz = function (x) {
  7455. if (Math.abs(x) > 1) {
  7456. x = (x > 1) ? 1 : -1;
  7457. }
  7458. return Math.asin(x);
  7459. };
  7460. function init$14() {
  7461. if (Math.abs(this.lat1 + this.lat2) < EPSLN) {
  7462. return;
  7463. }
  7464. this.temp = this.b / this.a;
  7465. this.es = 1 - Math.pow(this.temp, 2);
  7466. this.e3 = Math.sqrt(this.es);
  7467. this.sin_po = Math.sin(this.lat1);
  7468. this.cos_po = Math.cos(this.lat1);
  7469. this.t1 = this.sin_po;
  7470. this.con = this.sin_po;
  7471. this.ms1 = msfnz(this.e3, this.sin_po, this.cos_po);
  7472. this.qs1 = qsfnz(this.e3, this.sin_po, this.cos_po);
  7473. this.sin_po = Math.sin(this.lat2);
  7474. this.cos_po = Math.cos(this.lat2);
  7475. this.t2 = this.sin_po;
  7476. this.ms2 = msfnz(this.e3, this.sin_po, this.cos_po);
  7477. this.qs2 = qsfnz(this.e3, this.sin_po, this.cos_po);
  7478. this.sin_po = Math.sin(this.lat0);
  7479. this.cos_po = Math.cos(this.lat0);
  7480. this.t3 = this.sin_po;
  7481. this.qs0 = qsfnz(this.e3, this.sin_po, this.cos_po);
  7482. if (Math.abs(this.lat1 - this.lat2) > EPSLN) {
  7483. this.ns0 = (this.ms1 * this.ms1 - this.ms2 * this.ms2) / (this.qs2 - this.qs1);
  7484. }
  7485. else {
  7486. this.ns0 = this.con;
  7487. }
  7488. this.c = this.ms1 * this.ms1 + this.ns0 * this.qs1;
  7489. this.rh = this.a * Math.sqrt(this.c - this.ns0 * this.qs0) / this.ns0;
  7490. }
  7491. /* Albers Conical Equal Area forward equations--mapping lat,long to x,y
  7492. -------------------------------------------------------------------*/
  7493. function forward$13(p) {
  7494. var lon = p.x;
  7495. var lat = p.y;
  7496. this.sin_phi = Math.sin(lat);
  7497. this.cos_phi = Math.cos(lat);
  7498. var qs = qsfnz(this.e3, this.sin_phi, this.cos_phi);
  7499. var rh1 = this.a * Math.sqrt(this.c - this.ns0 * qs) / this.ns0;
  7500. var theta = this.ns0 * adjust_lon(lon - this.long0);
  7501. var x = rh1 * Math.sin(theta) + this.x0;
  7502. var y = this.rh - rh1 * Math.cos(theta) + this.y0;
  7503. p.x = x;
  7504. p.y = y;
  7505. return p;
  7506. }
  7507. function inverse$13(p) {
  7508. var rh1, qs, con, theta, lon, lat;
  7509. p.x -= this.x0;
  7510. p.y = this.rh - p.y + this.y0;
  7511. if (this.ns0 >= 0) {
  7512. rh1 = Math.sqrt(p.x * p.x + p.y * p.y);
  7513. con = 1;
  7514. }
  7515. else {
  7516. rh1 = -Math.sqrt(p.x * p.x + p.y * p.y);
  7517. con = -1;
  7518. }
  7519. theta = 0;
  7520. if (rh1 !== 0) {
  7521. theta = Math.atan2(con * p.x, con * p.y);
  7522. }
  7523. con = rh1 * this.ns0 / this.a;
  7524. if (this.sphere) {
  7525. lat = Math.asin((this.c - con * con) / (2 * this.ns0));
  7526. }
  7527. else {
  7528. qs = (this.c - con * con) / this.ns0;
  7529. lat = this.phi1z(this.e3, qs);
  7530. }
  7531. lon = adjust_lon(theta / this.ns0 + this.long0);
  7532. p.x = lon;
  7533. p.y = lat;
  7534. return p;
  7535. }
  7536. /* Function to compute phi1, the latitude for the inverse of the
  7537. Albers Conical Equal-Area projection.
  7538. -------------------------------------------*/
  7539. function phi1z(eccent, qs) {
  7540. var sinphi, cosphi, con, com, dphi;
  7541. var phi = asinz(0.5 * qs);
  7542. if (eccent < EPSLN) {
  7543. return phi;
  7544. }
  7545. var eccnts = eccent * eccent;
  7546. for (var i = 1; i <= 25; i++) {
  7547. sinphi = Math.sin(phi);
  7548. cosphi = Math.cos(phi);
  7549. con = eccent * sinphi;
  7550. com = 1 - con * con;
  7551. dphi = 0.5 * com * com / cosphi * (qs / (1 - eccnts) - sinphi / com + 0.5 / eccent * Math.log((1 - con) / (1 + con)));
  7552. phi = phi + dphi;
  7553. if (Math.abs(dphi) <= 1e-7) {
  7554. return phi;
  7555. }
  7556. }
  7557. return null;
  7558. }
  7559. var names$15 = ["Albers_Conic_Equal_Area", "Albers", "aea"];
  7560. var aea = {
  7561. init: init$14,
  7562. forward: forward$13,
  7563. inverse: inverse$13,
  7564. names: names$15,
  7565. phi1z: phi1z
  7566. };
  7567. /*
  7568. reference:
  7569. Wolfram Mathworld "Gnomonic Projection"
  7570. http://mathworld.wolfram.com/GnomonicProjection.html
  7571. Accessed: 12th November 2009
  7572. */
  7573. function init$15() {
  7574. /* Place parameters in static storage for common use
  7575. -------------------------------------------------*/
  7576. this.sin_p14 = Math.sin(this.lat0);
  7577. this.cos_p14 = Math.cos(this.lat0);
  7578. // Approximation for projecting points to the horizon (infinity)
  7579. this.infinity_dist = 1000 * this.a;
  7580. this.rc = 1;
  7581. }
  7582. /* Gnomonic forward equations--mapping lat,long to x,y
  7583. ---------------------------------------------------*/
  7584. function forward$14(p) {
  7585. var sinphi, cosphi; /* sin and cos value */
  7586. var dlon; /* delta longitude value */
  7587. var coslon; /* cos of longitude */
  7588. var ksp; /* scale factor */
  7589. var g;
  7590. var x, y;
  7591. var lon = p.x;
  7592. var lat = p.y;
  7593. /* Forward equations
  7594. -----------------*/
  7595. dlon = adjust_lon(lon - this.long0);
  7596. sinphi = Math.sin(lat);
  7597. cosphi = Math.cos(lat);
  7598. coslon = Math.cos(dlon);
  7599. g = this.sin_p14 * sinphi + this.cos_p14 * cosphi * coslon;
  7600. ksp = 1;
  7601. if ((g > 0) || (Math.abs(g) <= EPSLN)) {
  7602. x = this.x0 + this.a * ksp * cosphi * Math.sin(dlon) / g;
  7603. y = this.y0 + this.a * ksp * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon) / g;
  7604. }
  7605. else {
  7606. // Point is in the opposing hemisphere and is unprojectable
  7607. // We still need to return a reasonable point, so we project
  7608. // to infinity, on a bearing
  7609. // equivalent to the northern hemisphere equivalent
  7610. // This is a reasonable approximation for short shapes and lines that
  7611. // straddle the horizon.
  7612. x = this.x0 + this.infinity_dist * cosphi * Math.sin(dlon);
  7613. y = this.y0 + this.infinity_dist * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon);
  7614. }
  7615. p.x = x;
  7616. p.y = y;
  7617. return p;
  7618. }
  7619. function inverse$14(p) {
  7620. var rh; /* Rho */
  7621. var sinc, cosc;
  7622. var c;
  7623. var lon, lat;
  7624. /* Inverse equations
  7625. -----------------*/
  7626. p.x = (p.x - this.x0) / this.a;
  7627. p.y = (p.y - this.y0) / this.a;
  7628. p.x /= this.k0;
  7629. p.y /= this.k0;
  7630. if ((rh = Math.sqrt(p.x * p.x + p.y * p.y))) {
  7631. c = Math.atan2(rh, this.rc);
  7632. sinc = Math.sin(c);
  7633. cosc = Math.cos(c);
  7634. lat = asinz(cosc * this.sin_p14 + (p.y * sinc * this.cos_p14) / rh);
  7635. lon = Math.atan2(p.x * sinc, rh * this.cos_p14 * cosc - p.y * this.sin_p14 * sinc);
  7636. lon = adjust_lon(this.long0 + lon);
  7637. }
  7638. else {
  7639. lat = this.phic0;
  7640. lon = 0;
  7641. }
  7642. p.x = lon;
  7643. p.y = lat;
  7644. return p;
  7645. }
  7646. var names$16 = ["gnom"];
  7647. var gnom = {
  7648. init: init$15,
  7649. forward: forward$14,
  7650. inverse: inverse$14,
  7651. names: names$16
  7652. };
  7653. var iqsfnz = function (eccent, q) {
  7654. var temp = 1 - (1 - eccent * eccent) / (2 * eccent) * Math.log((1 - eccent) / (1 + eccent));
  7655. if (Math.abs(Math.abs(q) - temp) < 1.0E-6) {
  7656. if (q < 0) {
  7657. return (-1 * HALF_PI);
  7658. }
  7659. else {
  7660. return HALF_PI;
  7661. }
  7662. }
  7663. //var phi = 0.5* q/(1-eccent*eccent);
  7664. var phi = Math.asin(0.5 * q);
  7665. var dphi;
  7666. var sin_phi;
  7667. var cos_phi;
  7668. var con;
  7669. for (var i = 0; i < 30; i++) {
  7670. sin_phi = Math.sin(phi);
  7671. cos_phi = Math.cos(phi);
  7672. con = eccent * sin_phi;
  7673. dphi = Math.pow(1 - con * con, 2) / (2 * cos_phi) * (q / (1 - eccent * eccent) - sin_phi / (1 - con * con) + 0.5 / eccent * Math.log((1 - con) / (1 + con)));
  7674. phi += dphi;
  7675. if (Math.abs(dphi) <= 0.0000000001) {
  7676. return phi;
  7677. }
  7678. }
  7679. //console.log("IQSFN-CONV:Latitude failed to converge after 30 iterations");
  7680. return NaN;
  7681. };
  7682. /*
  7683. reference:
  7684. "Cartographic Projection Procedures for the UNIX Environment-
  7685. A User's Manual" by Gerald I. Evenden,
  7686. USGS Open File Report 90-284and Release 4 Interim Reports (2003)
  7687. */
  7688. function init$16() {
  7689. //no-op
  7690. if (!this.sphere) {
  7691. this.k0 = msfnz(this.e, Math.sin(this.lat_ts), Math.cos(this.lat_ts));
  7692. }
  7693. }
  7694. /* Cylindrical Equal Area forward equations--mapping lat,long to x,y
  7695. ------------------------------------------------------------*/
  7696. function forward$15(p) {
  7697. var lon = p.x;
  7698. var lat = p.y;
  7699. var x, y;
  7700. /* Forward equations
  7701. -----------------*/
  7702. var dlon = adjust_lon(lon - this.long0);
  7703. if (this.sphere) {
  7704. x = this.x0 + this.a * dlon * Math.cos(this.lat_ts);
  7705. y = this.y0 + this.a * Math.sin(lat) / Math.cos(this.lat_ts);
  7706. }
  7707. else {
  7708. var qs = qsfnz(this.e, Math.sin(lat));
  7709. x = this.x0 + this.a * this.k0 * dlon;
  7710. y = this.y0 + this.a * qs * 0.5 / this.k0;
  7711. }
  7712. p.x = x;
  7713. p.y = y;
  7714. return p;
  7715. }
  7716. /* Cylindrical Equal Area inverse equations--mapping x,y to lat/long
  7717. ------------------------------------------------------------*/
  7718. function inverse$15(p) {
  7719. p.x -= this.x0;
  7720. p.y -= this.y0;
  7721. var lon, lat;
  7722. if (this.sphere) {
  7723. lon = adjust_lon(this.long0 + (p.x / this.a) / Math.cos(this.lat_ts));
  7724. lat = Math.asin((p.y / this.a) * Math.cos(this.lat_ts));
  7725. }
  7726. else {
  7727. lat = iqsfnz(this.e, 2 * p.y * this.k0 / this.a);
  7728. lon = adjust_lon(this.long0 + p.x / (this.a * this.k0));
  7729. }
  7730. p.x = lon;
  7731. p.y = lat;
  7732. return p;
  7733. }
  7734. var names$17 = ["cea"];
  7735. var cea = {
  7736. init: init$16,
  7737. forward: forward$15,
  7738. inverse: inverse$15,
  7739. names: names$17
  7740. };
  7741. function init$17() {
  7742. this.x0 = this.x0 || 0;
  7743. this.y0 = this.y0 || 0;
  7744. this.lat0 = this.lat0 || 0;
  7745. this.long0 = this.long0 || 0;
  7746. this.lat_ts = this.lat_ts || 0;
  7747. this.title = this.title || "Equidistant Cylindrical (Plate Carre)";
  7748. this.rc = Math.cos(this.lat_ts);
  7749. }
  7750. // forward equations--mapping lat,long to x,y
  7751. // -----------------------------------------------------------------
  7752. function forward$16(p) {
  7753. var lon = p.x;
  7754. var lat = p.y;
  7755. var dlon = adjust_lon(lon - this.long0);
  7756. var dlat = adjust_lat(lat - this.lat0);
  7757. p.x = this.x0 + (this.a * dlon * this.rc);
  7758. p.y = this.y0 + (this.a * dlat);
  7759. return p;
  7760. }
  7761. // inverse equations--mapping x,y to lat/long
  7762. // -----------------------------------------------------------------
  7763. function inverse$16(p) {
  7764. var x = p.x;
  7765. var y = p.y;
  7766. p.x = adjust_lon(this.long0 + ((x - this.x0) / (this.a * this.rc)));
  7767. p.y = adjust_lat(this.lat0 + ((y - this.y0) / (this.a)));
  7768. return p;
  7769. }
  7770. var names$18 = ["Equirectangular", "Equidistant_Cylindrical", "eqc"];
  7771. var eqc = {
  7772. init: init$17,
  7773. forward: forward$16,
  7774. inverse: inverse$16,
  7775. names: names$18
  7776. };
  7777. var MAX_ITER$2 = 20;
  7778. function init$18() {
  7779. /* Place parameters in static storage for common use
  7780. -------------------------------------------------*/
  7781. this.temp = this.b / this.a;
  7782. this.es = 1 - Math.pow(this.temp, 2); // devait etre dans tmerc.js mais n y est pas donc je commente sinon retour de valeurs nulles
  7783. this.e = Math.sqrt(this.es);
  7784. this.e0 = e0fn(this.es);
  7785. this.e1 = e1fn(this.es);
  7786. this.e2 = e2fn(this.es);
  7787. this.e3 = e3fn(this.es);
  7788. this.ml0 = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, this.lat0); //si que des zeros le calcul ne se fait pas
  7789. }
  7790. /* Polyconic forward equations--mapping lat,long to x,y
  7791. ---------------------------------------------------*/
  7792. function forward$17(p) {
  7793. var lon = p.x;
  7794. var lat = p.y;
  7795. var x, y, el;
  7796. var dlon = adjust_lon(lon - this.long0);
  7797. el = dlon * Math.sin(lat);
  7798. if (this.sphere) {
  7799. if (Math.abs(lat) <= EPSLN) {
  7800. x = this.a * dlon;
  7801. y = -1 * this.a * this.lat0;
  7802. }
  7803. else {
  7804. x = this.a * Math.sin(el) / Math.tan(lat);
  7805. y = this.a * (adjust_lat(lat - this.lat0) + (1 - Math.cos(el)) / Math.tan(lat));
  7806. }
  7807. }
  7808. else {
  7809. if (Math.abs(lat) <= EPSLN) {
  7810. x = this.a * dlon;
  7811. y = -1 * this.ml0;
  7812. }
  7813. else {
  7814. var nl = gN(this.a, this.e, Math.sin(lat)) / Math.tan(lat);
  7815. x = nl * Math.sin(el);
  7816. y = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, lat) - this.ml0 + nl * (1 - Math.cos(el));
  7817. }
  7818. }
  7819. p.x = x + this.x0;
  7820. p.y = y + this.y0;
  7821. return p;
  7822. }
  7823. /* Inverse equations
  7824. -----------------*/
  7825. function inverse$17(p) {
  7826. var lon, lat, x, y, i;
  7827. var al, bl;
  7828. var phi, dphi;
  7829. x = p.x - this.x0;
  7830. y = p.y - this.y0;
  7831. if (this.sphere) {
  7832. if (Math.abs(y + this.a * this.lat0) <= EPSLN) {
  7833. lon = adjust_lon(x / this.a + this.long0);
  7834. lat = 0;
  7835. }
  7836. else {
  7837. al = this.lat0 + y / this.a;
  7838. bl = x * x / this.a / this.a + al * al;
  7839. phi = al;
  7840. var tanphi;
  7841. for (i = MAX_ITER$2; i; --i) {
  7842. tanphi = Math.tan(phi);
  7843. dphi = -1 * (al * (phi * tanphi + 1) - phi - 0.5 * (phi * phi + bl) * tanphi) / ((phi - al) / tanphi - 1);
  7844. phi += dphi;
  7845. if (Math.abs(dphi) <= EPSLN) {
  7846. lat = phi;
  7847. break;
  7848. }
  7849. }
  7850. lon = adjust_lon(this.long0 + (Math.asin(x * Math.tan(phi) / this.a)) / Math.sin(lat));
  7851. }
  7852. }
  7853. else {
  7854. if (Math.abs(y + this.ml0) <= EPSLN) {
  7855. lat = 0;
  7856. lon = adjust_lon(this.long0 + x / this.a);
  7857. }
  7858. else {
  7859. al = (this.ml0 + y) / this.a;
  7860. bl = x * x / this.a / this.a + al * al;
  7861. phi = al;
  7862. var cl, mln, mlnp, ma;
  7863. var con;
  7864. for (i = MAX_ITER$2; i; --i) {
  7865. con = this.e * Math.sin(phi);
  7866. cl = Math.sqrt(1 - con * con) * Math.tan(phi);
  7867. mln = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, phi);
  7868. mlnp = this.e0 - 2 * this.e1 * Math.cos(2 * phi) + 4 * this.e2 * Math.cos(4 * phi) - 6 * this.e3 * Math.cos(6 * phi);
  7869. ma = mln / this.a;
  7870. dphi = (al * (cl * ma + 1) - ma - 0.5 * cl * (ma * ma + bl)) / (this.es * Math.sin(2 * phi) * (ma * ma + bl - 2 * al * ma) / (4 * cl) + (al - ma) * (cl * mlnp - 2 / Math.sin(2 * phi)) - mlnp);
  7871. phi -= dphi;
  7872. if (Math.abs(dphi) <= EPSLN) {
  7873. lat = phi;
  7874. break;
  7875. }
  7876. }
  7877. //lat=phi4z(this.e,this.e0,this.e1,this.e2,this.e3,al,bl,0,0);
  7878. cl = Math.sqrt(1 - this.es * Math.pow(Math.sin(lat), 2)) * Math.tan(lat);
  7879. lon = adjust_lon(this.long0 + Math.asin(x * cl / this.a) / Math.sin(lat));
  7880. }
  7881. }
  7882. p.x = lon;
  7883. p.y = lat;
  7884. return p;
  7885. }
  7886. var names$19 = ["Polyconic", "poly"];
  7887. var poly = {
  7888. init: init$18,
  7889. forward: forward$17,
  7890. inverse: inverse$17,
  7891. names: names$19
  7892. };
  7893. /*
  7894. reference
  7895. Department of Land and Survey Technical Circular 1973/32
  7896. http://www.linz.govt.nz/docs/miscellaneous/nz-map-definition.pdf
  7897. OSG Technical Report 4.1
  7898. http://www.linz.govt.nz/docs/miscellaneous/nzmg.pdf
  7899. */
  7900. /**
  7901. * iterations: Number of iterations to refine inverse transform.
  7902. * 0 -> km accuracy
  7903. * 1 -> m accuracy -- suitable for most mapping applications
  7904. * 2 -> mm accuracy
  7905. */
  7906. function init$19() {
  7907. this.A = [];
  7908. this.A[1] = 0.6399175073;
  7909. this.A[2] = -0.1358797613;
  7910. this.A[3] = 0.063294409;
  7911. this.A[4] = -0.02526853;
  7912. this.A[5] = 0.0117879;
  7913. this.A[6] = -0.0055161;
  7914. this.A[7] = 0.0026906;
  7915. this.A[8] = -0.001333;
  7916. this.A[9] = 0.00067;
  7917. this.A[10] = -0.00034;
  7918. this.B_re = [];
  7919. this.B_im = [];
  7920. this.B_re[1] = 0.7557853228;
  7921. this.B_im[1] = 0;
  7922. this.B_re[2] = 0.249204646;
  7923. this.B_im[2] = 0.003371507;
  7924. this.B_re[3] = -0.001541739;
  7925. this.B_im[3] = 0.041058560;
  7926. this.B_re[4] = -0.10162907;
  7927. this.B_im[4] = 0.01727609;
  7928. this.B_re[5] = -0.26623489;
  7929. this.B_im[5] = -0.36249218;
  7930. this.B_re[6] = -0.6870983;
  7931. this.B_im[6] = -1.1651967;
  7932. this.C_re = [];
  7933. this.C_im = [];
  7934. this.C_re[1] = 1.3231270439;
  7935. this.C_im[1] = 0;
  7936. this.C_re[2] = -0.577245789;
  7937. this.C_im[2] = -0.007809598;
  7938. this.C_re[3] = 0.508307513;
  7939. this.C_im[3] = -0.112208952;
  7940. this.C_re[4] = -0.15094762;
  7941. this.C_im[4] = 0.18200602;
  7942. this.C_re[5] = 1.01418179;
  7943. this.C_im[5] = 1.64497696;
  7944. this.C_re[6] = 1.9660549;
  7945. this.C_im[6] = 2.5127645;
  7946. this.D = [];
  7947. this.D[1] = 1.5627014243;
  7948. this.D[2] = 0.5185406398;
  7949. this.D[3] = -0.03333098;
  7950. this.D[4] = -0.1052906;
  7951. this.D[5] = -0.0368594;
  7952. this.D[6] = 0.007317;
  7953. this.D[7] = 0.01220;
  7954. this.D[8] = 0.00394;
  7955. this.D[9] = -0.0013;
  7956. }
  7957. /**
  7958. New Zealand Map Grid Forward - long/lat to x/y
  7959. long/lat in radians
  7960. */
  7961. function forward$18(p) {
  7962. var n;
  7963. var lon = p.x;
  7964. var lat = p.y;
  7965. var delta_lat = lat - this.lat0;
  7966. var delta_lon = lon - this.long0;
  7967. // 1. Calculate d_phi and d_psi ... // and d_lambda
  7968. // For this algorithm, delta_latitude is in seconds of arc x 10-5, so we need to scale to those units. Longitude is radians.
  7969. var d_phi = delta_lat / SEC_TO_RAD * 1E-5;
  7970. var d_lambda = delta_lon;
  7971. var d_phi_n = 1; // d_phi^0
  7972. var d_psi = 0;
  7973. for (n = 1; n <= 10; n++) {
  7974. d_phi_n = d_phi_n * d_phi;
  7975. d_psi = d_psi + this.A[n] * d_phi_n;
  7976. }
  7977. // 2. Calculate theta
  7978. var th_re = d_psi;
  7979. var th_im = d_lambda;
  7980. // 3. Calculate z
  7981. var th_n_re = 1;
  7982. var th_n_im = 0; // theta^0
  7983. var th_n_re1;
  7984. var th_n_im1;
  7985. var z_re = 0;
  7986. var z_im = 0;
  7987. for (n = 1; n <= 6; n++) {
  7988. th_n_re1 = th_n_re * th_re - th_n_im * th_im;
  7989. th_n_im1 = th_n_im * th_re + th_n_re * th_im;
  7990. th_n_re = th_n_re1;
  7991. th_n_im = th_n_im1;
  7992. z_re = z_re + this.B_re[n] * th_n_re - this.B_im[n] * th_n_im;
  7993. z_im = z_im + this.B_im[n] * th_n_re + this.B_re[n] * th_n_im;
  7994. }
  7995. // 4. Calculate easting and northing
  7996. p.x = (z_im * this.a) + this.x0;
  7997. p.y = (z_re * this.a) + this.y0;
  7998. return p;
  7999. }
  8000. /**
  8001. New Zealand Map Grid Inverse - x/y to long/lat
  8002. */
  8003. function inverse$18(p) {
  8004. var n;
  8005. var x = p.x;
  8006. var y = p.y;
  8007. var delta_x = x - this.x0;
  8008. var delta_y = y - this.y0;
  8009. // 1. Calculate z
  8010. var z_re = delta_y / this.a;
  8011. var z_im = delta_x / this.a;
  8012. // 2a. Calculate theta - first approximation gives km accuracy
  8013. var z_n_re = 1;
  8014. var z_n_im = 0; // z^0
  8015. var z_n_re1;
  8016. var z_n_im1;
  8017. var th_re = 0;
  8018. var th_im = 0;
  8019. for (n = 1; n <= 6; n++) {
  8020. z_n_re1 = z_n_re * z_re - z_n_im * z_im;
  8021. z_n_im1 = z_n_im * z_re + z_n_re * z_im;
  8022. z_n_re = z_n_re1;
  8023. z_n_im = z_n_im1;
  8024. th_re = th_re + this.C_re[n] * z_n_re - this.C_im[n] * z_n_im;
  8025. th_im = th_im + this.C_im[n] * z_n_re + this.C_re[n] * z_n_im;
  8026. }
  8027. // 2b. Iterate to refine the accuracy of the calculation
  8028. // 0 iterations gives km accuracy
  8029. // 1 iteration gives m accuracy -- good enough for most mapping applications
  8030. // 2 iterations bives mm accuracy
  8031. for (var i = 0; i < this.iterations; i++) {
  8032. var th_n_re = th_re;
  8033. var th_n_im = th_im;
  8034. var th_n_re1;
  8035. var th_n_im1;
  8036. var num_re = z_re;
  8037. var num_im = z_im;
  8038. for (n = 2; n <= 6; n++) {
  8039. th_n_re1 = th_n_re * th_re - th_n_im * th_im;
  8040. th_n_im1 = th_n_im * th_re + th_n_re * th_im;
  8041. th_n_re = th_n_re1;
  8042. th_n_im = th_n_im1;
  8043. num_re = num_re + (n - 1) * (this.B_re[n] * th_n_re - this.B_im[n] * th_n_im);
  8044. num_im = num_im + (n - 1) * (this.B_im[n] * th_n_re + this.B_re[n] * th_n_im);
  8045. }
  8046. th_n_re = 1;
  8047. th_n_im = 0;
  8048. var den_re = this.B_re[1];
  8049. var den_im = this.B_im[1];
  8050. for (n = 2; n <= 6; n++) {
  8051. th_n_re1 = th_n_re * th_re - th_n_im * th_im;
  8052. th_n_im1 = th_n_im * th_re + th_n_re * th_im;
  8053. th_n_re = th_n_re1;
  8054. th_n_im = th_n_im1;
  8055. den_re = den_re + n * (this.B_re[n] * th_n_re - this.B_im[n] * th_n_im);
  8056. den_im = den_im + n * (this.B_im[n] * th_n_re + this.B_re[n] * th_n_im);
  8057. }
  8058. // Complex division
  8059. var den2 = den_re * den_re + den_im * den_im;
  8060. th_re = (num_re * den_re + num_im * den_im) / den2;
  8061. th_im = (num_im * den_re - num_re * den_im) / den2;
  8062. }
  8063. // 3. Calculate d_phi ... // and d_lambda
  8064. var d_psi = th_re;
  8065. var d_lambda = th_im;
  8066. var d_psi_n = 1; // d_psi^0
  8067. var d_phi = 0;
  8068. for (n = 1; n <= 9; n++) {
  8069. d_psi_n = d_psi_n * d_psi;
  8070. d_phi = d_phi + this.D[n] * d_psi_n;
  8071. }
  8072. // 4. Calculate latitude and longitude
  8073. // d_phi is calcuated in second of arc * 10^-5, so we need to scale back to radians. d_lambda is in radians.
  8074. var lat = this.lat0 + (d_phi * SEC_TO_RAD * 1E5);
  8075. var lon = this.long0 + d_lambda;
  8076. p.x = lon;
  8077. p.y = lat;
  8078. return p;
  8079. }
  8080. var names$20 = ["New_Zealand_Map_Grid", "nzmg"];
  8081. var nzmg = {
  8082. init: init$19,
  8083. forward: forward$18,
  8084. inverse: inverse$18,
  8085. names: names$20
  8086. };
  8087. /*
  8088. reference
  8089. "New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
  8090. The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
  8091. */
  8092. /* Initialize the Miller Cylindrical projection
  8093. -------------------------------------------*/
  8094. function init$20() {
  8095. //no-op
  8096. }
  8097. /* Miller Cylindrical forward equations--mapping lat,long to x,y
  8098. ------------------------------------------------------------*/
  8099. function forward$19(p) {
  8100. var lon = p.x;
  8101. var lat = p.y;
  8102. /* Forward equations
  8103. -----------------*/
  8104. var dlon = adjust_lon(lon - this.long0);
  8105. var x = this.x0 + this.a * dlon;
  8106. var y = this.y0 + this.a * Math.log(Math.tan((Math.PI / 4) + (lat / 2.5))) * 1.25;
  8107. p.x = x;
  8108. p.y = y;
  8109. return p;
  8110. }
  8111. /* Miller Cylindrical inverse equations--mapping x,y to lat/long
  8112. ------------------------------------------------------------*/
  8113. function inverse$19(p) {
  8114. p.x -= this.x0;
  8115. p.y -= this.y0;
  8116. var lon = adjust_lon(this.long0 + p.x / this.a);
  8117. var lat = 2.5 * (Math.atan(Math.exp(0.8 * p.y / this.a)) - Math.PI / 4);
  8118. p.x = lon;
  8119. p.y = lat;
  8120. return p;
  8121. }
  8122. var names$21 = ["Miller_Cylindrical", "mill"];
  8123. var mill = {
  8124. init: init$20,
  8125. forward: forward$19,
  8126. inverse: inverse$19,
  8127. names: names$21
  8128. };
  8129. var MAX_ITER$3 = 20;
  8130. function init$21() {
  8131. /* Place parameters in static storage for common use
  8132. -------------------------------------------------*/
  8133. if (!this.sphere) {
  8134. this.en = pj_enfn(this.es);
  8135. }
  8136. else {
  8137. this.n = 1;
  8138. this.m = 0;
  8139. this.es = 0;
  8140. this.C_y = Math.sqrt((this.m + 1) / this.n);
  8141. this.C_x = this.C_y / (this.m + 1);
  8142. }
  8143. }
  8144. /* Sinusoidal forward equations--mapping lat,long to x,y
  8145. -----------------------------------------------------*/
  8146. function forward$20(p) {
  8147. var x, y;
  8148. var lon = p.x;
  8149. var lat = p.y;
  8150. /* Forward equations
  8151. -----------------*/
  8152. lon = adjust_lon(lon - this.long0);
  8153. if (this.sphere) {
  8154. if (!this.m) {
  8155. lat = this.n !== 1 ? Math.asin(this.n * Math.sin(lat)) : lat;
  8156. }
  8157. else {
  8158. var k = this.n * Math.sin(lat);
  8159. for (var i = MAX_ITER$3; i; --i) {
  8160. var V = (this.m * lat + Math.sin(lat) - k) / (this.m + Math.cos(lat));
  8161. lat -= V;
  8162. if (Math.abs(V) < EPSLN) {
  8163. break;
  8164. }
  8165. }
  8166. }
  8167. x = this.a * this.C_x * lon * (this.m + Math.cos(lat));
  8168. y = this.a * this.C_y * lat;
  8169. }
  8170. else {
  8171. var s = Math.sin(lat);
  8172. var c = Math.cos(lat);
  8173. y = this.a * pj_mlfn(lat, s, c, this.en);
  8174. x = this.a * lon * c / Math.sqrt(1 - this.es * s * s);
  8175. }
  8176. p.x = x;
  8177. p.y = y;
  8178. return p;
  8179. }
  8180. function inverse$20(p) {
  8181. var lat, temp, lon, s;
  8182. p.x -= this.x0;
  8183. lon = p.x / this.a;
  8184. p.y -= this.y0;
  8185. lat = p.y / this.a;
  8186. if (this.sphere) {
  8187. lat /= this.C_y;
  8188. lon = lon / (this.C_x * (this.m + Math.cos(lat)));
  8189. if (this.m) {
  8190. lat = asinz((this.m * lat + Math.sin(lat)) / this.n);
  8191. }
  8192. else if (this.n !== 1) {
  8193. lat = asinz(Math.sin(lat) / this.n);
  8194. }
  8195. lon = adjust_lon(lon + this.long0);
  8196. lat = adjust_lat(lat);
  8197. }
  8198. else {
  8199. lat = pj_inv_mlfn(p.y / this.a, this.es, this.en);
  8200. s = Math.abs(lat);
  8201. if (s < HALF_PI) {
  8202. s = Math.sin(lat);
  8203. temp = this.long0 + p.x * Math.sqrt(1 - this.es * s * s) / (this.a * Math.cos(lat));
  8204. //temp = this.long0 + p.x / (this.a * Math.cos(lat));
  8205. lon = adjust_lon(temp);
  8206. }
  8207. else if ((s - EPSLN) < HALF_PI) {
  8208. lon = this.long0;
  8209. }
  8210. }
  8211. p.x = lon;
  8212. p.y = lat;
  8213. return p;
  8214. }
  8215. var names$22 = ["Sinusoidal", "sinu"];
  8216. var sinu = {
  8217. init: init$21,
  8218. forward: forward$20,
  8219. inverse: inverse$20,
  8220. names: names$22
  8221. };
  8222. function init$22() { }
  8223. /* Mollweide forward equations--mapping lat,long to x,y
  8224. ----------------------------------------------------*/
  8225. function forward$21(p) {
  8226. /* Forward equations
  8227. -----------------*/
  8228. var lon = p.x;
  8229. var lat = p.y;
  8230. var delta_lon = adjust_lon(lon - this.long0);
  8231. var theta = lat;
  8232. var con = Math.PI * Math.sin(lat);
  8233. /* Iterate using the Newton-Raphson method to find theta
  8234. -----------------------------------------------------*/
  8235. while (true) {
  8236. var delta_theta = -(theta + Math.sin(theta) - con) / (1 + Math.cos(theta));
  8237. theta += delta_theta;
  8238. if (Math.abs(delta_theta) < EPSLN) {
  8239. break;
  8240. }
  8241. }
  8242. theta /= 2;
  8243. /* If the latitude is 90 deg, force the x coordinate to be "0 + false easting"
  8244. this is done here because of precision problems with "cos(theta)"
  8245. --------------------------------------------------------------------------*/
  8246. if (Math.PI / 2 - Math.abs(lat) < EPSLN) {
  8247. delta_lon = 0;
  8248. }
  8249. var x = 0.900316316158 * this.a * delta_lon * Math.cos(theta) + this.x0;
  8250. var y = 1.4142135623731 * this.a * Math.sin(theta) + this.y0;
  8251. p.x = x;
  8252. p.y = y;
  8253. return p;
  8254. }
  8255. function inverse$21(p) {
  8256. var theta;
  8257. var arg;
  8258. /* Inverse equations
  8259. -----------------*/
  8260. p.x -= this.x0;
  8261. p.y -= this.y0;
  8262. arg = p.y / (1.4142135623731 * this.a);
  8263. /* Because of division by zero problems, 'arg' can not be 1. Therefore
  8264. a number very close to one is used instead.
  8265. -------------------------------------------------------------------*/
  8266. if (Math.abs(arg) > 0.999999999999) {
  8267. arg = 0.999999999999;
  8268. }
  8269. theta = Math.asin(arg);
  8270. var lon = adjust_lon(this.long0 + (p.x / (0.900316316158 * this.a * Math.cos(theta))));
  8271. if (lon < (-Math.PI)) {
  8272. lon = -Math.PI;
  8273. }
  8274. if (lon > Math.PI) {
  8275. lon = Math.PI;
  8276. }
  8277. arg = (2 * theta + Math.sin(2 * theta)) / Math.PI;
  8278. if (Math.abs(arg) > 1) {
  8279. arg = 1;
  8280. }
  8281. var lat = Math.asin(arg);
  8282. p.x = lon;
  8283. p.y = lat;
  8284. return p;
  8285. }
  8286. var names$23 = ["Mollweide", "moll"];
  8287. var moll = {
  8288. init: init$22,
  8289. forward: forward$21,
  8290. inverse: inverse$21,
  8291. names: names$23
  8292. };
  8293. function init$23() {
  8294. /* Place parameters in static storage for common use
  8295. -------------------------------------------------*/
  8296. // Standard Parallels cannot be equal and on opposite sides of the equator
  8297. if (Math.abs(this.lat1 + this.lat2) < EPSLN) {
  8298. return;
  8299. }
  8300. this.lat2 = this.lat2 || this.lat1;
  8301. this.temp = this.b / this.a;
  8302. this.es = 1 - Math.pow(this.temp, 2);
  8303. this.e = Math.sqrt(this.es);
  8304. this.e0 = e0fn(this.es);
  8305. this.e1 = e1fn(this.es);
  8306. this.e2 = e2fn(this.es);
  8307. this.e3 = e3fn(this.es);
  8308. this.sinphi = Math.sin(this.lat1);
  8309. this.cosphi = Math.cos(this.lat1);
  8310. this.ms1 = msfnz(this.e, this.sinphi, this.cosphi);
  8311. this.ml1 = mlfn(this.e0, this.e1, this.e2, this.e3, this.lat1);
  8312. if (Math.abs(this.lat1 - this.lat2) < EPSLN) {
  8313. this.ns = this.sinphi;
  8314. }
  8315. else {
  8316. this.sinphi = Math.sin(this.lat2);
  8317. this.cosphi = Math.cos(this.lat2);
  8318. this.ms2 = msfnz(this.e, this.sinphi, this.cosphi);
  8319. this.ml2 = mlfn(this.e0, this.e1, this.e2, this.e3, this.lat2);
  8320. this.ns = (this.ms1 - this.ms2) / (this.ml2 - this.ml1);
  8321. }
  8322. this.g = this.ml1 + this.ms1 / this.ns;
  8323. this.ml0 = mlfn(this.e0, this.e1, this.e2, this.e3, this.lat0);
  8324. this.rh = this.a * (this.g - this.ml0);
  8325. }
  8326. /* Equidistant Conic forward equations--mapping lat,long to x,y
  8327. -----------------------------------------------------------*/
  8328. function forward$22(p) {
  8329. var lon = p.x;
  8330. var lat = p.y;
  8331. var rh1;
  8332. /* Forward equations
  8333. -----------------*/
  8334. if (this.sphere) {
  8335. rh1 = this.a * (this.g - lat);
  8336. }
  8337. else {
  8338. var ml = mlfn(this.e0, this.e1, this.e2, this.e3, lat);
  8339. rh1 = this.a * (this.g - ml);
  8340. }
  8341. var theta = this.ns * adjust_lon(lon - this.long0);
  8342. var x = this.x0 + rh1 * Math.sin(theta);
  8343. var y = this.y0 + this.rh - rh1 * Math.cos(theta);
  8344. p.x = x;
  8345. p.y = y;
  8346. return p;
  8347. }
  8348. /* Inverse equations
  8349. -----------------*/
  8350. function inverse$22(p) {
  8351. p.x -= this.x0;
  8352. p.y = this.rh - p.y + this.y0;
  8353. var con, rh1, lat, lon;
  8354. if (this.ns >= 0) {
  8355. rh1 = Math.sqrt(p.x * p.x + p.y * p.y);
  8356. con = 1;
  8357. }
  8358. else {
  8359. rh1 = -Math.sqrt(p.x * p.x + p.y * p.y);
  8360. con = -1;
  8361. }
  8362. var theta = 0;
  8363. if (rh1 !== 0) {
  8364. theta = Math.atan2(con * p.x, con * p.y);
  8365. }
  8366. if (this.sphere) {
  8367. lon = adjust_lon(this.long0 + theta / this.ns);
  8368. lat = adjust_lat(this.g - rh1 / this.a);
  8369. p.x = lon;
  8370. p.y = lat;
  8371. return p;
  8372. }
  8373. else {
  8374. var ml = this.g - rh1 / this.a;
  8375. lat = imlfn(ml, this.e0, this.e1, this.e2, this.e3);
  8376. lon = adjust_lon(this.long0 + theta / this.ns);
  8377. p.x = lon;
  8378. p.y = lat;
  8379. return p;
  8380. }
  8381. }
  8382. var names$24 = ["Equidistant_Conic", "eqdc"];
  8383. var eqdc = {
  8384. init: init$23,
  8385. forward: forward$22,
  8386. inverse: inverse$22,
  8387. names: names$24
  8388. };
  8389. /* Initialize the Van Der Grinten projection
  8390. ----------------------------------------*/
  8391. function init$24() {
  8392. //this.R = 6370997; //Radius of earth
  8393. this.R = this.a;
  8394. }
  8395. function forward$23(p) {
  8396. var lon = p.x;
  8397. var lat = p.y;
  8398. /* Forward equations
  8399. -----------------*/
  8400. var dlon = adjust_lon(lon - this.long0);
  8401. var x, y;
  8402. if (Math.abs(lat) <= EPSLN) {
  8403. x = this.x0 + this.R * dlon;
  8404. y = this.y0;
  8405. }
  8406. var theta = asinz(2 * Math.abs(lat / Math.PI));
  8407. if ((Math.abs(dlon) <= EPSLN) || (Math.abs(Math.abs(lat) - HALF_PI) <= EPSLN)) {
  8408. x = this.x0;
  8409. if (lat >= 0) {
  8410. y = this.y0 + Math.PI * this.R * Math.tan(0.5 * theta);
  8411. }
  8412. else {
  8413. y = this.y0 + Math.PI * this.R * -Math.tan(0.5 * theta);
  8414. }
  8415. // return(OK);
  8416. }
  8417. var al = 0.5 * Math.abs((Math.PI / dlon) - (dlon / Math.PI));
  8418. var asq = al * al;
  8419. var sinth = Math.sin(theta);
  8420. var costh = Math.cos(theta);
  8421. var g = costh / (sinth + costh - 1);
  8422. var gsq = g * g;
  8423. var m = g * (2 / sinth - 1);
  8424. var msq = m * m;
  8425. var con = Math.PI * this.R * (al * (g - msq) + Math.sqrt(asq * (g - msq) * (g - msq) - (msq + asq) * (gsq - msq))) / (msq + asq);
  8426. if (dlon < 0) {
  8427. con = -con;
  8428. }
  8429. x = this.x0 + con;
  8430. //con = Math.abs(con / (Math.PI * this.R));
  8431. var q = asq + g;
  8432. con = Math.PI * this.R * (m * q - al * Math.sqrt((msq + asq) * (asq + 1) - q * q)) / (msq + asq);
  8433. if (lat >= 0) {
  8434. //y = this.y0 + Math.PI * this.R * Math.sqrt(1 - con * con - 2 * al * con);
  8435. y = this.y0 + con;
  8436. }
  8437. else {
  8438. //y = this.y0 - Math.PI * this.R * Math.sqrt(1 - con * con - 2 * al * con);
  8439. y = this.y0 - con;
  8440. }
  8441. p.x = x;
  8442. p.y = y;
  8443. return p;
  8444. }
  8445. /* Van Der Grinten inverse equations--mapping x,y to lat/long
  8446. ---------------------------------------------------------*/
  8447. function inverse$23(p) {
  8448. var lon, lat;
  8449. var xx, yy, xys, c1, c2, c3;
  8450. var a1;
  8451. var m1;
  8452. var con;
  8453. var th1;
  8454. var d;
  8455. /* inverse equations
  8456. -----------------*/
  8457. p.x -= this.x0;
  8458. p.y -= this.y0;
  8459. con = Math.PI * this.R;
  8460. xx = p.x / con;
  8461. yy = p.y / con;
  8462. xys = xx * xx + yy * yy;
  8463. c1 = -Math.abs(yy) * (1 + xys);
  8464. c2 = c1 - 2 * yy * yy + xx * xx;
  8465. c3 = -2 * c1 + 1 + 2 * yy * yy + xys * xys;
  8466. d = yy * yy / c3 + (2 * c2 * c2 * c2 / c3 / c3 / c3 - 9 * c1 * c2 / c3 / c3) / 27;
  8467. a1 = (c1 - c2 * c2 / 3 / c3) / c3;
  8468. m1 = 2 * Math.sqrt(-a1 / 3);
  8469. con = ((3 * d) / a1) / m1;
  8470. if (Math.abs(con) > 1) {
  8471. if (con >= 0) {
  8472. con = 1;
  8473. }
  8474. else {
  8475. con = -1;
  8476. }
  8477. }
  8478. th1 = Math.acos(con) / 3;
  8479. if (p.y >= 0) {
  8480. lat = (-m1 * Math.cos(th1 + Math.PI / 3) - c2 / 3 / c3) * Math.PI;
  8481. }
  8482. else {
  8483. lat = -(-m1 * Math.cos(th1 + Math.PI / 3) - c2 / 3 / c3) * Math.PI;
  8484. }
  8485. if (Math.abs(xx) < EPSLN) {
  8486. lon = this.long0;
  8487. }
  8488. else {
  8489. lon = adjust_lon(this.long0 + Math.PI * (xys - 1 + Math.sqrt(1 + 2 * (xx * xx - yy * yy) + xys * xys)) / 2 / xx);
  8490. }
  8491. p.x = lon;
  8492. p.y = lat;
  8493. return p;
  8494. }
  8495. var names$25 = ["Van_der_Grinten_I", "VanDerGrinten", "vandg"];
  8496. var vandg = {
  8497. init: init$24,
  8498. forward: forward$23,
  8499. inverse: inverse$23,
  8500. names: names$25
  8501. };
  8502. function init$25() {
  8503. this.sin_p12 = Math.sin(this.lat0);
  8504. this.cos_p12 = Math.cos(this.lat0);
  8505. }
  8506. function forward$24(p) {
  8507. var lon = p.x;
  8508. var lat = p.y;
  8509. var sinphi = Math.sin(p.y);
  8510. var cosphi = Math.cos(p.y);
  8511. var dlon = adjust_lon(lon - this.long0);
  8512. var e0, e1, e2, e3, Mlp, Ml, tanphi, Nl1, Nl, psi, Az, G, H, GH, Hs, c, kp, cos_c, s, s2, s3, s4, s5;
  8513. if (this.sphere) {
  8514. if (Math.abs(this.sin_p12 - 1) <= EPSLN) {
  8515. //North Pole case
  8516. p.x = this.x0 + this.a * (HALF_PI - lat) * Math.sin(dlon);
  8517. p.y = this.y0 - this.a * (HALF_PI - lat) * Math.cos(dlon);
  8518. return p;
  8519. }
  8520. else if (Math.abs(this.sin_p12 + 1) <= EPSLN) {
  8521. //South Pole case
  8522. p.x = this.x0 + this.a * (HALF_PI + lat) * Math.sin(dlon);
  8523. p.y = this.y0 + this.a * (HALF_PI + lat) * Math.cos(dlon);
  8524. return p;
  8525. }
  8526. else {
  8527. //default case
  8528. cos_c = this.sin_p12 * sinphi + this.cos_p12 * cosphi * Math.cos(dlon);
  8529. c = Math.acos(cos_c);
  8530. kp = c ? c / Math.sin(c) : 1;
  8531. p.x = this.x0 + this.a * kp * cosphi * Math.sin(dlon);
  8532. p.y = this.y0 + this.a * kp * (this.cos_p12 * sinphi - this.sin_p12 * cosphi * Math.cos(dlon));
  8533. return p;
  8534. }
  8535. }
  8536. else {
  8537. e0 = e0fn(this.es);
  8538. e1 = e1fn(this.es);
  8539. e2 = e2fn(this.es);
  8540. e3 = e3fn(this.es);
  8541. if (Math.abs(this.sin_p12 - 1) <= EPSLN) {
  8542. //North Pole case
  8543. Mlp = this.a * mlfn(e0, e1, e2, e3, HALF_PI);
  8544. Ml = this.a * mlfn(e0, e1, e2, e3, lat);
  8545. p.x = this.x0 + (Mlp - Ml) * Math.sin(dlon);
  8546. p.y = this.y0 - (Mlp - Ml) * Math.cos(dlon);
  8547. return p;
  8548. }
  8549. else if (Math.abs(this.sin_p12 + 1) <= EPSLN) {
  8550. //South Pole case
  8551. Mlp = this.a * mlfn(e0, e1, e2, e3, HALF_PI);
  8552. Ml = this.a * mlfn(e0, e1, e2, e3, lat);
  8553. p.x = this.x0 + (Mlp + Ml) * Math.sin(dlon);
  8554. p.y = this.y0 + (Mlp + Ml) * Math.cos(dlon);
  8555. return p;
  8556. }
  8557. else {
  8558. //Default case
  8559. tanphi = sinphi / cosphi;
  8560. Nl1 = gN(this.a, this.e, this.sin_p12);
  8561. Nl = gN(this.a, this.e, sinphi);
  8562. psi = Math.atan((1 - this.es) * tanphi + this.es * Nl1 * this.sin_p12 / (Nl * cosphi));
  8563. Az = Math.atan2(Math.sin(dlon), this.cos_p12 * Math.tan(psi) - this.sin_p12 * Math.cos(dlon));
  8564. if (Az === 0) {
  8565. s = Math.asin(this.cos_p12 * Math.sin(psi) - this.sin_p12 * Math.cos(psi));
  8566. }
  8567. else if (Math.abs(Math.abs(Az) - Math.PI) <= EPSLN) {
  8568. s = -Math.asin(this.cos_p12 * Math.sin(psi) - this.sin_p12 * Math.cos(psi));
  8569. }
  8570. else {
  8571. s = Math.asin(Math.sin(dlon) * Math.cos(psi) / Math.sin(Az));
  8572. }
  8573. G = this.e * this.sin_p12 / Math.sqrt(1 - this.es);
  8574. H = this.e * this.cos_p12 * Math.cos(Az) / Math.sqrt(1 - this.es);
  8575. GH = G * H;
  8576. Hs = H * H;
  8577. s2 = s * s;
  8578. s3 = s2 * s;
  8579. s4 = s3 * s;
  8580. s5 = s4 * s;
  8581. c = Nl1 * s * (1 - s2 * Hs * (1 - Hs) / 6 + s3 / 8 * GH * (1 - 2 * Hs) + s4 / 120 * (Hs * (4 - 7 * Hs) - 3 * G * G * (1 - 7 * Hs)) - s5 / 48 * GH);
  8582. p.x = this.x0 + c * Math.sin(Az);
  8583. p.y = this.y0 + c * Math.cos(Az);
  8584. return p;
  8585. }
  8586. }
  8587. }
  8588. function inverse$24(p) {
  8589. p.x -= this.x0;
  8590. p.y -= this.y0;
  8591. var rh, z, sinz, cosz, lon, lat, con, e0, e1, e2, e3, Mlp, M, N1, psi, Az, cosAz, tmp, A, B, D, Ee, F, sinpsi;
  8592. if (this.sphere) {
  8593. rh = Math.sqrt(p.x * p.x + p.y * p.y);
  8594. if (rh > (2 * HALF_PI * this.a)) {
  8595. return;
  8596. }
  8597. z = rh / this.a;
  8598. sinz = Math.sin(z);
  8599. cosz = Math.cos(z);
  8600. lon = this.long0;
  8601. if (Math.abs(rh) <= EPSLN) {
  8602. lat = this.lat0;
  8603. }
  8604. else {
  8605. lat = asinz(cosz * this.sin_p12 + (p.y * sinz * this.cos_p12) / rh);
  8606. con = Math.abs(this.lat0) - HALF_PI;
  8607. if (Math.abs(con) <= EPSLN) {
  8608. if (this.lat0 >= 0) {
  8609. lon = adjust_lon(this.long0 + Math.atan2(p.x, - p.y));
  8610. }
  8611. else {
  8612. lon = adjust_lon(this.long0 - Math.atan2(-p.x, p.y));
  8613. }
  8614. }
  8615. else {
  8616. /*con = cosz - this.sin_p12 * Math.sin(lat);
  8617. if ((Math.abs(con) < EPSLN) && (Math.abs(p.x) < EPSLN)) {
  8618. //no-op, just keep the lon value as is
  8619. } else {
  8620. var temp = Math.atan2((p.x * sinz * this.cos_p12), (con * rh));
  8621. lon = adjust_lon(this.long0 + Math.atan2((p.x * sinz * this.cos_p12), (con * rh)));
  8622. }*/
  8623. lon = adjust_lon(this.long0 + Math.atan2(p.x * sinz, rh * this.cos_p12 * cosz - p.y * this.sin_p12 * sinz));
  8624. }
  8625. }
  8626. p.x = lon;
  8627. p.y = lat;
  8628. return p;
  8629. }
  8630. else {
  8631. e0 = e0fn(this.es);
  8632. e1 = e1fn(this.es);
  8633. e2 = e2fn(this.es);
  8634. e3 = e3fn(this.es);
  8635. if (Math.abs(this.sin_p12 - 1) <= EPSLN) {
  8636. //North pole case
  8637. Mlp = this.a * mlfn(e0, e1, e2, e3, HALF_PI);
  8638. rh = Math.sqrt(p.x * p.x + p.y * p.y);
  8639. M = Mlp - rh;
  8640. lat = imlfn(M / this.a, e0, e1, e2, e3);
  8641. lon = adjust_lon(this.long0 + Math.atan2(p.x, - 1 * p.y));
  8642. p.x = lon;
  8643. p.y = lat;
  8644. return p;
  8645. }
  8646. else if (Math.abs(this.sin_p12 + 1) <= EPSLN) {
  8647. //South pole case
  8648. Mlp = this.a * mlfn(e0, e1, e2, e3, HALF_PI);
  8649. rh = Math.sqrt(p.x * p.x + p.y * p.y);
  8650. M = rh - Mlp;
  8651. lat = imlfn(M / this.a, e0, e1, e2, e3);
  8652. lon = adjust_lon(this.long0 + Math.atan2(p.x, p.y));
  8653. p.x = lon;
  8654. p.y = lat;
  8655. return p;
  8656. }
  8657. else {
  8658. //default case
  8659. rh = Math.sqrt(p.x * p.x + p.y * p.y);
  8660. Az = Math.atan2(p.x, p.y);
  8661. N1 = gN(this.a, this.e, this.sin_p12);
  8662. cosAz = Math.cos(Az);
  8663. tmp = this.e * this.cos_p12 * cosAz;
  8664. A = -tmp * tmp / (1 - this.es);
  8665. B = 3 * this.es * (1 - A) * this.sin_p12 * this.cos_p12 * cosAz / (1 - this.es);
  8666. D = rh / N1;
  8667. Ee = D - A * (1 + A) * Math.pow(D, 3) / 6 - B * (1 + 3 * A) * Math.pow(D, 4) / 24;
  8668. F = 1 - A * Ee * Ee / 2 - D * Ee * Ee * Ee / 6;
  8669. psi = Math.asin(this.sin_p12 * Math.cos(Ee) + this.cos_p12 * Math.sin(Ee) * cosAz);
  8670. lon = adjust_lon(this.long0 + Math.asin(Math.sin(Az) * Math.sin(Ee) / Math.cos(psi)));
  8671. sinpsi = Math.sin(psi);
  8672. lat = Math.atan2((sinpsi - this.es * F * this.sin_p12) * Math.tan(psi), sinpsi * (1 - this.es));
  8673. p.x = lon;
  8674. p.y = lat;
  8675. return p;
  8676. }
  8677. }
  8678. }
  8679. var names$26 = ["Azimuthal_Equidistant", "aeqd"];
  8680. var aeqd = {
  8681. init: init$25,
  8682. forward: forward$24,
  8683. inverse: inverse$24,
  8684. names: names$26
  8685. };
  8686. function init$26() {
  8687. //double temp; /* temporary variable */
  8688. /* Place parameters in static storage for common use
  8689. -------------------------------------------------*/
  8690. this.sin_p14 = Math.sin(this.lat0);
  8691. this.cos_p14 = Math.cos(this.lat0);
  8692. }
  8693. /* Orthographic forward equations--mapping lat,long to x,y
  8694. ---------------------------------------------------*/
  8695. function forward$25(p) {
  8696. var sinphi, cosphi; /* sin and cos value */
  8697. var dlon; /* delta longitude value */
  8698. var coslon; /* cos of longitude */
  8699. var ksp; /* scale factor */
  8700. var g, x, y;
  8701. var lon = p.x;
  8702. var lat = p.y;
  8703. /* Forward equations
  8704. -----------------*/
  8705. dlon = adjust_lon(lon - this.long0);
  8706. sinphi = Math.sin(lat);
  8707. cosphi = Math.cos(lat);
  8708. coslon = Math.cos(dlon);
  8709. g = this.sin_p14 * sinphi + this.cos_p14 * cosphi * coslon;
  8710. ksp = 1;
  8711. if ((g > 0) || (Math.abs(g) <= EPSLN)) {
  8712. x = this.a * ksp * cosphi * Math.sin(dlon);
  8713. y = this.y0 + this.a * ksp * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon);
  8714. }
  8715. p.x = x;
  8716. p.y = y;
  8717. return p;
  8718. }
  8719. function inverse$25(p) {
  8720. var rh; /* height above ellipsoid */
  8721. var z; /* angle */
  8722. var sinz, cosz; /* sin of z and cos of z */
  8723. var con;
  8724. var lon, lat;
  8725. /* Inverse equations
  8726. -----------------*/
  8727. p.x -= this.x0;
  8728. p.y -= this.y0;
  8729. rh = Math.sqrt(p.x * p.x + p.y * p.y);
  8730. z = asinz(rh / this.a);
  8731. sinz = Math.sin(z);
  8732. cosz = Math.cos(z);
  8733. lon = this.long0;
  8734. if (Math.abs(rh) <= EPSLN) {
  8735. lat = this.lat0;
  8736. p.x = lon;
  8737. p.y = lat;
  8738. return p;
  8739. }
  8740. lat = asinz(cosz * this.sin_p14 + (p.y * sinz * this.cos_p14) / rh);
  8741. con = Math.abs(this.lat0) - HALF_PI;
  8742. if (Math.abs(con) <= EPSLN) {
  8743. if (this.lat0 >= 0) {
  8744. lon = adjust_lon(this.long0 + Math.atan2(p.x, - p.y));
  8745. }
  8746. else {
  8747. lon = adjust_lon(this.long0 - Math.atan2(-p.x, p.y));
  8748. }
  8749. p.x = lon;
  8750. p.y = lat;
  8751. return p;
  8752. }
  8753. lon = adjust_lon(this.long0 + Math.atan2((p.x * sinz), rh * this.cos_p14 * cosz - p.y * this.sin_p14 * sinz));
  8754. p.x = lon;
  8755. p.y = lat;
  8756. return p;
  8757. }
  8758. var names$27 = ["ortho"];
  8759. var ortho = {
  8760. init: init$26,
  8761. forward: forward$25,
  8762. inverse: inverse$25,
  8763. names: names$27
  8764. };
  8765. // QSC projection rewritten from the original PROJ4
  8766. // https://github.com/OSGeo/proj.4/blob/master/src/PJ_qsc.c
  8767. /* constants */
  8768. var FACE_ENUM = {
  8769. FRONT: 1,
  8770. RIGHT: 2,
  8771. BACK: 3,
  8772. LEFT: 4,
  8773. TOP: 5,
  8774. BOTTOM: 6
  8775. };
  8776. var AREA_ENUM = {
  8777. AREA_0: 1,
  8778. AREA_1: 2,
  8779. AREA_2: 3,
  8780. AREA_3: 4
  8781. };
  8782. function init$27() {
  8783. this.x0 = this.x0 || 0;
  8784. this.y0 = this.y0 || 0;
  8785. this.lat0 = this.lat0 || 0;
  8786. this.long0 = this.long0 || 0;
  8787. this.lat_ts = this.lat_ts || 0;
  8788. this.title = this.title || "Quadrilateralized Spherical Cube";
  8789. /* Determine the cube face from the center of projection. */
  8790. if (this.lat0 >= HALF_PI - FORTPI / 2.0) {
  8791. this.face = FACE_ENUM.TOP;
  8792. } else if (this.lat0 <= -(HALF_PI - FORTPI / 2.0)) {
  8793. this.face = FACE_ENUM.BOTTOM;
  8794. } else if (Math.abs(this.long0) <= FORTPI) {
  8795. this.face = FACE_ENUM.FRONT;
  8796. } else if (Math.abs(this.long0) <= HALF_PI + FORTPI) {
  8797. this.face = this.long0 > 0.0 ? FACE_ENUM.RIGHT : FACE_ENUM.LEFT;
  8798. } else {
  8799. this.face = FACE_ENUM.BACK;
  8800. }
  8801. /* Fill in useful values for the ellipsoid <-> sphere shift
  8802. * described in [LK12]. */
  8803. if (this.es !== 0) {
  8804. this.one_minus_f = 1 - (this.a - this.b) / this.a;
  8805. this.one_minus_f_squared = this.one_minus_f * this.one_minus_f;
  8806. }
  8807. }
  8808. // QSC forward equations--mapping lat,long to x,y
  8809. // -----------------------------------------------------------------
  8810. function forward$26(p) {
  8811. var xy = { x: 0, y: 0 };
  8812. var lat, lon;
  8813. var theta, phi;
  8814. var t, mu;
  8815. /* nu; */
  8816. var area = { value: 0 };
  8817. // move lon according to projection's lon
  8818. p.x -= this.long0;
  8819. /* Convert the geodetic latitude to a geocentric latitude.
  8820. * This corresponds to the shift from the ellipsoid to the sphere
  8821. * described in [LK12]. */
  8822. if (this.es !== 0) {//if (P->es != 0) {
  8823. lat = Math.atan(this.one_minus_f_squared * Math.tan(p.y));
  8824. } else {
  8825. lat = p.y;
  8826. }
  8827. /* Convert the input lat, lon into theta, phi as used by QSC.
  8828. * This depends on the cube face and the area on it.
  8829. * For the top and bottom face, we can compute theta and phi
  8830. * directly from phi, lam. For the other faces, we must use
  8831. * unit sphere cartesian coordinates as an intermediate step. */
  8832. lon = p.x; //lon = lp.lam;
  8833. if (this.face === FACE_ENUM.TOP) {
  8834. phi = HALF_PI - lat;
  8835. if (lon >= FORTPI && lon <= HALF_PI + FORTPI) {
  8836. area.value = AREA_ENUM.AREA_0;
  8837. theta = lon - HALF_PI;
  8838. } else if (lon > HALF_PI + FORTPI || lon <= -(HALF_PI + FORTPI)) {
  8839. area.value = AREA_ENUM.AREA_1;
  8840. theta = (lon > 0.0 ? lon - SPI : lon + SPI);
  8841. } else if (lon > -(HALF_PI + FORTPI) && lon <= -FORTPI) {
  8842. area.value = AREA_ENUM.AREA_2;
  8843. theta = lon + HALF_PI;
  8844. } else {
  8845. area.value = AREA_ENUM.AREA_3;
  8846. theta = lon;
  8847. }
  8848. } else if (this.face === FACE_ENUM.BOTTOM) {
  8849. phi = HALF_PI + lat;
  8850. if (lon >= FORTPI && lon <= HALF_PI + FORTPI) {
  8851. area.value = AREA_ENUM.AREA_0;
  8852. theta = -lon + HALF_PI;
  8853. } else if (lon < FORTPI && lon >= -FORTPI) {
  8854. area.value = AREA_ENUM.AREA_1;
  8855. theta = -lon;
  8856. } else if (lon < -FORTPI && lon >= -(HALF_PI + FORTPI)) {
  8857. area.value = AREA_ENUM.AREA_2;
  8858. theta = -lon - HALF_PI;
  8859. } else {
  8860. area.value = AREA_ENUM.AREA_3;
  8861. theta = (lon > 0.0 ? -lon + SPI : -lon - SPI);
  8862. }
  8863. } else {
  8864. var q, r, s;
  8865. var sinlat, coslat;
  8866. var sinlon, coslon;
  8867. if (this.face === FACE_ENUM.RIGHT) {
  8868. lon = qsc_shift_lon_origin(lon, +HALF_PI);
  8869. } else if (this.face === FACE_ENUM.BACK) {
  8870. lon = qsc_shift_lon_origin(lon, +SPI);
  8871. } else if (this.face === FACE_ENUM.LEFT) {
  8872. lon = qsc_shift_lon_origin(lon, -HALF_PI);
  8873. }
  8874. sinlat = Math.sin(lat);
  8875. coslat = Math.cos(lat);
  8876. sinlon = Math.sin(lon);
  8877. coslon = Math.cos(lon);
  8878. q = coslat * coslon;
  8879. r = coslat * sinlon;
  8880. s = sinlat;
  8881. if (this.face === FACE_ENUM.FRONT) {
  8882. phi = Math.acos(q);
  8883. theta = qsc_fwd_equat_face_theta(phi, s, r, area);
  8884. } else if (this.face === FACE_ENUM.RIGHT) {
  8885. phi = Math.acos(r);
  8886. theta = qsc_fwd_equat_face_theta(phi, s, -q, area);
  8887. } else if (this.face === FACE_ENUM.BACK) {
  8888. phi = Math.acos(-q);
  8889. theta = qsc_fwd_equat_face_theta(phi, s, -r, area);
  8890. } else if (this.face === FACE_ENUM.LEFT) {
  8891. phi = Math.acos(-r);
  8892. theta = qsc_fwd_equat_face_theta(phi, s, q, area);
  8893. } else {
  8894. /* Impossible */
  8895. phi = theta = 0;
  8896. area.value = AREA_ENUM.AREA_0;
  8897. }
  8898. }
  8899. /* Compute mu and nu for the area of definition.
  8900. * For mu, see Eq. (3-21) in [OL76], but note the typos:
  8901. * compare with Eq. (3-14). For nu, see Eq. (3-38). */
  8902. mu = Math.atan((12 / SPI) * (theta + Math.acos(Math.sin(theta) * Math.cos(FORTPI)) - HALF_PI));
  8903. t = Math.sqrt((1 - Math.cos(phi)) / (Math.cos(mu) * Math.cos(mu)) / (1 - Math.cos(Math.atan(1 / Math.cos(theta)))));
  8904. /* Apply the result to the real area. */
  8905. if (area.value === AREA_ENUM.AREA_1) {
  8906. mu += HALF_PI;
  8907. } else if (area.value === AREA_ENUM.AREA_2) {
  8908. mu += SPI;
  8909. } else if (area.value === AREA_ENUM.AREA_3) {
  8910. mu += 1.5 * SPI;
  8911. }
  8912. /* Now compute x, y from mu and nu */
  8913. xy.x = t * Math.cos(mu);
  8914. xy.y = t * Math.sin(mu);
  8915. xy.x = xy.x * this.a + this.x0;
  8916. xy.y = xy.y * this.a + this.y0;
  8917. p.x = xy.x;
  8918. p.y = xy.y;
  8919. return p;
  8920. }
  8921. // QSC inverse equations--mapping x,y to lat/long
  8922. // -----------------------------------------------------------------
  8923. function inverse$26(p) {
  8924. var lp = { lam: 0, phi: 0 };
  8925. var mu, nu, cosmu, tannu;
  8926. var tantheta, theta, cosphi, phi;
  8927. var t;
  8928. var area = { value: 0 };
  8929. /* de-offset */
  8930. p.x = (p.x - this.x0) / this.a;
  8931. p.y = (p.y - this.y0) / this.a;
  8932. /* Convert the input x, y to the mu and nu angles as used by QSC.
  8933. * This depends on the area of the cube face. */
  8934. nu = Math.atan(Math.sqrt(p.x * p.x + p.y * p.y));
  8935. mu = Math.atan2(p.y, p.x);
  8936. if (p.x >= 0.0 && p.x >= Math.abs(p.y)) {
  8937. area.value = AREA_ENUM.AREA_0;
  8938. } else if (p.y >= 0.0 && p.y >= Math.abs(p.x)) {
  8939. area.value = AREA_ENUM.AREA_1;
  8940. mu -= HALF_PI;
  8941. } else if (p.x < 0.0 && -p.x >= Math.abs(p.y)) {
  8942. area.value = AREA_ENUM.AREA_2;
  8943. mu = (mu < 0.0 ? mu + SPI : mu - SPI);
  8944. } else {
  8945. area.value = AREA_ENUM.AREA_3;
  8946. mu += HALF_PI;
  8947. }
  8948. /* Compute phi and theta for the area of definition.
  8949. * The inverse projection is not described in the original paper, but some
  8950. * good hints can be found here (as of 2011-12-14):
  8951. * http://fits.gsfc.nasa.gov/fitsbits/saf.93/saf.9302
  8952. * (search for "Message-Id: <9302181759.AA25477 at fits.cv.nrao.edu>") */
  8953. t = (SPI / 12) * Math.tan(mu);
  8954. tantheta = Math.sin(t) / (Math.cos(t) - (1 / Math.sqrt(2)));
  8955. theta = Math.atan(tantheta);
  8956. cosmu = Math.cos(mu);
  8957. tannu = Math.tan(nu);
  8958. cosphi = 1 - cosmu * cosmu * tannu * tannu * (1 - Math.cos(Math.atan(1 / Math.cos(theta))));
  8959. if (cosphi < -1) {
  8960. cosphi = -1;
  8961. } else if (cosphi > +1) {
  8962. cosphi = +1;
  8963. }
  8964. /* Apply the result to the real area on the cube face.
  8965. * For the top and bottom face, we can compute phi and lam directly.
  8966. * For the other faces, we must use unit sphere cartesian coordinates
  8967. * as an intermediate step. */
  8968. if (this.face === FACE_ENUM.TOP) {
  8969. phi = Math.acos(cosphi);
  8970. lp.phi = HALF_PI - phi;
  8971. if (area.value === AREA_ENUM.AREA_0) {
  8972. lp.lam = theta + HALF_PI;
  8973. } else if (area.value === AREA_ENUM.AREA_1) {
  8974. lp.lam = (theta < 0.0 ? theta + SPI : theta - SPI);
  8975. } else if (area.value === AREA_ENUM.AREA_2) {
  8976. lp.lam = theta - HALF_PI;
  8977. } else /* area.value == AREA_ENUM.AREA_3 */ {
  8978. lp.lam = theta;
  8979. }
  8980. } else if (this.face === FACE_ENUM.BOTTOM) {
  8981. phi = Math.acos(cosphi);
  8982. lp.phi = phi - HALF_PI;
  8983. if (area.value === AREA_ENUM.AREA_0) {
  8984. lp.lam = -theta + HALF_PI;
  8985. } else if (area.value === AREA_ENUM.AREA_1) {
  8986. lp.lam = -theta;
  8987. } else if (area.value === AREA_ENUM.AREA_2) {
  8988. lp.lam = -theta - HALF_PI;
  8989. } else /* area.value == AREA_ENUM.AREA_3 */ {
  8990. lp.lam = (theta < 0.0 ? -theta - SPI : -theta + SPI);
  8991. }
  8992. } else {
  8993. /* Compute phi and lam via cartesian unit sphere coordinates. */
  8994. var q, r, s;
  8995. q = cosphi;
  8996. t = q * q;
  8997. if (t >= 1) {
  8998. s = 0;
  8999. } else {
  9000. s = Math.sqrt(1 - t) * Math.sin(theta);
  9001. }
  9002. t += s * s;
  9003. if (t >= 1) {
  9004. r = 0;
  9005. } else {
  9006. r = Math.sqrt(1 - t);
  9007. }
  9008. /* Rotate q,r,s into the correct area. */
  9009. if (area.value === AREA_ENUM.AREA_1) {
  9010. t = r;
  9011. r = -s;
  9012. s = t;
  9013. } else if (area.value === AREA_ENUM.AREA_2) {
  9014. r = -r;
  9015. s = -s;
  9016. } else if (area.value === AREA_ENUM.AREA_3) {
  9017. t = r;
  9018. r = s;
  9019. s = -t;
  9020. }
  9021. /* Rotate q,r,s into the correct cube face. */
  9022. if (this.face === FACE_ENUM.RIGHT) {
  9023. t = q;
  9024. q = -r;
  9025. r = t;
  9026. } else if (this.face === FACE_ENUM.BACK) {
  9027. q = -q;
  9028. r = -r;
  9029. } else if (this.face === FACE_ENUM.LEFT) {
  9030. t = q;
  9031. q = r;
  9032. r = -t;
  9033. }
  9034. /* Now compute phi and lam from the unit sphere coordinates. */
  9035. lp.phi = Math.acos(-s) - HALF_PI;
  9036. lp.lam = Math.atan2(r, q);
  9037. if (this.face === FACE_ENUM.RIGHT) {
  9038. lp.lam = qsc_shift_lon_origin(lp.lam, -HALF_PI);
  9039. } else if (this.face === FACE_ENUM.BACK) {
  9040. lp.lam = qsc_shift_lon_origin(lp.lam, -SPI);
  9041. } else if (this.face === FACE_ENUM.LEFT) {
  9042. lp.lam = qsc_shift_lon_origin(lp.lam, +HALF_PI);
  9043. }
  9044. }
  9045. /* Apply the shift from the sphere to the ellipsoid as described
  9046. * in [LK12]. */
  9047. if (this.es !== 0) {
  9048. var invert_sign;
  9049. var tanphi, xa;
  9050. invert_sign = (lp.phi < 0 ? 1 : 0);
  9051. tanphi = Math.tan(lp.phi);
  9052. xa = this.b / Math.sqrt(tanphi * tanphi + this.one_minus_f_squared);
  9053. lp.phi = Math.atan(Math.sqrt(this.a * this.a - xa * xa) / (this.one_minus_f * xa));
  9054. if (invert_sign) {
  9055. lp.phi = -lp.phi;
  9056. }
  9057. }
  9058. lp.lam += this.long0;
  9059. p.x = lp.lam;
  9060. p.y = lp.phi;
  9061. return p;
  9062. }
  9063. /* Helper function for forward projection: compute the theta angle
  9064. * and determine the area number. */
  9065. function qsc_fwd_equat_face_theta(phi, y, x, area) {
  9066. var theta;
  9067. if (phi < EPSLN) {
  9068. area.value = AREA_ENUM.AREA_0;
  9069. theta = 0.0;
  9070. } else {
  9071. theta = Math.atan2(y, x);
  9072. if (Math.abs(theta) <= FORTPI) {
  9073. area.value = AREA_ENUM.AREA_0;
  9074. } else if (theta > FORTPI && theta <= HALF_PI + FORTPI) {
  9075. area.value = AREA_ENUM.AREA_1;
  9076. theta -= HALF_PI;
  9077. } else if (theta > HALF_PI + FORTPI || theta <= -(HALF_PI + FORTPI)) {
  9078. area.value = AREA_ENUM.AREA_2;
  9079. theta = (theta >= 0.0 ? theta - SPI : theta + SPI);
  9080. } else {
  9081. area.value = AREA_ENUM.AREA_3;
  9082. theta += HALF_PI;
  9083. }
  9084. }
  9085. return theta;
  9086. }
  9087. /* Helper function: shift the longitude. */
  9088. function qsc_shift_lon_origin(lon, offset) {
  9089. var slon = lon + offset;
  9090. if (slon < -SPI) {
  9091. slon += TWO_PI;
  9092. } else if (slon > +SPI) {
  9093. slon -= TWO_PI;
  9094. }
  9095. return slon;
  9096. }
  9097. var names$28 = ["Quadrilateralized Spherical Cube", "Quadrilateralized_Spherical_Cube", "qsc"];
  9098. var qsc = {
  9099. init: init$27,
  9100. forward: forward$26,
  9101. inverse: inverse$26,
  9102. names: names$28
  9103. };
  9104. // Robinson projection
  9105. // Based on https://github.com/OSGeo/proj.4/blob/master/src/PJ_robin.c
  9106. // Polynomial coeficients from http://article.gmane.org/gmane.comp.gis.proj-4.devel/6039
  9107. var COEFS_X = [
  9108. [1.0000, 2.2199e-17, -7.15515e-05, 3.1103e-06],
  9109. [0.9986, -0.000482243, -2.4897e-05, -1.3309e-06],
  9110. [0.9954, -0.00083103, -4.48605e-05, -9.86701e-07],
  9111. [0.9900, -0.00135364, -5.9661e-05, 3.6777e-06],
  9112. [0.9822, -0.00167442, -4.49547e-06, -5.72411e-06],
  9113. [0.9730, -0.00214868, -9.03571e-05, 1.8736e-08],
  9114. [0.9600, -0.00305085, -9.00761e-05, 1.64917e-06],
  9115. [0.9427, -0.00382792, -6.53386e-05, -2.6154e-06],
  9116. [0.9216, -0.00467746, -0.00010457, 4.81243e-06],
  9117. [0.8962, -0.00536223, -3.23831e-05, -5.43432e-06],
  9118. [0.8679, -0.00609363, -0.000113898, 3.32484e-06],
  9119. [0.8350, -0.00698325, -6.40253e-05, 9.34959e-07],
  9120. [0.7986, -0.00755338, -5.00009e-05, 9.35324e-07],
  9121. [0.7597, -0.00798324, -3.5971e-05, -2.27626e-06],
  9122. [0.7186, -0.00851367, -7.01149e-05, -8.6303e-06],
  9123. [0.6732, -0.00986209, -0.000199569, 1.91974e-05],
  9124. [0.6213, -0.010418, 8.83923e-05, 6.24051e-06],
  9125. [0.5722, -0.00906601, 0.000182, 6.24051e-06],
  9126. [0.5322, -0.00677797, 0.000275608, 6.24051e-06]
  9127. ];
  9128. var COEFS_Y = [
  9129. [-5.20417e-18, 0.0124, 1.21431e-18, -8.45284e-11],
  9130. [0.0620, 0.0124, -1.26793e-09, 4.22642e-10],
  9131. [0.1240, 0.0124, 5.07171e-09, -1.60604e-09],
  9132. [0.1860, 0.0123999, -1.90189e-08, 6.00152e-09],
  9133. [0.2480, 0.0124002, 7.10039e-08, -2.24e-08],
  9134. [0.3100, 0.0123992, -2.64997e-07, 8.35986e-08],
  9135. [0.3720, 0.0124029, 9.88983e-07, -3.11994e-07],
  9136. [0.4340, 0.0123893, -3.69093e-06, -4.35621e-07],
  9137. [0.4958, 0.0123198, -1.02252e-05, -3.45523e-07],
  9138. [0.5571, 0.0121916, -1.54081e-05, -5.82288e-07],
  9139. [0.6176, 0.0119938, -2.41424e-05, -5.25327e-07],
  9140. [0.6769, 0.011713, -3.20223e-05, -5.16405e-07],
  9141. [0.7346, 0.0113541, -3.97684e-05, -6.09052e-07],
  9142. [0.7903, 0.0109107, -4.89042e-05, -1.04739e-06],
  9143. [0.8435, 0.0103431, -6.4615e-05, -1.40374e-09],
  9144. [0.8936, 0.00969686, -6.4636e-05, -8.547e-06],
  9145. [0.9394, 0.00840947, -0.000192841, -4.2106e-06],
  9146. [0.9761, 0.00616527, -0.000256, -4.2106e-06],
  9147. [1.0000, 0.00328947, -0.000319159, -4.2106e-06]
  9148. ];
  9149. var FXC = 0.8487;
  9150. var FYC = 1.3523;
  9151. var C1 = R2D / 5; // rad to 5-degree interval
  9152. var RC1 = 1 / C1;
  9153. var NODES = 18;
  9154. var poly3_val = function (coefs, x) {
  9155. return coefs[0] + x * (coefs[1] + x * (coefs[2] + x * coefs[3]));
  9156. };
  9157. var poly3_der = function (coefs, x) {
  9158. return coefs[1] + x * (2 * coefs[2] + x * 3 * coefs[3]);
  9159. };
  9160. function newton_rapshon(f_df, start, max_err, iters) {
  9161. var x = start;
  9162. for (; iters; --iters) {
  9163. var upd = f_df(x);
  9164. x -= upd;
  9165. if (Math.abs(upd) < max_err) {
  9166. break;
  9167. }
  9168. }
  9169. return x;
  9170. }
  9171. function init$28() {
  9172. this.x0 = this.x0 || 0;
  9173. this.y0 = this.y0 || 0;
  9174. this.long0 = this.long0 || 0;
  9175. this.es = 0;
  9176. this.title = this.title || "Robinson";
  9177. }
  9178. function forward$27(ll) {
  9179. var lon = adjust_lon(ll.x - this.long0);
  9180. var dphi = Math.abs(ll.y);
  9181. var i = Math.floor(dphi * C1);
  9182. if (i < 0) {
  9183. i = 0;
  9184. } else if (i >= NODES) {
  9185. i = NODES - 1;
  9186. }
  9187. dphi = R2D * (dphi - RC1 * i);
  9188. var xy = {
  9189. x: poly3_val(COEFS_X[i], dphi) * lon,
  9190. y: poly3_val(COEFS_Y[i], dphi)
  9191. };
  9192. if (ll.y < 0) {
  9193. xy.y = -xy.y;
  9194. }
  9195. xy.x = xy.x * this.a * FXC + this.x0;
  9196. xy.y = xy.y * this.a * FYC + this.y0;
  9197. return xy;
  9198. }
  9199. function inverse$27(xy) {
  9200. var ll = {
  9201. x: (xy.x - this.x0) / (this.a * FXC),
  9202. y: Math.abs(xy.y - this.y0) / (this.a * FYC)
  9203. };
  9204. if (ll.y >= 1) { // pathologic case
  9205. ll.x /= COEFS_X[NODES][0];
  9206. ll.y = xy.y < 0 ? -HALF_PI : HALF_PI;
  9207. } else {
  9208. // find table interval
  9209. var i = Math.floor(ll.y * NODES);
  9210. if (i < 0) {
  9211. i = 0;
  9212. } else if (i >= NODES) {
  9213. i = NODES - 1;
  9214. }
  9215. for (; ;) {
  9216. if (COEFS_Y[i][0] > ll.y) {
  9217. --i;
  9218. } else if (COEFS_Y[i + 1][0] <= ll.y) {
  9219. ++i;
  9220. } else {
  9221. break;
  9222. }
  9223. }
  9224. // linear interpolation in 5 degree interval
  9225. var coefs = COEFS_Y[i];
  9226. var t = 5 * (ll.y - coefs[0]) / (COEFS_Y[i + 1][0] - coefs[0]);
  9227. // find t so that poly3_val(coefs, t) = ll.y
  9228. t = newton_rapshon(function (x) {
  9229. return (poly3_val(coefs, x) - ll.y) / poly3_der(coefs, x);
  9230. }, t, EPSLN, 100);
  9231. ll.x /= poly3_val(COEFS_X[i], t);
  9232. ll.y = (5 * i + t) * D2R;
  9233. if (xy.y < 0) {
  9234. ll.y = -ll.y;
  9235. }
  9236. }
  9237. ll.x = adjust_lon(ll.x + this.long0);
  9238. return ll;
  9239. }
  9240. var names$29 = ["Robinson", "robin"];
  9241. var robin = {
  9242. init: init$28,
  9243. forward: forward$27,
  9244. inverse: inverse$27,
  9245. names: names$29
  9246. };
  9247. function init$29() {
  9248. this.name = 'geocent';
  9249. }
  9250. function forward$28(p) {
  9251. var point = geodeticToGeocentric(p, this.es, this.a);
  9252. return point;
  9253. }
  9254. function inverse$28(p) {
  9255. var point = geocentricToGeodetic(p, this.es, this.a, this.b);
  9256. return point;
  9257. }
  9258. var names$30 = ["Geocentric", 'geocentric', "geocent", "Geocent"];
  9259. var geocent = {
  9260. init: init$29,
  9261. forward: forward$28,
  9262. inverse: inverse$28,
  9263. names: names$30
  9264. };
  9265. var mode = {
  9266. N_POLE: 0,
  9267. S_POLE: 1,
  9268. EQUIT: 2,
  9269. OBLIQ: 3
  9270. };
  9271. var params = {
  9272. h: { def: 100000, num: true }, // default is Karman line, no default in PROJ.7
  9273. azi: { def: 0, num: true, degrees: true }, // default is North
  9274. tilt: { def: 0, num: true, degrees: true }, // default is Nadir
  9275. long0: { def: 0, num: true }, // default is Greenwich, conversion to rad is automatic
  9276. lat0: { def: 0, num: true } // default is Equator, conversion to rad is automatic
  9277. };
  9278. function init$30() {
  9279. Object.keys(params).forEach(function (p) {
  9280. if (typeof this[p] === "undefined") {
  9281. this[p] = params[p].def;
  9282. } else if (params[p].num && isNaN(this[p])) {
  9283. throw new Error("Invalid parameter value, must be numeric " + p + " = " + this[p]);
  9284. } else if (params[p].num) {
  9285. this[p] = parseFloat(this[p]);
  9286. }
  9287. if (params[p].degrees) {
  9288. this[p] = this[p] * D2R;
  9289. }
  9290. }.bind(this));
  9291. if (Math.abs((Math.abs(this.lat0) - HALF_PI)) < EPSLN) {
  9292. this.mode = this.lat0 < 0 ? mode.S_POLE : mode.N_POLE;
  9293. } else if (Math.abs(this.lat0) < EPSLN) {
  9294. this.mode = mode.EQUIT;
  9295. } else {
  9296. this.mode = mode.OBLIQ;
  9297. this.sinph0 = Math.sin(this.lat0);
  9298. this.cosph0 = Math.cos(this.lat0);
  9299. }
  9300. this.pn1 = this.h / this.a; // Normalize relative to the Earth's radius
  9301. if (this.pn1 <= 0 || this.pn1 > 1e10) {
  9302. throw new Error("Invalid height");
  9303. }
  9304. this.p = 1 + this.pn1;
  9305. this.rp = 1 / this.p;
  9306. this.h1 = 1 / this.pn1;
  9307. this.pfact = (this.p + 1) * this.h1;
  9308. this.es = 0;
  9309. var omega = this.tilt;
  9310. var gamma = this.azi;
  9311. this.cg = Math.cos(gamma);
  9312. this.sg = Math.sin(gamma);
  9313. this.cw = Math.cos(omega);
  9314. this.sw = Math.sin(omega);
  9315. }
  9316. function forward$29(p) {
  9317. p.x -= this.long0;
  9318. var sinphi = Math.sin(p.y);
  9319. var cosphi = Math.cos(p.y);
  9320. var coslam = Math.cos(p.x);
  9321. var x, y;
  9322. switch (this.mode) {
  9323. case mode.OBLIQ:
  9324. y = this.sinph0 * sinphi + this.cosph0 * cosphi * coslam;
  9325. break;
  9326. case mode.EQUIT:
  9327. y = cosphi * coslam;
  9328. break;
  9329. case mode.S_POLE:
  9330. y = -sinphi;
  9331. break;
  9332. case mode.N_POLE:
  9333. y = sinphi;
  9334. break;
  9335. }
  9336. y = this.pn1 / (this.p - y);
  9337. x = y * cosphi * Math.sin(p.x);
  9338. switch (this.mode) {
  9339. case mode.OBLIQ:
  9340. y *= this.cosph0 * sinphi - this.sinph0 * cosphi * coslam;
  9341. break;
  9342. case mode.EQUIT:
  9343. y *= sinphi;
  9344. break;
  9345. case mode.N_POLE:
  9346. y *= -(cosphi * coslam);
  9347. break;
  9348. case mode.S_POLE:
  9349. y *= cosphi * coslam;
  9350. break;
  9351. }
  9352. // Tilt
  9353. var yt, ba;
  9354. yt = y * this.cg + x * this.sg;
  9355. ba = 1 / (yt * this.sw * this.h1 + this.cw);
  9356. x = (x * this.cg - y * this.sg) * this.cw * ba;
  9357. y = yt * ba;
  9358. p.x = x * this.a;
  9359. p.y = y * this.a;
  9360. return p;
  9361. }
  9362. function inverse$29(p) {
  9363. p.x /= this.a;
  9364. p.y /= this.a;
  9365. var r = { x: p.x, y: p.y };
  9366. // Un-Tilt
  9367. var bm, bq, yt;
  9368. yt = 1 / (this.pn1 - p.y * this.sw);
  9369. bm = this.pn1 * p.x * yt;
  9370. bq = this.pn1 * p.y * this.cw * yt;
  9371. p.x = bm * this.cg + bq * this.sg;
  9372. p.y = bq * this.cg - bm * this.sg;
  9373. var rh = hypot(p.x, p.y);
  9374. if (Math.abs(rh) < EPSLN) {
  9375. r.x = 0;
  9376. r.y = p.y;
  9377. } else {
  9378. var cosz, sinz;
  9379. sinz = 1 - rh * rh * this.pfact;
  9380. sinz = (this.p - Math.sqrt(sinz)) / (this.pn1 / rh + rh / this.pn1);
  9381. cosz = Math.sqrt(1 - sinz * sinz);
  9382. switch (this.mode) {
  9383. case mode.OBLIQ:
  9384. r.y = Math.asin(cosz * this.sinph0 + p.y * sinz * this.cosph0 / rh);
  9385. p.y = (cosz - this.sinph0 * Math.sin(r.y)) * rh;
  9386. p.x *= sinz * this.cosph0;
  9387. break;
  9388. case mode.EQUIT:
  9389. r.y = Math.asin(p.y * sinz / rh);
  9390. p.y = cosz * rh;
  9391. p.x *= sinz;
  9392. break;
  9393. case mode.N_POLE:
  9394. r.y = Math.asin(cosz);
  9395. p.y = -p.y;
  9396. break;
  9397. case mode.S_POLE:
  9398. r.y = -Math.asin(cosz);
  9399. break;
  9400. }
  9401. r.x = Math.atan2(p.x, p.y);
  9402. }
  9403. p.x = r.x + this.long0;
  9404. p.y = r.y;
  9405. return p;
  9406. }
  9407. var names$31 = ["Tilted_Perspective", "tpers"];
  9408. var tpers = {
  9409. init: init$30,
  9410. forward: forward$29,
  9411. inverse: inverse$29,
  9412. names: names$31
  9413. };
  9414. var includedProjections = function (proj4) {
  9415. proj4.Proj.projections.add(tmerc);
  9416. proj4.Proj.projections.add(etmerc);
  9417. proj4.Proj.projections.add(utm);
  9418. proj4.Proj.projections.add(sterea);
  9419. proj4.Proj.projections.add(stere);
  9420. proj4.Proj.projections.add(somerc);
  9421. proj4.Proj.projections.add(omerc);
  9422. proj4.Proj.projections.add(lcc);
  9423. proj4.Proj.projections.add(krovak);
  9424. proj4.Proj.projections.add(cass);
  9425. proj4.Proj.projections.add(laea);
  9426. proj4.Proj.projections.add(aea);
  9427. proj4.Proj.projections.add(gnom);
  9428. proj4.Proj.projections.add(cea);
  9429. proj4.Proj.projections.add(eqc);
  9430. proj4.Proj.projections.add(poly);
  9431. proj4.Proj.projections.add(nzmg);
  9432. proj4.Proj.projections.add(mill);
  9433. proj4.Proj.projections.add(sinu);
  9434. proj4.Proj.projections.add(moll);
  9435. proj4.Proj.projections.add(eqdc);
  9436. proj4.Proj.projections.add(vandg);
  9437. proj4.Proj.projections.add(aeqd);
  9438. proj4.Proj.projections.add(ortho);
  9439. proj4.Proj.projections.add(qsc);
  9440. proj4.Proj.projections.add(robin);
  9441. proj4.Proj.projections.add(geocent);
  9442. proj4.Proj.projections.add(tpers);
  9443. };
  9444. proj4$1.defaultDatum = 'WGS84'; //default datum
  9445. proj4$1.Proj = Projection;
  9446. proj4$1.WGS84 = new proj4$1.Proj('WGS84');
  9447. proj4$1.Point = Point;
  9448. proj4$1.toPoint = toPoint;
  9449. proj4$1.defs = defs;
  9450. proj4$1.nadgrid = nadgrid;
  9451. proj4$1.transform = transform;
  9452. proj4$1.mgrs = mgrs;
  9453. proj4$1.version = '2.7.4';
  9454. includedProjections(proj4$1);
  9455. return proj4$1;
  9456. })));
  9457. }, {}], 18: [function (require, module, exports) {
  9458. /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
  9459. /* eslint-disable node/no-deprecated-api */
  9460. var buffer = require('buffer')
  9461. var Buffer = buffer.Buffer
  9462. // alternative to using Object.keys for old browsers
  9463. function copyProps(src, dst) {
  9464. for (var key in src) {
  9465. dst[key] = src[key]
  9466. }
  9467. }
  9468. if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
  9469. module.exports = buffer
  9470. } else {
  9471. // Copy properties from require('buffer')
  9472. copyProps(buffer, exports)
  9473. exports.Buffer = SafeBuffer
  9474. }
  9475. function SafeBuffer(arg, encodingOrOffset, length) {
  9476. return Buffer(arg, encodingOrOffset, length)
  9477. }
  9478. SafeBuffer.prototype = Object.create(Buffer.prototype)
  9479. // Copy static methods from Buffer
  9480. copyProps(Buffer, SafeBuffer)
  9481. SafeBuffer.from = function (arg, encodingOrOffset, length) {
  9482. if (typeof arg === 'number') {
  9483. throw new TypeError('Argument must not be a number')
  9484. }
  9485. return Buffer(arg, encodingOrOffset, length)
  9486. }
  9487. SafeBuffer.alloc = function (size, fill, encoding) {
  9488. if (typeof size !== 'number') {
  9489. throw new TypeError('Argument must be a number')
  9490. }
  9491. var buf = Buffer(size)
  9492. if (fill !== undefined) {
  9493. if (typeof encoding === 'string') {
  9494. buf.fill(fill, encoding)
  9495. } else {
  9496. buf.fill(fill)
  9497. }
  9498. } else {
  9499. buf.fill(0)
  9500. }
  9501. return buf
  9502. }
  9503. SafeBuffer.allocUnsafe = function (size) {
  9504. if (typeof size !== 'number') {
  9505. throw new TypeError('Argument must be a number')
  9506. }
  9507. return Buffer(size)
  9508. }
  9509. SafeBuffer.allocUnsafeSlow = function (size) {
  9510. if (typeof size !== 'number') {
  9511. throw new TypeError('Argument must be a number')
  9512. }
  9513. return buffer.SlowBuffer(size)
  9514. }
  9515. }, { "buffer": 8 }], 19: [function (require, module, exports) {
  9516. // Copyright Joyent, Inc. and other Node contributors.
  9517. //
  9518. // Permission is hereby granted, free of charge, to any person obtaining a
  9519. // copy of this software and associated documentation files (the
  9520. // "Software"), to deal in the Software without restriction, including
  9521. // without limitation the rights to use, copy, modify, merge, publish,
  9522. // distribute, sublicense, and/or sell copies of the Software, and to permit
  9523. // persons to whom the Software is furnished to do so, subject to the
  9524. // following conditions:
  9525. //
  9526. // The above copyright notice and this permission notice shall be included
  9527. // in all copies or substantial portions of the Software.
  9528. //
  9529. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  9530. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  9531. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  9532. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  9533. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  9534. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  9535. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  9536. 'use strict';
  9537. /*<replacement>*/
  9538. var Buffer = require('safe-buffer').Buffer;
  9539. /*</replacement>*/
  9540. var isEncoding = Buffer.isEncoding || function (encoding) {
  9541. encoding = '' + encoding;
  9542. switch (encoding && encoding.toLowerCase()) {
  9543. case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'binary': case 'base64': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': case 'raw':
  9544. return true;
  9545. default:
  9546. return false;
  9547. }
  9548. };
  9549. function _normalizeEncoding(enc) {
  9550. if (!enc) return 'utf8';
  9551. var retried;
  9552. while (true) {
  9553. switch (enc) {
  9554. case 'utf8':
  9555. case 'utf-8':
  9556. return 'utf8';
  9557. case 'ucs2':
  9558. case 'ucs-2':
  9559. case 'utf16le':
  9560. case 'utf-16le':
  9561. return 'utf16le';
  9562. case 'latin1':
  9563. case 'binary':
  9564. return 'latin1';
  9565. case 'base64':
  9566. case 'ascii':
  9567. case 'hex':
  9568. return enc;
  9569. default:
  9570. if (retried) return; // undefined
  9571. enc = ('' + enc).toLowerCase();
  9572. retried = true;
  9573. }
  9574. }
  9575. };
  9576. // Do not cache `Buffer.isEncoding` when checking encoding names as some
  9577. // modules monkey-patch it to support additional encodings
  9578. function normalizeEncoding(enc) {
  9579. var nenc = _normalizeEncoding(enc);
  9580. if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
  9581. return nenc || enc;
  9582. }
  9583. // StringDecoder provides an interface for efficiently splitting a series of
  9584. // buffers into a series of JS strings without breaking apart multi-byte
  9585. // characters.
  9586. exports.StringDecoder = StringDecoder;
  9587. function StringDecoder(encoding) {
  9588. this.encoding = normalizeEncoding(encoding);
  9589. var nb;
  9590. switch (this.encoding) {
  9591. case 'utf16le':
  9592. this.text = utf16Text;
  9593. this.end = utf16End;
  9594. nb = 4;
  9595. break;
  9596. case 'utf8':
  9597. this.fillLast = utf8FillLast;
  9598. nb = 4;
  9599. break;
  9600. case 'base64':
  9601. this.text = base64Text;
  9602. this.end = base64End;
  9603. nb = 3;
  9604. break;
  9605. default:
  9606. this.write = simpleWrite;
  9607. this.end = simpleEnd;
  9608. return;
  9609. }
  9610. this.lastNeed = 0;
  9611. this.lastTotal = 0;
  9612. this.lastChar = Buffer.allocUnsafe(nb);
  9613. }
  9614. StringDecoder.prototype.write = function (buf) {
  9615. if (buf.length === 0) return '';
  9616. var r;
  9617. var i;
  9618. if (this.lastNeed) {
  9619. r = this.fillLast(buf);
  9620. if (r === undefined) return '';
  9621. i = this.lastNeed;
  9622. this.lastNeed = 0;
  9623. } else {
  9624. i = 0;
  9625. }
  9626. if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
  9627. return r || '';
  9628. };
  9629. StringDecoder.prototype.end = utf8End;
  9630. // Returns only complete characters in a Buffer
  9631. StringDecoder.prototype.text = utf8Text;
  9632. // Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
  9633. StringDecoder.prototype.fillLast = function (buf) {
  9634. if (this.lastNeed <= buf.length) {
  9635. buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
  9636. return this.lastChar.toString(this.encoding, 0, this.lastTotal);
  9637. }
  9638. buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
  9639. this.lastNeed -= buf.length;
  9640. };
  9641. // Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
  9642. // continuation byte. If an invalid byte is detected, -2 is returned.
  9643. function utf8CheckByte(byte) {
  9644. 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;
  9645. return byte >> 6 === 0x02 ? -1 : -2;
  9646. }
  9647. // Checks at most 3 bytes at the end of a Buffer in order to detect an
  9648. // incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4)
  9649. // needed to complete the UTF-8 character (if applicable) are returned.
  9650. function utf8CheckIncomplete(self, buf, i) {
  9651. var j = buf.length - 1;
  9652. if (j < i) return 0;
  9653. var nb = utf8CheckByte(buf[j]);
  9654. if (nb >= 0) {
  9655. if (nb > 0) self.lastNeed = nb - 1;
  9656. return nb;
  9657. }
  9658. if (--j < i || nb === -2) return 0;
  9659. nb = utf8CheckByte(buf[j]);
  9660. if (nb >= 0) {
  9661. if (nb > 0) self.lastNeed = nb - 2;
  9662. return nb;
  9663. }
  9664. if (--j < i || nb === -2) return 0;
  9665. nb = utf8CheckByte(buf[j]);
  9666. if (nb >= 0) {
  9667. if (nb > 0) {
  9668. if (nb === 2) nb = 0; else self.lastNeed = nb - 3;
  9669. }
  9670. return nb;
  9671. }
  9672. return 0;
  9673. }
  9674. // Validates as many continuation bytes for a multi-byte UTF-8 character as
  9675. // needed or are available. If we see a non-continuation byte where we expect
  9676. // one, we "replace" the validated continuation bytes we've seen so far with
  9677. // a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding
  9678. // behavior. The continuation byte check is included three times in the case
  9679. // where all of the continuation bytes for a character exist in the same buffer.
  9680. // It is also done this way as a slight performance increase instead of using a
  9681. // loop.
  9682. function utf8CheckExtraBytes(self, buf, p) {
  9683. if ((buf[0] & 0xC0) !== 0x80) {
  9684. self.lastNeed = 0;
  9685. return '\ufffd';
  9686. }
  9687. if (self.lastNeed > 1 && buf.length > 1) {
  9688. if ((buf[1] & 0xC0) !== 0x80) {
  9689. self.lastNeed = 1;
  9690. return '\ufffd';
  9691. }
  9692. if (self.lastNeed > 2 && buf.length > 2) {
  9693. if ((buf[2] & 0xC0) !== 0x80) {
  9694. self.lastNeed = 2;
  9695. return '\ufffd';
  9696. }
  9697. }
  9698. }
  9699. }
  9700. // Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
  9701. function utf8FillLast(buf) {
  9702. var p = this.lastTotal - this.lastNeed;
  9703. var r = utf8CheckExtraBytes(this, buf, p);
  9704. if (r !== undefined) return r;
  9705. if (this.lastNeed <= buf.length) {
  9706. buf.copy(this.lastChar, p, 0, this.lastNeed);
  9707. return this.lastChar.toString(this.encoding, 0, this.lastTotal);
  9708. }
  9709. buf.copy(this.lastChar, p, 0, buf.length);
  9710. this.lastNeed -= buf.length;
  9711. }
  9712. // Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a
  9713. // partial character, the character's bytes are buffered until the required
  9714. // number of bytes are available.
  9715. function utf8Text(buf, i) {
  9716. var total = utf8CheckIncomplete(this, buf, i);
  9717. if (!this.lastNeed) return buf.toString('utf8', i);
  9718. this.lastTotal = total;
  9719. var end = buf.length - (total - this.lastNeed);
  9720. buf.copy(this.lastChar, 0, end);
  9721. return buf.toString('utf8', i, end);
  9722. }
  9723. // For UTF-8, a replacement character is added when ending on a partial
  9724. // character.
  9725. function utf8End(buf) {
  9726. var r = buf && buf.length ? this.write(buf) : '';
  9727. if (this.lastNeed) return r + '\ufffd';
  9728. return r;
  9729. }
  9730. // UTF-16LE typically needs two bytes per character, but even if we have an even
  9731. // number of bytes available, we need to check if we end on a leading/high
  9732. // surrogate. In that case, we need to wait for the next two bytes in order to
  9733. // decode the last character properly.
  9734. function utf16Text(buf, i) {
  9735. if ((buf.length - i) % 2 === 0) {
  9736. var r = buf.toString('utf16le', i);
  9737. if (r) {
  9738. var c = r.charCodeAt(r.length - 1);
  9739. if (c >= 0xD800 && c <= 0xDBFF) {
  9740. this.lastNeed = 2;
  9741. this.lastTotal = 4;
  9742. this.lastChar[0] = buf[buf.length - 2];
  9743. this.lastChar[1] = buf[buf.length - 1];
  9744. return r.slice(0, -1);
  9745. }
  9746. }
  9747. return r;
  9748. }
  9749. this.lastNeed = 1;
  9750. this.lastTotal = 2;
  9751. this.lastChar[0] = buf[buf.length - 1];
  9752. return buf.toString('utf16le', i, buf.length - 1);
  9753. }
  9754. // For UTF-16LE we do not explicitly append special replacement characters if we
  9755. // end on a partial character, we simply let v8 handle that.
  9756. function utf16End(buf) {
  9757. var r = buf && buf.length ? this.write(buf) : '';
  9758. if (this.lastNeed) {
  9759. var end = this.lastTotal - this.lastNeed;
  9760. return r + this.lastChar.toString('utf16le', 0, end);
  9761. }
  9762. return r;
  9763. }
  9764. function base64Text(buf, i) {
  9765. var n = (buf.length - i) % 3;
  9766. if (n === 0) return buf.toString('base64', i);
  9767. this.lastNeed = 3 - n;
  9768. this.lastTotal = 3;
  9769. if (n === 1) {
  9770. this.lastChar[0] = buf[buf.length - 1];
  9771. } else {
  9772. this.lastChar[0] = buf[buf.length - 2];
  9773. this.lastChar[1] = buf[buf.length - 1];
  9774. }
  9775. return buf.toString('base64', i, buf.length - n);
  9776. }
  9777. function base64End(buf) {
  9778. var r = buf && buf.length ? this.write(buf) : '';
  9779. if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
  9780. return r;
  9781. }
  9782. // Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex)
  9783. function simpleWrite(buf) {
  9784. return buf.toString(this.encoding);
  9785. }
  9786. function simpleEnd(buf) {
  9787. return buf && buf.length ? this.write(buf) : '';
  9788. }
  9789. }, { "safe-buffer": 18 }], 20: [function (require, module, exports) {
  9790. // This is free and unencumbered software released into the public domain.
  9791. // See LICENSE.md for more information.
  9792. module.exports = require("./lib/encoding.js");
  9793. }, { "./lib/encoding.js": 21 }], 21: [function (require, module, exports) {
  9794. // This is free and unencumbered software released into the public domain.
  9795. // See LICENSE.md for more information.
  9796. /**
  9797. * @fileoverview Global |this| required for resolving indexes in node.
  9798. * @suppress {globalThis}
  9799. */
  9800. (function (global) {
  9801. 'use strict';
  9802. // If we're in node require encoding-indexes and attach it to the global.
  9803. if (typeof module !== "undefined" && module.exports &&
  9804. !global["encoding-indexes"]) {
  9805. require("./encoding-indexes.js");
  9806. }
  9807. //
  9808. // Utilities
  9809. //
  9810. /**
  9811. * @param {number} a The number to test.
  9812. * @param {number} min The minimum value in the range, inclusive.
  9813. * @param {number} max The maximum value in the range, inclusive.
  9814. * @return {boolean} True if a >= min and a <= max.
  9815. */
  9816. function inRange(a, min, max) {
  9817. return min <= a && a <= max;
  9818. }
  9819. /**
  9820. * @param {!Array.<*>} array The array to check.
  9821. * @param {*} item The item to look for in the array.
  9822. * @return {boolean} True if the item appears in the array.
  9823. */
  9824. function includes(array, item) {
  9825. return array.indexOf(item) !== -1;
  9826. }
  9827. var floor = Math.floor;
  9828. /**
  9829. * @param {*} o
  9830. * @return {Object}
  9831. */
  9832. function ToDictionary(o) {
  9833. if (o === undefined) return {};
  9834. if (o === Object(o)) return o;
  9835. throw TypeError('Could not convert argument to dictionary');
  9836. }
  9837. /**
  9838. * @param {string} string Input string of UTF-16 code units.
  9839. * @return {!Array.<number>} Code points.
  9840. */
  9841. function stringToCodePoints(string) {
  9842. // https://heycam.github.io/webidl/#dfn-obtain-unicode
  9843. // 1. Let S be the DOMString value.
  9844. var s = String(string);
  9845. // 2. Let n be the length of S.
  9846. var n = s.length;
  9847. // 3. Initialize i to 0.
  9848. var i = 0;
  9849. // 4. Initialize U to be an empty sequence of Unicode characters.
  9850. var u = [];
  9851. // 5. While i < n:
  9852. while (i < n) {
  9853. // 1. Let c be the code unit in S at index i.
  9854. var c = s.charCodeAt(i);
  9855. // 2. Depending on the value of c:
  9856. // c < 0xD800 or c > 0xDFFF
  9857. if (c < 0xD800 || c > 0xDFFF) {
  9858. // Append to U the Unicode character with code point c.
  9859. u.push(c);
  9860. }
  9861. // 0xDC00 ≤ c ≤ 0xDFFF
  9862. else if (0xDC00 <= c && c <= 0xDFFF) {
  9863. // Append to U a U+FFFD REPLACEMENT CHARACTER.
  9864. u.push(0xFFFD);
  9865. }
  9866. // 0xD800 ≤ c ≤ 0xDBFF
  9867. else if (0xD800 <= c && c <= 0xDBFF) {
  9868. // 1. If i = n−1, then append to U a U+FFFD REPLACEMENT
  9869. // CHARACTER.
  9870. if (i === n - 1) {
  9871. u.push(0xFFFD);
  9872. }
  9873. // 2. Otherwise, i < n−1:
  9874. else {
  9875. // 1. Let d be the code unit in S at index i+1.
  9876. var d = s.charCodeAt(i + 1);
  9877. // 2. If 0xDC00 ≤ d ≤ 0xDFFF, then:
  9878. if (0xDC00 <= d && d <= 0xDFFF) {
  9879. // 1. Let a be c & 0x3FF.
  9880. var a = c & 0x3FF;
  9881. // 2. Let b be d & 0x3FF.
  9882. var b = d & 0x3FF;
  9883. // 3. Append to U the Unicode character with code point
  9884. // 2^16+2^10*a+b.
  9885. u.push(0x10000 + (a << 10) + b);
  9886. // 4. Set i to i+1.
  9887. i += 1;
  9888. }
  9889. // 3. Otherwise, d < 0xDC00 or d > 0xDFFF. Append to U a
  9890. // U+FFFD REPLACEMENT CHARACTER.
  9891. else {
  9892. u.push(0xFFFD);
  9893. }
  9894. }
  9895. }
  9896. // 3. Set i to i+1.
  9897. i += 1;
  9898. }
  9899. // 6. Return U.
  9900. return u;
  9901. }
  9902. /**
  9903. * @param {!Array.<number>} code_points Array of code points.
  9904. * @return {string} string String of UTF-16 code units.
  9905. */
  9906. function codePointsToString(code_points) {
  9907. var s = '';
  9908. for (var i = 0; i < code_points.length; ++i) {
  9909. var cp = code_points[i];
  9910. if (cp <= 0xFFFF) {
  9911. s += String.fromCharCode(cp);
  9912. } else {
  9913. cp -= 0x10000;
  9914. s += String.fromCharCode((cp >> 10) + 0xD800,
  9915. (cp & 0x3FF) + 0xDC00);
  9916. }
  9917. }
  9918. return s;
  9919. }
  9920. //
  9921. // Implementation of Encoding specification
  9922. // https://encoding.spec.whatwg.org/
  9923. //
  9924. //
  9925. // 4. Terminology
  9926. //
  9927. /**
  9928. * An ASCII byte is a byte in the range 0x00 to 0x7F, inclusive.
  9929. * @param {number} a The number to test.
  9930. * @return {boolean} True if a is in the range 0x00 to 0x7F, inclusive.
  9931. */
  9932. function isASCIIByte(a) {
  9933. return 0x00 <= a && a <= 0x7F;
  9934. }
  9935. /**
  9936. * An ASCII code point is a code point in the range U+0000 to
  9937. * U+007F, inclusive.
  9938. */
  9939. var isASCIICodePoint = isASCIIByte;
  9940. /**
  9941. * End-of-stream is a special token that signifies no more tokens
  9942. * are in the stream.
  9943. * @const
  9944. */ var end_of_stream = -1;
  9945. /**
  9946. * A stream represents an ordered sequence of tokens.
  9947. *
  9948. * @constructor
  9949. * @param {!(Array.<number>|Uint8Array)} tokens Array of tokens that provide
  9950. * the stream.
  9951. */
  9952. function Stream(tokens) {
  9953. /** @type {!Array.<number>} */
  9954. this.tokens = [].slice.call(tokens);
  9955. // Reversed as push/pop is more efficient than shift/unshift.
  9956. this.tokens.reverse();
  9957. }
  9958. Stream.prototype = {
  9959. /**
  9960. * @return {boolean} True if end-of-stream has been hit.
  9961. */
  9962. endOfStream: function () {
  9963. return !this.tokens.length;
  9964. },
  9965. /**
  9966. * When a token is read from a stream, the first token in the
  9967. * stream must be returned and subsequently removed, and
  9968. * end-of-stream must be returned otherwise.
  9969. *
  9970. * @return {number} Get the next token from the stream, or
  9971. * end_of_stream.
  9972. */
  9973. read: function () {
  9974. if (!this.tokens.length)
  9975. return end_of_stream;
  9976. return this.tokens.pop();
  9977. },
  9978. /**
  9979. * When one or more tokens are prepended to a stream, those tokens
  9980. * must be inserted, in given order, before the first token in the
  9981. * stream.
  9982. *
  9983. * @param {(number|!Array.<number>)} token The token(s) to prepend to the
  9984. * stream.
  9985. */
  9986. prepend: function (token) {
  9987. if (Array.isArray(token)) {
  9988. var tokens = /**@type {!Array.<number>}*/(token);
  9989. while (tokens.length)
  9990. this.tokens.push(tokens.pop());
  9991. } else {
  9992. this.tokens.push(token);
  9993. }
  9994. },
  9995. /**
  9996. * When one or more tokens are pushed to a stream, those tokens
  9997. * must be inserted, in given order, after the last token in the
  9998. * stream.
  9999. *
  10000. * @param {(number|!Array.<number>)} token The tokens(s) to push to the
  10001. * stream.
  10002. */
  10003. push: function (token) {
  10004. if (Array.isArray(token)) {
  10005. var tokens = /**@type {!Array.<number>}*/(token);
  10006. while (tokens.length)
  10007. this.tokens.unshift(tokens.shift());
  10008. } else {
  10009. this.tokens.unshift(token);
  10010. }
  10011. }
  10012. };
  10013. //
  10014. // 5. Encodings
  10015. //
  10016. // 5.1 Encoders and decoders
  10017. /** @const */
  10018. var finished = -1;
  10019. /**
  10020. * @param {boolean} fatal If true, decoding errors raise an exception.
  10021. * @param {number=} opt_code_point Override the standard fallback code point.
  10022. * @return {number} The code point to insert on a decoding error.
  10023. */
  10024. function decoderError(fatal, opt_code_point) {
  10025. if (fatal)
  10026. throw TypeError('Decoder error');
  10027. return opt_code_point || 0xFFFD;
  10028. }
  10029. /**
  10030. * @param {number} code_point The code point that could not be encoded.
  10031. * @return {number} Always throws, no value is actually returned.
  10032. */
  10033. function encoderError(code_point) {
  10034. throw TypeError('The code point ' + code_point + ' could not be encoded.');
  10035. }
  10036. /** @interface */
  10037. function Decoder() { }
  10038. Decoder.prototype = {
  10039. /**
  10040. * @param {Stream} stream The stream of bytes being decoded.
  10041. * @param {number} bite The next byte read from the stream.
  10042. * @return {?(number|!Array.<number>)} The next code point(s)
  10043. * decoded, or null if not enough data exists in the input
  10044. * stream to decode a complete code point, or |finished|.
  10045. */
  10046. handler: function (stream, bite) { }
  10047. };
  10048. /** @interface */
  10049. function Encoder() { }
  10050. Encoder.prototype = {
  10051. /**
  10052. * @param {Stream} stream The stream of code points being encoded.
  10053. * @param {number} code_point Next code point read from the stream.
  10054. * @return {(number|!Array.<number>)} Byte(s) to emit, or |finished|.
  10055. */
  10056. handler: function (stream, code_point) { }
  10057. };
  10058. // 5.2 Names and labels
  10059. // TODO: Define @typedef for Encoding: {name:string,labels:Array.<string>}
  10060. // https://github.com/google/closure-compiler/issues/247
  10061. /**
  10062. * @param {string} label The encoding label.
  10063. * @return {?{name:string,labels:Array.<string>}}
  10064. */
  10065. function getEncoding(label) {
  10066. // 1. Remove any leading and trailing ASCII whitespace from label.
  10067. label = String(label).trim().toLowerCase();
  10068. // 2. If label is an ASCII case-insensitive match for any of the
  10069. // labels listed in the table below, return the corresponding
  10070. // encoding, and failure otherwise.
  10071. if (Object.prototype.hasOwnProperty.call(label_to_encoding, label)) {
  10072. return label_to_encoding[label];
  10073. }
  10074. return null;
  10075. }
  10076. /**
  10077. * Encodings table: https://encoding.spec.whatwg.org/encodings.json
  10078. * @const
  10079. * @type {!Array.<{
  10080. * heading: string,
  10081. * encodings: Array.<{name:string,labels:Array.<string>}>
  10082. * }>}
  10083. */
  10084. var encodings = [
  10085. {
  10086. "encodings": [
  10087. {
  10088. "labels": [
  10089. "unicode-1-1-utf-8",
  10090. "utf-8",
  10091. "utf8"
  10092. ],
  10093. "name": "UTF-8"
  10094. }
  10095. ],
  10096. "heading": "The Encoding"
  10097. },
  10098. {
  10099. "encodings": [
  10100. {
  10101. "labels": [
  10102. "866",
  10103. "cp866",
  10104. "csibm866",
  10105. "ibm866"
  10106. ],
  10107. "name": "IBM866"
  10108. },
  10109. {
  10110. "labels": [
  10111. "csisolatin2",
  10112. "iso-8859-2",
  10113. "iso-ir-101",
  10114. "iso8859-2",
  10115. "iso88592",
  10116. "iso_8859-2",
  10117. "iso_8859-2:1987",
  10118. "l2",
  10119. "latin2"
  10120. ],
  10121. "name": "ISO-8859-2"
  10122. },
  10123. {
  10124. "labels": [
  10125. "csisolatin3",
  10126. "iso-8859-3",
  10127. "iso-ir-109",
  10128. "iso8859-3",
  10129. "iso88593",
  10130. "iso_8859-3",
  10131. "iso_8859-3:1988",
  10132. "l3",
  10133. "latin3"
  10134. ],
  10135. "name": "ISO-8859-3"
  10136. },
  10137. {
  10138. "labels": [
  10139. "csisolatin4",
  10140. "iso-8859-4",
  10141. "iso-ir-110",
  10142. "iso8859-4",
  10143. "iso88594",
  10144. "iso_8859-4",
  10145. "iso_8859-4:1988",
  10146. "l4",
  10147. "latin4"
  10148. ],
  10149. "name": "ISO-8859-4"
  10150. },
  10151. {
  10152. "labels": [
  10153. "csisolatincyrillic",
  10154. "cyrillic",
  10155. "iso-8859-5",
  10156. "iso-ir-144",
  10157. "iso8859-5",
  10158. "iso88595",
  10159. "iso_8859-5",
  10160. "iso_8859-5:1988"
  10161. ],
  10162. "name": "ISO-8859-5"
  10163. },
  10164. {
  10165. "labels": [
  10166. "arabic",
  10167. "asmo-708",
  10168. "csiso88596e",
  10169. "csiso88596i",
  10170. "csisolatinarabic",
  10171. "ecma-114",
  10172. "iso-8859-6",
  10173. "iso-8859-6-e",
  10174. "iso-8859-6-i",
  10175. "iso-ir-127",
  10176. "iso8859-6",
  10177. "iso88596",
  10178. "iso_8859-6",
  10179. "iso_8859-6:1987"
  10180. ],
  10181. "name": "ISO-8859-6"
  10182. },
  10183. {
  10184. "labels": [
  10185. "csisolatingreek",
  10186. "ecma-118",
  10187. "elot_928",
  10188. "greek",
  10189. "greek8",
  10190. "iso-8859-7",
  10191. "iso-ir-126",
  10192. "iso8859-7",
  10193. "iso88597",
  10194. "iso_8859-7",
  10195. "iso_8859-7:1987",
  10196. "sun_eu_greek"
  10197. ],
  10198. "name": "ISO-8859-7"
  10199. },
  10200. {
  10201. "labels": [
  10202. "csiso88598e",
  10203. "csisolatinhebrew",
  10204. "hebrew",
  10205. "iso-8859-8",
  10206. "iso-8859-8-e",
  10207. "iso-ir-138",
  10208. "iso8859-8",
  10209. "iso88598",
  10210. "iso_8859-8",
  10211. "iso_8859-8:1988",
  10212. "visual"
  10213. ],
  10214. "name": "ISO-8859-8"
  10215. },
  10216. {
  10217. "labels": [
  10218. "csiso88598i",
  10219. "iso-8859-8-i",
  10220. "logical"
  10221. ],
  10222. "name": "ISO-8859-8-I"
  10223. },
  10224. {
  10225. "labels": [
  10226. "csisolatin6",
  10227. "iso-8859-10",
  10228. "iso-ir-157",
  10229. "iso8859-10",
  10230. "iso885910",
  10231. "l6",
  10232. "latin6"
  10233. ],
  10234. "name": "ISO-8859-10"
  10235. },
  10236. {
  10237. "labels": [
  10238. "iso-8859-13",
  10239. "iso8859-13",
  10240. "iso885913"
  10241. ],
  10242. "name": "ISO-8859-13"
  10243. },
  10244. {
  10245. "labels": [
  10246. "iso-8859-14",
  10247. "iso8859-14",
  10248. "iso885914"
  10249. ],
  10250. "name": "ISO-8859-14"
  10251. },
  10252. {
  10253. "labels": [
  10254. "csisolatin9",
  10255. "iso-8859-15",
  10256. "iso8859-15",
  10257. "iso885915",
  10258. "iso_8859-15",
  10259. "l9"
  10260. ],
  10261. "name": "ISO-8859-15"
  10262. },
  10263. {
  10264. "labels": [
  10265. "iso-8859-16"
  10266. ],
  10267. "name": "ISO-8859-16"
  10268. },
  10269. {
  10270. "labels": [
  10271. "cskoi8r",
  10272. "koi",
  10273. "koi8",
  10274. "koi8-r",
  10275. "koi8_r"
  10276. ],
  10277. "name": "KOI8-R"
  10278. },
  10279. {
  10280. "labels": [
  10281. "koi8-ru",
  10282. "koi8-u"
  10283. ],
  10284. "name": "KOI8-U"
  10285. },
  10286. {
  10287. "labels": [
  10288. "csmacintosh",
  10289. "mac",
  10290. "macintosh",
  10291. "x-mac-roman"
  10292. ],
  10293. "name": "macintosh"
  10294. },
  10295. {
  10296. "labels": [
  10297. "dos-874",
  10298. "iso-8859-11",
  10299. "iso8859-11",
  10300. "iso885911",
  10301. "tis-620",
  10302. "windows-874"
  10303. ],
  10304. "name": "windows-874"
  10305. },
  10306. {
  10307. "labels": [
  10308. "cp1250",
  10309. "windows-1250",
  10310. "x-cp1250"
  10311. ],
  10312. "name": "windows-1250"
  10313. },
  10314. {
  10315. "labels": [
  10316. "cp1251",
  10317. "windows-1251",
  10318. "x-cp1251"
  10319. ],
  10320. "name": "windows-1251"
  10321. },
  10322. {
  10323. "labels": [
  10324. "ansi_x3.4-1968",
  10325. "ascii",
  10326. "cp1252",
  10327. "cp819",
  10328. "csisolatin1",
  10329. "ibm819",
  10330. "iso-8859-1",
  10331. "iso-ir-100",
  10332. "iso8859-1",
  10333. "iso88591",
  10334. "iso_8859-1",
  10335. "iso_8859-1:1987",
  10336. "l1",
  10337. "latin1",
  10338. "us-ascii",
  10339. "windows-1252",
  10340. "x-cp1252"
  10341. ],
  10342. "name": "windows-1252"
  10343. },
  10344. {
  10345. "labels": [
  10346. "cp1253",
  10347. "windows-1253",
  10348. "x-cp1253"
  10349. ],
  10350. "name": "windows-1253"
  10351. },
  10352. {
  10353. "labels": [
  10354. "cp1254",
  10355. "csisolatin5",
  10356. "iso-8859-9",
  10357. "iso-ir-148",
  10358. "iso8859-9",
  10359. "iso88599",
  10360. "iso_8859-9",
  10361. "iso_8859-9:1989",
  10362. "l5",
  10363. "latin5",
  10364. "windows-1254",
  10365. "x-cp1254"
  10366. ],
  10367. "name": "windows-1254"
  10368. },
  10369. {
  10370. "labels": [
  10371. "cp1255",
  10372. "windows-1255",
  10373. "x-cp1255"
  10374. ],
  10375. "name": "windows-1255"
  10376. },
  10377. {
  10378. "labels": [
  10379. "cp1256",
  10380. "windows-1256",
  10381. "x-cp1256"
  10382. ],
  10383. "name": "windows-1256"
  10384. },
  10385. {
  10386. "labels": [
  10387. "cp1257",
  10388. "windows-1257",
  10389. "x-cp1257"
  10390. ],
  10391. "name": "windows-1257"
  10392. },
  10393. {
  10394. "labels": [
  10395. "cp1258",
  10396. "windows-1258",
  10397. "x-cp1258"
  10398. ],
  10399. "name": "windows-1258"
  10400. },
  10401. {
  10402. "labels": [
  10403. "x-mac-cyrillic",
  10404. "x-mac-ukrainian"
  10405. ],
  10406. "name": "x-mac-cyrillic"
  10407. }
  10408. ],
  10409. "heading": "Legacy single-byte encodings"
  10410. },
  10411. {
  10412. "encodings": [
  10413. {
  10414. "labels": [
  10415. "chinese",
  10416. "csgb2312",
  10417. "csiso58gb231280",
  10418. "gb2312",
  10419. "gb_2312",
  10420. "gb_2312-80",
  10421. "gbk",
  10422. "iso-ir-58",
  10423. "x-gbk"
  10424. ],
  10425. "name": "GBK"
  10426. },
  10427. {
  10428. "labels": [
  10429. "gb18030"
  10430. ],
  10431. "name": "gb18030"
  10432. }
  10433. ],
  10434. "heading": "Legacy multi-byte Chinese (simplified) encodings"
  10435. },
  10436. {
  10437. "encodings": [
  10438. {
  10439. "labels": [
  10440. "big5",
  10441. "big5-hkscs",
  10442. "cn-big5",
  10443. "csbig5",
  10444. "x-x-big5"
  10445. ],
  10446. "name": "Big5"
  10447. }
  10448. ],
  10449. "heading": "Legacy multi-byte Chinese (traditional) encodings"
  10450. },
  10451. {
  10452. "encodings": [
  10453. {
  10454. "labels": [
  10455. "cseucpkdfmtjapanese",
  10456. "euc-jp",
  10457. "x-euc-jp"
  10458. ],
  10459. "name": "EUC-JP"
  10460. },
  10461. {
  10462. "labels": [
  10463. "csiso2022jp",
  10464. "iso-2022-jp"
  10465. ],
  10466. "name": "ISO-2022-JP"
  10467. },
  10468. {
  10469. "labels": [
  10470. "csshiftjis",
  10471. "ms932",
  10472. "ms_kanji",
  10473. "shift-jis",
  10474. "shift_jis",
  10475. "sjis",
  10476. "windows-31j",
  10477. "x-sjis"
  10478. ],
  10479. "name": "Shift_JIS"
  10480. }
  10481. ],
  10482. "heading": "Legacy multi-byte Japanese encodings"
  10483. },
  10484. {
  10485. "encodings": [
  10486. {
  10487. "labels": [
  10488. "cseuckr",
  10489. "csksc56011987",
  10490. "euc-kr",
  10491. "iso-ir-149",
  10492. "korean",
  10493. "ks_c_5601-1987",
  10494. "ks_c_5601-1989",
  10495. "ksc5601",
  10496. "ksc_5601",
  10497. "windows-949"
  10498. ],
  10499. "name": "EUC-KR"
  10500. }
  10501. ],
  10502. "heading": "Legacy multi-byte Korean encodings"
  10503. },
  10504. {
  10505. "encodings": [
  10506. {
  10507. "labels": [
  10508. "csiso2022kr",
  10509. "hz-gb-2312",
  10510. "iso-2022-cn",
  10511. "iso-2022-cn-ext",
  10512. "iso-2022-kr"
  10513. ],
  10514. "name": "replacement"
  10515. },
  10516. {
  10517. "labels": [
  10518. "utf-16be"
  10519. ],
  10520. "name": "UTF-16BE"
  10521. },
  10522. {
  10523. "labels": [
  10524. "utf-16",
  10525. "utf-16le"
  10526. ],
  10527. "name": "UTF-16LE"
  10528. },
  10529. {
  10530. "labels": [
  10531. "x-user-defined"
  10532. ],
  10533. "name": "x-user-defined"
  10534. }
  10535. ],
  10536. "heading": "Legacy miscellaneous encodings"
  10537. }
  10538. ];
  10539. // Label to encoding registry.
  10540. /** @type {Object.<string,{name:string,labels:Array.<string>}>} */
  10541. var label_to_encoding = {};
  10542. encodings.forEach(function (category) {
  10543. category.encodings.forEach(function (encoding) {
  10544. encoding.labels.forEach(function (label) {
  10545. label_to_encoding[label] = encoding;
  10546. });
  10547. });
  10548. });
  10549. // Registry of of encoder/decoder factories, by encoding name.
  10550. /** @type {Object.<string, function({fatal:boolean}): Encoder>} */
  10551. var encoders = {};
  10552. /** @type {Object.<string, function({fatal:boolean}): Decoder>} */
  10553. var decoders = {};
  10554. //
  10555. // 6. Indexes
  10556. //
  10557. /**
  10558. * @param {number} pointer The |pointer| to search for.
  10559. * @param {(!Array.<?number>|undefined)} index The |index| to search within.
  10560. * @return {?number} The code point corresponding to |pointer| in |index|,
  10561. * or null if |code point| is not in |index|.
  10562. */
  10563. function indexCodePointFor(pointer, index) {
  10564. if (!index) return null;
  10565. return index[pointer] || null;
  10566. }
  10567. /**
  10568. * @param {number} code_point The |code point| to search for.
  10569. * @param {!Array.<?number>} index The |index| to search within.
  10570. * @return {?number} The first pointer corresponding to |code point| in
  10571. * |index|, or null if |code point| is not in |index|.
  10572. */
  10573. function indexPointerFor(code_point, index) {
  10574. var pointer = index.indexOf(code_point);
  10575. return pointer === -1 ? null : pointer;
  10576. }
  10577. /**
  10578. * @param {string} name Name of the index.
  10579. * @return {(!Array.<number>|!Array.<Array.<number>>)}
  10580. * */
  10581. function index(name) {
  10582. if (!('encoding-indexes' in global)) {
  10583. throw Error("Indexes missing." +
  10584. " Did you forget to include encoding-indexes.js first?");
  10585. }
  10586. return global['encoding-indexes'][name];
  10587. }
  10588. /**
  10589. * @param {number} pointer The |pointer| to search for in the gb18030 index.
  10590. * @return {?number} The code point corresponding to |pointer| in |index|,
  10591. * or null if |code point| is not in the gb18030 index.
  10592. */
  10593. function indexGB18030RangesCodePointFor(pointer) {
  10594. // 1. If pointer is greater than 39419 and less than 189000, or
  10595. // pointer is greater than 1237575, return null.
  10596. if ((pointer > 39419 && pointer < 189000) || (pointer > 1237575))
  10597. return null;
  10598. // 2. If pointer is 7457, return code point U+E7C7.
  10599. if (pointer === 7457) return 0xE7C7;
  10600. // 3. Let offset be the last pointer in index gb18030 ranges that
  10601. // is equal to or less than pointer and let code point offset be
  10602. // its corresponding code point.
  10603. var offset = 0;
  10604. var code_point_offset = 0;
  10605. var idx = index('gb18030-ranges');
  10606. var i;
  10607. for (i = 0; i < idx.length; ++i) {
  10608. /** @type {!Array.<number>} */
  10609. var entry = idx[i];
  10610. if (entry[0] <= pointer) {
  10611. offset = entry[0];
  10612. code_point_offset = entry[1];
  10613. } else {
  10614. break;
  10615. }
  10616. }
  10617. // 4. Return a code point whose value is code point offset +
  10618. // pointer − offset.
  10619. return code_point_offset + pointer - offset;
  10620. }
  10621. /**
  10622. * @param {number} code_point The |code point| to locate in the gb18030 index.
  10623. * @return {number} The first pointer corresponding to |code point| in the
  10624. * gb18030 index.
  10625. */
  10626. function indexGB18030RangesPointerFor(code_point) {
  10627. // 1. If code point is U+E7C7, return pointer 7457.
  10628. if (code_point === 0xE7C7) return 7457;
  10629. // 2. Let offset be the last code point in index gb18030 ranges
  10630. // that is equal to or less than code point and let pointer offset
  10631. // be its corresponding pointer.
  10632. var offset = 0;
  10633. var pointer_offset = 0;
  10634. var idx = index('gb18030-ranges');
  10635. var i;
  10636. for (i = 0; i < idx.length; ++i) {
  10637. /** @type {!Array.<number>} */
  10638. var entry = idx[i];
  10639. if (entry[1] <= code_point) {
  10640. offset = entry[1];
  10641. pointer_offset = entry[0];
  10642. } else {
  10643. break;
  10644. }
  10645. }
  10646. // 3. Return a pointer whose value is pointer offset + code point
  10647. // − offset.
  10648. return pointer_offset + code_point - offset;
  10649. }
  10650. /**
  10651. * @param {number} code_point The |code_point| to search for in the Shift_JIS
  10652. * index.
  10653. * @return {?number} The code point corresponding to |pointer| in |index|,
  10654. * or null if |code point| is not in the Shift_JIS index.
  10655. */
  10656. function indexShiftJISPointerFor(code_point) {
  10657. // 1. Let index be index jis0208 excluding all entries whose
  10658. // pointer is in the range 8272 to 8835, inclusive.
  10659. shift_jis_index = shift_jis_index ||
  10660. index('jis0208').map(function (code_point, pointer) {
  10661. return inRange(pointer, 8272, 8835) ? null : code_point;
  10662. });
  10663. var index_ = shift_jis_index;
  10664. // 2. Return the index pointer for code point in index.
  10665. return index_.indexOf(code_point);
  10666. }
  10667. var shift_jis_index;
  10668. /**
  10669. * @param {number} code_point The |code_point| to search for in the big5
  10670. * index.
  10671. * @return {?number} The code point corresponding to |pointer| in |index|,
  10672. * or null if |code point| is not in the big5 index.
  10673. */
  10674. function indexBig5PointerFor(code_point) {
  10675. // 1. Let index be index Big5 excluding all entries whose pointer
  10676. big5_index_no_hkscs = big5_index_no_hkscs ||
  10677. index('big5').map(function (code_point, pointer) {
  10678. return (pointer < (0xA1 - 0x81) * 157) ? null : code_point;
  10679. });
  10680. var index_ = big5_index_no_hkscs;
  10681. // 2. If code point is U+2550, U+255E, U+2561, U+256A, U+5341, or
  10682. // U+5345, return the last pointer corresponding to code point in
  10683. // index.
  10684. if (code_point === 0x2550 || code_point === 0x255E ||
  10685. code_point === 0x2561 || code_point === 0x256A ||
  10686. code_point === 0x5341 || code_point === 0x5345) {
  10687. return index_.lastIndexOf(code_point);
  10688. }
  10689. // 3. Return the index pointer for code point in index.
  10690. return indexPointerFor(code_point, index_);
  10691. }
  10692. var big5_index_no_hkscs;
  10693. //
  10694. // 8. API
  10695. //
  10696. /** @const */ var DEFAULT_ENCODING = 'utf-8';
  10697. // 8.1 Interface TextDecoder
  10698. /**
  10699. * @constructor
  10700. * @param {string=} label The label of the encoding;
  10701. * defaults to 'utf-8'.
  10702. * @param {Object=} options
  10703. */
  10704. function TextDecoder(label, options) {
  10705. // Web IDL conventions
  10706. if (!(this instanceof TextDecoder))
  10707. throw TypeError('Called as a function. Did you forget \'new\'?');
  10708. label = label !== undefined ? String(label) : DEFAULT_ENCODING;
  10709. options = ToDictionary(options);
  10710. // A TextDecoder object has an associated encoding, decoder,
  10711. // stream, ignore BOM flag (initially unset), BOM seen flag
  10712. // (initially unset), error mode (initially replacement), and do
  10713. // not flush flag (initially unset).
  10714. /** @private */
  10715. this._encoding = null;
  10716. /** @private @type {?Decoder} */
  10717. this._decoder = null;
  10718. /** @private @type {boolean} */
  10719. this._ignoreBOM = false;
  10720. /** @private @type {boolean} */
  10721. this._BOMseen = false;
  10722. /** @private @type {string} */
  10723. this._error_mode = 'replacement';
  10724. /** @private @type {boolean} */
  10725. this._do_not_flush = false;
  10726. // 1. Let encoding be the result of getting an encoding from
  10727. // label.
  10728. var encoding = getEncoding(label);
  10729. // 2. If encoding is failure or replacement, throw a RangeError.
  10730. if (encoding === null || encoding.name === 'replacement')
  10731. throw RangeError('Unknown encoding: ' + label);
  10732. if (!decoders[encoding.name]) {
  10733. throw Error('Decoder not present.' +
  10734. ' Did you forget to include encoding-indexes.js first?');
  10735. }
  10736. // 3. Let dec be a new TextDecoder object.
  10737. var dec = this;
  10738. // 4. Set dec's encoding to encoding.
  10739. dec._encoding = encoding;
  10740. // 5. If options's fatal member is true, set dec's error mode to
  10741. // fatal.
  10742. if (Boolean(options['fatal']))
  10743. dec._error_mode = 'fatal';
  10744. // 6. If options's ignoreBOM member is true, set dec's ignore BOM
  10745. // flag.
  10746. if (Boolean(options['ignoreBOM']))
  10747. dec._ignoreBOM = true;
  10748. // For pre-ES5 runtimes:
  10749. if (!Object.defineProperty) {
  10750. this.encoding = dec._encoding.name.toLowerCase();
  10751. this.fatal = dec._error_mode === 'fatal';
  10752. this.ignoreBOM = dec._ignoreBOM;
  10753. }
  10754. // 7. Return dec.
  10755. return dec;
  10756. }
  10757. if (Object.defineProperty) {
  10758. // The encoding attribute's getter must return encoding's name.
  10759. Object.defineProperty(TextDecoder.prototype, 'encoding', {
  10760. /** @this {TextDecoder} */
  10761. get: function () { return this._encoding.name.toLowerCase(); }
  10762. });
  10763. // The fatal attribute's getter must return true if error mode
  10764. // is fatal, and false otherwise.
  10765. Object.defineProperty(TextDecoder.prototype, 'fatal', {
  10766. /** @this {TextDecoder} */
  10767. get: function () { return this._error_mode === 'fatal'; }
  10768. });
  10769. // The ignoreBOM attribute's getter must return true if ignore
  10770. // BOM flag is set, and false otherwise.
  10771. Object.defineProperty(TextDecoder.prototype, 'ignoreBOM', {
  10772. /** @this {TextDecoder} */
  10773. get: function () { return this._ignoreBOM; }
  10774. });
  10775. }
  10776. /**
  10777. * @param {BufferSource=} input The buffer of bytes to decode.
  10778. * @param {Object=} options
  10779. * @return {string} The decoded string.
  10780. */
  10781. TextDecoder.prototype.decode = function decode(input, options) {
  10782. var bytes;
  10783. if (typeof input === 'object' && input instanceof ArrayBuffer) {
  10784. bytes = new Uint8Array(input);
  10785. } else if (typeof input === 'object' && 'buffer' in input &&
  10786. input.buffer instanceof ArrayBuffer) {
  10787. bytes = new Uint8Array(input.buffer,
  10788. input.byteOffset,
  10789. input.byteLength);
  10790. } else {
  10791. bytes = new Uint8Array(0);
  10792. }
  10793. options = ToDictionary(options);
  10794. // 1. If the do not flush flag is unset, set decoder to a new
  10795. // encoding's decoder, set stream to a new stream, and unset the
  10796. // BOM seen flag.
  10797. if (!this._do_not_flush) {
  10798. this._decoder = decoders[this._encoding.name]({
  10799. fatal: this._error_mode === 'fatal'
  10800. });
  10801. this._BOMseen = false;
  10802. }
  10803. // 2. If options's stream is true, set the do not flush flag, and
  10804. // unset the do not flush flag otherwise.
  10805. this._do_not_flush = Boolean(options['stream']);
  10806. // 3. If input is given, push a copy of input to stream.
  10807. // TODO: Align with spec algorithm - maintain stream on instance.
  10808. var input_stream = new Stream(bytes);
  10809. // 4. Let output be a new stream.
  10810. var output = [];
  10811. /** @type {?(number|!Array.<number>)} */
  10812. var result;
  10813. // 5. While true:
  10814. while (true) {
  10815. // 1. Let token be the result of reading from stream.
  10816. var token = input_stream.read();
  10817. // 2. If token is end-of-stream and the do not flush flag is
  10818. // set, return output, serialized.
  10819. // TODO: Align with spec algorithm.
  10820. if (token === end_of_stream)
  10821. break;
  10822. // 3. Otherwise, run these subsubsteps:
  10823. // 1. Let result be the result of processing token for decoder,
  10824. // stream, output, and error mode.
  10825. result = this._decoder.handler(input_stream, token);
  10826. // 2. If result is finished, return output, serialized.
  10827. if (result === finished)
  10828. break;
  10829. if (result !== null) {
  10830. if (Array.isArray(result))
  10831. output.push.apply(output, /**@type {!Array.<number>}*/(result));
  10832. else
  10833. output.push(result);
  10834. }
  10835. // 3. Otherwise, if result is error, throw a TypeError.
  10836. // (Thrown in handler)
  10837. // 4. Otherwise, do nothing.
  10838. }
  10839. // TODO: Align with spec algorithm.
  10840. if (!this._do_not_flush) {
  10841. do {
  10842. result = this._decoder.handler(input_stream, input_stream.read());
  10843. if (result === finished)
  10844. break;
  10845. if (result === null)
  10846. continue;
  10847. if (Array.isArray(result))
  10848. output.push.apply(output, /**@type {!Array.<number>}*/(result));
  10849. else
  10850. output.push(result);
  10851. } while (!input_stream.endOfStream());
  10852. this._decoder = null;
  10853. }
  10854. // A TextDecoder object also has an associated serialize stream
  10855. // algorithm...
  10856. /**
  10857. * @param {!Array.<number>} stream
  10858. * @return {string}
  10859. * @this {TextDecoder}
  10860. */
  10861. function serializeStream(stream) {
  10862. // 1. Let token be the result of reading from stream.
  10863. // (Done in-place on array, rather than as a stream)
  10864. // 2. If encoding is UTF-8, UTF-16BE, or UTF-16LE, and ignore
  10865. // BOM flag and BOM seen flag are unset, run these subsubsteps:
  10866. if (includes(['UTF-8', 'UTF-16LE', 'UTF-16BE'], this._encoding.name) &&
  10867. !this._ignoreBOM && !this._BOMseen) {
  10868. if (stream.length > 0 && stream[0] === 0xFEFF) {
  10869. // 1. If token is U+FEFF, set BOM seen flag.
  10870. this._BOMseen = true;
  10871. stream.shift();
  10872. } else if (stream.length > 0) {
  10873. // 2. Otherwise, if token is not end-of-stream, set BOM seen
  10874. // flag and append token to stream.
  10875. this._BOMseen = true;
  10876. } else {
  10877. // 3. Otherwise, if token is not end-of-stream, append token
  10878. // to output.
  10879. // (no-op)
  10880. }
  10881. }
  10882. // 4. Otherwise, return output.
  10883. return codePointsToString(stream);
  10884. }
  10885. return serializeStream.call(this, output);
  10886. };
  10887. // 8.2 Interface TextEncoder
  10888. /**
  10889. * @constructor
  10890. * @param {string=} label The label of the encoding. NONSTANDARD.
  10891. * @param {Object=} options NONSTANDARD.
  10892. */
  10893. function TextEncoder(label, options) {
  10894. // Web IDL conventions
  10895. if (!(this instanceof TextEncoder))
  10896. throw TypeError('Called as a function. Did you forget \'new\'?');
  10897. options = ToDictionary(options);
  10898. // A TextEncoder object has an associated encoding and encoder.
  10899. /** @private */
  10900. this._encoding = null;
  10901. /** @private @type {?Encoder} */
  10902. this._encoder = null;
  10903. // Non-standard
  10904. /** @private @type {boolean} */
  10905. this._do_not_flush = false;
  10906. /** @private @type {string} */
  10907. this._fatal = Boolean(options['fatal']) ? 'fatal' : 'replacement';
  10908. // 1. Let enc be a new TextEncoder object.
  10909. var enc = this;
  10910. // 2. Set enc's encoding to UTF-8's encoder.
  10911. if (Boolean(options['NONSTANDARD_allowLegacyEncoding'])) {
  10912. // NONSTANDARD behavior.
  10913. label = label !== undefined ? String(label) : DEFAULT_ENCODING;
  10914. var encoding = getEncoding(label);
  10915. if (encoding === null || encoding.name === 'replacement')
  10916. throw RangeError('Unknown encoding: ' + label);
  10917. if (!encoders[encoding.name]) {
  10918. throw Error('Encoder not present.' +
  10919. ' Did you forget to include encoding-indexes.js first?');
  10920. }
  10921. enc._encoding = encoding;
  10922. } else {
  10923. // Standard behavior.
  10924. enc._encoding = getEncoding('utf-8');
  10925. if (label !== undefined && 'console' in global) {
  10926. console.warn('TextEncoder constructor called with encoding label, '
  10927. + 'which is ignored.');
  10928. }
  10929. }
  10930. // For pre-ES5 runtimes:
  10931. if (!Object.defineProperty)
  10932. this.encoding = enc._encoding.name.toLowerCase();
  10933. // 3. Return enc.
  10934. return enc;
  10935. }
  10936. if (Object.defineProperty) {
  10937. // The encoding attribute's getter must return encoding's name.
  10938. Object.defineProperty(TextEncoder.prototype, 'encoding', {
  10939. /** @this {TextEncoder} */
  10940. get: function () { return this._encoding.name.toLowerCase(); }
  10941. });
  10942. }
  10943. /**
  10944. * @param {string=} opt_string The string to encode.
  10945. * @param {Object=} options
  10946. * @return {!Uint8Array} Encoded bytes, as a Uint8Array.
  10947. */
  10948. TextEncoder.prototype.encode = function encode(opt_string, options) {
  10949. opt_string = opt_string === undefined ? '' : String(opt_string);
  10950. options = ToDictionary(options);
  10951. // NOTE: This option is nonstandard. None of the encodings
  10952. // permitted for encoding (i.e. UTF-8, UTF-16) are stateful when
  10953. // the input is a USVString so streaming is not necessary.
  10954. if (!this._do_not_flush)
  10955. this._encoder = encoders[this._encoding.name]({
  10956. fatal: this._fatal === 'fatal'
  10957. });
  10958. this._do_not_flush = Boolean(options['stream']);
  10959. // 1. Convert input to a stream.
  10960. var input = new Stream(stringToCodePoints(opt_string));
  10961. // 2. Let output be a new stream
  10962. var output = [];
  10963. /** @type {?(number|!Array.<number>)} */
  10964. var result;
  10965. // 3. While true, run these substeps:
  10966. while (true) {
  10967. // 1. Let token be the result of reading from input.
  10968. var token = input.read();
  10969. if (token === end_of_stream)
  10970. break;
  10971. // 2. Let result be the result of processing token for encoder,
  10972. // input, output.
  10973. result = this._encoder.handler(input, token);
  10974. if (result === finished)
  10975. break;
  10976. if (Array.isArray(result))
  10977. output.push.apply(output, /**@type {!Array.<number>}*/(result));
  10978. else
  10979. output.push(result);
  10980. }
  10981. // TODO: Align with spec algorithm.
  10982. if (!this._do_not_flush) {
  10983. while (true) {
  10984. result = this._encoder.handler(input, input.read());
  10985. if (result === finished)
  10986. break;
  10987. if (Array.isArray(result))
  10988. output.push.apply(output, /**@type {!Array.<number>}*/(result));
  10989. else
  10990. output.push(result);
  10991. }
  10992. this._encoder = null;
  10993. }
  10994. // 3. If result is finished, convert output into a byte sequence,
  10995. // and then return a Uint8Array object wrapping an ArrayBuffer
  10996. // containing output.
  10997. return new Uint8Array(output);
  10998. };
  10999. //
  11000. // 9. The encoding
  11001. //
  11002. // 9.1 utf-8
  11003. // 9.1.1 utf-8 decoder
  11004. /**
  11005. * @constructor
  11006. * @implements {Decoder}
  11007. * @param {{fatal: boolean}} options
  11008. */
  11009. function UTF8Decoder(options) {
  11010. var fatal = options.fatal;
  11011. // utf-8's decoder's has an associated utf-8 code point, utf-8
  11012. // bytes seen, and utf-8 bytes needed (all initially 0), a utf-8
  11013. // lower boundary (initially 0x80), and a utf-8 upper boundary
  11014. // (initially 0xBF).
  11015. var /** @type {number} */ utf8_code_point = 0,
  11016. /** @type {number} */ utf8_bytes_seen = 0,
  11017. /** @type {number} */ utf8_bytes_needed = 0,
  11018. /** @type {number} */ utf8_lower_boundary = 0x80,
  11019. /** @type {number} */ utf8_upper_boundary = 0xBF;
  11020. /**
  11021. * @param {Stream} stream The stream of bytes being decoded.
  11022. * @param {number} bite The next byte read from the stream.
  11023. * @return {?(number|!Array.<number>)} The next code point(s)
  11024. * decoded, or null if not enough data exists in the input
  11025. * stream to decode a complete code point.
  11026. */
  11027. this.handler = function (stream, bite) {
  11028. // 1. If byte is end-of-stream and utf-8 bytes needed is not 0,
  11029. // set utf-8 bytes needed to 0 and return error.
  11030. if (bite === end_of_stream && utf8_bytes_needed !== 0) {
  11031. utf8_bytes_needed = 0;
  11032. return decoderError(fatal);
  11033. }
  11034. // 2. If byte is end-of-stream, return finished.
  11035. if (bite === end_of_stream)
  11036. return finished;
  11037. // 3. If utf-8 bytes needed is 0, based on byte:
  11038. if (utf8_bytes_needed === 0) {
  11039. // 0x00 to 0x7F
  11040. if (inRange(bite, 0x00, 0x7F)) {
  11041. // Return a code point whose value is byte.
  11042. return bite;
  11043. }
  11044. // 0xC2 to 0xDF
  11045. else if (inRange(bite, 0xC2, 0xDF)) {
  11046. // 1. Set utf-8 bytes needed to 1.
  11047. utf8_bytes_needed = 1;
  11048. // 2. Set UTF-8 code point to byte & 0x1F.
  11049. utf8_code_point = bite & 0x1F;
  11050. }
  11051. // 0xE0 to 0xEF
  11052. else if (inRange(bite, 0xE0, 0xEF)) {
  11053. // 1. If byte is 0xE0, set utf-8 lower boundary to 0xA0.
  11054. if (bite === 0xE0)
  11055. utf8_lower_boundary = 0xA0;
  11056. // 2. If byte is 0xED, set utf-8 upper boundary to 0x9F.
  11057. if (bite === 0xED)
  11058. utf8_upper_boundary = 0x9F;
  11059. // 3. Set utf-8 bytes needed to 2.
  11060. utf8_bytes_needed = 2;
  11061. // 4. Set UTF-8 code point to byte & 0xF.
  11062. utf8_code_point = bite & 0xF;
  11063. }
  11064. // 0xF0 to 0xF4
  11065. else if (inRange(bite, 0xF0, 0xF4)) {
  11066. // 1. If byte is 0xF0, set utf-8 lower boundary to 0x90.
  11067. if (bite === 0xF0)
  11068. utf8_lower_boundary = 0x90;
  11069. // 2. If byte is 0xF4, set utf-8 upper boundary to 0x8F.
  11070. if (bite === 0xF4)
  11071. utf8_upper_boundary = 0x8F;
  11072. // 3. Set utf-8 bytes needed to 3.
  11073. utf8_bytes_needed = 3;
  11074. // 4. Set UTF-8 code point to byte & 0x7.
  11075. utf8_code_point = bite & 0x7;
  11076. }
  11077. // Otherwise
  11078. else {
  11079. // Return error.
  11080. return decoderError(fatal);
  11081. }
  11082. // Return continue.
  11083. return null;
  11084. }
  11085. // 4. If byte is not in the range utf-8 lower boundary to utf-8
  11086. // upper boundary, inclusive, run these substeps:
  11087. if (!inRange(bite, utf8_lower_boundary, utf8_upper_boundary)) {
  11088. // 1. Set utf-8 code point, utf-8 bytes needed, and utf-8
  11089. // bytes seen to 0, set utf-8 lower boundary to 0x80, and set
  11090. // utf-8 upper boundary to 0xBF.
  11091. utf8_code_point = utf8_bytes_needed = utf8_bytes_seen = 0;
  11092. utf8_lower_boundary = 0x80;
  11093. utf8_upper_boundary = 0xBF;
  11094. // 2. Prepend byte to stream.
  11095. stream.prepend(bite);
  11096. // 3. Return error.
  11097. return decoderError(fatal);
  11098. }
  11099. // 5. Set utf-8 lower boundary to 0x80 and utf-8 upper boundary
  11100. // to 0xBF.
  11101. utf8_lower_boundary = 0x80;
  11102. utf8_upper_boundary = 0xBF;
  11103. // 6. Set UTF-8 code point to (UTF-8 code point << 6) | (byte &
  11104. // 0x3F)
  11105. utf8_code_point = (utf8_code_point << 6) | (bite & 0x3F);
  11106. // 7. Increase utf-8 bytes seen by one.
  11107. utf8_bytes_seen += 1;
  11108. // 8. If utf-8 bytes seen is not equal to utf-8 bytes needed,
  11109. // continue.
  11110. if (utf8_bytes_seen !== utf8_bytes_needed)
  11111. return null;
  11112. // 9. Let code point be utf-8 code point.
  11113. var code_point = utf8_code_point;
  11114. // 10. Set utf-8 code point, utf-8 bytes needed, and utf-8 bytes
  11115. // seen to 0.
  11116. utf8_code_point = utf8_bytes_needed = utf8_bytes_seen = 0;
  11117. // 11. Return a code point whose value is code point.
  11118. return code_point;
  11119. };
  11120. }
  11121. // 9.1.2 utf-8 encoder
  11122. /**
  11123. * @constructor
  11124. * @implements {Encoder}
  11125. * @param {{fatal: boolean}} options
  11126. */
  11127. function UTF8Encoder(options) {
  11128. var fatal = options.fatal;
  11129. /**
  11130. * @param {Stream} stream Input stream.
  11131. * @param {number} code_point Next code point read from the stream.
  11132. * @return {(number|!Array.<number>)} Byte(s) to emit.
  11133. */
  11134. this.handler = function (stream, code_point) {
  11135. // 1. If code point is end-of-stream, return finished.
  11136. if (code_point === end_of_stream)
  11137. return finished;
  11138. // 2. If code point is an ASCII code point, return a byte whose
  11139. // value is code point.
  11140. if (isASCIICodePoint(code_point))
  11141. return code_point;
  11142. // 3. Set count and offset based on the range code point is in:
  11143. var count, offset;
  11144. // U+0080 to U+07FF, inclusive:
  11145. if (inRange(code_point, 0x0080, 0x07FF)) {
  11146. // 1 and 0xC0
  11147. count = 1;
  11148. offset = 0xC0;
  11149. }
  11150. // U+0800 to U+FFFF, inclusive:
  11151. else if (inRange(code_point, 0x0800, 0xFFFF)) {
  11152. // 2 and 0xE0
  11153. count = 2;
  11154. offset = 0xE0;
  11155. }
  11156. // U+10000 to U+10FFFF, inclusive:
  11157. else if (inRange(code_point, 0x10000, 0x10FFFF)) {
  11158. // 3 and 0xF0
  11159. count = 3;
  11160. offset = 0xF0;
  11161. }
  11162. // 4. Let bytes be a byte sequence whose first byte is (code
  11163. // point >> (6 × count)) + offset.
  11164. var bytes = [(code_point >> (6 * count)) + offset];
  11165. // 5. Run these substeps while count is greater than 0:
  11166. while (count > 0) {
  11167. // 1. Set temp to code point >> (6 × (count − 1)).
  11168. var temp = code_point >> (6 * (count - 1));
  11169. // 2. Append to bytes 0x80 | (temp & 0x3F).
  11170. bytes.push(0x80 | (temp & 0x3F));
  11171. // 3. Decrease count by one.
  11172. count -= 1;
  11173. }
  11174. // 6. Return bytes bytes, in order.
  11175. return bytes;
  11176. };
  11177. }
  11178. /** @param {{fatal: boolean}} options */
  11179. encoders['UTF-8'] = function (options) {
  11180. return new UTF8Encoder(options);
  11181. };
  11182. /** @param {{fatal: boolean}} options */
  11183. decoders['UTF-8'] = function (options) {
  11184. return new UTF8Decoder(options);
  11185. };
  11186. //
  11187. // 10. Legacy single-byte encodings
  11188. //
  11189. // 10.1 single-byte decoder
  11190. /**
  11191. * @constructor
  11192. * @implements {Decoder}
  11193. * @param {!Array.<number>} index The encoding index.
  11194. * @param {{fatal: boolean}} options
  11195. */
  11196. function SingleByteDecoder(index, options) {
  11197. var fatal = options.fatal;
  11198. /**
  11199. * @param {Stream} stream The stream of bytes being decoded.
  11200. * @param {number} bite The next byte read from the stream.
  11201. * @return {?(number|!Array.<number>)} The next code point(s)
  11202. * decoded, or null if not enough data exists in the input
  11203. * stream to decode a complete code point.
  11204. */
  11205. this.handler = function (stream, bite) {
  11206. // 1. If byte is end-of-stream, return finished.
  11207. if (bite === end_of_stream)
  11208. return finished;
  11209. // 2. If byte is an ASCII byte, return a code point whose value
  11210. // is byte.
  11211. if (isASCIIByte(bite))
  11212. return bite;
  11213. // 3. Let code point be the index code point for byte − 0x80 in
  11214. // index single-byte.
  11215. var code_point = index[bite - 0x80];
  11216. // 4. If code point is null, return error.
  11217. if (code_point === null)
  11218. return decoderError(fatal);
  11219. // 5. Return a code point whose value is code point.
  11220. return code_point;
  11221. };
  11222. }
  11223. // 10.2 single-byte encoder
  11224. /**
  11225. * @constructor
  11226. * @implements {Encoder}
  11227. * @param {!Array.<?number>} index The encoding index.
  11228. * @param {{fatal: boolean}} options
  11229. */
  11230. function SingleByteEncoder(index, options) {
  11231. var fatal = options.fatal;
  11232. /**
  11233. * @param {Stream} stream Input stream.
  11234. * @param {number} code_point Next code point read from the stream.
  11235. * @return {(number|!Array.<number>)} Byte(s) to emit.
  11236. */
  11237. this.handler = function (stream, code_point) {
  11238. // 1. If code point is end-of-stream, return finished.
  11239. if (code_point === end_of_stream)
  11240. return finished;
  11241. // 2. If code point is an ASCII code point, return a byte whose
  11242. // value is code point.
  11243. if (isASCIICodePoint(code_point))
  11244. return code_point;
  11245. // 3. Let pointer be the index pointer for code point in index
  11246. // single-byte.
  11247. var pointer = indexPointerFor(code_point, index);
  11248. // 4. If pointer is null, return error with code point.
  11249. if (pointer === null)
  11250. encoderError(code_point);
  11251. // 5. Return a byte whose value is pointer + 0x80.
  11252. return pointer + 0x80;
  11253. };
  11254. }
  11255. (function () {
  11256. if (!('encoding-indexes' in global))
  11257. return;
  11258. encodings.forEach(function (category) {
  11259. if (category.heading !== 'Legacy single-byte encodings')
  11260. return;
  11261. category.encodings.forEach(function (encoding) {
  11262. var name = encoding.name;
  11263. var idx = index(name.toLowerCase());
  11264. /** @param {{fatal: boolean}} options */
  11265. decoders[name] = function (options) {
  11266. return new SingleByteDecoder(idx, options);
  11267. };
  11268. /** @param {{fatal: boolean}} options */
  11269. encoders[name] = function (options) {
  11270. return new SingleByteEncoder(idx, options);
  11271. };
  11272. });
  11273. });
  11274. }());
  11275. //
  11276. // 11. Legacy multi-byte Chinese (simplified) encodings
  11277. //
  11278. // 11.1 gbk
  11279. // 11.1.1 gbk decoder
  11280. // gbk's decoder is gb18030's decoder.
  11281. /** @param {{fatal: boolean}} options */
  11282. decoders['GBK'] = function (options) {
  11283. return new GB18030Decoder(options);
  11284. };
  11285. // 11.1.2 gbk encoder
  11286. // gbk's encoder is gb18030's encoder with its gbk flag set.
  11287. /** @param {{fatal: boolean}} options */
  11288. encoders['GBK'] = function (options) {
  11289. return new GB18030Encoder(options, true);
  11290. };
  11291. // 11.2 gb18030
  11292. // 11.2.1 gb18030 decoder
  11293. /**
  11294. * @constructor
  11295. * @implements {Decoder}
  11296. * @param {{fatal: boolean}} options
  11297. */
  11298. function GB18030Decoder(options) {
  11299. var fatal = options.fatal;
  11300. // gb18030's decoder has an associated gb18030 first, gb18030
  11301. // second, and gb18030 third (all initially 0x00).
  11302. var /** @type {number} */ gb18030_first = 0x00,
  11303. /** @type {number} */ gb18030_second = 0x00,
  11304. /** @type {number} */ gb18030_third = 0x00;
  11305. /**
  11306. * @param {Stream} stream The stream of bytes being decoded.
  11307. * @param {number} bite The next byte read from the stream.
  11308. * @return {?(number|!Array.<number>)} The next code point(s)
  11309. * decoded, or null if not enough data exists in the input
  11310. * stream to decode a complete code point.
  11311. */
  11312. this.handler = function (stream, bite) {
  11313. // 1. If byte is end-of-stream and gb18030 first, gb18030
  11314. // second, and gb18030 third are 0x00, return finished.
  11315. if (bite === end_of_stream && gb18030_first === 0x00 &&
  11316. gb18030_second === 0x00 && gb18030_third === 0x00) {
  11317. return finished;
  11318. }
  11319. // 2. If byte is end-of-stream, and gb18030 first, gb18030
  11320. // second, or gb18030 third is not 0x00, set gb18030 first,
  11321. // gb18030 second, and gb18030 third to 0x00, and return error.
  11322. if (bite === end_of_stream &&
  11323. (gb18030_first !== 0x00 || gb18030_second !== 0x00 ||
  11324. gb18030_third !== 0x00)) {
  11325. gb18030_first = 0x00;
  11326. gb18030_second = 0x00;
  11327. gb18030_third = 0x00;
  11328. decoderError(fatal);
  11329. }
  11330. var code_point;
  11331. // 3. If gb18030 third is not 0x00, run these substeps:
  11332. if (gb18030_third !== 0x00) {
  11333. // 1. Let code point be null.
  11334. code_point = null;
  11335. // 2. If byte is in the range 0x30 to 0x39, inclusive, set
  11336. // code point to the index gb18030 ranges code point for
  11337. // (((gb18030 first − 0x81) × 10 + gb18030 second − 0x30) ×
  11338. // 126 + gb18030 third − 0x81) × 10 + byte − 0x30.
  11339. if (inRange(bite, 0x30, 0x39)) {
  11340. code_point = indexGB18030RangesCodePointFor(
  11341. (((gb18030_first - 0x81) * 10 + gb18030_second - 0x30) * 126 +
  11342. gb18030_third - 0x81) * 10 + bite - 0x30);
  11343. }
  11344. // 3. Let buffer be a byte sequence consisting of gb18030
  11345. // second, gb18030 third, and byte, in order.
  11346. var buffer = [gb18030_second, gb18030_third, bite];
  11347. // 4. Set gb18030 first, gb18030 second, and gb18030 third to
  11348. // 0x00.
  11349. gb18030_first = 0x00;
  11350. gb18030_second = 0x00;
  11351. gb18030_third = 0x00;
  11352. // 5. If code point is null, prepend buffer to stream and
  11353. // return error.
  11354. if (code_point === null) {
  11355. stream.prepend(buffer);
  11356. return decoderError(fatal);
  11357. }
  11358. // 6. Return a code point whose value is code point.
  11359. return code_point;
  11360. }
  11361. // 4. If gb18030 second is not 0x00, run these substeps:
  11362. if (gb18030_second !== 0x00) {
  11363. // 1. If byte is in the range 0x81 to 0xFE, inclusive, set
  11364. // gb18030 third to byte and return continue.
  11365. if (inRange(bite, 0x81, 0xFE)) {
  11366. gb18030_third = bite;
  11367. return null;
  11368. }
  11369. // 2. Prepend gb18030 second followed by byte to stream, set
  11370. // gb18030 first and gb18030 second to 0x00, and return error.
  11371. stream.prepend([gb18030_second, bite]);
  11372. gb18030_first = 0x00;
  11373. gb18030_second = 0x00;
  11374. return decoderError(fatal);
  11375. }
  11376. // 5. If gb18030 first is not 0x00, run these substeps:
  11377. if (gb18030_first !== 0x00) {
  11378. // 1. If byte is in the range 0x30 to 0x39, inclusive, set
  11379. // gb18030 second to byte and return continue.
  11380. if (inRange(bite, 0x30, 0x39)) {
  11381. gb18030_second = bite;
  11382. return null;
  11383. }
  11384. // 2. Let lead be gb18030 first, let pointer be null, and set
  11385. // gb18030 first to 0x00.
  11386. var lead = gb18030_first;
  11387. var pointer = null;
  11388. gb18030_first = 0x00;
  11389. // 3. Let offset be 0x40 if byte is less than 0x7F and 0x41
  11390. // otherwise.
  11391. var offset = bite < 0x7F ? 0x40 : 0x41;
  11392. // 4. If byte is in the range 0x40 to 0x7E, inclusive, or 0x80
  11393. // to 0xFE, inclusive, set pointer to (lead − 0x81) × 190 +
  11394. // (byte − offset).
  11395. if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0x80, 0xFE))
  11396. pointer = (lead - 0x81) * 190 + (bite - offset);
  11397. // 5. Let code point be null if pointer is null and the index
  11398. // code point for pointer in index gb18030 otherwise.
  11399. code_point = pointer === null ? null :
  11400. indexCodePointFor(pointer, index('gb18030'));
  11401. // 6. If code point is null and byte is an ASCII byte, prepend
  11402. // byte to stream.
  11403. if (code_point === null && isASCIIByte(bite))
  11404. stream.prepend(bite);
  11405. // 7. If code point is null, return error.
  11406. if (code_point === null)
  11407. return decoderError(fatal);
  11408. // 8. Return a code point whose value is code point.
  11409. return code_point;
  11410. }
  11411. // 6. If byte is an ASCII byte, return a code point whose value
  11412. // is byte.
  11413. if (isASCIIByte(bite))
  11414. return bite;
  11415. // 7. If byte is 0x80, return code point U+20AC.
  11416. if (bite === 0x80)
  11417. return 0x20AC;
  11418. // 8. If byte is in the range 0x81 to 0xFE, inclusive, set
  11419. // gb18030 first to byte and return continue.
  11420. if (inRange(bite, 0x81, 0xFE)) {
  11421. gb18030_first = bite;
  11422. return null;
  11423. }
  11424. // 9. Return error.
  11425. return decoderError(fatal);
  11426. };
  11427. }
  11428. // 11.2.2 gb18030 encoder
  11429. /**
  11430. * @constructor
  11431. * @implements {Encoder}
  11432. * @param {{fatal: boolean}} options
  11433. * @param {boolean=} gbk_flag
  11434. */
  11435. function GB18030Encoder(options, gbk_flag) {
  11436. var fatal = options.fatal;
  11437. // gb18030's decoder has an associated gbk flag (initially unset).
  11438. /**
  11439. * @param {Stream} stream Input stream.
  11440. * @param {number} code_point Next code point read from the stream.
  11441. * @return {(number|!Array.<number>)} Byte(s) to emit.
  11442. */
  11443. this.handler = function (stream, code_point) {
  11444. // 1. If code point is end-of-stream, return finished.
  11445. if (code_point === end_of_stream)
  11446. return finished;
  11447. // 2. If code point is an ASCII code point, return a byte whose
  11448. // value is code point.
  11449. if (isASCIICodePoint(code_point))
  11450. return code_point;
  11451. // 3. If code point is U+E5E5, return error with code point.
  11452. if (code_point === 0xE5E5)
  11453. return encoderError(code_point);
  11454. // 4. If the gbk flag is set and code point is U+20AC, return
  11455. // byte 0x80.
  11456. if (gbk_flag && code_point === 0x20AC)
  11457. return 0x80;
  11458. // 5. Let pointer be the index pointer for code point in index
  11459. // gb18030.
  11460. var pointer = indexPointerFor(code_point, index('gb18030'));
  11461. // 6. If pointer is not null, run these substeps:
  11462. if (pointer !== null) {
  11463. // 1. Let lead be floor(pointer / 190) + 0x81.
  11464. var lead = floor(pointer / 190) + 0x81;
  11465. // 2. Let trail be pointer % 190.
  11466. var trail = pointer % 190;
  11467. // 3. Let offset be 0x40 if trail is less than 0x3F and 0x41 otherwise.
  11468. var offset = trail < 0x3F ? 0x40 : 0x41;
  11469. // 4. Return two bytes whose values are lead and trail + offset.
  11470. return [lead, trail + offset];
  11471. }
  11472. // 7. If gbk flag is set, return error with code point.
  11473. if (gbk_flag)
  11474. return encoderError(code_point);
  11475. // 8. Set pointer to the index gb18030 ranges pointer for code
  11476. // point.
  11477. pointer = indexGB18030RangesPointerFor(code_point);
  11478. // 9. Let byte1 be floor(pointer / 10 / 126 / 10).
  11479. var byte1 = floor(pointer / 10 / 126 / 10);
  11480. // 10. Set pointer to pointer − byte1 × 10 × 126 × 10.
  11481. pointer = pointer - byte1 * 10 * 126 * 10;
  11482. // 11. Let byte2 be floor(pointer / 10 / 126).
  11483. var byte2 = floor(pointer / 10 / 126);
  11484. // 12. Set pointer to pointer − byte2 × 10 × 126.
  11485. pointer = pointer - byte2 * 10 * 126;
  11486. // 13. Let byte3 be floor(pointer / 10).
  11487. var byte3 = floor(pointer / 10);
  11488. // 14. Let byte4 be pointer − byte3 × 10.
  11489. var byte4 = pointer - byte3 * 10;
  11490. // 15. Return four bytes whose values are byte1 + 0x81, byte2 +
  11491. // 0x30, byte3 + 0x81, byte4 + 0x30.
  11492. return [byte1 + 0x81,
  11493. byte2 + 0x30,
  11494. byte3 + 0x81,
  11495. byte4 + 0x30];
  11496. };
  11497. }
  11498. /** @param {{fatal: boolean}} options */
  11499. encoders['gb18030'] = function (options) {
  11500. return new GB18030Encoder(options);
  11501. };
  11502. /** @param {{fatal: boolean}} options */
  11503. decoders['gb18030'] = function (options) {
  11504. return new GB18030Decoder(options);
  11505. };
  11506. //
  11507. // 12. Legacy multi-byte Chinese (traditional) encodings
  11508. //
  11509. // 12.1 Big5
  11510. // 12.1.1 Big5 decoder
  11511. /**
  11512. * @constructor
  11513. * @implements {Decoder}
  11514. * @param {{fatal: boolean}} options
  11515. */
  11516. function Big5Decoder(options) {
  11517. var fatal = options.fatal;
  11518. // Big5's decoder has an associated Big5 lead (initially 0x00).
  11519. var /** @type {number} */ Big5_lead = 0x00;
  11520. /**
  11521. * @param {Stream} stream The stream of bytes being decoded.
  11522. * @param {number} bite The next byte read from the stream.
  11523. * @return {?(number|!Array.<number>)} The next code point(s)
  11524. * decoded, or null if not enough data exists in the input
  11525. * stream to decode a complete code point.
  11526. */
  11527. this.handler = function (stream, bite) {
  11528. // 1. If byte is end-of-stream and Big5 lead is not 0x00, set
  11529. // Big5 lead to 0x00 and return error.
  11530. if (bite === end_of_stream && Big5_lead !== 0x00) {
  11531. Big5_lead = 0x00;
  11532. return decoderError(fatal);
  11533. }
  11534. // 2. If byte is end-of-stream and Big5 lead is 0x00, return
  11535. // finished.
  11536. if (bite === end_of_stream && Big5_lead === 0x00)
  11537. return finished;
  11538. // 3. If Big5 lead is not 0x00, let lead be Big5 lead, let
  11539. // pointer be null, set Big5 lead to 0x00, and then run these
  11540. // substeps:
  11541. if (Big5_lead !== 0x00) {
  11542. var lead = Big5_lead;
  11543. var pointer = null;
  11544. Big5_lead = 0x00;
  11545. // 1. Let offset be 0x40 if byte is less than 0x7F and 0x62
  11546. // otherwise.
  11547. var offset = bite < 0x7F ? 0x40 : 0x62;
  11548. // 2. If byte is in the range 0x40 to 0x7E, inclusive, or 0xA1
  11549. // to 0xFE, inclusive, set pointer to (lead − 0x81) × 157 +
  11550. // (byte − offset).
  11551. if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0xA1, 0xFE))
  11552. pointer = (lead - 0x81) * 157 + (bite - offset);
  11553. // 3. If there is a row in the table below whose first column
  11554. // is pointer, return the two code points listed in its second
  11555. // column
  11556. // Pointer | Code points
  11557. // --------+--------------
  11558. // 1133 | U+00CA U+0304
  11559. // 1135 | U+00CA U+030C
  11560. // 1164 | U+00EA U+0304
  11561. // 1166 | U+00EA U+030C
  11562. switch (pointer) {
  11563. case 1133: return [0x00CA, 0x0304];
  11564. case 1135: return [0x00CA, 0x030C];
  11565. case 1164: return [0x00EA, 0x0304];
  11566. case 1166: return [0x00EA, 0x030C];
  11567. }
  11568. // 4. Let code point be null if pointer is null and the index
  11569. // code point for pointer in index Big5 otherwise.
  11570. var code_point = (pointer === null) ? null :
  11571. indexCodePointFor(pointer, index('big5'));
  11572. // 5. If code point is null and byte is an ASCII byte, prepend
  11573. // byte to stream.
  11574. if (code_point === null && isASCIIByte(bite))
  11575. stream.prepend(bite);
  11576. // 6. If code point is null, return error.
  11577. if (code_point === null)
  11578. return decoderError(fatal);
  11579. // 7. Return a code point whose value is code point.
  11580. return code_point;
  11581. }
  11582. // 4. If byte is an ASCII byte, return a code point whose value
  11583. // is byte.
  11584. if (isASCIIByte(bite))
  11585. return bite;
  11586. // 5. If byte is in the range 0x81 to 0xFE, inclusive, set Big5
  11587. // lead to byte and return continue.
  11588. if (inRange(bite, 0x81, 0xFE)) {
  11589. Big5_lead = bite;
  11590. return null;
  11591. }
  11592. // 6. Return error.
  11593. return decoderError(fatal);
  11594. };
  11595. }
  11596. // 12.1.2 Big5 encoder
  11597. /**
  11598. * @constructor
  11599. * @implements {Encoder}
  11600. * @param {{fatal: boolean}} options
  11601. */
  11602. function Big5Encoder(options) {
  11603. var fatal = options.fatal;
  11604. /**
  11605. * @param {Stream} stream Input stream.
  11606. * @param {number} code_point Next code point read from the stream.
  11607. * @return {(number|!Array.<number>)} Byte(s) to emit.
  11608. */
  11609. this.handler = function (stream, code_point) {
  11610. // 1. If code point is end-of-stream, return finished.
  11611. if (code_point === end_of_stream)
  11612. return finished;
  11613. // 2. If code point is an ASCII code point, return a byte whose
  11614. // value is code point.
  11615. if (isASCIICodePoint(code_point))
  11616. return code_point;
  11617. // 3. Let pointer be the index Big5 pointer for code point.
  11618. var pointer = indexBig5PointerFor(code_point);
  11619. // 4. If pointer is null, return error with code point.
  11620. if (pointer === null)
  11621. return encoderError(code_point);
  11622. // 5. Let lead be floor(pointer / 157) + 0x81.
  11623. var lead = floor(pointer / 157) + 0x81;
  11624. // 6. If lead is less than 0xA1, return error with code point.
  11625. if (lead < 0xA1)
  11626. return encoderError(code_point);
  11627. // 7. Let trail be pointer % 157.
  11628. var trail = pointer % 157;
  11629. // 8. Let offset be 0x40 if trail is less than 0x3F and 0x62
  11630. // otherwise.
  11631. var offset = trail < 0x3F ? 0x40 : 0x62;
  11632. // Return two bytes whose values are lead and trail + offset.
  11633. return [lead, trail + offset];
  11634. };
  11635. }
  11636. /** @param {{fatal: boolean}} options */
  11637. encoders['Big5'] = function (options) {
  11638. return new Big5Encoder(options);
  11639. };
  11640. /** @param {{fatal: boolean}} options */
  11641. decoders['Big5'] = function (options) {
  11642. return new Big5Decoder(options);
  11643. };
  11644. //
  11645. // 13. Legacy multi-byte Japanese encodings
  11646. //
  11647. // 13.1 euc-jp
  11648. // 13.1.1 euc-jp decoder
  11649. /**
  11650. * @constructor
  11651. * @implements {Decoder}
  11652. * @param {{fatal: boolean}} options
  11653. */
  11654. function EUCJPDecoder(options) {
  11655. var fatal = options.fatal;
  11656. // euc-jp's decoder has an associated euc-jp jis0212 flag
  11657. // (initially unset) and euc-jp lead (initially 0x00).
  11658. var /** @type {boolean} */ eucjp_jis0212_flag = false,
  11659. /** @type {number} */ eucjp_lead = 0x00;
  11660. /**
  11661. * @param {Stream} stream The stream of bytes being decoded.
  11662. * @param {number} bite The next byte read from the stream.
  11663. * @return {?(number|!Array.<number>)} The next code point(s)
  11664. * decoded, or null if not enough data exists in the input
  11665. * stream to decode a complete code point.
  11666. */
  11667. this.handler = function (stream, bite) {
  11668. // 1. If byte is end-of-stream and euc-jp lead is not 0x00, set
  11669. // euc-jp lead to 0x00, and return error.
  11670. if (bite === end_of_stream && eucjp_lead !== 0x00) {
  11671. eucjp_lead = 0x00;
  11672. return decoderError(fatal);
  11673. }
  11674. // 2. If byte is end-of-stream and euc-jp lead is 0x00, return
  11675. // finished.
  11676. if (bite === end_of_stream && eucjp_lead === 0x00)
  11677. return finished;
  11678. // 3. If euc-jp lead is 0x8E and byte is in the range 0xA1 to
  11679. // 0xDF, inclusive, set euc-jp lead to 0x00 and return a code
  11680. // point whose value is 0xFF61 − 0xA1 + byte.
  11681. if (eucjp_lead === 0x8E && inRange(bite, 0xA1, 0xDF)) {
  11682. eucjp_lead = 0x00;
  11683. return 0xFF61 - 0xA1 + bite;
  11684. }
  11685. // 4. If euc-jp lead is 0x8F and byte is in the range 0xA1 to
  11686. // 0xFE, inclusive, set the euc-jp jis0212 flag, set euc-jp lead
  11687. // to byte, and return continue.
  11688. if (eucjp_lead === 0x8F && inRange(bite, 0xA1, 0xFE)) {
  11689. eucjp_jis0212_flag = true;
  11690. eucjp_lead = bite;
  11691. return null;
  11692. }
  11693. // 5. If euc-jp lead is not 0x00, let lead be euc-jp lead, set
  11694. // euc-jp lead to 0x00, and run these substeps:
  11695. if (eucjp_lead !== 0x00) {
  11696. var lead = eucjp_lead;
  11697. eucjp_lead = 0x00;
  11698. // 1. Let code point be null.
  11699. var code_point = null;
  11700. // 2. If lead and byte are both in the range 0xA1 to 0xFE,
  11701. // inclusive, set code point to the index code point for (lead
  11702. // − 0xA1) × 94 + byte − 0xA1 in index jis0208 if the euc-jp
  11703. // jis0212 flag is unset and in index jis0212 otherwise.
  11704. if (inRange(lead, 0xA1, 0xFE) && inRange(bite, 0xA1, 0xFE)) {
  11705. code_point = indexCodePointFor(
  11706. (lead - 0xA1) * 94 + (bite - 0xA1),
  11707. index(!eucjp_jis0212_flag ? 'jis0208' : 'jis0212'));
  11708. }
  11709. // 3. Unset the euc-jp jis0212 flag.
  11710. eucjp_jis0212_flag = false;
  11711. // 4. If byte is not in the range 0xA1 to 0xFE, inclusive,
  11712. // prepend byte to stream.
  11713. if (!inRange(bite, 0xA1, 0xFE))
  11714. stream.prepend(bite);
  11715. // 5. If code point is null, return error.
  11716. if (code_point === null)
  11717. return decoderError(fatal);
  11718. // 6. Return a code point whose value is code point.
  11719. return code_point;
  11720. }
  11721. // 6. If byte is an ASCII byte, return a code point whose value
  11722. // is byte.
  11723. if (isASCIIByte(bite))
  11724. return bite;
  11725. // 7. If byte is 0x8E, 0x8F, or in the range 0xA1 to 0xFE,
  11726. // inclusive, set euc-jp lead to byte and return continue.
  11727. if (bite === 0x8E || bite === 0x8F || inRange(bite, 0xA1, 0xFE)) {
  11728. eucjp_lead = bite;
  11729. return null;
  11730. }
  11731. // 8. Return error.
  11732. return decoderError(fatal);
  11733. };
  11734. }
  11735. // 13.1.2 euc-jp encoder
  11736. /**
  11737. * @constructor
  11738. * @implements {Encoder}
  11739. * @param {{fatal: boolean}} options
  11740. */
  11741. function EUCJPEncoder(options) {
  11742. var fatal = options.fatal;
  11743. /**
  11744. * @param {Stream} stream Input stream.
  11745. * @param {number} code_point Next code point read from the stream.
  11746. * @return {(number|!Array.<number>)} Byte(s) to emit.
  11747. */
  11748. this.handler = function (stream, code_point) {
  11749. // 1. If code point is end-of-stream, return finished.
  11750. if (code_point === end_of_stream)
  11751. return finished;
  11752. // 2. If code point is an ASCII code point, return a byte whose
  11753. // value is code point.
  11754. if (isASCIICodePoint(code_point))
  11755. return code_point;
  11756. // 3. If code point is U+00A5, return byte 0x5C.
  11757. if (code_point === 0x00A5)
  11758. return 0x5C;
  11759. // 4. If code point is U+203E, return byte 0x7E.
  11760. if (code_point === 0x203E)
  11761. return 0x7E;
  11762. // 5. If code point is in the range U+FF61 to U+FF9F, inclusive,
  11763. // return two bytes whose values are 0x8E and code point −
  11764. // 0xFF61 + 0xA1.
  11765. if (inRange(code_point, 0xFF61, 0xFF9F))
  11766. return [0x8E, code_point - 0xFF61 + 0xA1];
  11767. // 6. If code point is U+2212, set it to U+FF0D.
  11768. if (code_point === 0x2212)
  11769. code_point = 0xFF0D;
  11770. // 7. Let pointer be the index pointer for code point in index
  11771. // jis0208.
  11772. var pointer = indexPointerFor(code_point, index('jis0208'));
  11773. // 8. If pointer is null, return error with code point.
  11774. if (pointer === null)
  11775. return encoderError(code_point);
  11776. // 9. Let lead be floor(pointer / 94) + 0xA1.
  11777. var lead = floor(pointer / 94) + 0xA1;
  11778. // 10. Let trail be pointer % 94 + 0xA1.
  11779. var trail = pointer % 94 + 0xA1;
  11780. // 11. Return two bytes whose values are lead and trail.
  11781. return [lead, trail];
  11782. };
  11783. }
  11784. /** @param {{fatal: boolean}} options */
  11785. encoders['EUC-JP'] = function (options) {
  11786. return new EUCJPEncoder(options);
  11787. };
  11788. /** @param {{fatal: boolean}} options */
  11789. decoders['EUC-JP'] = function (options) {
  11790. return new EUCJPDecoder(options);
  11791. };
  11792. // 13.2 iso-2022-jp
  11793. // 13.2.1 iso-2022-jp decoder
  11794. /**
  11795. * @constructor
  11796. * @implements {Decoder}
  11797. * @param {{fatal: boolean}} options
  11798. */
  11799. function ISO2022JPDecoder(options) {
  11800. var fatal = options.fatal;
  11801. /** @enum */
  11802. var states = {
  11803. ASCII: 0,
  11804. Roman: 1,
  11805. Katakana: 2,
  11806. LeadByte: 3,
  11807. TrailByte: 4,
  11808. EscapeStart: 5,
  11809. Escape: 6
  11810. };
  11811. // iso-2022-jp's decoder has an associated iso-2022-jp decoder
  11812. // state (initially ASCII), iso-2022-jp decoder output state
  11813. // (initially ASCII), iso-2022-jp lead (initially 0x00), and
  11814. // iso-2022-jp output flag (initially unset).
  11815. var /** @type {number} */ iso2022jp_decoder_state = states.ASCII,
  11816. /** @type {number} */ iso2022jp_decoder_output_state = states.ASCII,
  11817. /** @type {number} */ iso2022jp_lead = 0x00,
  11818. /** @type {boolean} */ iso2022jp_output_flag = false;
  11819. /**
  11820. * @param {Stream} stream The stream of bytes being decoded.
  11821. * @param {number} bite The next byte read from the stream.
  11822. * @return {?(number|!Array.<number>)} The next code point(s)
  11823. * decoded, or null if not enough data exists in the input
  11824. * stream to decode a complete code point.
  11825. */
  11826. this.handler = function (stream, bite) {
  11827. // switching on iso-2022-jp decoder state:
  11828. switch (iso2022jp_decoder_state) {
  11829. default:
  11830. case states.ASCII:
  11831. // ASCII
  11832. // Based on byte:
  11833. // 0x1B
  11834. if (bite === 0x1B) {
  11835. // Set iso-2022-jp decoder state to escape start and return
  11836. // continue.
  11837. iso2022jp_decoder_state = states.EscapeStart;
  11838. return null;
  11839. }
  11840. // 0x00 to 0x7F, excluding 0x0E, 0x0F, and 0x1B
  11841. if (inRange(bite, 0x00, 0x7F) && bite !== 0x0E
  11842. && bite !== 0x0F && bite !== 0x1B) {
  11843. // Unset the iso-2022-jp output flag and return a code point
  11844. // whose value is byte.
  11845. iso2022jp_output_flag = false;
  11846. return bite;
  11847. }
  11848. // end-of-stream
  11849. if (bite === end_of_stream) {
  11850. // Return finished.
  11851. return finished;
  11852. }
  11853. // Otherwise
  11854. // Unset the iso-2022-jp output flag and return error.
  11855. iso2022jp_output_flag = false;
  11856. return decoderError(fatal);
  11857. case states.Roman:
  11858. // Roman
  11859. // Based on byte:
  11860. // 0x1B
  11861. if (bite === 0x1B) {
  11862. // Set iso-2022-jp decoder state to escape start and return
  11863. // continue.
  11864. iso2022jp_decoder_state = states.EscapeStart;
  11865. return null;
  11866. }
  11867. // 0x5C
  11868. if (bite === 0x5C) {
  11869. // Unset the iso-2022-jp output flag and return code point
  11870. // U+00A5.
  11871. iso2022jp_output_flag = false;
  11872. return 0x00A5;
  11873. }
  11874. // 0x7E
  11875. if (bite === 0x7E) {
  11876. // Unset the iso-2022-jp output flag and return code point
  11877. // U+203E.
  11878. iso2022jp_output_flag = false;
  11879. return 0x203E;
  11880. }
  11881. // 0x00 to 0x7F, excluding 0x0E, 0x0F, 0x1B, 0x5C, and 0x7E
  11882. if (inRange(bite, 0x00, 0x7F) && bite !== 0x0E && bite !== 0x0F
  11883. && bite !== 0x1B && bite !== 0x5C && bite !== 0x7E) {
  11884. // Unset the iso-2022-jp output flag and return a code point
  11885. // whose value is byte.
  11886. iso2022jp_output_flag = false;
  11887. return bite;
  11888. }
  11889. // end-of-stream
  11890. if (bite === end_of_stream) {
  11891. // Return finished.
  11892. return finished;
  11893. }
  11894. // Otherwise
  11895. // Unset the iso-2022-jp output flag and return error.
  11896. iso2022jp_output_flag = false;
  11897. return decoderError(fatal);
  11898. case states.Katakana:
  11899. // Katakana
  11900. // Based on byte:
  11901. // 0x1B
  11902. if (bite === 0x1B) {
  11903. // Set iso-2022-jp decoder state to escape start and return
  11904. // continue.
  11905. iso2022jp_decoder_state = states.EscapeStart;
  11906. return null;
  11907. }
  11908. // 0x21 to 0x5F
  11909. if (inRange(bite, 0x21, 0x5F)) {
  11910. // Unset the iso-2022-jp output flag and return a code point
  11911. // whose value is 0xFF61 − 0x21 + byte.
  11912. iso2022jp_output_flag = false;
  11913. return 0xFF61 - 0x21 + bite;
  11914. }
  11915. // end-of-stream
  11916. if (bite === end_of_stream) {
  11917. // Return finished.
  11918. return finished;
  11919. }
  11920. // Otherwise
  11921. // Unset the iso-2022-jp output flag and return error.
  11922. iso2022jp_output_flag = false;
  11923. return decoderError(fatal);
  11924. case states.LeadByte:
  11925. // Lead byte
  11926. // Based on byte:
  11927. // 0x1B
  11928. if (bite === 0x1B) {
  11929. // Set iso-2022-jp decoder state to escape start and return
  11930. // continue.
  11931. iso2022jp_decoder_state = states.EscapeStart;
  11932. return null;
  11933. }
  11934. // 0x21 to 0x7E
  11935. if (inRange(bite, 0x21, 0x7E)) {
  11936. // Unset the iso-2022-jp output flag, set iso-2022-jp lead
  11937. // to byte, iso-2022-jp decoder state to trail byte, and
  11938. // return continue.
  11939. iso2022jp_output_flag = false;
  11940. iso2022jp_lead = bite;
  11941. iso2022jp_decoder_state = states.TrailByte;
  11942. return null;
  11943. }
  11944. // end-of-stream
  11945. if (bite === end_of_stream) {
  11946. // Return finished.
  11947. return finished;
  11948. }
  11949. // Otherwise
  11950. // Unset the iso-2022-jp output flag and return error.
  11951. iso2022jp_output_flag = false;
  11952. return decoderError(fatal);
  11953. case states.TrailByte:
  11954. // Trail byte
  11955. // Based on byte:
  11956. // 0x1B
  11957. if (bite === 0x1B) {
  11958. // Set iso-2022-jp decoder state to escape start and return
  11959. // continue.
  11960. iso2022jp_decoder_state = states.EscapeStart;
  11961. return decoderError(fatal);
  11962. }
  11963. // 0x21 to 0x7E
  11964. if (inRange(bite, 0x21, 0x7E)) {
  11965. // 1. Set the iso-2022-jp decoder state to lead byte.
  11966. iso2022jp_decoder_state = states.LeadByte;
  11967. // 2. Let pointer be (iso-2022-jp lead − 0x21) × 94 + byte − 0x21.
  11968. var pointer = (iso2022jp_lead - 0x21) * 94 + bite - 0x21;
  11969. // 3. Let code point be the index code point for pointer in
  11970. // index jis0208.
  11971. var code_point = indexCodePointFor(pointer, index('jis0208'));
  11972. // 4. If code point is null, return error.
  11973. if (code_point === null)
  11974. return decoderError(fatal);
  11975. // 5. Return a code point whose value is code point.
  11976. return code_point;
  11977. }
  11978. // end-of-stream
  11979. if (bite === end_of_stream) {
  11980. // Set the iso-2022-jp decoder state to lead byte, prepend
  11981. // byte to stream, and return error.
  11982. iso2022jp_decoder_state = states.LeadByte;
  11983. stream.prepend(bite);
  11984. return decoderError(fatal);
  11985. }
  11986. // Otherwise
  11987. // Set iso-2022-jp decoder state to lead byte and return
  11988. // error.
  11989. iso2022jp_decoder_state = states.LeadByte;
  11990. return decoderError(fatal);
  11991. case states.EscapeStart:
  11992. // Escape start
  11993. // 1. If byte is either 0x24 or 0x28, set iso-2022-jp lead to
  11994. // byte, iso-2022-jp decoder state to escape, and return
  11995. // continue.
  11996. if (bite === 0x24 || bite === 0x28) {
  11997. iso2022jp_lead = bite;
  11998. iso2022jp_decoder_state = states.Escape;
  11999. return null;
  12000. }
  12001. // 2. Prepend byte to stream.
  12002. stream.prepend(bite);
  12003. // 3. Unset the iso-2022-jp output flag, set iso-2022-jp
  12004. // decoder state to iso-2022-jp decoder output state, and
  12005. // return error.
  12006. iso2022jp_output_flag = false;
  12007. iso2022jp_decoder_state = iso2022jp_decoder_output_state;
  12008. return decoderError(fatal);
  12009. case states.Escape:
  12010. // Escape
  12011. // 1. Let lead be iso-2022-jp lead and set iso-2022-jp lead to
  12012. // 0x00.
  12013. var lead = iso2022jp_lead;
  12014. iso2022jp_lead = 0x00;
  12015. // 2. Let state be null.
  12016. var state = null;
  12017. // 3. If lead is 0x28 and byte is 0x42, set state to ASCII.
  12018. if (lead === 0x28 && bite === 0x42)
  12019. state = states.ASCII;
  12020. // 4. If lead is 0x28 and byte is 0x4A, set state to Roman.
  12021. if (lead === 0x28 && bite === 0x4A)
  12022. state = states.Roman;
  12023. // 5. If lead is 0x28 and byte is 0x49, set state to Katakana.
  12024. if (lead === 0x28 && bite === 0x49)
  12025. state = states.Katakana;
  12026. // 6. If lead is 0x24 and byte is either 0x40 or 0x42, set
  12027. // state to lead byte.
  12028. if (lead === 0x24 && (bite === 0x40 || bite === 0x42))
  12029. state = states.LeadByte;
  12030. // 7. If state is non-null, run these substeps:
  12031. if (state !== null) {
  12032. // 1. Set iso-2022-jp decoder state and iso-2022-jp decoder
  12033. // output state to states.
  12034. iso2022jp_decoder_state = iso2022jp_decoder_state = state;
  12035. // 2. Let output flag be the iso-2022-jp output flag.
  12036. var output_flag = iso2022jp_output_flag;
  12037. // 3. Set the iso-2022-jp output flag.
  12038. iso2022jp_output_flag = true;
  12039. // 4. Return continue, if output flag is unset, and error
  12040. // otherwise.
  12041. return !output_flag ? null : decoderError(fatal);
  12042. }
  12043. // 8. Prepend lead and byte to stream.
  12044. stream.prepend([lead, bite]);
  12045. // 9. Unset the iso-2022-jp output flag, set iso-2022-jp
  12046. // decoder state to iso-2022-jp decoder output state and
  12047. // return error.
  12048. iso2022jp_output_flag = false;
  12049. iso2022jp_decoder_state = iso2022jp_decoder_output_state;
  12050. return decoderError(fatal);
  12051. }
  12052. };
  12053. }
  12054. // 13.2.2 iso-2022-jp encoder
  12055. /**
  12056. * @constructor
  12057. * @implements {Encoder}
  12058. * @param {{fatal: boolean}} options
  12059. */
  12060. function ISO2022JPEncoder(options) {
  12061. var fatal = options.fatal;
  12062. // iso-2022-jp's encoder has an associated iso-2022-jp encoder
  12063. // state which is one of ASCII, Roman, and jis0208 (initially
  12064. // ASCII).
  12065. /** @enum */
  12066. var states = {
  12067. ASCII: 0,
  12068. Roman: 1,
  12069. jis0208: 2
  12070. };
  12071. var /** @type {number} */ iso2022jp_state = states.ASCII;
  12072. /**
  12073. * @param {Stream} stream Input stream.
  12074. * @param {number} code_point Next code point read from the stream.
  12075. * @return {(number|!Array.<number>)} Byte(s) to emit.
  12076. */
  12077. this.handler = function (stream, code_point) {
  12078. // 1. If code point is end-of-stream and iso-2022-jp encoder
  12079. // state is not ASCII, prepend code point to stream, set
  12080. // iso-2022-jp encoder state to ASCII, and return three bytes
  12081. // 0x1B 0x28 0x42.
  12082. if (code_point === end_of_stream &&
  12083. iso2022jp_state !== states.ASCII) {
  12084. stream.prepend(code_point);
  12085. iso2022jp_state = states.ASCII;
  12086. return [0x1B, 0x28, 0x42];
  12087. }
  12088. // 2. If code point is end-of-stream and iso-2022-jp encoder
  12089. // state is ASCII, return finished.
  12090. if (code_point === end_of_stream && iso2022jp_state === states.ASCII)
  12091. return finished;
  12092. // 3. If ISO-2022-JP encoder state is ASCII or Roman, and code
  12093. // point is U+000E, U+000F, or U+001B, return error with U+FFFD.
  12094. if ((iso2022jp_state === states.ASCII ||
  12095. iso2022jp_state === states.Roman) &&
  12096. (code_point === 0x000E || code_point === 0x000F ||
  12097. code_point === 0x001B)) {
  12098. return encoderError(0xFFFD);
  12099. }
  12100. // 4. If iso-2022-jp encoder state is ASCII and code point is an
  12101. // ASCII code point, return a byte whose value is code point.
  12102. if (iso2022jp_state === states.ASCII &&
  12103. isASCIICodePoint(code_point))
  12104. return code_point;
  12105. // 5. If iso-2022-jp encoder state is Roman and code point is an
  12106. // ASCII code point, excluding U+005C and U+007E, or is U+00A5
  12107. // or U+203E, run these substeps:
  12108. if (iso2022jp_state === states.Roman &&
  12109. ((isASCIICodePoint(code_point) &&
  12110. code_point !== 0x005C && code_point !== 0x007E) ||
  12111. (code_point == 0x00A5 || code_point == 0x203E))) {
  12112. // 1. If code point is an ASCII code point, return a byte
  12113. // whose value is code point.
  12114. if (isASCIICodePoint(code_point))
  12115. return code_point;
  12116. // 2. If code point is U+00A5, return byte 0x5C.
  12117. if (code_point === 0x00A5)
  12118. return 0x5C;
  12119. // 3. If code point is U+203E, return byte 0x7E.
  12120. if (code_point === 0x203E)
  12121. return 0x7E;
  12122. }
  12123. // 6. If code point is an ASCII code point, and iso-2022-jp
  12124. // encoder state is not ASCII, prepend code point to stream, set
  12125. // iso-2022-jp encoder state to ASCII, and return three bytes
  12126. // 0x1B 0x28 0x42.
  12127. if (isASCIICodePoint(code_point) &&
  12128. iso2022jp_state !== states.ASCII) {
  12129. stream.prepend(code_point);
  12130. iso2022jp_state = states.ASCII;
  12131. return [0x1B, 0x28, 0x42];
  12132. }
  12133. // 7. If code point is either U+00A5 or U+203E, and iso-2022-jp
  12134. // encoder state is not Roman, prepend code point to stream, set
  12135. // iso-2022-jp encoder state to Roman, and return three bytes
  12136. // 0x1B 0x28 0x4A.
  12137. if ((code_point === 0x00A5 || code_point === 0x203E) &&
  12138. iso2022jp_state !== states.Roman) {
  12139. stream.prepend(code_point);
  12140. iso2022jp_state = states.Roman;
  12141. return [0x1B, 0x28, 0x4A];
  12142. }
  12143. // 8. If code point is U+2212, set it to U+FF0D.
  12144. if (code_point === 0x2212)
  12145. code_point = 0xFF0D;
  12146. // 9. Let pointer be the index pointer for code point in index
  12147. // jis0208.
  12148. var pointer = indexPointerFor(code_point, index('jis0208'));
  12149. // 10. If pointer is null, return error with code point.
  12150. if (pointer === null)
  12151. return encoderError(code_point);
  12152. // 11. If iso-2022-jp encoder state is not jis0208, prepend code
  12153. // point to stream, set iso-2022-jp encoder state to jis0208,
  12154. // and return three bytes 0x1B 0x24 0x42.
  12155. if (iso2022jp_state !== states.jis0208) {
  12156. stream.prepend(code_point);
  12157. iso2022jp_state = states.jis0208;
  12158. return [0x1B, 0x24, 0x42];
  12159. }
  12160. // 12. Let lead be floor(pointer / 94) + 0x21.
  12161. var lead = floor(pointer / 94) + 0x21;
  12162. // 13. Let trail be pointer % 94 + 0x21.
  12163. var trail = pointer % 94 + 0x21;
  12164. // 14. Return two bytes whose values are lead and trail.
  12165. return [lead, trail];
  12166. };
  12167. }
  12168. /** @param {{fatal: boolean}} options */
  12169. encoders['ISO-2022-JP'] = function (options) {
  12170. return new ISO2022JPEncoder(options);
  12171. };
  12172. /** @param {{fatal: boolean}} options */
  12173. decoders['ISO-2022-JP'] = function (options) {
  12174. return new ISO2022JPDecoder(options);
  12175. };
  12176. // 13.3 Shift_JIS
  12177. // 13.3.1 Shift_JIS decoder
  12178. /**
  12179. * @constructor
  12180. * @implements {Decoder}
  12181. * @param {{fatal: boolean}} options
  12182. */
  12183. function ShiftJISDecoder(options) {
  12184. var fatal = options.fatal;
  12185. // Shift_JIS's decoder has an associated Shift_JIS lead (initially
  12186. // 0x00).
  12187. var /** @type {number} */ Shift_JIS_lead = 0x00;
  12188. /**
  12189. * @param {Stream} stream The stream of bytes being decoded.
  12190. * @param {number} bite The next byte read from the stream.
  12191. * @return {?(number|!Array.<number>)} The next code point(s)
  12192. * decoded, or null if not enough data exists in the input
  12193. * stream to decode a complete code point.
  12194. */
  12195. this.handler = function (stream, bite) {
  12196. // 1. If byte is end-of-stream and Shift_JIS lead is not 0x00,
  12197. // set Shift_JIS lead to 0x00 and return error.
  12198. if (bite === end_of_stream && Shift_JIS_lead !== 0x00) {
  12199. Shift_JIS_lead = 0x00;
  12200. return decoderError(fatal);
  12201. }
  12202. // 2. If byte is end-of-stream and Shift_JIS lead is 0x00,
  12203. // return finished.
  12204. if (bite === end_of_stream && Shift_JIS_lead === 0x00)
  12205. return finished;
  12206. // 3. If Shift_JIS lead is not 0x00, let lead be Shift_JIS lead,
  12207. // let pointer be null, set Shift_JIS lead to 0x00, and then run
  12208. // these substeps:
  12209. if (Shift_JIS_lead !== 0x00) {
  12210. var lead = Shift_JIS_lead;
  12211. var pointer = null;
  12212. Shift_JIS_lead = 0x00;
  12213. // 1. Let offset be 0x40, if byte is less than 0x7F, and 0x41
  12214. // otherwise.
  12215. var offset = (bite < 0x7F) ? 0x40 : 0x41;
  12216. // 2. Let lead offset be 0x81, if lead is less than 0xA0, and
  12217. // 0xC1 otherwise.
  12218. var lead_offset = (lead < 0xA0) ? 0x81 : 0xC1;
  12219. // 3. If byte is in the range 0x40 to 0x7E, inclusive, or 0x80
  12220. // to 0xFC, inclusive, set pointer to (lead − lead offset) ×
  12221. // 188 + byte − offset.
  12222. if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0x80, 0xFC))
  12223. pointer = (lead - lead_offset) * 188 + bite - offset;
  12224. // 4. If pointer is in the range 8836 to 10715, inclusive,
  12225. // return a code point whose value is 0xE000 − 8836 + pointer.
  12226. if (inRange(pointer, 8836, 10715))
  12227. return 0xE000 - 8836 + pointer;
  12228. // 5. Let code point be null, if pointer is null, and the
  12229. // index code point for pointer in index jis0208 otherwise.
  12230. var code_point = (pointer === null) ? null :
  12231. indexCodePointFor(pointer, index('jis0208'));
  12232. // 6. If code point is null and byte is an ASCII byte, prepend
  12233. // byte to stream.
  12234. if (code_point === null && isASCIIByte(bite))
  12235. stream.prepend(bite);
  12236. // 7. If code point is null, return error.
  12237. if (code_point === null)
  12238. return decoderError(fatal);
  12239. // 8. Return a code point whose value is code point.
  12240. return code_point;
  12241. }
  12242. // 4. If byte is an ASCII byte or 0x80, return a code point
  12243. // whose value is byte.
  12244. if (isASCIIByte(bite) || bite === 0x80)
  12245. return bite;
  12246. // 5. If byte is in the range 0xA1 to 0xDF, inclusive, return a
  12247. // code point whose value is 0xFF61 − 0xA1 + byte.
  12248. if (inRange(bite, 0xA1, 0xDF))
  12249. return 0xFF61 - 0xA1 + bite;
  12250. // 6. If byte is in the range 0x81 to 0x9F, inclusive, or 0xE0
  12251. // to 0xFC, inclusive, set Shift_JIS lead to byte and return
  12252. // continue.
  12253. if (inRange(bite, 0x81, 0x9F) || inRange(bite, 0xE0, 0xFC)) {
  12254. Shift_JIS_lead = bite;
  12255. return null;
  12256. }
  12257. // 7. Return error.
  12258. return decoderError(fatal);
  12259. };
  12260. }
  12261. // 13.3.2 Shift_JIS encoder
  12262. /**
  12263. * @constructor
  12264. * @implements {Encoder}
  12265. * @param {{fatal: boolean}} options
  12266. */
  12267. function ShiftJISEncoder(options) {
  12268. var fatal = options.fatal;
  12269. /**
  12270. * @param {Stream} stream Input stream.
  12271. * @param {number} code_point Next code point read from the stream.
  12272. * @return {(number|!Array.<number>)} Byte(s) to emit.
  12273. */
  12274. this.handler = function (stream, code_point) {
  12275. // 1. If code point is end-of-stream, return finished.
  12276. if (code_point === end_of_stream)
  12277. return finished;
  12278. // 2. If code point is an ASCII code point or U+0080, return a
  12279. // byte whose value is code point.
  12280. if (isASCIICodePoint(code_point) || code_point === 0x0080)
  12281. return code_point;
  12282. // 3. If code point is U+00A5, return byte 0x5C.
  12283. if (code_point === 0x00A5)
  12284. return 0x5C;
  12285. // 4. If code point is U+203E, return byte 0x7E.
  12286. if (code_point === 0x203E)
  12287. return 0x7E;
  12288. // 5. If code point is in the range U+FF61 to U+FF9F, inclusive,
  12289. // return a byte whose value is code point − 0xFF61 + 0xA1.
  12290. if (inRange(code_point, 0xFF61, 0xFF9F))
  12291. return code_point - 0xFF61 + 0xA1;
  12292. // 6. If code point is U+2212, set it to U+FF0D.
  12293. if (code_point === 0x2212)
  12294. code_point = 0xFF0D;
  12295. // 7. Let pointer be the index Shift_JIS pointer for code point.
  12296. var pointer = indexShiftJISPointerFor(code_point);
  12297. // 8. If pointer is null, return error with code point.
  12298. if (pointer === null)
  12299. return encoderError(code_point);
  12300. // 9. Let lead be floor(pointer / 188).
  12301. var lead = floor(pointer / 188);
  12302. // 10. Let lead offset be 0x81, if lead is less than 0x1F, and
  12303. // 0xC1 otherwise.
  12304. var lead_offset = (lead < 0x1F) ? 0x81 : 0xC1;
  12305. // 11. Let trail be pointer % 188.
  12306. var trail = pointer % 188;
  12307. // 12. Let offset be 0x40, if trail is less than 0x3F, and 0x41
  12308. // otherwise.
  12309. var offset = (trail < 0x3F) ? 0x40 : 0x41;
  12310. // 13. Return two bytes whose values are lead + lead offset and
  12311. // trail + offset.
  12312. return [lead + lead_offset, trail + offset];
  12313. };
  12314. }
  12315. /** @param {{fatal: boolean}} options */
  12316. encoders['Shift_JIS'] = function (options) {
  12317. return new ShiftJISEncoder(options);
  12318. };
  12319. /** @param {{fatal: boolean}} options */
  12320. decoders['Shift_JIS'] = function (options) {
  12321. return new ShiftJISDecoder(options);
  12322. };
  12323. //
  12324. // 14. Legacy multi-byte Korean encodings
  12325. //
  12326. // 14.1 euc-kr
  12327. // 14.1.1 euc-kr decoder
  12328. /**
  12329. * @constructor
  12330. * @implements {Decoder}
  12331. * @param {{fatal: boolean}} options
  12332. */
  12333. function EUCKRDecoder(options) {
  12334. var fatal = options.fatal;
  12335. // euc-kr's decoder has an associated euc-kr lead (initially 0x00).
  12336. var /** @type {number} */ euckr_lead = 0x00;
  12337. /**
  12338. * @param {Stream} stream The stream of bytes being decoded.
  12339. * @param {number} bite The next byte read from the stream.
  12340. * @return {?(number|!Array.<number>)} The next code point(s)
  12341. * decoded, or null if not enough data exists in the input
  12342. * stream to decode a complete code point.
  12343. */
  12344. this.handler = function (stream, bite) {
  12345. // 1. If byte is end-of-stream and euc-kr lead is not 0x00, set
  12346. // euc-kr lead to 0x00 and return error.
  12347. if (bite === end_of_stream && euckr_lead !== 0) {
  12348. euckr_lead = 0x00;
  12349. return decoderError(fatal);
  12350. }
  12351. // 2. If byte is end-of-stream and euc-kr lead is 0x00, return
  12352. // finished.
  12353. if (bite === end_of_stream && euckr_lead === 0)
  12354. return finished;
  12355. // 3. If euc-kr lead is not 0x00, let lead be euc-kr lead, let
  12356. // pointer be null, set euc-kr lead to 0x00, and then run these
  12357. // substeps:
  12358. if (euckr_lead !== 0x00) {
  12359. var lead = euckr_lead;
  12360. var pointer = null;
  12361. euckr_lead = 0x00;
  12362. // 1. If byte is in the range 0x41 to 0xFE, inclusive, set
  12363. // pointer to (lead − 0x81) × 190 + (byte − 0x41).
  12364. if (inRange(bite, 0x41, 0xFE))
  12365. pointer = (lead - 0x81) * 190 + (bite - 0x41);
  12366. // 2. Let code point be null, if pointer is null, and the
  12367. // index code point for pointer in index euc-kr otherwise.
  12368. var code_point = (pointer === null)
  12369. ? null : indexCodePointFor(pointer, index('euc-kr'));
  12370. // 3. If code point is null and byte is an ASCII byte, prepend
  12371. // byte to stream.
  12372. if (pointer === null && isASCIIByte(bite))
  12373. stream.prepend(bite);
  12374. // 4. If code point is null, return error.
  12375. if (code_point === null)
  12376. return decoderError(fatal);
  12377. // 5. Return a code point whose value is code point.
  12378. return code_point;
  12379. }
  12380. // 4. If byte is an ASCII byte, return a code point whose value
  12381. // is byte.
  12382. if (isASCIIByte(bite))
  12383. return bite;
  12384. // 5. If byte is in the range 0x81 to 0xFE, inclusive, set
  12385. // euc-kr lead to byte and return continue.
  12386. if (inRange(bite, 0x81, 0xFE)) {
  12387. euckr_lead = bite;
  12388. return null;
  12389. }
  12390. // 6. Return error.
  12391. return decoderError(fatal);
  12392. };
  12393. }
  12394. // 14.1.2 euc-kr encoder
  12395. /**
  12396. * @constructor
  12397. * @implements {Encoder}
  12398. * @param {{fatal: boolean}} options
  12399. */
  12400. function EUCKREncoder(options) {
  12401. var fatal = options.fatal;
  12402. /**
  12403. * @param {Stream} stream Input stream.
  12404. * @param {number} code_point Next code point read from the stream.
  12405. * @return {(number|!Array.<number>)} Byte(s) to emit.
  12406. */
  12407. this.handler = function (stream, code_point) {
  12408. // 1. If code point is end-of-stream, return finished.
  12409. if (code_point === end_of_stream)
  12410. return finished;
  12411. // 2. If code point is an ASCII code point, return a byte whose
  12412. // value is code point.
  12413. if (isASCIICodePoint(code_point))
  12414. return code_point;
  12415. // 3. Let pointer be the index pointer for code point in index
  12416. // euc-kr.
  12417. var pointer = indexPointerFor(code_point, index('euc-kr'));
  12418. // 4. If pointer is null, return error with code point.
  12419. if (pointer === null)
  12420. return encoderError(code_point);
  12421. // 5. Let lead be floor(pointer / 190) + 0x81.
  12422. var lead = floor(pointer / 190) + 0x81;
  12423. // 6. Let trail be pointer % 190 + 0x41.
  12424. var trail = (pointer % 190) + 0x41;
  12425. // 7. Return two bytes whose values are lead and trail.
  12426. return [lead, trail];
  12427. };
  12428. }
  12429. /** @param {{fatal: boolean}} options */
  12430. encoders['EUC-KR'] = function (options) {
  12431. return new EUCKREncoder(options);
  12432. };
  12433. /** @param {{fatal: boolean}} options */
  12434. decoders['EUC-KR'] = function (options) {
  12435. return new EUCKRDecoder(options);
  12436. };
  12437. //
  12438. // 15. Legacy miscellaneous encodings
  12439. //
  12440. // 15.1 replacement
  12441. // Not needed - API throws RangeError
  12442. // 15.2 Common infrastructure for utf-16be and utf-16le
  12443. /**
  12444. * @param {number} code_unit
  12445. * @param {boolean} utf16be
  12446. * @return {!Array.<number>} bytes
  12447. */
  12448. function convertCodeUnitToBytes(code_unit, utf16be) {
  12449. // 1. Let byte1 be code unit >> 8.
  12450. var byte1 = code_unit >> 8;
  12451. // 2. Let byte2 be code unit & 0x00FF.
  12452. var byte2 = code_unit & 0x00FF;
  12453. // 3. Then return the bytes in order:
  12454. // utf-16be flag is set: byte1, then byte2.
  12455. if (utf16be)
  12456. return [byte1, byte2];
  12457. // utf-16be flag is unset: byte2, then byte1.
  12458. return [byte2, byte1];
  12459. }
  12460. // 15.2.1 shared utf-16 decoder
  12461. /**
  12462. * @constructor
  12463. * @implements {Decoder}
  12464. * @param {boolean} utf16_be True if big-endian, false if little-endian.
  12465. * @param {{fatal: boolean}} options
  12466. */
  12467. function UTF16Decoder(utf16_be, options) {
  12468. var fatal = options.fatal;
  12469. var /** @type {?number} */ utf16_lead_byte = null,
  12470. /** @type {?number} */ utf16_lead_surrogate = null;
  12471. /**
  12472. * @param {Stream} stream The stream of bytes being decoded.
  12473. * @param {number} bite The next byte read from the stream.
  12474. * @return {?(number|!Array.<number>)} The next code point(s)
  12475. * decoded, or null if not enough data exists in the input
  12476. * stream to decode a complete code point.
  12477. */
  12478. this.handler = function (stream, bite) {
  12479. // 1. If byte is end-of-stream and either utf-16 lead byte or
  12480. // utf-16 lead surrogate is not null, set utf-16 lead byte and
  12481. // utf-16 lead surrogate to null, and return error.
  12482. if (bite === end_of_stream && (utf16_lead_byte !== null ||
  12483. utf16_lead_surrogate !== null)) {
  12484. return decoderError(fatal);
  12485. }
  12486. // 2. If byte is end-of-stream and utf-16 lead byte and utf-16
  12487. // lead surrogate are null, return finished.
  12488. if (bite === end_of_stream && utf16_lead_byte === null &&
  12489. utf16_lead_surrogate === null) {
  12490. return finished;
  12491. }
  12492. // 3. If utf-16 lead byte is null, set utf-16 lead byte to byte
  12493. // and return continue.
  12494. if (utf16_lead_byte === null) {
  12495. utf16_lead_byte = bite;
  12496. return null;
  12497. }
  12498. // 4. Let code unit be the result of:
  12499. var code_unit;
  12500. if (utf16_be) {
  12501. // utf-16be decoder flag is set
  12502. // (utf-16 lead byte << 8) + byte.
  12503. code_unit = (utf16_lead_byte << 8) + bite;
  12504. } else {
  12505. // utf-16be decoder flag is unset
  12506. // (byte << 8) + utf-16 lead byte.
  12507. code_unit = (bite << 8) + utf16_lead_byte;
  12508. }
  12509. // Then set utf-16 lead byte to null.
  12510. utf16_lead_byte = null;
  12511. // 5. If utf-16 lead surrogate is not null, let lead surrogate
  12512. // be utf-16 lead surrogate, set utf-16 lead surrogate to null,
  12513. // and then run these substeps:
  12514. if (utf16_lead_surrogate !== null) {
  12515. var lead_surrogate = utf16_lead_surrogate;
  12516. utf16_lead_surrogate = null;
  12517. // 1. If code unit is in the range U+DC00 to U+DFFF,
  12518. // inclusive, return a code point whose value is 0x10000 +
  12519. // ((lead surrogate − 0xD800) << 10) + (code unit − 0xDC00).
  12520. if (inRange(code_unit, 0xDC00, 0xDFFF)) {
  12521. return 0x10000 + (lead_surrogate - 0xD800) * 0x400 +
  12522. (code_unit - 0xDC00);
  12523. }
  12524. // 2. Prepend the sequence resulting of converting code unit
  12525. // to bytes using utf-16be decoder flag to stream and return
  12526. // error.
  12527. stream.prepend(convertCodeUnitToBytes(code_unit, utf16_be));
  12528. return decoderError(fatal);
  12529. }
  12530. // 6. If code unit is in the range U+D800 to U+DBFF, inclusive,
  12531. // set utf-16 lead surrogate to code unit and return continue.
  12532. if (inRange(code_unit, 0xD800, 0xDBFF)) {
  12533. utf16_lead_surrogate = code_unit;
  12534. return null;
  12535. }
  12536. // 7. If code unit is in the range U+DC00 to U+DFFF, inclusive,
  12537. // return error.
  12538. if (inRange(code_unit, 0xDC00, 0xDFFF))
  12539. return decoderError(fatal);
  12540. // 8. Return code point code unit.
  12541. return code_unit;
  12542. };
  12543. }
  12544. // 15.2.2 shared utf-16 encoder
  12545. /**
  12546. * @constructor
  12547. * @implements {Encoder}
  12548. * @param {boolean} utf16_be True if big-endian, false if little-endian.
  12549. * @param {{fatal: boolean}} options
  12550. */
  12551. function UTF16Encoder(utf16_be, options) {
  12552. var fatal = options.fatal;
  12553. /**
  12554. * @param {Stream} stream Input stream.
  12555. * @param {number} code_point Next code point read from the stream.
  12556. * @return {(number|!Array.<number>)} Byte(s) to emit.
  12557. */
  12558. this.handler = function (stream, code_point) {
  12559. // 1. If code point is end-of-stream, return finished.
  12560. if (code_point === end_of_stream)
  12561. return finished;
  12562. // 2. If code point is in the range U+0000 to U+FFFF, inclusive,
  12563. // return the sequence resulting of converting code point to
  12564. // bytes using utf-16be encoder flag.
  12565. if (inRange(code_point, 0x0000, 0xFFFF))
  12566. return convertCodeUnitToBytes(code_point, utf16_be);
  12567. // 3. Let lead be ((code point − 0x10000) >> 10) + 0xD800,
  12568. // converted to bytes using utf-16be encoder flag.
  12569. var lead = convertCodeUnitToBytes(
  12570. ((code_point - 0x10000) >> 10) + 0xD800, utf16_be);
  12571. // 4. Let trail be ((code point − 0x10000) & 0x3FF) + 0xDC00,
  12572. // converted to bytes using utf-16be encoder flag.
  12573. var trail = convertCodeUnitToBytes(
  12574. ((code_point - 0x10000) & 0x3FF) + 0xDC00, utf16_be);
  12575. // 5. Return a byte sequence of lead followed by trail.
  12576. return lead.concat(trail);
  12577. };
  12578. }
  12579. // 15.3 utf-16be
  12580. // 15.3.1 utf-16be decoder
  12581. /** @param {{fatal: boolean}} options */
  12582. encoders['UTF-16BE'] = function (options) {
  12583. return new UTF16Encoder(true, options);
  12584. };
  12585. // 15.3.2 utf-16be encoder
  12586. /** @param {{fatal: boolean}} options */
  12587. decoders['UTF-16BE'] = function (options) {
  12588. return new UTF16Decoder(true, options);
  12589. };
  12590. // 15.4 utf-16le
  12591. // 15.4.1 utf-16le decoder
  12592. /** @param {{fatal: boolean}} options */
  12593. encoders['UTF-16LE'] = function (options) {
  12594. return new UTF16Encoder(false, options);
  12595. };
  12596. // 15.4.2 utf-16le encoder
  12597. /** @param {{fatal: boolean}} options */
  12598. decoders['UTF-16LE'] = function (options) {
  12599. return new UTF16Decoder(false, options);
  12600. };
  12601. // 15.5 x-user-defined
  12602. // 15.5.1 x-user-defined decoder
  12603. /**
  12604. * @constructor
  12605. * @implements {Decoder}
  12606. * @param {{fatal: boolean}} options
  12607. */
  12608. function XUserDefinedDecoder(options) {
  12609. var fatal = options.fatal;
  12610. /**
  12611. * @param {Stream} stream The stream of bytes being decoded.
  12612. * @param {number} bite The next byte read from the stream.
  12613. * @return {?(number|!Array.<number>)} The next code point(s)
  12614. * decoded, or null if not enough data exists in the input
  12615. * stream to decode a complete code point.
  12616. */
  12617. this.handler = function (stream, bite) {
  12618. // 1. If byte is end-of-stream, return finished.
  12619. if (bite === end_of_stream)
  12620. return finished;
  12621. // 2. If byte is an ASCII byte, return a code point whose value
  12622. // is byte.
  12623. if (isASCIIByte(bite))
  12624. return bite;
  12625. // 3. Return a code point whose value is 0xF780 + byte − 0x80.
  12626. return 0xF780 + bite - 0x80;
  12627. };
  12628. }
  12629. // 15.5.2 x-user-defined encoder
  12630. /**
  12631. * @constructor
  12632. * @implements {Encoder}
  12633. * @param {{fatal: boolean}} options
  12634. */
  12635. function XUserDefinedEncoder(options) {
  12636. var fatal = options.fatal;
  12637. /**
  12638. * @param {Stream} stream Input stream.
  12639. * @param {number} code_point Next code point read from the stream.
  12640. * @return {(number|!Array.<number>)} Byte(s) to emit.
  12641. */
  12642. this.handler = function (stream, code_point) {
  12643. // 1.If code point is end-of-stream, return finished.
  12644. if (code_point === end_of_stream)
  12645. return finished;
  12646. // 2. If code point is an ASCII code point, return a byte whose
  12647. // value is code point.
  12648. if (isASCIICodePoint(code_point))
  12649. return code_point;
  12650. // 3. If code point is in the range U+F780 to U+F7FF, inclusive,
  12651. // return a byte whose value is code point − 0xF780 + 0x80.
  12652. if (inRange(code_point, 0xF780, 0xF7FF))
  12653. return code_point - 0xF780 + 0x80;
  12654. // 4. Return error with code point.
  12655. return encoderError(code_point);
  12656. };
  12657. }
  12658. /** @param {{fatal: boolean}} options */
  12659. encoders['x-user-defined'] = function (options) {
  12660. return new XUserDefinedEncoder(options);
  12661. };
  12662. /** @param {{fatal: boolean}} options */
  12663. decoders['x-user-defined'] = function (options) {
  12664. return new XUserDefinedDecoder(options);
  12665. };
  12666. if (!global['TextEncoder'])
  12667. global['TextEncoder'] = TextEncoder;
  12668. if (!global['TextDecoder'])
  12669. global['TextDecoder'] = TextDecoder;
  12670. if (typeof module !== "undefined" && module.exports) {
  12671. module.exports = {
  12672. TextEncoder: global['TextEncoder'],
  12673. TextDecoder: global['TextDecoder'],
  12674. EncodingIndexes: global["encoding-indexes"]
  12675. };
  12676. }
  12677. // For strict environments where `this` inside the global scope
  12678. // is `undefined`, take a pure object instead
  12679. }(this || {}));
  12680. }, { "./encoding-indexes.js": 7 }], 22: [function (require, module, exports) {
  12681. (function (setImmediate, clearImmediate) {
  12682. (function () {
  12683. var nextTick = require('process/browser.js').nextTick;
  12684. var apply = Function.prototype.apply;
  12685. var slice = Array.prototype.slice;
  12686. var immediateIds = {};
  12687. var nextImmediateId = 0;
  12688. // DOM APIs, for completeness
  12689. exports.setTimeout = function () {
  12690. return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
  12691. };
  12692. exports.setInterval = function () {
  12693. return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
  12694. };
  12695. exports.clearTimeout =
  12696. exports.clearInterval = function (timeout) { timeout.close(); };
  12697. function Timeout(id, clearFn) {
  12698. this._id = id;
  12699. this._clearFn = clearFn;
  12700. }
  12701. Timeout.prototype.unref = Timeout.prototype.ref = function () { };
  12702. Timeout.prototype.close = function () {
  12703. this._clearFn.call(window, this._id);
  12704. };
  12705. // Does not start the time, just sets up the members needed.
  12706. exports.enroll = function (item, msecs) {
  12707. clearTimeout(item._idleTimeoutId);
  12708. item._idleTimeout = msecs;
  12709. };
  12710. exports.unenroll = function (item) {
  12711. clearTimeout(item._idleTimeoutId);
  12712. item._idleTimeout = -1;
  12713. };
  12714. exports._unrefActive = exports.active = function (item) {
  12715. clearTimeout(item._idleTimeoutId);
  12716. var msecs = item._idleTimeout;
  12717. if (msecs >= 0) {
  12718. item._idleTimeoutId = setTimeout(function onTimeout() {
  12719. if (item._onTimeout)
  12720. item._onTimeout();
  12721. }, msecs);
  12722. }
  12723. };
  12724. // That's not how node.js implements it but the exposed api is the same.
  12725. exports.setImmediate = typeof setImmediate === "function" ? setImmediate : function (fn) {
  12726. var id = nextImmediateId++;
  12727. var args = arguments.length < 2 ? false : slice.call(arguments, 1);
  12728. immediateIds[id] = true;
  12729. nextTick(function onNextTick() {
  12730. if (immediateIds[id]) {
  12731. // fn.call() is faster so we optimize for the common use-case
  12732. // @see http://jsperf.com/call-apply-segu
  12733. if (args) {
  12734. fn.apply(null, args);
  12735. } else {
  12736. fn.call(null);
  12737. }
  12738. // Prevent ids from leaking
  12739. exports.clearImmediate(id);
  12740. }
  12741. });
  12742. return id;
  12743. };
  12744. exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate : function (id) {
  12745. delete immediateIds[id];
  12746. };
  12747. }).call(this)
  12748. }).call(this, require("timers").setImmediate, require("timers").clearImmediate)
  12749. }, { "process/browser.js": 16, "timers": 22 }], 23: [function (require, module, exports) {
  12750. (function (global) {
  12751. (function () {
  12752. 'use strict';
  12753. let proj4 = require('proj4');
  12754. if (proj4.default) {
  12755. proj4 = proj4.default;
  12756. }
  12757. const unzip = require('./unzip');
  12758. const binaryAjax = require('./binaryajax');
  12759. const parseShp = require('./parseShp');
  12760. const parseDbf = require('parsedbf');
  12761. const Promise = require('lie');
  12762. const Cache = require('lru-cache');
  12763. const Buffer = require('buffer').Buffer;
  12764. const URL = global.URL;
  12765. const cache = new Cache({
  12766. max: 20
  12767. });
  12768. function toBuffer(b) {
  12769. if (!b) {
  12770. throw new Error('forgot to pass buffer');
  12771. }
  12772. if (Buffer.isBuffer(b)) {
  12773. return b;
  12774. }
  12775. if (isArrayBuffer(b)) {
  12776. return Buffer.from(b);
  12777. }
  12778. if (isArrayBuffer(b.buffer)) {
  12779. if (b.BYTES_PER_ELEMENT === 1) {
  12780. return Buffer.from(b);
  12781. }
  12782. return Buffer.from(b.buffer);
  12783. }
  12784. }
  12785. function isArrayBuffer(subject) {
  12786. return subject instanceof global.ArrayBuffer || Object.prototype.toString.call(subject) === '[object ArrayBuffer]';
  12787. }
  12788. function shp(base, whiteList) {
  12789. if (typeof base === 'string' && cache.has(base)) {
  12790. return Promise.resolve(cache.get(base));
  12791. }
  12792. return shp.getShapefile(base, whiteList).then(function (resp) {
  12793. if (typeof base === 'string') {
  12794. cache.set(base, resp);
  12795. }
  12796. return resp;
  12797. });
  12798. }
  12799. shp.combine = function ([shp, dbf]) {
  12800. const out = {};
  12801. out.type = 'FeatureCollection';
  12802. out.features = [];
  12803. let i = 0;
  12804. const len = shp.length;
  12805. if (!dbf) {
  12806. dbf = [];
  12807. }
  12808. while (i < len) {
  12809. out.features.push({
  12810. type: 'Feature',
  12811. geometry: shp[i],
  12812. properties: dbf[i] || {}
  12813. });
  12814. i++;
  12815. }
  12816. return out;
  12817. };
  12818. shp.parseZip = async function (buffer, whiteList) {
  12819. let key;
  12820. buffer = toBuffer(buffer);
  12821. const zip = await unzip(buffer);
  12822. const names = [];
  12823. whiteList = whiteList || [];
  12824. for (key in zip) {
  12825. if (key.indexOf('__MACOSX') !== -1) {
  12826. continue;
  12827. }
  12828. if (key.slice(-3).toLowerCase() === 'shp') {
  12829. names.push(key.slice(0, -4));
  12830. zip[key.slice(0, -3) + key.slice(-3).toLowerCase()] = zip[key];
  12831. } else if (key.slice(-3).toLowerCase() === 'prj') {
  12832. zip[key.slice(0, -3) + key.slice(-3).toLowerCase()] = proj4(zip[key]);
  12833. } else if (key.slice(-4).toLowerCase() === 'json' || whiteList.indexOf(key.split('.').pop()) > -1) {
  12834. names.push(key.slice(0, -3) + key.slice(-3).toLowerCase());
  12835. } else if (key.slice(-3).toLowerCase() === 'dbf' || key.slice(-3).toLowerCase() === 'cpg') {
  12836. zip[key.slice(0, -3) + key.slice(-3).toLowerCase()] = zip[key];
  12837. }
  12838. }
  12839. if (!names.length) {
  12840. throw new Error('no layers founds');
  12841. }
  12842. const geojson = names.map(function (name) {
  12843. let parsed, dbf;
  12844. const lastDotIdx = name.lastIndexOf('.');
  12845. if (lastDotIdx > -1 && name.slice(lastDotIdx).indexOf('json') > -1) {
  12846. parsed = JSON.parse(zip[name]);
  12847. parsed.fileName = name.slice(0, lastDotIdx);
  12848. } else if (whiteList.indexOf(name.slice(lastDotIdx + 1)) > -1) {
  12849. parsed = zip[name];
  12850. parsed.fileName = name;
  12851. } else {
  12852. if (zip[name + '.dbf']) {
  12853. dbf = parseDbf(zip[name + '.dbf'], zip[name + '.cpg']);
  12854. }
  12855. parsed = shp.combine([parseShp(zip[name + '.shp'], zip[name + '.prj']), dbf]);
  12856. parsed.fileName = name;
  12857. }
  12858. return parsed;
  12859. });
  12860. if (geojson.length === 1) {
  12861. return geojson[0];
  12862. } else {
  12863. return geojson;
  12864. }
  12865. };
  12866. async function getZip(base, whiteList) {
  12867. const a = await binaryAjax(base);
  12868. return shp.parseZip(a, whiteList);
  12869. }
  12870. const handleShp = async (base) => {
  12871. const args = await Promise.all([
  12872. binaryAjax(base, 'shp'),
  12873. binaryAjax(base, 'prj')
  12874. ]);
  12875. let prj = false;
  12876. try {
  12877. if (args[1]) {
  12878. prj = proj4(args[1]);
  12879. }
  12880. } catch (e) {
  12881. prj = false;
  12882. }
  12883. return parseShp(args[0], prj);
  12884. };
  12885. const handleDbf = async (base) => {
  12886. const [dbf, cpg] = await Promise.all([
  12887. binaryAjax(base, 'dbf'),
  12888. binaryAjax(base, 'cpg')
  12889. ]);
  12890. if (!dbf) {
  12891. return;
  12892. }
  12893. return parseDbf(dbf, cpg);
  12894. };
  12895. const checkSuffix = (base, suffix) => {
  12896. const url = new URL(base);
  12897. return url.pathname.slice(-4).toLowerCase() === suffix;
  12898. };
  12899. shp.getShapefile = async function (base, whiteList) {
  12900. if (typeof base !== 'string') {
  12901. return shp.parseZip(base);
  12902. }
  12903. if (checkSuffix(base, '.zip')) {
  12904. return getZip(base, whiteList);
  12905. }
  12906. const results = await Promise.all([
  12907. handleShp(base),
  12908. handleDbf(base)
  12909. ]);
  12910. return shp.combine(results);
  12911. };
  12912. shp.parseShp = function (shp, prj) {
  12913. shp = toBuffer(shp);
  12914. if (Buffer.isBuffer(prj)) {
  12915. prj = prj.toString();
  12916. }
  12917. if (typeof prj === 'string') {
  12918. try {
  12919. prj = proj4(prj);
  12920. } catch (e) {
  12921. prj = false;
  12922. }
  12923. }
  12924. return parseShp(shp, prj);
  12925. };
  12926. shp.parseDbf = function (dbf, cpg) {
  12927. dbf = toBuffer(dbf);
  12928. return parseDbf(dbf, cpg);
  12929. };
  12930. module.exports = shp;
  12931. }).call(this)
  12932. }).call(this, typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  12933. }, { "./binaryajax": 2, "./parseShp": 4, "./unzip": 5, "buffer": 8, "lie": 12, "lru-cache": 13, "parsedbf": 15, "proj4": 17 }]
  12934. }, {}, [23])(23)
  12935. });