shp.js 499 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  3. typeof define === 'function' && define.amd ? define(factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.shp = factory());
  5. })(this, (function () { 'use strict';
  6. function globals(defs) {
  7. defs('EPSG:4326', "+title=WGS 84 (long/lat) +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees");
  8. defs('EPSG:4269', "+title=NAD83 (long/lat) +proj=longlat +a=6378137.0 +b=6356752.31414036 +ellps=GRS80 +datum=NAD83 +units=degrees");
  9. 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");
  10. defs.WGS84 = defs['EPSG:4326'];
  11. defs['EPSG:3785'] = defs['EPSG:3857']; // maintain backward compat, official code is 3857
  12. defs.GOOGLE = defs['EPSG:3857'];
  13. defs['EPSG:900913'] = defs['EPSG:3857'];
  14. defs['EPSG:102113'] = defs['EPSG:3857'];
  15. }
  16. var PJD_3PARAM = 1;
  17. var PJD_7PARAM = 2;
  18. var PJD_GRIDSHIFT = 3;
  19. var PJD_WGS84 = 4; // WGS84 or equivalent
  20. var PJD_NODATUM = 5; // WGS84 or equivalent
  21. var SRS_WGS84_SEMIMAJOR = 6378137.0; // only used in grid shift transforms
  22. var SRS_WGS84_SEMIMINOR = 6356752.314; // only used in grid shift transforms
  23. var SRS_WGS84_ESQUARED = 0.0066943799901413165; // only used in grid shift transforms
  24. var SEC_TO_RAD = 4.84813681109535993589914102357e-6;
  25. var HALF_PI = Math.PI/2;
  26. // ellipoid pj_set_ell.c
  27. var SIXTH = 0.1666666666666666667;
  28. /* 1/6 */
  29. var RA4 = 0.04722222222222222222;
  30. /* 17/360 */
  31. var RA6 = 0.02215608465608465608;
  32. var EPSLN = 1.0e-10;
  33. // you'd think you could use Number.EPSILON above but that makes
  34. // Mollweide get into an infinate loop.
  35. var D2R$1 = 0.01745329251994329577;
  36. var R2D = 57.29577951308232088;
  37. var FORTPI = Math.PI/4;
  38. var TWO_PI = Math.PI * 2;
  39. // SPI is slightly greater than Math.PI, so values that exceed the -180..180
  40. // degree range by a tiny amount don't get wrapped. This prevents points that
  41. // have drifted from their original location along the 180th meridian (due to
  42. // floating point error) from changing their sign.
  43. var SPI = 3.14159265359;
  44. var exports$3 = {};
  45. exports$3.greenwich = 0.0; //"0dE",
  46. exports$3.lisbon = -9.131906111111; //"9d07'54.862\"W",
  47. exports$3.paris = 2.337229166667; //"2d20'14.025\"E",
  48. exports$3.bogota = -74.080916666667; //"74d04'51.3\"W",
  49. exports$3.madrid = -3.687938888889; //"3d41'16.58\"W",
  50. exports$3.rome = 12.452333333333; //"12d27'8.4\"E",
  51. exports$3.bern = 7.439583333333; //"7d26'22.5\"E",
  52. exports$3.jakarta = 106.807719444444; //"106d48'27.79\"E",
  53. exports$3.ferro = -17.666666666667; //"17d40'W",
  54. exports$3.brussels = 4.367975; //"4d22'4.71\"E",
  55. exports$3.stockholm = 18.058277777778; //"18d3'29.8\"E",
  56. exports$3.athens = 23.7163375; //"23d42'58.815\"E",
  57. exports$3.oslo = 10.722916666667; //"10d43'22.5\"E"
  58. var units = {
  59. ft: {to_meter: 0.3048},
  60. 'us-ft': {to_meter: 1200 / 3937}
  61. };
  62. var ignoredChar = /[\s_\-\/\(\)]/g;
  63. function match(obj, key) {
  64. if (obj[key]) {
  65. return obj[key];
  66. }
  67. var keys = Object.keys(obj);
  68. var lkey = key.toLowerCase().replace(ignoredChar, '');
  69. var i = -1;
  70. var testkey, processedKey;
  71. while (++i < keys.length) {
  72. testkey = keys[i];
  73. processedKey = testkey.toLowerCase().replace(ignoredChar, '');
  74. if (processedKey === lkey) {
  75. return obj[testkey];
  76. }
  77. }
  78. }
  79. function projStr(defData) {
  80. var self = {};
  81. var paramObj = defData.split('+').map(function(v) {
  82. return v.trim();
  83. }).filter(function(a) {
  84. return a;
  85. }).reduce(function(p, a) {
  86. var split = a.split('=');
  87. split.push(true);
  88. p[split[0].toLowerCase()] = split[1];
  89. return p;
  90. }, {});
  91. var paramName, paramVal, paramOutname;
  92. var params = {
  93. proj: 'projName',
  94. datum: 'datumCode',
  95. rf: function(v) {
  96. self.rf = parseFloat(v);
  97. },
  98. lat_0: function(v) {
  99. self.lat0 = v * D2R$1;
  100. },
  101. lat_1: function(v) {
  102. self.lat1 = v * D2R$1;
  103. },
  104. lat_2: function(v) {
  105. self.lat2 = v * D2R$1;
  106. },
  107. lat_ts: function(v) {
  108. self.lat_ts = v * D2R$1;
  109. },
  110. lon_0: function(v) {
  111. self.long0 = v * D2R$1;
  112. },
  113. lon_1: function(v) {
  114. self.long1 = v * D2R$1;
  115. },
  116. lon_2: function(v) {
  117. self.long2 = v * D2R$1;
  118. },
  119. alpha: function(v) {
  120. self.alpha = parseFloat(v) * D2R$1;
  121. },
  122. gamma: function(v) {
  123. self.rectified_grid_angle = parseFloat(v);
  124. },
  125. lonc: function(v) {
  126. self.longc = v * D2R$1;
  127. },
  128. x_0: function(v) {
  129. self.x0 = parseFloat(v);
  130. },
  131. y_0: function(v) {
  132. self.y0 = parseFloat(v);
  133. },
  134. k_0: function(v) {
  135. self.k0 = parseFloat(v);
  136. },
  137. k: function(v) {
  138. self.k0 = parseFloat(v);
  139. },
  140. a: function(v) {
  141. self.a = parseFloat(v);
  142. },
  143. b: function(v) {
  144. self.b = parseFloat(v);
  145. },
  146. r_a: function() {
  147. self.R_A = true;
  148. },
  149. zone: function(v) {
  150. self.zone = parseInt(v, 10);
  151. },
  152. south: function() {
  153. self.utmSouth = true;
  154. },
  155. towgs84: function(v) {
  156. self.datum_params = v.split(",").map(function(a) {
  157. return parseFloat(a);
  158. });
  159. },
  160. to_meter: function(v) {
  161. self.to_meter = parseFloat(v);
  162. },
  163. units: function(v) {
  164. self.units = v;
  165. var unit = match(units, v);
  166. if (unit) {
  167. self.to_meter = unit.to_meter;
  168. }
  169. },
  170. from_greenwich: function(v) {
  171. self.from_greenwich = v * D2R$1;
  172. },
  173. pm: function(v) {
  174. var pm = match(exports$3, v);
  175. self.from_greenwich = (pm ? pm : parseFloat(v)) * D2R$1;
  176. },
  177. nadgrids: function(v) {
  178. if (v === '@null') {
  179. self.datumCode = 'none';
  180. }
  181. else {
  182. self.nadgrids = v;
  183. }
  184. },
  185. axis: function(v) {
  186. var legalAxis = "ewnsud";
  187. 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) {
  188. self.axis = v;
  189. }
  190. },
  191. approx: function() {
  192. self.approx = true;
  193. }
  194. };
  195. for (paramName in paramObj) {
  196. paramVal = paramObj[paramName];
  197. if (paramName in params) {
  198. paramOutname = params[paramName];
  199. if (typeof paramOutname === 'function') {
  200. paramOutname(paramVal);
  201. }
  202. else {
  203. self[paramOutname] = paramVal;
  204. }
  205. }
  206. else {
  207. self[paramName] = paramVal;
  208. }
  209. }
  210. if(typeof self.datumCode === 'string' && self.datumCode !== "WGS84"){
  211. self.datumCode = self.datumCode.toLowerCase();
  212. }
  213. return self;
  214. }
  215. var NEUTRAL = 1;
  216. var KEYWORD = 2;
  217. var NUMBER = 3;
  218. var QUOTED = 4;
  219. var AFTERQUOTE = 5;
  220. var ENDED = -1;
  221. var whitespace = /\s/;
  222. var latin = /[A-Za-z]/;
  223. var keyword = /[A-Za-z84_]/;
  224. var endThings = /[,\]]/;
  225. var digets = /[\d\.E\-\+]/;
  226. // const ignoredChar = /[\s_\-\/\(\)]/g;
  227. function Parser(text) {
  228. if (typeof text !== 'string') {
  229. throw new Error('not a string');
  230. }
  231. this.text = text.trim();
  232. this.level = 0;
  233. this.place = 0;
  234. this.root = null;
  235. this.stack = [];
  236. this.currentObject = null;
  237. this.state = NEUTRAL;
  238. }
  239. Parser.prototype.readCharicter = function() {
  240. var char = this.text[this.place++];
  241. if (this.state !== QUOTED) {
  242. while (whitespace.test(char)) {
  243. if (this.place >= this.text.length) {
  244. return;
  245. }
  246. char = this.text[this.place++];
  247. }
  248. }
  249. switch (this.state) {
  250. case NEUTRAL:
  251. return this.neutral(char);
  252. case KEYWORD:
  253. return this.keyword(char)
  254. case QUOTED:
  255. return this.quoted(char);
  256. case AFTERQUOTE:
  257. return this.afterquote(char);
  258. case NUMBER:
  259. return this.number(char);
  260. case ENDED:
  261. return;
  262. }
  263. };
  264. Parser.prototype.afterquote = function(char) {
  265. if (char === '"') {
  266. this.word += '"';
  267. this.state = QUOTED;
  268. return;
  269. }
  270. if (endThings.test(char)) {
  271. this.word = this.word.trim();
  272. this.afterItem(char);
  273. return;
  274. }
  275. throw new Error('havn\'t handled "' +char + '" in afterquote yet, index ' + this.place);
  276. };
  277. Parser.prototype.afterItem = function(char) {
  278. if (char === ',') {
  279. if (this.word !== null) {
  280. this.currentObject.push(this.word);
  281. }
  282. this.word = null;
  283. this.state = NEUTRAL;
  284. return;
  285. }
  286. if (char === ']') {
  287. this.level--;
  288. if (this.word !== null) {
  289. this.currentObject.push(this.word);
  290. this.word = null;
  291. }
  292. this.state = NEUTRAL;
  293. this.currentObject = this.stack.pop();
  294. if (!this.currentObject) {
  295. this.state = ENDED;
  296. }
  297. return;
  298. }
  299. };
  300. Parser.prototype.number = function(char) {
  301. if (digets.test(char)) {
  302. this.word += char;
  303. return;
  304. }
  305. if (endThings.test(char)) {
  306. this.word = parseFloat(this.word);
  307. this.afterItem(char);
  308. return;
  309. }
  310. throw new Error('havn\'t handled "' +char + '" in number yet, index ' + this.place);
  311. };
  312. Parser.prototype.quoted = function(char) {
  313. if (char === '"') {
  314. this.state = AFTERQUOTE;
  315. return;
  316. }
  317. this.word += char;
  318. return;
  319. };
  320. Parser.prototype.keyword = function(char) {
  321. if (keyword.test(char)) {
  322. this.word += char;
  323. return;
  324. }
  325. if (char === '[') {
  326. var newObjects = [];
  327. newObjects.push(this.word);
  328. this.level++;
  329. if (this.root === null) {
  330. this.root = newObjects;
  331. } else {
  332. this.currentObject.push(newObjects);
  333. }
  334. this.stack.push(this.currentObject);
  335. this.currentObject = newObjects;
  336. this.state = NEUTRAL;
  337. return;
  338. }
  339. if (endThings.test(char)) {
  340. this.afterItem(char);
  341. return;
  342. }
  343. throw new Error('havn\'t handled "' +char + '" in keyword yet, index ' + this.place);
  344. };
  345. Parser.prototype.neutral = function(char) {
  346. if (latin.test(char)) {
  347. this.word = char;
  348. this.state = KEYWORD;
  349. return;
  350. }
  351. if (char === '"') {
  352. this.word = '';
  353. this.state = QUOTED;
  354. return;
  355. }
  356. if (digets.test(char)) {
  357. this.word = char;
  358. this.state = NUMBER;
  359. return;
  360. }
  361. if (endThings.test(char)) {
  362. this.afterItem(char);
  363. return;
  364. }
  365. throw new Error('havn\'t handled "' +char + '" in neutral yet, index ' + this.place);
  366. };
  367. Parser.prototype.output = function() {
  368. while (this.place < this.text.length) {
  369. this.readCharicter();
  370. }
  371. if (this.state === ENDED) {
  372. return this.root;
  373. }
  374. throw new Error('unable to parse string "' +this.text + '". State is ' + this.state);
  375. };
  376. function parseString(txt) {
  377. var parser = new Parser(txt);
  378. return parser.output();
  379. }
  380. function mapit(obj, key, value) {
  381. if (Array.isArray(key)) {
  382. value.unshift(key);
  383. key = null;
  384. }
  385. var thing = key ? {} : obj;
  386. var out = value.reduce(function(newObj, item) {
  387. sExpr(item, newObj);
  388. return newObj
  389. }, thing);
  390. if (key) {
  391. obj[key] = out;
  392. }
  393. }
  394. function sExpr(v, obj) {
  395. if (!Array.isArray(v)) {
  396. obj[v] = true;
  397. return;
  398. }
  399. var key = v.shift();
  400. if (key === 'PARAMETER') {
  401. key = v.shift();
  402. }
  403. if (v.length === 1) {
  404. if (Array.isArray(v[0])) {
  405. obj[key] = {};
  406. sExpr(v[0], obj[key]);
  407. return;
  408. }
  409. obj[key] = v[0];
  410. return;
  411. }
  412. if (!v.length) {
  413. obj[key] = true;
  414. return;
  415. }
  416. if (key === 'TOWGS84') {
  417. obj[key] = v;
  418. return;
  419. }
  420. if (key === 'AXIS') {
  421. if (!(key in obj)) {
  422. obj[key] = [];
  423. }
  424. obj[key].push(v);
  425. return;
  426. }
  427. if (!Array.isArray(key)) {
  428. obj[key] = {};
  429. }
  430. var i;
  431. switch (key) {
  432. case 'UNIT':
  433. case 'PRIMEM':
  434. case 'VERT_DATUM':
  435. obj[key] = {
  436. name: v[0].toLowerCase(),
  437. convert: v[1]
  438. };
  439. if (v.length === 3) {
  440. sExpr(v[2], obj[key]);
  441. }
  442. return;
  443. case 'SPHEROID':
  444. case 'ELLIPSOID':
  445. obj[key] = {
  446. name: v[0],
  447. a: v[1],
  448. rf: v[2]
  449. };
  450. if (v.length === 4) {
  451. sExpr(v[3], obj[key]);
  452. }
  453. return;
  454. case 'PROJECTEDCRS':
  455. case 'PROJCRS':
  456. case 'GEOGCS':
  457. case 'GEOCCS':
  458. case 'PROJCS':
  459. case 'LOCAL_CS':
  460. case 'GEODCRS':
  461. case 'GEODETICCRS':
  462. case 'GEODETICDATUM':
  463. case 'EDATUM':
  464. case 'ENGINEERINGDATUM':
  465. case 'VERT_CS':
  466. case 'VERTCRS':
  467. case 'VERTICALCRS':
  468. case 'COMPD_CS':
  469. case 'COMPOUNDCRS':
  470. case 'ENGINEERINGCRS':
  471. case 'ENGCRS':
  472. case 'FITTED_CS':
  473. case 'LOCAL_DATUM':
  474. case 'DATUM':
  475. v[0] = ['name', v[0]];
  476. mapit(obj, key, v);
  477. return;
  478. default:
  479. i = -1;
  480. while (++i < v.length) {
  481. if (!Array.isArray(v[i])) {
  482. return sExpr(v, obj[key]);
  483. }
  484. }
  485. return mapit(obj, key, v);
  486. }
  487. }
  488. var D2R = 0.01745329251994329577;
  489. function rename(obj, params) {
  490. var outName = params[0];
  491. var inName = params[1];
  492. if (!(outName in obj) && (inName in obj)) {
  493. obj[outName] = obj[inName];
  494. if (params.length === 3) {
  495. obj[outName] = params[2](obj[outName]);
  496. }
  497. }
  498. }
  499. function d2r(input) {
  500. return input * D2R;
  501. }
  502. function cleanWKT(wkt) {
  503. if (wkt.type === 'GEOGCS') {
  504. wkt.projName = 'longlat';
  505. } else if (wkt.type === 'LOCAL_CS') {
  506. wkt.projName = 'identity';
  507. wkt.local = true;
  508. } else {
  509. if (typeof wkt.PROJECTION === 'object') {
  510. wkt.projName = Object.keys(wkt.PROJECTION)[0];
  511. } else {
  512. wkt.projName = wkt.PROJECTION;
  513. }
  514. }
  515. if (wkt.AXIS) {
  516. var axisOrder = '';
  517. for (var i = 0, ii = wkt.AXIS.length; i < ii; ++i) {
  518. var axis = [wkt.AXIS[i][0].toLowerCase(), wkt.AXIS[i][1].toLowerCase()];
  519. if (axis[0].indexOf('north') !== -1 || ((axis[0] === 'y' || axis[0] === 'lat') && axis[1] === 'north')) {
  520. axisOrder += 'n';
  521. } else if (axis[0].indexOf('south') !== -1 || ((axis[0] === 'y' || axis[0] === 'lat') && axis[1] === 'south')) {
  522. axisOrder += 's';
  523. } else if (axis[0].indexOf('east') !== -1 || ((axis[0] === 'x' || axis[0] === 'lon') && axis[1] === 'east')) {
  524. axisOrder += 'e';
  525. } else if (axis[0].indexOf('west') !== -1 || ((axis[0] === 'x' || axis[0] === 'lon') && axis[1] === 'west')) {
  526. axisOrder += 'w';
  527. }
  528. }
  529. if (axisOrder.length === 2) {
  530. axisOrder += 'u';
  531. }
  532. if (axisOrder.length === 3) {
  533. wkt.axis = axisOrder;
  534. }
  535. }
  536. if (wkt.UNIT) {
  537. wkt.units = wkt.UNIT.name.toLowerCase();
  538. if (wkt.units === 'metre') {
  539. wkt.units = 'meter';
  540. }
  541. if (wkt.UNIT.convert) {
  542. if (wkt.type === 'GEOGCS') {
  543. if (wkt.DATUM && wkt.DATUM.SPHEROID) {
  544. wkt.to_meter = wkt.UNIT.convert*wkt.DATUM.SPHEROID.a;
  545. }
  546. } else {
  547. wkt.to_meter = wkt.UNIT.convert;
  548. }
  549. }
  550. }
  551. var geogcs = wkt.GEOGCS;
  552. if (wkt.type === 'GEOGCS') {
  553. geogcs = wkt;
  554. }
  555. if (geogcs) {
  556. //if(wkt.GEOGCS.PRIMEM&&wkt.GEOGCS.PRIMEM.convert){
  557. // wkt.from_greenwich=wkt.GEOGCS.PRIMEM.convert*D2R;
  558. //}
  559. if (geogcs.DATUM) {
  560. wkt.datumCode = geogcs.DATUM.name.toLowerCase();
  561. } else {
  562. wkt.datumCode = geogcs.name.toLowerCase();
  563. }
  564. if (wkt.datumCode.slice(0, 2) === 'd_') {
  565. wkt.datumCode = wkt.datumCode.slice(2);
  566. }
  567. if (wkt.datumCode === 'new_zealand_geodetic_datum_1949' || wkt.datumCode === 'new_zealand_1949') {
  568. wkt.datumCode = 'nzgd49';
  569. }
  570. if (wkt.datumCode === 'wgs_1984' || wkt.datumCode === 'world_geodetic_system_1984') {
  571. if (wkt.PROJECTION === 'Mercator_Auxiliary_Sphere') {
  572. wkt.sphere = true;
  573. }
  574. wkt.datumCode = 'wgs84';
  575. }
  576. if (wkt.datumCode.slice(-6) === '_ferro') {
  577. wkt.datumCode = wkt.datumCode.slice(0, - 6);
  578. }
  579. if (wkt.datumCode.slice(-8) === '_jakarta') {
  580. wkt.datumCode = wkt.datumCode.slice(0, - 8);
  581. }
  582. if (~wkt.datumCode.indexOf('belge')) {
  583. wkt.datumCode = 'rnb72';
  584. }
  585. if (geogcs.DATUM && geogcs.DATUM.SPHEROID) {
  586. wkt.ellps = geogcs.DATUM.SPHEROID.name.replace('_19', '').replace(/[Cc]larke\_18/, 'clrk');
  587. if (wkt.ellps.toLowerCase().slice(0, 13) === 'international') {
  588. wkt.ellps = 'intl';
  589. }
  590. wkt.a = geogcs.DATUM.SPHEROID.a;
  591. wkt.rf = parseFloat(geogcs.DATUM.SPHEROID.rf, 10);
  592. }
  593. if (geogcs.DATUM && geogcs.DATUM.TOWGS84) {
  594. wkt.datum_params = geogcs.DATUM.TOWGS84;
  595. }
  596. if (~wkt.datumCode.indexOf('osgb_1936')) {
  597. wkt.datumCode = 'osgb36';
  598. }
  599. if (~wkt.datumCode.indexOf('osni_1952')) {
  600. wkt.datumCode = 'osni52';
  601. }
  602. if (~wkt.datumCode.indexOf('tm65')
  603. || ~wkt.datumCode.indexOf('geodetic_datum_of_1965')) {
  604. wkt.datumCode = 'ire65';
  605. }
  606. if (wkt.datumCode === 'ch1903+') {
  607. wkt.datumCode = 'ch1903';
  608. }
  609. if (~wkt.datumCode.indexOf('israel')) {
  610. wkt.datumCode = 'isr93';
  611. }
  612. }
  613. if (wkt.b && !isFinite(wkt.b)) {
  614. wkt.b = wkt.a;
  615. }
  616. function toMeter(input) {
  617. var ratio = wkt.to_meter || 1;
  618. return input * ratio;
  619. }
  620. var renamer = function(a) {
  621. return rename(wkt, a);
  622. };
  623. var list = [
  624. ['standard_parallel_1', 'Standard_Parallel_1'],
  625. ['standard_parallel_1', 'Latitude of 1st standard parallel'],
  626. ['standard_parallel_2', 'Standard_Parallel_2'],
  627. ['standard_parallel_2', 'Latitude of 2nd standard parallel'],
  628. ['false_easting', 'False_Easting'],
  629. ['false_easting', 'False easting'],
  630. ['false-easting', 'Easting at false origin'],
  631. ['false_northing', 'False_Northing'],
  632. ['false_northing', 'False northing'],
  633. ['false_northing', 'Northing at false origin'],
  634. ['central_meridian', 'Central_Meridian'],
  635. ['central_meridian', 'Longitude of natural origin'],
  636. ['central_meridian', 'Longitude of false origin'],
  637. ['latitude_of_origin', 'Latitude_Of_Origin'],
  638. ['latitude_of_origin', 'Central_Parallel'],
  639. ['latitude_of_origin', 'Latitude of natural origin'],
  640. ['latitude_of_origin', 'Latitude of false origin'],
  641. ['scale_factor', 'Scale_Factor'],
  642. ['k0', 'scale_factor'],
  643. ['latitude_of_center', 'Latitude_Of_Center'],
  644. ['latitude_of_center', 'Latitude_of_center'],
  645. ['lat0', 'latitude_of_center', d2r],
  646. ['longitude_of_center', 'Longitude_Of_Center'],
  647. ['longitude_of_center', 'Longitude_of_center'],
  648. ['longc', 'longitude_of_center', d2r],
  649. ['x0', 'false_easting', toMeter],
  650. ['y0', 'false_northing', toMeter],
  651. ['long0', 'central_meridian', d2r],
  652. ['lat0', 'latitude_of_origin', d2r],
  653. ['lat0', 'standard_parallel_1', d2r],
  654. ['lat1', 'standard_parallel_1', d2r],
  655. ['lat2', 'standard_parallel_2', d2r],
  656. ['azimuth', 'Azimuth'],
  657. ['alpha', 'azimuth', d2r],
  658. ['srsCode', 'name']
  659. ];
  660. list.forEach(renamer);
  661. if (!wkt.long0 && wkt.longc && (wkt.projName === 'Albers_Conic_Equal_Area' || wkt.projName === 'Lambert_Azimuthal_Equal_Area')) {
  662. wkt.long0 = wkt.longc;
  663. }
  664. if (!wkt.lat_ts && wkt.lat1 && (wkt.projName === 'Stereographic_South_Pole' || wkt.projName === 'Polar Stereographic (variant B)')) {
  665. wkt.lat0 = d2r(wkt.lat1 > 0 ? 90 : -90);
  666. wkt.lat_ts = wkt.lat1;
  667. } else if (!wkt.lat_ts && wkt.lat0 && wkt.projName === 'Polar_Stereographic') {
  668. wkt.lat_ts = wkt.lat0;
  669. wkt.lat0 = d2r(wkt.lat0 > 0 ? 90 : -90);
  670. }
  671. }
  672. function wkt(wkt) {
  673. var lisp = parseString(wkt);
  674. var type = lisp.shift();
  675. var name = lisp.shift();
  676. lisp.unshift(['name', name]);
  677. lisp.unshift(['type', type]);
  678. var obj = {};
  679. sExpr(lisp, obj);
  680. cleanWKT(obj);
  681. return obj;
  682. }
  683. function defs(name) {
  684. /*global console*/
  685. var that = this;
  686. if (arguments.length === 2) {
  687. var def = arguments[1];
  688. if (typeof def === 'string') {
  689. if (def.charAt(0) === '+') {
  690. defs[name] = projStr(arguments[1]);
  691. }
  692. else {
  693. defs[name] = wkt(arguments[1]);
  694. }
  695. } else {
  696. defs[name] = def;
  697. }
  698. }
  699. else if (arguments.length === 1) {
  700. if (Array.isArray(name)) {
  701. return name.map(function(v) {
  702. if (Array.isArray(v)) {
  703. defs.apply(that, v);
  704. }
  705. else {
  706. defs(v);
  707. }
  708. });
  709. }
  710. else if (typeof name === 'string') {
  711. if (name in defs) {
  712. return defs[name];
  713. }
  714. }
  715. else if ('EPSG' in name) {
  716. defs['EPSG:' + name.EPSG] = name;
  717. }
  718. else if ('ESRI' in name) {
  719. defs['ESRI:' + name.ESRI] = name;
  720. }
  721. else if ('IAU2000' in name) {
  722. defs['IAU2000:' + name.IAU2000] = name;
  723. }
  724. else {
  725. console.log(name);
  726. }
  727. return;
  728. }
  729. }
  730. globals(defs);
  731. function testObj(code){
  732. return typeof code === 'string';
  733. }
  734. function testDef(code){
  735. return code in defs;
  736. }
  737. var codeWords = ['PROJECTEDCRS', 'PROJCRS', 'GEOGCS','GEOCCS','PROJCS','LOCAL_CS', 'GEODCRS', 'GEODETICCRS', 'GEODETICDATUM', 'ENGCRS', 'ENGINEERINGCRS'];
  738. function testWKT(code){
  739. return codeWords.some(function (word) {
  740. return code.indexOf(word) > -1;
  741. });
  742. }
  743. var codes = ['3857', '900913', '3785', '102113'];
  744. function checkMercator(item) {
  745. var auth = match(item, 'authority');
  746. if (!auth) {
  747. return;
  748. }
  749. var code = match(auth, 'epsg');
  750. return code && codes.indexOf(code) > -1;
  751. }
  752. function checkProjStr(item) {
  753. var ext = match(item, 'extension');
  754. if (!ext) {
  755. return;
  756. }
  757. return match(ext, 'proj4');
  758. }
  759. function testProj(code){
  760. return code[0] === '+';
  761. }
  762. function parse(code){
  763. if (testObj(code)) {
  764. //check to see if this is a WKT string
  765. if (testDef(code)) {
  766. return defs[code];
  767. }
  768. if (testWKT(code)) {
  769. var out = wkt(code);
  770. // test of spetial case, due to this being a very common and often malformed
  771. if (checkMercator(out)) {
  772. return defs['EPSG:3857'];
  773. }
  774. var maybeProjStr = checkProjStr(out);
  775. if (maybeProjStr) {
  776. return projStr(maybeProjStr);
  777. }
  778. return out;
  779. }
  780. if (testProj(code)) {
  781. return projStr(code);
  782. }
  783. }else {
  784. return code;
  785. }
  786. }
  787. function extend(destination, source) {
  788. destination = destination || {};
  789. var value, property;
  790. if (!source) {
  791. return destination;
  792. }
  793. for (property in source) {
  794. value = source[property];
  795. if (value !== undefined) {
  796. destination[property] = value;
  797. }
  798. }
  799. return destination;
  800. }
  801. function msfnz(eccent, sinphi, cosphi) {
  802. var con = eccent * sinphi;
  803. return cosphi / (Math.sqrt(1 - con * con));
  804. }
  805. function sign(x) {
  806. return x<0 ? -1 : 1;
  807. }
  808. function adjust_lon(x) {
  809. return (Math.abs(x) <= SPI) ? x : (x - (sign(x) * TWO_PI));
  810. }
  811. function tsfnz(eccent, phi, sinphi) {
  812. var con = eccent * sinphi;
  813. var com = 0.5 * eccent;
  814. con = Math.pow(((1 - con) / (1 + con)), com);
  815. return (Math.tan(0.5 * (HALF_PI - phi)) / con);
  816. }
  817. function phi2z(eccent, ts) {
  818. var eccnth = 0.5 * eccent;
  819. var con, dphi;
  820. var phi = HALF_PI - 2 * Math.atan(ts);
  821. for (var i = 0; i <= 15; i++) {
  822. con = eccent * Math.sin(phi);
  823. dphi = HALF_PI - 2 * Math.atan(ts * (Math.pow(((1 - con) / (1 + con)), eccnth))) - phi;
  824. phi += dphi;
  825. if (Math.abs(dphi) <= 0.0000000001) {
  826. return phi;
  827. }
  828. }
  829. //console.log("phi2z has NoConvergence");
  830. return -9999;
  831. }
  832. function init$w() {
  833. var con = this.b / this.a;
  834. this.es = 1 - con * con;
  835. if(!('x0' in this)){
  836. this.x0 = 0;
  837. }
  838. if(!('y0' in this)){
  839. this.y0 = 0;
  840. }
  841. this.e = Math.sqrt(this.es);
  842. if (this.lat_ts) {
  843. if (this.sphere) {
  844. this.k0 = Math.cos(this.lat_ts);
  845. }
  846. else {
  847. this.k0 = msfnz(this.e, Math.sin(this.lat_ts), Math.cos(this.lat_ts));
  848. }
  849. }
  850. else {
  851. if (!this.k0) {
  852. if (this.k) {
  853. this.k0 = this.k;
  854. }
  855. else {
  856. this.k0 = 1;
  857. }
  858. }
  859. }
  860. }
  861. /* Mercator forward equations--mapping lat,long to x,y
  862. --------------------------------------------------*/
  863. function forward$u(p) {
  864. var lon = p.x;
  865. var lat = p.y;
  866. // convert to radians
  867. if (lat * R2D > 90 && lat * R2D < -90 && lon * R2D > 180 && lon * R2D < -180) {
  868. return null;
  869. }
  870. var x, y;
  871. if (Math.abs(Math.abs(lat) - HALF_PI) <= EPSLN) {
  872. return null;
  873. }
  874. else {
  875. if (this.sphere) {
  876. x = this.x0 + this.a * this.k0 * adjust_lon(lon - this.long0);
  877. y = this.y0 + this.a * this.k0 * Math.log(Math.tan(FORTPI + 0.5 * lat));
  878. }
  879. else {
  880. var sinphi = Math.sin(lat);
  881. var ts = tsfnz(this.e, lat, sinphi);
  882. x = this.x0 + this.a * this.k0 * adjust_lon(lon - this.long0);
  883. y = this.y0 - this.a * this.k0 * Math.log(ts);
  884. }
  885. p.x = x;
  886. p.y = y;
  887. return p;
  888. }
  889. }
  890. /* Mercator inverse equations--mapping x,y to lat/long
  891. --------------------------------------------------*/
  892. function inverse$u(p) {
  893. var x = p.x - this.x0;
  894. var y = p.y - this.y0;
  895. var lon, lat;
  896. if (this.sphere) {
  897. lat = HALF_PI - 2 * Math.atan(Math.exp(-y / (this.a * this.k0)));
  898. }
  899. else {
  900. var ts = Math.exp(-y / (this.a * this.k0));
  901. lat = phi2z(this.e, ts);
  902. if (lat === -9999) {
  903. return null;
  904. }
  905. }
  906. lon = adjust_lon(this.long0 + x / (this.a * this.k0));
  907. p.x = lon;
  908. p.y = lat;
  909. return p;
  910. }
  911. var names$w = ["Mercator", "Popular Visualisation Pseudo Mercator", "Mercator_1SP", "Mercator_Auxiliary_Sphere", "merc"];
  912. var merc = {
  913. init: init$w,
  914. forward: forward$u,
  915. inverse: inverse$u,
  916. names: names$w
  917. };
  918. function init$v() {
  919. //no-op for longlat
  920. }
  921. function identity(pt) {
  922. return pt;
  923. }
  924. var names$v = ["longlat", "identity"];
  925. var longlat = {
  926. init: init$v,
  927. forward: identity,
  928. inverse: identity,
  929. names: names$v
  930. };
  931. var projs = [merc, longlat];
  932. var names$u = {};
  933. var projStore = [];
  934. function add(proj, i) {
  935. var len = projStore.length;
  936. if (!proj.names) {
  937. console.log(i);
  938. return true;
  939. }
  940. projStore[len] = proj;
  941. proj.names.forEach(function(n) {
  942. names$u[n.toLowerCase()] = len;
  943. });
  944. return this;
  945. }
  946. function get(name) {
  947. if (!name) {
  948. return false;
  949. }
  950. var n = name.toLowerCase();
  951. if (typeof names$u[n] !== 'undefined' && projStore[names$u[n]]) {
  952. return projStore[names$u[n]];
  953. }
  954. }
  955. function start() {
  956. projs.forEach(add);
  957. }
  958. var projections = {
  959. start: start,
  960. add: add,
  961. get: get
  962. };
  963. var exports$2 = {};
  964. exports$2.MERIT = {
  965. a: 6378137.0,
  966. rf: 298.257,
  967. ellipseName: "MERIT 1983"
  968. };
  969. exports$2.SGS85 = {
  970. a: 6378136.0,
  971. rf: 298.257,
  972. ellipseName: "Soviet Geodetic System 85"
  973. };
  974. exports$2.GRS80 = {
  975. a: 6378137.0,
  976. rf: 298.257222101,
  977. ellipseName: "GRS 1980(IUGG, 1980)"
  978. };
  979. exports$2.IAU76 = {
  980. a: 6378140.0,
  981. rf: 298.257,
  982. ellipseName: "IAU 1976"
  983. };
  984. exports$2.airy = {
  985. a: 6377563.396,
  986. b: 6356256.910,
  987. ellipseName: "Airy 1830"
  988. };
  989. exports$2.APL4 = {
  990. a: 6378137,
  991. rf: 298.25,
  992. ellipseName: "Appl. Physics. 1965"
  993. };
  994. exports$2.NWL9D = {
  995. a: 6378145.0,
  996. rf: 298.25,
  997. ellipseName: "Naval Weapons Lab., 1965"
  998. };
  999. exports$2.mod_airy = {
  1000. a: 6377340.189,
  1001. b: 6356034.446,
  1002. ellipseName: "Modified Airy"
  1003. };
  1004. exports$2.andrae = {
  1005. a: 6377104.43,
  1006. rf: 300.0,
  1007. ellipseName: "Andrae 1876 (Den., Iclnd.)"
  1008. };
  1009. exports$2.aust_SA = {
  1010. a: 6378160.0,
  1011. rf: 298.25,
  1012. ellipseName: "Australian Natl & S. Amer. 1969"
  1013. };
  1014. exports$2.GRS67 = {
  1015. a: 6378160.0,
  1016. rf: 298.2471674270,
  1017. ellipseName: "GRS 67(IUGG 1967)"
  1018. };
  1019. exports$2.bessel = {
  1020. a: 6377397.155,
  1021. rf: 299.1528128,
  1022. ellipseName: "Bessel 1841"
  1023. };
  1024. exports$2.bess_nam = {
  1025. a: 6377483.865,
  1026. rf: 299.1528128,
  1027. ellipseName: "Bessel 1841 (Namibia)"
  1028. };
  1029. exports$2.clrk66 = {
  1030. a: 6378206.4,
  1031. b: 6356583.8,
  1032. ellipseName: "Clarke 1866"
  1033. };
  1034. exports$2.clrk80 = {
  1035. a: 6378249.145,
  1036. rf: 293.4663,
  1037. ellipseName: "Clarke 1880 mod."
  1038. };
  1039. exports$2.clrk80ign = {
  1040. a: 6378249.2,
  1041. b: 6356515,
  1042. rf: 293.4660213,
  1043. ellipseName: "Clarke 1880 (IGN)"
  1044. };
  1045. exports$2.clrk58 = {
  1046. a: 6378293.645208759,
  1047. rf: 294.2606763692654,
  1048. ellipseName: "Clarke 1858"
  1049. };
  1050. exports$2.CPM = {
  1051. a: 6375738.7,
  1052. rf: 334.29,
  1053. ellipseName: "Comm. des Poids et Mesures 1799"
  1054. };
  1055. exports$2.delmbr = {
  1056. a: 6376428.0,
  1057. rf: 311.5,
  1058. ellipseName: "Delambre 1810 (Belgium)"
  1059. };
  1060. exports$2.engelis = {
  1061. a: 6378136.05,
  1062. rf: 298.2566,
  1063. ellipseName: "Engelis 1985"
  1064. };
  1065. exports$2.evrst30 = {
  1066. a: 6377276.345,
  1067. rf: 300.8017,
  1068. ellipseName: "Everest 1830"
  1069. };
  1070. exports$2.evrst48 = {
  1071. a: 6377304.063,
  1072. rf: 300.8017,
  1073. ellipseName: "Everest 1948"
  1074. };
  1075. exports$2.evrst56 = {
  1076. a: 6377301.243,
  1077. rf: 300.8017,
  1078. ellipseName: "Everest 1956"
  1079. };
  1080. exports$2.evrst69 = {
  1081. a: 6377295.664,
  1082. rf: 300.8017,
  1083. ellipseName: "Everest 1969"
  1084. };
  1085. exports$2.evrstSS = {
  1086. a: 6377298.556,
  1087. rf: 300.8017,
  1088. ellipseName: "Everest (Sabah & Sarawak)"
  1089. };
  1090. exports$2.fschr60 = {
  1091. a: 6378166.0,
  1092. rf: 298.3,
  1093. ellipseName: "Fischer (Mercury Datum) 1960"
  1094. };
  1095. exports$2.fschr60m = {
  1096. a: 6378155.0,
  1097. rf: 298.3,
  1098. ellipseName: "Fischer 1960"
  1099. };
  1100. exports$2.fschr68 = {
  1101. a: 6378150.0,
  1102. rf: 298.3,
  1103. ellipseName: "Fischer 1968"
  1104. };
  1105. exports$2.helmert = {
  1106. a: 6378200.0,
  1107. rf: 298.3,
  1108. ellipseName: "Helmert 1906"
  1109. };
  1110. exports$2.hough = {
  1111. a: 6378270.0,
  1112. rf: 297.0,
  1113. ellipseName: "Hough"
  1114. };
  1115. exports$2.intl = {
  1116. a: 6378388.0,
  1117. rf: 297.0,
  1118. ellipseName: "International 1909 (Hayford)"
  1119. };
  1120. exports$2.kaula = {
  1121. a: 6378163.0,
  1122. rf: 298.24,
  1123. ellipseName: "Kaula 1961"
  1124. };
  1125. exports$2.lerch = {
  1126. a: 6378139.0,
  1127. rf: 298.257,
  1128. ellipseName: "Lerch 1979"
  1129. };
  1130. exports$2.mprts = {
  1131. a: 6397300.0,
  1132. rf: 191.0,
  1133. ellipseName: "Maupertius 1738"
  1134. };
  1135. exports$2.new_intl = {
  1136. a: 6378157.5,
  1137. b: 6356772.2,
  1138. ellipseName: "New International 1967"
  1139. };
  1140. exports$2.plessis = {
  1141. a: 6376523.0,
  1142. rf: 6355863.0,
  1143. ellipseName: "Plessis 1817 (France)"
  1144. };
  1145. exports$2.krass = {
  1146. a: 6378245.0,
  1147. rf: 298.3,
  1148. ellipseName: "Krassovsky, 1942"
  1149. };
  1150. exports$2.SEasia = {
  1151. a: 6378155.0,
  1152. b: 6356773.3205,
  1153. ellipseName: "Southeast Asia"
  1154. };
  1155. exports$2.walbeck = {
  1156. a: 6376896.0,
  1157. b: 6355834.8467,
  1158. ellipseName: "Walbeck"
  1159. };
  1160. exports$2.WGS60 = {
  1161. a: 6378165.0,
  1162. rf: 298.3,
  1163. ellipseName: "WGS 60"
  1164. };
  1165. exports$2.WGS66 = {
  1166. a: 6378145.0,
  1167. rf: 298.25,
  1168. ellipseName: "WGS 66"
  1169. };
  1170. exports$2.WGS7 = {
  1171. a: 6378135.0,
  1172. rf: 298.26,
  1173. ellipseName: "WGS 72"
  1174. };
  1175. var WGS84 = exports$2.WGS84 = {
  1176. a: 6378137.0,
  1177. rf: 298.257223563,
  1178. ellipseName: "WGS 84"
  1179. };
  1180. exports$2.sphere = {
  1181. a: 6370997.0,
  1182. b: 6370997.0,
  1183. ellipseName: "Normal Sphere (r=6370997)"
  1184. };
  1185. function eccentricity(a, b, rf, R_A) {
  1186. var a2 = a * a; // used in geocentric
  1187. var b2 = b * b; // used in geocentric
  1188. var es = (a2 - b2) / a2; // e ^ 2
  1189. var e = 0;
  1190. if (R_A) {
  1191. a *= 1 - es * (SIXTH + es * (RA4 + es * RA6));
  1192. a2 = a * a;
  1193. es = 0;
  1194. } else {
  1195. e = Math.sqrt(es); // eccentricity
  1196. }
  1197. var ep2 = (a2 - b2) / b2; // used in geocentric
  1198. return {
  1199. es: es,
  1200. e: e,
  1201. ep2: ep2
  1202. };
  1203. }
  1204. function sphere(a, b, rf, ellps, sphere) {
  1205. if (!a) { // do we have an ellipsoid?
  1206. var ellipse = match(exports$2, ellps);
  1207. if (!ellipse) {
  1208. ellipse = WGS84;
  1209. }
  1210. a = ellipse.a;
  1211. b = ellipse.b;
  1212. rf = ellipse.rf;
  1213. }
  1214. if (rf && !b) {
  1215. b = (1.0 - 1.0 / rf) * a;
  1216. }
  1217. if (rf === 0 || Math.abs(a - b) < EPSLN) {
  1218. sphere = true;
  1219. b = a;
  1220. }
  1221. return {
  1222. a: a,
  1223. b: b,
  1224. rf: rf,
  1225. sphere: sphere
  1226. };
  1227. }
  1228. var exports$1 = {};
  1229. exports$1.wgs84 = {
  1230. towgs84: "0,0,0",
  1231. ellipse: "WGS84",
  1232. datumName: "WGS84"
  1233. };
  1234. exports$1.ch1903 = {
  1235. towgs84: "674.374,15.056,405.346",
  1236. ellipse: "bessel",
  1237. datumName: "swiss"
  1238. };
  1239. exports$1.ggrs87 = {
  1240. towgs84: "-199.87,74.79,246.62",
  1241. ellipse: "GRS80",
  1242. datumName: "Greek_Geodetic_Reference_System_1987"
  1243. };
  1244. exports$1.nad83 = {
  1245. towgs84: "0,0,0",
  1246. ellipse: "GRS80",
  1247. datumName: "North_American_Datum_1983"
  1248. };
  1249. exports$1.nad27 = {
  1250. nadgrids: "@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat",
  1251. ellipse: "clrk66",
  1252. datumName: "North_American_Datum_1927"
  1253. };
  1254. exports$1.potsdam = {
  1255. towgs84: "598.1,73.7,418.2,0.202,0.045,-2.455,6.7",
  1256. ellipse: "bessel",
  1257. datumName: "Potsdam Rauenberg 1950 DHDN"
  1258. };
  1259. exports$1.carthage = {
  1260. towgs84: "-263.0,6.0,431.0",
  1261. ellipse: "clark80",
  1262. datumName: "Carthage 1934 Tunisia"
  1263. };
  1264. exports$1.hermannskogel = {
  1265. towgs84: "577.326,90.129,463.919,5.137,1.474,5.297,2.4232",
  1266. ellipse: "bessel",
  1267. datumName: "Hermannskogel"
  1268. };
  1269. exports$1.militargeographische_institut = {
  1270. towgs84: "577.326,90.129,463.919,5.137,1.474,5.297,2.4232",
  1271. ellipse: "bessel",
  1272. datumName: "Militar-Geographische Institut"
  1273. };
  1274. exports$1.osni52 = {
  1275. towgs84: "482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15",
  1276. ellipse: "airy",
  1277. datumName: "Irish National"
  1278. };
  1279. exports$1.ire65 = {
  1280. towgs84: "482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15",
  1281. ellipse: "mod_airy",
  1282. datumName: "Ireland 1965"
  1283. };
  1284. exports$1.rassadiran = {
  1285. towgs84: "-133.63,-157.5,-158.62",
  1286. ellipse: "intl",
  1287. datumName: "Rassadiran"
  1288. };
  1289. exports$1.nzgd49 = {
  1290. towgs84: "59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993",
  1291. ellipse: "intl",
  1292. datumName: "New Zealand Geodetic Datum 1949"
  1293. };
  1294. exports$1.osgb36 = {
  1295. towgs84: "446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894",
  1296. ellipse: "airy",
  1297. datumName: "Airy 1830"
  1298. };
  1299. exports$1.s_jtsk = {
  1300. towgs84: "589,76,480",
  1301. ellipse: 'bessel',
  1302. datumName: 'S-JTSK (Ferro)'
  1303. };
  1304. exports$1.beduaram = {
  1305. towgs84: '-106,-87,188',
  1306. ellipse: 'clrk80',
  1307. datumName: 'Beduaram'
  1308. };
  1309. exports$1.gunung_segara = {
  1310. towgs84: '-403,684,41',
  1311. ellipse: 'bessel',
  1312. datumName: 'Gunung Segara Jakarta'
  1313. };
  1314. exports$1.rnb72 = {
  1315. towgs84: "106.869,-52.2978,103.724,-0.33657,0.456955,-1.84218,1",
  1316. ellipse: "intl",
  1317. datumName: "Reseau National Belge 1972"
  1318. };
  1319. function datum(datumCode, datum_params, a, b, es, ep2, nadgrids) {
  1320. var out = {};
  1321. if (datumCode === undefined || datumCode === 'none') {
  1322. out.datum_type = PJD_NODATUM;
  1323. } else {
  1324. out.datum_type = PJD_WGS84;
  1325. }
  1326. if (datum_params) {
  1327. out.datum_params = datum_params.map(parseFloat);
  1328. if (out.datum_params[0] !== 0 || out.datum_params[1] !== 0 || out.datum_params[2] !== 0) {
  1329. out.datum_type = PJD_3PARAM;
  1330. }
  1331. if (out.datum_params.length > 3) {
  1332. if (out.datum_params[3] !== 0 || out.datum_params[4] !== 0 || out.datum_params[5] !== 0 || out.datum_params[6] !== 0) {
  1333. out.datum_type = PJD_7PARAM;
  1334. out.datum_params[3] *= SEC_TO_RAD;
  1335. out.datum_params[4] *= SEC_TO_RAD;
  1336. out.datum_params[5] *= SEC_TO_RAD;
  1337. out.datum_params[6] = (out.datum_params[6] / 1000000.0) + 1.0;
  1338. }
  1339. }
  1340. }
  1341. if (nadgrids) {
  1342. out.datum_type = PJD_GRIDSHIFT;
  1343. out.grids = nadgrids;
  1344. }
  1345. out.a = a; //datum object also uses these values
  1346. out.b = b;
  1347. out.es = es;
  1348. out.ep2 = ep2;
  1349. return out;
  1350. }
  1351. /**
  1352. * Resources for details of NTv2 file formats:
  1353. * - https://web.archive.org/web/20140127204822if_/http://www.mgs.gov.on.ca:80/stdprodconsume/groups/content/@mgs/@iandit/documents/resourcelist/stel02_047447.pdf
  1354. * - http://mimaka.com/help/gs/html/004_NTV2%20Data%20Format.htm
  1355. */
  1356. var loadedNadgrids = {};
  1357. /**
  1358. * Load a binary NTv2 file (.gsb) to a key that can be used in a proj string like +nadgrids=<key>. Pass the NTv2 file
  1359. * as an ArrayBuffer.
  1360. */
  1361. function nadgrid(key, data) {
  1362. var view = new DataView(data);
  1363. var isLittleEndian = detectLittleEndian(view);
  1364. var header = readHeader(view, isLittleEndian);
  1365. var subgrids = readSubgrids(view, header, isLittleEndian);
  1366. var nadgrid = {header: header, subgrids: subgrids};
  1367. loadedNadgrids[key] = nadgrid;
  1368. return nadgrid;
  1369. }
  1370. /**
  1371. * Given a proj4 value for nadgrids, return an array of loaded grids
  1372. */
  1373. function getNadgrids(nadgrids) {
  1374. // Format details: http://proj.maptools.org/gen_parms.html
  1375. if (nadgrids === undefined) { return null; }
  1376. var grids = nadgrids.split(',');
  1377. return grids.map(parseNadgridString);
  1378. }
  1379. function parseNadgridString(value) {
  1380. if (value.length === 0) {
  1381. return null;
  1382. }
  1383. var optional = value[0] === '@';
  1384. if (optional) {
  1385. value = value.slice(1);
  1386. }
  1387. if (value === 'null') {
  1388. return {name: 'null', mandatory: !optional, grid: null, isNull: true};
  1389. }
  1390. return {
  1391. name: value,
  1392. mandatory: !optional,
  1393. grid: loadedNadgrids[value] || null,
  1394. isNull: false
  1395. };
  1396. }
  1397. function secondsToRadians(seconds) {
  1398. return (seconds / 3600) * Math.PI / 180;
  1399. }
  1400. function detectLittleEndian(view) {
  1401. var nFields = view.getInt32(8, false);
  1402. if (nFields === 11) {
  1403. return false;
  1404. }
  1405. nFields = view.getInt32(8, true);
  1406. if (nFields !== 11) {
  1407. console.warn('Failed to detect nadgrid endian-ness, defaulting to little-endian');
  1408. }
  1409. return true;
  1410. }
  1411. function readHeader(view, isLittleEndian) {
  1412. return {
  1413. nFields: view.getInt32(8, isLittleEndian),
  1414. nSubgridFields: view.getInt32(24, isLittleEndian),
  1415. nSubgrids: view.getInt32(40, isLittleEndian),
  1416. shiftType: decodeString(view, 56, 56 + 8).trim(),
  1417. fromSemiMajorAxis: view.getFloat64(120, isLittleEndian),
  1418. fromSemiMinorAxis: view.getFloat64(136, isLittleEndian),
  1419. toSemiMajorAxis: view.getFloat64(152, isLittleEndian),
  1420. toSemiMinorAxis: view.getFloat64(168, isLittleEndian),
  1421. };
  1422. }
  1423. function decodeString(view, start, end) {
  1424. return String.fromCharCode.apply(null, new Uint8Array(view.buffer.slice(start, end)));
  1425. }
  1426. function readSubgrids(view, header, isLittleEndian) {
  1427. var gridOffset = 176;
  1428. var grids = [];
  1429. for (var i = 0; i < header.nSubgrids; i++) {
  1430. var subHeader = readGridHeader(view, gridOffset, isLittleEndian);
  1431. var nodes = readGridNodes(view, gridOffset, subHeader, isLittleEndian);
  1432. var lngColumnCount = Math.round(
  1433. 1 + (subHeader.upperLongitude - subHeader.lowerLongitude) / subHeader.longitudeInterval);
  1434. var latColumnCount = Math.round(
  1435. 1 + (subHeader.upperLatitude - subHeader.lowerLatitude) / subHeader.latitudeInterval);
  1436. // Proj4 operates on radians whereas the coordinates are in seconds in the grid
  1437. grids.push({
  1438. ll: [secondsToRadians(subHeader.lowerLongitude), secondsToRadians(subHeader.lowerLatitude)],
  1439. del: [secondsToRadians(subHeader.longitudeInterval), secondsToRadians(subHeader.latitudeInterval)],
  1440. lim: [lngColumnCount, latColumnCount],
  1441. count: subHeader.gridNodeCount,
  1442. cvs: mapNodes(nodes)
  1443. });
  1444. gridOffset += 176 + subHeader.gridNodeCount * 16;
  1445. }
  1446. return grids;
  1447. }
  1448. function mapNodes(nodes) {
  1449. return nodes.map(function (r) {return [secondsToRadians(r.longitudeShift), secondsToRadians(r.latitudeShift)];});
  1450. }
  1451. function readGridHeader(view, offset, isLittleEndian) {
  1452. return {
  1453. name: decodeString(view, offset + 8, offset + 16).trim(),
  1454. parent: decodeString(view, offset + 24, offset + 24 + 8).trim(),
  1455. lowerLatitude: view.getFloat64(offset + 72, isLittleEndian),
  1456. upperLatitude: view.getFloat64(offset + 88, isLittleEndian),
  1457. lowerLongitude: view.getFloat64(offset + 104, isLittleEndian),
  1458. upperLongitude: view.getFloat64(offset + 120, isLittleEndian),
  1459. latitudeInterval: view.getFloat64(offset + 136, isLittleEndian),
  1460. longitudeInterval: view.getFloat64(offset + 152, isLittleEndian),
  1461. gridNodeCount: view.getInt32(offset + 168, isLittleEndian)
  1462. };
  1463. }
  1464. function readGridNodes(view, offset, gridHeader, isLittleEndian) {
  1465. var nodesOffset = offset + 176;
  1466. var gridRecordLength = 16;
  1467. var gridShiftRecords = [];
  1468. for (var i = 0; i < gridHeader.gridNodeCount; i++) {
  1469. var record = {
  1470. latitudeShift: view.getFloat32(nodesOffset + i * gridRecordLength, isLittleEndian),
  1471. longitudeShift: view.getFloat32(nodesOffset + i * gridRecordLength + 4, isLittleEndian),
  1472. latitudeAccuracy: view.getFloat32(nodesOffset + i * gridRecordLength + 8, isLittleEndian),
  1473. longitudeAccuracy: view.getFloat32(nodesOffset + i * gridRecordLength + 12, isLittleEndian),
  1474. };
  1475. gridShiftRecords.push(record);
  1476. }
  1477. return gridShiftRecords;
  1478. }
  1479. function Projection(srsCode,callback) {
  1480. if (!(this instanceof Projection)) {
  1481. return new Projection(srsCode);
  1482. }
  1483. callback = callback || function(error){
  1484. if(error){
  1485. throw error;
  1486. }
  1487. };
  1488. var json = parse(srsCode);
  1489. if(typeof json !== 'object'){
  1490. callback(srsCode);
  1491. return;
  1492. }
  1493. var ourProj = Projection.projections.get(json.projName);
  1494. if(!ourProj){
  1495. callback(srsCode);
  1496. return;
  1497. }
  1498. if (json.datumCode && json.datumCode !== 'none') {
  1499. var datumDef = match(exports$1, json.datumCode);
  1500. if (datumDef) {
  1501. json.datum_params = json.datum_params || (datumDef.towgs84 ? datumDef.towgs84.split(',') : null);
  1502. json.ellps = datumDef.ellipse;
  1503. json.datumName = datumDef.datumName ? datumDef.datumName : json.datumCode;
  1504. }
  1505. }
  1506. json.k0 = json.k0 || 1.0;
  1507. json.axis = json.axis || 'enu';
  1508. json.ellps = json.ellps || 'wgs84';
  1509. json.lat1 = json.lat1 || json.lat0; // Lambert_Conformal_Conic_1SP, for example, needs this
  1510. var sphere_ = sphere(json.a, json.b, json.rf, json.ellps, json.sphere);
  1511. var ecc = eccentricity(sphere_.a, sphere_.b, sphere_.rf, json.R_A);
  1512. var nadgrids = getNadgrids(json.nadgrids);
  1513. var datumObj = json.datum || datum(json.datumCode, json.datum_params, sphere_.a, sphere_.b, ecc.es, ecc.ep2,
  1514. nadgrids);
  1515. extend(this, json); // transfer everything over from the projection because we don't know what we'll need
  1516. extend(this, ourProj); // transfer all the methods from the projection
  1517. // copy the 4 things over we calculated in deriveConstants.sphere
  1518. this.a = sphere_.a;
  1519. this.b = sphere_.b;
  1520. this.rf = sphere_.rf;
  1521. this.sphere = sphere_.sphere;
  1522. // copy the 3 things we calculated in deriveConstants.eccentricity
  1523. this.es = ecc.es;
  1524. this.e = ecc.e;
  1525. this.ep2 = ecc.ep2;
  1526. // add in the datum object
  1527. this.datum = datumObj;
  1528. // init the projection
  1529. this.init();
  1530. // legecy callback from back in the day when it went to spatialreference.org
  1531. callback(null, this);
  1532. }
  1533. Projection.projections = projections;
  1534. Projection.projections.start();
  1535. function compareDatums(source, dest) {
  1536. if (source.datum_type !== dest.datum_type) {
  1537. return false; // false, datums are not equal
  1538. } else if (source.a !== dest.a || Math.abs(source.es - dest.es) > 0.000000000050) {
  1539. // the tolerance for es is to ensure that GRS80 and WGS84
  1540. // are considered identical
  1541. return false;
  1542. } else if (source.datum_type === PJD_3PARAM) {
  1543. 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]);
  1544. } else if (source.datum_type === PJD_7PARAM) {
  1545. 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]);
  1546. } else {
  1547. return true; // datums are equal
  1548. }
  1549. } // cs_compare_datums()
  1550. /*
  1551. * The function Convert_Geodetic_To_Geocentric converts geodetic coordinates
  1552. * (latitude, longitude, and height) to geocentric coordinates (X, Y, Z),
  1553. * according to the current ellipsoid parameters.
  1554. *
  1555. * Latitude : Geodetic latitude in radians (input)
  1556. * Longitude : Geodetic longitude in radians (input)
  1557. * Height : Geodetic height, in meters (input)
  1558. * X : Calculated Geocentric X coordinate, in meters (output)
  1559. * Y : Calculated Geocentric Y coordinate, in meters (output)
  1560. * Z : Calculated Geocentric Z coordinate, in meters (output)
  1561. *
  1562. */
  1563. function geodeticToGeocentric(p, es, a) {
  1564. var Longitude = p.x;
  1565. var Latitude = p.y;
  1566. var Height = p.z ? p.z : 0; //Z value not always supplied
  1567. var Rn; /* Earth radius at location */
  1568. var Sin_Lat; /* Math.sin(Latitude) */
  1569. var Sin2_Lat; /* Square of Math.sin(Latitude) */
  1570. var Cos_Lat; /* Math.cos(Latitude) */
  1571. /*
  1572. ** Don't blow up if Latitude is just a little out of the value
  1573. ** range as it may just be a rounding issue. Also removed longitude
  1574. ** test, it should be wrapped by Math.cos() and Math.sin(). NFW for PROJ.4, Sep/2001.
  1575. */
  1576. if (Latitude < -HALF_PI && Latitude > -1.001 * HALF_PI) {
  1577. Latitude = -HALF_PI;
  1578. } else if (Latitude > HALF_PI && Latitude < 1.001 * HALF_PI) {
  1579. Latitude = HALF_PI;
  1580. } else if (Latitude < -HALF_PI) {
  1581. /* Latitude out of range */
  1582. //..reportError('geocent:lat out of range:' + Latitude);
  1583. return { x: -Infinity, y: -Infinity, z: p.z };
  1584. } else if (Latitude > HALF_PI) {
  1585. /* Latitude out of range */
  1586. return { x: Infinity, y: Infinity, z: p.z };
  1587. }
  1588. if (Longitude > Math.PI) {
  1589. Longitude -= (2 * Math.PI);
  1590. }
  1591. Sin_Lat = Math.sin(Latitude);
  1592. Cos_Lat = Math.cos(Latitude);
  1593. Sin2_Lat = Sin_Lat * Sin_Lat;
  1594. Rn = a / (Math.sqrt(1.0e0 - es * Sin2_Lat));
  1595. return {
  1596. x: (Rn + Height) * Cos_Lat * Math.cos(Longitude),
  1597. y: (Rn + Height) * Cos_Lat * Math.sin(Longitude),
  1598. z: ((Rn * (1 - es)) + Height) * Sin_Lat
  1599. };
  1600. } // cs_geodetic_to_geocentric()
  1601. function geocentricToGeodetic(p, es, a, b) {
  1602. /* local defintions and variables */
  1603. /* end-criterium of loop, accuracy of sin(Latitude) */
  1604. var genau = 1e-12;
  1605. var genau2 = (genau * genau);
  1606. var maxiter = 30;
  1607. var P; /* distance between semi-minor axis and location */
  1608. var RR; /* distance between center and location */
  1609. var CT; /* sin of geocentric latitude */
  1610. var ST; /* cos of geocentric latitude */
  1611. var RX;
  1612. var RK;
  1613. var RN; /* Earth radius at location */
  1614. var CPHI0; /* cos of start or old geodetic latitude in iterations */
  1615. var SPHI0; /* sin of start or old geodetic latitude in iterations */
  1616. var CPHI; /* cos of searched geodetic latitude */
  1617. var SPHI; /* sin of searched geodetic latitude */
  1618. var SDPHI; /* end-criterium: addition-theorem of sin(Latitude(iter)-Latitude(iter-1)) */
  1619. var iter; /* # of continous iteration, max. 30 is always enough (s.a.) */
  1620. var X = p.x;
  1621. var Y = p.y;
  1622. var Z = p.z ? p.z : 0.0; //Z value not always supplied
  1623. var Longitude;
  1624. var Latitude;
  1625. var Height;
  1626. P = Math.sqrt(X * X + Y * Y);
  1627. RR = Math.sqrt(X * X + Y * Y + Z * Z);
  1628. /* special cases for latitude and longitude */
  1629. if (P / a < genau) {
  1630. /* special case, if P=0. (X=0., Y=0.) */
  1631. Longitude = 0.0;
  1632. /* if (X,Y,Z)=(0.,0.,0.) then Height becomes semi-minor axis
  1633. * of ellipsoid (=center of mass), Latitude becomes PI/2 */
  1634. if (RR / a < genau) {
  1635. Latitude = HALF_PI;
  1636. Height = -b;
  1637. return {
  1638. x: p.x,
  1639. y: p.y,
  1640. z: p.z
  1641. };
  1642. }
  1643. } else {
  1644. /* ellipsoidal (geodetic) longitude
  1645. * interval: -PI < Longitude <= +PI */
  1646. Longitude = Math.atan2(Y, X);
  1647. }
  1648. /* --------------------------------------------------------------
  1649. * Following iterative algorithm was developped by
  1650. * "Institut for Erdmessung", University of Hannover, July 1988.
  1651. * Internet: www.ife.uni-hannover.de
  1652. * Iterative computation of CPHI,SPHI and Height.
  1653. * Iteration of CPHI and SPHI to 10**-12 radian resp.
  1654. * 2*10**-7 arcsec.
  1655. * --------------------------------------------------------------
  1656. */
  1657. CT = Z / RR;
  1658. ST = P / RR;
  1659. RX = 1.0 / Math.sqrt(1.0 - es * (2.0 - es) * ST * ST);
  1660. CPHI0 = ST * (1.0 - es) * RX;
  1661. SPHI0 = CT * RX;
  1662. iter = 0;
  1663. /* loop to find sin(Latitude) resp. Latitude
  1664. * until |sin(Latitude(iter)-Latitude(iter-1))| < genau */
  1665. do {
  1666. iter++;
  1667. RN = a / Math.sqrt(1.0 - es * SPHI0 * SPHI0);
  1668. /* ellipsoidal (geodetic) height */
  1669. Height = P * CPHI0 + Z * SPHI0 - RN * (1.0 - es * SPHI0 * SPHI0);
  1670. RK = es * RN / (RN + Height);
  1671. RX = 1.0 / Math.sqrt(1.0 - RK * (2.0 - RK) * ST * ST);
  1672. CPHI = ST * (1.0 - RK) * RX;
  1673. SPHI = CT * RX;
  1674. SDPHI = SPHI * CPHI0 - CPHI * SPHI0;
  1675. CPHI0 = CPHI;
  1676. SPHI0 = SPHI;
  1677. }
  1678. while (SDPHI * SDPHI > genau2 && iter < maxiter);
  1679. /* ellipsoidal (geodetic) latitude */
  1680. Latitude = Math.atan(SPHI / Math.abs(CPHI));
  1681. return {
  1682. x: Longitude,
  1683. y: Latitude,
  1684. z: Height
  1685. };
  1686. } // cs_geocentric_to_geodetic()
  1687. /****************************************************************/
  1688. // pj_geocentic_to_wgs84( p )
  1689. // p = point to transform in geocentric coordinates (x,y,z)
  1690. /** point object, nothing fancy, just allows values to be
  1691. passed back and forth by reference rather than by value.
  1692. Other point classes may be used as long as they have
  1693. x and y properties, which will get modified in the transform method.
  1694. */
  1695. function geocentricToWgs84(p, datum_type, datum_params) {
  1696. if (datum_type === PJD_3PARAM) {
  1697. // if( x[io] === HUGE_VAL )
  1698. // continue;
  1699. return {
  1700. x: p.x + datum_params[0],
  1701. y: p.y + datum_params[1],
  1702. z: p.z + datum_params[2],
  1703. };
  1704. } else if (datum_type === PJD_7PARAM) {
  1705. var Dx_BF = datum_params[0];
  1706. var Dy_BF = datum_params[1];
  1707. var Dz_BF = datum_params[2];
  1708. var Rx_BF = datum_params[3];
  1709. var Ry_BF = datum_params[4];
  1710. var Rz_BF = datum_params[5];
  1711. var M_BF = datum_params[6];
  1712. // if( x[io] === HUGE_VAL )
  1713. // continue;
  1714. return {
  1715. x: M_BF * (p.x - Rz_BF * p.y + Ry_BF * p.z) + Dx_BF,
  1716. y: M_BF * (Rz_BF * p.x + p.y - Rx_BF * p.z) + Dy_BF,
  1717. z: M_BF * (-Ry_BF * p.x + Rx_BF * p.y + p.z) + Dz_BF
  1718. };
  1719. }
  1720. } // cs_geocentric_to_wgs84
  1721. /****************************************************************/
  1722. // pj_geocentic_from_wgs84()
  1723. // coordinate system definition,
  1724. // point to transform in geocentric coordinates (x,y,z)
  1725. function geocentricFromWgs84(p, datum_type, datum_params) {
  1726. if (datum_type === PJD_3PARAM) {
  1727. //if( x[io] === HUGE_VAL )
  1728. // continue;
  1729. return {
  1730. x: p.x - datum_params[0],
  1731. y: p.y - datum_params[1],
  1732. z: p.z - datum_params[2],
  1733. };
  1734. } else if (datum_type === PJD_7PARAM) {
  1735. var Dx_BF = datum_params[0];
  1736. var Dy_BF = datum_params[1];
  1737. var Dz_BF = datum_params[2];
  1738. var Rx_BF = datum_params[3];
  1739. var Ry_BF = datum_params[4];
  1740. var Rz_BF = datum_params[5];
  1741. var M_BF = datum_params[6];
  1742. var x_tmp = (p.x - Dx_BF) / M_BF;
  1743. var y_tmp = (p.y - Dy_BF) / M_BF;
  1744. var z_tmp = (p.z - Dz_BF) / M_BF;
  1745. //if( x[io] === HUGE_VAL )
  1746. // continue;
  1747. return {
  1748. x: x_tmp + Rz_BF * y_tmp - Ry_BF * z_tmp,
  1749. y: -Rz_BF * x_tmp + y_tmp + Rx_BF * z_tmp,
  1750. z: Ry_BF * x_tmp - Rx_BF * y_tmp + z_tmp
  1751. };
  1752. } //cs_geocentric_from_wgs84()
  1753. }
  1754. function checkParams(type) {
  1755. return (type === PJD_3PARAM || type === PJD_7PARAM);
  1756. }
  1757. function datum_transform(source, dest, point) {
  1758. // Short cut if the datums are identical.
  1759. if (compareDatums(source, dest)) {
  1760. return point; // in this case, zero is sucess,
  1761. // whereas cs_compare_datums returns 1 to indicate TRUE
  1762. // confusing, should fix this
  1763. }
  1764. // Explicitly skip datum transform by setting 'datum=none' as parameter for either source or dest
  1765. if (source.datum_type === PJD_NODATUM || dest.datum_type === PJD_NODATUM) {
  1766. return point;
  1767. }
  1768. // If this datum requires grid shifts, then apply it to geodetic coordinates.
  1769. var source_a = source.a;
  1770. var source_es = source.es;
  1771. if (source.datum_type === PJD_GRIDSHIFT) {
  1772. var gridShiftCode = applyGridShift(source, false, point);
  1773. if (gridShiftCode !== 0) {
  1774. return undefined;
  1775. }
  1776. source_a = SRS_WGS84_SEMIMAJOR;
  1777. source_es = SRS_WGS84_ESQUARED;
  1778. }
  1779. var dest_a = dest.a;
  1780. var dest_b = dest.b;
  1781. var dest_es = dest.es;
  1782. if (dest.datum_type === PJD_GRIDSHIFT) {
  1783. dest_a = SRS_WGS84_SEMIMAJOR;
  1784. dest_b = SRS_WGS84_SEMIMINOR;
  1785. dest_es = SRS_WGS84_ESQUARED;
  1786. }
  1787. // Do we need to go through geocentric coordinates?
  1788. if (source_es === dest_es && source_a === dest_a && !checkParams(source.datum_type) && !checkParams(dest.datum_type)) {
  1789. return point;
  1790. }
  1791. // Convert to geocentric coordinates.
  1792. point = geodeticToGeocentric(point, source_es, source_a);
  1793. // Convert between datums
  1794. if (checkParams(source.datum_type)) {
  1795. point = geocentricToWgs84(point, source.datum_type, source.datum_params);
  1796. }
  1797. if (checkParams(dest.datum_type)) {
  1798. point = geocentricFromWgs84(point, dest.datum_type, dest.datum_params);
  1799. }
  1800. point = geocentricToGeodetic(point, dest_es, dest_a, dest_b);
  1801. if (dest.datum_type === PJD_GRIDSHIFT) {
  1802. var destGridShiftResult = applyGridShift(dest, true, point);
  1803. if (destGridShiftResult !== 0) {
  1804. return undefined;
  1805. }
  1806. }
  1807. return point;
  1808. }
  1809. function applyGridShift(source, inverse, point) {
  1810. if (source.grids === null || source.grids.length === 0) {
  1811. console.log('Grid shift grids not found');
  1812. return -1;
  1813. }
  1814. var input = {x: -point.x, y: point.y};
  1815. var output = {x: Number.NaN, y: Number.NaN};
  1816. var attemptedGrids = [];
  1817. outer:
  1818. for (var i = 0; i < source.grids.length; i++) {
  1819. var grid = source.grids[i];
  1820. attemptedGrids.push(grid.name);
  1821. if (grid.isNull) {
  1822. output = input;
  1823. break;
  1824. }
  1825. grid.mandatory;
  1826. if (grid.grid === null) {
  1827. if (grid.mandatory) {
  1828. console.log("Unable to find mandatory grid '" + grid.name + "'");
  1829. return -1;
  1830. }
  1831. continue;
  1832. }
  1833. var subgrids = grid.grid.subgrids;
  1834. for (var j = 0, jj = subgrids.length; j < jj; j++) {
  1835. var subgrid = subgrids[j];
  1836. // skip tables that don't match our point at all
  1837. var epsilon = (Math.abs(subgrid.del[1]) + Math.abs(subgrid.del[0])) / 10000.0;
  1838. var minX = subgrid.ll[0] - epsilon;
  1839. var minY = subgrid.ll[1] - epsilon;
  1840. var maxX = subgrid.ll[0] + (subgrid.lim[0] - 1) * subgrid.del[0] + epsilon;
  1841. var maxY = subgrid.ll[1] + (subgrid.lim[1] - 1) * subgrid.del[1] + epsilon;
  1842. if (minY > input.y || minX > input.x || maxY < input.y || maxX < input.x ) {
  1843. continue;
  1844. }
  1845. output = applySubgridShift(input, inverse, subgrid);
  1846. if (!isNaN(output.x)) {
  1847. break outer;
  1848. }
  1849. }
  1850. }
  1851. if (isNaN(output.x)) {
  1852. console.log("Failed to find a grid shift table for location '"+
  1853. -input.x * R2D + " " + input.y * R2D + " tried: '" + attemptedGrids + "'");
  1854. return -1;
  1855. }
  1856. point.x = -output.x;
  1857. point.y = output.y;
  1858. return 0;
  1859. }
  1860. function applySubgridShift(pin, inverse, ct) {
  1861. var val = {x: Number.NaN, y: Number.NaN};
  1862. if (isNaN(pin.x)) { return val; }
  1863. var tb = {x: pin.x, y: pin.y};
  1864. tb.x -= ct.ll[0];
  1865. tb.y -= ct.ll[1];
  1866. tb.x = adjust_lon(tb.x - Math.PI) + Math.PI;
  1867. var t = nadInterpolate(tb, ct);
  1868. if (inverse) {
  1869. if (isNaN(t.x)) {
  1870. return val;
  1871. }
  1872. t.x = tb.x - t.x;
  1873. t.y = tb.y - t.y;
  1874. var i = 9, tol = 1e-12;
  1875. var dif, del;
  1876. do {
  1877. del = nadInterpolate(t, ct);
  1878. if (isNaN(del.x)) {
  1879. console.log("Inverse grid shift iteration failed, presumably at grid edge. Using first approximation.");
  1880. break;
  1881. }
  1882. dif = {x: tb.x - (del.x + t.x), y: tb.y - (del.y + t.y)};
  1883. t.x += dif.x;
  1884. t.y += dif.y;
  1885. } while (i-- && Math.abs(dif.x) > tol && Math.abs(dif.y) > tol);
  1886. if (i < 0) {
  1887. console.log("Inverse grid shift iterator failed to converge.");
  1888. return val;
  1889. }
  1890. val.x = adjust_lon(t.x + ct.ll[0]);
  1891. val.y = t.y + ct.ll[1];
  1892. } else {
  1893. if (!isNaN(t.x)) {
  1894. val.x = pin.x + t.x;
  1895. val.y = pin.y + t.y;
  1896. }
  1897. }
  1898. return val;
  1899. }
  1900. function nadInterpolate(pin, ct) {
  1901. var t = {x: pin.x / ct.del[0], y: pin.y / ct.del[1]};
  1902. var indx = {x: Math.floor(t.x), y: Math.floor(t.y)};
  1903. var frct = {x: t.x - 1.0 * indx.x, y: t.y - 1.0 * indx.y};
  1904. var val= {x: Number.NaN, y: Number.NaN};
  1905. var inx;
  1906. if (indx.x < 0 || indx.x >= ct.lim[0]) {
  1907. return val;
  1908. }
  1909. if (indx.y < 0 || indx.y >= ct.lim[1]) {
  1910. return val;
  1911. }
  1912. inx = (indx.y * ct.lim[0]) + indx.x;
  1913. var f00 = {x: ct.cvs[inx][0], y: ct.cvs[inx][1]};
  1914. inx++;
  1915. var f10= {x: ct.cvs[inx][0], y: ct.cvs[inx][1]};
  1916. inx += ct.lim[0];
  1917. var f11 = {x: ct.cvs[inx][0], y: ct.cvs[inx][1]};
  1918. inx--;
  1919. var f01 = {x: ct.cvs[inx][0], y: ct.cvs[inx][1]};
  1920. var m11 = frct.x * frct.y, m10 = frct.x * (1.0 - frct.y),
  1921. m00 = (1.0 - frct.x) * (1.0 - frct.y), m01 = (1.0 - frct.x) * frct.y;
  1922. val.x = (m00 * f00.x + m10 * f10.x + m01 * f01.x + m11 * f11.x);
  1923. val.y = (m00 * f00.y + m10 * f10.y + m01 * f01.y + m11 * f11.y);
  1924. return val;
  1925. }
  1926. function adjust_axis(crs, denorm, point) {
  1927. var xin = point.x,
  1928. yin = point.y,
  1929. zin = point.z || 0.0;
  1930. var v, t, i;
  1931. var out = {};
  1932. for (i = 0; i < 3; i++) {
  1933. if (denorm && i === 2 && point.z === undefined) {
  1934. continue;
  1935. }
  1936. if (i === 0) {
  1937. v = xin;
  1938. if ("ew".indexOf(crs.axis[i]) !== -1) {
  1939. t = 'x';
  1940. } else {
  1941. t = 'y';
  1942. }
  1943. }
  1944. else if (i === 1) {
  1945. v = yin;
  1946. if ("ns".indexOf(crs.axis[i]) !== -1) {
  1947. t = 'y';
  1948. } else {
  1949. t = 'x';
  1950. }
  1951. }
  1952. else {
  1953. v = zin;
  1954. t = 'z';
  1955. }
  1956. switch (crs.axis[i]) {
  1957. case 'e':
  1958. out[t] = v;
  1959. break;
  1960. case 'w':
  1961. out[t] = -v;
  1962. break;
  1963. case 'n':
  1964. out[t] = v;
  1965. break;
  1966. case 's':
  1967. out[t] = -v;
  1968. break;
  1969. case 'u':
  1970. if (point[t] !== undefined) {
  1971. out.z = v;
  1972. }
  1973. break;
  1974. case 'd':
  1975. if (point[t] !== undefined) {
  1976. out.z = -v;
  1977. }
  1978. break;
  1979. default:
  1980. //console.log("ERROR: unknow axis ("+crs.axis[i]+") - check definition of "+crs.projName);
  1981. return null;
  1982. }
  1983. }
  1984. return out;
  1985. }
  1986. function common (array){
  1987. var out = {
  1988. x: array[0],
  1989. y: array[1]
  1990. };
  1991. if (array.length>2) {
  1992. out.z = array[2];
  1993. }
  1994. if (array.length>3) {
  1995. out.m = array[3];
  1996. }
  1997. return out;
  1998. }
  1999. function checkSanity (point) {
  2000. checkCoord(point.x);
  2001. checkCoord(point.y);
  2002. }
  2003. function checkCoord(num) {
  2004. if (typeof Number.isFinite === 'function') {
  2005. if (Number.isFinite(num)) {
  2006. return;
  2007. }
  2008. throw new TypeError('coordinates must be finite numbers');
  2009. }
  2010. if (typeof num !== 'number' || num !== num || !isFinite(num)) {
  2011. throw new TypeError('coordinates must be finite numbers');
  2012. }
  2013. }
  2014. function checkNotWGS(source, dest) {
  2015. return (
  2016. (source.datum.datum_type === PJD_3PARAM || source.datum.datum_type === PJD_7PARAM || source.datum.datum_type === PJD_GRIDSHIFT) && dest.datumCode !== 'WGS84') ||
  2017. ((dest.datum.datum_type === PJD_3PARAM || dest.datum.datum_type === PJD_7PARAM || dest.datum.datum_type === PJD_GRIDSHIFT) && source.datumCode !== 'WGS84');
  2018. }
  2019. function transform(source, dest, point, enforceAxis) {
  2020. var wgs84;
  2021. if (Array.isArray(point)) {
  2022. point = common(point);
  2023. } else {
  2024. // Clone the point object so inputs don't get modified
  2025. point = {
  2026. x: point.x,
  2027. y: point.y,
  2028. z: point.z,
  2029. m: point.m
  2030. };
  2031. }
  2032. var hasZ = point.z !== undefined;
  2033. checkSanity(point);
  2034. // Workaround for datum shifts towgs84, if either source or destination projection is not wgs84
  2035. if (source.datum && dest.datum && checkNotWGS(source, dest)) {
  2036. wgs84 = new Projection('WGS84');
  2037. point = transform(source, wgs84, point, enforceAxis);
  2038. source = wgs84;
  2039. }
  2040. // DGR, 2010/11/12
  2041. if (enforceAxis && source.axis !== 'enu') {
  2042. point = adjust_axis(source, false, point);
  2043. }
  2044. // Transform source points to long/lat, if they aren't already.
  2045. if (source.projName === 'longlat') {
  2046. point = {
  2047. x: point.x * D2R$1,
  2048. y: point.y * D2R$1,
  2049. z: point.z || 0
  2050. };
  2051. } else {
  2052. if (source.to_meter) {
  2053. point = {
  2054. x: point.x * source.to_meter,
  2055. y: point.y * source.to_meter,
  2056. z: point.z || 0
  2057. };
  2058. }
  2059. point = source.inverse(point); // Convert Cartesian to longlat
  2060. if (!point) {
  2061. return;
  2062. }
  2063. }
  2064. // Adjust for the prime meridian if necessary
  2065. if (source.from_greenwich) {
  2066. point.x += source.from_greenwich;
  2067. }
  2068. // Convert datums if needed, and if possible.
  2069. point = datum_transform(source.datum, dest.datum, point);
  2070. if (!point) {
  2071. return;
  2072. }
  2073. // Adjust for the prime meridian if necessary
  2074. if (dest.from_greenwich) {
  2075. point = {
  2076. x: point.x - dest.from_greenwich,
  2077. y: point.y,
  2078. z: point.z || 0
  2079. };
  2080. }
  2081. if (dest.projName === 'longlat') {
  2082. // convert radians to decimal degrees
  2083. point = {
  2084. x: point.x * R2D,
  2085. y: point.y * R2D,
  2086. z: point.z || 0
  2087. };
  2088. } else { // else project
  2089. point = dest.forward(point);
  2090. if (dest.to_meter) {
  2091. point = {
  2092. x: point.x / dest.to_meter,
  2093. y: point.y / dest.to_meter,
  2094. z: point.z || 0
  2095. };
  2096. }
  2097. }
  2098. // DGR, 2010/11/12
  2099. if (enforceAxis && dest.axis !== 'enu') {
  2100. return adjust_axis(dest, true, point);
  2101. }
  2102. if (point && !hasZ) {
  2103. delete point.z;
  2104. }
  2105. return point;
  2106. }
  2107. var wgs84 = Projection('WGS84');
  2108. function transformer(from, to, coords, enforceAxis) {
  2109. var transformedArray, out, keys;
  2110. if (Array.isArray(coords)) {
  2111. transformedArray = transform(from, to, coords, enforceAxis) || {x: NaN, y: NaN};
  2112. if (coords.length > 2) {
  2113. if ((typeof from.name !== 'undefined' && from.name === 'geocent') || (typeof to.name !== 'undefined' && to.name === 'geocent')) {
  2114. if (typeof transformedArray.z === 'number') {
  2115. return [transformedArray.x, transformedArray.y, transformedArray.z].concat(coords.splice(3));
  2116. } else {
  2117. return [transformedArray.x, transformedArray.y, coords[2]].concat(coords.splice(3));
  2118. }
  2119. } else {
  2120. return [transformedArray.x, transformedArray.y].concat(coords.splice(2));
  2121. }
  2122. } else {
  2123. return [transformedArray.x, transformedArray.y];
  2124. }
  2125. } else {
  2126. out = transform(from, to, coords, enforceAxis);
  2127. keys = Object.keys(coords);
  2128. if (keys.length === 2) {
  2129. return out;
  2130. }
  2131. keys.forEach(function (key) {
  2132. if ((typeof from.name !== 'undefined' && from.name === 'geocent') || (typeof to.name !== 'undefined' && to.name === 'geocent')) {
  2133. if (key === 'x' || key === 'y' || key === 'z') {
  2134. return;
  2135. }
  2136. } else {
  2137. if (key === 'x' || key === 'y') {
  2138. return;
  2139. }
  2140. }
  2141. out[key] = coords[key];
  2142. });
  2143. return out;
  2144. }
  2145. }
  2146. function checkProj(item) {
  2147. if (item instanceof Projection) {
  2148. return item;
  2149. }
  2150. if (item.oProj) {
  2151. return item.oProj;
  2152. }
  2153. return Projection(item);
  2154. }
  2155. function proj4(fromProj, toProj, coord) {
  2156. fromProj = checkProj(fromProj);
  2157. var single = false;
  2158. var obj;
  2159. if (typeof toProj === 'undefined') {
  2160. toProj = fromProj;
  2161. fromProj = wgs84;
  2162. single = true;
  2163. } else if (typeof toProj.x !== 'undefined' || Array.isArray(toProj)) {
  2164. coord = toProj;
  2165. toProj = fromProj;
  2166. fromProj = wgs84;
  2167. single = true;
  2168. }
  2169. toProj = checkProj(toProj);
  2170. if (coord) {
  2171. return transformer(fromProj, toProj, coord);
  2172. } else {
  2173. obj = {
  2174. forward: function (coords, enforceAxis) {
  2175. return transformer(fromProj, toProj, coords, enforceAxis);
  2176. },
  2177. inverse: function (coords, enforceAxis) {
  2178. return transformer(toProj, fromProj, coords, enforceAxis);
  2179. }
  2180. };
  2181. if (single) {
  2182. obj.oProj = toProj;
  2183. }
  2184. return obj;
  2185. }
  2186. }
  2187. /**
  2188. * UTM zones are grouped, and assigned to one of a group of 6
  2189. * sets.
  2190. *
  2191. * {int} @private
  2192. */
  2193. var NUM_100K_SETS = 6;
  2194. /**
  2195. * The column letters (for easting) of the lower left value, per
  2196. * set.
  2197. *
  2198. * {string} @private
  2199. */
  2200. var SET_ORIGIN_COLUMN_LETTERS = 'AJSAJS';
  2201. /**
  2202. * The row letters (for northing) of the lower left value, per
  2203. * set.
  2204. *
  2205. * {string} @private
  2206. */
  2207. var SET_ORIGIN_ROW_LETTERS = 'AFAFAF';
  2208. var A = 65; // A
  2209. var I = 73; // I
  2210. var O = 79; // O
  2211. var V = 86; // V
  2212. var Z = 90; // Z
  2213. var mgrs = {
  2214. forward: forward$t,
  2215. inverse: inverse$t,
  2216. toPoint: toPoint
  2217. };
  2218. /**
  2219. * Conversion of lat/lon to MGRS.
  2220. *
  2221. * @param {object} ll Object literal with lat and lon properties on a
  2222. * WGS84 ellipsoid.
  2223. * @param {int} accuracy Accuracy in digits (5 for 1 m, 4 for 10 m, 3 for
  2224. * 100 m, 2 for 1000 m or 1 for 10000 m). Optional, default is 5.
  2225. * @return {string} the MGRS string for the given location and accuracy.
  2226. */
  2227. function forward$t(ll, accuracy) {
  2228. accuracy = accuracy || 5; // default accuracy 1m
  2229. return encode(LLtoUTM({
  2230. lat: ll[1],
  2231. lon: ll[0]
  2232. }), accuracy);
  2233. }
  2234. /**
  2235. * Conversion of MGRS to lat/lon.
  2236. *
  2237. * @param {string} mgrs MGRS string.
  2238. * @return {array} An array with left (longitude), bottom (latitude), right
  2239. * (longitude) and top (latitude) values in WGS84, representing the
  2240. * bounding box for the provided MGRS reference.
  2241. */
  2242. function inverse$t(mgrs) {
  2243. var bbox = UTMtoLL(decode(mgrs.toUpperCase()));
  2244. if (bbox.lat && bbox.lon) {
  2245. return [bbox.lon, bbox.lat, bbox.lon, bbox.lat];
  2246. }
  2247. return [bbox.left, bbox.bottom, bbox.right, bbox.top];
  2248. }
  2249. function toPoint(mgrs) {
  2250. var bbox = UTMtoLL(decode(mgrs.toUpperCase()));
  2251. if (bbox.lat && bbox.lon) {
  2252. return [bbox.lon, bbox.lat];
  2253. }
  2254. return [(bbox.left + bbox.right) / 2, (bbox.top + bbox.bottom) / 2];
  2255. }/**
  2256. * Conversion from degrees to radians.
  2257. *
  2258. * @private
  2259. * @param {number} deg the angle in degrees.
  2260. * @return {number} the angle in radians.
  2261. */
  2262. function degToRad(deg) {
  2263. return (deg * (Math.PI / 180.0));
  2264. }
  2265. /**
  2266. * Conversion from radians to degrees.
  2267. *
  2268. * @private
  2269. * @param {number} rad the angle in radians.
  2270. * @return {number} the angle in degrees.
  2271. */
  2272. function radToDeg(rad) {
  2273. return (180.0 * (rad / Math.PI));
  2274. }
  2275. /**
  2276. * Converts a set of Longitude and Latitude co-ordinates to UTM
  2277. * using the WGS84 ellipsoid.
  2278. *
  2279. * @private
  2280. * @param {object} ll Object literal with lat and lon properties
  2281. * representing the WGS84 coordinate to be converted.
  2282. * @return {object} Object literal containing the UTM value with easting,
  2283. * northing, zoneNumber and zoneLetter properties, and an optional
  2284. * accuracy property in digits. Returns null if the conversion failed.
  2285. */
  2286. function LLtoUTM(ll) {
  2287. var Lat = ll.lat;
  2288. var Long = ll.lon;
  2289. var a = 6378137.0; //ellip.radius;
  2290. var eccSquared = 0.00669438; //ellip.eccsq;
  2291. var k0 = 0.9996;
  2292. var LongOrigin;
  2293. var eccPrimeSquared;
  2294. var N, T, C, A, M;
  2295. var LatRad = degToRad(Lat);
  2296. var LongRad = degToRad(Long);
  2297. var LongOriginRad;
  2298. var ZoneNumber;
  2299. // (int)
  2300. ZoneNumber = Math.floor((Long + 180) / 6) + 1;
  2301. //Make sure the longitude 180.00 is in Zone 60
  2302. if (Long === 180) {
  2303. ZoneNumber = 60;
  2304. }
  2305. // Special zone for Norway
  2306. if (Lat >= 56.0 && Lat < 64.0 && Long >= 3.0 && Long < 12.0) {
  2307. ZoneNumber = 32;
  2308. }
  2309. // Special zones for Svalbard
  2310. if (Lat >= 72.0 && Lat < 84.0) {
  2311. if (Long >= 0.0 && Long < 9.0) {
  2312. ZoneNumber = 31;
  2313. }
  2314. else if (Long >= 9.0 && Long < 21.0) {
  2315. ZoneNumber = 33;
  2316. }
  2317. else if (Long >= 21.0 && Long < 33.0) {
  2318. ZoneNumber = 35;
  2319. }
  2320. else if (Long >= 33.0 && Long < 42.0) {
  2321. ZoneNumber = 37;
  2322. }
  2323. }
  2324. LongOrigin = (ZoneNumber - 1) * 6 - 180 + 3; //+3 puts origin
  2325. // in middle of
  2326. // zone
  2327. LongOriginRad = degToRad(LongOrigin);
  2328. eccPrimeSquared = (eccSquared) / (1 - eccSquared);
  2329. N = a / Math.sqrt(1 - eccSquared * Math.sin(LatRad) * Math.sin(LatRad));
  2330. T = Math.tan(LatRad) * Math.tan(LatRad);
  2331. C = eccPrimeSquared * Math.cos(LatRad) * Math.cos(LatRad);
  2332. A = Math.cos(LatRad) * (LongRad - LongOriginRad);
  2333. 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));
  2334. 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);
  2335. 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)));
  2336. if (Lat < 0.0) {
  2337. UTMNorthing += 10000000.0; //10000000 meter offset for
  2338. // southern hemisphere
  2339. }
  2340. return {
  2341. northing: Math.round(UTMNorthing),
  2342. easting: Math.round(UTMEasting),
  2343. zoneNumber: ZoneNumber,
  2344. zoneLetter: getLetterDesignator(Lat)
  2345. };
  2346. }
  2347. /**
  2348. * Converts UTM coords to lat/long, using the WGS84 ellipsoid. This is a convenience
  2349. * class where the Zone can be specified as a single string eg."60N" which
  2350. * is then broken down into the ZoneNumber and ZoneLetter.
  2351. *
  2352. * @private
  2353. * @param {object} utm An object literal with northing, easting, zoneNumber
  2354. * and zoneLetter properties. If an optional accuracy property is
  2355. * provided (in meters), a bounding box will be returned instead of
  2356. * latitude and longitude.
  2357. * @return {object} An object literal containing either lat and lon values
  2358. * (if no accuracy was provided), or top, right, bottom and left values
  2359. * for the bounding box calculated according to the provided accuracy.
  2360. * Returns null if the conversion failed.
  2361. */
  2362. function UTMtoLL(utm) {
  2363. var UTMNorthing = utm.northing;
  2364. var UTMEasting = utm.easting;
  2365. var zoneLetter = utm.zoneLetter;
  2366. var zoneNumber = utm.zoneNumber;
  2367. // check the ZoneNummber is valid
  2368. if (zoneNumber < 0 || zoneNumber > 60) {
  2369. return null;
  2370. }
  2371. var k0 = 0.9996;
  2372. var a = 6378137.0; //ellip.radius;
  2373. var eccSquared = 0.00669438; //ellip.eccsq;
  2374. var eccPrimeSquared;
  2375. var e1 = (1 - Math.sqrt(1 - eccSquared)) / (1 + Math.sqrt(1 - eccSquared));
  2376. var N1, T1, C1, R1, D, M;
  2377. var LongOrigin;
  2378. var mu, phi1Rad;
  2379. // remove 500,000 meter offset for longitude
  2380. var x = UTMEasting - 500000.0;
  2381. var y = UTMNorthing;
  2382. // We must know somehow if we are in the Northern or Southern
  2383. // hemisphere, this is the only time we use the letter So even
  2384. // if the Zone letter isn't exactly correct it should indicate
  2385. // the hemisphere correctly
  2386. if (zoneLetter < 'N') {
  2387. y -= 10000000.0; // remove 10,000,000 meter offset used
  2388. // for southern hemisphere
  2389. }
  2390. // There are 60 zones with zone 1 being at West -180 to -174
  2391. LongOrigin = (zoneNumber - 1) * 6 - 180 + 3; // +3 puts origin
  2392. // in middle of
  2393. // zone
  2394. eccPrimeSquared = (eccSquared) / (1 - eccSquared);
  2395. M = y / k0;
  2396. mu = M / (a * (1 - eccSquared / 4 - 3 * eccSquared * eccSquared / 64 - 5 * eccSquared * eccSquared * eccSquared / 256));
  2397. 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);
  2398. // double phi1 = ProjMath.radToDeg(phi1Rad);
  2399. N1 = a / Math.sqrt(1 - eccSquared * Math.sin(phi1Rad) * Math.sin(phi1Rad));
  2400. T1 = Math.tan(phi1Rad) * Math.tan(phi1Rad);
  2401. C1 = eccPrimeSquared * Math.cos(phi1Rad) * Math.cos(phi1Rad);
  2402. R1 = a * (1 - eccSquared) / Math.pow(1 - eccSquared * Math.sin(phi1Rad) * Math.sin(phi1Rad), 1.5);
  2403. D = x / (N1 * k0);
  2404. 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);
  2405. lat = radToDeg(lat);
  2406. 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);
  2407. lon = LongOrigin + radToDeg(lon);
  2408. var result;
  2409. if (utm.accuracy) {
  2410. var topRight = UTMtoLL({
  2411. northing: utm.northing + utm.accuracy,
  2412. easting: utm.easting + utm.accuracy,
  2413. zoneLetter: utm.zoneLetter,
  2414. zoneNumber: utm.zoneNumber
  2415. });
  2416. result = {
  2417. top: topRight.lat,
  2418. right: topRight.lon,
  2419. bottom: lat,
  2420. left: lon
  2421. };
  2422. }
  2423. else {
  2424. result = {
  2425. lat: lat,
  2426. lon: lon
  2427. };
  2428. }
  2429. return result;
  2430. }
  2431. /**
  2432. * Calculates the MGRS letter designator for the given latitude.
  2433. *
  2434. * @private
  2435. * @param {number} lat The latitude in WGS84 to get the letter designator
  2436. * for.
  2437. * @return {char} The letter designator.
  2438. */
  2439. function getLetterDesignator(lat) {
  2440. //This is here as an error flag to show that the Latitude is
  2441. //outside MGRS limits
  2442. var LetterDesignator = 'Z';
  2443. if ((84 >= lat) && (lat >= 72)) {
  2444. LetterDesignator = 'X';
  2445. }
  2446. else if ((72 > lat) && (lat >= 64)) {
  2447. LetterDesignator = 'W';
  2448. }
  2449. else if ((64 > lat) && (lat >= 56)) {
  2450. LetterDesignator = 'V';
  2451. }
  2452. else if ((56 > lat) && (lat >= 48)) {
  2453. LetterDesignator = 'U';
  2454. }
  2455. else if ((48 > lat) && (lat >= 40)) {
  2456. LetterDesignator = 'T';
  2457. }
  2458. else if ((40 > lat) && (lat >= 32)) {
  2459. LetterDesignator = 'S';
  2460. }
  2461. else if ((32 > lat) && (lat >= 24)) {
  2462. LetterDesignator = 'R';
  2463. }
  2464. else if ((24 > lat) && (lat >= 16)) {
  2465. LetterDesignator = 'Q';
  2466. }
  2467. else if ((16 > lat) && (lat >= 8)) {
  2468. LetterDesignator = 'P';
  2469. }
  2470. else if ((8 > lat) && (lat >= 0)) {
  2471. LetterDesignator = 'N';
  2472. }
  2473. else if ((0 > lat) && (lat >= -8)) {
  2474. LetterDesignator = 'M';
  2475. }
  2476. else if ((-8 > lat) && (lat >= -16)) {
  2477. LetterDesignator = 'L';
  2478. }
  2479. else if ((-16 > lat) && (lat >= -24)) {
  2480. LetterDesignator = 'K';
  2481. }
  2482. else if ((-24 > lat) && (lat >= -32)) {
  2483. LetterDesignator = 'J';
  2484. }
  2485. else if ((-32 > lat) && (lat >= -40)) {
  2486. LetterDesignator = 'H';
  2487. }
  2488. else if ((-40 > lat) && (lat >= -48)) {
  2489. LetterDesignator = 'G';
  2490. }
  2491. else if ((-48 > lat) && (lat >= -56)) {
  2492. LetterDesignator = 'F';
  2493. }
  2494. else if ((-56 > lat) && (lat >= -64)) {
  2495. LetterDesignator = 'E';
  2496. }
  2497. else if ((-64 > lat) && (lat >= -72)) {
  2498. LetterDesignator = 'D';
  2499. }
  2500. else if ((-72 > lat) && (lat >= -80)) {
  2501. LetterDesignator = 'C';
  2502. }
  2503. return LetterDesignator;
  2504. }
  2505. /**
  2506. * Encodes a UTM location as MGRS string.
  2507. *
  2508. * @private
  2509. * @param {object} utm An object literal with easting, northing,
  2510. * zoneLetter, zoneNumber
  2511. * @param {number} accuracy Accuracy in digits (1-5).
  2512. * @return {string} MGRS string for the given UTM location.
  2513. */
  2514. function encode(utm, accuracy) {
  2515. // prepend with leading zeroes
  2516. var seasting = "00000" + utm.easting,
  2517. snorthing = "00000" + utm.northing;
  2518. return utm.zoneNumber + utm.zoneLetter + get100kID(utm.easting, utm.northing, utm.zoneNumber) + seasting.substr(seasting.length - 5, accuracy) + snorthing.substr(snorthing.length - 5, accuracy);
  2519. }
  2520. /**
  2521. * Get the two letter 100k designator for a given UTM easting,
  2522. * northing and zone number value.
  2523. *
  2524. * @private
  2525. * @param {number} easting
  2526. * @param {number} northing
  2527. * @param {number} zoneNumber
  2528. * @return the two letter 100k designator for the given UTM location.
  2529. */
  2530. function get100kID(easting, northing, zoneNumber) {
  2531. var setParm = get100kSetForZone(zoneNumber);
  2532. var setColumn = Math.floor(easting / 100000);
  2533. var setRow = Math.floor(northing / 100000) % 20;
  2534. return getLetter100kID(setColumn, setRow, setParm);
  2535. }
  2536. /**
  2537. * Given a UTM zone number, figure out the MGRS 100K set it is in.
  2538. *
  2539. * @private
  2540. * @param {number} i An UTM zone number.
  2541. * @return {number} the 100k set the UTM zone is in.
  2542. */
  2543. function get100kSetForZone(i) {
  2544. var setParm = i % NUM_100K_SETS;
  2545. if (setParm === 0) {
  2546. setParm = NUM_100K_SETS;
  2547. }
  2548. return setParm;
  2549. }
  2550. /**
  2551. * Get the two-letter MGRS 100k designator given information
  2552. * translated from the UTM northing, easting and zone number.
  2553. *
  2554. * @private
  2555. * @param {number} column the column index as it relates to the MGRS
  2556. * 100k set spreadsheet, created from the UTM easting.
  2557. * Values are 1-8.
  2558. * @param {number} row the row index as it relates to the MGRS 100k set
  2559. * spreadsheet, created from the UTM northing value. Values
  2560. * are from 0-19.
  2561. * @param {number} parm the set block, as it relates to the MGRS 100k set
  2562. * spreadsheet, created from the UTM zone. Values are from
  2563. * 1-60.
  2564. * @return two letter MGRS 100k code.
  2565. */
  2566. function getLetter100kID(column, row, parm) {
  2567. // colOrigin and rowOrigin are the letters at the origin of the set
  2568. var index = parm - 1;
  2569. var colOrigin = SET_ORIGIN_COLUMN_LETTERS.charCodeAt(index);
  2570. var rowOrigin = SET_ORIGIN_ROW_LETTERS.charCodeAt(index);
  2571. // colInt and rowInt are the letters to build to return
  2572. var colInt = colOrigin + column - 1;
  2573. var rowInt = rowOrigin + row;
  2574. var rollover = false;
  2575. if (colInt > Z) {
  2576. colInt = colInt - Z + A - 1;
  2577. rollover = true;
  2578. }
  2579. if (colInt === I || (colOrigin < I && colInt > I) || ((colInt > I || colOrigin < I) && rollover)) {
  2580. colInt++;
  2581. }
  2582. if (colInt === O || (colOrigin < O && colInt > O) || ((colInt > O || colOrigin < O) && rollover)) {
  2583. colInt++;
  2584. if (colInt === I) {
  2585. colInt++;
  2586. }
  2587. }
  2588. if (colInt > Z) {
  2589. colInt = colInt - Z + A - 1;
  2590. }
  2591. if (rowInt > V) {
  2592. rowInt = rowInt - V + A - 1;
  2593. rollover = true;
  2594. }
  2595. else {
  2596. rollover = false;
  2597. }
  2598. if (((rowInt === I) || ((rowOrigin < I) && (rowInt > I))) || (((rowInt > I) || (rowOrigin < I)) && rollover)) {
  2599. rowInt++;
  2600. }
  2601. if (((rowInt === O) || ((rowOrigin < O) && (rowInt > O))) || (((rowInt > O) || (rowOrigin < O)) && rollover)) {
  2602. rowInt++;
  2603. if (rowInt === I) {
  2604. rowInt++;
  2605. }
  2606. }
  2607. if (rowInt > V) {
  2608. rowInt = rowInt - V + A - 1;
  2609. }
  2610. var twoLetter = String.fromCharCode(colInt) + String.fromCharCode(rowInt);
  2611. return twoLetter;
  2612. }
  2613. /**
  2614. * Decode the UTM parameters from a MGRS string.
  2615. *
  2616. * @private
  2617. * @param {string} mgrsString an UPPERCASE coordinate string is expected.
  2618. * @return {object} An object literal with easting, northing, zoneLetter,
  2619. * zoneNumber and accuracy (in meters) properties.
  2620. */
  2621. function decode(mgrsString) {
  2622. if (mgrsString && mgrsString.length === 0) {
  2623. throw ("MGRSPoint coverting from nothing");
  2624. }
  2625. var length = mgrsString.length;
  2626. var hunK = null;
  2627. var sb = "";
  2628. var testChar;
  2629. var i = 0;
  2630. // get Zone number
  2631. while (!(/[A-Z]/).test(testChar = mgrsString.charAt(i))) {
  2632. if (i >= 2) {
  2633. throw ("MGRSPoint bad conversion from: " + mgrsString);
  2634. }
  2635. sb += testChar;
  2636. i++;
  2637. }
  2638. var zoneNumber = parseInt(sb, 10);
  2639. if (i === 0 || i + 3 > length) {
  2640. // A good MGRS string has to be 4-5 digits long,
  2641. // ##AAA/#AAA at least.
  2642. throw ("MGRSPoint bad conversion from: " + mgrsString);
  2643. }
  2644. var zoneLetter = mgrsString.charAt(i++);
  2645. // Should we check the zone letter here? Why not.
  2646. if (zoneLetter <= 'A' || zoneLetter === 'B' || zoneLetter === 'Y' || zoneLetter >= 'Z' || zoneLetter === 'I' || zoneLetter === 'O') {
  2647. throw ("MGRSPoint zone letter " + zoneLetter + " not handled: " + mgrsString);
  2648. }
  2649. hunK = mgrsString.substring(i, i += 2);
  2650. var set = get100kSetForZone(zoneNumber);
  2651. var east100k = getEastingFromChar(hunK.charAt(0), set);
  2652. var north100k = getNorthingFromChar(hunK.charAt(1), set);
  2653. // We have a bug where the northing may be 2000000 too low.
  2654. // How
  2655. // do we know when to roll over?
  2656. while (north100k < getMinNorthing(zoneLetter)) {
  2657. north100k += 2000000;
  2658. }
  2659. // calculate the char index for easting/northing separator
  2660. var remainder = length - i;
  2661. if (remainder % 2 !== 0) {
  2662. 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);
  2663. }
  2664. var sep = remainder / 2;
  2665. var sepEasting = 0.0;
  2666. var sepNorthing = 0.0;
  2667. var accuracyBonus, sepEastingString, sepNorthingString, easting, northing;
  2668. if (sep > 0) {
  2669. accuracyBonus = 100000.0 / Math.pow(10, sep);
  2670. sepEastingString = mgrsString.substring(i, i + sep);
  2671. sepEasting = parseFloat(sepEastingString) * accuracyBonus;
  2672. sepNorthingString = mgrsString.substring(i + sep);
  2673. sepNorthing = parseFloat(sepNorthingString) * accuracyBonus;
  2674. }
  2675. easting = sepEasting + east100k;
  2676. northing = sepNorthing + north100k;
  2677. return {
  2678. easting: easting,
  2679. northing: northing,
  2680. zoneLetter: zoneLetter,
  2681. zoneNumber: zoneNumber,
  2682. accuracy: accuracyBonus
  2683. };
  2684. }
  2685. /**
  2686. * Given the first letter from a two-letter MGRS 100k zone, and given the
  2687. * MGRS table set for the zone number, figure out the easting value that
  2688. * should be added to the other, secondary easting value.
  2689. *
  2690. * @private
  2691. * @param {char} e The first letter from a two-letter MGRS 100´k zone.
  2692. * @param {number} set The MGRS table set for the zone number.
  2693. * @return {number} The easting value for the given letter and set.
  2694. */
  2695. function getEastingFromChar(e, set) {
  2696. // colOrigin is the letter at the origin of the set for the
  2697. // column
  2698. var curCol = SET_ORIGIN_COLUMN_LETTERS.charCodeAt(set - 1);
  2699. var eastingValue = 100000.0;
  2700. var rewindMarker = false;
  2701. while (curCol !== e.charCodeAt(0)) {
  2702. curCol++;
  2703. if (curCol === I) {
  2704. curCol++;
  2705. }
  2706. if (curCol === O) {
  2707. curCol++;
  2708. }
  2709. if (curCol > Z) {
  2710. if (rewindMarker) {
  2711. throw ("Bad character: " + e);
  2712. }
  2713. curCol = A;
  2714. rewindMarker = true;
  2715. }
  2716. eastingValue += 100000.0;
  2717. }
  2718. return eastingValue;
  2719. }
  2720. /**
  2721. * Given the second letter from a two-letter MGRS 100k zone, and given the
  2722. * MGRS table set for the zone number, figure out the northing value that
  2723. * should be added to the other, secondary northing value. You have to
  2724. * remember that Northings are determined from the equator, and the vertical
  2725. * cycle of letters mean a 2000000 additional northing meters. This happens
  2726. * approx. every 18 degrees of latitude. This method does *NOT* count any
  2727. * additional northings. You have to figure out how many 2000000 meters need
  2728. * to be added for the zone letter of the MGRS coordinate.
  2729. *
  2730. * @private
  2731. * @param {char} n Second letter of the MGRS 100k zone
  2732. * @param {number} set The MGRS table set number, which is dependent on the
  2733. * UTM zone number.
  2734. * @return {number} The northing value for the given letter and set.
  2735. */
  2736. function getNorthingFromChar(n, set) {
  2737. if (n > 'V') {
  2738. throw ("MGRSPoint given invalid Northing " + n);
  2739. }
  2740. // rowOrigin is the letter at the origin of the set for the
  2741. // column
  2742. var curRow = SET_ORIGIN_ROW_LETTERS.charCodeAt(set - 1);
  2743. var northingValue = 0.0;
  2744. var rewindMarker = false;
  2745. while (curRow !== n.charCodeAt(0)) {
  2746. curRow++;
  2747. if (curRow === I) {
  2748. curRow++;
  2749. }
  2750. if (curRow === O) {
  2751. curRow++;
  2752. }
  2753. // fixing a bug making whole application hang in this loop
  2754. // when 'n' is a wrong character
  2755. if (curRow > V) {
  2756. if (rewindMarker) { // making sure that this loop ends
  2757. throw ("Bad character: " + n);
  2758. }
  2759. curRow = A;
  2760. rewindMarker = true;
  2761. }
  2762. northingValue += 100000.0;
  2763. }
  2764. return northingValue;
  2765. }
  2766. /**
  2767. * The function getMinNorthing returns the minimum northing value of a MGRS
  2768. * zone.
  2769. *
  2770. * Ported from Geotrans' c Lattitude_Band_Value structure table.
  2771. *
  2772. * @private
  2773. * @param {char} zoneLetter The MGRS zone to get the min northing for.
  2774. * @return {number}
  2775. */
  2776. function getMinNorthing(zoneLetter) {
  2777. var northing;
  2778. switch (zoneLetter) {
  2779. case 'C':
  2780. northing = 1100000.0;
  2781. break;
  2782. case 'D':
  2783. northing = 2000000.0;
  2784. break;
  2785. case 'E':
  2786. northing = 2800000.0;
  2787. break;
  2788. case 'F':
  2789. northing = 3700000.0;
  2790. break;
  2791. case 'G':
  2792. northing = 4600000.0;
  2793. break;
  2794. case 'H':
  2795. northing = 5500000.0;
  2796. break;
  2797. case 'J':
  2798. northing = 6400000.0;
  2799. break;
  2800. case 'K':
  2801. northing = 7300000.0;
  2802. break;
  2803. case 'L':
  2804. northing = 8200000.0;
  2805. break;
  2806. case 'M':
  2807. northing = 9100000.0;
  2808. break;
  2809. case 'N':
  2810. northing = 0.0;
  2811. break;
  2812. case 'P':
  2813. northing = 800000.0;
  2814. break;
  2815. case 'Q':
  2816. northing = 1700000.0;
  2817. break;
  2818. case 'R':
  2819. northing = 2600000.0;
  2820. break;
  2821. case 'S':
  2822. northing = 3500000.0;
  2823. break;
  2824. case 'T':
  2825. northing = 4400000.0;
  2826. break;
  2827. case 'U':
  2828. northing = 5300000.0;
  2829. break;
  2830. case 'V':
  2831. northing = 6200000.0;
  2832. break;
  2833. case 'W':
  2834. northing = 7000000.0;
  2835. break;
  2836. case 'X':
  2837. northing = 7900000.0;
  2838. break;
  2839. default:
  2840. northing = -1.0;
  2841. }
  2842. if (northing >= 0.0) {
  2843. return northing;
  2844. }
  2845. else {
  2846. throw ("Invalid zone letter: " + zoneLetter);
  2847. }
  2848. }
  2849. function Point(x, y, z) {
  2850. if (!(this instanceof Point)) {
  2851. return new Point(x, y, z);
  2852. }
  2853. if (Array.isArray(x)) {
  2854. this.x = x[0];
  2855. this.y = x[1];
  2856. this.z = x[2] || 0.0;
  2857. } else if(typeof x === 'object') {
  2858. this.x = x.x;
  2859. this.y = x.y;
  2860. this.z = x.z || 0.0;
  2861. } else if (typeof x === 'string' && typeof y === 'undefined') {
  2862. var coords = x.split(',');
  2863. this.x = parseFloat(coords[0], 10);
  2864. this.y = parseFloat(coords[1], 10);
  2865. this.z = parseFloat(coords[2], 10) || 0.0;
  2866. } else {
  2867. this.x = x;
  2868. this.y = y;
  2869. this.z = z || 0.0;
  2870. }
  2871. console.warn('proj4.Point will be removed in version 3, use proj4.toPoint');
  2872. }
  2873. Point.fromMGRS = function(mgrsStr) {
  2874. return new Point(toPoint(mgrsStr));
  2875. };
  2876. Point.prototype.toMGRS = function(accuracy) {
  2877. return forward$t([this.x, this.y], accuracy);
  2878. };
  2879. var C00 = 1;
  2880. var C02 = 0.25;
  2881. var C04 = 0.046875;
  2882. var C06 = 0.01953125;
  2883. var C08 = 0.01068115234375;
  2884. var C22 = 0.75;
  2885. var C44 = 0.46875;
  2886. var C46 = 0.01302083333333333333;
  2887. var C48 = 0.00712076822916666666;
  2888. var C66 = 0.36458333333333333333;
  2889. var C68 = 0.00569661458333333333;
  2890. var C88 = 0.3076171875;
  2891. function pj_enfn(es) {
  2892. var en = [];
  2893. en[0] = C00 - es * (C02 + es * (C04 + es * (C06 + es * C08)));
  2894. en[1] = es * (C22 - es * (C04 + es * (C06 + es * C08)));
  2895. var t = es * es;
  2896. en[2] = t * (C44 - es * (C46 + es * C48));
  2897. t *= es;
  2898. en[3] = t * (C66 - es * C68);
  2899. en[4] = t * es * C88;
  2900. return en;
  2901. }
  2902. function pj_mlfn(phi, sphi, cphi, en) {
  2903. cphi *= sphi;
  2904. sphi *= sphi;
  2905. return (en[0] * phi - cphi * (en[1] + sphi * (en[2] + sphi * (en[3] + sphi * en[4]))));
  2906. }
  2907. var MAX_ITER$3 = 20;
  2908. function pj_inv_mlfn(arg, es, en) {
  2909. var k = 1 / (1 - es);
  2910. var phi = arg;
  2911. for (var i = MAX_ITER$3; i; --i) { /* rarely goes over 2 iterations */
  2912. var s = Math.sin(phi);
  2913. var t = 1 - es * s * s;
  2914. //t = this.pj_mlfn(phi, s, Math.cos(phi), en) - arg;
  2915. //phi -= t * (t * Math.sqrt(t)) * k;
  2916. t = (pj_mlfn(phi, s, Math.cos(phi), en) - arg) * (t * Math.sqrt(t)) * k;
  2917. phi -= t;
  2918. if (Math.abs(t) < EPSLN) {
  2919. return phi;
  2920. }
  2921. }
  2922. //..reportError("cass:pj_inv_mlfn: Convergence error");
  2923. return phi;
  2924. }
  2925. // Heavily based on this tmerc projection implementation
  2926. // https://github.com/mbloch/mapshaper-proj/blob/master/src/projections/tmerc.js
  2927. function init$u() {
  2928. this.x0 = this.x0 !== undefined ? this.x0 : 0;
  2929. this.y0 = this.y0 !== undefined ? this.y0 : 0;
  2930. this.long0 = this.long0 !== undefined ? this.long0 : 0;
  2931. this.lat0 = this.lat0 !== undefined ? this.lat0 : 0;
  2932. if (this.es) {
  2933. this.en = pj_enfn(this.es);
  2934. this.ml0 = pj_mlfn(this.lat0, Math.sin(this.lat0), Math.cos(this.lat0), this.en);
  2935. }
  2936. }
  2937. /**
  2938. Transverse Mercator Forward - long/lat to x/y
  2939. long/lat in radians
  2940. */
  2941. function forward$s(p) {
  2942. var lon = p.x;
  2943. var lat = p.y;
  2944. var delta_lon = adjust_lon(lon - this.long0);
  2945. var con;
  2946. var x, y;
  2947. var sin_phi = Math.sin(lat);
  2948. var cos_phi = Math.cos(lat);
  2949. if (!this.es) {
  2950. var b = cos_phi * Math.sin(delta_lon);
  2951. if ((Math.abs(Math.abs(b) - 1)) < EPSLN) {
  2952. return (93);
  2953. }
  2954. else {
  2955. x = 0.5 * this.a * this.k0 * Math.log((1 + b) / (1 - b)) + this.x0;
  2956. y = cos_phi * Math.cos(delta_lon) / Math.sqrt(1 - Math.pow(b, 2));
  2957. b = Math.abs(y);
  2958. if (b >= 1) {
  2959. if ((b - 1) > EPSLN) {
  2960. return (93);
  2961. }
  2962. else {
  2963. y = 0;
  2964. }
  2965. }
  2966. else {
  2967. y = Math.acos(y);
  2968. }
  2969. if (lat < 0) {
  2970. y = -y;
  2971. }
  2972. y = this.a * this.k0 * (y - this.lat0) + this.y0;
  2973. }
  2974. }
  2975. else {
  2976. var al = cos_phi * delta_lon;
  2977. var als = Math.pow(al, 2);
  2978. var c = this.ep2 * Math.pow(cos_phi, 2);
  2979. var cs = Math.pow(c, 2);
  2980. var tq = Math.abs(cos_phi) > EPSLN ? Math.tan(lat) : 0;
  2981. var t = Math.pow(tq, 2);
  2982. var ts = Math.pow(t, 2);
  2983. con = 1 - this.es * Math.pow(sin_phi, 2);
  2984. al = al / Math.sqrt(con);
  2985. var ml = pj_mlfn(lat, sin_phi, cos_phi, this.en);
  2986. x = this.a * (this.k0 * al * (1 +
  2987. als / 6 * (1 - t + c +
  2988. als / 20 * (5 - 18 * t + ts + 14 * c - 58 * t * c +
  2989. als / 42 * (61 + 179 * ts - ts * t - 479 * t))))) +
  2990. this.x0;
  2991. y = this.a * (this.k0 * (ml - this.ml0 +
  2992. sin_phi * delta_lon * al / 2 * (1 +
  2993. als / 12 * (5 - t + 9 * c + 4 * cs +
  2994. als / 30 * (61 + ts - 58 * t + 270 * c - 330 * t * c +
  2995. als / 56 * (1385 + 543 * ts - ts * t - 3111 * t)))))) +
  2996. this.y0;
  2997. }
  2998. p.x = x;
  2999. p.y = y;
  3000. return p;
  3001. }
  3002. /**
  3003. Transverse Mercator Inverse - x/y to long/lat
  3004. */
  3005. function inverse$s(p) {
  3006. var con, phi;
  3007. var lat, lon;
  3008. var x = (p.x - this.x0) * (1 / this.a);
  3009. var y = (p.y - this.y0) * (1 / this.a);
  3010. if (!this.es) {
  3011. var f = Math.exp(x / this.k0);
  3012. var g = 0.5 * (f - 1 / f);
  3013. var temp = this.lat0 + y / this.k0;
  3014. var h = Math.cos(temp);
  3015. con = Math.sqrt((1 - Math.pow(h, 2)) / (1 + Math.pow(g, 2)));
  3016. lat = Math.asin(con);
  3017. if (y < 0) {
  3018. lat = -lat;
  3019. }
  3020. if ((g === 0) && (h === 0)) {
  3021. lon = 0;
  3022. }
  3023. else {
  3024. lon = adjust_lon(Math.atan2(g, h) + this.long0);
  3025. }
  3026. }
  3027. else { // ellipsoidal form
  3028. con = this.ml0 + y / this.k0;
  3029. phi = pj_inv_mlfn(con, this.es, this.en);
  3030. if (Math.abs(phi) < HALF_PI) {
  3031. var sin_phi = Math.sin(phi);
  3032. var cos_phi = Math.cos(phi);
  3033. var tan_phi = Math.abs(cos_phi) > EPSLN ? Math.tan(phi) : 0;
  3034. var c = this.ep2 * Math.pow(cos_phi, 2);
  3035. var cs = Math.pow(c, 2);
  3036. var t = Math.pow(tan_phi, 2);
  3037. var ts = Math.pow(t, 2);
  3038. con = 1 - this.es * Math.pow(sin_phi, 2);
  3039. var d = x * Math.sqrt(con) / this.k0;
  3040. var ds = Math.pow(d, 2);
  3041. con = con * tan_phi;
  3042. lat = phi - (con * ds / (1 - this.es)) * 0.5 * (1 -
  3043. ds / 12 * (5 + 3 * t - 9 * c * t + c - 4 * cs -
  3044. ds / 30 * (61 + 90 * t - 252 * c * t + 45 * ts + 46 * c -
  3045. ds / 56 * (1385 + 3633 * t + 4095 * ts + 1574 * ts * t))));
  3046. lon = adjust_lon(this.long0 + (d * (1 -
  3047. ds / 6 * (1 + 2 * t + c -
  3048. ds / 20 * (5 + 28 * t + 24 * ts + 8 * c * t + 6 * c -
  3049. ds / 42 * (61 + 662 * t + 1320 * ts + 720 * ts * t)))) / cos_phi));
  3050. }
  3051. else {
  3052. lat = HALF_PI * sign(y);
  3053. lon = 0;
  3054. }
  3055. }
  3056. p.x = lon;
  3057. p.y = lat;
  3058. return p;
  3059. }
  3060. var names$t = ["Fast_Transverse_Mercator", "Fast Transverse Mercator"];
  3061. var tmerc = {
  3062. init: init$u,
  3063. forward: forward$s,
  3064. inverse: inverse$s,
  3065. names: names$t
  3066. };
  3067. function sinh(x) {
  3068. var r = Math.exp(x);
  3069. r = (r - 1 / r) / 2;
  3070. return r;
  3071. }
  3072. function hypot(x, y) {
  3073. x = Math.abs(x);
  3074. y = Math.abs(y);
  3075. var a = Math.max(x, y);
  3076. var b = Math.min(x, y) / (a ? a : 1);
  3077. return a * Math.sqrt(1 + Math.pow(b, 2));
  3078. }
  3079. function log1py(x) {
  3080. var y = 1 + x;
  3081. var z = y - 1;
  3082. return z === 0 ? x : x * Math.log(y) / z;
  3083. }
  3084. function asinhy(x) {
  3085. var y = Math.abs(x);
  3086. y = log1py(y * (1 + y / (hypot(1, y) + 1)));
  3087. return x < 0 ? -y : y;
  3088. }
  3089. function gatg(pp, B) {
  3090. var cos_2B = 2 * Math.cos(2 * B);
  3091. var i = pp.length - 1;
  3092. var h1 = pp[i];
  3093. var h2 = 0;
  3094. var h;
  3095. while (--i >= 0) {
  3096. h = -h2 + cos_2B * h1 + pp[i];
  3097. h2 = h1;
  3098. h1 = h;
  3099. }
  3100. return (B + h * Math.sin(2 * B));
  3101. }
  3102. function clens(pp, arg_r) {
  3103. var r = 2 * Math.cos(arg_r);
  3104. var i = pp.length - 1;
  3105. var hr1 = pp[i];
  3106. var hr2 = 0;
  3107. var hr;
  3108. while (--i >= 0) {
  3109. hr = -hr2 + r * hr1 + pp[i];
  3110. hr2 = hr1;
  3111. hr1 = hr;
  3112. }
  3113. return Math.sin(arg_r) * hr;
  3114. }
  3115. function cosh(x) {
  3116. var r = Math.exp(x);
  3117. r = (r + 1 / r) / 2;
  3118. return r;
  3119. }
  3120. function clens_cmplx(pp, arg_r, arg_i) {
  3121. var sin_arg_r = Math.sin(arg_r);
  3122. var cos_arg_r = Math.cos(arg_r);
  3123. var sinh_arg_i = sinh(arg_i);
  3124. var cosh_arg_i = cosh(arg_i);
  3125. var r = 2 * cos_arg_r * cosh_arg_i;
  3126. var i = -2 * sin_arg_r * sinh_arg_i;
  3127. var j = pp.length - 1;
  3128. var hr = pp[j];
  3129. var hi1 = 0;
  3130. var hr1 = 0;
  3131. var hi = 0;
  3132. var hr2;
  3133. var hi2;
  3134. while (--j >= 0) {
  3135. hr2 = hr1;
  3136. hi2 = hi1;
  3137. hr1 = hr;
  3138. hi1 = hi;
  3139. hr = -hr2 + r * hr1 - i * hi1 + pp[j];
  3140. hi = -hi2 + i * hr1 + r * hi1;
  3141. }
  3142. r = sin_arg_r * cosh_arg_i;
  3143. i = cos_arg_r * sinh_arg_i;
  3144. return [r * hr - i * hi, r * hi + i * hr];
  3145. }
  3146. // Heavily based on this etmerc projection implementation
  3147. // https://github.com/mbloch/mapshaper-proj/blob/master/src/projections/etmerc.js
  3148. function init$t() {
  3149. if (!this.approx && (isNaN(this.es) || this.es <= 0)) {
  3150. throw new Error('Incorrect elliptical usage. Try using the +approx option in the proj string, or PROJECTION["Fast_Transverse_Mercator"] in the WKT.');
  3151. }
  3152. if (this.approx) {
  3153. // When '+approx' is set, use tmerc instead
  3154. tmerc.init.apply(this);
  3155. this.forward = tmerc.forward;
  3156. this.inverse = tmerc.inverse;
  3157. }
  3158. this.x0 = this.x0 !== undefined ? this.x0 : 0;
  3159. this.y0 = this.y0 !== undefined ? this.y0 : 0;
  3160. this.long0 = this.long0 !== undefined ? this.long0 : 0;
  3161. this.lat0 = this.lat0 !== undefined ? this.lat0 : 0;
  3162. this.cgb = [];
  3163. this.cbg = [];
  3164. this.utg = [];
  3165. this.gtu = [];
  3166. var f = this.es / (1 + Math.sqrt(1 - this.es));
  3167. var n = f / (2 - f);
  3168. var np = n;
  3169. this.cgb[0] = n * (2 + n * (-2 / 3 + n * (-2 + n * (116 / 45 + n * (26 / 45 + n * (-2854 / 675 ))))));
  3170. this.cbg[0] = n * (-2 + n * ( 2 / 3 + n * ( 4 / 3 + n * (-82 / 45 + n * (32 / 45 + n * (4642 / 4725))))));
  3171. np = np * n;
  3172. this.cgb[1] = np * (7 / 3 + n * (-8 / 5 + n * (-227 / 45 + n * (2704 / 315 + n * (2323 / 945)))));
  3173. this.cbg[1] = np * (5 / 3 + n * (-16 / 15 + n * ( -13 / 9 + n * (904 / 315 + n * (-1522 / 945)))));
  3174. np = np * n;
  3175. this.cgb[2] = np * (56 / 15 + n * (-136 / 35 + n * (-1262 / 105 + n * (73814 / 2835))));
  3176. this.cbg[2] = np * (-26 / 15 + n * (34 / 21 + n * (8 / 5 + n * (-12686 / 2835))));
  3177. np = np * n;
  3178. this.cgb[3] = np * (4279 / 630 + n * (-332 / 35 + n * (-399572 / 14175)));
  3179. this.cbg[3] = np * (1237 / 630 + n * (-12 / 5 + n * ( -24832 / 14175)));
  3180. np = np * n;
  3181. this.cgb[4] = np * (4174 / 315 + n * (-144838 / 6237));
  3182. this.cbg[4] = np * (-734 / 315 + n * (109598 / 31185));
  3183. np = np * n;
  3184. this.cgb[5] = np * (601676 / 22275);
  3185. this.cbg[5] = np * (444337 / 155925);
  3186. np = Math.pow(n, 2);
  3187. this.Qn = this.k0 / (1 + n) * (1 + np * (1 / 4 + np * (1 / 64 + np / 256)));
  3188. this.utg[0] = n * (-0.5 + n * ( 2 / 3 + n * (-37 / 96 + n * ( 1 / 360 + n * (81 / 512 + n * (-96199 / 604800))))));
  3189. this.gtu[0] = n * (0.5 + n * (-2 / 3 + n * (5 / 16 + n * (41 / 180 + n * (-127 / 288 + n * (7891 / 37800))))));
  3190. this.utg[1] = np * (-1 / 48 + n * (-1 / 15 + n * (437 / 1440 + n * (-46 / 105 + n * (1118711 / 3870720)))));
  3191. this.gtu[1] = np * (13 / 48 + n * (-3 / 5 + n * (557 / 1440 + n * (281 / 630 + n * (-1983433 / 1935360)))));
  3192. np = np * n;
  3193. this.utg[2] = np * (-17 / 480 + n * (37 / 840 + n * (209 / 4480 + n * (-5569 / 90720 ))));
  3194. this.gtu[2] = np * (61 / 240 + n * (-103 / 140 + n * (15061 / 26880 + n * (167603 / 181440))));
  3195. np = np * n;
  3196. this.utg[3] = np * (-4397 / 161280 + n * (11 / 504 + n * (830251 / 7257600)));
  3197. this.gtu[3] = np * (49561 / 161280 + n * (-179 / 168 + n * (6601661 / 7257600)));
  3198. np = np * n;
  3199. this.utg[4] = np * (-4583 / 161280 + n * (108847 / 3991680));
  3200. this.gtu[4] = np * (34729 / 80640 + n * (-3418889 / 1995840));
  3201. np = np * n;
  3202. this.utg[5] = np * (-20648693 / 638668800);
  3203. this.gtu[5] = np * (212378941 / 319334400);
  3204. var Z = gatg(this.cbg, this.lat0);
  3205. this.Zb = -this.Qn * (Z + clens(this.gtu, 2 * Z));
  3206. }
  3207. function forward$r(p) {
  3208. var Ce = adjust_lon(p.x - this.long0);
  3209. var Cn = p.y;
  3210. Cn = gatg(this.cbg, Cn);
  3211. var sin_Cn = Math.sin(Cn);
  3212. var cos_Cn = Math.cos(Cn);
  3213. var sin_Ce = Math.sin(Ce);
  3214. var cos_Ce = Math.cos(Ce);
  3215. Cn = Math.atan2(sin_Cn, cos_Ce * cos_Cn);
  3216. Ce = Math.atan2(sin_Ce * cos_Cn, hypot(sin_Cn, cos_Cn * cos_Ce));
  3217. Ce = asinhy(Math.tan(Ce));
  3218. var tmp = clens_cmplx(this.gtu, 2 * Cn, 2 * Ce);
  3219. Cn = Cn + tmp[0];
  3220. Ce = Ce + tmp[1];
  3221. var x;
  3222. var y;
  3223. if (Math.abs(Ce) <= 2.623395162778) {
  3224. x = this.a * (this.Qn * Ce) + this.x0;
  3225. y = this.a * (this.Qn * Cn + this.Zb) + this.y0;
  3226. }
  3227. else {
  3228. x = Infinity;
  3229. y = Infinity;
  3230. }
  3231. p.x = x;
  3232. p.y = y;
  3233. return p;
  3234. }
  3235. function inverse$r(p) {
  3236. var Ce = (p.x - this.x0) * (1 / this.a);
  3237. var Cn = (p.y - this.y0) * (1 / this.a);
  3238. Cn = (Cn - this.Zb) / this.Qn;
  3239. Ce = Ce / this.Qn;
  3240. var lon;
  3241. var lat;
  3242. if (Math.abs(Ce) <= 2.623395162778) {
  3243. var tmp = clens_cmplx(this.utg, 2 * Cn, 2 * Ce);
  3244. Cn = Cn + tmp[0];
  3245. Ce = Ce + tmp[1];
  3246. Ce = Math.atan(sinh(Ce));
  3247. var sin_Cn = Math.sin(Cn);
  3248. var cos_Cn = Math.cos(Cn);
  3249. var sin_Ce = Math.sin(Ce);
  3250. var cos_Ce = Math.cos(Ce);
  3251. Cn = Math.atan2(sin_Cn * cos_Ce, hypot(sin_Ce, cos_Ce * cos_Cn));
  3252. Ce = Math.atan2(sin_Ce, cos_Ce * cos_Cn);
  3253. lon = adjust_lon(Ce + this.long0);
  3254. lat = gatg(this.cgb, Cn);
  3255. }
  3256. else {
  3257. lon = Infinity;
  3258. lat = Infinity;
  3259. }
  3260. p.x = lon;
  3261. p.y = lat;
  3262. return p;
  3263. }
  3264. var names$s = ["Extended_Transverse_Mercator", "Extended Transverse Mercator", "etmerc", "Transverse_Mercator", "Transverse Mercator", "Gauss Kruger", "Gauss_Kruger", "tmerc"];
  3265. var etmerc = {
  3266. init: init$t,
  3267. forward: forward$r,
  3268. inverse: inverse$r,
  3269. names: names$s
  3270. };
  3271. function adjust_zone(zone, lon) {
  3272. if (zone === undefined) {
  3273. zone = Math.floor((adjust_lon(lon) + Math.PI) * 30 / Math.PI) + 1;
  3274. if (zone < 0) {
  3275. return 0;
  3276. } else if (zone > 60) {
  3277. return 60;
  3278. }
  3279. }
  3280. return zone;
  3281. }
  3282. var dependsOn = 'etmerc';
  3283. function init$s() {
  3284. var zone = adjust_zone(this.zone, this.long0);
  3285. if (zone === undefined) {
  3286. throw new Error('unknown utm zone');
  3287. }
  3288. this.lat0 = 0;
  3289. this.long0 = ((6 * Math.abs(zone)) - 183) * D2R$1;
  3290. this.x0 = 500000;
  3291. this.y0 = this.utmSouth ? 10000000 : 0;
  3292. this.k0 = 0.9996;
  3293. etmerc.init.apply(this);
  3294. this.forward = etmerc.forward;
  3295. this.inverse = etmerc.inverse;
  3296. }
  3297. var names$r = ["Universal Transverse Mercator System", "utm"];
  3298. var utm = {
  3299. init: init$s,
  3300. names: names$r,
  3301. dependsOn: dependsOn
  3302. };
  3303. function srat(esinp, exp) {
  3304. return (Math.pow((1 - esinp) / (1 + esinp), exp));
  3305. }
  3306. var MAX_ITER$2 = 20;
  3307. function init$r() {
  3308. var sphi = Math.sin(this.lat0);
  3309. var cphi = Math.cos(this.lat0);
  3310. cphi *= cphi;
  3311. this.rc = Math.sqrt(1 - this.es) / (1 - this.es * sphi * sphi);
  3312. this.C = Math.sqrt(1 + this.es * cphi * cphi / (1 - this.es));
  3313. this.phic0 = Math.asin(sphi / this.C);
  3314. this.ratexp = 0.5 * this.C * this.e;
  3315. 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));
  3316. }
  3317. function forward$q(p) {
  3318. var lon = p.x;
  3319. var lat = p.y;
  3320. 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;
  3321. p.x = this.C * lon;
  3322. return p;
  3323. }
  3324. function inverse$q(p) {
  3325. var DEL_TOL = 1e-14;
  3326. var lon = p.x / this.C;
  3327. var lat = p.y;
  3328. var num = Math.pow(Math.tan(0.5 * lat + FORTPI) / this.K, 1 / this.C);
  3329. for (var i = MAX_ITER$2; i > 0; --i) {
  3330. lat = 2 * Math.atan(num * srat(this.e * Math.sin(p.y), - 0.5 * this.e)) - HALF_PI;
  3331. if (Math.abs(lat - p.y) < DEL_TOL) {
  3332. break;
  3333. }
  3334. p.y = lat;
  3335. }
  3336. /* convergence failed */
  3337. if (!i) {
  3338. return null;
  3339. }
  3340. p.x = lon;
  3341. p.y = lat;
  3342. return p;
  3343. }
  3344. var names$q = ["gauss"];
  3345. var gauss = {
  3346. init: init$r,
  3347. forward: forward$q,
  3348. inverse: inverse$q,
  3349. names: names$q
  3350. };
  3351. function init$q() {
  3352. gauss.init.apply(this);
  3353. if (!this.rc) {
  3354. return;
  3355. }
  3356. this.sinc0 = Math.sin(this.phic0);
  3357. this.cosc0 = Math.cos(this.phic0);
  3358. this.R2 = 2 * this.rc;
  3359. if (!this.title) {
  3360. this.title = "Oblique Stereographic Alternative";
  3361. }
  3362. }
  3363. function forward$p(p) {
  3364. var sinc, cosc, cosl, k;
  3365. p.x = adjust_lon(p.x - this.long0);
  3366. gauss.forward.apply(this, [p]);
  3367. sinc = Math.sin(p.y);
  3368. cosc = Math.cos(p.y);
  3369. cosl = Math.cos(p.x);
  3370. k = this.k0 * this.R2 / (1 + this.sinc0 * sinc + this.cosc0 * cosc * cosl);
  3371. p.x = k * cosc * Math.sin(p.x);
  3372. p.y = k * (this.cosc0 * sinc - this.sinc0 * cosc * cosl);
  3373. p.x = this.a * p.x + this.x0;
  3374. p.y = this.a * p.y + this.y0;
  3375. return p;
  3376. }
  3377. function inverse$p(p) {
  3378. var sinc, cosc, lon, lat, rho;
  3379. p.x = (p.x - this.x0) / this.a;
  3380. p.y = (p.y - this.y0) / this.a;
  3381. p.x /= this.k0;
  3382. p.y /= this.k0;
  3383. if ((rho = hypot(p.x, p.y))) {
  3384. var c = 2 * Math.atan2(rho, this.R2);
  3385. sinc = Math.sin(c);
  3386. cosc = Math.cos(c);
  3387. lat = Math.asin(cosc * this.sinc0 + p.y * sinc * this.cosc0 / rho);
  3388. lon = Math.atan2(p.x * sinc, rho * this.cosc0 * cosc - p.y * this.sinc0 * sinc);
  3389. }
  3390. else {
  3391. lat = this.phic0;
  3392. lon = 0;
  3393. }
  3394. p.x = lon;
  3395. p.y = lat;
  3396. gauss.inverse.apply(this, [p]);
  3397. p.x = adjust_lon(p.x + this.long0);
  3398. return p;
  3399. }
  3400. var names$p = ["Stereographic_North_Pole", "Oblique_Stereographic", "sterea","Oblique Stereographic Alternative","Double_Stereographic"];
  3401. var sterea = {
  3402. init: init$q,
  3403. forward: forward$p,
  3404. inverse: inverse$p,
  3405. names: names$p
  3406. };
  3407. function ssfn_(phit, sinphi, eccen) {
  3408. sinphi *= eccen;
  3409. return (Math.tan(0.5 * (HALF_PI + phit)) * Math.pow((1 - sinphi) / (1 + sinphi), 0.5 * eccen));
  3410. }
  3411. function init$p() {
  3412. // setting default parameters
  3413. this.x0 = this.x0 || 0;
  3414. this.y0 = this.y0 || 0;
  3415. this.lat0 = this.lat0 || 0;
  3416. this.long0 = this.long0 || 0;
  3417. this.coslat0 = Math.cos(this.lat0);
  3418. this.sinlat0 = Math.sin(this.lat0);
  3419. if (this.sphere) {
  3420. if (this.k0 === 1 && !isNaN(this.lat_ts) && Math.abs(this.coslat0) <= EPSLN) {
  3421. this.k0 = 0.5 * (1 + sign(this.lat0) * Math.sin(this.lat_ts));
  3422. }
  3423. }
  3424. else {
  3425. if (Math.abs(this.coslat0) <= EPSLN) {
  3426. if (this.lat0 > 0) {
  3427. //North pole
  3428. //trace('stere:north pole');
  3429. this.con = 1;
  3430. }
  3431. else {
  3432. //South pole
  3433. //trace('stere:south pole');
  3434. this.con = -1;
  3435. }
  3436. }
  3437. this.cons = Math.sqrt(Math.pow(1 + this.e, 1 + this.e) * Math.pow(1 - this.e, 1 - this.e));
  3438. if (this.k0 === 1 && !isNaN(this.lat_ts) && Math.abs(this.coslat0) <= EPSLN && Math.abs(Math.cos(this.lat_ts)) > EPSLN) {
  3439. // When k0 is 1 (default value) and lat_ts is a vaild number and lat0 is at a pole and lat_ts is not at a pole
  3440. // Recalculate k0 using formula 21-35 from p161 of Snyder, 1987
  3441. 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));
  3442. }
  3443. this.ms1 = msfnz(this.e, this.sinlat0, this.coslat0);
  3444. this.X0 = 2 * Math.atan(this.ssfn_(this.lat0, this.sinlat0, this.e)) - HALF_PI;
  3445. this.cosX0 = Math.cos(this.X0);
  3446. this.sinX0 = Math.sin(this.X0);
  3447. }
  3448. }
  3449. // Stereographic forward equations--mapping lat,long to x,y
  3450. function forward$o(p) {
  3451. var lon = p.x;
  3452. var lat = p.y;
  3453. var sinlat = Math.sin(lat);
  3454. var coslat = Math.cos(lat);
  3455. var A, X, sinX, cosX, ts, rh;
  3456. var dlon = adjust_lon(lon - this.long0);
  3457. if (Math.abs(Math.abs(lon - this.long0) - Math.PI) <= EPSLN && Math.abs(lat + this.lat0) <= EPSLN) {
  3458. //case of the origine point
  3459. //trace('stere:this is the origin point');
  3460. p.x = NaN;
  3461. p.y = NaN;
  3462. return p;
  3463. }
  3464. if (this.sphere) {
  3465. //trace('stere:sphere case');
  3466. A = 2 * this.k0 / (1 + this.sinlat0 * sinlat + this.coslat0 * coslat * Math.cos(dlon));
  3467. p.x = this.a * A * coslat * Math.sin(dlon) + this.x0;
  3468. p.y = this.a * A * (this.coslat0 * sinlat - this.sinlat0 * coslat * Math.cos(dlon)) + this.y0;
  3469. return p;
  3470. }
  3471. else {
  3472. X = 2 * Math.atan(this.ssfn_(lat, sinlat, this.e)) - HALF_PI;
  3473. cosX = Math.cos(X);
  3474. sinX = Math.sin(X);
  3475. if (Math.abs(this.coslat0) <= EPSLN) {
  3476. ts = tsfnz(this.e, lat * this.con, this.con * sinlat);
  3477. rh = 2 * this.a * this.k0 * ts / this.cons;
  3478. p.x = this.x0 + rh * Math.sin(lon - this.long0);
  3479. p.y = this.y0 - this.con * rh * Math.cos(lon - this.long0);
  3480. //trace(p.toString());
  3481. return p;
  3482. }
  3483. else if (Math.abs(this.sinlat0) < EPSLN) {
  3484. //Eq
  3485. //trace('stere:equateur');
  3486. A = 2 * this.a * this.k0 / (1 + cosX * Math.cos(dlon));
  3487. p.y = A * sinX;
  3488. }
  3489. else {
  3490. //other case
  3491. //trace('stere:normal case');
  3492. A = 2 * this.a * this.k0 * this.ms1 / (this.cosX0 * (1 + this.sinX0 * sinX + this.cosX0 * cosX * Math.cos(dlon)));
  3493. p.y = A * (this.cosX0 * sinX - this.sinX0 * cosX * Math.cos(dlon)) + this.y0;
  3494. }
  3495. p.x = A * cosX * Math.sin(dlon) + this.x0;
  3496. }
  3497. //trace(p.toString());
  3498. return p;
  3499. }
  3500. //* Stereographic inverse equations--mapping x,y to lat/long
  3501. function inverse$o(p) {
  3502. p.x -= this.x0;
  3503. p.y -= this.y0;
  3504. var lon, lat, ts, ce, Chi;
  3505. var rh = Math.sqrt(p.x * p.x + p.y * p.y);
  3506. if (this.sphere) {
  3507. var c = 2 * Math.atan(rh / (2 * this.a * this.k0));
  3508. lon = this.long0;
  3509. lat = this.lat0;
  3510. if (rh <= EPSLN) {
  3511. p.x = lon;
  3512. p.y = lat;
  3513. return p;
  3514. }
  3515. lat = Math.asin(Math.cos(c) * this.sinlat0 + p.y * Math.sin(c) * this.coslat0 / rh);
  3516. if (Math.abs(this.coslat0) < EPSLN) {
  3517. if (this.lat0 > 0) {
  3518. lon = adjust_lon(this.long0 + Math.atan2(p.x, - 1 * p.y));
  3519. }
  3520. else {
  3521. lon = adjust_lon(this.long0 + Math.atan2(p.x, p.y));
  3522. }
  3523. }
  3524. else {
  3525. 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)));
  3526. }
  3527. p.x = lon;
  3528. p.y = lat;
  3529. return p;
  3530. }
  3531. else {
  3532. if (Math.abs(this.coslat0) <= EPSLN) {
  3533. if (rh <= EPSLN) {
  3534. lat = this.lat0;
  3535. lon = this.long0;
  3536. p.x = lon;
  3537. p.y = lat;
  3538. //trace(p.toString());
  3539. return p;
  3540. }
  3541. p.x *= this.con;
  3542. p.y *= this.con;
  3543. ts = rh * this.cons / (2 * this.a * this.k0);
  3544. lat = this.con * phi2z(this.e, ts);
  3545. lon = this.con * adjust_lon(this.con * this.long0 + Math.atan2(p.x, - 1 * p.y));
  3546. }
  3547. else {
  3548. ce = 2 * Math.atan(rh * this.cosX0 / (2 * this.a * this.k0 * this.ms1));
  3549. lon = this.long0;
  3550. if (rh <= EPSLN) {
  3551. Chi = this.X0;
  3552. }
  3553. else {
  3554. Chi = Math.asin(Math.cos(ce) * this.sinX0 + p.y * Math.sin(ce) * this.cosX0 / rh);
  3555. 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)));
  3556. }
  3557. lat = -1 * phi2z(this.e, Math.tan(0.5 * (HALF_PI + Chi)));
  3558. }
  3559. }
  3560. p.x = lon;
  3561. p.y = lat;
  3562. //trace(p.toString());
  3563. return p;
  3564. }
  3565. var names$o = ["stere", "Stereographic_South_Pole", "Polar Stereographic (variant B)", "Polar_Stereographic"];
  3566. var stere = {
  3567. init: init$p,
  3568. forward: forward$o,
  3569. inverse: inverse$o,
  3570. names: names$o,
  3571. ssfn_: ssfn_
  3572. };
  3573. /*
  3574. references:
  3575. Formules et constantes pour le Calcul pour la
  3576. projection cylindrique conforme à axe oblique et pour la transformation entre
  3577. des systèmes de référence.
  3578. http://www.swisstopo.admin.ch/internet/swisstopo/fr/home/topics/survey/sys/refsys/switzerland.parsysrelated1.31216.downloadList.77004.DownloadFile.tmp/swissprojectionfr.pdf
  3579. */
  3580. function init$o() {
  3581. var phy0 = this.lat0;
  3582. this.lambda0 = this.long0;
  3583. var sinPhy0 = Math.sin(phy0);
  3584. var semiMajorAxis = this.a;
  3585. var invF = this.rf;
  3586. var flattening = 1 / invF;
  3587. var e2 = 2 * flattening - Math.pow(flattening, 2);
  3588. var e = this.e = Math.sqrt(e2);
  3589. this.R = this.k0 * semiMajorAxis * Math.sqrt(1 - e2) / (1 - e2 * Math.pow(sinPhy0, 2));
  3590. this.alpha = Math.sqrt(1 + e2 / (1 - e2) * Math.pow(Math.cos(phy0), 4));
  3591. this.b0 = Math.asin(sinPhy0 / this.alpha);
  3592. var k1 = Math.log(Math.tan(Math.PI / 4 + this.b0 / 2));
  3593. var k2 = Math.log(Math.tan(Math.PI / 4 + phy0 / 2));
  3594. var k3 = Math.log((1 + e * sinPhy0) / (1 - e * sinPhy0));
  3595. this.K = k1 - this.alpha * k2 + this.alpha * e / 2 * k3;
  3596. }
  3597. function forward$n(p) {
  3598. var Sa1 = Math.log(Math.tan(Math.PI / 4 - p.y / 2));
  3599. var Sa2 = this.e / 2 * Math.log((1 + this.e * Math.sin(p.y)) / (1 - this.e * Math.sin(p.y)));
  3600. var S = -this.alpha * (Sa1 + Sa2) + this.K;
  3601. // spheric latitude
  3602. var b = 2 * (Math.atan(Math.exp(S)) - Math.PI / 4);
  3603. // spheric longitude
  3604. var I = this.alpha * (p.x - this.lambda0);
  3605. // psoeudo equatorial rotation
  3606. var rotI = Math.atan(Math.sin(I) / (Math.sin(this.b0) * Math.tan(b) + Math.cos(this.b0) * Math.cos(I)));
  3607. var rotB = Math.asin(Math.cos(this.b0) * Math.sin(b) - Math.sin(this.b0) * Math.cos(b) * Math.cos(I));
  3608. p.y = this.R / 2 * Math.log((1 + Math.sin(rotB)) / (1 - Math.sin(rotB))) + this.y0;
  3609. p.x = this.R * rotI + this.x0;
  3610. return p;
  3611. }
  3612. function inverse$n(p) {
  3613. var Y = p.x - this.x0;
  3614. var X = p.y - this.y0;
  3615. var rotI = Y / this.R;
  3616. var rotB = 2 * (Math.atan(Math.exp(X / this.R)) - Math.PI / 4);
  3617. var b = Math.asin(Math.cos(this.b0) * Math.sin(rotB) + Math.sin(this.b0) * Math.cos(rotB) * Math.cos(rotI));
  3618. var I = Math.atan(Math.sin(rotI) / (Math.cos(this.b0) * Math.cos(rotI) - Math.sin(this.b0) * Math.tan(rotB)));
  3619. var lambda = this.lambda0 + I / this.alpha;
  3620. var S = 0;
  3621. var phy = b;
  3622. var prevPhy = -1000;
  3623. var iteration = 0;
  3624. while (Math.abs(phy - prevPhy) > 0.0000001) {
  3625. if (++iteration > 20) {
  3626. //...reportError("omercFwdInfinity");
  3627. return;
  3628. }
  3629. //S = Math.log(Math.tan(Math.PI / 4 + phy / 2));
  3630. 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));
  3631. prevPhy = phy;
  3632. phy = 2 * Math.atan(Math.exp(S)) - Math.PI / 2;
  3633. }
  3634. p.x = lambda;
  3635. p.y = phy;
  3636. return p;
  3637. }
  3638. var names$n = ["somerc"];
  3639. var somerc = {
  3640. init: init$o,
  3641. forward: forward$n,
  3642. inverse: inverse$n,
  3643. names: names$n
  3644. };
  3645. var TOL = 1e-7;
  3646. function isTypeA(P) {
  3647. var typeAProjections = ['Hotine_Oblique_Mercator','Hotine_Oblique_Mercator_Azimuth_Natural_Origin'];
  3648. var projectionName = typeof P.PROJECTION === "object" ? Object.keys(P.PROJECTION)[0] : P.PROJECTION;
  3649. return 'no_uoff' in P || 'no_off' in P || typeAProjections.indexOf(projectionName) !== -1;
  3650. }
  3651. /* Initialize the Oblique Mercator projection
  3652. ------------------------------------------*/
  3653. function init$n() {
  3654. var con, com, cosph0, D, F, H, L, sinph0, p, J, gamma = 0,
  3655. gamma0, lamc = 0, lam1 = 0, lam2 = 0, phi1 = 0, phi2 = 0, alpha_c = 0;
  3656. // only Type A uses the no_off or no_uoff property
  3657. // https://github.com/OSGeo/proj.4/issues/104
  3658. this.no_off = isTypeA(this);
  3659. this.no_rot = 'no_rot' in this;
  3660. var alp = false;
  3661. if ("alpha" in this) {
  3662. alp = true;
  3663. }
  3664. var gam = false;
  3665. if ("rectified_grid_angle" in this) {
  3666. gam = true;
  3667. }
  3668. if (alp) {
  3669. alpha_c = this.alpha;
  3670. }
  3671. if (gam) {
  3672. gamma = (this.rectified_grid_angle * D2R$1);
  3673. }
  3674. if (alp || gam) {
  3675. lamc = this.longc;
  3676. } else {
  3677. lam1 = this.long1;
  3678. phi1 = this.lat1;
  3679. lam2 = this.long2;
  3680. phi2 = this.lat2;
  3681. if (Math.abs(phi1 - phi2) <= TOL || (con = Math.abs(phi1)) <= TOL ||
  3682. Math.abs(con - HALF_PI) <= TOL || Math.abs(Math.abs(this.lat0) - HALF_PI) <= TOL ||
  3683. Math.abs(Math.abs(phi2) - HALF_PI) <= TOL) {
  3684. throw new Error();
  3685. }
  3686. }
  3687. var one_es = 1.0 - this.es;
  3688. com = Math.sqrt(one_es);
  3689. if (Math.abs(this.lat0) > EPSLN) {
  3690. sinph0 = Math.sin(this.lat0);
  3691. cosph0 = Math.cos(this.lat0);
  3692. con = 1 - this.es * sinph0 * sinph0;
  3693. this.B = cosph0 * cosph0;
  3694. this.B = Math.sqrt(1 + this.es * this.B * this.B / one_es);
  3695. this.A = this.B * this.k0 * com / con;
  3696. D = this.B * com / (cosph0 * Math.sqrt(con));
  3697. F = D * D -1;
  3698. if (F <= 0) {
  3699. F = 0;
  3700. } else {
  3701. F = Math.sqrt(F);
  3702. if (this.lat0 < 0) {
  3703. F = -F;
  3704. }
  3705. }
  3706. this.E = F += D;
  3707. this.E *= Math.pow(tsfnz(this.e, this.lat0, sinph0), this.B);
  3708. } else {
  3709. this.B = 1 / com;
  3710. this.A = this.k0;
  3711. this.E = D = F = 1;
  3712. }
  3713. if (alp || gam) {
  3714. if (alp) {
  3715. gamma0 = Math.asin(Math.sin(alpha_c) / D);
  3716. if (!gam) {
  3717. gamma = alpha_c;
  3718. }
  3719. } else {
  3720. gamma0 = gamma;
  3721. alpha_c = Math.asin(D * Math.sin(gamma0));
  3722. }
  3723. this.lam0 = lamc - Math.asin(0.5 * (F - 1 / F) * Math.tan(gamma0)) / this.B;
  3724. } else {
  3725. H = Math.pow(tsfnz(this.e, phi1, Math.sin(phi1)), this.B);
  3726. L = Math.pow(tsfnz(this.e, phi2, Math.sin(phi2)), this.B);
  3727. F = this.E / H;
  3728. p = (L - H) / (L + H);
  3729. J = this.E * this.E;
  3730. J = (J - L * H) / (J + L * H);
  3731. con = lam1 - lam2;
  3732. if (con < -Math.pi) {
  3733. lam2 -=TWO_PI;
  3734. } else if (con > Math.pi) {
  3735. lam2 += TWO_PI;
  3736. }
  3737. this.lam0 = adjust_lon(0.5 * (lam1 + lam2) - Math.atan(J * Math.tan(0.5 * this.B * (lam1 - lam2)) / p) / this.B);
  3738. gamma0 = Math.atan(2 * Math.sin(this.B * adjust_lon(lam1 - this.lam0)) / (F - 1 / F));
  3739. gamma = alpha_c = Math.asin(D * Math.sin(gamma0));
  3740. }
  3741. this.singam = Math.sin(gamma0);
  3742. this.cosgam = Math.cos(gamma0);
  3743. this.sinrot = Math.sin(gamma);
  3744. this.cosrot = Math.cos(gamma);
  3745. this.rB = 1 / this.B;
  3746. this.ArB = this.A * this.rB;
  3747. this.BrA = 1 / this.ArB;
  3748. this.A * this.B;
  3749. if (this.no_off) {
  3750. this.u_0 = 0;
  3751. } else {
  3752. this.u_0 = Math.abs(this.ArB * Math.atan(Math.sqrt(D * D - 1) / Math.cos(alpha_c)));
  3753. if (this.lat0 < 0) {
  3754. this.u_0 = - this.u_0;
  3755. }
  3756. }
  3757. F = 0.5 * gamma0;
  3758. this.v_pole_n = this.ArB * Math.log(Math.tan(FORTPI - F));
  3759. this.v_pole_s = this.ArB * Math.log(Math.tan(FORTPI + F));
  3760. }
  3761. /* Oblique Mercator forward equations--mapping lat,long to x,y
  3762. ----------------------------------------------------------*/
  3763. function forward$m(p) {
  3764. var coords = {};
  3765. var S, T, U, V, W, temp, u, v;
  3766. p.x = p.x - this.lam0;
  3767. if (Math.abs(Math.abs(p.y) - HALF_PI) > EPSLN) {
  3768. W = this.E / Math.pow(tsfnz(this.e, p.y, Math.sin(p.y)), this.B);
  3769. temp = 1 / W;
  3770. S = 0.5 * (W - temp);
  3771. T = 0.5 * (W + temp);
  3772. V = Math.sin(this.B * p.x);
  3773. U = (S * this.singam - V * this.cosgam) / T;
  3774. if (Math.abs(Math.abs(U) - 1.0) < EPSLN) {
  3775. throw new Error();
  3776. }
  3777. v = 0.5 * this.ArB * Math.log((1 - U)/(1 + U));
  3778. temp = Math.cos(this.B * p.x);
  3779. if (Math.abs(temp) < TOL) {
  3780. u = this.A * p.x;
  3781. } else {
  3782. u = this.ArB * Math.atan2((S * this.cosgam + V * this.singam), temp);
  3783. }
  3784. } else {
  3785. v = p.y > 0 ? this.v_pole_n : this.v_pole_s;
  3786. u = this.ArB * p.y;
  3787. }
  3788. if (this.no_rot) {
  3789. coords.x = u;
  3790. coords.y = v;
  3791. } else {
  3792. u -= this.u_0;
  3793. coords.x = v * this.cosrot + u * this.sinrot;
  3794. coords.y = u * this.cosrot - v * this.sinrot;
  3795. }
  3796. coords.x = (this.a * coords.x + this.x0);
  3797. coords.y = (this.a * coords.y + this.y0);
  3798. return coords;
  3799. }
  3800. function inverse$m(p) {
  3801. var u, v, Qp, Sp, Tp, Vp, Up;
  3802. var coords = {};
  3803. p.x = (p.x - this.x0) * (1.0 / this.a);
  3804. p.y = (p.y - this.y0) * (1.0 / this.a);
  3805. if (this.no_rot) {
  3806. v = p.y;
  3807. u = p.x;
  3808. } else {
  3809. v = p.x * this.cosrot - p.y * this.sinrot;
  3810. u = p.y * this.cosrot + p.x * this.sinrot + this.u_0;
  3811. }
  3812. Qp = Math.exp(-this.BrA * v);
  3813. Sp = 0.5 * (Qp - 1 / Qp);
  3814. Tp = 0.5 * (Qp + 1 / Qp);
  3815. Vp = Math.sin(this.BrA * u);
  3816. Up = (Vp * this.cosgam + Sp * this.singam) / Tp;
  3817. if (Math.abs(Math.abs(Up) - 1) < EPSLN) {
  3818. coords.x = 0;
  3819. coords.y = Up < 0 ? -HALF_PI : HALF_PI;
  3820. } else {
  3821. coords.y = this.E / Math.sqrt((1 + Up) / (1 - Up));
  3822. coords.y = phi2z(this.e, Math.pow(coords.y, 1 / this.B));
  3823. if (coords.y === Infinity) {
  3824. throw new Error();
  3825. }
  3826. coords.x = -this.rB * Math.atan2((Sp * this.cosgam - Vp * this.singam), Math.cos(this.BrA * u));
  3827. }
  3828. coords.x += this.lam0;
  3829. return coords;
  3830. }
  3831. var names$m = ["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"];
  3832. var omerc = {
  3833. init: init$n,
  3834. forward: forward$m,
  3835. inverse: inverse$m,
  3836. names: names$m
  3837. };
  3838. function init$m() {
  3839. //double lat0; /* the reference latitude */
  3840. //double long0; /* the reference longitude */
  3841. //double lat1; /* first standard parallel */
  3842. //double lat2; /* second standard parallel */
  3843. //double r_maj; /* major axis */
  3844. //double r_min; /* minor axis */
  3845. //double false_east; /* x offset in meters */
  3846. //double false_north; /* y offset in meters */
  3847. //the above value can be set with proj4.defs
  3848. //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");
  3849. if (!this.lat2) {
  3850. this.lat2 = this.lat1;
  3851. } //if lat2 is not defined
  3852. if (!this.k0) {
  3853. this.k0 = 1;
  3854. }
  3855. this.x0 = this.x0 || 0;
  3856. this.y0 = this.y0 || 0;
  3857. // Standard Parallels cannot be equal and on opposite sides of the equator
  3858. if (Math.abs(this.lat1 + this.lat2) < EPSLN) {
  3859. return;
  3860. }
  3861. var temp = this.b / this.a;
  3862. this.e = Math.sqrt(1 - temp * temp);
  3863. var sin1 = Math.sin(this.lat1);
  3864. var cos1 = Math.cos(this.lat1);
  3865. var ms1 = msfnz(this.e, sin1, cos1);
  3866. var ts1 = tsfnz(this.e, this.lat1, sin1);
  3867. var sin2 = Math.sin(this.lat2);
  3868. var cos2 = Math.cos(this.lat2);
  3869. var ms2 = msfnz(this.e, sin2, cos2);
  3870. var ts2 = tsfnz(this.e, this.lat2, sin2);
  3871. var ts0 = tsfnz(this.e, this.lat0, Math.sin(this.lat0));
  3872. if (Math.abs(this.lat1 - this.lat2) > EPSLN) {
  3873. this.ns = Math.log(ms1 / ms2) / Math.log(ts1 / ts2);
  3874. }
  3875. else {
  3876. this.ns = sin1;
  3877. }
  3878. if (isNaN(this.ns)) {
  3879. this.ns = sin1;
  3880. }
  3881. this.f0 = ms1 / (this.ns * Math.pow(ts1, this.ns));
  3882. this.rh = this.a * this.f0 * Math.pow(ts0, this.ns);
  3883. if (!this.title) {
  3884. this.title = "Lambert Conformal Conic";
  3885. }
  3886. }
  3887. // Lambert Conformal conic forward equations--mapping lat,long to x,y
  3888. // -----------------------------------------------------------------
  3889. function forward$l(p) {
  3890. var lon = p.x;
  3891. var lat = p.y;
  3892. // singular cases :
  3893. if (Math.abs(2 * Math.abs(lat) - Math.PI) <= EPSLN) {
  3894. lat = sign(lat) * (HALF_PI - 2 * EPSLN);
  3895. }
  3896. var con = Math.abs(Math.abs(lat) - HALF_PI);
  3897. var ts, rh1;
  3898. if (con > EPSLN) {
  3899. ts = tsfnz(this.e, lat, Math.sin(lat));
  3900. rh1 = this.a * this.f0 * Math.pow(ts, this.ns);
  3901. }
  3902. else {
  3903. con = lat * this.ns;
  3904. if (con <= 0) {
  3905. return null;
  3906. }
  3907. rh1 = 0;
  3908. }
  3909. var theta = this.ns * adjust_lon(lon - this.long0);
  3910. p.x = this.k0 * (rh1 * Math.sin(theta)) + this.x0;
  3911. p.y = this.k0 * (this.rh - rh1 * Math.cos(theta)) + this.y0;
  3912. return p;
  3913. }
  3914. // Lambert Conformal Conic inverse equations--mapping x,y to lat/long
  3915. // -----------------------------------------------------------------
  3916. function inverse$l(p) {
  3917. var rh1, con, ts;
  3918. var lat, lon;
  3919. var x = (p.x - this.x0) / this.k0;
  3920. var y = (this.rh - (p.y - this.y0) / this.k0);
  3921. if (this.ns > 0) {
  3922. rh1 = Math.sqrt(x * x + y * y);
  3923. con = 1;
  3924. }
  3925. else {
  3926. rh1 = -Math.sqrt(x * x + y * y);
  3927. con = -1;
  3928. }
  3929. var theta = 0;
  3930. if (rh1 !== 0) {
  3931. theta = Math.atan2((con * x), (con * y));
  3932. }
  3933. if ((rh1 !== 0) || (this.ns > 0)) {
  3934. con = 1 / this.ns;
  3935. ts = Math.pow((rh1 / (this.a * this.f0)), con);
  3936. lat = phi2z(this.e, ts);
  3937. if (lat === -9999) {
  3938. return null;
  3939. }
  3940. }
  3941. else {
  3942. lat = -HALF_PI;
  3943. }
  3944. lon = adjust_lon(theta / this.ns + this.long0);
  3945. p.x = lon;
  3946. p.y = lat;
  3947. return p;
  3948. }
  3949. var names$l = [
  3950. "Lambert Tangential Conformal Conic Projection",
  3951. "Lambert_Conformal_Conic",
  3952. "Lambert_Conformal_Conic_1SP",
  3953. "Lambert_Conformal_Conic_2SP",
  3954. "lcc",
  3955. "Lambert Conic Conformal (1SP)",
  3956. "Lambert Conic Conformal (2SP)"
  3957. ];
  3958. var lcc = {
  3959. init: init$m,
  3960. forward: forward$l,
  3961. inverse: inverse$l,
  3962. names: names$l
  3963. };
  3964. function init$l() {
  3965. this.a = 6377397.155;
  3966. this.es = 0.006674372230614;
  3967. this.e = Math.sqrt(this.es);
  3968. if (!this.lat0) {
  3969. this.lat0 = 0.863937979737193;
  3970. }
  3971. if (!this.long0) {
  3972. this.long0 = 0.7417649320975901 - 0.308341501185665;
  3973. }
  3974. /* if scale not set default to 0.9999 */
  3975. if (!this.k0) {
  3976. this.k0 = 0.9999;
  3977. }
  3978. this.s45 = 0.785398163397448; /* 45 */
  3979. this.s90 = 2 * this.s45;
  3980. this.fi0 = this.lat0;
  3981. this.e2 = this.es;
  3982. this.e = Math.sqrt(this.e2);
  3983. this.alfa = Math.sqrt(1 + (this.e2 * Math.pow(Math.cos(this.fi0), 4)) / (1 - this.e2));
  3984. this.uq = 1.04216856380474;
  3985. this.u0 = Math.asin(Math.sin(this.fi0) / this.alfa);
  3986. this.g = Math.pow((1 + this.e * Math.sin(this.fi0)) / (1 - this.e * Math.sin(this.fi0)), this.alfa * this.e / 2);
  3987. this.k = Math.tan(this.u0 / 2 + this.s45) / Math.pow(Math.tan(this.fi0 / 2 + this.s45), this.alfa) * this.g;
  3988. this.k1 = this.k0;
  3989. this.n0 = this.a * Math.sqrt(1 - this.e2) / (1 - this.e2 * Math.pow(Math.sin(this.fi0), 2));
  3990. this.s0 = 1.37008346281555;
  3991. this.n = Math.sin(this.s0);
  3992. this.ro0 = this.k1 * this.n0 / Math.tan(this.s0);
  3993. this.ad = this.s90 - this.uq;
  3994. }
  3995. /* ellipsoid */
  3996. /* calculate xy from lat/lon */
  3997. /* Constants, identical to inverse transform function */
  3998. function forward$k(p) {
  3999. var gfi, u, deltav, s, d, eps, ro;
  4000. var lon = p.x;
  4001. var lat = p.y;
  4002. var delta_lon = adjust_lon(lon - this.long0);
  4003. /* Transformation */
  4004. gfi = Math.pow(((1 + this.e * Math.sin(lat)) / (1 - this.e * Math.sin(lat))), (this.alfa * this.e / 2));
  4005. u = 2 * (Math.atan(this.k * Math.pow(Math.tan(lat / 2 + this.s45), this.alfa) / gfi) - this.s45);
  4006. deltav = -delta_lon * this.alfa;
  4007. s = Math.asin(Math.cos(this.ad) * Math.sin(u) + Math.sin(this.ad) * Math.cos(u) * Math.cos(deltav));
  4008. d = Math.asin(Math.cos(u) * Math.sin(deltav) / Math.cos(s));
  4009. eps = this.n * d;
  4010. ro = this.ro0 * Math.pow(Math.tan(this.s0 / 2 + this.s45), this.n) / Math.pow(Math.tan(s / 2 + this.s45), this.n);
  4011. p.y = ro * Math.cos(eps) / 1;
  4012. p.x = ro * Math.sin(eps) / 1;
  4013. if (!this.czech) {
  4014. p.y *= -1;
  4015. p.x *= -1;
  4016. }
  4017. return (p);
  4018. }
  4019. /* calculate lat/lon from xy */
  4020. function inverse$k(p) {
  4021. var u, deltav, s, d, eps, ro, fi1;
  4022. var ok;
  4023. /* Transformation */
  4024. /* revert y, x*/
  4025. var tmp = p.x;
  4026. p.x = p.y;
  4027. p.y = tmp;
  4028. if (!this.czech) {
  4029. p.y *= -1;
  4030. p.x *= -1;
  4031. }
  4032. ro = Math.sqrt(p.x * p.x + p.y * p.y);
  4033. eps = Math.atan2(p.y, p.x);
  4034. d = eps / Math.sin(this.s0);
  4035. s = 2 * (Math.atan(Math.pow(this.ro0 / ro, 1 / this.n) * Math.tan(this.s0 / 2 + this.s45)) - this.s45);
  4036. u = Math.asin(Math.cos(this.ad) * Math.sin(s) - Math.sin(this.ad) * Math.cos(s) * Math.cos(d));
  4037. deltav = Math.asin(Math.cos(s) * Math.sin(d) / Math.cos(u));
  4038. p.x = this.long0 - deltav / this.alfa;
  4039. fi1 = u;
  4040. ok = 0;
  4041. var iter = 0;
  4042. do {
  4043. 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);
  4044. if (Math.abs(fi1 - p.y) < 0.0000000001) {
  4045. ok = 1;
  4046. }
  4047. fi1 = p.y;
  4048. iter += 1;
  4049. } while (ok === 0 && iter < 15);
  4050. if (iter >= 15) {
  4051. return null;
  4052. }
  4053. return (p);
  4054. }
  4055. var names$k = ["Krovak", "krovak"];
  4056. var krovak = {
  4057. init: init$l,
  4058. forward: forward$k,
  4059. inverse: inverse$k,
  4060. names: names$k
  4061. };
  4062. function mlfn(e0, e1, e2, e3, phi) {
  4063. return (e0 * phi - e1 * Math.sin(2 * phi) + e2 * Math.sin(4 * phi) - e3 * Math.sin(6 * phi));
  4064. }
  4065. function e0fn(x) {
  4066. return (1 - 0.25 * x * (1 + x / 16 * (3 + 1.25 * x)));
  4067. }
  4068. function e1fn(x) {
  4069. return (0.375 * x * (1 + 0.25 * x * (1 + 0.46875 * x)));
  4070. }
  4071. function e2fn(x) {
  4072. return (0.05859375 * x * x * (1 + 0.75 * x));
  4073. }
  4074. function e3fn(x) {
  4075. return (x * x * x * (35 / 3072));
  4076. }
  4077. function gN(a, e, sinphi) {
  4078. var temp = e * sinphi;
  4079. return a / Math.sqrt(1 - temp * temp);
  4080. }
  4081. function adjust_lat(x) {
  4082. return (Math.abs(x) < HALF_PI) ? x : (x - (sign(x) * Math.PI));
  4083. }
  4084. function imlfn(ml, e0, e1, e2, e3) {
  4085. var phi;
  4086. var dphi;
  4087. phi = ml / e0;
  4088. for (var i = 0; i < 15; i++) {
  4089. 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));
  4090. phi += dphi;
  4091. if (Math.abs(dphi) <= 0.0000000001) {
  4092. return phi;
  4093. }
  4094. }
  4095. //..reportError("IMLFN-CONV:Latitude failed to converge after 15 iterations");
  4096. return NaN;
  4097. }
  4098. function init$k() {
  4099. if (!this.sphere) {
  4100. this.e0 = e0fn(this.es);
  4101. this.e1 = e1fn(this.es);
  4102. this.e2 = e2fn(this.es);
  4103. this.e3 = e3fn(this.es);
  4104. this.ml0 = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, this.lat0);
  4105. }
  4106. }
  4107. /* Cassini forward equations--mapping lat,long to x,y
  4108. -----------------------------------------------------------------------*/
  4109. function forward$j(p) {
  4110. /* Forward equations
  4111. -----------------*/
  4112. var x, y;
  4113. var lam = p.x;
  4114. var phi = p.y;
  4115. lam = adjust_lon(lam - this.long0);
  4116. if (this.sphere) {
  4117. x = this.a * Math.asin(Math.cos(phi) * Math.sin(lam));
  4118. y = this.a * (Math.atan2(Math.tan(phi), Math.cos(lam)) - this.lat0);
  4119. }
  4120. else {
  4121. //ellipsoid
  4122. var sinphi = Math.sin(phi);
  4123. var cosphi = Math.cos(phi);
  4124. var nl = gN(this.a, this.e, sinphi);
  4125. var tl = Math.tan(phi) * Math.tan(phi);
  4126. var al = lam * Math.cos(phi);
  4127. var asq = al * al;
  4128. var cl = this.es * cosphi * cosphi / (1 - this.es);
  4129. var ml = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, phi);
  4130. x = nl * al * (1 - asq * tl * (1 / 6 - (8 - tl + 8 * cl) * asq / 120));
  4131. y = ml - this.ml0 + nl * sinphi / cosphi * asq * (0.5 + (5 - tl + 6 * cl) * asq / 24);
  4132. }
  4133. p.x = x + this.x0;
  4134. p.y = y + this.y0;
  4135. return p;
  4136. }
  4137. /* Inverse equations
  4138. -----------------*/
  4139. function inverse$j(p) {
  4140. p.x -= this.x0;
  4141. p.y -= this.y0;
  4142. var x = p.x / this.a;
  4143. var y = p.y / this.a;
  4144. var phi, lam;
  4145. if (this.sphere) {
  4146. var dd = y + this.lat0;
  4147. phi = Math.asin(Math.sin(dd) * Math.cos(x));
  4148. lam = Math.atan2(Math.tan(x), Math.cos(dd));
  4149. }
  4150. else {
  4151. /* ellipsoid */
  4152. var ml1 = this.ml0 / this.a + y;
  4153. var phi1 = imlfn(ml1, this.e0, this.e1, this.e2, this.e3);
  4154. if (Math.abs(Math.abs(phi1) - HALF_PI) <= EPSLN) {
  4155. p.x = this.long0;
  4156. p.y = HALF_PI;
  4157. if (y < 0) {
  4158. p.y *= -1;
  4159. }
  4160. return p;
  4161. }
  4162. var nl1 = gN(this.a, this.e, Math.sin(phi1));
  4163. var rl1 = nl1 * nl1 * nl1 / this.a / this.a * (1 - this.es);
  4164. var tl1 = Math.pow(Math.tan(phi1), 2);
  4165. var dl = x * this.a / nl1;
  4166. var dsq = dl * dl;
  4167. phi = phi1 - nl1 * Math.tan(phi1) / rl1 * dl * dl * (0.5 - (1 + 3 * tl1) * dl * dl / 24);
  4168. lam = dl * (1 - dsq * (tl1 / 3 + (1 + 3 * tl1) * tl1 * dsq / 15)) / Math.cos(phi1);
  4169. }
  4170. p.x = adjust_lon(lam + this.long0);
  4171. p.y = adjust_lat(phi);
  4172. return p;
  4173. }
  4174. var names$j = ["Cassini", "Cassini_Soldner", "cass"];
  4175. var cass = {
  4176. init: init$k,
  4177. forward: forward$j,
  4178. inverse: inverse$j,
  4179. names: names$j
  4180. };
  4181. function qsfnz(eccent, sinphi) {
  4182. var con;
  4183. if (eccent > 1.0e-7) {
  4184. con = eccent * sinphi;
  4185. return ((1 - eccent * eccent) * (sinphi / (1 - con * con) - (0.5 / eccent) * Math.log((1 - con) / (1 + con))));
  4186. }
  4187. else {
  4188. return (2 * sinphi);
  4189. }
  4190. }
  4191. /*
  4192. reference
  4193. "New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
  4194. The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
  4195. */
  4196. var S_POLE = 1;
  4197. var N_POLE = 2;
  4198. var EQUIT = 3;
  4199. var OBLIQ = 4;
  4200. /* Initialize the Lambert Azimuthal Equal Area projection
  4201. ------------------------------------------------------*/
  4202. function init$j() {
  4203. var t = Math.abs(this.lat0);
  4204. if (Math.abs(t - HALF_PI) < EPSLN) {
  4205. this.mode = this.lat0 < 0 ? this.S_POLE : this.N_POLE;
  4206. }
  4207. else if (Math.abs(t) < EPSLN) {
  4208. this.mode = this.EQUIT;
  4209. }
  4210. else {
  4211. this.mode = this.OBLIQ;
  4212. }
  4213. if (this.es > 0) {
  4214. var sinphi;
  4215. this.qp = qsfnz(this.e, 1);
  4216. this.mmf = 0.5 / (1 - this.es);
  4217. this.apa = authset(this.es);
  4218. switch (this.mode) {
  4219. case this.N_POLE:
  4220. this.dd = 1;
  4221. break;
  4222. case this.S_POLE:
  4223. this.dd = 1;
  4224. break;
  4225. case this.EQUIT:
  4226. this.rq = Math.sqrt(0.5 * this.qp);
  4227. this.dd = 1 / this.rq;
  4228. this.xmf = 1;
  4229. this.ymf = 0.5 * this.qp;
  4230. break;
  4231. case this.OBLIQ:
  4232. this.rq = Math.sqrt(0.5 * this.qp);
  4233. sinphi = Math.sin(this.lat0);
  4234. this.sinb1 = qsfnz(this.e, sinphi) / this.qp;
  4235. this.cosb1 = Math.sqrt(1 - this.sinb1 * this.sinb1);
  4236. this.dd = Math.cos(this.lat0) / (Math.sqrt(1 - this.es * sinphi * sinphi) * this.rq * this.cosb1);
  4237. this.ymf = (this.xmf = this.rq) / this.dd;
  4238. this.xmf *= this.dd;
  4239. break;
  4240. }
  4241. }
  4242. else {
  4243. if (this.mode === this.OBLIQ) {
  4244. this.sinph0 = Math.sin(this.lat0);
  4245. this.cosph0 = Math.cos(this.lat0);
  4246. }
  4247. }
  4248. }
  4249. /* Lambert Azimuthal Equal Area forward equations--mapping lat,long to x,y
  4250. -----------------------------------------------------------------------*/
  4251. function forward$i(p) {
  4252. /* Forward equations
  4253. -----------------*/
  4254. var x, y, coslam, sinlam, sinphi, q, sinb, cosb, b, cosphi;
  4255. var lam = p.x;
  4256. var phi = p.y;
  4257. lam = adjust_lon(lam - this.long0);
  4258. if (this.sphere) {
  4259. sinphi = Math.sin(phi);
  4260. cosphi = Math.cos(phi);
  4261. coslam = Math.cos(lam);
  4262. if (this.mode === this.OBLIQ || this.mode === this.EQUIT) {
  4263. y = (this.mode === this.EQUIT) ? 1 + cosphi * coslam : 1 + this.sinph0 * sinphi + this.cosph0 * cosphi * coslam;
  4264. if (y <= EPSLN) {
  4265. return null;
  4266. }
  4267. y = Math.sqrt(2 / y);
  4268. x = y * cosphi * Math.sin(lam);
  4269. y *= (this.mode === this.EQUIT) ? sinphi : this.cosph0 * sinphi - this.sinph0 * cosphi * coslam;
  4270. }
  4271. else if (this.mode === this.N_POLE || this.mode === this.S_POLE) {
  4272. if (this.mode === this.N_POLE) {
  4273. coslam = -coslam;
  4274. }
  4275. if (Math.abs(phi + this.lat0) < EPSLN) {
  4276. return null;
  4277. }
  4278. y = FORTPI - phi * 0.5;
  4279. y = 2 * ((this.mode === this.S_POLE) ? Math.cos(y) : Math.sin(y));
  4280. x = y * Math.sin(lam);
  4281. y *= coslam;
  4282. }
  4283. }
  4284. else {
  4285. sinb = 0;
  4286. cosb = 0;
  4287. b = 0;
  4288. coslam = Math.cos(lam);
  4289. sinlam = Math.sin(lam);
  4290. sinphi = Math.sin(phi);
  4291. q = qsfnz(this.e, sinphi);
  4292. if (this.mode === this.OBLIQ || this.mode === this.EQUIT) {
  4293. sinb = q / this.qp;
  4294. cosb = Math.sqrt(1 - sinb * sinb);
  4295. }
  4296. switch (this.mode) {
  4297. case this.OBLIQ:
  4298. b = 1 + this.sinb1 * sinb + this.cosb1 * cosb * coslam;
  4299. break;
  4300. case this.EQUIT:
  4301. b = 1 + cosb * coslam;
  4302. break;
  4303. case this.N_POLE:
  4304. b = HALF_PI + phi;
  4305. q = this.qp - q;
  4306. break;
  4307. case this.S_POLE:
  4308. b = phi - HALF_PI;
  4309. q = this.qp + q;
  4310. break;
  4311. }
  4312. if (Math.abs(b) < EPSLN) {
  4313. return null;
  4314. }
  4315. switch (this.mode) {
  4316. case this.OBLIQ:
  4317. case this.EQUIT:
  4318. b = Math.sqrt(2 / b);
  4319. if (this.mode === this.OBLIQ) {
  4320. y = this.ymf * b * (this.cosb1 * sinb - this.sinb1 * cosb * coslam);
  4321. }
  4322. else {
  4323. y = (b = Math.sqrt(2 / (1 + cosb * coslam))) * sinb * this.ymf;
  4324. }
  4325. x = this.xmf * b * cosb * sinlam;
  4326. break;
  4327. case this.N_POLE:
  4328. case this.S_POLE:
  4329. if (q >= 0) {
  4330. x = (b = Math.sqrt(q)) * sinlam;
  4331. y = coslam * ((this.mode === this.S_POLE) ? b : -b);
  4332. }
  4333. else {
  4334. x = y = 0;
  4335. }
  4336. break;
  4337. }
  4338. }
  4339. p.x = this.a * x + this.x0;
  4340. p.y = this.a * y + this.y0;
  4341. return p;
  4342. }
  4343. /* Inverse equations
  4344. -----------------*/
  4345. function inverse$i(p) {
  4346. p.x -= this.x0;
  4347. p.y -= this.y0;
  4348. var x = p.x / this.a;
  4349. var y = p.y / this.a;
  4350. var lam, phi, cCe, sCe, q, rho, ab;
  4351. if (this.sphere) {
  4352. var cosz = 0,
  4353. rh, sinz = 0;
  4354. rh = Math.sqrt(x * x + y * y);
  4355. phi = rh * 0.5;
  4356. if (phi > 1) {
  4357. return null;
  4358. }
  4359. phi = 2 * Math.asin(phi);
  4360. if (this.mode === this.OBLIQ || this.mode === this.EQUIT) {
  4361. sinz = Math.sin(phi);
  4362. cosz = Math.cos(phi);
  4363. }
  4364. switch (this.mode) {
  4365. case this.EQUIT:
  4366. phi = (Math.abs(rh) <= EPSLN) ? 0 : Math.asin(y * sinz / rh);
  4367. x *= sinz;
  4368. y = cosz * rh;
  4369. break;
  4370. case this.OBLIQ:
  4371. phi = (Math.abs(rh) <= EPSLN) ? this.lat0 : Math.asin(cosz * this.sinph0 + y * sinz * this.cosph0 / rh);
  4372. x *= sinz * this.cosph0;
  4373. y = (cosz - Math.sin(phi) * this.sinph0) * rh;
  4374. break;
  4375. case this.N_POLE:
  4376. y = -y;
  4377. phi = HALF_PI - phi;
  4378. break;
  4379. case this.S_POLE:
  4380. phi -= HALF_PI;
  4381. break;
  4382. }
  4383. lam = (y === 0 && (this.mode === this.EQUIT || this.mode === this.OBLIQ)) ? 0 : Math.atan2(x, y);
  4384. }
  4385. else {
  4386. ab = 0;
  4387. if (this.mode === this.OBLIQ || this.mode === this.EQUIT) {
  4388. x /= this.dd;
  4389. y *= this.dd;
  4390. rho = Math.sqrt(x * x + y * y);
  4391. if (rho < EPSLN) {
  4392. p.x = this.long0;
  4393. p.y = this.lat0;
  4394. return p;
  4395. }
  4396. sCe = 2 * Math.asin(0.5 * rho / this.rq);
  4397. cCe = Math.cos(sCe);
  4398. x *= (sCe = Math.sin(sCe));
  4399. if (this.mode === this.OBLIQ) {
  4400. ab = cCe * this.sinb1 + y * sCe * this.cosb1 / rho;
  4401. q = this.qp * ab;
  4402. y = rho * this.cosb1 * cCe - y * this.sinb1 * sCe;
  4403. }
  4404. else {
  4405. ab = y * sCe / rho;
  4406. q = this.qp * ab;
  4407. y = rho * cCe;
  4408. }
  4409. }
  4410. else if (this.mode === this.N_POLE || this.mode === this.S_POLE) {
  4411. if (this.mode === this.N_POLE) {
  4412. y = -y;
  4413. }
  4414. q = (x * x + y * y);
  4415. if (!q) {
  4416. p.x = this.long0;
  4417. p.y = this.lat0;
  4418. return p;
  4419. }
  4420. ab = 1 - q / this.qp;
  4421. if (this.mode === this.S_POLE) {
  4422. ab = -ab;
  4423. }
  4424. }
  4425. lam = Math.atan2(x, y);
  4426. phi = authlat(Math.asin(ab), this.apa);
  4427. }
  4428. p.x = adjust_lon(this.long0 + lam);
  4429. p.y = phi;
  4430. return p;
  4431. }
  4432. /* determine latitude from authalic latitude */
  4433. var P00 = 0.33333333333333333333;
  4434. var P01 = 0.17222222222222222222;
  4435. var P02 = 0.10257936507936507936;
  4436. var P10 = 0.06388888888888888888;
  4437. var P11 = 0.06640211640211640211;
  4438. var P20 = 0.01641501294219154443;
  4439. function authset(es) {
  4440. var t;
  4441. var APA = [];
  4442. APA[0] = es * P00;
  4443. t = es * es;
  4444. APA[0] += t * P01;
  4445. APA[1] = t * P10;
  4446. t *= es;
  4447. APA[0] += t * P02;
  4448. APA[1] += t * P11;
  4449. APA[2] = t * P20;
  4450. return APA;
  4451. }
  4452. function authlat(beta, APA) {
  4453. var t = beta + beta;
  4454. return (beta + APA[0] * Math.sin(t) + APA[1] * Math.sin(t + t) + APA[2] * Math.sin(t + t + t));
  4455. }
  4456. var names$i = ["Lambert Azimuthal Equal Area", "Lambert_Azimuthal_Equal_Area", "laea"];
  4457. var laea = {
  4458. init: init$j,
  4459. forward: forward$i,
  4460. inverse: inverse$i,
  4461. names: names$i,
  4462. S_POLE: S_POLE,
  4463. N_POLE: N_POLE,
  4464. EQUIT: EQUIT,
  4465. OBLIQ: OBLIQ
  4466. };
  4467. function asinz(x) {
  4468. if (Math.abs(x) > 1) {
  4469. x = (x > 1) ? 1 : -1;
  4470. }
  4471. return Math.asin(x);
  4472. }
  4473. function init$i() {
  4474. if (Math.abs(this.lat1 + this.lat2) < EPSLN) {
  4475. return;
  4476. }
  4477. this.temp = this.b / this.a;
  4478. this.es = 1 - Math.pow(this.temp, 2);
  4479. this.e3 = Math.sqrt(this.es);
  4480. this.sin_po = Math.sin(this.lat1);
  4481. this.cos_po = Math.cos(this.lat1);
  4482. this.t1 = this.sin_po;
  4483. this.con = this.sin_po;
  4484. this.ms1 = msfnz(this.e3, this.sin_po, this.cos_po);
  4485. this.qs1 = qsfnz(this.e3, this.sin_po);
  4486. this.sin_po = Math.sin(this.lat2);
  4487. this.cos_po = Math.cos(this.lat2);
  4488. this.t2 = this.sin_po;
  4489. this.ms2 = msfnz(this.e3, this.sin_po, this.cos_po);
  4490. this.qs2 = qsfnz(this.e3, this.sin_po);
  4491. this.sin_po = Math.sin(this.lat0);
  4492. this.cos_po = Math.cos(this.lat0);
  4493. this.t3 = this.sin_po;
  4494. this.qs0 = qsfnz(this.e3, this.sin_po);
  4495. if (Math.abs(this.lat1 - this.lat2) > EPSLN) {
  4496. this.ns0 = (this.ms1 * this.ms1 - this.ms2 * this.ms2) / (this.qs2 - this.qs1);
  4497. }
  4498. else {
  4499. this.ns0 = this.con;
  4500. }
  4501. this.c = this.ms1 * this.ms1 + this.ns0 * this.qs1;
  4502. this.rh = this.a * Math.sqrt(this.c - this.ns0 * this.qs0) / this.ns0;
  4503. }
  4504. /* Albers Conical Equal Area forward equations--mapping lat,long to x,y
  4505. -------------------------------------------------------------------*/
  4506. function forward$h(p) {
  4507. var lon = p.x;
  4508. var lat = p.y;
  4509. this.sin_phi = Math.sin(lat);
  4510. this.cos_phi = Math.cos(lat);
  4511. var qs = qsfnz(this.e3, this.sin_phi);
  4512. var rh1 = this.a * Math.sqrt(this.c - this.ns0 * qs) / this.ns0;
  4513. var theta = this.ns0 * adjust_lon(lon - this.long0);
  4514. var x = rh1 * Math.sin(theta) + this.x0;
  4515. var y = this.rh - rh1 * Math.cos(theta) + this.y0;
  4516. p.x = x;
  4517. p.y = y;
  4518. return p;
  4519. }
  4520. function inverse$h(p) {
  4521. var rh1, qs, con, theta, lon, lat;
  4522. p.x -= this.x0;
  4523. p.y = this.rh - p.y + this.y0;
  4524. if (this.ns0 >= 0) {
  4525. rh1 = Math.sqrt(p.x * p.x + p.y * p.y);
  4526. con = 1;
  4527. }
  4528. else {
  4529. rh1 = -Math.sqrt(p.x * p.x + p.y * p.y);
  4530. con = -1;
  4531. }
  4532. theta = 0;
  4533. if (rh1 !== 0) {
  4534. theta = Math.atan2(con * p.x, con * p.y);
  4535. }
  4536. con = rh1 * this.ns0 / this.a;
  4537. if (this.sphere) {
  4538. lat = Math.asin((this.c - con * con) / (2 * this.ns0));
  4539. }
  4540. else {
  4541. qs = (this.c - con * con) / this.ns0;
  4542. lat = this.phi1z(this.e3, qs);
  4543. }
  4544. lon = adjust_lon(theta / this.ns0 + this.long0);
  4545. p.x = lon;
  4546. p.y = lat;
  4547. return p;
  4548. }
  4549. /* Function to compute phi1, the latitude for the inverse of the
  4550. Albers Conical Equal-Area projection.
  4551. -------------------------------------------*/
  4552. function phi1z(eccent, qs) {
  4553. var sinphi, cosphi, con, com, dphi;
  4554. var phi = asinz(0.5 * qs);
  4555. if (eccent < EPSLN) {
  4556. return phi;
  4557. }
  4558. var eccnts = eccent * eccent;
  4559. for (var i = 1; i <= 25; i++) {
  4560. sinphi = Math.sin(phi);
  4561. cosphi = Math.cos(phi);
  4562. con = eccent * sinphi;
  4563. com = 1 - con * con;
  4564. dphi = 0.5 * com * com / cosphi * (qs / (1 - eccnts) - sinphi / com + 0.5 / eccent * Math.log((1 - con) / (1 + con)));
  4565. phi = phi + dphi;
  4566. if (Math.abs(dphi) <= 1e-7) {
  4567. return phi;
  4568. }
  4569. }
  4570. return null;
  4571. }
  4572. var names$h = ["Albers_Conic_Equal_Area", "Albers", "aea"];
  4573. var aea = {
  4574. init: init$i,
  4575. forward: forward$h,
  4576. inverse: inverse$h,
  4577. names: names$h,
  4578. phi1z: phi1z
  4579. };
  4580. /*
  4581. reference:
  4582. Wolfram Mathworld "Gnomonic Projection"
  4583. http://mathworld.wolfram.com/GnomonicProjection.html
  4584. Accessed: 12th November 2009
  4585. */
  4586. function init$h() {
  4587. /* Place parameters in static storage for common use
  4588. -------------------------------------------------*/
  4589. this.sin_p14 = Math.sin(this.lat0);
  4590. this.cos_p14 = Math.cos(this.lat0);
  4591. // Approximation for projecting points to the horizon (infinity)
  4592. this.infinity_dist = 1000 * this.a;
  4593. this.rc = 1;
  4594. }
  4595. /* Gnomonic forward equations--mapping lat,long to x,y
  4596. ---------------------------------------------------*/
  4597. function forward$g(p) {
  4598. var sinphi, cosphi; /* sin and cos value */
  4599. var dlon; /* delta longitude value */
  4600. var coslon; /* cos of longitude */
  4601. var ksp; /* scale factor */
  4602. var g;
  4603. var x, y;
  4604. var lon = p.x;
  4605. var lat = p.y;
  4606. /* Forward equations
  4607. -----------------*/
  4608. dlon = adjust_lon(lon - this.long0);
  4609. sinphi = Math.sin(lat);
  4610. cosphi = Math.cos(lat);
  4611. coslon = Math.cos(dlon);
  4612. g = this.sin_p14 * sinphi + this.cos_p14 * cosphi * coslon;
  4613. ksp = 1;
  4614. if ((g > 0) || (Math.abs(g) <= EPSLN)) {
  4615. x = this.x0 + this.a * ksp * cosphi * Math.sin(dlon) / g;
  4616. y = this.y0 + this.a * ksp * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon) / g;
  4617. }
  4618. else {
  4619. // Point is in the opposing hemisphere and is unprojectable
  4620. // We still need to return a reasonable point, so we project
  4621. // to infinity, on a bearing
  4622. // equivalent to the northern hemisphere equivalent
  4623. // This is a reasonable approximation for short shapes and lines that
  4624. // straddle the horizon.
  4625. x = this.x0 + this.infinity_dist * cosphi * Math.sin(dlon);
  4626. y = this.y0 + this.infinity_dist * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon);
  4627. }
  4628. p.x = x;
  4629. p.y = y;
  4630. return p;
  4631. }
  4632. function inverse$g(p) {
  4633. var rh; /* Rho */
  4634. var sinc, cosc;
  4635. var c;
  4636. var lon, lat;
  4637. /* Inverse equations
  4638. -----------------*/
  4639. p.x = (p.x - this.x0) / this.a;
  4640. p.y = (p.y - this.y0) / this.a;
  4641. p.x /= this.k0;
  4642. p.y /= this.k0;
  4643. if ((rh = Math.sqrt(p.x * p.x + p.y * p.y))) {
  4644. c = Math.atan2(rh, this.rc);
  4645. sinc = Math.sin(c);
  4646. cosc = Math.cos(c);
  4647. lat = asinz(cosc * this.sin_p14 + (p.y * sinc * this.cos_p14) / rh);
  4648. lon = Math.atan2(p.x * sinc, rh * this.cos_p14 * cosc - p.y * this.sin_p14 * sinc);
  4649. lon = adjust_lon(this.long0 + lon);
  4650. }
  4651. else {
  4652. lat = this.phic0;
  4653. lon = 0;
  4654. }
  4655. p.x = lon;
  4656. p.y = lat;
  4657. return p;
  4658. }
  4659. var names$g = ["gnom"];
  4660. var gnom = {
  4661. init: init$h,
  4662. forward: forward$g,
  4663. inverse: inverse$g,
  4664. names: names$g
  4665. };
  4666. function iqsfnz(eccent, q) {
  4667. var temp = 1 - (1 - eccent * eccent) / (2 * eccent) * Math.log((1 - eccent) / (1 + eccent));
  4668. if (Math.abs(Math.abs(q) - temp) < 1.0E-6) {
  4669. if (q < 0) {
  4670. return (-1 * HALF_PI);
  4671. }
  4672. else {
  4673. return HALF_PI;
  4674. }
  4675. }
  4676. //var phi = 0.5* q/(1-eccent*eccent);
  4677. var phi = Math.asin(0.5 * q);
  4678. var dphi;
  4679. var sin_phi;
  4680. var cos_phi;
  4681. var con;
  4682. for (var i = 0; i < 30; i++) {
  4683. sin_phi = Math.sin(phi);
  4684. cos_phi = Math.cos(phi);
  4685. con = eccent * sin_phi;
  4686. 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)));
  4687. phi += dphi;
  4688. if (Math.abs(dphi) <= 0.0000000001) {
  4689. return phi;
  4690. }
  4691. }
  4692. //console.log("IQSFN-CONV:Latitude failed to converge after 30 iterations");
  4693. return NaN;
  4694. }
  4695. /*
  4696. reference:
  4697. "Cartographic Projection Procedures for the UNIX Environment-
  4698. A User's Manual" by Gerald I. Evenden,
  4699. USGS Open File Report 90-284and Release 4 Interim Reports (2003)
  4700. */
  4701. function init$g() {
  4702. //no-op
  4703. if (!this.sphere) {
  4704. this.k0 = msfnz(this.e, Math.sin(this.lat_ts), Math.cos(this.lat_ts));
  4705. }
  4706. }
  4707. /* Cylindrical Equal Area forward equations--mapping lat,long to x,y
  4708. ------------------------------------------------------------*/
  4709. function forward$f(p) {
  4710. var lon = p.x;
  4711. var lat = p.y;
  4712. var x, y;
  4713. /* Forward equations
  4714. -----------------*/
  4715. var dlon = adjust_lon(lon - this.long0);
  4716. if (this.sphere) {
  4717. x = this.x0 + this.a * dlon * Math.cos(this.lat_ts);
  4718. y = this.y0 + this.a * Math.sin(lat) / Math.cos(this.lat_ts);
  4719. }
  4720. else {
  4721. var qs = qsfnz(this.e, Math.sin(lat));
  4722. x = this.x0 + this.a * this.k0 * dlon;
  4723. y = this.y0 + this.a * qs * 0.5 / this.k0;
  4724. }
  4725. p.x = x;
  4726. p.y = y;
  4727. return p;
  4728. }
  4729. /* Cylindrical Equal Area inverse equations--mapping x,y to lat/long
  4730. ------------------------------------------------------------*/
  4731. function inverse$f(p) {
  4732. p.x -= this.x0;
  4733. p.y -= this.y0;
  4734. var lon, lat;
  4735. if (this.sphere) {
  4736. lon = adjust_lon(this.long0 + (p.x / this.a) / Math.cos(this.lat_ts));
  4737. lat = Math.asin((p.y / this.a) * Math.cos(this.lat_ts));
  4738. }
  4739. else {
  4740. lat = iqsfnz(this.e, 2 * p.y * this.k0 / this.a);
  4741. lon = adjust_lon(this.long0 + p.x / (this.a * this.k0));
  4742. }
  4743. p.x = lon;
  4744. p.y = lat;
  4745. return p;
  4746. }
  4747. var names$f = ["cea"];
  4748. var cea = {
  4749. init: init$g,
  4750. forward: forward$f,
  4751. inverse: inverse$f,
  4752. names: names$f
  4753. };
  4754. function init$f() {
  4755. this.x0 = this.x0 || 0;
  4756. this.y0 = this.y0 || 0;
  4757. this.lat0 = this.lat0 || 0;
  4758. this.long0 = this.long0 || 0;
  4759. this.lat_ts = this.lat_ts || 0;
  4760. this.title = this.title || "Equidistant Cylindrical (Plate Carre)";
  4761. this.rc = Math.cos(this.lat_ts);
  4762. }
  4763. // forward equations--mapping lat,long to x,y
  4764. // -----------------------------------------------------------------
  4765. function forward$e(p) {
  4766. var lon = p.x;
  4767. var lat = p.y;
  4768. var dlon = adjust_lon(lon - this.long0);
  4769. var dlat = adjust_lat(lat - this.lat0);
  4770. p.x = this.x0 + (this.a * dlon * this.rc);
  4771. p.y = this.y0 + (this.a * dlat);
  4772. return p;
  4773. }
  4774. // inverse equations--mapping x,y to lat/long
  4775. // -----------------------------------------------------------------
  4776. function inverse$e(p) {
  4777. var x = p.x;
  4778. var y = p.y;
  4779. p.x = adjust_lon(this.long0 + ((x - this.x0) / (this.a * this.rc)));
  4780. p.y = adjust_lat(this.lat0 + ((y - this.y0) / (this.a)));
  4781. return p;
  4782. }
  4783. var names$e = ["Equirectangular", "Equidistant_Cylindrical", "eqc"];
  4784. var eqc = {
  4785. init: init$f,
  4786. forward: forward$e,
  4787. inverse: inverse$e,
  4788. names: names$e
  4789. };
  4790. var MAX_ITER$1 = 20;
  4791. function init$e() {
  4792. /* Place parameters in static storage for common use
  4793. -------------------------------------------------*/
  4794. this.temp = this.b / this.a;
  4795. 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
  4796. this.e = Math.sqrt(this.es);
  4797. this.e0 = e0fn(this.es);
  4798. this.e1 = e1fn(this.es);
  4799. this.e2 = e2fn(this.es);
  4800. this.e3 = e3fn(this.es);
  4801. 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
  4802. }
  4803. /* Polyconic forward equations--mapping lat,long to x,y
  4804. ---------------------------------------------------*/
  4805. function forward$d(p) {
  4806. var lon = p.x;
  4807. var lat = p.y;
  4808. var x, y, el;
  4809. var dlon = adjust_lon(lon - this.long0);
  4810. el = dlon * Math.sin(lat);
  4811. if (this.sphere) {
  4812. if (Math.abs(lat) <= EPSLN) {
  4813. x = this.a * dlon;
  4814. y = -1 * this.a * this.lat0;
  4815. }
  4816. else {
  4817. x = this.a * Math.sin(el) / Math.tan(lat);
  4818. y = this.a * (adjust_lat(lat - this.lat0) + (1 - Math.cos(el)) / Math.tan(lat));
  4819. }
  4820. }
  4821. else {
  4822. if (Math.abs(lat) <= EPSLN) {
  4823. x = this.a * dlon;
  4824. y = -1 * this.ml0;
  4825. }
  4826. else {
  4827. var nl = gN(this.a, this.e, Math.sin(lat)) / Math.tan(lat);
  4828. x = nl * Math.sin(el);
  4829. y = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, lat) - this.ml0 + nl * (1 - Math.cos(el));
  4830. }
  4831. }
  4832. p.x = x + this.x0;
  4833. p.y = y + this.y0;
  4834. return p;
  4835. }
  4836. /* Inverse equations
  4837. -----------------*/
  4838. function inverse$d(p) {
  4839. var lon, lat, x, y, i;
  4840. var al, bl;
  4841. var phi, dphi;
  4842. x = p.x - this.x0;
  4843. y = p.y - this.y0;
  4844. if (this.sphere) {
  4845. if (Math.abs(y + this.a * this.lat0) <= EPSLN) {
  4846. lon = adjust_lon(x / this.a + this.long0);
  4847. lat = 0;
  4848. }
  4849. else {
  4850. al = this.lat0 + y / this.a;
  4851. bl = x * x / this.a / this.a + al * al;
  4852. phi = al;
  4853. var tanphi;
  4854. for (i = MAX_ITER$1; i; --i) {
  4855. tanphi = Math.tan(phi);
  4856. dphi = -1 * (al * (phi * tanphi + 1) - phi - 0.5 * (phi * phi + bl) * tanphi) / ((phi - al) / tanphi - 1);
  4857. phi += dphi;
  4858. if (Math.abs(dphi) <= EPSLN) {
  4859. lat = phi;
  4860. break;
  4861. }
  4862. }
  4863. lon = adjust_lon(this.long0 + (Math.asin(x * Math.tan(phi) / this.a)) / Math.sin(lat));
  4864. }
  4865. }
  4866. else {
  4867. if (Math.abs(y + this.ml0) <= EPSLN) {
  4868. lat = 0;
  4869. lon = adjust_lon(this.long0 + x / this.a);
  4870. }
  4871. else {
  4872. al = (this.ml0 + y) / this.a;
  4873. bl = x * x / this.a / this.a + al * al;
  4874. phi = al;
  4875. var cl, mln, mlnp, ma;
  4876. var con;
  4877. for (i = MAX_ITER$1; i; --i) {
  4878. con = this.e * Math.sin(phi);
  4879. cl = Math.sqrt(1 - con * con) * Math.tan(phi);
  4880. mln = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, phi);
  4881. mlnp = this.e0 - 2 * this.e1 * Math.cos(2 * phi) + 4 * this.e2 * Math.cos(4 * phi) - 6 * this.e3 * Math.cos(6 * phi);
  4882. ma = mln / this.a;
  4883. 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);
  4884. phi -= dphi;
  4885. if (Math.abs(dphi) <= EPSLN) {
  4886. lat = phi;
  4887. break;
  4888. }
  4889. }
  4890. //lat=phi4z(this.e,this.e0,this.e1,this.e2,this.e3,al,bl,0,0);
  4891. cl = Math.sqrt(1 - this.es * Math.pow(Math.sin(lat), 2)) * Math.tan(lat);
  4892. lon = adjust_lon(this.long0 + Math.asin(x * cl / this.a) / Math.sin(lat));
  4893. }
  4894. }
  4895. p.x = lon;
  4896. p.y = lat;
  4897. return p;
  4898. }
  4899. var names$d = ["Polyconic", "poly"];
  4900. var poly = {
  4901. init: init$e,
  4902. forward: forward$d,
  4903. inverse: inverse$d,
  4904. names: names$d
  4905. };
  4906. function init$d() {
  4907. this.A = [];
  4908. this.A[1] = 0.6399175073;
  4909. this.A[2] = -0.1358797613;
  4910. this.A[3] = 0.063294409;
  4911. this.A[4] = -0.02526853;
  4912. this.A[5] = 0.0117879;
  4913. this.A[6] = -0.0055161;
  4914. this.A[7] = 0.0026906;
  4915. this.A[8] = -0.001333;
  4916. this.A[9] = 0.00067;
  4917. this.A[10] = -0.00034;
  4918. this.B_re = [];
  4919. this.B_im = [];
  4920. this.B_re[1] = 0.7557853228;
  4921. this.B_im[1] = 0;
  4922. this.B_re[2] = 0.249204646;
  4923. this.B_im[2] = 0.003371507;
  4924. this.B_re[3] = -0.001541739;
  4925. this.B_im[3] = 0.041058560;
  4926. this.B_re[4] = -0.10162907;
  4927. this.B_im[4] = 0.01727609;
  4928. this.B_re[5] = -0.26623489;
  4929. this.B_im[5] = -0.36249218;
  4930. this.B_re[6] = -0.6870983;
  4931. this.B_im[6] = -1.1651967;
  4932. this.C_re = [];
  4933. this.C_im = [];
  4934. this.C_re[1] = 1.3231270439;
  4935. this.C_im[1] = 0;
  4936. this.C_re[2] = -0.577245789;
  4937. this.C_im[2] = -0.007809598;
  4938. this.C_re[3] = 0.508307513;
  4939. this.C_im[3] = -0.112208952;
  4940. this.C_re[4] = -0.15094762;
  4941. this.C_im[4] = 0.18200602;
  4942. this.C_re[5] = 1.01418179;
  4943. this.C_im[5] = 1.64497696;
  4944. this.C_re[6] = 1.9660549;
  4945. this.C_im[6] = 2.5127645;
  4946. this.D = [];
  4947. this.D[1] = 1.5627014243;
  4948. this.D[2] = 0.5185406398;
  4949. this.D[3] = -0.03333098;
  4950. this.D[4] = -0.1052906;
  4951. this.D[5] = -0.0368594;
  4952. this.D[6] = 0.007317;
  4953. this.D[7] = 0.01220;
  4954. this.D[8] = 0.00394;
  4955. this.D[9] = -0.0013;
  4956. }
  4957. /**
  4958. New Zealand Map Grid Forward - long/lat to x/y
  4959. long/lat in radians
  4960. */
  4961. function forward$c(p) {
  4962. var n;
  4963. var lon = p.x;
  4964. var lat = p.y;
  4965. var delta_lat = lat - this.lat0;
  4966. var delta_lon = lon - this.long0;
  4967. // 1. Calculate d_phi and d_psi ... // and d_lambda
  4968. // For this algorithm, delta_latitude is in seconds of arc x 10-5, so we need to scale to those units. Longitude is radians.
  4969. var d_phi = delta_lat / SEC_TO_RAD * 1E-5;
  4970. var d_lambda = delta_lon;
  4971. var d_phi_n = 1; // d_phi^0
  4972. var d_psi = 0;
  4973. for (n = 1; n <= 10; n++) {
  4974. d_phi_n = d_phi_n * d_phi;
  4975. d_psi = d_psi + this.A[n] * d_phi_n;
  4976. }
  4977. // 2. Calculate theta
  4978. var th_re = d_psi;
  4979. var th_im = d_lambda;
  4980. // 3. Calculate z
  4981. var th_n_re = 1;
  4982. var th_n_im = 0; // theta^0
  4983. var th_n_re1;
  4984. var th_n_im1;
  4985. var z_re = 0;
  4986. var z_im = 0;
  4987. for (n = 1; n <= 6; n++) {
  4988. th_n_re1 = th_n_re * th_re - th_n_im * th_im;
  4989. th_n_im1 = th_n_im * th_re + th_n_re * th_im;
  4990. th_n_re = th_n_re1;
  4991. th_n_im = th_n_im1;
  4992. z_re = z_re + this.B_re[n] * th_n_re - this.B_im[n] * th_n_im;
  4993. z_im = z_im + this.B_im[n] * th_n_re + this.B_re[n] * th_n_im;
  4994. }
  4995. // 4. Calculate easting and northing
  4996. p.x = (z_im * this.a) + this.x0;
  4997. p.y = (z_re * this.a) + this.y0;
  4998. return p;
  4999. }
  5000. /**
  5001. New Zealand Map Grid Inverse - x/y to long/lat
  5002. */
  5003. function inverse$c(p) {
  5004. var n;
  5005. var x = p.x;
  5006. var y = p.y;
  5007. var delta_x = x - this.x0;
  5008. var delta_y = y - this.y0;
  5009. // 1. Calculate z
  5010. var z_re = delta_y / this.a;
  5011. var z_im = delta_x / this.a;
  5012. // 2a. Calculate theta - first approximation gives km accuracy
  5013. var z_n_re = 1;
  5014. var z_n_im = 0; // z^0
  5015. var z_n_re1;
  5016. var z_n_im1;
  5017. var th_re = 0;
  5018. var th_im = 0;
  5019. for (n = 1; n <= 6; n++) {
  5020. z_n_re1 = z_n_re * z_re - z_n_im * z_im;
  5021. z_n_im1 = z_n_im * z_re + z_n_re * z_im;
  5022. z_n_re = z_n_re1;
  5023. z_n_im = z_n_im1;
  5024. th_re = th_re + this.C_re[n] * z_n_re - this.C_im[n] * z_n_im;
  5025. th_im = th_im + this.C_im[n] * z_n_re + this.C_re[n] * z_n_im;
  5026. }
  5027. // 2b. Iterate to refine the accuracy of the calculation
  5028. // 0 iterations gives km accuracy
  5029. // 1 iteration gives m accuracy -- good enough for most mapping applications
  5030. // 2 iterations bives mm accuracy
  5031. for (var i = 0; i < this.iterations; i++) {
  5032. var th_n_re = th_re;
  5033. var th_n_im = th_im;
  5034. var th_n_re1;
  5035. var th_n_im1;
  5036. var num_re = z_re;
  5037. var num_im = z_im;
  5038. for (n = 2; n <= 6; n++) {
  5039. th_n_re1 = th_n_re * th_re - th_n_im * th_im;
  5040. th_n_im1 = th_n_im * th_re + th_n_re * th_im;
  5041. th_n_re = th_n_re1;
  5042. th_n_im = th_n_im1;
  5043. num_re = num_re + (n - 1) * (this.B_re[n] * th_n_re - this.B_im[n] * th_n_im);
  5044. num_im = num_im + (n - 1) * (this.B_im[n] * th_n_re + this.B_re[n] * th_n_im);
  5045. }
  5046. th_n_re = 1;
  5047. th_n_im = 0;
  5048. var den_re = this.B_re[1];
  5049. var den_im = this.B_im[1];
  5050. for (n = 2; n <= 6; n++) {
  5051. th_n_re1 = th_n_re * th_re - th_n_im * th_im;
  5052. th_n_im1 = th_n_im * th_re + th_n_re * th_im;
  5053. th_n_re = th_n_re1;
  5054. th_n_im = th_n_im1;
  5055. den_re = den_re + n * (this.B_re[n] * th_n_re - this.B_im[n] * th_n_im);
  5056. den_im = den_im + n * (this.B_im[n] * th_n_re + this.B_re[n] * th_n_im);
  5057. }
  5058. // Complex division
  5059. var den2 = den_re * den_re + den_im * den_im;
  5060. th_re = (num_re * den_re + num_im * den_im) / den2;
  5061. th_im = (num_im * den_re - num_re * den_im) / den2;
  5062. }
  5063. // 3. Calculate d_phi ... // and d_lambda
  5064. var d_psi = th_re;
  5065. var d_lambda = th_im;
  5066. var d_psi_n = 1; // d_psi^0
  5067. var d_phi = 0;
  5068. for (n = 1; n <= 9; n++) {
  5069. d_psi_n = d_psi_n * d_psi;
  5070. d_phi = d_phi + this.D[n] * d_psi_n;
  5071. }
  5072. // 4. Calculate latitude and longitude
  5073. // d_phi is calcuated in second of arc * 10^-5, so we need to scale back to radians. d_lambda is in radians.
  5074. var lat = this.lat0 + (d_phi * SEC_TO_RAD * 1E5);
  5075. var lon = this.long0 + d_lambda;
  5076. p.x = lon;
  5077. p.y = lat;
  5078. return p;
  5079. }
  5080. var names$c = ["New_Zealand_Map_Grid", "nzmg"];
  5081. var nzmg = {
  5082. init: init$d,
  5083. forward: forward$c,
  5084. inverse: inverse$c,
  5085. names: names$c
  5086. };
  5087. /*
  5088. reference
  5089. "New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
  5090. The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
  5091. */
  5092. /* Initialize the Miller Cylindrical projection
  5093. -------------------------------------------*/
  5094. function init$c() {
  5095. //no-op
  5096. }
  5097. /* Miller Cylindrical forward equations--mapping lat,long to x,y
  5098. ------------------------------------------------------------*/
  5099. function forward$b(p) {
  5100. var lon = p.x;
  5101. var lat = p.y;
  5102. /* Forward equations
  5103. -----------------*/
  5104. var dlon = adjust_lon(lon - this.long0);
  5105. var x = this.x0 + this.a * dlon;
  5106. var y = this.y0 + this.a * Math.log(Math.tan((Math.PI / 4) + (lat / 2.5))) * 1.25;
  5107. p.x = x;
  5108. p.y = y;
  5109. return p;
  5110. }
  5111. /* Miller Cylindrical inverse equations--mapping x,y to lat/long
  5112. ------------------------------------------------------------*/
  5113. function inverse$b(p) {
  5114. p.x -= this.x0;
  5115. p.y -= this.y0;
  5116. var lon = adjust_lon(this.long0 + p.x / this.a);
  5117. var lat = 2.5 * (Math.atan(Math.exp(0.8 * p.y / this.a)) - Math.PI / 4);
  5118. p.x = lon;
  5119. p.y = lat;
  5120. return p;
  5121. }
  5122. var names$b = ["Miller_Cylindrical", "mill"];
  5123. var mill = {
  5124. init: init$c,
  5125. forward: forward$b,
  5126. inverse: inverse$b,
  5127. names: names$b
  5128. };
  5129. var MAX_ITER = 20;
  5130. function init$b() {
  5131. /* Place parameters in static storage for common use
  5132. -------------------------------------------------*/
  5133. if (!this.sphere) {
  5134. this.en = pj_enfn(this.es);
  5135. }
  5136. else {
  5137. this.n = 1;
  5138. this.m = 0;
  5139. this.es = 0;
  5140. this.C_y = Math.sqrt((this.m + 1) / this.n);
  5141. this.C_x = this.C_y / (this.m + 1);
  5142. }
  5143. }
  5144. /* Sinusoidal forward equations--mapping lat,long to x,y
  5145. -----------------------------------------------------*/
  5146. function forward$a(p) {
  5147. var x, y;
  5148. var lon = p.x;
  5149. var lat = p.y;
  5150. /* Forward equations
  5151. -----------------*/
  5152. lon = adjust_lon(lon - this.long0);
  5153. if (this.sphere) {
  5154. if (!this.m) {
  5155. lat = this.n !== 1 ? Math.asin(this.n * Math.sin(lat)) : lat;
  5156. }
  5157. else {
  5158. var k = this.n * Math.sin(lat);
  5159. for (var i = MAX_ITER; i; --i) {
  5160. var V = (this.m * lat + Math.sin(lat) - k) / (this.m + Math.cos(lat));
  5161. lat -= V;
  5162. if (Math.abs(V) < EPSLN) {
  5163. break;
  5164. }
  5165. }
  5166. }
  5167. x = this.a * this.C_x * lon * (this.m + Math.cos(lat));
  5168. y = this.a * this.C_y * lat;
  5169. }
  5170. else {
  5171. var s = Math.sin(lat);
  5172. var c = Math.cos(lat);
  5173. y = this.a * pj_mlfn(lat, s, c, this.en);
  5174. x = this.a * lon * c / Math.sqrt(1 - this.es * s * s);
  5175. }
  5176. p.x = x;
  5177. p.y = y;
  5178. return p;
  5179. }
  5180. function inverse$a(p) {
  5181. var lat, temp, lon, s;
  5182. p.x -= this.x0;
  5183. lon = p.x / this.a;
  5184. p.y -= this.y0;
  5185. lat = p.y / this.a;
  5186. if (this.sphere) {
  5187. lat /= this.C_y;
  5188. lon = lon / (this.C_x * (this.m + Math.cos(lat)));
  5189. if (this.m) {
  5190. lat = asinz((this.m * lat + Math.sin(lat)) / this.n);
  5191. }
  5192. else if (this.n !== 1) {
  5193. lat = asinz(Math.sin(lat) / this.n);
  5194. }
  5195. lon = adjust_lon(lon + this.long0);
  5196. lat = adjust_lat(lat);
  5197. }
  5198. else {
  5199. lat = pj_inv_mlfn(p.y / this.a, this.es, this.en);
  5200. s = Math.abs(lat);
  5201. if (s < HALF_PI) {
  5202. s = Math.sin(lat);
  5203. temp = this.long0 + p.x * Math.sqrt(1 - this.es * s * s) / (this.a * Math.cos(lat));
  5204. //temp = this.long0 + p.x / (this.a * Math.cos(lat));
  5205. lon = adjust_lon(temp);
  5206. }
  5207. else if ((s - EPSLN) < HALF_PI) {
  5208. lon = this.long0;
  5209. }
  5210. }
  5211. p.x = lon;
  5212. p.y = lat;
  5213. return p;
  5214. }
  5215. var names$a = ["Sinusoidal", "sinu"];
  5216. var sinu = {
  5217. init: init$b,
  5218. forward: forward$a,
  5219. inverse: inverse$a,
  5220. names: names$a
  5221. };
  5222. function init$a() {}
  5223. /* Mollweide forward equations--mapping lat,long to x,y
  5224. ----------------------------------------------------*/
  5225. function forward$9(p) {
  5226. /* Forward equations
  5227. -----------------*/
  5228. var lon = p.x;
  5229. var lat = p.y;
  5230. var delta_lon = adjust_lon(lon - this.long0);
  5231. var theta = lat;
  5232. var con = Math.PI * Math.sin(lat);
  5233. /* Iterate using the Newton-Raphson method to find theta
  5234. -----------------------------------------------------*/
  5235. while (true) {
  5236. var delta_theta = -(theta + Math.sin(theta) - con) / (1 + Math.cos(theta));
  5237. theta += delta_theta;
  5238. if (Math.abs(delta_theta) < EPSLN) {
  5239. break;
  5240. }
  5241. }
  5242. theta /= 2;
  5243. /* If the latitude is 90 deg, force the x coordinate to be "0 + false easting"
  5244. this is done here because of precision problems with "cos(theta)"
  5245. --------------------------------------------------------------------------*/
  5246. if (Math.PI / 2 - Math.abs(lat) < EPSLN) {
  5247. delta_lon = 0;
  5248. }
  5249. var x = 0.900316316158 * this.a * delta_lon * Math.cos(theta) + this.x0;
  5250. var y = 1.4142135623731 * this.a * Math.sin(theta) + this.y0;
  5251. p.x = x;
  5252. p.y = y;
  5253. return p;
  5254. }
  5255. function inverse$9(p) {
  5256. var theta;
  5257. var arg;
  5258. /* Inverse equations
  5259. -----------------*/
  5260. p.x -= this.x0;
  5261. p.y -= this.y0;
  5262. arg = p.y / (1.4142135623731 * this.a);
  5263. /* Because of division by zero problems, 'arg' can not be 1. Therefore
  5264. a number very close to one is used instead.
  5265. -------------------------------------------------------------------*/
  5266. if (Math.abs(arg) > 0.999999999999) {
  5267. arg = 0.999999999999;
  5268. }
  5269. theta = Math.asin(arg);
  5270. var lon = adjust_lon(this.long0 + (p.x / (0.900316316158 * this.a * Math.cos(theta))));
  5271. if (lon < (-Math.PI)) {
  5272. lon = -Math.PI;
  5273. }
  5274. if (lon > Math.PI) {
  5275. lon = Math.PI;
  5276. }
  5277. arg = (2 * theta + Math.sin(2 * theta)) / Math.PI;
  5278. if (Math.abs(arg) > 1) {
  5279. arg = 1;
  5280. }
  5281. var lat = Math.asin(arg);
  5282. p.x = lon;
  5283. p.y = lat;
  5284. return p;
  5285. }
  5286. var names$9 = ["Mollweide", "moll"];
  5287. var moll = {
  5288. init: init$a,
  5289. forward: forward$9,
  5290. inverse: inverse$9,
  5291. names: names$9
  5292. };
  5293. function init$9() {
  5294. /* Place parameters in static storage for common use
  5295. -------------------------------------------------*/
  5296. // Standard Parallels cannot be equal and on opposite sides of the equator
  5297. if (Math.abs(this.lat1 + this.lat2) < EPSLN) {
  5298. return;
  5299. }
  5300. this.lat2 = this.lat2 || this.lat1;
  5301. this.temp = this.b / this.a;
  5302. this.es = 1 - Math.pow(this.temp, 2);
  5303. this.e = Math.sqrt(this.es);
  5304. this.e0 = e0fn(this.es);
  5305. this.e1 = e1fn(this.es);
  5306. this.e2 = e2fn(this.es);
  5307. this.e3 = e3fn(this.es);
  5308. this.sinphi = Math.sin(this.lat1);
  5309. this.cosphi = Math.cos(this.lat1);
  5310. this.ms1 = msfnz(this.e, this.sinphi, this.cosphi);
  5311. this.ml1 = mlfn(this.e0, this.e1, this.e2, this.e3, this.lat1);
  5312. if (Math.abs(this.lat1 - this.lat2) < EPSLN) {
  5313. this.ns = this.sinphi;
  5314. }
  5315. else {
  5316. this.sinphi = Math.sin(this.lat2);
  5317. this.cosphi = Math.cos(this.lat2);
  5318. this.ms2 = msfnz(this.e, this.sinphi, this.cosphi);
  5319. this.ml2 = mlfn(this.e0, this.e1, this.e2, this.e3, this.lat2);
  5320. this.ns = (this.ms1 - this.ms2) / (this.ml2 - this.ml1);
  5321. }
  5322. this.g = this.ml1 + this.ms1 / this.ns;
  5323. this.ml0 = mlfn(this.e0, this.e1, this.e2, this.e3, this.lat0);
  5324. this.rh = this.a * (this.g - this.ml0);
  5325. }
  5326. /* Equidistant Conic forward equations--mapping lat,long to x,y
  5327. -----------------------------------------------------------*/
  5328. function forward$8(p) {
  5329. var lon = p.x;
  5330. var lat = p.y;
  5331. var rh1;
  5332. /* Forward equations
  5333. -----------------*/
  5334. if (this.sphere) {
  5335. rh1 = this.a * (this.g - lat);
  5336. }
  5337. else {
  5338. var ml = mlfn(this.e0, this.e1, this.e2, this.e3, lat);
  5339. rh1 = this.a * (this.g - ml);
  5340. }
  5341. var theta = this.ns * adjust_lon(lon - this.long0);
  5342. var x = this.x0 + rh1 * Math.sin(theta);
  5343. var y = this.y0 + this.rh - rh1 * Math.cos(theta);
  5344. p.x = x;
  5345. p.y = y;
  5346. return p;
  5347. }
  5348. /* Inverse equations
  5349. -----------------*/
  5350. function inverse$8(p) {
  5351. p.x -= this.x0;
  5352. p.y = this.rh - p.y + this.y0;
  5353. var con, rh1, lat, lon;
  5354. if (this.ns >= 0) {
  5355. rh1 = Math.sqrt(p.x * p.x + p.y * p.y);
  5356. con = 1;
  5357. }
  5358. else {
  5359. rh1 = -Math.sqrt(p.x * p.x + p.y * p.y);
  5360. con = -1;
  5361. }
  5362. var theta = 0;
  5363. if (rh1 !== 0) {
  5364. theta = Math.atan2(con * p.x, con * p.y);
  5365. }
  5366. if (this.sphere) {
  5367. lon = adjust_lon(this.long0 + theta / this.ns);
  5368. lat = adjust_lat(this.g - rh1 / this.a);
  5369. p.x = lon;
  5370. p.y = lat;
  5371. return p;
  5372. }
  5373. else {
  5374. var ml = this.g - rh1 / this.a;
  5375. lat = imlfn(ml, this.e0, this.e1, this.e2, this.e3);
  5376. lon = adjust_lon(this.long0 + theta / this.ns);
  5377. p.x = lon;
  5378. p.y = lat;
  5379. return p;
  5380. }
  5381. }
  5382. var names$8 = ["Equidistant_Conic", "eqdc"];
  5383. var eqdc = {
  5384. init: init$9,
  5385. forward: forward$8,
  5386. inverse: inverse$8,
  5387. names: names$8
  5388. };
  5389. /* Initialize the Van Der Grinten projection
  5390. ----------------------------------------*/
  5391. function init$8() {
  5392. //this.R = 6370997; //Radius of earth
  5393. this.R = this.a;
  5394. }
  5395. function forward$7(p) {
  5396. var lon = p.x;
  5397. var lat = p.y;
  5398. /* Forward equations
  5399. -----------------*/
  5400. var dlon = adjust_lon(lon - this.long0);
  5401. var x, y;
  5402. if (Math.abs(lat) <= EPSLN) {
  5403. x = this.x0 + this.R * dlon;
  5404. y = this.y0;
  5405. }
  5406. var theta = asinz(2 * Math.abs(lat / Math.PI));
  5407. if ((Math.abs(dlon) <= EPSLN) || (Math.abs(Math.abs(lat) - HALF_PI) <= EPSLN)) {
  5408. x = this.x0;
  5409. if (lat >= 0) {
  5410. y = this.y0 + Math.PI * this.R * Math.tan(0.5 * theta);
  5411. }
  5412. else {
  5413. y = this.y0 + Math.PI * this.R * -Math.tan(0.5 * theta);
  5414. }
  5415. // return(OK);
  5416. }
  5417. var al = 0.5 * Math.abs((Math.PI / dlon) - (dlon / Math.PI));
  5418. var asq = al * al;
  5419. var sinth = Math.sin(theta);
  5420. var costh = Math.cos(theta);
  5421. var g = costh / (sinth + costh - 1);
  5422. var gsq = g * g;
  5423. var m = g * (2 / sinth - 1);
  5424. var msq = m * m;
  5425. var con = Math.PI * this.R * (al * (g - msq) + Math.sqrt(asq * (g - msq) * (g - msq) - (msq + asq) * (gsq - msq))) / (msq + asq);
  5426. if (dlon < 0) {
  5427. con = -con;
  5428. }
  5429. x = this.x0 + con;
  5430. //con = Math.abs(con / (Math.PI * this.R));
  5431. var q = asq + g;
  5432. con = Math.PI * this.R * (m * q - al * Math.sqrt((msq + asq) * (asq + 1) - q * q)) / (msq + asq);
  5433. if (lat >= 0) {
  5434. //y = this.y0 + Math.PI * this.R * Math.sqrt(1 - con * con - 2 * al * con);
  5435. y = this.y0 + con;
  5436. }
  5437. else {
  5438. //y = this.y0 - Math.PI * this.R * Math.sqrt(1 - con * con - 2 * al * con);
  5439. y = this.y0 - con;
  5440. }
  5441. p.x = x;
  5442. p.y = y;
  5443. return p;
  5444. }
  5445. /* Van Der Grinten inverse equations--mapping x,y to lat/long
  5446. ---------------------------------------------------------*/
  5447. function inverse$7(p) {
  5448. var lon, lat;
  5449. var xx, yy, xys, c1, c2, c3;
  5450. var a1;
  5451. var m1;
  5452. var con;
  5453. var th1;
  5454. var d;
  5455. /* inverse equations
  5456. -----------------*/
  5457. p.x -= this.x0;
  5458. p.y -= this.y0;
  5459. con = Math.PI * this.R;
  5460. xx = p.x / con;
  5461. yy = p.y / con;
  5462. xys = xx * xx + yy * yy;
  5463. c1 = -Math.abs(yy) * (1 + xys);
  5464. c2 = c1 - 2 * yy * yy + xx * xx;
  5465. c3 = -2 * c1 + 1 + 2 * yy * yy + xys * xys;
  5466. d = yy * yy / c3 + (2 * c2 * c2 * c2 / c3 / c3 / c3 - 9 * c1 * c2 / c3 / c3) / 27;
  5467. a1 = (c1 - c2 * c2 / 3 / c3) / c3;
  5468. m1 = 2 * Math.sqrt(-a1 / 3);
  5469. con = ((3 * d) / a1) / m1;
  5470. if (Math.abs(con) > 1) {
  5471. if (con >= 0) {
  5472. con = 1;
  5473. }
  5474. else {
  5475. con = -1;
  5476. }
  5477. }
  5478. th1 = Math.acos(con) / 3;
  5479. if (p.y >= 0) {
  5480. lat = (-m1 * Math.cos(th1 + Math.PI / 3) - c2 / 3 / c3) * Math.PI;
  5481. }
  5482. else {
  5483. lat = -(-m1 * Math.cos(th1 + Math.PI / 3) - c2 / 3 / c3) * Math.PI;
  5484. }
  5485. if (Math.abs(xx) < EPSLN) {
  5486. lon = this.long0;
  5487. }
  5488. else {
  5489. lon = adjust_lon(this.long0 + Math.PI * (xys - 1 + Math.sqrt(1 + 2 * (xx * xx - yy * yy) + xys * xys)) / 2 / xx);
  5490. }
  5491. p.x = lon;
  5492. p.y = lat;
  5493. return p;
  5494. }
  5495. var names$7 = ["Van_der_Grinten_I", "VanDerGrinten", "vandg"];
  5496. var vandg = {
  5497. init: init$8,
  5498. forward: forward$7,
  5499. inverse: inverse$7,
  5500. names: names$7
  5501. };
  5502. function init$7() {
  5503. this.sin_p12 = Math.sin(this.lat0);
  5504. this.cos_p12 = Math.cos(this.lat0);
  5505. }
  5506. function forward$6(p) {
  5507. var lon = p.x;
  5508. var lat = p.y;
  5509. var sinphi = Math.sin(p.y);
  5510. var cosphi = Math.cos(p.y);
  5511. var dlon = adjust_lon(lon - this.long0);
  5512. 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;
  5513. if (this.sphere) {
  5514. if (Math.abs(this.sin_p12 - 1) <= EPSLN) {
  5515. //North Pole case
  5516. p.x = this.x0 + this.a * (HALF_PI - lat) * Math.sin(dlon);
  5517. p.y = this.y0 - this.a * (HALF_PI - lat) * Math.cos(dlon);
  5518. return p;
  5519. }
  5520. else if (Math.abs(this.sin_p12 + 1) <= EPSLN) {
  5521. //South Pole case
  5522. p.x = this.x0 + this.a * (HALF_PI + lat) * Math.sin(dlon);
  5523. p.y = this.y0 + this.a * (HALF_PI + lat) * Math.cos(dlon);
  5524. return p;
  5525. }
  5526. else {
  5527. //default case
  5528. cos_c = this.sin_p12 * sinphi + this.cos_p12 * cosphi * Math.cos(dlon);
  5529. c = Math.acos(cos_c);
  5530. kp = c ? c / Math.sin(c) : 1;
  5531. p.x = this.x0 + this.a * kp * cosphi * Math.sin(dlon);
  5532. p.y = this.y0 + this.a * kp * (this.cos_p12 * sinphi - this.sin_p12 * cosphi * Math.cos(dlon));
  5533. return p;
  5534. }
  5535. }
  5536. else {
  5537. e0 = e0fn(this.es);
  5538. e1 = e1fn(this.es);
  5539. e2 = e2fn(this.es);
  5540. e3 = e3fn(this.es);
  5541. if (Math.abs(this.sin_p12 - 1) <= EPSLN) {
  5542. //North Pole case
  5543. Mlp = this.a * mlfn(e0, e1, e2, e3, HALF_PI);
  5544. Ml = this.a * mlfn(e0, e1, e2, e3, lat);
  5545. p.x = this.x0 + (Mlp - Ml) * Math.sin(dlon);
  5546. p.y = this.y0 - (Mlp - Ml) * Math.cos(dlon);
  5547. return p;
  5548. }
  5549. else if (Math.abs(this.sin_p12 + 1) <= EPSLN) {
  5550. //South Pole case
  5551. Mlp = this.a * mlfn(e0, e1, e2, e3, HALF_PI);
  5552. Ml = this.a * mlfn(e0, e1, e2, e3, lat);
  5553. p.x = this.x0 + (Mlp + Ml) * Math.sin(dlon);
  5554. p.y = this.y0 + (Mlp + Ml) * Math.cos(dlon);
  5555. return p;
  5556. }
  5557. else {
  5558. //Default case
  5559. tanphi = sinphi / cosphi;
  5560. Nl1 = gN(this.a, this.e, this.sin_p12);
  5561. Nl = gN(this.a, this.e, sinphi);
  5562. psi = Math.atan((1 - this.es) * tanphi + this.es * Nl1 * this.sin_p12 / (Nl * cosphi));
  5563. Az = Math.atan2(Math.sin(dlon), this.cos_p12 * Math.tan(psi) - this.sin_p12 * Math.cos(dlon));
  5564. if (Az === 0) {
  5565. s = Math.asin(this.cos_p12 * Math.sin(psi) - this.sin_p12 * Math.cos(psi));
  5566. }
  5567. else if (Math.abs(Math.abs(Az) - Math.PI) <= EPSLN) {
  5568. s = -Math.asin(this.cos_p12 * Math.sin(psi) - this.sin_p12 * Math.cos(psi));
  5569. }
  5570. else {
  5571. s = Math.asin(Math.sin(dlon) * Math.cos(psi) / Math.sin(Az));
  5572. }
  5573. G = this.e * this.sin_p12 / Math.sqrt(1 - this.es);
  5574. H = this.e * this.cos_p12 * Math.cos(Az) / Math.sqrt(1 - this.es);
  5575. GH = G * H;
  5576. Hs = H * H;
  5577. s2 = s * s;
  5578. s3 = s2 * s;
  5579. s4 = s3 * s;
  5580. s5 = s4 * s;
  5581. 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);
  5582. p.x = this.x0 + c * Math.sin(Az);
  5583. p.y = this.y0 + c * Math.cos(Az);
  5584. return p;
  5585. }
  5586. }
  5587. }
  5588. function inverse$6(p) {
  5589. p.x -= this.x0;
  5590. p.y -= this.y0;
  5591. 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;
  5592. if (this.sphere) {
  5593. rh = Math.sqrt(p.x * p.x + p.y * p.y);
  5594. if (rh > (2 * HALF_PI * this.a)) {
  5595. return;
  5596. }
  5597. z = rh / this.a;
  5598. sinz = Math.sin(z);
  5599. cosz = Math.cos(z);
  5600. lon = this.long0;
  5601. if (Math.abs(rh) <= EPSLN) {
  5602. lat = this.lat0;
  5603. }
  5604. else {
  5605. lat = asinz(cosz * this.sin_p12 + (p.y * sinz * this.cos_p12) / rh);
  5606. con = Math.abs(this.lat0) - HALF_PI;
  5607. if (Math.abs(con) <= EPSLN) {
  5608. if (this.lat0 >= 0) {
  5609. lon = adjust_lon(this.long0 + Math.atan2(p.x, - p.y));
  5610. }
  5611. else {
  5612. lon = adjust_lon(this.long0 - Math.atan2(-p.x, p.y));
  5613. }
  5614. }
  5615. else {
  5616. /*con = cosz - this.sin_p12 * Math.sin(lat);
  5617. if ((Math.abs(con) < EPSLN) && (Math.abs(p.x) < EPSLN)) {
  5618. //no-op, just keep the lon value as is
  5619. } else {
  5620. var temp = Math.atan2((p.x * sinz * this.cos_p12), (con * rh));
  5621. lon = adjust_lon(this.long0 + Math.atan2((p.x * sinz * this.cos_p12), (con * rh)));
  5622. }*/
  5623. lon = adjust_lon(this.long0 + Math.atan2(p.x * sinz, rh * this.cos_p12 * cosz - p.y * this.sin_p12 * sinz));
  5624. }
  5625. }
  5626. p.x = lon;
  5627. p.y = lat;
  5628. return p;
  5629. }
  5630. else {
  5631. e0 = e0fn(this.es);
  5632. e1 = e1fn(this.es);
  5633. e2 = e2fn(this.es);
  5634. e3 = e3fn(this.es);
  5635. if (Math.abs(this.sin_p12 - 1) <= EPSLN) {
  5636. //North pole case
  5637. Mlp = this.a * mlfn(e0, e1, e2, e3, HALF_PI);
  5638. rh = Math.sqrt(p.x * p.x + p.y * p.y);
  5639. M = Mlp - rh;
  5640. lat = imlfn(M / this.a, e0, e1, e2, e3);
  5641. lon = adjust_lon(this.long0 + Math.atan2(p.x, - 1 * p.y));
  5642. p.x = lon;
  5643. p.y = lat;
  5644. return p;
  5645. }
  5646. else if (Math.abs(this.sin_p12 + 1) <= EPSLN) {
  5647. //South pole case
  5648. Mlp = this.a * mlfn(e0, e1, e2, e3, HALF_PI);
  5649. rh = Math.sqrt(p.x * p.x + p.y * p.y);
  5650. M = rh - Mlp;
  5651. lat = imlfn(M / this.a, e0, e1, e2, e3);
  5652. lon = adjust_lon(this.long0 + Math.atan2(p.x, p.y));
  5653. p.x = lon;
  5654. p.y = lat;
  5655. return p;
  5656. }
  5657. else {
  5658. //default case
  5659. rh = Math.sqrt(p.x * p.x + p.y * p.y);
  5660. Az = Math.atan2(p.x, p.y);
  5661. N1 = gN(this.a, this.e, this.sin_p12);
  5662. cosAz = Math.cos(Az);
  5663. tmp = this.e * this.cos_p12 * cosAz;
  5664. A = -tmp * tmp / (1 - this.es);
  5665. B = 3 * this.es * (1 - A) * this.sin_p12 * this.cos_p12 * cosAz / (1 - this.es);
  5666. D = rh / N1;
  5667. Ee = D - A * (1 + A) * Math.pow(D, 3) / 6 - B * (1 + 3 * A) * Math.pow(D, 4) / 24;
  5668. F = 1 - A * Ee * Ee / 2 - D * Ee * Ee * Ee / 6;
  5669. psi = Math.asin(this.sin_p12 * Math.cos(Ee) + this.cos_p12 * Math.sin(Ee) * cosAz);
  5670. lon = adjust_lon(this.long0 + Math.asin(Math.sin(Az) * Math.sin(Ee) / Math.cos(psi)));
  5671. sinpsi = Math.sin(psi);
  5672. lat = Math.atan2((sinpsi - this.es * F * this.sin_p12) * Math.tan(psi), sinpsi * (1 - this.es));
  5673. p.x = lon;
  5674. p.y = lat;
  5675. return p;
  5676. }
  5677. }
  5678. }
  5679. var names$6 = ["Azimuthal_Equidistant", "aeqd"];
  5680. var aeqd = {
  5681. init: init$7,
  5682. forward: forward$6,
  5683. inverse: inverse$6,
  5684. names: names$6
  5685. };
  5686. function init$6() {
  5687. //double temp; /* temporary variable */
  5688. /* Place parameters in static storage for common use
  5689. -------------------------------------------------*/
  5690. this.sin_p14 = Math.sin(this.lat0);
  5691. this.cos_p14 = Math.cos(this.lat0);
  5692. }
  5693. /* Orthographic forward equations--mapping lat,long to x,y
  5694. ---------------------------------------------------*/
  5695. function forward$5(p) {
  5696. var sinphi, cosphi; /* sin and cos value */
  5697. var dlon; /* delta longitude value */
  5698. var coslon; /* cos of longitude */
  5699. var ksp; /* scale factor */
  5700. var g, x, y;
  5701. var lon = p.x;
  5702. var lat = p.y;
  5703. /* Forward equations
  5704. -----------------*/
  5705. dlon = adjust_lon(lon - this.long0);
  5706. sinphi = Math.sin(lat);
  5707. cosphi = Math.cos(lat);
  5708. coslon = Math.cos(dlon);
  5709. g = this.sin_p14 * sinphi + this.cos_p14 * cosphi * coslon;
  5710. ksp = 1;
  5711. if ((g > 0) || (Math.abs(g) <= EPSLN)) {
  5712. x = this.a * ksp * cosphi * Math.sin(dlon);
  5713. y = this.y0 + this.a * ksp * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon);
  5714. }
  5715. p.x = x;
  5716. p.y = y;
  5717. return p;
  5718. }
  5719. function inverse$5(p) {
  5720. var rh; /* height above ellipsoid */
  5721. var z; /* angle */
  5722. var sinz, cosz; /* sin of z and cos of z */
  5723. var con;
  5724. var lon, lat;
  5725. /* Inverse equations
  5726. -----------------*/
  5727. p.x -= this.x0;
  5728. p.y -= this.y0;
  5729. rh = Math.sqrt(p.x * p.x + p.y * p.y);
  5730. z = asinz(rh / this.a);
  5731. sinz = Math.sin(z);
  5732. cosz = Math.cos(z);
  5733. lon = this.long0;
  5734. if (Math.abs(rh) <= EPSLN) {
  5735. lat = this.lat0;
  5736. p.x = lon;
  5737. p.y = lat;
  5738. return p;
  5739. }
  5740. lat = asinz(cosz * this.sin_p14 + (p.y * sinz * this.cos_p14) / rh);
  5741. con = Math.abs(this.lat0) - HALF_PI;
  5742. if (Math.abs(con) <= EPSLN) {
  5743. if (this.lat0 >= 0) {
  5744. lon = adjust_lon(this.long0 + Math.atan2(p.x, - p.y));
  5745. }
  5746. else {
  5747. lon = adjust_lon(this.long0 - Math.atan2(-p.x, p.y));
  5748. }
  5749. p.x = lon;
  5750. p.y = lat;
  5751. return p;
  5752. }
  5753. lon = adjust_lon(this.long0 + Math.atan2((p.x * sinz), rh * this.cos_p14 * cosz - p.y * this.sin_p14 * sinz));
  5754. p.x = lon;
  5755. p.y = lat;
  5756. return p;
  5757. }
  5758. var names$5 = ["ortho"];
  5759. var ortho = {
  5760. init: init$6,
  5761. forward: forward$5,
  5762. inverse: inverse$5,
  5763. names: names$5
  5764. };
  5765. // QSC projection rewritten from the original PROJ4
  5766. // https://github.com/OSGeo/proj.4/blob/master/src/PJ_qsc.c
  5767. /* constants */
  5768. var FACE_ENUM = {
  5769. FRONT: 1,
  5770. RIGHT: 2,
  5771. BACK: 3,
  5772. LEFT: 4,
  5773. TOP: 5,
  5774. BOTTOM: 6
  5775. };
  5776. var AREA_ENUM = {
  5777. AREA_0: 1,
  5778. AREA_1: 2,
  5779. AREA_2: 3,
  5780. AREA_3: 4
  5781. };
  5782. function init$5() {
  5783. this.x0 = this.x0 || 0;
  5784. this.y0 = this.y0 || 0;
  5785. this.lat0 = this.lat0 || 0;
  5786. this.long0 = this.long0 || 0;
  5787. this.lat_ts = this.lat_ts || 0;
  5788. this.title = this.title || "Quadrilateralized Spherical Cube";
  5789. /* Determine the cube face from the center of projection. */
  5790. if (this.lat0 >= HALF_PI - FORTPI / 2.0) {
  5791. this.face = FACE_ENUM.TOP;
  5792. } else if (this.lat0 <= -(HALF_PI - FORTPI / 2.0)) {
  5793. this.face = FACE_ENUM.BOTTOM;
  5794. } else if (Math.abs(this.long0) <= FORTPI) {
  5795. this.face = FACE_ENUM.FRONT;
  5796. } else if (Math.abs(this.long0) <= HALF_PI + FORTPI) {
  5797. this.face = this.long0 > 0.0 ? FACE_ENUM.RIGHT : FACE_ENUM.LEFT;
  5798. } else {
  5799. this.face = FACE_ENUM.BACK;
  5800. }
  5801. /* Fill in useful values for the ellipsoid <-> sphere shift
  5802. * described in [LK12]. */
  5803. if (this.es !== 0) {
  5804. this.one_minus_f = 1 - (this.a - this.b) / this.a;
  5805. this.one_minus_f_squared = this.one_minus_f * this.one_minus_f;
  5806. }
  5807. }
  5808. // QSC forward equations--mapping lat,long to x,y
  5809. // -----------------------------------------------------------------
  5810. function forward$4(p) {
  5811. var xy = {x: 0, y: 0};
  5812. var lat, lon;
  5813. var theta, phi;
  5814. var t, mu;
  5815. /* nu; */
  5816. var area = {value: 0};
  5817. // move lon according to projection's lon
  5818. p.x -= this.long0;
  5819. /* Convert the geodetic latitude to a geocentric latitude.
  5820. * This corresponds to the shift from the ellipsoid to the sphere
  5821. * described in [LK12]. */
  5822. if (this.es !== 0) {//if (P->es != 0) {
  5823. lat = Math.atan(this.one_minus_f_squared * Math.tan(p.y));
  5824. } else {
  5825. lat = p.y;
  5826. }
  5827. /* Convert the input lat, lon into theta, phi as used by QSC.
  5828. * This depends on the cube face and the area on it.
  5829. * For the top and bottom face, we can compute theta and phi
  5830. * directly from phi, lam. For the other faces, we must use
  5831. * unit sphere cartesian coordinates as an intermediate step. */
  5832. lon = p.x; //lon = lp.lam;
  5833. if (this.face === FACE_ENUM.TOP) {
  5834. phi = HALF_PI - lat;
  5835. if (lon >= FORTPI && lon <= HALF_PI + FORTPI) {
  5836. area.value = AREA_ENUM.AREA_0;
  5837. theta = lon - HALF_PI;
  5838. } else if (lon > HALF_PI + FORTPI || lon <= -(HALF_PI + FORTPI)) {
  5839. area.value = AREA_ENUM.AREA_1;
  5840. theta = (lon > 0.0 ? lon - SPI : lon + SPI);
  5841. } else if (lon > -(HALF_PI + FORTPI) && lon <= -FORTPI) {
  5842. area.value = AREA_ENUM.AREA_2;
  5843. theta = lon + HALF_PI;
  5844. } else {
  5845. area.value = AREA_ENUM.AREA_3;
  5846. theta = lon;
  5847. }
  5848. } else if (this.face === FACE_ENUM.BOTTOM) {
  5849. phi = HALF_PI + lat;
  5850. if (lon >= FORTPI && lon <= HALF_PI + FORTPI) {
  5851. area.value = AREA_ENUM.AREA_0;
  5852. theta = -lon + HALF_PI;
  5853. } else if (lon < FORTPI && lon >= -FORTPI) {
  5854. area.value = AREA_ENUM.AREA_1;
  5855. theta = -lon;
  5856. } else if (lon < -FORTPI && lon >= -(HALF_PI + FORTPI)) {
  5857. area.value = AREA_ENUM.AREA_2;
  5858. theta = -lon - HALF_PI;
  5859. } else {
  5860. area.value = AREA_ENUM.AREA_3;
  5861. theta = (lon > 0.0 ? -lon + SPI : -lon - SPI);
  5862. }
  5863. } else {
  5864. var q, r, s;
  5865. var sinlat, coslat;
  5866. var sinlon, coslon;
  5867. if (this.face === FACE_ENUM.RIGHT) {
  5868. lon = qsc_shift_lon_origin(lon, +HALF_PI);
  5869. } else if (this.face === FACE_ENUM.BACK) {
  5870. lon = qsc_shift_lon_origin(lon, +SPI);
  5871. } else if (this.face === FACE_ENUM.LEFT) {
  5872. lon = qsc_shift_lon_origin(lon, -HALF_PI);
  5873. }
  5874. sinlat = Math.sin(lat);
  5875. coslat = Math.cos(lat);
  5876. sinlon = Math.sin(lon);
  5877. coslon = Math.cos(lon);
  5878. q = coslat * coslon;
  5879. r = coslat * sinlon;
  5880. s = sinlat;
  5881. if (this.face === FACE_ENUM.FRONT) {
  5882. phi = Math.acos(q);
  5883. theta = qsc_fwd_equat_face_theta(phi, s, r, area);
  5884. } else if (this.face === FACE_ENUM.RIGHT) {
  5885. phi = Math.acos(r);
  5886. theta = qsc_fwd_equat_face_theta(phi, s, -q, area);
  5887. } else if (this.face === FACE_ENUM.BACK) {
  5888. phi = Math.acos(-q);
  5889. theta = qsc_fwd_equat_face_theta(phi, s, -r, area);
  5890. } else if (this.face === FACE_ENUM.LEFT) {
  5891. phi = Math.acos(-r);
  5892. theta = qsc_fwd_equat_face_theta(phi, s, q, area);
  5893. } else {
  5894. /* Impossible */
  5895. phi = theta = 0;
  5896. area.value = AREA_ENUM.AREA_0;
  5897. }
  5898. }
  5899. /* Compute mu and nu for the area of definition.
  5900. * For mu, see Eq. (3-21) in [OL76], but note the typos:
  5901. * compare with Eq. (3-14). For nu, see Eq. (3-38). */
  5902. mu = Math.atan((12 / SPI) * (theta + Math.acos(Math.sin(theta) * Math.cos(FORTPI)) - HALF_PI));
  5903. t = Math.sqrt((1 - Math.cos(phi)) / (Math.cos(mu) * Math.cos(mu)) / (1 - Math.cos(Math.atan(1 / Math.cos(theta)))));
  5904. /* Apply the result to the real area. */
  5905. if (area.value === AREA_ENUM.AREA_1) {
  5906. mu += HALF_PI;
  5907. } else if (area.value === AREA_ENUM.AREA_2) {
  5908. mu += SPI;
  5909. } else if (area.value === AREA_ENUM.AREA_3) {
  5910. mu += 1.5 * SPI;
  5911. }
  5912. /* Now compute x, y from mu and nu */
  5913. xy.x = t * Math.cos(mu);
  5914. xy.y = t * Math.sin(mu);
  5915. xy.x = xy.x * this.a + this.x0;
  5916. xy.y = xy.y * this.a + this.y0;
  5917. p.x = xy.x;
  5918. p.y = xy.y;
  5919. return p;
  5920. }
  5921. // QSC inverse equations--mapping x,y to lat/long
  5922. // -----------------------------------------------------------------
  5923. function inverse$4(p) {
  5924. var lp = {lam: 0, phi: 0};
  5925. var mu, nu, cosmu, tannu;
  5926. var tantheta, theta, cosphi, phi;
  5927. var t;
  5928. var area = {value: 0};
  5929. /* de-offset */
  5930. p.x = (p.x - this.x0) / this.a;
  5931. p.y = (p.y - this.y0) / this.a;
  5932. /* Convert the input x, y to the mu and nu angles as used by QSC.
  5933. * This depends on the area of the cube face. */
  5934. nu = Math.atan(Math.sqrt(p.x * p.x + p.y * p.y));
  5935. mu = Math.atan2(p.y, p.x);
  5936. if (p.x >= 0.0 && p.x >= Math.abs(p.y)) {
  5937. area.value = AREA_ENUM.AREA_0;
  5938. } else if (p.y >= 0.0 && p.y >= Math.abs(p.x)) {
  5939. area.value = AREA_ENUM.AREA_1;
  5940. mu -= HALF_PI;
  5941. } else if (p.x < 0.0 && -p.x >= Math.abs(p.y)) {
  5942. area.value = AREA_ENUM.AREA_2;
  5943. mu = (mu < 0.0 ? mu + SPI : mu - SPI);
  5944. } else {
  5945. area.value = AREA_ENUM.AREA_3;
  5946. mu += HALF_PI;
  5947. }
  5948. /* Compute phi and theta for the area of definition.
  5949. * The inverse projection is not described in the original paper, but some
  5950. * good hints can be found here (as of 2011-12-14):
  5951. * http://fits.gsfc.nasa.gov/fitsbits/saf.93/saf.9302
  5952. * (search for "Message-Id: <9302181759.AA25477 at fits.cv.nrao.edu>") */
  5953. t = (SPI / 12) * Math.tan(mu);
  5954. tantheta = Math.sin(t) / (Math.cos(t) - (1 / Math.sqrt(2)));
  5955. theta = Math.atan(tantheta);
  5956. cosmu = Math.cos(mu);
  5957. tannu = Math.tan(nu);
  5958. cosphi = 1 - cosmu * cosmu * tannu * tannu * (1 - Math.cos(Math.atan(1 / Math.cos(theta))));
  5959. if (cosphi < -1) {
  5960. cosphi = -1;
  5961. } else if (cosphi > +1) {
  5962. cosphi = +1;
  5963. }
  5964. /* Apply the result to the real area on the cube face.
  5965. * For the top and bottom face, we can compute phi and lam directly.
  5966. * For the other faces, we must use unit sphere cartesian coordinates
  5967. * as an intermediate step. */
  5968. if (this.face === FACE_ENUM.TOP) {
  5969. phi = Math.acos(cosphi);
  5970. lp.phi = HALF_PI - phi;
  5971. if (area.value === AREA_ENUM.AREA_0) {
  5972. lp.lam = theta + HALF_PI;
  5973. } else if (area.value === AREA_ENUM.AREA_1) {
  5974. lp.lam = (theta < 0.0 ? theta + SPI : theta - SPI);
  5975. } else if (area.value === AREA_ENUM.AREA_2) {
  5976. lp.lam = theta - HALF_PI;
  5977. } else /* area.value == AREA_ENUM.AREA_3 */ {
  5978. lp.lam = theta;
  5979. }
  5980. } else if (this.face === FACE_ENUM.BOTTOM) {
  5981. phi = Math.acos(cosphi);
  5982. lp.phi = phi - HALF_PI;
  5983. if (area.value === AREA_ENUM.AREA_0) {
  5984. lp.lam = -theta + HALF_PI;
  5985. } else if (area.value === AREA_ENUM.AREA_1) {
  5986. lp.lam = -theta;
  5987. } else if (area.value === AREA_ENUM.AREA_2) {
  5988. lp.lam = -theta - HALF_PI;
  5989. } else /* area.value == AREA_ENUM.AREA_3 */ {
  5990. lp.lam = (theta < 0.0 ? -theta - SPI : -theta + SPI);
  5991. }
  5992. } else {
  5993. /* Compute phi and lam via cartesian unit sphere coordinates. */
  5994. var q, r, s;
  5995. q = cosphi;
  5996. t = q * q;
  5997. if (t >= 1) {
  5998. s = 0;
  5999. } else {
  6000. s = Math.sqrt(1 - t) * Math.sin(theta);
  6001. }
  6002. t += s * s;
  6003. if (t >= 1) {
  6004. r = 0;
  6005. } else {
  6006. r = Math.sqrt(1 - t);
  6007. }
  6008. /* Rotate q,r,s into the correct area. */
  6009. if (area.value === AREA_ENUM.AREA_1) {
  6010. t = r;
  6011. r = -s;
  6012. s = t;
  6013. } else if (area.value === AREA_ENUM.AREA_2) {
  6014. r = -r;
  6015. s = -s;
  6016. } else if (area.value === AREA_ENUM.AREA_3) {
  6017. t = r;
  6018. r = s;
  6019. s = -t;
  6020. }
  6021. /* Rotate q,r,s into the correct cube face. */
  6022. if (this.face === FACE_ENUM.RIGHT) {
  6023. t = q;
  6024. q = -r;
  6025. r = t;
  6026. } else if (this.face === FACE_ENUM.BACK) {
  6027. q = -q;
  6028. r = -r;
  6029. } else if (this.face === FACE_ENUM.LEFT) {
  6030. t = q;
  6031. q = r;
  6032. r = -t;
  6033. }
  6034. /* Now compute phi and lam from the unit sphere coordinates. */
  6035. lp.phi = Math.acos(-s) - HALF_PI;
  6036. lp.lam = Math.atan2(r, q);
  6037. if (this.face === FACE_ENUM.RIGHT) {
  6038. lp.lam = qsc_shift_lon_origin(lp.lam, -HALF_PI);
  6039. } else if (this.face === FACE_ENUM.BACK) {
  6040. lp.lam = qsc_shift_lon_origin(lp.lam, -SPI);
  6041. } else if (this.face === FACE_ENUM.LEFT) {
  6042. lp.lam = qsc_shift_lon_origin(lp.lam, +HALF_PI);
  6043. }
  6044. }
  6045. /* Apply the shift from the sphere to the ellipsoid as described
  6046. * in [LK12]. */
  6047. if (this.es !== 0) {
  6048. var invert_sign;
  6049. var tanphi, xa;
  6050. invert_sign = (lp.phi < 0 ? 1 : 0);
  6051. tanphi = Math.tan(lp.phi);
  6052. xa = this.b / Math.sqrt(tanphi * tanphi + this.one_minus_f_squared);
  6053. lp.phi = Math.atan(Math.sqrt(this.a * this.a - xa * xa) / (this.one_minus_f * xa));
  6054. if (invert_sign) {
  6055. lp.phi = -lp.phi;
  6056. }
  6057. }
  6058. lp.lam += this.long0;
  6059. p.x = lp.lam;
  6060. p.y = lp.phi;
  6061. return p;
  6062. }
  6063. /* Helper function for forward projection: compute the theta angle
  6064. * and determine the area number. */
  6065. function qsc_fwd_equat_face_theta(phi, y, x, area) {
  6066. var theta;
  6067. if (phi < EPSLN) {
  6068. area.value = AREA_ENUM.AREA_0;
  6069. theta = 0.0;
  6070. } else {
  6071. theta = Math.atan2(y, x);
  6072. if (Math.abs(theta) <= FORTPI) {
  6073. area.value = AREA_ENUM.AREA_0;
  6074. } else if (theta > FORTPI && theta <= HALF_PI + FORTPI) {
  6075. area.value = AREA_ENUM.AREA_1;
  6076. theta -= HALF_PI;
  6077. } else if (theta > HALF_PI + FORTPI || theta <= -(HALF_PI + FORTPI)) {
  6078. area.value = AREA_ENUM.AREA_2;
  6079. theta = (theta >= 0.0 ? theta - SPI : theta + SPI);
  6080. } else {
  6081. area.value = AREA_ENUM.AREA_3;
  6082. theta += HALF_PI;
  6083. }
  6084. }
  6085. return theta;
  6086. }
  6087. /* Helper function: shift the longitude. */
  6088. function qsc_shift_lon_origin(lon, offset) {
  6089. var slon = lon + offset;
  6090. if (slon < -SPI) {
  6091. slon += TWO_PI;
  6092. } else if (slon > +SPI) {
  6093. slon -= TWO_PI;
  6094. }
  6095. return slon;
  6096. }
  6097. var names$4 = ["Quadrilateralized Spherical Cube", "Quadrilateralized_Spherical_Cube", "qsc"];
  6098. var qsc = {
  6099. init: init$5,
  6100. forward: forward$4,
  6101. inverse: inverse$4,
  6102. names: names$4
  6103. };
  6104. // Robinson projection
  6105. // Based on https://github.com/OSGeo/proj.4/blob/master/src/PJ_robin.c
  6106. // Polynomial coeficients from http://article.gmane.org/gmane.comp.gis.proj-4.devel/6039
  6107. var COEFS_X = [
  6108. [1.0000, 2.2199e-17, -7.15515e-05, 3.1103e-06],
  6109. [0.9986, -0.000482243, -2.4897e-05, -1.3309e-06],
  6110. [0.9954, -0.00083103, -4.48605e-05, -9.86701e-07],
  6111. [0.9900, -0.00135364, -5.9661e-05, 3.6777e-06],
  6112. [0.9822, -0.00167442, -4.49547e-06, -5.72411e-06],
  6113. [0.9730, -0.00214868, -9.03571e-05, 1.8736e-08],
  6114. [0.9600, -0.00305085, -9.00761e-05, 1.64917e-06],
  6115. [0.9427, -0.00382792, -6.53386e-05, -2.6154e-06],
  6116. [0.9216, -0.00467746, -0.00010457, 4.81243e-06],
  6117. [0.8962, -0.00536223, -3.23831e-05, -5.43432e-06],
  6118. [0.8679, -0.00609363, -0.000113898, 3.32484e-06],
  6119. [0.8350, -0.00698325, -6.40253e-05, 9.34959e-07],
  6120. [0.7986, -0.00755338, -5.00009e-05, 9.35324e-07],
  6121. [0.7597, -0.00798324, -3.5971e-05, -2.27626e-06],
  6122. [0.7186, -0.00851367, -7.01149e-05, -8.6303e-06],
  6123. [0.6732, -0.00986209, -0.000199569, 1.91974e-05],
  6124. [0.6213, -0.010418, 8.83923e-05, 6.24051e-06],
  6125. [0.5722, -0.00906601, 0.000182, 6.24051e-06],
  6126. [0.5322, -0.00677797, 0.000275608, 6.24051e-06]
  6127. ];
  6128. var COEFS_Y = [
  6129. [-5.20417e-18, 0.0124, 1.21431e-18, -8.45284e-11],
  6130. [0.0620, 0.0124, -1.26793e-09, 4.22642e-10],
  6131. [0.1240, 0.0124, 5.07171e-09, -1.60604e-09],
  6132. [0.1860, 0.0123999, -1.90189e-08, 6.00152e-09],
  6133. [0.2480, 0.0124002, 7.10039e-08, -2.24e-08],
  6134. [0.3100, 0.0123992, -2.64997e-07, 8.35986e-08],
  6135. [0.3720, 0.0124029, 9.88983e-07, -3.11994e-07],
  6136. [0.4340, 0.0123893, -3.69093e-06, -4.35621e-07],
  6137. [0.4958, 0.0123198, -1.02252e-05, -3.45523e-07],
  6138. [0.5571, 0.0121916, -1.54081e-05, -5.82288e-07],
  6139. [0.6176, 0.0119938, -2.41424e-05, -5.25327e-07],
  6140. [0.6769, 0.011713, -3.20223e-05, -5.16405e-07],
  6141. [0.7346, 0.0113541, -3.97684e-05, -6.09052e-07],
  6142. [0.7903, 0.0109107, -4.89042e-05, -1.04739e-06],
  6143. [0.8435, 0.0103431, -6.4615e-05, -1.40374e-09],
  6144. [0.8936, 0.00969686, -6.4636e-05, -8.547e-06],
  6145. [0.9394, 0.00840947, -0.000192841, -4.2106e-06],
  6146. [0.9761, 0.00616527, -0.000256, -4.2106e-06],
  6147. [1.0000, 0.00328947, -0.000319159, -4.2106e-06]
  6148. ];
  6149. var FXC = 0.8487;
  6150. var FYC = 1.3523;
  6151. var C1 = R2D/5; // rad to 5-degree interval
  6152. var RC1 = 1/C1;
  6153. var NODES = 18;
  6154. var poly3_val = function(coefs, x) {
  6155. return coefs[0] + x * (coefs[1] + x * (coefs[2] + x * coefs[3]));
  6156. };
  6157. var poly3_der = function(coefs, x) {
  6158. return coefs[1] + x * (2 * coefs[2] + x * 3 * coefs[3]);
  6159. };
  6160. function newton_rapshon(f_df, start, max_err, iters) {
  6161. var x = start;
  6162. for (; iters; --iters) {
  6163. var upd = f_df(x);
  6164. x -= upd;
  6165. if (Math.abs(upd) < max_err) {
  6166. break;
  6167. }
  6168. }
  6169. return x;
  6170. }
  6171. function init$4() {
  6172. this.x0 = this.x0 || 0;
  6173. this.y0 = this.y0 || 0;
  6174. this.long0 = this.long0 || 0;
  6175. this.es = 0;
  6176. this.title = this.title || "Robinson";
  6177. }
  6178. function forward$3(ll) {
  6179. var lon = adjust_lon(ll.x - this.long0);
  6180. var dphi = Math.abs(ll.y);
  6181. var i = Math.floor(dphi * C1);
  6182. if (i < 0) {
  6183. i = 0;
  6184. } else if (i >= NODES) {
  6185. i = NODES - 1;
  6186. }
  6187. dphi = R2D * (dphi - RC1 * i);
  6188. var xy = {
  6189. x: poly3_val(COEFS_X[i], dphi) * lon,
  6190. y: poly3_val(COEFS_Y[i], dphi)
  6191. };
  6192. if (ll.y < 0) {
  6193. xy.y = -xy.y;
  6194. }
  6195. xy.x = xy.x * this.a * FXC + this.x0;
  6196. xy.y = xy.y * this.a * FYC + this.y0;
  6197. return xy;
  6198. }
  6199. function inverse$3(xy) {
  6200. var ll = {
  6201. x: (xy.x - this.x0) / (this.a * FXC),
  6202. y: Math.abs(xy.y - this.y0) / (this.a * FYC)
  6203. };
  6204. if (ll.y >= 1) { // pathologic case
  6205. ll.x /= COEFS_X[NODES][0];
  6206. ll.y = xy.y < 0 ? -HALF_PI : HALF_PI;
  6207. } else {
  6208. // find table interval
  6209. var i = Math.floor(ll.y * NODES);
  6210. if (i < 0) {
  6211. i = 0;
  6212. } else if (i >= NODES) {
  6213. i = NODES - 1;
  6214. }
  6215. for (;;) {
  6216. if (COEFS_Y[i][0] > ll.y) {
  6217. --i;
  6218. } else if (COEFS_Y[i+1][0] <= ll.y) {
  6219. ++i;
  6220. } else {
  6221. break;
  6222. }
  6223. }
  6224. // linear interpolation in 5 degree interval
  6225. var coefs = COEFS_Y[i];
  6226. var t = 5 * (ll.y - coefs[0]) / (COEFS_Y[i+1][0] - coefs[0]);
  6227. // find t so that poly3_val(coefs, t) = ll.y
  6228. t = newton_rapshon(function(x) {
  6229. return (poly3_val(coefs, x) - ll.y) / poly3_der(coefs, x);
  6230. }, t, EPSLN, 100);
  6231. ll.x /= poly3_val(COEFS_X[i], t);
  6232. ll.y = (5 * i + t) * D2R$1;
  6233. if (xy.y < 0) {
  6234. ll.y = -ll.y;
  6235. }
  6236. }
  6237. ll.x = adjust_lon(ll.x + this.long0);
  6238. return ll;
  6239. }
  6240. var names$3 = ["Robinson", "robin"];
  6241. var robin = {
  6242. init: init$4,
  6243. forward: forward$3,
  6244. inverse: inverse$3,
  6245. names: names$3
  6246. };
  6247. function init$3() {
  6248. this.name = 'geocent';
  6249. }
  6250. function forward$2(p) {
  6251. var point = geodeticToGeocentric(p, this.es, this.a);
  6252. return point;
  6253. }
  6254. function inverse$2(p) {
  6255. var point = geocentricToGeodetic(p, this.es, this.a, this.b);
  6256. return point;
  6257. }
  6258. var names$2 = ["Geocentric", 'geocentric', "geocent", "Geocent"];
  6259. var geocent = {
  6260. init: init$3,
  6261. forward: forward$2,
  6262. inverse: inverse$2,
  6263. names: names$2
  6264. };
  6265. var mode = {
  6266. N_POLE: 0,
  6267. S_POLE: 1,
  6268. EQUIT: 2,
  6269. OBLIQ: 3
  6270. };
  6271. var params = {
  6272. h: { def: 100000, num: true }, // default is Karman line, no default in PROJ.7
  6273. azi: { def: 0, num: true, degrees: true }, // default is North
  6274. tilt: { def: 0, num: true, degrees: true }, // default is Nadir
  6275. long0: { def: 0, num: true }, // default is Greenwich, conversion to rad is automatic
  6276. lat0: { def: 0, num: true } // default is Equator, conversion to rad is automatic
  6277. };
  6278. function init$2() {
  6279. Object.keys(params).forEach(function (p) {
  6280. if (typeof this[p] === "undefined") {
  6281. this[p] = params[p].def;
  6282. } else if (params[p].num && isNaN(this[p])) {
  6283. throw new Error("Invalid parameter value, must be numeric " + p + " = " + this[p]);
  6284. } else if (params[p].num) {
  6285. this[p] = parseFloat(this[p]);
  6286. }
  6287. if (params[p].degrees) {
  6288. this[p] = this[p] * D2R$1;
  6289. }
  6290. }.bind(this));
  6291. if (Math.abs((Math.abs(this.lat0) - HALF_PI)) < EPSLN) {
  6292. this.mode = this.lat0 < 0 ? mode.S_POLE : mode.N_POLE;
  6293. } else if (Math.abs(this.lat0) < EPSLN) {
  6294. this.mode = mode.EQUIT;
  6295. } else {
  6296. this.mode = mode.OBLIQ;
  6297. this.sinph0 = Math.sin(this.lat0);
  6298. this.cosph0 = Math.cos(this.lat0);
  6299. }
  6300. this.pn1 = this.h / this.a; // Normalize relative to the Earth's radius
  6301. if (this.pn1 <= 0 || this.pn1 > 1e10) {
  6302. throw new Error("Invalid height");
  6303. }
  6304. this.p = 1 + this.pn1;
  6305. this.rp = 1 / this.p;
  6306. this.h1 = 1 / this.pn1;
  6307. this.pfact = (this.p + 1) * this.h1;
  6308. this.es = 0;
  6309. var omega = this.tilt;
  6310. var gamma = this.azi;
  6311. this.cg = Math.cos(gamma);
  6312. this.sg = Math.sin(gamma);
  6313. this.cw = Math.cos(omega);
  6314. this.sw = Math.sin(omega);
  6315. }
  6316. function forward$1(p) {
  6317. p.x -= this.long0;
  6318. var sinphi = Math.sin(p.y);
  6319. var cosphi = Math.cos(p.y);
  6320. var coslam = Math.cos(p.x);
  6321. var x, y;
  6322. switch (this.mode) {
  6323. case mode.OBLIQ:
  6324. y = this.sinph0 * sinphi + this.cosph0 * cosphi * coslam;
  6325. break;
  6326. case mode.EQUIT:
  6327. y = cosphi * coslam;
  6328. break;
  6329. case mode.S_POLE:
  6330. y = -sinphi;
  6331. break;
  6332. case mode.N_POLE:
  6333. y = sinphi;
  6334. break;
  6335. }
  6336. y = this.pn1 / (this.p - y);
  6337. x = y * cosphi * Math.sin(p.x);
  6338. switch (this.mode) {
  6339. case mode.OBLIQ:
  6340. y *= this.cosph0 * sinphi - this.sinph0 * cosphi * coslam;
  6341. break;
  6342. case mode.EQUIT:
  6343. y *= sinphi;
  6344. break;
  6345. case mode.N_POLE:
  6346. y *= -(cosphi * coslam);
  6347. break;
  6348. case mode.S_POLE:
  6349. y *= cosphi * coslam;
  6350. break;
  6351. }
  6352. // Tilt
  6353. var yt, ba;
  6354. yt = y * this.cg + x * this.sg;
  6355. ba = 1 / (yt * this.sw * this.h1 + this.cw);
  6356. x = (x * this.cg - y * this.sg) * this.cw * ba;
  6357. y = yt * ba;
  6358. p.x = x * this.a;
  6359. p.y = y * this.a;
  6360. return p;
  6361. }
  6362. function inverse$1(p) {
  6363. p.x /= this.a;
  6364. p.y /= this.a;
  6365. var r = { x: p.x, y: p.y };
  6366. // Un-Tilt
  6367. var bm, bq, yt;
  6368. yt = 1 / (this.pn1 - p.y * this.sw);
  6369. bm = this.pn1 * p.x * yt;
  6370. bq = this.pn1 * p.y * this.cw * yt;
  6371. p.x = bm * this.cg + bq * this.sg;
  6372. p.y = bq * this.cg - bm * this.sg;
  6373. var rh = hypot(p.x, p.y);
  6374. if (Math.abs(rh) < EPSLN) {
  6375. r.x = 0;
  6376. r.y = p.y;
  6377. } else {
  6378. var cosz, sinz;
  6379. sinz = 1 - rh * rh * this.pfact;
  6380. sinz = (this.p - Math.sqrt(sinz)) / (this.pn1 / rh + rh / this.pn1);
  6381. cosz = Math.sqrt(1 - sinz * sinz);
  6382. switch (this.mode) {
  6383. case mode.OBLIQ:
  6384. r.y = Math.asin(cosz * this.sinph0 + p.y * sinz * this.cosph0 / rh);
  6385. p.y = (cosz - this.sinph0 * Math.sin(r.y)) * rh;
  6386. p.x *= sinz * this.cosph0;
  6387. break;
  6388. case mode.EQUIT:
  6389. r.y = Math.asin(p.y * sinz / rh);
  6390. p.y = cosz * rh;
  6391. p.x *= sinz;
  6392. break;
  6393. case mode.N_POLE:
  6394. r.y = Math.asin(cosz);
  6395. p.y = -p.y;
  6396. break;
  6397. case mode.S_POLE:
  6398. r.y = -Math.asin(cosz);
  6399. break;
  6400. }
  6401. r.x = Math.atan2(p.x, p.y);
  6402. }
  6403. p.x = r.x + this.long0;
  6404. p.y = r.y;
  6405. return p;
  6406. }
  6407. var names$1 = ["Tilted_Perspective", "tpers"];
  6408. var tpers = {
  6409. init: init$2,
  6410. forward: forward$1,
  6411. inverse: inverse$1,
  6412. names: names$1
  6413. };
  6414. function init$1() {
  6415. this.flip_axis = (this.sweep === 'x' ? 1 : 0);
  6416. this.h = Number(this.h);
  6417. this.radius_g_1 = this.h / this.a;
  6418. if (this.radius_g_1 <= 0 || this.radius_g_1 > 1e10) {
  6419. throw new Error();
  6420. }
  6421. this.radius_g = 1.0 + this.radius_g_1;
  6422. this.C = this.radius_g * this.radius_g - 1.0;
  6423. if (this.es !== 0.0) {
  6424. var one_es = 1.0 - this.es;
  6425. var rone_es = 1 / one_es;
  6426. this.radius_p = Math.sqrt(one_es);
  6427. this.radius_p2 = one_es;
  6428. this.radius_p_inv2 = rone_es;
  6429. this.shape = 'ellipse'; // Use as a condition in the forward and inverse functions.
  6430. } else {
  6431. this.radius_p = 1.0;
  6432. this.radius_p2 = 1.0;
  6433. this.radius_p_inv2 = 1.0;
  6434. this.shape = 'sphere'; // Use as a condition in the forward and inverse functions.
  6435. }
  6436. if (!this.title) {
  6437. this.title = "Geostationary Satellite View";
  6438. }
  6439. }
  6440. function forward(p) {
  6441. var lon = p.x;
  6442. var lat = p.y;
  6443. var tmp, v_x, v_y, v_z;
  6444. lon = lon - this.long0;
  6445. if (this.shape === 'ellipse') {
  6446. lat = Math.atan(this.radius_p2 * Math.tan(lat));
  6447. var r = this.radius_p / hypot(this.radius_p * Math.cos(lat), Math.sin(lat));
  6448. v_x = r * Math.cos(lon) * Math.cos(lat);
  6449. v_y = r * Math.sin(lon) * Math.cos(lat);
  6450. v_z = r * Math.sin(lat);
  6451. if (((this.radius_g - v_x) * v_x - v_y * v_y - v_z * v_z * this.radius_p_inv2) < 0.0) {
  6452. p.x = Number.NaN;
  6453. p.y = Number.NaN;
  6454. return p;
  6455. }
  6456. tmp = this.radius_g - v_x;
  6457. if (this.flip_axis) {
  6458. p.x = this.radius_g_1 * Math.atan(v_y / hypot(v_z, tmp));
  6459. p.y = this.radius_g_1 * Math.atan(v_z / tmp);
  6460. } else {
  6461. p.x = this.radius_g_1 * Math.atan(v_y / tmp);
  6462. p.y = this.radius_g_1 * Math.atan(v_z / hypot(v_y, tmp));
  6463. }
  6464. } else if (this.shape === 'sphere') {
  6465. tmp = Math.cos(lat);
  6466. v_x = Math.cos(lon) * tmp;
  6467. v_y = Math.sin(lon) * tmp;
  6468. v_z = Math.sin(lat);
  6469. tmp = this.radius_g - v_x;
  6470. if (this.flip_axis) {
  6471. p.x = this.radius_g_1 * Math.atan(v_y / hypot(v_z, tmp));
  6472. p.y = this.radius_g_1 * Math.atan(v_z / tmp);
  6473. } else {
  6474. p.x = this.radius_g_1 * Math.atan(v_y / tmp);
  6475. p.y = this.radius_g_1 * Math.atan(v_z / hypot(v_y, tmp));
  6476. }
  6477. }
  6478. p.x = p.x * this.a;
  6479. p.y = p.y * this.a;
  6480. return p;
  6481. }
  6482. function inverse(p) {
  6483. var v_x = -1.0;
  6484. var v_y = 0.0;
  6485. var v_z = 0.0;
  6486. var a, b, det, k;
  6487. p.x = p.x / this.a;
  6488. p.y = p.y / this.a;
  6489. if (this.shape === 'ellipse') {
  6490. if (this.flip_axis) {
  6491. v_z = Math.tan(p.y / this.radius_g_1);
  6492. v_y = Math.tan(p.x / this.radius_g_1) * hypot(1.0, v_z);
  6493. } else {
  6494. v_y = Math.tan(p.x / this.radius_g_1);
  6495. v_z = Math.tan(p.y / this.radius_g_1) * hypot(1.0, v_y);
  6496. }
  6497. var v_zp = v_z / this.radius_p;
  6498. a = v_y * v_y + v_zp * v_zp + v_x * v_x;
  6499. b = 2 * this.radius_g * v_x;
  6500. det = (b * b) - 4 * a * this.C;
  6501. if (det < 0.0) {
  6502. p.x = Number.NaN;
  6503. p.y = Number.NaN;
  6504. return p;
  6505. }
  6506. k = (-b - Math.sqrt(det)) / (2.0 * a);
  6507. v_x = this.radius_g + k * v_x;
  6508. v_y *= k;
  6509. v_z *= k;
  6510. p.x = Math.atan2(v_y, v_x);
  6511. p.y = Math.atan(v_z * Math.cos(p.x) / v_x);
  6512. p.y = Math.atan(this.radius_p_inv2 * Math.tan(p.y));
  6513. } else if (this.shape === 'sphere') {
  6514. if (this.flip_axis) {
  6515. v_z = Math.tan(p.y / this.radius_g_1);
  6516. v_y = Math.tan(p.x / this.radius_g_1) * Math.sqrt(1.0 + v_z * v_z);
  6517. } else {
  6518. v_y = Math.tan(p.x / this.radius_g_1);
  6519. v_z = Math.tan(p.y / this.radius_g_1) * Math.sqrt(1.0 + v_y * v_y);
  6520. }
  6521. a = v_y * v_y + v_z * v_z + v_x * v_x;
  6522. b = 2 * this.radius_g * v_x;
  6523. det = (b * b) - 4 * a * this.C;
  6524. if (det < 0.0) {
  6525. p.x = Number.NaN;
  6526. p.y = Number.NaN;
  6527. return p;
  6528. }
  6529. k = (-b - Math.sqrt(det)) / (2.0 * a);
  6530. v_x = this.radius_g + k * v_x;
  6531. v_y *= k;
  6532. v_z *= k;
  6533. p.x = Math.atan2(v_y, v_x);
  6534. p.y = Math.atan(v_z * Math.cos(p.x) / v_x);
  6535. }
  6536. p.x = p.x + this.long0;
  6537. return p;
  6538. }
  6539. var names = ["Geostationary Satellite View", "Geostationary_Satellite", "geos"];
  6540. var geos = {
  6541. init: init$1,
  6542. forward: forward,
  6543. inverse: inverse,
  6544. names: names,
  6545. };
  6546. function includedProjections(proj4){
  6547. proj4.Proj.projections.add(tmerc);
  6548. proj4.Proj.projections.add(etmerc);
  6549. proj4.Proj.projections.add(utm);
  6550. proj4.Proj.projections.add(sterea);
  6551. proj4.Proj.projections.add(stere);
  6552. proj4.Proj.projections.add(somerc);
  6553. proj4.Proj.projections.add(omerc);
  6554. proj4.Proj.projections.add(lcc);
  6555. proj4.Proj.projections.add(krovak);
  6556. proj4.Proj.projections.add(cass);
  6557. proj4.Proj.projections.add(laea);
  6558. proj4.Proj.projections.add(aea);
  6559. proj4.Proj.projections.add(gnom);
  6560. proj4.Proj.projections.add(cea);
  6561. proj4.Proj.projections.add(eqc);
  6562. proj4.Proj.projections.add(poly);
  6563. proj4.Proj.projections.add(nzmg);
  6564. proj4.Proj.projections.add(mill);
  6565. proj4.Proj.projections.add(sinu);
  6566. proj4.Proj.projections.add(moll);
  6567. proj4.Proj.projections.add(eqdc);
  6568. proj4.Proj.projections.add(vandg);
  6569. proj4.Proj.projections.add(aeqd);
  6570. proj4.Proj.projections.add(ortho);
  6571. proj4.Proj.projections.add(qsc);
  6572. proj4.Proj.projections.add(robin);
  6573. proj4.Proj.projections.add(geocent);
  6574. proj4.Proj.projections.add(tpers);
  6575. proj4.Proj.projections.add(geos);
  6576. }
  6577. proj4.defaultDatum = 'WGS84'; //default datum
  6578. proj4.Proj = Projection;
  6579. proj4.WGS84 = new proj4.Proj('WGS84');
  6580. proj4.Point = Point;
  6581. proj4.toPoint = common;
  6582. proj4.defs = defs;
  6583. proj4.nadgrid = nadgrid;
  6584. proj4.transform = transform;
  6585. proj4.mgrs = mgrs;
  6586. proj4.version = '__VERSION__';
  6587. includedProjections(proj4);
  6588. var global$1 = (typeof global !== "undefined" ? global :
  6589. typeof self !== "undefined" ? self :
  6590. typeof window !== "undefined" ? window : {});
  6591. var lookup = [];
  6592. var revLookup = [];
  6593. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
  6594. var inited = false;
  6595. function init () {
  6596. inited = true;
  6597. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  6598. for (var i = 0, len = code.length; i < len; ++i) {
  6599. lookup[i] = code[i];
  6600. revLookup[code.charCodeAt(i)] = i;
  6601. }
  6602. revLookup['-'.charCodeAt(0)] = 62;
  6603. revLookup['_'.charCodeAt(0)] = 63;
  6604. }
  6605. function toByteArray (b64) {
  6606. if (!inited) {
  6607. init();
  6608. }
  6609. var i, j, l, tmp, placeHolders, arr;
  6610. var len = b64.length;
  6611. if (len % 4 > 0) {
  6612. throw new Error('Invalid string. Length must be a multiple of 4')
  6613. }
  6614. // the number of equal signs (place holders)
  6615. // if there are two placeholders, than the two characters before it
  6616. // represent one byte
  6617. // if there is only one, then the three characters before it represent 2 bytes
  6618. // this is just a cheap hack to not do indexOf twice
  6619. placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0;
  6620. // base64 is 4/3 + up to two characters of the original data
  6621. arr = new Arr(len * 3 / 4 - placeHolders);
  6622. // if there are placeholders, only get up to the last complete 4 chars
  6623. l = placeHolders > 0 ? len - 4 : len;
  6624. var L = 0;
  6625. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  6626. tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)];
  6627. arr[L++] = (tmp >> 16) & 0xFF;
  6628. arr[L++] = (tmp >> 8) & 0xFF;
  6629. arr[L++] = tmp & 0xFF;
  6630. }
  6631. if (placeHolders === 2) {
  6632. tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4);
  6633. arr[L++] = tmp & 0xFF;
  6634. } else if (placeHolders === 1) {
  6635. tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2);
  6636. arr[L++] = (tmp >> 8) & 0xFF;
  6637. arr[L++] = tmp & 0xFF;
  6638. }
  6639. return arr
  6640. }
  6641. function tripletToBase64 (num) {
  6642. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
  6643. }
  6644. function encodeChunk (uint8, start, end) {
  6645. var tmp;
  6646. var output = [];
  6647. for (var i = start; i < end; i += 3) {
  6648. tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
  6649. output.push(tripletToBase64(tmp));
  6650. }
  6651. return output.join('')
  6652. }
  6653. function fromByteArray (uint8) {
  6654. if (!inited) {
  6655. init();
  6656. }
  6657. var tmp;
  6658. var len = uint8.length;
  6659. var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
  6660. var output = '';
  6661. var parts = [];
  6662. var maxChunkLength = 16383; // must be multiple of 3
  6663. // go through the array every three bytes, we'll deal with trailing stuff later
  6664. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  6665. parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
  6666. }
  6667. // pad the end with zeros, but make sure to not forget the extra bytes
  6668. if (extraBytes === 1) {
  6669. tmp = uint8[len - 1];
  6670. output += lookup[tmp >> 2];
  6671. output += lookup[(tmp << 4) & 0x3F];
  6672. output += '==';
  6673. } else if (extraBytes === 2) {
  6674. tmp = (uint8[len - 2] << 8) + (uint8[len - 1]);
  6675. output += lookup[tmp >> 10];
  6676. output += lookup[(tmp >> 4) & 0x3F];
  6677. output += lookup[(tmp << 2) & 0x3F];
  6678. output += '=';
  6679. }
  6680. parts.push(output);
  6681. return parts.join('')
  6682. }
  6683. function read (buffer, offset, isLE, mLen, nBytes) {
  6684. var e, m;
  6685. var eLen = nBytes * 8 - mLen - 1;
  6686. var eMax = (1 << eLen) - 1;
  6687. var eBias = eMax >> 1;
  6688. var nBits = -7;
  6689. var i = isLE ? (nBytes - 1) : 0;
  6690. var d = isLE ? -1 : 1;
  6691. var s = buffer[offset + i];
  6692. i += d;
  6693. e = s & ((1 << (-nBits)) - 1);
  6694. s >>= (-nBits);
  6695. nBits += eLen;
  6696. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  6697. m = e & ((1 << (-nBits)) - 1);
  6698. e >>= (-nBits);
  6699. nBits += mLen;
  6700. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  6701. if (e === 0) {
  6702. e = 1 - eBias;
  6703. } else if (e === eMax) {
  6704. return m ? NaN : ((s ? -1 : 1) * Infinity)
  6705. } else {
  6706. m = m + Math.pow(2, mLen);
  6707. e = e - eBias;
  6708. }
  6709. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  6710. }
  6711. function write (buffer, value, offset, isLE, mLen, nBytes) {
  6712. var e, m, c;
  6713. var eLen = nBytes * 8 - mLen - 1;
  6714. var eMax = (1 << eLen) - 1;
  6715. var eBias = eMax >> 1;
  6716. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
  6717. var i = isLE ? 0 : (nBytes - 1);
  6718. var d = isLE ? 1 : -1;
  6719. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
  6720. value = Math.abs(value);
  6721. if (isNaN(value) || value === Infinity) {
  6722. m = isNaN(value) ? 1 : 0;
  6723. e = eMax;
  6724. } else {
  6725. e = Math.floor(Math.log(value) / Math.LN2);
  6726. if (value * (c = Math.pow(2, -e)) < 1) {
  6727. e--;
  6728. c *= 2;
  6729. }
  6730. if (e + eBias >= 1) {
  6731. value += rt / c;
  6732. } else {
  6733. value += rt * Math.pow(2, 1 - eBias);
  6734. }
  6735. if (value * c >= 2) {
  6736. e++;
  6737. c /= 2;
  6738. }
  6739. if (e + eBias >= eMax) {
  6740. m = 0;
  6741. e = eMax;
  6742. } else if (e + eBias >= 1) {
  6743. m = (value * c - 1) * Math.pow(2, mLen);
  6744. e = e + eBias;
  6745. } else {
  6746. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  6747. e = 0;
  6748. }
  6749. }
  6750. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  6751. e = (e << mLen) | m;
  6752. eLen += mLen;
  6753. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  6754. buffer[offset + i - d] |= s * 128;
  6755. }
  6756. var toString = {}.toString;
  6757. var isArray = Array.isArray || function (arr) {
  6758. return toString.call(arr) == '[object Array]';
  6759. };
  6760. /*!
  6761. * The buffer module from node.js, for the browser.
  6762. *
  6763. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  6764. * @license MIT
  6765. */
  6766. var INSPECT_MAX_BYTES = 50;
  6767. /**
  6768. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  6769. * === true Use Uint8Array implementation (fastest)
  6770. * === false Use Object implementation (most compatible, even IE6)
  6771. *
  6772. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  6773. * Opera 11.6+, iOS 4.2+.
  6774. *
  6775. * Due to various browser bugs, sometimes the Object implementation will be used even
  6776. * when the browser supports typed arrays.
  6777. *
  6778. * Note:
  6779. *
  6780. * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
  6781. * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
  6782. *
  6783. * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
  6784. *
  6785. * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
  6786. * incorrect length in some situations.
  6787. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
  6788. * get the Object implementation, which is slower but behaves correctly.
  6789. */
  6790. Buffer.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== undefined
  6791. ? global$1.TYPED_ARRAY_SUPPORT
  6792. : true;
  6793. /*
  6794. * Export kMaxLength after typed array support is determined.
  6795. */
  6796. kMaxLength();
  6797. function kMaxLength () {
  6798. return Buffer.TYPED_ARRAY_SUPPORT
  6799. ? 0x7fffffff
  6800. : 0x3fffffff
  6801. }
  6802. function createBuffer (that, length) {
  6803. if (kMaxLength() < length) {
  6804. throw new RangeError('Invalid typed array length')
  6805. }
  6806. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6807. // Return an augmented `Uint8Array` instance, for best performance
  6808. that = new Uint8Array(length);
  6809. that.__proto__ = Buffer.prototype;
  6810. } else {
  6811. // Fallback: Return an object instance of the Buffer class
  6812. if (that === null) {
  6813. that = new Buffer(length);
  6814. }
  6815. that.length = length;
  6816. }
  6817. return that
  6818. }
  6819. /**
  6820. * The Buffer constructor returns instances of `Uint8Array` that have their
  6821. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  6822. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  6823. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  6824. * returns a single octet.
  6825. *
  6826. * The `Uint8Array` prototype remains unmodified.
  6827. */
  6828. function Buffer (arg, encodingOrOffset, length) {
  6829. if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
  6830. return new Buffer(arg, encodingOrOffset, length)
  6831. }
  6832. // Common case.
  6833. if (typeof arg === 'number') {
  6834. if (typeof encodingOrOffset === 'string') {
  6835. throw new Error(
  6836. 'If encoding is specified then the first argument must be a string'
  6837. )
  6838. }
  6839. return allocUnsafe(this, arg)
  6840. }
  6841. return from(this, arg, encodingOrOffset, length)
  6842. }
  6843. Buffer.poolSize = 8192; // not used by this implementation
  6844. // TODO: Legacy, not needed anymore. Remove in next major version.
  6845. Buffer._augment = function (arr) {
  6846. arr.__proto__ = Buffer.prototype;
  6847. return arr
  6848. };
  6849. function from (that, value, encodingOrOffset, length) {
  6850. if (typeof value === 'number') {
  6851. throw new TypeError('"value" argument must not be a number')
  6852. }
  6853. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  6854. return fromArrayBuffer(that, value, encodingOrOffset, length)
  6855. }
  6856. if (typeof value === 'string') {
  6857. return fromString(that, value, encodingOrOffset)
  6858. }
  6859. return fromObject(that, value)
  6860. }
  6861. /**
  6862. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  6863. * if value is a number.
  6864. * Buffer.from(str[, encoding])
  6865. * Buffer.from(array)
  6866. * Buffer.from(buffer)
  6867. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  6868. **/
  6869. Buffer.from = function (value, encodingOrOffset, length) {
  6870. return from(null, value, encodingOrOffset, length)
  6871. };
  6872. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6873. Buffer.prototype.__proto__ = Uint8Array.prototype;
  6874. Buffer.__proto__ = Uint8Array;
  6875. }
  6876. function assertSize (size) {
  6877. if (typeof size !== 'number') {
  6878. throw new TypeError('"size" argument must be a number')
  6879. } else if (size < 0) {
  6880. throw new RangeError('"size" argument must not be negative')
  6881. }
  6882. }
  6883. function alloc (that, size, fill, encoding) {
  6884. assertSize(size);
  6885. if (size <= 0) {
  6886. return createBuffer(that, size)
  6887. }
  6888. if (fill !== undefined) {
  6889. // Only pay attention to encoding if it's a string. This
  6890. // prevents accidentally sending in a number that would
  6891. // be interpretted as a start offset.
  6892. return typeof encoding === 'string'
  6893. ? createBuffer(that, size).fill(fill, encoding)
  6894. : createBuffer(that, size).fill(fill)
  6895. }
  6896. return createBuffer(that, size)
  6897. }
  6898. /**
  6899. * Creates a new filled Buffer instance.
  6900. * alloc(size[, fill[, encoding]])
  6901. **/
  6902. Buffer.alloc = function (size, fill, encoding) {
  6903. return alloc(null, size, fill, encoding)
  6904. };
  6905. function allocUnsafe (that, size) {
  6906. assertSize(size);
  6907. that = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
  6908. if (!Buffer.TYPED_ARRAY_SUPPORT) {
  6909. for (var i = 0; i < size; ++i) {
  6910. that[i] = 0;
  6911. }
  6912. }
  6913. return that
  6914. }
  6915. /**
  6916. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  6917. * */
  6918. Buffer.allocUnsafe = function (size) {
  6919. return allocUnsafe(null, size)
  6920. };
  6921. /**
  6922. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  6923. */
  6924. Buffer.allocUnsafeSlow = function (size) {
  6925. return allocUnsafe(null, size)
  6926. };
  6927. function fromString (that, string, encoding) {
  6928. if (typeof encoding !== 'string' || encoding === '') {
  6929. encoding = 'utf8';
  6930. }
  6931. if (!Buffer.isEncoding(encoding)) {
  6932. throw new TypeError('"encoding" must be a valid string encoding')
  6933. }
  6934. var length = byteLength(string, encoding) | 0;
  6935. that = createBuffer(that, length);
  6936. var actual = that.write(string, encoding);
  6937. if (actual !== length) {
  6938. // Writing a hex string, for example, that contains invalid characters will
  6939. // cause everything after the first invalid character to be ignored. (e.g.
  6940. // 'abxxcd' will be treated as 'ab')
  6941. that = that.slice(0, actual);
  6942. }
  6943. return that
  6944. }
  6945. function fromArrayLike (that, array) {
  6946. var length = array.length < 0 ? 0 : checked(array.length) | 0;
  6947. that = createBuffer(that, length);
  6948. for (var i = 0; i < length; i += 1) {
  6949. that[i] = array[i] & 255;
  6950. }
  6951. return that
  6952. }
  6953. function fromArrayBuffer (that, array, byteOffset, length) {
  6954. array.byteLength; // this throws if `array` is not a valid ArrayBuffer
  6955. if (byteOffset < 0 || array.byteLength < byteOffset) {
  6956. throw new RangeError('\'offset\' is out of bounds')
  6957. }
  6958. if (array.byteLength < byteOffset + (length || 0)) {
  6959. throw new RangeError('\'length\' is out of bounds')
  6960. }
  6961. if (byteOffset === undefined && length === undefined) {
  6962. array = new Uint8Array(array);
  6963. } else if (length === undefined) {
  6964. array = new Uint8Array(array, byteOffset);
  6965. } else {
  6966. array = new Uint8Array(array, byteOffset, length);
  6967. }
  6968. if (Buffer.TYPED_ARRAY_SUPPORT) {
  6969. // Return an augmented `Uint8Array` instance, for best performance
  6970. that = array;
  6971. that.__proto__ = Buffer.prototype;
  6972. } else {
  6973. // Fallback: Return an object instance of the Buffer class
  6974. that = fromArrayLike(that, array);
  6975. }
  6976. return that
  6977. }
  6978. function fromObject (that, obj) {
  6979. if (internalIsBuffer(obj)) {
  6980. var len = checked(obj.length) | 0;
  6981. that = createBuffer(that, len);
  6982. if (that.length === 0) {
  6983. return that
  6984. }
  6985. obj.copy(that, 0, 0, len);
  6986. return that
  6987. }
  6988. if (obj) {
  6989. if ((typeof ArrayBuffer !== 'undefined' &&
  6990. obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
  6991. if (typeof obj.length !== 'number' || isnan(obj.length)) {
  6992. return createBuffer(that, 0)
  6993. }
  6994. return fromArrayLike(that, obj)
  6995. }
  6996. if (obj.type === 'Buffer' && isArray(obj.data)) {
  6997. return fromArrayLike(that, obj.data)
  6998. }
  6999. }
  7000. throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
  7001. }
  7002. function checked (length) {
  7003. // Note: cannot use `length < kMaxLength()` here because that fails when
  7004. // length is NaN (which is otherwise coerced to zero.)
  7005. if (length >= kMaxLength()) {
  7006. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  7007. 'size: 0x' + kMaxLength().toString(16) + ' bytes')
  7008. }
  7009. return length | 0
  7010. }
  7011. Buffer.isBuffer = isBuffer;
  7012. function internalIsBuffer (b) {
  7013. return !!(b != null && b._isBuffer)
  7014. }
  7015. Buffer.compare = function compare (a, b) {
  7016. if (!internalIsBuffer(a) || !internalIsBuffer(b)) {
  7017. throw new TypeError('Arguments must be Buffers')
  7018. }
  7019. if (a === b) return 0
  7020. var x = a.length;
  7021. var y = b.length;
  7022. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  7023. if (a[i] !== b[i]) {
  7024. x = a[i];
  7025. y = b[i];
  7026. break
  7027. }
  7028. }
  7029. if (x < y) return -1
  7030. if (y < x) return 1
  7031. return 0
  7032. };
  7033. Buffer.isEncoding = function isEncoding (encoding) {
  7034. switch (String(encoding).toLowerCase()) {
  7035. case 'hex':
  7036. case 'utf8':
  7037. case 'utf-8':
  7038. case 'ascii':
  7039. case 'latin1':
  7040. case 'binary':
  7041. case 'base64':
  7042. case 'ucs2':
  7043. case 'ucs-2':
  7044. case 'utf16le':
  7045. case 'utf-16le':
  7046. return true
  7047. default:
  7048. return false
  7049. }
  7050. };
  7051. Buffer.concat = function concat (list, length) {
  7052. if (!isArray(list)) {
  7053. throw new TypeError('"list" argument must be an Array of Buffers')
  7054. }
  7055. if (list.length === 0) {
  7056. return Buffer.alloc(0)
  7057. }
  7058. var i;
  7059. if (length === undefined) {
  7060. length = 0;
  7061. for (i = 0; i < list.length; ++i) {
  7062. length += list[i].length;
  7063. }
  7064. }
  7065. var buffer = Buffer.allocUnsafe(length);
  7066. var pos = 0;
  7067. for (i = 0; i < list.length; ++i) {
  7068. var buf = list[i];
  7069. if (!internalIsBuffer(buf)) {
  7070. throw new TypeError('"list" argument must be an Array of Buffers')
  7071. }
  7072. buf.copy(buffer, pos);
  7073. pos += buf.length;
  7074. }
  7075. return buffer
  7076. };
  7077. function byteLength (string, encoding) {
  7078. if (internalIsBuffer(string)) {
  7079. return string.length
  7080. }
  7081. if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
  7082. (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
  7083. return string.byteLength
  7084. }
  7085. if (typeof string !== 'string') {
  7086. string = '' + string;
  7087. }
  7088. var len = string.length;
  7089. if (len === 0) return 0
  7090. // Use a for loop to avoid recursion
  7091. var loweredCase = false;
  7092. for (;;) {
  7093. switch (encoding) {
  7094. case 'ascii':
  7095. case 'latin1':
  7096. case 'binary':
  7097. return len
  7098. case 'utf8':
  7099. case 'utf-8':
  7100. case undefined:
  7101. return utf8ToBytes(string).length
  7102. case 'ucs2':
  7103. case 'ucs-2':
  7104. case 'utf16le':
  7105. case 'utf-16le':
  7106. return len * 2
  7107. case 'hex':
  7108. return len >>> 1
  7109. case 'base64':
  7110. return base64ToBytes(string).length
  7111. default:
  7112. if (loweredCase) return utf8ToBytes(string).length // assume utf8
  7113. encoding = ('' + encoding).toLowerCase();
  7114. loweredCase = true;
  7115. }
  7116. }
  7117. }
  7118. Buffer.byteLength = byteLength;
  7119. function slowToString (encoding, start, end) {
  7120. var loweredCase = false;
  7121. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  7122. // property of a typed array.
  7123. // This behaves neither like String nor Uint8Array in that we set start/end
  7124. // to their upper/lower bounds if the value passed is out of range.
  7125. // undefined is handled specially as per ECMA-262 6th Edition,
  7126. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  7127. if (start === undefined || start < 0) {
  7128. start = 0;
  7129. }
  7130. // Return early if start > this.length. Done here to prevent potential uint32
  7131. // coercion fail below.
  7132. if (start > this.length) {
  7133. return ''
  7134. }
  7135. if (end === undefined || end > this.length) {
  7136. end = this.length;
  7137. }
  7138. if (end <= 0) {
  7139. return ''
  7140. }
  7141. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  7142. end >>>= 0;
  7143. start >>>= 0;
  7144. if (end <= start) {
  7145. return ''
  7146. }
  7147. if (!encoding) encoding = 'utf8';
  7148. while (true) {
  7149. switch (encoding) {
  7150. case 'hex':
  7151. return hexSlice(this, start, end)
  7152. case 'utf8':
  7153. case 'utf-8':
  7154. return utf8Slice(this, start, end)
  7155. case 'ascii':
  7156. return asciiSlice(this, start, end)
  7157. case 'latin1':
  7158. case 'binary':
  7159. return latin1Slice(this, start, end)
  7160. case 'base64':
  7161. return base64Slice(this, start, end)
  7162. case 'ucs2':
  7163. case 'ucs-2':
  7164. case 'utf16le':
  7165. case 'utf-16le':
  7166. return utf16leSlice(this, start, end)
  7167. default:
  7168. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  7169. encoding = (encoding + '').toLowerCase();
  7170. loweredCase = true;
  7171. }
  7172. }
  7173. }
  7174. // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
  7175. // Buffer instances.
  7176. Buffer.prototype._isBuffer = true;
  7177. function swap (b, n, m) {
  7178. var i = b[n];
  7179. b[n] = b[m];
  7180. b[m] = i;
  7181. }
  7182. Buffer.prototype.swap16 = function swap16 () {
  7183. var len = this.length;
  7184. if (len % 2 !== 0) {
  7185. throw new RangeError('Buffer size must be a multiple of 16-bits')
  7186. }
  7187. for (var i = 0; i < len; i += 2) {
  7188. swap(this, i, i + 1);
  7189. }
  7190. return this
  7191. };
  7192. Buffer.prototype.swap32 = function swap32 () {
  7193. var len = this.length;
  7194. if (len % 4 !== 0) {
  7195. throw new RangeError('Buffer size must be a multiple of 32-bits')
  7196. }
  7197. for (var i = 0; i < len; i += 4) {
  7198. swap(this, i, i + 3);
  7199. swap(this, i + 1, i + 2);
  7200. }
  7201. return this
  7202. };
  7203. Buffer.prototype.swap64 = function swap64 () {
  7204. var len = this.length;
  7205. if (len % 8 !== 0) {
  7206. throw new RangeError('Buffer size must be a multiple of 64-bits')
  7207. }
  7208. for (var i = 0; i < len; i += 8) {
  7209. swap(this, i, i + 7);
  7210. swap(this, i + 1, i + 6);
  7211. swap(this, i + 2, i + 5);
  7212. swap(this, i + 3, i + 4);
  7213. }
  7214. return this
  7215. };
  7216. Buffer.prototype.toString = function toString () {
  7217. var length = this.length | 0;
  7218. if (length === 0) return ''
  7219. if (arguments.length === 0) return utf8Slice(this, 0, length)
  7220. return slowToString.apply(this, arguments)
  7221. };
  7222. Buffer.prototype.equals = function equals (b) {
  7223. if (!internalIsBuffer(b)) throw new TypeError('Argument must be a Buffer')
  7224. if (this === b) return true
  7225. return Buffer.compare(this, b) === 0
  7226. };
  7227. Buffer.prototype.inspect = function inspect () {
  7228. var str = '';
  7229. var max = INSPECT_MAX_BYTES;
  7230. if (this.length > 0) {
  7231. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ');
  7232. if (this.length > max) str += ' ... ';
  7233. }
  7234. return '<Buffer ' + str + '>'
  7235. };
  7236. Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  7237. if (!internalIsBuffer(target)) {
  7238. throw new TypeError('Argument must be a Buffer')
  7239. }
  7240. if (start === undefined) {
  7241. start = 0;
  7242. }
  7243. if (end === undefined) {
  7244. end = target ? target.length : 0;
  7245. }
  7246. if (thisStart === undefined) {
  7247. thisStart = 0;
  7248. }
  7249. if (thisEnd === undefined) {
  7250. thisEnd = this.length;
  7251. }
  7252. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  7253. throw new RangeError('out of range index')
  7254. }
  7255. if (thisStart >= thisEnd && start >= end) {
  7256. return 0
  7257. }
  7258. if (thisStart >= thisEnd) {
  7259. return -1
  7260. }
  7261. if (start >= end) {
  7262. return 1
  7263. }
  7264. start >>>= 0;
  7265. end >>>= 0;
  7266. thisStart >>>= 0;
  7267. thisEnd >>>= 0;
  7268. if (this === target) return 0
  7269. var x = thisEnd - thisStart;
  7270. var y = end - start;
  7271. var len = Math.min(x, y);
  7272. var thisCopy = this.slice(thisStart, thisEnd);
  7273. var targetCopy = target.slice(start, end);
  7274. for (var i = 0; i < len; ++i) {
  7275. if (thisCopy[i] !== targetCopy[i]) {
  7276. x = thisCopy[i];
  7277. y = targetCopy[i];
  7278. break
  7279. }
  7280. }
  7281. if (x < y) return -1
  7282. if (y < x) return 1
  7283. return 0
  7284. };
  7285. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  7286. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  7287. //
  7288. // Arguments:
  7289. // - buffer - a Buffer to search
  7290. // - val - a string, Buffer, or number
  7291. // - byteOffset - an index into `buffer`; will be clamped to an int32
  7292. // - encoding - an optional encoding, relevant is val is a string
  7293. // - dir - true for indexOf, false for lastIndexOf
  7294. function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
  7295. // Empty buffer means no match
  7296. if (buffer.length === 0) return -1
  7297. // Normalize byteOffset
  7298. if (typeof byteOffset === 'string') {
  7299. encoding = byteOffset;
  7300. byteOffset = 0;
  7301. } else if (byteOffset > 0x7fffffff) {
  7302. byteOffset = 0x7fffffff;
  7303. } else if (byteOffset < -0x80000000) {
  7304. byteOffset = -0x80000000;
  7305. }
  7306. byteOffset = +byteOffset; // Coerce to Number.
  7307. if (isNaN(byteOffset)) {
  7308. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  7309. byteOffset = dir ? 0 : (buffer.length - 1);
  7310. }
  7311. // Normalize byteOffset: negative offsets start from the end of the buffer
  7312. if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
  7313. if (byteOffset >= buffer.length) {
  7314. if (dir) return -1
  7315. else byteOffset = buffer.length - 1;
  7316. } else if (byteOffset < 0) {
  7317. if (dir) byteOffset = 0;
  7318. else return -1
  7319. }
  7320. // Normalize val
  7321. if (typeof val === 'string') {
  7322. val = Buffer.from(val, encoding);
  7323. }
  7324. // Finally, search either indexOf (if dir is true) or lastIndexOf
  7325. if (internalIsBuffer(val)) {
  7326. // Special case: looking for empty string/buffer always fails
  7327. if (val.length === 0) {
  7328. return -1
  7329. }
  7330. return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
  7331. } else if (typeof val === 'number') {
  7332. val = val & 0xFF; // Search for a byte value [0-255]
  7333. if (Buffer.TYPED_ARRAY_SUPPORT &&
  7334. typeof Uint8Array.prototype.indexOf === 'function') {
  7335. if (dir) {
  7336. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
  7337. } else {
  7338. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
  7339. }
  7340. }
  7341. return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
  7342. }
  7343. throw new TypeError('val must be string, number or Buffer')
  7344. }
  7345. function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
  7346. var indexSize = 1;
  7347. var arrLength = arr.length;
  7348. var valLength = val.length;
  7349. if (encoding !== undefined) {
  7350. encoding = String(encoding).toLowerCase();
  7351. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  7352. encoding === 'utf16le' || encoding === 'utf-16le') {
  7353. if (arr.length < 2 || val.length < 2) {
  7354. return -1
  7355. }
  7356. indexSize = 2;
  7357. arrLength /= 2;
  7358. valLength /= 2;
  7359. byteOffset /= 2;
  7360. }
  7361. }
  7362. function read (buf, i) {
  7363. if (indexSize === 1) {
  7364. return buf[i]
  7365. } else {
  7366. return buf.readUInt16BE(i * indexSize)
  7367. }
  7368. }
  7369. var i;
  7370. if (dir) {
  7371. var foundIndex = -1;
  7372. for (i = byteOffset; i < arrLength; i++) {
  7373. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  7374. if (foundIndex === -1) foundIndex = i;
  7375. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  7376. } else {
  7377. if (foundIndex !== -1) i -= i - foundIndex;
  7378. foundIndex = -1;
  7379. }
  7380. }
  7381. } else {
  7382. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
  7383. for (i = byteOffset; i >= 0; i--) {
  7384. var found = true;
  7385. for (var j = 0; j < valLength; j++) {
  7386. if (read(arr, i + j) !== read(val, j)) {
  7387. found = false;
  7388. break
  7389. }
  7390. }
  7391. if (found) return i
  7392. }
  7393. }
  7394. return -1
  7395. }
  7396. Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
  7397. return this.indexOf(val, byteOffset, encoding) !== -1
  7398. };
  7399. Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  7400. return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
  7401. };
  7402. Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
  7403. return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
  7404. };
  7405. function hexWrite (buf, string, offset, length) {
  7406. offset = Number(offset) || 0;
  7407. var remaining = buf.length - offset;
  7408. if (!length) {
  7409. length = remaining;
  7410. } else {
  7411. length = Number(length);
  7412. if (length > remaining) {
  7413. length = remaining;
  7414. }
  7415. }
  7416. // must be an even number of digits
  7417. var strLen = string.length;
  7418. if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
  7419. if (length > strLen / 2) {
  7420. length = strLen / 2;
  7421. }
  7422. for (var i = 0; i < length; ++i) {
  7423. var parsed = parseInt(string.substr(i * 2, 2), 16);
  7424. if (isNaN(parsed)) return i
  7425. buf[offset + i] = parsed;
  7426. }
  7427. return i
  7428. }
  7429. function utf8Write (buf, string, offset, length) {
  7430. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  7431. }
  7432. function asciiWrite (buf, string, offset, length) {
  7433. return blitBuffer(asciiToBytes(string), buf, offset, length)
  7434. }
  7435. function latin1Write (buf, string, offset, length) {
  7436. return asciiWrite(buf, string, offset, length)
  7437. }
  7438. function base64Write (buf, string, offset, length) {
  7439. return blitBuffer(base64ToBytes(string), buf, offset, length)
  7440. }
  7441. function ucs2Write (buf, string, offset, length) {
  7442. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  7443. }
  7444. Buffer.prototype.write = function write (string, offset, length, encoding) {
  7445. // Buffer#write(string)
  7446. if (offset === undefined) {
  7447. encoding = 'utf8';
  7448. length = this.length;
  7449. offset = 0;
  7450. // Buffer#write(string, encoding)
  7451. } else if (length === undefined && typeof offset === 'string') {
  7452. encoding = offset;
  7453. length = this.length;
  7454. offset = 0;
  7455. // Buffer#write(string, offset[, length][, encoding])
  7456. } else if (isFinite(offset)) {
  7457. offset = offset | 0;
  7458. if (isFinite(length)) {
  7459. length = length | 0;
  7460. if (encoding === undefined) encoding = 'utf8';
  7461. } else {
  7462. encoding = length;
  7463. length = undefined;
  7464. }
  7465. // legacy write(string, encoding, offset, length) - remove in v0.13
  7466. } else {
  7467. throw new Error(
  7468. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  7469. )
  7470. }
  7471. var remaining = this.length - offset;
  7472. if (length === undefined || length > remaining) length = remaining;
  7473. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  7474. throw new RangeError('Attempt to write outside buffer bounds')
  7475. }
  7476. if (!encoding) encoding = 'utf8';
  7477. var loweredCase = false;
  7478. for (;;) {
  7479. switch (encoding) {
  7480. case 'hex':
  7481. return hexWrite(this, string, offset, length)
  7482. case 'utf8':
  7483. case 'utf-8':
  7484. return utf8Write(this, string, offset, length)
  7485. case 'ascii':
  7486. return asciiWrite(this, string, offset, length)
  7487. case 'latin1':
  7488. case 'binary':
  7489. return latin1Write(this, string, offset, length)
  7490. case 'base64':
  7491. // Warning: maxLength not taken into account in base64Write
  7492. return base64Write(this, string, offset, length)
  7493. case 'ucs2':
  7494. case 'ucs-2':
  7495. case 'utf16le':
  7496. case 'utf-16le':
  7497. return ucs2Write(this, string, offset, length)
  7498. default:
  7499. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  7500. encoding = ('' + encoding).toLowerCase();
  7501. loweredCase = true;
  7502. }
  7503. }
  7504. };
  7505. Buffer.prototype.toJSON = function toJSON () {
  7506. return {
  7507. type: 'Buffer',
  7508. data: Array.prototype.slice.call(this._arr || this, 0)
  7509. }
  7510. };
  7511. function base64Slice (buf, start, end) {
  7512. if (start === 0 && end === buf.length) {
  7513. return fromByteArray(buf)
  7514. } else {
  7515. return fromByteArray(buf.slice(start, end))
  7516. }
  7517. }
  7518. function utf8Slice (buf, start, end) {
  7519. end = Math.min(buf.length, end);
  7520. var res = [];
  7521. var i = start;
  7522. while (i < end) {
  7523. var firstByte = buf[i];
  7524. var codePoint = null;
  7525. var bytesPerSequence = (firstByte > 0xEF) ? 4
  7526. : (firstByte > 0xDF) ? 3
  7527. : (firstByte > 0xBF) ? 2
  7528. : 1;
  7529. if (i + bytesPerSequence <= end) {
  7530. var secondByte, thirdByte, fourthByte, tempCodePoint;
  7531. switch (bytesPerSequence) {
  7532. case 1:
  7533. if (firstByte < 0x80) {
  7534. codePoint = firstByte;
  7535. }
  7536. break
  7537. case 2:
  7538. secondByte = buf[i + 1];
  7539. if ((secondByte & 0xC0) === 0x80) {
  7540. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
  7541. if (tempCodePoint > 0x7F) {
  7542. codePoint = tempCodePoint;
  7543. }
  7544. }
  7545. break
  7546. case 3:
  7547. secondByte = buf[i + 1];
  7548. thirdByte = buf[i + 2];
  7549. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  7550. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
  7551. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  7552. codePoint = tempCodePoint;
  7553. }
  7554. }
  7555. break
  7556. case 4:
  7557. secondByte = buf[i + 1];
  7558. thirdByte = buf[i + 2];
  7559. fourthByte = buf[i + 3];
  7560. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  7561. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
  7562. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  7563. codePoint = tempCodePoint;
  7564. }
  7565. }
  7566. }
  7567. }
  7568. if (codePoint === null) {
  7569. // we did not generate a valid codePoint so insert a
  7570. // replacement char (U+FFFD) and advance only 1 byte
  7571. codePoint = 0xFFFD;
  7572. bytesPerSequence = 1;
  7573. } else if (codePoint > 0xFFFF) {
  7574. // encode to utf16 (surrogate pair dance)
  7575. codePoint -= 0x10000;
  7576. res.push(codePoint >>> 10 & 0x3FF | 0xD800);
  7577. codePoint = 0xDC00 | codePoint & 0x3FF;
  7578. }
  7579. res.push(codePoint);
  7580. i += bytesPerSequence;
  7581. }
  7582. return decodeCodePointsArray(res)
  7583. }
  7584. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  7585. // the lowest limit is Chrome, with 0x10000 args.
  7586. // We go 1 magnitude less, for safety
  7587. var MAX_ARGUMENTS_LENGTH = 0x1000;
  7588. function decodeCodePointsArray (codePoints) {
  7589. var len = codePoints.length;
  7590. if (len <= MAX_ARGUMENTS_LENGTH) {
  7591. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  7592. }
  7593. // Decode in chunks to avoid "call stack size exceeded".
  7594. var res = '';
  7595. var i = 0;
  7596. while (i < len) {
  7597. res += String.fromCharCode.apply(
  7598. String,
  7599. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  7600. );
  7601. }
  7602. return res
  7603. }
  7604. function asciiSlice (buf, start, end) {
  7605. var ret = '';
  7606. end = Math.min(buf.length, end);
  7607. for (var i = start; i < end; ++i) {
  7608. ret += String.fromCharCode(buf[i] & 0x7F);
  7609. }
  7610. return ret
  7611. }
  7612. function latin1Slice (buf, start, end) {
  7613. var ret = '';
  7614. end = Math.min(buf.length, end);
  7615. for (var i = start; i < end; ++i) {
  7616. ret += String.fromCharCode(buf[i]);
  7617. }
  7618. return ret
  7619. }
  7620. function hexSlice (buf, start, end) {
  7621. var len = buf.length;
  7622. if (!start || start < 0) start = 0;
  7623. if (!end || end < 0 || end > len) end = len;
  7624. var out = '';
  7625. for (var i = start; i < end; ++i) {
  7626. out += toHex(buf[i]);
  7627. }
  7628. return out
  7629. }
  7630. function utf16leSlice (buf, start, end) {
  7631. var bytes = buf.slice(start, end);
  7632. var res = '';
  7633. for (var i = 0; i < bytes.length; i += 2) {
  7634. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
  7635. }
  7636. return res
  7637. }
  7638. Buffer.prototype.slice = function slice (start, end) {
  7639. var len = this.length;
  7640. start = ~~start;
  7641. end = end === undefined ? len : ~~end;
  7642. if (start < 0) {
  7643. start += len;
  7644. if (start < 0) start = 0;
  7645. } else if (start > len) {
  7646. start = len;
  7647. }
  7648. if (end < 0) {
  7649. end += len;
  7650. if (end < 0) end = 0;
  7651. } else if (end > len) {
  7652. end = len;
  7653. }
  7654. if (end < start) end = start;
  7655. var newBuf;
  7656. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7657. newBuf = this.subarray(start, end);
  7658. newBuf.__proto__ = Buffer.prototype;
  7659. } else {
  7660. var sliceLen = end - start;
  7661. newBuf = new Buffer(sliceLen, undefined);
  7662. for (var i = 0; i < sliceLen; ++i) {
  7663. newBuf[i] = this[i + start];
  7664. }
  7665. }
  7666. return newBuf
  7667. };
  7668. /*
  7669. * Need to make sure that buffer isn't trying to write out of bounds.
  7670. */
  7671. function checkOffset (offset, ext, length) {
  7672. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  7673. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  7674. }
  7675. Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  7676. offset = offset | 0;
  7677. byteLength = byteLength | 0;
  7678. if (!noAssert) checkOffset(offset, byteLength, this.length);
  7679. var val = this[offset];
  7680. var mul = 1;
  7681. var i = 0;
  7682. while (++i < byteLength && (mul *= 0x100)) {
  7683. val += this[offset + i] * mul;
  7684. }
  7685. return val
  7686. };
  7687. Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  7688. offset = offset | 0;
  7689. byteLength = byteLength | 0;
  7690. if (!noAssert) {
  7691. checkOffset(offset, byteLength, this.length);
  7692. }
  7693. var val = this[offset + --byteLength];
  7694. var mul = 1;
  7695. while (byteLength > 0 && (mul *= 0x100)) {
  7696. val += this[offset + --byteLength] * mul;
  7697. }
  7698. return val
  7699. };
  7700. Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  7701. if (!noAssert) checkOffset(offset, 1, this.length);
  7702. return this[offset]
  7703. };
  7704. Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  7705. if (!noAssert) checkOffset(offset, 2, this.length);
  7706. return this[offset] | (this[offset + 1] << 8)
  7707. };
  7708. Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  7709. if (!noAssert) checkOffset(offset, 2, this.length);
  7710. return (this[offset] << 8) | this[offset + 1]
  7711. };
  7712. Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  7713. if (!noAssert) checkOffset(offset, 4, this.length);
  7714. return ((this[offset]) |
  7715. (this[offset + 1] << 8) |
  7716. (this[offset + 2] << 16)) +
  7717. (this[offset + 3] * 0x1000000)
  7718. };
  7719. Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  7720. if (!noAssert) checkOffset(offset, 4, this.length);
  7721. return (this[offset] * 0x1000000) +
  7722. ((this[offset + 1] << 16) |
  7723. (this[offset + 2] << 8) |
  7724. this[offset + 3])
  7725. };
  7726. Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  7727. offset = offset | 0;
  7728. byteLength = byteLength | 0;
  7729. if (!noAssert) checkOffset(offset, byteLength, this.length);
  7730. var val = this[offset];
  7731. var mul = 1;
  7732. var i = 0;
  7733. while (++i < byteLength && (mul *= 0x100)) {
  7734. val += this[offset + i] * mul;
  7735. }
  7736. mul *= 0x80;
  7737. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  7738. return val
  7739. };
  7740. Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  7741. offset = offset | 0;
  7742. byteLength = byteLength | 0;
  7743. if (!noAssert) checkOffset(offset, byteLength, this.length);
  7744. var i = byteLength;
  7745. var mul = 1;
  7746. var val = this[offset + --i];
  7747. while (i > 0 && (mul *= 0x100)) {
  7748. val += this[offset + --i] * mul;
  7749. }
  7750. mul *= 0x80;
  7751. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  7752. return val
  7753. };
  7754. Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
  7755. if (!noAssert) checkOffset(offset, 1, this.length);
  7756. if (!(this[offset] & 0x80)) return (this[offset])
  7757. return ((0xff - this[offset] + 1) * -1)
  7758. };
  7759. Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  7760. if (!noAssert) checkOffset(offset, 2, this.length);
  7761. var val = this[offset] | (this[offset + 1] << 8);
  7762. return (val & 0x8000) ? val | 0xFFFF0000 : val
  7763. };
  7764. Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  7765. if (!noAssert) checkOffset(offset, 2, this.length);
  7766. var val = this[offset + 1] | (this[offset] << 8);
  7767. return (val & 0x8000) ? val | 0xFFFF0000 : val
  7768. };
  7769. Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  7770. if (!noAssert) checkOffset(offset, 4, this.length);
  7771. return (this[offset]) |
  7772. (this[offset + 1] << 8) |
  7773. (this[offset + 2] << 16) |
  7774. (this[offset + 3] << 24)
  7775. };
  7776. Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  7777. if (!noAssert) checkOffset(offset, 4, this.length);
  7778. return (this[offset] << 24) |
  7779. (this[offset + 1] << 16) |
  7780. (this[offset + 2] << 8) |
  7781. (this[offset + 3])
  7782. };
  7783. Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  7784. if (!noAssert) checkOffset(offset, 4, this.length);
  7785. return read(this, offset, true, 23, 4)
  7786. };
  7787. Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  7788. if (!noAssert) checkOffset(offset, 4, this.length);
  7789. return read(this, offset, false, 23, 4)
  7790. };
  7791. Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  7792. if (!noAssert) checkOffset(offset, 8, this.length);
  7793. return read(this, offset, true, 52, 8)
  7794. };
  7795. Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  7796. if (!noAssert) checkOffset(offset, 8, this.length);
  7797. return read(this, offset, false, 52, 8)
  7798. };
  7799. function checkInt (buf, value, offset, ext, max, min) {
  7800. if (!internalIsBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  7801. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  7802. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  7803. }
  7804. Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  7805. value = +value;
  7806. offset = offset | 0;
  7807. byteLength = byteLength | 0;
  7808. if (!noAssert) {
  7809. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  7810. checkInt(this, value, offset, byteLength, maxBytes, 0);
  7811. }
  7812. var mul = 1;
  7813. var i = 0;
  7814. this[offset] = value & 0xFF;
  7815. while (++i < byteLength && (mul *= 0x100)) {
  7816. this[offset + i] = (value / mul) & 0xFF;
  7817. }
  7818. return offset + byteLength
  7819. };
  7820. Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  7821. value = +value;
  7822. offset = offset | 0;
  7823. byteLength = byteLength | 0;
  7824. if (!noAssert) {
  7825. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  7826. checkInt(this, value, offset, byteLength, maxBytes, 0);
  7827. }
  7828. var i = byteLength - 1;
  7829. var mul = 1;
  7830. this[offset + i] = value & 0xFF;
  7831. while (--i >= 0 && (mul *= 0x100)) {
  7832. this[offset + i] = (value / mul) & 0xFF;
  7833. }
  7834. return offset + byteLength
  7835. };
  7836. Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  7837. value = +value;
  7838. offset = offset | 0;
  7839. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
  7840. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
  7841. this[offset] = (value & 0xff);
  7842. return offset + 1
  7843. };
  7844. function objectWriteUInt16 (buf, value, offset, littleEndian) {
  7845. if (value < 0) value = 0xffff + value + 1;
  7846. for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
  7847. buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  7848. (littleEndian ? i : 1 - i) * 8;
  7849. }
  7850. }
  7851. Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  7852. value = +value;
  7853. offset = offset | 0;
  7854. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  7855. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7856. this[offset] = (value & 0xff);
  7857. this[offset + 1] = (value >>> 8);
  7858. } else {
  7859. objectWriteUInt16(this, value, offset, true);
  7860. }
  7861. return offset + 2
  7862. };
  7863. Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  7864. value = +value;
  7865. offset = offset | 0;
  7866. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  7867. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7868. this[offset] = (value >>> 8);
  7869. this[offset + 1] = (value & 0xff);
  7870. } else {
  7871. objectWriteUInt16(this, value, offset, false);
  7872. }
  7873. return offset + 2
  7874. };
  7875. function objectWriteUInt32 (buf, value, offset, littleEndian) {
  7876. if (value < 0) value = 0xffffffff + value + 1;
  7877. for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
  7878. buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff;
  7879. }
  7880. }
  7881. Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  7882. value = +value;
  7883. offset = offset | 0;
  7884. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  7885. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7886. this[offset + 3] = (value >>> 24);
  7887. this[offset + 2] = (value >>> 16);
  7888. this[offset + 1] = (value >>> 8);
  7889. this[offset] = (value & 0xff);
  7890. } else {
  7891. objectWriteUInt32(this, value, offset, true);
  7892. }
  7893. return offset + 4
  7894. };
  7895. Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  7896. value = +value;
  7897. offset = offset | 0;
  7898. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  7899. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7900. this[offset] = (value >>> 24);
  7901. this[offset + 1] = (value >>> 16);
  7902. this[offset + 2] = (value >>> 8);
  7903. this[offset + 3] = (value & 0xff);
  7904. } else {
  7905. objectWriteUInt32(this, value, offset, false);
  7906. }
  7907. return offset + 4
  7908. };
  7909. Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  7910. value = +value;
  7911. offset = offset | 0;
  7912. if (!noAssert) {
  7913. var limit = Math.pow(2, 8 * byteLength - 1);
  7914. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  7915. }
  7916. var i = 0;
  7917. var mul = 1;
  7918. var sub = 0;
  7919. this[offset] = value & 0xFF;
  7920. while (++i < byteLength && (mul *= 0x100)) {
  7921. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  7922. sub = 1;
  7923. }
  7924. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
  7925. }
  7926. return offset + byteLength
  7927. };
  7928. Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  7929. value = +value;
  7930. offset = offset | 0;
  7931. if (!noAssert) {
  7932. var limit = Math.pow(2, 8 * byteLength - 1);
  7933. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  7934. }
  7935. var i = byteLength - 1;
  7936. var mul = 1;
  7937. var sub = 0;
  7938. this[offset + i] = value & 0xFF;
  7939. while (--i >= 0 && (mul *= 0x100)) {
  7940. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  7941. sub = 1;
  7942. }
  7943. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
  7944. }
  7945. return offset + byteLength
  7946. };
  7947. Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  7948. value = +value;
  7949. offset = offset | 0;
  7950. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
  7951. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
  7952. if (value < 0) value = 0xff + value + 1;
  7953. this[offset] = (value & 0xff);
  7954. return offset + 1
  7955. };
  7956. Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  7957. value = +value;
  7958. offset = offset | 0;
  7959. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  7960. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7961. this[offset] = (value & 0xff);
  7962. this[offset + 1] = (value >>> 8);
  7963. } else {
  7964. objectWriteUInt16(this, value, offset, true);
  7965. }
  7966. return offset + 2
  7967. };
  7968. Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  7969. value = +value;
  7970. offset = offset | 0;
  7971. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  7972. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7973. this[offset] = (value >>> 8);
  7974. this[offset + 1] = (value & 0xff);
  7975. } else {
  7976. objectWriteUInt16(this, value, offset, false);
  7977. }
  7978. return offset + 2
  7979. };
  7980. Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  7981. value = +value;
  7982. offset = offset | 0;
  7983. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  7984. if (Buffer.TYPED_ARRAY_SUPPORT) {
  7985. this[offset] = (value & 0xff);
  7986. this[offset + 1] = (value >>> 8);
  7987. this[offset + 2] = (value >>> 16);
  7988. this[offset + 3] = (value >>> 24);
  7989. } else {
  7990. objectWriteUInt32(this, value, offset, true);
  7991. }
  7992. return offset + 4
  7993. };
  7994. Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  7995. value = +value;
  7996. offset = offset | 0;
  7997. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  7998. if (value < 0) value = 0xffffffff + value + 1;
  7999. if (Buffer.TYPED_ARRAY_SUPPORT) {
  8000. this[offset] = (value >>> 24);
  8001. this[offset + 1] = (value >>> 16);
  8002. this[offset + 2] = (value >>> 8);
  8003. this[offset + 3] = (value & 0xff);
  8004. } else {
  8005. objectWriteUInt32(this, value, offset, false);
  8006. }
  8007. return offset + 4
  8008. };
  8009. function checkIEEE754 (buf, value, offset, ext, max, min) {
  8010. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  8011. if (offset < 0) throw new RangeError('Index out of range')
  8012. }
  8013. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  8014. if (!noAssert) {
  8015. checkIEEE754(buf, value, offset, 4);
  8016. }
  8017. write(buf, value, offset, littleEndian, 23, 4);
  8018. return offset + 4
  8019. }
  8020. Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  8021. return writeFloat(this, value, offset, true, noAssert)
  8022. };
  8023. Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  8024. return writeFloat(this, value, offset, false, noAssert)
  8025. };
  8026. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  8027. if (!noAssert) {
  8028. checkIEEE754(buf, value, offset, 8);
  8029. }
  8030. write(buf, value, offset, littleEndian, 52, 8);
  8031. return offset + 8
  8032. }
  8033. Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  8034. return writeDouble(this, value, offset, true, noAssert)
  8035. };
  8036. Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  8037. return writeDouble(this, value, offset, false, noAssert)
  8038. };
  8039. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  8040. Buffer.prototype.copy = function copy (target, targetStart, start, end) {
  8041. if (!start) start = 0;
  8042. if (!end && end !== 0) end = this.length;
  8043. if (targetStart >= target.length) targetStart = target.length;
  8044. if (!targetStart) targetStart = 0;
  8045. if (end > 0 && end < start) end = start;
  8046. // Copy 0 bytes; we're done
  8047. if (end === start) return 0
  8048. if (target.length === 0 || this.length === 0) return 0
  8049. // Fatal error conditions
  8050. if (targetStart < 0) {
  8051. throw new RangeError('targetStart out of bounds')
  8052. }
  8053. if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
  8054. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  8055. // Are we oob?
  8056. if (end > this.length) end = this.length;
  8057. if (target.length - targetStart < end - start) {
  8058. end = target.length - targetStart + start;
  8059. }
  8060. var len = end - start;
  8061. var i;
  8062. if (this === target && start < targetStart && targetStart < end) {
  8063. // descending copy from end
  8064. for (i = len - 1; i >= 0; --i) {
  8065. target[i + targetStart] = this[i + start];
  8066. }
  8067. } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
  8068. // ascending copy from start
  8069. for (i = 0; i < len; ++i) {
  8070. target[i + targetStart] = this[i + start];
  8071. }
  8072. } else {
  8073. Uint8Array.prototype.set.call(
  8074. target,
  8075. this.subarray(start, start + len),
  8076. targetStart
  8077. );
  8078. }
  8079. return len
  8080. };
  8081. // Usage:
  8082. // buffer.fill(number[, offset[, end]])
  8083. // buffer.fill(buffer[, offset[, end]])
  8084. // buffer.fill(string[, offset[, end]][, encoding])
  8085. Buffer.prototype.fill = function fill (val, start, end, encoding) {
  8086. // Handle string cases:
  8087. if (typeof val === 'string') {
  8088. if (typeof start === 'string') {
  8089. encoding = start;
  8090. start = 0;
  8091. end = this.length;
  8092. } else if (typeof end === 'string') {
  8093. encoding = end;
  8094. end = this.length;
  8095. }
  8096. if (val.length === 1) {
  8097. var code = val.charCodeAt(0);
  8098. if (code < 256) {
  8099. val = code;
  8100. }
  8101. }
  8102. if (encoding !== undefined && typeof encoding !== 'string') {
  8103. throw new TypeError('encoding must be a string')
  8104. }
  8105. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  8106. throw new TypeError('Unknown encoding: ' + encoding)
  8107. }
  8108. } else if (typeof val === 'number') {
  8109. val = val & 255;
  8110. }
  8111. // Invalid ranges are not set to a default, so can range check early.
  8112. if (start < 0 || this.length < start || this.length < end) {
  8113. throw new RangeError('Out of range index')
  8114. }
  8115. if (end <= start) {
  8116. return this
  8117. }
  8118. start = start >>> 0;
  8119. end = end === undefined ? this.length : end >>> 0;
  8120. if (!val) val = 0;
  8121. var i;
  8122. if (typeof val === 'number') {
  8123. for (i = start; i < end; ++i) {
  8124. this[i] = val;
  8125. }
  8126. } else {
  8127. var bytes = internalIsBuffer(val)
  8128. ? val
  8129. : utf8ToBytes(new Buffer(val, encoding).toString());
  8130. var len = bytes.length;
  8131. for (i = 0; i < end - start; ++i) {
  8132. this[i + start] = bytes[i % len];
  8133. }
  8134. }
  8135. return this
  8136. };
  8137. // HELPER FUNCTIONS
  8138. // ================
  8139. var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;
  8140. function base64clean (str) {
  8141. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  8142. str = stringtrim(str).replace(INVALID_BASE64_RE, '');
  8143. // Node converts strings with length < 2 to ''
  8144. if (str.length < 2) return ''
  8145. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  8146. while (str.length % 4 !== 0) {
  8147. str = str + '=';
  8148. }
  8149. return str
  8150. }
  8151. function stringtrim (str) {
  8152. if (str.trim) return str.trim()
  8153. return str.replace(/^\s+|\s+$/g, '')
  8154. }
  8155. function toHex (n) {
  8156. if (n < 16) return '0' + n.toString(16)
  8157. return n.toString(16)
  8158. }
  8159. function utf8ToBytes (string, units) {
  8160. units = units || Infinity;
  8161. var codePoint;
  8162. var length = string.length;
  8163. var leadSurrogate = null;
  8164. var bytes = [];
  8165. for (var i = 0; i < length; ++i) {
  8166. codePoint = string.charCodeAt(i);
  8167. // is surrogate component
  8168. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  8169. // last char was a lead
  8170. if (!leadSurrogate) {
  8171. // no lead yet
  8172. if (codePoint > 0xDBFF) {
  8173. // unexpected trail
  8174. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  8175. continue
  8176. } else if (i + 1 === length) {
  8177. // unpaired lead
  8178. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  8179. continue
  8180. }
  8181. // valid lead
  8182. leadSurrogate = codePoint;
  8183. continue
  8184. }
  8185. // 2 leads in a row
  8186. if (codePoint < 0xDC00) {
  8187. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  8188. leadSurrogate = codePoint;
  8189. continue
  8190. }
  8191. // valid surrogate pair
  8192. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
  8193. } else if (leadSurrogate) {
  8194. // valid bmp char, but last char was a lead
  8195. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  8196. }
  8197. leadSurrogate = null;
  8198. // encode utf8
  8199. if (codePoint < 0x80) {
  8200. if ((units -= 1) < 0) break
  8201. bytes.push(codePoint);
  8202. } else if (codePoint < 0x800) {
  8203. if ((units -= 2) < 0) break
  8204. bytes.push(
  8205. codePoint >> 0x6 | 0xC0,
  8206. codePoint & 0x3F | 0x80
  8207. );
  8208. } else if (codePoint < 0x10000) {
  8209. if ((units -= 3) < 0) break
  8210. bytes.push(
  8211. codePoint >> 0xC | 0xE0,
  8212. codePoint >> 0x6 & 0x3F | 0x80,
  8213. codePoint & 0x3F | 0x80
  8214. );
  8215. } else if (codePoint < 0x110000) {
  8216. if ((units -= 4) < 0) break
  8217. bytes.push(
  8218. codePoint >> 0x12 | 0xF0,
  8219. codePoint >> 0xC & 0x3F | 0x80,
  8220. codePoint >> 0x6 & 0x3F | 0x80,
  8221. codePoint & 0x3F | 0x80
  8222. );
  8223. } else {
  8224. throw new Error('Invalid code point')
  8225. }
  8226. }
  8227. return bytes
  8228. }
  8229. function asciiToBytes (str) {
  8230. var byteArray = [];
  8231. for (var i = 0; i < str.length; ++i) {
  8232. // Node's code seems to be doing this and not & 0x7F..
  8233. byteArray.push(str.charCodeAt(i) & 0xFF);
  8234. }
  8235. return byteArray
  8236. }
  8237. function utf16leToBytes (str, units) {
  8238. var c, hi, lo;
  8239. var byteArray = [];
  8240. for (var i = 0; i < str.length; ++i) {
  8241. if ((units -= 2) < 0) break
  8242. c = str.charCodeAt(i);
  8243. hi = c >> 8;
  8244. lo = c % 256;
  8245. byteArray.push(lo);
  8246. byteArray.push(hi);
  8247. }
  8248. return byteArray
  8249. }
  8250. function base64ToBytes (str) {
  8251. return toByteArray(base64clean(str))
  8252. }
  8253. function blitBuffer (src, dst, offset, length) {
  8254. for (var i = 0; i < length; ++i) {
  8255. if ((i + offset >= dst.length) || (i >= src.length)) break
  8256. dst[i + offset] = src[i];
  8257. }
  8258. return i
  8259. }
  8260. function isnan (val) {
  8261. return val !== val // eslint-disable-line no-self-compare
  8262. }
  8263. // the following is from is-buffer, also by Feross Aboukhadijeh and with same lisence
  8264. // The _isBuffer check is for Safari 5-7 support, because it's missing
  8265. // Object.prototype.constructor. Remove this eventually
  8266. function isBuffer(obj) {
  8267. return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj))
  8268. }
  8269. function isFastBuffer (obj) {
  8270. return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
  8271. }
  8272. // For Node v0.10 support. Remove this eventually.
  8273. function isSlowBuffer (obj) {
  8274. return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isFastBuffer(obj.slice(0, 0))
  8275. }
  8276. // shim for using process in browser
  8277. // based off https://github.com/defunctzombie/node-process/blob/master/browser.js
  8278. function defaultSetTimout() {
  8279. throw new Error('setTimeout has not been defined');
  8280. }
  8281. function defaultClearTimeout () {
  8282. throw new Error('clearTimeout has not been defined');
  8283. }
  8284. var cachedSetTimeout = defaultSetTimout;
  8285. var cachedClearTimeout = defaultClearTimeout;
  8286. if (typeof global$1.setTimeout === 'function') {
  8287. cachedSetTimeout = setTimeout;
  8288. }
  8289. if (typeof global$1.clearTimeout === 'function') {
  8290. cachedClearTimeout = clearTimeout;
  8291. }
  8292. function runTimeout(fun) {
  8293. if (cachedSetTimeout === setTimeout) {
  8294. //normal enviroments in sane situations
  8295. return setTimeout(fun, 0);
  8296. }
  8297. // if setTimeout wasn't available but was latter defined
  8298. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  8299. cachedSetTimeout = setTimeout;
  8300. return setTimeout(fun, 0);
  8301. }
  8302. try {
  8303. // when when somebody has screwed with setTimeout but no I.E. maddness
  8304. return cachedSetTimeout(fun, 0);
  8305. } catch(e){
  8306. try {
  8307. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  8308. return cachedSetTimeout.call(null, fun, 0);
  8309. } catch(e){
  8310. // 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
  8311. return cachedSetTimeout.call(this, fun, 0);
  8312. }
  8313. }
  8314. }
  8315. function runClearTimeout(marker) {
  8316. if (cachedClearTimeout === clearTimeout) {
  8317. //normal enviroments in sane situations
  8318. return clearTimeout(marker);
  8319. }
  8320. // if clearTimeout wasn't available but was latter defined
  8321. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  8322. cachedClearTimeout = clearTimeout;
  8323. return clearTimeout(marker);
  8324. }
  8325. try {
  8326. // when when somebody has screwed with setTimeout but no I.E. maddness
  8327. return cachedClearTimeout(marker);
  8328. } catch (e){
  8329. try {
  8330. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  8331. return cachedClearTimeout.call(null, marker);
  8332. } catch (e){
  8333. // 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.
  8334. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  8335. return cachedClearTimeout.call(this, marker);
  8336. }
  8337. }
  8338. }
  8339. var queue = [];
  8340. var draining = false;
  8341. var currentQueue;
  8342. var queueIndex = -1;
  8343. function cleanUpNextTick() {
  8344. if (!draining || !currentQueue) {
  8345. return;
  8346. }
  8347. draining = false;
  8348. if (currentQueue.length) {
  8349. queue = currentQueue.concat(queue);
  8350. } else {
  8351. queueIndex = -1;
  8352. }
  8353. if (queue.length) {
  8354. drainQueue();
  8355. }
  8356. }
  8357. function drainQueue() {
  8358. if (draining) {
  8359. return;
  8360. }
  8361. var timeout = runTimeout(cleanUpNextTick);
  8362. draining = true;
  8363. var len = queue.length;
  8364. while(len) {
  8365. currentQueue = queue;
  8366. queue = [];
  8367. while (++queueIndex < len) {
  8368. if (currentQueue) {
  8369. currentQueue[queueIndex].run();
  8370. }
  8371. }
  8372. queueIndex = -1;
  8373. len = queue.length;
  8374. }
  8375. currentQueue = null;
  8376. draining = false;
  8377. runClearTimeout(timeout);
  8378. }
  8379. function nextTick(fun) {
  8380. var args = new Array(arguments.length - 1);
  8381. if (arguments.length > 1) {
  8382. for (var i = 1; i < arguments.length; i++) {
  8383. args[i - 1] = arguments[i];
  8384. }
  8385. }
  8386. queue.push(new Item(fun, args));
  8387. if (queue.length === 1 && !draining) {
  8388. runTimeout(drainQueue);
  8389. }
  8390. }
  8391. // v8 likes predictible objects
  8392. function Item(fun, array) {
  8393. this.fun = fun;
  8394. this.array = array;
  8395. }
  8396. Item.prototype.run = function () {
  8397. this.fun.apply(null, this.array);
  8398. };
  8399. var title = 'browser';
  8400. var platform = 'browser';
  8401. var browser = true;
  8402. var env = {};
  8403. var argv = [];
  8404. var version = ''; // empty string to avoid regexp issues
  8405. var versions = {};
  8406. var release = {};
  8407. var config = {};
  8408. function noop() {}
  8409. var on = noop;
  8410. var addListener = noop;
  8411. var once = noop;
  8412. var off = noop;
  8413. var removeListener = noop;
  8414. var removeAllListeners = noop;
  8415. var emit = noop;
  8416. function binding(name) {
  8417. throw new Error('process.binding is not supported');
  8418. }
  8419. function cwd () { return '/' }
  8420. function chdir (dir) {
  8421. throw new Error('process.chdir is not supported');
  8422. }function umask() { return 0; }
  8423. // from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
  8424. var performance = global$1.performance || {};
  8425. var performanceNow =
  8426. performance.now ||
  8427. performance.mozNow ||
  8428. performance.msNow ||
  8429. performance.oNow ||
  8430. performance.webkitNow ||
  8431. function(){ return (new Date()).getTime() };
  8432. // generate timestamp or delta
  8433. // see http://nodejs.org/api/process.html#process_process_hrtime
  8434. function hrtime(previousTimestamp){
  8435. var clocktime = performanceNow.call(performance)*1e-3;
  8436. var seconds = Math.floor(clocktime);
  8437. var nanoseconds = Math.floor((clocktime%1)*1e9);
  8438. if (previousTimestamp) {
  8439. seconds = seconds - previousTimestamp[0];
  8440. nanoseconds = nanoseconds - previousTimestamp[1];
  8441. if (nanoseconds<0) {
  8442. seconds--;
  8443. nanoseconds += 1e9;
  8444. }
  8445. }
  8446. return [seconds,nanoseconds]
  8447. }
  8448. var startTime = new Date();
  8449. function uptime() {
  8450. var currentTime = new Date();
  8451. var dif = currentTime - startTime;
  8452. return dif / 1000;
  8453. }
  8454. var browser$1 = {
  8455. nextTick: nextTick,
  8456. title: title,
  8457. browser: browser,
  8458. env: env,
  8459. argv: argv,
  8460. version: version,
  8461. versions: versions,
  8462. on: on,
  8463. addListener: addListener,
  8464. once: once,
  8465. off: off,
  8466. removeListener: removeListener,
  8467. removeAllListeners: removeAllListeners,
  8468. emit: emit,
  8469. binding: binding,
  8470. cwd: cwd,
  8471. chdir: chdir,
  8472. umask: umask,
  8473. hrtime: hrtime,
  8474. platform: platform,
  8475. release: release,
  8476. config: config,
  8477. uptime: uptime
  8478. };
  8479. var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  8480. function getDefaultExportFromCjs (x) {
  8481. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  8482. }
  8483. function getAugmentedNamespace(n) {
  8484. if (n.__esModule) return n;
  8485. var f = n.default;
  8486. if (typeof f == "function") {
  8487. var a = function a () {
  8488. if (this instanceof a) {
  8489. return Reflect.construct(f, arguments, this.constructor);
  8490. }
  8491. return f.apply(this, arguments);
  8492. };
  8493. a.prototype = f.prototype;
  8494. } else a = {};
  8495. Object.defineProperty(a, '__esModule', {value: true});
  8496. Object.keys(n).forEach(function (k) {
  8497. var d = Object.getOwnPropertyDescriptor(n, k);
  8498. Object.defineProperty(a, k, d.get ? d : {
  8499. enumerable: true,
  8500. get: function () {
  8501. return n[k];
  8502. }
  8503. });
  8504. });
  8505. return a;
  8506. }
  8507. function commonjsRequire(path) {
  8508. throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
  8509. }
  8510. var jszip_min = {exports: {}};
  8511. (function (module, exports) {
  8512. !function(e){module.exports=e();}(function(){return function s(a,o,h){function u(r,e){if(!o[r]){if(!a[r]){var t="function"==typeof commonjsRequire&&commonjsRequire;if(!e&&t)return t(r,!0);if(l)return l(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 u(t||e)},i,i.exports,s,a,o,h);}return o[r].exports}for(var l="function"==typeof commonjsRequire&&commonjsRequire,e=0;e<h.length;e++)u(h[e]);return u}({1:[function(e,t,r){var d=e("./utils"),c=e("./support"),p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.encode=function(e){for(var t,r,n,i,s,a,o,h=[],u=0,l=e.length,f=l,c="string"!==d.getTypeOf(e);u<e.length;)f=l-u,n=c?(t=e[u++],r=u<l?e[u++]:0,u<l?e[u++]:0):(t=e.charCodeAt(u++),r=u<l?e.charCodeAt(u++):0,u<l?e.charCodeAt(u++):0),i=t>>2,s=(3&t)<<4|r>>4,a=1<f?(15&r)<<2|n>>6:64,o=2<f?63&n:64,h.push(p.charAt(i)+p.charAt(s)+p.charAt(a)+p.charAt(o));return h.join("")},r.decode=function(e){var t,r,n,i,s,a,o=0,h=0,u="data:";if(e.substr(0,u.length)===u)throw new Error("Invalid base64 input, it looks like a data url.");var l,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(l=c.uint8array?new Uint8Array(0|f):new Array(0|f);o<e.length;)t=p.indexOf(e.charAt(o++))<<2|(i=p.indexOf(e.charAt(o++)))>>4,r=(15&i)<<4|(s=p.indexOf(e.charAt(o++)))>>2,n=(3&s)<<6|(a=p.indexOf(e.charAt(o++))),l[h++]=t,64!==s&&(l[h++]=r),64!==a&&(l[h++]=n);return l};},{"./support":30,"./utils":32}],2:[function(e,t,r){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){var n=e("./stream/GenericWorker");r.STORE={magic:"\0\0",compressWorker:function(){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){var n=e("./utils");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){return void 0!==e&&e.length?"string"!==n.getTypeOf(e)?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}(0|t,e,e.length,0):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.charCodeAt(a))];return -1^e}(0|t,e,e.length,0):0};},{"./utils":32}],5:[function(e,t,r){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){var n=null;n="undefined"!=typeof Promise?Promise:e("lie"),t.exports={Promise:n};},{lie:37}],7:[function(e,t,r){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 h(e,t){a.call(this,"FlateWorker/"+e),this._pako=null,this._pakoAction=e,this._pakoOptions=t,this.meta={};}r.magic="\b\0",s.inherits(h,a),h.prototype.processChunk=function(e){this.meta=e.meta,null===this._pako&&this._createPako(),this._pako.push(s.transformTo(o,e.data),!1);},h.prototype.flush=function(){a.prototype.flush.call(this),null===this._pako&&this._createPako(),this._pako.push([],!0);},h.prototype.cleanUp=function(){a.prototype.cleanUp.call(this),this._pako=null;},h.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 h("Deflate",e)},r.uncompressWorker=function(){return new h("Inflate",{})};},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(e,t,r){function A(e,t){var r,n="";for(r=0;r<t;r++)n+=String.fromCharCode(255&e),e>>>=8;return n}function n(e,t,r,n,i,s){var a,o,h=e.file,u=e.compression,l=s!==O.utf8encode,f=I.transformTo("string",s(h.name)),c=I.transformTo("string",O.utf8encode(h.name)),d=h.comment,p=I.transformTo("string",s(d)),m=I.transformTo("string",O.utf8encode(d)),_=c.length!==h.name.length,g=m.length!==d.length,b="",v="",y="",w=h.dir,k=h.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),l||!_&&!g||(S|=2048);var z=0,C=0;w&&(z|=16),"UNIX"===i?(C=798,z|=function(e,t){var r=e;return e||(r=t?16893:33204),(65535&r)<<16}(h.unixPermissions,w)):(C=20,z|=function(e){return 63&(e||0)}(h.dosPermissions)),a=k.getUTCHours(),a<<=6,a|=k.getUTCMinutes(),a<<=5,a|=k.getUTCSeconds()/2,o=k.getUTCFullYear()-1980,o<<=4,o|=k.getUTCMonth()+1,o<<=5,o|=k.getUTCDate(),_&&(v=A(1,1)+A(B(f),4)+c,b+="up"+A(v.length,2)+v),g&&(y=A(1,1)+A(B(p),4)+m,b+="uc"+A(y.length,2)+y);var E="";return E+="\n\0",E+=A(S,2),E+=u.magic,E+=A(a,2),E+=A(o,2),E+=A(x.crc32,4),E+=A(x.compressedSize,4),E+=A(x.uncompressedSize,4),E+=A(f.length,2),E+=A(b.length,2),{fileRecord:R.LOCAL_FILE_HEADER+E+f+b,dirRecord:R.CENTRAL_FILE_HEADER+A(C,2)+E+A(p.length,2)+"\0\0\0\0"+A(z,4)+A(n,4)+f+b+p}}var I=e("../utils"),i=e("../stream/GenericWorker"),O=e("../utf8"),B=e("../crc32"),R=e("../signature");function s(e,t,r,n){i.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=t,this.zipPlatform=r,this.encodeFileName=n,this.streamFiles=e,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[];}I.inherits(s,i),s.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,i.prototype.push.call(this,{data:e.data,meta:{currentFile:this.currentFile,percent:r?(t+100*(r-n-1))/r:100}}));},s.prototype.openedSource=function(e){this.currentSourceOffset=this.bytesWritten,this.currentFile=e.file.name;var t=this.streamFiles&&!e.file.dir;if(t){var r=n(e,t,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:r.fileRecord,meta:{percent:0}});}else this.accumulate=!0;},s.prototype.closedSource=function(e){this.accumulate=!1;var t=this.streamFiles&&!e.file.dir,r=n(e,t,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(r.dirRecord),t)this.push({data:function(e){return R.DATA_DESCRIPTOR+A(e.crc32,4)+A(e.compressedSize,4)+A(e.uncompressedSize,4)}(e),meta:{percent:100}});else for(this.push({data:r.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null;},s.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=this.bytesWritten-e,n=function(e,t,r,n,i){var s=I.transformTo("string",i(n));return R.CENTRAL_DIRECTORY_END+"\0\0\0\0"+A(e,2)+A(e,2)+A(t,4)+A(r,4)+A(s.length,2)+s}(this.dirRecords.length,r,e,this.zipComment,this.encodeFileName);this.push({data:n,meta:{percent:100}});},s.prototype.prepareNextSource=function(){this.previous=this._sources.shift(),this.openedSource(this.previous.streamInfo),this.isPaused?this.previous.pause():this.previous.resume();},s.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},s.prototype.resume=function(){return !!i.prototype.resume.call(this)&&(!this.previous&&this._sources.length?(this.prepareNextSource(),!0):this.previous||this._sources.length||this.generatedError?void 0:(this.end(),!0))},s.prototype.error=function(e){var t=this._sources;if(!i.prototype.error.call(this,e))return !1;for(var r=0;r<t.length;r++)try{t[r].error(e);}catch(e){}return !0},s.prototype.lock=function(){i.prototype.lock.call(this);for(var e=this._sources,t=0;t<e.length;t++)e[t].lock();},t.exports=s;},{"../crc32":4,"../signature":23,"../stream/GenericWorker":28,"../utf8":31,"../utils":32}],9:[function(e,t,r){var u=e("../compressions"),n=e("./ZipFileWorker");r.generateWorker=function(e,a,t){var o=new n(a.streamFiles,t,a.platform,a.encodeFileName),h=0;try{e.forEach(function(e,t){h++;var r=function(e,t){var r=e||t,n=u[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=h;}catch(e){o.error(e);}return o};},{"../compressions":3,"./ZipFileWorker":8}],10:[function(e,t,r){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=Object.create(null),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.10.1",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){var u=e("./utils"),i=e("./external"),n=e("./utf8"),s=e("./zipEntries"),a=e("./stream/Crc32Probe"),l=e("./nodejsUtils");function f(n){return new i.Promise(function(e,t){var r=n.decompressed.getContentWorker().pipe(new a);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,o){var h=this;return o=u.extend(o||{},{base64:!1,checkCRC32:!1,optimizedBinaryString:!1,createFolders:!1,decodeFileName:n.utf8decode}),l.isNode&&l.isStream(e)?i.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file.")):u.prepareContent("the loaded zip file",e,!0,o.optimizedBinaryString,o.base64).then(function(e){var t=new s(o);return t.load(e),t}).then(function(e){var t=[i.Promise.resolve(e)],r=e.files;if(o.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],s=i.fileNameStr,a=u.resolve(i.fileNameStr);h.file(a,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:o.createFolders}),i.dir||(h.file(a).unsafeOriginalName=s);}return t.zipComment.length&&(h.comment=t.zipComment),h})};},{"./external":6,"./nodejsUtils":14,"./stream/Crc32Probe":25,"./utf8":31,"./utils":32,"./zipEntries":33}],12:[function(e,t,r){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){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){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){function s(e,t,r){var n,i=u.getTypeOf(t),s=u.extend(r||{},f);s.date=s.date||new Date,null!==s.compression&&(s.compression=s.compression.toUpperCase()),"string"==typeof s.unixPermissions&&(s.unixPermissions=parseInt(s.unixPermissions,8)),s.unixPermissions&&16384&s.unixPermissions&&(s.dir=!0),s.dosPermissions&&16&s.dosPermissions&&(s.dir=!0),s.dir&&(e=g(e)),s.createFolders&&(n=_(e))&&b.call(this,n,!0);var a="string"===i&&!1===s.binary&&!1===s.base64;r&&void 0!==r.binary||(s.binary=!a),(t instanceof c&&0===t.uncompressedSize||s.dir||!t||0===t.length)&&(s.base64=!1,s.binary=!0,t="",s.compression="STORE",i="string");var o=null;o=t instanceof c||t instanceof l?t:p.isNode&&p.isStream(t)?new m(e,t):u.prepareContent(e,t,s.binary,s.optimizedBinaryString,s.base64);var h=new d(e,o,s);this.files[e]=h;}var i=e("./utf8"),u=e("./utils"),l=e("./stream/GenericWorker"),a=e("./stream/StreamHelper"),f=e("./defaults"),c=e("./compressedObject"),d=e("./zipObject"),o=e("./generate"),p=e("./nodejsUtils"),m=e("./nodejs/NodejsStreamInputAdapter"),_=function(e){"/"===e.slice(-1)&&(e=e.substring(0,e.length-1));var t=e.lastIndexOf("/");return 0<t?e.substring(0,t):""},g=function(e){return "/"!==e.slice(-1)&&(e+="/"),e},b=function(e,t){return t=void 0!==t?t:f.createFolders,e=g(e),this.files[e]||s.call(this,e,null,{dir:!0,createFolders:t}),this.files[e]};function h(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)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(h(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(h(r))return this.filter(function(e,t){return t.dir&&r.test(e)});var e=this.root+r,t=b.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(){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=u.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.");u.checkSupport(r.type),"darwin"!==r.platform&&"freebsd"!==r.platform&&"linux"!==r.platform&&"sunos"!==r.platform||(r.platform="UNIX"),"win32"===r.platform&&(r.platform="DOS");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){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){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(){},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(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},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){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){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){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){var n=e("../utils"),i=e("../support"),s=e("./ArrayReader"),a=e("./StringReader"),o=e("./NodeBufferReader"),h=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 h(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){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){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){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){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){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){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)Object.prototype.hasOwnProperty.call(this.extraStreamInfo,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){var h=e("../utils"),i=e("./ConvertWorker"),s=e("./GenericWorker"),u=e("../base64"),n=e("../support"),a=e("../external"),o=null;if(n.nodestream)try{o=e("../nodejs/NodejsStreamOutputAdapter");}catch(e){}function l(e,o){return new a.Promise(function(t,r){var n=[],i=e._internalType,s=e._outputType,a=e._mimeType;e.on("data",function(e,t){n.push(e),o&&o(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 u.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();})}function f(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);}}f.prototype={accumulate:function(e){return l(this,e)},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=f;},{"../base64":1,"../external":6,"../nodejs/NodejsStreamOutputAdapter":13,"../support":30,"../utils":32,"./ConvertWorker":24,"./GenericWorker":28}],30:[function(e,t,r){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){for(var o=e("./utils"),h=e("./support"),r=e("./nodejsUtils"),n=e("./stream/GenericWorker"),u=new Array(256),i=0;i<256;i++)u[i]=252<=i?6:248<=i?5:240<=i?4:224<=i?3:192<=i?2:1;u[254]=u[254]=1;function a(){n.call(this,"utf-8 decode"),this.leftOver=null;}function l(){n.call(this,"utf-8 encode");}s.utf8encode=function(e){return h.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=h.uint8array?new Uint8Array(o):new Array(o),i=s=0;s<o;i++)55296==(64512&(r=e.charCodeAt(i)))&&i+1<a&&56320==(64512&(n=e.charCodeAt(i+1)))&&(r=65536+(r-55296<<10)+(n-56320),i++),r<128?t[s++]=r:(r<2048?t[s++]=192|r>>>6:(r<65536?t[s++]=224|r>>>12:(t[s++]=240|r>>>18,t[s++]=128|r>>>12&63),t[s++]=128|r>>>6&63),t[s++]=128|63&r);return t}(e)},s.utf8decode=function(e){return h.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=u[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(h.uint8array?"uint8array":"array",e))},o.inherits(a,n),a.prototype.processChunk=function(e){var t=o.transformTo(h.uint8array?"uint8array":"array",e.data);if(this.leftOver&&this.leftOver.length){if(h.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+u[e[r]]>t?r:t}(t),i=t;n!==t.length&&(h.uint8array?(i=t.subarray(0,n),this.leftOver=t.subarray(n,t.length)):(i=t.slice(0,n),this.leftOver=t.slice(n,t.length))),this.push({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(l,n),l.prototype.processChunk=function(e){this.push({data:s.utf8encode(e.data),meta:e.meta});},s.Utf8EncodeWorker=l;},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(e,t,a){var o=e("./support"),h=e("./base64"),r=e("./nodejsUtils"),u=e("./external");function n(e){return e}function l(e,t){for(var r=0;r<e.length;++r)t[r]=255&e.charCodeAt(r);return t}e("setimmediate"),a.newBlob=function(t,r){a.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 i={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 o.uint8array&&1===String.fromCharCode.apply(null,new Uint8Array(1)).length}catch(e){return !1}}(),nodebuffer:function(){try{return o.nodebuffer&&1===String.fromCharCode.apply(null,r.allocBuffer(1)).length}catch(e){return !1}}()}};function s(e){var t=65536,r=a.getTypeOf(e),n=!0;if("uint8array"===r?n=i.applyCanBeUsed.uint8array:"nodebuffer"===r&&(n=i.applyCanBeUsed.nodebuffer),n)for(;1<t;)try{return i.stringifyByChunk(e,r,t)}catch(e){t=Math.floor(t/2);}return i.stringifyByChar(e)}function f(e,t){for(var r=0;r<e.length;r++)t[r]=e[r];return t}a.applyFromCharCode=s;var c={};c.string={string:n,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:s,array:n,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 s(new Uint8Array(e))},array:function(e){return f(new Uint8Array(e),new Array(e.byteLength))},arraybuffer:n,uint8array:function(e){return new Uint8Array(e)},nodebuffer:function(e){return r.newBufferFrom(new Uint8Array(e))}},c.uint8array={string:s,array:function(e){return f(e,new Array(e.length))},arraybuffer:function(e){return e.buffer},uint8array:n,nodebuffer:function(e){return r.newBufferFrom(e)}},c.nodebuffer={string:s,array:function(e){return f(e,new Array(e.length))},arraybuffer:function(e){return c.nodebuffer.uint8array(e).buffer},uint8array:function(e){return f(e,new Uint8Array(e.length))},nodebuffer:n},a.transformTo=function(e,t){if(t=t||"",!e)return t;a.checkSupport(e);var r=a.getTypeOf(t);return c[r][e](t)},a.resolve=function(e){for(var t=e.split("/"),r=[],n=0;n<t.length;n++){var i=t[n];"."===i||""===i&&0!==n&&n!==t.length-1||(".."===i?r.pop():r.push(i));}return r.join("/")},a.getTypeOf=function(e){return "string"==typeof e?"string":"[object Array]"===Object.prototype.toString.call(e)?"array":o.nodebuffer&&r.isBuffer(e)?"nodebuffer":o.uint8array&&e instanceof Uint8Array?"uint8array":o.arraybuffer&&e instanceof ArrayBuffer?"arraybuffer":void 0},a.checkSupport=function(e){if(!o[e.toLowerCase()])throw new Error(e+" is not supported by this platform")},a.MAX_VALUE_16BITS=65535,a.MAX_VALUE_32BITS=-1,a.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},a.delay=function(e,t,r){setImmediate(function(){e.apply(r||null,t||[]);});},a.inherits=function(e,t){function r(){}r.prototype=t.prototype,e.prototype=new r;},a.extend=function(){var e,t,r={};for(e=0;e<arguments.length;e++)for(t in arguments[e])Object.prototype.hasOwnProperty.call(arguments[e],t)&&void 0===r[t]&&(r[t]=arguments[e][t]);return r},a.prepareContent=function(r,e,n,i,s){return u.Promise.resolve(e).then(function(n){return o.blob&&(n instanceof Blob||-1!==["[object File]","[object Blob]"].indexOf(Object.prototype.toString.call(n)))&&"undefined"!=typeof FileReader?new u.Promise(function(t,r){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=a.getTypeOf(e);return t?("arraybuffer"===t?e=a.transformTo("uint8array",e):"string"===t&&(s?e=h.decode(e):n&&!0!==i&&(e=function(e){return l(e,o.uint8array?new Uint8Array(e.length):new Array(e.length))}(e))),e):u.Promise.reject(new Error("Can't read the data of '"+r+"'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?"))})};},{"./base64":1,"./external":6,"./nodejsUtils":14,"./support":30,setimmediate:54}],33:[function(e,t,r){var n=e("./reader/readerFor"),i=e("./utils"),s=e("./signature"),a=e("./zipEntry"),o=e("./support");function h(e){this.files=[],this.loadOptions=e;}h.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("Can't find end of central directory : is this a zip file ? If it is, see https://stuk.github.io/jszip/documentation/howto/read_zip.html"):new Error("Corrupted zip: can't find end of central directory");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=h;},{"./reader/readerFor":22,"./signature":23,"./support":30,"./utils":32,"./zipEntry":34}],34:[function(e,t,r){var n=e("./reader/readerFor"),s=e("./utils"),i=e("./compressedObject"),a=e("./crc32"),o=e("./utf8"),h=e("./compressions"),u=e("./support");function l(e,t){this.options=e,this.loadOptions=t;}l.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 h)if(Object.prototype.hasOwnProperty.call(h,t)&&h[t].magic===e)return h[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(){if(this.extraFields[1]){var e=n(this.extraFields[1].value);this.uncompressedSize===s.MAX_VALUE_32BITS&&(this.uncompressedSize=e.readInt(8)),this.compressedSize===s.MAX_VALUE_32BITS&&(this.compressedSize=e.readInt(8)),this.localHeaderOffset===s.MAX_VALUE_32BITS&&(this.localHeaderOffset=e.readInt(8)),this.diskNumberStart===s.MAX_VALUE_32BITS&&(this.diskNumberStart=e.readInt(4));}},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=u.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=l;},{"./compressedObject":2,"./compressions":3,"./crc32":4,"./reader/readerFor":22,"./support":30,"./utf8":31,"./utils":32}],35:[function(e,t,r){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"),h=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 h("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 h?this._data:new i(this._data)}};for(var u=["asText","asBinary","asNodeBuffer","asUint8Array","asArrayBuffer"],l=function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},f=0;f<u.length;f++)n.prototype[u[f]]=l;t.exports=n;},{"./compressedObject":2,"./stream/DataWorker":27,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31}],36:[function(e,l,t){(function(t){var r,n,e=t.MutationObserver||t.WebKitMutationObserver;if(e){var i=0,s=new e(u),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(){u(),e.onreadystatechange=null,e.parentNode.removeChild(e),e=null;},t.document.documentElement.appendChild(e);}:function(){setTimeout(u,0);};else {var o=new t.MessageChannel;o.port1.onmessage=u,r=function(){o.port2.postMessage(0);};}var h=[];function u(){var e,t;n=!0;for(var r=h.length;r;){for(t=h,h=[],e=-1;++e<r;)t[e]();r=h.length;}n=!1;}l.exports=function(e){1!==h.push(e)||n||r();};}).call(this,"undefined"!=typeof commonjsGlobal?commonjsGlobal:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{});},{}],37:[function(e,t,r){var i=e("immediate");function u(){}var l={},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!==u&&d(this,e);}function h(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 f(t,r,n){i(function(){var e;try{e=r(n);}catch(e){return l.reject(t,e)}e===t?l.reject(t,new TypeError("Cannot resolve promise with itself")):l.resolve(t,e);});}function c(e){var t=e&&e.then;if(e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof t)return function(){t.apply(e,arguments);}}function d(t,e){var r=!1;function n(e){r||(r=!0,l.reject(t,e));}function i(e){r||(r=!0,l.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(u);this.state!==n?f(r,this.state===a?e:t,this.outcome):this.queue.push(new h(r,e,t));return r},h.prototype.callFulfilled=function(e){l.resolve(this.promise,e);},h.prototype.otherCallFulfilled=function(e){f(this.promise,this.onFulfilled,e);},h.prototype.callRejected=function(e){l.reject(this.promise,e);},h.prototype.otherCallRejected=function(e){f(this.promise,this.onRejected,e);},l.resolve=function(e,t){var r=p(c,t);if("error"===r.status)return l.reject(e,r.value);var n=r.value;if(n)d(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},l.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){if(e instanceof this)return e;return l.resolve(new this(u),e)},o.reject=function(e){var t=new this(u);return l.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([]);var s=new Array(n),a=0,t=-1,o=new this(u);for(;++t<n;)h(e[t],t);return o;function h(e,t){r.resolve(e).then(function(e){s[t]=e,++a!==n||i||(i=!0,l.resolve(o,s));},function(e){i||(i=!0,l.reject(o,e));});}},o.race=function(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var r=e.length,n=!1;if(!r)return this.resolve([]);var i=-1,s=new this(u);for(;++i<r;)a=e[i],t.resolve(a).then(function(e){n||(n=!0,l.resolve(s,e));},function(e){n||(n=!0,l.reject(s,e));});var a;return s};},{immediate:36}],38:[function(e,t,r){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){var a=e("./zlib/deflate"),o=e("./utils/common"),h=e("./utils/strings"),i=e("./zlib/messages"),s=e("./zlib/zstream"),u=Object.prototype.toString,l=0,f=-1,c=0,d=8;function p(e){if(!(this instanceof p))return new p(e);this.options=o.assign({level:f,method:d,chunkSize:16384,windowBits:15,memLevel:8,strategy:c,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!==l)throw new Error(i[r]);if(t.header&&a.deflateSetHeader(this.strm,t.header),t.dictionary){var n;if(n="string"==typeof t.dictionary?h.string2buf(t.dictionary):"[object ArrayBuffer]"===u.call(t.dictionary)?new Uint8Array(t.dictionary):t.dictionary,(r=a.deflateSetDictionary(this.strm,n))!==l)throw new Error(i[r]);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=h.string2buf(e):"[object ArrayBuffer]"===u.call(e)?i.input=new Uint8Array(e):i.input=e,i.next_in=0,i.avail_in=i.input.length;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!==l)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(h.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===l):2!==n||(this.onEnd(l),!(i.avail_out=0))},p.prototype.onData=function(e){this.chunks.push(e);},p.prototype.onEnd=function(e){e===l&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=o.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg;},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){var c=e("./zlib/inflate"),d=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=d.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=c.inflateInit2(this.strm,t.windowBits);if(r!==m.Z_OK)throw new Error(n[r]);this.header=new s,c.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,h=this.strm,u=this.options.chunkSize,l=this.options.dictionary,f=!1;if(this.ended)return !1;n=t===~~t?t:!0===t?m.Z_FINISH:m.Z_NO_FLUSH,"string"==typeof e?h.input=p.binstring2buf(e):"[object ArrayBuffer]"===_.call(e)?h.input=new Uint8Array(e):h.input=e,h.next_in=0,h.avail_in=h.input.length;do{if(0===h.avail_out&&(h.output=new d.Buf8(u),h.next_out=0,h.avail_out=u),(r=c.inflate(h,m.Z_NO_FLUSH))===m.Z_NEED_DICT&&l&&(o="string"==typeof l?p.string2buf(l):"[object ArrayBuffer]"===_.call(l)?new Uint8Array(l):l,r=c.inflateSetDictionary(this.strm,o)),r===m.Z_BUF_ERROR&&!0===f&&(r=m.Z_OK,f=!1),r!==m.Z_STREAM_END&&r!==m.Z_OK)return this.onEnd(r),!(this.ended=!0);h.next_out&&(0!==h.avail_out&&r!==m.Z_STREAM_END&&(0!==h.avail_in||n!==m.Z_FINISH&&n!==m.Z_SYNC_FLUSH)||("string"===this.options.to?(i=p.utf8border(h.output,h.next_out),s=h.next_out-i,a=p.buf2string(h.output,i),h.next_out=s,h.avail_out=u-s,s&&d.arraySet(h.output,h.output,i,s,0),this.onData(a)):this.onData(d.shrinkBuf(h.output,h.next_out)))),0===h.avail_in&&0===h.avail_out&&(f=!0);}while((0<h.avail_in||0===h.avail_out)&&r!==m.Z_STREAM_END);return r===m.Z_STREAM_END&&(n=m.Z_FINISH),n===m.Z_FINISH?(r=c.inflateEnd(this.strm),this.onEnd(r),this.ended=!0,r===m.Z_OK):n!==m.Z_SYNC_FLUSH||(this.onEnd(m.Z_OK),!(h.avail_out=0))},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=d.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){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){var h=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 u=new h.Buf8(256),n=0;n<256;n++)u[n]=252<=n?6:248<=n?5:240<=n?4:224<=n?3:192<=n?2:1;function l(e,t){if(t<65537&&(e.subarray&&s||!e.subarray&&i))return String.fromCharCode.apply(null,h.shrinkBuf(e,t));for(var r="",n=0;n<t;n++)r+=String.fromCharCode(e[n]);return r}u[254]=u[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 h.Buf8(o),i=s=0;s<o;i++)55296==(64512&(r=e.charCodeAt(i)))&&i+1<a&&56320==(64512&(n=e.charCodeAt(i+1)))&&(r=65536+(r-55296<<10)+(n-56320),i++),r<128?t[s++]=r:(r<2048?t[s++]=192|r>>>6:(r<65536?t[s++]=224|r>>>12:(t[s++]=240|r>>>18,t[s++]=128|r>>>12&63),t[s++]=128|r>>>6&63),t[s++]=128|63&r);return t},r.buf2binstring=function(e){return l(e,e.length)},r.binstring2buf=function(e){for(var t=new h.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=u[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 l(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+u[e[r]]>t?r:t};},{"./common":41}],43:[function(e,t,r){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){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){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){var h,c=e("../utils/common"),u=e("./trees"),d=e("./adler32"),p=e("./crc32"),n=e("./messages"),l=0,f=4,m=0,_=-2,g=-1,b=4,i=2,v=8,y=9,s=286,a=30,o=19,w=2*s+1,k=15,x=3,S=258,z=S+x+1,C=42,E=113,A=1,I=2,O=3,B=4;function R(e,t){return e.msg=n[t],t}function T(e){return (e<<1)-(4<e?9:0)}function D(e){for(var t=e.length;0<=--t;)e[t]=0;}function F(e){var t=e.state,r=t.pending;r>e.avail_out&&(r=e.avail_out),0!==r&&(c.arraySet(e.output,t.pending_buf,t.pending_out,r,e.next_out),e.next_out+=r,t.pending_out+=r,e.total_out+=r,e.avail_out-=r,t.pending-=r,0===t.pending&&(t.pending_out=0));}function N(e,t){u._tr_flush_block(e,0<=e.block_start?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,F(e.strm);}function U(e,t){e.pending_buf[e.pending++]=t;}function P(e,t){e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=255&t;}function L(e,t){var r,n,i=e.max_chain_length,s=e.strstart,a=e.prev_length,o=e.nice_match,h=e.strstart>e.w_size-z?e.strstart-(e.w_size-z):0,u=e.window,l=e.w_mask,f=e.prev,c=e.strstart+S,d=u[s+a-1],p=u[s+a];e.prev_length>=e.good_match&&(i>>=2),o>e.lookahead&&(o=e.lookahead);do{if(u[(r=t)+a]===p&&u[r+a-1]===d&&u[r]===u[s]&&u[++r]===u[s+1]){s+=2,r++;do{}while(u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&u[++s]===u[++r]&&s<c);if(n=S-(c-s),s=c-S,a<n){if(e.match_start=t,o<=(a=n))break;d=u[s+a-1],p=u[s+a];}}}while((t=f[t&l])>h&&0!=--i);return a<=e.lookahead?a:e.lookahead}function j(e){var t,r,n,i,s,a,o,h,u,l,f=e.w_size;do{if(i=e.window_size-e.lookahead-e.strstart,e.strstart>=f+(f-z)){for(c.arraySet(e.window,e.window,f,f,0),e.match_start-=f,e.strstart-=f,e.block_start-=f,t=r=e.hash_size;n=e.head[--t],e.head[t]=f<=n?n-f:0,--r;);for(t=r=f;n=e.prev[--t],e.prev[t]=f<=n?n-f:0,--r;);i+=f;}if(0===e.strm.avail_in)break;if(a=e.strm,o=e.window,h=e.strstart+e.lookahead,u=i,l=void 0,l=a.avail_in,u<l&&(l=u),r=0===l?0:(a.avail_in-=l,c.arraySet(o,a.input,a.next_in,l,h),1===a.state.wrap?a.adler=d(a.adler,o,l,h):2===a.state.wrap&&(a.adler=p(a.adler,o,l,h)),a.next_in+=l,a.total_in+=l,l),e.lookahead+=r,e.lookahead+e.insert>=x)for(s=e.strstart-e.insert,e.ins_h=e.window[s],e.ins_h=(e.ins_h<<e.hash_shift^e.window[s+1])&e.hash_mask;e.insert&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[s+x-1])&e.hash_mask,e.prev[s&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=s,s++,e.insert--,!(e.lookahead+e.insert<x)););}while(e.lookahead<z&&0!==e.strm.avail_in)}function Z(e,t){for(var r,n;;){if(e.lookahead<z){if(j(e),e.lookahead<z&&t===l)return A;if(0===e.lookahead)break}if(r=0,e.lookahead>=x&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+x-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),0!==r&&e.strstart-r<=e.w_size-z&&(e.match_length=L(e,r)),e.match_length>=x)if(n=u._tr_tally(e,e.strstart-e.match_start,e.match_length-x),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=x){for(e.match_length--;e.strstart++,e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+x-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart,0!=--e.match_length;);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=u._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(n&&(N(e,!1),0===e.strm.avail_out))return A}return e.insert=e.strstart<x-1?e.strstart:x-1,t===f?(N(e,!0),0===e.strm.avail_out?O:B):e.last_lit&&(N(e,!1),0===e.strm.avail_out)?A:I}function W(e,t){for(var r,n,i;;){if(e.lookahead<z){if(j(e),e.lookahead<z&&t===l)return A;if(0===e.lookahead)break}if(r=0,e.lookahead>=x&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+x-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),e.prev_length=e.match_length,e.prev_match=e.match_start,e.match_length=x-1,0!==r&&e.prev_length<e.max_lazy_match&&e.strstart-r<=e.w_size-z&&(e.match_length=L(e,r),e.match_length<=5&&(1===e.strategy||e.match_length===x&&4096<e.strstart-e.match_start)&&(e.match_length=x-1)),e.prev_length>=x&&e.match_length<=e.prev_length){for(i=e.strstart+e.lookahead-x,n=u._tr_tally(e,e.strstart-1-e.prev_match,e.prev_length-x),e.lookahead-=e.prev_length-1,e.prev_length-=2;++e.strstart<=i&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+x-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),0!=--e.prev_length;);if(e.match_available=0,e.match_length=x-1,e.strstart++,n&&(N(e,!1),0===e.strm.avail_out))return A}else if(e.match_available){if((n=u._tr_tally(e,0,e.window[e.strstart-1]))&&N(e,!1),e.strstart++,e.lookahead--,0===e.strm.avail_out)return A}else e.match_available=1,e.strstart++,e.lookahead--;}return e.match_available&&(n=u._tr_tally(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=e.strstart<x-1?e.strstart:x-1,t===f?(N(e,!0),0===e.strm.avail_out?O:B):e.last_lit&&(N(e,!1),0===e.strm.avail_out)?A:I}function M(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 H(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=v,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new c.Buf16(2*w),this.dyn_dtree=new c.Buf16(2*(2*a+1)),this.bl_tree=new c.Buf16(2*(2*o+1)),D(this.dyn_ltree),D(this.dyn_dtree),D(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new c.Buf16(k+1),this.heap=new c.Buf16(2*s+1),D(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new c.Buf16(2*s+1),D(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0;}function G(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?C:E,e.adler=2===t.wrap?0:1,t.last_flush=l,u._tr_init(t),m):R(e,_)}function K(e){var t=G(e);return t===m&&function(e){e.window_size=2*e.w_size,D(e.head),e.max_lazy_match=h[e.level].max_lazy,e.good_match=h[e.level].good_length,e.nice_match=h[e.level].nice_length,e.max_chain_length=h[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=x-1,e.match_available=0,e.ins_h=0;}(e.state),t}function Y(e,t,r,n,i,s){if(!e)return _;var a=1;if(t===g&&(t=6),n<0?(a=0,n=-n):15<n&&(a=2,n-=16),i<1||y<i||r!==v||n<8||15<n||t<0||9<t||s<0||b<s)return R(e,_);8===n&&(n=9);var o=new H;return (e.state=o).strm=e,o.wrap=a,o.gzhead=null,o.w_bits=n,o.w_size=1<<o.w_bits,o.w_mask=o.w_size-1,o.hash_bits=i+7,o.hash_size=1<<o.hash_bits,o.hash_mask=o.hash_size-1,o.hash_shift=~~((o.hash_bits+x-1)/x),o.window=new c.Buf8(2*o.w_size),o.head=new c.Buf16(o.hash_size),o.prev=new c.Buf16(o.w_size),o.lit_bufsize=1<<i+6,o.pending_buf_size=4*o.lit_bufsize,o.pending_buf=new c.Buf8(o.pending_buf_size),o.d_buf=1*o.lit_bufsize,o.l_buf=3*o.lit_bufsize,o.level=t,o.strategy=s,o.method=r,K(e)}h=[new M(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(j(e),0===e.lookahead&&t===l)return A;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,N(e,!1),0===e.strm.avail_out))return A;if(e.strstart-e.block_start>=e.w_size-z&&(N(e,!1),0===e.strm.avail_out))return A}return e.insert=0,t===f?(N(e,!0),0===e.strm.avail_out?O:B):(e.strstart>e.block_start&&(N(e,!1),e.strm.avail_out),A)}),new M(4,4,8,4,Z),new M(4,5,16,8,Z),new M(4,6,32,32,Z),new M(4,4,16,16,W),new M(8,16,32,32,W),new M(8,16,128,128,W),new M(8,32,128,256,W),new M(32,128,258,1024,W),new M(32,258,258,4096,W)],r.deflateInit=function(e,t){return Y(e,t,v,15,8,0)},r.deflateInit2=Y,r.deflateReset=K,r.deflateResetKeep=G,r.deflateSetHeader=function(e,t){return e&&e.state?2!==e.state.wrap?_:(e.state.gzhead=t,m):_},r.deflate=function(e,t){var r,n,i,s;if(!e||!e.state||5<t||t<0)return e?R(e,_):_;if(n=e.state,!e.output||!e.input&&0!==e.avail_in||666===n.status&&t!==f)return R(e,0===e.avail_out?-5:_);if(n.strm=e,r=n.last_flush,n.last_flush=t,n.status===C)if(2===n.wrap)e.adler=0,U(n,31),U(n,139),U(n,8),n.gzhead?(U(n,(n.gzhead.text?1:0)+(n.gzhead.hcrc?2:0)+(n.gzhead.extra?4:0)+(n.gzhead.name?8:0)+(n.gzhead.comment?16:0)),U(n,255&n.gzhead.time),U(n,n.gzhead.time>>8&255),U(n,n.gzhead.time>>16&255),U(n,n.gzhead.time>>24&255),U(n,9===n.level?2:2<=n.strategy||n.level<2?4:0),U(n,255&n.gzhead.os),n.gzhead.extra&&n.gzhead.extra.length&&(U(n,255&n.gzhead.extra.length),U(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(e.adler=p(e.adler,n.pending_buf,n.pending,0)),n.gzindex=0,n.status=69):(U(n,0),U(n,0),U(n,0),U(n,0),U(n,0),U(n,9===n.level?2:2<=n.strategy||n.level<2?4:0),U(n,3),n.status=E);else {var a=v+(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=E,P(n,a),0!==n.strstart&&(P(n,e.adler>>>16),P(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)),F(e),i=n.pending,n.pending!==n.pending_buf_size));)U(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)),F(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,U(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)),F(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,U(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&&F(e),n.pending+2<=n.pending_buf_size&&(U(n,255&e.adler),U(n,e.adler>>8&255),e.adler=0,n.status=E)):n.status=E),0!==n.pending){if(F(e),0===e.avail_out)return n.last_flush=-1,m}else if(0===e.avail_in&&T(t)<=T(r)&&t!==f)return R(e,-5);if(666===n.status&&0!==e.avail_in)return R(e,-5);if(0!==e.avail_in||0!==n.lookahead||t!==l&&666!==n.status){var o=2===n.strategy?function(e,t){for(var r;;){if(0===e.lookahead&&(j(e),0===e.lookahead)){if(t===l)return A;break}if(e.match_length=0,r=u._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,r&&(N(e,!1),0===e.strm.avail_out))return A}return e.insert=0,t===f?(N(e,!0),0===e.strm.avail_out?O:B):e.last_lit&&(N(e,!1),0===e.strm.avail_out)?A:I}(n,t):3===n.strategy?function(e,t){for(var r,n,i,s,a=e.window;;){if(e.lookahead<=S){if(j(e),e.lookahead<=S&&t===l)return A;if(0===e.lookahead)break}if(e.match_length=0,e.lookahead>=x&&0<e.strstart&&(n=a[i=e.strstart-1])===a[++i]&&n===a[++i]&&n===a[++i]){s=e.strstart+S;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=S-(s-i),e.match_length>e.lookahead&&(e.match_length=e.lookahead);}if(e.match_length>=x?(r=u._tr_tally(e,1,e.match_length-x),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(r=u._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),r&&(N(e,!1),0===e.strm.avail_out))return A}return e.insert=0,t===f?(N(e,!0),0===e.strm.avail_out?O:B):e.last_lit&&(N(e,!1),0===e.strm.avail_out)?A:I}(n,t):h[n.level].func(n,t);if(o!==O&&o!==B||(n.status=666),o===A||o===O)return 0===e.avail_out&&(n.last_flush=-1),m;if(o===I&&(1===t?u._tr_align(n):5!==t&&(u._tr_stored_block(n,0,0,!1),3===t&&(D(n.head),0===n.lookahead&&(n.strstart=0,n.block_start=0,n.insert=0))),F(e),0===e.avail_out))return n.last_flush=-1,m}return t!==f?m:n.wrap<=0?1:(2===n.wrap?(U(n,255&e.adler),U(n,e.adler>>8&255),U(n,e.adler>>16&255),U(n,e.adler>>24&255),U(n,255&e.total_in),U(n,e.total_in>>8&255),U(n,e.total_in>>16&255),U(n,e.total_in>>24&255)):(P(n,e.adler>>>16),P(n,65535&e.adler)),F(e),0<n.wrap&&(n.wrap=-n.wrap),0!==n.pending?m:1)},r.deflateEnd=function(e){var t;return e&&e.state?(t=e.state.status)!==C&&69!==t&&73!==t&&91!==t&&103!==t&&t!==E&&666!==t?R(e,_):(e.state=null,t===E?R(e,-3):m):_},r.deflateSetDictionary=function(e,t){var r,n,i,s,a,o,h,u,l=t.length;if(!e||!e.state)return _;if(2===(s=(r=e.state).wrap)||1===s&&r.status!==C||r.lookahead)return _;for(1===s&&(e.adler=d(e.adler,t,l,0)),r.wrap=0,l>=r.w_size&&(0===s&&(D(r.head),r.strstart=0,r.block_start=0,r.insert=0),u=new c.Buf8(r.w_size),c.arraySet(u,t,l-r.w_size,r.w_size,0),t=u,l=r.w_size),a=e.avail_in,o=e.next_in,h=e.input,e.avail_in=l,e.next_in=0,e.input=t,j(r);r.lookahead>=x;){for(n=r.strstart,i=r.lookahead-(x-1);r.ins_h=(r.ins_h<<r.hash_shift^r.window[n+x-1])&r.hash_mask,r.prev[n&r.w_mask]=r.head[r.ins_h],r.head[r.ins_h]=n,n++,--i;);r.strstart=n,r.lookahead=x-1,j(r);}return r.strstart+=r.lookahead,r.block_start=r.strstart,r.insert=r.lookahead,r.lookahead=0,r.match_length=r.prev_length=x-1,r.match_available=0,e.next_in=o,e.input=h,e.avail_in=a,r.wrap=s,m},r.deflateInfo="pako deflate (from Nodeca project)";},{"../utils/common":41,"./adler32":43,"./crc32":45,"./messages":51,"./trees":52}],47:[function(e,t,r){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){t.exports=function(e,t){var r,n,i,s,a,o,h,u,l,f,c,d,p,m,_,g,b,v,y,w,k,x,S,z,C;r=e.state,n=e.next_in,z=e.input,i=n+(e.avail_in-5),s=e.next_out,C=e.output,a=s-(t-e.avail_out),o=s+(e.avail_out-257),h=r.dmax,u=r.wsize,l=r.whave,f=r.wnext,c=r.window,d=r.hold,p=r.bits,m=r.lencode,_=r.distcode,g=(1<<r.lenbits)-1,b=(1<<r.distbits)-1;e:do{p<15&&(d+=z[n++]<<p,p+=8,d+=z[n++]<<p,p+=8),v=m[d&g];t:for(;;){if(d>>>=y=v>>>24,p-=y,0===(y=v>>>16&255))C[s++]=65535&v;else {if(!(16&y)){if(0==(64&y)){v=m[(65535&v)+(d&(1<<y)-1)];continue t}if(32&y){r.mode=12;break e}e.msg="invalid literal/length code",r.mode=30;break e}w=65535&v,(y&=15)&&(p<y&&(d+=z[n++]<<p,p+=8),w+=d&(1<<y)-1,d>>>=y,p-=y),p<15&&(d+=z[n++]<<p,p+=8,d+=z[n++]<<p,p+=8),v=_[d&b];r:for(;;){if(d>>>=y=v>>>24,p-=y,!(16&(y=v>>>16&255))){if(0==(64&y)){v=_[(65535&v)+(d&(1<<y)-1)];continue r}e.msg="invalid distance code",r.mode=30;break e}if(k=65535&v,p<(y&=15)&&(d+=z[n++]<<p,(p+=8)<y&&(d+=z[n++]<<p,p+=8)),h<(k+=d&(1<<y)-1)){e.msg="invalid distance too far back",r.mode=30;break e}if(d>>>=y,p-=y,(y=s-a)<k){if(l<(y=k-y)&&r.sane){e.msg="invalid distance too far back",r.mode=30;break e}if(S=c,(x=0)===f){if(x+=u-y,y<w){for(w-=y;C[s++]=c[x++],--y;);x=s-k,S=C;}}else if(f<y){if(x+=u+f-y,(y-=f)<w){for(w-=y;C[s++]=c[x++],--y;);if(x=0,f<w){for(w-=y=f;C[s++]=c[x++],--y;);x=s-k,S=C;}}}else if(x+=f-y,y<w){for(w-=y;C[s++]=c[x++],--y;);x=s-k,S=C;}for(;2<w;)C[s++]=S[x++],C[s++]=S[x++],C[s++]=S[x++],w-=3;w&&(C[s++]=S[x++],1<w&&(C[s++]=S[x++]));}else {for(x=s-k;C[s++]=C[x++],C[s++]=C[x++],C[s++]=C[x++],2<(w-=3););w&&(C[s++]=C[x++],1<w&&(C[s++]=C[x++]));}break}}break}}while(n<i&&s<o);n-=w=p>>3,d&=(1<<(p-=w<<3))-1,e.next_in=n,e.next_out=s,e.avail_in=n<i?i-n+5:5-(n-i),e.avail_out=s<o?o-s+257:257-(s-o),r.hold=d,r.bits=p;};},{}],49:[function(e,t,r){var I=e("../utils/common"),O=e("./adler32"),B=e("./crc32"),R=e("./inffast"),T=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 h(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 u(e,t){var r,n;return e?(n=new s,(e.state=n).window=null,(r=h(e,t))!==N&&(e.state=null),r):U}var l,f,c=!0;function j(e){if(c){var t;for(l=new I.Buf32(512),f=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(T(D,e.lens,0,288,l,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;T(F,e.lens,0,32,f,0,e.work,{bits:5}),c=!1;}e.lencode=l,e.lenbits=9,e.distcode=f,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=h,r.inflateResetKeep=a,r.inflateInit=function(e){return u(e,15)},r.inflateInit2=u,r.inflate=function(e,t){var r,n,i,s,a,o,h,u,l,f,c,d,p,m,_,g,b,v,y,w,k,x,S,z,C=0,E=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,h=e.avail_out,s=e.next_in,n=e.input,o=e.avail_in,u=r.hold,l=r.bits,f=o,c=h,x=N;e:for(;;)switch(r.mode){case P:if(0===r.wrap){r.mode=13;break}for(;l<16;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8;}if(2&r.wrap&&35615===u){E[r.check=0]=255&u,E[1]=u>>>8&255,r.check=B(r.check,E,2,0),l=u=0,r.mode=2;break}if(r.flags=0,r.head&&(r.head.done=!1),!(1&r.wrap)||(((255&u)<<8)+(u>>8))%31){e.msg="incorrect header check",r.mode=30;break}if(8!=(15&u)){e.msg="unknown compression method",r.mode=30;break}if(l-=4,k=8+(15&(u>>>=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&u?10:12,l=u=0;break;case 2:for(;l<16;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8;}if(r.flags=u,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=u>>8&1),512&r.flags&&(E[0]=255&u,E[1]=u>>>8&255,r.check=B(r.check,E,2,0)),l=u=0,r.mode=3;case 3:for(;l<32;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8;}r.head&&(r.head.time=u),512&r.flags&&(E[0]=255&u,E[1]=u>>>8&255,E[2]=u>>>16&255,E[3]=u>>>24&255,r.check=B(r.check,E,4,0)),l=u=0,r.mode=4;case 4:for(;l<16;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8;}r.head&&(r.head.xflags=255&u,r.head.os=u>>8),512&r.flags&&(E[0]=255&u,E[1]=u>>>8&255,r.check=B(r.check,E,2,0)),l=u=0,r.mode=5;case 5:if(1024&r.flags){for(;l<16;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8;}r.length=u,r.head&&(r.head.extra_len=u),512&r.flags&&(E[0]=255&u,E[1]=u>>>8&255,r.check=B(r.check,E,2,0)),l=u=0;}else r.head&&(r.head.extra=null);r.mode=6;case 6:if(1024&r.flags&&(o<(d=r.length)&&(d=o),d&&(r.head&&(k=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Array(r.head.extra_len)),I.arraySet(r.head.extra,n,s,d,k)),512&r.flags&&(r.check=B(r.check,n,d,s)),o-=d,s+=d,r.length-=d),r.length))break e;r.length=0,r.mode=7;case 7:if(2048&r.flags){if(0===o)break e;for(d=0;k=n[s+d++],r.head&&k&&r.length<65536&&(r.head.name+=String.fromCharCode(k)),k&&d<o;);if(512&r.flags&&(r.check=B(r.check,n,d,s)),o-=d,s+=d,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(d=0;k=n[s+d++],r.head&&k&&r.length<65536&&(r.head.comment+=String.fromCharCode(k)),k&&d<o;);if(512&r.flags&&(r.check=B(r.check,n,d,s)),o-=d,s+=d,k)break e}else r.head&&(r.head.comment=null);r.mode=9;case 9:if(512&r.flags){for(;l<16;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8;}if(u!==(65535&r.check)){e.msg="header crc mismatch",r.mode=30;break}l=u=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(;l<32;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8;}e.adler=r.check=L(u),l=u=0,r.mode=11;case 11:if(0===r.havedict)return e.next_out=a,e.avail_out=h,e.next_in=s,e.avail_in=o,r.hold=u,r.bits=l,2;e.adler=r.check=1,r.mode=12;case 12:if(5===t||6===t)break e;case 13:if(r.last){u>>>=7&l,l-=7&l,r.mode=27;break}for(;l<3;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8;}switch(r.last=1&u,l-=1,3&(u>>>=1)){case 0:r.mode=14;break;case 1:if(j(r),r.mode=20,6!==t)break;u>>>=2,l-=2;break e;case 2:r.mode=17;break;case 3:e.msg="invalid block type",r.mode=30;}u>>>=2,l-=2;break;case 14:for(u>>>=7&l,l-=7&l;l<32;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8;}if((65535&u)!=(u>>>16^65535)){e.msg="invalid stored block lengths",r.mode=30;break}if(r.length=65535&u,l=u=0,r.mode=15,6===t)break e;case 15:r.mode=16;case 16:if(d=r.length){if(o<d&&(d=o),h<d&&(d=h),0===d)break e;I.arraySet(i,n,s,d,a),o-=d,s+=d,h-=d,a+=d,r.length-=d;break}r.mode=12;break;case 17:for(;l<14;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8;}if(r.nlen=257+(31&u),u>>>=5,l-=5,r.ndist=1+(31&u),u>>>=5,l-=5,r.ncode=4+(15&u),u>>>=4,l-=4,286<r.nlen||30<r.ndist){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(;l<3;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8;}r.lens[A[r.have++]]=7&u,u>>>=3,l-=3;}for(;r.have<19;)r.lens[A[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,S={bits:r.lenbits},x=T(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=(C=r.lencode[u&(1<<r.lenbits)-1])>>>16&255,b=65535&C,!((_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<<l,l+=8;}if(b<16)u>>>=_,l-=_,r.lens[r.have++]=b;else {if(16===b){for(z=_+2;l<z;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8;}if(u>>>=_,l-=_,0===r.have){e.msg="invalid bit length repeat",r.mode=30;break}k=r.lens[r.have-1],d=3+(3&u),u>>>=2,l-=2;}else if(17===b){for(z=_+3;l<z;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8;}l-=_,k=0,d=3+(7&(u>>>=_)),u>>>=3,l-=3;}else {for(z=_+7;l<z;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8;}l-=_,k=0,d=11+(127&(u>>>=_)),u>>>=7,l-=7;}if(r.have+d>r.nlen+r.ndist){e.msg="invalid bit length repeat",r.mode=30;break}for(;d--;)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=T(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=T(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<=h){e.next_out=a,e.avail_out=h,e.next_in=s,e.avail_in=o,r.hold=u,r.bits=l,R(e,c),a=e.next_out,i=e.output,h=e.avail_out,s=e.next_in,n=e.input,o=e.avail_in,u=r.hold,l=r.bits,12===r.mode&&(r.back=-1);break}for(r.back=0;g=(C=r.lencode[u&(1<<r.lenbits)-1])>>>16&255,b=65535&C,!((_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<<l,l+=8;}if(g&&0==(240&g)){for(v=_,y=g,w=b;g=(C=r.lencode[w+((u&(1<<v+y)-1)>>v)])>>>16&255,b=65535&C,!(v+(_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<<l,l+=8;}u>>>=v,l-=v,r.back+=v;}if(u>>>=_,l-=_,r.back+=_,r.length=b,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;l<z;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8;}r.length+=u&(1<<r.extra)-1,u>>>=r.extra,l-=r.extra,r.back+=r.extra;}r.was=r.length,r.mode=23;case 23:for(;g=(C=r.distcode[u&(1<<r.distbits)-1])>>>16&255,b=65535&C,!((_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<<l,l+=8;}if(0==(240&g)){for(v=_,y=g,w=b;g=(C=r.distcode[w+((u&(1<<v+y)-1)>>v)])>>>16&255,b=65535&C,!(v+(_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<<l,l+=8;}u>>>=v,l-=v,r.back+=v;}if(u>>>=_,l-=_,r.back+=_,64&g){e.msg="invalid distance code",r.mode=30;break}r.offset=b,r.extra=15&g,r.mode=24;case 24:if(r.extra){for(z=r.extra;l<z;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8;}r.offset+=u&(1<<r.extra)-1,u>>>=r.extra,l-=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===h)break e;if(d=c-h,r.offset>d){if((d=r.offset-d)>r.whave&&r.sane){e.msg="invalid distance too far back",r.mode=30;break}p=d>r.wnext?(d-=r.wnext,r.wsize-d):r.wnext-d,d>r.length&&(d=r.length),m=r.window;}else m=i,p=a-r.offset,d=r.length;for(h<d&&(d=h),h-=d,r.length-=d;i[a++]=m[p++],--d;);0===r.length&&(r.mode=21);break;case 26:if(0===h)break e;i[a++]=r.length,h--,r.mode=21;break;case 27:if(r.wrap){for(;l<32;){if(0===o)break e;o--,u|=n[s++]<<l,l+=8;}if(c-=h,e.total_out+=c,r.total+=c,c&&(e.adler=r.check=r.flags?B(r.check,i,c,a-c):O(r.check,i,c,a-c)),c=h,(r.flags?u:L(u))!==r.check){e.msg="incorrect data check",r.mode=30;break}l=u=0;}r.mode=28;case 28:if(r.wrap&&r.flags){for(;l<32;){if(0===o)break e;o--,u+=n[s++]<<l,l+=8;}if(u!==(4294967295&r.total)){e.msg="incorrect length check",r.mode=30;break}l=u=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=h,e.next_in=s,e.avail_in=o,r.hold=u,r.bits=l,(r.wsize||c!==e.avail_out&&r.mode<30&&(r.mode<27||4!==t))&&Z(e,e.output,e.next_out,c-e.avail_out)?(r.mode=31,-4):(f-=e.avail_in,c-=e.avail_out,e.total_in+=f,e.total_out+=c,r.total+=c,r.wrap&&c&&(e.adler=r.check=r.flags?B(r.check,i,c,e.next_out-c):O(r.check,i,c,e.next_out-c)),e.data_type=r.bits+(r.last?64:0)+(12===r.mode?128:0)+(20===r.mode||15===r.mode?256:0),(0==f&&0===c||4===t)&&x===N&&(x=-5),x)},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){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 h,u,l,f,c,d,p,m,_,g=o.bits,b=0,v=0,y=0,w=0,k=0,x=0,S=0,z=0,C=0,E=0,A=null,I=0,O=new D.Buf16(16),B=new D.Buf16(16),R=null,T=0;for(b=0;b<=15;b++)O[b]=0;for(v=0;v<n;v++)O[t[r+v]]++;for(k=g,w=15;1<=w&&0===O[w];w--);if(w<k&&(k=w),0===w)return i[s++]=20971520,i[s++]=20971520,o.bits=1,0;for(y=1;y<w&&0===O[y];y++);for(k<y&&(k=y),b=z=1;b<=15;b++)if(z<<=1,(z-=O[b])<0)return -1;if(0<z&&(0===e||1!==w))return -1;for(B[1]=0,b=1;b<15;b++)B[b+1]=B[b]+O[b];for(v=0;v<n;v++)0!==t[r+v]&&(a[B[t[r+v]]++]=v);if(d=0===e?(A=R=a,19):1===e?(A=F,I-=257,R=N,T-=257,256):(A=U,R=P,-1),b=y,c=s,S=v=E=0,l=-1,f=(C=1<<(x=k))-1,1===e&&852<C||2===e&&592<C)return 1;for(;;){for(p=b-S,_=a[v]<d?(m=0,a[v]):a[v]>d?(m=R[T+a[v]],A[I+a[v]]):(m=96,0),h=1<<b-S,y=u=1<<x;i[c+(E>>S)+(u-=h)]=p<<24|m<<16|_|0,0!==u;);for(h=1<<b-1;E&h;)h>>=1;if(0!==h?(E&=h-1,E+=h):E=0,v++,0==--O[b]){if(b===w)break;b=t[r+a[v]];}if(k<b&&(E&f)!==l){for(0===S&&(S=k),c+=y,z=1<<(x=b-S);x+S<w&&!((z-=O[x+S])<=0);)x++,z<<=1;if(C+=1<<x,1===e&&852<C||2===e&&592<C)return 1;i[l=E&f]=k<<24|x<<16|c-s|0;}}return 0!==E&&(i[c+E]=b-S<<24|64<<16|0),o.bits=k,0};},{"../utils/common":41}],51:[function(e,t,r){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){var i=e("../utils/common"),o=0,h=1;function n(e){for(var t=e.length;0<=--t;)e[t]=0;}var s=0,a=29,u=256,l=u+1+a,f=30,c=19,_=2*l+1,g=15,d=16,p=7,m=256,b=16,v=17,y=18,w=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],k=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],x=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],S=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],z=new Array(2*(l+2));n(z);var C=new Array(2*f);n(C);var E=new Array(512);n(E);var A=new Array(256);n(A);var I=new Array(a);n(I);var O,B,R,T=new Array(f);function D(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 F(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t;}function N(e){return e<256?E[e]:E[256+(e>>>7)]}function U(e,t){e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=t>>>8&255;}function P(e,t,r){e.bi_valid>d-r?(e.bi_buf|=t<<e.bi_valid&65535,U(e,e.bi_buf),e.bi_buf=t>>d-e.bi_valid,e.bi_valid+=r-d):(e.bi_buf|=t<<e.bi_valid&65535,e.bi_valid+=r);}function L(e,t,r){P(e,r[2*t],r[2*t+1]);}function j(e,t){for(var r=0;r|=1&e,e>>>=1,r<<=1,0<--t;);return r>>>1}function Z(e,t,r){var n,i,s=new Array(g+1),a=0;for(n=1;n<=g;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]=j(s[o]++,o));}}function W(e){var t;for(t=0;t<l;t++)e.dyn_ltree[2*t]=0;for(t=0;t<f;t++)e.dyn_dtree[2*t]=0;for(t=0;t<c;t++)e.bl_tree[2*t]=0;e.dyn_ltree[2*m]=1,e.opt_len=e.static_len=0,e.last_lit=e.matches=0;}function M(e){8<e.bi_valid?U(e,e.bi_buf):0<e.bi_valid&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0;}function H(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 G(e,t,r){for(var n=e.heap[r],i=r<<1;i<=e.heap_len&&(i<e.heap_len&&H(t,e.heap[i+1],e.heap[i],e.depth)&&i++,!H(t,n,e.heap[i],e.depth));)e.heap[r]=e.heap[i],r=i,i<<=1;e.heap[r]=n;}function K(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?L(e,i,t):(L(e,(s=A[i])+u+1,t),0!==(a=w[s])&&P(e,i-=I[s],a),L(e,s=N(--n),r),0!==(a=k[s])&&P(e,n-=T[s],a)),o<e.last_lit;);L(e,m,t);}function Y(e,t){var r,n,i,s=t.dyn_tree,a=t.stat_desc.static_tree,o=t.stat_desc.has_stree,h=t.stat_desc.elems,u=-1;for(e.heap_len=0,e.heap_max=_,r=0;r<h;r++)0!==s[2*r]?(e.heap[++e.heap_len]=u=r,e.depth[r]=0):s[2*r+1]=0;for(;e.heap_len<2;)s[2*(i=e.heap[++e.heap_len]=u<2?++u:0)]=1,e.depth[i]=0,e.opt_len--,o&&(e.static_len-=a[2*i+1]);for(t.max_code=u,r=e.heap_len>>1;1<=r;r--)G(e,s,r);for(i=h;r=e.heap[1],e.heap[1]=e.heap[e.heap_len--],G(e,s,1),n=e.heap[1],e.heap[--e.heap_max]=r,e.heap[--e.heap_max]=n,s[2*i]=s[2*r]+s[2*n],e.depth[i]=(e.depth[r]>=e.depth[n]?e.depth[r]:e.depth[n])+1,s[2*r+1]=s[2*n+1]=i,e.heap[1]=i++,G(e,s,1),2<=e.heap_len;);e.heap[--e.heap_max]=e.heap[1],function(e,t){var r,n,i,s,a,o,h=t.dyn_tree,u=t.max_code,l=t.stat_desc.static_tree,f=t.stat_desc.has_stree,c=t.stat_desc.extra_bits,d=t.stat_desc.extra_base,p=t.stat_desc.max_length,m=0;for(s=0;s<=g;s++)e.bl_count[s]=0;for(h[2*e.heap[e.heap_max]+1]=0,r=e.heap_max+1;r<_;r++)p<(s=h[2*h[2*(n=e.heap[r])+1]+1]+1)&&(s=p,m++),h[2*n+1]=s,u<n||(e.bl_count[s]++,a=0,d<=n&&(a=c[n-d]),o=h[2*n],e.opt_len+=o*(s+a),f&&(e.static_len+=o*(l[2*n+1]+a)));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;)u<(i=e.heap[--r])||(h[2*i+1]!==s&&(e.opt_len+=(s-h[2*i+1])*h[2*i],h[2*i+1]=s),n--);}}(e,t),Z(s,u,e.bl_count);}function X(e,t,r){var n,i,s=-1,a=t[1],o=0,h=7,u=4;for(0===a&&(h=138,u=3),t[2*(r+1)+1]=65535,n=0;n<=r;n++)i=a,a=t[2*(n+1)+1],++o<h&&i===a||(o<u?e.bl_tree[2*i]+=o:0!==i?(i!==s&&e.bl_tree[2*i]++,e.bl_tree[2*b]++):o<=10?e.bl_tree[2*v]++:e.bl_tree[2*y]++,s=i,u=(o=0)===a?(h=138,3):i===a?(h=6,3):(h=7,4));}function V(e,t,r){var n,i,s=-1,a=t[1],o=0,h=7,u=4;for(0===a&&(h=138,u=3),n=0;n<=r;n++)if(i=a,a=t[2*(n+1)+1],!(++o<h&&i===a)){if(o<u)for(;L(e,i,e.bl_tree),0!=--o;);else 0!==i?(i!==s&&(L(e,i,e.bl_tree),o--),L(e,b,e.bl_tree),P(e,o-3,2)):o<=10?(L(e,v,e.bl_tree),P(e,o-3,3)):(L(e,y,e.bl_tree),P(e,o-11,7));s=i,u=(o=0)===a?(h=138,3):i===a?(h=6,3):(h=7,4);}}n(T);var q=!1;function J(e,t,r,n){P(e,(s<<1)+(n?1:0),3),function(e,t,r,n){M(e),n&&(U(e,r),U(e,~r)),i.arraySet(e.pending_buf,e.window,t,r,e.pending),e.pending+=r;}(e,t,r,!0);}r._tr_init=function(e){q||(function(){var e,t,r,n,i,s=new Array(g+1);for(n=r=0;n<a-1;n++)for(I[n]=r,e=0;e<1<<w[n];e++)A[r++]=n;for(A[r-1]=n,n=i=0;n<16;n++)for(T[n]=i,e=0;e<1<<k[n];e++)E[i++]=n;for(i>>=7;n<f;n++)for(T[n]=i<<7,e=0;e<1<<k[n]-7;e++)E[256+i++]=n;for(t=0;t<=g;t++)s[t]=0;for(e=0;e<=143;)z[2*e+1]=8,e++,s[8]++;for(;e<=255;)z[2*e+1]=9,e++,s[9]++;for(;e<=279;)z[2*e+1]=7,e++,s[7]++;for(;e<=287;)z[2*e+1]=8,e++,s[8]++;for(Z(z,l+1,s),e=0;e<f;e++)C[2*e+1]=5,C[2*e]=j(e,5);O=new D(z,w,u+1,l,g),B=new D(C,k,0,f,g),R=new D(new Array(0),x,0,c,p);}(),q=!0),e.l_desc=new F(e.dyn_ltree,O),e.d_desc=new F(e.dyn_dtree,B),e.bl_desc=new F(e.bl_tree,R),e.bi_buf=0,e.bi_valid=0,W(e);},r._tr_stored_block=J,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 o;if(0!==e.dyn_ltree[18]||0!==e.dyn_ltree[20]||0!==e.dyn_ltree[26])return h;for(t=32;t<u;t++)if(0!==e.dyn_ltree[2*t])return h;return o}(e)),Y(e,e.l_desc),Y(e,e.d_desc),a=function(e){var t;for(X(e,e.dyn_ltree,e.l_desc.max_code),X(e,e.dyn_dtree,e.d_desc.max_code),Y(e,e.bl_desc),t=c-1;3<=t&&0===e.bl_tree[2*S[t]+1];t--);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?J(e,t,r,n):4===e.strategy||s===i?(P(e,2+(n?1:0),3),K(e,z,C)):(P(e,4+(n?1:0),3),function(e,t,r,n){var i;for(P(e,t-257,5),P(e,r-1,5),P(e,n-4,4),i=0;i<n;i++)P(e,e.bl_tree[2*S[i]+1],3);V(e,e.dyn_ltree,t-1),V(e,e.dyn_dtree,r-1);}(e,e.l_desc.max_code+1,e.d_desc.max_code+1,a+1),K(e,e.dyn_ltree,e.dyn_dtree)),W(e),n&&M(e);},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*(A[r]+u+1)]++,e.dyn_dtree[2*N(t)]++),e.last_lit===e.lit_bufsize-1},r._tr_align=function(e){P(e,2,3),L(e,m,z),function(e){16===e.bi_valid?(U(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):8<=e.bi_valid&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8);}(e);};},{"../utils/common":41}],53:[function(e,t,r){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){(function(e){!function(r,n){if(!r.setImmediate){var i,s,t,a,o=1,h={},u=!1,l=r.document,e=Object.getPrototypeOf&&Object.getPrototypeOf(r);e=e&&e.setTimeout?e:r,i="[object process]"==={}.toString.call(r.process)?function(e){browser$1.nextTick(function(){c(e);});}:function(){if(r.postMessage&&!r.importScripts){var e=!0,t=r.onmessage;return r.onmessage=function(){e=!1;},r.postMessage("","*"),r.onmessage=t,e}}()?(a="setImmediate$"+Math.random()+"$",r.addEventListener?r.addEventListener("message",d,!1):r.attachEvent("onmessage",d),function(e){r.postMessage(a+e,"*");}):r.MessageChannel?((t=new MessageChannel).port1.onmessage=function(e){c(e.data);},function(e){t.port2.postMessage(e);}):l&&"onreadystatechange"in l.createElement("script")?(s=l.documentElement,function(e){var t=l.createElement("script");t.onreadystatechange=function(){c(e),t.onreadystatechange=null,s.removeChild(t),t=null;},s.appendChild(t);}):function(e){setTimeout(c,0,e);},e.setImmediate=function(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),r=0;r<t.length;r++)t[r]=arguments[r+1];var n={callback:e,args:t};return h[o]=n,i(o),o++},e.clearImmediate=f;}function f(e){delete h[e];}function c(e){if(u)setTimeout(c,0,e);else {var t=h[e];if(t){u=!0;try{!function(e){var t=e.callback,r=e.args;switch(r.length){case 0:t();break;case 1:t(r[0]);break;case 2:t(r[0],r[1]);break;case 3:t(r[0],r[1],r[2]);break;default:t.apply(n,r);}}(t);}finally{f(e),u=!1;}}}}function d(e){e.source===r&&"string"==typeof e.data&&0===e.data.indexOf(a)&&c(+e.data.slice(a.length));}}("undefined"==typeof self?void 0===e?this:e:self);}).call(this,"undefined"!=typeof commonjsGlobal?commonjsGlobal:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{});},{}]},{},[10])(10)});
  8513. } (jszip_min));
  8514. var jszip_minExports = jszip_min.exports;
  8515. var JSZip = /*@__PURE__*/getDefaultExportFromCjs(jszip_minExports);
  8516. var unzip = async (buffer) => {
  8517. const zip = new JSZip();
  8518. await zip.loadAsync(buffer);
  8519. const files = zip.file(/.+/);
  8520. const out = {};
  8521. await Promise.all(files.map(async (a) => {
  8522. let result;
  8523. if (a.name.slice(-3).toLowerCase() === 'shp' || a.name.slice(-3).toLowerCase() === 'dbf') {
  8524. result = await a.async('nodebuffer');
  8525. } else {
  8526. result = await a.async('text');
  8527. }
  8528. out[a.name] = result;
  8529. }));
  8530. return out;
  8531. };
  8532. const URL$1 = globalThis.URL;
  8533. var combine$1 = (base, type) => {
  8534. if (!type) {
  8535. return base;
  8536. }
  8537. const url = new URL$1(base);
  8538. url.pathname = `${url.pathname}.${type}`;
  8539. return url.href;
  8540. };
  8541. function binaryAjax$1(_url, type) {
  8542. return new Promise(function (resolve, reject) {
  8543. const url = combine$1(_url, type);
  8544. const ajax = new XMLHttpRequest();
  8545. ajax.open('GET', url, true);
  8546. if (type !== 'prj' && type !== 'cpg') {
  8547. ajax.responseType = 'arraybuffer';
  8548. }
  8549. ajax.addEventListener('load', function () {
  8550. if (ajax.status > 399) {
  8551. if (type === 'prj' || type === 'cpg') {
  8552. return resolve(false);
  8553. } else {
  8554. return reject(new Error(ajax.status));
  8555. }
  8556. }
  8557. if (type !== 'prj' && type !== 'cpg') {
  8558. return resolve(Buffer.from(ajax.response));
  8559. } else {
  8560. return resolve(ajax.response);
  8561. }
  8562. }, false);
  8563. ajax.send();
  8564. });
  8565. }
  8566. async function binaryAjax(_url, type) {
  8567. if (!globalThis.fetch) {
  8568. return binaryAjax$1(_url, type);
  8569. }
  8570. const url = combine$1(_url, type);
  8571. const isOptionalTxt = type === 'prj' || type === 'cpg';
  8572. try {
  8573. const resp = await fetch(url);
  8574. if (resp.status > 399) {
  8575. throw new Error(resp.statusText);
  8576. }
  8577. if (isOptionalTxt) {
  8578. return resp.text();
  8579. }
  8580. const parsed = await resp.arrayBuffer();
  8581. return Buffer.from(parsed);
  8582. } catch (e) {
  8583. console.log('ERROR', e, type);
  8584. if (isOptionalTxt || type === 'dbf') {
  8585. return false;
  8586. }
  8587. throw e;
  8588. }
  8589. }
  8590. function isClockWise(array) {
  8591. let sum = 0;
  8592. let i = 1;
  8593. const len = array.length;
  8594. let prev, cur;
  8595. const bbox = [array[0][0], array[0][1], array[0][0], array[0][1]];
  8596. while (i < len) {
  8597. prev = cur || array[0];
  8598. cur = array[i];
  8599. sum += ((cur[0] - prev[0]) * (cur[1] + prev[1]));
  8600. i++;
  8601. if (cur[0] < bbox[0]) {
  8602. bbox[0] = cur[0];
  8603. }
  8604. if (cur[1] < bbox[1]) {
  8605. bbox[1] = cur[1];
  8606. }
  8607. if (cur[0] > bbox[2]) {
  8608. bbox[2] = cur[0];
  8609. }
  8610. if (cur[1] > bbox[3]) {
  8611. bbox[3] = cur[1];
  8612. }
  8613. }
  8614. return {
  8615. ring: array,
  8616. clockWise: sum > 0,
  8617. bbox,
  8618. children: []
  8619. }
  8620. }
  8621. function contains(outer, inner) {
  8622. if (outer.bbox[0] > inner.bbox[0]) {
  8623. return false;
  8624. }
  8625. if (outer.bbox[1] > inner.bbox[1]) {
  8626. return false;
  8627. }
  8628. if (outer.bbox[2] < inner.bbox[2]) {
  8629. return false;
  8630. }
  8631. if (outer.bbox[3] < inner.bbox[3]) {
  8632. return false;
  8633. }
  8634. return true;
  8635. }
  8636. function handleRings(rings) {
  8637. const outers = [];
  8638. const inners = [];
  8639. for (const ring of rings) {
  8640. const proccessed = isClockWise(ring);
  8641. if (proccessed.clockWise) {
  8642. outers.push(proccessed);
  8643. } else {
  8644. inners.push(proccessed);
  8645. }
  8646. }
  8647. // this is an optimization,
  8648. // but it would also put in weird bad rings that would otherwise get left out
  8649. // if (outers.length === 1) {
  8650. // const out = [outers[0].ring]
  8651. // for (const inner of inners) {
  8652. // out.push(inner.ring);
  8653. // }
  8654. // return [out];
  8655. // }
  8656. for (const inner of inners) {
  8657. for (const outer of outers) {
  8658. if (contains(outer, inner)) {
  8659. outer.children.push(inner.ring);
  8660. break;
  8661. }
  8662. }
  8663. }
  8664. const out = [];
  8665. for (const outer of outers) {
  8666. out.push([outer.ring].concat(outer.children));
  8667. }
  8668. return out;
  8669. }
  8670. ParseShp.prototype.parsePoint = function (data) {
  8671. return {
  8672. type: 'Point',
  8673. coordinates: this.parseCoord(data, 0)
  8674. };
  8675. };
  8676. ParseShp.prototype.parseZPoint = function (data) {
  8677. const pointXY = this.parsePoint(data);
  8678. pointXY.coordinates.push(data.readDoubleLE(16));
  8679. return pointXY;
  8680. };
  8681. ParseShp.prototype.parsePointArray = function (data, offset, num) {
  8682. const out = [];
  8683. let done = 0;
  8684. while (done < num) {
  8685. out.push(this.parseCoord(data, offset));
  8686. offset += 16;
  8687. done++;
  8688. }
  8689. return out;
  8690. };
  8691. ParseShp.prototype.parseZPointArray = function (data, zOffset, num, coordinates) {
  8692. let i = 0;
  8693. while (i < num) {
  8694. coordinates[i].push(data.readDoubleLE(zOffset));
  8695. i++;
  8696. zOffset += 8;
  8697. }
  8698. return coordinates;
  8699. };
  8700. ParseShp.prototype.parseArrayGroup = function (data, offset, partOffset, num, tot) {
  8701. const out = [];
  8702. let done = 0;
  8703. let curNum; let nextNum = 0;
  8704. let pointNumber;
  8705. while (done < num) {
  8706. done++;
  8707. partOffset += 4;
  8708. curNum = nextNum;
  8709. if (done === num) {
  8710. nextNum = tot;
  8711. } else {
  8712. nextNum = data.readInt32LE(partOffset);
  8713. }
  8714. pointNumber = nextNum - curNum;
  8715. if (!pointNumber) {
  8716. continue;
  8717. }
  8718. out.push(this.parsePointArray(data, offset, pointNumber));
  8719. offset += (pointNumber << 4);
  8720. }
  8721. return out;
  8722. };
  8723. ParseShp.prototype.parseZArrayGroup = function (data, zOffset, num, coordinates) {
  8724. let i = 0;
  8725. while (i < num) {
  8726. coordinates[i] = this.parseZPointArray(data, zOffset, coordinates[i].length, coordinates[i]);
  8727. zOffset += (coordinates[i].length << 3);
  8728. i++;
  8729. }
  8730. return coordinates;
  8731. };
  8732. ParseShp.prototype.parseMultiPoint = function (data) {
  8733. const out = {};
  8734. const num = data.readInt32LE(32, true);
  8735. if (!num) {
  8736. return null;
  8737. }
  8738. const mins = this.parseCoord(data, 0);
  8739. const maxs = this.parseCoord(data, 16);
  8740. out.bbox = [
  8741. mins[0],
  8742. mins[1],
  8743. maxs[0],
  8744. maxs[1]
  8745. ];
  8746. const offset = 36;
  8747. if (num === 1) {
  8748. out.type = 'Point';
  8749. out.coordinates = this.parseCoord(data, offset);
  8750. } else {
  8751. out.type = 'MultiPoint';
  8752. out.coordinates = this.parsePointArray(data, offset, num);
  8753. }
  8754. return out;
  8755. };
  8756. ParseShp.prototype.parseZMultiPoint = function (data) {
  8757. const geoJson = this.parseMultiPoint(data);
  8758. if (!geoJson) {
  8759. return null;
  8760. }
  8761. let num;
  8762. if (geoJson.type === 'Point') {
  8763. geoJson.coordinates.push(data.readDoubleLE(72));
  8764. return geoJson;
  8765. } else {
  8766. num = geoJson.coordinates.length;
  8767. }
  8768. const zOffset = 52 + (num << 4);
  8769. geoJson.coordinates = this.parseZPointArray(data, zOffset, num, geoJson.coordinates);
  8770. return geoJson;
  8771. };
  8772. ParseShp.prototype.parsePolyline = function (data) {
  8773. const out = {};
  8774. const numParts = data.readInt32LE(32);
  8775. if (!numParts) {
  8776. return null;
  8777. }
  8778. const mins = this.parseCoord(data, 0);
  8779. const maxs = this.parseCoord(data, 16);
  8780. out.bbox = [
  8781. mins[0],
  8782. mins[1],
  8783. maxs[0],
  8784. maxs[1]
  8785. ];
  8786. const num = data.readInt32LE(36);
  8787. let offset, partOffset;
  8788. if (numParts === 1) {
  8789. out.type = 'LineString';
  8790. offset = 44;
  8791. out.coordinates = this.parsePointArray(data, offset, num);
  8792. } else {
  8793. out.type = 'MultiLineString';
  8794. offset = 40 + (numParts << 2);
  8795. partOffset = 40;
  8796. out.coordinates = this.parseArrayGroup(data, offset, partOffset, numParts, num);
  8797. }
  8798. return out;
  8799. };
  8800. ParseShp.prototype.parseZPolyline = function (data) {
  8801. const geoJson = this.parsePolyline(data);
  8802. if (!geoJson) {
  8803. return null;
  8804. }
  8805. const num = geoJson.coordinates.length;
  8806. let zOffset;
  8807. if (geoJson.type === 'LineString') {
  8808. zOffset = 60 + (num << 4);
  8809. geoJson.coordinates = this.parseZPointArray(data, zOffset, num, geoJson.coordinates);
  8810. return geoJson;
  8811. } else {
  8812. const totalPoints = geoJson.coordinates.reduce(function (a, v) {
  8813. return a + v.length;
  8814. }, 0);
  8815. zOffset = 56 + (totalPoints << 4) + (num << 2);
  8816. geoJson.coordinates = this.parseZArrayGroup(data, zOffset, num, geoJson.coordinates);
  8817. return geoJson;
  8818. }
  8819. };
  8820. ParseShp.prototype.polyFuncs = function (out) {
  8821. if (!out) {
  8822. return out;
  8823. }
  8824. if (out.type === 'LineString') {
  8825. out.type = 'Polygon';
  8826. out.coordinates = [out.coordinates];
  8827. return out;
  8828. } else {
  8829. out.coordinates = handleRings(out.coordinates);
  8830. if (out.coordinates.length === 1) {
  8831. out.type = 'Polygon';
  8832. out.coordinates = out.coordinates[0];
  8833. return out;
  8834. } else {
  8835. out.type = 'MultiPolygon';
  8836. return out;
  8837. }
  8838. }
  8839. };
  8840. ParseShp.prototype.parsePolygon = function (data) {
  8841. return this.polyFuncs(this.parsePolyline(data));
  8842. };
  8843. ParseShp.prototype.parseZPolygon = function (data) {
  8844. return this.polyFuncs(this.parseZPolyline(data));
  8845. };
  8846. const shpFuncObj = {
  8847. 1: 'parsePoint',
  8848. 3: 'parsePolyline',
  8849. 5: 'parsePolygon',
  8850. 8: 'parseMultiPoint',
  8851. 11: 'parseZPoint',
  8852. 13: 'parseZPolyline',
  8853. 15: 'parseZPolygon',
  8854. 18: 'parseZMultiPoint'
  8855. };
  8856. function makeParseCoord(trans) {
  8857. if (trans) {
  8858. return function (data, offset) {
  8859. const args = [data.readDoubleLE(offset), data.readDoubleLE(offset + 8)];
  8860. return trans.inverse(args);
  8861. };
  8862. } else {
  8863. return function (data, offset) {
  8864. return [data.readDoubleLE(offset), data.readDoubleLE(offset + 8)];
  8865. };
  8866. }
  8867. }
  8868. function ParseShp(buffer, trans) {
  8869. if (!(this instanceof ParseShp)) {
  8870. return new ParseShp(buffer, trans);
  8871. }
  8872. this.buffer = buffer;
  8873. this.headers = this.parseHeader();
  8874. this.shpFuncs(trans);
  8875. this.rows = this.getRows();
  8876. }
  8877. ParseShp.prototype.shpFuncs = function (tran) {
  8878. let num = this.headers.shpCode;
  8879. if (num > 20) {
  8880. num -= 20;
  8881. }
  8882. if (!(num in shpFuncObj)) {
  8883. throw new Error('I don\'t know that shp type');
  8884. }
  8885. this.parseFunc = this[shpFuncObj[num]];
  8886. this.parseCoord = makeParseCoord(tran);
  8887. };
  8888. ParseShp.prototype.getShpCode = function () {
  8889. return this.parseHeader().shpCode;
  8890. };
  8891. ParseShp.prototype.parseHeader = function () {
  8892. const view = this.buffer.subarray(0, 100);
  8893. return {
  8894. length: view.readInt32BE(6 << 2) << 1,
  8895. version: view.readInt32LE(7 << 2),
  8896. shpCode: view.readInt32LE(8 << 2),
  8897. bbox: [
  8898. view.readDoubleLE(9 << 2),
  8899. view.readDoubleLE(11 << 2),
  8900. view.readDoubleLE(13 << 2),
  8901. view.readDoubleLE(15 << 2)
  8902. ]
  8903. };
  8904. };
  8905. ParseShp.prototype.getRows = function () {
  8906. let offset = 100;
  8907. const olen = this.buffer.byteLength;
  8908. const len = olen - 8;
  8909. const out = [];
  8910. let current;
  8911. while (offset <= len) {
  8912. current = this.getRow(offset, olen);
  8913. if (!current) {
  8914. break;
  8915. }
  8916. offset += 8;
  8917. offset += current.len;
  8918. if (current.type) {
  8919. out.push(this.parseFunc(current.data));
  8920. } else {
  8921. out.push(null);
  8922. }
  8923. }
  8924. return out;
  8925. };
  8926. ParseShp.prototype.getRow = function (offset, bufLen) {
  8927. const view = this.buffer.subarray(offset, offset + 12);
  8928. const len = view.readInt32BE(4) << 1;
  8929. const id = view.readInt32BE(0);
  8930. if (len === 0) {
  8931. return {
  8932. id: id,
  8933. len: len,
  8934. type: 0
  8935. };
  8936. }
  8937. if (offset + len + 8 > bufLen) {
  8938. return;
  8939. }
  8940. return {
  8941. id: id,
  8942. len: len,
  8943. data: this.buffer.subarray(offset + 12, offset + len + 8),
  8944. type: view.readInt32LE(8)
  8945. };
  8946. };
  8947. function parseShp (buffer, trans) {
  8948. return new ParseShp(buffer, trans).rows;
  8949. }
  8950. var encoding = {exports: {}};
  8951. (function (module) {
  8952. // This is free and unencumbered software released into the public domain.
  8953. // See LICENSE.md for more information.
  8954. /**
  8955. * @fileoverview Global |this| required for resolving indexes in node.
  8956. * @suppress {globalThis}
  8957. */
  8958. (function(global) {
  8959. // If we're in node require encoding-indexes and attach it to the global.
  8960. if (module.exports &&
  8961. !global["encoding-indexes"]) ;
  8962. //
  8963. // Utilities
  8964. //
  8965. /**
  8966. * @param {number} a The number to test.
  8967. * @param {number} min The minimum value in the range, inclusive.
  8968. * @param {number} max The maximum value in the range, inclusive.
  8969. * @return {boolean} True if a >= min and a <= max.
  8970. */
  8971. function inRange(a, min, max) {
  8972. return min <= a && a <= max;
  8973. }
  8974. /**
  8975. * @param {!Array.<*>} array The array to check.
  8976. * @param {*} item The item to look for in the array.
  8977. * @return {boolean} True if the item appears in the array.
  8978. */
  8979. function includes(array, item) {
  8980. return array.indexOf(item) !== -1;
  8981. }
  8982. var floor = Math.floor;
  8983. /**
  8984. * @param {*} o
  8985. * @return {Object}
  8986. */
  8987. function ToDictionary(o) {
  8988. if (o === undefined) return {};
  8989. if (o === Object(o)) return o;
  8990. throw TypeError('Could not convert argument to dictionary');
  8991. }
  8992. /**
  8993. * @param {string} string Input string of UTF-16 code units.
  8994. * @return {!Array.<number>} Code points.
  8995. */
  8996. function stringToCodePoints(string) {
  8997. // https://heycam.github.io/webidl/#dfn-obtain-unicode
  8998. // 1. Let S be the DOMString value.
  8999. var s = String(string);
  9000. // 2. Let n be the length of S.
  9001. var n = s.length;
  9002. // 3. Initialize i to 0.
  9003. var i = 0;
  9004. // 4. Initialize U to be an empty sequence of Unicode characters.
  9005. var u = [];
  9006. // 5. While i < n:
  9007. while (i < n) {
  9008. // 1. Let c be the code unit in S at index i.
  9009. var c = s.charCodeAt(i);
  9010. // 2. Depending on the value of c:
  9011. // c < 0xD800 or c > 0xDFFF
  9012. if (c < 0xD800 || c > 0xDFFF) {
  9013. // Append to U the Unicode character with code point c.
  9014. u.push(c);
  9015. }
  9016. // 0xDC00 ≤ c ≤ 0xDFFF
  9017. else if (0xDC00 <= c && c <= 0xDFFF) {
  9018. // Append to U a U+FFFD REPLACEMENT CHARACTER.
  9019. u.push(0xFFFD);
  9020. }
  9021. // 0xD800 ≤ c ≤ 0xDBFF
  9022. else if (0xD800 <= c && c <= 0xDBFF) {
  9023. // 1. If i = n−1, then append to U a U+FFFD REPLACEMENT
  9024. // CHARACTER.
  9025. if (i === n - 1) {
  9026. u.push(0xFFFD);
  9027. }
  9028. // 2. Otherwise, i < n−1:
  9029. else {
  9030. // 1. Let d be the code unit in S at index i+1.
  9031. var d = s.charCodeAt(i + 1);
  9032. // 2. If 0xDC00 ≤ d ≤ 0xDFFF, then:
  9033. if (0xDC00 <= d && d <= 0xDFFF) {
  9034. // 1. Let a be c & 0x3FF.
  9035. var a = c & 0x3FF;
  9036. // 2. Let b be d & 0x3FF.
  9037. var b = d & 0x3FF;
  9038. // 3. Append to U the Unicode character with code point
  9039. // 2^16+2^10*a+b.
  9040. u.push(0x10000 + (a << 10) + b);
  9041. // 4. Set i to i+1.
  9042. i += 1;
  9043. }
  9044. // 3. Otherwise, d < 0xDC00 or d > 0xDFFF. Append to U a
  9045. // U+FFFD REPLACEMENT CHARACTER.
  9046. else {
  9047. u.push(0xFFFD);
  9048. }
  9049. }
  9050. }
  9051. // 3. Set i to i+1.
  9052. i += 1;
  9053. }
  9054. // 6. Return U.
  9055. return u;
  9056. }
  9057. /**
  9058. * @param {!Array.<number>} code_points Array of code points.
  9059. * @return {string} string String of UTF-16 code units.
  9060. */
  9061. function codePointsToString(code_points) {
  9062. var s = '';
  9063. for (var i = 0; i < code_points.length; ++i) {
  9064. var cp = code_points[i];
  9065. if (cp <= 0xFFFF) {
  9066. s += String.fromCharCode(cp);
  9067. } else {
  9068. cp -= 0x10000;
  9069. s += String.fromCharCode((cp >> 10) + 0xD800,
  9070. (cp & 0x3FF) + 0xDC00);
  9071. }
  9072. }
  9073. return s;
  9074. }
  9075. //
  9076. // Implementation of Encoding specification
  9077. // https://encoding.spec.whatwg.org/
  9078. //
  9079. //
  9080. // 4. Terminology
  9081. //
  9082. /**
  9083. * An ASCII byte is a byte in the range 0x00 to 0x7F, inclusive.
  9084. * @param {number} a The number to test.
  9085. * @return {boolean} True if a is in the range 0x00 to 0x7F, inclusive.
  9086. */
  9087. function isASCIIByte(a) {
  9088. return 0x00 <= a && a <= 0x7F;
  9089. }
  9090. /**
  9091. * An ASCII code point is a code point in the range U+0000 to
  9092. * U+007F, inclusive.
  9093. */
  9094. var isASCIICodePoint = isASCIIByte;
  9095. /**
  9096. * End-of-stream is a special token that signifies no more tokens
  9097. * are in the stream.
  9098. * @const
  9099. */ var end_of_stream = -1;
  9100. /**
  9101. * A stream represents an ordered sequence of tokens.
  9102. *
  9103. * @constructor
  9104. * @param {!(Array.<number>|Uint8Array)} tokens Array of tokens that provide
  9105. * the stream.
  9106. */
  9107. function Stream(tokens) {
  9108. /** @type {!Array.<number>} */
  9109. this.tokens = [].slice.call(tokens);
  9110. // Reversed as push/pop is more efficient than shift/unshift.
  9111. this.tokens.reverse();
  9112. }
  9113. Stream.prototype = {
  9114. /**
  9115. * @return {boolean} True if end-of-stream has been hit.
  9116. */
  9117. endOfStream: function() {
  9118. return !this.tokens.length;
  9119. },
  9120. /**
  9121. * When a token is read from a stream, the first token in the
  9122. * stream must be returned and subsequently removed, and
  9123. * end-of-stream must be returned otherwise.
  9124. *
  9125. * @return {number} Get the next token from the stream, or
  9126. * end_of_stream.
  9127. */
  9128. read: function() {
  9129. if (!this.tokens.length)
  9130. return end_of_stream;
  9131. return this.tokens.pop();
  9132. },
  9133. /**
  9134. * When one or more tokens are prepended to a stream, those tokens
  9135. * must be inserted, in given order, before the first token in the
  9136. * stream.
  9137. *
  9138. * @param {(number|!Array.<number>)} token The token(s) to prepend to the
  9139. * stream.
  9140. */
  9141. prepend: function(token) {
  9142. if (Array.isArray(token)) {
  9143. var tokens = /**@type {!Array.<number>}*/(token);
  9144. while (tokens.length)
  9145. this.tokens.push(tokens.pop());
  9146. } else {
  9147. this.tokens.push(token);
  9148. }
  9149. },
  9150. /**
  9151. * When one or more tokens are pushed to a stream, those tokens
  9152. * must be inserted, in given order, after the last token in the
  9153. * stream.
  9154. *
  9155. * @param {(number|!Array.<number>)} token The tokens(s) to push to the
  9156. * stream.
  9157. */
  9158. push: function(token) {
  9159. if (Array.isArray(token)) {
  9160. var tokens = /**@type {!Array.<number>}*/(token);
  9161. while (tokens.length)
  9162. this.tokens.unshift(tokens.shift());
  9163. } else {
  9164. this.tokens.unshift(token);
  9165. }
  9166. }
  9167. };
  9168. //
  9169. // 5. Encodings
  9170. //
  9171. // 5.1 Encoders and decoders
  9172. /** @const */
  9173. var finished = -1;
  9174. /**
  9175. * @param {boolean} fatal If true, decoding errors raise an exception.
  9176. * @param {number=} opt_code_point Override the standard fallback code point.
  9177. * @return {number} The code point to insert on a decoding error.
  9178. */
  9179. function decoderError(fatal, opt_code_point) {
  9180. if (fatal)
  9181. throw TypeError('Decoder error');
  9182. return opt_code_point || 0xFFFD;
  9183. }
  9184. /**
  9185. * @param {number} code_point The code point that could not be encoded.
  9186. * @return {number} Always throws, no value is actually returned.
  9187. */
  9188. function encoderError(code_point) {
  9189. throw TypeError('The code point ' + code_point + ' could not be encoded.');
  9190. }
  9191. // 5.2 Names and labels
  9192. // TODO: Define @typedef for Encoding: {name:string,labels:Array.<string>}
  9193. // https://github.com/google/closure-compiler/issues/247
  9194. /**
  9195. * @param {string} label The encoding label.
  9196. * @return {?{name:string,labels:Array.<string>}}
  9197. */
  9198. function getEncoding(label) {
  9199. // 1. Remove any leading and trailing ASCII whitespace from label.
  9200. label = String(label).trim().toLowerCase();
  9201. // 2. If label is an ASCII case-insensitive match for any of the
  9202. // labels listed in the table below, return the corresponding
  9203. // encoding, and failure otherwise.
  9204. if (Object.prototype.hasOwnProperty.call(label_to_encoding, label)) {
  9205. return label_to_encoding[label];
  9206. }
  9207. return null;
  9208. }
  9209. /**
  9210. * Encodings table: https://encoding.spec.whatwg.org/encodings.json
  9211. * @const
  9212. * @type {!Array.<{
  9213. * heading: string,
  9214. * encodings: Array.<{name:string,labels:Array.<string>}>
  9215. * }>}
  9216. */
  9217. var encodings = [
  9218. {
  9219. "encodings": [
  9220. {
  9221. "labels": [
  9222. "unicode-1-1-utf-8",
  9223. "utf-8",
  9224. "utf8"
  9225. ],
  9226. "name": "UTF-8"
  9227. }
  9228. ],
  9229. "heading": "The Encoding"
  9230. },
  9231. {
  9232. "encodings": [
  9233. {
  9234. "labels": [
  9235. "866",
  9236. "cp866",
  9237. "csibm866",
  9238. "ibm866"
  9239. ],
  9240. "name": "IBM866"
  9241. },
  9242. {
  9243. "labels": [
  9244. "csisolatin2",
  9245. "iso-8859-2",
  9246. "iso-ir-101",
  9247. "iso8859-2",
  9248. "iso88592",
  9249. "iso_8859-2",
  9250. "iso_8859-2:1987",
  9251. "l2",
  9252. "latin2"
  9253. ],
  9254. "name": "ISO-8859-2"
  9255. },
  9256. {
  9257. "labels": [
  9258. "csisolatin3",
  9259. "iso-8859-3",
  9260. "iso-ir-109",
  9261. "iso8859-3",
  9262. "iso88593",
  9263. "iso_8859-3",
  9264. "iso_8859-3:1988",
  9265. "l3",
  9266. "latin3"
  9267. ],
  9268. "name": "ISO-8859-3"
  9269. },
  9270. {
  9271. "labels": [
  9272. "csisolatin4",
  9273. "iso-8859-4",
  9274. "iso-ir-110",
  9275. "iso8859-4",
  9276. "iso88594",
  9277. "iso_8859-4",
  9278. "iso_8859-4:1988",
  9279. "l4",
  9280. "latin4"
  9281. ],
  9282. "name": "ISO-8859-4"
  9283. },
  9284. {
  9285. "labels": [
  9286. "csisolatincyrillic",
  9287. "cyrillic",
  9288. "iso-8859-5",
  9289. "iso-ir-144",
  9290. "iso8859-5",
  9291. "iso88595",
  9292. "iso_8859-5",
  9293. "iso_8859-5:1988"
  9294. ],
  9295. "name": "ISO-8859-5"
  9296. },
  9297. {
  9298. "labels": [
  9299. "arabic",
  9300. "asmo-708",
  9301. "csiso88596e",
  9302. "csiso88596i",
  9303. "csisolatinarabic",
  9304. "ecma-114",
  9305. "iso-8859-6",
  9306. "iso-8859-6-e",
  9307. "iso-8859-6-i",
  9308. "iso-ir-127",
  9309. "iso8859-6",
  9310. "iso88596",
  9311. "iso_8859-6",
  9312. "iso_8859-6:1987"
  9313. ],
  9314. "name": "ISO-8859-6"
  9315. },
  9316. {
  9317. "labels": [
  9318. "csisolatingreek",
  9319. "ecma-118",
  9320. "elot_928",
  9321. "greek",
  9322. "greek8",
  9323. "iso-8859-7",
  9324. "iso-ir-126",
  9325. "iso8859-7",
  9326. "iso88597",
  9327. "iso_8859-7",
  9328. "iso_8859-7:1987",
  9329. "sun_eu_greek"
  9330. ],
  9331. "name": "ISO-8859-7"
  9332. },
  9333. {
  9334. "labels": [
  9335. "csiso88598e",
  9336. "csisolatinhebrew",
  9337. "hebrew",
  9338. "iso-8859-8",
  9339. "iso-8859-8-e",
  9340. "iso-ir-138",
  9341. "iso8859-8",
  9342. "iso88598",
  9343. "iso_8859-8",
  9344. "iso_8859-8:1988",
  9345. "visual"
  9346. ],
  9347. "name": "ISO-8859-8"
  9348. },
  9349. {
  9350. "labels": [
  9351. "csiso88598i",
  9352. "iso-8859-8-i",
  9353. "logical"
  9354. ],
  9355. "name": "ISO-8859-8-I"
  9356. },
  9357. {
  9358. "labels": [
  9359. "csisolatin6",
  9360. "iso-8859-10",
  9361. "iso-ir-157",
  9362. "iso8859-10",
  9363. "iso885910",
  9364. "l6",
  9365. "latin6"
  9366. ],
  9367. "name": "ISO-8859-10"
  9368. },
  9369. {
  9370. "labels": [
  9371. "iso-8859-13",
  9372. "iso8859-13",
  9373. "iso885913"
  9374. ],
  9375. "name": "ISO-8859-13"
  9376. },
  9377. {
  9378. "labels": [
  9379. "iso-8859-14",
  9380. "iso8859-14",
  9381. "iso885914"
  9382. ],
  9383. "name": "ISO-8859-14"
  9384. },
  9385. {
  9386. "labels": [
  9387. "csisolatin9",
  9388. "iso-8859-15",
  9389. "iso8859-15",
  9390. "iso885915",
  9391. "iso_8859-15",
  9392. "l9"
  9393. ],
  9394. "name": "ISO-8859-15"
  9395. },
  9396. {
  9397. "labels": [
  9398. "iso-8859-16"
  9399. ],
  9400. "name": "ISO-8859-16"
  9401. },
  9402. {
  9403. "labels": [
  9404. "cskoi8r",
  9405. "koi",
  9406. "koi8",
  9407. "koi8-r",
  9408. "koi8_r"
  9409. ],
  9410. "name": "KOI8-R"
  9411. },
  9412. {
  9413. "labels": [
  9414. "koi8-ru",
  9415. "koi8-u"
  9416. ],
  9417. "name": "KOI8-U"
  9418. },
  9419. {
  9420. "labels": [
  9421. "csmacintosh",
  9422. "mac",
  9423. "macintosh",
  9424. "x-mac-roman"
  9425. ],
  9426. "name": "macintosh"
  9427. },
  9428. {
  9429. "labels": [
  9430. "dos-874",
  9431. "iso-8859-11",
  9432. "iso8859-11",
  9433. "iso885911",
  9434. "tis-620",
  9435. "windows-874"
  9436. ],
  9437. "name": "windows-874"
  9438. },
  9439. {
  9440. "labels": [
  9441. "cp1250",
  9442. "windows-1250",
  9443. "x-cp1250"
  9444. ],
  9445. "name": "windows-1250"
  9446. },
  9447. {
  9448. "labels": [
  9449. "cp1251",
  9450. "windows-1251",
  9451. "x-cp1251"
  9452. ],
  9453. "name": "windows-1251"
  9454. },
  9455. {
  9456. "labels": [
  9457. "ansi_x3.4-1968",
  9458. "ascii",
  9459. "cp1252",
  9460. "cp819",
  9461. "csisolatin1",
  9462. "ibm819",
  9463. "iso-8859-1",
  9464. "iso-ir-100",
  9465. "iso8859-1",
  9466. "iso88591",
  9467. "iso_8859-1",
  9468. "iso_8859-1:1987",
  9469. "l1",
  9470. "latin1",
  9471. "us-ascii",
  9472. "windows-1252",
  9473. "x-cp1252"
  9474. ],
  9475. "name": "windows-1252"
  9476. },
  9477. {
  9478. "labels": [
  9479. "cp1253",
  9480. "windows-1253",
  9481. "x-cp1253"
  9482. ],
  9483. "name": "windows-1253"
  9484. },
  9485. {
  9486. "labels": [
  9487. "cp1254",
  9488. "csisolatin5",
  9489. "iso-8859-9",
  9490. "iso-ir-148",
  9491. "iso8859-9",
  9492. "iso88599",
  9493. "iso_8859-9",
  9494. "iso_8859-9:1989",
  9495. "l5",
  9496. "latin5",
  9497. "windows-1254",
  9498. "x-cp1254"
  9499. ],
  9500. "name": "windows-1254"
  9501. },
  9502. {
  9503. "labels": [
  9504. "cp1255",
  9505. "windows-1255",
  9506. "x-cp1255"
  9507. ],
  9508. "name": "windows-1255"
  9509. },
  9510. {
  9511. "labels": [
  9512. "cp1256",
  9513. "windows-1256",
  9514. "x-cp1256"
  9515. ],
  9516. "name": "windows-1256"
  9517. },
  9518. {
  9519. "labels": [
  9520. "cp1257",
  9521. "windows-1257",
  9522. "x-cp1257"
  9523. ],
  9524. "name": "windows-1257"
  9525. },
  9526. {
  9527. "labels": [
  9528. "cp1258",
  9529. "windows-1258",
  9530. "x-cp1258"
  9531. ],
  9532. "name": "windows-1258"
  9533. },
  9534. {
  9535. "labels": [
  9536. "x-mac-cyrillic",
  9537. "x-mac-ukrainian"
  9538. ],
  9539. "name": "x-mac-cyrillic"
  9540. }
  9541. ],
  9542. "heading": "Legacy single-byte encodings"
  9543. },
  9544. {
  9545. "encodings": [
  9546. {
  9547. "labels": [
  9548. "chinese",
  9549. "csgb2312",
  9550. "csiso58gb231280",
  9551. "gb2312",
  9552. "gb_2312",
  9553. "gb_2312-80",
  9554. "gbk",
  9555. "iso-ir-58",
  9556. "x-gbk"
  9557. ],
  9558. "name": "GBK"
  9559. },
  9560. {
  9561. "labels": [
  9562. "gb18030"
  9563. ],
  9564. "name": "gb18030"
  9565. }
  9566. ],
  9567. "heading": "Legacy multi-byte Chinese (simplified) encodings"
  9568. },
  9569. {
  9570. "encodings": [
  9571. {
  9572. "labels": [
  9573. "big5",
  9574. "big5-hkscs",
  9575. "cn-big5",
  9576. "csbig5",
  9577. "x-x-big5"
  9578. ],
  9579. "name": "Big5"
  9580. }
  9581. ],
  9582. "heading": "Legacy multi-byte Chinese (traditional) encodings"
  9583. },
  9584. {
  9585. "encodings": [
  9586. {
  9587. "labels": [
  9588. "cseucpkdfmtjapanese",
  9589. "euc-jp",
  9590. "x-euc-jp"
  9591. ],
  9592. "name": "EUC-JP"
  9593. },
  9594. {
  9595. "labels": [
  9596. "csiso2022jp",
  9597. "iso-2022-jp"
  9598. ],
  9599. "name": "ISO-2022-JP"
  9600. },
  9601. {
  9602. "labels": [
  9603. "csshiftjis",
  9604. "ms932",
  9605. "ms_kanji",
  9606. "shift-jis",
  9607. "shift_jis",
  9608. "sjis",
  9609. "windows-31j",
  9610. "x-sjis"
  9611. ],
  9612. "name": "Shift_JIS"
  9613. }
  9614. ],
  9615. "heading": "Legacy multi-byte Japanese encodings"
  9616. },
  9617. {
  9618. "encodings": [
  9619. {
  9620. "labels": [
  9621. "cseuckr",
  9622. "csksc56011987",
  9623. "euc-kr",
  9624. "iso-ir-149",
  9625. "korean",
  9626. "ks_c_5601-1987",
  9627. "ks_c_5601-1989",
  9628. "ksc5601",
  9629. "ksc_5601",
  9630. "windows-949"
  9631. ],
  9632. "name": "EUC-KR"
  9633. }
  9634. ],
  9635. "heading": "Legacy multi-byte Korean encodings"
  9636. },
  9637. {
  9638. "encodings": [
  9639. {
  9640. "labels": [
  9641. "csiso2022kr",
  9642. "hz-gb-2312",
  9643. "iso-2022-cn",
  9644. "iso-2022-cn-ext",
  9645. "iso-2022-kr"
  9646. ],
  9647. "name": "replacement"
  9648. },
  9649. {
  9650. "labels": [
  9651. "utf-16be"
  9652. ],
  9653. "name": "UTF-16BE"
  9654. },
  9655. {
  9656. "labels": [
  9657. "utf-16",
  9658. "utf-16le"
  9659. ],
  9660. "name": "UTF-16LE"
  9661. },
  9662. {
  9663. "labels": [
  9664. "x-user-defined"
  9665. ],
  9666. "name": "x-user-defined"
  9667. }
  9668. ],
  9669. "heading": "Legacy miscellaneous encodings"
  9670. }
  9671. ];
  9672. // Label to encoding registry.
  9673. /** @type {Object.<string,{name:string,labels:Array.<string>}>} */
  9674. var label_to_encoding = {};
  9675. encodings.forEach(function(category) {
  9676. category.encodings.forEach(function(encoding) {
  9677. encoding.labels.forEach(function(label) {
  9678. label_to_encoding[label] = encoding;
  9679. });
  9680. });
  9681. });
  9682. // Registry of of encoder/decoder factories, by encoding name.
  9683. /** @type {Object.<string, function({fatal:boolean}): Encoder>} */
  9684. var encoders = {};
  9685. /** @type {Object.<string, function({fatal:boolean}): Decoder>} */
  9686. var decoders = {};
  9687. //
  9688. // 6. Indexes
  9689. //
  9690. /**
  9691. * @param {number} pointer The |pointer| to search for.
  9692. * @param {(!Array.<?number>|undefined)} index The |index| to search within.
  9693. * @return {?number} The code point corresponding to |pointer| in |index|,
  9694. * or null if |code point| is not in |index|.
  9695. */
  9696. function indexCodePointFor(pointer, index) {
  9697. if (!index) return null;
  9698. return index[pointer] || null;
  9699. }
  9700. /**
  9701. * @param {number} code_point The |code point| to search for.
  9702. * @param {!Array.<?number>} index The |index| to search within.
  9703. * @return {?number} The first pointer corresponding to |code point| in
  9704. * |index|, or null if |code point| is not in |index|.
  9705. */
  9706. function indexPointerFor(code_point, index) {
  9707. var pointer = index.indexOf(code_point);
  9708. return pointer === -1 ? null : pointer;
  9709. }
  9710. /**
  9711. * @param {string} name Name of the index.
  9712. * @return {(!Array.<number>|!Array.<Array.<number>>)}
  9713. * */
  9714. function index(name) {
  9715. if (!('encoding-indexes' in global)) {
  9716. throw Error("Indexes missing." +
  9717. " Did you forget to include encoding-indexes.js first?");
  9718. }
  9719. return global['encoding-indexes'][name];
  9720. }
  9721. /**
  9722. * @param {number} pointer The |pointer| to search for in the gb18030 index.
  9723. * @return {?number} The code point corresponding to |pointer| in |index|,
  9724. * or null if |code point| is not in the gb18030 index.
  9725. */
  9726. function indexGB18030RangesCodePointFor(pointer) {
  9727. // 1. If pointer is greater than 39419 and less than 189000, or
  9728. // pointer is greater than 1237575, return null.
  9729. if ((pointer > 39419 && pointer < 189000) || (pointer > 1237575))
  9730. return null;
  9731. // 2. If pointer is 7457, return code point U+E7C7.
  9732. if (pointer === 7457) return 0xE7C7;
  9733. // 3. Let offset be the last pointer in index gb18030 ranges that
  9734. // is equal to or less than pointer and let code point offset be
  9735. // its corresponding code point.
  9736. var offset = 0;
  9737. var code_point_offset = 0;
  9738. var idx = index('gb18030-ranges');
  9739. var i;
  9740. for (i = 0; i < idx.length; ++i) {
  9741. /** @type {!Array.<number>} */
  9742. var entry = idx[i];
  9743. if (entry[0] <= pointer) {
  9744. offset = entry[0];
  9745. code_point_offset = entry[1];
  9746. } else {
  9747. break;
  9748. }
  9749. }
  9750. // 4. Return a code point whose value is code point offset +
  9751. // pointer − offset.
  9752. return code_point_offset + pointer - offset;
  9753. }
  9754. /**
  9755. * @param {number} code_point The |code point| to locate in the gb18030 index.
  9756. * @return {number} The first pointer corresponding to |code point| in the
  9757. * gb18030 index.
  9758. */
  9759. function indexGB18030RangesPointerFor(code_point) {
  9760. // 1. If code point is U+E7C7, return pointer 7457.
  9761. if (code_point === 0xE7C7) return 7457;
  9762. // 2. Let offset be the last code point in index gb18030 ranges
  9763. // that is equal to or less than code point and let pointer offset
  9764. // be its corresponding pointer.
  9765. var offset = 0;
  9766. var pointer_offset = 0;
  9767. var idx = index('gb18030-ranges');
  9768. var i;
  9769. for (i = 0; i < idx.length; ++i) {
  9770. /** @type {!Array.<number>} */
  9771. var entry = idx[i];
  9772. if (entry[1] <= code_point) {
  9773. offset = entry[1];
  9774. pointer_offset = entry[0];
  9775. } else {
  9776. break;
  9777. }
  9778. }
  9779. // 3. Return a pointer whose value is pointer offset + code point
  9780. // − offset.
  9781. return pointer_offset + code_point - offset;
  9782. }
  9783. /**
  9784. * @param {number} code_point The |code_point| to search for in the Shift_JIS
  9785. * index.
  9786. * @return {?number} The code point corresponding to |pointer| in |index|,
  9787. * or null if |code point| is not in the Shift_JIS index.
  9788. */
  9789. function indexShiftJISPointerFor(code_point) {
  9790. // 1. Let index be index jis0208 excluding all entries whose
  9791. // pointer is in the range 8272 to 8835, inclusive.
  9792. shift_jis_index = shift_jis_index ||
  9793. index('jis0208').map(function(code_point, pointer) {
  9794. return inRange(pointer, 8272, 8835) ? null : code_point;
  9795. });
  9796. var index_ = shift_jis_index;
  9797. // 2. Return the index pointer for code point in index.
  9798. return index_.indexOf(code_point);
  9799. }
  9800. var shift_jis_index;
  9801. /**
  9802. * @param {number} code_point The |code_point| to search for in the big5
  9803. * index.
  9804. * @return {?number} The code point corresponding to |pointer| in |index|,
  9805. * or null if |code point| is not in the big5 index.
  9806. */
  9807. function indexBig5PointerFor(code_point) {
  9808. // 1. Let index be index Big5 excluding all entries whose pointer
  9809. big5_index_no_hkscs = big5_index_no_hkscs ||
  9810. index('big5').map(function(code_point, pointer) {
  9811. return (pointer < (0xA1 - 0x81) * 157) ? null : code_point;
  9812. });
  9813. var index_ = big5_index_no_hkscs;
  9814. // 2. If code point is U+2550, U+255E, U+2561, U+256A, U+5341, or
  9815. // U+5345, return the last pointer corresponding to code point in
  9816. // index.
  9817. if (code_point === 0x2550 || code_point === 0x255E ||
  9818. code_point === 0x2561 || code_point === 0x256A ||
  9819. code_point === 0x5341 || code_point === 0x5345) {
  9820. return index_.lastIndexOf(code_point);
  9821. }
  9822. // 3. Return the index pointer for code point in index.
  9823. return indexPointerFor(code_point, index_);
  9824. }
  9825. var big5_index_no_hkscs;
  9826. //
  9827. // 8. API
  9828. //
  9829. /** @const */ var DEFAULT_ENCODING = 'utf-8';
  9830. // 8.1 Interface TextDecoder
  9831. /**
  9832. * @constructor
  9833. * @param {string=} label The label of the encoding;
  9834. * defaults to 'utf-8'.
  9835. * @param {Object=} options
  9836. */
  9837. function TextDecoder(label, options) {
  9838. // Web IDL conventions
  9839. if (!(this instanceof TextDecoder))
  9840. throw TypeError('Called as a function. Did you forget \'new\'?');
  9841. label = label !== undefined ? String(label) : DEFAULT_ENCODING;
  9842. options = ToDictionary(options);
  9843. // A TextDecoder object has an associated encoding, decoder,
  9844. // stream, ignore BOM flag (initially unset), BOM seen flag
  9845. // (initially unset), error mode (initially replacement), and do
  9846. // not flush flag (initially unset).
  9847. /** @private */
  9848. this._encoding = null;
  9849. /** @private @type {?Decoder} */
  9850. this._decoder = null;
  9851. /** @private @type {boolean} */
  9852. this._ignoreBOM = false;
  9853. /** @private @type {boolean} */
  9854. this._BOMseen = false;
  9855. /** @private @type {string} */
  9856. this._error_mode = 'replacement';
  9857. /** @private @type {boolean} */
  9858. this._do_not_flush = false;
  9859. // 1. Let encoding be the result of getting an encoding from
  9860. // label.
  9861. var encoding = getEncoding(label);
  9862. // 2. If encoding is failure or replacement, throw a RangeError.
  9863. if (encoding === null || encoding.name === 'replacement')
  9864. throw RangeError('Unknown encoding: ' + label);
  9865. if (!decoders[encoding.name]) {
  9866. throw Error('Decoder not present.' +
  9867. ' Did you forget to include encoding-indexes.js first?');
  9868. }
  9869. // 3. Let dec be a new TextDecoder object.
  9870. var dec = this;
  9871. // 4. Set dec's encoding to encoding.
  9872. dec._encoding = encoding;
  9873. // 5. If options's fatal member is true, set dec's error mode to
  9874. // fatal.
  9875. if (Boolean(options['fatal']))
  9876. dec._error_mode = 'fatal';
  9877. // 6. If options's ignoreBOM member is true, set dec's ignore BOM
  9878. // flag.
  9879. if (Boolean(options['ignoreBOM']))
  9880. dec._ignoreBOM = true;
  9881. // For pre-ES5 runtimes:
  9882. if (!Object.defineProperty) {
  9883. this.encoding = dec._encoding.name.toLowerCase();
  9884. this.fatal = dec._error_mode === 'fatal';
  9885. this.ignoreBOM = dec._ignoreBOM;
  9886. }
  9887. // 7. Return dec.
  9888. return dec;
  9889. }
  9890. if (Object.defineProperty) {
  9891. // The encoding attribute's getter must return encoding's name.
  9892. Object.defineProperty(TextDecoder.prototype, 'encoding', {
  9893. /** @this {TextDecoder} */
  9894. get: function() { return this._encoding.name.toLowerCase(); }
  9895. });
  9896. // The fatal attribute's getter must return true if error mode
  9897. // is fatal, and false otherwise.
  9898. Object.defineProperty(TextDecoder.prototype, 'fatal', {
  9899. /** @this {TextDecoder} */
  9900. get: function() { return this._error_mode === 'fatal'; }
  9901. });
  9902. // The ignoreBOM attribute's getter must return true if ignore
  9903. // BOM flag is set, and false otherwise.
  9904. Object.defineProperty(TextDecoder.prototype, 'ignoreBOM', {
  9905. /** @this {TextDecoder} */
  9906. get: function() { return this._ignoreBOM; }
  9907. });
  9908. }
  9909. /**
  9910. * @param {BufferSource=} input The buffer of bytes to decode.
  9911. * @param {Object=} options
  9912. * @return {string} The decoded string.
  9913. */
  9914. TextDecoder.prototype.decode = function decode(input, options) {
  9915. var bytes;
  9916. if (typeof input === 'object' && input instanceof ArrayBuffer) {
  9917. bytes = new Uint8Array(input);
  9918. } else if (typeof input === 'object' && 'buffer' in input &&
  9919. input.buffer instanceof ArrayBuffer) {
  9920. bytes = new Uint8Array(input.buffer,
  9921. input.byteOffset,
  9922. input.byteLength);
  9923. } else {
  9924. bytes = new Uint8Array(0);
  9925. }
  9926. options = ToDictionary(options);
  9927. // 1. If the do not flush flag is unset, set decoder to a new
  9928. // encoding's decoder, set stream to a new stream, and unset the
  9929. // BOM seen flag.
  9930. if (!this._do_not_flush) {
  9931. this._decoder = decoders[this._encoding.name]({
  9932. fatal: this._error_mode === 'fatal'});
  9933. this._BOMseen = false;
  9934. }
  9935. // 2. If options's stream is true, set the do not flush flag, and
  9936. // unset the do not flush flag otherwise.
  9937. this._do_not_flush = Boolean(options['stream']);
  9938. // 3. If input is given, push a copy of input to stream.
  9939. // TODO: Align with spec algorithm - maintain stream on instance.
  9940. var input_stream = new Stream(bytes);
  9941. // 4. Let output be a new stream.
  9942. var output = [];
  9943. /** @type {?(number|!Array.<number>)} */
  9944. var result;
  9945. // 5. While true:
  9946. while (true) {
  9947. // 1. Let token be the result of reading from stream.
  9948. var token = input_stream.read();
  9949. // 2. If token is end-of-stream and the do not flush flag is
  9950. // set, return output, serialized.
  9951. // TODO: Align with spec algorithm.
  9952. if (token === end_of_stream)
  9953. break;
  9954. // 3. Otherwise, run these subsubsteps:
  9955. // 1. Let result be the result of processing token for decoder,
  9956. // stream, output, and error mode.
  9957. result = this._decoder.handler(input_stream, token);
  9958. // 2. If result is finished, return output, serialized.
  9959. if (result === finished)
  9960. break;
  9961. if (result !== null) {
  9962. if (Array.isArray(result))
  9963. output.push.apply(output, /**@type {!Array.<number>}*/(result));
  9964. else
  9965. output.push(result);
  9966. }
  9967. // 3. Otherwise, if result is error, throw a TypeError.
  9968. // (Thrown in handler)
  9969. // 4. Otherwise, do nothing.
  9970. }
  9971. // TODO: Align with spec algorithm.
  9972. if (!this._do_not_flush) {
  9973. do {
  9974. result = this._decoder.handler(input_stream, input_stream.read());
  9975. if (result === finished)
  9976. break;
  9977. if (result === null)
  9978. continue;
  9979. if (Array.isArray(result))
  9980. output.push.apply(output, /**@type {!Array.<number>}*/(result));
  9981. else
  9982. output.push(result);
  9983. } while (!input_stream.endOfStream());
  9984. this._decoder = null;
  9985. }
  9986. // A TextDecoder object also has an associated serialize stream
  9987. // algorithm...
  9988. /**
  9989. * @param {!Array.<number>} stream
  9990. * @return {string}
  9991. * @this {TextDecoder}
  9992. */
  9993. function serializeStream(stream) {
  9994. // 1. Let token be the result of reading from stream.
  9995. // (Done in-place on array, rather than as a stream)
  9996. // 2. If encoding is UTF-8, UTF-16BE, or UTF-16LE, and ignore
  9997. // BOM flag and BOM seen flag are unset, run these subsubsteps:
  9998. if (includes(['UTF-8', 'UTF-16LE', 'UTF-16BE'], this._encoding.name) &&
  9999. !this._ignoreBOM && !this._BOMseen) {
  10000. if (stream.length > 0 && stream[0] === 0xFEFF) {
  10001. // 1. If token is U+FEFF, set BOM seen flag.
  10002. this._BOMseen = true;
  10003. stream.shift();
  10004. } else if (stream.length > 0) {
  10005. // 2. Otherwise, if token is not end-of-stream, set BOM seen
  10006. // flag and append token to stream.
  10007. this._BOMseen = true;
  10008. } else ;
  10009. }
  10010. // 4. Otherwise, return output.
  10011. return codePointsToString(stream);
  10012. }
  10013. return serializeStream.call(this, output);
  10014. };
  10015. // 8.2 Interface TextEncoder
  10016. /**
  10017. * @constructor
  10018. * @param {string=} label The label of the encoding. NONSTANDARD.
  10019. * @param {Object=} options NONSTANDARD.
  10020. */
  10021. function TextEncoder(label, options) {
  10022. // Web IDL conventions
  10023. if (!(this instanceof TextEncoder))
  10024. throw TypeError('Called as a function. Did you forget \'new\'?');
  10025. options = ToDictionary(options);
  10026. // A TextEncoder object has an associated encoding and encoder.
  10027. /** @private */
  10028. this._encoding = null;
  10029. /** @private @type {?Encoder} */
  10030. this._encoder = null;
  10031. // Non-standard
  10032. /** @private @type {boolean} */
  10033. this._do_not_flush = false;
  10034. /** @private @type {string} */
  10035. this._fatal = Boolean(options['fatal']) ? 'fatal' : 'replacement';
  10036. // 1. Let enc be a new TextEncoder object.
  10037. var enc = this;
  10038. // 2. Set enc's encoding to UTF-8's encoder.
  10039. if (Boolean(options['NONSTANDARD_allowLegacyEncoding'])) {
  10040. // NONSTANDARD behavior.
  10041. label = label !== undefined ? String(label) : DEFAULT_ENCODING;
  10042. var encoding = getEncoding(label);
  10043. if (encoding === null || encoding.name === 'replacement')
  10044. throw RangeError('Unknown encoding: ' + label);
  10045. if (!encoders[encoding.name]) {
  10046. throw Error('Encoder not present.' +
  10047. ' Did you forget to include encoding-indexes.js first?');
  10048. }
  10049. enc._encoding = encoding;
  10050. } else {
  10051. // Standard behavior.
  10052. enc._encoding = getEncoding('utf-8');
  10053. if (label !== undefined && 'console' in global) {
  10054. console.warn('TextEncoder constructor called with encoding label, '
  10055. + 'which is ignored.');
  10056. }
  10057. }
  10058. // For pre-ES5 runtimes:
  10059. if (!Object.defineProperty)
  10060. this.encoding = enc._encoding.name.toLowerCase();
  10061. // 3. Return enc.
  10062. return enc;
  10063. }
  10064. if (Object.defineProperty) {
  10065. // The encoding attribute's getter must return encoding's name.
  10066. Object.defineProperty(TextEncoder.prototype, 'encoding', {
  10067. /** @this {TextEncoder} */
  10068. get: function() { return this._encoding.name.toLowerCase(); }
  10069. });
  10070. }
  10071. /**
  10072. * @param {string=} opt_string The string to encode.
  10073. * @param {Object=} options
  10074. * @return {!Uint8Array} Encoded bytes, as a Uint8Array.
  10075. */
  10076. TextEncoder.prototype.encode = function encode(opt_string, options) {
  10077. opt_string = opt_string === undefined ? '' : String(opt_string);
  10078. options = ToDictionary(options);
  10079. // NOTE: This option is nonstandard. None of the encodings
  10080. // permitted for encoding (i.e. UTF-8, UTF-16) are stateful when
  10081. // the input is a USVString so streaming is not necessary.
  10082. if (!this._do_not_flush)
  10083. this._encoder = encoders[this._encoding.name]({
  10084. fatal: this._fatal === 'fatal'});
  10085. this._do_not_flush = Boolean(options['stream']);
  10086. // 1. Convert input to a stream.
  10087. var input = new Stream(stringToCodePoints(opt_string));
  10088. // 2. Let output be a new stream
  10089. var output = [];
  10090. /** @type {?(number|!Array.<number>)} */
  10091. var result;
  10092. // 3. While true, run these substeps:
  10093. while (true) {
  10094. // 1. Let token be the result of reading from input.
  10095. var token = input.read();
  10096. if (token === end_of_stream)
  10097. break;
  10098. // 2. Let result be the result of processing token for encoder,
  10099. // input, output.
  10100. result = this._encoder.handler(input, token);
  10101. if (result === finished)
  10102. break;
  10103. if (Array.isArray(result))
  10104. output.push.apply(output, /**@type {!Array.<number>}*/(result));
  10105. else
  10106. output.push(result);
  10107. }
  10108. // TODO: Align with spec algorithm.
  10109. if (!this._do_not_flush) {
  10110. while (true) {
  10111. result = this._encoder.handler(input, input.read());
  10112. if (result === finished)
  10113. break;
  10114. if (Array.isArray(result))
  10115. output.push.apply(output, /**@type {!Array.<number>}*/(result));
  10116. else
  10117. output.push(result);
  10118. }
  10119. this._encoder = null;
  10120. }
  10121. // 3. If result is finished, convert output into a byte sequence,
  10122. // and then return a Uint8Array object wrapping an ArrayBuffer
  10123. // containing output.
  10124. return new Uint8Array(output);
  10125. };
  10126. //
  10127. // 9. The encoding
  10128. //
  10129. // 9.1 utf-8
  10130. // 9.1.1 utf-8 decoder
  10131. /**
  10132. * @constructor
  10133. * @implements {Decoder}
  10134. * @param {{fatal: boolean}} options
  10135. */
  10136. function UTF8Decoder(options) {
  10137. var fatal = options.fatal;
  10138. // utf-8's decoder's has an associated utf-8 code point, utf-8
  10139. // bytes seen, and utf-8 bytes needed (all initially 0), a utf-8
  10140. // lower boundary (initially 0x80), and a utf-8 upper boundary
  10141. // (initially 0xBF).
  10142. var /** @type {number} */ utf8_code_point = 0,
  10143. /** @type {number} */ utf8_bytes_seen = 0,
  10144. /** @type {number} */ utf8_bytes_needed = 0,
  10145. /** @type {number} */ utf8_lower_boundary = 0x80,
  10146. /** @type {number} */ utf8_upper_boundary = 0xBF;
  10147. /**
  10148. * @param {Stream} stream The stream of bytes being decoded.
  10149. * @param {number} bite The next byte read from the stream.
  10150. * @return {?(number|!Array.<number>)} The next code point(s)
  10151. * decoded, or null if not enough data exists in the input
  10152. * stream to decode a complete code point.
  10153. */
  10154. this.handler = function(stream, bite) {
  10155. // 1. If byte is end-of-stream and utf-8 bytes needed is not 0,
  10156. // set utf-8 bytes needed to 0 and return error.
  10157. if (bite === end_of_stream && utf8_bytes_needed !== 0) {
  10158. utf8_bytes_needed = 0;
  10159. return decoderError(fatal);
  10160. }
  10161. // 2. If byte is end-of-stream, return finished.
  10162. if (bite === end_of_stream)
  10163. return finished;
  10164. // 3. If utf-8 bytes needed is 0, based on byte:
  10165. if (utf8_bytes_needed === 0) {
  10166. // 0x00 to 0x7F
  10167. if (inRange(bite, 0x00, 0x7F)) {
  10168. // Return a code point whose value is byte.
  10169. return bite;
  10170. }
  10171. // 0xC2 to 0xDF
  10172. else if (inRange(bite, 0xC2, 0xDF)) {
  10173. // 1. Set utf-8 bytes needed to 1.
  10174. utf8_bytes_needed = 1;
  10175. // 2. Set UTF-8 code point to byte & 0x1F.
  10176. utf8_code_point = bite & 0x1F;
  10177. }
  10178. // 0xE0 to 0xEF
  10179. else if (inRange(bite, 0xE0, 0xEF)) {
  10180. // 1. If byte is 0xE0, set utf-8 lower boundary to 0xA0.
  10181. if (bite === 0xE0)
  10182. utf8_lower_boundary = 0xA0;
  10183. // 2. If byte is 0xED, set utf-8 upper boundary to 0x9F.
  10184. if (bite === 0xED)
  10185. utf8_upper_boundary = 0x9F;
  10186. // 3. Set utf-8 bytes needed to 2.
  10187. utf8_bytes_needed = 2;
  10188. // 4. Set UTF-8 code point to byte & 0xF.
  10189. utf8_code_point = bite & 0xF;
  10190. }
  10191. // 0xF0 to 0xF4
  10192. else if (inRange(bite, 0xF0, 0xF4)) {
  10193. // 1. If byte is 0xF0, set utf-8 lower boundary to 0x90.
  10194. if (bite === 0xF0)
  10195. utf8_lower_boundary = 0x90;
  10196. // 2. If byte is 0xF4, set utf-8 upper boundary to 0x8F.
  10197. if (bite === 0xF4)
  10198. utf8_upper_boundary = 0x8F;
  10199. // 3. Set utf-8 bytes needed to 3.
  10200. utf8_bytes_needed = 3;
  10201. // 4. Set UTF-8 code point to byte & 0x7.
  10202. utf8_code_point = bite & 0x7;
  10203. }
  10204. // Otherwise
  10205. else {
  10206. // Return error.
  10207. return decoderError(fatal);
  10208. }
  10209. // Return continue.
  10210. return null;
  10211. }
  10212. // 4. If byte is not in the range utf-8 lower boundary to utf-8
  10213. // upper boundary, inclusive, run these substeps:
  10214. if (!inRange(bite, utf8_lower_boundary, utf8_upper_boundary)) {
  10215. // 1. Set utf-8 code point, utf-8 bytes needed, and utf-8
  10216. // bytes seen to 0, set utf-8 lower boundary to 0x80, and set
  10217. // utf-8 upper boundary to 0xBF.
  10218. utf8_code_point = utf8_bytes_needed = utf8_bytes_seen = 0;
  10219. utf8_lower_boundary = 0x80;
  10220. utf8_upper_boundary = 0xBF;
  10221. // 2. Prepend byte to stream.
  10222. stream.prepend(bite);
  10223. // 3. Return error.
  10224. return decoderError(fatal);
  10225. }
  10226. // 5. Set utf-8 lower boundary to 0x80 and utf-8 upper boundary
  10227. // to 0xBF.
  10228. utf8_lower_boundary = 0x80;
  10229. utf8_upper_boundary = 0xBF;
  10230. // 6. Set UTF-8 code point to (UTF-8 code point << 6) | (byte &
  10231. // 0x3F)
  10232. utf8_code_point = (utf8_code_point << 6) | (bite & 0x3F);
  10233. // 7. Increase utf-8 bytes seen by one.
  10234. utf8_bytes_seen += 1;
  10235. // 8. If utf-8 bytes seen is not equal to utf-8 bytes needed,
  10236. // continue.
  10237. if (utf8_bytes_seen !== utf8_bytes_needed)
  10238. return null;
  10239. // 9. Let code point be utf-8 code point.
  10240. var code_point = utf8_code_point;
  10241. // 10. Set utf-8 code point, utf-8 bytes needed, and utf-8 bytes
  10242. // seen to 0.
  10243. utf8_code_point = utf8_bytes_needed = utf8_bytes_seen = 0;
  10244. // 11. Return a code point whose value is code point.
  10245. return code_point;
  10246. };
  10247. }
  10248. // 9.1.2 utf-8 encoder
  10249. /**
  10250. * @constructor
  10251. * @implements {Encoder}
  10252. * @param {{fatal: boolean}} options
  10253. */
  10254. function UTF8Encoder(options) {
  10255. options.fatal;
  10256. /**
  10257. * @param {Stream} stream Input stream.
  10258. * @param {number} code_point Next code point read from the stream.
  10259. * @return {(number|!Array.<number>)} Byte(s) to emit.
  10260. */
  10261. this.handler = function(stream, code_point) {
  10262. // 1. If code point is end-of-stream, return finished.
  10263. if (code_point === end_of_stream)
  10264. return finished;
  10265. // 2. If code point is an ASCII code point, return a byte whose
  10266. // value is code point.
  10267. if (isASCIICodePoint(code_point))
  10268. return code_point;
  10269. // 3. Set count and offset based on the range code point is in:
  10270. var count, offset;
  10271. // U+0080 to U+07FF, inclusive:
  10272. if (inRange(code_point, 0x0080, 0x07FF)) {
  10273. // 1 and 0xC0
  10274. count = 1;
  10275. offset = 0xC0;
  10276. }
  10277. // U+0800 to U+FFFF, inclusive:
  10278. else if (inRange(code_point, 0x0800, 0xFFFF)) {
  10279. // 2 and 0xE0
  10280. count = 2;
  10281. offset = 0xE0;
  10282. }
  10283. // U+10000 to U+10FFFF, inclusive:
  10284. else if (inRange(code_point, 0x10000, 0x10FFFF)) {
  10285. // 3 and 0xF0
  10286. count = 3;
  10287. offset = 0xF0;
  10288. }
  10289. // 4. Let bytes be a byte sequence whose first byte is (code
  10290. // point >> (6 × count)) + offset.
  10291. var bytes = [(code_point >> (6 * count)) + offset];
  10292. // 5. Run these substeps while count is greater than 0:
  10293. while (count > 0) {
  10294. // 1. Set temp to code point >> (6 × (count − 1)).
  10295. var temp = code_point >> (6 * (count - 1));
  10296. // 2. Append to bytes 0x80 | (temp & 0x3F).
  10297. bytes.push(0x80 | (temp & 0x3F));
  10298. // 3. Decrease count by one.
  10299. count -= 1;
  10300. }
  10301. // 6. Return bytes bytes, in order.
  10302. return bytes;
  10303. };
  10304. }
  10305. /** @param {{fatal: boolean}} options */
  10306. encoders['UTF-8'] = function(options) {
  10307. return new UTF8Encoder(options);
  10308. };
  10309. /** @param {{fatal: boolean}} options */
  10310. decoders['UTF-8'] = function(options) {
  10311. return new UTF8Decoder(options);
  10312. };
  10313. //
  10314. // 10. Legacy single-byte encodings
  10315. //
  10316. // 10.1 single-byte decoder
  10317. /**
  10318. * @constructor
  10319. * @implements {Decoder}
  10320. * @param {!Array.<number>} index The encoding index.
  10321. * @param {{fatal: boolean}} options
  10322. */
  10323. function SingleByteDecoder(index, options) {
  10324. var fatal = options.fatal;
  10325. /**
  10326. * @param {Stream} stream The stream of bytes being decoded.
  10327. * @param {number} bite The next byte read from the stream.
  10328. * @return {?(number|!Array.<number>)} The next code point(s)
  10329. * decoded, or null if not enough data exists in the input
  10330. * stream to decode a complete code point.
  10331. */
  10332. this.handler = function(stream, bite) {
  10333. // 1. If byte is end-of-stream, return finished.
  10334. if (bite === end_of_stream)
  10335. return finished;
  10336. // 2. If byte is an ASCII byte, return a code point whose value
  10337. // is byte.
  10338. if (isASCIIByte(bite))
  10339. return bite;
  10340. // 3. Let code point be the index code point for byte − 0x80 in
  10341. // index single-byte.
  10342. var code_point = index[bite - 0x80];
  10343. // 4. If code point is null, return error.
  10344. if (code_point === null)
  10345. return decoderError(fatal);
  10346. // 5. Return a code point whose value is code point.
  10347. return code_point;
  10348. };
  10349. }
  10350. // 10.2 single-byte encoder
  10351. /**
  10352. * @constructor
  10353. * @implements {Encoder}
  10354. * @param {!Array.<?number>} index The encoding index.
  10355. * @param {{fatal: boolean}} options
  10356. */
  10357. function SingleByteEncoder(index, options) {
  10358. options.fatal;
  10359. /**
  10360. * @param {Stream} stream Input stream.
  10361. * @param {number} code_point Next code point read from the stream.
  10362. * @return {(number|!Array.<number>)} Byte(s) to emit.
  10363. */
  10364. this.handler = function(stream, code_point) {
  10365. // 1. If code point is end-of-stream, return finished.
  10366. if (code_point === end_of_stream)
  10367. return finished;
  10368. // 2. If code point is an ASCII code point, return a byte whose
  10369. // value is code point.
  10370. if (isASCIICodePoint(code_point))
  10371. return code_point;
  10372. // 3. Let pointer be the index pointer for code point in index
  10373. // single-byte.
  10374. var pointer = indexPointerFor(code_point, index);
  10375. // 4. If pointer is null, return error with code point.
  10376. if (pointer === null)
  10377. encoderError(code_point);
  10378. // 5. Return a byte whose value is pointer + 0x80.
  10379. return pointer + 0x80;
  10380. };
  10381. }
  10382. (function() {
  10383. if (!('encoding-indexes' in global))
  10384. return;
  10385. encodings.forEach(function(category) {
  10386. if (category.heading !== 'Legacy single-byte encodings')
  10387. return;
  10388. category.encodings.forEach(function(encoding) {
  10389. var name = encoding.name;
  10390. var idx = index(name.toLowerCase());
  10391. /** @param {{fatal: boolean}} options */
  10392. decoders[name] = function(options) {
  10393. return new SingleByteDecoder(idx, options);
  10394. };
  10395. /** @param {{fatal: boolean}} options */
  10396. encoders[name] = function(options) {
  10397. return new SingleByteEncoder(idx, options);
  10398. };
  10399. });
  10400. });
  10401. }());
  10402. //
  10403. // 11. Legacy multi-byte Chinese (simplified) encodings
  10404. //
  10405. // 11.1 gbk
  10406. // 11.1.1 gbk decoder
  10407. // gbk's decoder is gb18030's decoder.
  10408. /** @param {{fatal: boolean}} options */
  10409. decoders['GBK'] = function(options) {
  10410. return new GB18030Decoder(options);
  10411. };
  10412. // 11.1.2 gbk encoder
  10413. // gbk's encoder is gb18030's encoder with its gbk flag set.
  10414. /** @param {{fatal: boolean}} options */
  10415. encoders['GBK'] = function(options) {
  10416. return new GB18030Encoder(options, true);
  10417. };
  10418. // 11.2 gb18030
  10419. // 11.2.1 gb18030 decoder
  10420. /**
  10421. * @constructor
  10422. * @implements {Decoder}
  10423. * @param {{fatal: boolean}} options
  10424. */
  10425. function GB18030Decoder(options) {
  10426. var fatal = options.fatal;
  10427. // gb18030's decoder has an associated gb18030 first, gb18030
  10428. // second, and gb18030 third (all initially 0x00).
  10429. var /** @type {number} */ gb18030_first = 0x00,
  10430. /** @type {number} */ gb18030_second = 0x00,
  10431. /** @type {number} */ gb18030_third = 0x00;
  10432. /**
  10433. * @param {Stream} stream The stream of bytes being decoded.
  10434. * @param {number} bite The next byte read from the stream.
  10435. * @return {?(number|!Array.<number>)} The next code point(s)
  10436. * decoded, or null if not enough data exists in the input
  10437. * stream to decode a complete code point.
  10438. */
  10439. this.handler = function(stream, bite) {
  10440. // 1. If byte is end-of-stream and gb18030 first, gb18030
  10441. // second, and gb18030 third are 0x00, return finished.
  10442. if (bite === end_of_stream && gb18030_first === 0x00 &&
  10443. gb18030_second === 0x00 && gb18030_third === 0x00) {
  10444. return finished;
  10445. }
  10446. // 2. If byte is end-of-stream, and gb18030 first, gb18030
  10447. // second, or gb18030 third is not 0x00, set gb18030 first,
  10448. // gb18030 second, and gb18030 third to 0x00, and return error.
  10449. if (bite === end_of_stream &&
  10450. (gb18030_first !== 0x00 || gb18030_second !== 0x00 ||
  10451. gb18030_third !== 0x00)) {
  10452. gb18030_first = 0x00;
  10453. gb18030_second = 0x00;
  10454. gb18030_third = 0x00;
  10455. decoderError(fatal);
  10456. }
  10457. var code_point;
  10458. // 3. If gb18030 third is not 0x00, run these substeps:
  10459. if (gb18030_third !== 0x00) {
  10460. // 1. Let code point be null.
  10461. code_point = null;
  10462. // 2. If byte is in the range 0x30 to 0x39, inclusive, set
  10463. // code point to the index gb18030 ranges code point for
  10464. // (((gb18030 first − 0x81) × 10 + gb18030 second − 0x30) ×
  10465. // 126 + gb18030 third − 0x81) × 10 + byte − 0x30.
  10466. if (inRange(bite, 0x30, 0x39)) {
  10467. code_point = indexGB18030RangesCodePointFor(
  10468. (((gb18030_first - 0x81) * 10 + gb18030_second - 0x30) * 126 +
  10469. gb18030_third - 0x81) * 10 + bite - 0x30);
  10470. }
  10471. // 3. Let buffer be a byte sequence consisting of gb18030
  10472. // second, gb18030 third, and byte, in order.
  10473. var buffer = [gb18030_second, gb18030_third, bite];
  10474. // 4. Set gb18030 first, gb18030 second, and gb18030 third to
  10475. // 0x00.
  10476. gb18030_first = 0x00;
  10477. gb18030_second = 0x00;
  10478. gb18030_third = 0x00;
  10479. // 5. If code point is null, prepend buffer to stream and
  10480. // return error.
  10481. if (code_point === null) {
  10482. stream.prepend(buffer);
  10483. return decoderError(fatal);
  10484. }
  10485. // 6. Return a code point whose value is code point.
  10486. return code_point;
  10487. }
  10488. // 4. If gb18030 second is not 0x00, run these substeps:
  10489. if (gb18030_second !== 0x00) {
  10490. // 1. If byte is in the range 0x81 to 0xFE, inclusive, set
  10491. // gb18030 third to byte and return continue.
  10492. if (inRange(bite, 0x81, 0xFE)) {
  10493. gb18030_third = bite;
  10494. return null;
  10495. }
  10496. // 2. Prepend gb18030 second followed by byte to stream, set
  10497. // gb18030 first and gb18030 second to 0x00, and return error.
  10498. stream.prepend([gb18030_second, bite]);
  10499. gb18030_first = 0x00;
  10500. gb18030_second = 0x00;
  10501. return decoderError(fatal);
  10502. }
  10503. // 5. If gb18030 first is not 0x00, run these substeps:
  10504. if (gb18030_first !== 0x00) {
  10505. // 1. If byte is in the range 0x30 to 0x39, inclusive, set
  10506. // gb18030 second to byte and return continue.
  10507. if (inRange(bite, 0x30, 0x39)) {
  10508. gb18030_second = bite;
  10509. return null;
  10510. }
  10511. // 2. Let lead be gb18030 first, let pointer be null, and set
  10512. // gb18030 first to 0x00.
  10513. var lead = gb18030_first;
  10514. var pointer = null;
  10515. gb18030_first = 0x00;
  10516. // 3. Let offset be 0x40 if byte is less than 0x7F and 0x41
  10517. // otherwise.
  10518. var offset = bite < 0x7F ? 0x40 : 0x41;
  10519. // 4. If byte is in the range 0x40 to 0x7E, inclusive, or 0x80
  10520. // to 0xFE, inclusive, set pointer to (lead − 0x81) × 190 +
  10521. // (byte − offset).
  10522. if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0x80, 0xFE))
  10523. pointer = (lead - 0x81) * 190 + (bite - offset);
  10524. // 5. Let code point be null if pointer is null and the index
  10525. // code point for pointer in index gb18030 otherwise.
  10526. code_point = pointer === null ? null :
  10527. indexCodePointFor(pointer, index('gb18030'));
  10528. // 6. If code point is null and byte is an ASCII byte, prepend
  10529. // byte to stream.
  10530. if (code_point === null && isASCIIByte(bite))
  10531. stream.prepend(bite);
  10532. // 7. If code point is null, return error.
  10533. if (code_point === null)
  10534. return decoderError(fatal);
  10535. // 8. Return a code point whose value is code point.
  10536. return code_point;
  10537. }
  10538. // 6. If byte is an ASCII byte, return a code point whose value
  10539. // is byte.
  10540. if (isASCIIByte(bite))
  10541. return bite;
  10542. // 7. If byte is 0x80, return code point U+20AC.
  10543. if (bite === 0x80)
  10544. return 0x20AC;
  10545. // 8. If byte is in the range 0x81 to 0xFE, inclusive, set
  10546. // gb18030 first to byte and return continue.
  10547. if (inRange(bite, 0x81, 0xFE)) {
  10548. gb18030_first = bite;
  10549. return null;
  10550. }
  10551. // 9. Return error.
  10552. return decoderError(fatal);
  10553. };
  10554. }
  10555. // 11.2.2 gb18030 encoder
  10556. /**
  10557. * @constructor
  10558. * @implements {Encoder}
  10559. * @param {{fatal: boolean}} options
  10560. * @param {boolean=} gbk_flag
  10561. */
  10562. function GB18030Encoder(options, gbk_flag) {
  10563. options.fatal;
  10564. // gb18030's decoder has an associated gbk flag (initially unset).
  10565. /**
  10566. * @param {Stream} stream Input stream.
  10567. * @param {number} code_point Next code point read from the stream.
  10568. * @return {(number|!Array.<number>)} Byte(s) to emit.
  10569. */
  10570. this.handler = function(stream, code_point) {
  10571. // 1. If code point is end-of-stream, return finished.
  10572. if (code_point === end_of_stream)
  10573. return finished;
  10574. // 2. If code point is an ASCII code point, return a byte whose
  10575. // value is code point.
  10576. if (isASCIICodePoint(code_point))
  10577. return code_point;
  10578. // 3. If code point is U+E5E5, return error with code point.
  10579. if (code_point === 0xE5E5)
  10580. return encoderError(code_point);
  10581. // 4. If the gbk flag is set and code point is U+20AC, return
  10582. // byte 0x80.
  10583. if (gbk_flag && code_point === 0x20AC)
  10584. return 0x80;
  10585. // 5. Let pointer be the index pointer for code point in index
  10586. // gb18030.
  10587. var pointer = indexPointerFor(code_point, index('gb18030'));
  10588. // 6. If pointer is not null, run these substeps:
  10589. if (pointer !== null) {
  10590. // 1. Let lead be floor(pointer / 190) + 0x81.
  10591. var lead = floor(pointer / 190) + 0x81;
  10592. // 2. Let trail be pointer % 190.
  10593. var trail = pointer % 190;
  10594. // 3. Let offset be 0x40 if trail is less than 0x3F and 0x41 otherwise.
  10595. var offset = trail < 0x3F ? 0x40 : 0x41;
  10596. // 4. Return two bytes whose values are lead and trail + offset.
  10597. return [lead, trail + offset];
  10598. }
  10599. // 7. If gbk flag is set, return error with code point.
  10600. if (gbk_flag)
  10601. return encoderError(code_point);
  10602. // 8. Set pointer to the index gb18030 ranges pointer for code
  10603. // point.
  10604. pointer = indexGB18030RangesPointerFor(code_point);
  10605. // 9. Let byte1 be floor(pointer / 10 / 126 / 10).
  10606. var byte1 = floor(pointer / 10 / 126 / 10);
  10607. // 10. Set pointer to pointer − byte1 × 10 × 126 × 10.
  10608. pointer = pointer - byte1 * 10 * 126 * 10;
  10609. // 11. Let byte2 be floor(pointer / 10 / 126).
  10610. var byte2 = floor(pointer / 10 / 126);
  10611. // 12. Set pointer to pointer − byte2 × 10 × 126.
  10612. pointer = pointer - byte2 * 10 * 126;
  10613. // 13. Let byte3 be floor(pointer / 10).
  10614. var byte3 = floor(pointer / 10);
  10615. // 14. Let byte4 be pointer − byte3 × 10.
  10616. var byte4 = pointer - byte3 * 10;
  10617. // 15. Return four bytes whose values are byte1 + 0x81, byte2 +
  10618. // 0x30, byte3 + 0x81, byte4 + 0x30.
  10619. return [byte1 + 0x81,
  10620. byte2 + 0x30,
  10621. byte3 + 0x81,
  10622. byte4 + 0x30];
  10623. };
  10624. }
  10625. /** @param {{fatal: boolean}} options */
  10626. encoders['gb18030'] = function(options) {
  10627. return new GB18030Encoder(options);
  10628. };
  10629. /** @param {{fatal: boolean}} options */
  10630. decoders['gb18030'] = function(options) {
  10631. return new GB18030Decoder(options);
  10632. };
  10633. //
  10634. // 12. Legacy multi-byte Chinese (traditional) encodings
  10635. //
  10636. // 12.1 Big5
  10637. // 12.1.1 Big5 decoder
  10638. /**
  10639. * @constructor
  10640. * @implements {Decoder}
  10641. * @param {{fatal: boolean}} options
  10642. */
  10643. function Big5Decoder(options) {
  10644. var fatal = options.fatal;
  10645. // Big5's decoder has an associated Big5 lead (initially 0x00).
  10646. var /** @type {number} */ Big5_lead = 0x00;
  10647. /**
  10648. * @param {Stream} stream The stream of bytes being decoded.
  10649. * @param {number} bite The next byte read from the stream.
  10650. * @return {?(number|!Array.<number>)} The next code point(s)
  10651. * decoded, or null if not enough data exists in the input
  10652. * stream to decode a complete code point.
  10653. */
  10654. this.handler = function(stream, bite) {
  10655. // 1. If byte is end-of-stream and Big5 lead is not 0x00, set
  10656. // Big5 lead to 0x00 and return error.
  10657. if (bite === end_of_stream && Big5_lead !== 0x00) {
  10658. Big5_lead = 0x00;
  10659. return decoderError(fatal);
  10660. }
  10661. // 2. If byte is end-of-stream and Big5 lead is 0x00, return
  10662. // finished.
  10663. if (bite === end_of_stream && Big5_lead === 0x00)
  10664. return finished;
  10665. // 3. If Big5 lead is not 0x00, let lead be Big5 lead, let
  10666. // pointer be null, set Big5 lead to 0x00, and then run these
  10667. // substeps:
  10668. if (Big5_lead !== 0x00) {
  10669. var lead = Big5_lead;
  10670. var pointer = null;
  10671. Big5_lead = 0x00;
  10672. // 1. Let offset be 0x40 if byte is less than 0x7F and 0x62
  10673. // otherwise.
  10674. var offset = bite < 0x7F ? 0x40 : 0x62;
  10675. // 2. If byte is in the range 0x40 to 0x7E, inclusive, or 0xA1
  10676. // to 0xFE, inclusive, set pointer to (lead − 0x81) × 157 +
  10677. // (byte − offset).
  10678. if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0xA1, 0xFE))
  10679. pointer = (lead - 0x81) * 157 + (bite - offset);
  10680. // 3. If there is a row in the table below whose first column
  10681. // is pointer, return the two code points listed in its second
  10682. // column
  10683. // Pointer | Code points
  10684. // --------+--------------
  10685. // 1133 | U+00CA U+0304
  10686. // 1135 | U+00CA U+030C
  10687. // 1164 | U+00EA U+0304
  10688. // 1166 | U+00EA U+030C
  10689. switch (pointer) {
  10690. case 1133: return [0x00CA, 0x0304];
  10691. case 1135: return [0x00CA, 0x030C];
  10692. case 1164: return [0x00EA, 0x0304];
  10693. case 1166: return [0x00EA, 0x030C];
  10694. }
  10695. // 4. Let code point be null if pointer is null and the index
  10696. // code point for pointer in index Big5 otherwise.
  10697. var code_point = (pointer === null) ? null :
  10698. indexCodePointFor(pointer, index('big5'));
  10699. // 5. If code point is null and byte is an ASCII byte, prepend
  10700. // byte to stream.
  10701. if (code_point === null && isASCIIByte(bite))
  10702. stream.prepend(bite);
  10703. // 6. If code point is null, return error.
  10704. if (code_point === null)
  10705. return decoderError(fatal);
  10706. // 7. Return a code point whose value is code point.
  10707. return code_point;
  10708. }
  10709. // 4. If byte is an ASCII byte, return a code point whose value
  10710. // is byte.
  10711. if (isASCIIByte(bite))
  10712. return bite;
  10713. // 5. If byte is in the range 0x81 to 0xFE, inclusive, set Big5
  10714. // lead to byte and return continue.
  10715. if (inRange(bite, 0x81, 0xFE)) {
  10716. Big5_lead = bite;
  10717. return null;
  10718. }
  10719. // 6. Return error.
  10720. return decoderError(fatal);
  10721. };
  10722. }
  10723. // 12.1.2 Big5 encoder
  10724. /**
  10725. * @constructor
  10726. * @implements {Encoder}
  10727. * @param {{fatal: boolean}} options
  10728. */
  10729. function Big5Encoder(options) {
  10730. options.fatal;
  10731. /**
  10732. * @param {Stream} stream Input stream.
  10733. * @param {number} code_point Next code point read from the stream.
  10734. * @return {(number|!Array.<number>)} Byte(s) to emit.
  10735. */
  10736. this.handler = function(stream, code_point) {
  10737. // 1. If code point is end-of-stream, return finished.
  10738. if (code_point === end_of_stream)
  10739. return finished;
  10740. // 2. If code point is an ASCII code point, return a byte whose
  10741. // value is code point.
  10742. if (isASCIICodePoint(code_point))
  10743. return code_point;
  10744. // 3. Let pointer be the index Big5 pointer for code point.
  10745. var pointer = indexBig5PointerFor(code_point);
  10746. // 4. If pointer is null, return error with code point.
  10747. if (pointer === null)
  10748. return encoderError(code_point);
  10749. // 5. Let lead be floor(pointer / 157) + 0x81.
  10750. var lead = floor(pointer / 157) + 0x81;
  10751. // 6. If lead is less than 0xA1, return error with code point.
  10752. if (lead < 0xA1)
  10753. return encoderError(code_point);
  10754. // 7. Let trail be pointer % 157.
  10755. var trail = pointer % 157;
  10756. // 8. Let offset be 0x40 if trail is less than 0x3F and 0x62
  10757. // otherwise.
  10758. var offset = trail < 0x3F ? 0x40 : 0x62;
  10759. // Return two bytes whose values are lead and trail + offset.
  10760. return [lead, trail + offset];
  10761. };
  10762. }
  10763. /** @param {{fatal: boolean}} options */
  10764. encoders['Big5'] = function(options) {
  10765. return new Big5Encoder(options);
  10766. };
  10767. /** @param {{fatal: boolean}} options */
  10768. decoders['Big5'] = function(options) {
  10769. return new Big5Decoder(options);
  10770. };
  10771. //
  10772. // 13. Legacy multi-byte Japanese encodings
  10773. //
  10774. // 13.1 euc-jp
  10775. // 13.1.1 euc-jp decoder
  10776. /**
  10777. * @constructor
  10778. * @implements {Decoder}
  10779. * @param {{fatal: boolean}} options
  10780. */
  10781. function EUCJPDecoder(options) {
  10782. var fatal = options.fatal;
  10783. // euc-jp's decoder has an associated euc-jp jis0212 flag
  10784. // (initially unset) and euc-jp lead (initially 0x00).
  10785. var /** @type {boolean} */ eucjp_jis0212_flag = false,
  10786. /** @type {number} */ eucjp_lead = 0x00;
  10787. /**
  10788. * @param {Stream} stream The stream of bytes being decoded.
  10789. * @param {number} bite The next byte read from the stream.
  10790. * @return {?(number|!Array.<number>)} The next code point(s)
  10791. * decoded, or null if not enough data exists in the input
  10792. * stream to decode a complete code point.
  10793. */
  10794. this.handler = function(stream, bite) {
  10795. // 1. If byte is end-of-stream and euc-jp lead is not 0x00, set
  10796. // euc-jp lead to 0x00, and return error.
  10797. if (bite === end_of_stream && eucjp_lead !== 0x00) {
  10798. eucjp_lead = 0x00;
  10799. return decoderError(fatal);
  10800. }
  10801. // 2. If byte is end-of-stream and euc-jp lead is 0x00, return
  10802. // finished.
  10803. if (bite === end_of_stream && eucjp_lead === 0x00)
  10804. return finished;
  10805. // 3. If euc-jp lead is 0x8E and byte is in the range 0xA1 to
  10806. // 0xDF, inclusive, set euc-jp lead to 0x00 and return a code
  10807. // point whose value is 0xFF61 − 0xA1 + byte.
  10808. if (eucjp_lead === 0x8E && inRange(bite, 0xA1, 0xDF)) {
  10809. eucjp_lead = 0x00;
  10810. return 0xFF61 - 0xA1 + bite;
  10811. }
  10812. // 4. If euc-jp lead is 0x8F and byte is in the range 0xA1 to
  10813. // 0xFE, inclusive, set the euc-jp jis0212 flag, set euc-jp lead
  10814. // to byte, and return continue.
  10815. if (eucjp_lead === 0x8F && inRange(bite, 0xA1, 0xFE)) {
  10816. eucjp_jis0212_flag = true;
  10817. eucjp_lead = bite;
  10818. return null;
  10819. }
  10820. // 5. If euc-jp lead is not 0x00, let lead be euc-jp lead, set
  10821. // euc-jp lead to 0x00, and run these substeps:
  10822. if (eucjp_lead !== 0x00) {
  10823. var lead = eucjp_lead;
  10824. eucjp_lead = 0x00;
  10825. // 1. Let code point be null.
  10826. var code_point = null;
  10827. // 2. If lead and byte are both in the range 0xA1 to 0xFE,
  10828. // inclusive, set code point to the index code point for (lead
  10829. // − 0xA1) × 94 + byte − 0xA1 in index jis0208 if the euc-jp
  10830. // jis0212 flag is unset and in index jis0212 otherwise.
  10831. if (inRange(lead, 0xA1, 0xFE) && inRange(bite, 0xA1, 0xFE)) {
  10832. code_point = indexCodePointFor(
  10833. (lead - 0xA1) * 94 + (bite - 0xA1),
  10834. index(!eucjp_jis0212_flag ? 'jis0208' : 'jis0212'));
  10835. }
  10836. // 3. Unset the euc-jp jis0212 flag.
  10837. eucjp_jis0212_flag = false;
  10838. // 4. If byte is not in the range 0xA1 to 0xFE, inclusive,
  10839. // prepend byte to stream.
  10840. if (!inRange(bite, 0xA1, 0xFE))
  10841. stream.prepend(bite);
  10842. // 5. If code point is null, return error.
  10843. if (code_point === null)
  10844. return decoderError(fatal);
  10845. // 6. Return a code point whose value is code point.
  10846. return code_point;
  10847. }
  10848. // 6. If byte is an ASCII byte, return a code point whose value
  10849. // is byte.
  10850. if (isASCIIByte(bite))
  10851. return bite;
  10852. // 7. If byte is 0x8E, 0x8F, or in the range 0xA1 to 0xFE,
  10853. // inclusive, set euc-jp lead to byte and return continue.
  10854. if (bite === 0x8E || bite === 0x8F || inRange(bite, 0xA1, 0xFE)) {
  10855. eucjp_lead = bite;
  10856. return null;
  10857. }
  10858. // 8. Return error.
  10859. return decoderError(fatal);
  10860. };
  10861. }
  10862. // 13.1.2 euc-jp encoder
  10863. /**
  10864. * @constructor
  10865. * @implements {Encoder}
  10866. * @param {{fatal: boolean}} options
  10867. */
  10868. function EUCJPEncoder(options) {
  10869. options.fatal;
  10870. /**
  10871. * @param {Stream} stream Input stream.
  10872. * @param {number} code_point Next code point read from the stream.
  10873. * @return {(number|!Array.<number>)} Byte(s) to emit.
  10874. */
  10875. this.handler = function(stream, code_point) {
  10876. // 1. If code point is end-of-stream, return finished.
  10877. if (code_point === end_of_stream)
  10878. return finished;
  10879. // 2. If code point is an ASCII code point, return a byte whose
  10880. // value is code point.
  10881. if (isASCIICodePoint(code_point))
  10882. return code_point;
  10883. // 3. If code point is U+00A5, return byte 0x5C.
  10884. if (code_point === 0x00A5)
  10885. return 0x5C;
  10886. // 4. If code point is U+203E, return byte 0x7E.
  10887. if (code_point === 0x203E)
  10888. return 0x7E;
  10889. // 5. If code point is in the range U+FF61 to U+FF9F, inclusive,
  10890. // return two bytes whose values are 0x8E and code point −
  10891. // 0xFF61 + 0xA1.
  10892. if (inRange(code_point, 0xFF61, 0xFF9F))
  10893. return [0x8E, code_point - 0xFF61 + 0xA1];
  10894. // 6. If code point is U+2212, set it to U+FF0D.
  10895. if (code_point === 0x2212)
  10896. code_point = 0xFF0D;
  10897. // 7. Let pointer be the index pointer for code point in index
  10898. // jis0208.
  10899. var pointer = indexPointerFor(code_point, index('jis0208'));
  10900. // 8. If pointer is null, return error with code point.
  10901. if (pointer === null)
  10902. return encoderError(code_point);
  10903. // 9. Let lead be floor(pointer / 94) + 0xA1.
  10904. var lead = floor(pointer / 94) + 0xA1;
  10905. // 10. Let trail be pointer % 94 + 0xA1.
  10906. var trail = pointer % 94 + 0xA1;
  10907. // 11. Return two bytes whose values are lead and trail.
  10908. return [lead, trail];
  10909. };
  10910. }
  10911. /** @param {{fatal: boolean}} options */
  10912. encoders['EUC-JP'] = function(options) {
  10913. return new EUCJPEncoder(options);
  10914. };
  10915. /** @param {{fatal: boolean}} options */
  10916. decoders['EUC-JP'] = function(options) {
  10917. return new EUCJPDecoder(options);
  10918. };
  10919. // 13.2 iso-2022-jp
  10920. // 13.2.1 iso-2022-jp decoder
  10921. /**
  10922. * @constructor
  10923. * @implements {Decoder}
  10924. * @param {{fatal: boolean}} options
  10925. */
  10926. function ISO2022JPDecoder(options) {
  10927. var fatal = options.fatal;
  10928. /** @enum */
  10929. var states = {
  10930. ASCII: 0,
  10931. Roman: 1,
  10932. Katakana: 2,
  10933. LeadByte: 3,
  10934. TrailByte: 4,
  10935. EscapeStart: 5,
  10936. Escape: 6
  10937. };
  10938. // iso-2022-jp's decoder has an associated iso-2022-jp decoder
  10939. // state (initially ASCII), iso-2022-jp decoder output state
  10940. // (initially ASCII), iso-2022-jp lead (initially 0x00), and
  10941. // iso-2022-jp output flag (initially unset).
  10942. var /** @type {number} */ iso2022jp_decoder_state = states.ASCII,
  10943. /** @type {number} */ iso2022jp_decoder_output_state = states.ASCII,
  10944. /** @type {number} */ iso2022jp_lead = 0x00,
  10945. /** @type {boolean} */ iso2022jp_output_flag = false;
  10946. /**
  10947. * @param {Stream} stream The stream of bytes being decoded.
  10948. * @param {number} bite The next byte read from the stream.
  10949. * @return {?(number|!Array.<number>)} The next code point(s)
  10950. * decoded, or null if not enough data exists in the input
  10951. * stream to decode a complete code point.
  10952. */
  10953. this.handler = function(stream, bite) {
  10954. // switching on iso-2022-jp decoder state:
  10955. switch (iso2022jp_decoder_state) {
  10956. default:
  10957. case states.ASCII:
  10958. // ASCII
  10959. // Based on byte:
  10960. // 0x1B
  10961. if (bite === 0x1B) {
  10962. // Set iso-2022-jp decoder state to escape start and return
  10963. // continue.
  10964. iso2022jp_decoder_state = states.EscapeStart;
  10965. return null;
  10966. }
  10967. // 0x00 to 0x7F, excluding 0x0E, 0x0F, and 0x1B
  10968. if (inRange(bite, 0x00, 0x7F) && bite !== 0x0E
  10969. && bite !== 0x0F && bite !== 0x1B) {
  10970. // Unset the iso-2022-jp output flag and return a code point
  10971. // whose value is byte.
  10972. iso2022jp_output_flag = false;
  10973. return bite;
  10974. }
  10975. // end-of-stream
  10976. if (bite === end_of_stream) {
  10977. // Return finished.
  10978. return finished;
  10979. }
  10980. // Otherwise
  10981. // Unset the iso-2022-jp output flag and return error.
  10982. iso2022jp_output_flag = false;
  10983. return decoderError(fatal);
  10984. case states.Roman:
  10985. // Roman
  10986. // Based on byte:
  10987. // 0x1B
  10988. if (bite === 0x1B) {
  10989. // Set iso-2022-jp decoder state to escape start and return
  10990. // continue.
  10991. iso2022jp_decoder_state = states.EscapeStart;
  10992. return null;
  10993. }
  10994. // 0x5C
  10995. if (bite === 0x5C) {
  10996. // Unset the iso-2022-jp output flag and return code point
  10997. // U+00A5.
  10998. iso2022jp_output_flag = false;
  10999. return 0x00A5;
  11000. }
  11001. // 0x7E
  11002. if (bite === 0x7E) {
  11003. // Unset the iso-2022-jp output flag and return code point
  11004. // U+203E.
  11005. iso2022jp_output_flag = false;
  11006. return 0x203E;
  11007. }
  11008. // 0x00 to 0x7F, excluding 0x0E, 0x0F, 0x1B, 0x5C, and 0x7E
  11009. if (inRange(bite, 0x00, 0x7F) && bite !== 0x0E && bite !== 0x0F
  11010. && bite !== 0x1B && bite !== 0x5C && bite !== 0x7E) {
  11011. // Unset the iso-2022-jp output flag and return a code point
  11012. // whose value is byte.
  11013. iso2022jp_output_flag = false;
  11014. return bite;
  11015. }
  11016. // end-of-stream
  11017. if (bite === end_of_stream) {
  11018. // Return finished.
  11019. return finished;
  11020. }
  11021. // Otherwise
  11022. // Unset the iso-2022-jp output flag and return error.
  11023. iso2022jp_output_flag = false;
  11024. return decoderError(fatal);
  11025. case states.Katakana:
  11026. // Katakana
  11027. // Based on byte:
  11028. // 0x1B
  11029. if (bite === 0x1B) {
  11030. // Set iso-2022-jp decoder state to escape start and return
  11031. // continue.
  11032. iso2022jp_decoder_state = states.EscapeStart;
  11033. return null;
  11034. }
  11035. // 0x21 to 0x5F
  11036. if (inRange(bite, 0x21, 0x5F)) {
  11037. // Unset the iso-2022-jp output flag and return a code point
  11038. // whose value is 0xFF61 − 0x21 + byte.
  11039. iso2022jp_output_flag = false;
  11040. return 0xFF61 - 0x21 + bite;
  11041. }
  11042. // end-of-stream
  11043. if (bite === end_of_stream) {
  11044. // Return finished.
  11045. return finished;
  11046. }
  11047. // Otherwise
  11048. // Unset the iso-2022-jp output flag and return error.
  11049. iso2022jp_output_flag = false;
  11050. return decoderError(fatal);
  11051. case states.LeadByte:
  11052. // Lead byte
  11053. // Based on byte:
  11054. // 0x1B
  11055. if (bite === 0x1B) {
  11056. // Set iso-2022-jp decoder state to escape start and return
  11057. // continue.
  11058. iso2022jp_decoder_state = states.EscapeStart;
  11059. return null;
  11060. }
  11061. // 0x21 to 0x7E
  11062. if (inRange(bite, 0x21, 0x7E)) {
  11063. // Unset the iso-2022-jp output flag, set iso-2022-jp lead
  11064. // to byte, iso-2022-jp decoder state to trail byte, and
  11065. // return continue.
  11066. iso2022jp_output_flag = false;
  11067. iso2022jp_lead = bite;
  11068. iso2022jp_decoder_state = states.TrailByte;
  11069. return null;
  11070. }
  11071. // end-of-stream
  11072. if (bite === end_of_stream) {
  11073. // Return finished.
  11074. return finished;
  11075. }
  11076. // Otherwise
  11077. // Unset the iso-2022-jp output flag and return error.
  11078. iso2022jp_output_flag = false;
  11079. return decoderError(fatal);
  11080. case states.TrailByte:
  11081. // Trail byte
  11082. // Based on byte:
  11083. // 0x1B
  11084. if (bite === 0x1B) {
  11085. // Set iso-2022-jp decoder state to escape start and return
  11086. // continue.
  11087. iso2022jp_decoder_state = states.EscapeStart;
  11088. return decoderError(fatal);
  11089. }
  11090. // 0x21 to 0x7E
  11091. if (inRange(bite, 0x21, 0x7E)) {
  11092. // 1. Set the iso-2022-jp decoder state to lead byte.
  11093. iso2022jp_decoder_state = states.LeadByte;
  11094. // 2. Let pointer be (iso-2022-jp lead − 0x21) × 94 + byte − 0x21.
  11095. var pointer = (iso2022jp_lead - 0x21) * 94 + bite - 0x21;
  11096. // 3. Let code point be the index code point for pointer in
  11097. // index jis0208.
  11098. var code_point = indexCodePointFor(pointer, index('jis0208'));
  11099. // 4. If code point is null, return error.
  11100. if (code_point === null)
  11101. return decoderError(fatal);
  11102. // 5. Return a code point whose value is code point.
  11103. return code_point;
  11104. }
  11105. // end-of-stream
  11106. if (bite === end_of_stream) {
  11107. // Set the iso-2022-jp decoder state to lead byte, prepend
  11108. // byte to stream, and return error.
  11109. iso2022jp_decoder_state = states.LeadByte;
  11110. stream.prepend(bite);
  11111. return decoderError(fatal);
  11112. }
  11113. // Otherwise
  11114. // Set iso-2022-jp decoder state to lead byte and return
  11115. // error.
  11116. iso2022jp_decoder_state = states.LeadByte;
  11117. return decoderError(fatal);
  11118. case states.EscapeStart:
  11119. // Escape start
  11120. // 1. If byte is either 0x24 or 0x28, set iso-2022-jp lead to
  11121. // byte, iso-2022-jp decoder state to escape, and return
  11122. // continue.
  11123. if (bite === 0x24 || bite === 0x28) {
  11124. iso2022jp_lead = bite;
  11125. iso2022jp_decoder_state = states.Escape;
  11126. return null;
  11127. }
  11128. // 2. Prepend byte to stream.
  11129. stream.prepend(bite);
  11130. // 3. Unset the iso-2022-jp output flag, set iso-2022-jp
  11131. // decoder state to iso-2022-jp decoder output state, and
  11132. // return error.
  11133. iso2022jp_output_flag = false;
  11134. iso2022jp_decoder_state = iso2022jp_decoder_output_state;
  11135. return decoderError(fatal);
  11136. case states.Escape:
  11137. // Escape
  11138. // 1. Let lead be iso-2022-jp lead and set iso-2022-jp lead to
  11139. // 0x00.
  11140. var lead = iso2022jp_lead;
  11141. iso2022jp_lead = 0x00;
  11142. // 2. Let state be null.
  11143. var state = null;
  11144. // 3. If lead is 0x28 and byte is 0x42, set state to ASCII.
  11145. if (lead === 0x28 && bite === 0x42)
  11146. state = states.ASCII;
  11147. // 4. If lead is 0x28 and byte is 0x4A, set state to Roman.
  11148. if (lead === 0x28 && bite === 0x4A)
  11149. state = states.Roman;
  11150. // 5. If lead is 0x28 and byte is 0x49, set state to Katakana.
  11151. if (lead === 0x28 && bite === 0x49)
  11152. state = states.Katakana;
  11153. // 6. If lead is 0x24 and byte is either 0x40 or 0x42, set
  11154. // state to lead byte.
  11155. if (lead === 0x24 && (bite === 0x40 || bite === 0x42))
  11156. state = states.LeadByte;
  11157. // 7. If state is non-null, run these substeps:
  11158. if (state !== null) {
  11159. // 1. Set iso-2022-jp decoder state and iso-2022-jp decoder
  11160. // output state to states.
  11161. iso2022jp_decoder_state = iso2022jp_decoder_state = state;
  11162. // 2. Let output flag be the iso-2022-jp output flag.
  11163. var output_flag = iso2022jp_output_flag;
  11164. // 3. Set the iso-2022-jp output flag.
  11165. iso2022jp_output_flag = true;
  11166. // 4. Return continue, if output flag is unset, and error
  11167. // otherwise.
  11168. return !output_flag ? null : decoderError(fatal);
  11169. }
  11170. // 8. Prepend lead and byte to stream.
  11171. stream.prepend([lead, bite]);
  11172. // 9. Unset the iso-2022-jp output flag, set iso-2022-jp
  11173. // decoder state to iso-2022-jp decoder output state and
  11174. // return error.
  11175. iso2022jp_output_flag = false;
  11176. iso2022jp_decoder_state = iso2022jp_decoder_output_state;
  11177. return decoderError(fatal);
  11178. }
  11179. };
  11180. }
  11181. // 13.2.2 iso-2022-jp encoder
  11182. /**
  11183. * @constructor
  11184. * @implements {Encoder}
  11185. * @param {{fatal: boolean}} options
  11186. */
  11187. function ISO2022JPEncoder(options) {
  11188. options.fatal;
  11189. // iso-2022-jp's encoder has an associated iso-2022-jp encoder
  11190. // state which is one of ASCII, Roman, and jis0208 (initially
  11191. // ASCII).
  11192. /** @enum */
  11193. var states = {
  11194. ASCII: 0,
  11195. Roman: 1,
  11196. jis0208: 2
  11197. };
  11198. var /** @type {number} */ iso2022jp_state = states.ASCII;
  11199. /**
  11200. * @param {Stream} stream Input stream.
  11201. * @param {number} code_point Next code point read from the stream.
  11202. * @return {(number|!Array.<number>)} Byte(s) to emit.
  11203. */
  11204. this.handler = function(stream, code_point) {
  11205. // 1. If code point is end-of-stream and iso-2022-jp encoder
  11206. // state is not ASCII, prepend code point to stream, set
  11207. // iso-2022-jp encoder state to ASCII, and return three bytes
  11208. // 0x1B 0x28 0x42.
  11209. if (code_point === end_of_stream &&
  11210. iso2022jp_state !== states.ASCII) {
  11211. stream.prepend(code_point);
  11212. iso2022jp_state = states.ASCII;
  11213. return [0x1B, 0x28, 0x42];
  11214. }
  11215. // 2. If code point is end-of-stream and iso-2022-jp encoder
  11216. // state is ASCII, return finished.
  11217. if (code_point === end_of_stream && iso2022jp_state === states.ASCII)
  11218. return finished;
  11219. // 3. If ISO-2022-JP encoder state is ASCII or Roman, and code
  11220. // point is U+000E, U+000F, or U+001B, return error with U+FFFD.
  11221. if ((iso2022jp_state === states.ASCII ||
  11222. iso2022jp_state === states.Roman) &&
  11223. (code_point === 0x000E || code_point === 0x000F ||
  11224. code_point === 0x001B)) {
  11225. return encoderError(0xFFFD);
  11226. }
  11227. // 4. If iso-2022-jp encoder state is ASCII and code point is an
  11228. // ASCII code point, return a byte whose value is code point.
  11229. if (iso2022jp_state === states.ASCII &&
  11230. isASCIICodePoint(code_point))
  11231. return code_point;
  11232. // 5. If iso-2022-jp encoder state is Roman and code point is an
  11233. // ASCII code point, excluding U+005C and U+007E, or is U+00A5
  11234. // or U+203E, run these substeps:
  11235. if (iso2022jp_state === states.Roman &&
  11236. ((isASCIICodePoint(code_point) &&
  11237. code_point !== 0x005C && code_point !== 0x007E) ||
  11238. (code_point == 0x00A5 || code_point == 0x203E))) {
  11239. // 1. If code point is an ASCII code point, return a byte
  11240. // whose value is code point.
  11241. if (isASCIICodePoint(code_point))
  11242. return code_point;
  11243. // 2. If code point is U+00A5, return byte 0x5C.
  11244. if (code_point === 0x00A5)
  11245. return 0x5C;
  11246. // 3. If code point is U+203E, return byte 0x7E.
  11247. if (code_point === 0x203E)
  11248. return 0x7E;
  11249. }
  11250. // 6. If code point is an ASCII code point, and iso-2022-jp
  11251. // encoder state is not ASCII, prepend code point to stream, set
  11252. // iso-2022-jp encoder state to ASCII, and return three bytes
  11253. // 0x1B 0x28 0x42.
  11254. if (isASCIICodePoint(code_point) &&
  11255. iso2022jp_state !== states.ASCII) {
  11256. stream.prepend(code_point);
  11257. iso2022jp_state = states.ASCII;
  11258. return [0x1B, 0x28, 0x42];
  11259. }
  11260. // 7. If code point is either U+00A5 or U+203E, and iso-2022-jp
  11261. // encoder state is not Roman, prepend code point to stream, set
  11262. // iso-2022-jp encoder state to Roman, and return three bytes
  11263. // 0x1B 0x28 0x4A.
  11264. if ((code_point === 0x00A5 || code_point === 0x203E) &&
  11265. iso2022jp_state !== states.Roman) {
  11266. stream.prepend(code_point);
  11267. iso2022jp_state = states.Roman;
  11268. return [0x1B, 0x28, 0x4A];
  11269. }
  11270. // 8. If code point is U+2212, set it to U+FF0D.
  11271. if (code_point === 0x2212)
  11272. code_point = 0xFF0D;
  11273. // 9. Let pointer be the index pointer for code point in index
  11274. // jis0208.
  11275. var pointer = indexPointerFor(code_point, index('jis0208'));
  11276. // 10. If pointer is null, return error with code point.
  11277. if (pointer === null)
  11278. return encoderError(code_point);
  11279. // 11. If iso-2022-jp encoder state is not jis0208, prepend code
  11280. // point to stream, set iso-2022-jp encoder state to jis0208,
  11281. // and return three bytes 0x1B 0x24 0x42.
  11282. if (iso2022jp_state !== states.jis0208) {
  11283. stream.prepend(code_point);
  11284. iso2022jp_state = states.jis0208;
  11285. return [0x1B, 0x24, 0x42];
  11286. }
  11287. // 12. Let lead be floor(pointer / 94) + 0x21.
  11288. var lead = floor(pointer / 94) + 0x21;
  11289. // 13. Let trail be pointer % 94 + 0x21.
  11290. var trail = pointer % 94 + 0x21;
  11291. // 14. Return two bytes whose values are lead and trail.
  11292. return [lead, trail];
  11293. };
  11294. }
  11295. /** @param {{fatal: boolean}} options */
  11296. encoders['ISO-2022-JP'] = function(options) {
  11297. return new ISO2022JPEncoder(options);
  11298. };
  11299. /** @param {{fatal: boolean}} options */
  11300. decoders['ISO-2022-JP'] = function(options) {
  11301. return new ISO2022JPDecoder(options);
  11302. };
  11303. // 13.3 Shift_JIS
  11304. // 13.3.1 Shift_JIS decoder
  11305. /**
  11306. * @constructor
  11307. * @implements {Decoder}
  11308. * @param {{fatal: boolean}} options
  11309. */
  11310. function ShiftJISDecoder(options) {
  11311. var fatal = options.fatal;
  11312. // Shift_JIS's decoder has an associated Shift_JIS lead (initially
  11313. // 0x00).
  11314. var /** @type {number} */ Shift_JIS_lead = 0x00;
  11315. /**
  11316. * @param {Stream} stream The stream of bytes being decoded.
  11317. * @param {number} bite The next byte read from the stream.
  11318. * @return {?(number|!Array.<number>)} The next code point(s)
  11319. * decoded, or null if not enough data exists in the input
  11320. * stream to decode a complete code point.
  11321. */
  11322. this.handler = function(stream, bite) {
  11323. // 1. If byte is end-of-stream and Shift_JIS lead is not 0x00,
  11324. // set Shift_JIS lead to 0x00 and return error.
  11325. if (bite === end_of_stream && Shift_JIS_lead !== 0x00) {
  11326. Shift_JIS_lead = 0x00;
  11327. return decoderError(fatal);
  11328. }
  11329. // 2. If byte is end-of-stream and Shift_JIS lead is 0x00,
  11330. // return finished.
  11331. if (bite === end_of_stream && Shift_JIS_lead === 0x00)
  11332. return finished;
  11333. // 3. If Shift_JIS lead is not 0x00, let lead be Shift_JIS lead,
  11334. // let pointer be null, set Shift_JIS lead to 0x00, and then run
  11335. // these substeps:
  11336. if (Shift_JIS_lead !== 0x00) {
  11337. var lead = Shift_JIS_lead;
  11338. var pointer = null;
  11339. Shift_JIS_lead = 0x00;
  11340. // 1. Let offset be 0x40, if byte is less than 0x7F, and 0x41
  11341. // otherwise.
  11342. var offset = (bite < 0x7F) ? 0x40 : 0x41;
  11343. // 2. Let lead offset be 0x81, if lead is less than 0xA0, and
  11344. // 0xC1 otherwise.
  11345. var lead_offset = (lead < 0xA0) ? 0x81 : 0xC1;
  11346. // 3. If byte is in the range 0x40 to 0x7E, inclusive, or 0x80
  11347. // to 0xFC, inclusive, set pointer to (lead − lead offset) ×
  11348. // 188 + byte − offset.
  11349. if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0x80, 0xFC))
  11350. pointer = (lead - lead_offset) * 188 + bite - offset;
  11351. // 4. If pointer is in the range 8836 to 10715, inclusive,
  11352. // return a code point whose value is 0xE000 − 8836 + pointer.
  11353. if (inRange(pointer, 8836, 10715))
  11354. return 0xE000 - 8836 + pointer;
  11355. // 5. Let code point be null, if pointer is null, and the
  11356. // index code point for pointer in index jis0208 otherwise.
  11357. var code_point = (pointer === null) ? null :
  11358. indexCodePointFor(pointer, index('jis0208'));
  11359. // 6. If code point is null and byte is an ASCII byte, prepend
  11360. // byte to stream.
  11361. if (code_point === null && isASCIIByte(bite))
  11362. stream.prepend(bite);
  11363. // 7. If code point is null, return error.
  11364. if (code_point === null)
  11365. return decoderError(fatal);
  11366. // 8. Return a code point whose value is code point.
  11367. return code_point;
  11368. }
  11369. // 4. If byte is an ASCII byte or 0x80, return a code point
  11370. // whose value is byte.
  11371. if (isASCIIByte(bite) || bite === 0x80)
  11372. return bite;
  11373. // 5. If byte is in the range 0xA1 to 0xDF, inclusive, return a
  11374. // code point whose value is 0xFF61 − 0xA1 + byte.
  11375. if (inRange(bite, 0xA1, 0xDF))
  11376. return 0xFF61 - 0xA1 + bite;
  11377. // 6. If byte is in the range 0x81 to 0x9F, inclusive, or 0xE0
  11378. // to 0xFC, inclusive, set Shift_JIS lead to byte and return
  11379. // continue.
  11380. if (inRange(bite, 0x81, 0x9F) || inRange(bite, 0xE0, 0xFC)) {
  11381. Shift_JIS_lead = bite;
  11382. return null;
  11383. }
  11384. // 7. Return error.
  11385. return decoderError(fatal);
  11386. };
  11387. }
  11388. // 13.3.2 Shift_JIS encoder
  11389. /**
  11390. * @constructor
  11391. * @implements {Encoder}
  11392. * @param {{fatal: boolean}} options
  11393. */
  11394. function ShiftJISEncoder(options) {
  11395. options.fatal;
  11396. /**
  11397. * @param {Stream} stream Input stream.
  11398. * @param {number} code_point Next code point read from the stream.
  11399. * @return {(number|!Array.<number>)} Byte(s) to emit.
  11400. */
  11401. this.handler = function(stream, code_point) {
  11402. // 1. If code point is end-of-stream, return finished.
  11403. if (code_point === end_of_stream)
  11404. return finished;
  11405. // 2. If code point is an ASCII code point or U+0080, return a
  11406. // byte whose value is code point.
  11407. if (isASCIICodePoint(code_point) || code_point === 0x0080)
  11408. return code_point;
  11409. // 3. If code point is U+00A5, return byte 0x5C.
  11410. if (code_point === 0x00A5)
  11411. return 0x5C;
  11412. // 4. If code point is U+203E, return byte 0x7E.
  11413. if (code_point === 0x203E)
  11414. return 0x7E;
  11415. // 5. If code point is in the range U+FF61 to U+FF9F, inclusive,
  11416. // return a byte whose value is code point − 0xFF61 + 0xA1.
  11417. if (inRange(code_point, 0xFF61, 0xFF9F))
  11418. return code_point - 0xFF61 + 0xA1;
  11419. // 6. If code point is U+2212, set it to U+FF0D.
  11420. if (code_point === 0x2212)
  11421. code_point = 0xFF0D;
  11422. // 7. Let pointer be the index Shift_JIS pointer for code point.
  11423. var pointer = indexShiftJISPointerFor(code_point);
  11424. // 8. If pointer is null, return error with code point.
  11425. if (pointer === null)
  11426. return encoderError(code_point);
  11427. // 9. Let lead be floor(pointer / 188).
  11428. var lead = floor(pointer / 188);
  11429. // 10. Let lead offset be 0x81, if lead is less than 0x1F, and
  11430. // 0xC1 otherwise.
  11431. var lead_offset = (lead < 0x1F) ? 0x81 : 0xC1;
  11432. // 11. Let trail be pointer % 188.
  11433. var trail = pointer % 188;
  11434. // 12. Let offset be 0x40, if trail is less than 0x3F, and 0x41
  11435. // otherwise.
  11436. var offset = (trail < 0x3F) ? 0x40 : 0x41;
  11437. // 13. Return two bytes whose values are lead + lead offset and
  11438. // trail + offset.
  11439. return [lead + lead_offset, trail + offset];
  11440. };
  11441. }
  11442. /** @param {{fatal: boolean}} options */
  11443. encoders['Shift_JIS'] = function(options) {
  11444. return new ShiftJISEncoder(options);
  11445. };
  11446. /** @param {{fatal: boolean}} options */
  11447. decoders['Shift_JIS'] = function(options) {
  11448. return new ShiftJISDecoder(options);
  11449. };
  11450. //
  11451. // 14. Legacy multi-byte Korean encodings
  11452. //
  11453. // 14.1 euc-kr
  11454. // 14.1.1 euc-kr decoder
  11455. /**
  11456. * @constructor
  11457. * @implements {Decoder}
  11458. * @param {{fatal: boolean}} options
  11459. */
  11460. function EUCKRDecoder(options) {
  11461. var fatal = options.fatal;
  11462. // euc-kr's decoder has an associated euc-kr lead (initially 0x00).
  11463. var /** @type {number} */ euckr_lead = 0x00;
  11464. /**
  11465. * @param {Stream} stream The stream of bytes being decoded.
  11466. * @param {number} bite The next byte read from the stream.
  11467. * @return {?(number|!Array.<number>)} The next code point(s)
  11468. * decoded, or null if not enough data exists in the input
  11469. * stream to decode a complete code point.
  11470. */
  11471. this.handler = function(stream, bite) {
  11472. // 1. If byte is end-of-stream and euc-kr lead is not 0x00, set
  11473. // euc-kr lead to 0x00 and return error.
  11474. if (bite === end_of_stream && euckr_lead !== 0) {
  11475. euckr_lead = 0x00;
  11476. return decoderError(fatal);
  11477. }
  11478. // 2. If byte is end-of-stream and euc-kr lead is 0x00, return
  11479. // finished.
  11480. if (bite === end_of_stream && euckr_lead === 0)
  11481. return finished;
  11482. // 3. If euc-kr lead is not 0x00, let lead be euc-kr lead, let
  11483. // pointer be null, set euc-kr lead to 0x00, and then run these
  11484. // substeps:
  11485. if (euckr_lead !== 0x00) {
  11486. var lead = euckr_lead;
  11487. var pointer = null;
  11488. euckr_lead = 0x00;
  11489. // 1. If byte is in the range 0x41 to 0xFE, inclusive, set
  11490. // pointer to (lead − 0x81) × 190 + (byte − 0x41).
  11491. if (inRange(bite, 0x41, 0xFE))
  11492. pointer = (lead - 0x81) * 190 + (bite - 0x41);
  11493. // 2. Let code point be null, if pointer is null, and the
  11494. // index code point for pointer in index euc-kr otherwise.
  11495. var code_point = (pointer === null)
  11496. ? null : indexCodePointFor(pointer, index('euc-kr'));
  11497. // 3. If code point is null and byte is an ASCII byte, prepend
  11498. // byte to stream.
  11499. if (pointer === null && isASCIIByte(bite))
  11500. stream.prepend(bite);
  11501. // 4. If code point is null, return error.
  11502. if (code_point === null)
  11503. return decoderError(fatal);
  11504. // 5. Return a code point whose value is code point.
  11505. return code_point;
  11506. }
  11507. // 4. If byte is an ASCII byte, return a code point whose value
  11508. // is byte.
  11509. if (isASCIIByte(bite))
  11510. return bite;
  11511. // 5. If byte is in the range 0x81 to 0xFE, inclusive, set
  11512. // euc-kr lead to byte and return continue.
  11513. if (inRange(bite, 0x81, 0xFE)) {
  11514. euckr_lead = bite;
  11515. return null;
  11516. }
  11517. // 6. Return error.
  11518. return decoderError(fatal);
  11519. };
  11520. }
  11521. // 14.1.2 euc-kr encoder
  11522. /**
  11523. * @constructor
  11524. * @implements {Encoder}
  11525. * @param {{fatal: boolean}} options
  11526. */
  11527. function EUCKREncoder(options) {
  11528. options.fatal;
  11529. /**
  11530. * @param {Stream} stream Input stream.
  11531. * @param {number} code_point Next code point read from the stream.
  11532. * @return {(number|!Array.<number>)} Byte(s) to emit.
  11533. */
  11534. this.handler = function(stream, code_point) {
  11535. // 1. If code point is end-of-stream, return finished.
  11536. if (code_point === end_of_stream)
  11537. return finished;
  11538. // 2. If code point is an ASCII code point, return a byte whose
  11539. // value is code point.
  11540. if (isASCIICodePoint(code_point))
  11541. return code_point;
  11542. // 3. Let pointer be the index pointer for code point in index
  11543. // euc-kr.
  11544. var pointer = indexPointerFor(code_point, index('euc-kr'));
  11545. // 4. If pointer is null, return error with code point.
  11546. if (pointer === null)
  11547. return encoderError(code_point);
  11548. // 5. Let lead be floor(pointer / 190) + 0x81.
  11549. var lead = floor(pointer / 190) + 0x81;
  11550. // 6. Let trail be pointer % 190 + 0x41.
  11551. var trail = (pointer % 190) + 0x41;
  11552. // 7. Return two bytes whose values are lead and trail.
  11553. return [lead, trail];
  11554. };
  11555. }
  11556. /** @param {{fatal: boolean}} options */
  11557. encoders['EUC-KR'] = function(options) {
  11558. return new EUCKREncoder(options);
  11559. };
  11560. /** @param {{fatal: boolean}} options */
  11561. decoders['EUC-KR'] = function(options) {
  11562. return new EUCKRDecoder(options);
  11563. };
  11564. //
  11565. // 15. Legacy miscellaneous encodings
  11566. //
  11567. // 15.1 replacement
  11568. // Not needed - API throws RangeError
  11569. // 15.2 Common infrastructure for utf-16be and utf-16le
  11570. /**
  11571. * @param {number} code_unit
  11572. * @param {boolean} utf16be
  11573. * @return {!Array.<number>} bytes
  11574. */
  11575. function convertCodeUnitToBytes(code_unit, utf16be) {
  11576. // 1. Let byte1 be code unit >> 8.
  11577. var byte1 = code_unit >> 8;
  11578. // 2. Let byte2 be code unit & 0x00FF.
  11579. var byte2 = code_unit & 0x00FF;
  11580. // 3. Then return the bytes in order:
  11581. // utf-16be flag is set: byte1, then byte2.
  11582. if (utf16be)
  11583. return [byte1, byte2];
  11584. // utf-16be flag is unset: byte2, then byte1.
  11585. return [byte2, byte1];
  11586. }
  11587. // 15.2.1 shared utf-16 decoder
  11588. /**
  11589. * @constructor
  11590. * @implements {Decoder}
  11591. * @param {boolean} utf16_be True if big-endian, false if little-endian.
  11592. * @param {{fatal: boolean}} options
  11593. */
  11594. function UTF16Decoder(utf16_be, options) {
  11595. var fatal = options.fatal;
  11596. var /** @type {?number} */ utf16_lead_byte = null,
  11597. /** @type {?number} */ utf16_lead_surrogate = null;
  11598. /**
  11599. * @param {Stream} stream The stream of bytes being decoded.
  11600. * @param {number} bite The next byte read from the stream.
  11601. * @return {?(number|!Array.<number>)} The next code point(s)
  11602. * decoded, or null if not enough data exists in the input
  11603. * stream to decode a complete code point.
  11604. */
  11605. this.handler = function(stream, bite) {
  11606. // 1. If byte is end-of-stream and either utf-16 lead byte or
  11607. // utf-16 lead surrogate is not null, set utf-16 lead byte and
  11608. // utf-16 lead surrogate to null, and return error.
  11609. if (bite === end_of_stream && (utf16_lead_byte !== null ||
  11610. utf16_lead_surrogate !== null)) {
  11611. return decoderError(fatal);
  11612. }
  11613. // 2. If byte is end-of-stream and utf-16 lead byte and utf-16
  11614. // lead surrogate are null, return finished.
  11615. if (bite === end_of_stream && utf16_lead_byte === null &&
  11616. utf16_lead_surrogate === null) {
  11617. return finished;
  11618. }
  11619. // 3. If utf-16 lead byte is null, set utf-16 lead byte to byte
  11620. // and return continue.
  11621. if (utf16_lead_byte === null) {
  11622. utf16_lead_byte = bite;
  11623. return null;
  11624. }
  11625. // 4. Let code unit be the result of:
  11626. var code_unit;
  11627. if (utf16_be) {
  11628. // utf-16be decoder flag is set
  11629. // (utf-16 lead byte << 8) + byte.
  11630. code_unit = (utf16_lead_byte << 8) + bite;
  11631. } else {
  11632. // utf-16be decoder flag is unset
  11633. // (byte << 8) + utf-16 lead byte.
  11634. code_unit = (bite << 8) + utf16_lead_byte;
  11635. }
  11636. // Then set utf-16 lead byte to null.
  11637. utf16_lead_byte = null;
  11638. // 5. If utf-16 lead surrogate is not null, let lead surrogate
  11639. // be utf-16 lead surrogate, set utf-16 lead surrogate to null,
  11640. // and then run these substeps:
  11641. if (utf16_lead_surrogate !== null) {
  11642. var lead_surrogate = utf16_lead_surrogate;
  11643. utf16_lead_surrogate = null;
  11644. // 1. If code unit is in the range U+DC00 to U+DFFF,
  11645. // inclusive, return a code point whose value is 0x10000 +
  11646. // ((lead surrogate − 0xD800) << 10) + (code unit − 0xDC00).
  11647. if (inRange(code_unit, 0xDC00, 0xDFFF)) {
  11648. return 0x10000 + (lead_surrogate - 0xD800) * 0x400 +
  11649. (code_unit - 0xDC00);
  11650. }
  11651. // 2. Prepend the sequence resulting of converting code unit
  11652. // to bytes using utf-16be decoder flag to stream and return
  11653. // error.
  11654. stream.prepend(convertCodeUnitToBytes(code_unit, utf16_be));
  11655. return decoderError(fatal);
  11656. }
  11657. // 6. If code unit is in the range U+D800 to U+DBFF, inclusive,
  11658. // set utf-16 lead surrogate to code unit and return continue.
  11659. if (inRange(code_unit, 0xD800, 0xDBFF)) {
  11660. utf16_lead_surrogate = code_unit;
  11661. return null;
  11662. }
  11663. // 7. If code unit is in the range U+DC00 to U+DFFF, inclusive,
  11664. // return error.
  11665. if (inRange(code_unit, 0xDC00, 0xDFFF))
  11666. return decoderError(fatal);
  11667. // 8. Return code point code unit.
  11668. return code_unit;
  11669. };
  11670. }
  11671. // 15.2.2 shared utf-16 encoder
  11672. /**
  11673. * @constructor
  11674. * @implements {Encoder}
  11675. * @param {boolean} utf16_be True if big-endian, false if little-endian.
  11676. * @param {{fatal: boolean}} options
  11677. */
  11678. function UTF16Encoder(utf16_be, options) {
  11679. options.fatal;
  11680. /**
  11681. * @param {Stream} stream Input stream.
  11682. * @param {number} code_point Next code point read from the stream.
  11683. * @return {(number|!Array.<number>)} Byte(s) to emit.
  11684. */
  11685. this.handler = function(stream, code_point) {
  11686. // 1. If code point is end-of-stream, return finished.
  11687. if (code_point === end_of_stream)
  11688. return finished;
  11689. // 2. If code point is in the range U+0000 to U+FFFF, inclusive,
  11690. // return the sequence resulting of converting code point to
  11691. // bytes using utf-16be encoder flag.
  11692. if (inRange(code_point, 0x0000, 0xFFFF))
  11693. return convertCodeUnitToBytes(code_point, utf16_be);
  11694. // 3. Let lead be ((code point − 0x10000) >> 10) + 0xD800,
  11695. // converted to bytes using utf-16be encoder flag.
  11696. var lead = convertCodeUnitToBytes(
  11697. ((code_point - 0x10000) >> 10) + 0xD800, utf16_be);
  11698. // 4. Let trail be ((code point − 0x10000) & 0x3FF) + 0xDC00,
  11699. // converted to bytes using utf-16be encoder flag.
  11700. var trail = convertCodeUnitToBytes(
  11701. ((code_point - 0x10000) & 0x3FF) + 0xDC00, utf16_be);
  11702. // 5. Return a byte sequence of lead followed by trail.
  11703. return lead.concat(trail);
  11704. };
  11705. }
  11706. // 15.3 utf-16be
  11707. // 15.3.1 utf-16be decoder
  11708. /** @param {{fatal: boolean}} options */
  11709. encoders['UTF-16BE'] = function(options) {
  11710. return new UTF16Encoder(true, options);
  11711. };
  11712. // 15.3.2 utf-16be encoder
  11713. /** @param {{fatal: boolean}} options */
  11714. decoders['UTF-16BE'] = function(options) {
  11715. return new UTF16Decoder(true, options);
  11716. };
  11717. // 15.4 utf-16le
  11718. // 15.4.1 utf-16le decoder
  11719. /** @param {{fatal: boolean}} options */
  11720. encoders['UTF-16LE'] = function(options) {
  11721. return new UTF16Encoder(false, options);
  11722. };
  11723. // 15.4.2 utf-16le encoder
  11724. /** @param {{fatal: boolean}} options */
  11725. decoders['UTF-16LE'] = function(options) {
  11726. return new UTF16Decoder(false, options);
  11727. };
  11728. // 15.5 x-user-defined
  11729. // 15.5.1 x-user-defined decoder
  11730. /**
  11731. * @constructor
  11732. * @implements {Decoder}
  11733. * @param {{fatal: boolean}} options
  11734. */
  11735. function XUserDefinedDecoder(options) {
  11736. options.fatal;
  11737. /**
  11738. * @param {Stream} stream The stream of bytes being decoded.
  11739. * @param {number} bite The next byte read from the stream.
  11740. * @return {?(number|!Array.<number>)} The next code point(s)
  11741. * decoded, or null if not enough data exists in the input
  11742. * stream to decode a complete code point.
  11743. */
  11744. this.handler = function(stream, bite) {
  11745. // 1. If byte is end-of-stream, return finished.
  11746. if (bite === end_of_stream)
  11747. return finished;
  11748. // 2. If byte is an ASCII byte, return a code point whose value
  11749. // is byte.
  11750. if (isASCIIByte(bite))
  11751. return bite;
  11752. // 3. Return a code point whose value is 0xF780 + byte − 0x80.
  11753. return 0xF780 + bite - 0x80;
  11754. };
  11755. }
  11756. // 15.5.2 x-user-defined encoder
  11757. /**
  11758. * @constructor
  11759. * @implements {Encoder}
  11760. * @param {{fatal: boolean}} options
  11761. */
  11762. function XUserDefinedEncoder(options) {
  11763. options.fatal;
  11764. /**
  11765. * @param {Stream} stream Input stream.
  11766. * @param {number} code_point Next code point read from the stream.
  11767. * @return {(number|!Array.<number>)} Byte(s) to emit.
  11768. */
  11769. this.handler = function(stream, code_point) {
  11770. // 1.If code point is end-of-stream, return finished.
  11771. if (code_point === end_of_stream)
  11772. return finished;
  11773. // 2. If code point is an ASCII code point, return a byte whose
  11774. // value is code point.
  11775. if (isASCIICodePoint(code_point))
  11776. return code_point;
  11777. // 3. If code point is in the range U+F780 to U+F7FF, inclusive,
  11778. // return a byte whose value is code point − 0xF780 + 0x80.
  11779. if (inRange(code_point, 0xF780, 0xF7FF))
  11780. return code_point - 0xF780 + 0x80;
  11781. // 4. Return error with code point.
  11782. return encoderError(code_point);
  11783. };
  11784. }
  11785. /** @param {{fatal: boolean}} options */
  11786. encoders['x-user-defined'] = function(options) {
  11787. return new XUserDefinedEncoder(options);
  11788. };
  11789. /** @param {{fatal: boolean}} options */
  11790. decoders['x-user-defined'] = function(options) {
  11791. return new XUserDefinedDecoder(options);
  11792. };
  11793. if (!global['TextEncoder'])
  11794. global['TextEncoder'] = TextEncoder;
  11795. if (!global['TextDecoder'])
  11796. global['TextDecoder'] = TextDecoder;
  11797. if (module.exports) {
  11798. module.exports = {
  11799. TextEncoder: global['TextEncoder'],
  11800. TextDecoder: global['TextDecoder'],
  11801. EncodingIndexes: global["encoding-indexes"]
  11802. };
  11803. }
  11804. // For strict environments where `this` inside the global scope
  11805. // is `undefined`, take a pure object instead
  11806. }(commonjsGlobal || {}));
  11807. } (encoding));
  11808. // Copyright Joyent, Inc. and other Node contributors.
  11809. //
  11810. // Permission is hereby granted, free of charge, to any person obtaining a
  11811. // copy of this software and associated documentation files (the
  11812. // "Software"), to deal in the Software without restriction, including
  11813. // without limitation the rights to use, copy, modify, merge, publish,
  11814. // distribute, sublicense, and/or sell copies of the Software, and to permit
  11815. // persons to whom the Software is furnished to do so, subject to the
  11816. // following conditions:
  11817. //
  11818. // The above copyright notice and this permission notice shall be included
  11819. // in all copies or substantial portions of the Software.
  11820. //
  11821. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  11822. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11823. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  11824. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  11825. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  11826. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  11827. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  11828. var isBufferEncoding = Buffer.isEncoding
  11829. || function(encoding) {
  11830. switch (encoding && encoding.toLowerCase()) {
  11831. 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': return true;
  11832. default: return false;
  11833. }
  11834. };
  11835. function assertEncoding(encoding) {
  11836. if (encoding && !isBufferEncoding(encoding)) {
  11837. throw new Error('Unknown encoding: ' + encoding);
  11838. }
  11839. }
  11840. // StringDecoder provides an interface for efficiently splitting a series of
  11841. // buffers into a series of JS strings without breaking apart multi-byte
  11842. // characters. CESU-8 is handled as part of the UTF-8 encoding.
  11843. //
  11844. // @TODO Handling all encodings inside a single object makes it very difficult
  11845. // to reason about this code, so it should be split up in the future.
  11846. // @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code
  11847. // points as used by CESU-8.
  11848. function StringDecoder$1(encoding) {
  11849. this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
  11850. assertEncoding(encoding);
  11851. switch (this.encoding) {
  11852. case 'utf8':
  11853. // CESU-8 represents each of Surrogate Pair by 3-bytes
  11854. this.surrogateSize = 3;
  11855. break;
  11856. case 'ucs2':
  11857. case 'utf16le':
  11858. // UTF-16 represents each of Surrogate Pair by 2-bytes
  11859. this.surrogateSize = 2;
  11860. this.detectIncompleteChar = utf16DetectIncompleteChar;
  11861. break;
  11862. case 'base64':
  11863. // Base-64 stores 3 bytes in 4 chars, and pads the remainder.
  11864. this.surrogateSize = 3;
  11865. this.detectIncompleteChar = base64DetectIncompleteChar;
  11866. break;
  11867. default:
  11868. this.write = passThroughWrite;
  11869. return;
  11870. }
  11871. // Enough space to store all bytes of a single character. UTF-8 needs 4
  11872. // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate).
  11873. this.charBuffer = new Buffer(6);
  11874. // Number of bytes received for the current incomplete multi-byte character.
  11875. this.charReceived = 0;
  11876. // Number of bytes expected for the current incomplete multi-byte character.
  11877. this.charLength = 0;
  11878. }
  11879. // write decodes the given buffer and returns it as JS string that is
  11880. // guaranteed to not contain any partial multi-byte characters. Any partial
  11881. // character found at the end of the buffer is buffered up, and will be
  11882. // returned when calling write again with the remaining bytes.
  11883. //
  11884. // Note: Converting a Buffer containing an orphan surrogate to a String
  11885. // currently works, but converting a String to a Buffer (via `new Buffer`, or
  11886. // Buffer#write) will replace incomplete surrogates with the unicode
  11887. // replacement character. See https://codereview.chromium.org/121173009/ .
  11888. StringDecoder$1.prototype.write = function(buffer) {
  11889. var charStr = '';
  11890. // if our last write ended with an incomplete multibyte character
  11891. while (this.charLength) {
  11892. // determine how many remaining bytes this buffer has to offer for this char
  11893. var available = (buffer.length >= this.charLength - this.charReceived) ?
  11894. this.charLength - this.charReceived :
  11895. buffer.length;
  11896. // add the new bytes to the char buffer
  11897. buffer.copy(this.charBuffer, this.charReceived, 0, available);
  11898. this.charReceived += available;
  11899. if (this.charReceived < this.charLength) {
  11900. // still not enough chars in this buffer? wait for more ...
  11901. return '';
  11902. }
  11903. // remove bytes belonging to the current character from the buffer
  11904. buffer = buffer.slice(available, buffer.length);
  11905. // get the character that was split
  11906. charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
  11907. // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
  11908. var charCode = charStr.charCodeAt(charStr.length - 1);
  11909. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  11910. this.charLength += this.surrogateSize;
  11911. charStr = '';
  11912. continue;
  11913. }
  11914. this.charReceived = this.charLength = 0;
  11915. // if there are no more bytes in this buffer, just emit our char
  11916. if (buffer.length === 0) {
  11917. return charStr;
  11918. }
  11919. break;
  11920. }
  11921. // determine and set charLength / charReceived
  11922. this.detectIncompleteChar(buffer);
  11923. var end = buffer.length;
  11924. if (this.charLength) {
  11925. // buffer the incomplete character bytes we got
  11926. buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end);
  11927. end -= this.charReceived;
  11928. }
  11929. charStr += buffer.toString(this.encoding, 0, end);
  11930. var end = charStr.length - 1;
  11931. var charCode = charStr.charCodeAt(end);
  11932. // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
  11933. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  11934. var size = this.surrogateSize;
  11935. this.charLength += size;
  11936. this.charReceived += size;
  11937. this.charBuffer.copy(this.charBuffer, size, 0, size);
  11938. buffer.copy(this.charBuffer, 0, 0, size);
  11939. return charStr.substring(0, end);
  11940. }
  11941. // or just emit the charStr
  11942. return charStr;
  11943. };
  11944. // detectIncompleteChar determines if there is an incomplete UTF-8 character at
  11945. // the end of the given buffer. If so, it sets this.charLength to the byte
  11946. // length that character, and sets this.charReceived to the number of bytes
  11947. // that are available for this character.
  11948. StringDecoder$1.prototype.detectIncompleteChar = function(buffer) {
  11949. // determine how many bytes we have to check at the end of this buffer
  11950. var i = (buffer.length >= 3) ? 3 : buffer.length;
  11951. // Figure out if one of the last i bytes of our buffer announces an
  11952. // incomplete char.
  11953. for (; i > 0; i--) {
  11954. var c = buffer[buffer.length - i];
  11955. // See http://en.wikipedia.org/wiki/UTF-8#Description
  11956. // 110XXXXX
  11957. if (i == 1 && c >> 5 == 0x06) {
  11958. this.charLength = 2;
  11959. break;
  11960. }
  11961. // 1110XXXX
  11962. if (i <= 2 && c >> 4 == 0x0E) {
  11963. this.charLength = 3;
  11964. break;
  11965. }
  11966. // 11110XXX
  11967. if (i <= 3 && c >> 3 == 0x1E) {
  11968. this.charLength = 4;
  11969. break;
  11970. }
  11971. }
  11972. this.charReceived = i;
  11973. };
  11974. StringDecoder$1.prototype.end = function(buffer) {
  11975. var res = '';
  11976. if (buffer && buffer.length)
  11977. res = this.write(buffer);
  11978. if (this.charReceived) {
  11979. var cr = this.charReceived;
  11980. var buf = this.charBuffer;
  11981. var enc = this.encoding;
  11982. res += buf.slice(0, cr).toString(enc);
  11983. }
  11984. return res;
  11985. };
  11986. function passThroughWrite(buffer) {
  11987. return buffer.toString(this.encoding);
  11988. }
  11989. function utf16DetectIncompleteChar(buffer) {
  11990. this.charReceived = buffer.length % 2;
  11991. this.charLength = this.charReceived ? 2 : 0;
  11992. }
  11993. function base64DetectIncompleteChar(buffer) {
  11994. this.charReceived = buffer.length % 3;
  11995. this.charLength = this.charReceived ? 3 : 0;
  11996. }
  11997. var stringDecoder = /*#__PURE__*/Object.freeze({
  11998. __proto__: null,
  11999. StringDecoder: StringDecoder$1
  12000. });
  12001. var require$$1 = /*@__PURE__*/getAugmentedNamespace(stringDecoder);
  12002. var StringDecoder = require$$1.StringDecoder;
  12003. function defaultDecoder(data) {
  12004. var decoder = new StringDecoder();
  12005. var out = decoder.write(data) + decoder.end();
  12006. return out.replace(/\0/g, '').trim();
  12007. }
  12008. var decoderBrowser = createDecoder$1;
  12009. var regex = /^(?:ANSI\s)?(\d+)$/m;
  12010. function createDecoder$1(encoding, second) {
  12011. if (!encoding) {
  12012. return defaultDecoder;
  12013. }
  12014. try {
  12015. new TextDecoder(encoding.trim());
  12016. } catch(e) {
  12017. var match = regex.exec(encoding);
  12018. if (match && !second) {
  12019. return createDecoder$1('windows-' + match[1], true);
  12020. } else {
  12021. return defaultDecoder;
  12022. }
  12023. }
  12024. return browserDecoder;
  12025. function browserDecoder(buffer) {
  12026. var decoder = new TextDecoder(encoding);
  12027. var out = decoder.decode(buffer, {
  12028. stream: true
  12029. }) + decoder.decode();
  12030. return out.replace(/\0/g, '').trim();
  12031. }
  12032. }
  12033. var createDecoder = decoderBrowser;
  12034. function dbfHeader(data) {
  12035. var out = {};
  12036. out.lastUpdated = new Date(data.readUInt8(1) + 1900, data.readUInt8(2), data.readUInt8(3));
  12037. out.records = data.readUInt32LE(4);
  12038. out.headerLen = data.readUInt16LE(8);
  12039. out.recLen = data.readUInt16LE(10);
  12040. return out;
  12041. }
  12042. function dbfRowHeader(data, headerLen, decoder) {
  12043. var out = [];
  12044. var offset = 32;
  12045. while (offset < headerLen) {
  12046. out.push({
  12047. name: decoder(data.slice(offset, offset + 11)),
  12048. dataType: String.fromCharCode(data.readUInt8(offset + 11)),
  12049. len: data.readUInt8(offset + 16),
  12050. decimal: data.readUInt8(offset + 17)
  12051. });
  12052. if (data.readUInt8(offset + 32) === 13) {
  12053. break;
  12054. } else {
  12055. offset += 32;
  12056. }
  12057. }
  12058. return out;
  12059. }
  12060. function rowFuncs(buffer, offset, len, type, decoder) {
  12061. var data = buffer.slice(offset, offset + len);
  12062. var textData = decoder(data);
  12063. switch (type) {
  12064. case 'N':
  12065. case 'F':
  12066. case 'O':
  12067. return parseFloat(textData, 10);
  12068. case 'D':
  12069. return new Date(textData.slice(0, 4), parseInt(textData.slice(4, 6), 10) - 1, textData.slice(6, 8));
  12070. case 'L':
  12071. return textData.toLowerCase() === 'y' || textData.toLowerCase() === 't';
  12072. default:
  12073. return textData;
  12074. }
  12075. }
  12076. function parseRow(buffer, offset, rowHeaders, decoder) {
  12077. var out = {};
  12078. var i = 0;
  12079. var len = rowHeaders.length;
  12080. var field;
  12081. var header;
  12082. while (i < len) {
  12083. header = rowHeaders[i];
  12084. field = rowFuncs(buffer, offset, header.len, header.dataType, decoder);
  12085. offset += header.len;
  12086. if (typeof field !== 'undefined') {
  12087. out[header.name] = field;
  12088. }
  12089. i++;
  12090. }
  12091. return out;
  12092. }
  12093. var parsedbf = function(buffer, encoding) {
  12094. var decoder = createDecoder(encoding);
  12095. var header = dbfHeader(buffer);
  12096. var rowHeaders = dbfRowHeader(buffer, header.headerLen - 1, decoder);
  12097. var offset = ((rowHeaders.length + 1) << 5) + 2;
  12098. var recLen = header.recLen;
  12099. var records = header.records;
  12100. var out = [];
  12101. while (records) {
  12102. out.push(parseRow(buffer, offset, rowHeaders, decoder));
  12103. offset += recLen;
  12104. records--;
  12105. }
  12106. return out;
  12107. };
  12108. var parseDbf = /*@__PURE__*/getDefaultExportFromCjs(parsedbf);
  12109. const URL = globalThis.URL;
  12110. function toBuffer(b) {
  12111. if (!b) {
  12112. throw new Error('forgot to pass buffer');
  12113. }
  12114. if (Buffer.isBuffer(b)) {
  12115. return b;
  12116. }
  12117. if (isArrayBuffer(b)) {
  12118. return Buffer.from(b);
  12119. }
  12120. if (isArrayBuffer(b.buffer)) {
  12121. if (b.BYTES_PER_ELEMENT === 1) {
  12122. return Buffer.from(b);
  12123. }
  12124. return Buffer.from(b.buffer);
  12125. }
  12126. }
  12127. function isArrayBuffer(subject) {
  12128. return subject instanceof globalThis.ArrayBuffer || Object.prototype.toString.call(subject) === '[object ArrayBuffer]';
  12129. }
  12130. const combine = function ([shp, dbf]) {
  12131. const out = {};
  12132. out.type = 'FeatureCollection';
  12133. out.features = [];
  12134. let i = 0;
  12135. const len = shp.length;
  12136. if (!dbf) {
  12137. dbf = [];
  12138. }
  12139. while (i < len) {
  12140. out.features.push({
  12141. type: 'Feature',
  12142. geometry: shp[i],
  12143. properties: dbf[i] || {}
  12144. });
  12145. i++;
  12146. }
  12147. return out;
  12148. };
  12149. const parseZip = async function (buffer, whiteList) {
  12150. let key;
  12151. buffer = toBuffer(buffer);
  12152. const zip = await unzip(buffer);
  12153. const names = [];
  12154. whiteList = whiteList || [];
  12155. for (key in zip) {
  12156. if (key.indexOf('__MACOSX') !== -1) {
  12157. continue;
  12158. }
  12159. if (key.slice(-4).toLowerCase() === '.shp') {
  12160. names.push(key.slice(0, -4));
  12161. zip[key.slice(0, -3) + key.slice(-3).toLowerCase()] = zip[key];
  12162. } else if (key.slice(-4).toLowerCase() === '.prj') {
  12163. zip[key.slice(0, -3) + key.slice(-3).toLowerCase()] = proj4(zip[key]);
  12164. } else if (key.slice(-5).toLowerCase() === '.json' || whiteList.indexOf(key.split('.').pop()) > -1) {
  12165. names.push(key.slice(0, -3) + key.slice(-3).toLowerCase());
  12166. } else if (key.slice(-4).toLowerCase() === '.dbf' || key.slice(-4).toLowerCase() === '.cpg') {
  12167. zip[key.slice(0, -3) + key.slice(-3).toLowerCase()] = zip[key];
  12168. }
  12169. }
  12170. if (!names.length) {
  12171. throw new Error('no layers founds');
  12172. }
  12173. const geojson = names.map(function (name) {
  12174. let parsed, dbf;
  12175. const lastDotIdx = name.lastIndexOf('.');
  12176. if (lastDotIdx > -1 && name.slice(lastDotIdx).indexOf('json') > -1) {
  12177. parsed = JSON.parse(zip[name]);
  12178. parsed.fileName = name.slice(0, lastDotIdx);
  12179. } else if (whiteList.indexOf(name.slice(lastDotIdx + 1)) > -1) {
  12180. parsed = zip[name];
  12181. parsed.fileName = name;
  12182. } else {
  12183. if (zip[name + '.dbf']) {
  12184. dbf = parseDbf(zip[name + '.dbf'], zip[name + '.cpg']);
  12185. }
  12186. parsed = combine([parseShp(zip[name + '.shp'], zip[name + '.prj']), dbf]);
  12187. parsed.fileName = name;
  12188. }
  12189. return parsed;
  12190. });
  12191. if (geojson.length === 1) {
  12192. return geojson[0];
  12193. } else {
  12194. return geojson;
  12195. }
  12196. };
  12197. async function getZip(base, whiteList) {
  12198. const a = await binaryAjax(base);
  12199. return parseZip(a, whiteList);
  12200. }
  12201. const handleShp = async (base) => {
  12202. const args = await Promise.all([
  12203. binaryAjax(base, 'shp'),
  12204. binaryAjax(base, 'prj')
  12205. ]);
  12206. let prj = false;
  12207. try {
  12208. if (args[1]) {
  12209. prj = proj4(args[1]);
  12210. }
  12211. } catch (e) {
  12212. prj = false;
  12213. }
  12214. return parseShp(args[0], prj);
  12215. };
  12216. const handleDbf = async (base) => {
  12217. const [dbf, cpg] = await Promise.all([
  12218. binaryAjax(base, 'dbf'),
  12219. binaryAjax(base, 'cpg')
  12220. ]);
  12221. if (!dbf) {
  12222. return;
  12223. }
  12224. return parseDbf(dbf, cpg);
  12225. };
  12226. const checkSuffix = (base, suffix) => {
  12227. const url = new URL(base);
  12228. return url.pathname.slice(-4).toLowerCase() === suffix;
  12229. };
  12230. const getShapefile = async function (base, whiteList) {
  12231. if (typeof base !== 'string') {
  12232. return parseZip(base);
  12233. }
  12234. if (checkSuffix(base, '.zip')) {
  12235. return getZip(base, whiteList);
  12236. }
  12237. const results = await Promise.all([
  12238. handleShp(base),
  12239. handleDbf(base)
  12240. ]);
  12241. return combine(results);
  12242. };
  12243. const _parseShp = function (shp, prj) {
  12244. shp = toBuffer(shp);
  12245. if (Buffer.isBuffer(prj)) {
  12246. prj = prj.toString();
  12247. }
  12248. if (typeof prj === 'string') {
  12249. try {
  12250. prj = proj4(prj);
  12251. } catch (e) {
  12252. prj = false;
  12253. }
  12254. }
  12255. return parseShp(shp, prj);
  12256. };
  12257. const _parseDbf = function (dbf, cpg) {
  12258. dbf = toBuffer(dbf);
  12259. return parseDbf(dbf, cpg);
  12260. };
  12261. getShapefile.combine = combine;
  12262. getShapefile.parseDbf = _parseDbf;
  12263. getShapefile.parseZip = parseZip;
  12264. getShapefile.parseShp = _parseShp;
  12265. return getShapefile;
  12266. }));